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 System
.out
.println("startUsing");
52 Runnable task
= new Runnable()
59 if (SwingUtilities
.isEventDispatchThread())
65 SwingUtilities
.invokeLater(task
);
69 public void stopUsing()
71 System
.out
.println("stopUsing");
75 public JPanel
getEditorPanel()
77 System
.out
.println("getEditorPanel");
81 public String
getSource() throws Exception
83 System
.out
.println("getSource");
86 String source
= editor
.getSource();
87 logInfo("Source code uploaded to server.");
90 catch (Exception exception
)
92 logError("Failed to get source code: " + exception
.getLocalizedMessage());
97 public void setSource(String source
)
99 System
.out
.println("setSource: " + source
);
102 editor
.setSource(source
);
103 logInfo("Source code downloaded from server.");
105 catch (Exception exception
)
107 logError("Failed to save the source given by the server: " + exception
.getLocalizedMessage());
112 public void setProblemComponent(ProblemComponentModel component
,
116 System
.out
.println("setProblemComponent");
119 editor
= new Editor(component
, language
, renderer
);
121 catch (Exception exception
)
123 logError("An error occured while loading the problem: " + exception
.getLocalizedMessage());
128 private void log(final String what
)
130 Runnable task
= new Runnable()
134 SimpleDateFormat format
= new SimpleDateFormat("kk:mm:ss");
135 logArea
.append(format
.format(new Date()) + ", " + what
);
138 if (SwingUtilities
.isEventDispatchThread())
144 SwingUtilities
.invokeLater(task
);
148 private void logInfo(String what
)
150 log(" INFO: " + what
+ System
.getProperty("line.separator"));
153 private void logWarning(String what
)
155 log(" WARN: " + what
+ System
.getProperty("line.separator"));
158 private void logError(String what
)
160 log("ERROR: " + what
+ System
.getProperty("line.separator"));
164 public static void main(String args
[])
166 VimCoder plugin
= new VimCoder();
168 JFrame frame
= new JFrame("VimCoder");
169 frame
.add(plugin
.getEditorPanel());
170 frame
.setSize(640, 480);
171 frame
.setVisible(true);
172 frame
.setDefaultCloseOperation(JFrame
.EXIT_ON_CLOSE
);