private JButton addButton(String name, Color color) {
   JButton button = new JButton(name);
   button.setBackground(color);
   // button.setIcon(makeIcon(color, 50, 20));
   button.setAction(setColorAction);
   add(button);
   return button;
 }
  @Override
  public ButtonPanel createButtonPanel() {
    ButtonPanel buttonPanel = new ButtonPanel();
    JButton okButton = new JButton();
    JButton cancelButton = new JButton();
    JButton helpButton = new JButton();
    okButton.setName(OK);
    cancelButton.setName(CANCEL);
    helpButton.setName(HELP);
    buttonPanel.addButton(okButton, ButtonPanel.AFFIRMATIVE_BUTTON);
    buttonPanel.addButton(cancelButton, ButtonPanel.CANCEL_BUTTON);
    buttonPanel.addButton(helpButton, ButtonPanel.HELP_BUTTON);

    okButton.setAction(
        new AbstractAction(UIDefaultsLookup.getString("OptionPane.okButtonText")) {
          public void actionPerformed(ActionEvent e) {
            setDialogResult(RESULT_AFFIRMED);
            setVisible(false);
            dispose();
          }
        });
    cancelButton.setAction(
        new AbstractAction(UIDefaultsLookup.getString("OptionPane.cancelButtonText")) {
          public void actionPerformed(ActionEvent e) {
            setDialogResult(RESULT_CANCELLED);
            setVisible(false);
            dispose();
          }
        });
    final ResourceBundle resourceBundle = ButtonResources.getResourceBundle(Locale.getDefault());
    helpButton.setAction(
        new AbstractAction(resourceBundle.getString("Button.help")) {
          public void actionPerformed(ActionEvent e) {
            // do something
          }
        });
    helpButton.setMnemonic(resourceBundle.getString("Button.help.mnemonic").charAt(0));

    setDefaultCancelAction(cancelButton.getAction());
    setDefaultAction(okButton.getAction());
    getRootPane().setDefaultButton(okButton);
    buttonPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    return buttonPanel;
  }
