]> Dogcows Code - chaz/vimcoder/blobdiff - src/com/dogcows/VimCoder.java
do not add editor name to the end of a submission
[chaz/vimcoder] / src / com / dogcows / VimCoder.java
index 21374bb0877c8d9e29edb52d5e59e1a6db8c5c7c..d094394f2a0dbe41cdb9bc3f220319df38397de8 100644 (file)
@@ -2,12 +2,12 @@
 package com.dogcows;
 
 import java.awt.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
+import java.awt.event.*;
 import java.io.*;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import javax.swing.*;
+import javax.swing.border.*;
 
 import com.topcoder.client.contestApplet.common.Common;
 import com.topcoder.client.contestApplet.common.LocalPreferences;
@@ -27,23 +27,18 @@ public class VimCoder
        /**
         * The name and version of this plugin.
         */
-       public final static String      version = "VimCoder 0.3";
-
-       /**
-        * The website of the plugin project.
-        */
-       public final static String      website = "http://www.dogcows.com/vimcoder";
+       public final static String version = "VimCoder 0.3.5";
 
 
        /**
         * The first part of the command used to invoke the Vim server.
         */
-       private static String           vimCommand = "gvim";
+       private static String vimCommand = "gvim";
 
        /**
         * The path to the main VimCoder directory.
         */
-       private static File                     rootDir;
+       private static File rootDir;
        static
        {
                if (System.getProperty("os.name").toLowerCase().equals("win"))
@@ -51,29 +46,35 @@ public class VimCoder
                        vimCommand = "C:\\WINDOWS\\gvim.bat";
                }
                rootDir = new File(System.getProperty("user.home") +
-                                                  System.getProperty("file.separator") + ".vimcoder");
+                                  System.getProperty("file.separator") + ".vimcoder");
        }
 
+       /**
+        * Whether or not to use the contest name and point value as problem
+        * directory names.
+        */
+       private static boolean contestDirNames = false;
+
 
        /**
         * The panel given to the Arena applet when it is requested.
         */
-       private JPanel          panel;
+       private JPanel panel;
 
        /**
         * The text widget where log messages are appended.
         */
-       private JTextArea       logArea;
+       private JTextArea logArea;
 
        /**
         * The current editor object (or null if there is none).
         */
-       private Editor          editor;
+       private Editor editor;
 
        /**
         * The configuration panel.
         */
-       private JDialog         configDialog;
+       private JDialog configDialog;
 
 
        /**
@@ -86,6 +87,11 @@ public class VimCoder
         */
        private final static String ROOTDIR = "com.dogcows.VimCoder.config.rootdir";
 
+       /**
+        * The key for the problem directory name preference.
+        */
+       private final static String CONTESTDIRNAMES = "com.dogcows.VimCoder.config.contestdirnames";
+
        /**
         * The preferences object for storing plugin settings.
         */
@@ -110,6 +116,16 @@ public class VimCoder
                return rootDir;
        }
 
+       /**
+        * Get whether or not to save problems in a human-readable directory
+        * structure.
+        * @return The directory name setting.
+        */
+       public static boolean isContestDirNames()
+       {
+               return contestDirNames;
+       }
+
 
        /**
         * Instantiate the entry point of the editor plugin.
@@ -186,8 +202,7 @@ public class VimCoder
                }
                catch (Exception exception)
                {
-                       logError("Failed to get source code: " +
-                                        exception.getLocalizedMessage());
+                       logError("Failed to get source code: " + exception.getLocalizedMessage());
                        throw exception;
                }
        }
@@ -206,7 +221,7 @@ public class VimCoder
                catch (Exception exception)
                {
                        logError("Failed to save the source given by the server: " +
-                                        exception.getLocalizedMessage());
+                                exception.getLocalizedMessage());
                        return;
                }
        }
@@ -220,8 +235,7 @@ public class VimCoder
         * statement.
         */
        public void setProblemComponent(ProblemComponentModel component,
-                                                                       Language language,
-                                                                       Renderer renderer)
+                                       Language language, Renderer renderer)
        {
                try
                {
@@ -230,7 +244,7 @@ public class VimCoder
                catch (Exception exception)
                {
                        logError("An error occured while loading the problem: " +
-                                        exception.getLocalizedMessage());
+                                exception.getLocalizedMessage());
                }
        }
 
