示例#1
0
  public static Color getColor(String selectTitle, Color color) {
    JColorChooser chooser = getInstance();
    if (instance == null) return null;

    instance.setColor(color);
    JColorChooser.createDialog(VisualDCT.getInstance(), selectTitle, true, instance, null, null)
        .setVisible(true);
    return chooser.getColor();
  }
示例#2
0
    public void actionPerformed(ActionEvent e) {
      JColorChooser colorChooser = BasicComponentFactory.createColorChooser(bufferedColorModel);
      ActionListener okHandler = new OKHandler(trigger);
      JDialog dialog =
          JColorChooser.createDialog(parent, "Choose Color", true, colorChooser, okHandler, null);
      dialog.addWindowListener(new Closer());
      dialog.addComponentListener(new DisposeOnClose());

      dialog.setVisible(true); // blocks until user brings dialog down...
    }
示例#3
0
  @Override
  public Paint showEditor(Component parent, Paint initialValue) {

    color = initialValue;
    JDialog dialog =
        JColorChooser.createDialog(parent, "Please pick a color", true, chooser, listener, null);
    dialog.setVisible(true);

    return color;
  }
  ColorEditor() {
    // Set up the editor (from the table's point of view),
    // which is a button.
    // This button brings up the color chooser dialog,
    // which is the editor from the user's point of view.
    button = new JButton();
    button.setActionCommand(EDIT);
    button.addActionListener(this);
    button.setBorderPainted(false);

    // Set up the dialog that the button brings up.
    colorChooser = new JColorChooser();
    dialog = JColorChooser.createDialog(button, "Pick a Color", true, colorChooser, this, null);
  }
  public static Color showCommonJColorChooserDialog(
      Component component, String title, Color initialColor) throws HeadlessException {

    final JColorChooser pane = getCommonJColorChooser();
    pane.setColor(initialColor);

    ColorTracker ok = new ColorTracker(pane);
    JDialog dialog = JColorChooser.createDialog(component, title, true, pane, ok, null);
    dialog.addWindowListener(new Closer());
    dialog.addComponentListener(new DisposeOnClose());

    dialog.show(); // blocks until user brings dialog down...

    return ok.getColor();
  }
  @Override
  public void execute(ActionEvent e) {

    ApplicationContext ctx = AppContext.getContext();
    final ApplicationWindow win = ctx.getBean(ApplicationWindow.class);
    final String title = resources.getResourceByKey("SetLayerColorCommand.dialog.subtitle");

    final LayerTableModel model =
        AppContext.getContext().getBean(ShowLayersCommand.class).getLayerPanel().getLayerModel();
    AlternatingLineTable layerTable =
        AppContext.getContext().getBean(ShowLayersCommand.class).getLayerPanel().getLayerTable();

    int index = layerTable.convertRowIndexToModel(layerTable.getSelectedRow());

    if (index >= 0) {
      layer = model.getLayer().get(index);
    }

    if (layer == null) {
      return;
    }

    final JColorChooser chooser = new JColorChooser();

    ActionListener okListener =
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent arg0) {
            dialog.setVisible(false);
            layer.setColor(chooser.getColor());
            model.fireTableDataChanged();
            EditorUtils.getCurrentActiveEditor().setFileState(FileState.DIRTY);
          }
        };

    ActionListener cancelListener =
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent arg0) {
            dialog.setVisible(false);
          }
        };

    dialog = JColorChooser.createDialog(win, title, true, chooser, okListener, cancelListener);
    dialog.setVisible(true);
  }
