Kevin Trometer преди 7 години
родител
ревизия
eae667739a
променени са 2 файла, в които са добавени 26 реда и са изтрити 6 реда
  1. 13 3
      src/ui/view/MyCanvas.java
  2. 13 3
      src/ui/view/UpperNodeCanvas.java

+ 13 - 3
src/ui/view/MyCanvas.java

@@ -611,10 +611,20 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 			g2.setColor(new Color(255, 225, 150));
 			g2.setStroke(new BasicStroke(1));
 			int textWidth = g.getFontMetrics().stringWidth(toolTipText)+2; //Text width
-			g2.fillRect(toolTipPos.x-(textWidth>>1)+model.getScaleDiv2(), toolTipPos.y, textWidth, 15);
+			int fixXPos = toolTipPos.x-(textWidth>>1)+model.getScaleDiv2(); //Position fixed x Position to the screen
+			int fixYPos = toolTipPos.y;	////Position fixed y Position to the screen
+			if (fixXPos<0) {
+				fixXPos = 0;
+			} else if (fixXPos+textWidth+1>this.getWidth()) {
+				fixXPos -= (fixXPos+textWidth+1)-this.getWidth();
+			}
+			if (fixYPos+16>this.getHeight()) {
+				fixYPos-= (fixYPos+16)-this.getHeight();
+			}
+			g2.fillRect(fixXPos, fixYPos, textWidth, 15);
 			g2.setColor(Color.BLACK);
-			g2.drawRect(toolTipPos.x-(textWidth>>1)+model.getScaleDiv2(), toolTipPos.y, textWidth, 15);
-			g2.drawString(toolTipText, toolTipPos.x-(textWidth>>1)+model.getScaleDiv2()+2, toolTipPos.y+12);
+			g2.drawRect(fixXPos, fixYPos, textWidth, 15);
+			g2.drawString(toolTipText, fixXPos+2, fixYPos+12);
 		}
 		
 		// Dragg Highlighting

+ 13 - 3
src/ui/view/UpperNodeCanvas.java

@@ -751,10 +751,20 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 			g2.setColor(new Color(255, 225, 150));
 			g2.setStroke(new BasicStroke(1));
 			int textWidth = g.getFontMetrics().stringWidth(toolTipText) + 2; // Text width
-			g2.fillRect(toolTipPos.x - (textWidth >> 1) + model.getScaleDiv2(), toolTipPos.y, textWidth, 15);
+			int fixXPos = toolTipPos.x - (textWidth >> 1) + model.getScaleDiv2(); // Position fixed x Position to the screen
+			int fixYPos = toolTipPos.y; //// Position fixed y Position to the screen
+			if (fixXPos < 0) {
+				fixXPos = 0;
+			} else if (fixXPos + textWidth + 1 > this.getWidth()) {
+				fixXPos -= (fixXPos + textWidth + 1) - this.getWidth();
+			}
+			if (fixYPos + 16 > this.getHeight()) {
+				fixYPos -= (fixYPos + 16) - this.getHeight();
+			}
+			g2.fillRect(fixXPos, fixYPos, textWidth, 15);
 			g2.setColor(Color.BLACK);
-			g2.drawRect(toolTipPos.x - (textWidth >> 1) + model.getScaleDiv2(), toolTipPos.y, textWidth, 15);
-			g2.drawString(toolTipText, toolTipPos.x - (textWidth >> 1) + model.getScaleDiv2() + 2, toolTipPos.y + 12);
+			g2.drawRect(fixXPos, fixYPos, textWidth, 15);
+			g2.drawString(toolTipText, fixXPos + 2, fixYPos + 12);
 		}
 	}