Пример #1
0
    public void actionPerformed(ActionEvent evt) {
      Object source = evt.getSource();

      if (source == add) {
        ToolBarEditDialog dialog = new ToolBarEditDialog(ToolBarOptionPane.this, iconList, null);
        Button selection = dialog.getSelection();
        if (selection == null) return;

        int index = list.getSelectedIndex();
        if (index == -1) index = listModel.getSize();
        else index++;

        listModel.insertElementAt(selection, index);
        list.setSelectedIndex(index);
        list.ensureIndexIsVisible(index);
      } else if (source == remove) {
        int index = list.getSelectedIndex();
        listModel.removeElementAt(index);
        if (listModel.getSize() != 0) {
          if (listModel.getSize() == index) list.setSelectedIndex(index - 1);
          else list.setSelectedIndex(index);
        }
        updateButtons();
      } else if (source == moveUp) {
        int index = list.getSelectedIndex();
        Object selected = list.getSelectedValue();
        listModel.removeElementAt(index);
        listModel.insertElementAt(selected, index - 1);
        list.setSelectedIndex(index - 1);
        list.ensureIndexIsVisible(index - 1);
      } else if (source == moveDown) {
        int index = list.getSelectedIndex();
        Object selected = list.getSelectedValue();
        listModel.removeElementAt(index);
        listModel.insertElementAt(selected, index + 1);
        list.setSelectedIndex(index + 1);
        list.ensureIndexIsVisible(index + 1);
      } else if (source == edit) {
        ToolBarEditDialog dialog =
            new ToolBarEditDialog(
                ToolBarOptionPane.this, iconList, (Button) list.getSelectedValue());
        Button selection = dialog.getSelection();
        if (selection == null) return;

        int index = list.getSelectedIndex();

        listModel.setElementAt(selection, index);
        list.setSelectedIndex(index);
        list.ensureIndexIsVisible(index);
      }
    }
Пример #2
0
    public void actionPerformed(ActionEvent evt) {
      Object source = evt.getSource();
      if (source instanceof JRadioButton) updateEnabled();
      if (source == ok) ok();
      else if (source == cancel) cancel();
      else if (source == combo) updateList();
      else if (source == fileButton) {
        String directory;
        if (fileIcon == null) directory = null;
        else directory = MiscUtilities.getParentOfPath(fileIcon);
        String paths[] =
            GUIUtilities.showVFSFileDialog(null, directory, VFSBrowser.OPEN_DIALOG, false);
        if (paths == null) return;

        fileIcon = "file:" + paths[0];

        try {
          fileButton.setIcon(new ImageIcon(new URL(fileIcon)));
        } catch (MalformedURLException mf) {
          Log.log(Log.ERROR, this, mf);
        }
        fileButton.setText(MiscUtilities.getFileName(fileIcon));
      }
    }