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();
}
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");
}
}
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);
}
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();
}
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);
}
Aggregations