Class StringPaster
java.lang.Object
java.awt.event.MouseAdapter
uk.ac.starlink.util.gui.StringPaster
- All Implemented Interfaces:
MouseListener, MouseMotionListener, MouseWheelListener, EventListener
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(String) method and add it to the component you want to act on
using Component.addMouseListener(MouseListener).- Since:
- 3 Dec 2004
- Author:
- Mark Taylor (Starlink), Sun Microsystems
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected ToolkitReturns the Toolkit holding the selection.protected booleanisPasteEvent(MouseEvent evt) Determines whether a mouse event counts as a paste.voidmouseClicked(MouseEvent evt) Invokespasted(String)if appropriate.protected abstract voidInvoked when a paste event occurs.Methods inherited from class MouseAdapter
mouseDragged, mouseEntered, mouseExited, mouseMoved, mousePressed, mouseReleased, mouseWheelMoved
-
Constructor Details
-
StringPaster
public StringPaster()
-
-
Method Details
-
mouseClicked
Invokespasted(String)if appropriate.- Specified by:
mouseClickedin interfaceMouseListener- Overrides:
mouseClickedin classMouseAdapter
-
isPasteEvent
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
evtcounts as a paste gesture
-
getToolkit
Returns the Toolkit holding the selection. The default implementation returns AWT's default toolkit.- Returns:
- toolkit for selection
-
pasted
Invoked when a paste event occurs.- Parameters:
str- a string that has been pasted from the system-wide selection
-