Class RolloverProducer

  • All Implemented Interfaces:
    java.awt.event.ComponentListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.util.EventListener
    Direct Known Subclasses:
    ListRolloverProducer, TableRolloverProducer, TreeRolloverProducer

    public abstract class RolloverProducer
    extends java.lang.Object
    implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.ComponentListener
    Mouse/Motion/Listener which maps mouse coordinates to client coordinates and stores these as client properties in the target JComponent. The exact mapping process is left to subclasses. Typically, they will map to "cell" coordinates.

    Note: this class assumes that the target component is of type JComponent.

    Note: this implementation is stateful, it can't be shared across different instances of a target component.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String CLICKED_KEY
      Key for client property mapped from mouse-triggered action.
      private boolean isDragging  
      private static java.util.logging.Logger LOG  
      protected java.awt.Point rollover
      Current mouse location in client coordinates.
      static java.lang.String ROLLOVER_KEY
      Key for client property mapped from rollover events
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void componentHidden​(java.awt.event.ComponentEvent e)  
      void componentMoved​(java.awt.event.ComponentEvent e)  
      void componentResized​(java.awt.event.ComponentEvent e)  
      void componentShown​(java.awt.event.ComponentEvent e)  
      void install​(javax.swing.JComponent component)
      Installs all listeners, as required.
      protected boolean isClick​(java.awt.event.MouseEvent e, java.awt.Point oldRollover, boolean wasDragging)
      Returns a boolean indicating whether or not the given mouse event should be interpreted as a click.
      void mouseClicked​(java.awt.event.MouseEvent e)
      Implemented to do nothing.
      void mouseDragged​(java.awt.event.MouseEvent e)
      Implemented to set a dragging flag to true.
      void mouseEntered​(java.awt.event.MouseEvent e)
      Implemented to map to client property rollover and fire only if client coordinate changed.
      void mouseExited​(java.awt.event.MouseEvent e)
      Implemented to remove client properties rollover and clicked.
      void mouseMoved​(java.awt.event.MouseEvent e)
      Implemented to map to client property rollover and fire only if client coordinate changed.
      void mousePressed​(java.awt.event.MouseEvent e)
      Implemented to do nothing.
      void mouseReleased​(java.awt.event.MouseEvent e)
      Implemented to map to Rollover properties as needed.
      void release​(javax.swing.JComponent component)
      Removes all listeners.
      protected void updateClientProperty​(javax.swing.JComponent component, java.lang.String property, boolean fireAlways)
      Sets the given client property to the value of current mouse location in client coordinates.
      private void updateRollover​(java.awt.event.ComponentEvent e)  
      protected void updateRollover​(java.awt.event.MouseEvent e, java.lang.String property, boolean fireAlways)
      Controls the mapping of the given mouse event to a client property.
      protected abstract void updateRolloverPoint​(javax.swing.JComponent component, java.awt.Point mousePoint)
      Subclasses must implement to map the given mouse coordinates into appropriate client coordinates.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOG

        private static final java.util.logging.Logger LOG
      • CLICKED_KEY

        public static final java.lang.String CLICKED_KEY
        Key for client property mapped from mouse-triggered action. Note that the actual mouse-event which results in setting the property depends on the implementation of the concrete RolloverProducer.
        See Also:
        Constant Field Values
      • ROLLOVER_KEY

        public static final java.lang.String ROLLOVER_KEY
        Key for client property mapped from rollover events
        See Also:
        Constant Field Values
      • isDragging

        private boolean isDragging
      • rollover

        protected java.awt.Point rollover
        Current mouse location in client coordinates.
    • Constructor Detail

      • RolloverProducer

        public RolloverProducer()
    • Method Detail

      • install

        public void install​(javax.swing.JComponent component)
        Installs all listeners, as required.
        Parameters:
        component - target to install required listeners on, must not be null.
      • release

        public void release​(javax.swing.JComponent component)
        Removes all listeners.
        Parameters:
        component - target component to uninstall required listeners from, must not be null
      • mouseReleased

        public void mouseReleased​(java.awt.event.MouseEvent e)
        Implemented to map to Rollover properties as needed. This implemenation calls updateRollover with both ROLLOVER_KEY and CLICKED_KEY properties.
        Specified by:
        mouseReleased in interface java.awt.event.MouseListener
      • isClick

        protected boolean isClick​(java.awt.event.MouseEvent e,
                                  java.awt.Point oldRollover,
                                  boolean wasDragging)
        Returns a boolean indicating whether or not the given mouse event should be interpreted as a click. This method is called from mouseReleased after the cell coordiates were updated. While the ID of mouse event is not formally enforced, it is assumed to be a MOUSE_RELEASED. Calling for other types might or might not work as expected.

        This implementation returns true if the current rollover point is the same cell as the given oldRollover, that is ending a drag inside the same cell triggers the action while ending a drag somewhere does not.

        PENDING JW: open to more complex logic in case it clashes with existing code, see Issue #1387.

        Parameters:
        e - the mouseEvent which triggered calling this, assumed to be a mouseReleased, must not be null
        oldRollover - the cell before the mouseEvent was mapped, must not be null
        wasDragging - true if the release happened
        Returns:
        a boolean indicating whether or not the given mouseEvent should be interpreted as a click.
      • mouseEntered

        public void mouseEntered​(java.awt.event.MouseEvent e)
        Implemented to map to client property rollover and fire only if client coordinate changed.
        Specified by:
        mouseEntered in interface java.awt.event.MouseListener
      • mouseExited

        public void mouseExited​(java.awt.event.MouseEvent e)
        Implemented to remove client properties rollover and clicked. if the source is a JComponent. Does nothing otherwise.
        Specified by:
        mouseExited in interface java.awt.event.MouseListener
      • mouseClicked

        public void mouseClicked​(java.awt.event.MouseEvent e)
        Implemented to do nothing.
        Specified by:
        mouseClicked in interface java.awt.event.MouseListener
      • mousePressed

        public void mousePressed​(java.awt.event.MouseEvent e)
        Implemented to do nothing.
        Specified by:
        mousePressed in interface java.awt.event.MouseListener
      • mouseDragged

        public void mouseDragged​(java.awt.event.MouseEvent e)
        Implemented to set a dragging flag to true.
        Specified by:
        mouseDragged in interface java.awt.event.MouseMotionListener
      • mouseMoved

        public void mouseMoved​(java.awt.event.MouseEvent e)
        Implemented to map to client property rollover and fire only if client coordinate changed.
        Specified by:
        mouseMoved in interface java.awt.event.MouseMotionListener
      • componentShown

        public void componentShown​(java.awt.event.ComponentEvent e)
        Specified by:
        componentShown in interface java.awt.event.ComponentListener
      • componentResized

        public void componentResized​(java.awt.event.ComponentEvent e)
        Specified by:
        componentResized in interface java.awt.event.ComponentListener
      • componentMoved

        public void componentMoved​(java.awt.event.ComponentEvent e)
        Specified by:
        componentMoved in interface java.awt.event.ComponentListener
      • updateRollover

        private void updateRollover​(java.awt.event.ComponentEvent e)
        Parameters:
        e -
      • componentHidden

        public void componentHidden​(java.awt.event.ComponentEvent e)
        Specified by:
        componentHidden in interface java.awt.event.ComponentListener
      • updateRollover

        protected void updateRollover​(java.awt.event.MouseEvent e,
                                      java.lang.String property,
                                      boolean fireAlways)
        Controls the mapping of the given mouse event to a client property. This implementation first calls updateRolloverPoint to convert the mouse coordinates. Then calls updateClientProperty to actually set the client property in the
        Parameters:
        e - the MouseEvent to map to client coordinates
        property - the client property to map to
        fireAlways - a flag indicating whether a client event should be fired if unchanged.
        See Also:
        updateRolloverPoint(JComponent, Point), updateClientProperty(JComponent, String, boolean)
      • updateClientProperty

        protected void updateClientProperty​(javax.swing.JComponent component,
                                            java.lang.String property,
                                            boolean fireAlways)
        Sets the given client property to the value of current mouse location in client coordinates. If fireAlways, the property is force to fire a change.
        Parameters:
        component - the target component
        property - the client property to set
        fireAlways - a flag indicating whether a client property should be forced to fire an event.
      • updateRolloverPoint

        protected abstract void updateRolloverPoint​(javax.swing.JComponent component,
                                                    java.awt.Point mousePoint)
        Subclasses must implement to map the given mouse coordinates into appropriate client coordinates. The result must be stored in the rollover field.
        Parameters:
        component - the target component which received a mouse event
        mousePoint - the mouse position of the event, coordinates are component pixels