Procházet zdrojové kódy

Debug menu ist jetzt aktiv

Kolja Strohm před 7 roky
rodič
revize
5159b68668

+ 5 - 1
src/animation/Action.java

@@ -10,5 +10,9 @@ package animation;
  */
 public enum Action {
 	FORWARD,
-	BACKWARD
+	FORWARD_OVER,
+	FORWARD_OUT,
+	BACKWARD,
+	BACKWARD_OVER,
+	BACKWARD_OUT
 }

+ 0 - 2
src/animation/AlgorithmStage.java

@@ -1,7 +1,5 @@
 package animation;
 
-import javax.swing.tree.DefaultMutableTreeNode;
-
 import bk.BlockCalc;
 
 /**

+ 10 - 2
src/animation/AnimatedAlgorithm.java

@@ -1,7 +1,5 @@
 package animation;
 
-import javax.swing.tree.DefaultMutableTreeNode;
-
 import graph.LayeredGraphNode;
 
 public abstract class AnimatedAlgorithm extends Thread implements AlgorithmStage {
@@ -27,10 +25,20 @@ public abstract class AnimatedAlgorithm extends Thread implements AlgorithmStage
 					System.out.println( "FORWARD" );
 					forwardStep();
 					break;
+                case FORWARD_OUT:
+                    break;
+                case FORWARD_OVER:
+                    break;
 				case BACKWARD:
 					System.out.println( "BACKWARD" );
 					backwardStep();
 					break;
+                case BACKWARD_OUT:
+                    break;
+                case BACKWARD_OVER:
+                    break;
+                default:
+                    break;
 				}
 			} catch (InterruptedException e) {
 				e.printStackTrace();

+ 0 - 28
src/view/DebugView.java

@@ -1,28 +0,0 @@
-package view;
-
-import javax.swing.JButton;
-import javax.swing.JPanel;
-
-public class DebugView extends JPanel {
-
-    /**
-     * 
-     */
-    private static final long serialVersionUID = 1L;
-
-    private JButton stepForward;
-    private JButton stepForwardInto;
-    private JButton stepForwardOut;
-    private JButton stepBackward;
-    private JButton stepBackwardInto;
-    private JButton stepBackwardOut;
-    private JButton runForward;
-    private JButton runBackward;
-    private JButton pause;
-    private JButton generateRandom;
-    
-    DebugView()
-    {
-        
-    }
-}

+ 141 - 10
src/view/MainView.java

@@ -1,16 +1,16 @@
 package view;
 
 import java.awt.BorderLayout;
+import java.awt.Color;
 import java.awt.Dimension;
 import java.awt.GridLayout;
-import java.awt.Image;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
 import java.awt.event.ComponentAdapter;
 import java.awt.event.ComponentEvent;
 import java.awt.event.KeyEvent;
 import java.awt.event.KeyListener;
-import java.net.URL;
 
-import javax.swing.ImageIcon;
 import javax.swing.JButton;
 import javax.swing.JFrame;
 import javax.swing.JLabel;
@@ -19,7 +19,8 @@ import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.JTextField;
 import javax.swing.JTree;
-import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
 
 import animation.Action;
 import animation.AnimationController;
@@ -75,34 +76,164 @@ public class MainView {
 	 */
 	public MainView( LayeredGraphNode graph )
 	{
+        controller = new AnimationController();
+        controller.setTimeBetween( 50 );
+        BKNodePlacement algorithm = new BKNodePlacement( controller, graph );
+        
+        // Create Menu GUI
 	    stepForward = new NiceButton( "stepForward" );
 	    stepForward.setLocation( 10, 10 );
+	    stepForward.addActionListener( new ActionListener() {
+
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                controller.setContinuous( false );
+                controller.setNextAction( Action.FORWARD_OVER );
+            }
+            
+        });
 	    stepForwardInto = new NiceButton( "stepForwardInto" );
 	    stepForwardInto.setLocation( 60, 10 );
+	    stepForwardInto.addActionListener( new ActionListener() {
+
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                controller.setContinuous( false );
+                controller.setNextAction( Action.FORWARD );
+            }
+            
+        });
         stepForwardOut = new NiceButton( "stepForwardOut" );
         stepForwardOut.setLocation( 110, 10 );
+        stepForwardOut.addActionListener( new ActionListener() {
+
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                controller.setContinuous( false );
+                controller.setNextAction( Action.FORWARD_OUT );
+            }
+            
+        });
         runForward = new NiceButton( "runForward" );
         runForward.setLocation( 160, 10 );
