Java Doc for SpinnerNumberModel.java in  » 6.0-JDK-Core » swing » javax » swing » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » swing » javax.swing 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   javax.swing.AbstractSpinnerModel
      javax.swing.SpinnerNumberModel

SpinnerNumberModel
public class SpinnerNumberModel extends AbstractSpinnerModel implements Serializable(Code)
A SpinnerModel for sequences of numbers. The upper and lower bounds of the sequence are defined by properties called minimum and maximum. The size of the increase or decrease computed by the nextValue and previousValue methods is defined by a property called stepSize. The minimum and maximum properties can be null to indicate that the sequence has no lower or upper limit. All of the properties in this class are defined in terms of two generic types: Number and Comparable, so that all Java numeric types may be accommodated. Internally, there's only support for values whose type is one of the primitive Number types: Double, Float, Long, Integer, Short, or Byte.

To create a SpinnerNumberModel for the integer range zero to one hundred, with fifty as the initial value, one could write:

 
 Integer value = new Integer(50); 
 Integer min = new Integer(0);
 Integer max = new Integer(100); 
 Integer step = new Integer(1); 
 SpinnerNumberModel model = new SpinnerNumberModel(value, min, max, step); 
 int fifty = model.getNumber().intValue(); 
 

Spinners for integers and doubles are common, so special constructors for these cases are provided. For example to create the model in the previous example, one could also write:

 
 SpinnerNumberModel model = new SpinnerNumberModel(50, 0, 100, 1); 
 

This model inherits a ChangeListener. The ChangeListeners are notified whenever the model's value, stepSize, minimum, or maximum properties changes.
See Also:   JSpinner
See Also:   SpinnerModel
See Also:   AbstractSpinnerModel
See Also:   SpinnerListModel
See Also:   SpinnerDateModel
version:
   1.19 05/05/07
author:
   Hans Muller
since:
   1.4




Constructor Summary
public  SpinnerNumberModel(Number value, Comparable minimum, Comparable maximum, Number stepSize)
     Constructs a SpinnerModel that represents a closed sequence of numbers from minimum to maximum.
public  SpinnerNumberModel(int value, int minimum, int maximum, int stepSize)
     Constructs a SpinnerNumberModel with the specified value, minimum/maximum bounds, and stepSize.
public  SpinnerNumberModel(double value, double minimum, double maximum, double stepSize)
     Constructs a SpinnerNumberModel with the specified value, minimum/maximum bounds, and stepSize.
public  SpinnerNumberModel()
     Constructs a SpinnerNumberModel with no minimum or maximum value, stepSize equal to one, and an initial value of zero.

Method Summary
public  ComparablegetMaximum()
     Returns the last number in the sequence.
public  ComparablegetMinimum()
     Returns the first number in this sequence.
public  ObjectgetNextValue()
     Returns the next number in the sequence.
public  NumbergetNumber()
     Returns the value of the current element of the sequence.
public  ObjectgetPreviousValue()
     Returns the previous number in the sequence.
public  NumbergetStepSize()
     Returns the size of the value change computed by the getNextValue and getPreviousValue methods.
public  ObjectgetValue()
     Returns the value of the current element of the sequence.
public  voidsetMaximum(Comparable maximum)
     Changes the upper bound for numbers in this sequence.
public  voidsetMinimum(Comparable minimum)
     Changes the lower bound for numbers in this sequence.
public  voidsetStepSize(Number stepSize)
     Changes the size of the value change computed by the getNextValue and getPreviousValue methods.
public  voidsetValue(Object value)
     Sets the current value for this sequence.


Constructor Detail
SpinnerNumberModel
public SpinnerNumberModel(Number value, Comparable minimum, Comparable maximum, Number stepSize)(Code)
Constructs a SpinnerModel that represents a closed sequence of numbers from minimum to maximum. The nextValue and previousValue methods compute elements of the sequence by adding or subtracting stepSize respectively. All of the parameters must be mutually Comparable, value and stepSize must be instances of Integer Long, Float, or Double.

The minimum and maximum parameters can be null to indicate that the range doesn't have an upper or lower bound. If value or stepSize is null, or if both minimum and maximum are specified and mininum > maximum then an IllegalArgumentException is thrown. Similarly if (minimum <= value <= maximum) is false, an IllegalArgumentException is thrown.
Parameters:
  value - the current (non null) value of the model
Parameters:
  minimum - the first number in the sequence or null
Parameters:
  maximum - the last number in the sequence or null
Parameters:
  stepSize - the difference between elements of the sequence
throws:
  IllegalArgumentException - if stepSize or value isnull or if the following expression is false:minimum <= value <= maximum




SpinnerNumberModel
public SpinnerNumberModel(int value, int minimum, int maximum, int stepSize)(Code)
Constructs a SpinnerNumberModel with the specified value, minimum/maximum bounds, and stepSize.
Parameters:
  value - the current value of the model
Parameters:
  minimum - the first number in the sequence
Parameters:
  maximum - the last number in the sequence
Parameters:
  stepSize - the difference between elements of the sequence
throws:
  IllegalArgumentException - if the following expression is false:minimum <= value <= maximum



SpinnerNumberModel
public SpinnerNumberModel(double value, double minimum, double maximum, double stepSize)(Code)
Constructs a SpinnerNumberModel with the specified value, minimum/maximum bounds, and stepSize.
Parameters:
  value - the current value of the model
Parameters:
  minimum - the first number in the sequence
Parameters:
  maximum - the last number in the sequence
Parameters:
  stepSize - the difference between elements of the sequence
throws:
  IllegalArgumentException - if the following expression is false:minimum <= value <= maximum



