+ /**
+ * Called by the Arena when it's time to show our configuration panel.
+ */
+ public void configure()
+ {
+ final int border = 10;
+ final int inset = 2;
+
+ loadConfiguration();
+
+ configDialog = new JDialog();
+ 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)));
+
+ GridBagConstraints c = new GridBagConstraints();
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.insets = new Insets(inset, inset, inset, inset);
+
+ JLabel rootDirLabel = new JLabel("Storage Directory:");
+ rootDirLabel.setForeground(Common.FG_COLOR);
+ c.gridx = 0;
+ c.gridy = 0;
+ c.gridwidth = 1;
+ fieldPanel.add(rootDirLabel, c);
+
+ final JTextField rootDirField = new JTextField(rootDir.getPath());
+ rootDirField.setPreferredSize(new Dimension(0, 24));
+ c.gridx = 1;
+ c.gridy = 0;
+ 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;
+ 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:");
+ vimCommandLabel.setForeground(Common.FG_COLOR);
+ c.gridx = 0;
+ c.gridy = 2;
+ c.gridwidth = 1;
+ fieldPanel.add(vimCommandLabel, c);
+
+ final JTextField vimCommandField = new JTextField(vimCommand);
+ vimCommandField.setPreferredSize(new Dimension(0, 24));
+ c.gridx = 1;
+ c.gridy = 2;
+ c.weightx = 1.0;
+ c.gridwidth = 2;
+ fieldPanel.add(vimCommandField, 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");
+ buttonPanel.add(saveButton);
+ buttonPanel.add(Box.createRigidArea(new Dimension(1, 0)));
+
+ JButton closeButton = new JButton("Close");
+ buttonPanel.add(closeButton);
+
+ browseButton.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent actionEvent)
+ {
+ JFileChooser chooser = new JFileChooser();
+ chooser.setCurrentDirectory(new File("."));
+ chooser.setDialogTitle("Choose Storage Directory");
+ chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
+ chooser.setAcceptAllFileFilterUsed(false);
+
+ if (chooser.showOpenDialog(configDialog) == JFileChooser.APPROVE_OPTION)
+ {
+ rootDirField.setText(chooser.getSelectedFile().getPath());
+ }
+ }
+ });
+
+ closeButton.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent actionEvent)
+ {
+ configDialog.dispose();
+ }
+ });
+
+ saveButton.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent actionEvent)
+ {
+ prefs.setProperty(VIMCOMMAND, vimCommandField.getText());
+ prefs.setProperty(ROOTDIR, rootDirField.getText());
+ prefs.setProperty(CONTESTDIRNAMES, String.valueOf(contestDirNamesButton.isSelected()));
+ JOptionPane.showMessageDialog(null, "Preferences were saved successfully.");
+ }
+ });
+
+ configDialog.setTitle("VimCoder Preferences");
+ configDialog.pack();
+ configDialog.setLocationRelativeTo(null); // Center dialog in screen.
+ configDialog.setModalityType(Dialog.DEFAULT_MODALITY_TYPE);
+ configDialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
+ configDialog.setVisible(true);
+ }
+
+
+ /**
+ * Load the local preferences related to this plugin.
+ */
+ private void loadConfiguration()
+ {
+ String vc = prefs.getProperty(VIMCOMMAND);
+ if (vc != null) vimCommand = vc;
+
+ String dir = prefs.getProperty(ROOTDIR);
+ if (dir != null) rootDir = new File(dir);
+
+ String cn = prefs.getProperty(CONTESTDIRNAMES);
+ if (cn != null) contestDirNames = Boolean.parseBoolean(cn);
+ }
+
+
+ /**
+ * A generic logging function, appends text to the text area. A timestamp
+ * is also prepended to the next text.
+ * @param what The text to append.
+ */