Statistics
| Revision:

root / branches / v10 / libraries / libUI / src / de / ios / framework / swing / NumberRange.java @ 11087

History | View | Annotate | Download (4.43 KB)

1
/*
2
 * $Id: NumberRange.java 11087 2007-04-10 08:15:10Z jmvivo $
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.*;
24
import java.awt.event.*;
25
import java.util.*;
26
import de.ios.framework.swing.*;
27
import de.ios.framework.basic.*;
28

    
29
/**
30
 * Displays a Textfield with two small buttons in an own panel.
31
 */
32
public class NumberRange extends Panel {
33

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

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

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

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

    
59
  }
60

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

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

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

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

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

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

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

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

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

    
160
}
161

    
162
/*
163
 * $Log$
164
 * Revision 1.1.2.2  2007-04-10 08:15:10  jmvivo
165
 * Por compatibilidad con la v1_0_1 se vuelve a usar JNumberField
166
 *
167
 * Revision 1.1.2.1  2007/01/19 13:42:54  caballero
168
 * NumericField
169
 *
170
 * Revision 1.1.1.1  2001/02/07 15:24:01  rtfm
171
 * initial
172
 *
173
 * Revision 1.4  1998/05/15 08:45:04  js
174
 * added setValue
175
 *
176
 * Revision 1.3  1998/04/21 15:39:25  js
177
 * More comments.
178
 *
179
 * Revision 1.2  1998/04/17 12:49:13  js
180
 * Changes for layout of CardViews (missing right line...)
181
 *
182
 * Revision 1.1  1998/04/17 07:58:20  js
183
 * A textfield (NumberField) with two buttons to increment/decrement the
184
 * numerical value.
185
 *
186
 */
187