示例#1
0
  @Override
  protected void fireActionPerformed(ActionEvent event) {
    try {
      this.setSelected(true);

      // create the dialog if this has not been done yet.
      if (this.dialog == null) {
        // Get the top level ancestor as parent for the new dialog.
        // This ensures that on Mac OS X the global menu bar remains
        // visible while the dialog is open.
        final Container parent = this.getTopLevelAncestor();
        dialog =
            JColorChooser.createDialog(
                parent,
                colorChooserTitle,
                true, // modal
                colorChooser,
                this, // OK button handler
                null); // no CANCEL button handler
        dialog.pack();
        dialog.setResizable(false);
      }

      // show the dialog
      colorChooser.setColor(color);
      dialog.setVisible(true);

      /* A simpler option that is displaying the ugly preview panel:
      Color newColor = JColorChooser.showDialog(this.getTopLevelAncestor(),
              colorChooserTitle, color);
      if (newColor != null){
          // only set color and fire an event when user did not cancel.
          this.setColor(newColor);
          super.fireActionPerformed(event);
      }*/
    } catch (Exception e) {
    } finally {
      this.setSelected(false);
    }
  }
示例#2
0
  /**
   * Display a dialog which can be used to select a color
   *
   * @param dialogTitle
   * @param defaultColor The currently selected color
   * @return The color the user selected, or null if none/cancelled
   */
  public static Color showColorChooserDialog(String dialogTitle, Color defaultColor) {

    Color color = null;
    JColorChooser chooser = new JColorChooser();
    chooser.setColor(defaultColor);
    while (true) {

      int response =
          JOptionPane.showConfirmDialog(
              IGV.getMainFrame(), chooser, dialogTitle, JOptionPane.OK_CANCEL_OPTION);

      if ((response == JOptionPane.CANCEL_OPTION) || (response == JOptionPane.CLOSED_OPTION)) {
        return null;
      }

      color = chooser.getColor();
      if (color == null) {
        continue;
      } else {
        break;
      }
    }
    return color;
  }
 /** Set the colour the user has chosen. */
 public void setColour(Color color) {
   tcc.setColor(color);
 }