ソースを参照

add view for combined layout

Kolja Strohm 6 年 前
コミット
b275993170

+ 2 - 1
src/Algorithms/Animated/BK/ExtremalLayoutCalc.java

@@ -14,7 +14,8 @@ public class ExtremalLayoutCalc implements AlgorithmStage {
 		TOP_BOTTOM_LEFT,
 		TOP_BOTTOM_RIGHT,
 		BOTTOM_TOP_LEFT,
-		BOTTOM_TOP_RIGHT
+		BOTTOM_TOP_RIGHT,
+		COMBINED
 	}
 	
 	private enum LayoutState

+ 19 - 3
src/Model/LayeredEdge.java

@@ -34,9 +34,9 @@ public class LayeredEdge implements LayeredGraphEdge {
         this.graph = graph;
         reversed = false;
         dummy = false;
-        bindPoints = new ArrayList[ 4 ];
-        conflicted = new boolean[ 4 ];
-        for( int i = 0; i < 4; i++ )
+        bindPoints = new ArrayList[ 5 ];
+        conflicted = new boolean[ 5 ];
+        for( int i = 0; i < 5; i++ )
             bindPoints[ i ] = new ArrayList<>();
         for( ArrayList<Point> bps : bindPoints )
         {
@@ -56,6 +56,8 @@ public class LayeredEdge implements LayeredGraphEdge {
             return conflicted[ 2 ];
         if( layout == LayoutType.BOTTOM_TOP_RIGHT )
             return conflicted[ 3 ];
+        if( layout == LayoutType.COMBINED )
+            return conflicted[ 4 ];
         return false;
     }
     
@@ -92,6 +94,7 @@ public class LayeredEdge implements LayeredGraphEdge {
             this.conflicted[ 1 ] = conflicted;
             this.conflicted[ 2 ] = conflicted;
             this.conflicted[ 3 ] = conflicted;
+            this.conflicted[ 4 ] = conflicted;
         }
         if( layout == LayoutType.TOP_BOTTOM_LEFT )
             this.conflicted[ 0 ] = conflicted;
@@ -101,6 +104,8 @@ public class LayeredEdge implements LayeredGraphEdge {
             this.conflicted[ 2 ] = conflicted;
         if( layout == LayoutType.BOTTOM_TOP_RIGHT )
             this.conflicted[ 3 ] = conflicted;
+        if( layout == LayoutType.COMBINED )
+            this.conflicted[ 4 ] = conflicted;
     }
     
     @Override
@@ -112,6 +117,7 @@ public class LayeredEdge implements LayeredGraphEdge {
             bindPoints[ 1 ].set( 0, new Point( x, y ) );
             bindPoints[ 2 ].set( 0, new Point( x, y ) );
             bindPoints[ 3 ].set( 0, new Point( x, y ) );
+            bindPoints[ 4 ].set( 0, new Point( x, y ) );
         }
         if( layout == LayoutType.TOP_BOTTOM_LEFT )
             bindPoints[ 0 ].set( 0, new Point( x, y ) );
@@ -121,6 +127,8 @@ public class LayeredEdge implements LayeredGraphEdge {
             bindPoints[ 2 ].set( 0, new Point( x, y ) );
         if( layout == LayoutType.BOTTOM_TOP_RIGHT )
             bindPoints[ 3 ].set( 0, new Point( x, y ) );
+        if( layout == LayoutType.COMBINED )
+            bindPoints[ 4 ].set( 0, new Point( x, y ) );
     }
     
     @Override
@@ -132,6 +140,7 @@ public class LayeredEdge implements LayeredGraphEdge {
             bindPoints[ 1 ].add( bindPoints[ 1 ].size() - 1, new Point( x, y ) );
             bindPoints[ 2 ].add( bindPoints[ 2 ].size() - 1, new Point( x, y ) );
             bindPoints[ 3 ].add( bindPoints[ 3 ].size() - 1, new Point( x, y ) );
+            bindPoints[ 4 ].add( bindPoints[ 4 ].size() - 1, new Point( x, y ) );
         }
         if( layout == LayoutType.TOP_BOTTOM_LEFT )
             bindPoints[ 0 ].add( bindPoints[ 0 ].size() - 1, new Point( x, y ) );
@@ -141,6 +150,8 @@ public class LayeredEdge implements LayeredGraphEdge {
             bindPoints[ 2 ].add( bindPoints[ 2 ].size() - 1, new Point( x, y ) );
         if( layout == LayoutType.BOTTOM_TOP_RIGHT )
             bindPoints[ 3 ].add( bindPoints[ 3 ].size() - 1, new Point( x, y ) );
+        if( layout == LayoutType.COMBINED )
+            bindPoints[ 4 ].add( bindPoints[ 4 ].size() - 1, new Point( x, y ) );
     }
     
     @Override
@@ -152,6 +163,7 @@ public class LayeredEdge implements LayeredGraphEdge {
             bindPoints[ 1 ].set( bindPoints[ 1 ].size() - 1, new Point( x, y ) );
             bindPoints[ 2 ].set( bindPoints[ 2 ].size() - 1, new Point( x, y ) );
             bindPoints[ 3 ].set( bindPoints[ 3 ].size() - 1, new Point( x, y ) );
+            bindPoints[ 4 ].set( bindPoints[ 4 ].size() - 1, new Point( x, y ) );
         }
         if( layout == LayoutType.TOP_BOTTOM_LEFT )
             bindPoints[ 0 ].set( bindPoints[ 0 ].size() - 1, new Point( x, y ) );
@@ -161,6 +173,8 @@ public class LayeredEdge implements LayeredGraphEdge {
             bindPoints[ 2 ].set( bindPoints[ 2 ].size() - 1, new Point( x, y ) );
         if( layout == LayoutType.BOTTOM_TOP_RIGHT )
             bindPoints[ 3 ].set( bindPoints[ 3 ].size() - 1, new Point( x, y ) );
+        if( layout == LayoutType.COMBINED )
+            bindPoints[ 4 ].set( bindPoints[ 4 ].size() - 1, new Point( x, y ) );
     }
 
     @Override
@@ -182,6 +196,8 @@ public class LayeredEdge implements LayeredGraphEdge {
             return bindPoints[ 2 ];
         if( layout == LayoutType.BOTTOM_TOP_RIGHT )
             return bindPoints[ 3 ];
+        if( layout == LayoutType.COMBINED )
+            return bindPoints[ 4 ];
         return null;
     }
     

+ 60 - 1
src/Model/LayeredNode.java

@@ -42,8 +42,19 @@ public class LayeredNode implements LayeredGraphNode {
         public LayeredGraphNode sink;
         public double shift;
     }
-    LayoutInfo[] layouts;
     
+    private class CombinedLayoutInfo
+    {
+        public double x;
+        public double y;
+        public double w;
+        public double h;
+        public Color color;
+        public boolean selected;
+    }
+    
+    LayoutInfo[] layouts;
+    CombinedLayoutInfo combined;
     String name;
     
     // for subgraph in this node
@@ -78,6 +89,16 @@ public class LayeredNode implements LayeredGraphNode {
             l.xUndef = true;
         }
         dummy = false;
+        combined = new CombinedLayoutInfo();
+        if( original != null )
+        {
+	        combined.x = original.getX();
+	        combined.y = original.getX();
+	        combined.w = original.getWidth();
+	        combined.h = original.getHeight();
+        }
+        combined.color = null;
+        combined.selected = false;
     }
     
     @Override
@@ -261,6 +282,7 @@ public class LayeredNode implements LayeredGraphNode {
             this.layouts[ 1 ].selected = true;
             this.layouts[ 2 ].selected = true;
             this.layouts[ 3 ].selected = true;
+            combined.selected = true;
         }
         if( layout == LayoutType.TOP_BOTTOM_LEFT )
             this.layouts[ 0 ].selected = true;
@@ -270,6 +292,8 @@ public class LayeredNode implements LayeredGraphNode {
             this.layouts[ 2 ].selected = true;
         if( layout == LayoutType.BOTTOM_TOP_RIGHT )
             this.layouts[ 3 ].selected = true;
+        if( layout == LayoutType.COMBINED )
+        	combined.selected = true;
     	update();
     }
 
@@ -300,6 +324,12 @@ public class LayeredNode implements LayeredGraphNode {
             layouts[ 3 ].selected = false;
             return tmp;
         }
+        if( layout == LayoutType.COMBINED )
+        {
+            boolean tmp = combined.selected;
+            combined.selected = false;
+            return tmp;
+        }
         return false;
     }
     
