views
Class ImagePanel

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 views.ImagePanel
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.Scrollable

 class ImagePanel
extends javax.swing.JPanel
implements javax.swing.Scrollable, java.awt.event.MouseListener

Inner class that contains the Image with an area of the earth and the PlanetLab nodes Handles Zoom operations, tool-tips etc.

Author:
Leo Bosnjak

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
private  GenerateMap generateMap
           
private  java.awt.Dimension imageOffset
           
private  java.awt.Dimension imageSize
           
private  MapImage mapImage
           
private static double MAX_ZOOM_FACTOR
           
private static double MIN_ZOOM_FACTOR
           
private  double nodeSizeFactor
           
private  java.awt.Dimension optimalImageSize
           
private static double ORIGINAL_ZOOM_FACTOR
           
private  java.awt.Dimension originalImageSize
           
private static int SCROLL_BLOCK_INCREMENT
           
private static int SCROLL_UNIT_INCREMENT
           
private static long serialVersionUID
           
private  IImagePanelWorker worker
           
private static double ZOOM_STEP
           
private  double zoomFactor
           
 
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
ImagePanel(IImagePanelWorker worker, MapImage mapImage, GenerateMap generateMap, java.awt.Dimension imageOffset, java.awt.Dimension optimalImageSize)
          construct the ImagePanel
 
Method Summary
private  void calculateImageSize()
          calculates the scaled image size based on the zoom-factor
private  java.awt.Point convertPointToOriginalCoords(java.awt.Point point)
          converts the point to a point in the original image coordinates
 java.awt.Dimension getImageOffset()
           
 java.awt.Dimension getPreferredScrollableViewportSize()
           
 int getScrollableBlockIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)
          Likewise, the scroll pane calls the client's getScrollableBlockIncrement method each time the user clicks on the track.
 boolean getScrollableTracksViewportHeight()
           
 boolean getScrollableTracksViewportWidth()
           
 int getScrollableUnitIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)
          The scroll pane calls the client's getScrollableUnitIncrement method whenever the user clicks one of the buttons on the scroll bar.
 java.lang.String getToolTipText(java.awt.event.MouseEvent evt)
          gets the tooltip-text to a point, if it belongs to a Node/City
private  void handlePopupTrigger(java.awt.event.MouseEvent evt)
          Checks whether the MouseEvent is a popup trigger.
 void mouseClicked(java.awt.event.MouseEvent evt)
          Handles mouse clicks on the image by opening a popup menu when a click on a valid Node/City is done
 void mouseEntered(java.awt.event.MouseEvent evt)
          Empty method; definition required by the MouseListener interface.
 void mouseExited(java.awt.event.MouseEvent evt)
          Empty method; definition required by the MouseListener interface.
 void mousePressed(java.awt.event.MouseEvent evt)
          Handles popup clicks on the image by opening a popup menu when a click on a valid Node/City is done definition required by the MouseListener interface.
 void mouseReleased(java.awt.event.MouseEvent evt)
          Empty method; definition required by the MouseListener interface.
 void paintComponent(java.awt.Graphics g)
          draw the image
 void resetZoomFactor()
          resets the zoom-factor to the original image size (1.0)
 void setImageOffset(java.awt.Dimension imageOffset)
           
 boolean SetZoomFactor(double factor)
          Set the zoom factor of the image (eg to 200% == 2.0)
private  void updateNodeSizeFactor()
          Calculates and updates the size of the Node-circles on the map.
 void ZoomIn(int units)
          zooms one step in
 void ZoomOut(int units)
          zooms one step out
 
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, 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

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

MAX_ZOOM_FACTOR

private static final double MAX_ZOOM_FACTOR
See Also:
Constant Field Values

MIN_ZOOM_FACTOR

private static final double MIN_ZOOM_FACTOR
See Also:
Constant Field Values

ORIGINAL_ZOOM_FACTOR

private static final double ORIGINAL_ZOOM_FACTOR
See Also:
Constant Field Values

ZOOM_STEP

private static final double ZOOM_STEP
See Also:
Constant Field Values

SCROLL_UNIT_INCREMENT

private static final int SCROLL_UNIT_INCREMENT
See Also:
Constant Field Values

SCROLL_BLOCK_INCREMENT

private static final int SCROLL_BLOCK_INCREMENT
See Also:
Constant Field Values

mapImage

private MapImage mapImage

generateMap

private GenerateMap generateMap

imageOffset

private java.awt.Dimension imageOffset

zoomFactor

private double zoomFactor

imageSize

private java.awt.Dimension imageSize

