PamView
Class ClipboardCopier

java.lang.Object
  extended by PamView.ClipboardCopier
All Implemented Interfaces:
java.awt.datatransfer.ClipboardOwner, java.awt.datatransfer.Transferable, java.awt.print.Printable

public class ClipboardCopier
extends java.lang.Object
implements java.awt.datatransfer.ClipboardOwner, java.awt.datatransfer.Transferable, java.awt.print.Printable

Class to Copy graphics content to the clipboard and the printer

Written so that it can easily be added to any PAMGUARD component. Provides default menu items for including in pop up menus or main menu.

Author:
Doug Gillespie

Nested Class Summary
(package private)  class ClipboardCopier.CopyToClipboard
          Action listener for menu items.
(package private)  class ClipboardCopier.PrintAction
          Action listener for menu items.
 
Field Summary
private  java.awt.Component component
           
private  java.awt.Image image
           
private  java.lang.String printJobName
           
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Constructor Summary
ClipboardCopier(java.awt.Component component)
           
ClipboardCopier(java.awt.Component component, java.lang.String printJobName)
           
 
Method Summary
 void copyToClipBoard()
          Copy an image of the component to the clip board
private  void createTransferImage()
          Create the image to be transfered to the clipboard.
 javax.swing.JMenuItem getCopyMenuItem()
          Get a menu item with a default title of "Copy to clipboard".
 javax.swing.JMenuItem getCopyMenuItem(java.lang.String menuTitle)
          Get a menu item with a given title.
 java.lang.String getPrintJobName()
           
 javax.swing.JMenuItem getPrintMenuItem()
          Get a menu item with a default title of "Print ...".
 javax.swing.JMenuItem getPrintMenuItem(java.lang.String menuTitle)
          Get a menu item with a given title.
 java.lang.Object getTransferData(java.awt.datatransfer.DataFlavor flavor)
           
 java.awt.datatransfer.DataFlavor[] getTransferDataFlavors()
           
private  java.awt.Image getTransferImage()
          Get the transfer image.
 boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor flavor)
           
 void lostOwnership(java.awt.datatransfer.Clipboard arg0, java.awt.datatransfer.Transferable arg1)
           
 int print(java.awt.Graphics g, java.awt.print.PageFormat pf, int page)
           
private  void printComponent()
          Menu command to print.
 void setPrintJobName(java.lang.String printJobName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

component

private java.awt.Component component

image

private java.awt.Image image

printJobName

private java.lang.String printJobName
Constructor Detail

ClipboardCopier

public ClipboardCopier(java.awt.Component component)
Parameters:
component - Component to copy. All children will also be copied.

ClipboardCopier

public ClipboardCopier(java.awt.Component component,
                       java.lang.String printJobName)
Parameters:
component - Component to copy. All children will also be copied.
printJobName - name for print job (default is PAMGUARD)
Method Detail

copyToClipBoard

public void copyToClipBoard()
Copy an image of the component to the clip board


createTransferImage

private void createTransferImage()
Create the image to be transfered to the clipboard.


lostOwnership

public void lostOwnership(java.awt.datatransfer.Clipboard arg0,
                          java.awt.datatransfer.Transferable arg1)
Specified by:
lostOwnership in interface java.awt.datatransfer.ClipboardOwner

getTransferData

public java.lang.Object getTransferData(java.awt.datatransfer.DataFlavor flavor)
                                 throws java.awt.datatransfer.UnsupportedFlavorException,
                                        java.io.IOException
Specified by:
getTransferData in interface java.awt.datatransfer.Transferable
Throws:
java.awt.datatransfer.UnsupportedFlavorException
java.io.IOException

getTransferImage

private java.awt.Image getTransferImage()
Get the transfer image. Create if necessary.

Returns:
image to transfer.

getTransferDataFlavors

public java.awt.datatransfer.DataFlavor[] getTransferDataFlavors()
Specified by:
getTransferDataFlavors in interface java.awt.datatransfer.Transferable

isDataFlavorSupported

public boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor flavor)
Specified by:
isDataFlavorSupported in interface java.awt.datatransfer.Transferable

printComponent

private void printComponent()
Menu command to print. Sets up job, system does the rest


print

public int print(java.awt.Graphics g,
                 java.awt.print.PageFormat pf,
                 int page)
          throws java.awt.print.PrinterException
Specified by:
print in interface java.awt.print.Printable
Throws:
java.awt.print.PrinterException

getCopyMenuItem

public javax.swing.JMenuItem getCopyMenuItem()
Get a menu item with a default title of "Copy to clipboard". Menu action listeners will automatically be set up

Returns:
menu item.

getCopyMenuItem

public javax.swing.JMenuItem getCopyMenuItem(java.lang.String menuTitle)
Get a menu item with a given title. Menu action listeners will automatically be set up

Parameters:
menuTitle - menu title
Returns:
menu item.

getPrintMenuItem

public javax.swing.JMenuItem getPrintMenuItem()
Get a menu item with a default title of "Print ...". Menu action listeners will automatically be set up

Returns:
menu item.

getPrintMenuItem

public javax.swing.JMenuItem getPrintMenuItem(java.lang.String menuTitle)
Get a menu item with a given title. Menu action listeners will automatically be set up

Parameters:
menuTitle - menu title
Returns:
menu item.

getPrintJobName

public java.lang.String getPrintJobName()

setPrintJobName

public void setPrintJobName(java.lang.String printJobName)