@@ -312,6 +342,7 @@ public class LayeredNode implements LayeredGraphNode {
             this.layouts[ 1 ].color = c;
             this.layouts[ 2 ].color = c;
             this.layouts[ 3 ].color = c;
+            combined.color = c;
         }
         if( layout == LayoutType.TOP_BOTTOM_LEFT )
             this.layouts[ 0 ].color = c;
@@ -321,6 +352,8 @@ public class LayeredNode implements LayeredGraphNode {
             this.layouts[ 2 ].color = c;
         if( layout == LayoutType.BOTTOM_TOP_RIGHT )
             this.layouts[ 3 ].color = c;
+        if( layout == LayoutType.COMBINED )
+            combined.color = c;
     }
     
     @Override
@@ -334,6 +367,8 @@ public class LayeredNode implements LayeredGraphNode {
             return this.layouts[ 2 ].color;
         if( layout == LayoutType.BOTTOM_TOP_RIGHT )
             return this.layouts[ 3 ].color;
+        if( layout == LayoutType.COMBINED )
+            return combined.color;
         return null;
     }
     
@@ -381,6 +416,7 @@ public class LayeredNode implements LayeredGraphNode {
             layouts[ 1 ].x = x;
             layouts[ 2 ].x = x;
             layouts[ 3 ].x = x;
+            combined.x = x;
         }
         if( layout == LayoutType.TOP_BOTTOM_LEFT )
         {
@@ -402,6 +438,8 @@ public class LayeredNode implements LayeredGraphNode {
             layouts[ 3 ].xUndef = !def;
             layouts[ 3 ].x = x;
         }
+        if( layout == LayoutType.COMBINED )
+            combined.x = x;
     }
 
     @Override
