implement custom tooltip for error/warning hover

This commit is contained in:
Ben Fry
2015-09-29 21:34:26 -04:00
parent 4892690e4e
commit d72ca7e2cb
5 changed files with 70 additions and 18 deletions

View File

@@ -40,9 +40,11 @@ import processing.app.syntax.*;
import processing.core.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Image;
import java.awt.Point;
@@ -2836,6 +2838,47 @@ public abstract class Editor extends JFrame implements RunnerListener {
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
static Font font;
static Color textColor;
static Color bgColorWarning;
static Color bgColorError;
/*
public void toolTipError(JComponent comp, String message) {
setToolTip(comp, message, true);
}
public void toolTipWarning(JComponent comp, String message) {
setToolTip(comp, message, false);
}
*/
public void statusToolTip(JComponent comp, String message, boolean error) {
if (font == null) {
font = Toolkit.getSansFont(9, Font.PLAIN);
textColor = mode.getColor("errors.selection.fgcolor");
bgColorWarning = mode.getColor("errors.selection.warning.bgcolor");
bgColorError = mode.getColor("errors.selection.error.bgcolor");
}
Color bgColor = error ? //text.startsWith(Language.text("editor.status.error")) ?
bgColorError : bgColorWarning;
String content = "<html>" +
"<div style='margin: -3 -3 -3 -3; padding: 3 3 3 3; " +
"background: #" + PApplet.hex(bgColor.getRGB(), 8).substring(2) + ";" +
"font-family: " + font.getFontName() + ", sans-serif;" +
"font-size: " + font.getSize() + "px;'>" + message + "</div></html>";
//System.out.println(content);
comp.setToolTipText(content);
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
/**
* Returns the edit popup menu.
*/

View File

@@ -24,14 +24,19 @@
package processing.app.ui;
import java.awt.*;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.plaf.basic.BasicSplitPaneDivider;
import javax.swing.plaf.basic.BasicSplitPaneUI;
import processing.app.Language;
import processing.app.Mode;
import processing.app.Platform;
import processing.core.PApplet;

View File

@@ -42,7 +42,6 @@ import processing.app.Util;
import processing.core.PApplet;
import processing.mode.java.pdex.LineMarker;
import processing.mode.java.pdex.Problem;
import processing.app.Language;
/**
@@ -186,10 +185,11 @@ public class MarkerColumn extends JPanel {
LineMarker m = findClosestMarker(y);
if (m != null) {
Problem p = m.getProblem();
String kind = p.isError() ?
Language.text("editor.status.error") :
Language.text("editor.status.warning");
setToolTipText(kind + ": " + p.getMessage());
// String kind = p.isError() ?
// Language.text("editor.status.error") :
// Language.text("editor.status.warning");
// setToolTipText(kind + ": " + p.getMessage());
editor.statusToolTip(MarkerColumn.this, p.getMessage(), p.isError());
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
return null;

View File

@@ -137,7 +137,10 @@ public class JavaTextAreaPainter extends TextAreaPainter
if (x >= getJavaTextArea().offsetToX(line, startOffset) &&
x <= getJavaTextArea().offsetToX(line, stopOffset)) {
setToolTipText(problem.getMessage());
//setToolTipText(problem.getMessage());
getJavaEditor().statusToolTip(JavaTextAreaPainter.this,
problem.getMessage(),
problem.isError());
evt.consume();
}
}

View File

@@ -13,6 +13,9 @@ X https://github.com/processing/processing/issues/3882
X https://github.com/processing/processing/pull/3884
X Hide useless error in error checker
X https://github.com/processing/processing/pull/3887
X grab bag of CM work from Jakub
X https://github.com/processing/processing/issues/3895
X https://github.com/processing/processing/pull/3897
gui
X distinguish errors and warnings
@@ -36,7 +39,14 @@ X selecting a warning should also show the warning in the status area
X https://github.com/processing/processing/pull/3907
X clicking an error or warning should give the focus back to the editor
X https://github.com/processing/processing/pull/3905
X replace startup/about screen (1x and 2x versions)
X change 'alpha' to correct name
X also change the revision in the "about processing" dialog
X https://github.com/processing/processing/issues/3665
X implement splash screen on OS X
X also implement special retina version
X implement custom tooltip for error/warning hover
X applies to both MarkerColumn and JavaTextAreaPainter
earlier
X list with contrib types separated is really wonky
@@ -61,9 +71,6 @@ _ mouse events (i.e. toggle breakpoint) seem to be firing twice
_ https://github.com/processing/processing/milestones/3.0%20final
_ JavaEditor has several null colors, remove color support
_ once the design is complete and we for sure do not need color
_ grab bag of CM work from Jakub
_ https://github.com/processing/processing/issues/3895
X https://github.com/processing/processing/pull/3897
gui / James
_ make gutter of console match error list
@@ -73,16 +80,10 @@ _ remove extra border around the outside
_ change font
_ change selection highlight color
_ put some margin around it
_ implement custom tooltip for error/warning hover
_ applies to both MarkerColumn and
_ Fix placement and visual design when showing error on hover
_ https://github.com/processing/processing/issues/3173
_ import suggestions box needs design review
_ https://github.com/processing/processing/issues/3407
_ replace startup/about screen (1x and 2x versions)
_ change 'alpha' to correct name
_ also change the revision in the "about processing" dialog
_ https://github.com/processing/processing/issues/3665
_ different design of squiggly line
_ easy to do inside JavaTextAreaPainter.paintSquiggle()