Просмотр исходного кода

work on javadoc and do some refactoring

Eren Yilmaz 6 лет назад
Родитель
Сommit
a66a016d26

+ 43 - 7
src/animation/AlgorithmStage.java

@@ -7,6 +7,7 @@ import bk.BlockCalc;
 /**
  * Represents a specific stage of the algorithm.
  * Example calculating the blocks, see {@link BlockCalc}.
+ * Each of those stages also has an associated {@link PseudoCodeNode}, i.e., a line of pseudocode.
  * 
  * @author kolja
  *
@@ -25,28 +26,63 @@ public interface AlgorithmStage {
     }
 
     /**
-     * perform one atomic step of the algorithm
-     * @return whether the whole stage is finished.
-     * For example if all steps are reverted, then {@code FINISHED} is returned.
+     * Perform one atomic step of the algorithm. Stops at the end of the program.
+     * @return whether the whole stage is finished (afterwards).
+     * For example if all steps are finished, then {@code FINISHED} is returned.
      */
     public StageStatus forwardStep();
 
+    /**
+     * Perform steps until the next line of code on the same level of indentation as this line
+     * is reached. Stops at the end of the program.
+     * @return whether the whole stage is finished (afterwards).
+     * For example if all steps are finished, then {@code FINISHED} is returned.
+     */
     public StageStatus forwardStepOver();
 
+    /**
+     * Perform steps until the next line of code on the level of indentation above this lines 
+     * level is reached. Stops at the end of the program.
+     * @return whether the whole stage is finished (afterwards).
+     * For example if all steps are finished, then {@code FINISHED} is returned.
+     */
     public StageStatus forwardStepOut();
     
     /**
-     * undo one atomic step of the algorithm
-     * @return whether the whole stage is finished in backwards direction. 
-     * For example if all steps are reverted, then {@code FINISHED} is returned.
+     * Undo one atomic step of the algorithm. Stops at the beginning of the program.
+     * @return whether the whole stage is finished in backwards direction (afterwards).
+     * For example if all steps have been reverted, then {@code FINISHED} is returned.
      */
     public StageStatus backwardStep();
 
+    /**
+     * Perform backward steps until the previous line of code on the same level of indentation 
+     * as this line is reached. Stops at the end of the program.
+     * @return whether the whole stage is finished in backwards direction (afterwards).
+     * For example if all steps have been reverted, then {@code FINISHED} is returned.
+     */
     public StageStatus backwardStepOver();
-    
+
+
+    /**
+     * Perform backward steps until the previous line of code on the level of indentation above 
+     * this lines level is reached. Stops at the end of the program.
+     * @return whether the whole stage is finished in backwards direction (afterwards).
+     * For example if all steps have been reverted, then {@code FINISHED} is returned.
+     */
     public StageStatus backwardStepOut();
 
+    /**
+     * Creates a {@link PseudoCodeNode}, i.e., a line of pseudocode that resembles this Stage.
+     * @param tree The {@link JTree} where the node should be inserted.
+     * @return The node.
+     */
     public PseudoCodeNode createPseudocodeTree( JTree tree );
     
+    /**
+     * Writes the state of the variables used in this stage to a pretty table.
+     * This table should also render nicely if interpreted as markdown. 
+     * @return the table
+     */
     public String getDebugString();
 }

+ 2 - 3
src/animation/AnimatedAlgorithm.java

@@ -81,8 +81,7 @@ public abstract class AnimatedAlgorithm extends Thread implements AlgorithmStage
 
         }
     }
-    /**
-     * creates a node in the pseudo code tree
-     */
+
+    @Override
     public abstract PseudoCodeNode createPseudocodeTree( JTree tree );
 }

+ 37 - 8
src/animation/AnimationController.java

