Esempio n. 1
0
  @Override
  public void actionPerformed(ActionEvent ev) {
    if (ev.getSource() == checkAllButton) {
      for (int i = 0; i < numItems; i++) {
        chooseCB[i].setSelected(true);
      }
    }

    if (ev.getSource() == clearAllButton) {
      for (int i = 0; i < numItems; i++) {
        chooseCB[i].setSelected(false);
      }
    }
    if (ev.getSource() == titleColorButton) {
      Color newColor =
          JColorChooser.showDialog(this, "Select color", titleColorButton.getBackground());
      if (newColor != null) {
        titleColorButton.setBackground(newColor);
      }
    }
    if (ev.getSource() == textColorButton) {
      Color newColor =
          JColorChooser.showDialog(this, "Select color", textColorButton.getBackground());
      if (newColor != null) {
        textColorButton.setBackground(newColor);
      }
    }
    if (ev.getSource() == borderColorButton) {
      Color newColor =
          JColorChooser.showDialog(this, "Select color", borderColorButton.getBackground());
      if (newColor != null) {
        borderColorButton.setBackground(newColor);
      }
    }
  }
Esempio n. 2
0
  @Override
  public void appendTo(final MenuView view, ArrayList<JMenuItem> menuItems, String name) {
    JMenu menuItem = new JMenu();
    JColorChooser colorChooser = getColorChooser(name);
    colorChooser.setSelectionModel(new javax.swing.colorchooser.DefaultColorSelectionModel());
    final AbstractColorChooserPanel colorChooserPanel = colorChooser.getChooserPanels()[0];

    if (initialColor == null) initialColor = UIManager.getColor("Panel.background");
    colorChooserPanel.getColorSelectionModel().setSelectedColor(initialColor);

    colorChooserPanel
        .getColorSelectionModel()
        .addChangeListener(
            new ChangeListener() {
              @Override
              public void stateChanged(ChangeEvent e) {
                final ChangeListener self = this;

                view.execute(
                    new Action1<ActionRunner>() {
                      @Override
                      public void run(ActionRunner runner) {
                        colorChooserPanel.getColorSelectionModel().removeChangeListener(self);
                        Color color = colorChooserPanel.getColorSelectionModel().getSelectedColor();
                        Object action = actionCreator.call(color);
                        runner.run(action);
                        view.hide();
                      }
                    });
              }
            });

    menuItem.add(colorChooserPanel);
    menuItems.add(menuItem);
  }
Esempio n. 3
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();
  }
Esempio n. 4
0
 public static void main(String[] args) {
   JColorChooser chooser = new JColorChooser();
   if (null == chooser.getPreviewPanel()) {
     throw new Error("Failed: getPreviewPanel() returned null");
   }
   JButton button = new JButton("Color"); // NON-NLS: simple label
   chooser.setPreviewPanel(button);
   if (button != chooser.getPreviewPanel()) {
     throw new Error("Failed in setPreviewPanel()");
   }
 }
 public void actionPerformed(ActionEvent ev) {
   super.actionPerformed(ev);
   String com = ev.getActionCommand();
   if (com.equals("GameInformationFrame.LOAD")) // $NON-NLS-1$
   {
     tabs.setSelectedIndex(0);
     loadFromFile();
   }
   if (com.equals("GameInformationFrame.FILESAVE")) // $NON-NLS-1$
   {
     tabs.setSelectedIndex(0);
     saveToFile();
     return;
   }
   if (com.equals("GameInformationFrame.FONTCOLOR")) // $NON-NLS-1$
   {
     String colorStr = Messages.getString("GameInformationFrame.FONTCOLOR"); // $NON-NLS-1$
     Color c = JColorChooser.showDialog(this, colorStr, fgColor);
     if (c != null) {
       fgColor = c;
       setSelectionAttribute(StyleConstants.Foreground, c);
     }
     return;
   }
   if (com.equals("GameInformationFrame.COLOR")) // $NON-NLS-1$
   {
     String colorStr = Messages.getString("GameInformationFrame.COLOR"); // $NON-NLS-1$
     Color c = JColorChooser.showDialog(this, colorStr, editor.getBackground());
     if (c != null) setEditorBackground(c);
     return;
   }
   if (com.equals("GameInformationFrame.CUT")) // $NON-NLS-1$
   {
     editor.cut();
     return;
   }
   if (com.equals("GameInformationFrame.COPY")) // $NON-NLS-1$
   {
     editor.copy();
     return;
   }
   if (com.equals("GameInformationFrame.PASTE")) // $NON-NLS-1$
   {
     editor.paste();
     return;
   }
   if (com.equals("GameInformationFrame.SELECTALL")) // $NON-NLS-1$
   {
     editor.selectAll();
     return;
   }
 }
