public class ImgScrollPane extends Container
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 FormContainer.AccessibleAWTContainerComponent.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy| Modifier and Type | Field and Description |
|---|---|
static float |
MAX_ZOOM
The maximum possible zoom factor: 32.
|
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
|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH| Constructor and Description |
|---|
ImgScrollPane()
Creates a new ImgScrollPane with SCROLLBARS_AS_NEEDED scrollbars.
|
ImgScrollPane(int svt)
Creates a new ImgScrollPane with the specified type of scrollbar
visibility.
|
| Modifier and Type | Method and Description |
|---|---|
Component |
add(Component comp)
Throws an IllegalArgumentException since no components can be added to
this container.
|
Component |
add(Component comp,
int index)
Throws an IllegalArgumentException since no components can be added to
this container.
|
void |
add(Component comp,
Object constraints)
Throws an IllegalArgumentException since no components can be added to
this container.
|
void |
add(Component comp,
Object constraints,
int index)
Throws an IllegalArgumentException since no components can be added to
this container.
|
Component |
add(String name,
Component comp)
Throws an IllegalArgumentException since no components can be added to
this container.
|
void |
addFocusListener(FocusListener l)
Adds the specified focus listener to receive focus events from this
component.
|
void |
addKeyListener(KeyListener l)
Adds the specified key listener to receive key events from this
component.
|
void |
addMouseListener(MouseListener l)
Adds the specified mouse listener to receive mouse events from this
component.
|
void |
addMouseMotionListener(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.
|
Adjustable |
getHAdjustable()
Returns the Adjustable object which represents the state of the
horizontal scrollbar.
|
Image |
getImage()
Returns the image that is displayed in this component.
|
int |
getScrollbarDisplayPolicy()
Returns the display policy for the scrollbars.
|
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.
|
Adjustable |
getVAdjustable()
Returns the Adjustable object which represents the state of the
vertical scrollbar.
|
Dimension |
getViewportSize()
Returns the current size of the image scroll pane's view port.
|
float |
getZoom()
Returns the current zoom factor.
|
void |
remove(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(FocusListener l)
Removes the specified focus listener so that it no longer receives
focus events from this component.
|
void |
removeKeyListener(KeyListener l)
Removes the specified key listener so that it no longer receives key
events from this component.
|
void |
removeMouseListener(MouseListener l)
Removes the specified mouse listener so that it no longer receives
mouse events from this component.
|
void |
removeMouseMotionListener(MouseMotionListener l)
Removes the specified mouse motion listener so that it no longer
receives mouse motion events from this component.
|
void |
setBackground(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(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(Color c)
Sets the foreground color of this component.
|
void |
setImage(Image img)
Sets the image to display in this component.
|
void |
setLayout(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.
|
void |
setScrollPosition(int x,
int y)
Scrolls to the specified position within the image.
|
void |
setScrollPosition(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.
|
addContainerListener, addImpl, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, isValidateRoot, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusDownCycle, update, validate, validateTreeaction, 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, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getBackground, getBaseline, getBaselineResizeBehavior, 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, getMousePosition, 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, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, 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, revalidate, setBounds, setBounds, setComponentOrientation, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCyclepublic static final int SCROLLBARS_ALWAYS
public static final int SCROLLBARS_AS_NEEDED
public static final int SCROLLBARS_NEVER
public static final float MAX_ZOOM
public ImgScrollPane()
public ImgScrollPane(int svt)
svt - The scrollbar visibility typepublic void setImage(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 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 Adjustable getHAdjustable()
public 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(Point p)
p - the position to scroll topublic Point getScrollPosition()
public Dimension getViewportSize()
public void setCopyScroll(boolean v)
v - If true scrolling will be done by copying.public boolean getCopyScroll()
public void doLayout()
public void addFocusListener(FocusListener l)
addFocusListener in class Componentl - the focus listenerpublic void removeFocusListener(FocusListener l)
removeFocusListener in class Componentl - the focus listenerpublic void addKeyListener(KeyListener l)
addKeyListener in class Componentl - the key listenerpublic void removeKeyListener(KeyListener l)
removeKeyListener in class Componentl - the key listenerpublic void addMouseListener(MouseListener l)
addMouseListener in class Componentl - the mouse listenerpublic void removeMouseListener(MouseListener l)
removeMouseListener in class Componentl - the mouse listenerpublic void addMouseMotionListener(MouseMotionListener l)
addMouseMotionListener in class Componentl - the mouse motion listenerpublic void removeMouseMotionListener(MouseMotionListener l)
removeMouseMotionListener in class Componentl - the mouse motion listenerpublic void setBackground(Color c)
setBackground in class Componentc - The color to become background color for this componentpublic void setCursor(Cursor cursor)
public void setEnabled(boolean b)
setEnabled in class Componentb - If true, this component is enabled; otherwise this component
is disabled.public void setForeground(Color c)
setForeground in class Componentc - The color to become this component's foreground color.public Component add(Component comp)
public Component add(String name, Component comp)
public Component add(Component comp, int index)
public void add(Component comp, Object constraints)
public void add(Component comp, Object constraints, int index)
public void remove(int index)
public void remove(Component comp)
public void removeAll()
public void setLayout(LayoutManager mgr)
Copyright © 2015. All rights reserved.