示例#7
0
  /**
   * Displays a dialog that lets you change a color. Locks up the application until a choice is
   * made, returning the chosen color, or null if nothing was chosen.
   *
   * @param component the source component.
   * @param title the String title for the window.
   * @param startingColor the initial color.
   */
  public static Color showDialog(Component component, String title, Color startingColor) {
    Color initColor = startingColor != null ? startingColor : Color.white;

    final JColorChooser jcc = new JColorChooser(initColor);
    ColorTracker ok = new ColorTracker(jcc);

    jcc.getSelectionModel().addChangeListener(ok);
    /* WORKAROUND for Java bug #5029286 and #6199676 */
    //        jcc.setPreviewPanel(ok.getTransparancyAdjustment(initColor.getAlpha()));
    JComponent previewPanel = ok.getTransparancyAdjustment(initColor.getAlpha());
    previewPanel.setSize(previewPanel.getPreferredSize());
    previewPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 1, 0));
    jcc.setPreviewPanel(previewPanel);

    JDialog colorDialog = JColorChooser.createDialog(component, title, true, jcc, ok, null);
    colorDialog.setVisible(true);
    return ok.getColor();
  }
示例#8
0
  /** Constructor. */
  public ColorCellEditor() {
    button =
        new JButton() {
          @Override
          public void paintComponent(Graphics g) {
            // When the buttons are pressed they are redrawn with the default
            // background color but not what we want.
            g.setColor(getBackground());
            g.fillRect(0, 0, getWidth(), getHeight());
          }
        };

    button.setActionCommand(EDIT);
    button.addActionListener(this);

    // Set up the dialog that the button brings up.
    colorChooser = new JColorChooser();
    dialog = JColorChooser.createDialog(button, "Pick a Color", true, colorChooser, this, null);
  }
示例#9
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);
    }
  }
    @Override
    public void actionPerformed(ActionEvent e) {
      // Set up the dialog that the button brings up.
      colorChooser = new JColorChooser();
      JDialog dialog =
          JColorChooser.createDialog(
              colorbt,
              "Pick a Color",
              true, // modal
              colorChooser,
              new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                  updateColor(colorChooser.getColor());
                  getParticlePicker().setColor(colorChooser.getColor());
                }
              }, // OK button handler
              null); // no CANCEL button handler
      XmippWindowUtil.setLocation(0.5f, 0.5f, dialog);
      dialog.setVisible(true);
    }
示例#11
0
  private static Object[] create() {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    frame.setVisible(true);

    // show color chooser
    JColorChooser chooser = new JColorChooser();
    JDialog dialog = JColorChooser.createDialog(frame, null, false, chooser, null, null);
    dialog.setVisible(true);

    // process all values
    List<Object> list = new ArrayList<Object>(KEYS.length);

    Component component = getC(getC(dialog.getLayeredPane(), 0), 1);
    AbstractButton ok = (AbstractButton) getC(component, 0);
    AbstractButton cancel = (AbstractButton) getC(component, 1);
    AbstractButton reset = (AbstractButton) getC(component, 2);
    list.add(ok.getText());
    list.add(cancel.getText());
    list.add(reset.getText());
    list.add(Integer.valueOf(reset.getMnemonic()));

    for (int i = 0; i < 5; i++) {
      AbstractColorChooserPanel panel =
          (AbstractColorChooserPanel) getC(getC(getC(chooser, 0), i), 0);
      list.add(panel.getDisplayName());
      list.add(Integer.valueOf(panel.getMnemonic()));
      if (i == 0) {
        JLabel label = (JLabel) getC(getC(panel, 0), 1);
        JPanel upper = (JPanel) getC(getC(getC(panel, 0), 0), 0);
        JPanel lower = (JPanel) getC(getC(getC(panel, 0), 2), 0);
        addSize(list, upper, 1, 1, 31, 9);
        list.add(label.getText());
        addSize(list, lower, 1, 1, 5, 7);
      } else {
        Component container = getC(panel, 0);
        for (int j = 0; j < 3; j++) {
          AbstractButton button = (AbstractButton) getC(container, j);
          list.add(button.getText());
        }
        JLabel label = (JLabel) getC(container, 3);
        list.add(label.getText());
        if (i == 4) {
          label = (JLabel) getC(container, 4);
          list.add(label.getText());
        }
        if (i == 3) {
          label = (JLabel) getC(panel, 1);
          list.add(label.getText());
          list.add(Integer.valueOf(label.getDisplayedMnemonic()));
        }
      }
    }

    // close dialog
    dialog.setVisible(false);
    dialog.dispose();

    // close frame
    frame.setVisible(false);
    frame.dispose();

    return list.toArray();
  }