kawigi
Class KawigiEdit

java.lang.Object
  extended by kawigi.KawigiEdit

public class KawigiEdit
extends java.lang.Object

This class is the actual TopCoder arena plugin. When KawigiEdit is run as a plugin, this is where everything basically starts.

Kawigi's Discourse on KawigiEdit's Source Code

You'll notice that most of KawigiEdit's source code files don't know anything about TopCoder classes (this one is necessarily an exception, since the plugin interface needs to pass me TopCoder-defined objects). This is to make it so that KawigiEdit can be run as a standalone application without ContestApplet.jar needing to be in the classpath. The classes that do still reference TopCoder classes directly are currently: Aside from classes that have to decide whether to use those classes or standalone classes, the only thing that currently requires the code to check which mode we're in is the action for the Generate Code button, which does something completely different in standalone mode than in plugin mode. In general, where possible, any additions made to KawigiEdit should try to conform to that convention where a class is either strictly specific to plugin mode or doesn't reference TC classes directly. An interface/factory pattern is an easy way to do this in most cases. I'm assuming that people wanting to modify KawigiEdit will start by looking at this file. There isn't much here in the way of juicy code, but that does make it an opportune place to describe the general organization of the code and make suggestions on how to modify it if you so desire. Note that the HTML will be more readable if you look at the javadocs that should have been in the jar with any official release of KawigiEdit. First, here's a rundown of what's in each package. For those of you who are less initiated in Java, a package is basically a folder full of classes. In KawigiEdit, the source files are found in those folders along with the class files. The kawigi package is found in the kawigi folder, and the kawigi.cmd package is found in the kawigi/cmd folder. Also, the source code for each public class is always in a source code file of the same name, so the source code for kawigi.cmd.ActID is in kawigi\cmd\ActID.java. Next, it might be useful to understand the resources included with and used by KawigiEdit. Aside from a bunch of icons and images (that are mostly referenced in ActID.java, although some aren't used), there are four .words files directly in the rc folder, one for each language. These are text files that contain keywords and tokens and how the Views should highlight them. Then there's a folder called rc/templates which contains the default template for each language. There's no reason to change these directly, since you can set it to use a modified version of the template using the KawigiEdit settings dialog. If you think one of the templates should be modified for everyone, let me know. Finally, there's a folder called rc/ui which has a bunch of .ui files in it. The .ui files are XML representations of GUI hierarchies, and each one is loaded for different reasons (kawigi/cmd/MenuID.java will give you some idea of what each one is for). If you want to change the organization of the UI in KawigiEdit, you can edit these directly, or alternatively, you can write your own version and save it somewhere, then change your config file (contestapplet.conf for KawigiEdit as a plugin, or KawigiEdit.properties in standalone mode) to set a property called kawigi.ui.[a name from MenuID.java] to be the path to your version of the .ui file. Perhaps I'll someday make a way to easily add commands to KawigiEdit without modifying KawigiEdit at all. While I don't mind people hacking up KawigiEdit to their liking, it makes it hard for people to upgrade to a new version, so consider that if you want to make private modifications to the source code and try to make it as easy as possible to re-modify the KawigiEdit sources you touched. For now, the best way to add commands to KawigiEdit is basically like this:
  1. Create a class (perhaps in your own package) that extends kawigi.cmd.DefaultAction. The constructor of your action should take an ActID as a parameter if it's a global action or an ActID and CodePane as parameters if it's an editing action.
  2. Edit ActID.java and add elements to that enum for any commands you want to make. You can use the existing commands as a pattern, and you want to use your own action class as the class for your commands. You may need to use a fully qualified classname for it to be found (i.e. package.classname.class).
  3. Implement what should happen when your command is executed in the actionPerformed method of your action class. You may also want to customize the behavior of isEnabled or isVisible (note that isVisible won't work on many control types) and the getProperty and putProperty methods for overriding other properties.
  4. If you want to access your commands by keystrokes, you'll have to modify kawigi.editor.KawigiEditKeyMap to recognize those keystrokes.
  5. If you want your commands to be accessed by buttons or context menu items, follow the instructions above to customize .ui files. You may want to make a copy of the existing .ui file to use as a starting point. Feel free to use other .ui files as examples as well. If you want to make a whole new dialog or window or menu or something, you may have to add an entry to MenuID.java (although you can decide whether to add a .ui file to rc/ui or not - I think if you have the ui customized in the config files, it doesn't really matter if the resource file exists. Then you'll have to write the code to make that UI show up at the right time.
Consider that you may not actually need to write code to customize KawigiEdit to your liking - for instance, if all you want to do is add a button to the main KawigiEdit UI that inserts your tokenizer, you could just customize Plugin.ui to include a Snippet item there and hardcode your tokenizer code (with appropriate XML escape sequences) into your version of Plugin.ui. If you want to add some kind of post-processing to your code before saving it locally, you probably need to modify kawigi.cmd.LocalTestAction.saveLocal(). I'm fairly certain that someday there will be something which allows you to do this without modifying KawigiEdit, I'm just not exactly sure what it will look like. On the other hand, if you want to add some kind of post-processing to your code before submitting it to TopCoder, you should modify kawigi.KawigiEdit.getSource(). Again, it's pretty likely that this will be specifically addressed in some way in a future version of KawigiEdit.


Constructor Summary
KawigiEdit()
          KawigiEdit plugin constructor - sets the AppEnvironment to PluginMode.
 
Method Summary
 void clear()
          Empties the text pane.
 void configure()
          Brings up a configure dialog to set options in the editor plugin.
 javax.swing.JPanel getEditorPanel()
          Returns the magic KawigiEdit panel.
 java.lang.String getSource()
          Returns the text in the editor.
 void install()
          Verifies or sets several properties used by parts of the editor to set up.
 void setName(java.lang.String n)
          Sets the name given to this plugin.
 void setProblemComponent(com.topcoder.client.contestant.ProblemComponentModel component, com.topcoder.shared.language.Language lang, com.topcoder.shared.problem.Renderer renderer)
          Notifies the editor of a new problem being opened, or the language being changed, or whatever.
 void setSource(java.lang.String source)
          Sets the text in the editor.
 void setTextEnabled(java.lang.Boolean b)
          Enables/disables the text pane.
 void startUsing()
          Clears the text pane for a new problem.
 void stopUsing()
          Doesn't do anything.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KawigiEdit

public KawigiEdit()
KawigiEdit plugin constructor - sets the AppEnvironment to PluginMode.

Method Detail

getEditorPanel

public javax.swing.JPanel getEditorPanel()
Returns the magic KawigiEdit panel. From the TopCoder plugin interface.


getSource

public java.lang.String getSource()
Returns the text in the editor. This is the text that TopCoder thinks is in the editor - what it saves remotely, compiles, tests and submits. This is the code that can't break the UCR ;-) From the TopCoder plugin interface.


setSource

public void setSource(java.lang.String source)
Sets the text in the editor. This implementation will ignore the request if the source provided is empty. This is to maintain auto-generated code. Note that if you get code from TC and you want to keep it but use it for testing, you'll have to stick a <%:testing-code%> tag in there wherever the main method/testing code should be. From the TopCoder plugin interface.


clear

public void clear()
Empties the text pane. From the TopCoder plugin interface.


setTextEnabled

public void setTextEnabled(java.lang.Boolean b)
Enables/disables the text pane. I've considered ignoring this request, I think TC just started actually calling it, but it doesn't get called consistently (like it might not be called if you close and reopen the problem). From the TopCoder plugin interface.


setProblemComponent

public void setProblemComponent(com.topcoder.client.contestant.ProblemComponentModel component,
                                com.topcoder.shared.language.Language lang,
                                com.topcoder.shared.problem.Renderer renderer)
Notifies the editor of a new problem being opened, or the language being changed, or whatever. If the editor is empty, we will generate skeleton code. From the TopCoder plugin interface.


startUsing

public void startUsing()
Clears the text pane for a new problem. From the TopCoder plugin interface.


stopUsing

public void stopUsing()
Doesn't do anything. From the TopCoder plugin interface.


configure

public void configure()
Brings up a configure dialog to set options in the editor plugin. From the TopCoder plugin interface.


install

public void install()
Verifies or sets several properties used by parts of the editor to set up. For awhile, I was using this, but all the code pretty much checks to make sure I have all my configurations intact. I may start using this again very soon to offer an optional wizard-like initial configuration. From the TopCoder plugin interface.


setName

public void setName(java.lang.String n)
Sets the name given to this plugin. From the TopCoder plugin interface.