The KawigiEdit Plugin for TopCoder

KawigiEdit is a full-blown TopCoder Editor plugin with all the features I decided I wanted to have in it.

Among the most useful features in this plugin are:

Installing KawigiEdit

How to install KawigiEdit in 10 easy steps:

  1. Download the KawigiEdit jar to your computer (and remember where you saved it).
  2. Start the TopCoder Arena applet.
  3. From the Options menu, choose "Editor". The Editor Preferences dialog should come up.
  4. Click on the "Add" button. A dialog titled "Enter Plugin Information" should pop up.
  5. For "Name", enter "KawigiEdit" (or whatever you want it to be called, it doesn't really matter)
  6. For "EntryPoint", enter "kawigi.KawigiEdit" (this one does matter).
  7. For "ClassPath", hit "Browse" and find the KawigiEdit jar.
  8. Once those are entered in correctly, click OK.
  9. If you want KawigiEdit to be used as your default editor, check the "Default" box next to the new entry in the table.
  10. Click "Save".

Configuring KawigiEdit

Assuming everything worked without any error messages, KawigiEdit is now installed and ready to use. However, it is advisable to do a few more things, to make sure it is all configured correctly for your system (and to your liking).

To configure KawigiEdit, simply select it on the "Editor Preferences" dialog and hit the "Configure" button. A dialog will come up with three tabs for "General/Testing", "Editor" and "Languages".

General Settings

One setting you are likely to want to customize is where on your computer KawigiEdit will save your code. By default, it makes a directory called "testprograms" whereever the applet's current working directory is (in Windows this appears to be your desktop, in Linux it uses your home directory). Use the Browse button or directly enter the name of the folder you want to use.

The other general setting is "Use more standard UI". When writing this, I made UI design decisions based on the speed I could access features. As such, some of my UI might be "weird" to use, and may even not work in some versions of the JVM. This is now only partially implemented, so I don't recommend checking it at the moment. Eventually what it will do is use dialog boxes for the file chooser to view local code, for search and replace functions, and for the panel to add a snippet, rather than having the functionality right on the menu.

Testing Settings

Here, you can change the font and colors of the testing console panel. This is where the output to your programs will be displayed when you use the local compile and test features.

Editor Settings

Here, you can change the font and colors used in the editor and local code display. This includes syntax-related coloring, like:

Language Settings

On this tab, you configure how to save, compile and run your programs locally. Note that $PROBLEM$ will substitute the problem class name in, and $CWD$ will substitute the current working directory for the run command only. The CWD is not available for the filename and compile command (You may assume that you are in the current working directory).

The default settings should work for most people whose system is configured exactly like mine. Fat chance, eh?

The default Java settings should work beautifully if you have Sun's Java SDK installed, and Java's bin directory is in your default system path.

The default C++ settings should be correct if you use g++, and it is in the path, for either Windows or *nix.

The default C# and VB settings should be correct if you use Windows and have version 1.1 of the Microsoft .NET Framework, even if the compilers are not in the default path.

The rule of thumb on these settings is that you should try them out, and if they work, don' mess with them.

Using KawigiEdit - A Walkthrough

Here is a quick example of how to use KawigiEdit in the Arena.

My Reflector Utility

I also included a simple Java Reflection Utility I wrote that helped me figure out how to use undocumented classes referenced in the TopCoder plugin API. I figured it would be useful to other potential plugin authors if they could:

  1. Have some way of "looking" into classes that doesn't involve illegally reverse-engineering them
  2. Have a functional open-source plugin to look at for examples.

To use the Reflector on the contest applet jar, first download that jar (or copy it from your internet cache or whatever). It's called ContestApplet.jar, and its location on TopCoder.com can be derived from the applet tag in the window that launches the arena.

Put the contest applet jar in the same folder as the KawigiEdit jar, and browse there in a console window.

Now type:

	java -classpath ContestApplet.jar;KawigiEdit.jar kawigi.Reflector ContestApplet.jar
		

Note: On some operating systems, you will need to use a ':' instead of a ';'

A window should pop up with a JTree widget that can be expanded to see the packages, classes, and public/protected methods/members within the jar.

Eventually, I may write a bit on the useful undocumented features that I've slowly and painfully learned to use, also to help out future plugin authors.

Editing KawigiEdit

I included the source to KawigiEdit for a reason - I think that it's a good place to learn from (even if I did some slightly hackish things in some places), and I don't think it's perfect for everyone. If you are familiar with Java and want to customize KawigiEdit further than can be done through my configure dialog, you can unpack it and start hacking at it. If you find ways to improve it that you think would be useful to others, too, please let me know what you did and how/why you did it.

The standard way to unpack the jar would be to use Sun's jar utility (part of the Java SDK) like this:

	jar -xf KawigiEdit.jar
		

You can also likely open it and extract it using WinZip or another similar program.

To make the applet use the extracted plugin instead of the jarred one, set the directory you extracted it into as the classpath (rather than the jar). This directory should have a directory called "kawigi" in it (but it shouldn't be the directory called "kawigi").

You'll also notice that this html file, a folder for the manifest, and a folder called "docs" popped out of the jar. In the docs folder, you'll find full documentation of the classes included in the jar (sorry if it's not quite accurate). This may help you to know where to start in changing stuff.

Other Notes

As for things that I should mention that didn't fit anywhere else, the most notable thing is main methods - on testing, it seems to be ok to put a main method in your source file to use for test cases. It compiles and runs fine locally and compiles and runs fine on TopCoder, with the exception of using C++. Putting a main method in your source file in C++ causes a linker error on TopCoder. As such, I don't put it in there. However, don't be deceived - I still generate a main method for C++ programs for local testing, I just do it when you save the file. So, at the end of the saved file (if you were to open it), you would see something like this:

int main() {
	int time;
	int errors = 0;
	
	time = test0();
	if (time < 0)
		errors++;
	
	time = test1();
	if (time < 0)
		errors++;
	
	...
	
	if (errors == 0)
		cout <<"You're a stud (at least on the example cases)!" <<endl;
	else
		cout <<"Some of the test cases had errors." <<endl;
}
	

This allows you to test and also compile successfully on TopCoder.

Contact Info

Anyone is welcome to contact me about features they hacked in, features they think I should add, problems, suggestions, etc. Try to keep the "uR pLu61n suX0rZ, j00z sh0uLD uZ3 P0p53di7!" emails to a minimum.