org.fraid.graphics
Class GraphicsPanel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by org.fraid.graphics.GraphicsUser
                      extended by org.fraid.graphics.GraphicsPanel
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.ChangeListener

public class GraphicsPanel
extends GraphicsUser
implements javax.swing.event.ChangeListener

Objects of this class provide medium for 2D plotting. Must be used only embedded in a SliderPanel. Each instance selfregisters in the GraphicsStore at creation.

See Also:
GraphicsStore, Serialized Form

Nested Class Summary
 class GraphicsPanel.KeyPressedAction
           
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
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.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 boolean mIsZooming
          Do not use this variable.
 java.awt.Point mLastPopUpPosition
          Do not use this variable.
 
Fields inherited from class org.fraid.graphics.GraphicsUser
mAlgorithmThread, mImageSize, mPlugIn
 
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
 
Method Summary
 void clearZoomRegions()
          Cleans up when the zoom is canceled.
 void cornerButtonPressed()
          Depending on the state will stop painting or perform undo.
 void destroy()
          Cleans up when the window containing this panel is destroyed.
 void doZoom()
          Starts the zoom recalculations after the zoom parameters have been set.
 void drawZoomRegions(java.awt.Point endPoint)
          Marks the zoom region when the mouse is dragged.
 java.lang.Integer getKey()
          Returns the GraphicsStore key associated with this panel.
 SliderPanel getOwner()
          Returns the owning SliderPanel.
 javax.swing.JPopupMenu getPopUp()
          Retruns the associated popup menu.
 java.lang.String getToolTipText(java.awt.event.MouseEvent e)
           
 void interruptWatchingThread()
          Will stop the screen painting thread.
 void notifyWatchingThread()
          Will wake up the screen painting thread.
protected  void paintComponent(java.awt.Graphics g)
          The major repainting routine.
 void recalculateAndRepaint()
          Recalculates and repaints the image.
 void registerPrivateKeyboardActions()
           
 void repaintAfterPlugInChange()
          Use when changing the plugin.
 void scrollOffscreen(int direction, int disp)
          Scrolls the offscreen image and starts recalculation with the new values.
 void setInitialZoomMousePosition(java.awt.Point p)
          Sets the start position of the zooming region.
 void setOffscreenImage(java.awt.image.BufferedImage bi)
          Used by the PaintAlgorithmThread to set the generated image after it is done.
 void setOffscreenImage(int[] offscreenPixels)
          Used by the PaintAlgorithmThread to set the generated image after it is done.
 void setOffScreenOrigin(int x, int y)
          Sets the upper left corner of the plotting area to point where it should.
 BehaviorBean setPlugIn(java.lang.String aPlugInName)
          The method used to initialize the tripple GraphicsPanel - BehaviourPlugIn - PaintAlgorithmThread.
 void setStop()
          Called by the PaintAlgorithmThread to set the CornerButton to stop when calculations start.
protected  void setThreadNames()
           
 void stateChanged(javax.swing.event.ChangeEvent aEvent)
          Called when a function we are drawing changed.
 
Methods inherited from class org.fraid.graphics.GraphicsUser
getAlgorithm, getImageSize, getPlugIn, setAlgorithm, setPlugIn
 
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, 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, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, 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, setVisible, 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, 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
 
Methods inherited from interface java.awt.image.ImageObserver
imageUpdate
 

Field Detail

mLastPopUpPosition

public java.awt.Point mLastPopUpPosition
Do not use this variable. Used to pass the popup menu position from the mouse listener to the action listener.


mIsZooming

public boolean mIsZooming
Do not use this variable. Used to pass the boolean between the listeners

Method Detail

registerPrivateKeyboardActions

public void registerPrivateKeyboardActions()

setPlugIn

public BehaviorBean setPlugIn(java.lang.String aPlugInName)
                       throws PlugInException
The method used to initialize the tripple GraphicsPanel - BehaviourPlugIn - PaintAlgorithmThread. Do not use any other way for initialization.

Overrides:
setPlugIn in class GraphicsUser
Parameters:
aPlugInName - a String which could be: 1)String representation of an XML serialized BehaviourPlugIn, 2) PlugIn class name or 3)a file name of an XML serialized BehaviourPlugIn (checked in this order).
Returns:
a BehaviourPlugInAdapter value
Throws:
PlugInException - if the aPlugInName doesn't match anything.
See Also:
PlugInFactory

setThreadNames

