com.jstatcom.ts
Class TSDateRangeSelector

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.text.JTextComponent
                  extended by javax.swing.JTextField
                      extended by com.jstatcom.component.IValTextField
                          extended by com.jstatcom.ts.TSDateRangeSelector
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.Scrollable, javax.swing.SwingConstants

public final class TSDateRangeSelector
extends IValTextField

Component for display and selection of a TSDateRange. It interpretes an input string and validates it against a parser and a defined range. The range that is displayed in this text field always includes its bounds. This component can be costumized by setting an overall range that must enclose the range that is selected. This is ensured by the validation mechanism.

This class fires a "TSDateRange" property change, if a new date was set.

Author:
Markus Kraetzig
See Also:
TSDateRange, TSDateParser, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.text.JTextComponent
javax.swing.text.JTextComponent.AccessibleJTextComponent, javax.swing.text.JTextComponent.DropLocation, javax.swing.text.JTextComponent.KeyBinding
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.BaselineResizeBehavior
 
Field Summary
 
Fields inherited from class javax.swing.JTextField
notifyAction
 
Fields inherited from class javax.swing.text.JTextComponent
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEY
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, 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 javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
TSDateRangeSelector()
          Create a TSDateRangeSelectorwith the range set to [1960 q1,1982 q4].
 
Method Summary
 TSDateRange getEnclosingRange()
          Gets the overall range that the selected range must be in with.
 int getMinNumberOfObs()
          Gets the minimum number of observations selectable by this component.
 TSDateRange getTSDateRange()
          Gets the currently displayed date range.
 int[] getTSDateRangeAsIndices()
          Returns the currently displayed date range as an array of two indices relative to the lower bound of the overall range.
 void handleError(java.lang.String msg)
          Error handling routine if validation failed.
 void maxRange()
          Sets the display to the maximum possible range, which is the enclosing range.
 void setEnclosingRange(TSDate newStart, int numberOfPeriods)
          Sets the range that the selected range must be in with by setting an initial date and the desired number of available periods within the range.
 void setEnclosingRange(TSDateRange newOverallRange)
          Sets the overall range that the selected range must be in with.
 void setMinNumberOfObs(int newMinNumberOfObs)
          Sets the minimum number of observations selectable by this component.
 void setTSDateRange(TSDateRange newTSDateRange)
          Sets the currently displayed date range if it conforms to the specified overall range.
 java.lang.String validateInput()
          Validates input against the TSDateParser and the overall TSDateRange.
 
Methods inherited from class com.jstatcom.component.IValTextField
addNotify, isEditing, setTextCarefully
 
Methods inherited from class javax.swing.JTextField
addActionListener, getAccessibleContext, getAction, getActionListeners, getActions, getColumns, getHorizontalAlignment, getHorizontalVisibility, getPreferredSize, getScrollOffset, getUIClassID, isValidateRoot, postActionEvent, removeActionListener, scrollRectToVisible, setAction, setActionCommand, setColumns, setDocument, setFont, setHorizontalAlignment, setScrollOffset
 
Methods inherited from class javax.swing.text.JTextComponent
addCaretListener, addInputMethodListener, addKeymap, copy, cut, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getDropLocation, getDropMode, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPreferredScrollableViewportSize, getPrintable, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, moveCaretPosition, paste, print, print, print, read, removeCaretListener, removeKeymap, removeNotify, replaceSelection, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setText, setUI, updateUI, viewToModel, write
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, 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, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, 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, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TSDateRangeSelector

public TSDateRangeSelector()
Create a TSDateRangeSelectorwith the range set to [1960 q1,1982 q4].

Method Detail

getEnclosingRange

public TSDateRange getEnclosingRange()
Gets the overall range that the selected range must be in with.

Returns:
the enclosing range

getMinNumberOfObs

public int getMinNumberOfObs()
Gets the minimum number of observations selectable by this component.

Returns:
minimum number of observations

getTSDateRange

public TSDateRange getTSDateRange()
Gets the currently displayed date range.

Returns:
the currently selected range

getTSDateRangeAsIndices

public int[] getTSDateRangeAsIndices()
Returns the currently displayed date range as an array of two indices relative to the lower bound of the overall range. The index starts from 0.

Returns:
int array with int[0] = index of lower bound, int[1] = index of upper bound

handleError

public void handleError(java.lang.String msg)
Error handling routine if validation failed. Displays an error message and sets back the range value to the last valid one.

Overrides:
handleError in class IValTextField
Parameters:
msg - an error message

maxRange

public void maxRange()
Sets the display to the maximum possible range, which is the enclosing range.


setEnclosingRange

public void setEnclosingRange(TSDate newStart,
                              int numberOfPeriods)
Sets the range that the selected range must be in with by setting an initial date and the desired number of available periods within the range.

Parameters:
newStart - new start of bounding range
numberOfPeriods - > 0 to define the end of the bounding range

setEnclosingRange

public void setEnclosingRange(TSDateRange newOverallRange)
Sets the overall range that the selected range must be in with. The selected range is not changed unless it violates the new range setting.

Parameters:
newOverallRange - the new bounding range
Throws:
java.lang.IllegalArgumentException - if (newOverallRange == null)

setMinNumberOfObs

public void setMinNumberOfObs(int newMinNumberOfObs)
Sets the minimum number of observations selectable by this component. It also sets back the currently displayed range to the overall range.

Parameters:
newMinNumberOfObs - any int value. If it is larger than the current range, then only the whole range is still valid. Otherwise no selection would be possible anymore.

setTSDateRange

public void setTSDateRange(TSDateRange newTSDateRange)
Sets the currently displayed date range if it conforms to the specified overall range. This method fires a "TSDateRange" property change with the old value and the changed value if a new date range was set.

Parameters:
newTSDateRange - the range to be displayed
Throws:
java.lang.IllegalArgumentException - if newTSDateRange does not fit in overall range or is null

validateInput

public java.lang.String validateInput()
Validates input against the TSDateParser and the overall TSDateRange. It also checks the minimum number of observations restriction.

Specified by:
validateInput in class IValTextField
Returns:
error message if failure, null if ok