|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Component | +--java.awt.Container | +--jj2000.disp.ImgScrollPane
This class implements an image viewer that can display an image larger than the actual display area, and presents scrollbars to scroll the viewable area. This class also supports zooming in and out the image, with no extra memory requirements.
The zoom factor by default is 1. It can be changed with the 'zoom()' and 'setZoom()' methods. The maximum zoom factor is defined by MAX_ZOOM.
The zoom scaling is done directly by the AWT display system. In general it is performed by dropping or repeating lines. It is just intended to provide a display zoom and not for proper scaling of an image.
The scrolling can be performed by copying the actual displayed data to the new scrolled position and redrawing the damaged parts, or by redrawing the entire displayed image portion at the new scrolled position. Which is more efficient depends on the JVM and working environment. By default it is done by copying since it tends to provide less annoying visual artifacts while scrolling, but that can be changed with 'setCopyScroll()'.
This class is very similar to the AWT ScrollPane one, but it is optimized for display of large images and does not suffer from the problems of ScrollPane when changing zoom. The Adjustable elements that represent the scrollbars are made available as in ScrollPane, but the minimum, maximum, visible amount and block increment should not be set (IllegalArgumentException is thrown if attempted), since they are set internally by this class.
Focus and key event listeners that are registered are in fact registered with the components that implement the three areas (the image display and the two scrollbars) so that if any such event is fired in any of these areas it is handled by the registered listener.
Mouse and mouse movement event listeners that are registered are in fact registered with the image display component only. The mouse and mouse movement events on the scrollbars are handled by the Scrollbar default listeners only.
Although it is implemented as a container, it behaves like a component. Specifically no components can be added or removed from objects of this class. Furthermore, no layout manager can be set. It is internally set and it can not be changed.
The implementation uses a lightweight container with an inner class to display the image itself, and two scrollbars. The layout manager is a BorderLayout.
This class should be really implemented as a Component, but it is implemented as a Container for easyness. It should not be assumed it is a subclass of Container since in the future it might be rewritten as a subclass of Component only.
ScrollPane
,
Adjustable
,
Serialized FormNested Class Summary | |
private class |
ImgScrollPane.ImageScrollDisplay
This class implements the component that displays the currently viewable image portion inside the ImgScrollPane. |
(package private) class |
ImgScrollPane.ISPScrollbar
Scrollbars for the ImgScrollPane container. |
Nested classes inherited from class java.awt.Container |
java.awt.Container.AccessibleAWTContainer |
Nested classes inherited from class java.awt.Component |
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
Field Summary | |
(package private) static float |
BLOCK_INCREMENT_PROPORTION
The propertion between the visible scrollbar length and the block increment amount: 0.8 |
private boolean |
copyScroll
If scrolling is to be done by copying ot not. |
(package private) ImgScrollPane.ISPScrollbar |
hsbar
The horizontal scrollbar. |
private ImgScrollPane.ImageScrollDisplay |
imgDisplay
The image display |
(package private) static int |
INTERNAL_GAP
The inetrnal gap between the elements, in pixels: 0 |
private java.awt.Dimension |
lastSize
The viewable size used in the last scrollbar calculation. |
private float |
lastZoom
The zoom used in the last scrollbar calculation. |
static float |
MAX_ZOOM
The maximum possible zoom factor: 32. |
private int |
sbType
The scrollbar type (always, as needed, etc.) |
(package private) static int |
SCROLLBAR_THICKNESS
The thickness of the scrollbars: 16 pixels |
static int |
SCROLLBARS_ALWAYS
The ID for always visible scrollbars |
static int |
SCROLLBARS_AS_NEEDED
The ID for as needed visible scrollbars |
static int |
SCROLLBARS_NEVER
The ID for never visible scrollbars |
(package private) ImgScrollPane.ISPScrollbar |
vsbar
The vertical scrollabr. |
private float |
zoom
The zoom to use in displaying the image. |
Fields inherited from class java.awt.Container |
|
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 | |
ImgScrollPane()
Creates a new ImgScrollPane with SCROLLBARS_AS_NEEDED scrollbars. |
|
ImgScrollPane(int svt)
Creates a new ImgScrollPane with the specified type of scrollbar visibility. |
Method Summary | |
java.awt.Component |
add(java.awt.Component comp)
Throws an IllegalArgumentException since no components can be added to this container. |
java.awt.Component |
add(java.awt.Component comp,
int index)
Throws an IllegalArgumentException since no components can be added to this container. |
void |
add(java.awt.Component comp,
java.lang.Object constraints)
Throws an IllegalArgumentException since no components can be added to this container. |
void |
add(java.awt.Component comp,
java.lang.Object constraints,
int index)
Throws an IllegalArgumentException since no components can be added to this container. |
java.awt.Component |
add(java.lang.String name,
java.awt.Component comp)
Throws an IllegalArgumentException since no components can be added to this container. |
void |
addFocusListener(java.awt.event.FocusListener l)
Adds the specified focus listener to receive focus events from this component. |
void |
addKeyListener(java.awt.event.KeyListener l)
Adds the specified key listener to receive key events from this component. |
void |
addMouseListener(java.awt.event.MouseListener l)
Adds the specified mouse listener to receive mouse events from this component. |
void |
addMouseMotionListener(java.awt.event.MouseMotionListener l)
Adds the specified mouse motion listener to receive mouse motion events from this component. |
void |
doLayout()
Causes this container to lay out its components. |
boolean |
getCopyScroll()
Returns true if the scrolling is done by copying. |
java.awt.Adjustable |
getHAdjustable()
Returns the Adjustable object which represents the state of the horizontal scrollbar. |
java.awt.Image |
getImage()
Returns the image that is displayed in this component. |
int |
getScrollbarDisplayPolicy()
Returns the display policy for the scrollbars. |
java.awt.Point |
getScrollPosition()
Returns the current x,y position within the child which is displayed at the 0,0 location of the scrolled panel's view port. |
java.awt.Adjustable |
getVAdjustable()
Returns the Adjustable object which represents the state of the vertical scrollbar. |
java.awt.Dimension |
getViewportSize()
Returns the current size of the image scroll pane's view port. |
float |
getZoom()
Returns the current zoom factor. |
void |
remove(java.awt.Component comp)
Throws an IllegalArgumentException since the components should never be removed from this container. |
void |
remove(int index)
Throws an IllegalArgumentException since the components should never be removed from this container. |
void |
removeAll()
Throws an IllegalArgumentException since the components should never be removed from this container. |
void |
removeFocusListener(java.awt.event.FocusListener l)
Removes the specified focus listener so that it no longer receives focus events from this component. |
void |
removeKeyListener(java.awt.event.KeyListener l)
Removes the specified key listener so that it no longer receives key events from this component. |
void |
removeMouseListener(java.awt.event.MouseListener l)
Removes the specified mouse listener so that it no longer receives mouse events from this component. |
void |
removeMouseMotionListener(java.awt.event.MouseMotionListener l)
Removes the specified mouse motion listener so that it no longer receives mouse motion events from this component. |
void |
setBackground(java.awt.Color c)
Sets the background color of this component. |
void |
setCopyScroll(boolean v)
Sets if the scrolling is to be done by copying and redrawing of damaged parts of the displayed image. |
void |
setCursor(java.awt.Cursor cursor)
Set the cursor image to a predefined cursor. |
void |
setEnabled(boolean b)
Enables or disables this component, depending on the value of the parameter b. |
void |
setForeground(java.awt.Color c)
Sets the foreground color of this component. |
void |
setImage(java.awt.Image img)
Sets the image to display in this component. |
void |
setLayout(java.awt.LayoutManager mgr)
Throws an IllegalArgumentException since the layout manager is internally set and can not be changed. |
void |
setScrollbarDisplayPolicy(int v)
Sets the display policy for the scrollbars. |
private void |
setScrollbars()
Sets the scrollbars values, according to the image display area and image size. |
void |
setScrollPosition(int x,
int y)
Scrolls to the specified position within the image. |
void |
setScrollPosition(java.awt.Point p)
Scrolls to the specified position within the image. |
void |
setZoom(float zf)
Sets the zoom factor to display the image. |
void |
zoom(float zm)
Modifies the current zoom factor by the given multiplier. |
Methods inherited from class java.awt.Container |
addContainerListener, addImpl, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, removeContainerListener, removeNotify, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, transferFocusBackward, transferFocusDownCycle, update, validate, validateTree |
Methods inherited from class java.awt.Component |
action, add, addComponentListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBounds, setBounds, setComponentOrientation, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int SCROLLBARS_ALWAYS
public static final int SCROLLBARS_AS_NEEDED
public static final int SCROLLBARS_NEVER
public static final float MAX_ZOOM
static final int SCROLLBAR_THICKNESS
static final int INTERNAL_GAP
static final float BLOCK_INCREMENT_PROPORTION
ImgScrollPane.ISPScrollbar hsbar
ImgScrollPane.ISPScrollbar vsbar
private ImgScrollPane.ImageScrollDisplay imgDisplay
private int sbType
private float zoom
private float lastZoom
private java.awt.Dimension lastSize
private boolean copyScroll
Constructor Detail |
public ImgScrollPane()
public ImgScrollPane(int svt)
svt
- The scrollbar visibility typeMethod Detail |
public void setImage(java.awt.Image img)
If the image is not ready for display (i.e. it has not been rendered at its natural size) it will be rendered in the current thread, if not being already rendered in another one. This means that the current thread can block until the image is ready.
If the image is rendered incrementally (it depends on the underlying 'ImageProducer') it will be displayed in that way if the incremental display is set for the Component class. See the 'imageUpdate()' method of the 'Component' class.
If the image is the same as the current one nothing is done.
img
- The image to display.Component.imageUpdate(java.awt.Image, int, int, int, int, int)
public java.awt.Image getImage()
public void setZoom(float zf)
zf
- The zoom factorpublic void zoom(float zm)
zm
- The zoom multiplier to apply.public float getZoom()
public java.awt.Adjustable getHAdjustable()
public java.awt.Adjustable getVAdjustable()
public int getScrollbarDisplayPolicy()
public void setScrollbarDisplayPolicy(int v)
v
- the display policy for the scrollbarspublic void setScrollPosition(int x, int y)
x
- the x position to scroll toy
- the y position to scroll topublic void setScrollPosition(java.awt.Point p)
p
- the position to scroll topublic java.awt.Point getScrollPosition()
public java.awt.Dimension getViewportSize()
public void setCopyScroll(boolean v)
v
- If true scrolling will be done by copying.public boolean getCopyScroll()
public void doLayout()
doLayout
in class java.awt.Container
public void addFocusListener(java.awt.event.FocusListener l)
addFocusListener
in class java.awt.Component
l
- the focus listenerpublic void removeFocusListener(java.awt.event.FocusListener l)
removeFocusListener
in class java.awt.Component
l
- the focus listenerpublic void addKeyListener(java.awt.event.KeyListener l)
addKeyListener
in class java.awt.Component
l
- the key listenerpublic void removeKeyListener(java.awt.event.KeyListener l)
removeKeyListener
in class java.awt.Component
l
- the key listenerpublic void addMouseListener(java.awt.event.MouseListener l)
addMouseListener
in class java.awt.Component
l
- the mouse listenerpublic void removeMouseListener(java.awt.event.MouseListener l)
removeMouseListener
in class java.awt.Component
l
- the mouse listenerpublic void addMouseMotionListener(java.awt.event.MouseMotionListener l)
addMouseMotionListener
in class java.awt.Component
l
- the mouse motion listenerpublic void removeMouseMotionListener(java.awt.event.MouseMotionListener l)
removeMouseMotionListener
in class java.awt.Component
l
- the mouse motion listenerpublic void setBackground(java.awt.Color c)
setBackground
in class java.awt.Component
c
- The color to become background color for this componentpublic void setCursor(java.awt.Cursor cursor)
setCursor
in class java.awt.Component
cursor
- One of the constants defined by the Cursor class.public void setEnabled(boolean b)
setEnabled
in class java.awt.Component
b
- If true, this component is enabled; otherwise this component
is disabled.public void setForeground(java.awt.Color c)
setForeground
in class java.awt.Component
c
- The color to become this component's foreground color.public java.awt.Component add(java.awt.Component comp)
add
in class java.awt.Container
public java.awt.Component add(java.lang.String name, java.awt.Component comp)
add
in class java.awt.Container
public java.awt.Component add(java.awt.Component comp, int index)
add
in class java.awt.Container
public void add(java.awt.Component comp, java.lang.Object constraints)
add
in class java.awt.Container
public void add(java.awt.Component comp, java.lang.Object constraints, int index)
add
in class java.awt.Container
public void remove(int index)
remove
in class java.awt.Container
public void remove(java.awt.Component comp)
remove
in class java.awt.Container
public void removeAll()
removeAll
in class java.awt.Container
public void setLayout(java.awt.LayoutManager mgr)
setLayout
in class java.awt.Container
private void setScrollbars()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |