001: /*
002: #IFNDEF ALT_LICENSE
003: ThinWire(R) RIA Ajax Framework
004: Copyright (C) 2003-2007 Custom Credit Systems
005:
006: This library is free software; you can redistribute it and/or modify it under
007: the terms of the GNU Lesser General Public License as published by the Free
008: Software Foundation; either version 2.1 of the License, or (at your option) any
009: later version.
010:
011: This library is distributed in the hope that it will be useful, but WITHOUT ANY
012: WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
013: PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
014:
015: You should have received a copy of the GNU Lesser General Public License along
016: with this library; if not, write to the Free Software Foundation, Inc., 59
017: Temple Place, Suite 330, Boston, MA 02111-1307 USA
018:
019: Users who would rather have a commercial license, warranty or support should
020: contact the following company who invented, built and supports the technology:
021:
022: Custom Credit Systems, Richardson, TX 75081, USA.
023: email: info@thinwire.com ph: +1 (888) 644-6405
024: http://www.thinwire.com
025: #ENDIF
026: [ v1.2_RC2 ]
027: */
028: package thinwire.ui;
029:
030: /**
031: * A Slider is a screen element that has a cursor that can be set to any position between zero and a specified length.
032: * Sliders are either horizontal or vertical depending on their dimensions. If the width is greater than the height,
033: * then the Slider is horizontal, otherwise it is vertical.
034: * <p>
035: * <b>Example:</b> <br>
036: * <img src="doc-files/Slider-1.png"> <br>
037: *
038: * <pre>
039: * Frame f = Application.current().getFrame();
040: * f.setTitle("Slider Test");
041: * Dialog d = new Dialog("Slider Test");
042: * d.setBounds(10, 10, 250, 150);
043: * final Slider s = new Slider(5, 3);
044: * s.setBounds(10, 10, 100, 20);
045: * s.addPropertyChangeListener(Slider.PROPERTY_CURRENT_INDEX, new PropertyChangeListener() {
046: * public void propertyChange(PropertyChangeEvent ev) {
047: * tf.setText(String.valueOf((Integer) ev.getNewValue()));
048: * }
049: * });
050: * d.getChildren().add(s);
051: * final TextField tf = new TextField();
052: * tf.setBounds(10, 40, 50, 20);
053: * tf.setText(String.valueOf(s.getCurrentIndex()));
054: * d.getChildren().add(tf);
055: * Button b = new Button("SetValue");
056: * b.setBounds(70, 35, 60, 30);
057: * b.addActionListener(Button.ACTION_CLICK, new ActionListener() {
058: * public void actionPerformed(ActionEvent ev) {
059: * s.setCurrentIndex(Integer.parseInt(tf.getText()));
060: * }
061: * });
062: * d.getChildren().add(b);
063: * f.getChildren().add(d);
064: * </pre>
065: *
066: * </p>
067: * <p>
068: * <b>Keyboard Navigation:</b><br>
069: * <table border="1">
070: * <tr>
071: * <td>KEY</td>
072: * <td>RESPONSE</td>
073: * <td>NOTE</td>
074: * </tr>
075: * <tr>
076: * <td>Right Arrow</td>
077: * <td>Increments the cursorIndex by 1 and Fires PropertyChangeEvent( propertyName = Slider.PROPERTY_CURSOR_INDEX )</td>
078: * <td>Only if the component is horizontal.</td>
079: * </tr>
080: * <tr>
081: * <td>Left Arrow</td>
082: * <td>Decrements the cursorIndex by 1 and Fires PropertyChangeEvent( propertyName = Slider.PROPERTY_CURSOR_INDEX )</td>
083: * <td>Only if the component is horizontal.</td>
084: * </tr>
085: * <tr>
086: * <td>Up Arrow</td>
087: * <td>Increments the cursorIndex by 1 and Fires PropertyChangeEvent( propertyName = Slider.PROPERTY_CURSOR_INDEX )</td>
088: * <td>Only if the component is vertical.</td>
089: * </tr>
090: * <tr>
091: * <td>Down Arrow</td>
092: * <td>Decrements the cursorIndex by 1 and Fires PropertyChangeEvent( propertyName = Slider.PROPERTY_CURSOR_INDEX )</td>
093: * <td>Only if the component is vertical.</td>
094: * </tr>
095: * </table>
096: * </p>
097: *
098: * @author Ted C. Howard
099: */
100: public class Slider extends AbstractRangeComponent {
101: /**
102: * Constructs a new <code>Slider</code> with a length of 100 and initial currentIndex of 0.
103: *
104: */
105: public Slider() {
106: this (100);
107: }
108:
109: /**
110: * Constructs a new <code>Slider</code> with the specified length and an initial currentIndex of 0.
111: * @param length the number of increments on the Slider
112: */
113: public Slider(int length) {
114: this (length, 0);
115: }
116:
117: /**
118: * Constructs a new <code>Slider</code> with the specifed length and initial currentIndex.
119: * @param length the number of increments on the Slider
120: * @param currentIndex the initial position of the cursor
121: */
122: public Slider(int length, int currentIndex) {
123: setLength(length);
124: setCurrentIndex(currentIndex);
125: }
126:
127: }
|