fi.hu.cs.titokone
Class Animator

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended byfi.hu.cs.titokone.Animator
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.lang.Runnable, java.io.Serializable

public class Animator
extends javax.swing.JPanel
implements java.lang.Runnable

This class takes care of the animation window. It digs the needed information from a RunInfo instance.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
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
private static int ALU_IN1
           
private static int ALU_IN2
           
private static int ALU_OUT
           
private  java.lang.Thread animationThread
          Thread, that runs animation.
private  java.awt.image.BufferedImage backgroundImage
           
private static int BASE
           
private  java.lang.String comment1
          Comment label
private  java.lang.String comment2
           
private  java.lang.String currentCommand
          Current command label
private  int delay
           
private  java.awt.image.BufferedImage doubleBuffer
           
private  boolean executeAnimationImmediately
          If this is true, animation will be executed without repaitings and delays.
private static int EXTERNAL_DEVICE
           
private  RunInfo info
          RunInfo object of currently running animation.
private static int IR
           
private  boolean isAnimating
          Is animation currently running.
private static java.lang.String[] labels
           
private static int LIMIT
           
private static int MAR
           
private static int MBR
           
private static int MEMORY
           
private static int PC
           
private  int pointX
           
private  int pointY
           
private static int R0
           
private static int R1
           
private static int R2
           
private static int R3
           
private static int R4
           
private static int R5
           
private static int R6
           
private static int R7
           
private static int[][] routeToBus
           
private static int SR
           
private  java.lang.String SR_String
          String presentation of status register.
private static java.awt.Font textFont
           
private static int TR
           
private  int[] value
          Contains values of registers, alu, memory and external device.
private static int[][] whereWriteLabelTo
           
private static int[][] whereWriteValueTo
           
 
Fields inherited from class javax.swing.JPanel
 
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
Animator()
          Creats new animator.
 
Method Summary
 boolean animate(RunInfo info)
          This method produces an animation of a command based on the information in the RunInfo parameter.
private  void animateAnEvent(int from, int to)
           
private  void animateAnEvent(int from, int to, int newValue)
          This method animates one event like "move 7 from R1 to In2 in ALU using the bus in between" The building block of a more complex operations like "STORE R1, 100" where one needs to fetch an instruction, decipher it etc.
 void init(TTK91Cpu cpu, int baseValue, int limitValue)
          Initalizes animation.
 boolean isAnimationRunning()
           
static void main(java.lang.String[] args)
           
 void paint(java.awt.Graphics g)
           
private  void pause()
           
 void run()
          Animation is done in this run method.
 void setAnimationDelay(int delay)
          Sets animation delay.
 void stopAnimation()
          Stops currently running animation if there is one.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
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, 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, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, 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
 
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

textFont

private static final java.awt.Font textFont

R0

private static final int R0
See Also:
Constant Field Values

R1

private static final int R1
See Also:
Constant Field Values

R2

private static final int R2
See Also:
Constant Field Values

R3

private static final int R3
See Also:
Constant Field Values

R4

private static final int R4
See Also:
Constant Field Values

R5

private static final int R5
See Also:
Constant Field Values

R6

private static final int R6
See Also:
Constant Field Values

R7

private static final int R7
See Also:
Constant Field Values

TR

private static final int TR
See Also:
Constant Field Values

PC

private static final int PC
See Also:
Constant Field Values

IR

private static final int IR
See Also:
Constant Field Values

SR

private static final int SR
See Also:
Constant Field Values

BASE

private static final int BASE
See Also:
Constant Field Values

LIMIT

private static final int LIMIT
See Also:
Constant Field Values

MAR

private static final int MAR
See Also:
Constant Field Values

MBR

private static final int MBR
See Also:
Constant Field Values

ALU_IN1

private static final int ALU_IN1
See Also:
Constant Field Values

ALU_IN2

private static final int ALU_IN2
See Also:
Constant Field Values

ALU_OUT

private static final int ALU_OUT
See Also:
Constant Field Values

EXTERNAL_DEVICE

private static final int EXTERNAL_DEVICE
See Also:
Constant Field Values

MEMORY

private static final int MEMORY
See Also:
Constant Field Values

routeToBus

private static final int[][] routeToBus

whereWriteValueTo

private static final int[][] whereWriteValueTo

whereWriteLabelTo

private static final int[][] whereWriteLabelTo

labels

private static final java.lang.String[] labels

value

private int[] value
Contains values of registers, alu, memory and external device.


currentCommand

private java.lang.String currentCommand
Current command label


comment1

private java.lang.String comment1
Comment label


comment2

private java.lang.String comment2

SR_String

private java.lang.String SR_String
String presentation of status register.


executeAnimationImmediately

private boolean executeAnimationImmediately
If this is true, animation will be executed without repaitings and delays.


isAnimating

private boolean isAnimating
Is animation currently running.


animationThread

private java.lang.Thread animationThread
Thread, that runs animation.


info

private RunInfo info
RunInfo object of currently running animation.


backgroundImage

private java.awt.image.BufferedImage backgroundImage

doubleBuffer

private java.awt.image.BufferedImage doubleBuffer

pointX

private int pointX

pointY

private int pointY

delay

private int delay
Constructor Detail

Animator

public Animator()
         throws java.io.IOException
Creats new animator.

Throws:
java.io.IOException - If there are problems reading background image throw IOException.
Method Detail

paint

public void paint(java.awt.Graphics g)

run

public void run()
Animation is done in this run method. animate method awakes new thread with this run method.

Specified by:
run in interface java.lang.Runnable

stopAnimation

public void stopAnimation()
Stops currently running animation if there is one. The rest of the animation is done without delays and this method returns after current animation is done and new values are updated.


isAnimationRunning

public boolean isAnimationRunning()

animate

public boolean animate(RunInfo info)
This method produces an animation of a command based on the information in the RunInfo parameter. Animation is set to run only if there is no animation currently running.

Parameters:
info - A RunInfo to base the animation on.
Returns:
Returns false, if there is already an animation running.

init

public void init(TTK91Cpu cpu,
                 int baseValue,
                 int limitValue)
Initalizes animation.

Parameters:
cpu - A TTK91Cpu, giving the start values of the registers.
baseValue - Value of the BASE register in MMU.
limitValue - Value of the LIMIT register in MMU.

setAnimationDelay

public void setAnimationDelay(int delay)
Sets animation delay.

Parameters:
delay - Delay between frames in milliseconds.

animateAnEvent

private void animateAnEvent(int from,
                            int to,
                            int newValue)
This method animates one event like "move 7 from R1 to In2 in ALU using the bus in between" The building block of a more complex operations like "STORE R1, 100" where one needs to fetch an instruction, decipher it etc.

Parameters:
from - From where does the value come from.
to - Where is the value going to be transported.
newValue - New value replaces the old value in destination.

animateAnEvent

private void animateAnEvent(int from,
                            int to)

pause

private void pause()

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
Throws:
java.io.IOException