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.
23 package ini
.trakem2
.display
;
26 import ini
.trakem2
.utils
.Utils
;
28 import javax
.swing
.BoxLayout
;
29 import javax
.swing
.BorderFactory
;
30 import javax
.swing
.JLabel
;
31 import javax
.swing
.JSlider
;
32 import javax
.swing
.JPanel
;
33 import javax
.swing
.event
.ChangeEvent
;
34 import javax
.swing
.event
.ChangeListener
;
35 import java
.awt
.Event
;
36 import java
.awt
.event
.MouseListener
;
37 import java
.awt
.event
.MouseEvent
;
38 import java
.awt
.Color
;
39 import java
.awt
.Graphics
;
40 import java
.awt
.Dimension
;
43 public final class LayerPanel
extends JPanel
implements MouseListener
{
45 private final JLabel title
;
46 private final JSlider slider
= new JSlider(javax
.swing
.SwingConstants
.HORIZONTAL
, 0, 100, 0);
47 private Color color
= Color
.white
;
48 private float alpha
= 0.0f
; // for overlays
50 private final Display display
;
51 protected final Layer layer
;
53 public LayerPanel(final Display display
, final Layer layer
) {
54 this.display
= display
;
57 this.slider
.addChangeListener(new ChangeListener() {
58 public void stateChanged(final ChangeEvent ce
) {
59 final float a
= slider
.getValue() / 100.0f
;
61 display
.setLayerAlpha(LayerPanel
.this, a
);
65 this.title
= new JLabel(makeTitle());
66 this.title
.addMouseListener(this);
68 setLayout(new BoxLayout(this, BoxLayout
.Y_AXIS
));
72 final Dimension dim
= new Dimension(250 - Display
.scrollbar_width
, DisplayablePanel
.HEIGHT
);
75 //setPreferredSize(dim);
77 addMouseListener(this);
78 setBackground(this.color
);
79 setBorder(BorderFactory
.createLineBorder(Color
.black
));
82 private final String
makeTitle() {
83 return new StringBuffer().append(layer
.getParent().indexOf(layer
) + 1).append(':').append(' ').append(layer
.getTitle()).toString();
86 public final void setColor(final Color color
) {
89 slider
.setBackground(color
);
90 if (Color
.white
== color
) {
91 title
.setForeground(Color
.black
);
93 title
.setForeground(Color
.white
);
98 public final Color
getColor() { return color
; }
100 public final void setAlpha(final float alpha
) {
101 if (alpha
< 0 || alpha
> 1) return;
106 public final float getAlpha() { return alpha
; }
108 public final void paint(final Graphics g
) {
109 title
.setText(makeTitle());
110 if (display
.getLayer() == layer
) {
111 setBackground(Color
.green
);
112 slider
.setBackground(Color
.green
);
114 setBackground(color
);
115 slider
.setBackground(color
);
120 public void mousePressed(final MouseEvent me
) {
121 final int mod
= me
.getModifiers();
122 Utils
.log2("mouse pressed : " + mod
);
123 if (0 == (mod
& Event
.ALT_MASK
) && 0 == (mod
& Event
.SHIFT_MASK
)) {
124 display
.toLayer(this.layer
);
125 setColor(Color
.white
);
126 display
.setColorChannel(this.layer
, this.color
);
128 } else if (display
.getLayer() == this.layer
) {
130 } else if (0 != (mod
& Event
.ALT_MASK
)) {
131 if (this.color
== Color
.blue
) {
133 setColor(Color
.white
);
135 // set as blue channel
136 setColor(Color
.blue
);
138 } else if (0 != (mod
& Event
.SHIFT_MASK
)) {
139 if (this.color
== Color
.red
) {
141 setColor(Color
.white
);
143 // set as red channel
148 display
.setColorChannel(this.layer
, this.color
);
151 public void mouseReleased(MouseEvent me
) {}
152 public void mouseEntered(MouseEvent me
) {}
153 public void mouseExited (MouseEvent me
) {}
154 public void mouseClicked(MouseEvent me
) {}
156 public final String
toString() {
157 return "Layer panel for " + layer
.getTitle();