@@ -1,20 +1,31 @@
 package animation;
 
 public class AnimationController {
+    public static final int DEFAULT_DELAY = 100;
 
     private Action next;
     private boolean continuous;
     private long lastTime;
-    private long timeBetween;
+    private long delay;
 
     public AnimationController()
     {
         next = null;
         continuous = false;
         lastTime = 0;
-        timeBetween = 0;
+        delay = DEFAULT_DELAY;
     }
-
+    
+    /**
+     * Ask the controller, which kind of action should be done next.
+     * The controller waits until it knows this for sure.
+     * @return The action.
+     * @throws  InterruptedException if any thread interrupted the
+     *             current thread before or while the current thread
+     *             was waiting for a notification.  The <i>interrupted
+     *             status</i> of the current thread is cleared when
+     *             this exception is thrown.
+     */
     public Action getNextAction() throws InterruptedException
     {
         long old = lastTime;
@@ -29,26 +40,40 @@ public class AnimationController {
             next = null;
         else
         {
-            if( lastTime - old < timeBetween )
+            if( lastTime - old < delay )
             {
-                Thread.sleep( timeBetween - ( lastTime - old ) );
-                System.out.println( "sleep: " + ( timeBetween - ( lastTime - old ) ) );
+                Thread.sleep( delay - ( lastTime - old ) );
+                System.out.println( "sleep: " + ( delay - ( lastTime - old ) ) );
                 lastTime = System.currentTimeMillis();
             }
         }
         return ret;
     }
 
+    /**
+     * activates or deactivates automatic execution
+     * @param c automatic execution will be activated if c is true
+     * and deactivated otherwise
+     */
     public void setContinuous( boolean c )
     {
         this.continuous = c;
     }
 
-    public void setTimeBetween( long between )
+    /**
+     * sets the delay of the automatic execution.
+     * You might also want to enable it by calling setContinuous()
+     * @param delay the delay in milliseconds
+     */
+    public void setDelay( long delay )
     {
-        timeBetween = between;
+        this.delay = delay;
     }
 
+    /**
+     * sets the next action and wakes up one thread waiting for an answer of the controller.
+     * @param a
+     */
     public void setNextAction( Action a )
     {
         next = a;
@@ -57,6 +82,10 @@ public class AnimationController {
         }
     }
 
+    /**
+     * checks if automatic execution is active
+     * @return true if it is
+     */
     public boolean isContinuous()
     {
         return continuous;

+ 4 - 6
src/view/MainView.java

@@ -60,7 +60,6 @@ import lib.TextLayoutHelper;
  *
  */
 public class MainView {    
-    private static final int DEFAULT_DELAY = 100;
     /**
      * The 'frame' of the main window.
      * The reason why there can only be one instance of this class.
@@ -157,7 +156,6 @@ public class MainView {
         frameCounter++;
         this.graph = graph;
         controller = new AnimationController();
-        controller.setTimeBetween( DEFAULT_DELAY );
         frame = new JFrame( "NodeShuffler" );
         frame.addWindowListener(new java.awt.event.WindowAdapter() {
             @Override
@@ -599,7 +597,7 @@ public class MainView {
         });
         delayText = new JLabel( "Delay (ms)" );
         delayText.setBounds( 260, 10, 80, 20 );
-        delay = new JTextField( String.valueOf(DEFAULT_DELAY) );
+        delay = new JTextField( String.valueOf(AnimationController.DEFAULT_DELAY) );
         delay.setBounds( 260, 30, 90, 20 );
         delay.getDocument().addDocumentListener( new DocumentListener() {
 
@@ -607,7 +605,7 @@ public class MainView {
             public void insertUpdate(DocumentEvent e) {
                 try
                 {
-                    controller.setTimeBetween( Integer.parseInt( delay.getText() ) );
+                    controller.setDelay( Integer.parseInt( delay.getText() ) );
                     delay.setBackground( Color.WHITE );
                 } catch( Exception e1 )
                 {
@@ -619,7 +617,7 @@ public class MainView {
             public void removeUpdate(DocumentEvent e) {
                 try
                 {
-                    controller.setTimeBetween( Integer.parseInt( delay.getText() ) );
+                    controller.setDelay( Integer.parseInt( delay.getText() ) );
                     delay.setBackground( Color.WHITE );
                 } catch( Exception e1 )
                 {
@@ -631,7 +629,7 @@ public class MainView {
             public void changedUpdate(DocumentEvent e) {
                 try
                 {
-                    controller.setTimeBetween( Integer.parseInt( delay.getText() ) );
+                    controller.setDelay( Integer.parseInt( delay.getText() ) );
                     delay.setBackground( Color.WHITE );
                 } catch( Exception e1 )
                 {

+ 1 - 1
src/view/NiceButton.java

@@ -12,7 +12,7 @@ import javax.swing.ImageIcon;
 import javax.swing.JButton;
 
 /**
- * A {@link NiceButton} is a {@link JButton} that has an image on it.
+ * A {@link NiceButton} is a {@link JButton} that has an image on it AND looks nice.
  * @author kolja
  *
  */