optimalImageSize

private java.awt.Dimension optimalImageSize

originalImageSize

private java.awt.Dimension originalImageSize

worker

private IImagePanelWorker worker

nodeSizeFactor

private double nodeSizeFactor
Constructor Detail

ImagePanel

public ImagePanel(IImagePanelWorker worker,
                  MapImage mapImage,
                  GenerateMap generateMap,
                  java.awt.Dimension imageOffset,
                  java.awt.Dimension optimalImageSize)
construct the ImagePanel

Parameters:
mapImage -
imageOffset -
Method Detail

ZoomIn

public void ZoomIn(int units)
zooms one step in


ZoomOut

public void ZoomOut(int units)
zooms one step out


updateNodeSizeFactor

private void updateNodeSizeFactor()
Calculates and updates the size of the Node-circles on the map. The size depends on the zoomFactor, the optimal image size and the original image size. TODO: there are three issues left: - When zooming in at 1.9 and 2.0 a repaint is done -> only one should be made - When zooming out again from 1.9 the size remains at the smaller size until 1.0, allthough it should be equal to the 1.0 size - Optimal image size and the ones with greater resolutions are handled separately, why?


SetZoomFactor

public boolean SetZoomFactor(double factor)
Set the zoom factor of the image (eg to 200% == 2.0)

Parameters:
factor -
Returns:
true if successful, false if the factor is out of range

resetZoomFactor

public void resetZoomFactor()
resets the zoom-factor to the original image size (1.0)


calculateImageSize

private void calculateImageSize()
calculates the scaled image size based on the zoom-factor


paintComponent

public void paintComponent(java.awt.Graphics g)
draw the image

Overrides:
paintComponent in class javax.swing.JComponent

convertPointToOriginalCoords

private java.awt.Point convertPointToOriginalCoords(java.awt.Point point)
converts the point to a point in the original image coordinates

Parameters:
point - - the point to convert from (it is in the zoomed image coordinates)
Returns:
point in the original image coordinates

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent evt)
Handles mouse clicks on the image by opening a popup menu when a click on a valid Node/City is done

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
evt - a MouseEvent

mousePressed

public void mousePressed(java.awt.event.MouseEvent evt)
Handles popup clicks on the image by opening a popup menu when a click on a valid Node/City is done definition required by the MouseListener interface.

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

handlePopupTrigger

private void handlePopupTrigger(java.awt.event.MouseEvent evt)
Checks whether the MouseEvent is a popup trigger. If so, this method openes the popup menu.

Parameters:
evt -

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent evt)
Empty method; definition required by the MouseListener interface.

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

mouseExited

public void mouseExited(java.awt.event.MouseEvent evt)
Empty method; definition required by the MouseListener interface.

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

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent evt)
Empty method; definition required by the MouseListener interface.

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

getToolTipText

public java.lang.String getToolTipText(java.awt.event.MouseEvent evt)
gets the tooltip-text to a point, if it belongs to a Node/City

Overrides:
getToolTipText in class javax.swing.JComponent
Returns:
- the tooltip, if there is a Node/City on this point null - otherwise

getScrollableUnitIncrement

public int getScrollableUnitIncrement(java.awt.Rectangle visibleRect,
                                      int orientation,
                                      int direction)
The scroll pane calls the client's getScrollableUnitIncrement method whenever the user clicks one of the buttons on the scroll bar. This method returns the number of pixels to scroll.

Specified by:
getScrollableUnitIncrement in interface javax.swing.Scrollable

getScrollableBlockIncrement

public int getScrollableBlockIncrement(java.awt.Rectangle visibleRect,
                                       int orientation,
                                       int direction)
Likewise, the scroll pane calls the client's getScrollableBlockIncrement method each time the user clicks on the track.

Specified by:
getScrollableBlockIncrement in interface javax.swing.Scrollable

getPreferredScrollableViewportSize

public java.awt.Dimension getPreferredScrollableViewportSize()
Specified by:
getPreferredScrollableViewportSize in interface javax.swing.Scrollable

getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth()
Specified by:
getScrollableTracksViewportWidth in interface javax.swing.Scrollable

getScrollableTracksViewportHeight

public boolean getScrollableTracksViewportHeight()
Specified by:
getScrollableTracksViewportHeight in interface javax.swing.Scrollable

getImageOffset

public java.awt.Dimension getImageOffset()
Returns:
the imageOffset

setImageOffset

public void setImageOffset(java.awt.Dimension imageOffset)
Parameters:
imageOffset - the imageOffset to set