com.elixirtech.glint.viewer
Class ViewerCanvas

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by com.elixirtech.glint.viewer.ViewerCanvas
All Implemented Interfaces:
IViewerCanvas, Zoomable, com.elixirtech.ui.INavigation, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable
Direct Known Subclasses:
GlintCanvas

public abstract class ViewerCanvas
extends javax.swing.JComponent
implements IViewerCanvas, Zoomable, java.io.Serializable

The abstract implementation of IViewerCanvas that provides a common infrastructure independent of the model being viewed.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.BaselineResizeBehavior
 
Field Summary
 
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
ViewerCanvas()
           
 
Method Summary
 void addChangeListener(javax.swing.event.ChangeListener cl)
          Register interest in changes to the viewer.
 void first()
          Go to the first page
 java.awt.Paint getBackgroundColor()
          Get the current background colour of the viewer.
 javax.swing.JComponent getCanvasComponent()
          Get the component that shows the view.
 java.awt.Dimension getMaximumSize()
           
 java.awt.Dimension getMinimumSize()
           
abstract  int getPageCount()
          Get the number of pages in the model
 int getPageNo()
          Get the current page number
 java.awt.Dimension getPreferredSize()
           
 int getZoomPercent()
          Get the zoom percent
 boolean gotoPage(int index)
          Go to a specific page.
 boolean isBitmapZoom()
          Returns whether bitmap zoom is enabled
 void last()
          Go to the last page
 boolean next()
          Go to the next page
 void paintComponent(java.awt.Graphics g)
           
 boolean previous()
          Go to the previous page
 void read(java.io.File f)
          Read the model from a file
abstract  void read(java.io.InputStream is)
          Read the model from a stream
 void removeChangeListener(javax.swing.event.ChangeListener cl)
          Remove the change listener
 void setBackgroundColor(java.awt.Paint c)
          Set the background colour of the viewer - this is the area behind any pages, so it defaults to grey, so you can see the page boundaries.
 void setBitmapZoom(boolean b)
          Determine whether zoom should be bitmap scaling.
abstract  void setObject(java.lang.Object o)
          Set an object as the model for the viewer.
 void setPageNo(int no)
          Show a specific page (in the range 1<=no<=getPageCount())
 void setZoomPercent(int zoom)
          Set the zoom percent
abstract  void update()
          Recalculates the dimensions of the view and repaints.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, 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, updateUI
 
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, preferredSize, 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
 

Constructor Detail

ViewerCanvas

public ViewerCanvas()
Method Detail

addChangeListener

public void addChangeListener(javax.swing.event.ChangeListener cl)
Description copied from interface: IViewerCanvas
Register interest in changes to the viewer. This includes changes to the current page

Specified by:
addChangeListener in interface IViewerCanvas
Parameters:
cl - The change listener

removeChangeListener

public void removeChangeListener(javax.swing.event.ChangeListener cl)
Description copied from interface: IViewerCanvas
Remove the change listener

Specified by:
removeChangeListener in interface IViewerCanvas
Parameters:
cl - The change listener

setObject

public abstract void setObject(java.lang.Object o)
Description copied from interface: IViewerCanvas
Set an object as the model for the viewer. The kind of object supported varies with each implementation of the interface

Specified by:
setObject in interface IViewerCanvas
Parameters:
o - The object to view

read

public abstract void read(java.io.InputStream is)
                   throws java.io.IOException
Description copied from interface: IViewerCanvas
Read the model from a stream

Specified by:
read in interface IViewerCanvas
Parameters:
is - The input stream
Throws:
java.io.IOException - if the stream is invalid for this viewer

update

public abstract void update()
Description copied from interface: IViewerCanvas
Recalculates the dimensions of the view and repaints. This should be called after any changes to the model, eg. calls to setObject(...) or read(...) when ready to display.

Specified by:
update in interface IViewerCanvas

getPageCount

public abstract int getPageCount()
Description copied from interface: IViewerCanvas
Get the number of pages in the model

