]> Dogcows Code - chaz/vimcoder/blob - src/com/dogcows/VimCoder.java
improved C++ driver template
[chaz/vimcoder] / src / com / dogcows / VimCoder.java
1
2 package com.dogcows;
3
4 import javax.swing.*;
5 import java.awt.*;
6 import java.io.*;
7 import java.text.SimpleDateFormat;
8 import java.util.*;
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;
13
14 /**
15 * @author Charles McGarvey
16 * The TopCoder Arena editor plug-in providing support for Vim.
17 *
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.
20 */
21 public class VimCoder
22 {
23 /**
24 *
25 */
26 public final static String version = "VimCoder 0.1";
27 public final static String website = "http://www.dogcows.com/vimcoder";
28
29 private JPanel panel;
30 private JTextArea logArea;
31
32 private Editor editor;
33
34
35 public VimCoder()
36 {
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);
43
44 panel = new JPanel(new BorderLayout());
45 panel.add(new JScrollPane(logArea), BorderLayout.CENTER);
46 }
47
48
49 public void startUsing()
50 {
51 System.out.println("startUsing");
52 Runnable task = new Runnable()
53 {
54 public void run()
55 {
56 logArea.setText("");
57 }
58 };
59 if (SwingUtilities.isEventDispatchThread())
60 {
61 task.run();
62 }
63 else
64 {
65 SwingUtilities.invokeLater(task);
66 }
67 }
68
69 public void stopUsing()
70 {
71 System.out.println("stopUsing");
72 editor = null;
73 }
74
75 public JPanel getEditorPanel()
76 {
77 System.out.println("getEditorPanel");
78 return panel;
79 }
80
81 public String getSource() throws Exception
82 {
83 System.out.println("getSource");
84 try
85 {
86 String source = editor.getSource();
87 logInfo("Source code uploaded to server.");
88 return source;
89 }
90 catch (Exception exception)
91 {
92 logError("Failed to get source code: " + exception.getLocalizedMessage());
93 throw exception;
94 }
95 }
96
97 public void setSource(String source)
98 {
99 System.out.println("setSource: " + source);
100 try
101 {
102 editor.setSource(source);
103 logInfo("Source code downloaded from server.");
104 }
105 catch (Exception exception)
106 {
107 logError("Failed to save the source given by the server: " + exception.getLocalizedMessage());
108 return;
109 }
110 }
111
112 public void setProblemComponent(ProblemComponentModel component,
113 Language language,
114 Renderer renderer)
115 {
116 System.out.println("setProblemComponent");
117 try
118 {
119 editor = new Editor(component, language, renderer);
120 }
121 catch (Exception exception)
122 {
123 logError("An error occured while loading the problem: " + exception.getLocalizedMessage());
124 }
125 }
126
127
128 private void log(final String what)
129 {
130 Runnable task = new Runnable()
131 {
132 public void run()
133 {
134 SimpleDateFormat format = new SimpleDateFormat("kk:mm:ss");
135 logArea.append(format.format(new Date()) + ", " + what);
136 }
137 };
138 if (SwingUtilities.isEventDispatchThread())
139 {
140 task.run();
141 }
142 else
143 {
144 SwingUtilities.invokeLater(task);
145 }
146 }
147
148 private void logInfo(String what)
149 {
150 log(" INFO: " + what + System.getProperty("line.separator"));
151 }
152
153 private void logWarning(String what)
154 {
155 log(" WARN: " + what + System.getProperty("line.separator"));
156 }
157
158 private void logError(String what)
159 {
160 log("ERROR: " + what + System.getProperty("line.separator"));
161 }
162
163
164 public static void main(String args[])
165 {
166 VimCoder plugin = new VimCoder();
167
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);
173
174 plugin.startUsing();
175 }
176 }
177
This page took 0.038593 seconds and 4 git commands to generate.