Statistics
| Revision:

root / trunk / libraries / libUIComponent / src / de / ios / framework / swing / NumberRange.java @ 13655

History | View | Annotate | Download (4.73 KB)

1
/*
2
 * $Id: NumberRange.java 13655 2007-09-12 16:28:55Z bsanchez $
3
 * (c)1997 IoS Gesellschaft fr innovative Softwareentwicklung mbH
4
 * http://www.IoS-Online.de    mailto:info@IoS-Online.de
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License as
8
 * published by the Free Software Foundation; either version 2 of
9
 * the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
 * General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
 *
20
 */
21

    
22
package de.ios.framework.swing;
23
import java.awt.Button;
24
import java.awt.FlowLayout;
25
import java.awt.Panel;
26
import java.awt.event.ActionEvent;
27
import java.awt.event.ActionListener;
28

    
29
/**
30
 * Displays a Textfield with two small buttons in an own panel.
31
 */
32
public class NumberRange extends Panel {
33
  private static final long serialVersionUID = 6977082046201638066L;
34

    
35
        /** Output debugging mssages, if true */
36
  public static final boolean debug = false;
37

    
38
  /** TextField to hold the current value */
39
  protected NumberField value  = null;
40
  /** Button to increment the current value */
41
  protected Button      plusB  = new Button("+");;
42
  /** Button to decrement the current value */
43
  protected Button      minusB = new Button("-");;
44

    
45
  // Default values
46
  /** Size of NumberField (digits) */
47
  protected int digits   = 3;
48
  /** The smallest allowed value */
49
  protected int minValue = 0;
50
  /** The biggest allowed value */
51
  protected int maxValue = 999;
52

    
53
  /**
54
   * Default Constructor
55
   */
56
  public NumberRange() {
57
    createDialog();
58
    value.setValue( new Integer( minValue ) );
59

    
60
  }
61

    
62
  /**
63
   * Constructor to set an initial value.
64
   *
65
   * @param v Initial value
66
   */
67
  public NumberRange(int v) {
68
    createDialog();
69
    value.setValue( new Integer(v) );
70
  }
71

    
72
  /**
73
   * Constructor to set an initial, minimal and maximal value.
74
   *
75
   * @param v Initial value
76
   * @param min Min. value
77
   * @param max Max. value
78
   */
79
  public NumberRange(int v, int min, int max) {
80
    minValue = min;
81
    maxValue = max;
82
    createDialog();
83
    value.setValue( new Integer(v) );
84
  }
85

    
86
  /**
87
   * Constructor to set the field size (digits) and
88
   * an initial, minimal and maximal value.
89
   *
90
   * @param dig Field size (digits)
91
   * @param v Initial value
92
   * @param min Min. value
93
   * @param max Max. value
94
   */
95
  public NumberRange(int dig, int v, int min, int max) {
96
    digits = dig;
97
    minValue = min;
98
    maxValue = max;
99
    createDialog();
100
    value.setValue( new Integer(v) );
101
  }
102

    
103
  /**
104
   * Arranges the GUI components
105
   */
106
  protected void createDialog() {
107
    value  = new NumberField( digits );
108
    value.setEditable( false );
109
    setLayout( new FlowLayout( FlowLayout.LEFT, 1, 1) );
110
    add( value  );
111
    add( plusB  );
112
    add( minusB );
113

    
114
    // Button events
115
    plusB.addActionListener( new ActionListener() {
116
      public void actionPerformed(ActionEvent e) {
117
        incValue();
118
      }
119
    });
120
    minusB.addActionListener( new ActionListener() {
121
      public void actionPerformed(ActionEvent e) {
122
        decValue();
123
      }
124
    });
125
  }
126

    
127
  /**
128
   * Increment the current value.
129
   */
130
  protected void incValue() {
131
    int v = this.getValue();
132
    if (v < maxValue) {
133
      value.setValue( new Integer(v+1) );
134
    }
135
  }
136

    
137
  /**
138
   * Decrement the current value.
139
   */
140
  protected void decValue() {
141
    int v = this.getValue();
142
    if (v > minValue) {
143
      value.setValue( new Integer(v-1) );
144
    }
145
  }
146

    
147
  /**
148
   * Returns the current value.
149
   */
150
  public int getValue() {
151
    return value.getIntegerValue().intValue();
152
  }
153

    
154
  /**
155
   * Sets the current value
156
   */
157
  public void setValue(int v) {
158
    value.setValue( new Integer(v) );
159
  }
160

    
161
}
162

    
163
/*
164
 * $Log$
165
 * Revision 1.3  2007-09-12 16:28:23  bsanchez
166
 * *** empty log message ***
167
 *
168
 * Revision 1.2  2007/08/21 08:37:22  bsanchez
169
 * - Quitados warnings en imports innecesarios
170
 *
171
 * Revision 1.1  2007/08/20 08:34:46  evercher
172
 * He fusionado LibUI con LibUIComponents
173
 *
174
 * Revision 1.2  2007/01/23 13:11:06  caballero
175
 * valor no num?rico
176
 *
177
 * Revision 1.1.2.1  2007/01/19 13:42:54  caballero
178
 * NumericField
179
 *
180
 * Revision 1.1.1.1  2001/02/07 15:24:01  rtfm
181
 * initial
182
 *
183
 * Revision 1.4  1998/05/15 08:45:04  js
184
 * added setValue
185
 *
186
 * Revision 1.3  1998/04/21 15:39:25  js
187
 * More comments.
188
 *
189
 * Revision 1.2  1998/04/17 12:49:13  js
190
 * Changes for layout of CardViews (missing right line...)
191
 *
192
 * Revision 1.1  1998/04/17 07:58:20  js
193
 * A textfield (NumberField) with two buttons to increment/decrement the
194
 * numerical value.
195
 *
196
 */
197