net.grelf.grip
Class ImPane

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by net.grelf.grip.ImPane
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.swing.Scrollable
Direct Known Subclasses:
Hist3D_Pane, Prof3D_Pane

public class ImPane
extends javax.swing.JComponent
implements javax.swing.Scrollable, java.awt.event.MouseListener, java.awt.event.MouseMotionListener

This class is the component placed on an ImFrame's content pane to display an image. It has an object of class Im which has the image itself. ImPane also has a scaled-down version of the image for displaying at the user's required scale. Code for managing the scaling is held here. This class also looks after user interaction with the image via a mouse, mainly for drawing and measuring.

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.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected static java.lang.String[] zoomPercents
          Strings for use in ImFrame caption bars to show the current zoom percentage.
 
Fields inherited from class javax.swing.JComponent
accessibleContext, 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
ImPane(ImFrame parent, int width, int height, GlassPane gp)
           
ImPane(ImFrame parent, java.lang.String imFilename, GlassPane gp)
           
ImPane(ImFrame parent, java.lang.String imFilename, int width, int height, GlassPane gp)
           
 
Method Summary
 void clearAssociatedPane()
          Set associated pane to null.
 void dispose()
          Tidy up, for when the parent ImFrame is closed.
 GlassPane getGlassPane()
          Get a reference to the GlassPane object which overlays this ImPane in the parent ImFrame.
 Im getIm()
          Get a reference to the Im object for this ImPane, from which we can get to the image itself.
 ImFrame getImFrame()
          Get a reference to the parent ImFrame in which this ImPane is displayed.
 int getIpHeight()
          Get the height of this ImPane, in pixels.
 int getIpWidth()
          Get the width of this ImPane, in pixels.
 java.awt.Point getOrigin()
          Get the origin of the viewport of the scroll pane of the parent ImFrame.
 java.awt.Dimension getPreferredScrollableViewportSize()
          Implementing javax.swing.Scrollable.
 int getScale()
          Get the current scale factor for display.
 Im getScaledIm()
          Get reference to the scaled version of the Im, which is currently displayed in the parent ImFrame.
 int getScrollableBlockIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)
          Implementing javax.swing.Scrollable.
 boolean getScrollableTracksViewportHeight()
          Implementing javax.swing.Scrollable.
 boolean getScrollableTracksViewportWidth()
          Implementing javax.swing.Scrollable.
 int getScrollableUnitIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)
          Implementing javax.swing.Scrollable.
 boolean isPseudocolour()
          Whether the image is currently displayed in pseudocolour.
 void mouseClicked(java.awt.event.MouseEvent e)
          Implementing java.awt.event.MouseListener.
 void mouseDragged(java.awt.event.MouseEvent e)
          Implementing java.awt.event.MouseMotionListener.
 void mouseEntered(java.awt.event.MouseEvent e)
          Implementing java.awt.event.MouseListener.
 void mouseExited(java.awt.event.MouseEvent e)
          Implementing java.awt.event.MouseListener.
 void mouseMoved(java.awt.event.MouseEvent e)
          Implementing java.awt.event.MouseMotionListener.
 void mousePressed(java.awt.event.MouseEvent e)
          Implementing java.awt.event.MouseListener.
 void mouseReleased(java.awt.event.MouseEvent e)
          Implementing java.awt.event.MouseListener.
 void paintComponent(java.awt.Graphics g)
          Draw the image in this ImPane.
 void reScale()
          Recreate the scaled down version of the Im and reset the caption for the parent ImFrame.
 void setAssociatedPane(AssociatedPane ap)
          Set an associated pane which will be affected and given data when mouse actions occur in the current pane.
protected  void setIm(Im anIm)
          Set the Im object for this ImPane.
 void setInitialScale()
          Sets the scale so that the image would fit into the screen.
 void setIpHeight(int ht)
          Sets the height in pixels and then sets preferred size and revalidates, which may involve repainting.
 void setIpSize(int wd, int ht)
          Single operation combining setIpWidth and setIpHeight avoids repainting twice.
 void setIpWidth(int wd)
          Sets the width in pixels and then sets preferred size and revalidates, which may involve repainting.
protected  void setPseudocolour(Pseudocolour ps)
           
 void zoomDown()
          Increase the scale factor by 1 (if less than maximum), rescale and redisplay the image.
 void zoomUp()
          Decrease the scale factor by 1 (if greater than minimum), rescale and redisplay the image.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, 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, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, 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, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, 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, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, 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, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

zoomPercents

protected static java.lang.String[] zoomPercents
Strings for use in ImFrame caption bars to show the current zoom percentage.

Constructor Detail

ImPane

public ImPane(ImFrame parent,
              int width,
              int height,
              GlassPane gp)

ImPane

public ImPane(ImFrame parent,
              java.lang.String imFilename,
              GlassPane gp)