@@ -239,65 +253,89 @@ public class VimCoder
         */
        public void configure()
        {
+               final int border = 10;
+               final int inset = 2;
+
                loadConfiguration();
 
                configDialog = new JDialog();
-               Container pane = configDialog.getContentPane();
+               Container container = configDialog.getContentPane();
+               container.setForeground(Common.FG_COLOR);
+               container.setBackground(Common.WPB_COLOR);
+
+               JPanel pane = new JPanel();
+               container.add(pane);
+
+               BoxLayout boxLayout = new BoxLayout(pane, BoxLayout.Y_AXIS);
+               pane.setLayout(boxLayout);
+               pane.setBorder(BorderFactory.createEmptyBorder(border, border, border, border));
+
+               JPanel fieldPanel = new JPanel(new GridBagLayout());
+               pane.add(fieldPanel);
+               pane.add(Box.createRigidArea(new Dimension(0, border)));
 
-               pane.setPreferredSize(new Dimension(550, 135));
-               pane.setLayout(new GridBagLayout());
-               pane.setForeground(Common.FG_COLOR);
-               pane.setBackground(Common.WPB_COLOR);
                GridBagConstraints c = new GridBagConstraints();
+               c.fill = GridBagConstraints.HORIZONTAL;
+               c.insets = new Insets(inset, inset, inset, inset);
 
-               JLabel rootDirLabel = new JLabel("Storage Directory:", SwingConstants.RIGHT);
+               JLabel rootDirLabel = new JLabel("Storage Directory:");
                rootDirLabel.setForeground(Common.FG_COLOR);
-               c.fill = GridBagConstraints.HORIZONTAL;
-               c.insets = new Insets(5, 5, 5, 5);
                c.gridx = 0;
                c.gridy = 0;
                c.gridwidth = 1;
-               pane.add(rootDirLabel, c);
+               fieldPanel.add(rootDirLabel, c);
 
-               final JTextField rootDirField = new JTextField(rootDir.getPath(), 25);
+               final JTextField rootDirField = new JTextField(rootDir.getPath());
+               rootDirField.setPreferredSize(new Dimension(0, 24));
                c.gridx = 1;
                c.gridy = 0;
-               pane.add(rootDirField, c);
+               c.weightx = 1.0;
+               fieldPanel.add(rootDirField, c);
 
                JButton browseButton = new JButton("Browse");
                c.gridx = 2;
                c.gridy = 0;
+               c.weightx = 0.0;
                c.anchor = GridBagConstraints.BASELINE_LEADING;
-               pane.add(browseButton, c);
+               fieldPanel.add(browseButton, c);
+
+               final JCheckBox contestDirNamesButton = new JCheckBox(
+                       "Store problems according to contest name and point value.",
+                       contestDirNames
+               );
+               contestDirNamesButton.setForeground(Common.FG_COLOR);
+               contestDirNamesButton.setBackground(Common.WPB_COLOR);
+               contestDirNamesButton.setFont(rootDirLabel.getFont());
+               c.gridx = 1;
+               c.gridy = 1;
+               c.gridwidth = 2;
+               fieldPanel.add(contestDirNamesButton, c);
 
-               JLabel vimCommandLabel = new JLabel("Vim Command:", SwingConstants.RIGHT);
+               JLabel vimCommandLabel = new JLabel("Vim Command:");
                vimCommandLabel.setForeground(Common.FG_COLOR);
-               c.fill = GridBagConstraints.HORIZONTAL;
                c.gridx = 0;
-               c.gridy = 1;
-               pane.add(vimCommandLabel, c);
+               c.gridy = 2;
+               c.gridwidth = 1;
+               fieldPanel.add(vimCommandLabel, c);
 
-               final JTextField vimCommandField = new JTextField(vimCommand, 25);
+               final JTextField vimCommandField = new JTextField(vimCommand);
+               vimCommandField.setPreferredSize(new Dimension(0, 24));
                c.gridx = 1;
-               c.gridy = 1;
+               c.gridy = 2;
+               c.weightx = 1.0;
                c.gridwidth = 2;
-               pane.add(vimCommandField, c);
+               fieldPanel.add(vimCommandField, c);
 
-               JButton closeButton = new JButton("Cancel");
-               c.fill = GridBagConstraints.NONE;
-               c.gridx = 1;
-               c.gridy = 2;
-               c.gridwidth = 1;
-               c.anchor = GridBagConstraints.EAST;
-               pane.add(closeButton, c);
+               JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING, inset, inset));
+               buttonPanel.setPreferredSize(new Dimension(400, 24 + 2 * inset));
+               pane.add(buttonPanel);
 
                JButton saveButton = new JButton("Save");
-               c.fill = GridBagConstraints.HORIZONTAL;
-               c.gridx = 2;
-               c.gridy = 2;
-               c.anchor = GridBagConstraints.EAST;
-               pane.add(saveButton, c);
-               configDialog.getRootPane().setDefaultButton(saveButton);
+               buttonPanel.add(saveButton);
+               buttonPanel.add(Box.createRigidArea(new Dimension(1, 0)));
+
+               JButton closeButton = new JButton("Close");
+               buttonPanel.add(closeButton);
 
                browseButton.addActionListener(new ActionListener()
                {
@@ -330,13 +368,14 @@ public class VimCoder
                        {
                                prefs.setProperty(VIMCOMMAND, vimCommandField.getText());
                                prefs.setProperty(ROOTDIR, rootDirField.getText());
-                               configDialog.dispose();
+                               prefs.setProperty(CONTESTDIRNAMES, String.valueOf(contestDirNamesButton.isSelected()));
+                               JOptionPane.showMessageDialog(null, "Preferences were saved successfully.");
                        }
                });
 
                configDialog.setTitle("VimCoder Preferences");
                configDialog.pack();
-               configDialog.setLocationByPlatform(true);
+               configDialog.setLocationRelativeTo(null);       // Center dialog in screen.
                configDialog.setModalityType(Dialog.DEFAULT_MODALITY_TYPE);
                configDialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
                configDialog.setVisible(true);
@@ -353,6 +392,9 @@ public class VimCoder
 
                String dir = prefs.getProperty(ROOTDIR);
                if (dir != null) rootDir = new File(dir);
+
+               String cn  = prefs.getProperty(CONTESTDIRNAMES);
+               if (cn != null) contestDirNames = Boolean.parseBoolean(cn);
        }
 
 
@@ -400,3 +442,4 @@ public class VimCoder
        }
 }
 
+// vim:noet:ts=8
This page took 0.030143 seconds and 4 git commands to generate.