Prechádzať zdrojové kódy

automatisches skallieren hinzugefügt

Kolja Strohm 6 rokov pred
rodič
commit
cdb4016c60
2 zmenil súbory, kde vykonal 12 pridanie a 5 odobranie
  1. 10 5
      src/View/MainView.java
  2. 2 0
      src/View/NodeView.java

+ 10 - 5
src/View/MainView.java

@@ -1,5 +1,6 @@
 package View;
 
+import java.awt.BorderLayout;
 import java.awt.event.KeyEvent;
 import java.awt.event.KeyListener;
 
@@ -22,7 +23,7 @@ public class MainView {
 		controller = new AnnimationController();
 		controller.setTimeBetween( 100 );
 		frame = new JFrame();
-        frame.setSize( (int)graph.getWidth() + 200, (int)graph.getHeight() + 200 );
+        frame.setSize( Math.min( (int)graph.getWidth() + 200, 1700 ), Math.min( (int)graph.getHeight() + 200, 900 ) );
 		frame.setLocation( 100, 100 );
 		frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
 		frame.setVisible( true );
@@ -59,10 +60,9 @@ public class MainView {
 		});
 		
 		NodeView view = createNodeView( graph );
-		graph.setX( 40 );
-		graph.setY( 40 );
+		frame.setLayout(new BorderLayout());
+		frame.add(view, BorderLayout.CENTER);
 		frame.add( view );
-		
 		frame.repaint();
 		new BKNodePlacement( controller, graph );
 	}
@@ -70,6 +70,7 @@ public class MainView {
 	private NodeView createNodeView( LayeredGraphNode gNode )
 	{
 		NodeView graphView = new NodeView( gNode );
+		graphView.setLayout( null );
 		graphView.setOpaque( true );
         for( LayeredGraphEdge e : gNode.getContainedEdges() )
         {
@@ -78,7 +79,11 @@ public class MainView {
             graphView.add( ev );
         }
 		for( LayeredGraphNode n : gNode.getContainedNodes() )
-			graphView.add( createNodeView( n ) );
+		{
+		    NodeView nv = createNodeView( n );
+		    nv.setBounds( nv.getX(), nv.getY(), nv.getWidth(), nv.getHeight() );
+			graphView.add( nv );
+		}
 		return graphView;
 	}
 }

+ 2 - 0
src/View/NodeView.java

@@ -50,6 +50,8 @@ public class NodeView extends JPanel {
     @Override
     public void paint( Graphics g )
     {
+        double scale = Math.min( super.getWidth() / (double)getWidth(), super.getHeight() / (double)getHeight());
+        ((Graphics2D)g).scale( scale, scale );
         paintComponent( g );
         for( Component c : getComponents() )
             c.paint( g.create(