Search in sources :

Example 1 with AbstractColorChooserPanel

use of javax.swing.colorchooser.AbstractColorChooserPanel in project jdk8u_jdk by JetBrains.

the class Test4711996 method main.

public static void main(String[] args) {
    JColorChooser chooser = new JColorChooser();
    AbstractColorChooserPanel[] panels = chooser.getChooserPanels();
    chooser.removeChooserPanel(panels[0]);
    chooser.updateUI();
}
Also used : AbstractColorChooserPanel(javax.swing.colorchooser.AbstractColorChooserPanel) JColorChooser(javax.swing.JColorChooser)

Example 2 with AbstractColorChooserPanel

use of javax.swing.colorchooser.AbstractColorChooserPanel in project litiengine by gurkenlabs.

the class ColorChooser method showRgbDialog.

public static final Color showRgbDialog(String title, Color color) {
    JColorChooser chooser = new JColorChooser();
    chooser.setColor(color);
    for (AbstractColorChooserPanel accp : chooser.getChooserPanels()) {
        if (accp.getDisplayName().equals("RGB")) {
            int result = JOptionPane.showConfirmDialog(Game.getScreenManager().getRenderComponent(), accp, title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
            if (result == JOptionPane.OK_OPTION) {
                return chooser.getColor();
            }
            return color;
        }
    }
    return color;
}
Also used : AbstractColorChooserPanel(javax.swing.colorchooser.AbstractColorChooserPanel) JColorChooser(javax.swing.JColorChooser)

Example 3 with AbstractColorChooserPanel

use of javax.swing.colorchooser.AbstractColorChooserPanel in project opennars by opennars.

the class GUI method selectColor.

/**
 * This will open a version of the Java Swing color chooser dialog. The dialog's
 * UI is dependent on the OS and JVM implementation running. <br>
 *
 * If you click on Cancel then it returns the last color previously selected.
 *
 * @return the ARGB colour as a 32 bit integer (as used in Processing).
 */
public static int selectColor() {
    Frame owner = (applet == null) ? null : applet.frame;
    if (chooser == null) {
        chooser = new JColorChooser();
        AbstractColorChooserPanel[] oldPanels = chooser.getChooserPanels();
        // Do not assume what panels are present
        LinkedList<AbstractColorChooserPanel> panels = new LinkedList<AbstractColorChooserPanel>();
        for (AbstractColorChooserPanel p : oldPanels) {
            String displayName = p.getDisplayName().toLowerCase();
            if (displayName.equals("swatches"))
                panels.addLast(p);
            else if (displayName.equals("rgb"))
                panels.addFirst(p);
            else if (displayName.startsWith("hs"))
                panels.addFirst(p);
        }
        AbstractColorChooserPanel[] newPanels;
        newPanels = panels.toArray(new AbstractColorChooserPanel[panels.size()]);
        chooser.setChooserPanels(newPanels);
        ColorPreviewPanel pp = new ColorPreviewPanel(lastColor);
        chooser.getSelectionModel().addChangeListener(pp);
        chooser.setPreviewPanel(pp);
    }
    // Set the preview color
    ((ColorPreviewPanel) chooser.getPreviewPanel()).setPrevColor(lastColor);
    // Use the last color selected to start it off
    chooser.setColor(lastColor);
    JDialog dialog = JColorChooser.createDialog(owner, "Color picker", true, chooser, new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            lastColor = chooser.getColor();
        }
    }, null);
    dialog.setVisible(true);
    return lastColor.getRGB();
}
Also used : Frame(java.awt.Frame) AbstractColorChooserPanel(javax.swing.colorchooser.AbstractColorChooserPanel) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JColorChooser(javax.swing.JColorChooser) LinkedList(java.util.LinkedList) JDialog(javax.swing.JDialog)

Example 4 with AbstractColorChooserPanel

use of javax.swing.colorchooser.AbstractColorChooserPanel in project omegat by omegat-org.

the class CustomColorSelectionController method removeTransparencySlider.

// Hide the Transparency Slider.
// From: http://stackoverflow.com/a/22608885
private static void removeTransparencySlider(JColorChooser jc) throws Exception {
    AbstractColorChooserPanel[] colorPanels = jc.getChooserPanels();
    for (int i = 1; i < colorPanels.length; i++) {
        AbstractColorChooserPanel cp = colorPanels[i];
        Field f = cp.getClass().getDeclaredField("panel");
        f.setAccessible(true);
        Object colorPanel = f.get(cp);
        Field f2 = colorPanel.getClass().getDeclaredField("spinners");
        f2.setAccessible(true);
        Object spinners = f2.get(colorPanel);
        Object transpSlispinner = Array.get(spinners, 3);
        if (i == colorPanels.length - 1) {
            transpSlispinner = Array.get(spinners, 4);
        }
        Field f3 = transpSlispinner.getClass().getDeclaredField("slider");
        f3.setAccessible(true);
        JSlider slider = (JSlider) f3.get(transpSlispinner);
        slider.setEnabled(false);
        slider.setVisible(false);
        Field f4 = transpSlispinner.getClass().getDeclaredField("spinner");
        f4.setAccessible(true);
        JSpinner spinner = (JSpinner) f4.get(transpSlispinner);
        spinner.setEnabled(false);
        spinner.setVisible(false);
        Field f5 = transpSlispinner.getClass().getDeclaredField("label");
        f5.setAccessible(true);
        JLabel label = (JLabel) f5.get(transpSlispinner);
        label.setVisible(false);
    }
}
Also used : Field(java.lang.reflect.Field) AbstractColorChooserPanel(javax.swing.colorchooser.AbstractColorChooserPanel) JSlider(javax.swing.JSlider) JSpinner(javax.swing.JSpinner) JLabel(javax.swing.JLabel)

Example 5 with AbstractColorChooserPanel

use of javax.swing.colorchooser.AbstractColorChooserPanel in project jdk8u_jdk by JetBrains.

the class Test6524757 method create.

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();
}
Also used : JPanel(javax.swing.JPanel) AbstractColorChooserPanel(javax.swing.colorchooser.AbstractColorChooserPanel) AbstractButton(javax.swing.AbstractButton) JFrame(javax.swing.JFrame) ArrayList(java.util.ArrayList) JLabel(javax.swing.JLabel) JComponent(javax.swing.JComponent) Component(java.awt.Component) JColorChooser(javax.swing.JColorChooser) JDialog(javax.swing.JDialog)

Aggregations

AbstractColorChooserPanel (javax.swing.colorchooser.AbstractColorChooserPanel)10 JColorChooser (javax.swing.JColorChooser)6 JDialog (javax.swing.JDialog)4 JLabel (javax.swing.JLabel)3 Frame (java.awt.Frame)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 LinkedList (java.util.LinkedList)2 JPanel (javax.swing.JPanel)2 ChangeEvent (javax.swing.event.ChangeEvent)2 ChangeListener (javax.swing.event.ChangeListener)2 BorderLayout (java.awt.BorderLayout)1 Color (java.awt.Color)1 Component (java.awt.Component)1 Dimension (java.awt.Dimension)1 FlowLayout (java.awt.FlowLayout)1 Font (java.awt.Font)1 GridBagLayout (java.awt.GridBagLayout)1 Paint (java.awt.Paint)1 Point (java.awt.Point)1