Răsfoiți Sursa

Tootpip informationen über die knoten in den views hinzugefügt

Kolja Strohm 6 ani în urmă
părinte
comite
84d7b6a7f3

+ 0 - 1
src/animation/AnimationController.java

@@ -45,7 +45,6 @@ public class AnimationController {
             if( lastTime - old < delay )
             {
                 Thread.sleep( delay - ( lastTime - old ) );
-                System.out.println( "sleep: " + ( delay - ( lastTime - old ) ) );
                 lastTime = System.currentTimeMillis();
             }
         }

+ 1 - 1
src/main/Main.java

@@ -17,7 +17,7 @@ public class Main {
      * @param args the command line arguments, currently not in use
      */
     public static void main(String[] args) {
-        Reader r = new Reader( "logo.json" );
+        Reader r = new Reader( "papergraph.json" );
         LayeredGraphNode graph = r.readInputGraph();
         InitializeNodePositions.placeNodes( graph );
         new MainView( graph );

+ 30 - 0
src/view/MainView.java

@@ -468,15 +468,45 @@ public class MainView {
         pl.setLocation( 0, 0 );
         pl.setSize( frame.getSize() );
         NodeView topLeft = createNodeView( graph, LayoutType.TOP_BOTTOM_LEFT );
+        topLeft.addMouseMotionListener( new MouseAdapter() {
+            @Override
+            public void mouseMoved( MouseEvent e ) {
+                topLeft.setToolTipText( topLeft.updateTooltipText( e.getX(), e.getY() ) );
+            }
+        });
         NodeView topRight = createNodeView( graph, LayoutType.TOP_BOTTOM_RIGHT );
+        topRight.addMouseMotionListener( new MouseAdapter() {
+            @Override
+            public void mouseMoved( MouseEvent e ) {
+                topRight.setToolTipText( topRight.updateTooltipText( e.getX(), e.getY() ) );
+            }
+        });
         NodeView bottomLeft = createNodeView( graph, LayoutType.BOTTOM_TOP_LEFT );
+        bottomLeft.addMouseMotionListener( new MouseAdapter() {
+            @Override
+            public void mouseMoved( MouseEvent e ) {
+                bottomLeft.setToolTipText( bottomLeft.updateTooltipText( e.getX(), e.getY() ) );
+            }
+        });
         NodeView bottomRight = createNodeView( graph, LayoutType.BOTTOM_TOP_RIGHT );
+        bottomRight.addMouseMotionListener( new MouseAdapter() {
+            @Override
+            public void mouseMoved( MouseEvent e ) {
+                bottomRight.setToolTipText( bottomRight.updateTooltipText( e.getX(), e.getY() ) );
+            }
+        });
         pl.add( topLeft );
         pl.add( topRight );
         pl.add( bottomLeft );
         pl.add( bottomRight );
         layne.add( pl, 1 );
         NodeView combined = createNodeView( graph, LayoutType.COMBINED );
+        combined.addMouseMotionListener( new MouseAdapter() {
+            @Override
+            public void mouseMoved( MouseEvent e ) {
+                combined.setToolTipText( combined.updateTooltipText( e.getX(), e.getY() ) );
+            }
+        });
         combined.setSize( 500, 500 );
         layne.add( combined, 0 );
         

+ 43 - 0
src/view/NodeView.java

@@ -61,6 +61,45 @@ public class NodeView extends JPanel {
         return y;
     }
     
+    public String updateTooltipText( int mx, int my ) {
+        int x = 0;
+        int y = 0;
+        double scaleW = Math.min( (double)super.getWidth() / (int)model.getWidth( layout ), (double)super.getHeight() / (int)model.getHeight( layout ));
+        double scaleH = scaleW;
+        int width = (int)(super.getWidth() / scaleW);
+        if( scaleW == (double)super.getWidth() / (int)model.getWidth( layout ) )
+            y += (super.getHeight() - (model.getHeight( layout ) * scaleH )) / scaleH / 2;
+        if( scaleH == (double)super.getHeight() / (int)model.getHeight( layout ) )
+            x += (super.getWidth() - (model.getWidth( layout ) * scaleW )) / scaleW / 2;
+        if( model.isDummyNode() )
+        {
+            scaleW *= 1 / 4.0;
+            x += width / (3/4.0);
+        }
+        double minX = Double.POSITIVE_INFINITY;
+        for( Component c : getComponents() )
+        {
+            minX = Math.min( c.getLocation().x, minX);
+        }
+        for( Component c : getComponents() )
+        {
+            int nx = (int)(mx / scaleW) - (c.getLocation().x + 25 - (int)minX + x);
+            int ny = (int)(my / scaleH) - (c.getLocation().y + 25 + y);
+            int width1 = Math.min( (int)model.getWidth( layout ) - 25, c.getPreferredSize().width + 25 );
+            int height1 = Math.min( (int)model.getHeight( layout ) - 25, c.getPreferredSize().height + 25 );
+            if( nx < width1 && ny < height1 && nx > 0 && ny > 0 && c instanceof NodeView )
+                return ((NodeView)c).updateTooltipText( nx, ny );
+        }
+        if( layout != LayoutType.COMBINED )
+        {
+            return "<html>Name: " + model.toString() + 
+                    "<br>Root: " + model.getRoot( layout ).toString() +
+                    "<br>Shink: " + model.getSink( layout ).toString() + 
+                    "<br>Shift: " + model.getShift( layout ) + "</html>";
+        }
+        return "Name: " + model.toString(); 
+    }
+    
     @Override
     public void paint( Graphics g )
     {
@@ -100,6 +139,10 @@ public class NodeView extends JPanel {
     @Override
     public void paintComponent( Graphics g )
     {
+       /* this.setToolTipText( "<html>Name: " + model.toString() + 
+                "<br>Root: " + model.getRoot( layout ).toString() +
+                "<br>Shink: " + model.getSink( layout ).toString() + 
+                "<br>Shift: " + model.getShift( layout ) );*/
         Graphics2D g2 = (Graphics2D)g;
         g2.setColor( model.getColor( layout ) );
         g2.setStroke(new BasicStroke(5));