Esempio n. 6
0
 /**
  * Fonction appelée lorsque le joueur choisis un bouton radio. Elle charge la couleur actuelle
  * dans le sélecteur de couleur.
  *
  * @param e actionEvent permettant de recupérer le bouton qui vient d'être choisi
  */
 @Override
 public void actionPerformed(ActionEvent e) {
   JRadioButton radio = (JRadioButton) e.getSource();
   if (radio == bordersColor) {
     selectionColor.setColor(GridView.getBorderColor());
   } else if (radio == selectedCaseColor) {
     selectionColor.setColor(GridView.getSelectionColor());
   } else if (radio == alreadyViewColor) {
     selectionColor.setColor(GridView.getAlreadyViewColor());
   } else if (radio == caseBackground) {
     selectionColor.setColor(GridView.getBackgroundColor());
   }
 }
  /** Handles events from the editor button and from the dialog's OK button. */
  public void actionPerformed(ActionEvent e) {
    if (EDIT.equals(e.getActionCommand())) {
      // The user has clicked the cell, so
      // bring up the dialog.
      button.setBackground(currentColor);
      colorChooser.setColor(currentColor);
      dialog.setVisible(true);

      // Make the renderer reappear.
      fireEditingStopped();

    } else { // User pressed dialog's "OK" button.
      currentColor = colorChooser.getColor();
    }
  }
  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();
  }
 /** Handle a grid paint selection. */
 private void attemptGridPaintSelection() {
   Color c;
   c = JColorChooser.showDialog(this, localizationResources.getString("Grid_Color"), Color.blue);
   if (c != null) {
     this.gridPaintSample.setPaint(c);
   }
 }
Esempio n. 10
0
 /** Allows the user the opportunity to change the outline paint. */
 private void attemptModifyLabelPaint() {
   Color c;
   c = JColorChooser.showDialog(this, localizationResources.getString("Label_Color"), Color.blue);
   if (c != null) {
     this.labelPaintSample.setPaint(c);
   }
 }
Esempio n. 11
0
 /** Update the text colour. */
 protected void chooseColour() {
   Color newColour =
       JColorChooser.showDialog(this, "Select text colour", colourIcon.getMainColour());
   if (newColour != null) {
     setTextColour(newColour);
   }
 }
Esempio n. 12
0
 protected void actionForeground() {
   Color color = JColorChooser.showDialog(this, "Foreground", panel.getForeground());
   if (color != null) {
     total.setForeground(color);
     time.setForeground(color);
   }
 }
 /**
  * Shows a color chooser dialog and changes the foreground color of the button which is initiating
  * the dialog.
  *
  * @param aButton The button initiating the dialog
  */
 private void showColorChooser(JButton aButton) {
   Color newColor = JColorChooser.showDialog(this, "Choose Text Color", aButton.getForeground());
   if (null != newColor) {
     aButton.setForeground(newColor);
     onChange();
   }
 } // END private void showColorChooser(JButton)
  @Override
  public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub
    Object source = e.getSource();

    if (source == ok) {
      userResponse = APPLY_OPTION;
      this.setVisible(false);
    } else if (source == cancel) {
      userResponse = CANCEL_OPTION;
      this.setVisible(false);
    } else if (source == fontCombo) {
      @SuppressWarnings("unchecked")
      JComboBox<String> cb = (JComboBox<String>) source;
      String s = (String) cb.getSelectedItem();
      Font tmp = example.getFont();
      example.setFont(new Font(s, tmp.getStyle(), tmp.getSize()));
    } else if (source == sizeCombo) {
      @SuppressWarnings("unchecked")
      JComboBox<String> cb = (JComboBox<String>) source;
      String s = (String) cb.getSelectedItem();
      int newSize = Integer.parseInt(s);
      Font tmp = example.getFont();
      example.setFont(new Font(tmp.getFamily(), tmp.getStyle(), newSize));
    } else if (source == foreground) {
      Color tmp = JColorChooser.showDialog(this, "Choose text color", example.getForeground());
      if (tmp != null) example.setForeground(tmp);
    }
  }
