From 9045d512e9c2bbb3b1ca4420bbf659b6dfbd6a52 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Fri, 28 Mar 2008 23:14:00 -0400 Subject: [PATCH] Use thicker lines when drawing revplot diagrams By increasing the line thickness in both the SWT and the AWT rendering code we can make a nicer looking diagram that is easier to read on high resolution displays. Signed-off-by: Shawn O. Pearce --- .../egit/ui/internal/history/SWTPlotRenderer.java | 7 ++++- .../org/spearce/jgit/awtui/CommitGraphPane.java | 31 +++++++++++++++++++--- .../spearce/jgit/revplot/AbstractPlotRenderer.java | 28 +++++++++++-------- 3 files changed, 50 insertions(+), 16 deletions(-) diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/history/SWTPlotRenderer.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/history/SWTPlotRenderer.java index dcee8b22..e2670a60 100644 --- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/history/SWTPlotRenderer.java +++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/history/SWTPlotRenderer.java @@ -62,8 +62,9 @@ class SWTPlotRenderer extends AbstractPlotRenderer { } protected void drawLine(final Color color, final int x1, final int y1, - final int x2, final int y2) { + final int x2, final int y2, final int width) { g.setForeground(color); + g.setLineWidth(width); g.drawLine(cellX + x1, cellY + y1, cellX + x2, cellY + y2); } @@ -71,6 +72,7 @@ class SWTPlotRenderer extends AbstractPlotRenderer { final int h) { g.setBackground(sys_blue); g.setForeground(sys_black); + g.setLineWidth(1); g.fillOval(cellX + x, cellY + y, w, h); g.drawOval(cellX + x, cellY + y, w, h); } @@ -78,6 +80,9 @@ class SWTPlotRenderer extends AbstractPlotRenderer { protected void drawBoundaryDot(final int x, final int y, final int w, final int h) { g.setForeground(sys_gray); + g.setBackground(cellBG); + g.setLineWidth(1); + g.fillOval(cellX + x, cellY + y, w, h); g.drawOval(cellX + x, cellY + y, w, h); } diff --git a/org.spearce.jgit/src/org/spearce/jgit/awtui/CommitGraphPane.java b/org.spearce.jgit/src/org/spearce/jgit/awtui/CommitGraphPane.java index 673aea59..a84f41e2 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/awtui/CommitGraphPane.java +++ b/org.spearce.jgit/src/org/spearce/jgit/awtui/CommitGraphPane.java @@ -1,9 +1,12 @@ package org.spearce.jgit.awtui; +import java.awt.BasicStroke; import java.awt.Color; import java.awt.Component; import java.awt.Graphics; +import java.awt.Graphics2D; import java.awt.Polygon; +import java.awt.Stroke; import java.text.DateFormat; import java.text.SimpleDateFormat; @@ -186,17 +189,32 @@ public class CommitGraphPane extends JTable { } } + static final Stroke[] strokeCache; + + static { + strokeCache = new Stroke[4]; + for (int i = 1; i < strokeCache.length; i++) + strokeCache[i] = new BasicStroke(i); + } + + static Stroke stroke(final int width) { + if (width < strokeCache.length) + return strokeCache[width]; + return new BasicStroke(width); + } + final class AWTPlotRenderer extends AbstractPlotRenderer { + final GraphCellRender cell; - Graphics g; + Graphics2D g; AWTPlotRenderer(final GraphCellRender c) { cell = c; } void paint(final Graphics in, final PlotCommit commit) { - g = in.create(); + g = (Graphics2D) in.create(); try { final int h = cell.getHeight(); g.setColor(cell.getBackground()); @@ -211,8 +229,9 @@ public class CommitGraphPane extends JTable { @Override protected void drawLine(final Color color, final int x1, final int y1, - final int x2, final int y2) { + final int x2, final int y2, int width) { g.setColor(color); + g.setStroke(stroke(width)); g.drawLine(x1, y1, x2, y2); } @@ -220,6 +239,7 @@ public class CommitGraphPane extends JTable { protected void drawCommitDot(final int x, final int y, final int w, final int h) { g.setColor(Color.blue); + g.setStroke(strokeCache[1]); g.fillOval(x, y, w, h); g.setColor(Color.black); g.drawOval(x, y, w, h); @@ -228,7 +248,10 @@ public class CommitGraphPane extends JTable { @Override protected void drawBoundaryDot(final int x, final int y, final int w, final int h) { - g.setColor(Color.lightGray); + g.setColor(cell.getBackground()); + g.setStroke(strokeCache[1]); + g.fillOval(x, y, w, h); + g.setColor(Color.black); g.drawOval(x, y, w, h); } diff --git a/org.spearce.jgit/src/org/spearce/jgit/revplot/AbstractPlotRenderer.java b/org.spearce.jgit/src/org/spearce/jgit/revplot/AbstractPlotRenderer.java index 06888ef8..a682856c 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/revplot/AbstractPlotRenderer.java +++ b/org.spearce.jgit/src/org/spearce/jgit/revplot/AbstractPlotRenderer.java @@ -49,7 +49,9 @@ import org.spearce.jgit.revwalk.RevFlag; * type of color object used by the graphics library. */ public abstract class AbstractPlotRenderer { - private static final int LANE_WIDTH = 15; + private static final int LANE_WIDTH = 14; + + private static final int LINE_WIDTH = 2; private static final int LEFT_PAD = 2; @@ -62,15 +64,16 @@ public abstract class AbstractPlotRenderer { * total height (in pixels) of this cell. */ protected void paintCommit(final PlotCommit commit, final int h) { - final int dotSize = Math.max(0, Math.min(LANE_WIDTH - 2, h - 6)); + final int dotSize = Math.max(0, Math.min(LANE_WIDTH - 2, h - 8)) + 1; final TLane myLane = commit.getLane(); final int myLaneX = laneC(myLane); + final TColor myColor = laneColor(myLane); int maxCenter = 0; for (final TLane passingLane : (TLane[]) commit.passingLanes) { final int cx = laneC(passingLane); final TColor c = laneColor(passingLane); - drawLine(c, cx, 0, cx, h); + drawLine(c, cx, 0, cx, h, LINE_WIDTH); maxCenter = Math.max(maxCenter, cx); } @@ -92,24 +95,25 @@ public abstract class AbstractPlotRenderer { if (Math.abs(myLaneX - cx) > LANE_WIDTH) { if (myLaneX < cx) { final int ix = cx - LANE_WIDTH / 2; - drawLine(pColor, myLaneX, h / 2, ix, h / 2); - drawLine(pColor, ix, h / 2, cx, h); + drawLine(pColor, myLaneX, h / 2, ix, h / 2, LINE_WIDTH); + drawLine(pColor, ix, h / 2, cx, h, LINE_WIDTH); } else { final int ix = cx + LANE_WIDTH / 2; - drawLine(pColor, myLaneX, h / 2, ix, h / 2); - drawLine(pColor, ix, h / 2, cx, h); + drawLine(pColor, myLaneX, h / 2, ix, h / 2, LINE_WIDTH); + drawLine(pColor, ix, h / 2, cx, h, LINE_WIDTH); } } else { - drawLine(pColor, myLaneX, h / 2, cx, h); + drawLine(pColor, myLaneX, h / 2, cx, h, LINE_WIDTH); } maxCenter = Math.max(maxCenter, cx); } - final int dotX = myLaneX - dotSize / 2; + final int dotX = myLaneX - dotSize / 2 - 1; final int dotY = (h - dotSize) / 2; if (commit.getChildCount() > 0) - drawLine(laneColor(myLane), myLaneX, 0, myLaneX, dotY); + drawLine(myColor, myLaneX, 0, myLaneX, dotY, LINE_WIDTH); + if (commit.has(RevFlag.UNINTERESTING)) drawBoundaryDot(dotX, dotY, dotSize, dotSize); else @@ -149,9 +153,11 @@ public abstract class AbstractPlotRenderer { * ending X coordinate, 0 based. * @param y2 * ending Y coordinate, 0 based. + * @param width + * number of pixels wide for the line. Always at least 1. */ protected abstract void drawLine(TColor color, int x1, int y1, int x2, - int y2); + int y2, int width); /** * Draw a single commit dot. -- 2.11.4.GIT