001/*
002 * Copyright 2010-2015 Institut Pasteur.
003 * 
004 * This file is part of Icy.
005 * 
006 * Icy is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 * 
011 * Icy is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014 * GNU General Public License for more details.
015 * 
016 * You should have received a copy of the GNU General Public License
017 * along with Icy. If not, see <http://www.gnu.org/licenses/>.
018 */
019package icy.gui.viewer;
020
021import icy.gui.component.IcySlider;
022import icy.gui.util.ComponentUtil;
023import icy.gui.util.GuiUtil;
024import icy.system.thread.ThreadUtil;
025
026import java.awt.BorderLayout;
027
028import javax.swing.BorderFactory;
029import javax.swing.Box;
030import javax.swing.JLabel;
031import javax.swing.JPanel;
032import javax.swing.SwingConstants;
033import javax.swing.event.ChangeEvent;
034import javax.swing.event.ChangeListener;
035
036/**
037 * @author Stephane
038 */
039public class ZNavigationPanel extends JPanel
040{
041    /**
042     * 
043     */
044    private static final long serialVersionUID = -1839748578015800706L;
045
046    final IcySlider slider;
047    final JLabel topLabel;
048    final JLabel bottomLabel;
049
050    public ZNavigationPanel()
051    {
052        super();
053
054        slider = new IcySlider(SwingConstants.VERTICAL);
055        slider.setFocusable(false);
056        slider.setMaximum(0);
057        slider.setMinimum(0);
058        slider.setToolTipText("Move cursor to navigate in Z dimension");
059        slider.addChangeListener(new ChangeListener()
060        {
061            @Override
062            public void stateChanged(ChangeEvent e)
063            {
064                ThreadUtil.invokeLater(new Runnable()
065                {
066                    @Override
067                    public void run()
068                    {
069                        topLabel.setText(Integer.toString(slider.getMaximum()));
070                        bottomLabel.setText(Integer.toString(slider.getValue()));
071
072                        validate();
073                    }
074                });
075            }
076        });
077        ComponentUtil.setFixedWidth(slider, 22);
078
079        topLabel = new JLabel("000");
080        topLabel.setToolTipText("Z sequence size");
081        bottomLabel = new JLabel("000");
082        bottomLabel.setToolTipText("Z position");
083
084        final JLabel zLabel = GuiUtil.createBoldLabel("Z");
085
086        setBorder(BorderFactory.createTitledBorder("").getBorder());
087        setLayout(new BorderLayout());
088
089        add(GuiUtil.createCenteredLabel(topLabel), BorderLayout.NORTH);
090        add(slider, BorderLayout.CENTER);
091        add(GuiUtil.createPageBoxPanel(GuiUtil.createCenteredLabel(bottomLabel), Box.createVerticalStrut(8),
092                GuiUtil.createCenteredLabel(zLabel)), BorderLayout.SOUTH);
093
094        validate();
095    }
096
097    /**
098     * @see icy.gui.component.IcySlider#setPaintLabels(boolean)
099     */
100    public void setPaintLabels(boolean b)
101    {
102        slider.setPaintLabels(b);
103    }
104
105    /**
106     * @see icy.gui.component.IcySlider#setPaintTicks(boolean)
107     */
108    public void setPaintTicks(boolean b)
109    {
110        slider.setPaintTicks(b);
111    }
112
113    /**
114     * @see javax.swing.JSlider#addChangeListener(javax.swing.event.ChangeListener)
115     */
116    public void addChangeListener(ChangeListener l)
117    {
118        slider.addChangeListener(l);
119    }
120
121    /**
122     * @see javax.swing.JSlider#removeChangeListener(javax.swing.event.ChangeListener)
123     */
124    public void removeChangeListener(ChangeListener l)
125    {
126        slider.removeChangeListener(l);
127    }
128
129    /**
130     * Remove all change listener
131     */
132    public void removeAllChangeListener()
133    {
134        for (ChangeListener l : slider.getListeners(ChangeListener.class))
135            slider.removeChangeListener(l);
136    }
137
138    /**
139     * @see javax.swing.JSlider#getValue()
140     */
141    public int getValue()
142    {
143        return slider.getValue();
144    }
145
146    /**
147     * @param n
148     * @see javax.swing.JSlider#setValue(int)
149     */
150    public void setValue(int n)
151    {
152        slider.setValue(n);
153    }
154
155    /**
156     * @see javax.swing.JSlider#getMinimum()
157     */
158    public int getMinimum()
159    {
160        return slider.getMinimum();
161    }
162
163    /**
164     * @see javax.swing.JSlider#setMinimum(int)
165     */
166    public void setMinimum(int minimum)
167    {
168        slider.setMinimum(minimum);
169    }
170
171    /**
172     * @see javax.swing.JSlider#getMaximum()
173     */
174    public int getMaximum()
175    {
176        return slider.getMaximum();
177    }
178
179    /**
180     * @see javax.swing.JSlider#setMaximum(int)
181     */
182    public void setMaximum(int maximum)
183    {
184        slider.setMaximum(maximum);
185    }
186
187    /**
188     * @see javax.swing.JSlider#getPaintTicks()
189     */
190    public boolean getPaintTicks()
191    {
192        return slider.getPaintTicks();
193    }
194
195    /**
196     * @see javax.swing.JSlider#getPaintTrack()
197     */
198    public boolean getPaintTrack()
199    {
200        return slider.getPaintTrack();
201    }
202
203    /**
204     * @see javax.swing.JSlider#setPaintTrack(boolean)
205     */
206    public void setPaintTrack(boolean b)
207    {
208        slider.setPaintTrack(b);
209    }
210
211    /**
212     * @see javax.swing.JSlider#getPaintLabels()
213     */
214    public boolean getPaintLabels()
215    {
216        return slider.getPaintLabels();
217    }
218
219}