Ver código fonte

Knoten werden nun centriert gezeichnet

Kolja Strohm 6 anos atrás
pai
commit
7775a01483
2 arquivos alterados com 12 adições e 3 exclusões
  1. 1 0
      src/graph/LayeredNode.java
  2. 11 3
      src/view/NodeView.java

+ 1 - 0
src/graph/LayeredNode.java

@@ -71,6 +71,7 @@ public class LayeredNode implements LayeredGraphNode {
             ln.addNode( convertToLayeredGraph( node ) );
         for( ElkEdge edge : n.getContainedEdges() )
         {
+        	// TODO n.getProperty(Properties.LAYERPOS) reads position of node n in his layer
             ArrayList< LayeredGraphNode > sources = new ArrayList<>();
             ArrayList< LayeredGraphNode > targets = new ArrayList<>();
             EList<ElkConnectableShape> s = edge.getSources();

+ 11 - 3
src/view/NodeView.java

@@ -49,7 +49,15 @@ public class NodeView extends JPanel {
             return;
         double scale = Math.min( (double)super.getWidth() / (int)model.getWidth( layout ), (double)super.getHeight() / (int)model.getHeight( layout ));
         ((Graphics2D)g).scale( scale, scale );
-        paintComponent( g );
+        int x = 0;
+        int y = 0;
+        int width = (int)(super.getWidth() / scale);
+        int height = (int)(super.getHeight() / scale);
+        if( scale == (double)super.getWidth() / (int)model.getWidth( layout ) )
+        	y += (super.getHeight() - (model.getHeight( layout ) * scale )) / scale / 2;
+        if( scale == (double)super.getHeight() / (int)model.getHeight( layout ) )
+        	x += (super.getWidth() - (model.getWidth( layout ) * scale )) / scale / 2;
+        paintComponent( g.create( x, y, width, height ) );
         double minX = Double.POSITIVE_INFINITY;
         for( Component c : getComponents() )
         {
@@ -58,8 +66,8 @@ public class NodeView extends JPanel {
         for( Component c : getComponents() )
         {
             c.paint( g.create( 
-                    c.getLocation().x + 25 - (int)minX, 
-                    c.getLocation().y + 25, 
+                    c.getLocation().x + 25 - (int)minX + x, 
+                    c.getLocation().y + 25 + y, 
                     Math.min( (int)model.getWidth( layout ) - 25, c.getPreferredSize().width + Math.abs(c.getLocation().x) + 25 ), 
                     Math.min( (int)model.getHeight( layout ) - 25, c.getPreferredSize().height + Math.abs(c.getLocation().y) + 25 ) ) );
         }