Gnostice PDFOne Java
Std. Ed. v2.10


com.gnostice.pdfone
Class PdfViewer

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by com.gnostice.pdfone.PdfViewer
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class PdfViewer
extends JPanel
implements Serializable

This class represents a container for displaying an existing PDF documents. A PdfViewer object can be used to display a document only in reading mode.

See Also:
Article: How To Create a Java PDF Viewer In A Snap, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Field Summary
static int ANGLE_0
          Constant for displaying a page without any rotation or tilt.
static int ANGLE_180
          Constant for displaying a page rotated on its center by 180 degrees.
static int ANGLE_270
          Constant for displaying a page rotated on its center by 270 degrees.
static int ANGLE_90
          Constant for displaying a page rotated on its center by 90 degrees.
static int PAGEVIEW_ACTUAL_SIZE
          Constant for displaying the pages in their original size inside the viewer.
static int PAGEVIEW_CUSTOM
          Constant for resizing the pages in a way not similar to PAGEVIEW_ACTUAL_SIZE, PAGEVIEW_FIT_PAGE, or PAGEVIEW_FIT_WIDTH.
static int PAGEVIEW_FIT_PAGE
          Constant for resizing the pages to tightly fit their entire height and width inside the viewer.
static int PAGEVIEW_FIT_WIDTH
          Constant for resizing the pages to tightly fit their entire width inside the viewer.
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
PdfViewer()
          Zero-argument default constructor.
 
Method Summary
 void closeDocument()
          Removes the display of the document on the viewer.
 void firstPage()
          Changes the current page to the first page in the document.
 Color getBackgroundColor()
          Returns background color of the space between the edges of the viewer and displayed PDF document.
 int getCurrentPage()
          Returns number of the currently displayed page.
 int getHorizontalScrollBarPolicy()
          Returns horizontal scrollbar policy value.
 int getPageCount()
          Returns total number of pages in the displayed document.
 int getPageView()
          Returns how the height and width of the pages are accommodated inside the viewer.
 Dimension getPreferredSize()
           
 int getRotationAngle()
          Returns angle of tilt applied to pages when they are displayed.
 int getVerticalScrollBarPolicy()
          Returns vertical scrollbar policy value.
 Insets getViewerInsets()
          Returns how the edges of the viewer are padded.
 double getZoom()
          Returns magnification factor with which pages are displayed.
 void lastPage()
          Changes the current page to the last page in the document.
 void loadDocument(PdfDocument d)
          Displays a specified PDF document.
 void nextPage()
          Changes current page to the one right after it in the document.
 Dimension preferredSize()
           
 void previousPage()
          Changes current page to the one right ahead of it in the document.
 void rotateClockwise()
          Rotates current page by 90 degrees in the clockwise direction.
 void rotateCounterClockwise()
          Rotates current page by 90 degrees in the counter-clockwise direction.
 void setBackgroundColor(Color bg)
          Sets specified color for background of the space between the edges of the viewer and displayed PDF document.
 void setCurrentPage(int pageNum)
          Changes currently displayed page to the specified page.
 void setHorizontalScrollBarPolicy(int hsbPolicy)
          Specifies when the horizontal scrollbar appears in the scrollpane.
 void setPageView(int PageView)
          Specifies how the height and width of the pages need to be accommodated inside the viewer.
 void setRotationAngle(int rotation)
          Specifies angle of tilt that need to be applied to pages when they are displayed.
 void setVerticalScrollBarPolicy(int vsbPolicy)
          Specifies when the vertical scrollbar appears in the scrollpane.
 void setViewerInsets(Insets insets)
          Specfies how the edges of the viewer are padded.
 void setZoom(double zoomFactor)
          Specifies magnification factor with which pages need to be displayed.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, printComponents, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PAGEVIEW_ACTUAL_SIZE

public static final int PAGEVIEW_ACTUAL_SIZE
Constant for displaying the pages in their original size inside the viewer.

See Also:
Constant Field Values

PAGEVIEW_FIT_PAGE

public static final int PAGEVIEW_FIT_PAGE
Constant for resizing the pages to tightly fit their entire height and width inside the viewer.

See Also:
Constant Field Values

