Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Thienel2016-03-21 16:52:32 -0400
committerFlorian Thienel2016-03-21 16:52:32 -0400
commitaa9712a734a9ddc679e54d6cb2b45714b835be32 (patch)
tree6b5ef9c014a8b35ebfa4a141fcaa1071c91651ca
parentbdc44461f9e6ecadf6ed6ad570efd80597c504f6 (diff)
downloadorg.eclipse.mylyn.docs.vex-aa9712a734a9ddc679e54d6cb2b45714b835be32.tar.gz
org.eclipse.mylyn.docs.vex-aa9712a734a9ddc679e54d6cb2b45714b835be32.tar.xz
org.eclipse.mylyn.docs.vex-aa9712a734a9ddc679e54d6cb2b45714b835be32.zip
introduce a special purpose inline box that represents graphical bullets
Signed-off-by: Florian Thienel <florian@thienel.org>
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/BaseBoxVisitor.java5
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/BaseBoxVisitorWithResult.java5
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/BoxFactory.java8
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/GraphicalBullet.java117
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/IBoxVisitor.java2
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/IBoxVisitorWithResult.java2
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/InlineNodeReference.java6
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/ListItem.java5
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/ParentTraversal.java5
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/Square.java27
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/StructuralNodeReference.java6
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/cursor/Cursor.java7
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBasedBoxModelBuilder.java4
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBoxFactory.java12
14 files changed, 179 insertions, 32 deletions
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/BaseBoxVisitor.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/BaseBoxVisitor.java
index 8c264098..95753558 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/BaseBoxVisitor.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/BaseBoxVisitor.java
@@ -91,6 +91,11 @@ public class BaseBoxVisitor implements IBoxVisitor {
}
@Override
+ public void visit(final GraphicalBullet box) {
+ // ignore
+ }
+
+ @Override
public void visit(final Square box) {
// ignore
}
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/BaseBoxVisitorWithResult.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/BaseBoxVisitorWithResult.java
index 7138f3d5..63649403 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/BaseBoxVisitorWithResult.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/BaseBoxVisitorWithResult.java
@@ -101,6 +101,11 @@ public class BaseBoxVisitorWithResult<T> implements IBoxVisitorWithResult<T> {
}
@Override
+ public T visit(final GraphicalBullet box) {
+ return defaultValue;
+ }
+
+ @Override
public T visit(final Square box) {
return defaultValue;
}
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 cc1ad25f..794dc0f2 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
@@ -203,6 +203,14 @@ public class BoxFactory {
return square;
}
+ public static GraphicalBullet graphicalBullet(final BulletStyle.Type type, final FontSpec font, final Color color) {
+ final GraphicalBullet bullet = new GraphicalBullet();
+ bullet.setType(type);
+ bullet.setFont(font);
+ bullet.setColor(color);
+ return bullet;
+ }
+
public static NodeTag nodeTag(final Kind kind, final INode node, final Color foreground) {
final NodeTag nodeTag = new NodeTag();
nodeTag.setKind(kind);
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/GraphicalBullet.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/GraphicalBullet.java
new file mode 100644
index 00000000..77468a23
--- /dev/null
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/GraphicalBullet.java
@@ -0,0 +1,117 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Florian Thienel and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Florian Thienel - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.vex.core.internal.boxes;
+
+import org.eclipse.vex.core.internal.core.Color;
+import org.eclipse.vex.core.internal.core.FontResource;
+import org.eclipse.vex.core.internal.core.FontSpec;
+import org.eclipse.vex.core.internal.core.Graphics;
+import org.eclipse.vex.core.internal.css.BulletStyle;
+
+/**
+ * @author Florian Thienel
+ */
+public class GraphicalBullet extends SimpleInlineBox {
+
+ private static final float HEIGHT_RATIO = 0.8f;
+ private static final float LIFT_RATIO = 0.1f;
+
+ private int width;
+ private int height;
+
+ private BulletStyle.Type bulletType;
+ private FontSpec fontSpec;
+ private Color color;
+
+ @Override
+ public int getWidth() {
+ return width;
+ }
+
+ @Override
+ public int getHeight() {
+ return height;
+ }
+
+ @Override
+ public int getBaseline() {
+ return height;
+ }
+
+ public void accept(final IBoxVisitor visitor) {
+ visitor.visit(this);
+ }
+
+ @Override
+ public <T> T accept(final IBoxVisitorWithResult<T> visitor) {
+ return visitor.visit(this);
+ }
+
+ public void setType(final BulletStyle.Type bulletType) {
+ this.bulletType = bulletType;
+ }
+
+ public void setFont(final FontSpec fontSpec) {
+ this.fontSpec = fontSpec;
+ }
+
+ public void setColor(final Color color) {
+ this.color = color;
+ }
+
+ @Override
+ public void layout(final Graphics graphics) {
+ if (fontSpec == null) {
+ return;
+ }
+
+ applyFont(graphics);
+ final int ascent = graphics.getFontMetrics().getAscent();
+ height = Math.round(ascent * HEIGHT_RATIO);
+ final int lift = Math.round(ascent * LIFT_RATIO);
+ width = height - lift;
+ }
+
+ private void applyFont(final Graphics graphics) {
+ final FontResource font = graphics.getFont(fontSpec);
+ graphics.setCurrentFont(font);
+ }
+
+ @Override
+ public boolean reconcileLayout(final Graphics graphics) {
+ final int oldHeight = height;
+
+ layout(graphics);
+
+ return height != oldHeight;
+ }
+
+ @Override
+ public void paint(final Graphics graphics) {
+ graphics.setColor(graphics.getColor(color));
+
+ switch (bulletType) {
+ case SQUARE:
+ graphics.fillRect(0, 0, width, width);
+ break;
+ case DISC:
+ graphics.fillOval(0, 0, width, width);
+ break;
+ case CIRCLE:
+ graphics.setLineWidth(1);
+ graphics.drawOval(0, 0, width, width);
+ break;
+ default:
+ graphics.fillRect(0, 0, width, width);
+ break;
+ }
+ }
+}
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/IBoxVisitor.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/IBoxVisitor.java
index e1dad210..be3bc01e 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/IBoxVisitor.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/IBoxVisitor.java
@@ -45,6 +45,8 @@ public interface IBoxVisitor {
void visit(NodeEndOffsetPlaceholder box);
+ void visit(GraphicalBullet box);
+
void visit(Square box);
void visit(NodeTag box);
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/IBoxVisitorWithResult.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/IBoxVisitorWithResult.java
index 676926ee..1a01ea06 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/IBoxVisitorWithResult.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/IBoxVisitorWithResult.java
@@ -45,6 +45,8 @@ public interface IBoxVisitorWithResult<T> {
T visit(NodeEndOffsetPlaceholder box);
+ T visit(GraphicalBullet box);
+
T visit(Square box);
T visit(NodeTag box);
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/InlineNodeReference.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/InlineNodeReference.java
index e42d992f..5fae4e3d 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/InlineNodeReference.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/InlineNodeReference.java
@@ -260,6 +260,12 @@ public class InlineNodeReference extends BaseBox implements IInlineBox, IDecorat
}
@Override
+ public Object visit(final GraphicalBullet box) {
+ paintBox(graphics, box);
+ return super.visit(box);
+ }
+
+ @Override
public Object visit(final Square box) {
paintBox(graphics, box);
return super.visit(box);
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/ListItem.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/ListItem.java
index 2c58e9a8..6717e4f5 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/ListItem.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/ListItem.java
@@ -251,6 +251,11 @@ public class ListItem extends BaseBox implements IStructuralBox, IDecoratorBox<I
}
@Override
+ public Integer visit(final GraphicalBullet box) {
+ return getBaselineRelativeToParent(box);
+ }
+
+ @Override
public Integer visit(final Square box) {
return getBaselineRelativeToParent(box);
}
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/ParentTraversal.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/ParentTraversal.java
index 92ed0404..9e5ae4ac 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/ParentTraversal.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/ParentTraversal.java
@@ -101,6 +101,11 @@ public class ParentTraversal<T> implements IBoxVisitorWithResult<T> {
}
@Override
+ public T visit(final GraphicalBullet box) {
+ return box.getParent().accept(this);
+ }
+
+ @Override
public T visit(final Square box) {
return box.getParent().accept(this);
}
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/Square.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/Square.java
index 78b2347f..55526b45 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/Square.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/Square.java
@@ -11,8 +11,6 @@
package org.eclipse.vex.core.internal.boxes;
import org.eclipse.vex.core.internal.core.Color;
-import org.eclipse.vex.core.internal.core.FontResource;
-import org.eclipse.vex.core.internal.core.FontSpec;
import org.eclipse.vex.core.internal.core.Graphics;
/**
@@ -20,11 +18,8 @@ import org.eclipse.vex.core.internal.core.Graphics;
*/
public class Square extends SimpleInlineBox {
- private static final float ASCENT_RATIO = 0.6f;
-
private int size;
private Color color;
- private FontSpec fontSpec;
@Override
public int getWidth() {
@@ -49,10 +44,6 @@ public class Square extends SimpleInlineBox {
this.color = color;
}
- public void setFont(final FontSpec fontSpec) {
- this.fontSpec = fontSpec;
- }
-
public void accept(final IBoxVisitor visitor) {
visitor.visit(this);
}
@@ -64,26 +55,12 @@ public class Square extends SimpleInlineBox {
@Override
public void layout(final Graphics graphics) {
- if (fontSpec == null) {
- return;
- }
-
- applyFont(graphics);
- size = Math.round(graphics.getFontMetrics().getAscent() * ASCENT_RATIO);
- }
-
- private void applyFont(final Graphics graphics) {
- final FontResource font = graphics.getFont(fontSpec);
- graphics.setCurrentFont(font);
+ // ignore, static size
}
@Override
public boolean reconcileLayout(final Graphics graphics) {
- final int oldSize = size;
-
- layout(graphics);
-
- return size != oldSize;
+ return false; // static size
}
@Override
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/StructuralNodeReference.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/StructuralNodeReference.java
index a9a8ba20..161c3156 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/StructuralNodeReference.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/StructuralNodeReference.java
@@ -208,6 +208,12 @@ public class StructuralNodeReference extends BaseBox implements IStructuralBox,
}
@Override
+ public Object visit(final GraphicalBullet box) {
+ paintBox(graphics, box);
+ return super.visit(box);
+ }
+
+ @Override
public Object visit(final Square box) {
paintBox(graphics, box);
return super.visit(box);
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/cursor/Cursor.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/cursor/Cursor.java
index 738f777c..7507a08e 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/cursor/Cursor.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/cursor/Cursor.java
@@ -14,6 +14,7 @@ import java.util.LinkedList;
import org.eclipse.vex.core.internal.boxes.BaseBoxVisitorWithResult;
import org.eclipse.vex.core.internal.boxes.DepthFirstBoxTraversal;
+import org.eclipse.vex.core.internal.boxes.GraphicalBullet;
import org.eclipse.vex.core.internal.boxes.IBox;
import org.eclipse.vex.core.internal.boxes.IContentBox;
import org.eclipse.vex.core.internal.boxes.IInlineBox;
@@ -396,6 +397,12 @@ public class Cursor implements ICursor {
}
@Override
+ public IBox visit(final GraphicalBullet box) {
+ deepestLastChildBox[0] = box;
+ return null;
+ }
+
+ @Override
public IBox visit(final NodeTag box) {
deepestLastChildBox[0] = box;
return null;
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBasedBoxModelBuilder.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBasedBoxModelBuilder.java
index dac87330..4082aba7 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBasedBoxModelBuilder.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBasedBoxModelBuilder.java
@@ -20,11 +20,11 @@ import static org.eclipse.vex.core.internal.boxes.BoxFactory.verticalBlock;
import static org.eclipse.vex.core.internal.visualization.CssBoxFactory.endOffsetPlaceholder;
import static org.eclipse.vex.core.internal.visualization.CssBoxFactory.endTag;
import static org.eclipse.vex.core.internal.visualization.CssBoxFactory.frame;
+import static org.eclipse.vex.core.internal.visualization.CssBoxFactory.graphicalBullet;
import static org.eclipse.vex.core.internal.visualization.CssBoxFactory.image;
import static org.eclipse.vex.core.internal.visualization.CssBoxFactory.list;
import static org.eclipse.vex.core.internal.visualization.CssBoxFactory.nodeTag;
import static org.eclipse.vex.core.internal.visualization.CssBoxFactory.paragraph;
-import static org.eclipse.vex.core.internal.visualization.CssBoxFactory.square;
import static org.eclipse.vex.core.internal.visualization.CssBoxFactory.startTag;
import static org.eclipse.vex.core.internal.visualization.CssBoxFactory.staticText;
import static org.eclipse.vex.core.internal.visualization.CssBoxFactory.textContent;
@@ -224,7 +224,7 @@ public class CssBasedBoxModelBuilder implements IBoxModelBuilder {
if (bulletStyle.type.isTextual()) {
bullet = staticText(bulletStyle.getBulletAsText(itemIndex, itemCount), styles);
} else {
- bullet = square(styles);
+ bullet = graphicalBullet(bulletStyle.type, styles);
}
return bullet;
}
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 9d0465fc..bb618fd5 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
@@ -14,6 +14,7 @@ import java.net.URL;
import org.eclipse.vex.core.internal.boxes.Border;
import org.eclipse.vex.core.internal.boxes.BorderLine;
+import org.eclipse.vex.core.internal.boxes.GraphicalBullet;
import org.eclipse.vex.core.internal.boxes.IBulletFactory;
import org.eclipse.vex.core.internal.boxes.IInlineBox;
import org.eclipse.vex.core.internal.boxes.IStructuralBox;
@@ -129,11 +130,12 @@ public class CssBoxFactory {
return square;
}
- public static Square square(final Styles styles) {
- final Square square = new Square();
- square.setFont(font(styles));
- square.setColor(styles.getColor());
- return square;
+ public static GraphicalBullet graphicalBullet(final BulletStyle.Type type, final Styles styles) {
+ final GraphicalBullet bullet = new GraphicalBullet();
+ bullet.setType(type);
+ bullet.setFont(font(styles));
+ bullet.setColor(styles.getColor());
+ return bullet;
}
public static NodeTag nodeTag(final INode node, final Styles styles) {

Back to the top