Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Thienel2016-02-07 04:02:24 -0500
committerFlorian Thienel2016-02-07 05:25:05 -0500
commitf67d0358ff5df2a5fa54af15959cf308923908a5 (patch)
tree29bd969ae7de2b5ee9d092b395a69848965a9aa4
parent7b6a86f5d0ae288a849049733b051ebbd1430fff (diff)
downloadorg.eclipse.mylyn.docs.vex-f67d0358ff5df2a5fa54af15959cf308923908a5.tar.gz
org.eclipse.mylyn.docs.vex-f67d0358ff5df2a5fa54af15959cf308923908a5.tar.xz
org.eclipse.mylyn.docs.vex-f67d0358ff5df2a5fa54af15959cf308923908a5.zip
add new box type to visualize list items
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/DepthFirstBoxTraversal.java5
-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/ListItem.java256
-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.java29
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/css/ListStyleTypeProperty.java8
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBasedBoxModelBuilder.java18
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBoxFactory.java7
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/DOMVisualization.java5
13 files changed, 343 insertions, 12 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 20dc8572..9359baf1 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
@@ -41,6 +41,11 @@ public class BaseBoxVisitor implements IBoxVisitor {
}
@Override
+ public void visit(final ListItem box) {
+ // ignore
+ }
+
+ @Override
public void visit(final Paragraph 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 eb1a1ebf..fce06594 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
@@ -51,6 +51,11 @@ public class BaseBoxVisitorWithResult<T> implements IBoxVisitorWithResult<T> {
}
@Override
+ public T visit(final ListItem box) {
+ return defaultValue;
+ }
+
+ @Override
public T visit(final Paragraph 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 4a9b8845..5f7b1fe6 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
@@ -127,6 +127,14 @@ public class BoxFactory {
return horizontalBar;
}
+ public static ListItem listItem(final int bulletWidth, final IStructuralBox bullet, final IStructuralBox component) {
+ final ListItem listItem = new ListItem();
+ listItem.setBulletWidth(bulletWidth);
+ listItem.setBullet(bullet);
+ listItem.setComponent(component);
+ return listItem;
+ }
+
public static Paragraph paragraph(final IInlineBox... children) {
final Paragraph paragraph = new Paragraph();
for (final IInlineBox child : children) {
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/DepthFirstBoxTraversal.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/DepthFirstBoxTraversal.java
index ebf176a1..b92795cc 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/DepthFirstBoxTraversal.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/DepthFirstBoxTraversal.java
@@ -40,6 +40,11 @@ public abstract class DepthFirstBoxTraversal<T> extends BaseBoxVisitorWithResult
}
@Override
+ public T visit(final ListItem box) {
+ return box.getComponent().accept(this);
+ }
+
+ @Override
public T visit(final Paragraph box) {
return traverseChildren(box);
}
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 6cf9ad4b..a7353b1a 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
@@ -25,6 +25,8 @@ public interface IBoxVisitor {
void visit(HorizontalBar box);
+ void visit(ListItem box);
+
void visit(Paragraph box);
void visit(InlineNodeReference 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 4c8a01f9..c18b35f1 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
@@ -25,6 +25,8 @@ public interface IBoxVisitorWithResult<T> {
T visit(HorizontalBar box);
+ T visit(ListItem box);
+
T visit(Paragraph box);
T visit(InlineNodeReference 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
new file mode 100644
index 00000000..e3b4e3fe
--- /dev/null
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/ListItem.java
@@ -0,0 +1,256 @@
+/*******************************************************************************
+ * 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.Graphics;
+import org.eclipse.vex.core.internal.core.Rectangle;
+
+public class ListItem extends BaseBox implements IStructuralBox, IDecoratorBox<IStructuralBox> {
+
+ private IBox parent;
+ private int top;
+ private int left;
+ private int width;
+ private int height;
+
+ private int bulletWidth;
+ private IStructuralBox bullet;
+ private IStructuralBox component;
+
+ @Override
+ public void setParent(final IBox parent) {
+ this.parent = parent;
+ }
+
+ @Override
+ public IBox getParent() {
+ return parent;
+ }
+
+ @Override
+ public int getAbsoluteTop() {
+ if (parent == null) {
+ return top;
+ }
+ return parent.getAbsoluteTop() + top;
+ }
+
+ @Override
+ public int getAbsoluteLeft() {
+ if (parent == null) {
+ return left;
+ }
+ return parent.getAbsoluteLeft() + left;
+ }
+
+ public int getTop() {
+ return top;
+ }
+
+ public int getLeft() {
+ return left;
+ }
+
+ public void setPosition(final int top, final int left) {
+ this.top = top;
+ this.left = left;
+ }
+
+ @Override
+ public int getWidth() {
+ return width;
+ }
+
+ public void setWidth(final int width) {
+ this.width = Math.max(0, width);
+ }
+
+ @Override
+ public int getHeight() {
+ return height;
+ }
+
+ @Override
+ public Rectangle getBounds() {
+ return new Rectangle(left, top, width, height);
+ }
+
+ @Override
+ public void accept(final IBoxVisitor visitor) {
+ visitor.visit(this);
+ }
+
+ @Override
+ public <T> T accept(final IBoxVisitorWithResult<T> visitor) {
+ return visitor.visit(this);
+ }
+
+ public void setBulletWidth(final int bulletWidth) {
+ this.bulletWidth = bulletWidth;
+ }
+
+ public int getBulletWidth() {
+ return bulletWidth;
+ }
+
+ public void setBullet(final IStructuralBox bullet) {
+ this.bullet = bullet;
+ bullet.setParent(this);
+ }
+
+ public IStructuralBox getBullet() {
+ return bullet;
+ }
+
+ public void setComponent(final IStructuralBox component) {
+ this.component = component;
+ component.setParent(this);
+ }
+
+ @Override
+ public IStructuralBox getComponent() {
+ return component;
+ }
+
+ @Override
+ public void layout(final Graphics graphics) {
+ if (bullet != null) {
+ bullet.setWidth(bulletWidth);
+ bullet.layout(graphics);
+ }
+
+ if (component != null) {
+ component.setWidth(getWidthForComponent());
+ component.layout(graphics);
+ }
+
+ final int bulletBaseline = findTopBaselineRelativeToParent(bullet);
+ final int componentBaseline = findTopBaselineRelativeToParent(component);
+
+ final int baselineDelta = componentBaseline - bulletBaseline;
+ final int bulletTop;
+ final int componentTop;
+ if (baselineDelta > 0) {
+ bulletTop = baselineDelta;
+ componentTop = 0;
+ } else {
+ bulletTop = 0;
+ componentTop = -baselineDelta;
+ }
+
+ if (bullet != null) {
+ bullet.setPosition(bulletTop, 0);
+ }
+ if (component != null) {
+ component.setPosition(componentTop, bulletWidth);
+ }
+
+ height = Math.max(getBulletHeight(), getComponentHeight());
+ }
+
+ private static int findTopBaselineRelativeToParent(final IStructuralBox parent) {
+ if (parent == null) {
+ return 0;
+ }
+
+ final Integer result = parent.accept(new DepthFirstBoxTraversal<Integer>() {
+ private int getBaselineRelativeToParent(final IInlineBox box) {
+ return box.getBaseline() + box.getAbsoluteTop() - parent.getAbsoluteTop();
+ }
+
+ @Override
+ public Integer visit(final InlineContainer box) {
+ return getBaselineRelativeToParent(box);
+ }
+
+ @Override
+ public Integer visit(final Image box) {
+ return getBaselineRelativeToParent(box);
+ }
+
+ @Override
+ public Integer visit(final InlineFrame box) {
+ return getBaselineRelativeToParent(box);
+ }
+
+ @Override
+ public Integer visit(final InlineNodeReference box) {
+ return getBaselineRelativeToParent(box);
+ }
+
+ @Override
+ public Integer visit(final NodeEndOffsetPlaceholder box) {
+ return getBaselineRelativeToParent(box);
+ }
+
+ @Override
+ public Integer visit(final NodeTag box) {
+ return getBaselineRelativeToParent(box);
+ }
+
+ @Override
+ public Integer visit(final Square box) {
+ return getBaselineRelativeToParent(box);
+ }
+
+ @Override
+ public Integer visit(final StaticText box) {
+ return getBaselineRelativeToParent(box);
+ }
+
+ @Override
+ public Integer visit(final TextContent box) {
+ return getBaselineRelativeToParent(box);
+ }
+ });
+
+ if (result == null) {
+ return 0;
+ }
+ return result.intValue();
+ }
+
+ @Override
+ public boolean reconcileLayout(final Graphics graphics) {
+ final int oldHeight = height;
+
+ height = Math.max(getBulletHeight(), getComponentHeight());
+
+ return oldHeight != height;
+ }
+
+ private int getBulletHeight() {
+ if (bullet == null) {
+ return 0;
+ }
+ return bullet.getHeight();
+ }
+
+ private int getComponentHeight() {
+ if (component == null) {
+ return 0;
+ }
+ return component.getHeight();
+ }
+
+ private int getWidthForComponent() {
+ if (bullet == null) {
+ return width;
+ }
+ return width - bullet.getWidth();
+ }
+
+ @Override
+ public void paint(final Graphics graphics) {
+ ChildBoxPainter.paint(bullet, graphics);
+ ChildBoxPainter.paint(component, graphics);
+ }
+}
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 fadf16c4..61d103af 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
@@ -51,6 +51,11 @@ public class ParentTraversal<T> implements IBoxVisitorWithResult<T> {
}
@Override
+ public T visit(final ListItem box) {
+ return box.getParent().accept(this);
+ }
+
+ @Override
public T visit(final Paragraph 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 61de003d..78b2347f 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,6 +11,8 @@
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;
/**
@@ -18,8 +20,11 @@ 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() {
@@ -44,7 +49,10 @@ public class Square extends SimpleInlineBox {
this.color = color;
}
- @Override
+ public void setFont(final FontSpec fontSpec) {
+ this.fontSpec = fontSpec;
+ }
+
public void accept(final IBoxVisitor visitor) {
visitor.visit(this);
}
@@ -56,13 +64,26 @@ public class Square extends SimpleInlineBox {
@Override
public void layout(final Graphics graphics) {
- // ignore, everything is static
+ 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);
}
@Override
public boolean reconcileLayout(final Graphics graphics) {
- // ignore, everything is static
- return false;
+ final int oldSize = size;
+
+ layout(graphics);
+
+ return size != oldSize;
}
@Override
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/css/ListStyleTypeProperty.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/css/ListStyleTypeProperty.java
index 3ff6c9b5..03ff24de 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/css/ListStyleTypeProperty.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/css/ListStyleTypeProperty.java
@@ -27,17 +27,11 @@ public class ListStyleTypeProperty extends AbstractProperty {
if (isListStyleType(lu)) {
return lu.getStringValue();
} else {
- if (parentStyles == null) {
- return CSS.DISC;
- } else {
- return parentStyles.getListStyleType();
- }
+ return CSS.NONE;
}
-
}
private static boolean isListStyleType(final LexicalUnit lu) {
-
if (lu == null || lu.getLexicalUnitType() != LexicalUnit.SAC_IDENT) {
return false;
}
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 1a07c307..19b2e8fe 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
@@ -11,9 +11,11 @@
package org.eclipse.vex.core.internal.visualization;
import static org.eclipse.vex.core.internal.boxes.BoxFactory.inlineContainer;
+import static org.eclipse.vex.core.internal.boxes.BoxFactory.listItem;
import static org.eclipse.vex.core.internal.boxes.BoxFactory.nodeReference;
import static org.eclipse.vex.core.internal.boxes.BoxFactory.nodeReferenceWithInlineContent;
import static org.eclipse.vex.core.internal.boxes.BoxFactory.nodeReferenceWithText;
+import static org.eclipse.vex.core.internal.boxes.BoxFactory.paragraph;
import static org.eclipse.vex.core.internal.boxes.BoxFactory.rootBox;
import static org.eclipse.vex.core.internal.boxes.BoxFactory.verticalBlock;
import static org.eclipse.vex.core.internal.visualization.CssBoxFactory.endOffsetPlaceholder;
@@ -22,6 +24,7 @@ import static org.eclipse.vex.core.internal.visualization.CssBoxFactory.frame;
import static org.eclipse.vex.core.internal.visualization.CssBoxFactory.image;
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;
@@ -43,7 +46,9 @@ import org.eclipse.vex.core.internal.boxes.LineWrappingRule;
import org.eclipse.vex.core.internal.boxes.Paragraph;
import org.eclipse.vex.core.internal.boxes.RootBox;
import org.eclipse.vex.core.internal.boxes.TextContent;
+import org.eclipse.vex.core.internal.core.TextAlign;
import org.eclipse.vex.core.internal.css.AttributeDependendContent;
+import org.eclipse.vex.core.internal.css.BulletStyle;
import org.eclipse.vex.core.internal.css.CSS;
import org.eclipse.vex.core.internal.css.IPropertyContent;
import org.eclipse.vex.core.internal.css.IPropertyContentVisitor;
@@ -216,7 +221,18 @@ public class CssBasedBoxModelBuilder implements IBoxModelBuilder {
*/
private IStructuralBox visualizeAsListItem(final INode node, final Styles styles, final Collection<VisualizeResult> childrenResults) {
- return visualizeAsBlock(node, styles, childrenResults);
+ final BulletStyle bulletStyle = new BulletStyle(BulletStyle.Type.SQUARE, BulletStyle.Position.OUTSIDE, null, '\0');
+ final int bulletWidth = 20;
+ final int itemIndex = 0;
+ final int itemCount = 1;
+
+ final IInlineBox bullet;
+ if (bulletStyle.type.isTextual()) {
+ bullet = staticText(bulletStyle.getBulletAsText(itemIndex, itemCount), styles);
+ } else {
+ bullet = square(styles);
+ }
+ return listItem(bulletWidth, paragraph(TextAlign.RIGHT, bullet), visualizeAsBlock(node, styles, childrenResults));
}
/*
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 11cd6a6d..834a6a70 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
@@ -118,6 +118,13 @@ 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 NodeTag nodeTag(final INode node, final Styles styles) {
final NodeTag nodeTag = new NodeTag();
nodeTag.setKind(NodeTag.Kind.NODE);
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/DOMVisualization.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/DOMVisualization.java
index 126cb4aa..f40ef6da 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/DOMVisualization.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/DOMVisualization.java
@@ -125,6 +125,11 @@ public class DOMVisualization {
}
@Override
+ public void visit(final org.eclipse.vex.core.internal.boxes.ListItem box) {
+ box.setComponent(boxModelBuilder.visualizeStructure(node));
+ }
+
+ @Override
public void visit(final Paragraph box) {
box.replaceChildren(modifiedBoxes, boxModelBuilder.visualizeInline(node));
}

Back to the top