com.qoppa.pdf.annotations
Class FileAttachment

java.lang.Object
  extended bycom.qoppa.pdf.annotations.Annotation
      extended bycom.qoppa.pdf.annotations.FileAttachment

public class FileAttachment
extends Annotation

Class representing a File Attachment annotation in a PDF document.

Author:
Qoppa Software

Nested Class Summary
static interface FileAttachment.FileContentProvider
          Interface used to provide data to the FileAttachment class.
 
Field Summary
static String ICON_DEFAULT
           
static String ICON_GRAPH
           
static String ICON_PAPERCLIP
           
static String ICON_PUSHPIN
           
static String ICON_TAG
           
 
Fields inherited from class com.qoppa.pdf.annotations.Annotation
BORDERSTYLE_BEVELED, BORDERSTYLE_DASHED, BORDERSTYLE_INSETS, BORDERSTYLE_SOLID, BORDERSTYLE_UNDERLINE, FLAGS_HIDDEN, FLAGS_INVISIBLE, FLAGS_LOCKED, FLAGS_NOROTATE, FLAGS_NOVIEW, FLAGS_NOZOOM, FLAGS_PRINTABLE, FLAGS_READONLY
 
Constructor Summary
FileAttachment(byte[] fileContents, String fileName, String popupText)
          Constructs a file attachment annotation.
FileAttachment(FileAttachment.FileContentProvider contents, String fileName, String popupText)
          Constructor used when the file contents may not be so easily accessible as a byte array or file.
FileAttachment(File attachFile, String popupText)
          Convenience constructor to create a file attachment from a file system file.
 
Method Summary
 JComponent createComponent(Point2D cropOrigin, IPDFActionHandler actionHandler)
          Creates a JComponent object capable of displaying this annotation.
 byte[] getCheckSum()
          Returns the CRC checksum for the file contents.
 byte[] getDeflatedContents()
          Returns the file contents in deflated format
 String getFileName()
          Returns the name of the file.
 int getFileSize()
          Returns the length of the file, in bytes.
 String getIconName()
          Returns the name of the icon for this annotation.
 InputStream getInputStream()
          Returns the file contents as an input stream.
 String getPopupText()
          Returns the text that is displayed when the mouse hovers over the annotation.
 String getSubtype()
          Returns this annotation's subtype: "File-Attachment"
 boolean isPrintable()
          Sound icon never prints.
 void paintImpl(Graphics g, boolean hasFocus)
          Draws the text icon.
 void revalidate()
          Revalidates this annotation.
 void setFileContents(byte[] fileContents)
          Sets the file contents for the file attachment.
 void setFileName(String fileName)
          Sets the name of the attached file.
 void setIconName(String iconName)
          Sets the icon name used when displaying this annotation.
 void setPopupText(String popupText)
          Sets the text that is displayed when the mouse hovers over the annotation.
 
Methods inherited from class com.qoppa.pdf.annotations.Annotation
getActions, getAppearStream, getBorderStyle, getBorderWidth, getColor, getComponent, getContents, getCreationDate, getCreator, getFlags, getName, getOpacity, getPopup, getRectangle, getTriggerActions, isHidden, isInvisible, isLocked, isNoRotate, isNoView, isNoZoom, isReadOnly, paint, paintAppearStream, print, setActions, setAppearStream, setBorderStyle, setBorderWidth, setColor, setComponent, setComponentVisible, setCreationDate, setCreator, setFlags, setHidden, setInvisible, setLocked, setName, setNoRotate, setNoView, setNoZoom, setOpacity, setPopup, setPrintable, setReadOnly, setRectangle, setTriggerActions, shiftRectangle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ICON_GRAPH

public static final String ICON_GRAPH
See Also:
Constant Field Values

ICON_PAPERCLIP

public static final String ICON_PAPERCLIP
See Also:
Constant Field Values

ICON_PUSHPIN

public static final String ICON_PUSHPIN
See Also:
Constant Field Values

ICON_TAG

