de.uni_paderborn.robots.gui
Class ArenaDesignerCanvas

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--de.uni_paderborn.robots.gui.ArenaCanvas
                          |
                          +--de.uni_paderborn.robots.gui.ArenaDesignerCanvas
All Implemented Interfaces:
java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.io.Serializable

public class ArenaDesignerCanvas
extends ArenaCanvas
implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener

Canvas of the ArenaDesignerFrame, which draws the arena and responds to mouse clicks on the fields.

See Also:
Serialized Form

Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent, javax.swing.JComponent.ActionStandin, javax.swing.JComponent.IntVector, javax.swing.JComponent.KeyboardState
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.AWTTreeLock
 
Field Summary
private  ArenaDesignerFrame arenaDesignerFrame
          link to ArenaDesignerFrame
private static int EXIT
          constant for exit 18
private  Wormhole firstWormhole
          first marked wormhole of two wormholes
private static int FLOOR
          constant for floor
static int ICON_NUMBER
          number of icons
private  int lastMouseRowColX
          last mouse positions x-coordinate
private  int lastMouseRowColY
          last mouse positions y-coordinate
private static int lastPlacedItem
          last placed item
private static int ROBOT_FIELD
          constant for robot field
private static int WALL0
          constant for wall 0
private static int WALL1
          constant for wall 1
private static int WALL10
          constant for wall 10
private static int WALL11
          constant for wall 11
private static int WALL12
          constant for wall 12
private static int WALL13
          constant for wall 13
private static int WALL14
          constant for wall 14
private static int WALL15
          constant for wall 15
private static int WALL2
          constant for wall 2
private static int WALL3
          constant for wall 3
private static int WALL4
          constant for wall 4
private static int WALL5
          constant for wall 5
private static int WALL6
          constant for wall 6
private static int WALL7
          constant for wall 7
private static int WALL8
          constant for wall 8
private static int WALL9
          constant for wall 9
private static int WELL
          constant for well 17
private static int WORMHOLE
          constant for wormhole
 
Fields inherited from class de.uni_paderborn.robots.gui.ArenaCanvas
arenaImages, fields, zoom
 
Fields inherited from class javax.swing.JComponent
_bounds, accessibleContext, actionMap, ACTIONMAP_CREATED, alignmentX, alignmentY, ANCESTOR_INPUTMAP_CREATED, ANCESTOR_USING_BUFFER, ancestorInputMap, ancestorNotifier, autoscroller, border, changeSupport, clientProperties, CREATED_DOUBLE_BUFFER, flags, FOCUS_INPUTMAP_CREATED, focusInputMap, HAS_FOCUS, htmlKey, htmlView, inputVerifier, IS_DOUBLE_BUFFERED, IS_OPAQUE, IS_PAINTING_TILE, IS_PRINTING, IS_PRINTING_ALL, KEY_EVENTS_ENABLED, KEYBOARD_BINDINGS_KEY, listenerList, maximumSize, minimumSize, NEXT_FOCUS, paintImmediatelyClip, paintingChild, preferredSize, readObjectCallbacks, REQUEST_FOCUS_DISABLED, tmpRect, TOOL_TIP_TEXT_KEY, ui, uiClassID, UNDEFINED_CONDITION, verifyInputWhenFocusTarget, vetoableChangeSupport, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW, WHEN_IN_FOCUSED_WINDOW_BINDINGS, WIF_INPUTMAP_CREATED, windowInputMap
 
Fields inherited from class java.awt.Container
component, containerListener, containerSerializedDataVersion, dbg, dispatcher, layoutMgr, listeningBoundsChildren, listeningChildren, maxSize, ncomponents, printing, printingThreads, serialVersionUID
 
Fields inherited from class java.awt.Component
actionListenerK, adjustmentListenerK, appContext, background, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, componentListener, componentListenerK, componentOrientation, componentSerializedDataVersion, containerListenerK, cursor, dropTarget, enabled, eventMask, focusListener, focusListenerK, font, foreground, graphicsConfig, hasFocus, height, hierarchyBoundsListener, hierarchyBoundsListenerK, hierarchyListener, hierarchyListenerK, incRate, inputMethodListener, inputMethodListenerK, isInc, isPacked, itemListenerK, keyListener, keyListenerK, LEFT_ALIGNMENT, locale, LOCK, metrics, minSize, mouseListener, mouseListenerK, mouseMotionListener, mouseMotionListenerK, name, nameExplicitlySet, newEventsOnly, ownedWindowK, parent, peer, peerFont, popups, prefSize, privateKey, RIGHT_ALIGNMENT, textListenerK, TOP_ALIGNMENT, valid, visible, width, windowClosingException, windowListenerK, x, y
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
ArenaDesignerCanvas(ArenaDesignerFrame arenaDesignerFrame, Fields fields, boolean zoom)
          constructor, creates a new ArenaDesignerCanvas
 
Method Summary
private  java.awt.Point calculateRowCol(int x, int y)
          This method calculates the column and row of the field in the arena where the mouse click occured.
static int getLastPlacedItem()
          This method gets the last placed item
 void getMouseClick(java.awt.event.MouseEvent e)
          This method is executed if the user clicks with the mouse button, to place an item on a specified field.
private  Item getNewItem(int item)
          This method creates a new item specified by the number and returns it.
private  int getNextUsefulItem(int x, int y)
          This method computes the next useful item which can be placed on the given field.
 void mouseClicked(java.awt.event.MouseEvent e)
          Empty implementation.
 void mouseDragged(java.awt.event.MouseEvent e)
          This method is executed if the user clicks with the mouse button, to place an item on a specified field and drag the mouse.
 void mouseEntered(java.awt.event.MouseEvent e)
          Empty implementation.
 void mouseExited(java.awt.event.MouseEvent e)
          Empty implementation.
 void mouseMoved(java.awt.event.MouseEvent e)
          Empty implementation.
 void mousePressed(java.awt.event.MouseEvent e)
          This method is executed if the user presses a mouse button, to mark the first wormhole of two wormholes which should be connected.
 void mouseReleased(java.awt.event.MouseEvent e)
          This method is executed if the user releases a mouse button, to mark the second wormhole of two wormholes which should be connected.
 void paint(java.awt.Graphics g)
          Draws the arena fields and its contents.
static void setLastPlacedItem(int item)
          This method sets the last placed item
 
Methods inherited from class de.uni_paderborn.robots.gui.ArenaCanvas
drawField, getFields, getZoom, setFields, setZoom
 
Methods inherited from class javax.swing.JComponent
_paintImmediately, , addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, adjustPaintFlags, alwaysOnTop, checkIfChildObscuredBySibling, clearFocusOwners, componentInputMapChanged, computeVisibleRect, computeVisibleRect, compWriteObjectNotify, contains, createToolTip, disable, enable, enableSerialization, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getActionMap, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperties, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getCreatedDoubleBuffer, getDebugGraphicsOptions, getFlag, getGraphics, getHeight, getInputMap, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getUIClassID, getVerifyInputWhenFocusTarget, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paintWithBuffer, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyBindings, processKeyBindingsForAllComponents, processKeyEvent, processMouseMotionEvent, putClientProperty, readObject, rectangleIsObscured, rectangleIsObscuredBySibling, registerKeyboardAction, registerKeyboardAction, registerWithKeyboardManager, registerWithKeyboardManager, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setCreatedDoubleBuffer, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFlag, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPaintingChild, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, shouldDebugGraphics, superProcessMouseMotionEvent, unregisterKeyboardAction, unregisterWithKeyboardManager, unregisterWithKeyboardManager, update, updateUI, writeObject
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, adjustListeningChildren, applyOrientation, checkGD, countComponents, createChildHierarchyEvents, createHierarchyEvents, deliverEvent, dispatchEventImpl, dispatchEventToSelf, doLayout, eventEnabled, findComponentAt, findComponentAt, findComponentAt, getAccessibleAt, getAccessibleChild, getAccessibleChildrenCount, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents_NoClientCode, getComponents, getLayout, getMouseEventTarget, getWindow, initIDs, insets, invalidate, invalidateTree, isAncestorOf, layout, lightweightPaint, lightweightPrint, list, list, locate, minimumSize, nextFocus, numListening, paintComponents, paintHeavyweightComponents, postProcessKeyEvent, postsOldMouseEvents, preferredSize, preProcessKeyEvent, printComponents, printHeavyweightComponents, processContainerEvent, processEvent, proxyEnableEvents, proxyRequestFocus, remove, remove, removeAll, removeContainerListener, setFocusOwner, setLayout, transferFocus, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, areInputMethodsEnabled, bounds, checkImage, checkImage, checkWindowClosingException, coalesceEvents, constructComponentName, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getAccessibleIndexInParent, getAccessibleStateSet, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont_NoClientCode, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen_NoTreeLock, getLocationOnScreen, getName, getNativeContainer, getParent_NoClientCode, getParent, getPeer, getSize, getToolkit, getToolkitImpl, getTreeLock, getWindowForObject, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isEnabledImpl, isLightweight, isRecursivelyVisible, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resetGC, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

ICON_NUMBER

public static final int ICON_NUMBER
number of icons

FLOOR

private static final int FLOOR
constant for floor

WALL0

private static final int WALL0
constant for wall 0

WALL1

private static final int WALL1
constant for wall 1

WALL2

private static final int WALL2
constant for wall 2

WALL3

private static final int WALL3
constant for wall 3

WALL4

private static final int WALL4
constant for wall 4

WALL5

private static final int WALL5
constant for wall 5

WALL6

private static final int WALL6
constant for wall 6

WALL7

private static final int WALL7
constant for wall 7

WALL8

private static final int WALL8
constant for wall 8

WALL9

private static final int WALL9
constant for wall 9

WALL10

private static final int WALL10
constant for wall 10

WALL11

private static final int WALL11
constant for wall 11

WALL12

private static final int WALL12
constant for wall 12

WALL13

private static final int WALL13
constant for wall 13

WALL14

private static final int WALL14
constant for wall 14

WALL15

private static final int WALL15
constant for wall 15

WELL

private static final int WELL
constant for well 17

EXIT

private static final int EXIT
constant for exit 18

WORMHOLE

private static final int WORMHOLE
constant for wormhole

ROBOT_FIELD

private static final int ROBOT_FIELD
constant for robot field

lastPlacedItem

private static int lastPlacedItem
last placed item

lastMouseRowColX

private int lastMouseRowColX
last mouse positions x-coordinate

lastMouseRowColY

private int lastMouseRowColY
last mouse positions y-coordinate

arenaDesignerFrame

private ArenaDesignerFrame arenaDesignerFrame
link to ArenaDesignerFrame

firstWormhole

private Wormhole firstWormhole
first marked wormhole of two wormholes
Constructor Detail

ArenaDesignerCanvas

public ArenaDesignerCanvas(ArenaDesignerFrame arenaDesignerFrame,
                           Fields fields,
                           boolean zoom)
constructor, creates a new ArenaDesignerCanvas
Parameters:
fields - Fields-object with the fields of the arena
zoom - initial zoom of canvas
Method Detail

getMouseClick

public void getMouseClick(java.awt.event.MouseEvent e)
This method is executed if the user clicks with the mouse button, to place an item on a specified field. We only accept clicks in the inner square of a field!!!
Parameters:
e - MouseEvent object

getNextUsefulItem

private int getNextUsefulItem(int x,
                              int y)
This method computes the next useful item which can be placed on the given field.
Parameters:
x - x-coordinate of field
y - y-coordinate of field
Returns:
id for a new item

calculateRowCol

private java.awt.Point calculateRowCol(int x,
                                       int y)
This method calculates the column and row of the field in the arena where the mouse click occured.
Parameters:
x - x-coordinate in component
y - y-coordinate in component
Returns:
row and column of field in arena as Point object

paint

public void paint(java.awt.Graphics g)
Draws the arena fields and its contents. If we are not in wormhole mode, the paint method of the super-class is used. Otherwise we only draw gray fields and wormholes.
Overrides:
paint in class ArenaCanvas
Parameters:
g - Graphics object

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
This method is executed if the user clicks with the mouse button, to place an item on a specified field and drag the mouse. We only accept clicks in the inner square of a field!!!
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Parameters:
e - MouseEvent object

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Empty implementation.
Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
e - MouseEvent object

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Empty implementation.
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
Parameters:
e - MouseEvent object

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Empty implementation.
Specified by:
mouseEntered in interface java.awt.event.MouseListener
Parameters:
e - MouseEvent object

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Empty implementation.
Specified by:
mouseExited in interface java.awt.event.MouseListener
Parameters:
e - MouseEvent object

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
This method is executed if the user presses a mouse button, to mark the first wormhole of two wormholes which should be connected. We only accept clicks in the inner square of a field!!!
Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
e - MouseEvent object

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
This method is executed if the user releases a mouse button, to mark the second wormhole of two wormholes which should be connected. We only accept clicks in the inner square of a field!!!
Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
e - MouseEvent object

getNewItem

private Item getNewItem(int item)
This method creates a new item specified by the number and returns it. The method returns null, if no appropriate item could be created or if floor was specified.
Parameters:
item - int identifier for item
Returns:
new item

setLastPlacedItem

public static void setLastPlacedItem(int item)
This method sets the last placed item
Parameters:
item - int identifier for item

getLastPlacedItem

public static int getLastPlacedItem()
This method gets the last placed item
Returns:
int identifier for last placed item