de.uni_paderborn.fujaba.fsa.swing
Class JEgg

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byde.uni_paderborn.fujaba.fsa.swing.JEgg
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.lang.Runnable, java.io.Serializable

public class JEgg
extends javax.swing.JComponent
implements java.lang.Runnable

The Java Enterprise Grub Gang - shortly called J-EGG - serves to make possible problems that can occur in the design phase of a software project explicit. Imagine a large software design and suddenly you notice that behind nearly every part of that design something hides you did not expect. Getting rid of these things is not easy ...

Please not that JEgg requires FSA (the new Fujaba display structures) to run and one active diagram (what type does not matter).

Should you discover any bugs in this code, please do not remove them. :)

Version:
$Revision: 1.17 $
Author:
$Author: schneider $
See Also:
Serialized Form

Nested Class Summary
private  class JEgg.EggDeathMouseListener
          Listens for death-bringing mouse clicks
static class JEgg.EggMouseListener
          This key listener listens for a triple click and adds the EggKeyListener to a given component if a triple click has been found
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
(package private)  boolean alive
          Determines whether this JEgg is still alive or whether it has already been hit by a death-bringing mouse click
private static int COLLISION_WITH_JEGG
          Return value for isConcealed.
private static int CONCEALED
          Return value for isConcealed.
private static javax.swing.ImageIcon deadIcon
          The icon for the JEgg that will be displayed when alive is false.
private  int direction
          The direction this JEgg currently has.
private static int[] DIRECTION_X_DIFF
          This array converts an angle as defined in direction into the position difference in pixels of the x-axis that is used when a JEgg makes one step.
private static int[] DIRECTION_Y_DIFF
          This array converts an angle as defined in direction into the position difference in pixels of the y-axis that is used when a JEgg makes one step.
private  int directionDelta
          The direction in which this JEgg may turn.
private static int height
          The maximum height of all icons.
private static javax.swing.ImageIcon[][] icons
          The icons of the JEgg.
private static int instanceCount
          Counts the instances of Bugs on the diagram.
private  int moveState
          The move state this JEgg currently has.
private static int NOT_CONCEALED
          Return value for isConcealed.
private static int width
          The maximum width of all icons.
 
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.Container
 
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
private JEgg()
          Creates a new JEgg and initializes it.
 
Method Summary
private  void changeDirection()
          Calculates a new direction for this JEgg.
private  int getContainerHeight()
          Returns the height of the container this component is contained in
private  int getContainerWidth()
          Returns the width of the container this component is contained in
private  void getIcons()
          Ensures that the icons required for a JEgg are loaded.
 java.awt.Dimension getPreferredSize()
          Returns the preferred size of a JEgg
 boolean isAlive()
          Determines whether this JEgg is still alive or whether it has already been hit by a death-bringing mouse click
private  int isConcealed()
          Checks whether this component is concealed by any other component in the view (with the exception of JLines, because they are not really useful for hiding :).
 void paintComponent(java.awt.Graphics g)
          Paints this JEgg according to its state
private  void removeYou()
          Remove this component from its container
 void run()
          Run method for the Thread of this JEgg, as defined by the Runnable interface.
static void start()
          Starts JEgg.
private  void toBack()
          Puts this component behind all other components of the container
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, 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

instanceCount

private static int instanceCount
Counts the instances of Bugs on the diagram.


icons

private static javax.swing.ImageIcon[][] icons
The icons of the JEgg. To ensure that this array is set-up correctly call getIcons() . The first dimension defines the angle of the JEgg (the variable direction should be used as index for this dimension). This version of JEgg uses 8 different values, representing the angles 30�, 60�, 120�, 150�, 210�, 240�, 300� and 330�. The second dimension defines a move-state of the JEgg. There are currently three move-states. (the variable moveState should be used as index for this dimension).


deadIcon

private static javax.swing.ImageIcon deadIcon
The icon for the JEgg that will be displayed when alive is false. To ensure that this field is set-up correctly call getIcons().


width

private static int width
The maximum width of all icons. Calculated by getIcons().


height

private static int height
The maximum height of all icons. Calculated by getIcons().


direction

private int direction
The direction this JEgg currently has. First index for icons and index for the direction(X|Y)diff arrays.


directionDelta

private int directionDelta
The direction in which this JEgg may turn.


moveState

private int moveState
The move state this JEgg currently has. Second index for icons.


DIRECTION_X_DIFF

private static final int[] DIRECTION_X_DIFF
This array converts an angle as defined in direction into the position difference in pixels of the x-axis that is used when a JEgg makes one step. direction should be used as index for this.


DIRECTION_Y_DIFF

private static final int[] DIRECTION_Y_DIFF
This array converts an angle as defined in direction into the position difference in pixels of the y-axis that is used when a JEgg makes one step. direction should be used as index for this.


alive

boolean alive
Determines whether this JEgg is still alive or whether it has already been hit by a death-bringing mouse click


NOT_CONCEALED

private static final int NOT_CONCEALED
Return value for isConcealed. The JEgg is visible.

See Also:
Constant Field Values

CONCEALED

private static final int CONCEALED
Return value for isConcealed. The JEgg is not visible.

See Also:
Constant Field Values

COLLISION_WITH_JEGG

private static final int COLLISION_WITH_JEGG
Return value for isConcealed. The JEgg shares the same position with another JEgg.

See Also:
Constant Field Values
Constructor Detail

JEgg

private JEgg()
Creates a new JEgg and initializes it. Used by start().

Method Detail

getIcons

private void getIcons()
Ensures that the icons required for a JEgg are loaded. The loaded icons are put into the static variables icon and deadIcon.

Throws:
java.lang.RuntimeException - if the icons could not be loaded.

getPreferredSize

public java.awt.Dimension getPreferredSize()
Returns the preferred size of a JEgg

Returns:
The preferredSize value

paintComponent

public void paintComponent(java.awt.Graphics g)
Paints this JEgg according to its state

Parameters:
g - No description provided

isAlive

public boolean isAlive()
Determines whether this JEgg is still alive or whether it has already been hit by a death-bringing mouse click

Returns:
The alive value

run

public void run()
Run method for the Thread of this JEgg, as defined by the Runnable interface.

Specified by:
run in interface java.lang.Runnable

getContainerWidth

private int getContainerWidth()
Returns the width of the container this component is contained in

Returns:
the width of the container this component is contained in or -1 if this component has no container.

getContainerHeight

private int getContainerHeight()
Returns the height of the container this component is contained in

Returns:
the height of the container this component is contained in or -1 if this component has no container.

isConcealed

private int isConcealed()
Checks whether this component is concealed by any other component in the view (with the exception of JLines, because they are not really useful for hiding :). If this component is completely concealed, CONCEALED is returned. If this component shares its place with another JEgg, COLLISION_WITH_JEGG is returned. Otherwise NOT_CONCEALED is returned.

Returns:
The concealed value

changeDirection

private void changeDirection()
Calculates a new direction for this JEgg. This is done by adding the value of directionDelta to direction. In 30% of all cases directionDelta is automatically inverted.


removeYou

private void removeYou()
Remove this component from its container


toBack

private void toBack()
Puts this component behind all other components of the container


start

public static void start()
Starts JEgg. Note that JEgg requires FSA to run.