PAGEVIEW_FIT_WIDTH

public static final int PAGEVIEW_FIT_WIDTH
Constant for resizing the pages to tightly fit their entire width inside the viewer.

See Also:
Constant Field Values

PAGEVIEW_CUSTOM

public static final int PAGEVIEW_CUSTOM
Constant for resizing the pages in a way not similar to PAGEVIEW_ACTUAL_SIZE, PAGEVIEW_FIT_PAGE, or PAGEVIEW_FIT_WIDTH.

See Also:
setZoom(double), getZoom(), Constant Field Values

ANGLE_0

public static final int ANGLE_0
Constant for displaying a page without any rotation or tilt.

See Also:
Constant Field Values

ANGLE_90

public static final int ANGLE_90
Constant for displaying a page rotated on its center by 90 degrees.

See Also:
Constant Field Values

ANGLE_180

public static final int ANGLE_180
Constant for displaying a page rotated on its center by 180 degrees.

See Also:
Constant Field Values

ANGLE_270

public static final int ANGLE_270
Constant for displaying a page rotated on its center by 270 degrees.

See Also:
Constant Field Values
Constructor Detail

PdfViewer

public PdfViewer()
Zero-argument default constructor. Call loadDocument(PdfDocument) to display a PDF document in the viewer.

Method Detail

preferredSize

public Dimension preferredSize()
Overrides:
preferredSize in class Container

getPreferredSize

public Dimension getPreferredSize()
Overrides:
getPreferredSize in class JComponent

setBackgroundColor

public void setBackgroundColor(Color bg)
Sets specified color for background of the space between the edges of the viewer and displayed PDF document.

Parameters:
bg - background color of the space between the edges of the viewer and displayed PDF document
See Also:
getBackgroundColor()

getBackgroundColor

public Color getBackgroundColor()
Returns background color of the space between the edges of the viewer and displayed PDF document.

Returns:
background color of the space between the edges of the viewer and displayed PDF document
See Also:
setBackgroundColor(Color)

setHorizontalScrollBarPolicy

public void setHorizontalScrollBarPolicy(int hsbPolicy)
Specifies when the horizontal scrollbar appears in the scrollpane.

Parameters:
hsbPolicy - ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER

getHorizontalScrollBarPolicy

public int getHorizontalScrollBarPolicy()
Returns horizontal scrollbar policy value.

Returns:
horizontal scrollbar policy value
See Also:
setHorizontalScrollBarPolicy(int)

setVerticalScrollBarPolicy

public void setVerticalScrollBarPolicy(int vsbPolicy)
Specifies when the vertical scrollbar appears in the scrollpane.

Parameters:
vsbPolicy - ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER
See Also:
getVerticalScrollBarPolicy(), setHorizontalScrollBarPolicy(int), getHorizontalScrollBarPolicy()

getVerticalScrollBarPolicy

public int getVerticalScrollBarPolicy()
Returns vertical scrollbar policy value.

Returns:
horizontal scrollbar policy value
See Also:
getVerticalScrollBarPolicy(), setHorizontalScrollBarPolicy(int), getHorizontalScrollBarPolicy()

setPageView

public void setPageView(int PageView)
                 throws PdfException
Specifies how the height and width of the pages need to be accommodated inside the viewer.

Parameters:
PageView - constant specifying how the height and width of the pages need to be accommodated inside the viewer
Throws:
PdfException - if an illegal argument is supplied.
See Also:
PAGEVIEW_ACTUAL_SIZE, PAGEVIEW_FIT_PAGE, PAGEVIEW_FIT_WIDTH, PAGEVIEW_CUSTOM, getPageView(), setZoom(double)

getPageView

public int getPageView()
Returns how the height and width of the pages are accommodated inside the viewer.

Returns:
constant describing how the height and width of the pages need to be accommodated inside the viewer.
See Also:
PAGEVIEW_ACTUAL_SIZE, PAGEVIEW_FIT_PAGE, PAGEVIEW_FIT_WIDTH, PAGEVIEW_CUSTOM, setPageView(int), setZoom(double)

rotateClockwise

public void rotateClockwise()
                     throws PdfException
Rotates current page by 90 degrees in the clockwise direction.

