edu.uah.math.devices
Class Spinner

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by edu.uah.math.devices.Spinner
All Implemented Interfaces:
java.awt.event.MouseMotionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener

public class Spinner
extends javax.swing.JComponent
implements java.awt.event.MouseMotionListener, java.io.Serializable

This class models a simple spinner. The number of sectors and the probability distribution that governs the spinner can be specified. The size of the each sector is proportional to the probability of the sector.

Version:
August, 2003
Author:
Dawn Duehring, Kyle Siegrist
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Spinner()
          This default constructor creates a new spinner with four equal divisions.
Spinner(double[] p)
          This special constructor creates a new spinner with a specified array of probabilities and a the default array of colors.
Spinner(double[] p, java.awt.Color[] c)
          This general constructor creates a new spinner with a specified array of probabilities and a specified array of colors.
Spinner(int n)
          This special constuctor creates a new spinner with a specified number of equal sized divisions and the default array of colors.
Spinner(int n, java.awt.Color[] c)
          This special constuctor creates a new spinner with a specified number of equal sized divisions and a specified array of colors.
 
Method Summary
 double getAngle()
          This method returns the angle.
 java.awt.Color[] getColors()
          This method returns the array of colors
 java.awt.Color getColors(int i)
          This method returns an individual color
 int getDivisions()
          This method returns the number of divisions.
 double[] getProbabilities()
          This method returns the all of the probabilities.
 double getProbabilities(int i)
          This method returns an individual probability.
 int getValue()
          This method returns the current value of the spinner
 int getValue(double a)
          This method computes the value (sector number) corresponding to a give angle.
 void mouseDragged(java.awt.event.MouseEvent event)
           
 void mouseMoved(java.awt.event.MouseEvent e)
          This method handles the mouse move event.
 void paintComponent(java.awt.Graphics g)
          This method paints the spinner based on the number of divisions and paints the pointer based on the random angle computed in the spin method.
 void setAngle(double a)
          This method sets a specific angle measure and computes the value of the spin corresponding to that angle.
 void setColors(java.awt.Color[] c)
          This method sets the array of colors.
 void setColors(int i, java.awt.Color c)
          This method sets an individual color.
 void setDefaultColors()
          This method defines the default color array.
 void setDivisions(int n)
          This method sets the number of divisions.
 void setProbabilities(double[] p)
          This method sets the array of probabilities.
 void setProbabilities(int i, double p)
          This method sets an individual probability.
 void spin()
          This method "spins" the spinner by computing a random angle and the value of a spin based on that angle.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Spinner

public Spinner(double[] p,
               java.awt.Color[] c)
This general constructor creates a new spinner with a specified array of probabilities and a specified array of colors. The size of the array is the number of divisions..The areas of the sectors are proportional to the probabilities.

Parameters:
p - the array of probabilities
c - the array of colors

Spinner

public Spinner(double[] p)
This special constructor creates a new spinner with a specified array of probabilities and a the default array of colors. The size of the array is the number of divisions..The areas of the sectors are proportional to the probabilities.

Parameters:
p - the array of probabilities

Spinner

public Spinner(int n,
               java.awt.Color[] c)
This special constuctor creates a new spinner with a specified number of equal sized divisions and a specified array of colors. Thus the probability distribution is uniform.

Parameters:
n - the number of divisions
c - the array of colors

Spinner

public Spinner(int n)
This special constuctor creates a new spinner with a specified number of equal sized divisions and the default array of colors. Thus the probability distribution is uniform.

Parameters:
n - the number of divisions

Spinner

public Spinner()
This default constructor creates a new spinner with four equal divisions.

Method Detail

setProbabilities

public void setProbabilities(double[] p)
This method sets the array of probabilities. Error checking is performed to ensure that the probabilities are nonnegative and sum to 1. The sizes of the sectors are computed.

Parameters:
p - the array of probabilities

getProbabilities

public double[] getProbabilities()
This method returns the all of the probabilities.

Returns:
the array of probabilities

setProbabilities

public void setProbabilities(int i,
                             double p)
This method sets an individual probability. The other probabilities would be rescaled appropriately.

Parameters:
i - the index
p - the probability

getProbabilities

public double getProbabilities(int i)
This method returns an individual probability.

Parameters:
i - the index
Returns:
the probability corresponding to the index.

setColors

public void setColors(java.awt.Color[] c)
This method sets the array of colors.

Parameters:
c - the array of colors.

getColors

public java.awt.Color[] getColors()
This method returns the array of colors

Returns:
the array of colors

setColors

public void setColors(int i,
                      java.awt.Color c)
This method sets an individual color.

Parameters:
i - the index
c - the color of the index

getColors

public java.awt.Color getColors(int i)
This method returns an individual color

Parameters:
i - the index
Returns:
the color of the index.

setDefaultColors

public void setDefaultColors()
This method defines the default color array. This array cylces among the 10 basic colors


setDivisions

public void setDivisions(int n)
This method sets the number of divisions. The default unfiform probabilities and colors are specified.

Parameters:
n - the number of divisions

getDivisions

public int getDivisions()
This method returns the number of divisions.


setAngle

public void setAngle(double a)
This method sets a specific angle measure and computes the value of the spin corresponding to that angle.

Parameters:
a - the angle of the pointer relative to the horizontal ray

getAngle

public double getAngle()
This method returns the angle.

Returns:
the angle

spin

public void spin()
This method "spins" the spinner by computing a random angle and the value of a spin based on that angle.


getValue

public int getValue(double a)
This method computes the value (sector number) corresponding to a give angle.

Parameters:
a - the angle
Returns:
the value

getValue

public int getValue()
This method returns the current value of the spinner

Returns:
the number of the sector containing the spinner pointer.

paintComponent

public void paintComponent(java.awt.Graphics g)
This method paints the spinner based on the number of divisions and paints the pointer based on the random angle computed in the spin method.

Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g - the graphics context

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
This method handles the mouse move event. The coordinates of the mouse (in scale units) are tracked.

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
Parameters:
e - the mouse event

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent event)
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener