6 import ij.plugin.filter.*;
8 import java.awt.event.*;
9 import java.util.Vector;
13 private String[] colors = {
"red",
"green",
"blue",
"magenta ",
"cyan",
"yellow",
"orange",
"black",
"white"};
14 private Choice fchoice, bchoice, schoice;
15 private Color fc2, bc2, sc2;
17 public void run(String arg) {
22 Color fc =Toolbar.getForegroundColor();
23 String fname = getColorName(fc,
"black");
24 Color bc =Toolbar.getBackgroundColor();
25 String bname = getColorName(bc,
"white");
26 Color sc =Roi.getColor();
27 String sname = getColorName(sc,
"yellow");
28 GenericDialog gd =
new GenericDialog(
"Colors");
29 gd.addChoice(
"Foreground:", colors, fname);
30 gd.addChoice(
"Background:", colors, bname);
31 gd.addChoice(
"Selection:", colors, sname);
32 Vector choices = gd.getChoices();
33 fchoice = (Choice)choices.elementAt(0);
34 bchoice = (Choice)choices.elementAt(1);
35 schoice = (Choice)choices.elementAt(2);
36 fchoice.addItemListener(
this);
37 bchoice.addItemListener(
this);
38 schoice.addItemListener(
this);
41 if (gd.wasCanceled()) {
42 if (fc2!=fc) Toolbar.setForegroundColor(fc);
43 if (bc2!=bc) Toolbar.setBackgroundColor(bc);
47 if (imp!=null && imp.getRoi()!=null) imp.
draw();
51 fname = gd.getNextChoice();
52 bname = gd.getNextChoice();
53 sname = gd.getNextChoice();
54 fc2 = getColor(fname, Color.black);
55 bc2 = getColor(bname, Color.white);
56 sc2 = getColor(sname, Color.yellow);
57 if (fc2!=fc) Toolbar.setForegroundColor(fc2);
58 if (bc2!=bc) Toolbar.setBackgroundColor(bc2);
61 ImagePlus imp = IJ.getInstance().getImagePlus();
62 if (imp!=null) imp.
draw();
66 String getColorName(Color c, String defaultName) {
67 String name = defaultName;
68 if (c.equals(Color.red)) name = colors[0];
69 else if (c.equals(Color.green)) name = colors[1];
70 else if (c.equals(Color.blue)) name = colors[2];
71 else if (c.equals(Color.magenta)) name = colors[3];
72 else if (c.equals(Color.cyan)) name = colors[4];
73 else if (c.equals(Color.yellow)) name = colors[5];
74 else if (c.equals(Color.orange)) name = colors[6];
75 else if (c.equals(Color.black)) name = colors[7];
76 else if (c.equals(Color.white)) name = colors[8];
80 Color getColor(String name, Color defaultColor) {
81 Color c = defaultColor;
82 if (name.equals(colors[0])) c = Color.red;
83 else if (name.equals(colors[1])) c = Color.green;
84 else if (name.equals(colors[2])) c = Color.blue;
85 else if (name.equals(colors[3])) c = Color.magenta;
86 else if (name.equals(colors[4])) c = Color.cyan;
87 else if (name.equals(colors[5])) c = Color.yellow;
88 else if (name.equals(colors[6])) c = Color.orange;
89 else if (name.equals(colors[7])) c = Color.black;
90 else if (name.equals(colors[8])) c = Color.white;
94 public void itemStateChanged(ItemEvent e) {
95 Choice choice = (Choice)e.getSource();
96 String item = choice.getSelectedItem();
97 Color color = getColor(item, Color.black);
99 Toolbar.setForegroundColor(color);
100 else if (choice==bchoice)
101 Toolbar.setBackgroundColor(color);
102 else if (choice==schoice) {
104 ImagePlus imp = IJ.getInstance().getImagePlus();
105 if (imp!=null && imp.getRoi()!=null) imp.draw();