Esempio n. 15
0
    @Override
    public void actionPerformed(ActionEvent e) {
      // TODO Auto-generated method stub

      Object source = e.getSource();
      if (source == ok) {
        response = APPLY_OPTION;
        this.setVisible(false);
      } else if (source == cancel) {
        response = CANCEL_OPTION;
        this.setVisible(false);
      } else if (source == sizeCombo) {
        // get the number from the source
        JComboBox number = (JComboBox) source;
        String numberItem = (String) number.getSelectedItem();
        Font temp = example.getFont();
        // then set the font
        int newSize = Integer.parseInt(numberItem);
        example.setFont(new Font(temp.getFamily(), temp.getStyle(), newSize));
      } else if (source == fontCombo) {
        JComboBox font = (JComboBox) source;
        String s = (String) font.getSelectedItem();
        Font tmp = example.getFont();
        example.setFont(new Font(s, tmp.getStyle(), tmp.getSize()));
      } else if (source == foreground) {
        Color tmp = JColorChooser.showDialog(this, "Choose text color", example.getForeground());
        MenuBar.shapeLBG.setBackground(tmp);
        if (tmp != null) example.setForeground(tmp);
      }
    }
 public void actionPerformed(ActionEvent e) {
   Color color =
       JColorChooser.showDialog(InnereKlassemitmainMethode.this, "Eine Farbe wählen", Color.red);
   if (color != null) {
     g.setColor(color);
     status.setText("Farbe mit JColorChooser abgeändert");
   }
 }
Esempio n. 17
0
 public void setColorValue(Color c) {
   if (c == null) {
     useDefaultColor.setSelected(true);
   } else {
     useDefaultColor.setSelected(false);
     customColorChooser.setColor(c);
   }
 }
Esempio n. 18
0
 @Override
 public void actionPerformed(ActionEvent e) {
   Color chosen = JColorChooser.showDialog(null, button.getName(), button.getColor());
   if (chosen != null) {
     button.setColor(chosen);
     button.getCheckBox().ifPresent(checkBox -> checkBox.setSelected(true));
   }
 }
Esempio n. 19
0
  protected void attachTo(Component jc) {
    if (extListener != null && extListener.accept(jc)) {
      extListener.startListeningTo(jc, extNotifier);
      listenedTo.add(jc);
      if (wizardPage.getMapKeyFor(jc) != null) {
        wizardPage.maybeUpdateMap(jc);
      }
      return;
    }
    if (isProbablyAContainer(jc)) {
      attachToHierarchyOf((Container) jc);
    } else if (jc instanceof JList) {
      listenedTo.add(jc);
      ((JList) jc).addListSelectionListener(this);
    } else if (jc instanceof JComboBox) {
      ((JComboBox) jc).addActionListener(this);
    } else if (jc instanceof JTree) {
      listenedTo.add(jc);
      ((JTree) jc).getSelectionModel().addTreeSelectionListener(this);
    } else if (jc instanceof JToggleButton) {
      ((AbstractButton) jc).addItemListener(this);
    } else if (jc
        instanceof JFormattedTextField) { // JFormattedTextField must be tested before JTextCompoent
      jc.addPropertyChangeListener("value", this);
    } else if (jc instanceof JTextComponent) {
      listenedTo.add(jc);
      ((JTextComponent) jc).getDocument().addDocumentListener(this);
    } else if (jc instanceof JColorChooser) {
      listenedTo.add(jc);
      ((JColorChooser) jc).getSelectionModel().addChangeListener(this);
    } else if (jc instanceof JSpinner) {
      ((JSpinner) jc).addChangeListener(this);
    } else if (jc instanceof JSlider) {
      ((JSlider) jc).addChangeListener(this);
    } else if (jc instanceof JTable) {
      listenedTo.add(jc);
      ((JTable) jc).getSelectionModel().addListSelectionListener(this);
    } else {
      if (logger.isLoggable(Level.FINE)) {
        logger.fine(
            "Don't know how to listen to a "
                + // NOI18N
                jc.getClass().getName());
      }
    }

    if (accept(jc) && !(jc instanceof JPanel)) {
      jc.addPropertyChangeListener("name", this);
      if (wizardPage.getMapKeyFor(jc) != null) {
        wizardPage.maybeUpdateMap(jc);
      }
    }

    if (logger.isLoggable(Level.FINE) && accept(jc)) {
      logger.fine("Begin listening to " + jc); // NOI18N
    }
  }
