Skip to content

Commit 7c8e186

Browse files
committed
fix line number right-alignment
1 parent 0c91144 commit 7c8e186

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

java/src/processing/mode/java/pdex/JavaTextAreaPainter.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.awt.Color;
2828
import java.awt.Cursor;
2929
import java.awt.Font;
30-
import java.awt.FontMetrics;
3130
import java.awt.Graphics;
3231
import java.awt.Graphics2D;
3332
import java.awt.Point;
@@ -60,6 +59,8 @@
6059
/**
6160
* Customized line painter. Adds support for background colors,
6261
* left hand gutter area with background color and text.
62+
* TODO Most of this needs to be merged into the main TextAreaPainter,
63+
* since it has nothing to do with Java. [fry]
6364
*/
6465
public class JavaTextAreaPainter extends TextAreaPainter
6566
implements MouseListener, MouseMotionListener {
@@ -75,14 +76,14 @@ public class JavaTextAreaPainter extends TextAreaPainter
7576
protected Font gutterTextFont;
7677
protected Color gutterTextColor;
7778
// protected Color gutterTempColor;
78-
79+
7980
public static class ErrorLineCoord {
8081
public int xStart;
8182
public int xEnd;
8283
public int yStart;
8384
public int yEnd;
8485
public Problem problem;
85-
86+
8687
public ErrorLineCoord(int xStart, int xEnd, int yStart, int yEnd, Problem problem) {
8788
this.xStart = xStart;
8889
this.xEnd = xEnd;
@@ -110,7 +111,7 @@ public void mouseClicked(MouseEvent evt) {
110111
}
111112
}
112113
});
113-
114+
114115
addMouseMotionListener(new MouseMotionAdapter() {
115116
@Override
116117
public void mouseMoved(final MouseEvent evt) {
@@ -255,17 +256,12 @@ protected void paintLeftGutter(Graphics gfx, int line, int x) {
255256

256257
//gfx.setFont(getFont());
257258
gfx.setFont(gutterTextFont);
258-
FontMetrics gm = getFontMetrics();
259-
//int tx = Editor.GUTTER_MARGIN + ;
259+
// Right-align the text
260260
int tx = Editor.LEFT_GUTTER - Editor.GUTTER_MARGIN -
261-
gm.charsWidth(txt, 0, txt.length);
262-
// Color textColor = getTextArea().getGutterTextColor(line);
263-
// if (textColor == null) {
264-
// gfx.setColor(getForeground());
265-
// } else {
266-
// gfx.setColor(textColor);
267-
// }
261+
gfx.getFontMetrics().charsWidth(txt, 0, txt.length);
268262
gfx.setColor(gutterTextColor);
263+
// Using 'fm' here because it's relative to the editor text size,
264+
// not the numbers in the gutter
269265
int ty = textArea.lineToY(line) + fm.getHeight();
270266
Utilities.drawTabbedText(new Segment(txt, 0, text.length()),
271267
tx, ty, gfx, this, 0);
@@ -397,7 +393,7 @@ protected void paintErrorLine(Graphics gfx, int line, int x) {
397393
boolean notFound = true;
398394
boolean isWarning = false;
399395
Problem problem = null;
400-
396+
401397
errorLineCoords.clear();
402398
// Check if current line contains an error. If it does, find if it's an
403399
// error or warning
@@ -453,7 +449,7 @@ protected void paintErrorLine(Graphics gfx, int line, int x) {
453449
// Adding offsets for the gutter
454450
x1 += Editor.LEFT_GUTTER;
455451
x2 += Editor.LEFT_GUTTER;
456-
452+
457453
errorLineCoords.add(new ErrorLineCoord(x1, x2, y, y1, problem));
458454

459455
// gfx.fillRect(x1, y, rw, height);
@@ -529,7 +525,7 @@ public void setECSandTheme(ErrorCheckerService ecs, JavaMode mode) {
529525
gutterTextFont = mode.getFont("editor.gutter.text.font");
530526
gutterTextColor = mode.getColor("editor.gutter.text.color");
531527
}
532-
528+
533529
@Override
534530
public String getToolTipText(MouseEvent event) {
535531
if (!getEditor().hasJavaTabs()) {

0 commit comments

Comments
 (0)