SpinnerNumberModel
public SpinnerNumberModel()(Code)
Constructs a SpinnerNumberModel with no minimum or maximum value, stepSize equal to one, and an initial value of zero.




Method Detail
getMaximum
public Comparable getMaximum()(Code)
Returns the last number in the sequence. the value of the maximum property
See Also:   SpinnerNumberModel.setMaximum



getMinimum
public Comparable getMinimum()(Code)
Returns the first number in this sequence. the value of the minimum property
See Also:   SpinnerNumberModel.setMinimum



getNextValue
public Object getNextValue()(Code)
Returns the next number in the sequence. value + stepSize or null if the sum exceeds maximum.
See Also:   SpinnerModel.getNextValue
See Also:   SpinnerNumberModel.getPreviousValue
See Also:   SpinnerNumberModel.setStepSize



getNumber
public Number getNumber()(Code)
Returns the value of the current element of the sequence. the value property
See Also:   SpinnerNumberModel.setValue



getPreviousValue
public Object getPreviousValue()(Code)
Returns the previous number in the sequence. value - stepSize, ornull if the sum is less than minimum.
See Also:   SpinnerModel.getPreviousValue
See Also:   SpinnerNumberModel.getNextValue
See Also:   SpinnerNumberModel.setStepSize



getStepSize
public Number getStepSize()(Code)
Returns the size of the value change computed by the getNextValue and getPreviousValue methods. the value of the stepSize property
See Also:   SpinnerNumberModel.setStepSize



getValue
public Object getValue()(Code)
Returns the value of the current element of the sequence. the value property
See Also:   SpinnerNumberModel.setValue
See Also:   SpinnerNumberModel.getNumber



setMaximum
public void setMaximum(Comparable maximum)(Code)
Changes the upper bound for numbers in this sequence. If maximum is null, then there is no upper bound. No bounds checking is done here; the new maximum value may invalidate the (minimum <= value < maximum) invariant enforced by the constructors. This is to simplify updating the model, naturally one should ensure that the invariant is true before calling the next, previous, or setValue methods.

Typically this property is a Number of the same type as the value however it's possible to use any Comparable with a compareTo method for a Number with the same type as the value. See setMinimum for an example.

This method fires a ChangeEvent if the maximum has changed.
Parameters:
  maximum - a Comparable that has acompareTo method for Numbers with the same type as value
See Also:   SpinnerNumberModel.getMaximum
See Also:   SpinnerNumberModel.setMinimum
See Also:   SpinnerModel.addChangeListener




setMinimum
public void setMinimum(Comparable minimum)(Code)
Changes the lower bound for numbers in this sequence. If minimum is null, then there is no lower bound. No bounds checking is done here; the new minimum value may invalidate the (minimum <= value <= maximum) invariant enforced by the constructors. This is to simplify updating the model, naturally one should ensure that the invariant is true before calling the getNextValue, getPreviousValue, or setValue methods.

Typically this property is a Number of the same type as the value however it's possible to use any Comparable with a compareTo method for a Number with the same type as the value. For example if value was a Long, minimum might be a Date subclass defined like this:

 MyDate extends Date {  // Date already implements Comparable
 public int compareTo(Long o) {
 long t = getTime();
 return (t < o.longValue() ? -1 : (t == o.longValue() ? 0 : 1));
 }
 }
 

This method fires a ChangeEvent if the minimum has changed.
Parameters:
  minimum - a Comparable that has acompareTo method for Numbers with the same type as value
See Also:   SpinnerNumberModel.getMinimum
See Also:   SpinnerNumberModel.setMaximum
See Also:   SpinnerModel.addChangeListener




setStepSize
public void setStepSize(Number stepSize)(Code)
Changes the size of the value change computed by the getNextValue and getPreviousValue methods. An IllegalArgumentException is thrown if stepSize is null.

This method fires a ChangeEvent if the stepSize has changed.
Parameters:
  stepSize - the size of the value change computed by the getNextValue and getPreviousValue methods
See Also:   SpinnerNumberModel.getNextValue
See Also:   SpinnerNumberModel.getPreviousValue
See Also:   SpinnerNumberModel.getStepSize
See Also:   SpinnerModel.addChangeListener




setValue
public void setValue(Object value)(Code)
Sets the current value for this sequence. If value is null, or not a Number, an IllegalArgumentException is thrown. No bounds checking is done here; the new value may invalidate the (minimum <= value <= maximum) invariant enforced by the constructors. It's also possible to set the value to be something that wouldn't naturally occur in the sequence, i.e. a value that's not modulo the stepSize. This is to simplify updating the model, and to accommodate spinners that don't want to restrict values that have been directly entered by the user. Naturally, one should ensure that the (minimum <= value <= maximum) invariant is true before calling the next, previous, or setValue methods.

This method fires a ChangeEvent if the value has changed.
Parameters:
  value - the current (non null) Numberfor this sequence
throws:
  IllegalArgumentException - if value isnull or not a Number
See Also:   SpinnerNumberModel.getNumber
See Also:   SpinnerNumberModel.getValue
See Also:   SpinnerModel.addChangeListener




Fields inherited from javax.swing.AbstractSpinnerModel
protected EventListenerList listenerList(Code)(Java Doc)

Methods inherited from javax.swing.AbstractSpinnerModel
public void addChangeListener(ChangeListener l)(Code)(Java Doc)
protected void fireStateChanged()(Code)(Java Doc)
public ChangeListener[] getChangeListeners()(Code)(Java Doc)
public T[] getListeners(Class<T> listenerType)(Code)(Java Doc)
public void removeChangeListener(ChangeListener l)(Code)(Java Doc)

Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.