7 import java
.text
.SimpleDateFormat
;
9 import com
.topcoder
.client
.contestant
.ProblemComponentModel
;
10 import com
.topcoder
.shared
.language
.*;
11 import com
.topcoder
.shared
.problem
.*;
12 import com
.topcoder
.shared
.problem
.Renderer
;
15 * @author Charles McGarvey
16 * The TopCoder Arena editor plug-in providing support for Vim.
18 * Distributable under the terms and conditions of the 2-clause BSD license;
19 * see the file COPYING for a complete text of the license.
26 public final static String version
= "VimCoder 0.1";
27 public final static String website
= "http://www.dogcows.com/vimcoder";
30 private JTextArea logArea
;
32 private Editor editor
;
37 logArea
= new JTextArea();
38 logArea
.setForeground(Color
.GREEN
);
39 logArea
.setBackground(Color
.BLACK
);
40 logArea
.setEditable(false);
41 Font font
= new Font("Courier", Font
.PLAIN
, 12);
42 if (font
!= null) logArea
.setFont(font
);
44 panel
= new JPanel(new BorderLayout());
45 panel
.add(new JScrollPane(logArea
), BorderLayout
.CENTER
);
49 public void startUsing()
51 Runnable task
= new Runnable()
58 if (SwingUtilities
.isEventDispatchThread())
64 SwingUtilities
.invokeLater(task
);
68 public void stopUsing()
73 public JPanel
getEditorPanel()
78 public String
getSource() throws IOException
82 String source
= editor
.getSource();
83 logInfo("Source code uploaded to server.");
86 catch (IOException exception
)
88 logError("Failed to open source file for reading.");
93 public void setSource(String source
)
97 editor
.setSource(source
);
98 logInfo("Source code downloaded from server.");
100 catch (IOException exception
)
102 logError("Failed to save the source given by the server.");
107 public void setProblemComponent(ProblemComponentModel component
,
113 editor
= new Editor(component
, language
, renderer
);
115 catch (IOException exception
)
117 logError("An error occured while loading the problem.");
122 private void log(final String what
)
124 Runnable task
= new Runnable()
128 SimpleDateFormat format
= new SimpleDateFormat("kk:mm:ss");
129 logArea
.append(format
.format(new Date()) + ", " + what
);
132 if (SwingUtilities
.isEventDispatchThread())
138 SwingUtilities
.invokeLater(task
);
142 private void logInfo(String what
)
144 log(" INFO: " + what
+ "\n");
147 private void logWarning(String what
)
149 log(" WARN: " + what
+ "\n");
152 private void logError(String what
)
154 log("ERROR: " + what
+ "\n");
158 public static void main(String args
[])
160 VimCoder plugin
= new VimCoder();
162 JFrame frame
= new JFrame("VimCoder");
163 frame
.add(plugin
.getEditorPanel());
164 frame
.setSize(640, 480);
165 frame
.setVisible(true);
166 frame
.setDefaultCloseOperation(JFrame
.EXIT_ON_CLOSE
);