Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Thienel2016-03-26 09:30:54 -0400
committerFlorian Thienel2016-03-26 09:30:54 -0400
commit21b0936eec481b5d6bd997c6c14fc8c3696fac42 (patch)
tree045cbd76b49a3d355a74a9afba74bd8c15468a8a
parentc6b4b6885fa11a68cf01527c4c44e50f6de230c0 (diff)
downloadorg.eclipse.mylyn.docs.vex-21b0936eec481b5d6bd997c6c14fc8c3696fac42.tar.gz
org.eclipse.mylyn.docs.vex-21b0936eec481b5d6bd997c6c14fc8c3696fac42.tar.xz
org.eclipse.mylyn.docs.vex-21b0936eec481b5d6bd997c6c14fc8c3696fac42.zip
use smaller start and end tag markers
Signed-off-by: Florian Thienel <florian@thienel.org>
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/BoxFactory.java4
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/NodeTag.java51
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/core/NodeGraphics.java50
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBoxFactory.java3
4 files changed, 99 insertions, 9 deletions
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/BoxFactory.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/BoxFactory.java
index 794dc0f2..e47f8e16 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/BoxFactory.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/BoxFactory.java
@@ -211,11 +211,13 @@ public class BoxFactory {
return bullet;
}
- public static NodeTag nodeTag(final Kind kind, final INode node, final Color foreground) {
+ public static NodeTag nodeTag(final Kind kind, final INode node, final Color foreground, final boolean showText, final float fontSize) {
final NodeTag nodeTag = new NodeTag();
nodeTag.setKind(kind);
nodeTag.setNode(node);
nodeTag.setColor(foreground);
+ nodeTag.setShowText(showText);
+ nodeTag.setFontSize(fontSize);
return nodeTag;
}
}
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/NodeTag.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/NodeTag.java
index e7a95e37..773115d5 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/NodeTag.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/NodeTag.java
@@ -25,6 +25,10 @@ public class NodeTag extends SimpleInlineBox {
NODE, START, END;
}
+ private static final int MARGIN = 2;
+ private static final float SIZE_RATIO = 0.5f;
+ private static final float BASELINE_RATIO = 1.1f;
+
private int width;
private int height;
private int baseline;
@@ -33,6 +37,7 @@ public class NodeTag extends SimpleInlineBox {
private INode node;
private Color color;
private boolean showText;
+ private float fontSize;
@Override
public int getWidth() {
@@ -69,6 +74,14 @@ public class NodeTag extends SimpleInlineBox {
this.showText = showText;
}
+ public void setFontSize(final float fontSize) {
+ this.fontSize = fontSize;
+ }
+
+ public float getFontSize() {
+ return fontSize;
+ }
+
@Override
public void accept(final IBoxVisitor visitor) {
visitor.visit(this);
@@ -82,9 +95,13 @@ public class NodeTag extends SimpleInlineBox {
@Override
public void layout(final Graphics graphics) {
final Point tagSize = getTagSize(graphics);
- width = tagSize.getX();
+ width = tagSize.getX() + MARGIN;
height = tagSize.getY();
- baseline = NodeGraphics.getTagBaseline(graphics);
+ if (kind == Kind.NODE || showText) {
+ baseline = NodeGraphics.getTagBaseline(graphics);
+ } else {
+ baseline = Math.round(height * BASELINE_RATIO);
+ }
}
private Point getTagSize(final Graphics graphics) {
@@ -92,9 +109,19 @@ public class NodeTag extends SimpleInlineBox {
case NODE:
return NodeGraphics.getTagSize(graphics, getText());
case START:
- return NodeGraphics.getStartTagSize(graphics, getText());
+ if (showText) {
+ return NodeGraphics.getStartTagSize(graphics, getText());
+ } else {
+ final int size = Math.round(fontSize * SIZE_RATIO);
+ return new Point(size, size);
+ }
case END:
- return NodeGraphics.getEndTagSize(graphics, getText());
+ if (showText) {
+ return NodeGraphics.getEndTagSize(graphics, getText());
+ } else {
+ final int size = Math.round(fontSize * SIZE_RATIO);
+ return new Point(size, size);
+ }
default:
throw new IllegalStateException("Unknown kind " + kind + " of NodeTag.");
}
@@ -117,16 +144,24 @@ public class NodeTag extends SimpleInlineBox {
@Override
public void paint(final Graphics graphics) {
- graphics.setForeground(graphics.getColor(color));
+ graphics.setColor(graphics.getColor(color));
switch (kind) {
case NODE:
- NodeGraphics.drawTag(graphics, getText(), 0, 0, false, false, true);
+ NodeGraphics.drawTag(graphics, getText(), MARGIN / 2, 0, false, false, true);
break;
case START:
- NodeGraphics.drawStartTag(graphics, getText(), 0, 0, false, true);
+ if (showText) {
+ NodeGraphics.drawStartTag(graphics, getText(), MARGIN, 0, false, true);
+ } else {
+ NodeGraphics.drawSimpleStartTag(graphics, MARGIN, 0, height, false, true);
+ }
break;
case END:
- NodeGraphics.drawEndTag(graphics, getText(), 0, 0, false, true);
+ if (showText) {
+ NodeGraphics.drawEndTag(graphics, getText(), 0, 0, false, true);
+ } else {
+ NodeGraphics.drawSimpleEndTag(graphics, 0, 0, height, false, true);
+ }
break;
default:
throw new IllegalStateException("Unknown kind " + kind + " of NodeTag.");
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/core/NodeGraphics.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/core/NodeGraphics.java
index 77808953..e569979a 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/core/NodeGraphics.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/core/NodeGraphics.java
@@ -126,6 +126,31 @@ public class NodeGraphics {
return new Point(width, height);
}
+ public static void drawSimpleStartTag(final Graphics graphics, final int x, final int y, final int size, final boolean verticallyCentered, final boolean transparent) {
+ final int effectiveY;
+ if (verticallyCentered) {
+ effectiveY = y - size / 2;
+ } else {
+ effectiveY = y;
+ }
+
+ if (!transparent) {
+ graphics.fillPolygon(simpleArrowRight(x, effectiveY, size));
+ } else {
+ graphics.setLineStyle(LineStyle.SOLID);
+ graphics.setLineWidth(1);
+ graphics.drawPolygon(simpleArrowRight(x, effectiveY, size));
+ }
+ }
+
+ private static int[] simpleArrowRight(final int x, final int y, final int size) {
+ return new int[] {
+ x, y + size,
+ x, y,
+ x + size - 1, y + size / 2
+ };
+ }
+
public static void drawEndTag(final Graphics graphics, final INode node, final int x, final int y, final boolean verticallyCentered, final boolean transparent) {
drawEndTag(graphics, getNodeName(node), x, y, verticallyCentered, false);
}
@@ -176,6 +201,31 @@ public class NodeGraphics {
return new Point(width, height);
}
+ public static void drawSimpleEndTag(final Graphics graphics, final int x, final int y, final int size, final boolean verticallyCentered, final boolean transparent) {
+ final int effectiveY;
+ if (verticallyCentered) {
+ effectiveY = y - size / 2;
+ } else {
+ effectiveY = y;
+ }
+
+ if (!transparent) {
+ graphics.fillPolygon(simpleArrowLeft(x, effectiveY, size));
+ } else {
+ graphics.setLineStyle(LineStyle.SOLID);
+ graphics.setLineWidth(1);
+ graphics.drawPolygon(simpleArrowLeft(x, effectiveY, size));
+ }
+ }
+
+ private static int[] simpleArrowLeft(final int x, final int y, final int size) {
+ return new int[] {
+ x + size - 1, y + size,
+ x + size - 1, y,
+ x, y + size / 2
+ };
+ }
+
public static String getNodeName(final INode node) {
return node.accept(new BaseNodeVisitorWithResult<String>() {
@Override
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBoxFactory.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBoxFactory.java
index bb618fd5..3ea72360 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBoxFactory.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBoxFactory.java
@@ -144,6 +144,7 @@ public class CssBoxFactory {
nodeTag.setNode(node);
nodeTag.setColor(styles.getColor());
nodeTag.setShowText(true);
+ nodeTag.setFontSize(styles.getFontSize());
return nodeTag;
}
@@ -153,6 +154,7 @@ public class CssBoxFactory {
nodeTag.setNode(node);
nodeTag.setColor(styles.getColor());
nodeTag.setShowText(false);
+ nodeTag.setFontSize(styles.getFontSize());
return nodeTag;
}
@@ -162,6 +164,7 @@ public class CssBoxFactory {
nodeTag.setNode(node);
nodeTag.setColor(styles.getColor());
nodeTag.setShowText(false);
+ nodeTag.setFontSize(styles.getFontSize());
return nodeTag;
}

Back to the top