public static final String ICON_TAG
See Also:
Constant Field Values

ICON_DEFAULT

public static final String ICON_DEFAULT
See Also:
Constant Field Values
Constructor Detail

FileAttachment

public FileAttachment(byte[] fileContents,
                      String fileName,
                      String popupText)
               throws IOException
Constructs a file attachment annotation. The entire contents of the file are passed in the fileContents array.

Parameters:
fileContents - The binary contents of the file.
fileName - The name of the file.
popupText - The popup text to display when the mouse hovers over the annotation.

FileAttachment

public FileAttachment(File attachFile,
                      String popupText)
               throws IOException
Convenience constructor to create a file attachment from a file system file.

Parameters:
attachFile - The file to attach. The constructor reads the contents of the file into memory.
popupText - The popup text to display when the mouse hovers over the annotation.
Throws:
IOException

FileAttachment

public FileAttachment(FileAttachment.FileContentProvider contents,
                      String fileName,
                      String popupText)
Constructor used when the file contents may not be so easily accessible as a byte array or file. The constructor takes an object that implements the FileContentProvider interface that is responsible for providing the data when needed (normally just when the PDF file is saved).

Parameters:
contents - An object that fulfills the FileContentProvider interface.
fileName - The name of the file to use in the PDF document.
popupText - The popup text to display when the mouse hovers over the annotation.
Throws:
IOException
Method Detail

getSubtype

public String getSubtype()
Returns this annotation's subtype: "File-Attachment"

Specified by:
getSubtype in class Annotation
Returns:
The annotation subtype.

createComponent

public JComponent createComponent(Point2D cropOrigin,
                                  IPDFActionHandler actionHandler)
Creates a JComponent object capable of displaying this annotation.

Specified by:
createComponent in class Annotation
Returns:
JComponent do display this annotation.

paintImpl

public void paintImpl(Graphics g,
                      boolean hasFocus)
Draws the text icon.

Parameters:
g - The graphics object to use when drawing.

revalidate

public void revalidate()
Description copied from class: Annotation
Revalidates this annotation.

Specified by:
revalidate in class Annotation

isPrintable

public boolean isPrintable()
Sound icon never prints.

Overrides:
isPrintable in class Annotation
Returns:
Value of the PRINTABLE flag

getIconName

public String getIconName()
Returns the name of the icon for this annotation.

Returns:
Name of the icon.

getPopupText

public String getPopupText()
Returns the text that is displayed when the mouse hovers over the annotation.

Returns:
Popup text.

setPopupText

public void setPopupText(String popupText)
Sets the text that is displayed when the mouse hovers over the annotation.

Parameters:
popupText - The new text string.

setIconName

public void setIconName(String iconName)
Sets the icon name used when displaying this annotation.

Parameters:
iconName - The name of the icon to use when displaying the annotation in its un-opened mode. Please use one of the constants defined in this class (ICON_XXXX) to set the name of the icon.

setFileContents

public void setFileContents(byte[] fileContents)
                     throws IOException
Sets the file contents for the file attachment.

Parameters:
fileContents - The new file contents.
Throws:
IOException

getFileName

public String getFileName()
Returns the name of the file.

Returns:
The name of the file attached.

setFileName

public void setFileName(String fileName)
Sets the name of the attached file.

Parameters:
fileName - The name of the file.

getFileSize

public int getFileSize()
                throws IOException,
                       PDFException
Returns the length of the file, in bytes.

Returns:
The file length.
Throws:
IOException
PDFException

getDeflatedContents

public byte[] getDeflatedContents()
                           throws IOException,
                                  PDFException
Returns the file contents in deflated format

Throws:
IOException
PDFException

getInputStream

public InputStream getInputStream()
                           throws IOException,
                                  PDFException
Returns the file contents as an input stream.

Throws:
IOException
PDFException

getCheckSum

public byte[] getCheckSum()
                   throws PDFException,
                          IOException
Returns the CRC checksum for the file contents.

Returns:
CRC
Throws:
PDFException
IOException