3
3
4
4
import javax .swing .*;
5
5
import java .awt .*;
6
+ import java .awt .event .ActionEvent ;
7
+ import java .awt .event .ActionListener ;
8
+ import java .beans .PropertyChangeListener ;
6
9
import java .io .*;
7
10
import java .text .SimpleDateFormat ;
8
11
import java .util .*;
9
12
import com .topcoder .client .contestant .ProblemComponentModel ;
10
13
import com .topcoder .shared .language .*;
11
14
import com .topcoder .shared .problem .*;
12
15
import com .topcoder .shared .problem .Renderer ;
16
+ import com .topcoder .client .contestApplet .common .Common ;
17
+ import com .topcoder .client .contestApplet .common .LocalPreferences ;
13
18
14
19
/**
15
20
* @author Charles McGarvey
@@ -31,6 +36,17 @@ public class VimCoder
31
36
public final static String website = "http://www.dogcows.com/vimcoder" ;
32
37
33
38
39
+ /**
40
+ * The first part of the command used to invoke the Vim server.
41
+ */
42
+ private static String vimCommand = "gvim" ;
43
+
44
+ /**
45
+ * The path to the main VimCoder directory.
46
+ */
47
+ private static File rootDir = new File ("~/.vimcoder" );
48
+
49
+
34
50
/**
35
51
* The panel given to the Arena applet when it is requested.
36
52
*/
@@ -45,6 +61,46 @@ public class VimCoder
45
61
* The current editor object (or null if there is none).
46
62
*/
47
63
private Editor editor ;
64
+
65
+ /**
66
+ * The configuration panel.
67
+ */
68
+ private JDialog configDialog ;
69
+
70
+
71
+ /**
72
+ * The key for the vim command preference.
73
+ */
74
+ private final static String VIMCOMMAND = "com.dogcows.VimCoder.config.vimcommand" ;
75
+
76
+ /**
77
+ * The key for the root directory preference.
78
+ */
79
+ private final static String ROOTDIR = "com.dogcows.VimCoder.config.rootdir" ;
80
+
81
+ /**
82
+ * The preferences object for storing plugin settings.
83
+ */
84
+ private static LocalPreferences prefs = LocalPreferences .getInstance ();
85
+
86
+
87
+ /**
88
+ * Get the command for invoking vim.
89
+ * @return The command.
90
+ */
91
+ public static String getVimCommand ()
92
+ {
93
+ return vimCommand ;
94
+ }
95
+
96
+ /**
97
+ * Get the storage directory.
98
+ * @return The directory.
99
+ */
100
+ public static File getStorageDirectory ()
101
+ {
102
+ return rootDir ;
103
+ }
48
104
49
105
50
106
/**
@@ -70,7 +126,6 @@ public VimCoder()
70
126
*/
71
127
public void startUsing ()
72
128
{
73
- System .out .println ("startUsing" );
74
129
Runnable task = new Runnable ()
75
130
{
76
131
public void run ()
@@ -86,14 +141,14 @@ public void run()
86
141
{
87
142
SwingUtilities .invokeLater (task );
88
143
}
144
+ loadConfiguration ();
89
145
}
90
146
91
147
/**
92
148
* Called by the Arena when the plugin is no longer needed.
93
149
*/
94
150
public void stopUsing ()
95
151
{
96
- System .out .println ("stopUsing" );
97
152
editor = null ;
98
153
}
99
154
@@ -104,7 +159,6 @@ public void stopUsing()
104
159
*/
105
160
public JPanel getEditorPanel ()
106
161
{
107
- System .out .println ("getEditorPanel" );
108
162
return panel ;
109
163
}
110
164
@@ -116,7 +170,6 @@ public JPanel getEditorPanel()
116
170
*/
117
171
public String getSource () throws Exception
118
172
{
119
- System .out .println ("getSource" );
120
173
try
121
174
{
122
175
String source = editor .getSource ();
@@ -137,7 +190,6 @@ public String getSource() throws Exception
137
190
*/
138
191
public void setSource (String source )
139
192
{
140
- System .out .println ("setSource: " + source );
141
193
try
142
194
{
143
195
editor .setSource (source );
@@ -161,7 +213,6 @@ public void setProblemComponent(ProblemComponentModel component,
161
213
Language language ,
162
214
Renderer renderer )
163
215
{
164
- System .out .println ("setProblemComponent" );
165
216
try
166
217
{
167
218
editor = new Editor (component , language , renderer );
@@ -172,6 +223,127 @@ public void setProblemComponent(ProblemComponentModel component,
172
223
exception .getLocalizedMessage ());
173
224
}
174
225
}
226
+
227
+ /**
228
+ * Called by the Arena when it's time to show our configuration panel.
229
+ */
230
+ public void configure ()
231
+ {
232
+ loadConfiguration ();
233
+
234
+ configDialog = new JDialog ();
235
+ Container pane = configDialog .getContentPane ();
236
+
237
+ pane .setPreferredSize (new Dimension (550 , 135 ));
238
+ pane .setLayout (new GridBagLayout ());
239
+ pane .setForeground (Common .FG_COLOR );
240
+ pane .setBackground (Common .WPB_COLOR );
241
+ GridBagConstraints c = new GridBagConstraints ();
242
+
243
+ JLabel vimCommandLabel = new JLabel ("Vim Command:" );
244
+ vimCommandLabel .setForeground (Common .FG_COLOR );
245
+ vimCommandLabel .setAlignmentX (1.0f );
246
+ c .fill = GridBagConstraints .HORIZONTAL ;
247
+ c .gridx = 0 ;
248
+ c .gridy = 0 ;
249
+ c .insets = new Insets (5 , 5 , 5 , 5 );
250
+ pane .add (vimCommandLabel , c );
251
+
252
+ final JTextField vimCommandField = new JTextField (vimCommand , 25 );
253
+ c .gridx = 1 ;
254
+ c .gridy = 0 ;
255
+ c .gridwidth = 3 ;
256
+ pane .add (vimCommandField , c );
257
+
258
+ JLabel rootDirLabel = new JLabel ("Storage Directory:" );
259
+ rootDirLabel .setForeground (Common .FG_COLOR );
260
+ c .gridx = 0 ;
261
+ c .gridy = 1 ;
262
+ c .gridwidth = 1 ;
263
+ pane .add (rootDirLabel , c );
264
+
265
+ final JTextField rootDirField = new JTextField (rootDir .getPath (), 25 );
266
+ c .gridx = 1 ;
267
+ c .gridy = 1 ;
268
+ c .gridwidth = 2 ;
269
+ pane .add (rootDirField , c );
270
+
271
+ JButton browseButton = new JButton ("Browse" );
272
+ c .fill = GridBagConstraints .NONE ;
273
+ c .gridx = 3 ;
274
+ c .gridy = 1 ;
275
+ c .gridwidth = 1 ;
276
+ c .anchor = GridBagConstraints .BASELINE_LEADING ;
277
+ pane .add (browseButton , c );
278
+
279
+ JButton closeButton = new JButton ("Close" );
280
+ c .fill = GridBagConstraints .HORIZONTAL ;
281
+ c .gridx = 1 ;
282
+ c .gridy = 2 ;
283
+ c .anchor = GridBagConstraints .PAGE_END ;
284
+ pane .add (closeButton , c );
285
+
286
+ JButton saveButton = new JButton ("Save" );
287
+ c .gridx = 2 ;
288
+ c .gridy = 2 ;
289
+ c .gridwidth = 2 ;
290
+ pane .add (saveButton , c );
291
+
292
+ browseButton .addActionListener (new ActionListener ()
293
+ {
294
+ public void actionPerformed (ActionEvent actionEvent )
295
+ {
296
+ JFileChooser chooser = new JFileChooser ();
297
+ chooser .setCurrentDirectory (new File ("." ));
298
+ chooser .setDialogTitle ("Choose Storage Directory" );
299
+ chooser .setFileSelectionMode (JFileChooser .DIRECTORIES_ONLY );
300
+ chooser .setAcceptAllFileFilterUsed (false );
301
+
302
+ if (chooser .showOpenDialog (configDialog ) == JFileChooser .APPROVE_OPTION )
303
+ {
304
+ rootDirField .setText (chooser .getSelectedFile ().getPath ());
305
+ }
306
+ }
307
+ });
308
+
309
+ closeButton .addActionListener (new ActionListener ()
310
+ {
311
+ public void actionPerformed (ActionEvent actionEvent )
312
+ {
313
+ configDialog .dispose ();
314
+ }
315
+ });
316
+
317
+ saveButton .addActionListener (new ActionListener ()
318
+ {
319
+ public void actionPerformed (ActionEvent actionEvent )
320
+ {
321
+ prefs .setProperty (VIMCOMMAND , vimCommandField .getText ());
322
+ prefs .setProperty (ROOTDIR , rootDirField .getText ());
323
+ configDialog .dispose ();
324
+ }
325
+ });
326
+
327
+ configDialog .setTitle ("VimCoder Preferences" );
328
+ configDialog .pack ();
329
+ configDialog .setLocationByPlatform (true );
330
+ configDialog .setModalityType (Dialog .DEFAULT_MODALITY_TYPE );
331
+ configDialog .setDefaultCloseOperation (WindowConstants .DISPOSE_ON_CLOSE );
332
+ configDialog .setVisible (true );
333
+ }
334
+
335
+
336
+ /**
337
+ * Load the local preferences related to this plugin.
338
+ */
339
+ private void loadConfiguration ()
340
+ {
341
+ String vc = prefs .getProperty (VIMCOMMAND );
342
+ if (vc != null ) vimCommand = vc ;
343
+
344
+ String dir = prefs .getProperty (ROOTDIR );
345
+ if (dir != null ) rootDir = new File (dir );
346
+ }
175
347
176
348
177
349
/**
0 commit comments