Package adams.gui.visualization.image
Class ImagePanel.PaintPanel
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- adams.gui.core.BasePanel
-
- adams.gui.visualization.image.ImagePanel.PaintPanel
-
- All Implemented Interfaces:
CleanUpHandler,ImageObserver,MenuContainer,Serializable,Accessible
- Enclosing class:
- ImagePanel
public static class ImagePanel.PaintPanel extends BasePanel implements CleanUpHandler
The panel used for painting.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
-
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
-
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
-
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
-
Field Summary
Fields Modifier and Type Field Description protected BufferedImagem_CurrentImagethe current image.protected CustomPopupMenuProviderm_CustomPopupMenuProviderwhether to use a custom popup menu provider.protected booleanm_Draggedwhether dragging has happened at all.protected GenericObjectEditorDialogm_GOEImageOverlaythe GOE for adding an image overlay.protected HashSet<ImageOverlay>m_ImageOverlaysthe image overlays.protected InteractionLoggingFilterm_InteractionLoggingFilterthe interaction logger in use.protected Set<ImagePanelLeftClickListener>m_LeftClickListenersthe left-click listeners.protected ImagePanelm_Ownerthe owning image panel.protected Set<Paintlet>m_Paintletsadditional paintlets to execute.protected PrintMouseListenerm_PrintMouseListenerthe mouse listener.protected DefaultReportFileChooserm_ReportFileChooserthe filechooser for reports.protected doublem_Scalethe scaling factor.protected booleanm_Selectingwhether the selection box is currently been drawn.protected booleanm_SelectionEnabledwhether selection via box is enabled.protected Pointm_SelectionFromthe starting corner of the selection box.protected Set<ImagePanelSelectionListener>m_SelectionListenersthe selection listeners.protected SelectionShapePainterm_SelectionShapePainterthe color of the selection box.protected Pointm_SelectionTothe finishing corner of the selection box.protected List<Point>m_SelectionTracethe selection trace.-
Fields inherited from class adams.gui.core.BasePanel
m_FileChooser
-
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
accessibleContext, 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
Constructors Constructor Description PaintPanel(ImagePanel owner)Initializes the panel.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddImageOverlay(ImageOverlay io)Adds the image overlay.voidaddLeftClickListener(ImagePanelLeftClickListener l)Adds the given listener to the internal list of left-click listeners.voidaddPaintlet(Paintlet p)Adds the paintlet to the internal list.voidaddSelectionListener(ImagePanelSelectionListener l)Adds the given listener to the internal list of selection listeners.voidcleanUp()Cleans up data structures, frees up memory.voidclearImageOverlays()Removes all image overlays.voidclearLeftClickListeners()Removes all left-click listeners.voidclearSelectionListeners()Removes all selection listeners.voidexport()Exports the current image.BufferedImagegetCurrentImage()Returns the current image.CustomPopupMenuProvidergetCustomPopupMenuProvider()Returns the custom popup menu provider.InteractionLoggingFiltergetInteractionLoggingFilter()Returns the interaction log filter in use.ImagePanelgetOwner()Returns the owning panel.protected DefaultReportFileChoosergetReportFileChooser()Returns the report filechooser to use.doublegetScale()Returns the scaling factor (0-16).SelectionShapePaintergetSelectionShapePainter()Returns the painter to use for the selection shape.Iterator<ImageOverlay>imageOverlays()Returns an iterator over all the image overlays.protected voidinitGUI()Initializes the widgets.protected voidinitialize()Initializes members.booleanisDragged()Whether dragging is selection is currently active.booleanisSelecting()Whether selection is currently active.booleanisSelectionEnabled()Returns whether selection is enabled.voidloadReport()Loads a report from a file.protected voidlogMouseButtonClick(MouseEvent e)Logs a mouse click.protected voidlogMouseButtonPressed(MouseEvent e)Logs a mouse button pressed.protected voidlogMouseButtonReleased(MouseEvent e)Logs a mouse button released.protected voidlogMouseWheel(MouseWheelEvent e, double oldScale, double newScale)Logs a mouse click.protected voidlogScale(double newScale)Logs a scale change from the menu.PointmouseToPixelLocation(Point mousePos)Turns the mouse position into pixel location.voidnotifyLeftClickListeners(Point position, int modifiersEx)Notifies all left-click listeners.voidnotifySelectionListeners(Point topLeft, Point bottomRight, int modifiersEx)Notifies all selection listeners.voidpaint(Graphics g)Paints the image or just a white background.Iterator<Paintlet>paintlets()Returns an iterator over all currently stored paintlets.protected voidpaintSelectionShape(Graphics g)Paints the selection box, if necessary (i.e., currently selecting/dragging).PointpixelToMouseLocation(Point pixelPos)Converts the pixel position (at 100% scale) to a mouse location.voidremoveImageOverlay(ImageOverlay io)Removes the image overlay.voidremoveImageOverlays(Class cls)Removes all image overlay instances that are instances of the specified class.voidremoveLeftClickListener(ImagePanelLeftClickListener l)Removes the given listener from the internal list of left-click listeners.voidremovePaintlet(Paintlet p)Removes this paintlet from its internal list.voidremoveSelectionListener(ImagePanelSelectionListener l)Removes the given listener from the internal list of selection listeners.voidsaveReport()Saves the report to a file.voidselectImageOverlay()Lets the user select an overlay to add.voidsetCurrentImage(BufferedImage value)Sets the image to display.voidsetCurrentImage(BufferedImage value, double scale)Sets the image to display.voidsetCustomPopupMenuProvider(CustomPopupMenuProvider value)Sets the custom popup menu provider.voidsetInteractionLoggingFilter(InteractionLoggingFilter value)Sets the interaction log filter to use.voidsetScale(double value)Sets the scaling factor.voidsetSelectionEnabled(boolean value)Sets whether selection is enabled or not.voidsetSelectionShapePainter(SelectionShapePainter value)Sets the painter for the selection shape.voidshowPopup(MouseEvent e)Displays a popup-menu.voidupdate()Updates the image.voidupdate(boolean doLayout)Updates the image.voidupdateStatus()Updates the status bar.voidupdateStatus(Point pos)Updates the status bar.-
Methods inherited from class adams.gui.core.BasePanel
afterHide, afterShow, beforeHide, beforeShow, closeParent, finishInit, getParentChild, getParentDialog, getParentFrame, getParentInternalFrame, getParentTitle, initFileChooser, main, printErrorMessage, printException, saveComponent, setEnabledCascade, setEnabledCascade, setParentTitle, setVisible
-
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
-
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, 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, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, 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, unregisterKeyboardAction, update
-
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, 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
m_Owner
protected ImagePanel m_Owner
the owning image panel.
-
m_Scale
protected double m_Scale
the scaling factor.
-
m_CurrentImage
protected BufferedImage m_CurrentImage
the current image.
-
m_PrintMouseListener
protected PrintMouseListener m_PrintMouseListener
the mouse listener.
-
m_ImageOverlays
protected HashSet<ImageOverlay> m_ImageOverlays
the image overlays.
-
m_CustomPopupMenuProvider
protected CustomPopupMenuProvider m_CustomPopupMenuProvider
whether to use a custom popup menu provider.
-
m_SelectionEnabled
protected boolean m_SelectionEnabled
whether selection via box is enabled.
-
m_SelectionShapePainter
protected SelectionShapePainter m_SelectionShapePainter
the color of the selection box.
-
m_Selecting
protected boolean m_Selecting
whether the selection box is currently been drawn.
-
m_Dragged
protected boolean m_Dragged
whether dragging has happened at all.
-
m_SelectionFrom
protected Point m_SelectionFrom
the starting corner of the selection box.
-
m_SelectionTo
protected Point m_SelectionTo
the finishing corner of the selection box.
-
m_SelectionListeners
protected Set<ImagePanelSelectionListener> m_SelectionListeners
the selection listeners.
-
m_LeftClickListeners
protected Set<ImagePanelLeftClickListener> m_LeftClickListeners
the left-click listeners.
-
m_GOEImageOverlay
protected GenericObjectEditorDialog m_GOEImageOverlay
the GOE for adding an image overlay.
-
m_InteractionLoggingFilter
protected InteractionLoggingFilter m_InteractionLoggingFilter
the interaction logger in use.
-
m_ReportFileChooser
protected DefaultReportFileChooser m_ReportFileChooser
the filechooser for reports.
-
-
Constructor Detail
-
PaintPanel
public PaintPanel(ImagePanel owner)
Initializes the panel.- Parameters:
owner- the image panel this paint panel belongs to
-
-
Method Detail
-
initialize
protected void initialize()
Initializes members.- Overrides:
initializein classBasePanel
-
logMouseButtonPressed
protected void logMouseButtonPressed(MouseEvent e)
Logs a mouse button pressed.- Parameters:
e- the mouse event to record
-
logMouseButtonClick
protected void logMouseButtonClick(MouseEvent e)
Logs a mouse click.- Parameters:
e- the mouse event to record
-
logMouseButtonReleased
protected void logMouseButtonReleased(MouseEvent e)
Logs a mouse button released.- Parameters:
e- the mouse event to record
-
logMouseWheel
protected void logMouseWheel(MouseWheelEvent e, double oldScale, double newScale)
Logs a mouse click.- Parameters:
e- the mouse wheel event to recordoldScale- the old scalenewScale- the new scale
-
logScale
protected void logScale(double newScale)
Logs a scale change from the menu.- Parameters:
newScale- the new scale
-
addPaintlet
public void addPaintlet(Paintlet p)
Adds the paintlet to the internal list.- Parameters:
p- the paintlet to add.
-
removePaintlet
public void removePaintlet(Paintlet p)
Removes this paintlet from its internal list.- Parameters:
p- the paintlet to remove
-
paintlets
public Iterator<Paintlet> paintlets()
Returns an iterator over all currently stored paintlets.- Returns:
- the paintlets
-
setInteractionLoggingFilter
public void setInteractionLoggingFilter(InteractionLoggingFilter value)
Sets the interaction log filter to use.- Parameters:
value- the filter
-
getInteractionLoggingFilter
public InteractionLoggingFilter getInteractionLoggingFilter()
Returns the interaction log filter in use.- Returns:
- the filter
-
updateStatus
public void updateStatus()
Updates the status bar.
-
mouseToPixelLocation
public Point mouseToPixelLocation(Point mousePos)
Turns the mouse position into pixel location. Limits the pixel position to the size of the image, i.e., no negative pixel locations or ones that exceed the image size are generated.- Parameters:
mousePos- the mouse position- Returns:
- the pixel location
-
pixelToMouseLocation
public Point pixelToMouseLocation(Point pixelPos)
Converts the pixel position (at 100% scale) to a mouse location.- Parameters:
pixelPos- the pixel position- Returns:
- the mouse position
-
isSelecting
public boolean isSelecting()
Whether selection is currently active.- Returns:
- true if active
-
isDragged
public boolean isDragged()
Whether dragging is selection is currently active.- Returns:
- true if active
-
updateStatus
public void updateStatus(Point pos)
Updates the status bar.- Parameters:
pos- the mouse position
-
showPopup
public void showPopup(MouseEvent e)
Displays a popup-menu. Either provided by the custom popup menu provider or the default one.- Parameters:
e- the event that triggered the popup- See Also:
m_CustomPopupMenuProvider
-
getOwner
public ImagePanel getOwner()
Returns the owning panel.- Returns:
- the owner
-
setCurrentImage
public void setCurrentImage(BufferedImage value)
Sets the image to display.- Parameters:
value- the image to use
-
setCurrentImage
public void setCurrentImage(BufferedImage value, double scale)
Sets the image to display.- Parameters:
value- the image to usescale- the scale to use
-
getCurrentImage
public BufferedImage getCurrentImage()
Returns the current image.- Returns:
- the image, can be null if not set
-
setScale
public void setScale(double value)
Sets the scaling factor.- Parameters:
value- the scaling factor
-
update
public void update()
Updates the image.
-
update
public void update(boolean doLayout)
Updates the image.- Parameters:
doLayout- whether to update the layout
-
getScale
public double getScale()
Returns the scaling factor (0-16).- Returns:
- the scaling factor
-
clearImageOverlays
public void clearImageOverlays()
Removes all image overlays.
-
export
public void export()
Exports the current image.
-
getReportFileChooser
protected DefaultReportFileChooser getReportFileChooser()
Returns the report filechooser to use.- Returns:
- the file chooser
-
loadReport
public void loadReport()
Loads a report from a file.
-
saveReport
public void saveReport()
Saves the report to a file.
-
selectImageOverlay
public void selectImageOverlay()
Lets the user select an overlay to add.
-
addImageOverlay
public void addImageOverlay(ImageOverlay io)
Adds the image overlay.- Parameters:
io- the image overlay to add
-
removeImageOverlay
public void removeImageOverlay(ImageOverlay io)
Removes the image overlay.- Parameters:
io- the image overlay to remove
-
removeImageOverlays
public void removeImageOverlays(Class cls)
Removes all image overlay instances that are instances of the specified class.- Parameters:
cls- the image overlay class to remove
-
imageOverlays
public Iterator<ImageOverlay> imageOverlays()
Returns an iterator over all the image overlays.- Returns:
- iterator on image overlays
-
setCustomPopupMenuProvider
public void setCustomPopupMenuProvider(CustomPopupMenuProvider value)
Sets the custom popup menu provider.- Parameters:
value- the provider, use null to remove
-
getCustomPopupMenuProvider
public CustomPopupMenuProvider getCustomPopupMenuProvider()
Returns the custom popup menu provider.- Returns:
- the provider, null if none set
-
paintSelectionShape
protected void paintSelectionShape(Graphics g)
Paints the selection box, if necessary (i.e., currently selecting/dragging).- Parameters:
g- the graphics context
-
paint
public void paint(Graphics g)
Paints the image or just a white background.- Overrides:
paintin classJComponent- Parameters:
g- the graphics context
-
setSelectionShapePainter
public void setSelectionShapePainter(SelectionShapePainter value)
Sets the painter for the selection shape.- Parameters:
value- the painter
-
getSelectionShapePainter
public SelectionShapePainter getSelectionShapePainter()
Returns the painter to use for the selection shape.- Returns:
- the painter
-
setSelectionEnabled
public void setSelectionEnabled(boolean value)
Sets whether selection is enabled or not.- Parameters:
value- if true then selection is enabled
-
isSelectionEnabled
public boolean isSelectionEnabled()
Returns whether selection is enabled.- Returns:
- true if selection is enabled
-
clearSelectionListeners
public void clearSelectionListeners()
Removes all selection listeners.
-
addSelectionListener
public void addSelectionListener(ImagePanelSelectionListener l)
Adds the given listener to the internal list of selection listeners.- Parameters:
l- the listener to add
-
removeSelectionListener
public void removeSelectionListener(ImagePanelSelectionListener l)
Removes the given listener from the internal list of selection listeners.- Parameters:
l- the listener to remove
-
notifySelectionListeners
public void notifySelectionListeners(Point topLeft, Point bottomRight, int modifiersEx)
Notifies all selection listeners.- Parameters:
topLeft- the top-left of the selectionbottomRight- the bottom-right of the selectionmodifiersEx- the extended modifiers- See Also:
MouseEvent.getModifiersEx()
-
clearLeftClickListeners
public void clearLeftClickListeners()
Removes all left-click listeners.
-
addLeftClickListener
public void addLeftClickListener(ImagePanelLeftClickListener l)
Adds the given listener to the internal list of left-click listeners.- Parameters:
l- the listener to add
-
removeLeftClickListener
public void removeLeftClickListener(ImagePanelLeftClickListener l)
Removes the given listener from the internal list of left-click listeners.- Parameters:
l- the listener to remove
-
notifyLeftClickListeners
public void notifyLeftClickListeners(Point position, int modifiersEx)
Notifies all left-click listeners.- Parameters:
position- the position of the clickmodifiersEx- the extended modifiers- See Also:
MouseEvent.getModifiersEx()
-
cleanUp
public void cleanUp()
Cleans up data structures, frees up memory.- Specified by:
cleanUpin interfaceCleanUpHandler
-
-