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

public class TimeSlider extends JComponent implements MouseListener, MouseMotionListener
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:
  • 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 minimum
      The minimum time.
    • start

      protected double start
      The start of the selected time range.
    • value

      protected double value
      The selected time.
    • end

      protected double end
      The end of the selected time range.
    • maximum

      protected double maximum
      The maximum time.
    • timeRanges

      protected final List<TimeRange> timeRanges
      List of event markers. * protected final List markers; /** List of valid time ranges.
    • actualTimeRanges

      protected final List<TimeRange> actualTimeRanges
      List of valid times ranges, taking into account the minimum and maximum
    • startButton

      protected final JButton startButton
      The button used to indicate the start time.
    • valueButton

      protected final JButton valueButton
      The button used to indicate the time.
    • endButton

      protected final JButton endButton
      The button used to indicate the end time.
    • 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

      public void setTimeRanges(List<TimeRange> newTimeRanges)
      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.
      Overrides:
      doLayout in class Container
    • paintComponent

      protected void paintComponent(Graphics g)
      Paint the components. Also paint the slider and the markers.
      Overrides:
      paintComponent in class JComponent
    • getMinimumSize

      public Dimension getMinimumSize()
      Get the minimum dimensions for this component.
      Overrides:
      getMinimumSize in class JComponent
      Returns:
      the minimum dimensions
    • getPreferredSize

      public Dimension getPreferredSize()
      Get the preferred size for this component.
      Overrides:
      getPreferredSize in class JComponent
      Returns:
      the preferred dimensions
    • createToolTip

      public JToolTip createToolTip()
      Creates the tooltip for the component. This changes the default tooltip by setting a different border.
      Overrides:
      createToolTip in class JComponent
      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

      public void mouseDragged(MouseEvent me)
      Called when the mouse is dragged. This deals dragging the time value and range controls.
      Specified by:
      mouseDragged in interface MouseMotionListener
      Parameters:
      me - the mosue event that triggered this
    • mousePressed

      public void mousePressed(MouseEvent me)
      Called when the mouse is pressed. Used to tell when the value control is being adjusted.
      Specified by:
      mousePressed in interface MouseListener
      Parameters:
      me - the mouse event that triggered this
    • mouseReleased

      public void mouseReleased(MouseEvent me)
      Called whn the mouse is released. Used to tell when the value control is being adjusted.
      Specified by:
      mouseReleased in interface MouseListener
      Parameters:
      me - the mouse event that triggered this
    • mouseMoved

      public void mouseMoved(MouseEvent me)
      Specified by:
      mouseMoved in interface MouseMotionListener
    • mouseClicked

      public void mouseClicked(MouseEvent me)
      Called when the mouse is clicked. Used to set the time value when there is a click on the time slider.
      Specified by:
      mouseClicked in interface MouseListener
      Parameters:
      me - the mouse event that triggered this
    • mouseEntered

      public void mouseEntered(MouseEvent me)
      Specified by:
      mouseEntered in interface MouseListener
    • mouseExited

      public void mouseExited(MouseEvent me)
      Specified by:
      mouseExited in interface MouseListener
    • addTimeAdjustmentListener

      public void addTimeAdjustmentListener(TimeAdjustmentListener l)
      Add a listener for time adjustments.
      Parameters:
      l - the listener to add
    • removeTimeAdjustmentListener

      public void removeTimeAdjustmentListener(TimeAdjustmentListener l)
      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:
      setEnabled in class JComponent
      Parameters:
      enabled - true if this component should be enabled, false otherwise