Search in sources :

Example 11 with JColorChooser

use of javax.swing.JColorChooser in project hid-serial by rayshobby.

the class G4P 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 = (sketchApplet == null) ? null : sketchApplet.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 12 with JColorChooser

use of javax.swing.JColorChooser in project jdk8u_jdk by JetBrains.

the class InsetsEncapsulation method run.

@Override
public void run() {
    runTest(new JLabel("hi"));
    runTest(new JMenu());
    runTest(new JTree());
    runTest(new JTable());
    runTest(new JMenuItem());
    runTest(new JCheckBoxMenuItem());
    runTest(new JToggleButton());
    runTest(new JSpinner());
    runTest(new JSlider());
    runTest(Box.createVerticalBox());
    runTest(Box.createHorizontalBox());
    runTest(new JTextField());
    runTest(new JTextArea());
    runTest(new JTextPane());
    runTest(new JPasswordField());
    runTest(new JFormattedTextField());
    runTest(new JEditorPane());
    runTest(new JButton());
    runTest(new JColorChooser());
    runTest(new JFileChooser());
    runTest(new JCheckBox());
    runTest(new JInternalFrame());
    runTest(new JDesktopPane());
    runTest(new JTableHeader());
    runTest(new JLayeredPane());
    runTest(new JRootPane());
    runTest(new JMenuBar());
    runTest(new JOptionPane());
    runTest(new JRadioButton());
    runTest(new JRadioButtonMenuItem());
    runTest(new JPopupMenu());
    runTest(new JScrollBar());
    runTest(new JScrollPane());
    runTest(new JViewport());
    runTest(new JSplitPane());
    runTest(new JTabbedPane());
    runTest(new JToolBar());
    runTest(new JSeparator());
    runTest(new JProgressBar());
    if (!failures.isEmpty()) {
        System.out.println("These classes failed");
        for (final Component failure : failures) {
            System.out.println(failure.getClass());
        }
        throw new RuntimeException("Test failed");
    }
}
Also used : JDesktopPane(javax.swing.JDesktopPane) JTextArea(javax.swing.JTextArea) JRadioButton(javax.swing.JRadioButton) JLayeredPane(javax.swing.JLayeredPane) JTabbedPane(javax.swing.JTabbedPane) JButton(javax.swing.JButton) JProgressBar(javax.swing.JProgressBar) JTableHeader(javax.swing.table.JTableHeader) JTextField(javax.swing.JTextField) JSeparator(javax.swing.JSeparator) JScrollBar(javax.swing.JScrollBar) JTextPane(javax.swing.JTextPane) JToggleButton(javax.swing.JToggleButton) JSlider(javax.swing.JSlider) JMenuItem(javax.swing.JMenuItem) JComponent(javax.swing.JComponent) Component(java.awt.Component) JScrollPane(javax.swing.JScrollPane) JViewport(javax.swing.JViewport) JFormattedTextField(javax.swing.JFormattedTextField) JLabel(javax.swing.JLabel) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) JToolBar(javax.swing.JToolBar) JOptionPane(javax.swing.JOptionPane) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) JPopupMenu(javax.swing.JPopupMenu) JCheckBox(javax.swing.JCheckBox) JTree(javax.swing.JTree) JFileChooser(javax.swing.JFileChooser) JPasswordField(javax.swing.JPasswordField) JTable(javax.swing.JTable) JEditorPane(javax.swing.JEditorPane) JSpinner(javax.swing.JSpinner) JRootPane(javax.swing.JRootPane) JSplitPane(javax.swing.JSplitPane) JColorChooser(javax.swing.JColorChooser) JInternalFrame(javax.swing.JInternalFrame) JMenu(javax.swing.JMenu) JMenuBar(javax.swing.JMenuBar)

Example 13 with JColorChooser

use of javax.swing.JColorChooser in project jdk8u_jdk by JetBrains.

the class Test6199676 method run.

public synchronized void run() {
    if (this.chooser == null) {
        this.chooser = new JColorChooser();
        JFrame frame = new JFrame(getClass().getName());
        frame.add(this.chooser);
        frame.setVisible(true);
    } else if (this.updated) {
        if (isShowing(this.chooser.getPreviewPanel())) {
            exit("custom preview panel is showing");
        }
        exit(null);
    } else {
        Component component = this.chooser.getPreviewPanel();
        if (component == null) {
            component = getPreview(this.chooser);
        }
        if (!isShowing(component)) {
            exit("default preview panel is not showing");
        }
        this.updated = true;
        this.chooser.setPreviewPanel(new JPanel());
    }
    LookAndFeelInfo[] infos = UIManager.getInstalledLookAndFeels();
    LookAndFeelInfo info = infos[++this.index % infos.length];
    try {
        UIManager.setLookAndFeel(info.getClassName());
    } catch (Exception exception) {
        exit("could not change L&F");
    }
    SwingUtilities.updateComponentTreeUI(this.chooser);
    SwingUtilities.invokeLater(this);
}
Also used : JPanel(javax.swing.JPanel) LookAndFeelInfo(javax.swing.UIManager.LookAndFeelInfo) JFrame(javax.swing.JFrame) Component(java.awt.Component) JColorChooser(javax.swing.JColorChooser)

Example 14 with JColorChooser

use of javax.swing.JColorChooser 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)

Example 15 with JColorChooser

use of javax.swing.JColorChooser in project jdk8u_jdk by JetBrains.

the class Test6559154 method run.

public void run() {
    Timer timer = new Timer(1000, this);
    timer.setRepeats(false);
    timer.start();
    JColorChooser chooser = new JColorChooser();
    setEnabledRecursive(chooser, false);
    this.dialog = new JDialog();
    this.dialog.add(chooser);
    this.dialog.setVisible(true);
}
Also used : Timer(javax.swing.Timer) JColorChooser(javax.swing.JColorChooser) JDialog(javax.swing.JDialog)

Aggregations

JColorChooser (javax.swing.JColorChooser)21 JDialog (javax.swing.JDialog)7 JLabel (javax.swing.JLabel)6 JButton (javax.swing.JButton)5 Component (java.awt.Component)4 JFrame (javax.swing.JFrame)4 JPanel (javax.swing.JPanel)4 JCheckBox (javax.swing.JCheckBox)3 AbstractColorChooserPanel (javax.swing.colorchooser.AbstractColorChooserPanel)3 Color (java.awt.Color)2 Frame (java.awt.Frame)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 ArrayList (java.util.ArrayList)2 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)2 JComponent (javax.swing.JComponent)2 JDesktopPane (javax.swing.JDesktopPane)2 JEditorPane (javax.swing.JEditorPane)2 JFileChooser (javax.swing.JFileChooser)2 JFormattedTextField (javax.swing.JFormattedTextField)2