Major cleanup of Utils class.
[trakem2.git] / ini / trakem2 / display / Channel.java
blob11c89da04282484a017cb48ddeb6d19193786f9c
1 /**
3 TrakEM2 plugin for ImageJ(C).
4 Copyright (C) 2005,2006 Albert Cardona and Rodney Douglas.
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation (http://www.gnu.org/licenses/gpl.txt )
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 You may contact Albert Cardona at acardona at ini.phys.ethz.ch
20 Institute of Neuroinformatics, University of Zurich / ETH, Switzerland.
21 **/
23 package ini.trakem2.display;
26 import javax.swing.*;
27 import java.awt.event.*;
28 import java.awt.Color;
29 import java.awt.Dimension;
32 public class Channel extends JPanel implements ItemListener, MouseListener {
34 static public final int HEIGHT = 52;
36 private JCheckBox c;
37 private JLabel title;
39 private Display display;
41 static public final int MONO = 1;
42 static public final int RED = 2;
43 static public final int GREEN= 4;
44 static public final int BLUE = 8;
45 private int channel;
46 private float alpha = 1.0f;
48 Channel(Display display, int channel) {
49 this.display = display;
50 this.channel = channel;
51 this.c = new JCheckBox();
52 this.c.setSelected(true);
53 this.c.addItemListener(this);
54 String t = "mono";
55 switch (channel) {
56 case RED: t = "red"; break;
57 case GREEN: t = "green"; break;
58 case BLUE: t = "blue"; break;
59 default: t = "mono"; break;
61 JLabel title = new DisplayableTitleLabel(" " + t);
62 title.addMouseListener(this);
63 setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
64 add(c);
65 add(title);
67 Dimension dim = new Dimension(250, HEIGHT);
68 setMinimumSize(dim);
69 setMaximumSize(dim);
71 addMouseListener(this);
72 setBackground(Color.white);
73 setBorder(BorderFactory.createLineBorder(Color.black));
76 /** For reconstructing purposes. */
77 public void setAlpha(float alpha, boolean selected) {
78 if (alpha != this.alpha && alpha >= 0.0f && alpha <= 1.0f) {
79 this.alpha = alpha;
81 c.setSelected(selected);
84 public void setAlpha(float alpha) {
85 if (alpha != this.alpha && alpha >= 0.0f && alpha <= 1.0f) {
86 this.alpha = alpha;
87 display.setChannel(channel, alpha);
91 public float getAlpha() { return alpha; }
93 public void itemStateChanged(ItemEvent ie) {
94 Object source = ie.getSource();
95 if (source.equals(c)) {
96 if (ie.getStateChange() == ItemEvent.SELECTED) {
97 display.setChannel(channel, alpha);
98 } else if (ie.getStateChange() == ItemEvent.DESELECTED) {
99 display.setChannel(channel, 0.0f);
104 public boolean isSelected() {
105 return c.isSelected();
108 public void setActive(boolean active) {
109 if (active) {
110 setBackground(Color.cyan);
111 } else {
112 setBackground(Color.white);
116 public boolean isActive() {
117 return getBackground().equals(Color.cyan);
120 public void setSelected (boolean s) {
121 c.setSelected(s);
124 public void mousePressed(MouseEvent me) {
125 display.setActiveChannel(this);
128 public void mouseReleased(MouseEvent me) {}
129 public void mouseEntered(MouseEvent me) {}
130 public void mouseExited (MouseEvent me) {}
131 public void mouseClicked(MouseEvent me) {}