public static void fixOsxColorChooser(JColorChooser chooser) { if(!UIManager.getLookAndFeel().getName().equals("Mac OS X")) return; AbstractColorChooserPanel[] panels = chooser.getChooserPanels(); for(JPanel p : panels) { if(p!=null) { p.setOpaque(false); ((JComponent) p.getParent()).setOpaque(false); for(Component c : p.getComponents()) { ((JComponent) c).setBorder(null); ((JComponent) c).setOpaque(false); } } } }
public static Color showDialog(Component component, String title, Color initial) { JColorChooser choose = new JColorChooser(initial); JDialog dialog = createDialog(component, title, true, choose, null, null); AbstractColorChooserPanel[] panels = choose.getChooserPanels(); for (AbstractColorChooserPanel accp : panels) { choose.removeChooserPanel(accp); } GrayScaleSwatchChooserPanel grayScaleSwatchChooserPanelFreeStyle = new GrayScaleSwatchChooserPanel(); GrayScalePanel grayScalePanelFreeStyle = new GrayScalePanel(); choose.addChooserPanel(grayScaleSwatchChooserPanelFreeStyle); choose.addChooserPanel(grayScalePanelFreeStyle); dialog.getContentPane().add(choose); dialog.pack(); dialog.setVisible(true);//.show(); return choose.getColor(); }
public static void main(String[] args) throws Exception { JColorChooser chooser = new JColorChooser(); AbstractColorChooserPanel[] panels = chooser.getChooserPanels(); chooser.setChooserPanels(new AbstractColorChooserPanel[] { panels[1] }); JDialog dialog = show(chooser); pause(DELAY); dialog.dispose(); pause(DELAY); Test4177735 test = new Test4177735(); SwingUtilities.invokeAndWait(test); if (test.count != 0) { throw new Error("JColorChooser leaves " + test.count + " threads running"); } }
/** * This method sets the chooserPanels property for this JColorChooser. * * @param panels The new set of AbstractColorChooserPanels to use. */ public void setChooserPanels(AbstractColorChooserPanel[] panels) { if (panels != chooserPanels) { if (chooserPanels != null) for (int i = 0; i < chooserPanels.length; i++) if (chooserPanels[i] != null) chooserPanels[i].uninstallChooserPanel(this); AbstractColorChooserPanel[] old = chooserPanels; chooserPanels = panels; if (panels != null) for (int i = 0; i < panels.length; i++) if (panels[i] != null) panels[i].installChooserPanel(this); firePropertyChange(CHOOSER_PANELS_PROPERTY, old, chooserPanels); } }
private void addColorChooser() { // remove unwanted, extra color chooser features like other color // options and preview AbstractColorChooserPanel[] panels = chooser.getChooserPanels(); AbstractColorChooserPanel[] newPanels = { panels[0] }; chooser.setChooserPanels(newPanels); // customize preview panel JLabel preview = new JLabel("\u25FC\u25FC\u25FC\u25FC\u25FC", JLabel.CENTER); preview.setFont(new Font("Serif", Font.BOLD, 18)); chooser.setPreviewPanel(preview); chooser.getSelectionModel().addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { canvas.updateColor(chooser.getColor()); } }); southPanel.add(chooser, BorderLayout.WEST); }
private void setColorChooserDialog() { jColorChooser.setPreviewPanel(new JPanel()); AbstractColorChooserPanel[] panels = jColorChooser.getChooserPanels(); for (AbstractColorChooserPanel p : panels) { String displayName = p.getDisplayName(); switch (displayName.toUpperCase()) { case "HSV": jColorChooser.removeChooserPanel(p); break; case "HSL": jColorChooser.removeChooserPanel(p); break; case "CMYK": jColorChooser.removeChooserPanel(p); break; case "SWATCHES": jColorChooser.removeChooserPanel(p); break; } } }
private JColorChooser createSwatchColorChooser() { final JColorChooser chooser = new JColorChooser(); AbstractColorChooserPanel swatchPanel = chooser.getChooserPanels()[0]; for (AbstractColorChooserPanel panel : chooser.getChooserPanels()) { if (panel != swatchPanel) { // Swatch panel chooser.removeChooserPanel(panel); } } chooser.setPreviewPanel(new JPanel()); chooser.getSelectionModel().addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { setPaint(chooser.getColor()); hueColorChooser.setColor(chooser.getColor()); rgbColorChooser.setColor(chooser.getColor()); } }); return chooser; }
private JColorChooser createHueColorChooser() { final JColorChooser chooser = new JColorChooser(); AbstractColorChooserPanel hsvPanel = chooser.getChooserPanels()[1]; for (AbstractColorChooserPanel panel : chooser.getChooserPanels()) { if (panel != hsvPanel) { // Hue panel chooser.removeChooserPanel(panel); } } chooser.setPreviewPanel(new JPanel()); chooser.getSelectionModel().addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { setPaint(chooser.getColor()); swatchColorChooser.setColor(chooser.getColor()); rgbColorChooser.setColor(chooser.getColor()); } }); return chooser; }
private JColorChooser createRGBColorChooser() { final JColorChooser chooser = new JColorChooser(); AbstractColorChooserPanel rgbPanel; if (chooser.getChooserPanels().length > 3) { rgbPanel = chooser.getChooserPanels()[3]; } else { rgbPanel = chooser.getChooserPanels()[2]; } for (AbstractColorChooserPanel panel : chooser.getChooserPanels()) { if (panel != rgbPanel) { // RGB panel chooser.removeChooserPanel(panel); } } chooser.setPreviewPanel(new JPanel()); chooser.getSelectionModel().addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { setPaint(chooser.getColor()); swatchColorChooser.setColor(chooser.getColor()); hueColorChooser.setColor(chooser.getColor()); } }); return chooser; }
public AbstractColorChooserPanel removeChooserPanel(AbstractColorChooserPanel panel) { AbstractColorChooserPanel panelToRemove = null; int index = 0; for (int i = 0; i < chooserPanels.length; i++) { if (panel.equals(chooserPanels[i])) { panelToRemove = chooserPanels[i]; index = i; break; } } if (panelToRemove == null) { throw new IllegalArgumentException(Messages.getString("swing.0A")); //$NON-NLS-1$ } AbstractColorChooserPanel[] newChooserPanels = new AbstractColorChooserPanel[chooserPanels.length - 1]; System.arraycopy(chooserPanels, 0, newChooserPanels, 0, index); System.arraycopy(chooserPanels, index + 1, newChooserPanels, index, newChooserPanels.length - index); setChooserPanels(newChooserPanels); return panelToRemove; }
public void testUninstallDefaultChoosers() throws Exception { assertEquals(2, ch.getComponentCount()); assertNotNull(findComponent(ch, JTabbedPane.class, true)); assertEquals(3, ((JTabbedPane) findComponent(ch, JTabbedPane.class, true)) .getTabCount()); ch.removeChooserPanel(ch.getChooserPanels()[0]); assertEquals(2, ch.getComponentCount()); assertNotNull(findComponent(ch, JTabbedPane.class, true)); assertEquals(2, ((JTabbedPane) findComponent(ch, JTabbedPane.class, true)) .getTabCount()); ch.removeChooserPanel(ch.getChooserPanels()[0]); assertEquals(2, ch.getComponentCount()); assertNull(findComponent(ch, JTabbedPane.class, true)); ch.removeChooserPanel(ch.getChooserPanels()[0]); assertEquals(2, ch.getComponentCount()); assertNull(findComponent(ch, JTabbedPane.class, true)); ui.defaultChoosers = new AbstractColorChooserPanel[0]; ui.uninstallDefaultChoosers(); assertEquals(2, ch.getComponentCount()); assertNull(findComponent(ch, JTabbedPane.class, true)); }
/** * Creates a new instance of ColorButton. Default color is black, default * size of the icon is 16 x 16 pixels. This button is registered with itself * for receiving action performed calls. */ public ColorButton() { this.color = new Color(0, 0, 0); this.iconHeight = 16; this.iconWidth = 16; this.colorChooserTitle = "Choose a Color"; //Set up the dialog that the button brings up. colorChooser = new JColorChooser(); // replace the ugly and useless preview panel by an empty JPanel colorChooser.setPreviewPanel(new JPanel()); // remove the swatch AbstractColorChooserPanel[] choosers = colorChooser.getChooserPanels(); for (AbstractColorChooserPanel chooser : choosers) { String clsName = chooser.getClass().getName(); if (clsName.equals("javax.swing.colorchooser.DefaultSwatchChooserPanel")) { colorChooser.removeChooserPanel(chooser); } } ColorSelectionModel colorSelectionModel = colorChooser.getSelectionModel(); colorSelectionModel.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent evt) { ColorSelectionModel model = (ColorSelectionModel) evt.getSource(); setColor(model.getSelectedColor()); } }); this.updateIcon(); }
public static AbstractColorChooserPanel findPanel(JColorChooser chooser, String name) { AbstractColorChooserPanel[] panels = chooser.getChooserPanels(); for (int i = 0; i < panels.length; i++) { String clsName = panels[i].getClass().getName(); if (clsName.equals(name)) { return panels[i]; } } return null; }
/** * Constructs * * @param objPcontrolJFrame * @param objPpreferencesJDialog * @param bytPcolorPreferenceType */ public PreferencesJColorChooser(ControlJFrame objPcontrolJFrame, PreferencesJDialog objPpreferencesJDialog, byte bytPcolorPreferenceType) { // Init panels : this.objGcontrolJFrame = objPcontrolJFrame; this.objGpreferencesJDialog = objPpreferencesJDialog; this.bytGcolorPreferenceType = bytPcolorPreferenceType; this.setOpaque(true); this.setColor(Tools.getPenColor(this.objGpreferencesJDialog.strGstringLocalAA[this.bytGcolorPreferenceType][Constants.bytS_UNCLASS_TEMPORARY_CURRENT])); this.setPreviewPanel(new JPanel()); final AbstractColorChooserPanel[] objLabstractColorChooserPanelA = this.getChooserPanels(); for (final AbstractColorChooserPanel objLabstractColorChooserPanel : objLabstractColorChooserPanelA) { if (!objLabstractColorChooserPanel.getClass().getName().equals("javax.swing.colorchooser.DefaultHSBChooserPanel")) { this.removeChooserPanel(objLabstractColorChooserPanel); } } // Actions.doSetFont(this, this.objGcontrolJFrame.getFont()); // Init listeners : this.getSelectionModel().addChangeListener(this); this.objGoKActionListener = new PreferencesJColorChooserJDialogListener(this.objGpreferencesJDialog, this, this.bytGcolorPreferenceType, true); this.objGcancelActionListener = new PreferencesJColorChooserJDialogListener(this.objGpreferencesJDialog, this, this.bytGcolorPreferenceType, false); }
final public void setPopUp() { if (this.objGjWindow != null) { this.objGjWindow.dispose(); } this.objGjWindow = new JWindow(this.objGcontrolJFrame.getJuggleMasterPro().getFrame()); switch (this.bytGlocalStringType) { case Constants.bytS_STRING_LOCAL_JUGGLER_DAY: case Constants.bytS_STRING_LOCAL_SITESWAP_DAY: case Constants.bytS_STRING_LOCAL_BACKGROUND_DAY: this.objGjColorChooser = new JColorChooser(); final AbstractColorChooserPanel[] objLabstractColorChooserPanelA = this.objGjColorChooser.getChooserPanels(); for (final AbstractColorChooserPanel objLabstractColorChooserPanel : objLabstractColorChooserPanelA) { // if // (objLabstractColorChooserPanel.getClass().getName().equals("javax.swing.colorchooser.DefaultHSBChooserPanel")) // { if (objLabstractColorChooserPanel.getClass().getName().equals("javax.swing.colorchooser.DefaultSwatchChooserPanel")) { objLabstractColorChooserPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); this.objGjWindow.add(objLabstractColorChooserPanel); break; } } break; case Constants.bytS_STRING_LOCAL_COLORS: this.setBallsColorsPopUp(); //$FALL-THROUGH$ default: this.objGjColorChooser = null; break; } this.objGjWindow.pack(); this.objGjWindow.setLocation( (int) Constants.objS_GRAPHICS_TOOLKIT.getScreenSize().getWidth(), (int) Constants.objS_GRAPHICS_TOOLKIT.getScreenSize().getHeight()); }
public static void main(String[] args) throws Exception { int hsvIndex = 0; int panelsLength; int finalIndex; JColorChooser chooser = new JColorChooser(); AbstractColorChooserPanel[] panels = chooser.getChooserPanels(); panelsLength = panels.length; for(int i = 0; i < panelsLength; i++) { if(panels[i].getDisplayName().equals("HSV")) { hsvIndex = i; } } finalIndex = Math.min(hsvIndex, panelsLength - 1); chooser.setChooserPanels(new AbstractColorChooserPanel[] { panels[finalIndex] }); JDialog dialog = show(chooser); pause(DELAY); dialog.dispose(); pause(DELAY); Test4177735 test = new Test4177735(); SwingUtilities.invokeAndWait(test); if (test.count != 0) { throw new Error("JColorChooser leaves " + test.count + " threads running"); } }
private static void testColorPanels() throws Exception { SwingUtilities.invokeAndWait(() -> createAndShowGUI()); Robot robot = new Robot(); robot.setAutoDelay(50); robot.waitForIdle(); for (String[] tabs : TABS) { final String tab = tabs[0]; final String initialValue = tabs[1]; SwingUtilities.invokeAndWait(() -> { colorChooser.setColor(new Color(50, 100, 85)); JTabbedPane tabbedPane = (JTabbedPane) findComponent(colorChooser, "JTabbedPane"); int index = tabbedPane.indexOfTab(tab); tabbedPane.setSelectedIndex(index); AbstractColorChooserPanel colorChooserPanel = (AbstractColorChooserPanel) findComponent( tabbedPane.getComponent(index), "ColorChooserPanel"); propertyChangeListenerInvoked = false; colorChooserPanel.addPropertyChangeListener((e) -> { if (AbstractColorChooserPanel.TRANSPARENCY_ENABLED_PROPERTY. equals(e.getPropertyName())) { propertyChangeListenerInvoked = true; if(!(Boolean)e.getOldValue()){ throw new RuntimeException("Old color transparency" + " selection property should be true!"); } if((Boolean)e.getNewValue()){ throw new RuntimeException("New color transparency" + " selection property should be false!"); } } }); if (!colorChooserPanel.isColorTransparencySelectionEnabled()) { throw new RuntimeException("Color transparency selection" + " should be enabled by default"); } JFormattedTextField transparencyTextField = (JFormattedTextField) findTextField(colorChooserPanel, initialValue); if (!transparencyTextField.isEnabled()) { throw new RuntimeException("Transparency controls are" + " disabled by default!"); } transparencyTextField.setValue(50); if(!colorHasAlpha()){ throw new RuntimeException("Transparency selection should" + " be enabled!"); } colorChooserPanel.setColorTransparencySelectionEnabled(false); if (colorChooserPanel.isColorTransparencySelectionEnabled()) { throw new RuntimeException("Color transparency selection" + " should be disabled!"); } if(!propertyChangeListenerInvoked){ throw new RuntimeException("Property change listener is not" + " invoked!"); } if(colorHasAlpha()){ throw new RuntimeException("Transparency selection should" + " be disabled!"); } }); robot.waitForIdle(); } }
/** * Maps * {@code JColorChooser.addChooserPanel(AbstractColorChooserPanel)} * through queue */ public void addChooserPanel(final AbstractColorChooserPanel abstractColorChooserPanel) { runMapping(new MapVoidAction("addChooserPanel") { @Override public void map() { ((JColorChooser) getSource()).addChooserPanel(abstractColorChooserPanel); } }); }
/** * Maps {@code JColorChooser.getChooserPanels()} through queue */ public AbstractColorChooserPanel[] getChooserPanels() { return ((AbstractColorChooserPanel[]) runMapping(new MapAction<Object>("getChooserPanels") { @Override public Object map() { return ((JColorChooser) getSource()).getChooserPanels(); } })); }
/** * Maps * {@code JColorChooser.removeChooserPanel(AbstractColorChooserPanel)} * through queue */ public AbstractColorChooserPanel removeChooserPanel(final AbstractColorChooserPanel abstractColorChooserPanel) { return (runMapping(new MapAction<AbstractColorChooserPanel>("removeChooserPanel") { @Override public AbstractColorChooserPanel map() { return ((JColorChooser) getSource()).removeChooserPanel(abstractColorChooserPanel); } })); }
/** * Maps * {@code JColorChooser.setChooserPanels(AbstractColorChooserPanel[])} * through queue */ public void setChooserPanels(final AbstractColorChooserPanel[] abstractColorChooserPanel) { runMapping(new MapVoidAction("setChooserPanels") { @Override public void map() { ((JColorChooser) getSource()).setChooserPanels(abstractColorChooserPanel); } }); }