package ij.gui;
import ij.*;
import ij.process.*;
import ij.util.*;
import ij.plugin.Colors;
import java.awt.*;
import java.util.Vector;
import java.awt.event.*;
/** Displays a dialog that allows the user to select a color using three sliders. */
public class ColorChooser implements TextListener, AdjustmentListener {
Vector colors, sliders;
ColorPanel panel;
Color initialColor;
int red, green, blue;
boolean useHSB;
String title;
Frame frame;
/** Constructs a ColorChooser using the specified title and initial color. */
public ColorChooser(String title, Color initialColor, boolean useHSB) {
this(title, initialColor, useHSB, null);
}
public ColorChooser(String title, Color initialColor, boolean useHSB, Frame frame) {
this.title = title;
if (initialColor==null) initialColor = Color.black;
this.initialColor = initialColor;
red = initialColor.getRed();
green = initialColor.getGreen();
blue = initialColor.getBlue();
this.useHSB = useHSB;
this.frame = frame;
}
/** Displays a color selection dialog and returns the color selected by the user. */
public Color getColor() {
GenericDialog gd = frame!=null?new GenericDialog(title, frame):new GenericDialog(title);
gd.addSlider("Red:", 0, 255, red);
gd.addSlider("Green:", 0, 255, green);
gd.addSlider("Blue:", 0, 255, blue);
panel = new ColorPanel(initialColor);
gd.addPanel(panel, GridBagConstraints.CENTER, new Insets(10, 0, 0, 0));
colors = gd.getNumericFields();
for (int i=0; i255) red=255;
if (green<0) green=0; if (green>255) green=255;
if (blue<0) blue=0; if (blue>255) blue=255;
panel.setColor(new Color(red, green, blue));
panel.repaint();
}
public synchronized void adjustmentValueChanged(AdjustmentEvent e) {
Object source = e.getSource();
for (int i=0; i
Ads help maintain this website.