Browse Source

versuch tooltip in uppernode zu fixen

Kevin Trometer 7 years ago
parent
commit
b15ac3dfa8
2 changed files with 54 additions and 27 deletions
  1. 10 12
      src/ui/view/MyCanvas.java
  2. 44 15
      src/ui/view/UpperNodeCanvas.java

+ 10 - 12
src/ui/view/MyCanvas.java

@@ -86,7 +86,6 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 
 	// contains the value of the Capacity for new created Edges
 
-
 	/**
 	 * Constructor.
 	 * 
@@ -205,16 +204,16 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 				for (AbstractCpsObject cps : model.getSelectedCpsObjects()) {
 					controller.delCanvasObject(cps);
 					// Remove UpperNodeTab if UpperNode deleted
-					if(cps instanceof CpsUpperNode){
+					if (cps instanceof CpsUpperNode) {
 						JTabbedPane tabbedPane = (JTabbedPane) getParent().getParent().getParent();
 						for (int i = 2; i < tabbedPane.getTabCount(); i++) {
-							if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport().getComponent(0)).upperNode
-									.getID() == cps.getID()) {
+							if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
+									.getComponent(0)).upperNode.getID() == cps.getID()) {
 								tabbedPane.remove(i);
-								i = tabbedPane.getTabCount();				
+								i = tabbedPane.getTabCount();
 							}
 						}
-					}	
+					}
 				}
 				model.getSelectedCpsObjects().clear();
 				tempCps = null;
@@ -473,13 +472,13 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 		dataSelected = null;
 		edgeHighlight = null;
 		controller.setSelecteEdge(null);
-		
+
 		// Object Selection
 		for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
 			cx = cps.getPosition().x;
 			cy = cps.getPosition().y;
 			if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
-				tempCps = cps;				
+				tempCps = cps;
 				controller.addTextToConsole("Selected: ", Color.BLACK, 12, false, false, false);
 				controller.addTextToConsole("" + cps.getName(), Color.BLUE, 12, true, false, false);
 				controller.addTextToConsole(", ID:", Color.BLACK, 12, false, false, false);
@@ -700,14 +699,15 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 			cy = cps.getPosition().y;
 			if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
 
-				objectTT.setTipText(cps.getName() + ", " + cps.getID());
 				objectTT.setLocation(cx, cy + controller.getScale());
+				objectTT.setTipText(cps.getName() + ", " + cps.getID());
+
 				on = true;
 			}
 		}
 		if (!on) {
-			objectTT.setLocation(-200, -200);
 			objectTT.setTipText("");
+			objectTT.setLocation(-200, -200);
 		}
 	}
 
@@ -866,8 +866,6 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 		return false;
 	}
 
-
-
 	/**
 	 * Set if Information should be shown.
 	 * 

+ 44 - 15
src/ui/view/UpperNodeCanvas.java

@@ -89,7 +89,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 	public JMenuItem itemUngroup = new JMenuItem("Ungroup");
 	public JMenuItem itemTrack = new JMenuItem("Track");
 	public JMenuItem itemUntrack = new JMenuItem("Untrack");
-	// private JToolTip objectTT = new JToolTip();
+	private JToolTip objectTT = new JToolTip();
 
 	private Point mousePosition = new Point(); // Mouse Position when
 												// rightclicked
@@ -105,7 +105,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 	 *            the Controller
 	 */
 	public UpperNodeCanvas(Model mod, Control control, CpsUpperNode UpperNode, String parentPath) {
-		// this.add(objectTT);
+		this.add(objectTT);
 		this.controller = control;
 		this.model = mod;
 		this.upperNode = UpperNode;
@@ -606,6 +606,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 				}
 			}
 		} else {
+			// look fot objects connected to uppernode
 			int count = 0;
 			for (CpsEdge ed : upperNode.getConnections()) {
 				AbstractCpsObject cps;
@@ -841,19 +842,47 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 		x = e.getX();
 		y = e.getY();
 		// Everytghing for the tooltip :)
-		/*
-		 * boolean on = false; for (AbstractCpsObject cps :
-		 * upperNode.getNodes()) {
-		 * 
-		 * cx = cps.getPosition().x; cy = cps.getPosition().y; if (x -
-		 * controller.getScale() <= cx && y - controller.getScale() <= cy && x
-		 * >= cx && y >= cy) {
-		 * 
-		 * objectTT.setTipText(cps.getName() + ", " + cps.getID());
-		 * objectTT.setLocation(cx, cy + controller.getScale()); on = true; } }
-		 * if (!on) { objectTT.setLocation(-200, -200); objectTT.setTipText("");
-		 * }
-		 */
+
+		boolean on = false;
+		for (AbstractCpsObject cps : upperNode.getNodes()) {
+
+			cx = cps.getPosition().x;
+			cy = cps.getPosition().y;
+			if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
+
+				objectTT.setLocation(cx, cy + controller.getScale());
+				objectTT.setTipText(cps.getName() + ", " + cps.getID());
+
+				on = true;
+			}
+		}
+		int count = 0;
+		for (CpsEdge ed : upperNode.getConnections()) {
+
+			AbstractCpsObject cps;
+			if (ed.getA().equals(this.upperNode)) {
+				cps = ed.getB();
+			} else {
+				cps = ed.getA();
+			}
+
+			cx = borderPos>>1;
+			cy = (int) (scalediv20 + 5 + (model.getScale() + scalediv20 + 10) * count);
+			if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
+
+				objectTT.setLocation(cx-model.getScaleDiv2(), cy + controller.getScale());
+				objectTT.setTipText(cps.getName() + ", " + cps.getID());
+
+				on = true;
+			}
+			count++;
+		}
+
+		if (!on) {
+			objectTT.setTipText("");
+			objectTT.setLocation(-200, -200);
+		}
+
 	}
 
 	/**