Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Thienel2016-03-20 06:10:44 -0400
committerFlorian Thienel2016-03-20 08:51:14 -0400
commit184d6ccd87d32d75cf9a2ae11eccea348b4acb8b (patch)
treef45053922860609cfc1c439b0ef37fac0372195e
parent49a0bebe108bc78914bb3ab2ebcd1f0bb2a7e5a7 (diff)
downloadorg.eclipse.mylyn.docs.vex-184d6ccd87d32d75cf9a2ae11eccea348b4acb8b.tar.gz
org.eclipse.mylyn.docs.vex-184d6ccd87d32d75cf9a2ae11eccea348b4acb8b.tar.xz
org.eclipse.mylyn.docs.vex-184d6ccd87d32d75cf9a2ae11eccea348b4acb8b.zip
move calculations and layout for outside bullets to List
Signed-off-by: Florian Thienel <florian@thienel.org>
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/BoxFactory.java7
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/IBulletFactory.java20
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/List.java66
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/ListItem.java50
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBasedBoxModelBuilder.java34
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBoxFactory.java4
6 files changed, 144 insertions, 37 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 5a656dd6..cc1ad25f 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
@@ -128,17 +128,16 @@ public class BoxFactory {
return horizontalBar;
}
- public static List list(final IStructuralBox component, final BulletStyle bulletStyle) {
+ public static List list(final IStructuralBox component, final BulletStyle bulletStyle, final IBulletFactory bulletFactory) {
final List list = new List();
list.setBulletStyle(bulletStyle);
+ list.setBulletFactory(bulletFactory);
list.setComponent(component);
return list;
}
- public static ListItem listItem(final int bulletWidth, final IStructuralBox bullet, final IStructuralBox component) {
+ public static ListItem listItem(final IStructuralBox component) {
final ListItem listItem = new ListItem();
- listItem.setBulletWidth(bulletWidth);
- listItem.setBullet(bullet);
listItem.setComponent(component);
return listItem;
}
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/IBulletFactory.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/IBulletFactory.java
new file mode 100644
index 00000000..d7f6ee1b
--- /dev/null
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/IBulletFactory.java
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * 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.css.BulletStyle;
+
+/**
+ * @author Florian Thienel
+ */
+public interface IBulletFactory {
+ IInlineBox createBullet(BulletStyle style, int itemIndex, int itemCount);
+}
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/List.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/List.java
index 0208d4f8..82c86291 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/List.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/List.java
@@ -1,5 +1,7 @@
package org.eclipse.vex.core.internal.boxes;
+import java.util.ArrayList;
+
import org.eclipse.vex.core.internal.core.Graphics;
import org.eclipse.vex.core.internal.core.Rectangle;
import org.eclipse.vex.core.internal.css.BulletStyle;
@@ -13,6 +15,7 @@ public class List extends BaseBox implements IStructuralBox, IDecoratorBox<IStru
private int height;
private BulletStyle bulletStyle;
+ private IBulletFactory bulletFactory;
private IStructuralBox component;
@@ -92,6 +95,14 @@ public class List extends BaseBox implements IStructuralBox, IDecoratorBox<IStru
return bulletStyle;
}
+ public void setBulletFactory(final IBulletFactory bulletFactory) {
+ this.bulletFactory = bulletFactory;
+ }
+
+ public IBulletFactory getBulletFactory() {
+ return bulletFactory;
+ }
+
@Override
public void setComponent(final IStructuralBox component) {
this.component = component;
@@ -108,17 +119,68 @@ public class List extends BaseBox implements IStructuralBox, IDecoratorBox<IStru
if (component == null) {
return;
}
+
+ layoutBullets(graphics, collectListItems(this));
+ layoutComponent(graphics);
+
+ height = component.getHeight();
+ }
+
+ private void layoutBullets(final Graphics graphics, final java.util.List<ListItem> listItems) {
+ int bulletWidth = 0;
+ for (int i = 0; i < listItems.size(); i += 1) {
+ final IInlineBox bullet;
+ if (bulletFactory == null) {
+ bullet = null;
+ } else {
+ bullet = bulletFactory.createBullet(bulletStyle, i, listItems.size());
+ bullet.layout(graphics);
+ bulletWidth = Math.max(bulletWidth, bullet.getWidth());
+ }
+
+ listItems.get(i).setBullet(bullet);
+ }
+
+ for (final ListItem listItem : listItems) {
+ listItem.setBulletWidth(bulletWidth);
+ }
+ }
+
+ private static java.util.List<ListItem> collectListItems(final List list) {
+ final ArrayList<ListItem> listItems = new ArrayList<ListItem>();
+ list.accept(new DepthFirstBoxTraversal<Object>() {
+ @Override
+ public Object visit(final List box) {
+ if (box == list) {
+ return super.visit(box);
+ }
+ return null;
+ }
+
+ @Override
+ public Object visit(final ListItem box) {
+ listItems.add(box);
+ return null;
+ }
+ });
+ return listItems;
+ }
+
+ private void layoutComponent(final Graphics graphics) {
component.setPosition(0, 0);
component.setWidth(width);
component.layout(graphics);
- height = component.getHeight();
}
@Override
public boolean reconcileLayout(final Graphics graphics) {
final int oldHeight = height;
height = component.getHeight();
- return oldHeight != height;
+ if (oldHeight != height) {
+ layout(graphics);
+ return true;
+ }
+ return false;
}
@Override
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 97bd01a5..ba3bd4df 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
@@ -12,6 +12,7 @@ package org.eclipse.vex.core.internal.boxes;
import org.eclipse.vex.core.internal.core.Graphics;
import org.eclipse.vex.core.internal.core.Rectangle;
+import org.eclipse.vex.core.internal.core.TextAlign;
public class ListItem extends BaseBox implements IStructuralBox, IDecoratorBox<IStructuralBox> {
@@ -23,8 +24,11 @@ public class ListItem extends BaseBox implements IStructuralBox, IDecoratorBox<I
private int width;
private int height;
+ private IInlineBox bullet;
private int bulletWidth;
- private IStructuralBox bullet;
+ private TextAlign bulletAlign = TextAlign.RIGHT;
+
+ private Paragraph bulletContainer;
private IStructuralBox component;
private IVisualDecorator<IStructuralBox> visualDecorator;
@@ -105,12 +109,30 @@ public class ListItem extends BaseBox implements IStructuralBox, IDecoratorBox<I
return bulletWidth;
}
- public void setBullet(final IStructuralBox bullet) {
+ public void setBulletAlign(final TextAlign bulletAlign) {
+ this.bulletAlign = bulletAlign;
+ if (bulletContainer != null) {
+ bulletContainer.setTextAlign(bulletAlign);
+ }
+ }
+
+ public TextAlign getBulletAlign() {
+ return bulletAlign;
+ }
+
+ public void setBullet(final IInlineBox bullet) {
this.bullet = bullet;
- bullet.setParent(this);
+ if (bullet == null) {
+ bulletContainer = null;
+ } else {
+ bulletContainer = new Paragraph();
+ bulletContainer.setParent(this);
+ bulletContainer.setTextAlign(bulletAlign);
+ bulletContainer.appendChild(bullet);
+ }
}
- public IStructuralBox getBullet() {
+ public IInlineBox getBullet() {
return bullet;
}
@@ -126,9 +148,9 @@ public class ListItem extends BaseBox implements IStructuralBox, IDecoratorBox<I
@Override
public void layout(final Graphics graphics) {
- if (bullet != null) {
- bullet.setWidth(bulletWidth);
- bullet.layout(graphics);
+ if (bulletContainer != null) {
+ bulletContainer.setWidth(bulletWidth);
+ bulletContainer.layout(graphics);
}
if (component != null) {
@@ -136,7 +158,7 @@ public class ListItem extends BaseBox implements IStructuralBox, IDecoratorBox<I
component.layout(graphics);
}
- final int bulletBaseline = findTopBaselineRelativeToParent(bullet);
+ final int bulletBaseline = findTopBaselineRelativeToParent(bulletContainer);
final int componentBaseline = findTopBaselineRelativeToParent(component);
final int baselineDelta = componentBaseline - bulletBaseline;
@@ -150,8 +172,8 @@ public class ListItem extends BaseBox implements IStructuralBox, IDecoratorBox<I
componentTop = -baselineDelta;
}
- if (bullet != null) {
- bullet.setPosition(bulletTop, 0);
+ if (bulletContainer != null) {
+ bulletContainer.setPosition(bulletTop, 0);
}
if (component != null) {
component.setPosition(componentTop, width - component.getWidth());
@@ -246,15 +268,17 @@ public class ListItem extends BaseBox implements IStructuralBox, IDecoratorBox<I
}
private int getWidthForComponent() {
- if (bullet == null) {
+ if (bulletContainer == null) {
return width;
}
- return width - bullet.getWidth() - BULLET_SPACING;
+ return width - bulletWidth - BULLET_SPACING;
}
@Override
public void paint(final Graphics graphics) {
- ChildBoxPainter.paint(bullet, graphics);
+ if (bulletContainer != null) {
+ ChildBoxPainter.paint(bulletContainer, graphics);
+ }
ChildBoxPainter.paint(component, graphics);
}
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 c129f274..9a257bc3 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
@@ -16,7 +16,6 @@ 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;
@@ -42,6 +41,7 @@ import java.util.Set;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.vex.core.internal.boxes.Border;
import org.eclipse.vex.core.internal.boxes.DepthFirstBoxTraversal;
+import org.eclipse.vex.core.internal.boxes.IBulletFactory;
import org.eclipse.vex.core.internal.boxes.IInlineBox;
import org.eclipse.vex.core.internal.boxes.IParentBox;
import org.eclipse.vex.core.internal.boxes.IStructuralBox;
@@ -56,7 +56,6 @@ import org.eclipse.vex.core.internal.boxes.Padding;
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;
@@ -223,7 +222,7 @@ public class CssBasedBoxModelBuilder implements IBoxModelBuilder {
*/
private IStructuralBox visualizeAsList(final IElement element, final Styles styles, final Collection<VisualizeResult> childrenResults) {
- return list(visualizeAsBlock(element, styles, childrenResults), styles);
+ return list(visualizeAsBlock(element, styles, childrenResults), styles, visualizeBullet(styles));
}
/*
@@ -232,18 +231,14 @@ public class CssBasedBoxModelBuilder implements IBoxModelBuilder {
private IStructuralBox visualizeAsListItem(final IElement element, final Styles styles, final Collection<VisualizeResult> childrenResults) {
final BulletStyle bulletStyle = BulletStyle.fromStyles(styles);
- final int bulletWidth = 20;
- final int itemIndex = 0;
- final int itemCount = 1;
- final IInlineBox bullet = visualizeBullet(styles, bulletStyle, itemIndex, itemCount);
final IStructuralBox content = visualizeStructuralElementContent(element, styles, childrenResults);
switch (bulletStyle.position) {
case OUTSIDE:
- final IStructuralBox listItem = listItem(bulletWidth, paragraph(TextAlign.RIGHT, bullet), content);
- return wrapUpStructuralElementContent(element, styles, childrenResults, listItem);
+ return wrapUpStructuralElementContent(element, styles, childrenResults, listItem(content));
case INSIDE:
+ final IInlineBox bullet = visualizeBullet(styles).createBullet(bulletStyle, 0, 1);
content.setVisualDecorator(insertBulletIntoContent(bullet));
content.applyVisualDecorator();
return wrapUpStructuralElementContent(element, styles, childrenResults, content);
@@ -252,14 +247,19 @@ public class CssBasedBoxModelBuilder implements IBoxModelBuilder {
}
}
- private static IInlineBox visualizeBullet(final Styles styles, final BulletStyle bulletStyle, final int itemIndex, final int itemCount) {
- final IInlineBox bullet;
- if (bulletStyle.type.isTextual()) {
- bullet = staticText(bulletStyle.getBulletAsText(itemIndex, itemCount), styles);
- } else {
- bullet = square(styles);
- }
- return bullet;
+ private static IBulletFactory visualizeBullet(final Styles styles) {
+ return new IBulletFactory() {
+ @Override
+ public IInlineBox createBullet(final BulletStyle bulletStyle, final int itemIndex, final int itemCount) {
+ final IInlineBox bullet;
+ if (bulletStyle.type.isTextual()) {
+ bullet = staticText(bulletStyle.getBulletAsText(itemIndex, itemCount), styles);
+ } else {
+ bullet = square(styles);
+ }
+ return bullet;
+ }
+ };
}
private static IVisualDecorator<IStructuralBox> insertBulletIntoContent(final IInlineBox 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 74785b71..9d0465fc 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.IBulletFactory;
import org.eclipse.vex.core.internal.boxes.IInlineBox;
import org.eclipse.vex.core.internal.boxes.IStructuralBox;
import org.eclipse.vex.core.internal.boxes.Image;
@@ -61,9 +62,10 @@ public class CssBoxFactory {
return frame;
}
- public static List list(final IStructuralBox component, final Styles styles) {
+ public static List list(final IStructuralBox component, final Styles styles, final IBulletFactory bulletFactory) {
final List list = new List();
list.setBulletStyle(BulletStyle.fromStyles(styles));
+ list.setBulletFactory(bulletFactory);
list.setComponent(component);
return list;
}

Back to the top