Explorar o código

Display Option hinzugefügt, um zu bestimmen welche Layouts angezeigt werden sollen

Kolja Strohm %!s(int64=6) %!d(string=hai) anos
pai
achega
16e06e608c

+ 6 - 1
src/bk/BKNodePlacement.java

@@ -21,7 +21,7 @@ public class BKNodePlacement extends AnimatedAlgorithm {
      * Private data structures to store the process of the algorithm
      */
 
-    private enum State
+    public enum State
     {
         CONFLICTS,
         LAYOUT1,
@@ -55,6 +55,11 @@ public class BKNodePlacement extends AnimatedAlgorithm {
         combine = new Combine( graph );
         inside = false;
     }
+    
+    public State getAlgorithmState()
+    {
+        return state;
+    }
 
     @Override
     public StageStatus forwardStep() {

+ 105 - 2
src/view/MainView.java

@@ -75,11 +75,13 @@ public class MainView {
     private JButton load;
     private JButton save;
     private JButton debug;
+    private JButton options;
     private JButton randomGraph;
     private JLabel delayText;
     private JTextField delay;
     private JTree pseudoTree;
     private LayeredGraphNode graph;
+    private OptionsDialog optionsDialog;
 
     private String debugInfo()
     {
@@ -234,6 +236,18 @@ public class MainView {
                 controller.setNextAction( Action.BACKWARD );
             }
             
+        });
+        options = new NiceButton( "options" );
+        options.setLocation( 210, 60 );
+        options.setMnemonic( KeyEvent.VK_O );
+        options.setToolTipText( "Show Options Dialog (alt + o)" );
+        options.addActionListener( new ActionListener() {
+
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                optionsDialog.setVisible( true );
+            }
+            
         });
         stepBackward = new NiceButton( "stepBackward" );
         stepBackward.setLocation( 10, 60 );
@@ -353,7 +367,7 @@ public class MainView {
             
         });
         load = new NiceButton( "load" );
-        load.setLocation( 230, 60 );
+        load.setLocation( 260, 60 );
         load.setMnemonic( KeyEvent.VK_L );
         load.setToolTipText( "Load a graph (alt + l)" );
         load.addActionListener( new ActionListener() {
@@ -375,7 +389,7 @@ public class MainView {
             
         });
         save = new NiceButton( "save" );
-        save.setLocation( 295, 60 );
+        save.setLocation( 310, 60 );
         save.setMnemonic( KeyEvent.VK_S );
         save.setToolTipText( "Save graph (alt + s)" );
         save.addActionListener( new ActionListener() {
@@ -457,6 +471,8 @@ public class MainView {
         combined.setSize( 500, 500 );
         layne.add( combined, 0 );
         frame.add( layne );
+        //JPanel onlyCurrentLayout = new JPanel();
+        //onlyCurrentLayout.setLayout( new BorderLayout() );
         JPanel menue = new JPanel();
         menue.setLayout( null );
         menue.setPreferredSize( new Dimension( 410, 500 ) );
@@ -476,6 +492,7 @@ public class MainView {
         menue.add( randomGraph );
         menue.add( save );
         menue.add( load );
+        menue.add( options );
         menue.add( debugView );
         frame.add( menue, BorderLayout.EAST );
         frame.setSize( frame.getWidth() + 1, frame.getHeight() );
@@ -506,9 +523,95 @@ public class MainView {
                 debugText.setText( algorithm.getDebugString().trim() );
                 layne.remove( pl );
                 layne.add( pl, 1 );
+                if( optionsDialog != null && optionsDialog.getLayerDisplayOption() == 1 )
+                {
+                    pl.remove( topLeft );
+                    pl.remove( topRight );
+                    pl.remove( bottomLeft );
+                    pl.remove( bottomRight );
+                    pl.remove( combined );
+                    switch( algorithm.getAlgorithmState() )
+                    {
+                    case CONFLICTS:
+                        pl.add( topLeft );
+                        break;
+                    case LAYOUT1:
+                        pl.add( topLeft );
+                        break;
+                    case LAYOUT2:
+                        pl.add( topRight );
+                        break;
+                    case LAYOUT3:
+                        pl.add( bottomLeft );
+                        break;
+                    case LAYOUT4:
+                        pl.add( bottomRight );
+                        break;
+                    case COMBINE:
+                        pl.add( combined );
+                        break;
+                    }
+                    pl.revalidate();
+                }
                 frame.repaint();
             }
         });
+
+        optionsDialog = new OptionsDialog();
+        optionsDialog.addActionListener( new ActionListener() {
+
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                if( optionsDialog.getLayerDisplayOption() == 0 )
+                {
+                    pl.remove( topLeft );
+                    pl.remove( topRight );
+                    pl.remove( bottomLeft );
+                    pl.remove( bottomRight );
+                    pl.remove( combined );
+                    pl.setLayout( grout );
+                    pl.add( topLeft );
+                    pl.add( topRight );
+                    pl.add( bottomLeft );
+                    pl.add( bottomRight );
+                    layne.add( combined, 0 );
+                    pl.revalidate();
+                }
+                else
+                {
+                    pl.remove( topLeft );
+                    pl.remove( topRight );
+                    pl.remove( bottomLeft );
+                    pl.remove( bottomRight );
+                    layne.remove( combined );
+                    pl.setLayout( new BorderLayout() );
+                    switch( algorithm.getAlgorithmState() )
+                    {
+                    case CONFLICTS:
+                        pl.add( topLeft );
+                        break;
+                    case LAYOUT1:
+                        pl.add( topLeft );
+                        break;
+                    case LAYOUT2:
+                        pl.add( topRight );
+                        break;
+                    case LAYOUT3:
+                        pl.add( bottomLeft );
+                        break;
+                    case LAYOUT4:
+                        pl.add( bottomRight );
+                        break;
+                    case COMBINE:
+                        pl.add( combined );
+                        break;
+                    }
+                    pl.revalidate();
+                }
+                frame.repaint();
+            }
+            
+        });
         
         algorithm.start();
     }

+ 75 - 0
src/view/OptionsDialog.java

@@ -0,0 +1,75 @@
+package view;
+
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.ArrayList;
+
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+
+public class OptionsDialog extends JDialog {
+
+    private static final long serialVersionUID = 1L;
+
+    private ArrayList< ActionListener > listeners;
+    private JComboBox<String> display;
+    private JButton speichern;
+    
+    private static class Options
+    {
+        public int layoutDisplaySelection = 0;
+    }
+    
+    private Options options;
+    
+    OptionsDialog()
+    {
+        setTitle( "Optionen" );
+        setLayout( new GridLayout( 2, 2 ) );
+        add( new JLabel( "Dilspay layouts:" ) );
+        String[] displayValues = { "All", "Current" };
+        display = new JComboBox<String>( displayValues );
+        add( display );
+        add( new JLabel() );
+        speichern = new JButton( "Ok" );
+        speichern.addActionListener( new ActionListener() {
+
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                try {
+                    boolean change = options.layoutDisplaySelection != display.getSelectedIndex();
+                    options.layoutDisplaySelection = display.getSelectedIndex();
+                    if( change )
+                    {
+                        for( ActionListener l : listeners )
+                        {
+                            l.actionPerformed( new ActionEvent(this, 0, "Options changed" ) );
+                        }
+                    }
+                    setVisible( false );
+                } catch( Exception e1 )
+                {
+                    e1.printStackTrace();
+                }
+            }
+            
+        });
+        add( speichern );
+        setSize( 300, 200 );
+        listeners = new ArrayList<ActionListener>();
+        options = new Options();
+    }
+    
+    public int getLayerDisplayOption()
+    {
+        return options.layoutDisplaySelection;
+    }
+    
+    public void addActionListener( ActionListener al )
+    {
+        listeners.add( al );
+    }
+}

+ 1 - 1
src/view/RandomGraphDialog.java

@@ -34,7 +34,7 @@ public class RandomGraphDialog extends JDialog {
     private JTextField maxDepth;
     
     public RandomGraphDialog()
-    { 
+    {
         setTitle( "Generate random graph" );
         setLayout( new GridBagLayout() );
         GridBagConstraints c = new GridBagConstraints();