|
@@ -14,7 +14,6 @@ import java.awt.event.ComponentEvent;
|
|
|
import java.awt.event.FocusEvent;
|
|
|
import java.awt.event.FocusListener;
|
|
|
import java.awt.event.KeyEvent;
|
|
|
-import java.awt.event.KeyListener;
|
|
|
|
|
|
import javax.swing.JButton;
|
|
|
import javax.swing.JDialog;
|
|
@@ -28,6 +27,7 @@ import javax.swing.JTextField;
|
|
|
import javax.swing.JTree;
|
|
|
import javax.swing.event.DocumentEvent;
|
|
|
import javax.swing.event.DocumentListener;
|
|
|
+import javax.swing.tree.DefaultTreeModel;
|
|
|
|
|
|
import animation.Action;
|
|
|
import animation.AnimationController;
|
|
@@ -37,7 +37,6 @@ import graph.InitializeNodePositions;
|
|
|
import graph.LayeredGraphEdge;
|
|
|
import graph.LayeredGraphNode;
|
|
|
import graph.RandomGraphGenerator;
|
|
|
-import graph.io.Writer;
|
|
|
import lib.SweepCrossingMinimizer;
|
|
|
|
|
|
/**
|
|
@@ -52,6 +51,7 @@ public class MainView {
|
|
|
* The 'frame' of the main window.
|
|
|
* The reason why there can only be one instance of this class.
|
|
|
*/
|
|
|
+ private static int frameCounter = 0;
|
|
|
private JFrame frame;
|
|
|
private AnimationController controller;
|
|
|
private JButton stepForward;
|
|
@@ -67,7 +67,7 @@ public class MainView {
|
|
|
private JButton randomGraph;
|
|
|
private JLabel delayText;
|
|
|
private JTextField delay;
|
|
|
- public static JTree pseudoTree;
|
|
|
+ public JTree pseudoTree;
|
|
|
private LayeredGraphNode graph;
|
|
|
|
|
|
private String strToLen( String s, int l )
|
|
@@ -141,15 +141,26 @@ public class MainView {
|
|
|
*/
|
|
|
public MainView( LayeredGraphNode graph )
|
|
|
{
|
|
|
+ frameCounter++;
|
|
|
this.graph = graph;
|
|
|
controller = new AnimationController();
|
|
|
controller.setTimeBetween( 50 );
|
|
|
frame = new JFrame();
|
|
|
+ frame.addWindowListener(new java.awt.event.WindowAdapter() {
|
|
|
+ @Override
|
|
|
+ public void windowClosing(java.awt.event.WindowEvent windowEvent) {
|
|
|
+ frameCounter--;
|
|
|
+ if( frameCounter == 0 )
|
|
|
+ System.exit( 0 );
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
BKNodePlacement algorithm = new BKNodePlacement( controller, graph, frame );
|
|
|
|
|
|
// Create Menu GUI
|
|
|
stepForward = new NiceButton( "stepForward" );
|
|
|
stepForward.setLocation( 10, 10 );
|
|
|
+ stepForward.setMnemonic( KeyEvent.VK_DOWN );
|
|
|
stepForward.addActionListener( new ActionListener() {
|
|
|
|
|
|
@Override
|
|
@@ -161,6 +172,7 @@ public class MainView {
|
|
|
});
|
|
|
stepForwardInto = new NiceButton( "stepForwardInto" );
|
|
|
stepForwardInto.setLocation( 60, 10 );
|
|
|
+ stepForwardInto.setMnemonic( KeyEvent.VK_RIGHT );
|
|
|
stepForwardInto.addActionListener( new ActionListener() {
|
|
|
|
|
|
@Override
|
|
@@ -183,6 +195,7 @@ public class MainView {
|
|
|
});
|
|
|
runForward = new NiceButton( "runForward" );
|
|
|
runForward.setLocation( 160, 10 );
|
|
|
+ runForward.setMnemonic( KeyEvent.VK_P );
|
|
|
runForward.addActionListener( new ActionListener() {
|
|
|
|
|
|
@Override
|
|
@@ -194,6 +207,7 @@ public class MainView {
|
|
|
});
|
|
|
runBackward = new NiceButton( "runBackward" );
|
|
|
runBackward.setLocation( 160, 60 );
|
|
|
+ runBackward.setMnemonic( KeyEvent.VK_R );
|
|
|
runBackward.addActionListener( new ActionListener() {
|
|
|
|
|
|
@Override
|
|
@@ -205,6 +219,7 @@ public class MainView {
|
|
|
});
|
|
|
stepBackward = new NiceButton( "stepBackward" );
|
|
|
stepBackward.setLocation( 10, 60 );
|
|
|
+ stepBackward.setMnemonic( KeyEvent.VK_UP );
|
|
|
stepBackward.addActionListener( new ActionListener() {
|
|
|
|
|
|
@Override
|
|
@@ -216,6 +231,7 @@ public class MainView {
|
|
|
});
|
|
|
stepBackwardInto = new NiceButton( "stepBackwardInto" );
|
|
|
stepBackwardInto.setLocation( 60, 60 );
|
|
|
+ stepBackwardInto.setMnemonic( KeyEvent.VK_LEFT );
|
|
|
stepBackwardInto.addActionListener( new ActionListener() {
|
|
|
|
|
|
@Override
|
|
@@ -248,6 +264,7 @@ public class MainView {
|
|
|
});
|
|
|
debug = new NiceButton( "debug" );
|
|
|
debug.setLocation( 350, 10 );
|
|
|
+ debug.setMnemonic( KeyEvent.VK_D );
|
|
|
debug.addActionListener( new ActionListener() {
|
|
|
|
|
|
@Override
|
|
@@ -256,7 +273,7 @@ public class MainView {
|
|
|
}
|
|
|
|
|
|
});
|
|
|
- randomGraph = new NiceButton( "randomGraph" );
|
|
|
+ randomGraph = new NiceButton( "random" );
|
|
|
randomGraph.setLocation( 350, 60 );
|
|
|
randomGraph.addActionListener( new ActionListener() {
|
|
|
|
|
@@ -589,7 +606,8 @@ public class MainView {
|
|
|
}
|
|
|
|
|
|
});
|
|
|
- pseudoTree = new JTree( algorithm.createPseudocodeTree() );
|
|
|
+ pseudoTree = new JTree();
|
|
|
+ pseudoTree.setModel( new DefaultTreeModel( algorithm.createPseudocodeTree( pseudoTree ) ) );
|
|
|
pseudoTree.setCellRenderer( new PseudoCodeRenderer() );
|
|
|
pseudoTree.setSelectionModel( null );
|
|
|
JScrollPane treeView = new JScrollPane( pseudoTree );
|
|
@@ -597,45 +615,9 @@ public class MainView {
|
|
|
|
|
|
frame.setSize( Math.min( (int)graph.getWidth( LayoutType.TOP_BOTTOM_LEFT ) * 2 + 200, 1700 ), Math.min( (int)graph.getHeight( LayoutType.TOP_BOTTOM_LEFT ) * 2 + 200, 900 ) );
|
|
|
frame.setLocation( 100, 100 );
|
|
|
- frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
|
|
|
+ frame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
|
|
|
frame.setVisible( true );
|
|
|
|
|
|
- frame.addKeyListener( new KeyListener() {
|
|
|
-
|
|
|
- @Override
|
|
|
- public void keyTyped(KeyEvent e) {
|
|
|
- // TODO Auto-generated method stub
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void keyPressed(KeyEvent e) {
|
|
|
- if( e.getKeyCode() == KeyEvent.VK_S )
|
|
|
- {
|
|
|
- Writer w = new Writer( "save.json" );
|
|
|
- w.writeOutputGraph( graph );
|
|
|
- }
|
|
|
- if( e.getKeyCode() == KeyEvent.VK_LEFT )
|
|
|
- controller.setNextAction( Action.BACKWARD );
|
|
|
- if( e.getKeyCode() == KeyEvent.VK_RIGHT )
|
|
|
- controller.setNextAction( Action.FORWARD );
|
|
|
- if( e.getKeyCode() == KeyEvent.VK_P )
|
|
|
- controller.setContinuous( !controller.isContinuous() );
|
|
|
- frame.validate();
|
|
|
- if( e.getKeyCode() == KeyEvent.VK_D )
|
|
|
- {
|
|
|
- System.out.println( debugInfo() );
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void keyReleased(KeyEvent e) {
|
|
|
- // TODO Auto-generated method stub
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- });
|
|
|
-
|
|
|
JLayeredPane layne = new JLayeredPane();
|
|
|
JPanel pl = new JPanel();
|
|
|
GridLayout grout = new GridLayout( 2, 2, 10, 10 );
|