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

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()
          Constructs an empty file attachment object.
FileAttachment(byte[] fileContents, String fileName, String popupText)
          Constructs a file attachment annotation.
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.
static Vector getIconNames()
          Returns a vector containing the possible names for the file attachment icon.
 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.
 Rectangle2D getRectangle()
          Override getRectangle: Bounds are set by the size of the text icon
 String getSubtype()
          Returns this annotation's subtype: "File-Attachment"
 boolean isPrintable()
          Sound icon never prints.
 void openFile(String tempFileName)
          Open the file.
 void paintImpl(Graphics g, boolean hasFocus)
          Draws the text icon.
 void revalidate()
          Revalidates this annotation.
 void saveFile(File outFile)
          Saves the content of the file to a file.
 void setColor(Color c)
          Sets the annotation's color.
 void setFileContents(byte[] fileContents)
          Sets the file contents for the file attachment.
 void setFileContents(FileContentProvider provider)
          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.
 void writeContents(OutputStream outStream)
          Write the contents of the file attachment to an output stream
 
Methods inherited from class com.qoppa.pdf.annotations.Annotation
getActions, getAppearStream, getBorderStyle, getBorderWidth, getColor, getComponent, getContents, getCreationDate, getCreator, getFlags, getLayer, getName, getOpacity, getPopup, getTriggerActions, isHidden, isInvisible, isLocked, isNoRotate, isNoView, isNoZoom, isReadOnly, paint, print, setActions, setAppearStream, setBorderStyle, setBorderWidth, setComponent, setComponentVisible, setCreationDate, setCreator, setFlags, setHidden, setInvisible, setLayer, 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()
Constructs an empty file attachment object.


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(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.

setColor

public void setColor(Color c)
Sets the annotation's color.

Overrides:
setColor in class Annotation
Parameters:
c - The new color.

setFileContents

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

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

setFileContents

public void setFileContents(FileContentProvider provider)
Sets the file contents for the file attachment.

Parameters:
provider - The provider of the file contents

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

getRectangle

public Rectangle2D getRectangle()
Override getRectangle: Bounds are set by the size of the text icon

Overrides:
getRectangle in class Annotation
Returns:
The annotation's location on the page.

writeContents

public void writeContents(OutputStream outStream)
                   throws IOException
Write the contents of the file attachment to an output stream

Throws:
IOException

saveFile

public void saveFile(File outFile)
              throws PDFException
Saves the content of the file to a file.

Parameters:
outFile - the file to save to.
Throws:
PDFException

openFile

public void openFile(String tempFileName)
              throws IOException,
                     PDFException
Open the file.

Parameters:
tempFileName - the temporary name of the file created for display.
Throws:
IOException
PDFException

getIconNames

public static Vector getIconNames()
Returns a vector containing the possible names for the file attachment icon.