com.zfqjava.swing
Class JImageViewer

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--com.zfqjava.swing.JImageViewer
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, javax.swing.Scrollable, java.io.Serializable

public class JImageViewer
extends javax.swing.JComponent
implements javax.accessibility.Accessible, javax.swing.Scrollable

JImageViewer provides a panel to display images, adding support to zoom and rotate the image.

See Also:
Serialized Form

Inner Class Summary
protected  class JImageViewer.AccessibleJImageViewer
          This class implements accessibility support for the JImageViewer class.
 
Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
Field Summary
protected  javax.accessibility.AccessibleContext accessibleContext
           
static int AUTO_SIZE_MODE
          The JImageViewer is sized equal to the size of the image that it contains.
static int CENTER_IMAGE_SIZE_MODE
          The image is displayed in the center if the JImageViewer is larger than the image.
static int HORIZONTAL
          Indicates the horizontal filp orientation.
static int NORMAL_SIZE_MODE
          The image is placed in the upper-left corner of the JImageViewer.
static int ROTATE_180
          Identifies the rotate mode is rotate 180 degree in clockwise.
static int ROTATE_270
          Identifies the rotate mode is rotate 270 degree in clockwise.
static int ROTATE_90
          Identifies the rotate mode is rotate 90 degree in clockwise.
static int ROTATE_NONE
          Identifies the rotate mode is none.
static int STRETCH_IMAGE_SIZE_MODE
          The image within the JImageViewer is stretched or shrunk to fit the size of the JImageViewer.
static int VERTICAL
          Indicates the vertical filp orientation.
 
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, 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
JImageViewer()
          Constructs a JImageViewer.
JImageViewer(java.awt.Image image)
          Constructs a JImageViewer.
 
Method Summary
 javax.accessibility.AccessibleContext getAccessibleContext()
          Gets the AccessibleContext associated with this JImageViewer.
 java.awt.Image getImage()
          Returns the display image.
 javax.swing.ImageIcon getImageIcon()
          Returns the display image icon.
 java.awt.Dimension getPreferredScrollableViewportSize()
          Returns the preferred size of the viewport for a view component.
 java.awt.Dimension getPreferredSize()
           
 int getRotateMode()
          Returns the rotate mode.
 int getScrollableBlockIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)
          Components that display logical rows or columns should compute the scroll increment that will completely expose one block of rows or columns, depending on the value of orientation.
 boolean getScrollableTracksViewportHeight()
          Return true if a viewport should always force the height of this Scrollable to match the height of the viewport.
 boolean getScrollableTracksViewportWidth()
          Return true if a viewport should always force the width of this Scrollable to match the width of the viewport.
 int getScrollableUnitIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)
          Components that display logical rows or columns should compute the scroll increment that will completely expose one new row or column, depending on the value of orientation.
 int getSizeMode()
          Returns the JImageViewer size mode in use.
 double getZoomFactor()
          Returns the current zoom factor.
 boolean isHorizontalFlipEnabled()
          Determines the horizontal flip property.
 boolean isVerticalFlipEnabled()
          Determines the vertical flip property.
protected  void paintComponent(java.awt.Graphics g)
           
protected  java.lang.String paramString()
          Returns a string representation of this JImageViewer.
 void reset()
          Resets the image to the original state, no zooming and no rotate and no filp.
 void rotate(boolean clockwise)
          Rotates the image use the specify clockwise flag.
 void setHorizontalFlipEnabled(boolean enabled)
          Sets the horizontal flip property.
 void setImage(java.awt.Image image)
          Sets the image to display.
 void setImageIcon(javax.swing.ImageIcon imageIcon)
          Sets the image icon to display.
 void setRotateMode(int rotateMode)
          Sets the rotate mode.
 void setSizeMode(int sizeMode)
          Sets the JImageViewer size mode.
 void setVerticalFlipEnabled(boolean enabled)
          Sets the vertical flip property.
 void setZoomFactor(double factor)
          Sets the current zoom factor.
 void zoom(double factor)
          Zooms the image use the specify zoom factor based the current zoom factor.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getUIClassID, getVerifyInputWhenFocusTarget, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

AUTO_SIZE_MODE

public static final int AUTO_SIZE_MODE
The JImageViewer is sized equal to the size of the image that it contains.

CENTER_IMAGE_SIZE_MODE

