Java Code Examples for javax.swing.colorchooser.ColorSelectionModel

The following examples show how to use javax.swing.colorchooser.ColorSelectionModel. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public void actionPerformed(ActionEvent e) {
	ColorSelectionModel model = getColorSelectionModel();

	System.out.println("COLORSELECTIONMODEL: " + model);

	String command = ((JToggleButton)e.getSource()).getActionCommand();
	for (ColorBrewer palette: ColorBrewer.getSequentialColorPalettes(isShowColorBlindSave())) {
		
		
		if (palette.name().equals(command)) {
			System.out.println(palette.name() + " comm:" + command);
			((ColorPanelSelectionModel) model).setColorBrewer(palette);
			break;
		}
	}
}
 
Example 2
Source Project: darklaf   Source File: DarkSwatchesChooserPanel.java    License: MIT License 5 votes vote down vote up
protected void setSelectedColor(final Color color) {
    ColorSelectionModel model = getColorSelectionModel();
    previewPanel.setColor(color);
    if (model != null) {
        model.setSelectedColor(color);
    }
}
 
Example 3
Source Project: darklaf   Source File: DarkColorChooserPanel.java    License: MIT License 5 votes vote down vote up
@Override
public void colorChanged(final Color color, final Object source) {
    if (isChanging || color == null) return;
    isChanging = true;
    currentColor = color;
    ColorSelectionModel model = getColorSelectionModel();
    if (model != null) model.setSelectedColor(currentColor);
    applyColorToFields(color);
    if (source != textHex) textHex.setValue(color);
    previewComponent.setColor(color);
    colorWheelPanel.setColor(color, this);
    isChanging = false;
}
 
Example 4
public void stateChanged( ChangeEvent e ) {
    ColorSelectionModel model = (ColorSelectionModel)e.getSource();
    if (previewPanel != null) {
        previewPanel.setForeground(model.getSelectedColor());
        previewPanel.repaint();
    }
}
 
Example 5
/**
 * Maps {@code JColorChooser.getSelectionModel()} through queue
 */
public ColorSelectionModel getSelectionModel() {
    return (runMapping(new MapAction<ColorSelectionModel>("getSelectionModel") {
        @Override
        public ColorSelectionModel map() {
            return ((JColorChooser) getSource()).getSelectionModel();
        }
    }));
}
 
Example 6
/**
 * Maps {@code JColorChooser.setSelectionModel(ColorSelectionModel)}
 * through queue
 */
public void setSelectionModel(final ColorSelectionModel colorSelectionModel) {
    runMapping(new MapVoidAction("setSelectionModel") {
        @Override
        public void map() {
            ((JColorChooser) getSource()).setSelectionModel(colorSelectionModel);
        }
    });
}
 
Example 7
Source Project: pumpernickel   Source File: PaletteUI.java    License: MIT License 5 votes vote down vote up
@Override
public void propertyChange(PropertyChangeEvent evt) {
	ColorSelectionModel oldModel = (ColorSelectionModel) evt
			.getOldValue();
	ColorSelectionModel newModel = (ColorSelectionModel) evt
			.getNewValue();
	if (oldModel != null)
		oldModel.removeChangeListener(colorSelectionListener);
	if (newModel != null)
		newModel.addChangeListener(colorSelectionListener);
}
 
Example 8
Source Project: binnavi   Source File: CColorChooser.java    License: Apache License 2.0 5 votes vote down vote up
public CColorChooser(final ColorSelectionModel model, final Color[] recentColors) {
  super(model);

  // Remove first chooser panel ("Swatches")
  // TODO(cblichmann): Revisit this for JDK > 1.7
  final AbstractColorChooserPanel[] panels = getChooserPanels();
  if (panels.length > 0) {
    removeChooserPanel(panels[0]);
  }

  m_recentColors = recentColors;
  if (m_recentColors != null) {
    addChooserPanel(new RecentColorsColorChooserPanel());
  }
}
 
Example 9
Source Project: PyramidShader   Source File: ColorButton.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 10
public void actionPerformed(ActionEvent e) {
	ColorSelectionModel model = getColorSelectionModel();

	String command = ((JToggleButton)e.getSource()).getActionCommand();
	for (ColorBrewer palette: ColorBrewer.getDivergingColorPalettes(isShowColorBlindSave())) {
		if (palette.name().equals(command)) {
			((ColorPanelSelectionModel) model).setColorBrewer(palette);
			break;
		}
	}
}
 
