- Forward


Cut, Copy and Paste
in Java


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

Introduction
Back SMYC Forward
  • Drag and Drop (DnD):
    • A gesture-based mechanism that allows for data transfer from one GUI component to another
  • Cut, Copy and Paste (CCP):
    • A keyboard-based or virtual keyboard-based mechanism that allows for data transfer from one GUI compoenent to another
Background
Back SMYC Forward
  • Participants from Drag and Drop:
    • An Object that implements the Transferable interface
    • A DataFlavor that describes the Transferable
  • New Participants:
    • The actions
    • A Component that supports the actions
Image Cut, Copy and Paste using a Custom TransferHandler
Back SMYC Forward
  • The Desired Functionality:
    • The ability to cut and copy an image to the system clipboard and paste an image from the system clipboard
  • New Issues:
    • We need to worry about the keyboard focus
    • We need to add keyboard support
Image CCP using a Custom TransferHandler (cont.)
Back SMYC Forward
Forwarding the Focus
javaexamples/cutcopypaste/image/customhandler/ActionForwarder.java
 
Image CCP using a Custom TransferHandler (cont.)
Back SMYC Forward
Setting-Up the ActionForwarder in the Application
javaexamples/cutcopypaste/image/customhandler/ImagePanelDemo.java (Fragment: CCP)
 
Image CCP using a Custom TransferHandler (cont.)
Back SMYC Forward
Setting-Up the Keyboard Handling
javaexamples/cutcopypaste/image/customhandler/ImagePanel.java (Fragment: CCP)
 
Image CCP using a Custom TransferHandler (cont.)
Back SMYC Forward
  • What This Relies On:
    • The data transfer capabilities developed for DnD
  • In Case You Didn't Attend That Lecture:
    • Those classes are detailed below
Image CCP using a Custom TransferHandler
Back SMYC Forward
Requirements of the GUI Component
javaexamples/cutcopypaste/image/customhandler/ImageTransferer.java
 
Image CCP using a Custom TransferHandler
Back SMYC Forward
The Transferable
javaexamples/cutcopypaste/image/customhandler/ImageSelection.java
 
Image CCP using a Custom TransferHandler
Back SMYC Forward
The Custom TransferHandler
javaexamples/cutcopypaste/image/customhandler/ImageTransferHandler.java
 
Image CCP using a Custom TransferHandler
Back SMYC Forward
The GUI Component
javaexamples/cutcopypaste/image/customhandler/ImagePanel.java
 
There's Always More to Learn
Back -