public static final int CENTER_IMAGE_SIZE_MODE
The image is displayed in the center if the JImageViewer is larger than the image. If the image is larger than the JImageViewer, the picture is placed in the center of the JImageViewer and the outside edges are clipped.

NORMAL_SIZE_MODE

public static final int NORMAL_SIZE_MODE
The image is placed in the upper-left corner of the JImageViewer. The image is clipped if it is larger than the JImageViewer it is contained in.

STRETCH_IMAGE_SIZE_MODE

public static final int STRETCH_IMAGE_SIZE_MODE
The image within the JImageViewer is stretched or shrunk to fit the size of the JImageViewer.

HORIZONTAL

public static final int HORIZONTAL
Indicates the horizontal filp orientation.

VERTICAL

public static final int VERTICAL
Indicates the vertical filp orientation.

ROTATE_NONE

public static final int ROTATE_NONE
Identifies the rotate mode is none.

ROTATE_90

public static final int ROTATE_90
Identifies the rotate mode is rotate 90 degree in clockwise.

ROTATE_180

public static final int ROTATE_180
Identifies the rotate mode is rotate 180 degree in clockwise.

ROTATE_270

public static final int ROTATE_270
Identifies the rotate mode is rotate 270 degree in clockwise.

accessibleContext

protected javax.accessibility.AccessibleContext accessibleContext
Constructor Detail

JImageViewer

public JImageViewer()
Constructs a JImageViewer.
See Also:
JImageViewer()

JImageViewer

public JImageViewer(java.awt.Image image)
Constructs a JImageViewer.
Parameters:
image - the image to display
See Also:
JImageViewer()
Method Detail

setSizeMode

public void setSizeMode(int sizeMode)
Sets the JImageViewer size mode. The size mode of the JImageViewer:
Parameters:
sizeMode - the size mode of the JImageViewer
Throws:
java.lang.IllegalArgumentException - if the size mode is illegal
See Also:
getSizeMode()

getSizeMode

public int getSizeMode()
Returns the JImageViewer size mode in use. The size mode of the JImageViewer:
Returns:
the size mode of the JImageViewer
See Also:
setSizeMode(int)

setImage

public void setImage(java.awt.Image image)
Sets the image to display.
Parameters:
image - the image to display
See Also:
#setImage(File)

getImage

public java.awt.Image getImage()
Returns the display image.
Returns:
the display image

setImageIcon

public void setImageIcon(javax.swing.ImageIcon imageIcon)
Sets the image icon to display.
Parameters:
image - the image icon to display
See Also:
#setImageIcon(File)

getImageIcon

public javax.swing.ImageIcon getImageIcon()
Returns the display image icon.
Returns:
the display image icon
See Also:
setImageIcon(javax.swing.ImageIcon)

setZoomFactor

public void setZoomFactor(double factor)
Sets the current zoom factor.
Parameters:
factor - the current zoom factor
See Also:
getZoomFactor()

getZoomFactor

public double getZoomFactor()
Returns the current zoom factor.
Returns:
the current zoom factor
See Also:
setZoomFactor(double)

setRotateMode

public void setRotateMode(int rotateMode)
Sets the rotate mode.

One of 4 legal values:

Parameters:
int - the rotate mode
See Also:
getRotateMode()

getRotateMode

public int getRotateMode()
Returns the rotate mode.

One of 4 legal values:

Returns:
the rotate mode
See Also:
setRotateMode

setHorizontalFlipEnabled

public void setHorizontalFlipEnabled(boolean enabled)
Sets the horizontal flip property.
Parameters:
enabled - the horizontal flip property
See Also:
isHorizontalFlipEnabled()

isHorizontalFlipEnabled

public boolean isHorizontalFlipEnabled()
Determines the horizontal flip property.
Returns:
true if the horizontal flip is enabled, otherwise return false
See Also:
setHorizontalFlipEnabled(boolean)

setVerticalFlipEnabled

public void setVerticalFlipEnabled(boolean enabled)
Sets the vertical flip property.
Parameters:
enabled - the vertical flip property
See Also:
isVerticalFlipEnabled()

isVerticalFlipEnabled

public boolean isVerticalFlipEnabled()
Determines the vertical flip property.
Returns:
true if the vertical flip is enabled, otherwise return false
See Also:
setVerticalFlipEnabled(boolean)

zoom

