3636import java .awt .event .MouseAdapter ;
3737import java .awt .event .MouseEvent ;
3838import java .awt .event .MouseListener ;
39+ import java .awt .event .MouseMotionAdapter ;
3940import java .awt .event .MouseMotionListener ;
4041import java .awt .event .WindowAdapter ;
4142import java .awt .event .WindowEvent ;
4243import java .awt .image .BufferedImage ;
44+ import java .util .ArrayList ;
4345import java .util .List ;
4446
4547import javax .swing .text .BadLocationException ;
@@ -73,6 +75,23 @@ public class JavaTextAreaPainter extends TextAreaPainter
7375 protected Font gutterTextFont ;
7476 protected Color gutterTextColor ;
7577// protected Color gutterTempColor;
78+
79+ public static class ErrorLineCoord {
80+ public int xStart ;
81+ public int xEnd ;
82+ public int yStart ;
83+ public int yEnd ;
84+ public Problem problem ;
85+
86+ public ErrorLineCoord (int xStart , int xEnd , int yStart , int yEnd , Problem problem ) {
87+ this .xStart = xStart ;
88+ this .xEnd = xEnd ;
89+ this .yStart = yStart ;
90+ this .yEnd = yEnd ;
91+ this .problem = problem ;
92+ }
93+ }
94+ public List <ErrorLineCoord > errorLineCoords = new ArrayList <>();
7695
7796// static int ctrlMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
7897
@@ -91,6 +110,19 @@ public void mouseClicked(MouseEvent evt) {
91110 }
92111 }
93112 });
113+
114+ addMouseMotionListener (new MouseMotionAdapter () {
115+ @ Override
116+ public void mouseMoved (final MouseEvent evt ) {
117+ for (ErrorLineCoord coord : errorLineCoords ) {
118+ if (evt .getX () >= coord .xStart && evt .getX () <= coord .xEnd
119+ && evt .getY () >= coord .yStart && evt .getY () <= coord .yEnd + 2 ) {
120+ setToolTipText (coord .problem .getMessage ());
121+ break ;
122+ }
123+ }
124+ }
125+ });
94126
95127 // TweakMode code
96128 interactiveMode = false ;
@@ -365,7 +397,8 @@ protected void paintErrorLine(Graphics gfx, int line, int x) {
365397 boolean notFound = true ;
366398 boolean isWarning = false ;
367399 Problem problem = null ;
368-
400+
401+ errorLineCoords .clear ();
369402 // Check if current line contains an error. If it does, find if it's an
370403 // error or warning
371404 for (ErrorMarker emarker : errorCheckerService .getEditor ().getErrorPoints ()) {
@@ -420,6 +453,8 @@ protected void paintErrorLine(Graphics gfx, int line, int x) {
420453 // Adding offsets for the gutter
421454 x1 += Editor .LEFT_GUTTER ;
422455 x2 += Editor .LEFT_GUTTER ;
456+
457+ errorLineCoords .add (new ErrorLineCoord (x1 , x2 , y , y1 , problem ));
423458
424459 // gfx.fillRect(x1, y, rw, height);
425460
@@ -494,8 +529,8 @@ public void setECSandTheme(ErrorCheckerService ecs, JavaMode mode) {
494529 gutterTextFont = mode .getFont ("editor.gutter.text.font" );
495530 gutterTextColor = mode .getColor ("editor.gutter.text.color" );
496531 }
497-
498-
532+
533+ @ Override
499534 public String getToolTipText (MouseEvent event ) {
500535 if (!getEditor ().hasJavaTabs ()) {
501536 int off = textArea .xyToOffset (event .getX (), event .getY ());
@@ -577,7 +612,7 @@ public String getToolTipText(MouseEvent event) {
577612 }
578613 }
579614 // Used when there are Java tabs, but also the fall-through case from above
580- setToolTipText (null );
615+ // setToolTipText(null);
581616 return super .getToolTipText (event );
582617 }
583618
0 commit comments