@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)); } }
private void fillTable() { int i = 0; final int colorsPerRow = 2; for (Color c : cctrl.getUsableColors()) { Button bt = new Button(StyleHelper.getInstance().getDrawable("widgets/button")); ColorButton btn = new ColorButton(c); btn.addListener(new ColorButtonListener()); bt.add(btn).size(60, 60).center(); this.add(bt).size(76, 76).pad(6); i++; if (i % colorsPerRow == 0) { this.row(); } } }
/** * Adds color buttons to the specified panel. * * <p>This method will create a row containing the following items: * * <pre> * LABEL | COLOR (foreground) | COLOR (background) * </pre> * * @param gridPanel a 3 columns proportinal grid panel in which to add the buttons. * @param fontChooser used to decide which font to use in each color button's preview. * @param label label for the row. * @param foregroundId identifier of the color to display in the foreground button. * @param backgroundId identifier of the color to display in the background button. * @param comp component to register as a listener on the color buttons. */ protected PreviewLabel addColorButtons( ProportionalGridPanel gridPanel, FontChooser fontChooser, String label, int foregroundId, int backgroundId, JComponent comp) { ColorButton colorButton; PreviewLabel previewLabel; // Adds the row's caption label. gridPanel.add(createCaptionLabel(label)); // Initialises the color buttons' preview label. previewLabel = new PreviewLabel(); previewLabel.setTextPainted(true); addFontChooserListener(fontChooser, previewLabel); // Creates the foreground color button. gridPanel.add( colorButton = new ColorButton( parent, themeData, foregroundId, PreviewLabel.FOREGROUND_COLOR_PROPERTY_NAME, previewLabel)); if (comp != null) colorButton.addUpdatedPreviewComponent(comp); // Creates the background color button. gridPanel.add( colorButton = new ColorButton( parent, themeData, backgroundId, PreviewLabel.BACKGROUND_COLOR_PROPERTY_NAME, previewLabel)); if (comp != null) colorButton.addUpdatedPreviewComponent(comp); return previewLabel; }
public ColorSetupPanel(JCheckBox colorCodes, JCheckBox resolvedColorCodes, JCheckBox showGrid) { FormLayout layout = new FormLayout( "30dlu, 4dlu, fill:pref, 4dlu, fill:pref, 8dlu, 30dlu, 4dlu, fill:pref, 4dlu, fill:pref", "pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref"); FormBuilder builder = FormBuilder.create().layout(layout); buttons.add( new ColorButton(JabRefPreferences.TABLE_TEXT, Localization.lang("Table text color"))); buttons.add( new ColorButton( JabRefPreferences.MARKED_ENTRY_BACKGROUND0, Localization.lang("Marking color %0", "1"))); buttons.add( new ColorButton( JabRefPreferences.TABLE_BACKGROUND, Localization.lang("Table background color"))); buttons.add( new ColorButton( JabRefPreferences.MARKED_ENTRY_BACKGROUND1, Localization.lang("Marking color %0", "2"))); buttons.add( new ColorButton( JabRefPreferences.TABLE_REQ_FIELD_BACKGROUND, Localization.lang("Background color for required fields"), colorCodes)); buttons.add( new ColorButton( JabRefPreferences.MARKED_ENTRY_BACKGROUND2, Localization.lang("Marking color %0", "3"))); buttons.add( new ColorButton( JabRefPreferences.TABLE_OPT_FIELD_BACKGROUND, Localization.lang("Background color for optional fields"), colorCodes)); buttons.add( new ColorButton( JabRefPreferences.MARKED_ENTRY_BACKGROUND3, Localization.lang("Marking color %0", "4"))); buttons.add( new ColorButton( JabRefPreferences.INCOMPLETE_ENTRY_BACKGROUND, Localization.lang("Color for marking incomplete entries"))); buttons.add( new ColorButton( JabRefPreferences.MARKED_ENTRY_BACKGROUND4, Localization.lang("Marking color %0", "5"))); buttons.add( new ColorButton( JabRefPreferences.GRID_COLOR, Localization.lang("Table grid color"), showGrid)); buttons.add( new ColorButton( JabRefPreferences.MARKED_ENTRY_BACKGROUND5, Localization.lang("Import marking color"))); buttons.add( new ColorButton( JabRefPreferences.FIELD_EDITOR_TEXT_COLOR, Localization.lang("Entry editor font color"))); buttons.add( new ColorButton( JabRefPreferences.VALID_FIELD_BACKGROUND_COLOR, Localization.lang("Entry editor background color"))); buttons.add( new ColorButton( JabRefPreferences.ACTIVE_FIELD_EDITOR_BACKGROUND_COLOR, Localization.lang("Entry editor active background color"))); buttons.add( new ColorButton( JabRefPreferences.INVALID_FIELD_BACKGROUND_COLOR, Localization.lang("Entry editor invalid field color"))); buttons.add( new ColorButton( JabRefPreferences.TABLE_RESOLVED_FIELD_BACKGROUND, Localization.lang("Background color for resolved fields"), resolvedColorCodes)); int rowcnt = 0; int col = 0; int row; for (ColorButton but : buttons) { row = (2 * (rowcnt / 2)) + 1; // == 2*floor(rowcnt/2) + 1 builder.add((JButton) but).xy((6 * col) + 1, row); builder.add(but.getDefaultButton()).xy((6 * col) + 3, row); builder.add(but.getName()).xy((6 * col) + 5, row); but.addActionListener(new ColorButtonListener(but)); col = 1 - col; // Change 0 -> 1 -> 0 ... rowcnt++; } setLayout(new BorderLayout()); add(builder.getPanel(), BorderLayout.CENTER); setValues(); }
public void storeSettings() { for (ColorButton but : buttons) { Globals.prefs.putColor(but.getKey(), but.getColor()); } }
public void setValues() { for (ColorButton but : buttons) { but.setColor(Globals.prefs.getColor(but.getKey())); } }