Browse Source

new tooltip on canvas and a small surprise ;)

Kevin Trometer 7 years ago
parent
commit
860a3d1d01
1 changed files with 29 additions and 11 deletions
  1. 29 11
      src/ui/view/MyCanvas.java

+ 29 - 11
src/ui/view/MyCanvas.java

@@ -21,12 +21,12 @@ import java.util.Timer;
 import java.util.TimerTask;
 
 import javax.swing.ImageIcon;
+import javax.swing.JLabel;
 import javax.swing.JMenuItem;
 import javax.swing.JPanel;
 import javax.swing.JPopupMenu;
 import javax.swing.JScrollPane;
 import javax.swing.JTabbedPane;
-import javax.swing.JToolTip;
 
 import classes.CpsEdge;
 import classes.CpsNode;
@@ -86,8 +86,9 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 	public JMenuItem itemUngroup = new JMenuItem(Languages.getLanguage()[100]);
 	public JMenuItem itemTrack = new JMenuItem(Languages.getLanguage()[101]);
 	public JMenuItem itemUntrack = new JMenuItem(Languages.getLanguage()[102]);
-	private JToolTip objectTT = new JToolTip();
-
+	private boolean toolTip; // Tooltip on or off
+	private Position toolTipPos = new Position(); //Tooltip Position
+	private String toolTipText = "";
 	private Point mousePosition = new Point(); // Mouse Position when
 												// rightclicked
 
@@ -113,8 +114,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 	 *            the Controller
 	 */
 	public MyCanvas(Model mod, Control control) {
-		this.add(objectTT);
-		objectTT.setVisible(false);
+		toolTip = false;
 		this.controller = control;
 		this.model = mod;
 
@@ -345,6 +345,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 							}
 						}
 					}
+					toolTip = false;
 				}
 				model.getSelectedCpsObjects().clear();
 				tempCps = null;
@@ -396,6 +397,9 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 		RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
 		g2.setRenderingHints(rh);
 
+		img = new ImageIcon(this.getClass().getResource("/Button_Images/FlagES.png")).getImage();
+		g2.drawImage(img, 0, 0, model.getCanvasX(), model.getCanvasY(),
+				null);
 		// Test SubNet Coloring
 		int i = 0;
 		for (SubNet s : controller.getSimManager().getSubNets()) {
@@ -600,6 +604,16 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 
 		}
 
+		
+		if (toolTip) {
+			g2.setColor(new Color(255, 215, 100));
+			g2.setStroke(new BasicStroke(1));
+			JLabel tempLabel = new JLabel(toolTipText);
+			g2.fillRect(toolTipPos.x, toolTipPos.y, 100, 15);
+			g2.setColor(Color.BLACK);
+			g2.drawRect(toolTipPos.x, toolTipPos.y, 100, 15);
+			g2.drawString(toolTipText, toolTipPos.x+2, toolTipPos.y+12);
+		}
 		// Dragg Highlighting
 		if (doMark) {
 			g2.setColor(Color.BLACK);
@@ -811,8 +825,10 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 
 				tempCps.setPosition(x, y); // Drag Position
 				// TipText Position and name
-				objectTT.setTipText(tempCps.getName() + ", " + tempCps.getID());
-				objectTT.setLocation(x, y + controller.getScale());
+				toolTip = true;
+				toolTipText =  tempCps.getName()+", "+tempCps.getID();
+				toolTipPos.x = tempCps.getPosition().x-2;
+				toolTipPos.y = tempCps.getPosition().y + model.getScale();
 
 				// All Selected Objects
 				for (AbstractCpsObject cps : model.getSelectedCpsObjects()) {
@@ -876,16 +892,18 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 			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;
+				toolTipPos.x = cps.getPosition().x-2;
+				toolTipPos.y = cps.getPosition().y+ model.getScale();
+				toolTipText =  cps.getName()+", "+cps.getID();
 			}
 		}
 		if (on) {
-			objectTT.setVisible(true);
+			toolTip = true;
 		} else {
-			objectTT.setVisible(false);
+			toolTip = false;
 		}
+		repaint();
 	}
 
 	/**