public void zoom(double factor)
Zooms the image use the specify zoom factor based the current zoom factor. This is equals to setZoomFactor(getZoomFactor()*factor).
Parameters:
factor - the zoom factor
See Also:
setZoomFactor(double)

rotate

public void rotate(boolean clockwise)
Rotates the image use the specify clockwise flag.
Parameters:
clockwise - the rotate direction
See Also:
setRotateMode(int), getRotateMode()

reset

public void reset()
Resets the image to the original state, no zooming and no rotate and no filp.

getPreferredSize

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

paintComponent

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

getPreferredScrollableViewportSize

public java.awt.Dimension getPreferredScrollableViewportSize()
Returns the preferred size of the viewport for a view component. For example the preferredSize of a JList component is the size required to accommodate all of the cells in its list however the value of preferredScrollableViewportSize is the size required for JList.getVisibleRowCount() rows. A component without any properties that would effect the viewport size should just return getPreferredSize() here.
Specified by:
getPreferredScrollableViewportSize in interface javax.swing.Scrollable
Returns:
The preferredSize of a JViewport whose view is this Scrollable.
See Also:
JComponent.getPreferredSize()

getScrollableUnitIncrement

public int getScrollableUnitIncrement(java.awt.Rectangle visibleRect,
                                      int orientation,
                                      int direction)
Components that display logical rows or columns should compute the scroll increment that will completely expose one new row or column, depending on the value of orientation. Ideally, components should handle a partially exposed row or column by returning the distance required to completely expose the item.

Scrolling containers, like JScrollPane, will use this method each time the user requests a unit scroll.

Specified by:
getScrollableUnitIncrement in interface javax.swing.Scrollable
Parameters:
visibleRect - The view area visible within the viewport
orientation - Either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL.
direction - Less than zero to scroll up/left, greater than zero for down/right.
Returns:
The "unit" increment for scrolling in the specified direction. This value should always be positive.
See Also:
JScrollBar.setUnitIncrement(int)

getScrollableBlockIncrement

public int getScrollableBlockIncrement(java.awt.Rectangle visibleRect,
                                       int orientation,
                                       int direction)
Components that display logical rows or columns should compute the scroll increment that will completely expose one block of rows or columns, depending on the value of orientation.

Scrolling containers, like JScrollPane, will use this method each time the user requests a block scroll.

Specified by:
getScrollableBlockIncrement in interface javax.swing.Scrollable
Parameters:
visibleRect - The view area visible within the viewport
orientation - Either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL.
direction - Less than zero to scroll up/left, greater than zero for down/right.
Returns:
The "block" increment for scrolling in the specified direction. This value should always be positive.
See Also:
JScrollBar.setBlockIncrement(int)

getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth()
Return true if a viewport should always force the width of this Scrollable to match the width of the viewport. For example a normal text view that supported line wrapping would return true here, since it would be undesirable for wrapped lines to disappear beyond the right edge of the viewport. Note that returning true for a Scrollable whose ancestor is a JScrollPane effectively disables horizontal scrolling.

Scrolling containers, like JViewport, will use this method each time they are validated.

Specified by:
getScrollableTracksViewportWidth in interface javax.swing.Scrollable
Returns:
True if a viewport should force the Scrollables width to match its own.

getScrollableTracksViewportHeight

public boolean getScrollableTracksViewportHeight()
Return true if a viewport should always force the height of this Scrollable to match the height of the viewport. For example a columnar text view that flowed text in left to right columns could effectively disable vertical scrolling by returning true here.

Scrolling containers, like JViewport, will use this method each time they are validated.

Specified by:
getScrollableTracksViewportHeight in interface javax.swing.Scrollable
Returns:
True if a viewport should force the Scrollables height to match its own.

paramString

protected java.lang.String paramString()
Returns a string representation of this JImageViewer. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.
Overrides:
paramString in class javax.swing.JComponent
Returns:
a string representation of this JImageViewer

getAccessibleContext

public javax.accessibility.AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this JImageViewer. For color choosers, the AccessibleContext takes the form of an AccessibleJImageViewer. A new AccessibleJImageViewer instance is created if necessary.
Specified by:
getAccessibleContext in interface javax.accessibility.Accessible
Overrides:
getAccessibleContext in class javax.swing.JComponent
Returns:
an AccessibleJImageViewer that serves as the AccessibleContext of this JImageViewer


Copyright © 2001-2003 Extreme Component, Inc. All rights reserved.