Class TimeSlider
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
org.gvsig.timesupport.swing.impl.rdv.TimeSlider
- All Implemented Interfaces:
MouseListener,MouseMotionListener,ImageObserver,MenuContainer,Serializable,EventListener
A component that lets the user select a specific time or time range between a
bounded time interval by sliding knobs along a timeline. It also allows one
to display an event indicator at a specific time in the time line. (Modified by Pablo Viciano)
- Author:
- Jason P. Hanley
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionList of valid times ranges, taking into account the minimum and maximumprotected doubleThe end of the selected time range.protected final JButtonThe button used to indicate the end time.protected booleanprotected doubleThe maximum time.static final longstatic final longstatic final longstatic final longstatic final longstatic final longstatic final longprotected doubleThe minimum time.protected booleanprotected doubleThe start of the selected time range.protected final JButtonThe button used to indicate the start time.List of event markers. * protected final Listmarkers; /** List of valid time ranges. protected doubleThe selected time.protected final JButtonThe button used to indicate the time.Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionTimeSlider(boolean isAbsolute) Creates a time slider with the maximum available range. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a listener for time adjustments.voidRemove all time ranges.Creates the tooltip for the component.voiddoLayout()Layout the buttons.protected voidFires a bounds changed event to all adjustment listeners.voidFires a range changed event to all adjustment listeners.voidFires a value changed event to all adjustment listeners.doubleGet the maximum value allowed on the time slider.doubleGet the minimum value allowed on the time slider.org.gvsig.timesupport.InstantGet the current DateTime if the value is changeable or null if the value isn't changeable.org.gvsig.timesupport.InstantReturns a DateTime instance to represents the end datedoubleGets the maximum allowed time value.doubleGets the minimum allowed time value.Get the minimum dimensions for this component.doublegetNextValidTime(double time) Get a time that is valid and greater than or equal to the current one.Get the preferred size for this component.org.gvsig.timesupport.InstantGets the text for the tooltip.booleanbooleanisTimeValid(double time) Tell if the time is valid with respect to the current time bounds and ranges.booleanIndicates if the value is being continuously changed in the UI.voidCalled when the mouse is clicked.voidCalled when the mouse is dragged.voidvoidvoidmouseMoved(MouseEvent me) voidCalled when the mouse is pressed.voidCalled whn the mouse is released.voidmoveLeft(boolean left) voidmoveRight(boolean right) protected voidPaint the components.voidRemove a listener for time adjustments.voidReset all datesvoidReset to maximum datevoidReset to minimum datevoidReset to initial value datevoidsetCurrentInstant(org.gvsig.timesupport.Instant currentInstant) Sets the current time of the slidervoidsetEnabled(boolean enabled) Sets if this component is enabled.voidsetEndInstant(org.gvsig.timesupport.Instant endInstant) Sets the end DateTime of the slidervoidsetRangeChangeable(boolean changeable) Set if a time range can be changed via the UI elementsvoidsetStartInstant(org.gvsig.timesupport.Instant startInstant) Set the start DateTime of the slidervoidsetTimeRanges(List<TimeRange> newTimeRanges) Replace the current set of time ranges with this one.voidsetValueChangeable(boolean changeable) Sets if the time value of the slider can be changed by the UI element.voidsetValues(org.gvsig.timesupport.Instant minimunInstant, org.gvsig.timesupport.Instant maximumInstant) voidsetValueVisible(boolean visible) Set if the value is visible in the slider UI.Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, 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, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUI, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, 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, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUIMethods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, 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, transferFocusDownCycle, validate, validateTreeMethods 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, getAccessibleContext, 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
MILLIS_BY_SECOND
public static final long MILLIS_BY_SECOND- See Also:
-
MILLIS_BY_MINUTE
public static final long MILLIS_BY_MINUTE- See Also:
-
MILLIS_BY_HOUR
public static final long MILLIS_BY_HOUR- See Also:
-
MILLIS_BY_DAY
public static final long MILLIS_BY_DAY- See Also:
-
MILLIS_BY_WEEK
public static final long MILLIS_BY_WEEK- See Also:
-
MILLIS_BY_MONTH
public static final long MILLIS_BY_MONTH- See Also:
-
MILLIS_BY_YEAR
public static final long MILLIS_BY_YEAR- See Also:
-
minimum
protected double minimumThe minimum time. -
start
protected double startThe start of the selected time range. -
value
protected double valueThe selected time. -
end
protected double endThe end of the selected time range. -
maximum
protected double maximumThe maximum time. -
timeRanges
List of event markers. * protected final Listmarkers; /** List of valid time ranges. -
actualTimeRanges
List of valid times ranges, taking into account the minimum and maximum -
startButton
The button used to indicate the start time. -
valueButton
The button used to indicate the time. -
endButton
The button used to indicate the end time. -
right
protected boolean right -
left
protected boolean left
-
-
Constructor Details
-
TimeSlider
public TimeSlider(boolean isAbsolute) Creates a time slider with the maximum available range.
-
-
Method Details
-
setValueChangeable
public void setValueChangeable(boolean changeable) Sets if the time value of the slider can be changed by the UI element.- Parameters:
changeable- if true, the value can be changed, false otherwise.
-
getValueChangeable
public boolean getValueChangeable() -
setValueVisible
public void setValueVisible(boolean visible) Set if the value is visible in the slider UI.- Parameters:
visible- if true the value is shown, if false the value is not shown
-
setRangeChangeable
public void setRangeChangeable(boolean changeable) Set if a time range can be changed via the UI elements- Parameters:
changeable- if true, the time range can be changed, false otherwsie
-
moveRight
public void moveRight(boolean right) -
moveLeft
public void moveLeft(boolean left) -
setCurrentInstant
public void setCurrentInstant(org.gvsig.timesupport.Instant currentInstant) Sets the current time of the slider- Parameters:
current-
-
setStartInstant
public void setStartInstant(org.gvsig.timesupport.Instant startInstant) Set the start DateTime of the slider- Parameters:
start-
-
setEndInstant
public void setEndInstant(org.gvsig.timesupport.Instant endInstant) Sets the end DateTime of the slider- Parameters:
end-
-
setValues
public void setValues(org.gvsig.timesupport.Instant minimunInstant, org.gvsig.timesupport.Instant maximumInstant) -
getMinimum
public double getMinimum()Gets the minimum allowed time value.- Returns:
- the minimum allowed time value
-
getMaximum
public double getMaximum()Gets the maximum allowed time value.- Returns:
- the maximum allowed time value.
-
resetMinimumBound
public void resetMinimumBound()Reset to minimum date -
resetMaximumBound
public void resetMaximumBound()Reset to maximum date -
resetValue
public void resetValue()Reset to initial value date -
resetAllDates
public void resetAllDates()Reset all dates -
setTimeRanges
Replace the current set of time ranges with this one.- Parameters:
newTimeRanges- a list of time ranges
-
isTimeValid
public boolean isTimeValid(double time) Tell if the time is valid with respect to the current time bounds and ranges.- Parameters:
time- the time to check- Returns:
- true if the time is valid, false if it is not
-
getNextValidTime
public double getNextValidTime(double time) Get a time that is valid and greater than or equal to the current one.- Returns:
- the next valid time, or -1 if there is none
-
clearTimeRanges
public void clearTimeRanges()Remove all time ranges. -
isValueAdjusting
public boolean isValueAdjusting()Indicates if the value is being continuously changed in the UI.- Returns:
- true if the value is changing, false otherwise
-
getActualMinimum
public double getActualMinimum()Get the minimum value allowed on the time slider. This takes into account the time ranges.- Returns:
- the minimum value allowed on the time slider
-
getActualMaximum
public double getActualMaximum()Get the maximum value allowed on the time slider. This takes into account the time ranges.- Returns:
- the maximum value allowed on the time slider
-
doLayout
public void doLayout()Layout the buttons. -
paintComponent
Paint the components. Also paint the slider and the markers.- Overrides:
paintComponentin classJComponent
-
getMinimumSize
Get the minimum dimensions for this component.- Overrides:
getMinimumSizein classJComponent- Returns:
- the minimum dimensions
-
getPreferredSize
Get the preferred size for this component.- Overrides:
getPreferredSizein classJComponent- Returns:
- the preferred dimensions
-
createToolTip
Creates the tooltip for the component. This changes the default tooltip by setting a different border.- Overrides:
createToolTipin classJComponent- Returns:
- the tooltip created
-
getStartInstant
public org.gvsig.timesupport.Instant getStartInstant()Gets the text for the tooltip. This will return a description of the markers the mouse pointer is around.- Parameters:
me- the mouse event that triggered this- Returns:
- text describing the markers around the mouse pointer
public String getToolTipText(MouseEvent me) {
int x = me.getX();
if (me.getSource() == valueButton) {
x += valueButton.getX();
}
double time = getTimeFromX(x);
double timeOffset = time - value;
double markerOffset = 2 * getPixelTime();
// List
markersOver = getMarkersAroundTime(time, // markerOffset); String text = new String("invalid input: '<'font size=\"5\">"); return text; } /** Returns a DateTime instance to represents the start date
-
getEndInstant
public org.gvsig.timesupport.Instant getEndInstant()Returns a DateTime instance to represents the end date -
getCurrentInstant
public org.gvsig.timesupport.Instant getCurrentInstant()Get the current DateTime if the value is changeable or null if the value isn't changeable.- Returns:
-
mouseDragged
Called when the mouse is dragged. This deals dragging the time value and range controls.- Specified by:
mouseDraggedin interfaceMouseMotionListener- Parameters:
me- the mosue event that triggered this
-
mousePressed
Called when the mouse is pressed. Used to tell when the value control is being adjusted.- Specified by:
mousePressedin interfaceMouseListener- Parameters:
me- the mouse event that triggered this
-
mouseReleased
Called whn the mouse is released. Used to tell when the value control is being adjusted.- Specified by:
mouseReleasedin interfaceMouseListener- Parameters:
me- the mouse event that triggered this
-
mouseMoved
- Specified by:
mouseMovedin interfaceMouseMotionListener
-
mouseClicked
Called when the mouse is clicked. Used to set the time value when there is a click on the time slider.- Specified by:
mouseClickedin interfaceMouseListener- Parameters:
me- the mouse event that triggered this
-
mouseEntered
- Specified by:
mouseEnteredin interfaceMouseListener
-
mouseExited
- Specified by:
mouseExitedin interfaceMouseListener
-
addTimeAdjustmentListener
Add a listener for time adjustments.- Parameters:
l- the listener to add
-
removeTimeAdjustmentListener
Remove a listener for time adjustments.- Parameters:
l- the listener to remove
-
fireValueChanged
public void fireValueChanged()Fires a value changed event to all adjustment listeners. -
fireRangeChanged
public void fireRangeChanged()Fires a range changed event to all adjustment listeners. -
fireBoundsChanged
protected void fireBoundsChanged()Fires a bounds changed event to all adjustment listeners. -
setEnabled
public void setEnabled(boolean enabled) Sets if this component is enabled. If the component is not enabled, the time value and range controls will not respond to user input.- Overrides:
setEnabledin classJComponent- Parameters:
enabled- true if this component should be enabled, false otherwise
-