protected void setThreadNames()

destroy

public void destroy()
Cleans up when the window containing this panel is destroyed. Should be called by the owners or the two threads will be leaked.

Specified by:
destroy in class GraphicsUser

stateChanged

public void stateChanged(javax.swing.event.ChangeEvent aEvent)
Called when a function we are drawing changed. Comes from the change listener we are implementing.

Specified by:
stateChanged in interface javax.swing.event.ChangeListener
Parameters:
aEvent - a ChangeEvent which the method doesn't use

notifyWatchingThread

public void notifyWatchingThread()
Will wake up the screen painting thread. Used by the PaintAlgorithmThread.

Specified by:
notifyWatchingThread in class GraphicsUser

interruptWatchingThread

public void interruptWatchingThread()
Will stop the screen painting thread. Used by the PaintAlgorithmThread.

Specified by:
interruptWatchingThread in class GraphicsUser

getKey

public java.lang.Integer getKey()
Returns the GraphicsStore key associated with this panel.

Returns:
an Object value

getPopUp

public javax.swing.JPopupMenu getPopUp()
Retruns the associated popup menu. Used by the mouse listener.

Specified by:
getPopUp in class GraphicsUser
Returns:
a JPopupMenu value

getOwner

public SliderPanel getOwner()
Returns the owning SliderPanel.

Returns:
a SliderPanel value

setOffScreenOrigin

public void setOffScreenOrigin(int x,
                               int y)
Sets the upper left corner of the plotting area to point where it should. Used by PaintAlgorithmThread.

Specified by:
setOffScreenOrigin in class GraphicsUser
Parameters:
x - an int value
y - an int value

setOffscreenImage

public void setOffscreenImage(java.awt.image.BufferedImage bi)
Used by the PaintAlgorithmThread to set the generated image after it is done.

Specified by:
setOffscreenImage in class GraphicsUser
Parameters:
bi - a BufferedImage value
See Also:
setOffscreenImage( BufferedImage )

setOffscreenImage

public void setOffscreenImage(int[] offscreenPixels)
Used by the PaintAlgorithmThread to set the generated image after it is done.

Specified by:
setOffscreenImage in class GraphicsUser
Parameters:
offscreenPixels - an array to pass to MemoryImageSource.
See Also:
setOffscreenImage( int[] )

cornerButtonPressed

public void cornerButtonPressed()
Depending on the state will stop painting or perform undo. Called by the SliderPanel's CornerButton action listener.


setStop

public void setStop()
Called by the PaintAlgorithmThread to set the CornerButton to stop when calculations start.

Specified by:
setStop in class GraphicsUser

scrollOffscreen

public void scrollOffscreen(int direction,
                            int disp)
Scrolls the offscreen image and starts recalculation with the new values.

Parameters:
direction - Adjustable.HORIZONTAL or Adjustable.VERTICAL
disp - displacement in this direction

recalculateAndRepaint

public void recalculateAndRepaint()
Recalculates and repaints the image. If you call repaint() only the offscreen image is displayed. Call whenever you want your image to be painted fresh (i.e. something changed). Do not use when the plugin changed.

Specified by:
recalculateAndRepaint in class GraphicsUser
See Also:
GraphicsPanel.repaintPanelAfterPlugInChange()

repaintAfterPlugInChange

public void repaintAfterPlugInChange()
Use when changing the plugin. GraphicsPanel.recalculateAndRepaint() won't work in that case.


setInitialZoomMousePosition

public void setInitialZoomMousePosition(java.awt.Point p)
Sets the start position of the zooming region. Used by the mouse listener.

Parameters:
p - a Point value

doZoom

public void doZoom()
Starts the zoom recalculations after the zoom parameters have been set.


clearZoomRegions

public void clearZoomRegions()
Cleans up when the zoom is canceled.


drawZoomRegions

public void drawZoomRegions(java.awt.Point endPoint)
Marks the zoom region when the mouse is dragged.

Parameters:
endPoint - the endPoint of the region, the start point has been set by setInitialZoomMousePosition(Point).

getToolTipText

public java.lang.String getToolTipText(java.awt.event.MouseEvent e)
Overrides:
getToolTipText in class javax.swing.JComponent

paintComponent

protected void paintComponent(java.awt.Graphics g)
The major repainting routine. See code for details...

Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g - a Graphics value


Fraid (system and language). (C) 2003-2007 Ivaylo Iliev
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.