Class StringPaster

  • All Implemented Interfaces:
    java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.MouseWheelListener, java.util.EventListener

    public abstract class StringPaster
    extends java.awt.event.MouseAdapter
    Utility class to facilitate actions when a string is pasted into a component. If you select some text on a windowing system it's possible to paste it into a JTextComponent which is a convenient way of saving typing. Implementing this for other components is rather fiddly - this class does the hard work for you. To use it, implement the abstract pasted(java.lang.String) method and add it to the component you want to act on using Component.addMouseListener(java.awt.event.MouseListener).
    Since:
    3 Dec 2004
    Author:
    Mark Taylor (Starlink), Sun Microsystems
    • Constructor Summary

      Constructors 
      Constructor Description
      StringPaster()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.awt.Toolkit getToolkit()
      Returns the Toolkit holding the selection.
      protected boolean isPasteEvent​(java.awt.event.MouseEvent evt)
      Determines whether a mouse event counts as a paste.
      void mouseClicked​(java.awt.event.MouseEvent evt)
      Invokes pasted(java.lang.String) if appropriate.
      protected abstract void pasted​(java.lang.String str)
      Invoked when a paste event occurs.
      • Methods inherited from class java.awt.event.MouseAdapter

        mouseDragged, mouseEntered, mouseExited, mouseMoved, mousePressed, mouseReleased, mouseWheelMoved
      • Methods inherited from class java.lang.Object

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

      • StringPaster

        public StringPaster()
    • Method Detail

      • mouseClicked

        public void mouseClicked​(java.awt.event.MouseEvent evt)
        Invokes pasted(java.lang.String) if appropriate.
        Specified by:
        mouseClicked in interface java.awt.event.MouseListener
        Overrides:
        mouseClicked in class java.awt.event.MouseAdapter
      • isPasteEvent

        protected boolean isPasteEvent​(java.awt.event.MouseEvent evt)
        Determines whether a mouse event counts as a paste. The default implementation returns true for a single-click using the middle mouse button.
        Parameters:
        evt - mouse event
        Returns:
        true iff evt counts as a paste gesture
      • getToolkit

        protected java.awt.Toolkit getToolkit()
        Returns the Toolkit holding the selection. The default implementation returns AWT's default toolkit.
        Returns:
        toolkit for selection
      • pasted

        protected abstract void pasted​(java.lang.String str)
        Invoked when a paste event occurs.
        Parameters:
        str - a string that has been pasted from the system-wide selection