Esempio n. 20
0
 private void panelAttributeMouseClicked(
     java.awt.event.MouseEvent evt) { // GEN-FIRST:event_panelAttributeMouseClicked
   final Color c =
       JColorChooser.showDialog(
           RuleDisplayerPanel.this, "Choose the attribute color", panelAttribute.getBackground());
   if (c != null) {
     panelAttribute.setBackground(c);
   }
 } // GEN-LAST:event_panelAttributeMouseClicked
Esempio n. 21
0
 /**
  * Prompts the user for a new custom color and adds that color to the combo box.
  *
  * @param field the combobox to enter a new color for
  * @param title the title for the dialog box
  * @param targetColor the initial Color set when the color-chooser is shown
  */
 protected void handleCustomColor(JComboBox field, String title, Color targetColor) {
   Color newColor = JColorChooser.showDialog(ArgoFrame.getInstance(), title, targetColor);
   if (newColor != null) {
     field.insertItemAt(newColor, field.getItemCount() - 1);
     field.setSelectedItem(newColor);
   } else if (getPanelTarget() != null) {
     field.setSelectedItem(targetColor);
   }
 }
Esempio n. 22
0
 private static void createAndShowGUI() {
   JFrame frame = new JFrame(Test6827032.class.getName());
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   cc = new JColorChooser();
   cc.setDragEnabled(true);
   frame.add(cc);
   frame.pack();
   frame.setVisible(true);
 }
 private void boxColorButtonActionPerformed(
     java.awt.event.ActionEvent evt) // GEN-FIRST:event_boxColorButtonActionPerformed
     { // GEN-HEADEREND:event_boxColorButtonActionPerformed
   Color c = JColorChooser.showDialog(this, "background", params.getBoxColor());
   if (c != null) {
     params.setBoxColor(c);
     boxColorButton.setBackground(c);
   } // TODO add your handling code here:
 } // GEN-LAST:event_boxColorButtonActionPerformed
Esempio n. 24
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();
  }
Esempio n. 25
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;
  }
Esempio n. 26
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...
    }