Beispiel #3
0
 public JButton createButton(Action a) {
   JButton b =
       new JButton() {
         public Dimension getMaximumSize() {
           int width = Short.MAX_VALUE;
           int height = super.getMaximumSize().height;
           return new Dimension(width, height);
         }
       };
   // setting the following client property informs the button to show
   // the action text as it's name. The default is to not show the
   // action text.
   b.putClientProperty("displayActionText", Boolean.TRUE);
   b.setAction(a);
   // b.setAlignmentX(JButton.CENTER_ALIGNMENT);
   return b;
 }
  private static JButton createButton(String accessibleName, Icon icon, Action action) {
    JButton button =
        new JButton() {
          boolean mouseOverButton = false;

          {
            enableEvents(AWTEvent.MOUSE_EVENT_MASK);
            addMouseListener(
                new MouseAdapter() {
                  @Override
                  public void mouseEntered(MouseEvent e) {
                    mouseOverButton = true;
                    repaint();
                  }

                  @Override
                  public void mouseExited(MouseEvent e) {
                    mouseOverButton = false;
                    repaint();
                  }
                });
          }

          @Override
          protected void paintComponent(Graphics g) {
            final Window window = SwingUtilities.windowForComponent(this);
            float alpha = window.isActive() && mouseOverButton ? 1f : 0.5f;
            final GraphicsConfig config = GraphicsUtil.paintWithAlpha(g, alpha);
            getIcon().paintIcon(this, g, 0, 0);
            config.restore();
          }
        };
    button.setFocusPainted(false);
    button.setFocusable(false);
    button.setOpaque(false);
    button.putClientProperty("paintActive", Boolean.TRUE);
    button.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, accessibleName);
    button.setBorder(JBUI.Borders.empty());
    button.setText(null);
    button.setAction(action);
    button.setIcon(icon);
    return button;
  }
 private void updateToggleButton(Action action, Icon icon) {
   myToggleButton.setAction(action);
   myToggleButton.setIcon(icon);
   myToggleButton.setText(null);
 }
  /** make menu bar a separate component */
  private void buildMenuToolBar() {
    // get property manager
    PrideInspectorContext context = (PrideInspectorContext) getDesktopContext();

    // create all the actions
    // file open action
    Icon openFileIcon = GUIUtilities.loadIcon(context.getProperty("open.file.icon.small"));
    String openFileDesc = context.getProperty("open.file.title");
    String openFileTooltip = context.getProperty("open.file.tooltip");
    PrideAction openFileAction = new OpenFileAction(openFileDesc, openFileIcon);

    // database open action
    Icon openDbIcon = GUIUtilities.loadIcon(context.getProperty("open.database.icon.small"));
    String openDbDesc = context.getProperty("open.database.title");
    String openDbTooltip = context.getProperty("open.database.tooltip");
    PrideAction openDbAction = new OpenDatabaseAction(openDbDesc, openDbIcon);

    // open reviewer
    Icon openReviewerIcon =
        GUIUtilities.loadIcon(context.getProperty("reviewer.download.icon.small"));
    String openReviewerDesc = context.getProperty("reviewer.download.title");
    String openReviewerTooltip = context.getProperty("reviewer.download.tooltip");
    PrideAction openReviewerAction = new OpenReviewAction(openReviewerDesc, openReviewerIcon);

    // close
    String closeDesc = context.getProperty("close.source.title");
    String closeAllDesc = context.getProperty("close.all.soruce.title");
    PrideAction closeAction = new CloseControllerAction(closeDesc, null);
    PrideAction closeAllAction = new CloseAllControllersAction(closeAllDesc, null);
    context.addPropertyChangeListenerToDataAccessMonitor((PropertyChangeListener) closeAction);
    context.addPropertyChangeListenerToDataAccessMonitor((PropertyChangeListener) closeAllAction);

    // try pride xml sample
    String openPrideXmlExampleDesc = context.getProperty("open.pride.xml.example.title");
    File prideXmlExampleFile =
        getExampleFiles(context.getProperty("pride.inspector.pride.example.file"));
    java.util.List<File> prideXmlFiles = new ArrayList<File>();
    if (prideXmlExampleFile != null) {
      prideXmlFiles.add(prideXmlExampleFile);
    }
    PrideAction openPrideXmlExampleAction =
        new OpenFileAction(openPrideXmlExampleDesc, null, prideXmlFiles);
    openPrideXmlExampleAction.setEnabled(
        prideXmlExampleFile != null && prideXmlExampleFile.exists());

    // try mzml sample
    String openMzMLExampleDesc = context.getProperty("open.mzml.example.title");
    File mzMLExampleFile =
        getExampleFiles(context.getProperty("pride.inspector.mzml.example.file"));
    java.util.List<File> mzMLFiles = new ArrayList<File>();
    if (mzMLExampleFile != null) {
      mzMLFiles.add(mzMLExampleFile);
    }
    PrideAction openMzMLExampleAction = new OpenFileAction(openMzMLExampleDesc, null, mzMLFiles);
    openMzMLExampleAction.setEnabled(mzMLExampleFile != null && mzMLExampleFile.exists());

    // help
    Icon helpIcon = GUIUtilities.loadIcon(context.getProperty("help.icon.small"));
    String helpDesc = context.getProperty("help.title");
    String helpTooltip = context.getProperty("help.tooltip");
    PrideAction helpAction = new OpenHelpAction(helpDesc, helpIcon);

    // faq
    String faqDesc = context.getProperty("faq.title");
    PrideAction faqAction = new OpenFAQAction(faqDesc, null);

    // pride website
    String prideWeb = context.getProperty("open.pride.website.title");
    String prideWebUrl = context.getProperty("pride.website");
    PrideAction prideWebAction = new OpenUrlAction(prideWeb, null, prideWebUrl);

    // pride website
    String inspectorWeb = context.getProperty("open.pride.inspector.website.title");
    String inspectorWebUrl = context.getProperty("pride.inspector.website");
    PrideAction inspectorWebAction = new OpenUrlAction(inspectorWeb, null, inspectorWebUrl);

    // feedback
    String feedbackDesc = context.getProperty("feedback.title");
    PrideAction feedBackAction = new FeedbackAction(feedbackDesc, null);

    // export
    String exportDesc = context.getProperty("export.title");
    PrideAction exportAction = new ExportSpectrumAction(exportDesc, null);
    context.addPropertyChangeListenerToDataAccessMonitor((PropertyChangeListener) exportAction);

    // export identification
    String exportIdentDesc = context.getProperty("export.identification.title");
    PrideAction exportIdentAction = new ExportIdentificationPeptideAction(exportIdentDesc, null);

    // export spectrum description
    String exportSpectrumDesc = context.getProperty("export.spectrum.desc.title");
    PrideAction exportSpectrumDescAction = new ExportSpectrumDescAction(exportSpectrumDesc, null);

    // export identification description
    String exportIdentDescTitle = context.getProperty("export.identification.desc.title");
    PrideAction exportIdentDescAction =
        new ExportIdentificationDescAction(exportIdentDescTitle, null);

    // export peptide description
    String exportPeptideDescTitle = context.getProperty("export.peptide.desc.title");
    PrideAction exportPeptideAction = new ExportPeptideDescAction(exportPeptideDescTitle, null);

    // make experiment public
    String makeExpPublicTitle = context.getProperty("make.experiment.public.title");
    PrideAction makeExpPublicAction = new MakeExperimentPublicAction(makeExpPublicTitle, null);

    String createReviewerTitle = context.getProperty("create.reviewer.title");
    PrideAction createReviewerAction = new CreateReviewerAction(createReviewerTitle, null);

    // check update
    String updateDescTitle = context.getProperty("check.update.desc.title");
    PrideAction updateAction = new UpdateAction(updateDescTitle, null);

    // about
    String aboutDesc = context.getProperty("about.title");
    PrideAction aboutAction = new AboutAction(aboutDesc, null);

    // exit
    String exitDesc = context.getProperty("exit.title");
    PrideAction exitAction = new ExitAction(exitDesc, null);

    // menu items
    menuBar = new JMenuBar();

    // file menu
    JMenu fileMenu =
        MenuFactory.createMenu(
            "File",
            openFileAction,
            openDbAction,
            openReviewerAction,
            MenuFactory.ACTION_SEPARATOR,
            closeAction,
            closeAllAction,
            MenuFactory.ACTION_SEPARATOR,
            exitAction);
    fileMenu.setMnemonic(java.awt.event.KeyEvent.VK_F);
    menuBar.add(fileMenu);

    // try samples
    JMenu trySampleMenu =
        MenuFactory.createMenu("Examples", openPrideXmlExampleAction, openMzMLExampleAction);
    trySampleMenu.setMnemonic(java.awt.event.KeyEvent.VK_X);
    menuBar.add(trySampleMenu);

    // export menu
    JMenu exportMenu =
        MenuFactory.createMenu(
            "Export",
            exportAction,
            exportSpectrumDescAction,
            exportIdentAction,
            exportIdentDescAction,
            exportPeptideAction);
    exportMenu.setMnemonic(java.awt.event.KeyEvent.VK_E);
    menuBar.add(exportMenu);

    // curation menu
    boolean showCurationMenu = Boolean.parseBoolean(context.getProperty("include.curation.menu"));
    if (showCurationMenu) {
      JMenu curationMenu =
          MenuFactory.createMenu("Curation", makeExpPublicAction, createReviewerAction);
      curationMenu.setMnemonic(java.awt.event.KeyEvent.VK_C);
      menuBar.add(curationMenu);
    }

    // help menu
    JMenu helpMenu =
        MenuFactory.createMenu(
            "Help",
            helpAction,
            faqAction,
            MenuFactory.ACTION_SEPARATOR,
            prideWebAction,
            inspectorWebAction,
            MenuFactory.ACTION_SEPARATOR,
            feedBackAction,
            MenuFactory.ACTION_SEPARATOR,
            updateAction,
            aboutAction);
    helpMenu.setMnemonic(java.awt.event.KeyEvent.VK_H);
    menuBar.add(helpMenu);

    // add menus
    mainFrame.setJMenuBar(menuBar);

    // tool bar
    toolBar = new JToolBar();

    // open file
    JButton openFileButton = new JButton();
    openFileButton.setAction(openFileAction);
    openFileButton.setText("");
    openFileButton.setToolTipText(openFileTooltip);
    openFileButton.setFocusable(false);
    toolBar.add(openFileButton);
    // open database
    JButton openDbButton = new JButton();
    openDbButton.setAction(openDbAction);
    openDbButton.setText("");
    openDbButton.setToolTipText(openDbTooltip);
    openDbButton.setFocusable(false);
    toolBar.add(openDbButton);
    // open reviewer download
    JButton openReviewerButton = new JButton();
    openReviewerButton.setAction(openReviewerAction);
    openReviewerButton.setText("");
    openReviewerButton.setToolTipText(openReviewerTooltip);
    openReviewerButton.setFocusable(false);
    toolBar.add(openReviewerButton);
    // separator
    toolBar.addSeparator();
    // help
    JButton helpButton = new JButton(helpIcon);
    helpButton.setAction(helpAction);
    helpButton.setText("");
    helpButton.setToolTipText(helpTooltip);
    helpButton.setFocusable(false);
    toolBar.add(helpButton);
    mainFrame.getContentPane().add(toolBar, BorderLayout.PAGE_START);
  }
  private void setupActions() {

    wordList.addListSelectionListener(
        new ListSelectionListener() {
          public void valueChanged(ListSelectionEvent e) {
            wordEditField.setText((String) wordList.getSelectedValue());
            wordEditField.selectAll();
            new FocusRequester(wordEditField);
          }
        });

    newWord.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            newWordAction();
          }
        });

    wordEditFieldListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            int index = wordList.getSelectedIndex();
            String old = (String) wordList.getSelectedValue(), newVal = wordEditField.getText();
            if (newVal.equals("") || newVal.equals(old)) {
              return; // Empty string or no change.
            }
            if (wordListModel.contains(newVal)) {
              // ensure that word already in list is visible
              index = wordListModel.indexOf(newVal);
              wordList.ensureIndexIsVisible(index);
              return;
            }

            int newIndex = findPos(wordListModel, newVal);
            if (index >= 0) {
              // initiate replacement of selected word
              wordListModel.remove(index);
              if (newIndex > index) {
                // newIndex has to be adjusted after removal of previous entry
                newIndex--;
              }
            }
            wordListModel.add(newIndex, newVal);
            wordList.ensureIndexIsVisible(newIndex);
            wordEditField.selectAll();
          }
        };
    wordEditField.addActionListener(wordEditFieldListener);

    removeWord.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            int index = wordList.getSelectedIndex();
            if (index == -1) return;
            wordListModel.remove(index);
            wordEditField.setText("");
            if (wordListModel.size() > 0)
              wordList.setSelectedIndex(Math.min(index, wordListModel.size() - 1));
          }
        });

    fieldList.addListSelectionListener(
        new ListSelectionListener() {
          public void valueChanged(ListSelectionEvent e) {
            currentField = (String) fieldList.getSelectedValue();
            fieldNameField.setText("");
            setupWordSelector();
          }
        });

    newField.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (!fieldListModel.get(0).equals(FIELD_FIRST_LINE)) {
              // only add <field name> once
              fieldListModel.add(0, FIELD_FIRST_LINE);
            }
            fieldList.setSelectedIndex(0);
            fPane.getVerticalScrollBar().setValue(0);
            fieldNameField.setEnabled(true);
            fieldNameField.setText(currentField);
            fieldNameField.selectAll();

            new FocusRequester(fieldNameField);
          }
        });

    fieldNameField.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            fieldNameField.transferFocus();
          }
        });

    fieldNameField.addFocusListener(
        new FocusAdapter() {

          /** Adds the text value to the list */
          public void focusLost(FocusEvent e) {
            String s = fieldNameField.getText();
            fieldNameField.setText("");
            fieldNameField.setEnabled(false);
            if (!FIELD_FIRST_LINE.equals(s) && !"".equals(s)) {
              // user has typed something

              // remove "<first name>" from list
              fieldListModel.remove(0);

              int pos;
              if (fieldListModel.contains(s)) {
                // field already exists, scroll to that field (below)
                pos = fieldListModel.indexOf(s);
              } else {
                // Add new field.
                pos = findPos(fieldListModel, s);
                fieldListModel.add(Math.max(0, pos), s);
              }
              fieldList.setSelectedIndex(pos);
              fieldList.ensureIndexIsVisible(pos);
              currentField = s;
              setupWordSelector();
              newWordAction();
              // new FocusRequester(wordEditField);
            }
          }
        });

    removeField.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            int index = fieldList.getSelectedIndex();
            if (index == -1) return;
            String fieldName = (String) fieldListModel.get(index);
            removedFields.add(fieldName);
            fieldListModel.remove(index);
            wordListModels.remove(fieldName);
            fieldNameField.setText("");
            if (fieldListModel.size() > 0)
              fieldList.setSelectedIndex(Math.min(index, wordListModel.size() - 1));
          }
        });

    help.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            frame.helpDiag.showPage(GUIGlobals.contentSelectorHelp);
          }
        });

    ok.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            applyChanges();
            dispose();
          }
        });

    apply.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Store if an entry is currently being edited:
            if (!wordEditField.getText().equals("")) {
              wordEditFieldListener.actionPerformed(null);
            }
            applyChanges();
          }
        });

    @SuppressWarnings("serial")
    Action cancelAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            dispose();
          }
        };
    cancelAction.putValue(Action.NAME, Globals.lang("Cancel"));
    cancel.setAction(cancelAction);
  }