4 import ij.plugin.frame.*;
6 import java.awt.event.*;
7 import java.util.Vector;
15 private static JFrame instance;
17 public void run(String arg) {
22 int width = columns*colorWidth;
23 int height = rows*colorHeight;
24 ColorGenerator cg =
new ColorGenerator(width, height,
new int[width*height],
this);
25 cg.drawColors(colorWidth, colorHeight, columns, rows);
34 if (img==null && ip!=null)
35 img = ip.createImage();
44 int[] colors = {0xff0000, 0x00ff00, 0x0000ff, 0xffffff, 0x00ffff, 0xff00ff, 0xffff00, 0x000000};
46 public ColorGenerator(
int width,
int height,
int[] pixels, ImagePlus imp) {
47 super(width, height, pixels);
50 void drawColors(
int colorWidth,
int colorHeight,
int columns,
int rows) {
67 float hue, saturation=1f, brightness=1f;
68 double w=colorWidth, h=colorHeight;
69 for ( x=2; x<10; x++) {
70 for ( y=0; y<32; y++) {
71 hue = (float)(y/(2*h)-.15);
74 brightness = (float)(x*4/w);
76 saturation = 1f - ((float)((5-x)*-4/w));
79 c = Color.getHSBColor(hue, saturation, brightness);
80 setRoi(x*(
int)(w/2), y*(
int)(h/2), (
int)w/2, (
int)h/2);
89 void drawColor(
int x,
int y, Color c)
96 public void refreshBackground() {
99 drawRect((w*2)-12, 276, (w*2)+4, (h*2)+4);
101 drawRect((w*2)-11, 277, (w*2)+2, (h*2)+2);
102 setRoi((w*2)-10, 278, w*2, h*2);
103 setColor(Toolbar.getBackgroundColor());
108 public void refreshForeground() {
114 setRoi(10, 268, w*2, h*2);
115 setColor(Toolbar.getForegroundColor());
120 void drawSpectrum(
double h) {
122 for (
int x=5; x<7; x++) {
123 for (
int y=0; y<32; y++) {
124 float hue = (float)(y/(2*h)-.15);
125 c = Color.getHSBColor(hue, 1f, 1f);
126 setRoi(x*(
int)(w/2), y*(
int)(h/2), (
int)w/2, (
int)h/2);
153 for (
int x=0; x<w; x++) {
154 for (
double y=0; y<(h*16); y++) {
156 pixels[(int)y*width+x] = 0xff000000 | ((r<<16)&0xff0000) | ((g<<8)&0xff00) | (b&0xff);
187 class ColorCanvas
extends ImageCanvas {
190 boolean background =
false;
193 public ColorCanvas(ImagePlus imp) {
197 public void mousePressed(MouseEvent e) {
199 ImageProcessor ip = imp.getProcessor();
202 Rectangle flipperRect =
new Rectangle(86, 268, 18, 18);
203 Rectangle resetRect =
new Rectangle(86, 294, 18, 18);
204 Rectangle foreground1Rect =
new Rectangle(9, 266, 45, 10);
205 Rectangle foreground2Rect =
new Rectangle(9, 276, 23, 25);
206 Rectangle background1Rect =
new Rectangle(33, 302, 45, 10);
207 Rectangle background2Rect =
new Rectangle(56, 277, 23, 25);
208 int x = offScreenX(e.getX());
209 int y = offScreenY(e.getY());
210 long difference = System.currentTimeMillis()-mouseDownTime;
211 boolean doubleClick = (difference<=250);
212 mouseDownTime = System.currentTimeMillis();
213 if (flipperRect.contains(x, y)) {
214 Color c = Toolbar.getBackgroundColor();
215 Toolbar.setBackgroundColor(Toolbar.getForegroundColor());
216 Toolbar.setForegroundColor(c);
217 }
else if(resetRect.contains(x,y)) {
218 Toolbar.setForegroundColor(
new Color(0x000000));
219 Toolbar.setBackgroundColor(
new Color(0xffffff));
220 }
else if ((background1Rect.contains(x,y)) || (background2Rect.contains(x,y))) {
222 if (doubleClick) editColor();
223 ((ColorGenerator)ip).refreshForeground();
224 ((ColorGenerator)ip).refreshBackground();
225 }
else if ((foreground1Rect.contains(x,y)) || (foreground2Rect.contains(x,y))) {
227 if (doubleClick) editColor();
228 ((ColorGenerator)ip).refreshBackground();
229 ((ColorGenerator)ip).refreshForeground();
235 setDrawingColor(offScreenX(e.getX()), offScreenY(e.getY()), background);
238 if (ip instanceof ColorGenerator) {
240 ((ColorGenerator)ip).refreshForeground();
241 ((ColorGenerator)ip).refreshBackground();
243 ((ColorGenerator)ip).refreshBackground();
244 ((ColorGenerator)ip).refreshForeground();
250 Color c = background?Toolbar.getBackgroundColor():Toolbar.getForegroundColor();
251 ColorChooser cc =
new ColorChooser((background?
"Background":
"Foreground")+
" Color", c,
false);
254 Toolbar.setBackgroundColor(c);
256 Toolbar.setForegroundColor(c);
259 public void refreshColors() {
260 ImageProcessor ip = imp.getProcessor();
261 ((ColorGenerator)ip).refreshBackground();
262 ((ColorGenerator)ip).refreshForeground();