optics.graphics
Class Diagram2DPanel

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 optics.graphics.Diagram2DPanel
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.accessibility.Accessible
Direct Known Subclasses:
ImagePanel

public class Diagram2DPanel
extends javax.swing.JPanel
implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener

Class to implement a DiagramPanel, being an extended JPanel with internal Mouse control allowing for interactive zooming.

See Also:
Serialized Form

Nested Class Summary
 
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.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  java.awt.geom.Rectangle2D bounds
           
protected  Diagram2D diagram
          The Diagram2D displayed on the Panel.
protected  boolean drag
           
protected  java.awt.Point endDrag
           
protected  boolean inZoomMode
           
protected  java.awt.Point startDrag
           
protected  boolean startDragSet
           
protected  java.awt.geom.AffineTransform transform
           
 
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
Diagram2DPanel()
          Form a blank Diagram2DPanel containg a blank Diagram3D to which components can be added.
Diagram2DPanel(Diagram2D d)
          Form a Diagram2DPanel containing a prespecified Diagram2D.
 
Method Summary
 void add(Diagram2DComponent obj)
          Method to add Component to the Diagram.
 void add(LensSystem lens)
          Method to add an LensSystem to the DiagramPanel
 void clear()
          Method to clear the DiagramPanel
 java.awt.image.BufferedImage exportImage(java.awt.image.BufferedImage im)
          Method to export the pabel as a spefified BufferenedImage with size and type specified by the image characteristics
 Diagram2D getDiagram2D()
          Method to get the Diagram object
 java.awt.image.BufferedImage getImage(int w, int h)
          Method to get to Diagram2DPanel as a coloured BuffererImage of type INT_RGB.
 void mouseClicked(java.awt.event.MouseEvent e)
          Void mouseClicked event, implement Button 3 resetting to full bounds.
 void mouseDragged(java.awt.event.MouseEvent e)
          Void mouseDragged event (only for drag with botton 1), which will highlight the dragged area in light grey.
 void mouseEntered(java.awt.event.MouseEvent e)
          Void mouseEntered, does nothing.
 void mouseExited(java.awt.event.MouseEvent e)
          Void mouseExited, does nothing.
 void mouseMoved(java.awt.event.MouseEvent e)
          Void mouseMoved method, does nothing
 void mousePressed(java.awt.event.MouseEvent e)
          Void mousePressed event, implement button 1 staring drag area.
 void mouseReleased(java.awt.event.MouseEvent e)
          Void mouseReleased event, implement sbutton 1 being relased after a drag.
 void paintComponent(java.awt.Graphics g)
          Overload method to repaint the JPanel
 void resetBounds()
          Internal method to reset the bounds to to be slightly large than the diagram bounds.
 void setDiagram(Diagram2D d)
          Method to set/reset the displayed Diagram.
 void setFontSize(double h)
          Method to set the fontsize (defaults to 16pt)
 void setPenWidth(double w)
          Method to set the default penwidth (defaults to 1.0)
 boolean writeImage(int w, int h, java.io.File output)
          Method to write the the Diagram to a file as a image with type specified by filename suffix
 
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, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, 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
 

Field Detail

diagram

protected Diagram2D diagram
The Diagram2D displayed on the Panel.


bounds

protected java.awt.geom.Rectangle2D bounds

transform

protected java.awt.geom.AffineTransform transform

startDrag

protected java.awt.Point startDrag

startDragSet

protected boolean startDragSet

endDrag

protected java.awt.Point endDrag

drag

protected boolean drag

inZoomMode

protected boolean inZoomMode
Constructor Detail

Diagram2DPanel

public Diagram2DPanel(Diagram2D d)
Form a Diagram2DPanel containing a prespecified Diagram2D. The underlying JPanel has default flow layout.

Parameters:
d - the diagram to display.

Diagram2DPanel

public Diagram2DPanel()
Form a blank Diagram2DPanel containg a blank Diagram3D to which components can be added.

Method Detail

setDiagram

public void setDiagram(Diagram2D d)
Method to set/reset the displayed Diagram.

Parameters:
d - the Diagram2D to be displayed.

add

public void add(Diagram2DComponent obj)
Method to add Component to the Diagram. This will always result in the bounds being reset unless in Zoom mode where they will be left unchanged.

Note button 3 cancel zoom mode and reset defaults bounds.

Parameters:
obj - the DiagramObject

add

public void add(LensSystem lens)
Method to add an LensSystem to the DiagramPanel

Parameters:
lens - the LensSystem.

getDiagram2D

public Diagram2D getDiagram2D()
Method to get the Diagram object

Returns:
Diagram2D the panel Diagram

clear

public void clear()
Method to clear the DiagramPanel


setPenWidth

public void setPenWidth(double w)
Method to set the default penwidth (defaults to 1.0)

Parameters:
w - the penwidth

setFontSize

public void setFontSize(double h)
Method to set the fontsize (defaults to 16pt)

Parameters:
h - the fontsize

resetBounds

public void resetBounds()
Internal method to reset the bounds to to be slightly large than the diagram bounds.


writeImage

public boolean writeImage(int w,
                          int h,
                          java.io.File output)
Method to write the the Diagram to a file as a image with type specified by filename suffix

Parameters:
w - image width
h - image height
output - the File to be written to
Returns:
boolean true if successful, false for failure.

exportImage

public java.awt.image.BufferedImage exportImage(java.awt.image.BufferedImage im)
Method to export the pabel as a spefified BufferenedImage with size and type specified by the image characteristics

Parameters:
im - the BufferedImage
Returns:
BufferedImage which will be the specifed BufferedImage with the figure painted.

getImage

public java.awt.image.BufferedImage getImage(int w,
                                             int h)
Method to get to Diagram2DPanel as a coloured BuffererImage of type INT_RGB.

Parameters:
w - image width
h - image height
Returns:
BufferedImage image of the panel

paintComponent

public void paintComponent(java.awt.Graphics g)
Overload method to repaint the JPanel

Overrides:
paintComponent in class javax.swing.JComponent

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Void mouseClicked event, implement Button 3 resetting to full bounds.

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
e - the mouse event.

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Void mousePressed event, implement button 1 staring drag area.

Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
e - the mouse even

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Void mouseReleased event, implement sbutton 1 being relased after a drag. This does the zom to the dragged area.

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
e - the mouse event

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Void mouseEntered, does nothing.

Specified by:
mouseEntered in interface java.awt.event.MouseListener
Parameters:
e - the mourse event

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Void mouseExited, does nothing.

Specified by:
mouseExited in interface java.awt.event.MouseListener
Parameters:
e - the mourse event

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Void mouseDragged event (only for drag with botton 1), which will highlight the dragged area in light grey.

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Parameters:
e - the mouse event.

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Void mouseMoved method, does nothing

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
Parameters:
e - the mouse event