1
/* ========================================================================
2
* JCommon : a free general purpose class library for the Java(tm) platform
3
* ========================================================================
5
* (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
7
* Project Info: http://www.jfree.org/jcommon/index.html
9
* This library is free software; you can redistribute it and/or modify it
10
* under the terms of the GNU Lesser General Public License as published by
11
* the Free Software Foundation; either version 2.1 of the License, or
12
* (at your option) any later version.
14
* This library is distributed in the hope that it will be useful, but
15
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17
* License for more details.
19
* You should have received a copy of the GNU Lesser General Public
20
* License along with this library; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
24
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25
* in the United States and other countries.]
30
* (C) Copyright 2002-2004, by Object Refinery Limited.
32
* Original Author: David Gilbert (for Object Refinery Limited);
39
* 14-Oct-2002 : Version 1 (DG);
45
import java.awt.BorderLayout;
46
import java.awt.GridLayout;
47
import java.awt.event.MouseEvent;
48
import java.awt.event.MouseListener;
50
import javax.swing.JPanel;
51
import javax.swing.JTextField;
52
import javax.swing.SwingConstants;
55
* A very basic spinner component, used for demo purposes only.
57
* @author David Gilbert
59
public class Spinner extends JPanel implements MouseListener {
61
/** The current value. */
64
/** The text field displaying the value. */
65
private JTextField textField;
67
/** The arrow button panel. */
68
private JPanel buttonPanel;
71
private ArrowPanel upButton;
73
/** The down button. */
74
private ArrowPanel downButton;
77
* Creates a new spinner.
79
* @param value the initial value.
81
public Spinner(final int value) {
82
super(new BorderLayout());
84
this.textField = new JTextField(Integer.toString(this.value));
85
this.textField.setHorizontalAlignment(SwingConstants.RIGHT);
87
this.buttonPanel = new JPanel(new GridLayout(2, 1, 0, 1));
88
this.upButton = new ArrowPanel(ArrowPanel.UP);
89
this.upButton.addMouseListener(this);
90
this.downButton = new ArrowPanel(ArrowPanel.DOWN);
91
this.downButton.addMouseListener(this);
92
this.buttonPanel.add(this.upButton);
93
this.buttonPanel.add(this.downButton);
94
add(this.buttonPanel, BorderLayout.EAST);
98
* Returns the current value.
100
* @return the current value.
102
public int getValue() {
107
* Receives notification of mouse clicks.
109
* @param e the mouse event.
111
public void mouseClicked(final MouseEvent e) {
112
if (e.getSource() == this.upButton) {
114
this.textField.setText(Integer.toString(this.value));
115
firePropertyChange("value", this.value - 1, this.value);
117
else if (e.getSource() == this.downButton) {
119
this.textField.setText(Integer.toString(this.value));
120
firePropertyChange("value", this.value + 1, this.value);
125
* Receives notification of mouse events.
127
* @param e the mouse event.
129
public void mouseEntered(final MouseEvent e) {
134
* Receives notification of mouse events.
136
* @param e the mouse event.
138
public void mouseExited(final MouseEvent e) {
143
* Receives notification of mouse events.
145
* @param e the mouse event.
147
public void mousePressed(final MouseEvent e) {
152
* Receives notification of mouse events.
154
* @param e the mouse event.
156
public void mouseReleased(final MouseEvent e) {