@@ -412,6 +450,7 @@ public class LayeredNode implements LayeredGraphNode {
             layouts[ 1 ].y = y;
             layouts[ 2 ].y = y;
             layouts[ 3 ].y = y;
+            combined.y = y;
         }
         if( layout == LayoutType.TOP_BOTTOM_LEFT )
             layouts[ 0 ].y = y;
@@ -421,6 +460,8 @@ public class LayeredNode implements LayeredGraphNode {
             layouts[ 2 ].y = y;
         if( layout == LayoutType.BOTTOM_TOP_RIGHT )
             layouts[ 3 ].y = y;
+        if( layout == LayoutType.COMBINED )
+            combined.y = y;
     }
 
     @Override
@@ -433,6 +474,8 @@ public class LayeredNode implements LayeredGraphNode {
             return this.layouts[ 2 ].x;
         if( layout == LayoutType.BOTTOM_TOP_RIGHT )
             return this.layouts[ 3 ].x;
+        if( layout == LayoutType.COMBINED )
+            return combined.x;
         return 0;
     }
 
@@ -446,6 +489,8 @@ public class LayeredNode implements LayeredGraphNode {
             return this.layouts[ 2 ].y;
         if( layout == LayoutType.BOTTOM_TOP_RIGHT )
             return this.layouts[ 3 ].y;
+        if( layout == LayoutType.COMBINED )
+            return combined.y;
         return 0;
     }
 
@@ -469,6 +514,8 @@ public class LayeredNode implements LayeredGraphNode {
                 return Math.max( max - min, layouts[ 2 ].w );
             if( layout == LayoutType.BOTTOM_TOP_RIGHT )
                 return Math.max( max - min, layouts[ 3 ].w );
+            if( layout == LayoutType.COMBINED )
+                return Math.max( max - min, combined.w );
         }
         if( layout == LayoutType.TOP_BOTTOM_LEFT )
             return layouts[ 0 ].w;
@@ -478,6 +525,8 @@ public class LayeredNode implements LayeredGraphNode {
             return layouts[ 2 ].w;
         if( layout == LayoutType.BOTTOM_TOP_RIGHT )
             return layouts[ 3 ].w;
+        if( layout == LayoutType.COMBINED )
+            return combined.w;
         return 0;
     }
 
@@ -499,6 +548,8 @@ public class LayeredNode implements LayeredGraphNode {
                 return Math.max( max, layouts[ 2 ].h );
             if( layout == LayoutType.BOTTOM_TOP_RIGHT )
                 return Math.max( max, layouts[ 3 ].h );
+            if( layout == LayoutType.COMBINED )
+                return Math.max( max, combined.h );
         }
         if( layout == LayoutType.TOP_BOTTOM_LEFT )
             return layouts[ 0 ].h;
@@ -508,6 +559,8 @@ public class LayeredNode implements LayeredGraphNode {
             return layouts[ 2 ].h;
         if( layout == LayoutType.BOTTOM_TOP_RIGHT )
             return layouts[ 3 ].h;
+        if( layout == LayoutType.COMBINED )
+            return combined.h;
         return 0;
     }
     
@@ -520,6 +573,7 @@ public class LayeredNode implements LayeredGraphNode {
             this.layouts[ 1 ].w = w;
             this.layouts[ 2 ].w = w;
             this.layouts[ 3 ].w = w;
+            combined.w = w;
         }
         if( layout == LayoutType.TOP_BOTTOM_LEFT )
             this.layouts[ 0 ].w = w;
