Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Thienel2016-04-01 08:45:20 -0400
committerFlorian Thienel2016-04-01 08:45:20 -0400
commitac3e1e7daab1a0945b943837056ae9290d282e16 (patch)
tree328fbbadb861abff9bb66aed5115da98e5800ba0
parentfee523345ab9b5d56d8e69f2177c91d9b7396531 (diff)
downloadorg.eclipse.mylyn.docs.vex-ac3e1e7daab1a0945b943837056ae9290d282e16.tar.gz
org.eclipse.mylyn.docs.vex-ac3e1e7daab1a0945b943837056ae9290d282e16.tar.xz
org.eclipse.mylyn.docs.vex-ac3e1e7daab1a0945b943837056ae9290d282e16.zip
move column layout processing out of CssBasedBoxModelBuilder
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.java20
-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/ParentTraversal.java5
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/Table.java22
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableCell.java47
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableColumnLayout.java64
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableColumnSpec.java190
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableRow.java5
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableRowGroup.java12
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBasedBoxModelBuilder.java115
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/DOMVisualization.java6
15 files changed, 424 insertions, 81 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 deb1b834..13065169 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
@@ -61,6 +61,11 @@ public class BaseBoxVisitor implements IBoxVisitor {
}
@Override
+ public void visit(final TableColumnSpec box) {
+ // ignore
+ }
+
+ @Override
public void visit(final TableRow 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 09758c9a..80c9632c 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
@@ -71,6 +71,11 @@ public class BaseBoxVisitorWithResult<T> implements IBoxVisitorWithResult<T> {
}
@Override
+ public T visit(final TableColumnSpec box) {
+ return defaultValue;
+ }
+
+ @Override
public T visit(final TableRow 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 36d18c22..4e33052b 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
@@ -142,27 +142,35 @@ public class BoxFactory {
return listItem;
}
- public static Table table(final TableColumnLayout columnLayout, final IStructuralBox... children) {
+ public static Table table(final IStructuralBox... children) {
final Table table = new Table();
- table.setColumnLayout(columnLayout);
for (final IStructuralBox child : children) {
table.appendChild(child);
}
return table;
}
- public static TableRowGroup tableRowGroup(final TableColumnLayout columnLayout, final IStructuralBox... children) {
+ public static TableRowGroup tableRowGroup(final IStructuralBox... children) {
final TableRowGroup tableRowGroup = new TableRowGroup();
- tableRowGroup.setColumnLayout(columnLayout);
for (final IStructuralBox child : children) {
tableRowGroup.appendChild(child);
}
return tableRowGroup;
}
- public static TableRow tableRow(final TableColumnLayout columnLayout, final IStructuralBox... children) {
+ public static TableColumnSpec tableColumnSpec(final String name, final int startIndex, final int endIndex, final String startName, final String endName, final IStructuralBox component) {
+ final TableColumnSpec tableColumnSpec = new TableColumnSpec();
+ tableColumnSpec.setName(name);
+ tableColumnSpec.setStartIndex(startIndex);
+ tableColumnSpec.setEndIndex(endIndex);
+ tableColumnSpec.setStartName(startName);
+ tableColumnSpec.setEndName(endName);
+ tableColumnSpec.setComponent(component);
+ return tableColumnSpec;
+ }
+
+ public static TableRow tableRow(final IStructuralBox... children) {
final TableRow tableRow = new TableRow();
- tableRow.setColumnLayout(columnLayout);
for (final IStructuralBox child : children) {
tableRow.appendChild(child);
}
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 b4b2d708..ac6a63ca 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
@@ -60,6 +60,11 @@ public abstract class DepthFirstBoxTraversal<T> extends BaseBoxVisitorWithResult
}
@Override
+ public T visit(final TableColumnSpec box) {
+ return box.getComponent().accept(this);
+ }
+
+ @Override
public T visit(final TableRow 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 7209f9e6..1fee015c 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
@@ -33,6 +33,8 @@ public interface IBoxVisitor {
void visit(TableRowGroup box);
+ void visit(TableColumnSpec box);
+
void visit(TableRow box);
void visit(TableCell 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 583a140c..a3ee58d8 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
@@ -33,6 +33,8 @@ public interface IBoxVisitorWithResult<T> {
T visit(TableRowGroup box);
+ T visit(TableColumnSpec box);
+
T visit(TableRow box);
T visit(TableCell 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 f5d41a20..079b025b 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
@@ -71,6 +71,11 @@ public class ParentTraversal<T> implements IBoxVisitorWithResult<T> {
}
@Override
+ public T visit(final TableColumnSpec box) {
+ return box.getParent().accept(this);
+ }
+
+ @Override
public T visit(final TableRow box) {
return box.getParent().accept(this);
}
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/Table.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/Table.java
index 54c58322..89ab6e2c 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/Table.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/Table.java
@@ -140,15 +140,24 @@ public class Table extends BaseBox implements IStructuralBox, IParentBox<IStruct
return children;
}
+ public void setColumnLayout(final TableColumnLayout columnLayout) {
+ if (columnLayout == null) {
+ this.columnLayout = new TableColumnLayout();
+ } else {
+ this.columnLayout = columnLayout;
+ }
+ }
+
public TableColumnLayout getColumnLayout() {
return columnLayout;
}
- public void setColumnLayout(final TableColumnLayout columnLayout) {
- this.columnLayout = columnLayout;
+ public void layout(final Graphics graphics) {
+ layoutColumns(graphics);
+ layoutChildren(graphics);
}
- public void layout(final Graphics graphics) {
+ private void layoutChildren(final Graphics graphics) {
height = 0;
for (int i = 0; i < children.size(); i += 1) {
final IStructuralBox child = children.get(i);
@@ -159,6 +168,13 @@ public class Table extends BaseBox implements IStructuralBox, IParentBox<IStruct
}
}
+ private void layoutColumns(final Graphics graphics) {
+ if (columnLayout.getLastIndex() > 0) {
+ columnLayout = new TableColumnLayout(columnLayout.getParentLayout());
+ }
+ TableColumnLayout.addColumnLayoutInformationForChildren(graphics, this, columnLayout);
+ }
+
@Override
public boolean reconcileLayout(final Graphics graphics) {
final int oldHeight = height;
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableCell.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableCell.java
index 23d2fdad..b0576fd8 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableCell.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableCell.java
@@ -29,8 +29,11 @@ public class TableCell extends BaseBox implements IStructuralBox, IParentBox<ISt
private int height;
private final ArrayList<IStructuralBox> children = new ArrayList<IStructuralBox>();
- private int startColumn;
- private int endColumn;
+ private int startColumnIndex;
+ private int endColumnIndex;
+ private String columnName;
+ private String startColumnName;
+ private String endColumnName;
@Override
public void setParent(final IBox parent) {
@@ -141,20 +144,44 @@ public class TableCell extends BaseBox implements IStructuralBox, IParentBox<ISt
return children;
}
- public int getStartColumn() {
- return startColumn;
+ public int getStartColumnIndex() {
+ return startColumnIndex;
}
- public void setStartColumn(final int startColumn) {
- this.startColumn = startColumn;
+ public void setStartColumnIndex(final int startColumnIndex) {
+ this.startColumnIndex = startColumnIndex;
}
- public int getEndColumn() {
- return endColumn;
+ public int getEndColumnIndex() {
+ return endColumnIndex;
}
- public void setEndColumn(final int endColumn) {
- this.endColumn = endColumn;
+ public void setEndColumnIndex(final int endColumnIndex) {
+ this.endColumnIndex = endColumnIndex;
+ }
+
+ public String getColumnName() {
+ return columnName;
+ }
+
+ public void setColumnName(final String columnName) {
+ this.columnName = columnName;
+ }
+
+ public String getStartColumnName() {
+ return startColumnName;
+ }
+
+ public void setStartColumnName(final String startColumnName) {
+ this.startColumnName = startColumnName;
+ }
+
+ public String getEndColumnName() {
+ return endColumnName;
+ }
+
+ public void setEndColumnName(final String endColumnName) {
+ this.endColumnName = endColumnName;
}
public void layout(final Graphics graphics) {
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableColumnLayout.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableColumnLayout.java
index f3c2a8aa..885bcfe5 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableColumnLayout.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableColumnLayout.java
@@ -12,6 +12,8 @@ package org.eclipse.vex.core.internal.boxes;
import java.util.HashMap;
+import org.eclipse.vex.core.internal.core.Graphics;
+
/**
* @author Florian Thienel
*/
@@ -23,6 +25,68 @@ public class TableColumnLayout {
private int lastIndex;
private final HashMap<String, Span> indexByName = new HashMap<String, Span>();
+ public static void addColumnLayoutInformationForChildren(final Graphics graphics, final IStructuralBox parent, final TableColumnLayout parentColumnLayout) {
+ parent.accept(new DepthFirstBoxTraversal<Object>() {
+ @Override
+ public Object visit(final Table box) {
+ if (box == parent) {
+ traverseChildren(box);
+ } else {
+ box.setColumnLayout(new TableColumnLayout(parentColumnLayout));
+ }
+ return null;
+ }
+
+ @Override
+ public Object visit(final TableRowGroup box) {
+ if (box == parent) {
+ traverseChildren(box);
+ } else {
+ box.setColumnLayout(new TableColumnLayout(parentColumnLayout));
+ }
+ return null;
+ }
+
+ @Override
+ public Object visit(final TableColumnSpec box) {
+ if (box.getStartName() != null) {
+ box.setStartIndex(parentColumnLayout.getIndex(box.getStartName()));
+ }
+ if (box.getEndName() != null) {
+ box.setEndIndex(parentColumnLayout.getIndex(box.getEndName()));
+ }
+ if (box.getStartIndex() == box.getEndIndex()) {
+ parentColumnLayout.addColumn(box.getStartIndex(), box.getName(), box.getWidthExpression());
+ } else {
+ parentColumnLayout.addSpan(box.getStartIndex(), box.getEndIndex(), box.getName());
+ }
+ return null;
+ }
+
+ @Override
+ public Object visit(final TableRow box) {
+ if (box == parent) {
+ traverseChildren(box);
+ } else {
+ box.setColumnLayout(parentColumnLayout);
+ }
+ return null;
+ }
+
+ @Override
+ public Object visit(final TableCell box) {
+ if (box.getColumnName() != null) {
+ box.setStartColumnIndex(parentColumnLayout.getStartIndex(box.getColumnName()));
+ box.setEndColumnIndex(parentColumnLayout.getEndIndex(box.getColumnName()));
+ } else if (box.getStartColumnName() != null && box.getEndColumnName() != null) {
+ box.setStartColumnIndex(parentColumnLayout.getIndex(box.getStartColumnName()));
+ box.setEndColumnIndex(parentColumnLayout.getIndex(box.getEndColumnName()));
+ }
+ return null;
+ }
+ });
+ }
+
public TableColumnLayout() {
this(null);
}
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableColumnSpec.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableColumnSpec.java
new file mode 100644
index 00000000..0a6e008b
--- /dev/null
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableColumnSpec.java
@@ -0,0 +1,190 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * @author Florian Thienel
+ */
+public class TableColumnSpec extends BaseBox implements IStructuralBox, IDecoratorBox<IStructuralBox> {
+
+ private IBox parent;
+ private int top;
+ private int left;
+ private int width;
+ private int height;
+
+ private IStructuralBox component;
+
+ private String name;
+ private int startIndex;
+ private int endIndex;
+ private String startName;
+ private String endName;
+ private String widthExpression;
+
+ @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;
+ }
+
+ @Override
+ public int getTop() {
+ return top;
+ }
+
+ @Override
+ public int getLeft() {
+ return left;
+ }
+
+ @Override
+ public void setPosition(final int top, final int left) {
+ this.top = top;
+ this.left = left;
+ }
+
+ @Override
+ public int getWidth() {
+ return width;
+ }
+
+ @Override
+ 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);
+ }
+
+ @Override
+ public void setComponent(final IStructuralBox component) {
+ this.component = component;
+ component.setParent(this);
+ }
+
+ @Override
+ public IStructuralBox getComponent() {
+ return component;
+ }
+
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setStartIndex(final int startIndex) {
+ this.startIndex = startIndex;
+ }
+
+ public int getStartIndex() {
+ return startIndex;
+ }
+
+ public void setEndIndex(final int endIndex) {
+ this.endIndex = endIndex;
+ }
+
+ public int getEndIndex() {
+ return endIndex;
+ }
+
+ public void setStartName(final String startName) {
+ this.startName = startName;
+ }
+
+ public String getStartName() {
+ return startName;
+ }
+
+ public void setEndName(final String endName) {
+ this.endName = endName;
+ }
+
+ public String getEndName() {
+ return endName;
+ }
+
+ public void setWidthExpression(final String widthExpression) {
+ this.widthExpression = widthExpression;
+ }
+
+ public String getWidthExpression() {
+ return widthExpression;
+ }
+
+ @Override
+ public void layout(final Graphics graphics) {
+ if (component == null) {
+ return;
+ }
+ 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;
+ }
+
+ @Override
+ public void paint(final Graphics graphics) {
+ ChildBoxPainter.paint(component, graphics);
+ }
+
+}
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableRow.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableRow.java
index 7a418f63..9a45acea 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableRow.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableRow.java
@@ -153,6 +153,7 @@ public class TableRow extends BaseBox implements IStructuralBox, IParentBox<IStr
}
public void layout(final Graphics graphics) {
+ TableColumnLayout.addColumnLayoutInformationForChildren(graphics, this, columnLayout);
height = 0;
int columnIndex = 1;
for (int i = 0; i < children.size(); i += 1) {
@@ -191,7 +192,7 @@ public class TableRow extends BaseBox implements IStructuralBox, IParentBox<IStr
final int boxStartColumn = box.accept(new BaseBoxVisitorWithResult<Integer>(0) {
@Override
public Integer visit(final TableCell box) {
- return box.getStartColumn();
+ return box.getStartColumnIndex();
}
});
if (boxStartColumn > 0) {
@@ -204,7 +205,7 @@ public class TableRow extends BaseBox implements IStructuralBox, IParentBox<IStr
final int boxEndColumn = box.accept(new BaseBoxVisitorWithResult<Integer>(0) {
@Override
public Integer visit(final TableCell box) {
- return box.getEndColumn();
+ return box.getEndColumnIndex();
}
});
if (boxEndColumn > 0) {
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableRowGroup.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableRowGroup.java
index 11071d7d..cce9f7d5 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableRowGroup.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableRowGroup.java
@@ -149,6 +149,18 @@ public class TableRowGroup extends BaseBox implements IStructuralBox, IParentBox
}
public void layout(final Graphics graphics) {
+ layoutColumns(graphics);
+ layoutChildren(graphics);
+ }
+
+ private void layoutColumns(final Graphics graphics) {
+ if (columnLayout.getLastIndex() > 0) {
+ columnLayout = new TableColumnLayout(columnLayout.getParentLayout());
+ }
+ TableColumnLayout.addColumnLayoutInformationForChildren(graphics, this, columnLayout);
+ }
+
+ private void layoutChildren(final Graphics graphics) {
height = 0;
for (int i = 0; i < children.size(); i += 1) {
final IStructuralBox child = children.get(i);
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 5aa83c53..1709b3f0 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
@@ -18,6 +18,7 @@ import static org.eclipse.vex.core.internal.boxes.BoxFactory.nodeReferenceWithTe
import static org.eclipse.vex.core.internal.boxes.BoxFactory.rootBox;
import static org.eclipse.vex.core.internal.boxes.BoxFactory.table;
import static org.eclipse.vex.core.internal.boxes.BoxFactory.tableCell;
+import static org.eclipse.vex.core.internal.boxes.BoxFactory.tableColumnSpec;
import static org.eclipse.vex.core.internal.boxes.BoxFactory.tableRow;
import static org.eclipse.vex.core.internal.boxes.BoxFactory.tableRowGroup;
import static org.eclipse.vex.core.internal.boxes.BoxFactory.verticalBlock;
@@ -52,7 +53,7 @@ import org.eclipse.vex.core.internal.boxes.Paragraph;
import org.eclipse.vex.core.internal.boxes.RootBox;
import org.eclipse.vex.core.internal.boxes.Table;
import org.eclipse.vex.core.internal.boxes.TableCell;
-import org.eclipse.vex.core.internal.boxes.TableColumnLayout;
+import org.eclipse.vex.core.internal.boxes.TableColumnSpec;
import org.eclipse.vex.core.internal.boxes.TableRow;
import org.eclipse.vex.core.internal.boxes.TableRowGroup;
import org.eclipse.vex.core.internal.boxes.TextContent;
@@ -132,8 +133,6 @@ public class CssBasedBoxModelBuilder implements IBoxModelBuilder {
private VisualizeResult visualize(final INode node) {
return node.accept(new CollectingNodeTraversal<VisualizeResult>() {
- private TableColumnLayout currentColumnLayout = null;
-
@Override
public VisualizeResult visit(final IDocument document) {
final Styles styles = styleSheet.getStyles(document);
@@ -151,40 +150,26 @@ public class CssBasedBoxModelBuilder implements IBoxModelBuilder {
@Override
public VisualizeResult visit(final IElement element) {
final Styles styles = styleSheet.getStyles(element);
+ final Collection<VisualizeResult> childrenResults = traverseChildren(element);
if (isTable(styles)) {
- pushColumnLayout();
- final Collection<VisualizeResult> childrenResults = traverseChildren(element);
- final Table table = visualizeAsTable(element, styles, childrenResults, currentColumnLayout);
- popColumnLayout();
-
+ final Table table = visualizeAsTable(element, styles, childrenResults);
return new VisualizeResult(element, styles, childrenResults, table);
} else if (isTableRowGroup(styles)) {
- pushColumnLayout();
- final Collection<VisualizeResult> childrenResults = traverseChildren(element);
- final TableRowGroup rowGroup = visualizeAsTableRowGroup(element, styles, childrenResults, currentColumnLayout);
- popColumnLayout();
-
+ final TableRowGroup rowGroup = visualizeAsTableRowGroup(element, styles, childrenResults);
return new VisualizeResult(element, styles, childrenResults, rowGroup);
- } else if (isTableColSpec(styles, element)) {
- final Collection<VisualizeResult> childrenResults = traverseChildren(element);
- return new VisualizeResult(element, styles, childrenResults, visualizeAsTableColSpec(element, styles, childrenResults, currentColumnLayout));
+ } else if (isTableColumnSpec(styles, element)) {
+ return new VisualizeResult(element, styles, childrenResults, visualizeAsTableColumnSpec(element, styles, childrenResults));
} else if (isTableRow(styles)) {
- final Collection<VisualizeResult> childrenResults = traverseChildren(element);
- return new VisualizeResult(element, styles, childrenResults, visualizeAsTableRow(element, styles, childrenResults, currentColumnLayout));
+ return new VisualizeResult(element, styles, childrenResults, visualizeAsTableRow(element, styles, childrenResults));
} else if (isTableCell(styles)) {
- final Collection<VisualizeResult> childrenResults = traverseChildren(element);
- return new VisualizeResult(element, styles, childrenResults, visualizeAsTableCell(element, styles, childrenResults, currentColumnLayout));
+ return new VisualizeResult(element, styles, childrenResults, visualizeAsTableCell(element, styles, childrenResults));
} else if (isListRoot(styles)) {
- final Collection<VisualizeResult> childrenResults = traverseChildren(element);
return new VisualizeResult(element, styles, childrenResults, visualizeAsList(element, styles, childrenResults));
} else if (isListItem(styles)) {
- final Collection<VisualizeResult> childrenResults = traverseChildren(element);
return new VisualizeResult(element, styles, childrenResults, visualizeAsListItem(element, styles, childrenResults));
} else if (isDisplayedAsBlock(styles)) {
- final Collection<VisualizeResult> childrenResults = traverseChildren(element);
return new VisualizeResult(element, styles, childrenResults, visualizeAsBlock(element, styles, childrenResults));
} else {
- final Collection<VisualizeResult> childrenResults = traverseChildren(element);
return new VisualizeResult(element, styles, childrenResults, visualizeInline(element, styles, childrenResults));
}
}
@@ -217,18 +202,6 @@ public class CssBasedBoxModelBuilder implements IBoxModelBuilder {
final List<VisualizeResult> childrenResults = Collections.<VisualizeResult> emptyList();
return new VisualizeResult(text, styles, childrenResults, visualizeInline(text, styles, childrenResults));
}
-
- private void pushColumnLayout() {
- currentColumnLayout = new TableColumnLayout(currentColumnLayout);
- }
-
- private TableColumnLayout popColumnLayout() {
- final TableColumnLayout columnLayout = currentColumnLayout;
- if (currentColumnLayout != null) {
- currentColumnLayout = currentColumnLayout.getParentLayout();
- }
- return columnLayout;
- }
});
}
@@ -259,7 +232,7 @@ public class CssBasedBoxModelBuilder implements IBoxModelBuilder {
return CSS.TABLE_CELL.equals(styles.getDisplay());
}
- private static boolean isTableColSpec(final Styles styles, final IElement element) {
+ private static boolean isTableColumnSpec(final Styles styles, final IElement element) {
return CSS.TABLE_COLUMN.equals(styles.getDisplay())
|| "colspec".equals(element.getLocalName())
|| "spanspec".equals(element.getLocalName())
@@ -286,51 +259,73 @@ public class CssBasedBoxModelBuilder implements IBoxModelBuilder {
/*
* Render as Table
*/
- private Table visualizeAsTable(final IElement element, final Styles styles, final Collection<VisualizeResult> childrenResults, final TableColumnLayout columnLayout) {
- return table(columnLayout, visualizeAsBlock(element, styles, childrenResults));
+ private Table visualizeAsTable(final IElement element, final Styles styles, final Collection<VisualizeResult> childrenResults) {
+ return table(visualizeAsBlock(element, styles, childrenResults));
}
- private TableRowGroup visualizeAsTableRowGroup(final IElement element, final Styles styles, final Collection<VisualizeResult> childrenResults, final TableColumnLayout columnLayout) {
- return tableRowGroup(columnLayout, visualizeAsBlock(element, styles, childrenResults));
+ private TableRowGroup visualizeAsTableRowGroup(final IElement element, final Styles styles, final Collection<VisualizeResult> childrenResults) {
+ return tableRowGroup(visualizeAsBlock(element, styles, childrenResults));
}
- private IStructuralBox visualizeAsTableColSpec(final IElement element, final Styles styles, final Collection<VisualizeResult> childrenResults, final TableColumnLayout columnLayout) {
+ private TableColumnSpec visualizeAsTableColumnSpec(final IElement element, final Styles styles, final Collection<VisualizeResult> childrenResults) {
+ final String name;
+ final int startIndex;
+ final int endIndex;
+ final String startName;
+ final String endName;
+
if ("colspec".equals(element.getLocalName())) {
- final int index = toInt(element.getAttribute("colnum"));
- final String name = toString(element.getAttribute("colname"));
- columnLayout.addColumn(index, name, null);
+ name = toString(element.getAttribute("colname"));
+ startIndex = toInt(element.getAttribute("colnum"));
+ endIndex = startIndex;
+ startName = null;
+ endName = null;
} else if ("spanspec".equals(element.getLocalName())) {
- // TODO CALS span
+ name = toString(element.getAttribute("spanname"));
+ startIndex = 0;
+ endIndex = 0;
+ startName = toString(element.getAttribute("namest"));
+ endName = toString(element.getAttribute("nameend"));
} else if ("col".equals(element.getLocalName())) {
// TODO HTML table
+ name = null;
+ startIndex = 0;
+ endIndex = 0;
+ startName = null;
+ endName = null;
+ } else {
+ name = null;
+ startIndex = 0;
+ endIndex = 0;
+ startName = null;
+ endName = null;
}
- return visualizeAsBlock(element, styles, childrenResults);
+ return tableColumnSpec(name, startIndex, endIndex, startName, endName, visualizeAsBlock(element, styles, childrenResults));
}
- private IStructuralBox visualizeAsTableRow(final IElement element, final Styles styles, final Collection<VisualizeResult> childrenResults, final TableColumnLayout columnLayout) {
- final TableRow row = visualizeChildrenAsStructure(element, styles, childrenResults, tableRow(columnLayout));
+ private IStructuralBox visualizeAsTableRow(final IElement element, final Styles styles, final Collection<VisualizeResult> childrenResults) {
+ final TableRow row = visualizeChildrenAsStructure(element, styles, childrenResults, tableRow());
return wrapUpStructuralElementContent(element, styles, childrenResults, row);
}
- private TableCell visualizeAsTableCell(final IElement element, final Styles styles, final Collection<VisualizeResult> childrenResults, final TableColumnLayout columnLayout) {
+ private TableCell visualizeAsTableCell(final IElement element, final Styles styles, final Collection<VisualizeResult> childrenResults) {
final TableCell cell = tableCell(visualizeAsBlock(element, styles, childrenResults));
if ("entry".equals(element.getLocalName())) {
final IAttribute colName = element.getAttribute("colname");
final IAttribute spanName = element.getAttribute("spanname");
- final IAttribute nameStart = element.getAttribute("namest");
- final IAttribute nameEnd = element.getAttribute("nameend");
if (colName != null) {
- final int columnIndex = columnLayout.getIndex(colName.getValue());
- cell.setStartColumn(columnIndex);
- cell.setEndColumn(columnIndex);
+ cell.setColumnName(colName.getValue());
} else if (spanName != null) {
- cell.setStartColumn(columnLayout.getStartIndex(spanName.getValue()));
- cell.setEndColumn(columnLayout.getEndIndex(spanName.getValue()));
- } else if (nameStart != null && nameEnd != null) {
- cell.setStartColumn(columnLayout.getStartIndex(nameStart.getValue()));
- cell.setEndColumn(columnLayout.getEndIndex(nameEnd.getValue()));
+ cell.setColumnName(spanName.getValue());
+ }
+
+ final IAttribute nameStart = element.getAttribute("namest");
+ final IAttribute nameEnd = element.getAttribute("nameend");
+ if (nameStart != null && nameEnd != null) {
+ cell.setStartColumnName(nameStart.getValue());
+ cell.setEndColumnName(nameEnd.getValue());
}
} else if ("th".equals(element.getLocalName()) || "td".equals(element.getLocalName())) {
// TODO HTML table
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 bbfa746c..4c6bbcdd 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
@@ -30,6 +30,7 @@ import org.eclipse.vex.core.internal.boxes.StructuralFrame;
import org.eclipse.vex.core.internal.boxes.StructuralNodeReference;
import org.eclipse.vex.core.internal.boxes.Table;
import org.eclipse.vex.core.internal.boxes.TableCell;
+import org.eclipse.vex.core.internal.boxes.TableColumnSpec;
import org.eclipse.vex.core.internal.boxes.TableRow;
import org.eclipse.vex.core.internal.boxes.TableRowGroup;
import org.eclipse.vex.core.internal.boxes.TextContent;
@@ -151,6 +152,11 @@ public class DOMVisualization {
}
@Override
+ public void visit(final TableColumnSpec box) {
+ box.setComponent(boxModelBuilder.visualizeStructure(node));
+ }
+
+ @Override
public void visit(final TableRow box) {
box.replaceChildren(modifiedBoxes, boxModelBuilder.visualizeStructure(node));
}

Back to the top