Esempio n. 27
0
 private boolean optionRNADisplay() {
   // les options d'affichages generales
   if (_type.equals("gaspin")) {
     _vp.getVARNAUI().UIToggleGaspinMode();
   } else if (_type.equals("backbone")) {
     _vp.getVARNAUI().UISetBackboneColor();
   } else if (_type.equals("bonds")) {
     Color c = JColorChooser.showDialog(_vp, "Choose new bonds color", _vp.getBackground());
     if (c != null) {
       _vp.setDefaultBPColor(c);
       _vp.repaint();
     }
   } else if (_type.equals("basecolorforBP")) {
     if (_source != null) {
       if (_source instanceof JCheckBoxMenuItem) {
         JCheckBoxMenuItem check = (JCheckBoxMenuItem) _source;
         _vp.setUseBaseColorsForBPs(check.getState());
         _vp.repaint();
       }
     }
   } else if (_type.equals("bpstyle")) {
     _vp.getVARNAUI().UISetBPStyle();
   } else if (_type.equals("specialbasecolored")) {
     _vp.getVARNAUI().UIToggleColorSpecialBases();
   } else if (_type.equals("showwarnings")) {
     _vp.getVARNAUI().UIToggleShowWarnings();
   } else if (_type.equals("dashbasecolored")) {
     _vp.getVARNAUI().UIToggleColorGapsBases();
   } else if (_type.equals("numPeriod")) {
     _vp.getVARNAUI().UISetNumPeriod();
   } else if (_type.equals("eachKind")) {
     if (_vp.getRNA().get_listeBases() != null) {
       _vp.getVARNAUI().UIBaseTypeColor();
     } else {
       _vp.emitWarning("No base");
     }
   } else if (_type.equals("eachCouple")) {
     if (_vp.getRNA().get_listeBases() != null && _vp.getRNA().get_listeBases().size() != 0) {
       _vp.getVARNAUI().UIBasePairTypeColor();
     } else {
       _vp.emitWarning("No base");
     }
   } else if (_type.equals("eachBase")) {
     if (_vp.getRNA().get_listeBases() != null && _vp.getRNA().get_listeBases().size() != 0) {
       _vp.getVARNAUI().UIBaseAllColor();
     } else {
       _vp.emitWarning("No base");
     }
   } else if (_type.equals("specialBasesColor")) {
     _vp.getVARNAUI().UIPickSpecialBasesColor();
   } else if (_type.equals("dashBasesColor")) {
     _vp.getVARNAUI().UIPickGapsBasesColor();
   } else return colorBases();
   return true;
 }
Esempio n. 28
0
  public SwingDnDFrame() {
    setTitle("SwingDnDTest");
    JTabbedPane tabbedPane = new JTabbedPane();

    JList list = SampleComponents.list();
    tabbedPane.addTab("List", list);
    JTable table = SampleComponents.table();
    tabbedPane.addTab("Table", table);
    JTree tree = SampleComponents.tree();
    tabbedPane.addTab("Tree", tree);
    JFileChooser fileChooser = new JFileChooser();
    tabbedPane.addTab("File Chooser", fileChooser);
    JColorChooser colorChooser = new JColorChooser();
    tabbedPane.addTab("Color Chooser", colorChooser);

    final JTextArea textArea = new JTextArea(4, 40);
    JScrollPane scrollPane = new JScrollPane(textArea);
    scrollPane.setBorder(new TitledBorder(new EtchedBorder(), "Drag text here"));

    JTextField textField = new JTextField("Drag color here");
    textField.setTransferHandler(new TransferHandler("background"));

    tabbedPane.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            textArea.setText("");
          }
        });

    tree.setDragEnabled(true);
    table.setDragEnabled(true);
    list.setDragEnabled(true);
    fileChooser.setDragEnabled(true);
    colorChooser.setDragEnabled(true);
    textField.setDragEnabled(true);

    add(tabbedPane, BorderLayout.NORTH);
    add(scrollPane, BorderLayout.CENTER);
    add(textField, BorderLayout.SOUTH);
    pack();
  }
Esempio n. 29
0
  /**
   * Handle action events coming from the buttons.
   *
   * @param evt, the associated ActionEvent.
   */
  public void actionPerformed(ActionEvent evt) {
    Object source = evt.getSource();

    if (source instanceof JButton) {
      if (source == pbSave) {
        chosen = tcc.getColor();
        onCancel();
      } else {
        onCancel();
      }
    }
  }
 /** Shows a dialog where the user can select the plot background color. */
 private void createLineColorDialog() {
   Color oldColor = line.getFormat().getColor();
   if (oldColor == null) {
     oldColor = Color.BLACK;
   }
   Color newLineColor =
       JColorChooser.showDialog(
           null, I18N.getGUILabel("edit_parallel_line.line_color_title.label"), oldColor);
   if (newLineColor != null && !(newLineColor.equals(oldColor))) {
     lineColor = newLineColor;
   }
 }