+        runForward.addActionListener( new ActionListener() {
+
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                controller.setContinuous( true );
+                controller.setNextAction( Action.FORWARD );
+            }
+            
+        });
         runBackward = new NiceButton( "runBackward" );
         runBackward.setLocation( 160, 60 );
+        runBackward.addActionListener( new ActionListener() {
+
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                controller.setContinuous( true );
+                controller.setNextAction( Action.BACKWARD );
+            }
+            
+        });
         stepBackward = new NiceButton( "stepBackward" );
         stepBackward.setLocation( 10, 60 );
-        //stepBackwardInto = new NiceButton( "" );
-        //stepBackwardInto.setLocation( 60, 60 );
+        stepBackward.addActionListener( new ActionListener() {
+
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                controller.setContinuous( false );
+                controller.setNextAction( Action.BACKWARD_OVER );
+            }
+            
+        });
+        stepBackwardInto = new NiceButton( "stepBackwardInto" );
+        stepBackwardInto.setLocation( 60, 60 );
+        stepBackwardInto.addActionListener( new ActionListener() {
+
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                controller.setContinuous( false );
+                controller.setNextAction( Action.BACKWARD );
+            }
+            
+        });
         stepBackwardOut = new NiceButton( "stepBackwardOut" );
         stepBackwardOut.setLocation( 110, 60 );
+        stepBackwardOut.addActionListener( new ActionListener() {
+
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                controller.setContinuous( false );
+                controller.setNextAction( Action.BACKWARD_OUT );
+            }
+            
+        });
         pause = new NiceButton( "pause" );
         pause.setLocation( 210, 10 );
+        pause.addActionListener( new ActionListener() {
+
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                controller.setContinuous( false );
+            }
+            
+        });
         debug = new NiceButton( "debug" );
         debug.setLocation( 350, 10 );
+        generateRandom = new NiceButton( "generateRandom" );
+        generateRandom.setLocation( 350, 60 );
+        generateRandom.addActionListener( new ActionListener() {
+
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                
+            }
+            
+        });
         delayText = new JLabel( "Delay (ms)" );
         delayText.setBounds( 260, 10, 80, 20 );
         delay = new JTextField( "50" );
         delay.setBounds( 260, 30, 80, 20 );
-	    
-		controller = new AnimationController();
-		controller.setTimeBetween( 50 );
-        BKNodePlacement algorithm = new BKNodePlacement( controller, graph );
+        delay.getDocument().addDocumentListener( new DocumentListener() {
+
+            @Override
+            public void insertUpdate(DocumentEvent e) {
+                try
+                {
+                    controller.setTimeBetween( Integer.parseInt( delay.getText() ) );
+                    delay.setBackground( Color.WHITE );
+                } catch( Exception e1 )
+                {
+                    delay.setBackground( Color.RED );
+                }
+            }
+
+            @Override
+            public void removeUpdate(DocumentEvent e) {
+                try
+                {
+                    controller.setTimeBetween( Integer.parseInt( delay.getText() ) );
+                    delay.setBackground( Color.WHITE );
+                } catch( Exception e1 )
+                {
+                    delay.setBackground( Color.RED );
+                }
+            }
+
+            @Override
+            public void changedUpdate(DocumentEvent e) {
+                try
+                {
+                    controller.setTimeBetween( Integer.parseInt( delay.getText() ) );
+                    delay.setBackground( Color.WHITE );
+                } catch( Exception e1 )
+                {
+                    delay.setBackground( Color.RED );
+                }
+            }
+            
+        });
         pseudoTree = new JTree( algorithm.createPseudocodeTree() );
         pseudoTree.setEnabled( false );
         pseudoTree.setCellRenderer( new PseudoCodeRenderer() );

+ 1 - 1
src/view/NiceButton.java

@@ -23,7 +23,7 @@ public class NiceButton extends JButton implements MouseListener {
     
     public NiceButton( String name )
     {
-        super( makeColorTransparent( new ImageIcon( NiceButton.class.getResource( "../images/" + name + ".png" ) ).getImage().getScaledInstance( 40, 40, Image.SCALE_AREA_AVERAGING ), Color.WHITE, 0 ) );
+        super( NiceButton.class.getResource( "../images/" + name + ".png" ) != null ? makeColorTransparent( new ImageIcon( NiceButton.class.getResource( "../images/" + name + ".png" ) ).getImage().getScaledInstance( 40, 40, Image.SCALE_AREA_AVERAGING ), Color.WHITE, 0 ) : new ImageIcon() );
         setSize( 40, 40 );
         addMouseListener( this );
         setBorderPainted( false );