Example 11
public void actionPerformed(ActionEvent e) {
	ColorSelectionModel model = getColorSelectionModel();

	String command = ((JToggleButton)e.getSource()).getActionCommand();
	for (ColorBrewer palette: ColorBrewer.getQualitativeColorPalettes(isShowColorBlindSave())) {
		if (palette.name().equals(command)) {
			((ColorPanelSelectionModel) model).setColorBrewer(palette);
			break;
		}
	}
}
 
Example 12
Source Project: jclic   Source File: AlphaColorChooserPanel.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void alphaSliderStateChanged(javax.swing.event.ChangeEvent evt) { // GEN-FIRST:event_alphaSliderStateChanged

    int v = alphaSlider.getValue();
    alphaTxt.setText(Integer.toString(v));

    ColorSelectionModel csm = getColorSelectionModel();
    if (csm != null) {
      Color c = csm.getSelectedColor();
      Color nc = v < 255 ? new Color(c.getRed(), c.getGreen(), c.getBlue(), v)
          : new Color(c.getRed(), c.getGreen(), c.getBlue());
      csm.setSelectedColor(nc);
    }
  }
 
Example 13
/**
 * An implemented <code>ItemListener</code> to change colors when user changes value in the <code>comboBox</code>.
 * 
 * @param itemEvent	the received event
 * 
 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
 */
public void itemStateChanged(ItemEvent itemEvent) {
	int state = itemEvent.getStateChange();
	if (state == ItemEvent.SELECTED) {
		int position = findColorLabel(itemEvent.getItem());
		if (position != -1) {
			ColorSelectionModel selectionModel = getColorSelectionModel();
			selectionModel.setSelectedColor(COLORS[position]);
		}
	}
}
 
Example 14
public void setColorToModel(Color color) {
	ColorSelectionModel colorSelectionModel = getColorSelectionModel();
	if (colorSelectionModel != null) {
		colorSelectionModel.setSelectedColor(color);
	}
}
 
Example 15
Source Project: pumpernickel   Source File: JColorWell.java    License: MIT License 4 votes vote down vote up
public void setColorSelectionModel(ColorSelectionModel colorSelectionModel) {
	Objects.requireNonNull(colorSelectionModel);
	putClientProperty(KEY_COLOR_SELECTION_MODEL, colorSelectionModel);
}
 
Example 16
Source Project: pumpernickel   Source File: JColorWell.java    License: MIT License 4 votes vote down vote up
public ColorSelectionModel getColorSelectionModel() {
	return (ColorSelectionModel) getClientProperty(KEY_COLOR_SELECTION_MODEL);
}
 
Example 17
Source Project: pumpernickel   Source File: JPalette.java    License: MIT License 4 votes vote down vote up
public void setColorSelectionModel(ColorSelectionModel model) {
	Objects.requireNonNull(model);
	putClientProperty(PROPERTY_SELECTION_MODEL, model);
}
 
Example 18
Source Project: pumpernickel   Source File: JPalette.java    License: MIT License 4 votes vote down vote up
public ColorSelectionModel getColorSelectionModel() {
	return (ColorSelectionModel) getClientProperty(
			PROPERTY_SELECTION_MODEL);
}
 
Example 19
Source Project: binnavi   Source File: CColorChooser.java    License: Apache License 2.0 4 votes vote down vote up
public CColorChooser(final ColorSelectionModel model) {
  this(model, null);
}
 
Example 20
Source Project: weblaf   Source File: WebColorChooser.java    License: GNU General Public License v3.0 2 votes vote down vote up
/**
 * Constructs new color chooser.
 *
 * @param model color selection model
 */
public WebColorChooser ( final ColorSelectionModel model )
{
    this ( StyleId.auto, model );
}
 
Example 21
Source Project: weblaf   Source File: WebColorChooser.java    License: GNU General Public License v3.0 2 votes vote down vote up
/**
 * Constructs new color chooser.
 *
 * @param id    {@link StyleId}
 * @param model color selection model
 */
public WebColorChooser ( final StyleId id, final ColorSelectionModel model )
{
    super ( model );
    setStyleId ( id );
}