kawigi
Class KawigiEdit

java.lang.Object
  |
  +--kawigi.KawigiEdit
All Implemented Interfaces:
java.awt.event.ActionListener, javax.swing.event.CaretListener, java.util.EventListener, java.awt.event.KeyListener, java.awt.event.MouseListener, javax.swing.event.UndoableEditListener

public class KawigiEdit
extends java.lang.Object
implements java.awt.event.ActionListener, javax.swing.event.CaretListener, java.awt.event.KeyListener, java.awt.event.MouseListener, javax.swing.event.UndoableEditListener

KawigiEdit - an open-source, fully-featured editor plugin for the Top Coder Arena. It was written by me for me, so don't be surprised if the features aren't in line with what you want. If you want something that's not here, talk to me, and either I will add it, or if I don't care, you can.


Field Summary
protected  kawigi.editor.NoWrapJTextPane currentPopupThing
           
protected  kawigi.editor.NoWrapJTextPane localCodePane
           
protected  javax.swing.JFileChooser localFileChooser
           
protected  javax.swing.JPanel mainPanel
           
protected  javax.swing.JPanel replacePanel
           
protected  javax.swing.JPanel snippetPanel
           
protected  javax.swing.JTabbedPane tabs
           
protected  javax.swing.JTextArea testingPane
           
protected  kawigi.editor.NoWrapJTextPane textArea
           
protected  javax.swing.JPanel varReplacePanel
           
 
Constructor Summary
KawigiEdit()
          Initializes KawigiEdit and checks to make sure certain settings are available.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Handles events of all the buttons, menus, and so forth.
 void caretUpdate(javax.swing.event.CaretEvent e)
          Listens for changes in caret position on the text pane.
 void clear()
          Empties the text pane.
protected  boolean compileLocal()
          Compiles the saved file locally.
 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 keyPressed(java.awt.event.KeyEvent e)
          Listens for Key events on the text pane.
 void keyReleased(java.awt.event.KeyEvent e)
          Listens for Key events on the text pane.
 void keyTyped(java.awt.event.KeyEvent e)
          Listens for Key events on the text pane.
static void main(java.lang.String[] args)
          Run the plugin as a standalone application.
 void mouseClicked(java.awt.event.MouseEvent e)
          Required by the MouseListener interface.
 void mouseEntered(java.awt.event.MouseEvent e)
          Required by the MouseListener interface.
 void mouseExited(java.awt.event.MouseEvent e)
          Required by the MouseListener interface.
 void mousePressed(java.awt.event.MouseEvent e)
          Listens to mouse events on the text pane, so it knows when to create the popup menu.
 void mouseReleased(java.awt.event.MouseEvent e)
          Listens to mouse events on the text pane, so it knows when to create the popup menu.
protected  void saveLocal()
          Saves the current file to disk in the configured local directory with the appropriate name.
protected  void saveSnippets()
          Saves the snippet database to disk in a file called "snippets.dat".
 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 or something.
 void stopUsing()
          Doesn't do anything.
 void undoableEditHappened(javax.swing.event.UndoableEditEvent e)
          Stores away edits so they can be undone later.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

textArea

protected kawigi.editor.NoWrapJTextPane textArea

localCodePane

protected kawigi.editor.NoWrapJTextPane localCodePane

currentPopupThing

protected kawigi.editor.NoWrapJTextPane currentPopupThing

testingPane

protected javax.swing.JTextArea testingPane

tabs

protected javax.swing.JTabbedPane tabs

mainPanel

protected javax.swing.JPanel mainPanel

snippetPanel

protected javax.swing.JPanel snippetPanel

replacePanel

protected javax.swing.JPanel replacePanel

varReplacePanel

protected javax.swing.JPanel varReplacePanel

localFileChooser

protected javax.swing.JFileChooser localFileChooser
Constructor Detail

KawigiEdit

public KawigiEdit()
Initializes KawigiEdit and checks to make sure certain settings are available.

Method Detail

saveSnippets

protected void saveSnippets()
Saves the snippet database to disk in a file called "snippets.dat".


actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Handles events of all the buttons, menus, and so forth.

Specified by:
actionPerformed in interface java.awt.event.ActionListener

saveLocal

protected void saveLocal()
                  throws java.io.IOException
Saves the current file to disk in the configured local directory with the appropriate name.

java.io.IOException

compileLocal

protected boolean compileLocal()
                        throws java.lang.Exception
Compiles the saved file locally.

java.lang.Exception

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. 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. 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. 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. This resets some of the state, including the undo manager. If the editor has no text yet, this method will also generate skeleton and test code for the problem. Eventually in the right language, even.


startUsing

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


stopUsing

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


keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Listens for Key events on the text pane. Specifically listens for ctrl+z and ctrl+y for undo and redo, respectively.

Specified by:
keyPressed in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Listens for Key events on the text pane. Specifically listens for ctrl+i to popup the snippet popup menu.

Specified by:
keyReleased in interface java.awt.event.KeyListener

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Listens for Key events on the text pane. This handles the auto-indent.

Specified by:
keyTyped in interface java.awt.event.KeyListener

caretUpdate

public void caretUpdate(javax.swing.event.CaretEvent e)
Listens for changes in caret position on the text pane. Updates the line number displayed on the bottom-right.

Specified by:
caretUpdate in interface javax.swing.event.CaretListener

configure

public void configure()
Brings up a configure dialog to set options in the editor plugin. If I were to pick just one thing to complain about in the plugin specification, it would be the description on how to do this. I found it completely vague, and after reading still wasn't sure what it was supposed to do. Originally, this method actually froze or something, or otherwise didn't work, until I made the configure dialog modal. On the side, we are encouraged to use TopCoder's preferences class, but it is completely undocumented and the package it is found in is not specified. So I hacked up an old program I wrote that reads a jar and uses the jar classes as well as reflection classes to chart the classes in the jar on a JTree, and looked for about half an hour for it. Anyways, someone should write a tutorial on using configure() or something. 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 the constructor pretty much checks to make I have all my configurations intact. From the TopCoder plugin interface.


undoableEditHappened

public void undoableEditHappened(javax.swing.event.UndoableEditEvent e)
Stores away edits so they can be undone later.

Specified by:
undoableEditHappened in interface javax.swing.event.UndoableEditListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Listens to mouse events on the text pane, so it knows when to create the popup menu.

Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Listens to mouse events on the text pane, so it knows when to create the popup menu.

Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Required by the MouseListener interface.

Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Required by the MouseListener interface.

Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Required by the MouseListener interface.

Specified by:
mouseExited in interface java.awt.event.MouseListener

main

public static void main(java.lang.String[] args)
Run the plugin as a standalone application. This is mostly for view debugging, since it won't do anything exciting, and many of the features won't completely work (because the plugin methods won't be called).