Throws:
PdfException - if an illegal argument is supplied.
See Also:
rotateCounterClockwise()

rotateCounterClockwise

public void rotateCounterClockwise()
                            throws PdfException
Rotates current page by 90 degrees in the counter-clockwise direction.

Throws:
PdfException - if an illegal argument is supplied.
See Also:
rotateClockwise()

previousPage

public void previousPage()
                  throws IOException,
                         PdfException
Changes current page to the one right ahead of it in the document.

Throws:
IOException - if an I/O error occurs.
PdfException - if an illegal argument is supplied.
See Also:
nextPage(), firstPage(), lastPage(), setCurrentPage(int)

nextPage

public void nextPage()
              throws IOException,
                     PdfException
Changes current page to the one right after it in the document.

Throws:
IOException
PdfException
See Also:
previousPage(), firstPage(), lastPage(), setCurrentPage(int)

firstPage

public void firstPage()
               throws IOException,
                      PdfException
Changes the current page to the first page in the document.

Throws:
IOException - if an I/O error occurs.
PdfException - if an illegal argument is supplied.
See Also:
lastPage(), previousPage(), nextPage(), setCurrentPage(int)

lastPage

public void lastPage()
              throws IOException,
                     PdfException
Changes the current page to the last page in the document.

Throws:
IOException - if an I/O error occurs.
PdfException - if an illegal argument is supplied.
See Also:
firstPage(), previousPage(), nextPage(), setCurrentPage(int)

setZoom

public void setZoom(double zoomFactor)
             throws PdfException
Specifies magnification factor with which pages need to be displayed.

Parameters:
zoomFactor - magnification factor with which pages need to be displayed
Throws:
PdfException - if an illegal argument is supplied.
See Also:
getZoom()

getZoom

public double getZoom()
Returns magnification factor with which pages are displayed.

Returns:
magnification factor with which pages are displayed
See Also:
setZoom(double)

setRotationAngle

public void setRotationAngle(int rotation)
                      throws PdfException
Specifies angle of tilt that need to be applied to pages when they are displayed.

Parameters:
rotation - angle of the tilt
Throws:
PdfException - if an illegal argument is supplied.
See Also:
ANGLE_0, ANGLE_90, ANGLE_180, ANGLE_270, getRotationAngle()

getRotationAngle

public int getRotationAngle()
Returns angle of tilt applied to pages when they are displayed.

Returns:
angle of the tilt
See Also:
setRotationAngle(int)

setCurrentPage

public void setCurrentPage(int pageNum)
                    throws IOException,
                           PdfException
Changes currently displayed page to the specified page.

Parameters:
pageNum - number of the page that needs to be currently displayed
Throws:
IOException - if an I/O error occurs.
PdfException - if an illegal argument is supplied.
See Also:
getCurrentPage()

getCurrentPage

public int getCurrentPage()
Returns number of the currently displayed page.

Returns:
number of the currently displayed page
See Also:
setCurrentPage(int)

getPageCount

public int getPageCount()
Returns total number of pages in the displayed document.

Returns:
total number of pages in the displayed document

setViewerInsets

public void setViewerInsets(Insets insets)
Specfies how the edges of the viewer are padded.

Parameters:
insets - how the edges of the viewer are padded
See Also:
getViewerInsets(), Insets

getViewerInsets

public Insets getViewerInsets()
Returns how the edges of the viewer are padded.

Returns:
how the edges of the viewer are padded
See Also:
setViewerInsets(Insets), Insets

loadDocument

public void loadDocument(PdfDocument d)
                  throws IOException,
                         PdfException
Displays a specified PDF document.

Parameters:
d - PDF document that needs to be displayed
Throws:
IOException - if an I/O error occurs.
PdfException - if an illegal argument is supplied.
See Also:
setCurrentPage(int)

closeDocument

public void closeDocument()
Removes the display of the document on the viewer.

See Also:
loadDocument(PdfDocument)

Gnostice PDFOne Java
Std. Ed. v2.10

To contact our support team, send an e-mail to support@gnostice.com.
 
© 2008 Gnostice Information Technologies Private Limited. All rights reserved.
www.gnostice.com