Specified by:
getPageCount in interface IViewerCanvas
Specified by:
getPageCount in interface com.elixirtech.ui.INavigation
Returns:
The number of pages in the model

read

public void read(java.io.File f)
          throws java.io.IOException
Description copied from interface: IViewerCanvas
Read the model from a file

Specified by:
read in interface IViewerCanvas
Parameters:
f - The file to read
Throws:
java.io.IOException - if the file is invalid for this viewer, or doesn't exist

setZoomPercent

public void setZoomPercent(int zoom)
Description copied from interface: Zoomable
Set the zoom percent

Specified by:
setZoomPercent in interface Zoomable
Parameters:
zoom - A value 1 to 100 will zoom out, >100 will zoom in.

getZoomPercent

public int getZoomPercent()
Description copied from interface: Zoomable
Get the zoom percent

Specified by:
getZoomPercent in interface Zoomable
Returns:
The current zoom percent (100 is normal size)

setBitmapZoom

public void setBitmapZoom(boolean b)
Description copied from interface: Zoomable
Determine whether zoom should be bitmap scaling. By default zooming is done by graphics scaling. Bitmap scaling allows a closer look at the pixels of the 100% view, rather than generating a new scaled view. This is primarily for quality checking of the rendered output.

Specified by:
setBitmapZoom in interface Zoomable
Parameters:
b - True to enable bitmap zooms

isBitmapZoom

public boolean isBitmapZoom()
Description copied from interface: Zoomable
Returns whether bitmap zoom is enabled

Specified by:
isBitmapZoom in interface Zoomable
Returns:
True if bitmap zoom is enabled

setBackgroundColor

public void setBackgroundColor(java.awt.Paint c)
Set the background colour of the viewer - this is the area behind any pages, so it defaults to grey, so you can see the page boundaries.

Parameters:
c - The new background color

getBackgroundColor

public java.awt.Paint getBackgroundColor()
Get the current background colour of the viewer.

Returns:
The current background colour

setPageNo

public void setPageNo(int no)
Description copied from interface: IViewerCanvas
Show a specific page (in the range 1<=no<=getPageCount())

Specified by:
setPageNo in interface IViewerCanvas
Parameters:
no - The page to show (1-based)

getPageNo

public int getPageNo()
Description copied from interface: IViewerCanvas
Get the current page number

Specified by:
getPageNo in interface IViewerCanvas
Specified by:
getPageNo in interface com.elixirtech.ui.INavigation
Returns:
The current page (in the range 1<=no<=getPageCount())

getPreferredSize

public java.awt.Dimension getPreferredSize()
Overrides:
getPreferredSize in class javax.swing.JComponent

getMinimumSize

public java.awt.Dimension getMinimumSize()
Overrides:
getMinimumSize in class javax.swing.JComponent

getMaximumSize

public java.awt.Dimension getMaximumSize()
Overrides:
getMaximumSize in class javax.swing.JComponent

getCanvasComponent

public javax.swing.JComponent getCanvasComponent()
Description copied from interface: IViewerCanvas
Get the component that shows the view. Wrap this with a scrollpane if you want it scrollable.

Specified by:
getCanvasComponent in interface IViewerCanvas
Returns:
the component that shows the view

paintComponent

public void paintComponent(java.awt.Graphics g)
Overrides:
paintComponent in class javax.swing.JComponent

first

public void first()
Go to the first page

Specified by:
first in interface com.elixirtech.ui.INavigation

previous

public boolean previous()
Go to the previous page

Specified by:
previous in interface com.elixirtech.ui.INavigation
Returns:
False if already at the first page, else True

next

public boolean next()
Go to the next page

Specified by:
next in interface com.elixirtech.ui.INavigation
Returns:
False if already at the last page, else True

last

public void last()
Go to the last page

Specified by:
last in interface com.elixirtech.ui.INavigation

gotoPage

public boolean gotoPage(int index)
Go to a specific page.

Specified by:
gotoPage in interface com.elixirtech.ui.INavigation
Parameters:
index - The page number (1-based)
Returns:
True if the new page was shown.