ImPane

public ImPane(ImFrame parent,
              java.lang.String imFilename,
              int width,
              int height,
              GlassPane gp)
Method Detail

getScale

public int getScale()
Get the current scale factor for display. This is the amount the displayed image is scaled DOWN by, from full size. Integer value in the range 1 (100%) to 9 (6.25%).


setInitialScale

public void setInitialScale()
Sets the scale so that the image would fit into the screen. NB: Does NOT scale the image.


getIm

public Im getIm()
Get a reference to the Im object for this ImPane, from which we can get to the image itself.


setIm

protected void setIm(Im anIm)
Set the Im object for this ImPane. Use with care.


getScaledIm

public Im getScaledIm()
Get reference to the scaled version of the Im, which is currently displayed in the parent ImFrame.


getOrigin

public java.awt.Point getOrigin()
Get the origin of the viewport of the scroll pane of the parent ImFrame.


getIpWidth

public int getIpWidth()
Get the width of this ImPane, in pixels.


setIpWidth

public void setIpWidth(int wd)
Sets the width in pixels and then sets preferred size and revalidates, which may involve repainting.


getIpHeight

public int getIpHeight()
Get the height of this ImPane, in pixels.


setIpHeight

public void setIpHeight(int ht)
Sets the height in pixels and then sets preferred size and revalidates, which may involve repainting.


setIpSize

public void setIpSize(int wd,
                      int ht)
Single operation combining setIpWidth and setIpHeight avoids repainting twice.


getImFrame

public ImFrame getImFrame()
Get a reference to the parent ImFrame in which this ImPane is displayed.


getGlassPane

public GlassPane getGlassPane()
Get a reference to the GlassPane object which overlays this ImPane in the parent ImFrame.


isPseudocolour

public boolean isPseudocolour()
Whether the image is currently displayed in pseudocolour.


setPseudocolour

protected void setPseudocolour(Pseudocolour ps)

clearAssociatedPane

public void clearAssociatedPane()
Set associated pane to null.


setAssociatedPane

public void setAssociatedPane(AssociatedPane ap)
Set an associated pane which will be affected and given data when mouse actions occur in the current pane.


dispose

public void dispose()
Tidy up, for when the parent ImFrame is closed.


reScale

public void reScale()
Recreate the scaled down version of the Im and reset the caption for the parent ImFrame.


paintComponent

public void paintComponent(java.awt.Graphics g)
Draw the image in this ImPane.

Overrides:
paintComponent in class javax.swing.JComponent

zoomUp

public void zoomUp()
Decrease the scale factor by 1 (if greater than minimum), rescale and redisplay the image.


zoomDown

public void zoomDown()
Increase the scale factor by 1 (if less than maximum), rescale and redisplay the image.


getPreferredScrollableViewportSize

public java.awt.Dimension getPreferredScrollableViewportSize()
Implementing javax.swing.Scrollable. Returns the preferred size of this component.

Specified by:
getPreferredScrollableViewportSize in interface javax.swing.Scrollable

getScrollableUnitIncrement

public int getScrollableUnitIncrement(java.awt.Rectangle visibleRect,
                                      int orientation,
                                      int direction)
Implementing javax.swing.Scrollable. Returns 16.

Specified by:
getScrollableUnitIncrement in interface javax.swing.Scrollable

getScrollableBlockIncrement

public int getScrollableBlockIncrement(java.awt.Rectangle visibleRect,
                                       int orientation,
                                       int direction)
Implementing javax.swing.Scrollable. Returns 512.

Specified by:
getScrollableBlockIncrement in interface javax.swing.Scrollable

getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth()
Implementing javax.swing.Scrollable. Returns false.

Specified by:
getScrollableTracksViewportWidth in interface javax.swing.Scrollable

getScrollableTracksViewportHeight

public boolean getScrollableTracksViewportHeight()
Implementing javax.swing.Scrollable. Returns false.

Specified by:
getScrollableTracksViewportHeight in interface javax.swing.Scrollable

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Implementing java.awt.event.MouseListener. Does nothing.

Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Implementing java.awt.event.MouseListener. Does nothing.

Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Implementing java.awt.event.MouseListener. Does nothing.

Specified by:
mouseExited in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Implementing java.awt.event.MouseListener. Sets the initial position of a point in the GlassPane object's PointList, so a red cross can be displayed or the latest segment of a curve can be shown.

Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Implementing java.awt.event.MouseListener. Sets the final position of a point in the GlassPane object's PointList, after possible dragging.

Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Implementing java.awt.event.MouseMotionListener. Updates the last point in GlassPane object's PointList.

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Implementing java.awt.event.MouseMotionListener. Needed for the hovering DrawingModes, HOVER, BLOB_HOVER and STAR_CHART.

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener