KawigiEdit 2.0 - An Integrated 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:
- Syntax highlighting and line numbering in the editor and auto-indent.
- Undo/Redo support
- Advanced Search and Replace with support for literal strings, wildcards, regular expressions, case-insensitivity and word boundary matching.
- Generates testing code from the example test cases in the problem statement.
- Times the execution of each test case in the test code.
- Saves your code locally, compiles it, and runs the test cases all at the click of a button.
- Provides quick access to past code saved by KawigiEdit
- Allows you to save a database of code snippets for general use.
- Configurable to your preferences of colors, fonts, etc, as well as filenames, compile and run commands, tab width, etc. (so it can be configured to work on any platform with any compilers)
- Complete support for C++, Java, C# and Visual Basic (suggestions welcome on improving this)!
- Block matching - for language constructs that have a logical beginning and ending, if your cursor is over one end of it, the opposite end is highlighted
- In addition to the normal block matching, a graphical bracket next to the line numbers shows the span of curly braces that you are currently in.
- Mouse wheel scrolling (this seems to be extremely important to some people :-p).
- Drag and drop code, if you enjoy doing that.
- Configurable tab width.
- Simple code template customization (note - KawigiEdit 2.0 no longer supports compiled templates from KawigiEdit 1.1. This makes it easier for people to use who don't have a Java compiler handy, but is slightly less powerful).
- Can save your code to disk or load it back up from disk. Trust me, if your computer ever crashes during a match, this will make you happy.
- Several standard editing features.
- Open source and free to be hacked up by YOU if it's missing anything.
- Java 1.5 Runtime Environment! The arena now requires Java 1.4, as did KawigiEdit 1.x. KawigiEdit 2.0 uses lots of the new Java 1.5 features, so you will need Java 1.5 to use KawigiEdit 2.0.
- I recommend having at least about a 500 Mhz Intel-type processor, or something comparable. It will run on a slower system, as well. For computers at about that level, text rendering may start to lag if you have a lot of code in there. Eventually I'll get working on that so that the general experience is better.
- I recommend having at least 64 MB of RAM, but I've never actually tested it with less than 200 MB of RAM. I don't suspect KawigiEdit is likely to use nearly that much, let me know if it ever has more than 40 MB, because that's where I think it's getting absurd, even with a graphical Java application.
- If you want to use the testing features, you must have a compiler (and possibly runtime) installed for your language(s).
How to install KawigiEdit in 10 easy steps:
- Download the latest KawigiEdit jar to your computer (and remember where you saved it).
- Start the TopCoder Arena applet.
- From the Options menu, choose "Editor". The Editor Preferences dialog should come up.
- Click on the "Add" button. A dialog titled "Enter Plugin Information" should pop up.
- For "Name", enter "KawigiEdit" (or whatever you want it to be called, it doesn't really matter)
- For "EntryPoint", enter "kawigi.KawigiEdit" (this one does matter).
- For "ClassPath", hit "Browse" and find the KawigiEdit jar. You should not have a previous version of KawigiEdit in the global classpath (in the text field on the top of the Editor Preferences Dialog).
- Once those are entered in correctly, click OK.
- If you want KawigiEdit to be used as your default editor, check the "Default" box next to the new entry in the table. I recommend setting it as your default editor, of course.
- Click "Save". If you get errors here, make sure that you are absolutely using Java 1.5, and that no previous version of KawigiEdit is in the classpath, and if that's all in order and you're still having problems, contact me personally or see if you can find anyone in the arena who knows a lot KawigiEdit.
Now KawigiEdit will be ready to use! Of course, to get the most out of KawigiEdit, you will probably want to tweak the configuration.
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".
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" wherever 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. You can also configure here how long KawigiEdit should wait to attempt to forcibly terminate a process it starts.
Here, you can change the font and colors of the testing console panel. This is where the output from your programs and from the compiler will be displayed when you use the local compile and test features.
You can use this section to customize how often the problem timer updates, what colors it uses, and even turn the darn thing off. Rest assured that if you turn it off (even if you turn it off with the editor running), it will be removed and the thread it was running on will be killed, so you don't have to worry about it consuming any CPU time. If you like it but are worried about CPU time, just lengthen the update delay.
Here, you can change the font and colors used in the editor and local code display. This includes syntax-related coloring, like:
- Keywords : if, class, public, etc.
- Types : float, int, boolean, decimal, etc. Also used for constant values like null, true and false.
- Operators : +, -, *, /, sizeof, instanceof, typeof, etc.
- Strings/Characters : "In this format, or like" 'x'
- Comments: /*like this */ //or like this 'or in VB, like this!
- Compiler Directives: #include, #define, #region, etc.
- Standard library classes: vector (C++), StringTokenizer (java), etc.
- Template tags: specifically for when you're editing your template in my template editor.
You can also turn on or off parentheses (, etc.) matching and specify what color the highlights should be (I recommend a color that is not too much different from your background color) and set your tab width.
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). You can also use the Template Override field to pick a .ket file to use as a template for each language.
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 csc and vbc in your system path, or *nix with mono installed and in the system path.
The rule of thumb on these settings is that you should try them out, and if they work, don't mess with them. KawigiEdit has been made to work with probably half a dozen C++ compilers before, so if you're wondering if it can work with yours, the answer is probably yes.
This is the place to edit your code templates, which are parsed and expanded when you open a problem or hit "Generate Code".
The easiest way to get started is to click on "Open Default", and pick which template (.ket file) you want to edit. Change anything you want, and click save (or save as) and you'll be prompted where to save it. After saving, KawigiEdit will ask you if you want to set it as the default template for some language, and if you click yes, you're done! The Template Override should be filled in for that language on the Languages tab.
Using KawigiEdit - A Walkthrough
Here is a quick example of how to use KawigiEdit in the Arena.
- Log on to the applet and go to practice room 152 (SRM 191 Division 1).
- Skeleton and testing code should have been automatically generated in your language of choice by KawigiEdit. If you would like to use a different language, choose it at the top of the window and then press "Generate code".
- You should also notice that KawigiEdit inserted a "KawigiEdit tag" that looks like <%:testing-code%>. When you save your code locally, the testing code will be inserted at that point. When you submit your code to TopCoder, that tag is removed. If you ever reopen a problem (and previous code you sent to TopCoder is restored from the server), you will have to reinsert that tag.
- This problem involves parsing comma-delimited lists of integers from the given strings. Write a function called "splitInts" that returns an array/vector of integers and takes a string argument and tokenizes the string into the numbers. An example of a Java implementation might be:
int splitInts(String s)
String split = s.split("[ ,]+");
int ret = new int[split.length];
for (int i=0; i<ret.length; i++)
ret[i] = Integer.parseInt(split[i]);
- Now select the method you wrote. You can do this by dragging in the code pane, or by clicking and dragging on the line numbers.
- Right click on the code pane with the method selected, and go to "Add Snippet". A dialog should appear with two text fields and a couple buttons. The method name ("splitInts") should have appeared as the suggested Snippet name.
- Enter a category (Such as "string" or "string/parse" - use a '/' to denote "folders" in your categories) and hit enter or click on the "Add Snippet" button.
- Deselect your method. If you successfully added that method as a snippet, you should be able to right click on the code pane now and find it in the "Snippet" submenu. Try clicking on it. You'll notice that it pastes that code wherever your cursor was. These snippets are saved on your hard drive, so that they will be available to you later when you don't have time to type nice functions during the SRM.
- Hit ctrl+F and ctrl+H and try playing with the search and replace options. There's a lot of power in the Regular Expression option - For more information, go to the API documentation at http://java.sun.com/ and read the specification on java.util.regex.Pattern. Back-references may be used in the replacement using $1, $2, etc. Back-references may even be usable in the pattern using \1, \2, etc.
- Type a few things, and then hit ctrl+z a few times. It should undo your edits one thing at a time. Then try pushing ctrl+y - this should redo any undone edits.
- Now that you've messed around with it a bit, write the code in the correctVolume method. My Java version looks like this:
public int correctVolume(String queries, int numberOfBoxes, int ithBox)
int ret = 0;
for (int i=0; i<queries.length; i++)
int info = splitInts(queries[i]);
if (info == ithBox || info == ithBox)
ret = Math.max(ret, info);
- Once you're done typing it in, click on "Run Tests", or hit Alt+R. This should save the code to the local directory you have configured, compile it and run it. It will also automatically switch control over to the "Output" tab. If the Output tab displays something like My error: java.io.IOException: CreateProcess: <some kind of command> error=2, then either your run or compile command is not configured correctly. It could mean that your compiler isn't in the path or isn't in the place that it's configured to be. Go back to the settings dialog and see if you can figure it out. You may have also gotten compiler errors into the Compile console. Fix them! Otherwise, you got a series of test results. If it tells you you're a stud, and you think you don't have any other hidden bugs, go ahead and click compile and submit on the applet (I made it a habit to click on TopCoder's "compile" and my "Run Tests" at the same time so I don't forget to do it).
- Also take a look at the Test Code tab. This code is the code that is inserted into your source code wherever <%:testing-code%> is found.
- After submitting your code, close the problem and open it again. If you click on "Run Tests" again, you will probably get an error that there is no main method. Move your cursor to the place where the testing code should be generated (should be after the solution class in C++ or VB, or in the solution class in Java or C#), and reinsert the testing code tag. You can do this by either typing <%:testing-code%>, right clicking and selecting "Test Code Tag", or hitting ctrl+I. If you already had code or lost that tag somehow, you can move your cursor to some place where the testing code could go and type it in, or hit Ctrl+E, or right click and select "Test Code Tag". This code is omitted when your code is submitted to TopCoder.
I included the source to KawigiEdit for a reason - I think that it's a good place to learn things from (both in design and in using the plugin interface), 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 the settings 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 rename it to KawigiEdit.zip and extract it with any program that can extract zip files.
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, a resource folder, 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.
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.