@@ -529,6 +583,8 @@ public class LayeredNode implements LayeredGraphNode {
             this.layouts[ 2 ].w = w;
         if( layout == LayoutType.BOTTOM_TOP_RIGHT )
             this.layouts[ 3 ].w = w;
+        if( layout == LayoutType.COMBINED )
+            combined.w = w;
     }
     
     @Override
@@ -540,6 +596,7 @@ public class LayeredNode implements LayeredGraphNode {
             this.layouts[ 1 ].h = h;
             this.layouts[ 2 ].h = h;
             this.layouts[ 3 ].h = h;
+            combined.h = h;
         }
         if( layout == LayoutType.TOP_BOTTOM_LEFT )
             this.layouts[ 0 ].h = h;
@@ -549,6 +606,8 @@ public class LayeredNode implements LayeredGraphNode {
             this.layouts[ 2 ].h = h;
         if( layout == LayoutType.BOTTOM_TOP_RIGHT )
             this.layouts[ 3 ].h = h;
+        if( layout == LayoutType.COMBINED )
+            combined.h = h;
     }
 
     @Override

+ 28 - 5
src/View/MainView.java

@@ -1,10 +1,16 @@
 package View;
 
+import java.awt.Component;
 import java.awt.GridLayout;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
 import java.awt.event.KeyEvent;
 import java.awt.event.KeyListener;
 
+import javax.swing.JButton;
 import javax.swing.JFrame;
+import javax.swing.JLayeredPane;
+import javax.swing.JPanel;
 
 import Algorithms.Animated.Action;
 import Algorithms.Animated.AnimationController;
@@ -123,13 +129,30 @@ public class MainView {
 		    
 		});
 		
-		frame.setLayout(new GridLayout( 2, 2, 10, 10 ));
-		frame.add(createNodeView( graph, LayoutType.TOP_BOTTOM_LEFT ));
-        frame.add(createNodeView( graph, LayoutType.TOP_BOTTOM_RIGHT ));
-        frame.add(createNodeView( graph, LayoutType.BOTTOM_TOP_LEFT ));
-        frame.add(createNodeView( graph, LayoutType.BOTTOM_TOP_RIGHT ));
+		JLayeredPane layne = new JLayeredPane();
+		JPanel pl = new JPanel();
+		pl.setLayout(new GridLayout( 2, 2, 500, 500 ) );
+		pl.setLocation( 0, 0 );
+		pl.setSize( frame.getSize() );
+		pl.add(createNodeView( graph, LayoutType.TOP_BOTTOM_LEFT ));
+		pl.add(createNodeView( graph, LayoutType.TOP_BOTTOM_RIGHT ));
+		pl.add(createNodeView( graph, LayoutType.BOTTOM_TOP_LEFT ));
+		pl.add(createNodeView( graph, LayoutType.BOTTOM_TOP_RIGHT ));
+		layne.add( pl, 1 );
+		NodeView combined = createNodeView( graph, LayoutType.COMBINED );
+		combined.setSize( 500, 500 );
+		layne.add( combined, 0 );
+		frame.add( layne );
 		frame.validate();
 		frame.repaint();
+		
+		frame.addComponentListener(new ComponentAdapter() 
+		{  
+	        public void componentResized(ComponentEvent evt) {
+	    		pl.setSize( layne.getSize() );
+	    		combined.setLocation( layne.getWidth() / 2 - combined.getWidth() / 2, layne.getHeight() / 2 - combined.getHeight() / 2 );
+	        }
+		});
 		new BKNodePlacement( controller, graph );
 	}
 	

+ 1 - 1
src/View/NodeView.java

@@ -86,7 +86,7 @@ public class NodeView extends JPanel {
 		Border linebor = BorderFactory.createLineBorder(model.getColor( layout ), 5);
 		if( model.getRoot( layout ) != model || model.getContainedNodes().size() != 0  )
 			linebor.paintBorder( this, g2, 0, 0, (int)model.getWidth( layout )-1, (int)model.getHeight( layout )-1 );
-		if( model.getRoot( layout ).getSink( layout ).getColor( layout ) != model.getColor( layout ))
+		if( layout != LayoutType.COMBINED && model.getRoot( layout ).getSink( layout ).getColor( layout ) != model.getColor( layout ))
 		{
     		g.setColor( model.getRoot( layout ).getSink( layout ).getColor( layout ) );
     		if( model.getContainedNodes().size() == 0 )