Added Unit Tests to Suite for easier running
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/VEXCorePlugin.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/VEXCorePlugin.java
index 4680695..d84b61f 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/VEXCorePlugin.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/VEXCorePlugin.java
@@ -16,24 +16,24 @@
public class VEXCorePlugin extends AbstractUIPlugin {
- private static VEXCorePlugin instance;
-
- public VEXCorePlugin() {
- instance = this;
- }
-
- /**
- * Returns the shared instance.
- */
- public static VEXCorePlugin getInstance() {
- return instance;
- }
-
- public void start(BundleContext bundleContext) throws Exception {
- super.start(bundleContext);
- }
+ private static VEXCorePlugin instance;
- public void stop(BundleContext context) throws Exception {
- super.stop(context);
- }
+ public VEXCorePlugin() {
+ instance = this;
+ }
+
+ /**
+ * Returns the shared instance.
+ */
+ public static VEXCorePlugin getInstance() {
+ return instance;
+ }
+
+ public void start(BundleContext bundleContext) throws Exception {
+ super.start(bundleContext);
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ super.stop(context);
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/AbstractVexAction.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/AbstractVexAction.java
index da0e86e..1737530 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/AbstractVexAction.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/AbstractVexAction.java
@@ -13,22 +13,22 @@
import org.eclipse.wst.xml.vex.core.internal.widget.IVexWidget;
/**
- * Abstract Vex action. This class provides default implementations for
- * all methods in IVexAction except for <code>run</code>.
+ * Abstract Vex action. This class provides default implementations for all
+ * methods in IVexAction except for <code>run</code>.
*/
public abstract class AbstractVexAction implements IVexAction {
- /**
- * Class constructor.
- */
- public AbstractVexAction() {
- }
+ /**
+ * Class constructor.
+ */
+ public AbstractVexAction() {
+ }
- /**
- * Returns <code>true</code>.
- */
- public boolean isEnabled(IVexWidget vexWidget) {
- return true;
- }
+ /**
+ * Returns <code>true</code>.
+ */
+ public boolean isEnabled(IVexWidget vexWidget) {
+ return true;
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/ActionUtils.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/ActionUtils.java
index d757ef2..92929d3 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/ActionUtils.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/ActionUtils.java
@@ -27,468 +27,535 @@
import org.eclipse.wst.xml.vex.core.internal.widget.IBoxFilter;
import org.eclipse.wst.xml.vex.core.internal.widget.IVexWidget;
-
/**
* Static helper methods used across actions.
*/
public class ActionUtils {
- public static class RowColumnInfo {
- public Object row;
- public Object cell;
- public int rowIndex;
- public int cellIndex;
- public int rowCount;
- public int columnCount;
- public int maxColumnCount;
- }
+ public static class RowColumnInfo {
+ public Object row;
+ public Object cell;
+ public int rowIndex;
+ public int cellIndex;
+ public int rowCount;
+ public int columnCount;
+ public int maxColumnCount;
+ }
- /**
- * Clone the table cells from the given TableRowBox to the current offset in vexWidget.
- * @param vexWidget IVexWidget to modify.
- * @param tr TableRowBox whose cells are to be cloned.
- * @param moveToFirstCell TODO
- */
- public static void cloneTableCells(final IVexWidget vexWidget, final TableRowBox tr, final boolean moveToFirstCell) {
- vexWidget.doWork(new Runnable() {
- public void run() {
-
- int offset = vexWidget.getCaretOffset();
-
- boolean firstCellIsAnonymous = false;
- Box[] cells = tr.getChildren();
- for (int i = 0; i < cells.length; i++) {
- if (cells[i].isAnonymous()) {
- vexWidget.insertText(" ");
- if (i == 0) {
- firstCellIsAnonymous = true;
- }
- } else {
- vexWidget.insertElement((Element) cells[i].getElement().clone());
- vexWidget.moveBy(+1);
- }
- }
-
- if (moveToFirstCell) {
- vexWidget.moveTo(offset + 1);
- if (firstCellIsAnonymous) {
- vexWidget.moveBy(-1, true);
- }
- }
- }
- });
- }
-
- /**
- * Duplicate the given table row, inserting a new empty one below it. The new
- * row contains empty children corresponding to the given row's children.
- * @param vexWidget IVexWidget with which we're working
- * @param tr TableRowBox to be duplicated.
- */
- public static void duplicateTableRow(final IVexWidget vexWidget, final TableRowBox tr) {
- vexWidget.doWork(new Runnable() {
- public void run() {
-
- vexWidget.moveTo(tr.getEndOffset());
-
- if (!tr.isAnonymous()) {
- vexWidget.moveBy(+1); // Move past sentinel in current row
- vexWidget.insertElement((Element) tr.getElement().clone());
- }
+ /**
+ * Clone the table cells from the given TableRowBox to the current offset in
+ * vexWidget.
+ *
+ * @param vexWidget
+ * IVexWidget to modify.
+ * @param tr
+ * TableRowBox whose cells are to be cloned.
+ * @param moveToFirstCell
+ * TODO
+ */
+ public static void cloneTableCells(final IVexWidget vexWidget,
+ final TableRowBox tr, final boolean moveToFirstCell) {
+ vexWidget.doWork(new Runnable() {
+ public void run() {
- cloneTableCells(vexWidget, tr, true);
- }
- });
- }
+ int offset = vexWidget.getCaretOffset();
- /**
- * Returns true if the given element or range is at least partially selected.
- *
- * @param vexWidget IVexWidget being tested.
- * @param elementOrRange Element or IntRange being tested.
- */
- public static boolean elementOrRangeIsPartiallySelected(IVexWidget vexWidget, Object elementOrRange) {
- IntRange range = getInnerRange(elementOrRange);
- return range.getEnd() >= vexWidget.getSelectionStart()
- && range.getStart() <= vexWidget.getSelectionEnd();
- }
-
- /**
- * Returns the zero-based index of the table column containing the
- * current offset. Returns -1 if we are not inside a table.
- */
- public static int getCurrentColumnIndex(IVexWidget vexWidget) {
-
- Element row = getCurrentTableRow(vexWidget);
-
- if (row == null) {
- return -1;
- }
-
- final int offset = vexWidget.getCaretOffset();
- final int[] column = new int[] { -1 };
- LayoutUtils.iterateTableCells(vexWidget.getStyleSheet(), row, new ElementOrRangeCallback() {
- private int i = 0;
- public void onElement(Element child, String displayStyle) {
- if (offset > child.getStartOffset() && offset <= child.getEndOffset()) {
- column[0] = i;
- }
- i++;
- }
- public void onRange(Element parent, int startOffset, int endOffset) {
- i++;
- }
- });
-
- return column[0];
- }
+ boolean firstCellIsAnonymous = false;
+ Box[] cells = tr.getChildren();
+ for (int i = 0; i < cells.length; i++) {
+ if (cells[i].isAnonymous()) {
+ vexWidget.insertText(" ");
+ if (i == 0) {
+ firstCellIsAnonymous = true;
+ }
+ } else {
+ vexWidget.insertElement((Element) cells[i].getElement()
+ .clone());
+ vexWidget.moveBy(+1);
+ }
+ }
- /**
- * Returns the innermost Element with style table-row containing the caret,
- * or null if no such element exists.
- * @param vexWidget IVexWidget to use.
- */
- public static Element getCurrentTableRow(IVexWidget vexWidget) {
-
- StyleSheet ss = vexWidget.getStyleSheet();
- Element element = vexWidget.getCurrentElement();
-
- while (element != null) {
- if (ss.getStyles(element).getDisplay().equals(CSS.TABLE_ROW)) {
- return element;
- }
- element = element.getParent();
- }
+ if (moveToFirstCell) {
+ vexWidget.moveTo(offset + 1);
+ if (firstCellIsAnonymous) {
+ vexWidget.moveBy(-1, true);
+ }
+ }
+ }
+ });
+ }
- return null;
- }
-
- /**
- * Returns the start offset of the next sibling of the parent element.
- * Returns -1 if there is no previous sibling in the parent.
- * @param vexWidget VexWidget to use.
- */
- public static int getPreviousSiblingStart(IVexWidget vexWidget) {
- int startOffset;
-
- if (vexWidget.hasSelection()) {
- startOffset = vexWidget.getSelectionStart();
- } else {
- Box box = vexWidget.findInnermostBox(new IBoxFilter() {
- public boolean matches(Box box) {
- return box instanceof BlockBox
- && box.getElement() != null;
- }
- });
-
- if (box.getElement() == vexWidget.getDocument().getRootElement()) {
- return -1;
- }
-
- startOffset = box.getElement().getStartOffset();
- }
-
- int previousSiblingStart = -1;
- Element parent = vexWidget.getDocument().getElementAt(startOffset);
- Node[] children = parent.getChildNodes();
- for (int i = 0; i < children.length; i++) {
- Node child = children[i];
- if (startOffset == child.getStartOffset()) {
- break;
- }
- previousSiblingStart = child.getStartOffset();
- }
- return previousSiblingStart;
- }
+ /**
+ * Duplicate the given table row, inserting a new empty one below it. The
+ * new row contains empty children corresponding to the given row's
+ * children.
+ *
+ * @param vexWidget
+ * IVexWidget with which we're working
+ * @param tr
+ * TableRowBox to be duplicated.
+ */
+ public static void duplicateTableRow(final IVexWidget vexWidget,
+ final TableRowBox tr) {
+ vexWidget.doWork(new Runnable() {
+ public void run() {
- /**
- * Returns an array of the selected block boxes. Text nodes between boxes
- * are not returned. If the selection does not enclose any block boxes,
- * returns an empty array.
- * @param vexWidget VexWidget to use.
- */
- public static BlockBox[] getSelectedBlockBoxes(final IVexWidget vexWidget) {
-
- if (!vexWidget.hasSelection()) {
- return new BlockBox[0];
- }
-
- Box parent = vexWidget.findInnermostBox(new IBoxFilter() {
- public boolean matches(Box box) {
- System.out.println("Matching " + box);
- return box instanceof BlockBox
- && box.getStartOffset() <= vexWidget.getSelectionStart()
- && box.getEndOffset() >= vexWidget.getSelectionEnd();
- }
- });
-
- System.out.println("Matched " + parent);
-
- List blockList = new ArrayList();
-
- Box[] children = parent.getChildren();
- System.out.println("Parent has " + children.length + " children");
- for (int i = 0; i < children.length; i++) {
- Box child = children[i];
- if (child instanceof BlockBox
- && child.getStartOffset() >= vexWidget.getSelectionStart()
- && child.getEndOffset() <= vexWidget.getSelectionEnd()) {
- System.out.println(" adding " + child);
- blockList.add(child);
- } else {
- System.out.println(" skipping " + child);
- }
-
- }
-
- return (BlockBox[]) blockList.toArray(new BlockBox[blockList.size()]);
- }
+ vexWidget.moveTo(tr.getEndOffset());
- /**
- * Returns the currently selected table rows, or the current row if
- * ther is no selection. If no row can be found, returns an empty array.
- * @param vexWidget IVexWidget to use.
- */
- public static SelectedRows getSelectedTableRows(final IVexWidget vexWidget) {
-
- final SelectedRows selected = new SelectedRows();
-
- ActionUtils.iterateTableCells(vexWidget, new TableCellCallback() {
- public void startRow(Object row, int rowIndex) {
- if (ActionUtils.elementOrRangeIsPartiallySelected(vexWidget, row)) {
- if (selected.rows == null) {
- selected.rows = new ArrayList();
- }
- selected.rows.add(row);
- } else {
- if (selected.rows == null) {
- selected.rowBefore = row;
- } else {
- if (selected.rowAfter == null) {
- selected.rowAfter = row;
- }
- }
- }
- }
- public void onCell(Object row, Object cell, int rowIndex, int cellIndex) {
- }
- public void endRow(Object row, int rowIndex) {
- }
- });
-
- return selected;
- }
+ if (!tr.isAnonymous()) {
+ vexWidget.moveBy(+1); // Move past sentinel in current row
+ vexWidget.insertElement((Element) tr.getElement().clone());
+ }
- public static void iterateTableCells(IVexWidget vexWidget, final TableCellCallback callback) {
-
- final StyleSheet ss = vexWidget.getStyleSheet();
+ cloneTableCells(vexWidget, tr, true);
+ }
+ });
+ }
- iterateTableRows(vexWidget, new ElementOrRangeCallback() {
-
- final private int[] rowIndex = { 0 };
-
- public void onElement(final Element row, String displayStyle) {
-
- callback.startRow(row, rowIndex[0]);
-
- LayoutUtils.iterateTableCells(ss, row, new ElementOrRangeCallback() {
- private int cellIndex = 0;
- public void onElement(Element cell, String displayStyle) {
- callback.onCell(row, cell, rowIndex[0], cellIndex);
- cellIndex++;
- }
- public void onRange(Element parent, int startOffset, int endOffset) {
- callback.onCell(row, new IntRange(startOffset, endOffset), rowIndex[0], cellIndex);
- cellIndex++;
- }
- });
-
- callback.endRow(row, rowIndex[0]);
-
- rowIndex[0]++;
- }
-
- public void onRange(Element parent, final int startOffset, final int endOffset) {
-
- final IntRange row = new IntRange(startOffset, endOffset);
- callback.startRow(row, rowIndex[0]);
-
- LayoutUtils.iterateTableCells(ss, parent, startOffset, endOffset, new ElementOrRangeCallback() {
- private int cellIndex = 0;
- public void onElement(Element cell, String displayStyle) {
- callback.onCell(row, cell, rowIndex[0], cellIndex);
- cellIndex++;
- }
- public void onRange(Element parent, int startOffset, int endOffset) {
- callback.onCell(row, new IntRange(startOffset, endOffset), rowIndex[0], cellIndex);
- cellIndex++;
- }
- });
-
- callback.endRow(row, rowIndex[0]);
-
- rowIndex[0]++;
- }
- });
- }
+ /**
+ * Returns true if the given element or range is at least partially
+ * selected.
+ *
+ * @param vexWidget
+ * IVexWidget being tested.
+ * @param elementOrRange
+ * Element or IntRange being tested.
+ */
+ public static boolean elementOrRangeIsPartiallySelected(
+ IVexWidget vexWidget, Object elementOrRange) {
+ IntRange range = getInnerRange(elementOrRange);
+ return range.getEnd() >= vexWidget.getSelectionStart()
+ && range.getStart() <= vexWidget.getSelectionEnd();
+ }
- /**
- * Returns a RowColumnInfo structure containing information about the table
- * containing the caret. Returns null if the caret is not currently inside
- * a table.
- *
- * @param vexWidget IVexWidget to inspect.
- */
- public static RowColumnInfo getRowColumnInfo(IVexWidget vexWidget) {
-
- final boolean[] found = new boolean[1];
- final RowColumnInfo[] rcInfo = new RowColumnInfo[] { new RowColumnInfo() };
- final int offset = vexWidget.getCaretOffset();
-
- rcInfo[0].cellIndex = -1;
- rcInfo[0].rowIndex = -1;
-
- iterateTableCells(vexWidget, new TableCellCallback() {
-
- int rowColumnCount;
-
- public void startRow(Object row, int rowIndex) {
- rowColumnCount = 0;
- }
+ /**
+ * Returns the zero-based index of the table column containing the current
+ * offset. Returns -1 if we are not inside a table.
+ */
+ public static int getCurrentColumnIndex(IVexWidget vexWidget) {
- public void onCell(Object row, Object cell, int rowIndex, int cellIndex) {
- found[0] = true;
- if (LayoutUtils.elementOrRangeContains(row, offset)) {
- rcInfo[0].row = row;
- rcInfo[0].rowIndex = rowIndex;
- rcInfo[0].columnCount++;
-
- if (LayoutUtils.elementOrRangeContains(cell, offset)) {
- rcInfo[0].cell = cell;
- rcInfo[0].cellIndex = cellIndex;
- }
- }
-
- rowColumnCount++;
- }
+ Element row = getCurrentTableRow(vexWidget);
- public void endRow(Object row, int rowIndex) {
- rcInfo[0].rowCount++;
- rcInfo[0].maxColumnCount = Math.max(rcInfo[0].maxColumnCount, rowColumnCount);
- }
- });
-
- if (found[0]) {
- return rcInfo[0];
- } else {
- return null;
- }
- }
+ if (row == null) {
+ return -1;
+ }
- /**
- * Iterate over all rows in the table containing the caret.
- *
- * @param vexWidget IVexWidget to iterate over.
- * @param callback Caller-provided callback that this method calls for
- * each row in the current table.
- */
- public static void iterateTableRows(IVexWidget vexWidget, ElementOrRangeCallback callback) {
-
- final StyleSheet ss = vexWidget.getStyleSheet();
- final Document doc = vexWidget.getDocument();
- final int offset = vexWidget.getCaretOffset();
+ final int offset = vexWidget.getCaretOffset();
+ final int[] column = new int[] { -1 };
+ LayoutUtils.iterateTableCells(vexWidget.getStyleSheet(), row,
+ new ElementOrRangeCallback() {
+ private int i = 0;
- // This may or may not be a table
- // In any case, it's the element that contains the top-level table children
- Element table = doc.getElementAt(offset);
-
- while (table != null && !LayoutUtils.isTableChild(ss, table)) {
- table = table.getParent();
- }
-
- while (table != null && LayoutUtils.isTableChild(ss, table)) {
- table = table.getParent();
- }
-
- if (table == null || table.getParent() == null) {
- return;
- }
-
- final List tableChildren = new ArrayList();
- final boolean[] found = new boolean[] { false };
- LayoutUtils.iterateChildrenByDisplayStyle(ss, LayoutUtils.TABLE_CHILD_STYLES, table, new ElementOrRangeCallback() {
- public void onElement(Element child, String displayStyle) {
- if (offset >= child.getStartOffset() && offset <= child.getEndOffset()) {
- found[0] = true;
- }
- tableChildren.add(child);
- }
- public void onRange(Element parent, int startOffset, int endOffset) {
- if (!found[0]) {
- tableChildren.clear();
- }
- }
- });
-
- if (!found[0]) {
- return;
- }
-
- int startOffset = ((Element) tableChildren.get(0)).getStartOffset();
- int endOffset = ((Element) tableChildren.get(tableChildren.size() - 1)).getEndOffset() + 1;
- LayoutUtils.iterateTableRows(ss, table, startOffset, endOffset, callback);
- }
+ public void onElement(Element child, String displayStyle) {
+ if (offset > child.getStartOffset()
+ && offset <= child.getEndOffset()) {
+ column[0] = i;
+ }
+ i++;
+ }
- /**
- * Returns an IntRange representing the offsets inside the given Element or
- * IntRange. If an Element is passed, returns the offsets inside the
- * sentinels. If an IntRange is passed it is returned directly.
- *
- * @param elementOrRange Element or IntRange to be inspected.
- */
- public static IntRange getInnerRange(Object elementOrRange) {
- if (elementOrRange instanceof Element) {
- Element element = (Element) elementOrRange;
- return new IntRange(element.getStartOffset() + 1, element.getEndOffset());
- } else {
- return (IntRange) elementOrRange;
- }
- }
+ public void onRange(Element parent, int startOffset,
+ int endOffset) {
+ i++;
+ }
+ });
- /**
- * Returns an IntRange representing the offsets outside the given Element or
- * IntRange. If an Element is passed, returns the offsets outside the
- * sentinels. If an IntRange is passed it is returned directly.
- *
- * @param elementOrRange Element or IntRange to be inspected.
- */
- public static IntRange getOuterRange(Object elementOrRange) {
- if (elementOrRange instanceof Element) {
- Element element = (Element) elementOrRange;
- return new IntRange(element.getStartOffset(), element.getEndOffset() + 1);
- } else {
- return (IntRange) elementOrRange;
- }
- }
+ return column[0];
+ }
-
- public static class SelectedRows {
-
- private SelectedRows() {
- }
+ /**
+ * Returns the innermost Element with style table-row containing the caret,
+ * or null if no such element exists.
+ *
+ * @param vexWidget
+ * IVexWidget to use.
+ */
+ public static Element getCurrentTableRow(IVexWidget vexWidget) {
- public List getRows() {
- return this.rows;
- }
- public Object getRowBefore() {
- return this.rowBefore;
- }
- public Object getRowAfter() {
- return this.rowAfter;
- }
-
- private List rows;
- private Object rowBefore;
- private Object rowAfter;
- }
+ StyleSheet ss = vexWidget.getStyleSheet();
+ Element element = vexWidget.getCurrentElement();
+
+ while (element != null) {
+ if (ss.getStyles(element).getDisplay().equals(CSS.TABLE_ROW)) {
+ return element;
+ }
+ element = element.getParent();
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns the start offset of the next sibling of the parent element.
+ * Returns -1 if there is no previous sibling in the parent.
+ *
+ * @param vexWidget
+ * VexWidget to use.
+ */
+ public static int getPreviousSiblingStart(IVexWidget vexWidget) {
+ int startOffset;
+
+ if (vexWidget.hasSelection()) {
+ startOffset = vexWidget.getSelectionStart();
+ } else {
+ Box box = vexWidget.findInnermostBox(new IBoxFilter() {
+ public boolean matches(Box box) {
+ return box instanceof BlockBox && box.getElement() != null;
+ }
+ });
+
+ if (box.getElement() == vexWidget.getDocument().getRootElement()) {
+ return -1;
+ }
+
+ startOffset = box.getElement().getStartOffset();
+ }
+
+ int previousSiblingStart = -1;
+ Element parent = vexWidget.getDocument().getElementAt(startOffset);
+ Node[] children = parent.getChildNodes();
+ for (int i = 0; i < children.length; i++) {
+ Node child = children[i];
+ if (startOffset == child.getStartOffset()) {
+ break;
+ }
+ previousSiblingStart = child.getStartOffset();
+ }
+ return previousSiblingStart;
+ }
+
+ /**
+ * Returns an array of the selected block boxes. Text nodes between boxes
+ * are not returned. If the selection does not enclose any block boxes,
+ * returns an empty array.
+ *
+ * @param vexWidget
+ * VexWidget to use.
+ */
+ public static BlockBox[] getSelectedBlockBoxes(final IVexWidget vexWidget) {
+
+ if (!vexWidget.hasSelection()) {
+ return new BlockBox[0];
+ }
+
+ Box parent = vexWidget.findInnermostBox(new IBoxFilter() {
+ public boolean matches(Box box) {
+ System.out.println("Matching " + box);
+ return box instanceof BlockBox
+ && box.getStartOffset() <= vexWidget
+ .getSelectionStart()
+ && box.getEndOffset() >= vexWidget.getSelectionEnd();
+ }
+ });
+
+ System.out.println("Matched " + parent);
+
+ List blockList = new ArrayList();
+
+ Box[] children = parent.getChildren();
+ System.out.println("Parent has " + children.length + " children");
+ for (int i = 0; i < children.length; i++) {
+ Box child = children[i];
+ if (child instanceof BlockBox
+ && child.getStartOffset() >= vexWidget.getSelectionStart()
+ && child.getEndOffset() <= vexWidget.getSelectionEnd()) {
+ System.out.println(" adding " + child);
+ blockList.add(child);
+ } else {
+ System.out.println(" skipping " + child);
+ }
+
+ }
+
+ return (BlockBox[]) blockList.toArray(new BlockBox[blockList.size()]);
+ }
+
+ /**
+ * Returns the currently selected table rows, or the current row if ther is
+ * no selection. If no row can be found, returns an empty array.
+ *
+ * @param vexWidget
+ * IVexWidget to use.
+ */
+ public static SelectedRows getSelectedTableRows(final IVexWidget vexWidget) {
+
+ final SelectedRows selected = new SelectedRows();
+
+ ActionUtils.iterateTableCells(vexWidget, new TableCellCallback() {
+ public void startRow(Object row, int rowIndex) {
+ if (ActionUtils.elementOrRangeIsPartiallySelected(vexWidget,
+ row)) {
+ if (selected.rows == null) {
+ selected.rows = new ArrayList();
+ }
+ selected.rows.add(row);
+ } else {
+ if (selected.rows == null) {
+ selected.rowBefore = row;
+ } else {
+ if (selected.rowAfter == null) {
+ selected.rowAfter = row;
+ }
+ }
+ }
+ }
+
+ public void onCell(Object row, Object cell, int rowIndex,
+ int cellIndex) {
+ }
+
+ public void endRow(Object row, int rowIndex) {
+ }
+ });
+
+ return selected;
+ }
+
+ public static void iterateTableCells(IVexWidget vexWidget,
+ final TableCellCallback callback) {
+
+ final StyleSheet ss = vexWidget.getStyleSheet();
+
+ iterateTableRows(vexWidget, new ElementOrRangeCallback() {
+
+ final private int[] rowIndex = { 0 };
+
+ public void onElement(final Element row, String displayStyle) {
+
+ callback.startRow(row, rowIndex[0]);
+
+ LayoutUtils.iterateTableCells(ss, row,
+ new ElementOrRangeCallback() {
+ private int cellIndex = 0;
+
+ public void onElement(Element cell,
+ String displayStyle) {
+ callback.onCell(row, cell, rowIndex[0],
+ cellIndex);
+ cellIndex++;
+ }
+
+ public void onRange(Element parent,
+ int startOffset, int endOffset) {
+ callback.onCell(row, new IntRange(startOffset,
+ endOffset), rowIndex[0], cellIndex);
+ cellIndex++;
+ }
+ });
+
+ callback.endRow(row, rowIndex[0]);
+
+ rowIndex[0]++;
+ }
+
+ public void onRange(Element parent, final int startOffset,
+ final int endOffset) {
+
+ final IntRange row = new IntRange(startOffset, endOffset);
+ callback.startRow(row, rowIndex[0]);
+
+ LayoutUtils.iterateTableCells(ss, parent, startOffset,
+ endOffset, new ElementOrRangeCallback() {
+ private int cellIndex = 0;
+
+ public void onElement(Element cell,
+ String displayStyle) {
+ callback.onCell(row, cell, rowIndex[0],
+ cellIndex);
+ cellIndex++;
+ }
+
+ public void onRange(Element parent,
+ int startOffset, int endOffset) {
+ callback.onCell(row, new IntRange(startOffset,
+ endOffset), rowIndex[0], cellIndex);
+ cellIndex++;
+ }
+ });
+
+ callback.endRow(row, rowIndex[0]);
+
+ rowIndex[0]++;
+ }
+ });
+ }
+
+ /**
+ * Returns a RowColumnInfo structure containing information about the table
+ * containing the caret. Returns null if the caret is not currently inside a
+ * table.
+ *
+ * @param vexWidget
+ * IVexWidget to inspect.
+ */
+ public static RowColumnInfo getRowColumnInfo(IVexWidget vexWidget) {
+
+ final boolean[] found = new boolean[1];
+ final RowColumnInfo[] rcInfo = new RowColumnInfo[] { new RowColumnInfo() };
+ final int offset = vexWidget.getCaretOffset();
+
+ rcInfo[0].cellIndex = -1;
+ rcInfo[0].rowIndex = -1;
+
+ iterateTableCells(vexWidget, new TableCellCallback() {
+
+ int rowColumnCount;
+
+ public void startRow(Object row, int rowIndex) {
+ rowColumnCount = 0;
+ }
+
+ public void onCell(Object row, Object cell, int rowIndex,
+ int cellIndex) {
+ found[0] = true;
+ if (LayoutUtils.elementOrRangeContains(row, offset)) {
+ rcInfo[0].row = row;
+ rcInfo[0].rowIndex = rowIndex;
+ rcInfo[0].columnCount++;
+
+ if (LayoutUtils.elementOrRangeContains(cell, offset)) {
+ rcInfo[0].cell = cell;
+ rcInfo[0].cellIndex = cellIndex;
+ }
+ }
+
+ rowColumnCount++;
+ }
+
+ public void endRow(Object row, int rowIndex) {
+ rcInfo[0].rowCount++;
+ rcInfo[0].maxColumnCount = Math.max(rcInfo[0].maxColumnCount,
+ rowColumnCount);
+ }
+ });
+
+ if (found[0]) {
+ return rcInfo[0];
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Iterate over all rows in the table containing the caret.
+ *
+ * @param vexWidget
+ * IVexWidget to iterate over.
+ * @param callback
+ * Caller-provided callback that this method calls for each row
+ * in the current table.
+ */
+ public static void iterateTableRows(IVexWidget vexWidget,
+ ElementOrRangeCallback callback) {
+
+ final StyleSheet ss = vexWidget.getStyleSheet();
+ final Document doc = vexWidget.getDocument();
+ final int offset = vexWidget.getCaretOffset();
+
+ // This may or may not be a table
+ // In any case, it's the element that contains the top-level table
+ // children
+ Element table = doc.getElementAt(offset);
+
+ while (table != null && !LayoutUtils.isTableChild(ss, table)) {
+ table = table.getParent();
+ }
+
+ while (table != null && LayoutUtils.isTableChild(ss, table)) {
+ table = table.getParent();
+ }
+
+ if (table == null || table.getParent() == null) {
+ return;
+ }
+
+ final List tableChildren = new ArrayList();
+ final boolean[] found = new boolean[] { false };
+ LayoutUtils.iterateChildrenByDisplayStyle(ss,
+ LayoutUtils.TABLE_CHILD_STYLES, table,
+ new ElementOrRangeCallback() {
+ public void onElement(Element child, String displayStyle) {
+ if (offset >= child.getStartOffset()
+ && offset <= child.getEndOffset()) {
+ found[0] = true;
+ }
+ tableChildren.add(child);
+ }
+
+ public void onRange(Element parent, int startOffset,
+ int endOffset) {
+ if (!found[0]) {
+ tableChildren.clear();
+ }
+ }
+ });
+
+ if (!found[0]) {
+ return;
+ }
+
+ int startOffset = ((Element) tableChildren.get(0)).getStartOffset();
+ int endOffset = ((Element) tableChildren.get(tableChildren.size() - 1))
+ .getEndOffset() + 1;
+ LayoutUtils.iterateTableRows(ss, table, startOffset, endOffset,
+ callback);
+ }
+
+ /**
+ * Returns an IntRange representing the offsets inside the given Element or
+ * IntRange. If an Element is passed, returns the offsets inside the
+ * sentinels. If an IntRange is passed it is returned directly.
+ *
+ * @param elementOrRange
+ * Element or IntRange to be inspected.
+ */
+ public static IntRange getInnerRange(Object elementOrRange) {
+ if (elementOrRange instanceof Element) {
+ Element element = (Element) elementOrRange;
+ return new IntRange(element.getStartOffset() + 1, element
+ .getEndOffset());
+ } else {
+ return (IntRange) elementOrRange;
+ }
+ }
+
+ /**
+ * Returns an IntRange representing the offsets outside the given Element or
+ * IntRange. If an Element is passed, returns the offsets outside the
+ * sentinels. If an IntRange is passed it is returned directly.
+ *
+ * @param elementOrRange
+ * Element or IntRange to be inspected.
+ */
+ public static IntRange getOuterRange(Object elementOrRange) {
+ if (elementOrRange instanceof Element) {
+ Element element = (Element) elementOrRange;
+ return new IntRange(element.getStartOffset(), element
+ .getEndOffset() + 1);
+ } else {
+ return (IntRange) elementOrRange;
+ }
+ }
+
+ public static class SelectedRows {
+
+ private SelectedRows() {
+ }
+
+ public List getRows() {
+ return this.rows;
+ }
+
+ public Object getRowBefore() {
+ return this.rowBefore;
+ }
+
+ public Object getRowAfter() {
+ return this.rowAfter;
+ }
+
+ private List rows;
+ private Object rowBefore;
+ private Object rowAfter;
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/DeleteColumnAction.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/DeleteColumnAction.java
index 802eb34..a96c9c8 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/DeleteColumnAction.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/DeleteColumnAction.java
@@ -16,53 +16,57 @@
import org.eclipse.wst.xml.vex.core.internal.core.IntRange;
import org.eclipse.wst.xml.vex.core.internal.widget.IVexWidget;
-
/**
* Delete the table column containing the caret.
*/
public class DeleteColumnAction extends AbstractVexAction {
- public void run(final IVexWidget vexWidget) {
-
- vexWidget.doWork(new Runnable() {
- public void run() {
-
- final ActionUtils.RowColumnInfo rcInfo = ActionUtils.getRowColumnInfo(vexWidget);
-
- if (rcInfo == null) {
- return;
- }
+ public void run(final IVexWidget vexWidget) {
- final List cellsToDelete = new ArrayList();
- ActionUtils.iterateTableCells(vexWidget, new TableCellCallback() {
- public void startRow(Object row, int rowIndex) {
- }
- public void onCell(Object row, Object cell, int rowIndex, int cellIndex) {
- if (cellIndex == rcInfo.cellIndex) {
- cellsToDelete.add(cell);
- }
- }
- public void endRow(Object row, int rowIndex) {
- }
- });
+ vexWidget.doWork(new Runnable() {
+ public void run() {
- // Iterate the deletions in reverse, so that we don't mess up
- // offsets that are in anonymous cells, which are not stored
- // as Positions.
- for (int i = cellsToDelete.size() - 1; i >= 0; i--) {
- Object cell = cellsToDelete.get(i);
- IntRange range = ActionUtils.getOuterRange(cell);
- vexWidget.moveTo(range.getStart());
- vexWidget.moveTo(range.getEnd(), true);
- vexWidget.deleteSelection();
- }
- }
- });
-
- }
+ final ActionUtils.RowColumnInfo rcInfo = ActionUtils
+ .getRowColumnInfo(vexWidget);
- public boolean isEnabled(IVexWidget vexWidget) {
- return ActionUtils.getCurrentColumnIndex(vexWidget) != -1;
- }
+ if (rcInfo == null) {
+ return;
+ }
+
+ final List cellsToDelete = new ArrayList();
+ ActionUtils.iterateTableCells(vexWidget,
+ new TableCellCallback() {
+ public void startRow(Object row, int rowIndex) {
+ }
+
+ public void onCell(Object row, Object cell,
+ int rowIndex, int cellIndex) {
+ if (cellIndex == rcInfo.cellIndex) {
+ cellsToDelete.add(cell);
+ }
+ }
+
+ public void endRow(Object row, int rowIndex) {
+ }
+ });
+
+ // Iterate the deletions in reverse, so that we don't mess up
+ // offsets that are in anonymous cells, which are not stored
+ // as Positions.
+ for (int i = cellsToDelete.size() - 1; i >= 0; i--) {
+ Object cell = cellsToDelete.get(i);
+ IntRange range = ActionUtils.getOuterRange(cell);
+ vexWidget.moveTo(range.getStart());
+ vexWidget.moveTo(range.getEnd(), true);
+ vexWidget.deleteSelection();
+ }
+ }
+ });
+
+ }
+
+ public boolean isEnabled(IVexWidget vexWidget) {
+ return ActionUtils.getCurrentColumnIndex(vexWidget) != -1;
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/DeleteRowAction.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/DeleteRowAction.java
index 48d50c4..930c36f 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/DeleteRowAction.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/DeleteRowAction.java
@@ -14,35 +14,36 @@
import org.eclipse.wst.xml.vex.core.internal.widget.IVexWidget;
-
/**
* Delete selected table rows.
*/
public class DeleteRowAction extends AbstractVexAction {
- public void run(final IVexWidget vexWidget) {
+ public void run(final IVexWidget vexWidget) {
- final List rows = ActionUtils.getSelectedTableRows(vexWidget).getRows();
-
- if (rows == null) {
- return;
- }
+ final List rows = ActionUtils.getSelectedTableRows(vexWidget).getRows();
- vexWidget.doWork(new Runnable() {
- public void run() {
- int startOffset = ActionUtils.getOuterRange(rows.get(0)).getStart();
- int endOffset = ActionUtils.getOuterRange(rows.get(rows.size() - 1)).getEnd();
-
- vexWidget.moveTo(startOffset);
- vexWidget.moveTo(endOffset, true);
- vexWidget.deleteSelection();
- }
- });
+ if (rows == null) {
+ return;
+ }
- }
+ vexWidget.doWork(new Runnable() {
+ public void run() {
+ int startOffset = ActionUtils.getOuterRange(rows.get(0))
+ .getStart();
+ int endOffset = ActionUtils.getOuterRange(
+ rows.get(rows.size() - 1)).getEnd();
- public boolean isEnabled(IVexWidget vexWidget) {
- return ActionUtils.getSelectedTableRows(vexWidget).getRows() != null;
- }
+ vexWidget.moveTo(startOffset);
+ vexWidget.moveTo(endOffset, true);
+ vexWidget.deleteSelection();
+ }
+ });
+
+ }
+
+ public boolean isEnabled(IVexWidget vexWidget) {
+ return ActionUtils.getSelectedTableRows(vexWidget).getRows() != null;
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/DuplicateSelectionAction.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/DuplicateSelectionAction.java
index 7f41b93..332bc7c 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/DuplicateSelectionAction.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/DuplicateSelectionAction.java
@@ -13,35 +13,34 @@
import org.eclipse.wst.xml.vex.core.internal.dom.Element;
import org.eclipse.wst.xml.vex.core.internal.widget.IVexWidget;
-
/**
* Duplicates current selection or element.
*/
public class DuplicateSelectionAction extends AbstractVexAction {
- public void run(final IVexWidget vexWidget) {
-
- vexWidget.doWork(new Runnable() {
- public void run() {
- if (!vexWidget.hasSelection()) {
- Element element = vexWidget.getCurrentElement();
- if (element.getParent() == null) {
- // Can't dup the root element
- return;
- }
- vexWidget.moveTo(element.getStartOffset());
- vexWidget.moveTo(element.getEndOffset() + 1, true);
- }
+ public void run(final IVexWidget vexWidget) {
- vexWidget.copySelection();
- int startOffset = vexWidget.getSelectionEnd();
- vexWidget.moveTo(startOffset);
- vexWidget.paste();
- int endOffset = vexWidget.getCaretOffset();
- vexWidget.moveTo(startOffset);
- vexWidget.moveTo(endOffset, true);
- }
- });
- }
+ vexWidget.doWork(new Runnable() {
+ public void run() {
+ if (!vexWidget.hasSelection()) {
+ Element element = vexWidget.getCurrentElement();
+ if (element.getParent() == null) {
+ // Can't dup the root element
+ return;
+ }
+ vexWidget.moveTo(element.getStartOffset());
+ vexWidget.moveTo(element.getEndOffset() + 1, true);
+ }
+
+ vexWidget.copySelection();
+ int startOffset = vexWidget.getSelectionEnd();
+ vexWidget.moveTo(startOffset);
+ vexWidget.paste();
+ int endOffset = vexWidget.getCaretOffset();
+ vexWidget.moveTo(startOffset);
+ vexWidget.moveTo(endOffset, true);
+ }
+ });
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/IVexAction.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/IVexAction.java
index aa9ecfd..4ecba49 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/IVexAction.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/IVexAction.java
@@ -16,16 +16,20 @@
* Interface implemented by command objects that can act on a VexWidget.
*/
public interface IVexAction {
-
- /**
- * Performs the action on the VexWidget.
- * @param vexWidget IVexWidget on which the action is to be performed.
- */
- public void run(IVexWidget vexWidget);
-
- /**
- * Returns true if the action is valid for the given VexWidget.
- * @param vexWidget IVexWidget against which to test validity.
- */
- public boolean isEnabled(IVexWidget vexWidget);
+
+ /**
+ * Performs the action on the VexWidget.
+ *
+ * @param vexWidget
+ * IVexWidget on which the action is to be performed.
+ */
+ public void run(IVexWidget vexWidget);
+
+ /**
+ * Returns true if the action is valid for the given VexWidget.
+ *
+ * @param vexWidget
+ * IVexWidget against which to test validity.
+ */
+ public boolean isEnabled(IVexWidget vexWidget);
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/InsertColumnAfterAction.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/InsertColumnAfterAction.java
index 5fd253d..5092e9e 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/InsertColumnAfterAction.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/InsertColumnAfterAction.java
@@ -17,53 +17,57 @@
import org.eclipse.wst.xml.vex.core.internal.dom.Element;
import org.eclipse.wst.xml.vex.core.internal.widget.IVexWidget;
-
/**
* Inserts a single table column after the current one.
*/
public class InsertColumnAfterAction extends AbstractVexAction {
- public void run(final IVexWidget vexWidget) {
+ public void run(final IVexWidget vexWidget) {
- final int indexToDup = ActionUtils.getCurrentColumnIndex(vexWidget);
- if (indexToDup == -1) {
- return;
- }
-
- vexWidget.doWork(new Runnable() {
- public void run() {
+ final int indexToDup = ActionUtils.getCurrentColumnIndex(vexWidget);
+ if (indexToDup == -1) {
+ return;
+ }
- final List cellsToDup = new ArrayList();
- ActionUtils.iterateTableCells(vexWidget, new TableCellCallback() {
- public void startRow(Object row, int rowIndex) {
- }
- public void onCell(Object row, Object cell, int rowIndex, int cellIndex) {
- if (cellIndex == indexToDup && cell instanceof Element) {
- cellsToDup.add(cell);
- }
- }
- public void endRow(Object row, int rowIndex) {
- }
- });
-
- int finalOffset = -1;
- for (Iterator it = cellsToDup.iterator(); it.hasNext();) {
- Element element = (Element) it.next();
- if (finalOffset == -1) {
- finalOffset = element.getStartOffset() + 1;
- }
- vexWidget.moveTo(element.getEndOffset() + 1);
- vexWidget.insertElement((Element) element.clone());
- }
-
- if (finalOffset != -1) {
- vexWidget.moveTo(finalOffset);
- }
- }
- });
- }
+ vexWidget.doWork(new Runnable() {
+ public void run() {
- public boolean isEnabled(IVexWidget vexWidget) {
- return ActionUtils.getCurrentColumnIndex(vexWidget) != -1;
- }
+ final List cellsToDup = new ArrayList();
+ ActionUtils.iterateTableCells(vexWidget,
+ new TableCellCallback() {
+ public void startRow(Object row, int rowIndex) {
+ }
+
+ public void onCell(Object row, Object cell,
+ int rowIndex, int cellIndex) {
+ if (cellIndex == indexToDup
+ && cell instanceof Element) {
+ cellsToDup.add(cell);
+ }
+ }
+
+ public void endRow(Object row, int rowIndex) {
+ }
+ });
+
+ int finalOffset = -1;
+ for (Iterator it = cellsToDup.iterator(); it.hasNext();) {
+ Element element = (Element) it.next();
+ if (finalOffset == -1) {
+ finalOffset = element.getStartOffset() + 1;
+ }
+ vexWidget.moveTo(element.getEndOffset() + 1);
+ vexWidget.insertElement((Element) element.clone());
+ }
+
+ if (finalOffset != -1) {
+ vexWidget.moveTo(finalOffset);
+ }
+ }
+ });
+ }
+
+ public boolean isEnabled(IVexWidget vexWidget) {
+ return ActionUtils.getCurrentColumnIndex(vexWidget) != -1;
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/InsertColumnBeforeAction.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/InsertColumnBeforeAction.java
index f8f1e89..6bc50e9 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/InsertColumnBeforeAction.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/InsertColumnBeforeAction.java
@@ -17,56 +17,61 @@
import org.eclipse.wst.xml.vex.core.internal.dom.Element;
import org.eclipse.wst.xml.vex.core.internal.widget.IVexWidget;
-
/**
* Inserts a single table column before the current one.
*/
public class InsertColumnBeforeAction extends AbstractVexAction {
- public void run(final IVexWidget vexWidget) {
-
- vexWidget.doWork(new Runnable() {
- public void run() {
-
- final int indexToDup = ActionUtils.getCurrentColumnIndex(vexWidget);
- if (indexToDup == -1) {
- return;
- }
-
- final List cellsToDup = new ArrayList();
- ActionUtils.iterateTableCells(vexWidget, new TableCellCallback() {
- public void startRow(Object row, int rowIndex) {
- }
- public void onCell(Object row, Object cell, int rowIndex, int cellIndex) {
- if (cellIndex == indexToDup && cell instanceof Element) {
- cellsToDup.add(cell);
- }
- }
- public void endRow(Object row, int rowIndex) {
- }
- });
-
- int finalOffset = -1;
- for (Iterator it = cellsToDup.iterator(); it.hasNext();) {
- Element element = (Element) it.next();
- if (finalOffset == -1) {
- finalOffset = element.getStartOffset() + 1;
- }
- vexWidget.moveTo(element.getStartOffset());
- vexWidget.insertElement((Element) element.clone());
- }
-
- if (finalOffset != -1) {
- vexWidget.moveTo(finalOffset);
- }
+ public void run(final IVexWidget vexWidget) {
- }
- });
-
- }
+ vexWidget.doWork(new Runnable() {
+ public void run() {
- public boolean isEnabled(IVexWidget vexWidget) {
- return ActionUtils.getCurrentColumnIndex(vexWidget) != -1;
- }
+ final int indexToDup = ActionUtils
+ .getCurrentColumnIndex(vexWidget);
+ if (indexToDup == -1) {
+ return;
+ }
+
+ final List cellsToDup = new ArrayList();
+ ActionUtils.iterateTableCells(vexWidget,
+ new TableCellCallback() {
+ public void startRow(Object row, int rowIndex) {
+ }
+
+ public void onCell(Object row, Object cell,
+ int rowIndex, int cellIndex) {
+ if (cellIndex == indexToDup
+ && cell instanceof Element) {
+ cellsToDup.add(cell);
+ }
+ }
+
+ public void endRow(Object row, int rowIndex) {
+ }
+ });
+
+ int finalOffset = -1;
+ for (Iterator it = cellsToDup.iterator(); it.hasNext();) {
+ Element element = (Element) it.next();
+ if (finalOffset == -1) {
+ finalOffset = element.getStartOffset() + 1;
+ }
+ vexWidget.moveTo(element.getStartOffset());
+ vexWidget.insertElement((Element) element.clone());
+ }
+
+ if (finalOffset != -1) {
+ vexWidget.moveTo(finalOffset);
+ }
+
+ }
+ });
+
+ }
+
+ public boolean isEnabled(IVexWidget vexWidget) {
+ return ActionUtils.getCurrentColumnIndex(vexWidget) != -1;
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/InsertRowAboveAction.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/InsertRowAboveAction.java
index 00b227a..6fae2ac 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/InsertRowAboveAction.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/InsertRowAboveAction.java
@@ -10,13 +10,12 @@
*******************************************************************************/
package org.eclipse.wst.xml.vex.core.internal.action;
-
/**
* Inserts one or more table rows above the currently selected one(s).
*/
public class InsertRowAboveAction extends InsertRowAction {
- public InsertRowAboveAction() {
- super(true);
- }
+ public InsertRowAboveAction() {
+ super(true);
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/InsertRowAction.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/InsertRowAction.java
index 7e44ef9..c5a897f 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/InsertRowAction.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/InsertRowAction.java
@@ -16,129 +16,139 @@
import org.eclipse.wst.xml.vex.core.internal.dom.Element;
import org.eclipse.wst.xml.vex.core.internal.widget.IVexWidget;
-
/**
- * Inserts one or more table rows either above or below the currently selected one(s).
- * This class is meant as a base class for InsertRowAboveAction and
+ * Inserts one or more table rows either above or below the currently selected
+ * one(s). This class is meant as a base class for InsertRowAboveAction and
* InsertRowBelowAction.
*/
public class InsertRowAction extends AbstractVexAction {
- /**
- * Class constructor.
- * @param above If true, the new rows are inserted above the currently
- * selected ones, else they are inserted below.
- */
- public InsertRowAction(boolean above) {
- this.above = above;
- }
-
- public void run(final IVexWidget vexWidget) {
-
- vexWidget.doWork(new Runnable() {
- public void run() {
-
- final List rowsToInsert = new ArrayList();
- final List rowCellsToInsert = new ArrayList();
-
- ActionUtils.iterateTableCells(vexWidget, new TableCellCallback() {
+ /**
+ * Class constructor.
+ *
+ * @param above
+ * If true, the new rows are inserted above the currently
+ * selected ones, else they are inserted below.
+ */
+ public InsertRowAction(boolean above) {
+ this.above = above;
+ }
- boolean rowSelected;
- List cellsToInsert;
-
- public void startRow(Object row, int rowIndex) {
- rowSelected = ActionUtils.elementOrRangeIsPartiallySelected(vexWidget, row);
-
- if (rowSelected) {
- cellsToInsert = new ArrayList();
- }
- }
+ public void run(final IVexWidget vexWidget) {
- public void onCell(Object row, Object cell, int rowIndex, int cellIndex) {
- if (rowSelected) {
- cellsToInsert.add(cell);
- }
- }
+ vexWidget.doWork(new Runnable() {
+ public void run() {
- public void endRow(Object row, int rowIndex) {
- if (rowSelected) {
- rowsToInsert.add(row);
- rowCellsToInsert.add(cellsToInsert);
- }
- }
-
- });
-
- if (rowsToInsert.size() == 0) {
- return;
- }
-
+ final List rowsToInsert = new ArrayList();
+ final List rowCellsToInsert = new ArrayList();
- //
- // save the caret offset so that we return just inside the first
- // table cell
- //
- // (innerOffset - outerOffset) represents the final offset of
- // the caret, relative to the insertion point of the new rows
- //
- int outerOffset = ActionUtils.getOuterRange(rowsToInsert.get(0)).getStart();
- int innerOffset;
- List firstCells = (List) rowCellsToInsert.get(0);
- if (firstCells.size() == 0) {
- innerOffset = ActionUtils.getInnerRange(rowsToInsert.get(0)).getStart();
- } else {
- innerOffset = ActionUtils.getInnerRange(firstCells.get(0)).getStart();
- }
+ ActionUtils.iterateTableCells(vexWidget,
+ new TableCellCallback() {
- int insertOffset;
- if (above) {
- insertOffset = ActionUtils.getOuterRange(rowsToInsert.get(0)).getStart();
- } else {
- Object lastRow = rowsToInsert.get(rowsToInsert.size() - 1);
- insertOffset = ActionUtils.getOuterRange(lastRow).getEnd();
- }
+ boolean rowSelected;
+ List cellsToInsert;
- int finalOffset = insertOffset + (innerOffset - outerOffset);
-
- vexWidget.moveTo(insertOffset);
-
- for (int i = 0; i < rowsToInsert.size(); i++) {
-
- Object row = rowsToInsert.get(i);
-
- if (row instanceof Element) {
- vexWidget.insertElement((Element) ((Element) row).clone());
- }
-
- List cellsToInsert = (List) rowCellsToInsert.get(i);
-
- for (int j = 0; j < cellsToInsert.size(); j++) {
- Object cell = cellsToInsert.get(j);
- if (cell instanceof Element) {
- vexWidget.insertElement((Element) ((Element) cell).clone());
- vexWidget.moveBy(+1);
- } else {
- vexWidget.insertText(" ");
- }
- }
-
- if (row instanceof Element) {
- vexWidget.moveBy(+1);
- }
-
- }
-
- vexWidget.moveTo(finalOffset);
- }
- });
+ public void startRow(Object row, int rowIndex) {
+ rowSelected = ActionUtils
+ .elementOrRangeIsPartiallySelected(
+ vexWidget, row);
- }
+ if (rowSelected) {
+ cellsToInsert = new ArrayList();
+ }
+ }
- public boolean isEnabled(IVexWidget vexWidget) {
- // TODO only enable (a) if rows are selected, and (b) if not inserting
- // adjacent anonymous rows
- return true;
- }
+ public void onCell(Object row, Object cell,
+ int rowIndex, int cellIndex) {
+ if (rowSelected) {
+ cellsToInsert.add(cell);
+ }
+ }
- private boolean above;
+ public void endRow(Object row, int rowIndex) {
+ if (rowSelected) {
+ rowsToInsert.add(row);
+ rowCellsToInsert.add(cellsToInsert);
+ }
+ }
+
+ });
+
+ if (rowsToInsert.size() == 0) {
+ return;
+ }
+
+ //
+ // save the caret offset so that we return just inside the first
+ // table cell
+ //
+ // (innerOffset - outerOffset) represents the final offset of
+ // the caret, relative to the insertion point of the new rows
+ //
+ int outerOffset = ActionUtils
+ .getOuterRange(rowsToInsert.get(0)).getStart();
+ int innerOffset;
+ List firstCells = (List) rowCellsToInsert.get(0);
+ if (firstCells.size() == 0) {
+ innerOffset = ActionUtils
+ .getInnerRange(rowsToInsert.get(0)).getStart();
+ } else {
+ innerOffset = ActionUtils.getInnerRange(firstCells.get(0))
+ .getStart();
+ }
+
+ int insertOffset;
+ if (above) {
+ insertOffset = ActionUtils.getOuterRange(
+ rowsToInsert.get(0)).getStart();
+ } else {
+ Object lastRow = rowsToInsert.get(rowsToInsert.size() - 1);
+ insertOffset = ActionUtils.getOuterRange(lastRow).getEnd();
+ }
+
+ int finalOffset = insertOffset + (innerOffset - outerOffset);
+
+ vexWidget.moveTo(insertOffset);
+
+ for (int i = 0; i < rowsToInsert.size(); i++) {
+
+ Object row = rowsToInsert.get(i);
+
+ if (row instanceof Element) {
+ vexWidget.insertElement((Element) ((Element) row)
+ .clone());
+ }
+
+ List cellsToInsert = (List) rowCellsToInsert.get(i);
+
+ for (int j = 0; j < cellsToInsert.size(); j++) {
+ Object cell = cellsToInsert.get(j);
+ if (cell instanceof Element) {
+ vexWidget.insertElement((Element) ((Element) cell)
+ .clone());
+ vexWidget.moveBy(+1);
+ } else {
+ vexWidget.insertText(" ");
+ }
+ }
+
+ if (row instanceof Element) {
+ vexWidget.moveBy(+1);
+ }
+
+ }
+
+ vexWidget.moveTo(finalOffset);
+ }
+ });
+
+ }
+
+ public boolean isEnabled(IVexWidget vexWidget) {
+ // TODO only enable (a) if rows are selected, and (b) if not inserting
+ // adjacent anonymous rows
+ return true;
+ }
+
+ private boolean above;
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/InsertRowBelowAction.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/InsertRowBelowAction.java
index 9ce6ac3..c02c812 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/InsertRowBelowAction.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/InsertRowBelowAction.java
@@ -10,13 +10,12 @@
*******************************************************************************/
package org.eclipse.wst.xml.vex.core.internal.action;
-
/**
* Inserts one or more table rows below the currently selected one(s).
*/
public class InsertRowBelowAction extends InsertRowAction {
-
- public InsertRowBelowAction() {
- super(false);
- }
+
+ public InsertRowBelowAction() {
+ super(false);
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/MoveColumnLeftAction.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/MoveColumnLeftAction.java
index 946ea6c..0e99e73 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/MoveColumnLeftAction.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/MoveColumnLeftAction.java
@@ -16,76 +16,83 @@
import org.eclipse.wst.xml.vex.core.internal.core.IntRange;
import org.eclipse.wst.xml.vex.core.internal.widget.IVexWidget;
-
/**
* Moves the current table column to the left.
*/
public class MoveColumnLeftAction extends AbstractVexAction {
- public void run(final IVexWidget vexWidget) {
+ public void run(final IVexWidget vexWidget) {
- final ActionUtils.RowColumnInfo rcInfo = ActionUtils.getRowColumnInfo(vexWidget);
+ final ActionUtils.RowColumnInfo rcInfo = ActionUtils
+ .getRowColumnInfo(vexWidget);
- if (rcInfo == null || rcInfo.cellIndex < 1) {
- return;
- }
-
- vexWidget.doWork(true, new Runnable() {
- public void run() {
+ if (rcInfo == null || rcInfo.cellIndex < 1) {
+ return;
+ }
- // Cells to the left of the current column
- final List sourceCells = new ArrayList();
-
- // Cells in the current column
- final List destCells = new ArrayList();
+ vexWidget.doWork(true, new Runnable() {
+ public void run() {
- ActionUtils.iterateTableCells(vexWidget, new TableCellCallback() {
- Object prevCell = null;
- public void startRow(Object row, int rowIndex) {
- }
- public void onCell(Object row, Object cell, int rowIndex, int cellIndex) {
- if (cellIndex == rcInfo.cellIndex) {
- sourceCells.add(this.prevCell);
- destCells.add(cell);
- } else if (cellIndex == rcInfo.cellIndex - 1) {
- this.prevCell = cell;
- }
- }
- public void endRow(Object row, int rowIndex) {
- }
- });
+ // Cells to the left of the current column
+ final List sourceCells = new ArrayList();
- // Iterate the deletions in reverse, so that we don't mess up
- // offsets that are in anonymous cells, which are not stored
- // as Positions.
- //
- // Also, to preserve the current caret position, we don't cut
- // and paste the current column. Instead, we cut the column
- // to the left of the current column and paste it on the right.
- for (int i = sourceCells.size() - 1; i >= 0; i--) {
+ // Cells in the current column
+ final List destCells = new ArrayList();
- Object source = sourceCells.get(i);
- final IntRange sourceRange = ActionUtils.getOuterRange(source);
-
- Object dest = destCells.get(i);
- vexWidget.moveTo(ActionUtils.getOuterRange(dest).getEnd());
+ ActionUtils.iterateTableCells(vexWidget,
+ new TableCellCallback() {
+ Object prevCell = null;
- vexWidget.savePosition(new Runnable() {
- public void run() {
- vexWidget.moveTo(sourceRange.getStart());
- vexWidget.moveTo(sourceRange.getEnd(), true);
- vexWidget.cutSelection();
- }
- });
-
- vexWidget.paste();
- }
- }
- });
- }
+ public void startRow(Object row, int rowIndex) {
+ }
- public boolean isEnabled(IVexWidget vexWidget) {
- ActionUtils.RowColumnInfo rcInfo = ActionUtils.getRowColumnInfo(vexWidget);
- return rcInfo != null && rcInfo.cellIndex > 0;
- }
+ public void onCell(Object row, Object cell,
+ int rowIndex, int cellIndex) {
+ if (cellIndex == rcInfo.cellIndex) {
+ sourceCells.add(this.prevCell);
+ destCells.add(cell);
+ } else if (cellIndex == rcInfo.cellIndex - 1) {
+ this.prevCell = cell;
+ }
+ }
+
+ public void endRow(Object row, int rowIndex) {
+ }
+ });
+
+ // Iterate the deletions in reverse, so that we don't mess up
+ // offsets that are in anonymous cells, which are not stored
+ // as Positions.
+ //
+ // Also, to preserve the current caret position, we don't cut
+ // and paste the current column. Instead, we cut the column
+ // to the left of the current column and paste it on the right.
+ for (int i = sourceCells.size() - 1; i >= 0; i--) {
+
+ Object source = sourceCells.get(i);
+ final IntRange sourceRange = ActionUtils
+ .getOuterRange(source);
+
+ Object dest = destCells.get(i);
+ vexWidget.moveTo(ActionUtils.getOuterRange(dest).getEnd());
+
+ vexWidget.savePosition(new Runnable() {
+ public void run() {
+ vexWidget.moveTo(sourceRange.getStart());
+ vexWidget.moveTo(sourceRange.getEnd(), true);
+ vexWidget.cutSelection();
+ }
+ });
+
+ vexWidget.paste();
+ }
+ }
+ });
+ }
+
+ public boolean isEnabled(IVexWidget vexWidget) {
+ ActionUtils.RowColumnInfo rcInfo = ActionUtils
+ .getRowColumnInfo(vexWidget);
+ return rcInfo != null && rcInfo.cellIndex > 0;
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/MoveColumnRightAction.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/MoveColumnRightAction.java
index 784c00e..c9729c8 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/MoveColumnRightAction.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/MoveColumnRightAction.java
@@ -16,76 +16,84 @@
import org.eclipse.wst.xml.vex.core.internal.core.IntRange;
import org.eclipse.wst.xml.vex.core.internal.widget.IVexWidget;
-
/**
* Moves the current table column to the right.
*/
public class MoveColumnRightAction extends AbstractVexAction {
- public void run(final IVexWidget vexWidget) {
-
- final ActionUtils.RowColumnInfo rcInfo = ActionUtils.getRowColumnInfo(vexWidget);
+ public void run(final IVexWidget vexWidget) {
- if (rcInfo == null || rcInfo.cellIndex >= rcInfo.maxColumnCount - 1) {
- return;
- }
-
- vexWidget.doWork(true, new Runnable() {
- public void run() {
+ final ActionUtils.RowColumnInfo rcInfo = ActionUtils
+ .getRowColumnInfo(vexWidget);
- // Cells to the right of the current column
- final List sourceCells = new ArrayList();
-
- // Cells in the current column
- final List destCells = new ArrayList();
+ if (rcInfo == null || rcInfo.cellIndex >= rcInfo.maxColumnCount - 1) {
+ return;
+ }
- ActionUtils.iterateTableCells(vexWidget, new TableCellCallback() {
- Object thisCell = null;
- public void startRow(Object row, int rowIndex) {
- }
- public void onCell(Object row, Object cell, int rowIndex, int cellIndex) {
- if (cellIndex == rcInfo.cellIndex) {
- this.thisCell = cell;
- } else if (cellIndex == rcInfo.cellIndex + 1) {
- sourceCells.add(cell);
- destCells.add(this.thisCell);
- }
- }
- public void endRow(Object row, int rowIndex) {
- }
- });
+ vexWidget.doWork(true, new Runnable() {
+ public void run() {
- // Iterate the deletions in reverse, so that we don't mess up
- // offsets that are in anonymous cells, which are not stored
- // as Positions.
- //
- // Also, to preserve the current caret position, we don't cut
- // and paste the current column. Instead, we cut the column
- // to the right of the current column and paste it on the left.
- for (int i = sourceCells.size() - 1; i >= 0; i--) {
+ // Cells to the right of the current column
+ final List sourceCells = new ArrayList();
- Object source = sourceCells.get(i);
- final IntRange sourceRange = ActionUtils.getOuterRange(source);
-
- Object dest = destCells.get(i);
- vexWidget.moveTo(ActionUtils.getOuterRange(dest).getStart());
+ // Cells in the current column
+ final List destCells = new ArrayList();
- vexWidget.savePosition(new Runnable() {
- public void run() {
- vexWidget.moveTo(sourceRange.getStart());
- vexWidget.moveTo(sourceRange.getEnd(), true);
- vexWidget.cutSelection();
- }
- });
-
- vexWidget.paste();
- }
- }
- });
- }
+ ActionUtils.iterateTableCells(vexWidget,
+ new TableCellCallback() {
+ Object thisCell = null;
- public boolean isEnabled(IVexWidget vexWidget) {
- ActionUtils.RowColumnInfo rcInfo = ActionUtils.getRowColumnInfo(vexWidget);
- return rcInfo != null && rcInfo.cellIndex < rcInfo.maxColumnCount - 1;
- }
+ public void startRow(Object row, int rowIndex) {
+ }
+
+ public void onCell(Object row, Object cell,
+ int rowIndex, int cellIndex) {
+ if (cellIndex == rcInfo.cellIndex) {
+ this.thisCell = cell;
+ } else if (cellIndex == rcInfo.cellIndex + 1) {
+ sourceCells.add(cell);
+ destCells.add(this.thisCell);
+ }
+ }
+
+ public void endRow(Object row, int rowIndex) {
+ }
+ });
+
+ // Iterate the deletions in reverse, so that we don't mess up
+ // offsets that are in anonymous cells, which are not stored
+ // as Positions.
+ //
+ // Also, to preserve the current caret position, we don't cut
+ // and paste the current column. Instead, we cut the column
+ // to the right of the current column and paste it on the left.
+ for (int i = sourceCells.size() - 1; i >= 0; i--) {
+
+ Object source = sourceCells.get(i);
+ final IntRange sourceRange = ActionUtils
+ .getOuterRange(source);
+
+ Object dest = destCells.get(i);
+ vexWidget
+ .moveTo(ActionUtils.getOuterRange(dest).getStart());
+
+ vexWidget.savePosition(new Runnable() {
+ public void run() {
+ vexWidget.moveTo(sourceRange.getStart());
+ vexWidget.moveTo(sourceRange.getEnd(), true);
+ vexWidget.cutSelection();
+ }
+ });
+
+ vexWidget.paste();
+ }
+ }
+ });
+ }
+
+ public boolean isEnabled(IVexWidget vexWidget) {
+ ActionUtils.RowColumnInfo rcInfo = ActionUtils
+ .getRowColumnInfo(vexWidget);
+ return rcInfo != null && rcInfo.cellIndex < rcInfo.maxColumnCount - 1;
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/MoveRowDownAction.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/MoveRowDownAction.java
index f4b9df0..d6c0e80 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/MoveRowDownAction.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/MoveRowDownAction.java
@@ -13,36 +13,39 @@
import org.eclipse.wst.xml.vex.core.internal.core.IntRange;
import org.eclipse.wst.xml.vex.core.internal.widget.IVexWidget;
-
/**
* Moves the current table row down below its next sibling.
*/
public class MoveRowDownAction extends AbstractVexAction {
- public void run(final IVexWidget vexWidget) {
+ public void run(final IVexWidget vexWidget) {
- final ActionUtils.SelectedRows selected = ActionUtils.getSelectedTableRows(vexWidget);
-
- if (selected.getRows() == null || selected.getRowAfter() == null) {
- return;
- }
-
- vexWidget.doWork(true, new Runnable() {
- public void run() {
- IntRange range = ActionUtils.getOuterRange(selected.getRowAfter());
- vexWidget.moveTo(range.getStart());
- vexWidget.moveTo(range.getEnd(), true);
- vexWidget.cutSelection();
-
- Object firstRow = selected.getRows().get(0);
- vexWidget.moveTo(ActionUtils.getOuterRange(firstRow).getStart());
- vexWidget.paste();
- }
- });
- }
+ final ActionUtils.SelectedRows selected = ActionUtils
+ .getSelectedTableRows(vexWidget);
- public boolean isEnabled(IVexWidget vexWidget) {
- ActionUtils.SelectedRows selected = ActionUtils.getSelectedTableRows(vexWidget);
- return selected.getRows() != null && selected.getRowAfter() != null;
- }
+ if (selected.getRows() == null || selected.getRowAfter() == null) {
+ return;
+ }
+
+ vexWidget.doWork(true, new Runnable() {
+ public void run() {
+ IntRange range = ActionUtils.getOuterRange(selected
+ .getRowAfter());
+ vexWidget.moveTo(range.getStart());
+ vexWidget.moveTo(range.getEnd(), true);
+ vexWidget.cutSelection();
+
+ Object firstRow = selected.getRows().get(0);
+ vexWidget
+ .moveTo(ActionUtils.getOuterRange(firstRow).getStart());
+ vexWidget.paste();
+ }
+ });
+ }
+
+ public boolean isEnabled(IVexWidget vexWidget) {
+ ActionUtils.SelectedRows selected = ActionUtils
+ .getSelectedTableRows(vexWidget);
+ return selected.getRows() != null && selected.getRowAfter() != null;
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/MoveRowUpAction.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/MoveRowUpAction.java
index 2da3806..a7c0777 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/MoveRowUpAction.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/MoveRowUpAction.java
@@ -15,38 +15,40 @@
import org.eclipse.wst.xml.vex.core.internal.core.IntRange;
import org.eclipse.wst.xml.vex.core.internal.widget.IVexWidget;
-
/**
* Moves the current table row up above its previous sibling.
*/
public class MoveRowUpAction extends AbstractVexAction {
- public void run(final IVexWidget vexWidget) {
+ public void run(final IVexWidget vexWidget) {
- final ActionUtils.SelectedRows selected = ActionUtils.getSelectedTableRows(vexWidget);
-
- if (selected.getRows() == null || selected.getRowBefore() == null) {
- return;
- }
-
- vexWidget.doWork(true, new Runnable() {
- public void run() {
- IntRange range = ActionUtils.getOuterRange(selected.getRowBefore());
- vexWidget.moveTo(range.getStart());
- vexWidget.moveTo(range.getEnd(), true);
- vexWidget.cutSelection();
-
- List rows = selected.getRows();
- Object lastRow = rows.get(rows.size() - 1);
- vexWidget.moveTo(ActionUtils.getOuterRange(lastRow).getEnd());
- vexWidget.paste();
- }
- });
- }
+ final ActionUtils.SelectedRows selected = ActionUtils
+ .getSelectedTableRows(vexWidget);
- public boolean isEnabled(IVexWidget vexWidget) {
- ActionUtils.SelectedRows selected = ActionUtils.getSelectedTableRows(vexWidget);
- return selected.getRows() != null && selected.getRowBefore() != null;
- }
-
+ if (selected.getRows() == null || selected.getRowBefore() == null) {
+ return;
+ }
+
+ vexWidget.doWork(true, new Runnable() {
+ public void run() {
+ IntRange range = ActionUtils.getOuterRange(selected
+ .getRowBefore());
+ vexWidget.moveTo(range.getStart());
+ vexWidget.moveTo(range.getEnd(), true);
+ vexWidget.cutSelection();
+
+ List rows = selected.getRows();
+ Object lastRow = rows.get(rows.size() - 1);
+ vexWidget.moveTo(ActionUtils.getOuterRange(lastRow).getEnd());
+ vexWidget.paste();
+ }
+ });
+ }
+
+ public boolean isEnabled(IVexWidget vexWidget) {
+ ActionUtils.SelectedRows selected = ActionUtils
+ .getSelectedTableRows(vexWidget);
+ return selected.getRows() != null && selected.getRowBefore() != null;
+ }
+
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/MoveSelectionUpAction.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/MoveSelectionUpAction.java
index 1139873..24c63bf 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/MoveSelectionUpAction.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/MoveSelectionUpAction.java
@@ -16,65 +16,69 @@
import org.eclipse.wst.xml.vex.core.internal.widget.IBoxFilter;
import org.eclipse.wst.xml.vex.core.internal.widget.IVexWidget;
-
/**
- * Moves the current selection or block element above the previous sibling.
- * WORK IN PROGRESS.
+ * Moves the current selection or block element above the previous sibling. WORK
+ * IN PROGRESS.
*/
public class MoveSelectionUpAction extends AbstractVexAction {
- public void run(final IVexWidget vexWidget) {
+ public void run(final IVexWidget vexWidget) {
- // First we determine whether we should expand the selection
- // to contain an entire block box.
-
- // Find the lowest block box that completely contains the
- // selection
- Box box = vexWidget.findInnermostBox(new IBoxFilter() {
- public boolean matches(Box box) {
- return box instanceof BlockBox
- && box.getElement() != null
- && box.getStartOffset() <= vexWidget.getSelectionStart()
- && box.getEndOffset() >= vexWidget.getSelectionEnd();
- }
- });
-
- Box[] children = box.getChildren();
- if (children.length > 0 && children[0] instanceof BlockBox) {
- // The found box contains other block children, so we
- // do NOT have to expand the selection
- } else {
- // Expand selection to the containing box
-
- // (Note: This "if" is caused by the fact that getStartOffset is treated
- // differently between elements and boxes. Boxes own their startOffset,
- // while elements don't own theirs. Perhaps we should fix this by having
- // box.getStartOffset() return box.getStartPosition() + 1, but this would
- // be a VERY large change.)
- System.out.println("Box is " + box);
- Element element = box.getElement();
- if (element != null) {
- vexWidget.moveTo(element.getEndOffset());
- vexWidget.moveTo(element.getStartOffset(), true);
-
- } else {
- vexWidget.moveTo(box.getEndOffset());
- vexWidget.moveTo(box.getStartOffset(), true);
- }
- }
-
-// final int previousSiblingStart = ActionUtils.getPreviousSiblingStart(vexWidget);
-//
-// vexWidget.doWork(new IRunnable() {
-// public void run() throws Exception {
-// vexWidget.cutSelection();
-// vexWidget.moveTo(previousSiblingStart);
-// vexWidget.paste();
-// vexWidget.moveTo(previousSiblingStart, true);
-// }
-// });
-
-
- }
+ // First we determine whether we should expand the selection
+ // to contain an entire block box.
+
+ // Find the lowest block box that completely contains the
+ // selection
+ Box box = vexWidget.findInnermostBox(new IBoxFilter() {
+ public boolean matches(Box box) {
+ return box instanceof BlockBox
+ && box.getElement() != null
+ && box.getStartOffset() <= vexWidget
+ .getSelectionStart()
+ && box.getEndOffset() >= vexWidget.getSelectionEnd();
+ }
+ });
+
+ Box[] children = box.getChildren();
+ if (children.length > 0 && children[0] instanceof BlockBox) {
+ // The found box contains other block children, so we
+ // do NOT have to expand the selection
+ } else {
+ // Expand selection to the containing box
+
+ // (Note: This "if" is caused by the fact that getStartOffset is
+ // treated
+ // differently between elements and boxes. Boxes own their
+ // startOffset,
+ // while elements don't own theirs. Perhaps we should fix this by
+ // having
+ // box.getStartOffset() return box.getStartPosition() + 1, but this
+ // would
+ // be a VERY large change.)
+ System.out.println("Box is " + box);
+ Element element = box.getElement();
+ if (element != null) {
+ vexWidget.moveTo(element.getEndOffset());
+ vexWidget.moveTo(element.getStartOffset(), true);
+
+ } else {
+ vexWidget.moveTo(box.getEndOffset());
+ vexWidget.moveTo(box.getStartOffset(), true);
+ }
+ }
+
+ // final int previousSiblingStart =
+ // ActionUtils.getPreviousSiblingStart(vexWidget);
+ //
+ // vexWidget.doWork(new IRunnable() {
+ // public void run() throws Exception {
+ // vexWidget.cutSelection();
+ // vexWidget.moveTo(previousSiblingStart);
+ // vexWidget.paste();
+ // vexWidget.moveTo(previousSiblingStart, true);
+ // }
+ // });
+
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/NextTableCellAction.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/NextTableCellAction.java
index 2b4b29e..db89d3a 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/NextTableCellAction.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/NextTableCellAction.java
@@ -15,58 +15,57 @@
import org.eclipse.wst.xml.vex.core.internal.widget.IBoxFilter;
import org.eclipse.wst.xml.vex.core.internal.widget.IVexWidget;
-
/**
- * Moves the caret to the next table cell. The contents of the cell
- * are selected. If the current cell is the last cell in the table,
- * the current row is duplicated.
+ * Moves the caret to the next table cell. The contents of the cell are
+ * selected. If the current cell is the last cell in the table, the current row
+ * is duplicated.
*/
public class NextTableCellAction extends AbstractVexAction {
- public void run(final IVexWidget vexWidget) {
-
- final TableRowBox tr = (TableRowBox) vexWidget.findInnermostBox(new IBoxFilter() {
- public boolean matches(Box box) {
- return box instanceof TableRowBox;
- }
- });
+ public void run(final IVexWidget vexWidget) {
- if (tr == null) {
- // not in a table row
- return;
- }
-
- int offset = vexWidget.getCaretOffset();
-
- Box[] cells = tr.getChildren();
- for (int i = 0; i < cells.length; i++) {
- if (cells[i].getStartOffset() > offset) {
- vexWidget.moveTo(cells[i].getStartOffset());
- vexWidget.moveTo(cells[i].getEndOffset(), true);
- return;
- }
- }
-
- // No next cell found in this row
- // Find the next row
- Box[] rows = tr.getParent().getChildren();
- for (int i = 0; i < rows.length; i++) {
- if (rows[i].getStartOffset() > offset) {
- cells = rows[i].getChildren();
- if (cells.length > 0) {
- Box cell = cells[0];
- vexWidget.moveTo(cell.getStartOffset());
- vexWidget.moveTo(cell.getEndOffset(), true);
- } else {
- System.out.println("TODO - dup row into new empty row");
- }
- return;
- }
- }
-
+ final TableRowBox tr = (TableRowBox) vexWidget
+ .findInnermostBox(new IBoxFilter() {
+ public boolean matches(Box box) {
+ return box instanceof TableRowBox;
+ }
+ });
- // We didn't find a "next row", so let's dup the current one
- ActionUtils.duplicateTableRow(vexWidget, tr);
-
- }
+ if (tr == null) {
+ // not in a table row
+ return;
+ }
+
+ int offset = vexWidget.getCaretOffset();
+
+ Box[] cells = tr.getChildren();
+ for (int i = 0; i < cells.length; i++) {
+ if (cells[i].getStartOffset() > offset) {
+ vexWidget.moveTo(cells[i].getStartOffset());
+ vexWidget.moveTo(cells[i].getEndOffset(), true);
+ return;
+ }
+ }
+
+ // No next cell found in this row
+ // Find the next row
+ Box[] rows = tr.getParent().getChildren();
+ for (int i = 0; i < rows.length; i++) {
+ if (rows[i].getStartOffset() > offset) {
+ cells = rows[i].getChildren();
+ if (cells.length > 0) {
+ Box cell = cells[0];
+ vexWidget.moveTo(cell.getStartOffset());
+ vexWidget.moveTo(cell.getEndOffset(), true);
+ } else {
+ System.out.println("TODO - dup row into new empty row");
+ }
+ return;
+ }
+ }
+
+ // We didn't find a "next row", so let's dup the current one
+ ActionUtils.duplicateTableRow(vexWidget, tr);
+
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/PasteTextAction.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/PasteTextAction.java
index 38dca68..17f401f 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/PasteTextAction.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/PasteTextAction.java
@@ -13,16 +13,17 @@
import org.eclipse.wst.xml.vex.core.internal.widget.IVexWidget;
/**
- * Paste the clipboard contents into the document as plain text, ignoring
- * any markup.
+ * Paste the clipboard contents into the document as plain text, ignoring any
+ * markup.
*/
public class PasteTextAction extends AbstractVexAction {
- public void run(IVexWidget vexWidget) {
- throw new UnsupportedOperationException("PasteTextAction is not yet implemented.");
- }
+ public void run(IVexWidget vexWidget) {
+ throw new UnsupportedOperationException(
+ "PasteTextAction is not yet implemented.");
+ }
- public boolean isEnabled(IVexWidget vexWidget) {
- return false;
- }
+ public boolean isEnabled(IVexWidget vexWidget) {
+ return false;
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/PreviousTableCellAction.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/PreviousTableCellAction.java
index 045f922..74347fb 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/PreviousTableCellAction.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/PreviousTableCellAction.java
@@ -15,52 +15,52 @@
import org.eclipse.wst.xml.vex.core.internal.widget.IBoxFilter;
import org.eclipse.wst.xml.vex.core.internal.widget.IVexWidget;
-
/**
- * Moves the caret to the next table cell. The contents of the cell
- * are selected. If the current cell is the last cell in the table,
- * the current row is duplicated.
+ * Moves the caret to the next table cell. The contents of the cell are
+ * selected. If the current cell is the last cell in the table, the current row
+ * is duplicated.
*/
public class PreviousTableCellAction extends AbstractVexAction {
- public void run(final IVexWidget vexWidget) {
-
- final TableRowBox tr = (TableRowBox) vexWidget.findInnermostBox(new IBoxFilter() {
- public boolean matches(Box box) {
- return box instanceof TableRowBox;
- }
- });
+ public void run(final IVexWidget vexWidget) {
- if (tr == null) {
- // not in a table row
- return;
- }
-
- int offset = vexWidget.getCaretOffset();
-
- Box[] cells = tr.getChildren();
- for (int i = cells.length - 1; i >= 0; i--) {
- if (cells[i].getEndOffset() < offset) {
- vexWidget.moveTo(cells[i].getStartOffset());
- vexWidget.moveTo(cells[i].getEndOffset(), true);
- return;
- }
- }
-
- // No next cell found in this row
- // Find the previous row
- Box[] rows = tr.getParent().getChildren();
- for (int i = rows.length - 1; i >= 0; i--) {
- if (rows[i].getEndOffset() < offset) {
- cells = rows[i].getChildren();
- if (cells.length > 0) {
- Box cell = cells[cells.length - 1];
- vexWidget.moveTo(cell.getStartOffset());
- vexWidget.moveTo(cell.getEndOffset(), true);
- }
- return;
- }
- }
-
- }
+ final TableRowBox tr = (TableRowBox) vexWidget
+ .findInnermostBox(new IBoxFilter() {
+ public boolean matches(Box box) {
+ return box instanceof TableRowBox;
+ }
+ });
+
+ if (tr == null) {
+ // not in a table row
+ return;
+ }
+
+ int offset = vexWidget.getCaretOffset();
+
+ Box[] cells = tr.getChildren();
+ for (int i = cells.length - 1; i >= 0; i--) {
+ if (cells[i].getEndOffset() < offset) {
+ vexWidget.moveTo(cells[i].getStartOffset());
+ vexWidget.moveTo(cells[i].getEndOffset(), true);
+ return;
+ }
+ }
+
+ // No next cell found in this row
+ // Find the previous row
+ Box[] rows = tr.getParent().getChildren();
+ for (int i = rows.length - 1; i >= 0; i--) {
+ if (rows[i].getEndOffset() < offset) {
+ cells = rows[i].getChildren();
+ if (cells.length > 0) {
+ Box cell = cells[cells.length - 1];
+ vexWidget.moveTo(cell.getStartOffset());
+ vexWidget.moveTo(cell.getEndOffset(), true);
+ }
+ return;
+ }
+ }
+
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/RemoveElementAction.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/RemoveElementAction.java
index 6cc3a94..5cca284 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/RemoveElementAction.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/RemoveElementAction.java
@@ -14,27 +14,26 @@
import org.eclipse.wst.xml.vex.core.internal.dom.Element;
import org.eclipse.wst.xml.vex.core.internal.widget.IVexWidget;
-
/**
* Removes the current element, adding its content to the parent element.
*/
public class RemoveElementAction extends AbstractVexAction {
- public void run(final IVexWidget vexWidget) {
- vexWidget.doWork(new Runnable() {
- public void run() {
- Element element =
- vexWidget.getDocument().getElementAt(vexWidget.getCaretOffset());
- vexWidget.moveTo(element.getStartOffset() + 1, false);
- vexWidget.moveTo(element.getEndOffset(), true);
- DocumentFragment frag = vexWidget.getSelectedFragment();
- vexWidget.deleteSelection();
- vexWidget.moveBy(-1, false);
- vexWidget.moveBy(2, true);
- vexWidget.deleteSelection();
- vexWidget.insertFragment(frag);
- }
- });
- }
+ public void run(final IVexWidget vexWidget) {
+ vexWidget.doWork(new Runnable() {
+ public void run() {
+ Element element = vexWidget.getDocument().getElementAt(
+ vexWidget.getCaretOffset());
+ vexWidget.moveTo(element.getStartOffset() + 1, false);
+ vexWidget.moveTo(element.getEndOffset(), true);
+ DocumentFragment frag = vexWidget.getSelectedFragment();
+ vexWidget.deleteSelection();
+ vexWidget.moveBy(-1, false);
+ vexWidget.moveBy(2, true);
+ vexWidget.deleteSelection();
+ vexWidget.insertFragment(frag);
+ }
+ });
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/RestoreLastSelectionAction.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/RestoreLastSelectionAction.java
index 1956978..175a319 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/RestoreLastSelectionAction.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/RestoreLastSelectionAction.java
@@ -17,11 +17,12 @@
*/
public class RestoreLastSelectionAction extends AbstractVexAction {
- public void run(IVexWidget vexWidget) {
- throw new UnsupportedOperationException("RestoreLastSelectionAction is not yet implemented.");
- }
+ public void run(IVexWidget vexWidget) {
+ throw new UnsupportedOperationException(
+ "RestoreLastSelectionAction is not yet implemented.");
+ }
- public boolean isEnabled(IVexWidget vexWidget) {
- return false;
- }
+ public boolean isEnabled(IVexWidget vexWidget) {
+ return false;
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/SplitAction.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/SplitAction.java
index d41448c..370c7c6 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/SplitAction.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/SplitAction.java
@@ -21,84 +21,88 @@
import org.eclipse.wst.xml.vex.core.internal.dom.Element;
import org.eclipse.wst.xml.vex.core.internal.widget.IVexWidget;
-
/**
* Splits the current block element.
*/
public class SplitAction extends AbstractVexAction {
- public void run(final IVexWidget vexWidget) {
- Element element = vexWidget.getCurrentElement();
- Styles styles = vexWidget.getStyleSheet().getStyles(element);
- while (!styles.isBlock()) {
- element = element.getParent();
- styles = vexWidget.getStyleSheet().getStyles(element);
- }
- splitElement(vexWidget, element);
- }
+ public void run(final IVexWidget vexWidget) {
+ Element element = vexWidget.getCurrentElement();
+ Styles styles = vexWidget.getStyleSheet().getStyles(element);
+ while (!styles.isBlock()) {
+ element = element.getParent();
+ styles = vexWidget.getStyleSheet().getStyles(element);
+ }
+ splitElement(vexWidget, element);
+ }
+ /**
+ * Splits the given element.
+ *
+ * @param vexWidget
+ * IVexWidget containing the document.
+ * @param element
+ * Element to be split.
+ */
+ public static void splitElement(final IVexWidget vexWidget,
+ final Element element) {
- /**
- * Splits the given element.
- * @param vexWidget IVexWidget containing the document.
- * @param element Element to be split.
- */
- public static void splitElement(final IVexWidget vexWidget, final Element element) {
-
- vexWidget.doWork(new Runnable() {
- public void run() {
+ vexWidget.doWork(new Runnable() {
+ public void run() {
- long start = 0;
- if (VEXCorePlugin.getInstance().isDebugging()) {
- start = System.currentTimeMillis();
- }
-
- Styles styles = vexWidget.getStyleSheet().getStyles(element);
-
- if (styles.getWhiteSpace().equals(CSS.PRE)) {
- // can't call vexWidget.insertText() or we'll get an infinite loop
- Document doc = vexWidget.getDocument();
- int offset = vexWidget.getCaretOffset();
- doc.insertText(offset, "\n");
- vexWidget.moveTo(offset + 1);
- } else {
-
- // There may be a number of child elements below the given
- // element. We cut out the tails of each of these elements
- // and put them in a list of fragments to be reconstructed when
- // we clone the element.
- List children = new ArrayList();
- List frags = new ArrayList();
- Element child = vexWidget.getCurrentElement();
- while (true) {
- children.add(child);
- vexWidget.moveTo(child.getEndOffset(), true);
- frags.add(vexWidget.getSelectedFragment());
- vexWidget.deleteSelection();
- vexWidget.moveTo(child.getEndOffset() + 1);
- if (child == element) {
- break;
- }
- child = child.getParent();
- }
+ long start = 0;
+ if (VEXCorePlugin.getInstance().isDebugging()) {
+ start = System.currentTimeMillis();
+ }
- for (int i = children.size() - 1; i >= 0; i--) {
- child = (Element) children.get(i);
- DocumentFragment frag = (DocumentFragment) frags.get(i);
- vexWidget.insertElement((Element) child.clone());
- int offset = vexWidget.getCaretOffset();
- if (frag != null) {
- vexWidget.insertFragment(frag);
- }
- vexWidget.moveTo(offset);
- }
- }
+ Styles styles = vexWidget.getStyleSheet().getStyles(element);
- if (VEXCorePlugin.getInstance().isDebugging()) {
- long end = System.currentTimeMillis();
- System.out.println("split() took " + (end - start) + "ms");
- }
- }
- });
- }
+ if (styles.getWhiteSpace().equals(CSS.PRE)) {
+ // can't call vexWidget.insertText() or we'll get an
+ // infinite loop
+ Document doc = vexWidget.getDocument();
+ int offset = vexWidget.getCaretOffset();
+ doc.insertText(offset, "\n");
+ vexWidget.moveTo(offset + 1);
+ } else {
+
+ // There may be a number of child elements below the given
+ // element. We cut out the tails of each of these elements
+ // and put them in a list of fragments to be reconstructed
+ // when
+ // we clone the element.
+ List children = new ArrayList();
+ List frags = new ArrayList();
+ Element child = vexWidget.getCurrentElement();
+ while (true) {
+ children.add(child);
+ vexWidget.moveTo(child.getEndOffset(), true);
+ frags.add(vexWidget.getSelectedFragment());
+ vexWidget.deleteSelection();
+ vexWidget.moveTo(child.getEndOffset() + 1);
+ if (child == element) {
+ break;
+ }
+ child = child.getParent();
+ }
+
+ for (int i = children.size() - 1; i >= 0; i--) {
+ child = (Element) children.get(i);
+ DocumentFragment frag = (DocumentFragment) frags.get(i);
+ vexWidget.insertElement((Element) child.clone());
+ int offset = vexWidget.getCaretOffset();
+ if (frag != null) {
+ vexWidget.insertFragment(frag);
+ }
+ vexWidget.moveTo(offset);
+ }
+ }
+
+ if (VEXCorePlugin.getInstance().isDebugging()) {
+ long end = System.currentTimeMillis();
+ System.out.println("split() took " + (end - start) + "ms");
+ }
+ }
+ });
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/SplitItemAction.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/SplitItemAction.java
index 1c328fb..001d5ea 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/SplitItemAction.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/SplitItemAction.java
@@ -18,38 +18,39 @@
import org.eclipse.wst.xml.vex.core.internal.widget.IBoxFilter;
import org.eclipse.wst.xml.vex.core.internal.widget.IVexWidget;
-
/**
* Splits the nearest enclosing table row or list item. If a table row is being
* split, empty versions of the current row's cells are created.
*/
public class SplitItemAction extends AbstractVexAction {
- public void run(IVexWidget vexWidget) {
+ public void run(IVexWidget vexWidget) {
- final StyleSheet ss = vexWidget.getStyleSheet();
-
- // Item is either a TableRowBox or a BlockElementBox representing
- // a list item
- Box item = vexWidget.findInnermostBox(new IBoxFilter() {
- public boolean matches(Box box) {
- if (box instanceof TableRowBox) {
- return true;
- } else {
- Element element = box.getElement();
- return element != null && ss.getStyles(element).getDisplay().equals(CSS.LIST_ITEM);
- }
- }
- });
+ final StyleSheet ss = vexWidget.getStyleSheet();
- if (item instanceof TableRowBox) {
- insertRowBelowAction.run(vexWidget);
- //ActionUtils.duplicateTableRow(vexWidget, (TableRowBox) item);
- } else if (item != null) {
- SplitAction.splitElement(vexWidget, item.getElement());
- }
- }
-
- private static InsertRowBelowAction insertRowBelowAction = new InsertRowBelowAction();
-
+ // Item is either a TableRowBox or a BlockElementBox representing
+ // a list item
+ Box item = vexWidget.findInnermostBox(new IBoxFilter() {
+ public boolean matches(Box box) {
+ if (box instanceof TableRowBox) {
+ return true;
+ } else {
+ Element element = box.getElement();
+ return element != null
+ && ss.getStyles(element).getDisplay().equals(
+ CSS.LIST_ITEM);
+ }
+ }
+ });
+
+ if (item instanceof TableRowBox) {
+ insertRowBelowAction.run(vexWidget);
+ // ActionUtils.duplicateTableRow(vexWidget, (TableRowBox) item);
+ } else if (item != null) {
+ SplitAction.splitElement(vexWidget, item.getElement());
+ }
+ }
+
+ private static InsertRowBelowAction insertRowBelowAction = new InsertRowBelowAction();
+
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/TableCellCallback.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/TableCellCallback.java
index 907bc30..432576e 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/TableCellCallback.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/action/TableCellCallback.java
@@ -15,30 +15,38 @@
*/
public interface TableCellCallback {
- /**
- * Called before the first cell in a row is visited.
- *
- * @param row Element or IntRange representing the row.
- * @param rowIndex Zero-based index of the row.
- */
- public void startRow(Object row, int rowIndex);
-
- /**
- * Called when a cell is visited.
- *
- * @param row Element or IntRange representing the row.
- * @param cell Element or IntRange representing the cell.
- * @param rowIndex Zero-based index of the current row.
- * @param cellIndex Zero-based index of the current cell.
- */
- public void onCell(Object row, Object cell, int rowIndex, int cellIndex);
+ /**
+ * Called before the first cell in a row is visited.
+ *
+ * @param row
+ * Element or IntRange representing the row.
+ * @param rowIndex
+ * Zero-based index of the row.
+ */
+ public void startRow(Object row, int rowIndex);
- /**
- * Called after the last cell in a row is visited.
- *
- * @param row Element or IntRange representing the row.
- * @param rowIndex Zero-based index of the row.
- */
- public void endRow(Object row, int rowIndex);
-
+ /**
+ * Called when a cell is visited.
+ *
+ * @param row
+ * Element or IntRange representing the row.
+ * @param cell
+ * Element or IntRange representing the cell.
+ * @param rowIndex
+ * Zero-based index of the current row.
+ * @param cellIndex
+ * Zero-based index of the current cell.
+ */
+ public void onCell(Object row, Object cell, int rowIndex, int cellIndex);
+
+ /**
+ * Called after the last cell in a row is visited.
+ *
+ * @param row
+ * Element or IntRange representing the row.
+ * @param rowIndex
+ * Zero-based index of the row.
+ */
+ public void endRow(Object row, int rowIndex);
+
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Caret.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Caret.java
index 1078ebc..dbb41e2 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Caret.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Caret.java
@@ -11,57 +11,66 @@
package org.eclipse.wst.xml.vex.core.internal.core;
/**
- * Represents the caret, a line that indicates an insertion point in the
+ * Represents the caret, a line that indicates an insertion point in the
* document.
*/
public abstract class Caret {
- private int x;
- private int y;
-
- /**
- * Class constructor
- * @param x x-coordinate of the top left corner of the caret
- * @param y y-coordinate of the top left corner of the caret
- */
- public Caret(int x, int y) {
- this.x = x;
- this.y = y;
- }
-
- /**
- * Draws the caret in the given Graphics context.
- * @param g Graphics within which the caret should be drawn.
- * @param color Color with which the caret should be drawn.
- */
- public abstract void draw(Graphics g, Color color);
-
- /**
- * Returns the smallest rectangle that completely encloses the caret.
- */
- public abstract Rectangle getBounds();
-
- /**
- * Returns the x-coordinate of the top left corner of the caret
- */
- public int getX() {
- return this.x;
- }
-
- /**
- * Returns the y-coordinate of the top left corner of the caret
- */
- public int getY() {
- return this.y;
- }
-
- /**
- * Moves the caret by the given x and y distance.
- * @param x amount by which to move the caret to the right
- * @param y amount by which to move the caret down
- */
- public void translate(int x, int y) {
- this.x += x;
- this.y += y;
- }
+ private int x;
+ private int y;
+
+ /**
+ * Class constructor
+ *
+ * @param x
+ * x-coordinate of the top left corner of the caret
+ * @param y
+ * y-coordinate of the top left corner of the caret
+ */
+ public Caret(int x, int y) {
+ this.x = x;
+ this.y = y;
+ }
+
+ /**
+ * Draws the caret in the given Graphics context.
+ *
+ * @param g
+ * Graphics within which the caret should be drawn.
+ * @param color
+ * Color with which the caret should be drawn.
+ */
+ public abstract void draw(Graphics g, Color color);
+
+ /**
+ * Returns the smallest rectangle that completely encloses the caret.
+ */
+ public abstract Rectangle getBounds();
+
+ /**
+ * Returns the x-coordinate of the top left corner of the caret
+ */
+ public int getX() {
+ return this.x;
+ }
+
+ /**
+ * Returns the y-coordinate of the top left corner of the caret
+ */
+ public int getY() {
+ return this.y;
+ }
+
+ /**
+ * Moves the caret by the given x and y distance.
+ *
+ * @param x
+ * amount by which to move the caret to the right
+ * @param y
+ * amount by which to move the caret down
+ */
+ public void translate(int x, int y) {
+ this.x += x;
+ this.y += y;
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Color.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Color.java
index 420774a..b45099e 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Color.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Color.java
@@ -17,68 +17,72 @@
*/
public class Color {
- public static final Color BLACK = new Color(0, 0, 0);
-
- private int red;
- private int green;
- private int blue;
-
- /**
- * Class constructor.
- *
- * @param red red value, 0..255
- * @param green green value, 0..255
- * @param blue blue value, 0..255
- */
- public Color(int red, int green, int blue) {
- this.red = red;
- this.green = green;
- this.blue = blue;
- }
+ public static final Color BLACK = new Color(0, 0, 0);
- /**
- * Returns the blue component of the color, in the range 0..255
- */
- public int getBlue() {
- return blue;
- }
+ private int red;
+ private int green;
+ private int blue;
- /**
- * Returns the green component of the color, in the range 0..255
- */
- public int getGreen() {
- return green;
- }
+ /**
+ * Class constructor.
+ *
+ * @param red
+ * red value, 0..255
+ * @param green
+ * green value, 0..255
+ * @param blue
+ * blue value, 0..255
+ */
+ public Color(int red, int green, int blue) {
+ this.red = red;
+ this.green = green;
+ this.blue = blue;
+ }
- /**
- * Returns the red component of the color, in the range 0..255
- */
- public int getRed() {
- return red;
- }
-
- public boolean equals(Object o) {
- if (o.getClass() != this.getClass()) {
- return false;
- }
- Color c = (Color) o;
- return this.red == c.red && this.green == c.green && this.blue == c.blue;
- }
+ /**
+ * Returns the blue component of the color, in the range 0..255
+ */
+ public int getBlue() {
+ return blue;
+ }
- public int hashCode() {
- return this.red + this.green << 16 + this.blue << 24;
- }
-
- public String toString() {
- StringBuffer sb = new StringBuffer(20);
- sb.append("Color[r=");
- sb.append(this.red);
- sb.append(",g=");
- sb.append(this.green);
- sb.append(",b=");
- sb.append(this.blue);
- sb.append("]");
- return sb.toString();
- }
+ /**
+ * Returns the green component of the color, in the range 0..255
+ */
+ public int getGreen() {
+ return green;
+ }
+
+ /**
+ * Returns the red component of the color, in the range 0..255
+ */
+ public int getRed() {
+ return red;
+ }
+
+ public boolean equals(Object o) {
+ if (o.getClass() != this.getClass()) {
+ return false;
+ }
+ Color c = (Color) o;
+ return this.red == c.red && this.green == c.green
+ && this.blue == c.blue;
+ }
+
+ public int hashCode() {
+ return this.red + this.green << 16 + this.blue << 24;
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer(20);
+ sb.append("Color[r=");
+ sb.append(this.red);
+ sb.append(",g=");
+ sb.append(this.green);
+ sb.append(",b=");
+ sb.append(this.blue);
+ sb.append("]");
+ return sb.toString();
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/ColorResource.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/ColorResource.java
index 94ad77f..914173e 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/ColorResource.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/ColorResource.java
@@ -11,15 +11,15 @@
package org.eclipse.wst.xml.vex.core.internal.core;
/**
- * Wrapper for a toolkit-defined color. Color objects are system resources.
- * They should be retrieved with the Graphics.createColor method and should
- * be disposed when no longer needed.
+ * Wrapper for a toolkit-defined color. Color objects are system resources. They
+ * should be retrieved with the Graphics.createColor method and should be
+ * disposed when no longer needed.
*/
public interface ColorResource {
- public static final int SELECTION_BACKGROUND = 0;
- public static final int SELECTION_FOREGROUND = 1;
-
- public void dispose();
+ public static final int SELECTION_BACKGROUND = 0;
+ public static final int SELECTION_FOREGROUND = 1;
+
+ public void dispose();
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/DisplayDevice.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/DisplayDevice.java
index f4527fd..24038ae 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/DisplayDevice.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/DisplayDevice.java
@@ -11,45 +11,46 @@
package org.eclipse.wst.xml.vex.core.internal.core;
/**
- * Represents a device that can display graphics. This class is subclassed
- * for each target system.
+ * Represents a device that can display graphics. This class is subclassed for
+ * each target system.
*/
public abstract class DisplayDevice {
- /**
- * Class constructor.
- */
- public DisplayDevice() {
- }
+ /**
+ * Class constructor.
+ */
+ public DisplayDevice() {
+ }
- /**
- * Returns the current display device.
- */
- public static DisplayDevice getCurrent() {
- return current;
- }
- /**
- * Returns the horizontal resolution of the device, in pixels-per-inch.
- */
- public abstract int getHorizontalPPI();
-
+ /**
+ * Returns the current display device.
+ */
+ public static DisplayDevice getCurrent() {
+ return current;
+ }
- /**
- * Returns the horizontal resolution of the device, in pixels-per-inch.
- */
- public abstract int getVerticalPPI();
+ /**
+ * Returns the horizontal resolution of the device, in pixels-per-inch.
+ */
+ public abstract int getHorizontalPPI();
-
- /**
- * Sets the current display device. This is typically called by the
- * platform-specific widget;
- * @param current The device to use as the current device.
- */
- public static void setCurrent(DisplayDevice current) {
- DisplayDevice.current = current;
- }
-
- //======================================================= PRIVATE
-
- private static DisplayDevice current;
+ /**
+ * Returns the horizontal resolution of the device, in pixels-per-inch.
+ */
+ public abstract int getVerticalPPI();
+
+ /**
+ * Sets the current display device. This is typically called by the
+ * platform-specific widget;
+ *
+ * @param current
+ * The device to use as the current device.
+ */
+ public static void setCurrent(DisplayDevice current) {
+ DisplayDevice.current = current;
+ }
+
+ // ======================================================= PRIVATE
+
+ private static DisplayDevice current;
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Drawable.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Drawable.java
index d393279..2ba63d8 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Drawable.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Drawable.java
@@ -14,19 +14,22 @@
* An object that can be drawn into a Graphics.
*/
public interface Drawable {
-
- /**
- * Draw the object.
- * @param g Graphics into which to draw the object.
- * @param x x-coordinate where the object should be drawn
- * @param y y-coordinate where the object should be drawn
- */
- public void draw(Graphics g, int x, int y);
- /**
- * Returns the smallest rectangle that completely encloses the
- * drawn shape.
- */
- public Rectangle getBounds();
-
+ /**
+ * Draw the object.
+ *
+ * @param g
+ * Graphics into which to draw the object.
+ * @param x
+ * x-coordinate where the object should be drawn
+ * @param y
+ * y-coordinate where the object should be drawn
+ */
+ public void draw(Graphics g, int x, int y);
+
+ /**
+ * Returns the smallest rectangle that completely encloses the drawn shape.
+ */
+ public Rectangle getBounds();
+
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/FontMetrics.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/FontMetrics.java
index b758735..e46771a 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/FontMetrics.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/FontMetrics.java
@@ -14,8 +14,11 @@
* Toolkit-independent font metrics.
*/
public interface FontMetrics {
- public int getAscent();
- public int getDescent();
- public int getHeight();
- public int getLeading();
+ public int getAscent();
+
+ public int getDescent();
+
+ public int getHeight();
+
+ public int getLeading();
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/FontResource.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/FontResource.java
index 58019d6..037f4da 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/FontResource.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/FontResource.java
@@ -11,11 +11,11 @@
package org.eclipse.wst.xml.vex.core.internal.core;
/**
- * Wrapper for a toolkit-defined font. Fonts are system-defined resources.
- * They must be retrieved from the Graphics.createFont method, and must be
- * disposed when no longer needed.
+ * Wrapper for a toolkit-defined font. Fonts are system-defined resources. They
+ * must be retrieved from the Graphics.createFont method, and must be disposed
+ * when no longer needed.
*/
public interface FontResource {
- public void dispose();
+ public void dispose();
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/FontSpec.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/FontSpec.java
index 1aec35d..8cb4474 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/FontSpec.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/FontSpec.java
@@ -12,65 +12,71 @@
package org.eclipse.wst.xml.vex.core.internal.core;
/**
- * Toolkit-independent specifier of a font. This class does not encapsulate
- * an actual font, but simply the information needed
- * for the toolkit to find an actual font.
+ * Toolkit-independent specifier of a font. This class does not encapsulate an
+ * actual font, but simply the information needed for the toolkit to find an
+ * actual font.
*
- * <p>An array of font family names may be specified. If more than one name
- * is specified, the toolkit should select the first name that matches an
- * actual font on the platform.</p>
+ * <p>
+ * An array of font family names may be specified. If more than one name is
+ * specified, the toolkit should select the first name that matches an actual
+ * font on the platform.
+ * </p>
*/
public class FontSpec {
-
- public static final int PLAIN = 0x0;
- public static final int BOLD = 1<<0;
- public static final int ITALIC = 1<<1;
- public static final int UNDERLINE = 1<<2;
- public static final int OVERLINE = 1<<3;
- public static final int LINE_THROUGH = 1<<4;
- private String[] names;
- private float size;
- private int style;
+ public static final int PLAIN = 0x0;
+ public static final int BOLD = 1 << 0;
+ public static final int ITALIC = 1 << 1;
+ public static final int UNDERLINE = 1 << 2;
+ public static final int OVERLINE = 1 << 3;
+ public static final int LINE_THROUGH = 1 << 4;
- /**
- * Class constructor.
- * @param names Array of names of the font family.
- * @param style Bitwise-OR of the applicable style flages, e.g. BOLD | ITALIC
- * @param size Size of the font, in points.
- */
- public FontSpec(String[] names, int style, float size) {
- this.names = names;
- this.style = style;
- this.size = size;
- }
-
- /**
- * Returns the names of the font families that match the font.
- */
- public String[] getNames() {
- return names;
- }
+ private String[] names;
+ private float size;
+ private int style;
- /**
- * Returns the size of the font in points.
- */
- public float getSize() {
- return size;
- }
+ /**
+ * Class constructor.
+ *
+ * @param names
+ * Array of names of the font family.
+ * @param style
+ * Bitwise-OR of the applicable style flages, e.g. BOLD | ITALIC
+ * @param size
+ * Size of the font, in points.
+ */
+ public FontSpec(String[] names, int style, float size) {
+ this.names = names;
+ this.style = style;
+ this.size = size;
+ }
- /**
- * Returns a bitwise-OR of the style flags. The following sample checks if
- * the font is bold.
- *
- * <pre>
- * if (font.getStyle | VexFont.BOLD) {
- * // do something bold...
- * }
- * </pre>
- */
- public int getStyle() {
- return style;
- }
+ /**
+ * Returns the names of the font families that match the font.
+ */
+ public String[] getNames() {
+ return names;
+ }
+
+ /**
+ * Returns the size of the font in points.
+ */
+ public float getSize() {
+ return size;
+ }
+
+ /**
+ * Returns a bitwise-OR of the style flags. The following sample checks if
+ * the font is bold.
+ *
+ * <pre>
+ * if (font.getStyle | VexFont.BOLD) {
+ * // do something bold...
+ * }
+ * </pre>
+ */
+ public int getStyle() {
+ return style;
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Graphics.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Graphics.java
index 1d71711..d8adabd 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Graphics.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Graphics.java
@@ -10,50 +10,74 @@
*******************************************************************************/
package org.eclipse.wst.xml.vex.core.internal.core;
-
/**
- * Interface through which Vex performs graphics operations. Implemented
- * by adapters to the java.awt.Graphics and org.eclipse.swt.graphics.GC
- * classes.
+ * Interface through which Vex performs graphics operations. Implemented by
+ * adapters to the java.awt.Graphics and org.eclipse.swt.graphics.GC classes.
*/
public interface Graphics {
-
- public static final int LINE_SOLID = 0;
- public static final int LINE_DASH = 1;
- public static final int LINE_DOT = 2;
-
- public int charsWidth(char[] data, int offset, int length);
- public ColorResource createColor(Color rgb);
- public FontResource createFont(FontSpec fontSpec);
- public void dispose();
- public void drawChars(char[] chars, int offset, int length, int x, int y);
- public void drawLine(int x1, int y1, int x2, int y2);
-
- /**
- * Draw the given string at the given point using the current font.
- * @param s string to draw
- * @param x x-coordinate of the top left corner of the text box
- * @param y y-coordinate of the top left corner of the text box
- */
- public void drawString(String s, int x, int y);
- public void drawOval(int x, int y, int width, int height);
- public void drawRect(int x, int y, int width, int height);
- public void fillOval(int x, int y, int width, int height);
- public void fillRect(int x, int y, int width, int height);
- public Rectangle getClipBounds();
- public ColorResource getColor();
- public FontResource getFont();
- public int getLineStyle();
- public int getLineWidth();
- public ColorResource getSystemColor(int id);
- public FontMetrics getFontMetrics();
- public boolean isAntiAliased();
- public void setAntiAliased(boolean antiAliased);
- public ColorResource setColor(ColorResource color);
- public FontResource setFont(FontResource font);
- public void setLineStyle(int style);
- public void setLineWidth(int width);
-
- public int stringWidth(String s);
-
+
+ public static final int LINE_SOLID = 0;
+ public static final int LINE_DASH = 1;
+ public static final int LINE_DOT = 2;
+
+ public int charsWidth(char[] data, int offset, int length);
+
+ public ColorResource createColor(Color rgb);
+
+ public FontResource createFont(FontSpec fontSpec);
+
+ public void dispose();
+
+ public void drawChars(char[] chars, int offset, int length, int x, int y);
+
+ public void drawLine(int x1, int y1, int x2, int y2);
+
+ /**
+ * Draw the given string at the given point using the current font.
+ *
+ * @param s
+ * string to draw
+ * @param x
+ * x-coordinate of the top left corner of the text box
+ * @param y
+ * y-coordinate of the top left corner of the text box
+ */
+ public void drawString(String s, int x, int y);
+
+ public void drawOval(int x, int y, int width, int height);
+
+ public void drawRect(int x, int y, int width, int height);
+
+ public void fillOval(int x, int y, int width, int height);
+
+ public void fillRect(int x, int y, int width, int height);
+
+ public Rectangle getClipBounds();
+
+ public ColorResource getColor();
+
+ public FontResource getFont();
+
+ public int getLineStyle();
+
+ public int getLineWidth();
+
+ public ColorResource getSystemColor(int id);
+
+ public FontMetrics getFontMetrics();
+
+ public boolean isAntiAliased();
+
+ public void setAntiAliased(boolean antiAliased);
+
+ public ColorResource setColor(ColorResource color);
+
+ public FontResource setFont(FontResource font);
+
+ public void setLineStyle(int style);
+
+ public void setLineWidth(int width);
+
+ public int stringWidth(String s);
+
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Insets.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Insets.java
index 9d63ffa..d2f762a 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Insets.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Insets.java
@@ -14,71 +14,75 @@
* Toolkit-independent insets.
*/
public class Insets {
-
- private int top;
- private int left;
- private int bottom;
- private int right;
- /** Zero insets */
- public static final Insets ZERO_INSETS = new Insets(0, 0, 0, 0);
-
- /**
- * Class constructor.
- *
- * @param top Top inset.
- * @param left Left inset.
- * @param bottom Bottom inset.
- * @param right Right inset.
- */
- public Insets(int top, int left, int bottom, int right) {
- this.top = top;
- this.left = left;
- this.bottom = bottom;
- this.right = right;
- }
+ private int top;
+ private int left;
+ private int bottom;
+ private int right;
- /**
- * @return Returns the top.
- */
- public int getTop() {
- return top;
- }
+ /** Zero insets */
+ public static final Insets ZERO_INSETS = new Insets(0, 0, 0, 0);
- /**
- * @return Returns the left.
- */
- public int getLeft() {
- return left;
- }
+ /**
+ * Class constructor.
+ *
+ * @param top
+ * Top inset.
+ * @param left
+ * Left inset.
+ * @param bottom
+ * Bottom inset.
+ * @param right
+ * Right inset.
+ */
+ public Insets(int top, int left, int bottom, int right) {
+ this.top = top;
+ this.left = left;
+ this.bottom = bottom;
+ this.right = right;
+ }
- /**
- * @return Returns the bottom.
- */
- public int getBottom() {
- return bottom;
- }
+ /**
+ * @return Returns the top.
+ */
+ public int getTop() {
+ return top;
+ }
- /**
- * Returns the right inset.
- */
- public int getRight() {
- return right;
- }
+ /**
+ * @return Returns the left.
+ */
+ public int getLeft() {
+ return left;
+ }
- public String toString() {
- StringBuffer sb = new StringBuffer(80);
- sb.append(Insets.class.getName());
- sb.append("[top=");
- sb.append(this.getTop());
- sb.append(",left=");
- sb.append(this.getLeft());
- sb.append(",bottom=");
- sb.append(this.getBottom());
- sb.append(",right=");
- sb.append(this.getRight());
- sb.append("]");
- return sb.toString();
- }
+ /**
+ * @return Returns the bottom.
+ */
+ public int getBottom() {
+ return bottom;
+ }
+
+ /**
+ * Returns the right inset.
+ */
+ public int getRight() {
+ return right;
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer(80);
+ sb.append(Insets.class.getName());
+ sb.append("[top=");
+ sb.append(this.getTop());
+ sb.append(",left=");
+ sb.append(this.getLeft());
+ sb.append(",bottom=");
+ sb.append(this.getBottom());
+ sb.append(",right=");
+ sb.append(this.getRight());
+ sb.append("]");
+ return sb.toString();
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/IntRange.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/IntRange.java
index cdb66b2..c680f16 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/IntRange.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/IntRange.java
@@ -11,90 +11,103 @@
package org.eclipse.wst.xml.vex.core.internal.core;
/**
- * Represents a range of integers. Zero-length ranges (i.e. ranges where
- * start == end) are permitted. This class is immutable.
+ * Represents a range of integers. Zero-length ranges (i.e. ranges where start
+ * == end) are permitted. This class is immutable.
*/
public class IntRange {
- /**
- * Class constuctor.
- * @param start Start of the range.
- * @param end End of the range. Must be >= start.
- */
- public IntRange(int start, int end) {
- if (start > end) {
- throw new IllegalArgumentException("start (" + start + ") is greater than end (" + end + ")");
- }
- this.start = start;
- this.end = end;
- }
-
- /**
- * Returns the start of the range.
- */
- public int getStart() {
- return this.start;
- }
+ /**
+ * Class constuctor.
+ *
+ * @param start
+ * Start of the range.
+ * @param end
+ * End of the range. Must be >= start.
+ */
+ public IntRange(int start, int end) {
+ if (start > end) {
+ throw new IllegalArgumentException("start (" + start
+ + ") is greater than end (" + end + ")");
+ }
+ this.start = start;
+ this.end = end;
+ }
- /**
- * Returns the end of the range.
- */
- public int getEnd() {
- return this.end;
- }
-
- /**
- * Returns the range that represents the intersection of this range
- * and the given range. If the ranges do not intersect, returns null.
- * May return an empty range.
- * @param range Range with which to perform an intersection.
- */
- public IntRange intersection(IntRange range) {
- if (this.intersects(range)) {
- return new IntRange(Math.max(this.start, range.start), Math.min(this.end, range.end));
- } else {
- return null;
- }
-
- }
+ /**
+ * Returns the start of the range.
+ */
+ public int getStart() {
+ return this.start;
+ }
- /**
- * Returns true if this range intersects the given range, even if the
- * result would be an empty range.
- * @param range Range with which to intersect.
- */
- public boolean intersects(IntRange range) {
- return this.start <= range.end && this.end >= range.start;
- }
+ /**
+ * Returns the end of the range.
+ */
+ public int getEnd() {
+ return this.end;
+ }
- /**
- * Returns true if start and end are equal.
- */
- public boolean isEmpty() {
- return start == end;
- }
+ /**
+ * Returns the range that represents the intersection of this range and the
+ * given range. If the ranges do not intersect, returns null. May return an
+ * empty range.
+ *
+ * @param range
+ * Range with which to perform an intersection.
+ */
+ public IntRange intersection(IntRange range) {
+ if (this.intersects(range)) {
+ return new IntRange(Math.max(this.start, range.start), Math.min(
+ this.end, range.end));
+ } else {
+ return null;
+ }
- /**
- * Returns a range that is the union of this range and the given range.
- * If the ranges are disjoint, the gap between the ranges is included
- * in the result.
- * @param range Rnage with which to perform the union
- */
- public IntRange union(IntRange range) {
- return new IntRange(Math.min(this.start, range.start), Math.min(this.end, range.end));
- }
-
- public String toString() {
- StringBuffer sb = new StringBuffer();
- sb.append("IntRange(");
- sb.append(start);
- sb.append(",");
- sb.append(end);
- sb.append(")");
- return sb.toString();
- }
- //============================================================= PRIVATE
-
- private int start;
- private int end;
+ }
+
+ /**
+ * Returns true if this range intersects the given range, even if the result
+ * would be an empty range.
+ *
+ * @param range
+ * Range with which to intersect.
+ */
+ public boolean intersects(IntRange range) {
+ return this.start <= range.end && this.end >= range.start;
+ }
+
+ /**
+ * Returns true if start and end are equal.
+ */
+ public boolean isEmpty() {
+ return start == end;
+ }
+
+ /**
+ * Returns a range that is the union of this range and the given range. If
+ * the ranges are disjoint, the gap between the ranges is included in the
+ * result.
+ *
+ * @param range
+ * Rnage with which to perform the union
+ */
+ public IntRange union(IntRange range) {
+ return new IntRange(Math.min(this.start, range.start), Math.min(
+ this.end, range.end));
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("IntRange(");
+ sb.append(start);
+ sb.append(",");
+ sb.append(end);
+ sb.append(")");
+ return sb.toString();
+ }
+
+ // ============================================================= PRIVATE
+
+ private int start;
+ private int end;
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/ListenerList.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/ListenerList.java
index 18a4e67..1942739 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/ListenerList.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/ListenerList.java
@@ -19,95 +19,105 @@
import java.util.Map;
/**
- * A collection of listener objects. The main point of this class is the
- * fireEvent method, which takes care of the
- * tedium of iterating over the collection and catching exceptions generated
- * by listeners.
+ * A collection of listener objects. The main point of this class is the
+ * fireEvent method, which takes care of the tedium of iterating over the
+ * collection and catching exceptions generated by listeners.
*/
public class ListenerList {
- /**
- * Class constructor.
- * @param listenerClass Class of the listener interface.
- * @param eventClass Class of the event objects passed to methods in the
- * listener interface.
- */
- public ListenerList(Class listenerClass, Class eventClass) {
- this.listenerClass = listenerClass;
- this.methodParams = new Class[] { eventClass };
- }
-
- /**
- * Adds a listener to the list. Rejects listeners that are not subclasses
- * of the listener class passed to the constructor.
- * @param listener Listener to be added.
- */
- public void add(Object listener) {
- if (!listenerClass.isInstance(listener)) {
- this.handleException(new IllegalArgumentException("" + listener + " is not an instance of " + listenerClass));
- }
- this.listeners.add(listener);
- }
-
- /**
- * Calls the given method on each registered listener. Any exception
- * thrown from one of the called methods is passed to handleException, as
- * is any introspection error, e.g. if the given method doesn't exist.
- *
- * @param methodName Listener method to call.
- * @param event Event to be passed to each call.
- */
- public void fireEvent(String methodName, EventObject event) {
-
- Method method = (Method) this.methods.get(methodName);
- if (method == null) {
- try {
- method = listenerClass.getMethod(methodName, methodParams);
- this.methods.put(methodName, method);
- } catch (Exception e) {
- this.handleException(e);
- return;
- }
- }
-
- Object[] args = new Object[] { event };
- for (Iterator it = this.listeners.iterator(); it.hasNext();) {
- Object listener = it.next();
- try {
- method.invoke(listener, args);
- } catch (Exception ex) {
- this.handleException(ex);
- }
- }
-
- }
-
- /**
- * Called from fireEvent whenever a called listener method throws an
- * exception, or if there is a problem looking up the listener method
- * by reflection. By default, simply prints the stack trace to stdout.
- * Clients may override this method to provide a more suitable
- * implementation.
- * @param ex Exception thrown by the listener method.
- */
- public void handleException(Exception ex) {
- ex.printStackTrace();
- }
-
- /**
- * Removes a listener from the list.
- * @param listener Listener to remove.
- */
- public void remove(Object listener) {
- this.listeners.remove(listener);
- }
-
- //====================================================== PRIVATE
-
- private Class listenerClass;
- private Class[] methodParams;
- private Collection listeners = new ArrayList();
-
- // map methodName => Method object
- private Map methods = new HashMap();
+ /**
+ * Class constructor.
+ *
+ * @param listenerClass
+ * Class of the listener interface.
+ * @param eventClass
+ * Class of the event objects passed to methods in the listener
+ * interface.
+ */
+ public ListenerList(Class listenerClass, Class eventClass) {
+ this.listenerClass = listenerClass;
+ this.methodParams = new Class[] { eventClass };
+ }
+
+ /**
+ * Adds a listener to the list. Rejects listeners that are not subclasses of
+ * the listener class passed to the constructor.
+ *
+ * @param listener
+ * Listener to be added.
+ */
+ public void add(Object listener) {
+ if (!listenerClass.isInstance(listener)) {
+ this.handleException(new IllegalArgumentException("" + listener
+ + " is not an instance of " + listenerClass));
+ }
+ this.listeners.add(listener);
+ }
+
+ /**
+ * Calls the given method on each registered listener. Any exception thrown
+ * from one of the called methods is passed to handleException, as is any
+ * introspection error, e.g. if the given method doesn't exist.
+ *
+ * @param methodName
+ * Listener method to call.
+ * @param event
+ * Event to be passed to each call.
+ */
+ public void fireEvent(String methodName, EventObject event) {
+
+ Method method = (Method) this.methods.get(methodName);
+ if (method == null) {
+ try {
+ method = listenerClass.getMethod(methodName, methodParams);
+ this.methods.put(methodName, method);
+ } catch (Exception e) {
+ this.handleException(e);
+ return;
+ }
+ }
+
+ Object[] args = new Object[] { event };
+ for (Iterator it = this.listeners.iterator(); it.hasNext();) {
+ Object listener = it.next();
+ try {
+ method.invoke(listener, args);
+ } catch (Exception ex) {
+ this.handleException(ex);
+ }
+ }
+
+ }
+
+ /**
+ * Called from fireEvent whenever a called listener method throws an
+ * exception, or if there is a problem looking up the listener method by
+ * reflection. By default, simply prints the stack trace to stdout. Clients
+ * may override this method to provide a more suitable implementation.
+ *
+ * @param ex
+ * Exception thrown by the listener method.
+ */
+ public void handleException(Exception ex) {
+ ex.printStackTrace();
+ }
+
+ /**
+ * Removes a listener from the list.
+ *
+ * @param listener
+ * Listener to remove.
+ */
+ public void remove(Object listener) {
+ this.listeners.remove(listener);
+ }
+
+ // ====================================================== PRIVATE
+
+ private Class listenerClass;
+ private Class[] methodParams;
+ private Collection listeners = new ArrayList();
+
+ // map methodName => Method object
+ private Map methods = new HashMap();
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Point.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Point.java
index e3614e4..d3fdd29 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Point.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Point.java
@@ -14,43 +14,46 @@
* Toolkit-independent point.
*/
public class Point {
-
- private int x;
- private int y;
- /**
- * Class constructor.
- * @param x X-coordinate.
- * @param y Y-coordinate.
- */
- public Point(int x, int y) {
- this.x = x;
- this.y = y;
- }
-
- public String toString() {
- StringBuffer sb = new StringBuffer(80);
- sb.append(Point.class.getName());
- sb.append("[x=");
- sb.append(this.getX());
- sb.append(",y=");
- sb.append(this.getY());
- sb.append("]");
- return sb.toString();
- }
+ private int x;
+ private int y;
- /**
- * Returns the x-coordinate.
- */
- public int getX() {
- return x;
- }
+ /**
+ * Class constructor.
+ *
+ * @param x
+ * X-coordinate.
+ * @param y
+ * Y-coordinate.
+ */
+ public Point(int x, int y) {
+ this.x = x;
+ this.y = y;
+ }
- /**
- * Returns the y-coordinate.
- */
- public int getY() {
- return y;
- }
+ public String toString() {
+ StringBuffer sb = new StringBuffer(80);
+ sb.append(Point.class.getName());
+ sb.append("[x=");
+ sb.append(this.getX());
+ sb.append(",y=");
+ sb.append(this.getY());
+ sb.append("]");
+ return sb.toString();
+ }
+
+ /**
+ * Returns the x-coordinate.
+ */
+ public int getX() {
+ return x;
+ }
+
+ /**
+ * Returns the y-coordinate.
+ */
+ public int getY() {
+ return y;
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Rectangle.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Rectangle.java
index 3c26055..b996dcb 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Rectangle.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Rectangle.java
@@ -14,78 +14,79 @@
* Toolkit-independent rectangle.
*/
public class Rectangle {
-
- private int x;
- private int y;
- private int width;
- private int height;
-
- public Rectangle(int x, int y, int width, int height) {
- this.x = x;
- this.y = y;
- this.width = width;
- this.height = height;
- }
-
- public boolean intersects(Rectangle rect) {
- return rect.x < this.x + this.width
- && rect.x + rect.width > this.x
- && rect.y < this.y + this.height
- && rect.y + rect.height > this.y;
- }
- public String toString() {
- StringBuffer sb = new StringBuffer(80);
- sb.append(Rectangle.class.getName());
- sb.append("[x=");
- sb.append(this.getX());
- sb.append(",y=");
- sb.append(this.getY());
- sb.append(",width=");
- sb.append(this.getWidth());
- sb.append(",height=");
- sb.append(this.getHeight());
- sb.append("]");
- return sb.toString();
- }
+ private int x;
+ private int y;
+ private int width;
+ private int height;
- /**
- * @return Returns the x.
- */
- public int getX() {
- return x;
- }
+ public Rectangle(int x, int y, int width, int height) {
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ }
- /**
- * @return Returns the y.
- */
- public int getY() {
- return y;
- }
+ public boolean intersects(Rectangle rect) {
+ return rect.x < this.x + this.width && rect.x + rect.width > this.x
+ && rect.y < this.y + this.height
+ && rect.y + rect.height > this.y;
+ }
- /**
- * @return Returns the width.
- */
- public int getWidth() {
- return width;
- }
+ public String toString() {
+ StringBuffer sb = new StringBuffer(80);
+ sb.append(Rectangle.class.getName());
+ sb.append("[x=");
+ sb.append(this.getX());
+ sb.append(",y=");
+ sb.append(this.getY());
+ sb.append(",width=");
+ sb.append(this.getWidth());
+ sb.append(",height=");
+ sb.append(this.getHeight());
+ sb.append("]");
+ return sb.toString();
+ }
- /**
- * @return Returns the height.
- */
- public int getHeight() {
- return height;
- }
-
- /**
- * Returns a Rectangle that is the union of this rectangle with another.
- * @param rect Rectangle with which to union this one.
- */
- public Rectangle union(Rectangle rect) {
- int left = Math.min(this.x, rect.x);
- int top = Math.min(this.y, rect.y);
- int right = Math.max(this.x + this.width, rect.x + rect.width);
- int bottom = Math.max(this.y + this.height, rect.y + rect.height);
- return new Rectangle(left, top, right - left, bottom - top);
- }
+ /**
+ * @return Returns the x.
+ */
+ public int getX() {
+ return x;
+ }
+
+ /**
+ * @return Returns the y.
+ */
+ public int getY() {
+ return y;
+ }
+
+ /**
+ * @return Returns the width.
+ */
+ public int getWidth() {
+ return width;
+ }
+
+ /**
+ * @return Returns the height.
+ */
+ public int getHeight() {
+ return height;
+ }
+
+ /**
+ * Returns a Rectangle that is the union of this rectangle with another.
+ *
+ * @param rect
+ * Rectangle with which to union this one.
+ */
+ public Rectangle union(Rectangle rect) {
+ int left = Math.min(this.x, rect.x);
+ int top = Math.min(this.y, rect.y);
+ int right = Math.max(this.x + this.width, rect.x + rect.width);
+ int bottom = Math.max(this.y + this.height, rect.y + rect.height);
+ return new Rectangle(left, top, right - left, bottom - top);
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/AbstractProperty.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/AbstractProperty.java
index e217370..31b6662 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/AbstractProperty.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/AbstractProperty.java
@@ -12,7 +12,6 @@
import org.w3c.css.sac.LexicalUnit;
-
/**
* Abstract base class for property classes. Implements the <code>name</code>
* property but leaves the implementation of <code>calculate</code> to the
@@ -20,120 +19,115 @@
*/
public abstract class AbstractProperty implements IProperty {
- /**
- * Class constructor.
- * @param name Name of the property.
- */
- public AbstractProperty(String name) {
- this.name = name;
- }
+ /**
+ * Class constructor.
+ *
+ * @param name
+ * Name of the property.
+ */
+ public AbstractProperty(String name) {
+ this.name = name;
+ }
- /**
- * Returns true if the given lexical unit represents the token "inherit".
- */
- public static boolean isInherit(LexicalUnit lu) {
- return lu != null
- && lu.getLexicalUnitType() == LexicalUnit.SAC_INHERIT;
- }
+ /**
+ * Returns true if the given lexical unit represents the token "inherit".
+ */
+ public static boolean isInherit(LexicalUnit lu) {
+ return lu != null && lu.getLexicalUnitType() == LexicalUnit.SAC_INHERIT;
+ }
- public String getName() {
- return this.name;
- }
+ public String getName() {
+ return this.name;
+ }
- public static boolean isPercentage(LexicalUnit lu) {
- return lu != null &&
- lu.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE;
- }
+ public static boolean isPercentage(LexicalUnit lu) {
+ return lu != null
+ && lu.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE;
+ }
+ public static boolean isLength(LexicalUnit lu) {
+ if (lu == null) {
+ return false;
+ }
+ short type = lu.getLexicalUnitType();
- public static boolean isLength(LexicalUnit lu) {
- if (lu == null) {
- return false;
- }
-
- short type = lu.getLexicalUnitType();
-
- if (type == LexicalUnit.SAC_INTEGER &&
- lu.getIntegerValue() == 0) {
- return true;
- }
-
- return type == LexicalUnit.SAC_CENTIMETER
- || type == LexicalUnit.SAC_DIMENSION
- || type == LexicalUnit.SAC_EM
- || type == LexicalUnit.SAC_EX
- || type == LexicalUnit.SAC_INCH
- || type == LexicalUnit.SAC_MILLIMETER
- || type == LexicalUnit.SAC_PICA
- || type == LexicalUnit.SAC_PIXEL
- || type == LexicalUnit.SAC_POINT;
- }
+ if (type == LexicalUnit.SAC_INTEGER && lu.getIntegerValue() == 0) {
+ return true;
+ }
- public static int getIntLength(LexicalUnit lu, float fontSize, int ppi) {
- return Math.round(getFloatLength(lu, fontSize, ppi));
- }
+ return type == LexicalUnit.SAC_CENTIMETER
+ || type == LexicalUnit.SAC_DIMENSION
+ || type == LexicalUnit.SAC_EM || type == LexicalUnit.SAC_EX
+ || type == LexicalUnit.SAC_INCH
+ || type == LexicalUnit.SAC_MILLIMETER
+ || type == LexicalUnit.SAC_PICA
+ || type == LexicalUnit.SAC_PIXEL
+ || type == LexicalUnit.SAC_POINT;
+ }
- public static float getFloatLength(LexicalUnit lu, float fontSize, int ppi) {
-
- float value = 0f;
-
- switch (lu.getLexicalUnitType()) {
-
- case LexicalUnit.SAC_CENTIMETER:
- value = lu.getFloatValue() * ppi / 2.54f;
- break;
- case LexicalUnit.SAC_EM:
- value = lu.getFloatValue() * fontSize;
- break;
- case LexicalUnit.SAC_EX:
- value = lu.getFloatValue() * fontSize * EX_FACTOR;
- break;
- case LexicalUnit.SAC_INCH:
- value = lu.getFloatValue() * ppi;
- break;
- case LexicalUnit.SAC_INTEGER:
- value = 0; // 0 is the only valid length w/o a dimension
- break;
- case LexicalUnit.SAC_MILLIMETER:
- value = lu.getFloatValue() * ppi / 25.4f;
- break;
- case LexicalUnit.SAC_PICA:
- value = lu.getFloatValue() * ppi / 6;
- break;
- case LexicalUnit.SAC_PIXEL:
- value = lu.getFloatValue();
- break;
- case LexicalUnit.SAC_POINT:
- value = lu.getFloatValue() * ppi / 72;
- break;
- }
- return value;
- }
+ public static int getIntLength(LexicalUnit lu, float fontSize, int ppi) {
+ return Math.round(getFloatLength(lu, fontSize, ppi));
+ }
+ public static float getFloatLength(LexicalUnit lu, float fontSize, int ppi) {
- //============================================================== PRIVATE
-
- public static boolean isNumber(LexicalUnit lu) {
- return lu != null &&
- (lu.getLexicalUnitType() == LexicalUnit.SAC_INTEGER
- || lu.getLexicalUnitType() == LexicalUnit.SAC_REAL);
- }
+ float value = 0f;
+ switch (lu.getLexicalUnitType()) {
- public static float getNumber(LexicalUnit lu) {
- if (lu.getLexicalUnitType() == LexicalUnit.SAC_INTEGER) {
- return lu.getIntegerValue();
- } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_REAL) {
- return lu.getFloatValue();
- } else {
- throw new RuntimeException("LexicalUnit type " + lu.getLexicalUnitType() + " is not a numeric type.");
- }
- }
+ case LexicalUnit.SAC_CENTIMETER:
+ value = lu.getFloatValue() * ppi / 2.54f;
+ break;
+ case LexicalUnit.SAC_EM:
+ value = lu.getFloatValue() * fontSize;
+ break;
+ case LexicalUnit.SAC_EX:
+ value = lu.getFloatValue() * fontSize * EX_FACTOR;
+ break;
+ case LexicalUnit.SAC_INCH:
+ value = lu.getFloatValue() * ppi;
+ break;
+ case LexicalUnit.SAC_INTEGER:
+ value = 0; // 0 is the only valid length w/o a dimension
+ break;
+ case LexicalUnit.SAC_MILLIMETER:
+ value = lu.getFloatValue() * ppi / 25.4f;
+ break;
+ case LexicalUnit.SAC_PICA:
+ value = lu.getFloatValue() * ppi / 6;
+ break;
+ case LexicalUnit.SAC_PIXEL:
+ value = lu.getFloatValue();
+ break;
+ case LexicalUnit.SAC_POINT:
+ value = lu.getFloatValue() * ppi / 72;
+ break;
+ }
+ return value;
+ }
+ // ============================================================== PRIVATE
- private String name;
+ public static boolean isNumber(LexicalUnit lu) {
+ return lu != null
+ && (lu.getLexicalUnitType() == LexicalUnit.SAC_INTEGER || lu
+ .getLexicalUnitType() == LexicalUnit.SAC_REAL);
+ }
- private static final float EX_FACTOR = 0.6f;
+ public static float getNumber(LexicalUnit lu) {
+ if (lu.getLexicalUnitType() == LexicalUnit.SAC_INTEGER) {
+ return lu.getIntegerValue();
+ } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_REAL) {
+ return lu.getFloatValue();
+ } else {
+ throw new RuntimeException("LexicalUnit type "
+ + lu.getLexicalUnitType() + " is not a numeric type.");
+ }
+ }
+
+ private String name;
+
+ private static final float EX_FACTOR = 0.6f;
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/BorderSpacingProperty.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/BorderSpacingProperty.java
index 1c096ec..7ec3f35 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/BorderSpacingProperty.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/BorderSpacingProperty.java
@@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.wst.xml.vex.core.internal.css;
-
import org.eclipse.wst.xml.vex.core.internal.core.DisplayDevice;
import org.w3c.css.sac.LexicalUnit;
@@ -19,68 +18,70 @@
*/
public class BorderSpacingProperty extends AbstractProperty {
- /**
- * Represents the computed value of border-spacing, which is a pair
- * of values representing vertical and horizontal spacing.
- */
- public static class Value {
+ /**
+ * Represents the computed value of border-spacing, which is a pair of
+ * values representing vertical and horizontal spacing.
+ */
+ public static class Value {
- private int horizontal;
- private int vertical;
+ private int horizontal;
+ private int vertical;
- public static final Value ZERO = new Value(0, 0);
-
- public Value(int horizontal, int vertical) {
- this.horizontal = horizontal;
- this.vertical = vertical;
- }
-
- /**
- * Returns the horizontal spacing, in pixels.
- */
- public int getHorizontal() {
- return this.horizontal;
- }
-
- /**
- * Returns the vertical spacing, in pixels.
- */
- public int getVertical() {
- return this.vertical;
- }
- }
-
- /**
- * Class constructor.
- */
- public BorderSpacingProperty() {
- super(CSS.BORDER_SPACING);
- }
+ public static final Value ZERO = new Value(0, 0);
- public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles) {
+ public Value(int horizontal, int vertical) {
+ this.horizontal = horizontal;
+ this.vertical = vertical;
+ }
- int horizontal = 0;
- int vertical = 0;
-
- DisplayDevice device = DisplayDevice.getCurrent();
+ /**
+ * Returns the horizontal spacing, in pixels.
+ */
+ public int getHorizontal() {
+ return this.horizontal;
+ }
- if (isLength(lu)) {
- horizontal = getIntLength(lu, styles.getFontSize(), device.getHorizontalPPI());
- lu = lu.getNextLexicalUnit();
- if (isLength(lu)) {
- vertical = getIntLength(lu, styles.getFontSize(), device.getVerticalPPI());
- } else {
- vertical = horizontal;
- }
- return new Value(horizontal, vertical);
- } else {
- // 'inherit' or an invalid value
- if (parentStyles == null) {
- return Value.ZERO;
- } else {
- return parentStyles.getBorderSpacing();
- }
- }
- }
+ /**
+ * Returns the vertical spacing, in pixels.
+ */
+ public int getVertical() {
+ return this.vertical;
+ }
+ }
+
+ /**
+ * Class constructor.
+ */
+ public BorderSpacingProperty() {
+ super(CSS.BORDER_SPACING);
+ }
+
+ public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles) {
+
+ int horizontal = 0;
+ int vertical = 0;
+
+ DisplayDevice device = DisplayDevice.getCurrent();
+
+ if (isLength(lu)) {
+ horizontal = getIntLength(lu, styles.getFontSize(), device
+ .getHorizontalPPI());
+ lu = lu.getNextLexicalUnit();
+ if (isLength(lu)) {
+ vertical = getIntLength(lu, styles.getFontSize(), device
+ .getVerticalPPI());
+ } else {
+ vertical = horizontal;
+ }
+ return new Value(horizontal, vertical);
+ } else {
+ // 'inherit' or an invalid value
+ if (parentStyles == null) {
+ return Value.ZERO;
+ } else {
+ return parentStyles.getBorderSpacing();
+ }
+ }
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/BorderStyleProperty.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/BorderStyleProperty.java
index 44b9f22..2ecdcca 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/BorderStyleProperty.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/BorderStyleProperty.java
@@ -17,47 +17,45 @@
*/
public class BorderStyleProperty extends AbstractProperty {
- /**
- * Class constructor.
- * @param name Name of the property.
- */
- public BorderStyleProperty(String name) {
- super(name);
- }
+ /**
+ * Class constructor.
+ *
+ * @param name
+ * Name of the property.
+ */
+ public BorderStyleProperty(String name) {
+ super(name);
+ }
- /**
- * Returns true if the given lexical unit represents a border style.
- *
- * @param lu LexicalUnit to check.
- */
- public static boolean isBorderStyle(LexicalUnit lu) {
- if (lu == null) {
- return false;
- } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
- String s = lu.getStringValue();
- return s.equals(CSS.NONE)
- || s.equals(CSS.HIDDEN)
- || s.equals(CSS.DOTTED)
- || s.equals(CSS.DASHED)
- || s.equals(CSS.SOLID)
- || s.equals(CSS.DOUBLE)
- || s.equals(CSS.GROOVE)
- || s.equals(CSS.RIDGE)
- || s.equals(CSS.INSET)
- || s.equals(CSS.OUTSET);
- }
-
- return false;
- }
+ /**
+ * Returns true if the given lexical unit represents a border style.
+ *
+ * @param lu
+ * LexicalUnit to check.
+ */
+ public static boolean isBorderStyle(LexicalUnit lu) {
+ if (lu == null) {
+ return false;
+ } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
+ String s = lu.getStringValue();
+ return s.equals(CSS.NONE) || s.equals(CSS.HIDDEN)
+ || s.equals(CSS.DOTTED) || s.equals(CSS.DASHED)
+ || s.equals(CSS.SOLID) || s.equals(CSS.DOUBLE)
+ || s.equals(CSS.GROOVE) || s.equals(CSS.RIDGE)
+ || s.equals(CSS.INSET) || s.equals(CSS.OUTSET);
+ }
- public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles) {
- if (isBorderStyle(lu)) {
- return lu.getStringValue();
- } else if (isInherit(lu) && parentStyles != null) {
- return parentStyles.get(this.getName());
- } else {
- return CSS.NONE;
- }
- }
+ return false;
+ }
+
+ public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles) {
+ if (isBorderStyle(lu)) {
+ return lu.getStringValue();
+ } else if (isInherit(lu) && parentStyles != null) {
+ return parentStyles.get(this.getName());
+ } else {
+ return CSS.NONE;
+ }
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/BorderWidthProperty.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/BorderWidthProperty.java
index bb256dd..4548b23 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/BorderWidthProperty.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/BorderWidthProperty.java
@@ -10,109 +10,111 @@
*******************************************************************************/
package org.eclipse.wst.xml.vex.core.internal.css;
-
import org.eclipse.wst.xml.vex.core.internal.core.DisplayDevice;
import org.w3c.css.sac.LexicalUnit;
/**
- * The border-XXX-width CSS property. Since the value of this property
- * depends on the corresponding border-XXX-style property, the style
- * property must be calculated first and placed in the styles, and its
- * name given to the constructor of this class.
+ * The border-XXX-width CSS property. Since the value of this property depends
+ * on the corresponding border-XXX-style property, the style property must be
+ * calculated first and placed in the styles, and its name given to the
+ * constructor of this class.
*/
public class BorderWidthProperty extends AbstractProperty {
+ /**
+ * Class constructor.
+ *
+ * @param name
+ * Name of the property.
+ * @param borderStyleName
+ * Name of the corresponding border style property. For example,
+ * if name is CSS.BORDER_TOP_WIDTH, then borderStyleName should
+ * be CSS.BORDER_TOP_STYLE.
+ * @param axis
+ * AXIS_HORIZONTAL (for left and right borders) or AXIS_VERTICAL
+ * (for top and bottom borders).
+ */
+ public BorderWidthProperty(String name, String borderStyleName, byte axis) {
+ super(name);
+ this.borderStyleName = borderStyleName;
+ this.axis = axis;
+ }
- /**
- * Class constructor.
- * @param name Name of the property.
- * @param borderStyleName Name of the corresponding border style
- * property. For example, if name is CSS.BORDER_TOP_WIDTH, then
- * borderStyleName should be CSS.BORDER_TOP_STYLE.
- * @param axis AXIS_HORIZONTAL (for left and right borders) or
- * AXIS_VERTICAL (for top and bottom borders).
- */
- public BorderWidthProperty(String name, String borderStyleName, byte axis) {
- super(name);
- this.borderStyleName = borderStyleName;
- this.axis = axis;
- }
+ /**
+ * Returns true if the given lexical unit represents a border width.
+ *
+ * @param lu
+ * LexicalUnit to check.
+ */
+ public static boolean isBorderWidth(LexicalUnit lu) {
+ if (lu == null) {
+ return false;
+ } else if (isLength(lu)) {
+ return true;
+ } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
+ String s = lu.getStringValue();
+ return s.equals(CSS.THIN) || s.equals(CSS.MEDIUM)
+ || s.equals(CSS.THICK);
+ } else {
+ return false;
+ }
+ }
- /**
- * Returns true if the given lexical unit represents a border width.
- *
- * @param lu LexicalUnit to check.
- */
- public static boolean isBorderWidth(LexicalUnit lu) {
- if (lu == null) {
- return false;
- } else if (isLength(lu)) {
- return true;
- } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
- String s = lu.getStringValue();
- return s.equals(CSS.THIN)
- || s.equals(CSS.MEDIUM)
- || s.equals(CSS.THICK);
- } else {
- return false;
- }
- }
-
- public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles) {
- return new Integer(this.calculateInternal(lu, parentStyles, styles));
- }
+ public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles) {
+ return new Integer(this.calculateInternal(lu, parentStyles, styles));
+ }
- private int calculateInternal(LexicalUnit lu, Styles parentStyles, Styles styles) {
-
- DisplayDevice device = DisplayDevice.getCurrent();
- int ppi = this.axis == AXIS_HORIZONTAL ? device.getHorizontalPPI() : device.getVerticalPPI();
-
- String borderStyle = (String) styles.get(this.borderStyleName);
-
- if (borderStyle.equals(CSS.NONE) || borderStyle.equals(CSS.HIDDEN)) {
- return 0;
- } else if (isBorderWidth(lu)) {
- return getBorderWidth(lu, styles.getFontSize(), ppi);
- } else if (isInherit(lu) && parentStyles != null) {
- return ((Integer) parentStyles.get(this.getName())).intValue();
- } else {
- // not specified, "none", or other unknown value
- return BORDER_WIDTH_MEDIUM;
- }
- }
+ private int calculateInternal(LexicalUnit lu, Styles parentStyles,
+ Styles styles) {
- //=================================================== PRIVATE
+ DisplayDevice device = DisplayDevice.getCurrent();
+ int ppi = this.axis == AXIS_HORIZONTAL ? device.getHorizontalPPI()
+ : device.getVerticalPPI();
- // Name of the corresponding border style property
- private String borderStyleName;
+ String borderStyle = (String) styles.get(this.borderStyleName);
- // Axis along which the border width is measured.
- private byte axis;
+ if (borderStyle.equals(CSS.NONE) || borderStyle.equals(CSS.HIDDEN)) {
+ return 0;
+ } else if (isBorderWidth(lu)) {
+ return getBorderWidth(lu, styles.getFontSize(), ppi);
+ } else if (isInherit(lu) && parentStyles != null) {
+ return ((Integer) parentStyles.get(this.getName())).intValue();
+ } else {
+ // not specified, "none", or other unknown value
+ return BORDER_WIDTH_MEDIUM;
+ }
+ }
- // named border widths
- private static final int BORDER_WIDTH_THIN = 1;
- private static final int BORDER_WIDTH_MEDIUM = 3;
- private static final int BORDER_WIDTH_THICK = 5;
+ // =================================================== PRIVATE
+ // Name of the corresponding border style property
+ private String borderStyleName;
- private static int getBorderWidth(LexicalUnit lu, float fontSize, int ppi) {
- if (isLength(lu)) {
- return getIntLength(lu, fontSize, ppi);
- } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
- String s = lu.getStringValue();
- if (s.equals(CSS.THIN)) {
- return BORDER_WIDTH_THIN;
- } else if (s.equals(CSS.MEDIUM)) {
- return BORDER_WIDTH_MEDIUM;
- } else if (s.equals(CSS.THICK)) {
- return BORDER_WIDTH_THICK;
- } else {
- return 0;
- }
- } else {
- return 0;
- }
- }
-
-
+ // Axis along which the border width is measured.
+ private byte axis;
+
+ // named border widths
+ private static final int BORDER_WIDTH_THIN = 1;
+ private static final int BORDER_WIDTH_MEDIUM = 3;
+ private static final int BORDER_WIDTH_THICK = 5;
+
+ private static int getBorderWidth(LexicalUnit lu, float fontSize, int ppi) {
+ if (isLength(lu)) {
+ return getIntLength(lu, fontSize, ppi);
+ } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
+ String s = lu.getStringValue();
+ if (s.equals(CSS.THIN)) {
+ return BORDER_WIDTH_THIN;
+ } else if (s.equals(CSS.MEDIUM)) {
+ return BORDER_WIDTH_MEDIUM;
+ } else if (s.equals(CSS.THICK)) {
+ return BORDER_WIDTH_THICK;
+ } else {
+ return 0;
+ }
+ } else {
+ return 0;
+ }
+ }
+
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/CSS.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/CSS.java
index 1adcf06..88c7a37 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/CSS.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/CSS.java
@@ -17,217 +17,215 @@
*/
public interface CSS {
- // property names
- public static final String AZIMUTH = "azimuth";
- public static final String BACKGROUND = "background";
- public static final String BACKGROUND_ATTACHMENT = "background-attachment";
- public static final String BACKGROUND_COLOR = "background-color";
- public static final String BACKGROUND_IMAGE = "background-image";
- public static final String BACKGROUND_POSITION = "background-position";
- public static final String BACKGROUND_REPEAT = "background-repeat";
- public static final String BORDER = "border";
- public static final String BORDER_BOTTOM = "border-bottom";
- public static final String BORDER_BOTTOM_COLOR = "border-bottom-color";
- public static final String BORDER_BOTTOM_STYLE = "border-bottom-style";
- public static final String BORDER_BOTTOM_WIDTH = "border-bottom-width";
- public static final String BORDER_COLOR = "border-color";
- public static final String BORDER_LEFT = "border-left";
- public static final String BORDER_LEFT_COLOR = "border-left-color";
- public static final String BORDER_LEFT_STYLE = "border-left-style";
- public static final String BORDER_LEFT_WIDTH = "border-left-width";
- public static final String BORDER_RIGHT = "border-right";
- public static final String BORDER_RIGHT_COLOR = "border-right-color";
- public static final String BORDER_RIGHT_STYLE = "border-right-style";
- public static final String BORDER_RIGHT_WIDTH = "border-right-width";
- public static final String BORDER_SPACING = "border-spacing";
- public static final String BORDER_STYLE = "border-style";
- public static final String BORDER_TOP = "border-top";
- public static final String BORDER_TOP_COLOR = "border-top-color";
- public static final String BORDER_TOP_STYLE = "border-top-style";
- public static final String BORDER_TOP_WIDTH = "border-top-width";
- public static final String BORDER_WIDTH = "border-width";
- public static final String BOTTOM = "bottom";
- public static final String CAPTION_SIDE = "caption-side";
- public static final String CLEAR = "clear";
- public static final String CLIP= "clip";
- public static final String COLOR = "color";
- public static final String CONTENT = "content";
- public static final String COUNTER_INCREMENT = "counter-increment";
- public static final String COUNTER_RESET= "counter-reset";
- public static final String CUE = "cue";
- public static final String CUE_AFTER = "cue-after";
- public static final String CUE_BEFORE = "cue-before";
- public static final String CURSOR = "cursor";
- public static final String DIRECTION = "direction";
- public static final String DISPLAY = "display";
- public static final String ELEVATION = "elevation";
- public static final String EMPTY_CELLS = "empty-cells";
- public static final String FLOAT = "float";
- public static final String FONT = "font";
- public static final String FONT_FAMILY = "font-family";
- public static final String FONT_SIZE = "font-size";
- public static final String FONT_STYLE = "font-style";
- public static final String FONT_VARIANT = "font-variant";
- public static final String FONT_WEIGHT = "font-weight";
- public static final String HEIGHT = "height";
- public static final String HIDDEN = "hidden";
- public static final String LETTER_SPACING = "letter-spacing";
- public static final String LINE_HEIGHT = "line-height";
- public static final String LIST_STYLE = "list-style";
- public static final String LIST_STYLE_IMAGE = "list-style-image";
- public static final String LIST_STYLE_POSITION = "list-style-position";
- public static final String LIST_STYLE_TYPE = "list-style-type";
- public static final String MARGIN = "margin";
- public static final String MARGIN_BOTTOM = "margin-bottom";
- public static final String MARGIN_LEFT = "margin-left";
- public static final String MARGIN_RIGHT = "margin-right";
- public static final String MARGIN_TOP = "margin-top";
- public static final String MAX_HEIGHT = "max-height";
- public static final String MAX_WIDTH = "max-width";
- public static final String MIN_HEIGHT = "min-height";
- public static final String MIN_WIDTH = "min-width";
- public static final String ORPHANS = "orphans";
- public static final String OUTLINE = "outline";
- public static final String OVERFLOW = "overflow";
- public static final String OUTLINE_COLOR = "outline-color";
- public static final String OUTLINE_STYLE = "outline-style";
- public static final String OUTLINE_WIDTH = "outline-width";
- public static final String PADDING = "padding";
- public static final String PADDING_BOTTOM = "padding-bottom";
- public static final String PADDING_LEFT = "padding-left";
- public static final String PADDING_RIGHT = "padding-right";
- public static final String PADDING_TOP = "padding-top";
- public static final String PAUSE = "pause";
- public static final String PAUSE_AFTER = "pause-after";
- public static final String PAUSE_BEFORE = "pause-before";
- public static final String PITCH = "pitch";
- public static final String PITCH_RANGE = "pitch-range";
- public static final String PLAY_DURING = "play-during";
- public static final String POSITION = "position";
- public static final String QUOTES = "quotes";
- public static final String RICHNESS = "richness";
- public static final String SPEAK = "speak";
- public static final String SPEAK_HEADER = "speak-header";
- public static final String SPEAK_NUMERAL = "speak-numeral";
- public static final String SPEAK_PUNCTUATION= "speak-punctuation";
- public static final String SPEECH_RATE = "speech-rate";
- public static final String STRESS = "stress";
- public static final String TABLE_LAYOUT = "table-layout";
- public static final String TEXT_ALIGN = "text-align";
- public static final String TEXT_DECORATION = "text-decoration";
- public static final String TEXT_INDENT = "text-indent";
- public static final String TEXT_TRANSFORM = "text-transform";
- public static final String UNICODE_BIDI = "unicode-bidi";
- public static final String VERTICAL_ALIGN= "vertical-align";
- public static final String VISIBILITY = "visibility";
- public static final String VOICE_FAMILY = "voice-family";
- public static final String VOLUME = "volume";
- public static final String WHITE_SPACE = "white-space";
- public static final String WIDOWS = "widows";
- public static final String WIDTH = "width";
- public static final String WORD_SPACING = "word-spacing";
- public static final String Z_SPACING = "z-spacing";
+ // property names
+ public static final String AZIMUTH = "azimuth";
+ public static final String BACKGROUND = "background";
+ public static final String BACKGROUND_ATTACHMENT = "background-attachment";
+ public static final String BACKGROUND_COLOR = "background-color";
+ public static final String BACKGROUND_IMAGE = "background-image";
+ public static final String BACKGROUND_POSITION = "background-position";
+ public static final String BACKGROUND_REPEAT = "background-repeat";
+ public static final String BORDER = "border";
+ public static final String BORDER_BOTTOM = "border-bottom";
+ public static final String BORDER_BOTTOM_COLOR = "border-bottom-color";
+ public static final String BORDER_BOTTOM_STYLE = "border-bottom-style";
+ public static final String BORDER_BOTTOM_WIDTH = "border-bottom-width";
+ public static final String BORDER_COLOR = "border-color";
+ public static final String BORDER_LEFT = "border-left";
+ public static final String BORDER_LEFT_COLOR = "border-left-color";
+ public static final String BORDER_LEFT_STYLE = "border-left-style";
+ public static final String BORDER_LEFT_WIDTH = "border-left-width";
+ public static final String BORDER_RIGHT = "border-right";
+ public static final String BORDER_RIGHT_COLOR = "border-right-color";
+ public static final String BORDER_RIGHT_STYLE = "border-right-style";
+ public static final String BORDER_RIGHT_WIDTH = "border-right-width";
+ public static final String BORDER_SPACING = "border-spacing";
+ public static final String BORDER_STYLE = "border-style";
+ public static final String BORDER_TOP = "border-top";
+ public static final String BORDER_TOP_COLOR = "border-top-color";
+ public static final String BORDER_TOP_STYLE = "border-top-style";
+ public static final String BORDER_TOP_WIDTH = "border-top-width";
+ public static final String BORDER_WIDTH = "border-width";
+ public static final String BOTTOM = "bottom";
+ public static final String CAPTION_SIDE = "caption-side";
+ public static final String CLEAR = "clear";
+ public static final String CLIP = "clip";
+ public static final String COLOR = "color";
+ public static final String CONTENT = "content";
+ public static final String COUNTER_INCREMENT = "counter-increment";
+ public static final String COUNTER_RESET = "counter-reset";
+ public static final String CUE = "cue";
+ public static final String CUE_AFTER = "cue-after";
+ public static final String CUE_BEFORE = "cue-before";
+ public static final String CURSOR = "cursor";
+ public static final String DIRECTION = "direction";
+ public static final String DISPLAY = "display";
+ public static final String ELEVATION = "elevation";
+ public static final String EMPTY_CELLS = "empty-cells";
+ public static final String FLOAT = "float";
+ public static final String FONT = "font";
+ public static final String FONT_FAMILY = "font-family";
+ public static final String FONT_SIZE = "font-size";
+ public static final String FONT_STYLE = "font-style";
+ public static final String FONT_VARIANT = "font-variant";
+ public static final String FONT_WEIGHT = "font-weight";
+ public static final String HEIGHT = "height";
+ public static final String HIDDEN = "hidden";
+ public static final String LETTER_SPACING = "letter-spacing";
+ public static final String LINE_HEIGHT = "line-height";
+ public static final String LIST_STYLE = "list-style";
+ public static final String LIST_STYLE_IMAGE = "list-style-image";
+ public static final String LIST_STYLE_POSITION = "list-style-position";
+ public static final String LIST_STYLE_TYPE = "list-style-type";
+ public static final String MARGIN = "margin";
+ public static final String MARGIN_BOTTOM = "margin-bottom";
+ public static final String MARGIN_LEFT = "margin-left";
+ public static final String MARGIN_RIGHT = "margin-right";
+ public static final String MARGIN_TOP = "margin-top";
+ public static final String MAX_HEIGHT = "max-height";
+ public static final String MAX_WIDTH = "max-width";
+ public static final String MIN_HEIGHT = "min-height";
+ public static final String MIN_WIDTH = "min-width";
+ public static final String ORPHANS = "orphans";
+ public static final String OUTLINE = "outline";
+ public static final String OVERFLOW = "overflow";
+ public static final String OUTLINE_COLOR = "outline-color";
+ public static final String OUTLINE_STYLE = "outline-style";
+ public static final String OUTLINE_WIDTH = "outline-width";
+ public static final String PADDING = "padding";
+ public static final String PADDING_BOTTOM = "padding-bottom";
+ public static final String PADDING_LEFT = "padding-left";
+ public static final String PADDING_RIGHT = "padding-right";
+ public static final String PADDING_TOP = "padding-top";
+ public static final String PAUSE = "pause";
+ public static final String PAUSE_AFTER = "pause-after";
+ public static final String PAUSE_BEFORE = "pause-before";
+ public static final String PITCH = "pitch";
+ public static final String PITCH_RANGE = "pitch-range";
+ public static final String PLAY_DURING = "play-during";
+ public static final String POSITION = "position";
+ public static final String QUOTES = "quotes";
+ public static final String RICHNESS = "richness";
+ public static final String SPEAK = "speak";
+ public static final String SPEAK_HEADER = "speak-header";
+ public static final String SPEAK_NUMERAL = "speak-numeral";
+ public static final String SPEAK_PUNCTUATION = "speak-punctuation";
+ public static final String SPEECH_RATE = "speech-rate";
+ public static final String STRESS = "stress";
+ public static final String TABLE_LAYOUT = "table-layout";
+ public static final String TEXT_ALIGN = "text-align";
+ public static final String TEXT_DECORATION = "text-decoration";
+ public static final String TEXT_INDENT = "text-indent";
+ public static final String TEXT_TRANSFORM = "text-transform";
+ public static final String UNICODE_BIDI = "unicode-bidi";
+ public static final String VERTICAL_ALIGN = "vertical-align";
+ public static final String VISIBILITY = "visibility";
+ public static final String VOICE_FAMILY = "voice-family";
+ public static final String VOLUME = "volume";
+ public static final String WHITE_SPACE = "white-space";
+ public static final String WIDOWS = "widows";
+ public static final String WIDTH = "width";
+ public static final String WORD_SPACING = "word-spacing";
+ public static final String Z_SPACING = "z-spacing";
- // suffixes to BORDER_XXX
- public static final String COLOR_SUFFIX = "-color";
- public static final String STYLE_SUFFIX = "-style";
- public static final String WIDTH_SUFFIX = "-width";
+ // suffixes to BORDER_XXX
+ public static final String COLOR_SUFFIX = "-color";
+ public static final String STYLE_SUFFIX = "-style";
+ public static final String WIDTH_SUFFIX = "-width";
- // color values
- public static final String AQUA = "aqua";
- public static final String BLACK = "black";
- public static final String BLUE = "blue";
- public static final String FUCHSIA = "fuchsia";
- public static final String GRAY = "gray";
- public static final String GREEN = "green";
- public static final String LIME = "lime";
- public static final String MAROON = "maroon";
- public static final String NAVY = "navy";
- public static final String OLIVE = "olive";
- public static final String ORANGE = "orange";
- public static final String PURPLE = "purple";
- public static final String RED = "red";
- public static final String SILVER = "silver";
- public static final String TEAL = "teal";
- public static final String WHITE = "white";
- public static final String YELLOW = "yellow";
+ // color values
+ public static final String AQUA = "aqua";
+ public static final String BLACK = "black";
+ public static final String BLUE = "blue";
+ public static final String FUCHSIA = "fuchsia";
+ public static final String GRAY = "gray";
+ public static final String GREEN = "green";
+ public static final String LIME = "lime";
+ public static final String MAROON = "maroon";
+ public static final String NAVY = "navy";
+ public static final String OLIVE = "olive";
+ public static final String ORANGE = "orange";
+ public static final String PURPLE = "purple";
+ public static final String RED = "red";
+ public static final String SILVER = "silver";
+ public static final String TEAL = "teal";
+ public static final String WHITE = "white";
+ public static final String YELLOW = "yellow";
- // list-style values
- public static final String ARMENIAN = "armenian";
- public static final String CIRCLE = "circle";
- public static final String CJK_IDEOGRAPHIC = "cjk-ideographic";
- public static final String DECIMAL = "decimal";
- public static final String DECIMAL_LEADING_ZERO = "decimal-leading-zero";
- public static final String DISC = "disc";
- public static final String GEORGIAN = "georgian";
- public static final String HEBREW = "hebrew";
- public static final String HIRAGANA = "hiragana";
- public static final String HIRAGANA_IROHA = "hiragana-iroha";
- public static final String KATAKANA = "katakana";
- public static final String KATAKANA_IROHA = "katakana-iroha";
- public static final String LOWER_ALPHA = "lower-alpha";
- public static final String LOWER_GREEK = "lower-greek";
- public static final String LOWER_LATIN = "lower-latin";
- public static final String LOWER_ROMAN = "lower-roman";
- public static final String SQUARE = "square";
- public static final String UPPER_ALPHA = "upper-alpha";
- public static final String UPPER_LATIN = "upper-latin";
- public static final String UPPER_ROMAN = "upper-roman";
-
-
- // other values
- public static final String BLINK = "blink";
- public static final String BLOCK = "block";
- public static final String BOLD = "bold";
- public static final String BOLDER = "bolder";
- public static final String CENTER = "center";
- public static final String DASHED = "dashed";
- public static final String DOTTED = "dotted";
- public static final String DOUBLE = "double";
- public static final String GROOVE = "groove";
- public static final String INLINE = "inline";
- public static final String INLINE_BLOCK = "inline-block";
- public static final String INLINE_TABLE = "inline-table";
- public static final String INSET = "inset";
- public static final String ITALIC = "italic";
- public static final String JUSTIFY = "justify";
- public static final String LARGE = "large";
- public static final String LARGER = "larger";
- public static final String LEFT = "left";
- public static final String LIGHTER = "lighter";
- public static final String LINE_THROUGH = "line-through";
- public static final String LIST_ITEM = "list-item";
- public static final String MEDIUM = "medium";
- public static final String NONE = "none";
- public static final String NORMAL = "normal";
- public static final String NOWRAP = "nowrap";
- public static final String OBLIQUE = "oblique";
- public static final String OUTSET = "outset";
- public static final String OVERLINE = "overline";
- public static final String PRE = "pre";
- public static final String RIDGE = "ridge";
- public static final String RIGHT = "right";
- public static final String RUN_IN = "run-in";
- public static final String SOLID = "solid";
- public static final String SMALL = "small";
- public static final String SMALL_CAPS = "small-caps";
- public static final String SMALLER = "smaller";
- public static final String TABLE = "table";
- public static final String TABLE_CAPTION = "table-caption";
- public static final String TABLE_CELL = "table-cell";
- public static final String TABLE_COLUMN = "table-column";
- public static final String TABLE_COLUMN_GROUP = "table-column-group";
- public static final String TABLE_FOOTER_GROUP = "table-footer-group";
- public static final String TABLE_HEADER_GROUP = "table-header-group";
- public static final String TABLE_ROW = "table-row";
- public static final String TABLE_ROW_GROUP = "table-row-group";
- public static final String THICK = "thick";
- public static final String THIN = "thin";
- public static final String UNDERLINE = "underline";
- public static final String X_LARGE = "x-large";
- public static final String X_SMALL = "x-small";
- public static final String XX_LARGE = "xx-large";
- public static final String XX_SMALL = "xx-small";
-
+ // list-style values
+ public static final String ARMENIAN = "armenian";
+ public static final String CIRCLE = "circle";
+ public static final String CJK_IDEOGRAPHIC = "cjk-ideographic";
+ public static final String DECIMAL = "decimal";
+ public static final String DECIMAL_LEADING_ZERO = "decimal-leading-zero";
+ public static final String DISC = "disc";
+ public static final String GEORGIAN = "georgian";
+ public static final String HEBREW = "hebrew";
+ public static final String HIRAGANA = "hiragana";
+ public static final String HIRAGANA_IROHA = "hiragana-iroha";
+ public static final String KATAKANA = "katakana";
+ public static final String KATAKANA_IROHA = "katakana-iroha";
+ public static final String LOWER_ALPHA = "lower-alpha";
+ public static final String LOWER_GREEK = "lower-greek";
+ public static final String LOWER_LATIN = "lower-latin";
+ public static final String LOWER_ROMAN = "lower-roman";
+ public static final String SQUARE = "square";
+ public static final String UPPER_ALPHA = "upper-alpha";
+ public static final String UPPER_LATIN = "upper-latin";
+ public static final String UPPER_ROMAN = "upper-roman";
+
+ // other values
+ public static final String BLINK = "blink";
+ public static final String BLOCK = "block";
+ public static final String BOLD = "bold";
+ public static final String BOLDER = "bolder";
+ public static final String CENTER = "center";
+ public static final String DASHED = "dashed";
+ public static final String DOTTED = "dotted";
+ public static final String DOUBLE = "double";
+ public static final String GROOVE = "groove";
+ public static final String INLINE = "inline";
+ public static final String INLINE_BLOCK = "inline-block";
+ public static final String INLINE_TABLE = "inline-table";
+ public static final String INSET = "inset";
+ public static final String ITALIC = "italic";
+ public static final String JUSTIFY = "justify";
+ public static final String LARGE = "large";
+ public static final String LARGER = "larger";
+ public static final String LEFT = "left";
+ public static final String LIGHTER = "lighter";
+ public static final String LINE_THROUGH = "line-through";
+ public static final String LIST_ITEM = "list-item";
+ public static final String MEDIUM = "medium";
+ public static final String NONE = "none";
+ public static final String NORMAL = "normal";
+ public static final String NOWRAP = "nowrap";
+ public static final String OBLIQUE = "oblique";
+ public static final String OUTSET = "outset";
+ public static final String OVERLINE = "overline";
+ public static final String PRE = "pre";
+ public static final String RIDGE = "ridge";
+ public static final String RIGHT = "right";
+ public static final String RUN_IN = "run-in";
+ public static final String SOLID = "solid";
+ public static final String SMALL = "small";
+ public static final String SMALL_CAPS = "small-caps";
+ public static final String SMALLER = "smaller";
+ public static final String TABLE = "table";
+ public static final String TABLE_CAPTION = "table-caption";
+ public static final String TABLE_CELL = "table-cell";
+ public static final String TABLE_COLUMN = "table-column";
+ public static final String TABLE_COLUMN_GROUP = "table-column-group";
+ public static final String TABLE_FOOTER_GROUP = "table-footer-group";
+ public static final String TABLE_HEADER_GROUP = "table-header-group";
+ public static final String TABLE_ROW = "table-row";
+ public static final String TABLE_ROW_GROUP = "table-row-group";
+ public static final String THICK = "thick";
+ public static final String THIN = "thin";
+ public static final String UNDERLINE = "underline";
+ public static final String X_LARGE = "x-large";
+ public static final String X_SMALL = "x-small";
+ public static final String XX_LARGE = "xx-large";
+ public static final String XX_SMALL = "xx-small";
+
}
-
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/ColorProperty.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/ColorProperty.java
index 1dfd0b8..99ec847 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/ColorProperty.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/ColorProperty.java
@@ -13,7 +13,6 @@
import java.util.HashMap;
import java.util.Map;
-
import org.eclipse.wst.xml.vex.core.internal.core.Color;
import org.w3c.css.sac.LexicalUnit;
@@ -22,131 +21,135 @@
*/
public class ColorProperty extends AbstractProperty {
- private static Map colorNames = new HashMap();
+ private static Map colorNames = new HashMap();
- static {
- colorNames.put(CSS.AQUA, new Color(0, 255, 255));
- colorNames.put(CSS.BLACK, new Color(0, 0, 0));
- colorNames.put(CSS.BLUE, new Color(0, 0, 255));
- colorNames.put(CSS.FUCHSIA, new Color(255, 0, 255));
- colorNames.put(CSS.GRAY, new Color(128, 128, 128));
- colorNames.put(CSS.GREEN, new Color(0, 128, 0));
- colorNames.put(CSS.LIME, new Color(0, 255, 0));
- colorNames.put(CSS.MAROON, new Color(128, 0, 0));
- colorNames.put(CSS.NAVY, new Color(0, 0, 128));
- colorNames.put(CSS.OLIVE, new Color(128, 128, 0));
- colorNames.put(CSS.ORANGE, new Color( 255, 165, 0));
- colorNames.put(CSS.PURPLE, new Color(128, 0, 128));
- colorNames.put(CSS.RED, new Color(255, 0, 0));
- colorNames.put(CSS.SILVER, new Color(192, 192, 192));
- colorNames.put(CSS.TEAL, new Color(0, 128, 128));
- colorNames.put(CSS.WHITE, new Color(255, 255, 255));
- colorNames.put(CSS.YELLOW, new Color(255, 255, 0));
- }
+ static {
+ colorNames.put(CSS.AQUA, new Color(0, 255, 255));
+ colorNames.put(CSS.BLACK, new Color(0, 0, 0));
+ colorNames.put(CSS.BLUE, new Color(0, 0, 255));
+ colorNames.put(CSS.FUCHSIA, new Color(255, 0, 255));
+ colorNames.put(CSS.GRAY, new Color(128, 128, 128));
+ colorNames.put(CSS.GREEN, new Color(0, 128, 0));
+ colorNames.put(CSS.LIME, new Color(0, 255, 0));
+ colorNames.put(CSS.MAROON, new Color(128, 0, 0));
+ colorNames.put(CSS.NAVY, new Color(0, 0, 128));
+ colorNames.put(CSS.OLIVE, new Color(128, 128, 0));
+ colorNames.put(CSS.ORANGE, new Color(255, 165, 0));
+ colorNames.put(CSS.PURPLE, new Color(128, 0, 128));
+ colorNames.put(CSS.RED, new Color(255, 0, 0));
+ colorNames.put(CSS.SILVER, new Color(192, 192, 192));
+ colorNames.put(CSS.TEAL, new Color(0, 128, 128));
+ colorNames.put(CSS.WHITE, new Color(255, 255, 255));
+ colorNames.put(CSS.YELLOW, new Color(255, 255, 0));
+ }
- /**
- * Class constructor. The names CSS.COLOR and
- * CSS.BACKGROUND_COLOR are treated specially, as follows.
- *
- * <ul>
- * <li>If name is CSS.COLOR, it is inherited and defaults to black.</li>
- * <li>If name is CSS.BACKGROUND_COLOR, it is not inherited and defaults
- * to transparent (null).</li>
- * <li>Otherwise, it is not inherited and defaults to the current color.</li>
- * </ul>
- *
- * <p>Because of the default in the third case, the ColorProperty
- * for CSS.COLOR must be processed before any others.</p>
- * @param name Name of the element.
- */
- public ColorProperty(String name) {
- super(name);
- }
+ /**
+ * Class constructor. The names CSS.COLOR and CSS.BACKGROUND_COLOR are
+ * treated specially, as follows.
+ *
+ * <ul>
+ * <li>If name is CSS.COLOR, it is inherited and defaults to black.</li>
+ * <li>If name is CSS.BACKGROUND_COLOR, it is not inherited and defaults to
+ * transparent (null).</li>
+ * <li>Otherwise, it is not inherited and defaults to the current color.</li>
+ * </ul>
+ *
+ * <p>
+ * Because of the default in the third case, the ColorProperty for CSS.COLOR
+ * must be processed before any others.
+ * </p>
+ *
+ * @param name
+ * Name of the element.
+ */
+ public ColorProperty(String name) {
+ super(name);
+ }
- public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles) {
-
- boolean inherit = isInherit(lu) || this.getName().equals(CSS.COLOR);
-
- if (isColor(lu)) {
- return getColor(lu);
- } else if (inherit && parentStyles != null) {
- return parentStyles.get(this.getName());
- } else {
- if (this.getName().equals(CSS.COLOR)) {
- return Color.BLACK;
- } else if (this.getName().equals(CSS.BACKGROUND_COLOR)) {
- return null; // transparent
- } else {
- return styles.getColor();
- }
- }
- }
+ public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles) {
- /**
- * Returns true if the given lexical unit represents a color.
- *
- * @param lu LexicalUnit to check.
- */
- public static boolean isColor(LexicalUnit lu) {
- if (lu == null) {
- return false;
- } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT &&
- colorNames.containsKey(lu.getStringValue())) {
- return true;
- } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_RGBCOLOR) {
- return true;
- } else {
- return false;
- }
- }
+ boolean inherit = isInherit(lu) || this.getName().equals(CSS.COLOR);
- //========================================================== PRIVATE
+ if (isColor(lu)) {
+ return getColor(lu);
+ } else if (inherit && parentStyles != null) {
+ return parentStyles.get(this.getName());
+ } else {
+ if (this.getName().equals(CSS.COLOR)) {
+ return Color.BLACK;
+ } else if (this.getName().equals(CSS.BACKGROUND_COLOR)) {
+ return null; // transparent
+ } else {
+ return styles.getColor();
+ }
+ }
+ }
- private static Color getColor(LexicalUnit lu) {
- if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
- String s = lu.getStringValue();
- if (colorNames.containsKey(s)) {
- return (Color) colorNames.get(s);
- } else {
- return null;
- }
- } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_RGBCOLOR) {
- lu = lu.getParameters();
- int red = getColorPart(lu);
- lu = lu.getNextLexicalUnit(); // gobble comma
- lu = lu.getNextLexicalUnit();
- int green = getColorPart(lu);
- lu = lu.getNextLexicalUnit(); // gobble comma
- lu = lu.getNextLexicalUnit();
- int blue = getColorPart(lu);
-
- if (red == -1 || green == -1 || blue == -1) {
- return null;
- } else {
- return new Color(red, green, blue);
- }
- } else {
- System.out.println("WARNING: unsupported color type: " + lu);
- return null;
- }
- }
-
- /**
- * Converts one of the color channels into an int from 0-255, or -1
- * if there's an error.
- */
- private static int getColorPart(LexicalUnit lu) {
- int value;
- if (lu.getLexicalUnitType() == LexicalUnit.SAC_INTEGER) {
- value = lu.getIntegerValue();
- } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE) {
- value = Math.round(lu.getFloatValue() * 255);
- } else {
- System.out.println("WARNING: unsupported color part: " + lu);
- return -1;
- }
- return Math.max(0, Math.min(255, value));
- }
-
-
+ /**
+ * Returns true if the given lexical unit represents a color.
+ *
+ * @param lu
+ * LexicalUnit to check.
+ */
+ public static boolean isColor(LexicalUnit lu) {
+ if (lu == null) {
+ return false;
+ } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT
+ && colorNames.containsKey(lu.getStringValue())) {
+ return true;
+ } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_RGBCOLOR) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ // ========================================================== PRIVATE
+
+ private static Color getColor(LexicalUnit lu) {
+ if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
+ String s = lu.getStringValue();
+ if (colorNames.containsKey(s)) {
+ return (Color) colorNames.get(s);
+ } else {
+ return null;
+ }
+ } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_RGBCOLOR) {
+ lu = lu.getParameters();
+ int red = getColorPart(lu);
+ lu = lu.getNextLexicalUnit(); // gobble comma
+ lu = lu.getNextLexicalUnit();
+ int green = getColorPart(lu);
+ lu = lu.getNextLexicalUnit(); // gobble comma
+ lu = lu.getNextLexicalUnit();
+ int blue = getColorPart(lu);
+
+ if (red == -1 || green == -1 || blue == -1) {
+ return null;
+ } else {
+ return new Color(red, green, blue);
+ }
+ } else {
+ System.out.println("WARNING: unsupported color type: " + lu);
+ return null;
+ }
+ }
+
+ /**
+ * Converts one of the color channels into an int from 0-255, or -1 if
+ * there's an error.
+ */
+ private static int getColorPart(LexicalUnit lu) {
+ int value;
+ if (lu.getLexicalUnitType() == LexicalUnit.SAC_INTEGER) {
+ value = lu.getIntegerValue();
+ } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE) {
+ value = Math.round(lu.getFloatValue() * 255);
+ } else {
+ System.out.println("WARNING: unsupported color part: " + lu);
+ return -1;
+ }
+ return Math.max(0, Math.min(255, value));
+ }
+
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/DisplayProperty.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/DisplayProperty.java
index 919a17c..9fdc2dc 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/DisplayProperty.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/DisplayProperty.java
@@ -17,57 +17,52 @@
*/
public class DisplayProperty extends AbstractProperty {
- /**
- * Class constructor.
- */
- public DisplayProperty() {
- super(CSS.DISPLAY);
- }
+ /**
+ * Class constructor.
+ */
+ public DisplayProperty() {
+ super(CSS.DISPLAY);
+ }
- public Object calculate(LexicalUnit lu, Styles parentStyles,
- Styles styles) {
-
- if (isDisplay(lu)) {
- return lu.getStringValue();
- } else if (isInherit(lu) && parentStyles != null) {
- return parentStyles.getDisplay();
- } else {
- // not specified or other unknown value
- return CSS.INLINE;
- }
- }
+ public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles) {
- //======================================================== PRIVATE
-
- /**
- * Returns true if the value of the given LexicalUnit represents
- * a valid value for this property.
- * @param lu LexicalUnit to inspect.
- */
- private static boolean isDisplay(LexicalUnit lu) {
- if (lu == null) {
- return false;
- } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
- String s = lu.getStringValue();
- return s.equals(CSS.BLOCK)
- || s.equals(CSS.INLINE)
- || s.equals(CSS.INLINE_BLOCK)
- || s.equals(CSS.INLINE_TABLE)
- || s.equals(CSS.LIST_ITEM)
- || s.equals(CSS.NONE)
- || s.equals(CSS.RUN_IN)
- || s.equals(CSS.TABLE)
- || s.equals(CSS.TABLE_CAPTION)
- || s.equals(CSS.TABLE_CELL)
- || s.equals(CSS.TABLE_COLUMN)
- || s.equals(CSS.TABLE_COLUMN_GROUP)
- || s.equals(CSS.TABLE_FOOTER_GROUP)
- || s.equals(CSS.TABLE_HEADER_GROUP)
- || s.equals(CSS.TABLE_ROW)
- || s.equals(CSS.TABLE_ROW_GROUP);
- } else {
- return false;
- }
- }
-
+ if (isDisplay(lu)) {
+ return lu.getStringValue();
+ } else if (isInherit(lu) && parentStyles != null) {
+ return parentStyles.getDisplay();
+ } else {
+ // not specified or other unknown value
+ return CSS.INLINE;
+ }
+ }
+
+ // ======================================================== PRIVATE
+
+ /**
+ * Returns true if the value of the given LexicalUnit represents a valid
+ * value for this property.
+ *
+ * @param lu
+ * LexicalUnit to inspect.
+ */
+ private static boolean isDisplay(LexicalUnit lu) {
+ if (lu == null) {
+ return false;
+ } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
+ String s = lu.getStringValue();
+ return s.equals(CSS.BLOCK) || s.equals(CSS.INLINE)
+ || s.equals(CSS.INLINE_BLOCK) || s.equals(CSS.INLINE_TABLE)
+ || s.equals(CSS.LIST_ITEM) || s.equals(CSS.NONE)
+ || s.equals(CSS.RUN_IN) || s.equals(CSS.TABLE)
+ || s.equals(CSS.TABLE_CAPTION) || s.equals(CSS.TABLE_CELL)
+ || s.equals(CSS.TABLE_COLUMN)
+ || s.equals(CSS.TABLE_COLUMN_GROUP)
+ || s.equals(CSS.TABLE_FOOTER_GROUP)
+ || s.equals(CSS.TABLE_HEADER_GROUP)
+ || s.equals(CSS.TABLE_ROW) || s.equals(CSS.TABLE_ROW_GROUP);
+ } else {
+ return false;
+ }
+ }
+
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/FontFamilyProperty.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/FontFamilyProperty.java
index ca857b3..f7a8491 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/FontFamilyProperty.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/FontFamilyProperty.java
@@ -20,52 +20,51 @@
*/
public class FontFamilyProperty extends AbstractProperty {
- /**
- * Class constructor.
- */
- public FontFamilyProperty() {
- super(CSS.FONT_FAMILY);
- }
+ /**
+ * Class constructor.
+ */
+ public FontFamilyProperty() {
+ super(CSS.FONT_FAMILY);
+ }
- /**
+ /**
*
*/
- public Object calculate(LexicalUnit lu, Styles parentStyles,
- Styles styles) {
- if (isFontFamily(lu)) {
- return getFontFamilies(lu);
- } else {
- // not specified, "inherit", or some other value
- if (parentStyles != null) {
- return parentStyles.getFontFamilies();
- } else {
- return DEFAULT_FONT_FAMILY;
- }
- }
- }
+ public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles) {
+ if (isFontFamily(lu)) {
+ return getFontFamilies(lu);
+ } else {
+ // not specified, "inherit", or some other value
+ if (parentStyles != null) {
+ return parentStyles.getFontFamilies();
+ } else {
+ return DEFAULT_FONT_FAMILY;
+ }
+ }
+ }
- //================================================= PRIVATE
-
- private static final String[] DEFAULT_FONT_FAMILY = new String[] { "sans-serif" };
+ // ================================================= PRIVATE
- private static boolean isFontFamily(LexicalUnit lu) {
- return lu != null
- && (lu.getLexicalUnitType() == LexicalUnit.SAC_STRING_VALUE
- || lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT);
- }
+ private static final String[] DEFAULT_FONT_FAMILY = new String[] { "sans-serif" };
- private static String[] getFontFamilies(LexicalUnit lu) {
- List list = new ArrayList();
- while (lu != null) {
- if (lu.getLexicalUnitType() == LexicalUnit.SAC_STRING_VALUE
- || lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
-
- list.add(lu.getStringValue());
- }
- lu = lu.getNextLexicalUnit();
- }
- return (String[]) list.toArray(new String[list.size()]);
- }
+ private static boolean isFontFamily(LexicalUnit lu) {
+ return lu != null
+ && (lu.getLexicalUnitType() == LexicalUnit.SAC_STRING_VALUE || lu
+ .getLexicalUnitType() == LexicalUnit.SAC_IDENT);
+ }
+
+ private static String[] getFontFamilies(LexicalUnit lu) {
+ List list = new ArrayList();
+ while (lu != null) {
+ if (lu.getLexicalUnitType() == LexicalUnit.SAC_STRING_VALUE
+ || lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
+
+ list.add(lu.getStringValue());
+ }
+ lu = lu.getNextLexicalUnit();
+ }
+ return (String[]) list.toArray(new String[list.size()]);
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/FontSizeProperty.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/FontSizeProperty.java
index 8f30991..7c64a97 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/FontSizeProperty.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/FontSizeProperty.java
@@ -10,138 +10,134 @@
*******************************************************************************/
package org.eclipse.wst.xml.vex.core.internal.css;
-
import org.eclipse.wst.xml.vex.core.internal.core.DisplayDevice;
import org.w3c.css.sac.LexicalUnit;
/**
- * The CSS font-size property. Note that other lengths depend on the
- * computed value of this property, so this should be evaluated early
- * on in the stylesheet, before any other lengths.
+ * The CSS font-size property. Note that other lengths depend on the computed
+ * value of this property, so this should be evaluated early on in the
+ * stylesheet, before any other lengths.
*/
public class FontSizeProperty extends AbstractProperty {
- /**
- * Class constructor,
- */
- public FontSizeProperty() {
- super(CSS.FONT_SIZE);
- }
+ /**
+ * Class constructor,
+ */
+ public FontSizeProperty() {
+ super(CSS.FONT_SIZE);
+ }
- public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles) {
- return new Float(this.calculateInternal(lu, parentStyles, styles));
- }
+ public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles) {
+ return new Float(this.calculateInternal(lu, parentStyles, styles));
+ }
- /**
- * Returns true if the given lexical unit represents a font size.
- *
- * @param lu LexicalUnit to check.
- */
- public static boolean isFontSize(LexicalUnit lu) {
- if (lu == null) {
- return false;
- } else if (isLength(lu)) {
- return true;
- } else if (isPercentage(lu)) {
- return true;
- } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
- String s = lu.getStringValue();
- return s.equals(CSS.XX_SMALL)
- || s.equals(CSS.X_SMALL)
- || s.equals(CSS.SMALL)
- || s.equals(CSS.MEDIUM)
- || s.equals(CSS.LARGE)
- || s.equals(CSS.X_LARGE)
- || s.equals(CSS.XX_LARGE)
- || s.equals(CSS.SMALLER)
- || s.equals(CSS.LARGER);
- } else {
- return false;
- }
- }
-
- //======================================================== PRIVATE
-
- private float calculateInternal(LexicalUnit lu, Styles parentStyles, Styles styles) {
+ /**
+ * Returns true if the given lexical unit represents a font size.
+ *
+ * @param lu
+ * LexicalUnit to check.
+ */
+ public static boolean isFontSize(LexicalUnit lu) {
+ if (lu == null) {
+ return false;
+ } else if (isLength(lu)) {
+ return true;
+ } else if (isPercentage(lu)) {
+ return true;
+ } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
+ String s = lu.getStringValue();
+ return s.equals(CSS.XX_SMALL) || s.equals(CSS.X_SMALL)
+ || s.equals(CSS.SMALL) || s.equals(CSS.MEDIUM)
+ || s.equals(CSS.LARGE) || s.equals(CSS.X_LARGE)
+ || s.equals(CSS.XX_LARGE) || s.equals(CSS.SMALLER)
+ || s.equals(CSS.LARGER);
+ } else {
+ return false;
+ }
+ }
- DisplayDevice device = DisplayDevice.getCurrent();
- float baseFontSize = DEFAULT_FONT_SIZE_POINTS * device.getVerticalPPI() / 72;
-
- if (parentStyles != null) {
- baseFontSize = parentStyles.getFontSize();
- }
-
- if (lu == null) {
- return baseFontSize;
- } else if (isLength(lu)) {
- return getFloatLength(lu, baseFontSize, device.getVerticalPPI());
- } else if (isPercentage(lu)) {
- return baseFontSize * lu.getFloatValue() / 100;
- } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
- String s = lu.getStringValue();
-
- if (s.equals(CSS.XX_SMALL)) {
- return baseFontSize * FONT_FACTOR_XX_SMALL;
-
- } else if (s.equals(CSS.X_SMALL)) {
- return baseFontSize * FONT_FACTOR_X_SMALL;
-
- } else if (s.equals(CSS.SMALL)) {
- return baseFontSize * FONT_FACTOR_SMALL;
-
- } else if (s.equals(CSS.MEDIUM)) {
- return baseFontSize * FONT_FACTOR_MEDIUM;
-
- } else if (s.equals(CSS.LARGE)) {
- return baseFontSize * FONT_FACTOR_LARGE;
-
- } else if (s.equals(CSS.X_LARGE)) {
- return baseFontSize * FONT_FACTOR_X_LARGE;
-
- } else if (s.equals(CSS.XX_LARGE)) {
- return baseFontSize * FONT_FACTOR_XX_LARGE;
-
- } else if (s.equals(CSS.SMALLER)) {
- return baseFontSize / FONT_SIZE_FACTOR;
-
- } else if (s.equals(CSS.LARGER)) {
- return baseFontSize * FONT_SIZE_FACTOR;
-
- } else {
- return baseFontSize;
- }
- } else {
- return baseFontSize;
- }
-
-
- }
+ // ======================================================== PRIVATE
- private static final float DEFAULT_FONT_SIZE_POINTS = 12;
+ private float calculateInternal(LexicalUnit lu, Styles parentStyles,
+ Styles styles) {
- // relative size of adjacent font size names
- private static final float FONT_SIZE_FACTOR = 1.2f;
+ DisplayDevice device = DisplayDevice.getCurrent();
+ float baseFontSize = DEFAULT_FONT_SIZE_POINTS * device.getVerticalPPI()
+ / 72;
- // Sizes of named font sizes, relative to "medium"
- private static final float FONT_FACTOR_MEDIUM = 1.0f;
-
- private static final float FONT_FACTOR_SMALL =
- FONT_FACTOR_MEDIUM / FONT_SIZE_FACTOR;
-
- private static final float FONT_FACTOR_X_SMALL =
- FONT_FACTOR_SMALL / FONT_SIZE_FACTOR;
-
- private static final float FONT_FACTOR_XX_SMALL =
- FONT_FACTOR_X_SMALL / FONT_SIZE_FACTOR;
-
- private static final float FONT_FACTOR_LARGE =
- FONT_FACTOR_MEDIUM * FONT_SIZE_FACTOR;
-
- private static final float FONT_FACTOR_X_LARGE =
- FONT_FACTOR_LARGE * FONT_SIZE_FACTOR;
-
- private static final float FONT_FACTOR_XX_LARGE =
- FONT_FACTOR_X_LARGE * FONT_SIZE_FACTOR;
+ if (parentStyles != null) {
+ baseFontSize = parentStyles.getFontSize();
+ }
+ if (lu == null) {
+ return baseFontSize;
+ } else if (isLength(lu)) {
+ return getFloatLength(lu, baseFontSize, device.getVerticalPPI());
+ } else if (isPercentage(lu)) {
+ return baseFontSize * lu.getFloatValue() / 100;
+ } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
+ String s = lu.getStringValue();
+
+ if (s.equals(CSS.XX_SMALL)) {
+ return baseFontSize * FONT_FACTOR_XX_SMALL;
+
+ } else if (s.equals(CSS.X_SMALL)) {
+ return baseFontSize * FONT_FACTOR_X_SMALL;
+
+ } else if (s.equals(CSS.SMALL)) {
+ return baseFontSize * FONT_FACTOR_SMALL;
+
+ } else if (s.equals(CSS.MEDIUM)) {
+ return baseFontSize * FONT_FACTOR_MEDIUM;
+
+ } else if (s.equals(CSS.LARGE)) {
+ return baseFontSize * FONT_FACTOR_LARGE;
+
+ } else if (s.equals(CSS.X_LARGE)) {
+ return baseFontSize * FONT_FACTOR_X_LARGE;
+
+ } else if (s.equals(CSS.XX_LARGE)) {
+ return baseFontSize * FONT_FACTOR_XX_LARGE;
+
+ } else if (s.equals(CSS.SMALLER)) {
+ return baseFontSize / FONT_SIZE_FACTOR;
+
+ } else if (s.equals(CSS.LARGER)) {
+ return baseFontSize * FONT_SIZE_FACTOR;
+
+ } else {
+ return baseFontSize;
+ }
+ } else {
+ return baseFontSize;
+ }
+
+ }
+
+ private static final float DEFAULT_FONT_SIZE_POINTS = 12;
+
+ // relative size of adjacent font size names
+ private static final float FONT_SIZE_FACTOR = 1.2f;
+
+ // Sizes of named font sizes, relative to "medium"
+ private static final float FONT_FACTOR_MEDIUM = 1.0f;
+
+ private static final float FONT_FACTOR_SMALL = FONT_FACTOR_MEDIUM
+ / FONT_SIZE_FACTOR;
+
+ private static final float FONT_FACTOR_X_SMALL = FONT_FACTOR_SMALL
+ / FONT_SIZE_FACTOR;
+
+ private static final float FONT_FACTOR_XX_SMALL = FONT_FACTOR_X_SMALL
+ / FONT_SIZE_FACTOR;
+
+ private static final float FONT_FACTOR_LARGE = FONT_FACTOR_MEDIUM
+ * FONT_SIZE_FACTOR;
+
+ private static final float FONT_FACTOR_X_LARGE = FONT_FACTOR_LARGE
+ * FONT_SIZE_FACTOR;
+
+ private static final float FONT_FACTOR_XX_LARGE = FONT_FACTOR_X_LARGE
+ * FONT_SIZE_FACTOR;
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/FontStyleProperty.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/FontStyleProperty.java
index ebf432d..6966518 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/FontStyleProperty.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/FontStyleProperty.java
@@ -17,43 +17,43 @@
*/
public class FontStyleProperty extends AbstractProperty {
- /**
- * Class constructor.
- */
- public FontStyleProperty() {
- super(CSS.FONT_STYLE);
- }
+ /**
+ * Class constructor.
+ */
+ public FontStyleProperty() {
+ super(CSS.FONT_STYLE);
+ }
- public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles) {
- if (isFontStyle(lu)) {
- return lu.getStringValue();
- } else {
- // not specified, "inherit", or some other value
- if (parentStyles != null) {
- return parentStyles.getFontStyle();
- } else {
- return CSS.NORMAL;
- }
- }
+ public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles) {
+ if (isFontStyle(lu)) {
+ return lu.getStringValue();
+ } else {
+ // not specified, "inherit", or some other value
+ if (parentStyles != null) {
+ return parentStyles.getFontStyle();
+ } else {
+ return CSS.NORMAL;
+ }
+ }
- }
+ }
- /**
- * Returns true if the given lexical unit represents a font style.
- *
- * @param lu LexicalUnit to check.
- */
- public static boolean isFontStyle(LexicalUnit lu) {
- if (lu == null) {
- return false;
- } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
- String s = lu.getStringValue();
- return s.equals(CSS.NORMAL)
- || s.equals(CSS.ITALIC)
- || s.equals(CSS.OBLIQUE);
- } else {
- return false;
- }
- }
-
+ /**
+ * Returns true if the given lexical unit represents a font style.
+ *
+ * @param lu
+ * LexicalUnit to check.
+ */
+ public static boolean isFontStyle(LexicalUnit lu) {
+ if (lu == null) {
+ return false;
+ } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
+ String s = lu.getStringValue();
+ return s.equals(CSS.NORMAL) || s.equals(CSS.ITALIC)
+ || s.equals(CSS.OBLIQUE);
+ } else {
+ return false;
+ }
+ }
+
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/FontVariantProperty.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/FontVariantProperty.java
index e6b57ca..613f0e1 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/FontVariantProperty.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/FontVariantProperty.java
@@ -17,42 +17,42 @@
*/
public class FontVariantProperty extends AbstractProperty {
- /**
- * Class constructor.
- */
- public FontVariantProperty() {
- super(CSS.FONT_VARIANT);
- }
+ /**
+ * Class constructor.
+ */
+ public FontVariantProperty() {
+ super(CSS.FONT_VARIANT);
+ }
- public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles) {
- if (isFontVariant(lu)) {
- return lu.getStringValue();
- } else {
- // not specified, "inherit", or some other value
- if (parentStyles != null) {
- return parentStyles.getFontStyle();
- } else {
- return CSS.NORMAL;
- }
- }
+ public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles) {
+ if (isFontVariant(lu)) {
+ return lu.getStringValue();
+ } else {
+ // not specified, "inherit", or some other value
+ if (parentStyles != null) {
+ return parentStyles.getFontStyle();
+ } else {
+ return CSS.NORMAL;
+ }
+ }
- }
+ }
- /**
- * Returns true if the given lexical unit represents a font variant.
- *
- * @param lu LexicalUnit to check.
- */
- public static boolean isFontVariant(LexicalUnit lu) {
- if (lu == null) {
- return false;
- } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
- String s = lu.getStringValue();
- return s.equals(CSS.NORMAL)
- || s.equals(CSS.SMALL_CAPS);
- } else {
- return false;
- }
- }
-
+ /**
+ * Returns true if the given lexical unit represents a font variant.
+ *
+ * @param lu
+ * LexicalUnit to check.
+ */
+ public static boolean isFontVariant(LexicalUnit lu) {
+ if (lu == null) {
+ return false;
+ } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
+ String s = lu.getStringValue();
+ return s.equals(CSS.NORMAL) || s.equals(CSS.SMALL_CAPS);
+ } else {
+ return false;
+ }
+ }
+
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/FontWeightProperty.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/FontWeightProperty.java
index 9336790..912a439 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/FontWeightProperty.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/FontWeightProperty.java
@@ -17,84 +17,84 @@
*/
public class FontWeightProperty extends AbstractProperty {
- private static final int FONT_WEIGHT_NORMAL = 400;
- private static final int FONT_WEIGHT_BOLD = 700;
+ private static final int FONT_WEIGHT_NORMAL = 400;
+ private static final int FONT_WEIGHT_BOLD = 700;
- /**
- * Class constructor.
- */
- public FontWeightProperty() {
- super(CSS.FONT_WEIGHT);
- }
+ /**
+ * Class constructor.
+ */
+ public FontWeightProperty() {
+ super(CSS.FONT_WEIGHT);
+ }
- public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles) {
- return new Integer(this.calculateInternal(lu, parentStyles, styles));
- }
+ public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles) {
+ return new Integer(this.calculateInternal(lu, parentStyles, styles));
+ }
- public int calculateInternal(LexicalUnit lu, Styles parentStyles, Styles styles) {
- if (isFontWeight(lu)) {
- return getFontWeight(lu, parentStyles);
- } else {
- // not specified, "inherit", or some other value
- if (parentStyles != null) {
- return parentStyles.getFontWeight();
- } else {
- return FONT_WEIGHT_NORMAL;
- }
- }
-
- }
+ public int calculateInternal(LexicalUnit lu, Styles parentStyles,
+ Styles styles) {
+ if (isFontWeight(lu)) {
+ return getFontWeight(lu, parentStyles);
+ } else {
+ // not specified, "inherit", or some other value
+ if (parentStyles != null) {
+ return parentStyles.getFontWeight();
+ } else {
+ return FONT_WEIGHT_NORMAL;
+ }
+ }
- /**
- * Returns true if the given lexical unit represents a font weight.
- *
- * @param lu LexicalUnit to check.
- */
- public static boolean isFontWeight(LexicalUnit lu) {
- if (lu == null) {
- return false;
- } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_INTEGER) {
- return true;
- } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
- String s = lu.getStringValue();
- return s.equals(CSS.NORMAL)
- || s.equals(CSS.BOLD)
- || s.equals(CSS.BOLDER)
- || s.equals(CSS.LIGHTER);
- } else {
- return false;
- }
- }
+ }
- private static int getFontWeight(LexicalUnit lu, Styles parentStyles) {
- if (lu == null) {
- return FONT_WEIGHT_NORMAL;
- } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_INTEGER) {
- return lu.getIntegerValue();
- } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
- String s = lu.getStringValue();
- if (s.equals(CSS.NORMAL)) {
- return FONT_WEIGHT_NORMAL;
- } else if (s.equals(CSS.BOLD)) {
- return FONT_WEIGHT_BOLD;
- } else if (s.equals(CSS.BOLDER)) {
- if (parentStyles != null) {
- return parentStyles.getFontWeight() + 151;
- } else {
- return FONT_WEIGHT_BOLD;
- }
- } else if (s.equals(CSS.LIGHTER)) {
- if (parentStyles != null) {
- return parentStyles.getFontWeight() - 151;
- } else {
- return FONT_WEIGHT_NORMAL;
- }
- } else {
- return FONT_WEIGHT_NORMAL;
- }
- } else {
- return FONT_WEIGHT_NORMAL;
- }
- }
-
+ /**
+ * Returns true if the given lexical unit represents a font weight.
+ *
+ * @param lu
+ * LexicalUnit to check.
+ */
+ public static boolean isFontWeight(LexicalUnit lu) {
+ if (lu == null) {
+ return false;
+ } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_INTEGER) {
+ return true;
+ } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
+ String s = lu.getStringValue();
+ return s.equals(CSS.NORMAL) || s.equals(CSS.BOLD)
+ || s.equals(CSS.BOLDER) || s.equals(CSS.LIGHTER);
+ } else {
+ return false;
+ }
+ }
+
+ private static int getFontWeight(LexicalUnit lu, Styles parentStyles) {
+ if (lu == null) {
+ return FONT_WEIGHT_NORMAL;
+ } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_INTEGER) {
+ return lu.getIntegerValue();
+ } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
+ String s = lu.getStringValue();
+ if (s.equals(CSS.NORMAL)) {
+ return FONT_WEIGHT_NORMAL;
+ } else if (s.equals(CSS.BOLD)) {
+ return FONT_WEIGHT_BOLD;
+ } else if (s.equals(CSS.BOLDER)) {
+ if (parentStyles != null) {
+ return parentStyles.getFontWeight() + 151;
+ } else {
+ return FONT_WEIGHT_BOLD;
+ }
+ } else if (s.equals(CSS.LIGHTER)) {
+ if (parentStyles != null) {
+ return parentStyles.getFontWeight() - 151;
+ } else {
+ return FONT_WEIGHT_NORMAL;
+ }
+ } else {
+ return FONT_WEIGHT_NORMAL;
+ }
+ } else {
+ return FONT_WEIGHT_NORMAL;
+ }
+ }
+
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/IProperty.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/IProperty.java
index 3190b35..5eaa60d 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/IProperty.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/IProperty.java
@@ -16,28 +16,31 @@
* Represents a CSS property.
*/
public interface IProperty {
-
- /** Constant indicating the length is along the horizontal axis. */
- public static final byte AXIS_HORIZONTAL = 0;
- /** Constant indicating the length is along the vertical axis. */
- public static final byte AXIS_VERTICAL = 1;
+ /** Constant indicating the length is along the horizontal axis. */
+ public static final byte AXIS_HORIZONTAL = 0;
+ /** Constant indicating the length is along the vertical axis. */
+ public static final byte AXIS_VERTICAL = 1;
- /**
- * Returns the name of the property.
- */
- public String getName();
+ /**
+ * Returns the name of the property.
+ */
+ public String getName();
- /**
- * Calculates the value of a property given a LexicalUnit.
- * @param lu LexicalUnit to interpret.
- * @param parentStyles Styles of the parent element. These are used
- * when the property inherits a value.
- * @param styles Styles currently in effect. Often, the calculated
- * value depends on previously calculated styles such as font size
- * and color.
- */
- public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles);
+ /**
+ * Calculates the value of a property given a LexicalUnit.
+ *
+ * @param lu
+ * LexicalUnit to interpret.
+ * @param parentStyles
+ * Styles of the parent element. These are used when the property
+ * inherits a value.
+ * @param styles
+ * Styles currently in effect. Often, the calculated value
+ * depends on previously calculated styles such as font size and
+ * color.
+ */
+ public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles);
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/LengthProperty.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/LengthProperty.java
index fc6c74e..8802136 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/LengthProperty.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/LengthProperty.java
@@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.wst.xml.vex.core.internal.css;
-
import org.eclipse.wst.xml.vex.core.internal.core.DisplayDevice;
import org.w3c.css.sac.LexicalUnit;
@@ -19,31 +18,31 @@
*/
public class LengthProperty extends AbstractProperty {
- public LengthProperty(String name, byte axis) {
- super(name);
- this.axis = axis;
- }
+ public LengthProperty(String name, byte axis) {
+ super(name);
+ this.axis = axis;
+ }
- public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles) {
+ public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles) {
- DisplayDevice device = DisplayDevice.getCurrent();
- int ppi = this.axis == AXIS_HORIZONTAL ? device.getHorizontalPPI() : device.getVerticalPPI();
-
- if (isLength(lu)) {
- int length = getIntLength(lu, styles.getFontSize(), ppi);
- return RelativeLength.createAbsolute(length);
- } else if (isPercentage(lu)) {
- return RelativeLength.createRelative(lu.getFloatValue() / 100);
- } else if (isInherit(lu) && parentStyles != null) {
- return parentStyles.get(this.getName());
- } else {
- // not specified, "auto", or other unknown value
- return RelativeLength.createAbsolute(0);
- }
- }
+ DisplayDevice device = DisplayDevice.getCurrent();
+ int ppi = this.axis == AXIS_HORIZONTAL ? device.getHorizontalPPI()
+ : device.getVerticalPPI();
+ if (isLength(lu)) {
+ int length = getIntLength(lu, styles.getFontSize(), ppi);
+ return RelativeLength.createAbsolute(length);
+ } else if (isPercentage(lu)) {
+ return RelativeLength.createRelative(lu.getFloatValue() / 100);
+ } else if (isInherit(lu) && parentStyles != null) {
+ return parentStyles.get(this.getName());
+ } else {
+ // not specified, "auto", or other unknown value
+ return RelativeLength.createAbsolute(0);
+ }
+ }
- //============================================================ PRIVATE
+ // ============================================================ PRIVATE
- private int axis;
+ private int axis;
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/LineHeightProperty.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/LineHeightProperty.java
index 8ef5f2f..d348751 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/LineHeightProperty.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/LineHeightProperty.java
@@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.wst.xml.vex.core.internal.css;
-
import org.eclipse.wst.xml.vex.core.internal.core.DisplayDevice;
import org.w3c.css.sac.LexicalUnit;
@@ -19,45 +18,47 @@
*/
public class LineHeightProperty extends AbstractProperty {
- private static final float LINE_HEIGHT_NORMAL = 1.2f;
+ private static final float LINE_HEIGHT_NORMAL = 1.2f;
- /**
- * Class constructor.
- */
- public LineHeightProperty() {
- super(CSS.LINE_HEIGHT);
- }
+ /**
+ * Class constructor.
+ */
+ public LineHeightProperty() {
+ super(CSS.LINE_HEIGHT);
+ }
- /**
- * Calculates the value of the property given a LexicalUnit. Returns
- * a RelativeLength that is relative to the current font size.
- */
- public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles) {
-
- int ppi = DisplayDevice.getCurrent().getVerticalPPI();
-
- if (isLength(lu)) {
- return RelativeLength.createAbsolute(Math.round(getIntLength(lu, styles.getFontSize(), ppi) / styles.getFontSize()));
- } else if (isNumber(lu)) {
- if (getNumber(lu) <= 0) {
- return RelativeLength.createRelative(LINE_HEIGHT_NORMAL);
- } else {
- return RelativeLength.createRelative(getNumber(lu));
- }
- } else if (isPercentage(lu)) {
- if (lu.getFloatValue() <= 0) {
- return RelativeLength.createRelative(LINE_HEIGHT_NORMAL);
- } else {
- return RelativeLength.createRelative(lu.getFloatValue() / 100);
- }
- } else {
- // not specified, "inherit", or other unknown value
- if (parentStyles == null) {
- return RelativeLength.createRelative(LINE_HEIGHT_NORMAL);
- } else {
- return (RelativeLength) parentStyles.get(CSS.LINE_HEIGHT);
- }
- }
- }
+ /**
+ * Calculates the value of the property given a LexicalUnit. Returns a
+ * RelativeLength that is relative to the current font size.
+ */
+ public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles) {
+
+ int ppi = DisplayDevice.getCurrent().getVerticalPPI();
+
+ if (isLength(lu)) {
+ return RelativeLength.createAbsolute(Math.round(getIntLength(lu,
+ styles.getFontSize(), ppi)
+ / styles.getFontSize()));
+ } else if (isNumber(lu)) {
+ if (getNumber(lu) <= 0) {
+ return RelativeLength.createRelative(LINE_HEIGHT_NORMAL);
+ } else {
+ return RelativeLength.createRelative(getNumber(lu));
+ }
+ } else if (isPercentage(lu)) {
+ if (lu.getFloatValue() <= 0) {
+ return RelativeLength.createRelative(LINE_HEIGHT_NORMAL);
+ } else {
+ return RelativeLength.createRelative(lu.getFloatValue() / 100);
+ }
+ } else {
+ // not specified, "inherit", or other unknown value
+ if (parentStyles == null) {
+ return RelativeLength.createRelative(LINE_HEIGHT_NORMAL);
+ } else {
+ return (RelativeLength) parentStyles.get(CSS.LINE_HEIGHT);
+ }
+ }
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/ListStyleTypeProperty.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/ListStyleTypeProperty.java
index efad554..25d5820 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/ListStyleTypeProperty.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/ListStyleTypeProperty.java
@@ -17,51 +17,41 @@
*/
public class ListStyleTypeProperty extends AbstractProperty {
- public ListStyleTypeProperty() {
- super(CSS.LIST_STYLE_TYPE);
- }
+ public ListStyleTypeProperty() {
+ super(CSS.LIST_STYLE_TYPE);
+ }
- public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles) {
- if (isListStyleType(lu)) {
- return lu.getStringValue();
- } else {
- if (parentStyles == null) {
- return CSS.DISC;
- } else {
- return parentStyles.getListStyleType();
- }
- }
-
- }
+ public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles) {
+ if (isListStyleType(lu)) {
+ return lu.getStringValue();
+ } else {
+ if (parentStyles == null) {
+ return CSS.DISC;
+ } else {
+ return parentStyles.getListStyleType();
+ }
+ }
- private static boolean isListStyleType(LexicalUnit lu) {
-
- if (lu == null || lu.getLexicalUnitType() != LexicalUnit.SAC_IDENT) {
- return false;
- }
-
- String s = lu.getStringValue();
- return s.equals(CSS.ARMENIAN)
- || s.equals(CSS.CIRCLE)
- || s.equals(CSS.CJK_IDEOGRAPHIC)
- || s.equals(CSS.DECIMAL)
- || s.equals(CSS.DECIMAL_LEADING_ZERO)
- || s.equals(CSS.DISC)
- || s.equals(CSS.GEORGIAN)
- || s.equals(CSS.HEBREW)
- || s.equals(CSS.HIRAGANA)
- || s.equals(CSS.HIRAGANA_IROHA)
- || s.equals(CSS.KATAKANA)
- || s.equals(CSS.KATAKANA_IROHA)
- || s.equals(CSS.LOWER_ALPHA)
- || s.equals(CSS.LOWER_GREEK)
- || s.equals(CSS.LOWER_LATIN)
- || s.equals(CSS.LOWER_ROMAN)
- || s.equals(CSS.NONE)
- || s.equals(CSS.SQUARE)
- || s.equals(CSS.UPPER_ALPHA)
- || s.equals(CSS.UPPER_LATIN)
- || s.equals(CSS.UPPER_ROMAN);
- }
+ }
+
+ private static boolean isListStyleType(LexicalUnit lu) {
+
+ if (lu == null || lu.getLexicalUnitType() != LexicalUnit.SAC_IDENT) {
+ return false;
+ }
+
+ String s = lu.getStringValue();
+ return s.equals(CSS.ARMENIAN) || s.equals(CSS.CIRCLE)
+ || s.equals(CSS.CJK_IDEOGRAPHIC) || s.equals(CSS.DECIMAL)
+ || s.equals(CSS.DECIMAL_LEADING_ZERO) || s.equals(CSS.DISC)
+ || s.equals(CSS.GEORGIAN) || s.equals(CSS.HEBREW)
+ || s.equals(CSS.HIRAGANA) || s.equals(CSS.HIRAGANA_IROHA)
+ || s.equals(CSS.KATAKANA) || s.equals(CSS.KATAKANA_IROHA)
+ || s.equals(CSS.LOWER_ALPHA) || s.equals(CSS.LOWER_GREEK)
+ || s.equals(CSS.LOWER_LATIN) || s.equals(CSS.LOWER_ROMAN)
+ || s.equals(CSS.NONE) || s.equals(CSS.SQUARE)
+ || s.equals(CSS.UPPER_ALPHA) || s.equals(CSS.UPPER_LATIN)
+ || s.equals(CSS.UPPER_ROMAN);
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/PropertyDecl.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/PropertyDecl.java
index 76d21a3..1fceea2 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/PropertyDecl.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/PropertyDecl.java
@@ -19,103 +19,99 @@
*/
public class PropertyDecl implements Comparable, Serializable {
- private static final long serialVersionUID = 1L;
-
- public static final byte SOURCE_DEFAULT = 0;
- public static final byte SOURCE_AUTHOR = 1;
- public static final byte SOURCE_USER = 2;
+ private static final long serialVersionUID = 1L;
- private Rule rule;
- private String property;
- private LexicalUnit value;
- private boolean important;
+ public static final byte SOURCE_DEFAULT = 0;
+ public static final byte SOURCE_AUTHOR = 1;
+ public static final byte SOURCE_USER = 2;
- /**
- * Class constructor.
- */
- public PropertyDecl(Rule rule,
- String property,
- LexicalUnit value,
+ private Rule rule;
+ private String property;
+ private LexicalUnit value;
+ private boolean important;
+
+ /**
+ * Class constructor.
+ */
+ public PropertyDecl(Rule rule, String property, LexicalUnit value,
boolean important) {
- this.rule = rule;
- this.property = property;
- this.value = value;
- this.important = important;
- }
-
- /**
- * Implementation of <code>Comparable.compareTo(Object)</code>
- * that implements CSS cascade ordering.
- */
- public int compareTo(Object o) {
- PropertyDecl other = (PropertyDecl) o;
- int thisWeight = this.getWeight();
- int otherWeight = other.getWeight();
- if (thisWeight != otherWeight) {
- return thisWeight - otherWeight;
+ this.rule = rule;
+ this.property = property;
+ this.value = value;
+ this.important = important;
}
- int thisSpec = this.getRule().getSpecificity();
- int otherSpec = other.getRule().getSpecificity();
+ /**
+ * Implementation of <code>Comparable.compareTo(Object)</code> that
+ * implements CSS cascade ordering.
+ */
+ public int compareTo(Object o) {
+ PropertyDecl other = (PropertyDecl) o;
+ int thisWeight = this.getWeight();
+ int otherWeight = other.getWeight();
+ if (thisWeight != otherWeight) {
+ return thisWeight - otherWeight;
+ }
- return thisSpec - otherSpec;
- }
+ int thisSpec = this.getRule().getSpecificity();
+ int otherSpec = other.getRule().getSpecificity();
- /**
- * Return the value of the <code>important</code> property.
- */
- public boolean isImportant() {
- return this.important;
- }
+ return thisSpec - otherSpec;
+ }
- /**
- * Return the value of the <code>property</code> property.
- */
- public String getProperty() {
- return this.property;
- }
+ /**
+ * Return the value of the <code>important</code> property.
+ */
+ public boolean isImportant() {
+ return this.important;
+ }
- /**
- * Return the value of the <code>rule</code> property.
- */
- public Rule getRule() {
- return this.rule;
- }
+ /**
+ * Return the value of the <code>property</code> property.
+ */
+ public String getProperty() {
+ return this.property;
+ }
- /**
- * Return the value of the <code>value</code> property.
- */
- public LexicalUnit getValue() {
- return this.value;
- }
+ /**
+ * Return the value of the <code>rule</code> property.
+ */
+ public Rule getRule() {
+ return this.rule;
+ }
+ /**
+ * Return the value of the <code>value</code> property.
+ */
+ public LexicalUnit getValue() {
+ return this.value;
+ }
- //===================================================== PRIVATE
+ // ===================================================== PRIVATE
- /**
- * Returns the weight of this declaration, as follows...
- *
- * <pre>
- * 4 => user stylesheet, important decl
- * 3 => author stylesheet, important decl
- * 2 => author stylesheet, not important
- * 1 => user stylesheet, not important
- * 0 => default stylesheet
- * </pre>
- */
- private int getWeight() {
- int source = this.getRule().getSource();
- if (this.isImportant() && source == StyleSheet.SOURCE_USER) {
- return 4;
- } else if (this.isImportant() && source == StyleSheet.SOURCE_AUTHOR) {
- return 3;
- } else if (!this.isImportant() && source == StyleSheet.SOURCE_AUTHOR) {
- return 2;
- } else if (!this.isImportant() && source == StyleSheet.SOURCE_USER) {
- return 1;
- } else {
- return 0;
- }
- }
+ /**
+ * Returns the weight of this declaration, as follows...
+ *
+ * <pre>
+ * 4 => user stylesheet, important decl
+ * 3 => author stylesheet, important decl
+ * 2 => author stylesheet, not important
+ * 1 => user stylesheet, not important
+ * 0 => default stylesheet
+ * </pre>
+ */
+ private int getWeight() {
+ int source = this.getRule().getSource();
+ if (this.isImportant() && source == StyleSheet.SOURCE_USER) {
+ return 4;
+ } else if (this.isImportant() && source == StyleSheet.SOURCE_AUTHOR) {
+ return 3;
+ } else if (!this.isImportant() && source == StyleSheet.SOURCE_AUTHOR) {
+ return 2;
+ } else if (!this.isImportant() && source == StyleSheet.SOURCE_USER) {
+ return 1;
+ } else {
+ return 0;
+ }
+ }
}
-
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/PseudoElement.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/PseudoElement.java
index bb8fbda..595b4a6 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/PseudoElement.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/PseudoElement.java
@@ -16,36 +16,39 @@
* Represents a :before or :after pseudo-element.
*/
public class PseudoElement extends Element {
-
- public static final String AFTER = "after";
- public static final String BEFORE = "before";
- /**
- * Class constructor.
- * @param parent Parent element to this pseudo-element.
- * @param name Name of this pseudo-element, e.g. PseudoElement.BEFORE.
- */
- public PseudoElement(Element parent, String name) {
- super(name);
- this.setParent(parent);
- }
-
- /**
- * @see java.lang.Object#equals(java.lang.Object)
- */
- public boolean equals(Object o) {
- if (o == null || o.getClass() != this.getClass()) {
- return false;
- }
- PseudoElement other = (PseudoElement) o;
- return this.getParent() == other.getParent()
- && this.getName().equals(other.getName());
- }
-
- /**
- * @see java.lang.Object#hashCode()
- */
- public int hashCode() {
- return this.getParent().hashCode() + this.getName().hashCode();
- }
+ public static final String AFTER = "after";
+ public static final String BEFORE = "before";
+
+ /**
+ * Class constructor.
+ *
+ * @param parent
+ * Parent element to this pseudo-element.
+ * @param name
+ * Name of this pseudo-element, e.g. PseudoElement.BEFORE.
+ */
+ public PseudoElement(Element parent, String name) {
+ super(name);
+ this.setParent(parent);
+ }
+
+ /**
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object o) {
+ if (o == null || o.getClass() != this.getClass()) {
+ return false;
+ }
+ PseudoElement other = (PseudoElement) o;
+ return this.getParent() == other.getParent()
+ && this.getName().equals(other.getName());
+ }
+
+ /**
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode() {
+ return this.getParent().hashCode() + this.getName().hashCode();
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/RelativeLength.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/RelativeLength.java
index 86eed18..0f96510 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/RelativeLength.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/RelativeLength.java
@@ -16,57 +16,61 @@
* A length that may be expressed as an absolute or relative value.
*/
public class RelativeLength implements Serializable {
-
- private static final long serialVersionUID = 1L;
- private float percentage;
- private int absolute;
- boolean isAbsolute;
-
- private static RelativeLength ZERO = new RelativeLength(0, 0, true);
-
- /**
- * Create a relative length representing an absolute value.
- * @return the new RelativeLength value.
- */
- public static RelativeLength createAbsolute(int value) {
- if (value == 0) {
- return ZERO;
- } else {
- return new RelativeLength(0, value, true);
- }
- }
+ private static final long serialVersionUID = 1L;
- /**
- * Create a relative length representing a relative value.
- * @return the new RelativeLength value.
- */
- public static RelativeLength createRelative(float percentage) {
- return new RelativeLength(percentage, 0, false);
- }
+ private float percentage;
+ private int absolute;
+ boolean isAbsolute;
- /**
- * Return the value of the length given a reference value. If this
- * object represents an absolute value, that value is simply returned.
- * Otherwise, returns the given reference length multiplied by the given
- * percentage and rounded to the nearest integer.
- * @param referenceLength reference length by which percentage lengths
- * will by multiplied.
- * @return the actual value
- */
- public int get(int referenceLength) {
- if (this.isAbsolute) {
- return this.absolute;
- } else {
- return Math.round(this.percentage * referenceLength);
- }
- }
-
- //==================================================== PRIVATE
-
- private RelativeLength(float percentage, int absolute, boolean isAbsolute) {
- this.percentage = percentage;
- this.absolute = absolute;
- this.isAbsolute = isAbsolute;
- }
+ private static RelativeLength ZERO = new RelativeLength(0, 0, true);
+
+ /**
+ * Create a relative length representing an absolute value.
+ *
+ * @return the new RelativeLength value.
+ */
+ public static RelativeLength createAbsolute(int value) {
+ if (value == 0) {
+ return ZERO;
+ } else {
+ return new RelativeLength(0, value, true);
+ }
+ }
+
+ /**
+ * Create a relative length representing a relative value.
+ *
+ * @return the new RelativeLength value.
+ */
+ public static RelativeLength createRelative(float percentage) {
+ return new RelativeLength(percentage, 0, false);
+ }
+
+ /**
+ * Return the value of the length given a reference value. If this object
+ * represents an absolute value, that value is simply returned. Otherwise,
+ * returns the given reference length multiplied by the given percentage and
+ * rounded to the nearest integer.
+ *
+ * @param referenceLength
+ * reference length by which percentage lengths will by
+ * multiplied.
+ * @return the actual value
+ */
+ public int get(int referenceLength) {
+ if (this.isAbsolute) {
+ return this.absolute;
+ } else {
+ return Math.round(this.percentage * referenceLength);
+ }
+ }
+
+ // ==================================================== PRIVATE
+
+ private RelativeLength(float percentage, int absolute, boolean isAbsolute) {
+ this.percentage = percentage;
+ this.absolute = absolute;
+ this.isAbsolute = isAbsolute;
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/Rule.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/Rule.java
index bc4e1e4..b4705e4 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/Rule.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/Rule.java
@@ -18,7 +18,6 @@
import java.util.List;
import java.util.StringTokenizer;
-
import org.eclipse.wst.xml.vex.core.internal.dom.Element;
import org.w3c.css.sac.AttributeCondition;
import org.w3c.css.sac.CombinatorCondition;
@@ -31,312 +30,321 @@
import org.w3c.css.sac.SiblingSelector;
/**
- * Represents a pairing of a selector with a list of styles. This does
- * not exactly correspond to a rule in a style sheet; there is only
- * one selector associated with an instance of this class, whereas
- * multiple selectors may be associated with a style sheet rule.
- *
- * Note: <code>Rule</code> implements the <code>Comparable</code>
- * interface in order to be sorted by "specificity" as defined by the
- * CSS spec. However, this ordering is <em>not</em> consistent with
- * <code>equals</code> (rules with the same specificity may not be
- * equal). Therefore, <code>Rule</code> objects should not be used
- * with sorted collections or maps in the <code>java.util</code>
- * package, unless a suitable <code>Comparator</code> is also used.
+ * Represents a pairing of a selector with a list of styles. This does not
+ * exactly correspond to a rule in a style sheet; there is only one selector
+ * associated with an instance of this class, whereas multiple selectors may be
+ * associated with a style sheet rule.
+ *
+ * Note: <code>Rule</code> implements the <code>Comparable</code> interface in
+ * order to be sorted by "specificity" as defined by the CSS spec. However, this
+ * ordering is <em>not</em> consistent with <code>equals</code> (rules with the
+ * same specificity may not be equal). Therefore, <code>Rule</code> objects
+ * should not be used with sorted collections or maps in the
+ * <code>java.util</code> package, unless a suitable <code>Comparator</code> is
+ * also used.
*/
public class Rule implements Serializable {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
- private byte source;
- private Selector selector;
- private List propertyDecls = new ArrayList();
+ private byte source;
+ private Selector selector;
+ private List propertyDecls = new ArrayList();
- /**
- * Class constructor.
- *
- * @param source Source of the rule.
- * @param selector Selector for the rule.
- */
- public Rule(byte source, Selector selector) {
- this.source = source;
- this.selector = selector;
- }
-
- /**
- * Adds a property declaration to the rule.
- *
- * @param decl new property declaration to add
- */
- public void add(PropertyDecl decl) {
- propertyDecls.add(decl);
- }
-
- /**
- * Returns the selector for the rule.
- */
- public Selector getSelector() {
- return this.selector;
- }
-
- /**
- * Returns the source of this rule.
- * @return one of StyleSheet.SOURCE_DEFAULT, StyleSheet.SOURCE_AUTHOR, or
- * StyleSheet.SOURCE_USER.
- */
- public byte getSource() {
- return this.source;
- }
-
- /**
- * Returns an array of the property declarations in this rule.
- */
- public PropertyDecl[] getPropertyDecls() {
- return (PropertyDecl[])
- this.propertyDecls.toArray(new PropertyDecl[propertyDecls.size()]);
- }
-
- /**
- * Calculates the specificity for the selector associated with
- * this rule. The specificity is represented as an integer whose
- * base-10 representation, xxxyyyzzz, can be decomposed into the
- * number of "id" selectors (xxx), "class" selectors (yyy), and
- * "element" selectors (zzz). Composite selectors result in a
- * recursive call.
- */
- public int getSpecificity() {
- return specificity(this.getSelector());
- }
-
- /**
- * Returns true if the given element matches this rule's selector.
- *
- * @param element Element to check.
- */
- public boolean matches(Element element) {
- return matches(this.selector, element);
- }
-
- //==================================================== PRIVATE
-
- /**
- * Returns true if the given element matches the given selector.
- */
- private static boolean matches(Selector selector, Element element) {
-
- if (element == null) {
- // This can happen when, e.g., with the rule "foo > *".
- // Since the root element matches the "*", we check if
- // its parent matches "foo", but of course its parent
- // is null
- return false;
- }
-
- String elementName = element.getName();
- int selectorType = selector.getSelectorType();
-
- switch (selectorType) {
-
- case Selector.SAC_ANY_NODE_SELECTOR:
- // You'd think we land here if we have a * rule, but instead
- // it appears we get a SAC_ELEMENT_NODE_SELECTOR with localName==null
- return true;
-
- case Selector.SAC_CONDITIONAL_SELECTOR:
- // This little wart is the product of a mismatch btn the CSS
- // spec an the Flute parser. CSS treats pseudo-elements as elements
- // attached to their parents, while Flute treats them like attributes
- ConditionalSelector cs = (ConditionalSelector) selector;
- if (cs.getCondition().getConditionType() == Condition.SAC_PSEUDO_CLASS_CONDITION) {
- if (element instanceof PseudoElement) {
- AttributeCondition ac = (AttributeCondition) cs.getCondition();
- return ac.getValue().equals(element.getName())
- && matches(cs.getSimpleSelector(), element.getParent());
- } else {
- return false;
- }
- } else {
- return matches(cs.getSimpleSelector(), element) &&
- matchesCondition(cs.getCondition(), element);
- }
-
- case Selector.SAC_ELEMENT_NODE_SELECTOR:
- String selectorName = ((ElementSelector)selector).getLocalName();
- if (selectorName == null) {
- // We land here if we have a wildcard selector (*) or
- // a pseudocondition w/o an element name (:before)
- // Probably other situations too (conditional w/o element
- // name? e.g. [attr=value])
- return true;
- }
- if (selectorName.equals(elementName)) {
- return true;
- }
- break;
-
- case Selector.SAC_DESCENDANT_SELECTOR:
- DescendantSelector ds = (DescendantSelector) selector;
- return matches(ds.getSimpleSelector(), element) &&
- matchesAncestor(ds.getAncestorSelector(), element.getParent());
-
- case Selector.SAC_CHILD_SELECTOR:
- DescendantSelector ds2 = (DescendantSelector) selector;
- Element parent = element.getParent();
- if (element instanceof PseudoElement) {
- parent = parent.getParent(); // sigh - this looks inelegant, but whatcha gonna do?
- }
- return matches(ds2.getSimpleSelector(), element) &&
- matches(ds2.getAncestorSelector(), parent);
-
- case Selector.SAC_DIRECT_ADJACENT_SELECTOR:
-
- SiblingSelector ss = (SiblingSelector) selector;
-
- if (element != null && element.getParent() != null
- && matches(ss.getSiblingSelector(), element) ) {
-
- // find next sibling
-
- final Iterator i = element.getParent().getChildIterator();
- Element e = null;
- Element f = null;
-
- while (i.hasNext() && e != element) {
- f = e;
- e = (Element)i.next();
- }
-
- if (e == element) {
- return matches(ss.getSelector(), f);
- }
- }
- return false;
-
- default:
- //System.out.println("DEBUG: selector type not supported");
- // TODO: warning: selector not supported
- }
- return false;
- }
-
- /**
- * Returns true if some ancestor of the given element matches the given
- * selector.
- */
- private static boolean matchesAncestor(Selector selector, Element element) {
- Element e = element;
- while (e != null) {
- if (matches(selector, e)) {
- return true;
- }
- e = e.getParent();
- }
- return false;
- }
-
- private static boolean matchesCondition(Condition condition, Element element) {
-
- AttributeCondition acon;
- String attributeName;
- String value;
-
- switch (condition.getConditionType()) {
- case Condition.SAC_PSEUDO_CLASS_CONDITION:
- return false;
-
- case Condition.SAC_ATTRIBUTE_CONDITION:
- acon = (AttributeCondition)condition;
- value = element.getAttribute(acon.getLocalName());
- if (acon.getValue() != null) {
- return acon.getValue().equals(value);
- } else {
- return value != null;
- }
-
- case Condition.SAC_ONE_OF_ATTRIBUTE_CONDITION:
- case Condition.SAC_CLASS_CONDITION:
-
- acon = (AttributeCondition)condition;
-
- if (condition.getConditionType() == Condition.SAC_CLASS_CONDITION) {
- attributeName = "class";
- } else {
- attributeName = acon.getLocalName();
- }
-
- value = element.getAttribute(attributeName);
- if (value == null) {
- return false;
- }
- StringTokenizer st = new StringTokenizer(value);
- while (st.hasMoreTokens()) {
- if (st.nextToken().equals(acon.getValue())) {
- return true;
- }
- }
- return false;
-
-
- case Condition.SAC_AND_CONDITION:
- CombinatorCondition ccon = (CombinatorCondition)condition;
- return matchesCondition(ccon.getFirstCondition(), element)
- && matchesCondition(ccon.getSecondCondition(), element);
-
- default:
- // TODO: warning: condition not supported
- System.out.println("Unsupported condition type: " + condition.getConditionType());
- }
- return false;
- }
-
- /**
- * Calculates the specificity for a selector.
- */
- private static int specificity(Selector sel) {
- if (sel instanceof ElementSelector) {
- if (((ElementSelector)sel).getLocalName() == null) {
- // actually wildcard selector -- see comment in matches()
- return 0;
- } else {
- return 1;
- }
- } else if (sel instanceof DescendantSelector) {
- DescendantSelector ds = (DescendantSelector) sel;
- return specificity(ds.getAncestorSelector()) +
- specificity(ds.getSimpleSelector());
- } else if (sel instanceof SiblingSelector) {
- SiblingSelector ss = (SiblingSelector) sel;
- return specificity(ss.getSelector()) +
- specificity(ss.getSiblingSelector());
- } else if (sel instanceof NegativeSelector) {
- NegativeSelector ns = (NegativeSelector) sel;
- return specificity(ns.getSimpleSelector());
- } else if (sel instanceof ConditionalSelector) {
- ConditionalSelector cs = (ConditionalSelector) sel;
- return specificity(cs.getCondition()) +
- specificity(cs.getSimpleSelector());
- } else {
- return 0;
+ /**
+ * Class constructor.
+ *
+ * @param source
+ * Source of the rule.
+ * @param selector
+ * Selector for the rule.
+ */
+ public Rule(byte source, Selector selector) {
+ this.source = source;
+ this.selector = selector;
}
- }
- /**
- * Calculates the specificity for a condition.
- */
- private static int specificity(Condition cond) {
- if (cond instanceof CombinatorCondition) {
- CombinatorCondition cc = (CombinatorCondition) cond;
- return specificity(cc.getFirstCondition()) +
- specificity(cc.getSecondCondition());
- } else if (cond instanceof AttributeCondition) {
- if (cond.getConditionType() == Condition.SAC_ID_CONDITION) {
- return 1000000;
- } else {
- return 1000;
- }
- } else {
- return 0;
+ /**
+ * Adds a property declaration to the rule.
+ *
+ * @param decl
+ * new property declaration to add
+ */
+ public void add(PropertyDecl decl) {
+ propertyDecls.add(decl);
}
- }
+
+ /**
+ * Returns the selector for the rule.
+ */
+ public Selector getSelector() {
+ return this.selector;
+ }
+
+ /**
+ * Returns the source of this rule.
+ *
+ * @return one of StyleSheet.SOURCE_DEFAULT, StyleSheet.SOURCE_AUTHOR, or
+ * StyleSheet.SOURCE_USER.
+ */
+ public byte getSource() {
+ return this.source;
+ }
+
+ /**
+ * Returns an array of the property declarations in this rule.
+ */
+ public PropertyDecl[] getPropertyDecls() {
+ return (PropertyDecl[]) this.propertyDecls
+ .toArray(new PropertyDecl[propertyDecls.size()]);
+ }
+
+ /**
+ * Calculates the specificity for the selector associated with this rule.
+ * The specificity is represented as an integer whose base-10
+ * representation, xxxyyyzzz, can be decomposed into the number of "id"
+ * selectors (xxx), "class" selectors (yyy), and "element" selectors (zzz).
+ * Composite selectors result in a recursive call.
+ */
+ public int getSpecificity() {
+ return specificity(this.getSelector());
+ }
+
+ /**
+ * Returns true if the given element matches this rule's selector.
+ *
+ * @param element
+ * Element to check.
+ */
+ public boolean matches(Element element) {
+ return matches(this.selector, element);
+ }
+
+ // ==================================================== PRIVATE
+
+ /**
+ * Returns true if the given element matches the given selector.
+ */
+ private static boolean matches(Selector selector, Element element) {
+
+ if (element == null) {
+ // This can happen when, e.g., with the rule "foo > *".
+ // Since the root element matches the "*", we check if
+ // its parent matches "foo", but of course its parent
+ // is null
+ return false;
+ }
+
+ String elementName = element.getName();
+ int selectorType = selector.getSelectorType();
+
+ switch (selectorType) {
+
+ case Selector.SAC_ANY_NODE_SELECTOR:
+ // You'd think we land here if we have a * rule, but instead
+ // it appears we get a SAC_ELEMENT_NODE_SELECTOR with
+ // localName==null
+ return true;
+
+ case Selector.SAC_CONDITIONAL_SELECTOR:
+ // This little wart is the product of a mismatch btn the CSS
+ // spec an the Flute parser. CSS treats pseudo-elements as elements
+ // attached to their parents, while Flute treats them like
+ // attributes
+ ConditionalSelector cs = (ConditionalSelector) selector;
+ if (cs.getCondition().getConditionType() == Condition.SAC_PSEUDO_CLASS_CONDITION) {
+ if (element instanceof PseudoElement) {
+ AttributeCondition ac = (AttributeCondition) cs
+ .getCondition();
+ return ac.getValue().equals(element.getName())
+ && matches(cs.getSimpleSelector(), element
+ .getParent());
+ } else {
+ return false;
+ }
+ } else {
+ return matches(cs.getSimpleSelector(), element)
+ && matchesCondition(cs.getCondition(), element);
+ }
+
+ case Selector.SAC_ELEMENT_NODE_SELECTOR:
+ String selectorName = ((ElementSelector) selector).getLocalName();
+ if (selectorName == null) {
+ // We land here if we have a wildcard selector (*) or
+ // a pseudocondition w/o an element name (:before)
+ // Probably other situations too (conditional w/o element
+ // name? e.g. [attr=value])
+ return true;
+ }
+ if (selectorName.equals(elementName)) {
+ return true;
+ }
+ break;
+
+ case Selector.SAC_DESCENDANT_SELECTOR:
+ DescendantSelector ds = (DescendantSelector) selector;
+ return matches(ds.getSimpleSelector(), element)
+ && matchesAncestor(ds.getAncestorSelector(), element
+ .getParent());
+
+ case Selector.SAC_CHILD_SELECTOR:
+ DescendantSelector ds2 = (DescendantSelector) selector;
+ Element parent = element.getParent();
+ if (element instanceof PseudoElement) {
+ parent = parent.getParent(); // sigh - this looks inelegant, but
+ // whatcha gonna do?
+ }
+ return matches(ds2.getSimpleSelector(), element)
+ && matches(ds2.getAncestorSelector(), parent);
+
+ case Selector.SAC_DIRECT_ADJACENT_SELECTOR:
+
+ SiblingSelector ss = (SiblingSelector) selector;
+
+ if (element != null && element.getParent() != null
+ && matches(ss.getSiblingSelector(), element)) {
+
+ // find next sibling
+
+ final Iterator i = element.getParent().getChildIterator();
+ Element e = null;
+ Element f = null;
+
+ while (i.hasNext() && e != element) {
+ f = e;
+ e = (Element) i.next();
+ }
+
+ if (e == element) {
+ return matches(ss.getSelector(), f);
+ }
+ }
+ return false;
+
+ default:
+ // System.out.println("DEBUG: selector type not supported");
+ // TODO: warning: selector not supported
+ }
+ return false;
+ }
+
+ /**
+ * Returns true if some ancestor of the given element matches the given
+ * selector.
+ */
+ private static boolean matchesAncestor(Selector selector, Element element) {
+ Element e = element;
+ while (e != null) {
+ if (matches(selector, e)) {
+ return true;
+ }
+ e = e.getParent();
+ }
+ return false;
+ }
+
+ private static boolean matchesCondition(Condition condition, Element element) {
+
+ AttributeCondition acon;
+ String attributeName;
+ String value;
+
+ switch (condition.getConditionType()) {
+ case Condition.SAC_PSEUDO_CLASS_CONDITION:
+ return false;
+
+ case Condition.SAC_ATTRIBUTE_CONDITION:
+ acon = (AttributeCondition) condition;
+ value = element.getAttribute(acon.getLocalName());
+ if (acon.getValue() != null) {
+ return acon.getValue().equals(value);
+ } else {
+ return value != null;
+ }
+
+ case Condition.SAC_ONE_OF_ATTRIBUTE_CONDITION:
+ case Condition.SAC_CLASS_CONDITION:
+
+ acon = (AttributeCondition) condition;
+
+ if (condition.getConditionType() == Condition.SAC_CLASS_CONDITION) {
+ attributeName = "class";
+ } else {
+ attributeName = acon.getLocalName();
+ }
+
+ value = element.getAttribute(attributeName);
+ if (value == null) {
+ return false;
+ }
+ StringTokenizer st = new StringTokenizer(value);
+ while (st.hasMoreTokens()) {
+ if (st.nextToken().equals(acon.getValue())) {
+ return true;
+ }
+ }
+ return false;
+
+ case Condition.SAC_AND_CONDITION:
+ CombinatorCondition ccon = (CombinatorCondition) condition;
+ return matchesCondition(ccon.getFirstCondition(), element)
+ && matchesCondition(ccon.getSecondCondition(), element);
+
+ default:
+ // TODO: warning: condition not supported
+ System.out.println("Unsupported condition type: "
+ + condition.getConditionType());
+ }
+ return false;
+ }
+
+ /**
+ * Calculates the specificity for a selector.
+ */
+ private static int specificity(Selector sel) {
+ if (sel instanceof ElementSelector) {
+ if (((ElementSelector) sel).getLocalName() == null) {
+ // actually wildcard selector -- see comment in matches()
+ return 0;
+ } else {
+ return 1;
+ }
+ } else if (sel instanceof DescendantSelector) {
+ DescendantSelector ds = (DescendantSelector) sel;
+ return specificity(ds.getAncestorSelector())
+ + specificity(ds.getSimpleSelector());
+ } else if (sel instanceof SiblingSelector) {
+ SiblingSelector ss = (SiblingSelector) sel;
+ return specificity(ss.getSelector())
+ + specificity(ss.getSiblingSelector());
+ } else if (sel instanceof NegativeSelector) {
+ NegativeSelector ns = (NegativeSelector) sel;
+ return specificity(ns.getSimpleSelector());
+ } else if (sel instanceof ConditionalSelector) {
+ ConditionalSelector cs = (ConditionalSelector) sel;
+ return specificity(cs.getCondition())
+ + specificity(cs.getSimpleSelector());
+ } else {
+ return 0;
+ }
+ }
+
+ /**
+ * Calculates the specificity for a condition.
+ */
+ private static int specificity(Condition cond) {
+ if (cond instanceof CombinatorCondition) {
+ CombinatorCondition cc = (CombinatorCondition) cond;
+ return specificity(cc.getFirstCondition())
+ + specificity(cc.getSecondCondition());
+ } else if (cond instanceof AttributeCondition) {
+ if (cond.getConditionType() == Condition.SAC_ID_CONDITION) {
+ return 1000000;
+ } else {
+ return 1000;
+ }
+ } else {
+ return 0;
+ }
+ }
}
-
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/SacFactory.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/SacFactory.java
index 9ef27b4..16c529b 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/SacFactory.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/SacFactory.java
@@ -33,416 +33,472 @@
import org.w3c.css.sac.SimpleSelector;
/**
- * Factory for producing serializable Conditions, LexicalUnits, and
- * Selectors. The SAC parser creates instances of these that may not be
- * serializable (and in fact, those from Flute aren't). To serialize
- * StyleSheets, which contain references to these SAC objects, we must
- * clone the objects into our own serializable ones.
+ * Factory for producing serializable Conditions, LexicalUnits, and Selectors.
+ * The SAC parser creates instances of these that may not be serializable (and
+ * in fact, those from Flute aren't). To serialize StyleSheets, which contain
+ * references to these SAC objects, we must clone the objects into our own
+ * serializable ones.
*/
public class SacFactory {
- /**
- * Clone the given condition, returning one that is serializable.
- * @param condition Condition to clone.
- */
- public Condition cloneCondition(Condition condition) {
- Condition clone = null;
- if (condition == null) {
- return null;
- } else if (condition instanceof AttributeCondition) {
- clone = new AttributeConditionImpl((AttributeCondition) condition);
- } else if (condition instanceof CombinatorCondition) {
- clone = new CombinatorConditionImpl((CombinatorCondition) condition, this);
- } else if (condition instanceof ContentCondition) {
- clone = new ContentConditionImpl((ContentCondition) condition);
- } else if (condition instanceof LangCondition) {
- clone = new LangConditionImpl((LangCondition) condition);
- } else if (condition instanceof NegativeCondition) {
- clone = new NegativeConditionImpl((NegativeCondition) condition, this);
- } else if (condition instanceof PositionalCondition) {
- clone = new PositionalConditionImpl((PositionalCondition) condition);
- } else {
- throw new IllegalArgumentException("Unsupported condition type: " + condition.getClass());
- }
- return clone;
- }
+ /**
+ * Clone the given condition, returning one that is serializable.
+ *
+ * @param condition
+ * Condition to clone.
+ */
+ public Condition cloneCondition(Condition condition) {
+ Condition clone = null;
+ if (condition == null) {
+ return null;
+ } else if (condition instanceof AttributeCondition) {
+ clone = new AttributeConditionImpl((AttributeCondition) condition);
+ } else if (condition instanceof CombinatorCondition) {
+ clone = new CombinatorConditionImpl(
+ (CombinatorCondition) condition, this);
+ } else if (condition instanceof ContentCondition) {
+ clone = new ContentConditionImpl((ContentCondition) condition);
+ } else if (condition instanceof LangCondition) {
+ clone = new LangConditionImpl((LangCondition) condition);
+ } else if (condition instanceof NegativeCondition) {
+ clone = new NegativeConditionImpl((NegativeCondition) condition,
+ this);
+ } else if (condition instanceof PositionalCondition) {
+ clone = new PositionalConditionImpl((PositionalCondition) condition);
+ } else {
+ throw new IllegalArgumentException("Unsupported condition type: "
+ + condition.getClass());
+ }
+ return clone;
+ }
- /**
- * Clone the given lexical unit, returning one that is serializable.
- * @param lu LexicalUnit to clone.
- */
- public LexicalUnit cloneLexicalUnit(LexicalUnit lu) {
- if (lu == null) {
- return null;
- } else if (this.cache.containsKey(lu)) {
- return (LexicalUnit) this.cache.get(lu);
- } else {
- return new LexicalUnitImpl(lu, this);
- }
- }
-
- /**
- * Clone the given selector, returning one that is serializable.
- */
- public Selector cloneSelector(Selector selector) {
- Selector clone = null;
- if (selector == null) {
- return null;
- } else if (selector instanceof CharacterDataSelector) {
- clone = new CharacterDataSelectorImpl((CharacterDataSelector) selector);
- } else if (selector instanceof ConditionalSelector) {
- clone = new ConditionalSelectorImpl((ConditionalSelector) selector, this);
- } else if (selector instanceof DescendantSelector) {
- clone = new DescendantSelectorImpl((DescendantSelector) selector, this);
- } else if (selector instanceof ElementSelector) {
- clone = new ElementSelectorImpl((ElementSelector) selector);
- } else if (selector instanceof NegativeSelector) {
- clone = new NegativeSelectorImpl((NegativeSelector) selector, this);
- } else if (selector instanceof ProcessingInstructionSelector) {
- clone = new ProcessingInstructionSelectorImpl((ProcessingInstructionSelector) selector);
- } else if (selector instanceof SiblingSelector) {
- clone = new SiblingSelectorImpl((SiblingSelector) selector, this);
- } else {
- throw new IllegalArgumentException("Unsupported selector type: " + selector.getClass());
- }
- return clone;
- }
+ /**
+ * Clone the given lexical unit, returning one that is serializable.
+ *
+ * @param lu
+ * LexicalUnit to clone.
+ */
+ public LexicalUnit cloneLexicalUnit(LexicalUnit lu) {
+ if (lu == null) {
+ return null;
+ } else if (this.cache.containsKey(lu)) {
+ return (LexicalUnit) this.cache.get(lu);
+ } else {
+ return new LexicalUnitImpl(lu, this);
+ }
+ }
- //===================================================== PRIVATE
-
- private Map cache = new HashMap();
-
- private static class ConditionImpl implements Condition, Serializable {
- public ConditionImpl(Condition condition) {
- this.type = condition.getConditionType();
- }
- public short getConditionType() {
- return this.type;
- }
- private short type;
- }
-
- private static class AttributeConditionImpl extends ConditionImpl
- implements AttributeCondition {
- public AttributeConditionImpl(AttributeCondition condition) {
- super(condition);
- this.namespaceURI = condition.getNamespaceURI();
- this.localName = condition.getLocalName();
- this.specified = condition.getSpecified();
- this.value = condition.getValue();
- }
- public String getNamespaceURI() {
- return this.namespaceURI;
- }
- public String getLocalName() {
- return this.localName;
- }
- public boolean getSpecified() {
- return this.specified;
- }
- public String getValue() {
- return this.value;
- }
- private String namespaceURI;
- private String localName;
- private boolean specified;
- private String value;
- }
-
- private static class CombinatorConditionImpl extends ConditionImpl
- implements CombinatorCondition {
- public CombinatorConditionImpl(CombinatorCondition condition, SacFactory factory) {
- super(condition);
- this.firstCondition = factory.cloneCondition(condition.getFirstCondition());
- this.secondCondition = factory.cloneCondition(condition.getSecondCondition());
- }
- public Condition getFirstCondition() {
- return this.firstCondition;
- }
- public Condition getSecondCondition() {
- return this.secondCondition;
- }
- private Condition firstCondition;
- private Condition secondCondition;
- }
-
- private static class ContentConditionImpl extends ConditionImpl
- implements ContentCondition {
- public ContentConditionImpl(ContentCondition condition) {
- super(condition);
- this.data = condition.getData();
- }
- public String getData() {
- return this.data;
- }
- private String data;
- }
-
- private static class LangConditionImpl extends ConditionImpl
- implements LangCondition {
- public LangConditionImpl(LangCondition condition) {
- super(condition);
- this.lang = condition.getLang();
- }
- public String getLang() {
- return this.lang;
- }
- private String lang;
- }
-
- private static class NegativeConditionImpl extends ConditionImpl
- implements NegativeCondition {
- public NegativeConditionImpl(NegativeCondition condition, SacFactory factory) {
- super(condition);
- this.condition = factory.cloneCondition(condition.getCondition());
- }
- public Condition getCondition() {
- return this.condition;
- }
- private Condition condition;
- }
-
- private static class PositionalConditionImpl extends ConditionImpl
- implements PositionalCondition {
- public PositionalConditionImpl(PositionalCondition condition) {
- super(condition);
- this.position = condition.getPosition();
- this.typeNode = condition.getTypeNode();
- this.type = condition.getType();
- }
- public int getPosition() {
- return this.position;
- }
- public boolean getTypeNode() {
- return this.typeNode;
- }
- public boolean getType() {
- return this.type;
- }
- private int position;
- private boolean typeNode;
- private boolean type;
- }
-
-
- private static class LexicalUnitImpl implements LexicalUnit, Serializable {
+ /**
+ * Clone the given selector, returning one that is serializable.
+ */
+ public Selector cloneSelector(Selector selector) {
+ Selector clone = null;
+ if (selector == null) {
+ return null;
+ } else if (selector instanceof CharacterDataSelector) {
+ clone = new CharacterDataSelectorImpl(
+ (CharacterDataSelector) selector);
+ } else if (selector instanceof ConditionalSelector) {
+ clone = new ConditionalSelectorImpl((ConditionalSelector) selector,
+ this);
+ } else if (selector instanceof DescendantSelector) {
+ clone = new DescendantSelectorImpl((DescendantSelector) selector,
+ this);
+ } else if (selector instanceof ElementSelector) {
+ clone = new ElementSelectorImpl((ElementSelector) selector);
+ } else if (selector instanceof NegativeSelector) {
+ clone = new NegativeSelectorImpl((NegativeSelector) selector, this);
+ } else if (selector instanceof ProcessingInstructionSelector) {
+ clone = new ProcessingInstructionSelectorImpl(
+ (ProcessingInstructionSelector) selector);
+ } else if (selector instanceof SiblingSelector) {
+ clone = new SiblingSelectorImpl((SiblingSelector) selector, this);
+ } else {
+ throw new IllegalArgumentException("Unsupported selector type: "
+ + selector.getClass());
+ }
+ return clone;
+ }
- public LexicalUnitImpl(LexicalUnit lu, SacFactory factory) {
- factory.cache.put(lu, this);
- this.type = lu.getLexicalUnitType();
- this.s = lu.getStringValue();
- this.i = lu.getIntegerValue();
- this.f = lu.getFloatValue();
- this.functionName = lu.getFunctionName();
- this.next = factory.cloneLexicalUnit(lu.getNextLexicalUnit());
- this.prev = factory.cloneLexicalUnit(lu.getPreviousLexicalUnit());
- this.parameters = factory.cloneLexicalUnit(lu.getParameters());
- if (this.type == SAC_PERCENTAGE
- || this.type == SAC_EM
- || this.type == SAC_EX
- || this.type == SAC_PIXEL
- || this.type == SAC_CENTIMETER
- || this.type == SAC_MILLIMETER
- || this.type == SAC_INCH
- || this.type == SAC_POINT
- || this.type == SAC_PICA
- || this.type == SAC_DEGREE
- || this.type == SAC_RADIAN
- || this.type == SAC_GRADIAN
- || this.type == SAC_MILLISECOND
- || this.type == SAC_SECOND
- || this.type == SAC_HERTZ
- || this.type == SAC_KILOHERTZ
- || this.type == SAC_DIMENSION) {
- this.dimensionText = lu.getDimensionUnitText();
- }
- this.stringRepresentation = lu.toString();
- }
+ // ===================================================== PRIVATE
- public short getLexicalUnitType() {
- return this.type;
- }
+ private Map cache = new HashMap();
- public LexicalUnit getNextLexicalUnit() {
- return this.next;
- }
+ private static class ConditionImpl implements Condition, Serializable {
+ public ConditionImpl(Condition condition) {
+ this.type = condition.getConditionType();
+ }
- public LexicalUnit getPreviousLexicalUnit() {
- return this.prev;
- }
+ public short getConditionType() {
+ return this.type;
+ }
- public int getIntegerValue() {
- return this.i;
- }
+ private short type;
+ }
- public float getFloatValue() {
- return this.f;
- }
+ private static class AttributeConditionImpl extends ConditionImpl implements
+ AttributeCondition {
+ public AttributeConditionImpl(AttributeCondition condition) {
+ super(condition);
+ this.namespaceURI = condition.getNamespaceURI();
+ this.localName = condition.getLocalName();
+ this.specified = condition.getSpecified();
+ this.value = condition.getValue();
+ }
- public String getDimensionUnitText() {
- return this.dimensionText;
- }
+ public String getNamespaceURI() {
+ return this.namespaceURI;
+ }
- public String getFunctionName() {
- return this.functionName;
- }
+ public String getLocalName() {
+ return this.localName;
+ }
- public LexicalUnit getParameters() {
- return this.parameters;
- }
+ public boolean getSpecified() {
+ return this.specified;
+ }
- public String getStringValue() {
- return this.s;
- }
+ public String getValue() {
+ return this.value;
+ }
- public String getStringRepresentation() {
- return this.stringRepresentation;
- }
-
- public LexicalUnit getSubValues() {
- return this.parameters;
- }
+ private String namespaceURI;
+ private String localName;
+ private boolean specified;
+ private String value;
+ }
- //================================================= PRIVATE
-
- private LexicalUnitImpl() {
- }
+ private static class CombinatorConditionImpl extends ConditionImpl
+ implements CombinatorCondition {
+ public CombinatorConditionImpl(CombinatorCondition condition,
+ SacFactory factory) {
+ super(condition);
+ this.firstCondition = factory.cloneCondition(condition
+ .getFirstCondition());
+ this.secondCondition = factory.cloneCondition(condition
+ .getSecondCondition());
+ }
- private short type;
- private LexicalUnit next;
- private LexicalUnit prev;
- private LexicalUnit parameters;
- private String s;
- private int i;
- private float f;
- private String functionName;
- private String dimensionText;
- private String stringRepresentation;
- }
+ public Condition getFirstCondition() {
+ return this.firstCondition;
+ }
- private static class SelectorImpl implements Selector, Serializable {
- public SelectorImpl(Selector selector) {
- this.type = selector.getSelectorType();
- }
- public short getSelectorType() {
- return this.type;
- }
- private short type;
- }
-
- private static class CharacterDataSelectorImpl extends SelectorImpl
- implements CharacterDataSelector {
- public CharacterDataSelectorImpl(CharacterDataSelector selector) {
- super(selector);
- this.data = selector.getData();
- }
- public String getData() {
- return this.data;
- }
- private String data;
- }
-
- private static class ConditionalSelectorImpl extends SelectorImpl
- implements ConditionalSelector {
- public ConditionalSelectorImpl(ConditionalSelector selector, SacFactory factory) {
- super(selector);
- this.condition = factory.cloneCondition(selector.getCondition());
- this.simpleSelector =
- (SimpleSelector) factory.cloneSelector(selector.getSimpleSelector());
- }
- public SimpleSelector getSimpleSelector() {
- return this.simpleSelector;
- }
- public Condition getCondition() {
- return this.condition;
- }
- private Condition condition;
- private SimpleSelector simpleSelector;
- }
-
- private static class DescendantSelectorImpl extends SelectorImpl
- implements DescendantSelector {
- public DescendantSelectorImpl(DescendantSelector selector, SacFactory factory) {
- super(selector);
- this.ancestor = factory.cloneSelector(selector.getAncestorSelector());
- this.simpleSelector =
- (SimpleSelector) factory.cloneSelector(selector.getSimpleSelector());
- }
- public Selector getAncestorSelector() {
- return this.ancestor;
- }
- public SimpleSelector getSimpleSelector() {
- return this.simpleSelector;
- }
- private Selector ancestor;
- private SimpleSelector simpleSelector;
- }
-
- private static class ElementSelectorImpl extends SelectorImpl
- implements ElementSelector {
- public ElementSelectorImpl(ElementSelector selector) {
- super(selector);
- this.namespaceURI = selector.getNamespaceURI();
- this.localName = selector.getLocalName();
- }
- public String getNamespaceURI() {
- return this.namespaceURI;
- }
- public String getLocalName() {
- return this.localName;
- }
- private String namespaceURI;
- private String localName;
- }
+ public Condition getSecondCondition() {
+ return this.secondCondition;
+ }
- private static class NegativeSelectorImpl extends SelectorImpl
- implements NegativeSelector {
- public NegativeSelectorImpl(NegativeSelector selector, SacFactory factory) {
- super(selector);
- this.simpleSelector = (SimpleSelector) factory.cloneSelector(selector.getSimpleSelector());
- }
- public SimpleSelector getSimpleSelector() {
- return this.simpleSelector;
- }
- private SimpleSelector simpleSelector;
- }
-
- private static class ProcessingInstructionSelectorImpl extends SelectorImpl
- implements ProcessingInstructionSelector {
- public ProcessingInstructionSelectorImpl(ProcessingInstructionSelector selector) {
- super(selector);
- this.target = selector.getTarget();
- this.data = selector.getData();
- }
- public String getTarget() {
- return this.target;
- }
- public String getData() {
- return this.data;
- }
- private String target;
- private String data;
- }
-
- private static class SiblingSelectorImpl extends SelectorImpl
- implements SiblingSelector {
- private SiblingSelectorImpl(SiblingSelector selector, SacFactory factory) {
- super(selector);
- this.nodeType = selector.getNodeType();
- this.selector = factory.cloneSelector(selector.getSelector());
- this.siblingSelector = (SimpleSelector) factory.cloneSelector(selector.getSiblingSelector());
- }
- public short getNodeType() {
- return this.nodeType;
- }
- public Selector getSelector() {
- return this.selector;
- }
- public SimpleSelector getSiblingSelector() {
- return this.siblingSelector;
- }
- private short nodeType;
- private Selector selector;
- private SimpleSelector siblingSelector;
- }
+ private Condition firstCondition;
+ private Condition secondCondition;
+ }
+
+ private static class ContentConditionImpl extends ConditionImpl implements
+ ContentCondition {
+ public ContentConditionImpl(ContentCondition condition) {
+ super(condition);
+ this.data = condition.getData();
+ }
+
+ public String getData() {
+ return this.data;
+ }
+
+ private String data;
+ }
+
+ private static class LangConditionImpl extends ConditionImpl implements
+ LangCondition {
+ public LangConditionImpl(LangCondition condition) {
+ super(condition);
+ this.lang = condition.getLang();
+ }
+
+ public String getLang() {
+ return this.lang;
+ }
+
+ private String lang;
+ }
+
+ private static class NegativeConditionImpl extends ConditionImpl implements
+ NegativeCondition {
+ public NegativeConditionImpl(NegativeCondition condition,
+ SacFactory factory) {
+ super(condition);
+ this.condition = factory.cloneCondition(condition.getCondition());
+ }
+
+ public Condition getCondition() {
+ return this.condition;
+ }
+
+ private Condition condition;
+ }
+
+ private static class PositionalConditionImpl extends ConditionImpl
+ implements PositionalCondition {
+ public PositionalConditionImpl(PositionalCondition condition) {
+ super(condition);
+ this.position = condition.getPosition();
+ this.typeNode = condition.getTypeNode();
+ this.type = condition.getType();
+ }
+
+ public int getPosition() {
+ return this.position;
+ }
+
+ public boolean getTypeNode() {
+ return this.typeNode;
+ }
+
+ public boolean getType() {
+ return this.type;
+ }
+
+ private int position;
+ private boolean typeNode;
+ private boolean type;
+ }
+
+ private static class LexicalUnitImpl implements LexicalUnit, Serializable {
+
+ public LexicalUnitImpl(LexicalUnit lu, SacFactory factory) {
+ factory.cache.put(lu, this);
+ this.type = lu.getLexicalUnitType();
+ this.s = lu.getStringValue();
+ this.i = lu.getIntegerValue();
+ this.f = lu.getFloatValue();
+ this.functionName = lu.getFunctionName();
+ this.next = factory.cloneLexicalUnit(lu.getNextLexicalUnit());
+ this.prev = factory.cloneLexicalUnit(lu.getPreviousLexicalUnit());
+ this.parameters = factory.cloneLexicalUnit(lu.getParameters());
+ if (this.type == SAC_PERCENTAGE || this.type == SAC_EM
+ || this.type == SAC_EX || this.type == SAC_PIXEL
+ || this.type == SAC_CENTIMETER
+ || this.type == SAC_MILLIMETER || this.type == SAC_INCH
+ || this.type == SAC_POINT || this.type == SAC_PICA
+ || this.type == SAC_DEGREE || this.type == SAC_RADIAN
+ || this.type == SAC_GRADIAN || this.type == SAC_MILLISECOND
+ || this.type == SAC_SECOND || this.type == SAC_HERTZ
+ || this.type == SAC_KILOHERTZ || this.type == SAC_DIMENSION) {
+ this.dimensionText = lu.getDimensionUnitText();
+ }
+ this.stringRepresentation = lu.toString();
+ }
+
+ public short getLexicalUnitType() {
+ return this.type;
+ }
+
+ public LexicalUnit getNextLexicalUnit() {
+ return this.next;
+ }
+
+ public LexicalUnit getPreviousLexicalUnit() {
+ return this.prev;
+ }
+
+ public int getIntegerValue() {
+ return this.i;
+ }
+
+ public float getFloatValue() {
+ return this.f;
+ }
+
+ public String getDimensionUnitText() {
+ return this.dimensionText;
+ }
+
+ public String getFunctionName() {
+ return this.functionName;
+ }
+
+ public LexicalUnit getParameters() {
+ return this.parameters;
+ }
+
+ public String getStringValue() {
+ return this.s;
+ }
+
+ public String getStringRepresentation() {
+ return this.stringRepresentation;
+ }
+
+ public LexicalUnit getSubValues() {
+ return this.parameters;
+ }
+
+ // ================================================= PRIVATE
+
+ private LexicalUnitImpl() {
+ }
+
+ private short type;
+ private LexicalUnit next;
+ private LexicalUnit prev;
+ private LexicalUnit parameters;
+ private String s;
+ private int i;
+ private float f;
+ private String functionName;
+ private String dimensionText;
+ private String stringRepresentation;
+ }
+
+ private static class SelectorImpl implements Selector, Serializable {
+ public SelectorImpl(Selector selector) {
+ this.type = selector.getSelectorType();
+ }
+
+ public short getSelectorType() {
+ return this.type;
+ }
+
+ private short type;
+ }
+
+ private static class CharacterDataSelectorImpl extends SelectorImpl
+ implements CharacterDataSelector {
+ public CharacterDataSelectorImpl(CharacterDataSelector selector) {
+ super(selector);
+ this.data = selector.getData();
+ }
+
+ public String getData() {
+ return this.data;
+ }
+
+ private String data;
+ }
+
+ private static class ConditionalSelectorImpl extends SelectorImpl implements
+ ConditionalSelector {
+ public ConditionalSelectorImpl(ConditionalSelector selector,
+ SacFactory factory) {
+ super(selector);
+ this.condition = factory.cloneCondition(selector.getCondition());
+ this.simpleSelector = (SimpleSelector) factory
+ .cloneSelector(selector.getSimpleSelector());
+ }
+
+ public SimpleSelector getSimpleSelector() {
+ return this.simpleSelector;
+ }
+
+ public Condition getCondition() {
+ return this.condition;
+ }
+
+ private Condition condition;
+ private SimpleSelector simpleSelector;
+ }
+
+ private static class DescendantSelectorImpl extends SelectorImpl implements
+ DescendantSelector {
+ public DescendantSelectorImpl(DescendantSelector selector,
+ SacFactory factory) {
+ super(selector);
+ this.ancestor = factory.cloneSelector(selector
+ .getAncestorSelector());
+ this.simpleSelector = (SimpleSelector) factory
+ .cloneSelector(selector.getSimpleSelector());
+ }
+
+ public Selector getAncestorSelector() {
+ return this.ancestor;
+ }
+
+ public SimpleSelector getSimpleSelector() {
+ return this.simpleSelector;
+ }
+
+ private Selector ancestor;
+ private SimpleSelector simpleSelector;
+ }
+
+ private static class ElementSelectorImpl extends SelectorImpl implements
+ ElementSelector {
+ public ElementSelectorImpl(ElementSelector selector) {
+ super(selector);
+ this.namespaceURI = selector.getNamespaceURI();
+ this.localName = selector.getLocalName();
+ }
+
+ public String getNamespaceURI() {
+ return this.namespaceURI;
+ }
+
+ public String getLocalName() {
+ return this.localName;
+ }
+
+ private String namespaceURI;
+ private String localName;
+ }
+
+ private static class NegativeSelectorImpl extends SelectorImpl implements
+ NegativeSelector {
+ public NegativeSelectorImpl(NegativeSelector selector,
+ SacFactory factory) {
+ super(selector);
+ this.simpleSelector = (SimpleSelector) factory
+ .cloneSelector(selector.getSimpleSelector());
+ }
+
+ public SimpleSelector getSimpleSelector() {
+ return this.simpleSelector;
+ }
+
+ private SimpleSelector simpleSelector;
+ }
+
+ private static class ProcessingInstructionSelectorImpl extends SelectorImpl
+ implements ProcessingInstructionSelector {
+ public ProcessingInstructionSelectorImpl(
+ ProcessingInstructionSelector selector) {
+ super(selector);
+ this.target = selector.getTarget();
+ this.data = selector.getData();
+ }
+
+ public String getTarget() {
+ return this.target;
+ }
+
+ public String getData() {
+ return this.data;
+ }
+
+ private String target;
+ private String data;
+ }
+
+ private static class SiblingSelectorImpl extends SelectorImpl implements
+ SiblingSelector {
+ private SiblingSelectorImpl(SiblingSelector selector, SacFactory factory) {
+ super(selector);
+ this.nodeType = selector.getNodeType();
+ this.selector = factory.cloneSelector(selector.getSelector());
+ this.siblingSelector = (SimpleSelector) factory
+ .cloneSelector(selector.getSiblingSelector());
+ }
+
+ public short getNodeType() {
+ return this.nodeType;
+ }
+
+ public Selector getSelector() {
+ return this.selector;
+ }
+
+ public SimpleSelector getSiblingSelector() {
+ return this.siblingSelector;
+ }
+
+ private short nodeType;
+ private Selector selector;
+ private SimpleSelector siblingSelector;
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/StyleSheet.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/StyleSheet.java
index f33e939..5cda7eb 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/StyleSheet.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/StyleSheet.java
@@ -23,7 +23,6 @@
import java.util.Map;
import java.util.WeakHashMap;
-
import org.eclipse.wst.xml.vex.core.internal.core.FontSpec;
import org.eclipse.wst.xml.vex.core.internal.dom.Element;
import org.w3c.css.sac.LexicalUnit;
@@ -33,319 +32,327 @@
*/
public class StyleSheet implements Serializable {
- /**
- * Standard CSS properties.
- */
- private static final IProperty[] CSS_PROPERTIES = new IProperty[] {
- new DisplayProperty(),
- new LineHeightProperty(),
- new ListStyleTypeProperty(),
- new TextAlignProperty(),
- new WhiteSpaceProperty(),
-
- new FontFamilyProperty(),
- new FontSizeProperty(),
- new FontStyleProperty(),
- new FontWeightProperty(),
- new TextDecorationProperty(),
-
- new ColorProperty(CSS.COLOR),
- new ColorProperty(CSS.BACKGROUND_COLOR),
-
- new LengthProperty(CSS.MARGIN_BOTTOM, IProperty.AXIS_VERTICAL),
- new LengthProperty(CSS.MARGIN_LEFT, IProperty.AXIS_HORIZONTAL),
- new LengthProperty(CSS.MARGIN_RIGHT, IProperty.AXIS_HORIZONTAL),
- new LengthProperty(CSS.MARGIN_TOP, IProperty.AXIS_VERTICAL),
-
- new LengthProperty(CSS.PADDING_BOTTOM, IProperty.AXIS_VERTICAL),
- new LengthProperty(CSS.PADDING_LEFT, IProperty.AXIS_HORIZONTAL),
- new LengthProperty(CSS.PADDING_RIGHT, IProperty.AXIS_HORIZONTAL),
- new LengthProperty(CSS.PADDING_TOP, IProperty.AXIS_VERTICAL),
-
- new ColorProperty(CSS.BORDER_BOTTOM_COLOR),
- new ColorProperty(CSS.BORDER_LEFT_COLOR),
- new ColorProperty(CSS.BORDER_RIGHT_COLOR),
- new ColorProperty(CSS.BORDER_TOP_COLOR),
- new BorderStyleProperty(CSS.BORDER_BOTTOM_STYLE),
- new BorderStyleProperty(CSS.BORDER_LEFT_STYLE),
- new BorderStyleProperty(CSS.BORDER_RIGHT_STYLE),
- new BorderStyleProperty(CSS.BORDER_TOP_STYLE),
- new BorderWidthProperty(CSS.BORDER_BOTTOM_WIDTH, CSS.BORDER_BOTTOM_STYLE, IProperty.AXIS_VERTICAL),
- new BorderWidthProperty(CSS.BORDER_LEFT_WIDTH, CSS.BORDER_LEFT_STYLE, IProperty.AXIS_HORIZONTAL),
- new BorderWidthProperty(CSS.BORDER_RIGHT_WIDTH, CSS.BORDER_RIGHT_STYLE, IProperty.AXIS_HORIZONTAL),
- new BorderWidthProperty(CSS.BORDER_TOP_WIDTH, CSS.BORDER_TOP_STYLE, IProperty.AXIS_VERTICAL),
- new BorderSpacingProperty(),
- };
+ /**
+ * Standard CSS properties.
+ */
+ private static final IProperty[] CSS_PROPERTIES = new IProperty[] {
+ new DisplayProperty(),
+ new LineHeightProperty(),
+ new ListStyleTypeProperty(),
+ new TextAlignProperty(),
+ new WhiteSpaceProperty(),
- /**
- * The properties to calculate. This can be changed by the app.
- */
- private static IProperty[] properties = CSS_PROPERTIES;
+ new FontFamilyProperty(),
+ new FontSizeProperty(),
+ new FontStyleProperty(),
+ new FontWeightProperty(),
+ new TextDecorationProperty(),
- /**
- * Style sheet is the default for the renderer.
- */
- public static final byte SOURCE_DEFAULT = 0;
+ new ColorProperty(CSS.COLOR),
+ new ColorProperty(CSS.BACKGROUND_COLOR),
- /**
- * Style sheet was provided by the document author.
- */
- public static final byte SOURCE_AUTHOR = 1;
+ new LengthProperty(CSS.MARGIN_BOTTOM, IProperty.AXIS_VERTICAL),
+ new LengthProperty(CSS.MARGIN_LEFT, IProperty.AXIS_HORIZONTAL),
+ new LengthProperty(CSS.MARGIN_RIGHT, IProperty.AXIS_HORIZONTAL),
+ new LengthProperty(CSS.MARGIN_TOP, IProperty.AXIS_VERTICAL),
- /**
- * Style sheet was provided by the user.
- */
- public static final byte SOURCE_USER = 2;
+ new LengthProperty(CSS.PADDING_BOTTOM, IProperty.AXIS_VERTICAL),
+ new LengthProperty(CSS.PADDING_LEFT, IProperty.AXIS_HORIZONTAL),
+ new LengthProperty(CSS.PADDING_RIGHT, IProperty.AXIS_HORIZONTAL),
+ new LengthProperty(CSS.PADDING_TOP, IProperty.AXIS_VERTICAL),
- /**
- * The rules that comprise the stylesheet.
- */
- private Rule[] rules;
-
- /**
- * Computing styles can be expensive, e.g. we have to calculate the styles
- * of all parents of an element. We therefore cache styles in a map of
- * element => WeakReference(styles). A weak hash map is used to avoid
- * leaking memory as elements are deleted. By using weak references to
- * the values, we also ensure the cache is memory-sensitive.
- *
- * This must be transient to prevent it from being serialized, as
- * WeakHashMaps are not serializable.
- */
- private transient Map styleMap = null;
-
- /**
- * Class constructor.
- *
- * @param rules Rules that constitute the style sheet.
- */
- public StyleSheet(Rule[] rules) {
- this.rules = rules;
- }
+ new ColorProperty(CSS.BORDER_BOTTOM_COLOR),
+ new ColorProperty(CSS.BORDER_LEFT_COLOR),
+ new ColorProperty(CSS.BORDER_RIGHT_COLOR),
+ new ColorProperty(CSS.BORDER_TOP_COLOR),
+ new BorderStyleProperty(CSS.BORDER_BOTTOM_STYLE),
+ new BorderStyleProperty(CSS.BORDER_LEFT_STYLE),
+ new BorderStyleProperty(CSS.BORDER_RIGHT_STYLE),
+ new BorderStyleProperty(CSS.BORDER_TOP_STYLE),
+ new BorderWidthProperty(CSS.BORDER_BOTTOM_WIDTH,
+ CSS.BORDER_BOTTOM_STYLE, IProperty.AXIS_VERTICAL),
+ new BorderWidthProperty(CSS.BORDER_LEFT_WIDTH,
+ CSS.BORDER_LEFT_STYLE, IProperty.AXIS_HORIZONTAL),
+ new BorderWidthProperty(CSS.BORDER_RIGHT_WIDTH,
+ CSS.BORDER_RIGHT_STYLE, IProperty.AXIS_HORIZONTAL),
+ new BorderWidthProperty(CSS.BORDER_TOP_WIDTH, CSS.BORDER_TOP_STYLE,
+ IProperty.AXIS_VERTICAL), new BorderSpacingProperty(), };
- /**
- * Flush any cached styles for the given element.
- * @param element Element for which styles are to be flushed.
- */
- public void flushStyles(Element element) {
- this.getStyleMap().remove(element);
- }
-
- /**
- * Returns a pseudo-element representing content to be displayed
- * after the given element, or null if there is no such content.
- * @param element Parent element of the pseudo-element.
- */
- public Element getAfterElement(Element element) {
- PseudoElement pe = new PseudoElement(element, PseudoElement.AFTER);
- Styles styles = this.getStyles(pe);
- if (styles == null) {
- return null;
- } else {
- return pe;
- }
- }
-
- /**
- * Returns a pseudo-element representing content to be displayed
- * before the given element, or null if there is no such content.
- * @param element Parent element of the pseudo-element.
- */
- public Element getBeforeElement(Element element) {
- PseudoElement pe = new PseudoElement(element, PseudoElement.BEFORE);
- Styles styles = this.getStyles(pe);
- if (styles == null) {
- return null;
- } else {
- return pe;
- }
- }
-
- /**
- * Returns the array of standard CSS properties.
- */
- public static IProperty[] getCssProperties() {
- return CSS_PROPERTIES;
- }
+ /**
+ * The properties to calculate. This can be changed by the app.
+ */
+ private static IProperty[] properties = CSS_PROPERTIES;
- /**
- * Returns the styles for the given element. The styles are cached to
- * ensure reasonable performance.
- *
- * @param element Element for which to calculate the styles.
- */
- public Styles getStyles(Element element) {
+ /**
+ * Style sheet is the default for the renderer.
+ */
+ public static final byte SOURCE_DEFAULT = 0;
- Styles styles;
- WeakReference ref = (WeakReference) this.getStyleMap().get(element);
-
- if (ref != null) {
- // can't combine these tests, since calling ref.get() twice
- // (once to query for null, once to get the value) would
- // cause a race condition should the GC happen btn the two.
- styles = (Styles) ref.get();
- if (styles != null) {
- return styles;
- }
- } else if (this.getStyleMap().containsKey(element)) {
- // this must be a pseudo-element with no content
- return null;
- }
+ /**
+ * Style sheet was provided by the document author.
+ */
+ public static final byte SOURCE_AUTHOR = 1;
- styles = calculateStyles(element);
+ /**
+ * Style sheet was provided by the user.
+ */
+ public static final byte SOURCE_USER = 2;
- if (styles == null) {
- // Yes, they can be null if element is a PseudoElement with no content property
- this.getStyleMap().put(element, null);
- } else {
- this.getStyleMap().put(element, new WeakReference(styles));
- }
+ /**
+ * The rules that comprise the stylesheet.
+ */
+ private Rule[] rules;
- return styles;
- }
-
-
-
- private Styles calculateStyles(Element element) {
-
- Styles styles = new Styles();
- Styles parentStyles = null;
- if (element.getParent() != null) {
- parentStyles = this.getStyles(element.getParent());
- }
-
- Map decls = this.getApplicableDecls(element);
+ /**
+ * Computing styles can be expensive, e.g. we have to calculate the styles
+ * of all parents of an element. We therefore cache styles in a map of
+ * element => WeakReference(styles). A weak hash map is used to avoid
+ * leaking memory as elements are deleted. By using weak references to the
+ * values, we also ensure the cache is memory-sensitive.
+ *
+ * This must be transient to prevent it from being serialized, as
+ * WeakHashMaps are not serializable.
+ */
+ private transient Map styleMap = null;
- LexicalUnit lu;
-
- // If we're finding a pseudo-element, look at the 'content' property
- // first, since most of the time it'll be empty and we'll return null.
- if (element instanceof PseudoElement) {
- lu = (LexicalUnit) decls.get(CSS.CONTENT);
- if (lu == null) {
- return null;
- }
-
- List content = new ArrayList();
- while (lu != null) {
- if (lu.getLexicalUnitType() == LexicalUnit.SAC_STRING_VALUE) {
- content.add(lu.getStringValue());
- }
- lu = lu.getNextLexicalUnit();
- }
- styles.setContent(content);
- }
-
- for (int i = 0; i < properties.length; i++) {
- IProperty property = properties[i];
- lu = (LexicalUnit) decls.get(property.getName());
- Object value = property.calculate(lu, parentStyles, styles);
- styles.put(property.getName(), value);
- }
-
- // Now, map font-family, font-style, font-weight, and font-size onto
- // an AWT font.
-
- int styleFlags = FontSpec.PLAIN;
- String fontStyle = styles.getFontStyle();
- if (fontStyle.equals(CSS.ITALIC) || fontStyle.equals(CSS.OBLIQUE)) {
- styleFlags |= FontSpec.ITALIC;
+ /**
+ * Class constructor.
+ *
+ * @param rules
+ * Rules that constitute the style sheet.
+ */
+ public StyleSheet(Rule[] rules) {
+ this.rules = rules;
}
- if (styles.getFontWeight() > 550) {
- // 550 is halfway btn normal (400) and bold (700)
- styleFlags |= FontSpec.BOLD;
+
+ /**
+ * Flush any cached styles for the given element.
+ *
+ * @param element
+ * Element for which styles are to be flushed.
+ */
+ public void flushStyles(Element element) {
+ this.getStyleMap().remove(element);
}
- String textDecoration = styles.getTextDecoration();
- if (textDecoration.equals(CSS.UNDERLINE)) {
- styleFlags |= FontSpec.UNDERLINE;
- } else if (textDecoration.equals(CSS.OVERLINE)) {
- styleFlags |= FontSpec.OVERLINE;
- } else if (textDecoration.equals(CSS.LINE_THROUGH)) {
- styleFlags |= FontSpec.LINE_THROUGH;
- }
- styles.setFont(new FontSpec(styles.getFontFamilies(),
- styleFlags,
- Math.round(styles.getFontSize())));
-
- return styles;
- }
-
- /**
- * Returns the list of properties to be parsed by StyleSheets in this app.
- */
- public static IProperty[] getProperties() {
- return StyleSheet.properties;
- }
-
- /**
- * Returns the rules comprising this stylesheet.
- */
- public Rule[] getRules() {
- return this.rules;
- }
-
-
- /**
- * Sets the list of properties to be used by StyleSheets in this application.
- * @param properties New array of IProperty objects to be used.
- */
- public static void setProperties(IProperty[] properties) {
- StyleSheet.properties = properties;
- }
-
- //========================================================= PRIVATE
-
-
- /**
- * Returns all the declarations that apply to the given element.
- */
- private Map getApplicableDecls(Element element) {
- // Find all the property declarations that apply to this element.
- List declList = new ArrayList();
- Rule[] rules = this.getRules();
-
- for (int i = 0; i < rules.length; i++) {
- Rule rule = rules[i];
- if (rule.matches(element)) {
- PropertyDecl[] ruleDecls = rule.getPropertyDecls();
- for (int j = 0; j < ruleDecls.length; j++) {
- declList.add(ruleDecls[j]);
+ /**
+ * Returns a pseudo-element representing content to be displayed after the
+ * given element, or null if there is no such content.
+ *
+ * @param element
+ * Parent element of the pseudo-element.
+ */
+ public Element getAfterElement(Element element) {
+ PseudoElement pe = new PseudoElement(element, PseudoElement.AFTER);
+ Styles styles = this.getStyles(pe);
+ if (styles == null) {
+ return null;
+ } else {
+ return pe;
}
- }
}
- // Sort in cascade order. We can then just stuff them into a
- // map and get the right values since higher-priority values
- // come later and overwrite lower-priority ones.
- Collections.sort(declList);
-
- Map decls = new HashMap();
- Iterator iter = declList.iterator();
- while (iter.hasNext()) {
- PropertyDecl decl = (PropertyDecl) iter.next();
- PropertyDecl prevDecl = (PropertyDecl) decls.get(decl.getProperty());
- if (prevDecl == null || !prevDecl.isImportant() || decl.isImportant()) {
- decls.put(decl.getProperty(), decl);
- }
+ /**
+ * Returns a pseudo-element representing content to be displayed before the
+ * given element, or null if there is no such content.
+ *
+ * @param element
+ * Parent element of the pseudo-element.
+ */
+ public Element getBeforeElement(Element element) {
+ PseudoElement pe = new PseudoElement(element, PseudoElement.BEFORE);
+ Styles styles = this.getStyles(pe);
+ if (styles == null) {
+ return null;
+ } else {
+ return pe;
+ }
}
- Map values = new HashMap();
- for (Iterator it = decls.keySet().iterator(); it.hasNext();) {
- PropertyDecl decl = (PropertyDecl) decls.get(it.next());
- values.put(decl.getProperty(), decl.getValue());
+ /**
+ * Returns the array of standard CSS properties.
+ */
+ public static IProperty[] getCssProperties() {
+ return CSS_PROPERTIES;
}
- return values;
- }
+ /**
+ * Returns the styles for the given element. The styles are cached to ensure
+ * reasonable performance.
+ *
+ * @param element
+ * Element for which to calculate the styles.
+ */
+ public Styles getStyles(Element element) {
+ Styles styles;
+ WeakReference ref = (WeakReference) this.getStyleMap().get(element);
- private Map getStyleMap() {
- if (this.styleMap == null) {
- this.styleMap = new WeakHashMap();
- }
- return this.styleMap;
- }
+ if (ref != null) {
+ // can't combine these tests, since calling ref.get() twice
+ // (once to query for null, once to get the value) would
+ // cause a race condition should the GC happen btn the two.
+ styles = (Styles) ref.get();
+ if (styles != null) {
+ return styles;
+ }
+ } else if (this.getStyleMap().containsKey(element)) {
+ // this must be a pseudo-element with no content
+ return null;
+ }
+
+ styles = calculateStyles(element);
+
+ if (styles == null) {
+ // Yes, they can be null if element is a PseudoElement with no
+ // content property
+ this.getStyleMap().put(element, null);
+ } else {
+ this.getStyleMap().put(element, new WeakReference(styles));
+ }
+
+ return styles;
+ }
+
+ private Styles calculateStyles(Element element) {
+
+ Styles styles = new Styles();
+ Styles parentStyles = null;
+ if (element.getParent() != null) {
+ parentStyles = this.getStyles(element.getParent());
+ }
+
+ Map decls = this.getApplicableDecls(element);
+
+ LexicalUnit lu;
+
+ // If we're finding a pseudo-element, look at the 'content' property
+ // first, since most of the time it'll be empty and we'll return null.
+ if (element instanceof PseudoElement) {
+ lu = (LexicalUnit) decls.get(CSS.CONTENT);
+ if (lu == null) {
+ return null;
+ }
+
+ List content = new ArrayList();
+ while (lu != null) {
+ if (lu.getLexicalUnitType() == LexicalUnit.SAC_STRING_VALUE) {
+ content.add(lu.getStringValue());
+ }
+ lu = lu.getNextLexicalUnit();
+ }
+ styles.setContent(content);
+ }
+
+ for (int i = 0; i < properties.length; i++) {
+ IProperty property = properties[i];
+ lu = (LexicalUnit) decls.get(property.getName());
+ Object value = property.calculate(lu, parentStyles, styles);
+ styles.put(property.getName(), value);
+ }
+
+ // Now, map font-family, font-style, font-weight, and font-size onto
+ // an AWT font.
+
+ int styleFlags = FontSpec.PLAIN;
+ String fontStyle = styles.getFontStyle();
+ if (fontStyle.equals(CSS.ITALIC) || fontStyle.equals(CSS.OBLIQUE)) {
+ styleFlags |= FontSpec.ITALIC;
+ }
+ if (styles.getFontWeight() > 550) {
+ // 550 is halfway btn normal (400) and bold (700)
+ styleFlags |= FontSpec.BOLD;
+ }
+ String textDecoration = styles.getTextDecoration();
+ if (textDecoration.equals(CSS.UNDERLINE)) {
+ styleFlags |= FontSpec.UNDERLINE;
+ } else if (textDecoration.equals(CSS.OVERLINE)) {
+ styleFlags |= FontSpec.OVERLINE;
+ } else if (textDecoration.equals(CSS.LINE_THROUGH)) {
+ styleFlags |= FontSpec.LINE_THROUGH;
+ }
+
+ styles.setFont(new FontSpec(styles.getFontFamilies(), styleFlags, Math
+ .round(styles.getFontSize())));
+
+ return styles;
+ }
+
+ /**
+ * Returns the list of properties to be parsed by StyleSheets in this app.
+ */
+ public static IProperty[] getProperties() {
+ return StyleSheet.properties;
+ }
+
+ /**
+ * Returns the rules comprising this stylesheet.
+ */
+ public Rule[] getRules() {
+ return this.rules;
+ }
+
+ /**
+ * Sets the list of properties to be used by StyleSheets in this
+ * application.
+ *
+ * @param properties
+ * New array of IProperty objects to be used.
+ */
+ public static void setProperties(IProperty[] properties) {
+ StyleSheet.properties = properties;
+ }
+
+ // ========================================================= PRIVATE
+
+ /**
+ * Returns all the declarations that apply to the given element.
+ */
+ private Map getApplicableDecls(Element element) {
+ // Find all the property declarations that apply to this element.
+ List declList = new ArrayList();
+ Rule[] rules = this.getRules();
+
+ for (int i = 0; i < rules.length; i++) {
+ Rule rule = rules[i];
+ if (rule.matches(element)) {
+ PropertyDecl[] ruleDecls = rule.getPropertyDecls();
+ for (int j = 0; j < ruleDecls.length; j++) {
+ declList.add(ruleDecls[j]);
+ }
+ }
+ }
+
+ // Sort in cascade order. We can then just stuff them into a
+ // map and get the right values since higher-priority values
+ // come later and overwrite lower-priority ones.
+ Collections.sort(declList);
+
+ Map decls = new HashMap();
+ Iterator iter = declList.iterator();
+ while (iter.hasNext()) {
+ PropertyDecl decl = (PropertyDecl) iter.next();
+ PropertyDecl prevDecl = (PropertyDecl) decls
+ .get(decl.getProperty());
+ if (prevDecl == null || !prevDecl.isImportant()
+ || decl.isImportant()) {
+ decls.put(decl.getProperty(), decl);
+ }
+ }
+
+ Map values = new HashMap();
+ for (Iterator it = decls.keySet().iterator(); it.hasNext();) {
+ PropertyDecl decl = (PropertyDecl) decls.get(it.next());
+ values.put(decl.getProperty(), decl.getValue());
+ }
+
+ return values;
+ }
+
+ private Map getStyleMap() {
+ if (this.styleMap == null) {
+ this.styleMap = new WeakHashMap();
+ }
+ return this.styleMap;
+ }
}
-
-
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/StyleSheetReader.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/StyleSheetReader.java
index b32d4c8..e869eb9 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/StyleSheetReader.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/StyleSheetReader.java
@@ -32,514 +32,517 @@
*/
public class StyleSheetReader {
- /**
- * Class constructor.
- */
- public StyleSheetReader() {
-
- }
-
- protected static Parser createParser() {
- //return new org.apache.batik.css.parser.Parser();
- return new org.w3c.flute.parser.Parser();
- }
-
- /**
- * Creates a new StyleSheet object from a URL.
- * @param url URL from which to read the style sheet.
- */
- public StyleSheet read(URL url) throws IOException {
- return this.read(new InputSource(url.toString()), url);
- }
+ /**
+ * Class constructor.
+ */
+ public StyleSheetReader() {
- /**
- * Creates a style sheet from a string. This is mainly used for small
- * style sheets within unit tests.
- * @param s String containing the style sheet.
- */
- public StyleSheet read(String s) throws CSSException, IOException {
- Reader reader = new CharArrayReader(s.toCharArray());
- return this.read(new InputSource(reader), null);
- }
-
- /**
- * Creates a new Stylesheet from an input source.
- * @param inputSource InputSource from which to read the stylesheet.
- * @param url URL representing the input source, used to resolve @import
- * rules with relative URIs. May be null, in which case @import rules
- * are ignored.
- */
- public StyleSheet read(InputSource inputSource, URL url)
- throws CSSException, IOException {
-
- Parser parser = createParser();
- List rules = new ArrayList();
- StyleSheetBuilder ssBuilder = new StyleSheetBuilder(this.source, rules, url);
- parser.setDocumentHandler(ssBuilder);
- parser.parseStyleSheet(inputSource);
- Rule[] ruleArray = (Rule[]) rules.toArray(new Rule[rules.size()]);
- return new StyleSheet(ruleArray);
- }
-
- /**
- * Returns the source of the stylesheet.
- */
- public byte getSource() {
- return source;
- }
+ }
- /**
- * Sets the source of the stylesheet. Must be one of StyleSheet.SOURCE_USER,
- * StyleSheet.SOURCE_AUTHOR, or StyleSheet.SOURCE_DEFAULT.
- * @param source The source to set.
- */
- public void setSource(byte source) {
- this.source = source;
- }
+ protected static Parser createParser() {
+ // return new org.apache.batik.css.parser.Parser();
+ return new org.w3c.flute.parser.Parser();
+ }
- //======================================================== PRIVATE
+ /**
+ * Creates a new StyleSheet object from a URL.
+ *
+ * @param url
+ * URL from which to read the style sheet.
+ */
+ public StyleSheet read(URL url) throws IOException {
+ return this.read(new InputSource(url.toString()), url);
+ }
- private byte source = StyleSheet.SOURCE_DEFAULT;
-
- private static class StyleSheetBuilder implements DocumentHandler {
+ /**
+ * Creates a style sheet from a string. This is mainly used for small style
+ * sheets within unit tests.
+ *
+ * @param s
+ * String containing the style sheet.
+ */
+ public StyleSheet read(String s) throws CSSException, IOException {
+ Reader reader = new CharArrayReader(s.toCharArray());
+ return this.read(new InputSource(reader), null);
+ }
- private byte source;
-
- // The rules that will be added to the stylesheet
- private List rules;
-
- // The rules to which decls are currently being added
- private List currentRules;
-
- // URL from which @import rules relative URIs are resolved.
- // May be null!
- private URL url;
-
- // Factory for creating serializable clones of SAC objects
- SacFactory factory = new SacFactory();
+ /**
+ * Creates a new Stylesheet from an input source.
+ *
+ * @param inputSource
+ * InputSource from which to read the stylesheet.
+ * @param url
+ * URL representing the input source, used to resolve @import
+ * rules with relative URIs. May be null, in which case @import
+ * rules are ignored.
+ */
+ public StyleSheet read(InputSource inputSource, URL url)
+ throws CSSException, IOException {
- public StyleSheetBuilder(byte source, List rules, URL url) {
- this.source = source;
- this.rules = rules;
- this.url = url;
- }
-
- //-------------------------------------------- DocumentHandler methods
+ Parser parser = createParser();
+ List rules = new ArrayList();
+ StyleSheetBuilder ssBuilder = new StyleSheetBuilder(this.source, rules,
+ url);
+ parser.setDocumentHandler(ssBuilder);
+ parser.parseStyleSheet(inputSource);
+ Rule[] ruleArray = (Rule[]) rules.toArray(new Rule[rules.size()]);
+ return new StyleSheet(ruleArray);
+ }
- public void comment(java.lang.String text) {
- }
+ /**
+ * Returns the source of the stylesheet.
+ */
+ public byte getSource() {
+ return source;
+ }
- public void endDocument(InputSource source) {
- }
+ /**
+ * Sets the source of the stylesheet. Must be one of StyleSheet.SOURCE_USER,
+ * StyleSheet.SOURCE_AUTHOR, or StyleSheet.SOURCE_DEFAULT.
+ *
+ * @param source
+ * The source to set.
+ */
+ public void setSource(byte source) {
+ this.source = source;
+ }
- public void endFontFace() {
- }
+ // ======================================================== PRIVATE
- public void endMedia(SACMediaList media) {
- }
+ private byte source = StyleSheet.SOURCE_DEFAULT;
- public void endPage(String name, String pseudo_page) {
- }
+ private static class StyleSheetBuilder implements DocumentHandler {
- public void endSelector(SelectorList selectors) {
- this.rules.addAll(this.currentRules);
- this.currentRules = null;
- }
+ private byte source;
- public void ignorableAtRule(String atRule) {
- }
+ // The rules that will be added to the stylesheet
+ private List rules;
- public void importStyle(
- String uri,
- SACMediaList media,
- String defaultNamespaceURI) {
-
- if (this.url == null) {
- return;
- }
+ // The rules to which decls are currently being added
+ private List currentRules;
- try {
- Parser parser = createParser();
- URL importUrl = new URL(this.url, uri);
- StyleSheetBuilder ssBuilder = new StyleSheetBuilder(this.source, rules, importUrl);
- parser.setDocumentHandler(ssBuilder);
- parser.parseStyleSheet(new InputSource(importUrl.toString()));
- } catch (CSSException e) {
- } catch (IOException e) {
- }
-
- }
+ // URL from which @import rules relative URIs are resolved.
+ // May be null!
+ private URL url;
- public void namespaceDeclaration(String prefix, String uri) {
- }
+ // Factory for creating serializable clones of SAC objects
+ SacFactory factory = new SacFactory();
- public void property(
- String name,
- LexicalUnit value,
- boolean important) {
+ public StyleSheetBuilder(byte source, List rules, URL url) {
+ this.source = source;
+ this.rules = rules;
+ this.url = url;
+ }
- // Create a serializable clone of the value for storage in our
- // stylesheet.
- LexicalUnit val = factory.cloneLexicalUnit(value);
-
- if (name.equals(CSS.BORDER)) {
- this.expandBorder(val, important);
- } else if (name.equals(CSS.BORDER_BOTTOM)) {
- this.expandBorder(val, CSS.BORDER_BOTTOM, important);
- } else if (name.equals(CSS.BORDER_LEFT)) {
- this.expandBorder(val, CSS.BORDER_LEFT, important);
- } else if (name.equals(CSS.BORDER_RIGHT)) {
- this.expandBorder(val, CSS.BORDER_RIGHT, important);
- } else if (name.equals(CSS.BORDER_TOP)) {
- this.expandBorder(val, CSS.BORDER_TOP, important);
- } else if (name.equals(CSS.BORDER_COLOR)) {
- this.expandBorderColor(val, important);
- } else if (name.equals(CSS.BORDER_STYLE)) {
- this.expandBorderStyle(val, important);
- } else if (name.equals(CSS.BORDER_WIDTH)) {
- this.expandBorderWidth(val, important);
- } else if (name.equals(CSS.FONT)) {
- this.expandFont(val, important);
- } else if (name.equals(CSS.MARGIN)) {
- this.expandMargin(val, important);
- } else if (name.equals(CSS.PADDING)) {
- this.expandPadding(val, important);
- } else {
- this.addDecl(name, val, important);
- }
- }
+ // -------------------------------------------- DocumentHandler methods
- public void startDocument(InputSource source) {
- }
+ public void comment(java.lang.String text) {
+ }
- public void startFontFace() {
- }
+ public void endDocument(InputSource source) {
+ }
- public void startMedia(SACMediaList media) {
- }
+ public void endFontFace() {
+ }
- public void startPage(String name, String pseudo_page) {
- }
+ public void endMedia(SACMediaList media) {
+ }
- public void startSelector(SelectorList selectors) {
- this.currentRules = new ArrayList();
- for (int i = 0; i < selectors.getLength(); i++) {
- Selector selector = factory.cloneSelector(selectors.item(i));
- Rule rule = new Rule(this.source, selector);
- this.currentRules.add(rule);
- }
- }
+ public void endPage(String name, String pseudo_page) {
+ }
- //----------------------------------------- DocumentHandler methods end
+ public void endSelector(SelectorList selectors) {
+ this.rules.addAll(this.currentRules);
+ this.currentRules = null;
+ }
- //======================================================= PRIVATE
+ public void ignorableAtRule(String atRule) {
+ }
- /**
- * Adds a PropertyDecl to the current set of rules.
- */
- private void addDecl(String name, LexicalUnit value, boolean important) {
- Iterator iter = this.currentRules.iterator();
- while (iter.hasNext()) {
- Rule rule = (Rule) iter.next();
- rule.add(new PropertyDecl(rule, name, value, important));
- }
- }
+ public void importStyle(String uri, SACMediaList media,
+ String defaultNamespaceURI) {
- /**
- * Expand the "border" shorthand property.
- */
- private void expandBorder(LexicalUnit value, boolean important) {
- this.expandBorder(value, CSS.BORDER_BOTTOM, important);
- this.expandBorder(value, CSS.BORDER_LEFT, important);
- this.expandBorder(value, CSS.BORDER_RIGHT, important);
- this.expandBorder(value, CSS.BORDER_TOP, important);
- }
+ if (this.url == null) {
+ return;
+ }
- /**
- * Expand one of the the "border-xxx" shorthand
- * properties. whichBorder must be one of CSS.BORDER_BOTTOM,
- * CSS.BORDER_LEFT, CSS.BORDER_RIGHT, CSS.BORDER_TOP.
- */
- private void expandBorder(
- LexicalUnit value,
- String whichBorder,
- boolean important) {
+ try {
+ Parser parser = createParser();
+ URL importUrl = new URL(this.url, uri);
+ StyleSheetBuilder ssBuilder = new StyleSheetBuilder(
+ this.source, rules, importUrl);
+ parser.setDocumentHandler(ssBuilder);
+ parser.parseStyleSheet(new InputSource(importUrl.toString()));
+ } catch (CSSException e) {
+ } catch (IOException e) {
+ }
- if (AbstractProperty.isInherit(value)) {
- this.addDecl(whichBorder + CSS.COLOR_SUFFIX, value, important);
- this.addDecl(whichBorder + CSS.STYLE_SUFFIX, value, important);
- this.addDecl(whichBorder + CSS.WIDTH_SUFFIX, value, important);
- return;
- }
+ }
- LexicalUnit[] lus = getLexicalUnitList(value);
- int i = 0;
- if (BorderWidthProperty.isBorderWidth(lus[i])) {
- this.addDecl(whichBorder + CSS.WIDTH_SUFFIX, lus[i], important);
- i++;
- }
+ public void namespaceDeclaration(String prefix, String uri) {
+ }
- if (i < lus.length && BorderStyleProperty.isBorderStyle(lus[i])) {
- this.addDecl(whichBorder + CSS.STYLE_SUFFIX, lus[i], important);
- i++;
- }
+ public void property(String name, LexicalUnit value, boolean important) {
- if (i < lus.length && ColorProperty.isColor(lus[i])) {
- this.addDecl(whichBorder + CSS.COLOR_SUFFIX, lus[i], important);
- i++;
- }
+ // Create a serializable clone of the value for storage in our
+ // stylesheet.
+ LexicalUnit val = factory.cloneLexicalUnit(value);
- }
+ if (name.equals(CSS.BORDER)) {
+ this.expandBorder(val, important);
+ } else if (name.equals(CSS.BORDER_BOTTOM)) {
+ this.expandBorder(val, CSS.BORDER_BOTTOM, important);
+ } else if (name.equals(CSS.BORDER_LEFT)) {
+ this.expandBorder(val, CSS.BORDER_LEFT, important);
+ } else if (name.equals(CSS.BORDER_RIGHT)) {
+ this.expandBorder(val, CSS.BORDER_RIGHT, important);
+ } else if (name.equals(CSS.BORDER_TOP)) {
+ this.expandBorder(val, CSS.BORDER_TOP, important);
+ } else if (name.equals(CSS.BORDER_COLOR)) {
+ this.expandBorderColor(val, important);
+ } else if (name.equals(CSS.BORDER_STYLE)) {
+ this.expandBorderStyle(val, important);
+ } else if (name.equals(CSS.BORDER_WIDTH)) {
+ this.expandBorderWidth(val, important);
+ } else if (name.equals(CSS.FONT)) {
+ this.expandFont(val, important);
+ } else if (name.equals(CSS.MARGIN)) {
+ this.expandMargin(val, important);
+ } else if (name.equals(CSS.PADDING)) {
+ this.expandPadding(val, important);
+ } else {
+ this.addDecl(name, val, important);
+ }
+ }
- /**
- * Expand the "border-color" shorthand property.
- */
- private void expandBorderColor(LexicalUnit value, boolean important) {
+ public void startDocument(InputSource source) {
+ }
- if (AbstractProperty.isInherit(value)) {
- this.addDecl(CSS.BORDER_TOP_COLOR, value, important);
- this.addDecl(CSS.BORDER_LEFT_COLOR, value, important);
- this.addDecl(CSS.BORDER_RIGHT_COLOR, value, important);
- this.addDecl(CSS.BORDER_BOTTOM_COLOR, value, important);
- return;
- }
+ public void startFontFace() {
+ }
- LexicalUnit[] lus = getLexicalUnitList(value);
- if (lus.length >= 4) {
- this.addDecl(CSS.BORDER_TOP_COLOR, lus[0], important);
- this.addDecl(CSS.BORDER_RIGHT_COLOR, lus[1], important);
- this.addDecl(CSS.BORDER_BOTTOM_COLOR, lus[2], important);
- this.addDecl(CSS.BORDER_LEFT_COLOR, lus[3], important);
- } else if (lus.length == 3) {
- this.addDecl(CSS.BORDER_TOP_COLOR, lus[0], important);
- this.addDecl(CSS.BORDER_LEFT_COLOR, lus[1], important);
- this.addDecl(CSS.BORDER_RIGHT_COLOR, lus[1], important);
- this.addDecl(CSS.BORDER_BOTTOM_COLOR, lus[2], important);
- } else if (lus.length == 2) {
- this.addDecl(CSS.BORDER_TOP_COLOR, lus[0], important);
- this.addDecl(CSS.BORDER_LEFT_COLOR, lus[1], important);
- this.addDecl(CSS.BORDER_RIGHT_COLOR, lus[1], important);
- this.addDecl(CSS.BORDER_BOTTOM_COLOR, lus[0], important);
- } else if (lus.length == 1) {
- this.addDecl(CSS.BORDER_TOP_COLOR, lus[0], important);
- this.addDecl(CSS.BORDER_LEFT_COLOR, lus[0], important);
- this.addDecl(CSS.BORDER_RIGHT_COLOR, lus[0], important);
- this.addDecl(CSS.BORDER_BOTTOM_COLOR, lus[0], important);
- }
- }
+ public void startMedia(SACMediaList media) {
+ }
- /**
- * Expand the "border-style" shorthand property.
- */
- private void expandBorderStyle(LexicalUnit value, boolean important) {
+ public void startPage(String name, String pseudo_page) {
+ }
- if (AbstractProperty.isInherit(value)) {
- this.addDecl(CSS.BORDER_TOP_STYLE, value, important);
- this.addDecl(CSS.BORDER_LEFT_STYLE, value, important);
- this.addDecl(CSS.BORDER_RIGHT_STYLE, value, important);
- this.addDecl(CSS.BORDER_BOTTOM_STYLE, value, important);
- return;
- }
+ public void startSelector(SelectorList selectors) {
+ this.currentRules = new ArrayList();
+ for (int i = 0; i < selectors.getLength(); i++) {
+ Selector selector = factory.cloneSelector(selectors.item(i));
+ Rule rule = new Rule(this.source, selector);
+ this.currentRules.add(rule);
+ }
+ }
- LexicalUnit[] lus = getLexicalUnitList(value);
- if (lus.length >= 4) {
- this.addDecl(CSS.BORDER_TOP_STYLE, lus[0], important);
- this.addDecl(CSS.BORDER_RIGHT_STYLE, lus[1], important);
- this.addDecl(CSS.BORDER_BOTTOM_STYLE, lus[2], important);
- this.addDecl(CSS.BORDER_LEFT_STYLE, lus[3], important);
- } else if (lus.length == 3) {
- this.addDecl(CSS.BORDER_TOP_STYLE, lus[0], important);
- this.addDecl(CSS.BORDER_LEFT_STYLE, lus[1], important);
- this.addDecl(CSS.BORDER_RIGHT_STYLE, lus[1], important);
- this.addDecl(CSS.BORDER_BOTTOM_STYLE, lus[2], important);
- } else if (lus.length == 2) {
- this.addDecl(CSS.BORDER_TOP_STYLE, lus[0], important);
- this.addDecl(CSS.BORDER_LEFT_STYLE, lus[1], important);
- this.addDecl(CSS.BORDER_RIGHT_STYLE, lus[1], important);
- this.addDecl(CSS.BORDER_BOTTOM_STYLE, lus[0], important);
- } else if (lus.length == 1) {
- this.addDecl(CSS.BORDER_TOP_STYLE, lus[0], important);
- this.addDecl(CSS.BORDER_LEFT_STYLE, lus[0], important);
- this.addDecl(CSS.BORDER_RIGHT_STYLE, lus[0], important);
- this.addDecl(CSS.BORDER_BOTTOM_STYLE, lus[0], important);
- }
- }
+ // ----------------------------------------- DocumentHandler methods end
- /**
- * Expand the "border-width" shorthand property.
- */
- private void expandBorderWidth(LexicalUnit value, boolean important) {
+ // ======================================================= PRIVATE
- if (AbstractProperty.isInherit(value)) {
- this.addDecl(CSS.BORDER_TOP_WIDTH, value, important);
- this.addDecl(CSS.BORDER_LEFT_WIDTH, value, important);
- this.addDecl(CSS.BORDER_RIGHT_WIDTH, value, important);
- this.addDecl(CSS.BORDER_BOTTOM_WIDTH, value, important);
- return;
- }
+ /**
+ * Adds a PropertyDecl to the current set of rules.
+ */
+ private void addDecl(String name, LexicalUnit value, boolean important) {
+ Iterator iter = this.currentRules.iterator();
+ while (iter.hasNext()) {
+ Rule rule = (Rule) iter.next();
+ rule.add(new PropertyDecl(rule, name, value, important));
+ }
+ }
- LexicalUnit[] lus = getLexicalUnitList(value);
- if (lus.length >= 4) {
- this.addDecl(CSS.BORDER_TOP_WIDTH, lus[0], important);
- this.addDecl(CSS.BORDER_RIGHT_WIDTH, lus[1], important);
- this.addDecl(CSS.BORDER_BOTTOM_WIDTH, lus[2], important);
- this.addDecl(CSS.BORDER_LEFT_WIDTH, lus[3], important);
- } else if (lus.length == 3) {
- this.addDecl(CSS.BORDER_TOP_WIDTH, lus[0], important);
- this.addDecl(CSS.BORDER_LEFT_WIDTH, lus[1], important);
- this.addDecl(CSS.BORDER_RIGHT_WIDTH, lus[1], important);
- this.addDecl(CSS.BORDER_BOTTOM_WIDTH, lus[2], important);
- } else if (lus.length == 2) {
- this.addDecl(CSS.BORDER_TOP_WIDTH, lus[0], important);
- this.addDecl(CSS.BORDER_LEFT_WIDTH, lus[1], important);
- this.addDecl(CSS.BORDER_RIGHT_WIDTH, lus[1], important);
- this.addDecl(CSS.BORDER_BOTTOM_WIDTH, lus[0], important);
- } else if (lus.length == 1) {
- this.addDecl(CSS.BORDER_TOP_WIDTH, lus[0], important);
- this.addDecl(CSS.BORDER_LEFT_WIDTH, lus[0], important);
- this.addDecl(CSS.BORDER_RIGHT_WIDTH, lus[0], important);
- this.addDecl(CSS.BORDER_BOTTOM_WIDTH, lus[0], important);
- }
- }
+ /**
+ * Expand the "border" shorthand property.
+ */
+ private void expandBorder(LexicalUnit value, boolean important) {
+ this.expandBorder(value, CSS.BORDER_BOTTOM, important);
+ this.expandBorder(value, CSS.BORDER_LEFT, important);
+ this.expandBorder(value, CSS.BORDER_RIGHT, important);
+ this.expandBorder(value, CSS.BORDER_TOP, important);
+ }
- /**
- * Expand the "font" shorthand property.
- */
- private void expandFont(LexicalUnit value, boolean important) {
+ /**
+ * Expand one of the the "border-xxx" shorthand properties. whichBorder
+ * must be one of CSS.BORDER_BOTTOM, CSS.BORDER_LEFT, CSS.BORDER_RIGHT,
+ * CSS.BORDER_TOP.
+ */
+ private void expandBorder(LexicalUnit value, String whichBorder,
+ boolean important) {
- if (AbstractProperty.isInherit(value)) {
- this.addDecl(CSS.FONT_STYLE, value, important);
- this.addDecl(CSS.FONT_VARIANT, value, important);
- this.addDecl(CSS.FONT_WEIGHT, value, important);
- this.addDecl(CSS.FONT_SIZE, value, important);
- this.addDecl(CSS.FONT_FAMILY, value, important);
- return;
- }
+ if (AbstractProperty.isInherit(value)) {
+ this.addDecl(whichBorder + CSS.COLOR_SUFFIX, value, important);
+ this.addDecl(whichBorder + CSS.STYLE_SUFFIX, value, important);
+ this.addDecl(whichBorder + CSS.WIDTH_SUFFIX, value, important);
+ return;
+ }
- LexicalUnit[] lus = getLexicalUnitList(value);
- int n = lus.length;
- int i = 0;
- if (i < n && FontStyleProperty.isFontStyle(lus[i])) {
- this.addDecl(CSS.FONT_STYLE, lus[i], important);
- i++;
- }
+ LexicalUnit[] lus = getLexicalUnitList(value);
+ int i = 0;
+ if (BorderWidthProperty.isBorderWidth(lus[i])) {
+ this.addDecl(whichBorder + CSS.WIDTH_SUFFIX, lus[i], important);
+ i++;
+ }
- if (i < n && FontVariantProperty.isFontVariant(lus[i])) {
- this.addDecl(CSS.FONT_VARIANT, lus[i], important);
- i++;
- }
+ if (i < lus.length && BorderStyleProperty.isBorderStyle(lus[i])) {
+ this.addDecl(whichBorder + CSS.STYLE_SUFFIX, lus[i], important);
+ i++;
+ }
- if (i < n && FontWeightProperty.isFontWeight(lus[i])) {
- this.addDecl(CSS.FONT_WEIGHT, lus[i], important);
- i++;
- }
+ if (i < lus.length && ColorProperty.isColor(lus[i])) {
+ this.addDecl(whichBorder + CSS.COLOR_SUFFIX, lus[i], important);
+ i++;
+ }
- if (i < n && FontSizeProperty.isFontSize(lus[i])) {
- this.addDecl(CSS.FONT_SIZE, lus[i], important);
- i++;
- }
+ }
- if (i < n
- && lus[i].getLexicalUnitType()
- == LexicalUnit.SAC_OPERATOR_SLASH) {
- i++; // gobble slash
- if (i < n) {
- this.addDecl(CSS.LINE_HEIGHT, lus[i], important);
- }
- i++;
- }
+ /**
+ * Expand the "border-color" shorthand property.
+ */
+ private void expandBorderColor(LexicalUnit value, boolean important) {
- if (i < n) {
- this.addDecl(CSS.FONT_FAMILY, lus[i], important);
- }
- }
+ if (AbstractProperty.isInherit(value)) {
+ this.addDecl(CSS.BORDER_TOP_COLOR, value, important);
+ this.addDecl(CSS.BORDER_LEFT_COLOR, value, important);
+ this.addDecl(CSS.BORDER_RIGHT_COLOR, value, important);
+ this.addDecl(CSS.BORDER_BOTTOM_COLOR, value, important);
+ return;
+ }
- /**
- * Expand the "margin" shorthand property.
- */
- private void expandMargin(LexicalUnit value, boolean important) {
+ LexicalUnit[] lus = getLexicalUnitList(value);
+ if (lus.length >= 4) {
+ this.addDecl(CSS.BORDER_TOP_COLOR, lus[0], important);
+ this.addDecl(CSS.BORDER_RIGHT_COLOR, lus[1], important);
+ this.addDecl(CSS.BORDER_BOTTOM_COLOR, lus[2], important);
+ this.addDecl(CSS.BORDER_LEFT_COLOR, lus[3], important);
+ } else if (lus.length == 3) {
+ this.addDecl(CSS.BORDER_TOP_COLOR, lus[0], important);
+ this.addDecl(CSS.BORDER_LEFT_COLOR, lus[1], important);
+ this.addDecl(CSS.BORDER_RIGHT_COLOR, lus[1], important);
+ this.addDecl(CSS.BORDER_BOTTOM_COLOR, lus[2], important);
+ } else if (lus.length == 2) {
+ this.addDecl(CSS.BORDER_TOP_COLOR, lus[0], important);
+ this.addDecl(CSS.BORDER_LEFT_COLOR, lus[1], important);
+ this.addDecl(CSS.BORDER_RIGHT_COLOR, lus[1], important);
+ this.addDecl(CSS.BORDER_BOTTOM_COLOR, lus[0], important);
+ } else if (lus.length == 1) {
+ this.addDecl(CSS.BORDER_TOP_COLOR, lus[0], important);
+ this.addDecl(CSS.BORDER_LEFT_COLOR, lus[0], important);
+ this.addDecl(CSS.BORDER_RIGHT_COLOR, lus[0], important);
+ this.addDecl(CSS.BORDER_BOTTOM_COLOR, lus[0], important);
+ }
+ }
- if (AbstractProperty.isInherit(value)) {
- this.addDecl(CSS.MARGIN_TOP, value, important);
- this.addDecl(CSS.MARGIN_RIGHT, value, important);
- this.addDecl(CSS.MARGIN_BOTTOM, value, important);
- this.addDecl(CSS.MARGIN_LEFT, value, important);
- return;
- }
+ /**
+ * Expand the "border-style" shorthand property.
+ */
+ private void expandBorderStyle(LexicalUnit value, boolean important) {
- LexicalUnit[] lus = getLexicalUnitList(value);
- if (lus.length >= 4) {
- this.addDecl(CSS.MARGIN_TOP, lus[0], important);
- this.addDecl(CSS.MARGIN_RIGHT, lus[1], important);
- this.addDecl(CSS.MARGIN_BOTTOM, lus[2], important);
- this.addDecl(CSS.MARGIN_LEFT, lus[3], important);
- } else if (lus.length == 3) {
- this.addDecl(CSS.MARGIN_TOP, lus[0], important);
- this.addDecl(CSS.MARGIN_LEFT, lus[1], important);
- this.addDecl(CSS.MARGIN_RIGHT, lus[1], important);
- this.addDecl(CSS.MARGIN_BOTTOM, lus[2], important);
- } else if (lus.length == 2) {
- this.addDecl(CSS.MARGIN_TOP, lus[0], important);
- this.addDecl(CSS.MARGIN_LEFT, lus[1], important);
- this.addDecl(CSS.MARGIN_RIGHT, lus[1], important);
- this.addDecl(CSS.MARGIN_BOTTOM, lus[0], important);
- } else if (lus.length == 1) {
- this.addDecl(CSS.MARGIN_TOP, lus[0], important);
- this.addDecl(CSS.MARGIN_LEFT, lus[0], important);
- this.addDecl(CSS.MARGIN_RIGHT, lus[0], important);
- this.addDecl(CSS.MARGIN_BOTTOM, lus[0], important);
- }
- }
+ if (AbstractProperty.isInherit(value)) {
+ this.addDecl(CSS.BORDER_TOP_STYLE, value, important);
+ this.addDecl(CSS.BORDER_LEFT_STYLE, value, important);
+ this.addDecl(CSS.BORDER_RIGHT_STYLE, value, important);
+ this.addDecl(CSS.BORDER_BOTTOM_STYLE, value, important);
+ return;
+ }
- /**
- * Expand the "padding" shorthand property.
- */
- private void expandPadding(LexicalUnit value, boolean important) {
+ LexicalUnit[] lus = getLexicalUnitList(value);
+ if (lus.length >= 4) {
+ this.addDecl(CSS.BORDER_TOP_STYLE, lus[0], important);
+ this.addDecl(CSS.BORDER_RIGHT_STYLE, lus[1], important);
+ this.addDecl(CSS.BORDER_BOTTOM_STYLE, lus[2], important);
+ this.addDecl(CSS.BORDER_LEFT_STYLE, lus[3], important);
+ } else if (lus.length == 3) {
+ this.addDecl(CSS.BORDER_TOP_STYLE, lus[0], important);
+ this.addDecl(CSS.BORDER_LEFT_STYLE, lus[1], important);
+ this.addDecl(CSS.BORDER_RIGHT_STYLE, lus[1], important);
+ this.addDecl(CSS.BORDER_BOTTOM_STYLE, lus[2], important);
+ } else if (lus.length == 2) {
+ this.addDecl(CSS.BORDER_TOP_STYLE, lus[0], important);
+ this.addDecl(CSS.BORDER_LEFT_STYLE, lus[1], important);
+ this.addDecl(CSS.BORDER_RIGHT_STYLE, lus[1], important);
+ this.addDecl(CSS.BORDER_BOTTOM_STYLE, lus[0], important);
+ } else if (lus.length == 1) {
+ this.addDecl(CSS.BORDER_TOP_STYLE, lus[0], important);
+ this.addDecl(CSS.BORDER_LEFT_STYLE, lus[0], important);
+ this.addDecl(CSS.BORDER_RIGHT_STYLE, lus[0], important);
+ this.addDecl(CSS.BORDER_BOTTOM_STYLE, lus[0], important);
+ }
+ }
- if (AbstractProperty.isInherit(value)) {
- this.addDecl(CSS.PADDING_TOP, value, important);
- this.addDecl(CSS.PADDING_LEFT, value, important);
- this.addDecl(CSS.PADDING_RIGHT, value, important);
- this.addDecl(CSS.PADDING_BOTTOM, value, important);
- return;
- }
+ /**
+ * Expand the "border-width" shorthand property.
+ */
+ private void expandBorderWidth(LexicalUnit value, boolean important) {
- LexicalUnit[] lus = getLexicalUnitList(value);
- if (lus.length >= 4) {
- this.addDecl(CSS.PADDING_TOP, lus[0], important);
- this.addDecl(CSS.PADDING_RIGHT, lus[1], important);
- this.addDecl(CSS.PADDING_BOTTOM, lus[2], important);
- this.addDecl(CSS.PADDING_LEFT, lus[3], important);
- } else if (lus.length == 3) {
- this.addDecl(CSS.PADDING_TOP, lus[0], important);
- this.addDecl(CSS.PADDING_LEFT, lus[1], important);
- this.addDecl(CSS.PADDING_RIGHT, lus[1], important);
- this.addDecl(CSS.PADDING_BOTTOM, lus[2], important);
- } else if (lus.length == 2) {
- this.addDecl(CSS.PADDING_TOP, lus[0], important);
- this.addDecl(CSS.PADDING_LEFT, lus[1], important);
- this.addDecl(CSS.PADDING_RIGHT, lus[1], important);
- this.addDecl(CSS.PADDING_BOTTOM, lus[0], important);
- } else if (lus.length == 1) {
- this.addDecl(CSS.PADDING_TOP, lus[0], important);
- this.addDecl(CSS.PADDING_LEFT, lus[0], important);
- this.addDecl(CSS.PADDING_RIGHT, lus[0], important);
- this.addDecl(CSS.PADDING_BOTTOM, lus[0], important);
- }
- }
+ if (AbstractProperty.isInherit(value)) {
+ this.addDecl(CSS.BORDER_TOP_WIDTH, value, important);
+ this.addDecl(CSS.BORDER_LEFT_WIDTH, value, important);
+ this.addDecl(CSS.BORDER_RIGHT_WIDTH, value, important);
+ this.addDecl(CSS.BORDER_BOTTOM_WIDTH, value, important);
+ return;
+ }
- /**
- * Returns an array of <code>LexicalUnit</code> objects, the first
- * of which is given.
- */
- private static LexicalUnit[] getLexicalUnitList(LexicalUnit lu) {
- List lus = new ArrayList();
- while (lu != null) {
- lus.add(lu);
- lu = lu.getNextLexicalUnit();
- }
- return (LexicalUnit[]) lus.toArray(new LexicalUnit[lus.size()]);
- }
+ LexicalUnit[] lus = getLexicalUnitList(value);
+ if (lus.length >= 4) {
+ this.addDecl(CSS.BORDER_TOP_WIDTH, lus[0], important);
+ this.addDecl(CSS.BORDER_RIGHT_WIDTH, lus[1], important);
+ this.addDecl(CSS.BORDER_BOTTOM_WIDTH, lus[2], important);
+ this.addDecl(CSS.BORDER_LEFT_WIDTH, lus[3], important);
+ } else if (lus.length == 3) {
+ this.addDecl(CSS.BORDER_TOP_WIDTH, lus[0], important);
+ this.addDecl(CSS.BORDER_LEFT_WIDTH, lus[1], important);
+ this.addDecl(CSS.BORDER_RIGHT_WIDTH, lus[1], important);
+ this.addDecl(CSS.BORDER_BOTTOM_WIDTH, lus[2], important);
+ } else if (lus.length == 2) {
+ this.addDecl(CSS.BORDER_TOP_WIDTH, lus[0], important);
+ this.addDecl(CSS.BORDER_LEFT_WIDTH, lus[1], important);
+ this.addDecl(CSS.BORDER_RIGHT_WIDTH, lus[1], important);
+ this.addDecl(CSS.BORDER_BOTTOM_WIDTH, lus[0], important);
+ } else if (lus.length == 1) {
+ this.addDecl(CSS.BORDER_TOP_WIDTH, lus[0], important);
+ this.addDecl(CSS.BORDER_LEFT_WIDTH, lus[0], important);
+ this.addDecl(CSS.BORDER_RIGHT_WIDTH, lus[0], important);
+ this.addDecl(CSS.BORDER_BOTTOM_WIDTH, lus[0], important);
+ }
+ }
- }
+ /**
+ * Expand the "font" shorthand property.
+ */
+ private void expandFont(LexicalUnit value, boolean important) {
+
+ if (AbstractProperty.isInherit(value)) {
+ this.addDecl(CSS.FONT_STYLE, value, important);
+ this.addDecl(CSS.FONT_VARIANT, value, important);
+ this.addDecl(CSS.FONT_WEIGHT, value, important);
+ this.addDecl(CSS.FONT_SIZE, value, important);
+ this.addDecl(CSS.FONT_FAMILY, value, important);
+ return;
+ }
+
+ LexicalUnit[] lus = getLexicalUnitList(value);
+ int n = lus.length;
+ int i = 0;
+ if (i < n && FontStyleProperty.isFontStyle(lus[i])) {
+ this.addDecl(CSS.FONT_STYLE, lus[i], important);
+ i++;
+ }
+
+ if (i < n && FontVariantProperty.isFontVariant(lus[i])) {
+ this.addDecl(CSS.FONT_VARIANT, lus[i], important);
+ i++;
+ }
+
+ if (i < n && FontWeightProperty.isFontWeight(lus[i])) {
+ this.addDecl(CSS.FONT_WEIGHT, lus[i], important);
+ i++;
+ }
+
+ if (i < n && FontSizeProperty.isFontSize(lus[i])) {
+ this.addDecl(CSS.FONT_SIZE, lus[i], important);
+ i++;
+ }
+
+ if (i < n
+ && lus[i].getLexicalUnitType() == LexicalUnit.SAC_OPERATOR_SLASH) {
+ i++; // gobble slash
+ if (i < n) {
+ this.addDecl(CSS.LINE_HEIGHT, lus[i], important);
+ }
+ i++;
+ }
+
+ if (i < n) {
+ this.addDecl(CSS.FONT_FAMILY, lus[i], important);
+ }
+ }
+
+ /**
+ * Expand the "margin" shorthand property.
+ */
+ private void expandMargin(LexicalUnit value, boolean important) {
+
+ if (AbstractProperty.isInherit(value)) {
+ this.addDecl(CSS.MARGIN_TOP, value, important);
+ this.addDecl(CSS.MARGIN_RIGHT, value, important);
+ this.addDecl(CSS.MARGIN_BOTTOM, value, important);
+ this.addDecl(CSS.MARGIN_LEFT, value, important);
+ return;
+ }
+
+ LexicalUnit[] lus = getLexicalUnitList(value);
+ if (lus.length >= 4) {
+ this.addDecl(CSS.MARGIN_TOP, lus[0], important);
+ this.addDecl(CSS.MARGIN_RIGHT, lus[1], important);
+ this.addDecl(CSS.MARGIN_BOTTOM, lus[2], important);
+ this.addDecl(CSS.MARGIN_LEFT, lus[3], important);
+ } else if (lus.length == 3) {
+ this.addDecl(CSS.MARGIN_TOP, lus[0], important);
+ this.addDecl(CSS.MARGIN_LEFT, lus[1], important);
+ this.addDecl(CSS.MARGIN_RIGHT, lus[1], important);
+ this.addDecl(CSS.MARGIN_BOTTOM, lus[2], important);
+ } else if (lus.length == 2) {
+ this.addDecl(CSS.MARGIN_TOP, lus[0], important);
+ this.addDecl(CSS.MARGIN_LEFT, lus[1], important);
+ this.addDecl(CSS.MARGIN_RIGHT, lus[1], important);
+ this.addDecl(CSS.MARGIN_BOTTOM, lus[0], important);
+ } else if (lus.length == 1) {
+ this.addDecl(CSS.MARGIN_TOP, lus[0], important);
+ this.addDecl(CSS.MARGIN_LEFT, lus[0], important);
+ this.addDecl(CSS.MARGIN_RIGHT, lus[0], important);
+ this.addDecl(CSS.MARGIN_BOTTOM, lus[0], important);
+ }
+ }
+
+ /**
+ * Expand the "padding" shorthand property.
+ */
+ private void expandPadding(LexicalUnit value, boolean important) {
+
+ if (AbstractProperty.isInherit(value)) {
+ this.addDecl(CSS.PADDING_TOP, value, important);
+ this.addDecl(CSS.PADDING_LEFT, value, important);
+ this.addDecl(CSS.PADDING_RIGHT, value, important);
+ this.addDecl(CSS.PADDING_BOTTOM, value, important);
+ return;
+ }
+
+ LexicalUnit[] lus = getLexicalUnitList(value);
+ if (lus.length >= 4) {
+ this.addDecl(CSS.PADDING_TOP, lus[0], important);
+ this.addDecl(CSS.PADDING_RIGHT, lus[1], important);
+ this.addDecl(CSS.PADDING_BOTTOM, lus[2], important);
+ this.addDecl(CSS.PADDING_LEFT, lus[3], important);
+ } else if (lus.length == 3) {
+ this.addDecl(CSS.PADDING_TOP, lus[0], important);
+ this.addDecl(CSS.PADDING_LEFT, lus[1], important);
+ this.addDecl(CSS.PADDING_RIGHT, lus[1], important);
+ this.addDecl(CSS.PADDING_BOTTOM, lus[2], important);
+ } else if (lus.length == 2) {
+ this.addDecl(CSS.PADDING_TOP, lus[0], important);
+ this.addDecl(CSS.PADDING_LEFT, lus[1], important);
+ this.addDecl(CSS.PADDING_RIGHT, lus[1], important);
+ this.addDecl(CSS.PADDING_BOTTOM, lus[0], important);
+ } else if (lus.length == 1) {
+ this.addDecl(CSS.PADDING_TOP, lus[0], important);
+ this.addDecl(CSS.PADDING_LEFT, lus[0], important);
+ this.addDecl(CSS.PADDING_RIGHT, lus[0], important);
+ this.addDecl(CSS.PADDING_BOTTOM, lus[0], important);
+ }
+ }
+
+ /**
+ * Returns an array of <code>LexicalUnit</code> objects, the first of
+ * which is given.
+ */
+ private static LexicalUnit[] getLexicalUnitList(LexicalUnit lu) {
+ List lus = new ArrayList();
+ while (lu != null) {
+ lus.add(lu);
+ lu = lu.getNextLexicalUnit();
+ }
+ return (LexicalUnit[]) lus.toArray(new LexicalUnit[lus.size()]);
+ }
+
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/Styles.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/Styles.java
index 0a2a7d5..aaf72fe 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/Styles.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/Styles.java
@@ -18,318 +18,326 @@
import org.eclipse.wst.xml.vex.core.internal.core.Color;
import org.eclipse.wst.xml.vex.core.internal.core.FontSpec;
-
-
/**
* Represents the computed style properties for a particular element.
*/
public class Styles {
- /** Maps property name (String) => value (Object) */
- private Map values = new HashMap();
-
- private List content;
- private FontSpec font;
+ /** Maps property name (String) => value (Object) */
+ private Map values = new HashMap();
- /**
- * Returns the value of the given property, or null if the property
- * does not have a value.
- * @param propertyName
- * @return
- */
- public Object get(String propertyName) {
- return this.values.get(propertyName);
- }
-
- /**
- * Returns the value of the <code>backgroundColor</code> property.
- */
- public Color getBackgroundColor() {
- return (Color) this.values.get(CSS.BACKGROUND_COLOR);
- }
+ private List content;
+ private FontSpec font;
- /**
- * Returns the value of the <code>borderBottomColor</code> property.
- */
- public Color getBorderBottomColor() {
- return (Color) this.values.get(CSS.BORDER_BOTTOM_COLOR);
- }
+ /**
+ * Returns the value of the given property, or null if the property does not
+ * have a value.
+ *
+ * @param propertyName
+ * @return
+ */
+ public Object get(String propertyName) {
+ return this.values.get(propertyName);
+ }
- /**
- * Returns the value of the <code>borderBottomStyle</code> property.
- */
- public String getBorderBottomStyle() {
- return (String) this.values.get(CSS.BORDER_BOTTOM_STYLE);
- }
+ /**
+ * Returns the value of the <code>backgroundColor</code> property.
+ */
+ public Color getBackgroundColor() {
+ return (Color) this.values.get(CSS.BACKGROUND_COLOR);
+ }
- /**
- * Returns the value of the <code>borderLeftColor</code> property.
- */
- public Color getBorderLeftColor() {
- return (Color) this.values.get(CSS.BORDER_LEFT_COLOR);
- }
+ /**
+ * Returns the value of the <code>borderBottomColor</code> property.
+ */
+ public Color getBorderBottomColor() {
+ return (Color) this.values.get(CSS.BORDER_BOTTOM_COLOR);
+ }
- /**
- * Returns the value of the <code>borderLeftStyle</code> property.
- */
- public String getBorderLeftStyle() {
- return (String) this.values.get(CSS.BORDER_LEFT_STYLE);
- }
+ /**
+ * Returns the value of the <code>borderBottomStyle</code> property.
+ */
+ public String getBorderBottomStyle() {
+ return (String) this.values.get(CSS.BORDER_BOTTOM_STYLE);
+ }
- /**
- * Returns the value of the <code>borderRightColor</code> property.
- */
- public Color getBorderRightColor() {
- return (Color) this.values.get(CSS.BORDER_RIGHT_COLOR);
- }
+ /**
+ * Returns the value of the <code>borderLeftColor</code> property.
+ */
+ public Color getBorderLeftColor() {
+ return (Color) this.values.get(CSS.BORDER_LEFT_COLOR);
+ }
- /**
- * Returns the value of the <code>borderRightStyle</code> property.
- */
- public String getBorderRightStyle() {
- return (String) this.values.get(CSS.BORDER_RIGHT_STYLE);
- }
+ /**
+ * Returns the value of the <code>borderLeftStyle</code> property.
+ */
+ public String getBorderLeftStyle() {
+ return (String) this.values.get(CSS.BORDER_LEFT_STYLE);
+ }
- /**
- * Returns the value of the <code>borderSpacing</code> property.
- */
- public BorderSpacingProperty.Value getBorderSpacing() {
- return (BorderSpacingProperty.Value) this.values.get(CSS.BORDER_SPACING);
- }
+ /**
+ * Returns the value of the <code>borderRightColor</code> property.
+ */
+ public Color getBorderRightColor() {
+ return (Color) this.values.get(CSS.BORDER_RIGHT_COLOR);
+ }
- /**
- * Returns the value of the <code>borderTopColor</code> property.
- */
- public Color getBorderTopColor() {
- return (Color) this.values.get(CSS.BORDER_TOP_COLOR);
- }
+ /**
+ * Returns the value of the <code>borderRightStyle</code> property.
+ */
+ public String getBorderRightStyle() {
+ return (String) this.values.get(CSS.BORDER_RIGHT_STYLE);
+ }
- /**
- * Returns the value of the <code>borderTopStyle</code> property.
- */
- public String getBorderTopStyle() {
- return (String) this.values.get(CSS.BORDER_TOP_STYLE);
- }
+ /**
+ * Returns the value of the <code>borderSpacing</code> property.
+ */
+ public BorderSpacingProperty.Value getBorderSpacing() {
+ return (BorderSpacingProperty.Value) this.values
+ .get(CSS.BORDER_SPACING);
+ }
- /**
- * Returns the value of the <code>color</code> property.
- */
- public Color getColor() {
- return (Color) this.values.get(CSS.COLOR);
- }
+ /**
+ * Returns the value of the <code>borderTopColor</code> property.
+ */
+ public Color getBorderTopColor() {
+ return (Color) this.values.get(CSS.BORDER_TOP_COLOR);
+ }
- /**
- * Returns a <code>List</code> of <code>ContentPart</code> objects
- * representing the <code>content</code> property.
- */
- public List getContent() {
- return content;
- }
-
- /**
- * Returns the value of the <code>display</code> property.
- */
- public String getDisplay() {
- return (String) this.values.get(CSS.DISPLAY);
- }
+ /**
+ * Returns the value of the <code>borderTopStyle</code> property.
+ */
+ public String getBorderTopStyle() {
+ return (String) this.values.get(CSS.BORDER_TOP_STYLE);
+ }
- /**
- * Returns the value of the <code>font</code> property.
- */
- public FontSpec getFont() {
- return font;
- }
+ /**
+ * Returns the value of the <code>color</code> property.
+ */
+ public Color getColor() {
+ return (Color) this.values.get(CSS.COLOR);
+ }
- /**
- * Returns the value of the <code>fontFamily</code> property.
- */
- public String[] getFontFamilies() {
- return (String[]) this.values.get(CSS.FONT_FAMILY);
- }
+ /**
+ * Returns a <code>List</code> of <code>ContentPart</code> objects
+ * representing the <code>content</code> property.
+ */
+ public List getContent() {
+ return content;
+ }
- /**
- * Returns the value of the <code>fontSize</code> property.
- */
- public float getFontSize() {
- return ((Float) this.values.get(CSS.FONT_SIZE)).floatValue();
- }
+ /**
+ * Returns the value of the <code>display</code> property.
+ */
+ public String getDisplay() {
+ return (String) this.values.get(CSS.DISPLAY);
+ }
- /**
- * Returns the value of the <code>fontStyle</code> property.
- */
- public String getFontStyle() {
- return (String) this.values.get(CSS.FONT_STYLE);
- }
+ /**
+ * Returns the value of the <code>font</code> property.
+ */
+ public FontSpec getFont() {
+ return font;
+ }
- /**
- * Returns the value of the <code>fontWeight</code> property.
- */
- public int getFontWeight() {
- return ((Integer) this.values.get(CSS.FONT_WEIGHT)).intValue();
- }
+ /**
+ * Returns the value of the <code>fontFamily</code> property.
+ */
+ public String[] getFontFamilies() {
+ return (String[]) this.values.get(CSS.FONT_FAMILY);
+ }
- /**
- * Returns the value of the <code>lineHeight</code> property.
- */
- public int getLineHeight() {
- return ((RelativeLength) this.values.get(CSS.LINE_HEIGHT)).get(Math.round(this.getFontSize()));
- }
+ /**
+ * Returns the value of the <code>fontSize</code> property.
+ */
+ public float getFontSize() {
+ return ((Float) this.values.get(CSS.FONT_SIZE)).floatValue();
+ }
- /**
- * Returns the value of the <code>listStyleType</code> property.
- */
- public String getListStyleType() {
- return (String) this.values.get(CSS.LIST_STYLE_TYPE);
- }
+ /**
+ * Returns the value of the <code>fontStyle</code> property.
+ */
+ public String getFontStyle() {
+ return (String) this.values.get(CSS.FONT_STYLE);
+ }
- /**
- * Returns the value of the <code>textAlign</code> property.
- */
- public String getTextAlign() {
- return (String) this.values.get(CSS.TEXT_ALIGN);
- }
+ /**
+ * Returns the value of the <code>fontWeight</code> property.
+ */
+ public int getFontWeight() {
+ return ((Integer) this.values.get(CSS.FONT_WEIGHT)).intValue();
+ }
- /**
- * Returns the value of the <code>textDecoration</code> property.
- */
- public String getTextDecoration() {
- return (String) this.values.get(CSS.TEXT_DECORATION);
- }
+ /**
+ * Returns the value of the <code>lineHeight</code> property.
+ */
+ public int getLineHeight() {
+ return ((RelativeLength) this.values.get(CSS.LINE_HEIGHT)).get(Math
+ .round(this.getFontSize()));
+ }
- /**
- * Returns the value of the <code>whiteSpace</code> property.
- */
- public String getWhiteSpace() {
- return (String) this.values.get(CSS.WHITE_SPACE);
- }
-
- /**
- * Returns true if this element is block-formatted, or false if it
- * is inline-formatted.
- */
- public boolean isBlock() {
- return this.getDisplay().equals(CSS.BLOCK)
- || this.getDisplay().equals(CSS.LIST_ITEM)
- || this.getDisplay().equals(CSS.TABLE)
- || this.getDisplay().equals(CSS.TABLE_CAPTION)
- || this.getDisplay().equals(CSS.TABLE_CELL)
- || this.getDisplay().equals(CSS.TABLE_COLUMN)
- || this.getDisplay().equals(CSS.TABLE_COLUMN_GROUP)
- || this.getDisplay().equals(CSS.TABLE_FOOTER_GROUP)
- || this.getDisplay().equals(CSS.TABLE_HEADER_GROUP)
- || this.getDisplay().equals(CSS.TABLE_ROW)
- || this.getDisplay().equals(CSS.TABLE_ROW_GROUP);
- }
+ /**
+ * Returns the value of the <code>listStyleType</code> property.
+ */
+ public String getListStyleType() {
+ return (String) this.values.get(CSS.LIST_STYLE_TYPE);
+ }
- /**
- * Sets the value of a property in this stylesheet.
- * @param propertyName Name of the property being set.
- * @param value Value of the property.
- */
- public void put(String propertyName, Object value) {
- this.values.put(propertyName, value);
- }
-
- /**
- * Sets the vale of the <code>content</code> property.
- * @param content <code>List</code> of <code>ContentPart</code> objects
- * representing the content.
- */
- public void setContent(List content) {
- this.content = content;
- }
-
- /**
- * Sets the value of the <code>font</code> property.
- * @param font new value for the <code>font</code> property.
- */
- public void setFont(FontSpec font) {
- this.font = font;
- }
+ /**
+ * Returns the value of the <code>textAlign</code> property.
+ */
+ public String getTextAlign() {
+ return (String) this.values.get(CSS.TEXT_ALIGN);
+ }
- /**
- * @return the value of border-bottom-width
- */
- public int getBorderBottomWidth() {
- return ((Integer) this.values.get(CSS.BORDER_BOTTOM_WIDTH)).intValue();
- }
+ /**
+ * Returns the value of the <code>textDecoration</code> property.
+ */
+ public String getTextDecoration() {
+ return (String) this.values.get(CSS.TEXT_DECORATION);
+ }
- /**
- * @return the value of border-left-width
- */
- public int getBorderLeftWidth() {
- return ((Integer) this.values.get(CSS.BORDER_LEFT_WIDTH)).intValue();
- }
+ /**
+ * Returns the value of the <code>whiteSpace</code> property.
+ */
+ public String getWhiteSpace() {
+ return (String) this.values.get(CSS.WHITE_SPACE);
+ }
- /**
- * @return the value of border-right-width
- */
- public int getBorderRightWidth() {
- return ((Integer) this.values.get(CSS.BORDER_RIGHT_WIDTH)).intValue();
- }
+ /**
+ * Returns true if this element is block-formatted, or false if it is
+ * inline-formatted.
+ */
+ public boolean isBlock() {
+ return this.getDisplay().equals(CSS.BLOCK)
+ || this.getDisplay().equals(CSS.LIST_ITEM)
+ || this.getDisplay().equals(CSS.TABLE)
+ || this.getDisplay().equals(CSS.TABLE_CAPTION)
+ || this.getDisplay().equals(CSS.TABLE_CELL)
+ || this.getDisplay().equals(CSS.TABLE_COLUMN)
+ || this.getDisplay().equals(CSS.TABLE_COLUMN_GROUP)
+ || this.getDisplay().equals(CSS.TABLE_FOOTER_GROUP)
+ || this.getDisplay().equals(CSS.TABLE_HEADER_GROUP)
+ || this.getDisplay().equals(CSS.TABLE_ROW)
+ || this.getDisplay().equals(CSS.TABLE_ROW_GROUP);
+ }
- /**
- * @return the value of border-top-width
- */
- public int getBorderTopWidth() {
- return ((Integer) this.values.get(CSS.BORDER_TOP_WIDTH)).intValue();
- }
+ /**
+ * Sets the value of a property in this stylesheet.
+ *
+ * @param propertyName
+ * Name of the property being set.
+ * @param value
+ * Value of the property.
+ */
+ public void put(String propertyName, Object value) {
+ this.values.put(propertyName, value);
+ }
- /**
- * @return the value of margin-bottom
- */
- public RelativeLength getMarginBottom() {
- return (RelativeLength) this.values.get(CSS.MARGIN_BOTTOM);
- //return marginBottom;
- }
+ /**
+ * Sets the vale of the <code>content</code> property.
+ *
+ * @param content
+ * <code>List</code> of <code>ContentPart</code> objects
+ * representing the content.
+ */
+ public void setContent(List content) {
+ this.content = content;
+ }
- /**
- * @return the value of margin-left
- */
- public RelativeLength getMarginLeft() {
- return (RelativeLength) this.values.get(CSS.MARGIN_LEFT);
- }
+ /**
+ * Sets the value of the <code>font</code> property.
+ *
+ * @param font
+ * new value for the <code>font</code> property.
+ */
+ public void setFont(FontSpec font) {
+ this.font = font;
+ }
- /**
- * @return the value of margin-right
- */
- public RelativeLength getMarginRight() {
- return (RelativeLength) this.values.get(CSS.MARGIN_RIGHT);
- }
+ /**
+ * @return the value of border-bottom-width
+ */
+ public int getBorderBottomWidth() {
+ return ((Integer) this.values.get(CSS.BORDER_BOTTOM_WIDTH)).intValue();
+ }
- /**
- * @return the value of margin-top
- */
- public RelativeLength getMarginTop() {
- return (RelativeLength) this.values.get(CSS.MARGIN_TOP);
- }
+ /**
+ * @return the value of border-left-width
+ */
+ public int getBorderLeftWidth() {
+ return ((Integer) this.values.get(CSS.BORDER_LEFT_WIDTH)).intValue();
+ }
- /**
- * @return the value of padding-bottom
- */
- public RelativeLength getPaddingBottom() {
- return (RelativeLength) this.values.get(CSS.PADDING_BOTTOM);
- }
+ /**
+ * @return the value of border-right-width
+ */
+ public int getBorderRightWidth() {
+ return ((Integer) this.values.get(CSS.BORDER_RIGHT_WIDTH)).intValue();
+ }
- /**
- * @return the value of padding-left
- */
- public RelativeLength getPaddingLeft() {
- return (RelativeLength) this.values.get(CSS.PADDING_LEFT);
- }
+ /**
+ * @return the value of border-top-width
+ */
+ public int getBorderTopWidth() {
+ return ((Integer) this.values.get(CSS.BORDER_TOP_WIDTH)).intValue();
+ }
- /**
- * @return the value of padding-right
- */
- public RelativeLength getPaddingRight() {
- return (RelativeLength) this.values.get(CSS.PADDING_RIGHT);
- }
+ /**
+ * @return the value of margin-bottom
+ */
+ public RelativeLength getMarginBottom() {
+ return (RelativeLength) this.values.get(CSS.MARGIN_BOTTOM);
+ // return marginBottom;
+ }
- /**
- * @return the value of padding-top
- */
- public RelativeLength getPaddingTop() {
- return (RelativeLength) this.values.get(CSS.PADDING_TOP);
- }
+ /**
+ * @return the value of margin-left
+ */
+ public RelativeLength getMarginLeft() {
+ return (RelativeLength) this.values.get(CSS.MARGIN_LEFT);
+ }
+
+ /**
+ * @return the value of margin-right
+ */
+ public RelativeLength getMarginRight() {
+ return (RelativeLength) this.values.get(CSS.MARGIN_RIGHT);
+ }
+
+ /**
+ * @return the value of margin-top
+ */
+ public RelativeLength getMarginTop() {
+ return (RelativeLength) this.values.get(CSS.MARGIN_TOP);
+ }
+
+ /**
+ * @return the value of padding-bottom
+ */
+ public RelativeLength getPaddingBottom() {
+ return (RelativeLength) this.values.get(CSS.PADDING_BOTTOM);
+ }
+
+ /**
+ * @return the value of padding-left
+ */
+ public RelativeLength getPaddingLeft() {
+ return (RelativeLength) this.values.get(CSS.PADDING_LEFT);
+ }
+
+ /**
+ * @return the value of padding-right
+ */
+ public RelativeLength getPaddingRight() {
+ return (RelativeLength) this.values.get(CSS.PADDING_RIGHT);
+ }
+
+ /**
+ * @return the value of padding-top
+ */
+ public RelativeLength getPaddingTop() {
+ return (RelativeLength) this.values.get(CSS.PADDING_TOP);
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/TextAlignProperty.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/TextAlignProperty.java
index c67d9c2..7cc1dbc 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/TextAlignProperty.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/TextAlignProperty.java
@@ -17,37 +17,37 @@
*/
public class TextAlignProperty extends AbstractProperty {
- /**
- * Class constructor
- */
- public TextAlignProperty() {
- super(CSS.TEXT_ALIGN);
- }
+ /**
+ * Class constructor
+ */
+ public TextAlignProperty() {
+ super(CSS.TEXT_ALIGN);
+ }
- public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles) {
- if (TextAlignProperty.isTextAlign(lu)) {
- return lu.getStringValue();
- } else {
- // not specified, "inherit", or some other value
- if (parentStyles != null) {
- return parentStyles.getTextAlign();
- } else {
- return CSS.LEFT;
- }
- }
+ public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles) {
+ if (TextAlignProperty.isTextAlign(lu)) {
+ return lu.getStringValue();
+ } else {
+ // not specified, "inherit", or some other value
+ if (parentStyles != null) {
+ return parentStyles.getTextAlign();
+ } else {
+ return CSS.LEFT;
+ }
+ }
- }
+ }
- //=================================================== PRIVATE
-
- private static boolean isTextAlign(LexicalUnit lu) {
- if (lu == null) {
- return false;
- } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
- return true;
- } else {
- return false;
- }
- }
+ // =================================================== PRIVATE
+
+ private static boolean isTextAlign(LexicalUnit lu) {
+ if (lu == null) {
+ return false;
+ } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
+ return true;
+ } else {
+ return false;
+ }
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/TextDecorationProperty.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/TextDecorationProperty.java
index ceb2f7d..8e40cda 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/TextDecorationProperty.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/TextDecorationProperty.java
@@ -17,46 +17,45 @@
*/
public class TextDecorationProperty extends AbstractProperty {
- /**
- * Class constructor.
- */
- public TextDecorationProperty() {
- super(CSS.TEXT_DECORATION);
- }
+ /**
+ * Class constructor.
+ */
+ public TextDecorationProperty() {
+ super(CSS.TEXT_DECORATION);
+ }
- public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles) {
- if (isTextDecoration(lu)) {
- return lu.getStringValue();
- } else {
- // not specified, "inherit", or some other value
- if (parentStyles != null) {
- return parentStyles.getTextDecoration();
- } else {
- return CSS.NONE;
- }
- }
- }
+ public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles) {
+ if (isTextDecoration(lu)) {
+ return lu.getStringValue();
+ } else {
+ // not specified, "inherit", or some other value
+ if (parentStyles != null) {
+ return parentStyles.getTextDecoration();
+ } else {
+ return CSS.NONE;
+ }
+ }
+ }
- //=================================================== PRIVATE
-
- /**
- * Returns true if the given lexical unit represents a text decoration.
- *
- * @param lu LexicalUnit to check.
- */
- private static boolean isTextDecoration(LexicalUnit lu) {
- if (lu == null) {
- return false;
- } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
- String s = lu.getStringValue();
- return s.equals(CSS.NONE)
- || s.equals(CSS.UNDERLINE)
- || s.equals(CSS.OVERLINE)
- || s.equals(CSS.LINE_THROUGH)
- || s.equals(CSS.BLINK);
- } else {
- return false;
- }
- }
+ // =================================================== PRIVATE
+
+ /**
+ * Returns true if the given lexical unit represents a text decoration.
+ *
+ * @param lu
+ * LexicalUnit to check.
+ */
+ private static boolean isTextDecoration(LexicalUnit lu) {
+ if (lu == null) {
+ return false;
+ } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
+ String s = lu.getStringValue();
+ return s.equals(CSS.NONE) || s.equals(CSS.UNDERLINE)
+ || s.equals(CSS.OVERLINE) || s.equals(CSS.LINE_THROUGH)
+ || s.equals(CSS.BLINK);
+ } else {
+ return false;
+ }
+ }
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/WhiteSpaceProperty.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/WhiteSpaceProperty.java
index ef60a50..5929c48 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/WhiteSpaceProperty.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/WhiteSpaceProperty.java
@@ -17,47 +17,47 @@
*/
public class WhiteSpaceProperty extends AbstractProperty {
- /**
- * Class constructor.
- */
- public WhiteSpaceProperty() {
- super(CSS.WHITE_SPACE);
- }
+ /**
+ * Class constructor.
+ */
+ public WhiteSpaceProperty() {
+ super(CSS.WHITE_SPACE);
+ }
- /**
+ /**
*
*/
- public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles) {
- if (isWhiteSpace(lu)) {
- return lu.getStringValue();
- } else {
- // not specified, "inherit", or some other value
- if (parentStyles != null) {
- return parentStyles.getWhiteSpace();
- } else {
- return CSS.NORMAL;
- }
- }
-
- }
+ public Object calculate(LexicalUnit lu, Styles parentStyles, Styles styles) {
+ if (isWhiteSpace(lu)) {
+ return lu.getStringValue();
+ } else {
+ // not specified, "inherit", or some other value
+ if (parentStyles != null) {
+ return parentStyles.getWhiteSpace();
+ } else {
+ return CSS.NORMAL;
+ }
+ }
- /**
- * Returns true if the given lexical unit represents a white space value.
- *
- * @param lu LexicalUnit to check.
- */
- public static boolean isWhiteSpace(LexicalUnit lu) {
- if (lu == null) {
- return false;
- } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
- String s = lu.getStringValue();
- return s.equals(CSS.NORMAL)
- || s.equals(CSS.PRE)
- || s.equals(CSS.NOWRAP);
- } else {
- return false;
- }
- }
-
+ }
+
+ /**
+ * Returns true if the given lexical unit represents a white space value.
+ *
+ * @param lu
+ * LexicalUnit to check.
+ */
+ public static boolean isWhiteSpace(LexicalUnit lu) {
+ if (lu == null) {
+ return false;
+ } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
+ String s = lu.getStringValue();
+ return s.equals(CSS.NORMAL) || s.equals(CSS.PRE)
+ || s.equals(CSS.NOWRAP);
+ } else {
+ return false;
+ }
+ }
+
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/dom/AbstractValidator.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/dom/AbstractValidator.java
index 4138c4b..2a999c4 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/dom/AbstractValidator.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/dom/AbstractValidator.java
@@ -18,46 +18,41 @@
*/
public abstract class AbstractValidator implements Validator {
-
- /**
- * @see Validator#isValidSequence
- */
- public boolean isValidSequence(
- String element,
- String[] seq1,
- String[] seq2,
- String[] seq3,
- boolean partial) {
-
- List list = new ArrayList();
- for (int i = 0; i < seq1.length; i++) {
- list.add(seq1[i]);
- }
- if (seq2 != null) {
- for (int i = 0; i < seq2.length; i++) {
- if (i == 0 && seq2[i].equals(Validator.PCDATA) && list.size() > 0
- && list.get(list.size() - 1).equals(Validator.PCDATA)) {
- // Avoid consecutive PCDATA's
- continue;
- }
- list.add(seq2[i]);
- }
- }
- if (seq3 != null) {
- for (int i = 0; i < seq3.length; i++) {
- if (i == 0 && seq3[i].equals(Validator.PCDATA) && list.size() > 0
- && list.get(list.size() - 1).equals(Validator.PCDATA)) {
- // Avoid consecutive PCDATA's
- continue;
- }
- list.add(seq3[i]);
- }
- }
+ /**
+ * @see Validator#isValidSequence
+ */
+ public boolean isValidSequence(String element, String[] seq1,
+ String[] seq2, String[] seq3, boolean partial) {
- String[] nodes = (String[]) list.toArray(new String[list.size()]);
- return this.isValidSequence(element, nodes, partial);
- }
+ List list = new ArrayList();
+ for (int i = 0; i < seq1.length; i++) {
+ list.add(seq1[i]);
+ }
+ if (seq2 != null) {
+ for (int i = 0; i < seq2.length; i++) {
+ if (i == 0 && seq2[i].equals(Validator.PCDATA)
+ && list.size() > 0
+ && list.get(list.size() - 1).equals(Validator.PCDATA)) {
+ // Avoid consecutive PCDATA's
+ continue;
+ }
+ list.add(seq2[i]);
+ }
+ }
+ if (seq3 != null) {
+ for (int i = 0; i < seq3.length; i++) {
+ if (i == 0 && seq3[i].equals(Validator.PCDATA)
+ && list.size() > 0
+ && list.get(list.size() - 1).equals(Validator.PCDATA)) {
+ // Avoid consecutive PCDATA's
+ continue;
+ }
+ list.add(seq3[i]);
+ }
+ }
+ String[] nodes = (String[]) list.toArray(new String[list.size()]);
+ return this.isValidSequence(element, nodes, partial);
+ }
}
-
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/dom/AttributeDefinition.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/dom/AttributeDefinition.java
index ca5ffe9..fd43bbc 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/dom/AttributeDefinition.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/dom/AttributeDefinition.java
@@ -13,153 +13,146 @@
import java.io.ObjectStreamException;
import java.io.Serializable;
-
/**
* <code>AttributeDefinition</code> represents an attribute definition in a DTD.
*/
public class AttributeDefinition implements Comparable, Serializable {
- private String name;
- private Type type;
- private String defaultValue;
- private String[] values;
- private boolean required;
- private boolean fixed;
+ private String name;
+ private Type type;
+ private String defaultValue;
+ private String[] values;
+ private boolean required;
+ private boolean fixed;
- /**
- * Enumeration of attribute types.
- */
- public static final class Type implements Serializable {
+ /**
+ * Enumeration of attribute types.
+ */
+ public static final class Type implements Serializable {
- private String s;
+ private String s;
- public static final Type CDATA = new Type("CDATA");
- public static final Type ID = new Type("ID");
- public static final Type IDREF = new Type("IDREF");
- public static final Type IDREFS = new Type("IDREFS");
- public static final Type NMTOKEN = new Type("NMTOKEN");
- public static final Type NMTOKENS = new Type("NMTOKENS");
- public static final Type ENTITY = new Type("ENTITY");
- public static final Type ENTITIES = new Type("ENTITIES");
- public static final Type NOTATION = new Type("NOTATION");
- public static final Type ENUMERATION = new Type("ENUMERATION");
+ public static final Type CDATA = new Type("CDATA");
+ public static final Type ID = new Type("ID");
+ public static final Type IDREF = new Type("IDREF");
+ public static final Type IDREFS = new Type("IDREFS");
+ public static final Type NMTOKEN = new Type("NMTOKEN");
+ public static final Type NMTOKENS = new Type("NMTOKENS");
+ public static final Type ENTITY = new Type("ENTITY");
+ public static final Type ENTITIES = new Type("ENTITIES");
+ public static final Type NOTATION = new Type("NOTATION");
+ public static final Type ENUMERATION = new Type("ENUMERATION");
- private Type(String s) {
- this.s = s;
- }
+ private Type(String s) {
+ this.s = s;
+ }
- public static Type get(String s) {
- if (s.equals(CDATA.toString())) {
- return CDATA;
- } else if (s.equals(ID.toString())) {
- return ID;
- } else if (s.equals(IDREF.toString())) {
- return IDREF;
- } else if (s.equals(IDREFS.toString())) {
- return IDREFS;
- } else if (s.equals(NMTOKEN.toString())) {
- return NMTOKEN;
- } else if (s.equals(NMTOKENS.toString())) {
- return NMTOKENS;
- } else if (s.equals(ENTITY.toString())) {
- return ENTITY;
- } else if (s.equals(ENTITIES.toString())) {
- return ENTITIES;
- } else if (s.equals(NOTATION.toString())) {
- return NOTATION;
- } else if (s.equals(ENUMERATION.toString())) {
- return ENUMERATION;
- } else {
- throw new IllegalArgumentException(
- "Attribute type '" + s + "' not recognized");
- }
- }
+ public static Type get(String s) {
+ if (s.equals(CDATA.toString())) {
+ return CDATA;
+ } else if (s.equals(ID.toString())) {
+ return ID;
+ } else if (s.equals(IDREF.toString())) {
+ return IDREF;
+ } else if (s.equals(IDREFS.toString())) {
+ return IDREFS;
+ } else if (s.equals(NMTOKEN.toString())) {
+ return NMTOKEN;
+ } else if (s.equals(NMTOKENS.toString())) {
+ return NMTOKENS;
+ } else if (s.equals(ENTITY.toString())) {
+ return ENTITY;
+ } else if (s.equals(ENTITIES.toString())) {
+ return ENTITIES;
+ } else if (s.equals(NOTATION.toString())) {
+ return NOTATION;
+ } else if (s.equals(ENUMERATION.toString())) {
+ return ENUMERATION;
+ } else {
+ throw new IllegalArgumentException("Attribute type '" + s
+ + "' not recognized");
+ }
+ }
- public String toString() {
- return this.s;
- }
-
- /**
- * Serialization method, to ensure that we do not introduce new
- * instances.
- */
- private Object readResolve() throws ObjectStreamException {
- return get(this.toString());
- }
- }
+ public String toString() {
+ return this.s;
+ }
+ /**
+ * Serialization method, to ensure that we do not introduce new
+ * instances.
+ */
+ private Object readResolve() throws ObjectStreamException {
+ return get(this.toString());
+ }
+ }
- /**
- * Class constructor.
- */
- public AttributeDefinition(
- String name,
- Type type,
- String defaultValue,
- String[] values,
- boolean required,
- boolean fixed) {
-
- this.name = name;
- this.type = type;
- this.defaultValue = defaultValue;
- this.values = values;
- this.required = required;
- this.fixed = fixed;
- }
+ /**
+ * Class constructor.
+ */
+ public AttributeDefinition(String name, Type type, String defaultValue,
+ String[] values, boolean required, boolean fixed) {
- /**
- * Implements <code>Comparable.compareTo</code> to sort alphabetically
- * by name.
- *
- * @param other The attribute to which this one is to be compared.
- */
- public int compareTo(Object other) {
- return this.name.compareTo(((AttributeDefinition)other).name);
- }
+ this.name = name;
+ this.type = type;
+ this.defaultValue = defaultValue;
+ this.values = values;
+ this.required = required;
+ this.fixed = fixed;
+ }
- /**
- * Returns the attribute's type.
- */
- public Type getType() {
- return this.type;
- }
+ /**
+ * Implements <code>Comparable.compareTo</code> to sort alphabetically by
+ * name.
+ *
+ * @param other
+ * The attribute to which this one is to be compared.
+ */
+ public int compareTo(Object other) {
+ return this.name.compareTo(((AttributeDefinition) other).name);
+ }
- /**
- * Returns the default value of the attribute.
- */
- public String getDefaultValue() {
- return defaultValue;
- }
+ /**
+ * Returns the attribute's type.
+ */
+ public Type getType() {
+ return this.type;
+ }
- /**
- * Returns true if the attribute value is fixed.
- */
- public boolean isFixed() {
- return fixed;
- }
+ /**
+ * Returns the default value of the attribute.
+ */
+ public String getDefaultValue() {
+ return defaultValue;
+ }
- /**
- * Returns the name of the attribute.
- */
- public String getName() {
- return name;
- }
+ /**
+ * Returns true if the attribute value is fixed.
+ */
+ public boolean isFixed() {
+ return fixed;
+ }
- /**
- * Returns true if the attribute is required.
- */
- public boolean isRequired() {
- return required;
- }
+ /**
+ * Returns the name of the attribute.
+ */
+ public String getName() {
+ return name;
+ }
- /**
- * Returns an array of acceptable values for the attribute.
- * If null is returned, any value is acceptable for the attribute.
- */
- public String[] getValues() {
- return values;
- }
+ /**
+ * Returns true if the attribute is required.
+ */
+ public boolean isRequired() {
+ return required;
+ }
+
+ /**
+ * Returns an array of acceptable values for the attribute. If null is
+ * returned, any value is acceptable for the attribute.
+ */
+ public String[] getValues() {
+ return values;
+ }
}
-
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/dom/Content.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/dom/Content.java
index 758f3e8..0a42f50 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/dom/Content.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/dom/Content.java
@@ -11,44 +11,51 @@
package org.eclipse.wst.xml.vex.core.internal.dom;
/**
- * Interface for classes that manage a string of characters representing
- * the content of a document.
+ * Interface for classes that manage a string of characters representing the
+ * content of a document.
*/
public interface Content {
- /**
- * Creates a new Position object at the given initial offset.
- *
- * @param offset initial offset of the position
- */
- public Position createPosition(int offset);
+ /**
+ * Creates a new Position object at the given initial offset.
+ *
+ * @param offset
+ * initial offset of the position
+ */
+ public Position createPosition(int offset);
- /**
- * Insert a string into the content.
- *
- * @param offset Offset at which to insert the string.
- * @param s String to insert.
- */
- public void insertString(int offset, String s);
+ /**
+ * Insert a string into the content.
+ *
+ * @param offset
+ * Offset at which to insert the string.
+ * @param s
+ * String to insert.
+ */
+ public void insertString(int offset, String s);
- /**
- * Deletes the given range of characters.
- *
- * @param offset Offset from which characters should be deleted.
- * @param length Number of characters to delete.
- */
- public void remove(int offset, int length);
+ /**
+ * Deletes the given range of characters.
+ *
+ * @param offset
+ * Offset from which characters should be deleted.
+ * @param length
+ * Number of characters to delete.
+ */
+ public void remove(int offset, int length);
- /**
- * Gets a substring of the content.
- *
- * @param offset Offset at which the string begins.
- * @param length Number of characters to return.
- */
- public String getString(int offset, int length);
+ /**
+ * Gets a substring of the content.
+ *
+ * @param offset
+ * Offset at which the string begins.
+ * @param length
+ * Number of characters to return.
+ */
+ public String getString(int offset, int length);
- /**
- * Return the length of the content.
- */
- public int getLength();
+ /**
+ * Return the length of the content.
+ */
+ public int getLength();
}
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/dom/DFABuilder.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/dom/DFABuilder.java
index 5e4671c..088d607 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/dom/DFABuilder.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/dom/DFABuilder.java
@@ -18,481 +18,487 @@
import java.util.Set;
import java.util.Stack;
-
/**
- * Tools for building a deterministic finite automaton (DFA)
- * recognizer for regular expression-like languages.
+ * Tools for building a deterministic finite automaton (DFA) recognizer for
+ * regular expression-like languages.
*/
public class DFABuilder {
- /**
- * Node represents a node in an abstract syntax tree. The first
- * step to creating a DFA is to build an AST using the given
- * createXxx methods.
- */
- public interface Node {
- public void accept(NodeVisitor visitor);
- public Object clone();
- public Set getFirstPos();
- public Set getLastPos();
- public boolean isNullable();
- }
+ /**
+ * Node represents a node in an abstract syntax tree. The first step to
+ * creating a DFA is to build an AST using the given createXxx methods.
+ */
+ public interface Node {
+ public void accept(NodeVisitor visitor);
- /**
- * Create a node that represents a choice between two nodes.
- *
- * @param child1 first choice
- * @param child2 second choice
- */
- public static Node createChoiceNode(Node child1, Node child2) {
- return new OrNode(child1, child2);
- }
+ public Object clone();
- /**
- * Create a DFA given the root node of the syntax tree.
- *
- * @return Initial state of the resulting DFA.
- * @param root Root node of the syntax tree.
- */
- public static DFAState createDFA(Node root) {
+ public Set getFirstPos();
- // Append a sentinel to indicate accepting states.
- SymbolNode sentinelNode = new SymbolNode(Sentinel.getInstance());
- Node fakeRoot = new CatNode(root, sentinelNode);
+ public Set getLastPos();
- // map symbol node set => state in the new DFA
- Map stateMap = new HashMap();
-
- // symbol node sets we have considered
- Set marked = new HashSet();
-
- // stack of symbol node sets we have yet to consider
- Stack unmarked = new Stack();
-
- // calculate followPos and symbolMap
- FollowPosBuilder fpb = new FollowPosBuilder();
- fakeRoot.accept(fpb);
-
- // map symbol node => set of symbol nodes that follow it
- Map followPos = fpb.getFollowPos();
-
- // map symbol => set of symbol nodes that represent it
- Map symbolMap = fpb.getSymbolMap();
-
- Set nodeSet = fakeRoot.getFirstPos();
- DFAState startState = new DFAState();
- if (nodeSet.contains(sentinelNode)) {
- startState.setAccepting(true);
+ public boolean isNullable();
}
- stateMap.put(nodeSet, startState);
+ /**
+ * Create a node that represents a choice between two nodes.
+ *
+ * @param child1
+ * first choice
+ * @param child2
+ * second choice
+ */
+ public static Node createChoiceNode(Node child1, Node child2) {
+ return new OrNode(child1, child2);
+ }
- unmarked.push(nodeSet);
+ /**
+ * Create a DFA given the root node of the syntax tree.
+ *
+ * @return Initial state of the resulting DFA.
+ * @param root
+ * Root node of the syntax tree.
+ */
+ public static DFAState createDFA(Node root) {
- while (unmarked.size() > 0) {
- nodeSet = (Set) unmarked.pop();
- marked.add(nodeSet);
- DFAState state = (DFAState) stateMap.get(nodeSet);
- if (state == null) {
- state = new DFAState();
- stateMap.put(nodeSet, state);
- }
+ // Append a sentinel to indicate accepting states.
+ SymbolNode sentinelNode = new SymbolNode(Sentinel.getInstance());
+ Node fakeRoot = new CatNode(root, sentinelNode);
- Iterator iterSymbols = symbolMap.keySet().iterator();
- while (iterSymbols.hasNext()) {
- Object symbol = iterSymbols.next();
- Set targetSet = new HashSet();
- Iterator iterNodes = nodeSet.iterator();
- while (iterNodes.hasNext()) {
- SymbolNode node = (SymbolNode) iterNodes.next();
- if (node.getSymbol().equals(symbol)) {
- targetSet.addAll((Set)followPos.get(node));
- }
+ // map symbol node set => state in the new DFA
+ Map stateMap = new HashMap();
+
+ // symbol node sets we have considered
+ Set marked = new HashSet();
+
+ // stack of symbol node sets we have yet to consider
+ Stack unmarked = new Stack();
+
+ // calculate followPos and symbolMap
+ FollowPosBuilder fpb = new FollowPosBuilder();
+ fakeRoot.accept(fpb);
+
+ // map symbol node => set of symbol nodes that follow it
+ Map followPos = fpb.getFollowPos();
+
+ // map symbol => set of symbol nodes that represent it
+ Map symbolMap = fpb.getSymbolMap();
+
+ Set nodeSet = fakeRoot.getFirstPos();
+ DFAState startState = new DFAState();
+ if (nodeSet.contains(sentinelNode)) {
+ startState.setAccepting(true);
}
- if (!targetSet.isEmpty()) {
- if (!unmarked.contains(targetSet)
- && !marked.contains(targetSet)) {
+ stateMap.put(nodeSet, startState);
- unmarked.push(targetSet);
- }
+ unmarked.push(nodeSet);
- DFAState targetState = (DFAState)
- stateMap.get(targetSet);
-
- if (targetState == null) {
- targetState = new DFAState();
- if (targetSet.contains(sentinelNode)) {
- targetState.setAccepting(true);
+ while (unmarked.size() > 0) {
+ nodeSet = (Set) unmarked.pop();
+ marked.add(nodeSet);
+ DFAState state = (DFAState) stateMap.get(nodeSet);
+ if (state == null) {
+ state = new DFAState();
+ stateMap.put(nodeSet, state);
}
- stateMap.put(targetSet, targetState);
- }
- state.addTransition(symbol, targetState);
+ Iterator iterSymbols = symbolMap.keySet().iterator();
+ while (iterSymbols.hasNext()) {
+ Object symbol = iterSymbols.next();
+ Set targetSet = new HashSet();
+ Iterator iterNodes = nodeSet.iterator();
+ while (iterNodes.hasNext()) {
+ SymbolNode node = (SymbolNode) iterNodes.next();
+ if (node.getSymbol().equals(symbol)) {
+ targetSet.addAll((Set) followPos.get(node));
+ }
+ }
+
+ if (!targetSet.isEmpty()) {
+ if (!unmarked.contains(targetSet)
+ && !marked.contains(targetSet)) {
+
+ unmarked.push(targetSet);
+ }
+
+ DFAState targetState = (DFAState) stateMap.get(targetSet);
+
+ if (targetState == null) {
+ targetState = new DFAState();
+ if (targetSet.contains(sentinelNode)) {
+ targetState.setAccepting(true);
+ }
+ stateMap.put(targetSet, targetState);
+ }
+
+ state.addTransition(symbol, targetState);
+ }
+ }
+
}
- }
-
+ return startState;
}
- return startState;
- }
-
- /**
- * Create optional node.
- *
- * @param child Node that is optional.
- */
- public static Node createOptionalNode(Node child) {
- return new OrNode(child, new NullNode());
- }
-
- /**
- * Create a repeating node.
- *
- * @param child Node that can be repeated.
- * @param minRepeat minimum number of times the node can be repeated.
- */
- public static Node createRepeatingNode(Node child, int minRepeat) {
- Node node = new StarNode(child);
- for (int i = 0; i < minRepeat; i++) {
- node = new CatNode(node, (Node) child.clone());
- }
- return node;
- }
-
- /**
- * Creates a node representing a sequence of two other nodes.
- *
- * @param child1 first node in the sequence.
- * @param child2 second node in the sequence.
- */
- public static Node createSequenceNode(Node child1, Node child2) {
- return new CatNode(child1, child2);
- }
-
- /**
- * Create a node for a symbol.
- *
- * @param symbol Symbol contained by the node.
- */
- public static Node createSymbolNode(Object symbol) {
- return new SymbolNode(symbol);
- }
-
- //============================================================ PRIVATE
-
- /**
- * Implementation of node that keeps firstPos, lastPos, and nullable
- * as instance variables. The accept method is undefined.
- */
- private abstract static class AbstractNode implements Node {
- protected Set firstPos;
- protected Set lastPos;
- protected boolean nullable;
-
- public abstract Object clone();
-
- public Set getFirstPos() {
- return this.firstPos;
- }
- public Set getLastPos() {
- return this.lastPos;
- }
- public boolean isNullable() {
- return this.nullable;
+ /**
+ * Create optional node.
+ *
+ * @param child
+ * Node that is optional.
+ */
+ public static Node createOptionalNode(Node child) {
+ return new OrNode(child, new NullNode());
}
- protected Set union(Set set1, Set set2) {
- Set retval = new HashSet();
- retval.addAll(set1);
- retval.addAll(set2);
- return retval;
- }
- }
-
- /**
- * Node representing a sequence of two nodes.
- */
- private static class CatNode extends AbstractNode {
- private Node leftChild;
- private Node rightChild;
-
- public CatNode(Node leftChild, Node rightChild) {
- this.leftChild = leftChild;
- this.rightChild = rightChild;
-
- if (leftChild.isNullable()) {
- this.firstPos = union(leftChild.getFirstPos(),
- rightChild.getFirstPos());
- } else {
- this.firstPos = leftChild.getFirstPos();
- }
-
- if (rightChild.isNullable()) {
- this.lastPos = union(leftChild.getLastPos(),
- rightChild.getLastPos());
- } else {
- this.lastPos = rightChild.getLastPos();
- }
-
- this.nullable = leftChild.isNullable() && rightChild.isNullable();
+ /**
+ * Create a repeating node.
+ *
+ * @param child
+ * Node that can be repeated.
+ * @param minRepeat
+ * minimum number of times the node can be repeated.
+ */
+ public static Node createRepeatingNode(Node child, int minRepeat) {
+ Node node = new StarNode(child);
+ for (int i = 0; i < minRepeat; i++) {
+ node = new CatNode(node, (Node) child.clone());
+ }
+ return node;
}
- public void accept(NodeVisitor visitor) {
- leftChild.accept(visitor);
- rightChild.accept(visitor);
- visitor.visitCatNode(this);
+ /**
+ * Creates a node representing a sequence of two other nodes.
+ *
+ * @param child1
+ * first node in the sequence.
+ * @param child2
+ * second node in the sequence.
+ */
+ public static Node createSequenceNode(Node child1, Node child2) {
+ return new CatNode(child1, child2);
}
- public Object clone() {
- return new CatNode((Node) this.leftChild.clone(),
- (Node) this.rightChild.clone());
+ /**
+ * Create a node for a symbol.
+ *
+ * @param symbol
+ * Symbol contained by the node.
+ */
+ public static Node createSymbolNode(Object symbol) {
+ return new SymbolNode(symbol);
}
- public Node getLeftChild() {
- return this.leftChild;
+ // ============================================================ PRIVATE
+
+ /**
+ * Implementation of node that keeps firstPos, lastPos, and nullable as
+ * instance variables. The accept method is undefined.
+ */
+ private abstract static class AbstractNode implements Node {
+ protected Set firstPos;
+ protected Set lastPos;
+ protected boolean nullable;
+
+ public abstract Object clone();
+
+ public Set getFirstPos() {
+ return this.firstPos;
+ }
+
+ public Set getLastPos() {
+ return this.lastPos;
+ }
+
+ public boolean isNullable() {
+ return this.nullable;
+ }
+
+ protected Set union(Set set1, Set set2) {
+ Set retval = new HashSet();
+ retval.addAll(set1);
+ retval.addAll(set2);
+ return retval;
+ }
}
- public Node getRightChild() {
- return this.rightChild;
- }
- }
+ /**
+ * Node representing a sequence of two nodes.
+ */
+ private static class CatNode extends AbstractNode {
+ private Node leftChild;
+ private Node rightChild;
- /**
- * Builds the followPos function. The function is represented by a
- * map from symbol nodes to sets of symbol nodes that can follow
- * them. Also generates a map of symbols to sets of symbol nodes
- * that represent them.
- */
- private static class FollowPosBuilder implements NodeVisitor {
- private Map followPos = new HashMap();
- private Map symbolMap = new HashMap();
+ public CatNode(Node leftChild, Node rightChild) {
+ this.leftChild = leftChild;
+ this.rightChild = rightChild;
- public Map getFollowPos() {
- return this.followPos;
+ if (leftChild.isNullable()) {
+ this.firstPos = union(leftChild.getFirstPos(), rightChild
+ .getFirstPos());
+ } else {
+ this.firstPos = leftChild.getFirstPos();
+ }
+
+ if (rightChild.isNullable()) {
+ this.lastPos = union(leftChild.getLastPos(), rightChild
+ .getLastPos());
+ } else {
+ this.lastPos = rightChild.getLastPos();
+ }
+
+ this.nullable = leftChild.isNullable() && rightChild.isNullable();
+ }
+
+ public void accept(NodeVisitor visitor) {
+ leftChild.accept(visitor);
+ rightChild.accept(visitor);
+ visitor.visitCatNode(this);
+ }
+
+ public Object clone() {
+ return new CatNode((Node) this.leftChild.clone(),
+ (Node) this.rightChild.clone());
+ }
+
+ public Node getLeftChild() {
+ return this.leftChild;
+ }
+
+ public Node getRightChild() {
+ return this.rightChild;
+ }
}
- public Map getSymbolMap() {
- return this.symbolMap;
+ /**
+ * Builds the followPos function. The function is represented by a map from
+ * symbol nodes to sets of symbol nodes that can follow them. Also generates
+ * a map of symbols to sets of symbol nodes that represent them.
+ */
+ private static class FollowPosBuilder implements NodeVisitor {
+ private Map followPos = new HashMap();
+ private Map symbolMap = new HashMap();
+
+ public Map getFollowPos() {
+ return this.followPos;
+ }
+
+ public Map getSymbolMap() {
+ return this.symbolMap;
+ }
+
+ public void visitCatNode(CatNode node) {
+ Iterator iter = node.getLeftChild().getLastPos().iterator();
+ while (iter.hasNext()) {
+ SymbolNode symbolNode = (SymbolNode) iter.next();
+ Set set = this.getFollowPos(symbolNode);
+ set.addAll(node.getRightChild().getFirstPos());
+ }
+ }
+
+ public void visitNullNode(NullNode node) {
+ }
+
+ public void visitOrNode(OrNode node) {
+ }
+
+ public void visitStarNode(StarNode node) {
+ Iterator iter = node.getChild().getLastPos().iterator();
+ while (iter.hasNext()) {
+ SymbolNode symbolNode = (SymbolNode) iter.next();
+ Set set = this.getFollowPos(symbolNode);
+ set.addAll(node.getChild().getFirstPos());
+ }
+ }
+
+ public void visitSymbolNode(SymbolNode node) {
+
+ // Done by getFollowPos(SymbolNode)
+ // this.followPos.put(node, new HashSet());
+
+ // Ensure we have an entry for this symbol
+ this.getFollowPos(node);
+
+ Object symbol = node.getSymbol();
+ Set symbolNodeSet = (Set) this.symbolMap.get(symbol);
+ if (symbolNodeSet == null) {
+ symbolNodeSet = new HashSet();
+ this.symbolMap.put(symbol, symbolNodeSet);
+ }
+ symbolNodeSet.add(node);
+ }
+
+ private Set getFollowPos(SymbolNode node) {
+ Set ret = (Set) this.followPos.get(node);
+ if (ret == null) {
+ ret = new HashSet();
+ this.followPos.put(node, ret);
+ }
+ return ret;
+ }
+
}
- public void visitCatNode(CatNode node) {
- Iterator iter = node.getLeftChild().getLastPos().iterator();
- while (iter.hasNext()) {
- SymbolNode symbolNode = (SymbolNode) iter.next();
- Set set = this.getFollowPos(symbolNode);
- set.addAll(node.getRightChild().getFirstPos());
- }
+ /**
+ * Describes a visitor that can walk an AST.
+ */
+ private interface NodeVisitor {
+ public void visitCatNode(CatNode node);
+
+ public void visitNullNode(NullNode node);
+
+ public void visitOrNode(OrNode node);
+
+ public void visitStarNode(StarNode node);
+
+ public void visitSymbolNode(SymbolNode node);
}
- public void visitNullNode(NullNode node) {
+ /**
+ * Node representing nothing. It is used with OrNode to construct an
+ * optional entry.
+ */
+ private static class NullNode extends AbstractNode {
+ public NullNode() {
+ this.firstPos = Collections.EMPTY_SET;
+ this.lastPos = Collections.EMPTY_SET;
+ this.nullable = true;
+ }
+
+ public void accept(NodeVisitor visitor) {
+ visitor.visitNullNode(this);
+ }
+
+ public Object clone() {
+ return new NullNode();
+ }
}
- public void visitOrNode(OrNode node) {
+ /**
+ * Node representing a choice between two alternatives.
+ */
+ private static class OrNode extends AbstractNode {
+ private Node leftChild;
+ private Node rightChild;
+
+ public OrNode(Node leftChild, Node rightChild) {
+ this.leftChild = leftChild;
+ this.rightChild = rightChild;
+
+ this.firstPos = union(leftChild.getFirstPos(), rightChild
+ .getFirstPos());
+ this.lastPos = union(leftChild.getLastPos(), rightChild
+ .getLastPos());
+
+ this.nullable = leftChild.isNullable() || rightChild.isNullable();
+ }
+
+ public void accept(NodeVisitor visitor) {
+ leftChild.accept(visitor);
+ rightChild.accept(visitor);
+ visitor.visitOrNode(this);
+ }
+
+ public Object clone() {
+ return new OrNode((Node) this.leftChild.clone(),
+ (Node) this.rightChild.clone());
+ }
+
+ public Node getLeftChild() {
+ return this.leftChild;
+ }
+
+ public Node getRightChild() {
+ return this.rightChild;
+ }
}
- public void visitStarNode(StarNode node) {
- Iterator iter = node.getChild().getLastPos().iterator();
- while (iter.hasNext()) {
- SymbolNode symbolNode = (SymbolNode) iter.next();
- Set set = this.getFollowPos(symbolNode);
- set.addAll(node.getChild().getFirstPos());
- }
+ /**
+ * Symbol appended to the AST to mark accepting states.
+ */
+ private static class Sentinel {
+ private static final Sentinel instance = new Sentinel();
+
+ private Sentinel() {
+ }
+
+ public static Sentinel getInstance() {
+ return instance;
+ }
+
+ public String toString() {
+ return "#";
+ }
}
- public void visitSymbolNode(SymbolNode node) {
+ /**
+ * Node representing zero or more repetitions of its child.
+ */
+ private static class StarNode extends AbstractNode {
+ private Node child;
- // Done by getFollowPos(SymbolNode)
- //this.followPos.put(node, new HashSet());
+ public StarNode(Node child) {
+ this.child = child;
+ this.firstPos = child.getFirstPos();
+ this.lastPos = child.getLastPos();
+ this.nullable = true;
+ }
- // Ensure we have an entry for this symbol
- this.getFollowPos(node);
+ public void accept(NodeVisitor visitor) {
+ child.accept(visitor);
+ visitor.visitStarNode(this);
+ }
- Object symbol = node.getSymbol();
- Set symbolNodeSet = (Set) this.symbolMap.get(symbol);
- if (symbolNodeSet == null) {
- symbolNodeSet = new HashSet();
- this.symbolMap.put(symbol, symbolNodeSet);
- }
- symbolNodeSet.add(node);
+ public Object clone() {
+ return new StarNode((Node) this.child.clone());
+ }
+
+ public Node getChild() {
+ return this.child;
+ }
}
- private Set getFollowPos(SymbolNode node) {
- Set ret = (Set) this.followPos.get(node);
- if (ret == null) {
- ret = new HashSet();
- this.followPos.put(node, ret);
- }
- return ret;
+ /**
+ * Node representing a symbol.
+ */
+ private static class SymbolNode extends AbstractNode {
+
+ private static int pos = 1;
+ private int myPos;
+ private Object symbol;
+
+ public SymbolNode(Object symbol) {
+ this.symbol = symbol;
+ this.firstPos = Collections.singleton(this);
+ this.lastPos = Collections.singleton(this);
+ this.nullable = false;
+ this.myPos = pos++;
+ }
+
+ public void accept(NodeVisitor visitor) {
+ visitor.visitSymbolNode(this);
+ }
+
+ public Object clone() {
+ return new SymbolNode(this.symbol);
+ }
+
+ public int getMyPos() {
+ return this.myPos;
+ }
+
+ public Object getSymbol() {
+ return this.symbol;
+ }
}
- }
-
- /**
- * Describes a visitor that can walk an AST.
- */
- private interface NodeVisitor {
- public void visitCatNode(CatNode node);
- public void visitNullNode(NullNode node);
- public void visitOrNode(OrNode node);
- public void visitStarNode(StarNode node);
- public void visitSymbolNode(SymbolNode node);
- }
-
- /**
- * Node representing nothing. It is used with OrNode to construct an
- * optional entry.
- */
- private static class NullNode extends AbstractNode {
- public NullNode() {
- this.firstPos = Collections.EMPTY_SET;
- this.lastPos = Collections.EMPTY_SET;
- this.nullable = true;
- }
-
- public void accept(NodeVisitor visitor) {
- visitor.visitNullNode(this);
- }
-
- public Object clone() {
- return new NullNode();
- }
- }
-
- /**
- * Node representing a choice between two alternatives.
- */
- private static class OrNode extends AbstractNode {
- private Node leftChild;
- private Node rightChild;
-
- public OrNode(Node leftChild, Node rightChild) {
- this.leftChild = leftChild;
- this.rightChild = rightChild;
-
- this.firstPos = union(leftChild.getFirstPos(),
- rightChild.getFirstPos());
- this.lastPos = union(leftChild.getLastPos(),
- rightChild.getLastPos());
-
- this.nullable = leftChild.isNullable() || rightChild.isNullable();
- }
-
- public void accept(NodeVisitor visitor) {
- leftChild.accept(visitor);
- rightChild.accept(visitor);
- visitor.visitOrNode(this);
- }
-
- public Object clone() {
- return new OrNode((Node) this.leftChild.clone(),
- (Node) this.rightChild.clone());
- }
-
- public Node getLeftChild() {
- return this.leftChild;
- }
-
- public Node getRightChild() {
- return this.rightChild;
- }
- }
-
- /**
- * Symbol appended to the AST to mark accepting states.
- */
- private static class Sentinel {
- private static final Sentinel instance = new Sentinel();
-
- private Sentinel() {
- }
-
- public static Sentinel getInstance() {
- return instance;
- }
-
- public String toString() {
- return "#";
- }
- }
-
- /**
- * Node representing zero or more repetitions of its child.
- */
- private static class StarNode extends AbstractNode {
- private Node child;
-
- public StarNode(Node child) {
- this.child = child;
- this.firstPos = child.getFirstPos();
- this.lastPos = child.getLastPos();
- this.nullable = true;
- }
-
- public void accept(NodeVisitor visitor) {
- child.accept(visitor);
- visitor.visitStarNode(this);
- }
-
- public Object clone() {
- return new StarNode((Node) this.child.clone());
- }
-
- public Node getChild() {
- return this.child;
- }
- }
-
- /**
- * Node representing a symbol.
- */
- private static class SymbolNode extends AbstractNode {
-
- private static int pos = 1;
- private int myPos;
- private Object symbol;
-
- public SymbolNode (Object symbol) {
- this.symbol = symbol;
- this.firstPos = Collections.singleton(this);
- this.lastPos = Collections.singleton(this);
- this.nullable = false;
- this.myPos = pos++;
- }
-
- public void accept(NodeVisitor visitor) {
- visitor.visitSymbolNode(this);
- }
-
- public Object clone() {
- return new SymbolNode(this.symbol);
- }
-
- public int getMyPos() {
- return this.myPos;
- }
-
- public Object getSymbol() {
- return this.symbol;
- }
- }
-
-
- /*
- private static String snSetToString(Set set) {
- StringBuffer sb = new StringBuffer();
- sb.append("{ ");
- Iterator i2 = set.iterator();
- while (i2.hasNext()) {
- SymbolNode sn2 = (SymbolNode) i2.next();
- sb.append(sn2.getMyPos());
- sb.append(" ");
- }
- sb.append("}");
- return sb.toString();
-
- }
- */
+ /*
+ * private static String snSetToString(Set set) { StringBuffer sb = new
+ * StringBuffer(); sb.append("{ "); Iterator i2 = set.iterator(); while
+ * (i2.hasNext()) { SymbolNode sn2 = (SymbolNode) i2.next();
+ * sb.append(sn2.getMyPos()); sb.append(" "); } sb.append("}"); return
+ * sb.toString();
+ *
+ * }
+ */
}
-
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/dom/DFAState.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/dom/DFAState.java
index 18d8453..9256790 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/dom/DFAState.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/dom/DFAState.java
@@ -17,97 +17,97 @@
import java.util.Map;
import java.util.Set;
-
/**
- * Represents a state in a deterministic finite automaton (DFA). A DFA
- * can be thought of as a directed graph, where each arc in the graph
- * represents a transition on an input symbol to a new state (i.e. a
- * node in the graph.) The DFA has a start state and one or more
- * accepting states. The DFA represents a grammar. If a sequence of
- * input symbols drives the DFA from the start state to one of the
- * accepting states, the sequence is a valid sentence in the grammar
- * represented by the DFA.
- *
- * <p>Within VEX, we use a DFA to validate the sequence of children of
- * a given element. A DFA is constructed for each element declaration
- * in the DTD.</p>
+ * Represents a state in a deterministic finite automaton (DFA). A DFA can be
+ * thought of as a directed graph, where each arc in the graph represents a
+ * transition on an input symbol to a new state (i.e. a node in the graph.) The
+ * DFA has a start state and one or more accepting states. The DFA represents a
+ * grammar. If a sequence of input symbols drives the DFA from the start state
+ * to one of the accepting states, the sequence is a valid sentence in the
+ * grammar represented by the DFA.
+ *
+ * <p>
+ * Within VEX, we use a DFA to validate the sequence of children of a given
+ * element. A DFA is constructed for each element declaration in the DTD.
+ * </p>
*/
public class DFAState implements Serializable {
- private boolean accepting = false;
- private Map transitions = new HashMap();
+ private boolean accepting = false;
+ private Map transitions = new HashMap();
- /**
- * Class constructor.
- */
- public DFAState() {
- }
-
- /**
- * Return the state obtained by traversing the given list of symbols.
- * Returns null if the given sequence does not lead to a state in the DFA.
- *
- * @param sequence Sequence of symbols to use.
- */
- public DFAState getState(List sequence) {
- DFAState state = this;
- Iterator iter = sequence.iterator();
- while (iter.hasNext()) {
- state = state.getNextState(iter.next());
- if (state == null) {
- break;
- }
+ /**
+ * Class constructor.
+ */
+ public DFAState() {
}
- return state;
- }
- /**
- * Adds an outgoing transition to the state.
- *
- * @param symbol Symbol that initiates the transition.
- * @param target State to which the transition leads.
- */
- public void addTransition(Object symbol, DFAState target) {
- this.transitions.put(symbol, target);
- }
+ /**
+ * Return the state obtained by traversing the given list of symbols.
+ * Returns null if the given sequence does not lead to a state in the DFA.
+ *
+ * @param sequence
+ * Sequence of symbols to use.
+ */
+ public DFAState getState(List sequence) {
+ DFAState state = this;
+ Iterator iter = sequence.iterator();
+ while (iter.hasNext()) {
+ state = state.getNextState(iter.next());
+ if (state == null) {
+ break;
+ }
+ }
+ return state;
+ }
- /**
- * Returns the set of symbols that are valid for this state.
- */
- public Set getValidSymbols() {
- return this.transitions.keySet();
- }
+ /**
+ * Adds an outgoing transition to the state.
+ *
+ * @param symbol
+ * Symbol that initiates the transition.
+ * @param target
+ * State to which the transition leads.
+ */
+ public void addTransition(Object symbol, DFAState target) {
+ this.transitions.put(symbol, target);
+ }
- /**
- * Returns true if this is an accepting state of the DFA.
- */
- public boolean isAccepting() {
- return this.accepting;
- }
+ /**
+ * Returns the set of symbols that are valid for this state.
+ */
+ public Set getValidSymbols() {
+ return this.transitions.keySet();
+ }
- /**
- * Returns the next state given the given input symbol, or
- * null if there are no outgoing transitions corresponding to
- * the given symbol.
- *
- * @param symbol input symbol
- */
- public DFAState getNextState(Object symbol) {
- return (DFAState) this.transitions.get(symbol);
- }
+ /**
+ * Returns true if this is an accepting state of the DFA.
+ */
+ public boolean isAccepting() {
+ return this.accepting;
+ }
- /**
- * Sets the value of the accepting property.
- *
- * @param accepting true if this an accepting state of the DFA.
- */
- public void setAccepting(boolean accepting) {
- this.accepting = accepting;
- }
+ /**
+ * Returns the next state given the given input symbol, or null if there are
+ * no outgoing transitions corresponding to the given symbol.
+ *
+ * @param symbol
+ * input symbol
+ */
+ public DFAState getNextState(Object symbol) {
+ return (DFAState) this.transitions.get(symbol);
+ }
+ /**
+ * Sets the value of the accepting property.
+ *
+ * @param accepting
+ * true if this an accepting state of the DFA.
+ */
+ public void setAccepting(boolean accepting) {
+ this.accepting = accepting;
+ }
-
- //========================================================= PRIVATE
+ // ========================================================= PRIVATE
}
-
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/dom/DTDValidator.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/dom/DTDValidator.java
index a0d4901..01f2fa7 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/dom/DTDValidator.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/dom/DTDValidator.java
@@ -43,259 +43,261 @@
*/
public class DTDValidator extends AbstractValidator {
- // DFA representing an EMPTY element; just a single non-accepting state
- // with no transitions.
- private static final DFAState emptyDFA = new DFAState();
+ // DFA representing an EMPTY element; just a single non-accepting state
+ // with no transitions.
+ private static final DFAState emptyDFA = new DFAState();
- // map element names to DFAs
- private Map elementDFAs = new HashMap();
+ // map element names to DFAs
+ private Map elementDFAs = new HashMap();
- // list of all element names plus PCDATA
- private Set anySet;
-
- // map element names to arrays of AttributeDefinition objects
- private Map attributeArrays = new HashMap();
-
- // map element names to maps of attribute name to attribute def
- private Map attributeMaps = new HashMap();
+ // list of all element names plus PCDATA
+ private Set anySet;
- /**
- * Creates a instance of DtdValidator given a URL.
- *
- * @param url URL of the DTD file to use.
- */
- public static DTDValidator create(URL url) throws IOException {
+ // map element names to arrays of AttributeDefinition objects
+ private Map attributeArrays = new HashMap();
- // Compute the DFAs for each element in the DTD
+ // map element names to maps of attribute name to attribute def
+ private Map attributeMaps = new HashMap();
- DTDParser parser = new DTDParser(url);
- DTD dtd = parser.parse();
+ /**
+ * Creates a instance of DtdValidator given a URL.
+ *
+ * @param url
+ * URL of the DTD file to use.
+ */
+ public static DTDValidator create(URL url) throws IOException {
- DTDValidator validator = new DTDValidator();
- Iterator iter = dtd.elements.values().iterator();
- while (iter.hasNext()) {
- DTDElement element = (DTDElement) iter.next();
- DFAState dfa;
- if (element.getContent() instanceof DTDEmpty) {
- dfa = emptyDFA;
- } else if (element.getContent() instanceof DTDAny) {
- dfa = null;
- } else {
- DFABuilder.Node node = createDFANode(element.getContent());
- dfa = DFABuilder.createDFA(node);
- }
- validator.elementDFAs.put(element.getName(), dfa);
+ // Compute the DFAs for each element in the DTD
- Map defMap = new HashMap();
- AttributeDefinition[] defArray = new AttributeDefinition[element.attributes.size()];
- int i = 0;
- Iterator iter2 = element.attributes.values().iterator();
- while (iter2.hasNext()) {
- DTDAttribute attr = (DTDAttribute) iter2.next();
- AttributeDefinition.Type type;
- String[] values = null;
- if (attr.getType() instanceof DTDEnumeration) {
- type = AttributeDefinition.Type.ENUMERATION;
- values = ((DTDEnumeration)attr.getType()).getItems();
- } else if (attr.getType() instanceof DTDNotationList) {
- type = AttributeDefinition.Type.ENUMERATION;
- values = ((DTDNotationList)attr.getType()).getItems();
- } else if (attr.getType() instanceof String) {
- type = AttributeDefinition.Type.get((String) attr.getType());
- } else {
- throw new RuntimeException("Unrecognized attribute type for element "
- + element.getName() + " attribute " + attr.getName()
- + " type " + attr.getType().getClass().getName());
- }
-
- AttributeDefinition ad = new AttributeDefinition(attr.getName(),
- type,
- attr.getDefaultValue(),
- values,
- attr.getDecl() == DTDDecl.REQUIRED,
- attr.getDecl() == DTDDecl.FIXED);
+ DTDParser parser = new DTDParser(url);
+ DTD dtd = parser.parse();
- defMap.put(attr.getName(), ad);
- defArray[i] = ad;
-
- i++;
- }
- validator.attributeMaps.put(element.getName(), defMap);
- Arrays.sort(defArray);
- validator.attributeArrays.put(element.getName(), defArray);
- }
+ DTDValidator validator = new DTDValidator();
+ Iterator iter = dtd.elements.values().iterator();
+ while (iter.hasNext()) {
+ DTDElement element = (DTDElement) iter.next();
+ DFAState dfa;
+ if (element.getContent() instanceof DTDEmpty) {
+ dfa = emptyDFA;
+ } else if (element.getContent() instanceof DTDAny) {
+ dfa = null;
+ } else {
+ DFABuilder.Node node = createDFANode(element.getContent());
+ dfa = DFABuilder.createDFA(node);
+ }
+ validator.elementDFAs.put(element.getName(), dfa);
- // Calculate anySet
+ Map defMap = new HashMap();
+ AttributeDefinition[] defArray = new AttributeDefinition[element.attributes
+ .size()];
+ int i = 0;
+ Iterator iter2 = element.attributes.values().iterator();
+ while (iter2.hasNext()) {
+ DTDAttribute attr = (DTDAttribute) iter2.next();
+ AttributeDefinition.Type type;
+ String[] values = null;
+ if (attr.getType() instanceof DTDEnumeration) {
+ type = AttributeDefinition.Type.ENUMERATION;
+ values = ((DTDEnumeration) attr.getType()).getItems();
+ } else if (attr.getType() instanceof DTDNotationList) {
+ type = AttributeDefinition.Type.ENUMERATION;
+ values = ((DTDNotationList) attr.getType()).getItems();
+ } else if (attr.getType() instanceof String) {
+ type = AttributeDefinition.Type
+ .get((String) attr.getType());
+ } else {
+ throw new RuntimeException(
+ "Unrecognized attribute type for element "
+ + element.getName() + " attribute "
+ + attr.getName() + " type "
+ + attr.getType().getClass().getName());
+ }
- validator.anySet = new HashSet();
- validator.anySet.addAll(validator.elementDFAs.keySet());
- validator.anySet.add(Validator.PCDATA);
+ AttributeDefinition ad = new AttributeDefinition(
+ attr.getName(), type, attr.getDefaultValue(), values,
+ attr.getDecl() == DTDDecl.REQUIRED,
+ attr.getDecl() == DTDDecl.FIXED);
- return validator;
- }
+ defMap.put(attr.getName(), ad);
+ defArray[i] = ad;
- public AttributeDefinition getAttributeDefinition(String element, String attribute) {
- Map attrMap = (Map) this.attributeMaps.get(element);
- return attrMap == null ? null : (AttributeDefinition) attrMap.get(attribute);
- }
-
- public AttributeDefinition[] getAttributeDefinitions(String element) {
- if (this.attributeArrays.containsKey(element)) {
- return (AttributeDefinition[]) this.attributeArrays.get(element);
- } else {
- return new AttributeDefinition[0];
- }
- }
-
- public Set getValidRootElements() {
- return this.elementDFAs.keySet();
- }
-
- /** @see Validator#getValidItems */
- public Set getValidItems(String element, String[] prefix, String[] suffix) {
-
- // First, get a set of candidates. We'll later test to see if each is
- // valid to insert here.
-
- Set candidates = null;
- DFAState dfa = (DFAState) elementDFAs.get(element);
- if (dfa == null) {
- // Anything goes!
- return this.anySet;
- }
-
- DFAState target = dfa.getState(Arrays.asList(prefix));
- if (target == null) {
- return Collections.EMPTY_SET;
- } else {
- // If the last transition was due to PCDATA, adding more PCDATA
- // is also valid
- if (prefix.length > 0
- && prefix[prefix.length - 1].equals(Validator.PCDATA)) {
- candidates = new HashSet();
- candidates.addAll(target.getValidSymbols());
- candidates.add(Validator.PCDATA);
- } else {
- candidates = target.getValidSymbols();
- }
- }
-
- // Now, see if each candidate can be inserted at the given
- // offset. This second test is necessary in some simple
- // cases. Consider a <section> with an optional <title>; if
- // we're at the first offset of the <section> and a <title>
- // already exists, we should not allow another <title>.
-
- Set results = new HashSet();
- String[] middle = new String[1];
- for (Iterator iter = candidates.iterator(); iter.hasNext(); ) {
- middle[0] = (String) iter.next();
- if (this.isValidSequence(element, prefix, middle, suffix, true)) {
- results.add(middle[0]);
- }
- }
-
- return Collections.unmodifiableSet(results);
- }
-
- /**
- * @see Validator#isValidSequence
- */
- public boolean isValidSequence(
- String element,
- String[] nodes,
- boolean partial) {
-
- DFAState dfa = (DFAState) this.elementDFAs.get(element);
- if (dfa == null) {
- // Unrecognized element. Give the user the benefit of the doubt.
- return true;
- }
-
- DFAState target = dfa.getState(Arrays.asList(nodes));
-
- return target != null && (partial || target.isAccepting());
- }
-
- //==================================================== PRIVATE
-
- /**
- * Homeys must call create()
- */
- private DTDValidator() {
- }
-
- /**
- * Create a DFABuilder.Node corresponding to the given DTDItem.
- */
- private static DFABuilder.Node createDFANode(DTDItem item) {
- DFABuilder.Node node = null;
-
- if (item instanceof DTDName) {
- String name = ((DTDName) item).getValue();
- node = DFABuilder.createSymbolNode(name);
-
- } else if (item instanceof DTDPCData) {
- node = DFABuilder.createSymbolNode(Validator.PCDATA);
-
- } else if (item instanceof DTDChoice) {
- Iterator iter = ((DTDContainer)item).getItemsVec().iterator();
- while (iter.hasNext()) {
- DTDItem child = (DTDItem) iter.next();
- DFABuilder.Node newNode = createDFANode(child);
- if (node == null) {
- node = newNode;
- } else {
- node = DFABuilder.createChoiceNode(node, newNode);
+ i++;
+ }
+ validator.attributeMaps.put(element.getName(), defMap);
+ Arrays.sort(defArray);
+ validator.attributeArrays.put(element.getName(), defArray);
}
- }
- } else if (item instanceof DTDMixed) {
- Iterator iter = ((DTDContainer)item).getItemsVec().iterator();
- while (iter.hasNext()) {
- DTDItem child = (DTDItem) iter.next();
- DFABuilder.Node newNode = createDFANode(child);
- if (node == null) {
- node = newNode;
- } else {
- node = DFABuilder.createChoiceNode(node, newNode);
- }
- }
- DFABuilder.Node pcdata =
- DFABuilder.createSymbolNode(Validator.PCDATA);
- node = DFABuilder.createChoiceNode(node, pcdata);
-
- } else if (item instanceof DTDSequence) {
- Iterator iter = ((DTDContainer)item).getItemsVec().iterator();
- while (iter.hasNext()) {
- DTDItem child = (DTDItem) iter.next();
- DFABuilder.Node newNode = createDFANode(child);
- if (node == null) {
- node = newNode;
- } else {
- node = DFABuilder.createSequenceNode(node, newNode);
- }
- }
- } else {
- throw new RuntimeException("Unexpected DTDItem subclass: " +
- item.getClass().getName());
+ // Calculate anySet
+
+ validator.anySet = new HashSet();
+ validator.anySet.addAll(validator.elementDFAs.keySet());
+ validator.anySet.add(Validator.PCDATA);
+
+ return validator;
}
- // Cardinality is moot if it's a null node
- if (node == null) {
- return node;
+ public AttributeDefinition getAttributeDefinition(String element,
+ String attribute) {
+ Map attrMap = (Map) this.attributeMaps.get(element);
+ return attrMap == null ? null : (AttributeDefinition) attrMap
+ .get(attribute);
}
- if (item.cardinal == DTDCardinal.OPTIONAL) {
- node = DFABuilder.createOptionalNode(node);
- } else if (item.cardinal == DTDCardinal.ZEROMANY) {
- node = DFABuilder.createRepeatingNode(node, 0);
- } else if (item.cardinal == DTDCardinal.ONEMANY) {
- node = DFABuilder.createRepeatingNode(node, 1);
- }
+ public AttributeDefinition[] getAttributeDefinitions(String element) {
+ if (this.attributeArrays.containsKey(element)) {
+ return (AttributeDefinition[]) this.attributeArrays.get(element);
+ } else {
+ return new AttributeDefinition[0];
+ }
+ }
- return node;
- }
+ public Set getValidRootElements() {
+ return this.elementDFAs.keySet();
+ }
+
+ /** @see Validator#getValidItems */
+ public Set getValidItems(String element, String[] prefix, String[] suffix) {
+
+ // First, get a set of candidates. We'll later test to see if each is
+ // valid to insert here.
+
+ Set candidates = null;
+ DFAState dfa = (DFAState) elementDFAs.get(element);
+ if (dfa == null) {
+ // Anything goes!
+ return this.anySet;
+ }
+
+ DFAState target = dfa.getState(Arrays.asList(prefix));
+ if (target == null) {
+ return Collections.EMPTY_SET;
+ } else {
+ // If the last transition was due to PCDATA, adding more PCDATA
+ // is also valid
+ if (prefix.length > 0
+ && prefix[prefix.length - 1].equals(Validator.PCDATA)) {
+ candidates = new HashSet();
+ candidates.addAll(target.getValidSymbols());
+ candidates.add(Validator.PCDATA);
+ } else {
+ candidates = target.getValidSymbols();
+ }
+ }
+
+ // Now, see if each candidate can be inserted at the given
+ // offset. This second test is necessary in some simple
+ // cases. Consider a <section> with an optional <title>; if
+ // we're at the first offset of the <section> and a <title>
+ // already exists, we should not allow another <title>.
+
+ Set results = new HashSet();
+ String[] middle = new String[1];
+ for (Iterator iter = candidates.iterator(); iter.hasNext();) {
+ middle[0] = (String) iter.next();
+ if (this.isValidSequence(element, prefix, middle, suffix, true)) {
+ results.add(middle[0]);
+ }
+ }
+
+ return Collections.unmodifiableSet(results);
+ }
+
+ /**
+ * @see Validator#isValidSequence
+ */
+ public boolean isValidSequence(String element, String[] nodes,
+ boolean partial) {
+
+ DFAState dfa = (DFAState) this.elementDFAs.get(element);
+ if (dfa == null) {
+ // Unrecognized element. Give the user the benefit of the doubt.
+ return true;
+ }
+
+ DFAState target = dfa.getState(Arrays.asList(nodes));
+
+ return target != null && (partial || target.isAccepting());
+ }
+
+ // ==================================================== PRIVATE
+
+ /**
+ * Homeys must call create()
+ */
+ private DTDValidator() {
+ }
+
+ /**
+ * Create a DFABuilder.Node corresponding to the given DTDItem.
+ */
+ private static DFABuilder.Node createDFANode(DTDItem item) {
+ DFABuilder.Node node = null;
+
+ if (item instanceof DTDName) {
+ String name = ((DTDName) item).getValue();
+ node = DFABuilder.createSymbolNode(name);
+
+ } else if (item instanceof DTDPCData) {
+ node = DFABuilder.createSymbolNode(Validator.PCDATA);
+
+ } else if (item instanceof DTDChoice) {
+ Iterator iter = ((DTDContainer) item).getItemsVec().iterator();
+ while (iter.hasNext()) {
+ DTDItem child = (DTDItem) iter.next();
+ DFABuilder.Node newNode = createDFANode(child);
+ if (node == null) {
+ node = newNode;
+ } else {
+ node = DFABuilder.createChoiceNode(node, newNode);
+ }
+ }
+
+ } else if (item instanceof DTDMixed) {
+ Iterator iter = ((DTDContainer) item).getItemsVec().iterator();
+ while (iter.hasNext()) {
+ DTDItem child = (DTDItem) iter.next();
+ DFABuilder.Node newNode = createDFANode(child);
+ if (node == null) {
+ node = newNode;
+ } else {
+ node = DFABuilder.createChoiceNode(node, newNode);
+ }
+ }
+ DFABuilder.Node pcdata = DFABuilder
+ .createSymbolNode(Validator.PCDATA);
+ node = DFABuilder.createChoiceNode(node, pcdata);
+
+ } else if (item instanceof DTDSequence) {
+ Iterator iter = ((DTDContainer) item).getItemsVec().iterator();
+ while (iter.hasNext()) {
+ DTDItem child = (DTDItem) iter.next();
+ DFABuilder.Node newNode = createDFANode(child);
+ if (node == null) {
+ node = newNode;
+ } else {
+ node = DFABuilder.createSequenceNode(node, newNode);
+ }
+ }
+ } else {
+ throw new RuntimeException("Unexpected DTDItem subclass: "
+ + item.getClass().getName());
+ }
+
+ // Cardinality is moot if it's a null node
+ if (node == null) {
+ return node;
+ }
+
+ if (item.cardinal == DTDCardinal.OPTIONAL) {
+ node = DFABuilder.createOptionalNode(node);
+ } else if (item.cardinal == DTDCardinal.ZEROMANY) {
+ node = DFABuilder.createRepeatingNode(node, 0);
+ } else if (item.cardinal == DTDCardinal.ONEMANY) {
+ node = DFABuilder.createRepeatingNode(node, 1);
+ }
+
+ return node;
+ }
}
-
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/dom/Document.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/dom/Document.java
index 016d3b1..f82033a 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/dom/Document.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/dom/Document.java
@@ -19,948 +19,996 @@
import org.eclipse.wst.xml.vex.core.internal.undo.CannotUndoException;
import org.eclipse.wst.xml.vex.core.internal.undo.IUndoableEdit;
-
/**
* Represents an XML document.
*/
public class Document {
- private Content content;
- private RootElement rootElement;
- private ListenerList listeners = new ListenerList(DocumentListener.class, DocumentEvent.class);
- private boolean undoEnabled = true;
-
- private String publicID;
- private String systemID;
- private String encoding;
- private Validator validator;
+ private Content content;
+ private RootElement rootElement;
+ private ListenerList listeners = new ListenerList(DocumentListener.class,
+ DocumentEvent.class);
+ private boolean undoEnabled = true;
- /**
- * Class constructor.
- * @param rootElement root element of the document. The
- * document property of this RootElement is set by this
- * constructor.
- */
- public Document(RootElement rootElement) {
- this.content = new GapContent(100);
- this.rootElement = rootElement;
- rootElement.setDocument(this);
- this.content.insertString(0, "\0\0");
- rootElement.setContent(this.content, 0, 1);
- }
+ private String publicID;
+ private String systemID;
+ private String encoding;
+ private Validator validator;
- /**
- * Class constructor. This constructor is used by the document builder
- * and assumes that the content and root element have bee properly set up.
- *
- * @param content Content object used to store the document's content.
- * @param rootElement RootElement of the document.
- */
- public Document(Content content, RootElement rootElement) {
- this.content = content;
- this.rootElement = rootElement;
- }
-
- /**
- * Adds a document listener to the list of listeners to be notified of
- * document changes.
- *
- * @param listener <code>DocumentListener</code> to add.
- */
- public void addDocumentListener(DocumentListener listener) {
- this.listeners.add(listener);
- }
-
- /**
- * Returns true if the given document fragment can be inserted at the
- * given offset.
- *
- * @param offset offset where the insertion is to occur
- * @param fragment fragment to be inserted
- */
- public boolean canInsertFragment(int offset, DocumentFragment fragment) {
-
- if (this.validator == null) {
- return true;
- }
-
- Element element = this.getElementAt(offset);
- String[] seq1 = this.getNodeNames(element.getStartOffset() + 1, offset);
- String[] seq2 = fragment.getNodeNames();
- String[] seq3 = this.getNodeNames(offset, element.getEndOffset());
- return this.validator.isValidSequence(
- element.getName(),
- seq1, seq2, seq3, true);
- }
-
- /**
- * Returns true if text can be inserted at the
- * given offset.
- *
- * @param offset offset where the insertion is to occur
- */
- public boolean canInsertText(int offset) {
-
- if (this.validator == null) {
- return true;
- }
-
- Element element = this.getElementAt(offset);
- String[] seq1 = this.getNodeNames(element.getStartOffset() + 1, offset);
- String[] seq2 = new String[] { Validator.PCDATA };
- String[] seq3 = this.getNodeNames(offset, element.getEndOffset());
-
- return this.validator.isValidSequence(
- element.getName(), seq1, seq2, seq3, true);
- }
-
- /**
- * Creates a <code>Position</code> object at the given character offset.
- *
- * @param offset initial character offset of the position
- */
- public Position createPosition(int offset) {
- return this.content.createPosition(offset);
- }
-
- /**
- * Deletes a portion of the document. No element may straddle the
- * deletion span.
- *
- * @param startOffset start of the range to delete
- * @param endOffset end of the range to delete
- * @throws DocumentValidationException if the change would result
- * in an invalid document.
- */
- public void delete(int startOffset, int endOffset)
- throws DocumentValidationException {
-
- Element e1 = this.getElementAt(startOffset);
- Element e2 = this.getElementAt(endOffset);
- if (e1 != e2) {
- throw new IllegalArgumentException("Deletion from " + startOffset + " to " + endOffset + " is unbalanced");
- }
-
- Validator validator = this.getValidator();
- if (validator != null) {
- String[] seq1 = this.getNodeNames(e1.getStartOffset() + 1, startOffset);
- String[] seq2 = this.getNodeNames(endOffset, e1.getEndOffset());
- if (!validator.isValidSequence(
- e1.getName(), seq1, seq2, null, true)) {
- throw new DocumentValidationException("Unable to delete from " + startOffset + " to " + endOffset);
- }
- }
-
- // Grab the fragment for the undoable edit while it's still here
- DocumentFragment frag = getFragment(startOffset, endOffset);
-
- this.fireBeforeContentDeleted(
- new DocumentEvent(this, e1, startOffset, endOffset - startOffset, null));
-
- Iterator iter = e1.getChildIterator();
- while (iter.hasNext()) {
- Element child = (Element) iter.next();
- if (startOffset <= child.getStartOffset() &&
- child.getEndOffset() < endOffset) {
- iter.remove();
- }
+ /**
+ * Class constructor.
+ *
+ * @param rootElement
+ * root element of the document. The document property of this
+ * RootElement is set by this constructor.
+ */
+ public Document(RootElement rootElement) {
+ this.content = new GapContent(100);
+ this.rootElement = rootElement;
+ rootElement.setDocument(this);
+ this.content.insertString(0, "\0\0");
+ rootElement.setContent(this.content, 0, 1);
}
- this.content.remove(startOffset, endOffset - startOffset);
+ /**
+ * Class constructor. This constructor is used by the document builder and
+ * assumes that the content and root element have bee properly set up.
+ *
+ * @param content
+ * Content object used to store the document's content.
+ * @param rootElement
+ * RootElement of the document.
+ */
+ public Document(Content content, RootElement rootElement) {
+ this.content = content;
+ this.rootElement = rootElement;
+ }
- IUndoableEdit edit = this.undoEnabled ?
- new DeleteEdit(startOffset, endOffset, frag) : null;
-
- this.fireContentDeleted(
- new DocumentEvent(this, e1, startOffset, endOffset - startOffset, edit));
- }
+ /**
+ * Adds a document listener to the list of listeners to be notified of
+ * document changes.
+ *
+ * @param listener
+ * <code>DocumentListener</code> to add.
+ */
+ public void addDocumentListener(DocumentListener listener) {
+ this.listeners.add(listener);
+ }
- /**
- * Finds the lowest element that contains both of the given offsets.
- *
- * @param offset1 the first offset
- * @param offset2 the second offset
- */
- public Element findCommonElement(int offset1, int offset2) {
- Element element = this.rootElement;
- for (;;) {
- boolean tryAgain = false;
- Element[] children = element.getChildElements();
- for (int i = 0; i < children.length; i++) {
- if (offset1 > children[i].getStartOffset() &&
- offset2 > children[i].getStartOffset() &&
- offset1 <= children[i].getEndOffset() &&
- offset2 <= children[i].getEndOffset()) {
-
- element = children[i];
- tryAgain = true;
- break;
+ /**
+ * Returns true if the given document fragment can be inserted at the given
+ * offset.
+ *
+ * @param offset
+ * offset where the insertion is to occur
+ * @param fragment
+ * fragment to be inserted
+ */
+ public boolean canInsertFragment(int offset, DocumentFragment fragment) {
+
+ if (this.validator == null) {
+ return true;
}
- }
- if (!tryAgain) {
- break;
- }
- }
- return element;
- }
- /**
- * Returns the character at the given offset.
- */
- public char getCharacterAt(int offset) {
- return this.content.getString(offset, 1).charAt(0);
- }
-
- /**
- * Returns the element at the given offset. The given offset must be
- * greater or equal to 1 and less than the current document length.
- */
- public Element getElementAt(int offset) {
- if (offset < 1 || offset >= this.getLength()) {
- throw new IllegalArgumentException("Illegal offset: " + offset + ". Must be between 1 and n-1");
+ Element element = this.getElementAt(offset);
+ String[] seq1 = this.getNodeNames(element.getStartOffset() + 1, offset);
+ String[] seq2 = fragment.getNodeNames();
+ String[] seq3 = this.getNodeNames(offset, element.getEndOffset());
+ return this.validator.isValidSequence(element.getName(), seq1, seq2,
+ seq3, true);
}
- Element element = this.rootElement;
- for (;;) {
- boolean tryAgain = false;
- Element[] children = element.getChildElements();
- for (int i = 0; i < children.length; i++) {
- Element child = children[i];
- if (offset <= child.getStartOffset()) {
- return element;
- } else if (offset <= child.getEndOffset()) {
- element = child;
- tryAgain = true;
- break;
+
+ /**
+ * Returns true if text can be inserted at the given offset.
+ *
+ * @param offset
+ * offset where the insertion is to occur
+ */
+ public boolean canInsertText(int offset) {
+
+ if (this.validator == null) {
+ return true;
}
- }
- if (!tryAgain) {
- break;
- }
- }
- return element;
- }
- /**
- * Returns the encoding used for this document, or null if no
- * encoding has been declared.
- */
- public String getEncoding() {
- return this.encoding;
- }
+ Element element = this.getElementAt(offset);
+ String[] seq1 = this.getNodeNames(element.getStartOffset() + 1, offset);
+ String[] seq2 = new String[] { Validator.PCDATA };
+ String[] seq3 = this.getNodeNames(offset, element.getEndOffset());
- /**
- * Create a <code>DocumentFragment</code> representing the given
- * range of offsets.
- *
- * @return
- */
- public DocumentFragment getFragment(int startOffset, int endOffset) {
-
- assertOffset(startOffset, 0, this.content.getLength());
- assertOffset(endOffset, 0, this.content.getLength());
-
- if (endOffset <= startOffset) {
- throw new IllegalArgumentException(
- "Invalid range (" + startOffset + ", " + endOffset + ")");
- }
-
- Element e1 = this.getElementAt(startOffset);
- Element e2 = this.getElementAt(endOffset);
- if (e1 != e2) {
- throw new IllegalArgumentException(
- "Fragment from "
- + startOffset
- + " to "
- + endOffset
- + " is unbalanced");
- }
-
- Element[] children = e1.getChildElements();
-
- Content newContent = new GapContent(endOffset - startOffset);
- String s = this.content.getString(startOffset, endOffset - startOffset);
- newContent.insertString(0, s);
- List newChildren = new ArrayList();
- for (int i = 0; i < children.length; i++) {
- Element child = children[i];
- if (child.getEndOffset() <= startOffset) {
- continue;
- } else if (child.getStartOffset() >= endOffset) {
- break;
- } else {
- newChildren.add(
- this.cloneElement(child, newContent, -startOffset, null));
- }
- }
-
- Element[] elementArray =
- (Element[]) newChildren.toArray(new Element[newChildren.size()]);
- return new DocumentFragment(newContent, elementArray);
- }
-
- /**
- * Returns the length of the document in characters, including the null
- * characters that delimit each element.
- */
- public int getLength() {
- return this.content.getLength();
- }
-
- /**
- * Returns an array of element names and Validator.PCDATA representing
- * the content between the given offsets. The given offsets must both
- * be directly in the same element.
- *
- * @param startOffset the offset at which the sequence begins
- * @param endOffset the offset at which the sequence ends
- */
- public String[] getNodeNames(int startOffset, int endOffset) {
-
- Node[] nodes = this.getNodes(startOffset, endOffset);
- String[] names = new String[nodes.length];
-
- for (int i = 0; i < nodes.length; i++) {
- Node node = nodes[i];
- if (node instanceof Element) {
- names[i] = ((Element)node).getName();
- } else {
- names[i] = Validator.PCDATA;
- }
- }
-
- return names;
- }
-
- /**
- * Returns an array of Nodes representing the selected range. The given offsets must both
- * be directly in the same element.
- *
- * @param startOffset the offset at which the sequence begins
- * @param endOffset the offset at which the sequence ends
- */
- public Node[] getNodes(int startOffset, int endOffset) {
-
- Element element = this.getElementAt(startOffset);
- if (element != this.getElementAt(endOffset)) {
- throw new IllegalArgumentException(
- "Offsets are unbalanced: " +
- startOffset + " is in " + element.getName() + ", " +
- endOffset + " is in " + this.getElementAt(endOffset).getName());
- }
-
- List list = new ArrayList();
- Node[] nodes = element.getChildNodes();
- for (int i = 0; i < nodes.length; i++) {
- Node node = nodes[i];
- if (node.getEndOffset() <= startOffset) {
- continue;
- } else if (node.getStartOffset() >= endOffset) {
- break;
- } else {
- if (node instanceof Element) {
- list.add(node);
- } else {
- Text text = (Text) node;
- if (text.getStartOffset() < startOffset) {
- text.setContent(text.getContent(), startOffset, text.getEndOffset());
- } else if (text.getEndOffset() > endOffset) {
- text.setContent(text.getContent(), text.getStartOffset(), endOffset);
- }
- list.add(text);
- }
- }
- }
-
- return (Node[]) list.toArray(new Node[list.size()]);
- }
-
- /**
- * Creates an array of nodes for a given run of content. The returned array includes the given child
- * elements and <code>Text</code> objects where text appears between elements.
- *
- * @param content Content object containing the content
- * @param startOffset start offset of the run
- * @param endOffset end offset of the run
- * @param elements child elements that are within the run
- */
- static Node[] createNodeArray(Content content, int startOffset, int endOffset, Element[] elements) {
-
- List nodes = new ArrayList();
- int offset = startOffset;
- for (int i = 0; i < elements.length; i++) {
- int start = elements[i].getStartOffset();
- if (offset < start) {
- nodes.add(new Text(content, offset, start));
- }
- nodes.add(elements[i]);
- offset = elements[i].getEndOffset() + 1;
- }
-
- if (offset < endOffset) {
- nodes.add(new Text(content, offset, endOffset));
- }
-
- return (Node[]) nodes.toArray(new Node[nodes.size()]);
- }
-
- /**
- * Returns the public ID of the document type.
- */
- public String getPublicID() {
- return this.publicID;
- }
-
- /**
- * Returns the text between the two given offsets. Unlike getText,
- * sentinel characters are not removed.
- *
- * @param startOffset character offset of the start of the text
- * @param endOffset character offset of the end of the text
- */
- public String getRawText(int startOffset, int endOffset) {
- return this.content.getString(startOffset,
- endOffset - startOffset);
- }
-
- /**
- * Returns the root element of this document.
- */
- public Element getRootElement() {
- return this.rootElement;
- }
-
- /**
- * Returns the system ID of the document type.
- */
- public String getSystemID() {
- return this.systemID;
- }
-
- /**
- * Returns the text between the two given offsets. Sentinal characters
- * are removed.
- *
- * @param startOffset character offset of the start of the text
- * @param endOffset character offset of the end of the text
- */
- public String getText(int startOffset, int endOffset) {
- String raw = this.content.getString(startOffset,
- endOffset - startOffset);
- StringBuffer sb = new StringBuffer(raw.length());
- for (int i = 0; i < raw.length(); i++) {
- char c = raw.charAt(i);
- if (c != '\0') {
- sb.append(c);
- }
- }
- return sb.toString();
- }
-
- /**
- * Returns the validator used to validate the document, or null if
- * a validator has not been set. Note that the DocumentFactory
- * does not automatically create a validator.
- */
- public Validator getValidator() {
- return this.validator;
- }
-
- /**
- * Inserts an element at the given position.
- *
- * @param offset character offset at which the element is to be inserted.
- * Must be greater or equal to 1 and less than the current length of the
- * document, i.e. it must be within the range of the root element.
- * @param element element to insert
- * @throws DocumentValidationException if the change would result
- * in an invalid document.
- */
- public void insertElement(int offset, Element element)
- throws DocumentValidationException {
-
- if (offset < 1 || offset >= this.getLength()) {
- throw new IllegalArgumentException("Error inserting element <" + element.getName() + ">: offset is " + offset + ", but it must be between 1 and " + (this.getLength() - 1));
+ return this.validator.isValidSequence(element.getName(), seq1, seq2,
+ seq3, true);
}
- Validator validator = this.getValidator();
- if (validator != null) {
- Element parent = this.getElementAt(offset);
- String[] seq1 = this.getNodeNames(parent.getStartOffset() + 1, offset);
- String[] seq2 = new String[] { element.getName() };
- String[] seq3 = this.getNodeNames(offset, parent.getEndOffset());
- if (!validator.isValidSequence(
- parent.getName(), seq1, seq2, seq3, true)) {
- throw new DocumentValidationException("Cannot insert element " + element.getName() + " at offset " + offset);
- }
+ /**
+ * Creates a <code>Position</code> object at the given character offset.
+ *
+ * @param offset
+ * initial character offset of the position
+ */
+ public Position createPosition(int offset) {
+ return this.content.createPosition(offset);
}
- // find the parent, and the index into its children at which
- // this element should be inserted
- Element parent = this.rootElement;
- int childIndex = -1;
- while (childIndex == -1) {
- boolean tryAgain = false;
- Element[] children = parent.getChildElements();
- for (int i = 0; i < children.length; i++) {
- Element child = children[i];
- if (offset <= child.getStartOffset()) {
- childIndex = i;
- break;
- } else if (offset <= child.getEndOffset()) {
- parent = child;
- tryAgain = true;
- break;
+ /**
+ * Deletes a portion of the document. No element may straddle the deletion
+ * span.
+ *
+ * @param startOffset
+ * start of the range to delete
+ * @param endOffset
+ * end of the range to delete
+ * @throws DocumentValidationException
+ * if the change would result in an invalid document.
+ */
+ public void delete(int startOffset, int endOffset)
+ throws DocumentValidationException {
+
+ Element e1 = this.getElementAt(startOffset);
+ Element e2 = this.getElementAt(endOffset);
+ if (e1 != e2) {
+ throw new IllegalArgumentException("Deletion from " + startOffset
+ + " to " + endOffset + " is unbalanced");
}
- }
- if (!tryAgain && childIndex == -1) {
- childIndex = children.length;
- break;
- }
+
+ Validator validator = this.getValidator();
+ if (validator != null) {
+ String[] seq1 = this.getNodeNames(e1.getStartOffset() + 1,
+ startOffset);
+ String[] seq2 = this.getNodeNames(endOffset, e1.getEndOffset());
+ if (!validator
+ .isValidSequence(e1.getName(), seq1, seq2, null, true)) {
+ throw new DocumentValidationException("Unable to delete from "
+ + startOffset + " to " + endOffset);
+ }
+ }
+
+ // Grab the fragment for the undoable edit while it's still here
+ DocumentFragment frag = getFragment(startOffset, endOffset);
+
+ this.fireBeforeContentDeleted(new DocumentEvent(this, e1, startOffset,
+ endOffset - startOffset, null));
+
+ Iterator iter = e1.getChildIterator();
+ while (iter.hasNext()) {
+ Element child = (Element) iter.next();
+ if (startOffset <= child.getStartOffset()
+ && child.getEndOffset() < endOffset) {
+ iter.remove();
+ }
+ }
+
+ this.content.remove(startOffset, endOffset - startOffset);
+
+ IUndoableEdit edit = this.undoEnabled ? new DeleteEdit(startOffset,
+ endOffset, frag) : null;
+
+ this.fireContentDeleted(new DocumentEvent(this, e1, startOffset,
+ endOffset - startOffset, edit));
}
- this.fireBeforeContentInserted(new DocumentEvent(this, parent, offset, 2, null));
-
- this.content.insertString(offset, "\0\0");
+ /**
+ * Finds the lowest element that contains both of the given offsets.
+ *
+ * @param offset1
+ * the first offset
+ * @param offset2
+ * the second offset
+ */
+ public Element findCommonElement(int offset1, int offset2) {
+ Element element = this.rootElement;
+ for (;;) {
+ boolean tryAgain = false;
+ Element[] children = element.getChildElements();
+ for (int i = 0; i < children.length; i++) {
+ if (offset1 > children[i].getStartOffset()
+ && offset2 > children[i].getStartOffset()
+ && offset1 <= children[i].getEndOffset()
+ && offset2 <= children[i].getEndOffset()) {
- element.setContent(this.content, offset, offset + 1);
- element.setParent(parent);
- parent.insertChild(childIndex, element);
-
- IUndoableEdit edit = this.undoEnabled ?
- new InsertElementEdit(offset, element) : null;
-
- this.fireContentInserted(new DocumentEvent(this, parent, offset, 2, edit));
- }
-
-
- /**
- * Inserts a document fragment at the given position.
- *
- * @param offset character offset at which the element is to be inserted.
- * Must be greater or equal to 1 and less than the current length of the
- * document, i.e. it must be within the range of the root element.
- * @param fragment fragment to insert
- * @throws DocumentValidationException if the change would result
- * in an invalid document.
- */
- public void insertFragment(int offset, DocumentFragment fragment)
- throws DocumentValidationException {
-
- if (offset < 1 || offset >= this.getLength()) {
- throw new IllegalArgumentException("Error inserting document fragment");
- }
-
- Element parent = this.getElementAt(offset);
-
- if (this.validator != null) {
- String[] seq1 = this.getNodeNames(parent.getStartOffset() + 1, offset);
- String[] seq2 = fragment.getNodeNames();
- String[] seq3 = this.getNodeNames(offset, parent.getEndOffset());
- if (!validator.isValidSequence(
- parent.getName(), seq1, seq2, seq3, true)) {
-
- throw new DocumentValidationException("Cannot insert document fragment");
- }
- }
-
- this.fireBeforeContentInserted(new DocumentEvent(this, parent, offset, 2, null));
-
- Content c = fragment.getContent();
- String s = c.getString(0, c.getLength());
- this.content.insertString(offset, s);
-
- Element[] children = parent.getChildElements();
- int index = 0;
- while (index < children.length
- && children[index].getEndOffset() < offset) {
- index++;
- }
-
- Element[] elements = fragment.getElements();
- for (int i = 0; i < elements.length; i++) {
- Element newElement = this.cloneElement(elements[i], this.content, offset, parent);
- parent.insertChild(index, newElement);
- index++;
- }
-
- IUndoableEdit edit = this.undoEnabled ?
- new InsertFragmentEdit(offset, fragment) : null;
-
- this.fireContentInserted(
- new DocumentEvent(this, parent, offset, fragment.getContent().getLength(), edit));
- }
-
- /**
- * Inserts text at the given position.
- *
- * @param offset character offset at which the text is to be inserted.
- * Must be greater or equal to 1 and less than the current length of the
- * document, i.e. it must be within the range of the root element.
- * @param text text to insert
- * @return UndoableEdit that can be used to undo the deletion
- * @throws DocumentValidationException if the change would result
- * in an invalid document.
- */
- public void insertText(int offset, String text)
- throws DocumentValidationException {
-
- if (offset < 1 || offset >= this.getLength()) {
- throw new IllegalArgumentException("Offset must be between 1 and n-1");
+ element = children[i];
+ tryAgain = true;
+ break;
+ }
+ }
+ if (!tryAgain) {
+ break;
+ }
+ }
+ return element;
}
- Element parent = this.getElementAt(offset);
-
- boolean isValid = false;
- if (this.getCharacterAt(offset-1) != '\0') {
- isValid = true;
- } else if (this.getCharacterAt(offset) != '\0') {
- isValid = true;
- } else {
- Validator validator = this.getValidator();
- if (validator != null) {
- String[] seq1 = this.getNodeNames(parent.getStartOffset() + 1, offset);
- String[] seq2 = new String[] { Validator.PCDATA };
- String[] seq3 = this.getNodeNames(offset, parent.getEndOffset());
- isValid = validator.isValidSequence(
- parent.getName(), seq1, seq2, seq3, true);
- } else {
- isValid = true;
- }
+ /**
+ * Returns the character at the given offset.
+ */
+ public char getCharacterAt(int offset) {
+ return this.content.getString(offset, 1).charAt(0);
}
- if (!isValid) {
- throw new DocumentValidationException("Cannot insert text '" + text + "' at offset " + offset);
+ /**
+ * Returns the element at the given offset. The given offset must be greater
+ * or equal to 1 and less than the current document length.
+ */
+ public Element getElementAt(int offset) {
+ if (offset < 1 || offset >= this.getLength()) {
+ throw new IllegalArgumentException("Illegal offset: " + offset
+ + ". Must be between 1 and n-1");
+ }
+ Element element = this.rootElement;
+ for (;;) {
+ boolean tryAgain = false;
+ Element[] children = element.getChildElements();
+ for (int i = 0; i < children.length; i++) {
+ Element child = children[i];
+ if (offset <= child.getStartOffset()) {
+ return element;
+ } else if (offset <= child.getEndOffset()) {
+ element = child;
+ tryAgain = true;
+ break;
+ }
+ }
+ if (!tryAgain) {
+ break;
+ }
+ }
+ return element;
}
-
- // Convert control chars to spaces
- StringBuffer sb = new StringBuffer(text);
- for (int i = 0; i < sb.length(); i++) {
- if (Character.isISOControl(sb.charAt(i)) && sb.charAt(i) != '\n') {
- sb.setCharAt(i, ' ');
- }
+
+ /**
+ * Returns the encoding used for this document, or null if no encoding has
+ * been declared.
+ */
+ public String getEncoding() {
+ return this.encoding;
}
-
- String s = sb.toString();
- this.fireBeforeContentInserted(new DocumentEvent(this, parent, offset, 2, null));
-
- this.content.insertString(offset, s);
+ /**
+ * Create a <code>DocumentFragment</code> representing the given range of
+ * offsets.
+ *
+ * @return
+ */
+ public DocumentFragment getFragment(int startOffset, int endOffset) {
- IUndoableEdit edit = this.undoEnabled ?
- new InsertTextEdit(offset, s) : null;
-
- this.fireContentInserted(
- new DocumentEvent(this, parent, offset, s.length(), edit));
- }
+ assertOffset(startOffset, 0, this.content.getLength());
+ assertOffset(endOffset, 0, this.content.getLength());
- /**
- * Returns true if undo is enabled, that is, undoable edit events are fired
- * to registered listeners.
- */
- public boolean isUndoEnabled() {
- return this.undoEnabled;
- }
-
- /**
- * Removes a document listener from the list of listeners so that
- * it is no longer notified of document changes.
- *
- * @param listener <code>DocumentListener</code> to remove.
- */
- public void removeDocumentListener(DocumentListener listener) {
- this.listeners.remove(listener);
- }
+ if (endOffset <= startOffset) {
+ throw new IllegalArgumentException("Invalid range (" + startOffset
+ + ", " + endOffset + ")");
+ }
- /**
- * Sets the public ID for the document's document type.
- *
- * @param publicID New value for the public ID.
- */
- public void setPublicID(String publicID) {
- this.publicID = publicID;
- }
+ Element e1 = this.getElementAt(startOffset);
+ Element e2 = this.getElementAt(endOffset);
+ if (e1 != e2) {
+ throw new IllegalArgumentException("Fragment from " + startOffset
+ + " to " + endOffset + " is unbalanced");
+ }
- /**
- * Sets the system ID for the document's document type.
- *
- * @param systemID New value for the system ID.
- */
- public void setSystemID(String systemID) {
- this.systemID = systemID;
- }
+ Element[] children = e1.getChildElements();
- /**
- * Sets whether undo events are enabled. Typically, undo events are
- * disabled while an edit is being undone or redone.
- *
- * @param undoEnabled If true, undoable edit events are fired to
- * registered listeners.
- */
- public void setUndoEnabled(boolean undoEnabled) {
- this.undoEnabled = undoEnabled;
- }
-
- /**
- * Sets the validator to use for this document.
- *
- * @param validator Validator to use for this document.
- */
- public void setValidator(Validator validator) {
- this.validator = validator;
- }
+ Content newContent = new GapContent(endOffset - startOffset);
+ String s = this.content.getString(startOffset, endOffset - startOffset);
+ newContent.insertString(0, s);
+ List newChildren = new ArrayList();
+ for (int i = 0; i < children.length; i++) {
+ Element child = children[i];
+ if (child.getEndOffset() <= startOffset) {
+ continue;
+ } else if (child.getStartOffset() >= endOffset) {
+ break;
+ } else {
+ newChildren.add(this.cloneElement(child, newContent,
+ -startOffset, null));
+ }
+ }
- //==================================================== PRIVATE
-
- /**
- * Represents a deletion from a document that can be undone
- * and redone.
- */
- private class DeleteEdit implements IUndoableEdit {
+ Element[] elementArray = (Element[]) newChildren
+ .toArray(new Element[newChildren.size()]);
+ return new DocumentFragment(newContent, elementArray);
+ }
- private int startOffset;
- private int endOffset;
- private DocumentFragment frag;
-
- public DeleteEdit(int startOffset, int endOffset, DocumentFragment frag) {
- this.startOffset = startOffset;
- this.endOffset = endOffset;
- this.frag = frag;
- }
-
- public boolean combine(IUndoableEdit edit) {
- return false;
- }
+ /**
+ * Returns the length of the document in characters, including the null
+ * characters that delimit each element.
+ */
+ public int getLength() {
+ return this.content.getLength();
+ }
- public void undo() throws CannotUndoException {
- try {
- setUndoEnabled(false);
- insertFragment(this.startOffset, this.frag);
- } catch (DocumentValidationException ex) {
- throw new CannotUndoException();
- } finally {
- setUndoEnabled(true);
- }
- }
+ /**
+ * Returns an array of element names and Validator.PCDATA representing the
+ * content between the given offsets. The given offsets must both be
+ * directly in the same element.
+ *
+ * @param startOffset
+ * the offset at which the sequence begins
+ * @param endOffset
+ * the offset at which the sequence ends
+ */
+ public String[] getNodeNames(int startOffset, int endOffset) {
- public void redo() throws CannotRedoException {
- try {
- setUndoEnabled(false);
- delete(this.startOffset, this.endOffset);
- } catch (DocumentValidationException ex) {
- throw new CannotUndoException();
- } finally {
- setUndoEnabled(true);
- }
- }
+ Node[] nodes = this.getNodes(startOffset, endOffset);
+ String[] names = new String[nodes.length];
- }
+ for (int i = 0; i < nodes.length; i++) {
+ Node node = nodes[i];
+ if (node instanceof Element) {
+ names[i] = ((Element) node).getName();
+ } else {
+ names[i] = Validator.PCDATA;
+ }
+ }
+ return names;
+ }
- /**
- * Represents an insertion of an element into the document.
- */
- private class InsertElementEdit implements IUndoableEdit {
+ /**
+ * Returns an array of Nodes representing the selected range. The given
+ * offsets must both be directly in the same element.
+ *
+ * @param startOffset
+ * the offset at which the sequence begins
+ * @param endOffset
+ * the offset at which the sequence ends
+ */
+ public Node[] getNodes(int startOffset, int endOffset) {
- private int offset;
- private Element element;
-
- public InsertElementEdit(int offset, Element element) {
- this.offset = offset;
- this.element = element;
- }
+ Element element = this.getElementAt(startOffset);
+ if (element != this.getElementAt(endOffset)) {
+ throw new IllegalArgumentException("Offsets are unbalanced: "
+ + startOffset + " is in " + element.getName() + ", "
+ + endOffset + " is in "
+ + this.getElementAt(endOffset).getName());
+ }
- public boolean combine(IUndoableEdit edit) {
- return false;
- }
+ List list = new ArrayList();
+ Node[] nodes = element.getChildNodes();
+ for (int i = 0; i < nodes.length; i++) {
+ Node node = nodes[i];
+ if (node.getEndOffset() <= startOffset) {
+ continue;
+ } else if (node.getStartOffset() >= endOffset) {
+ break;
+ } else {
+ if (node instanceof Element) {
+ list.add(node);
+ } else {
+ Text text = (Text) node;
+ if (text.getStartOffset() < startOffset) {
+ text.setContent(text.getContent(), startOffset, text
+ .getEndOffset());
+ } else if (text.getEndOffset() > endOffset) {
+ text.setContent(text.getContent(), text
+ .getStartOffset(), endOffset);
+ }
+ list.add(text);
+ }
+ }
+ }
- public void undo() throws CannotUndoException {
- try {
- setUndoEnabled(false);
- delete(this.offset, this.offset + 2);
- } catch (DocumentValidationException ex) {
- throw new CannotUndoException();
- } finally {
- setUndoEnabled(true);
- }
- }
+ return (Node[]) list.toArray(new Node[list.size()]);
+ }
- public void redo() throws CannotRedoException {
- try {
- setUndoEnabled(false);
- insertElement(this.offset, this.element);
- } catch (DocumentValidationException ex) {
- throw new CannotUndoException();
- } finally {
- setUndoEnabled(true);
- }
- }
+ /**
+ * Creates an array of nodes for a given run of content. The returned array
+ * includes the given child elements and <code>Text</code> objects where
+ * text appears between elements.
+ *
+ * @param content
+ * Content object containing the content
+ * @param startOffset
+ * start offset of the run
+ * @param endOffset
+ * end offset of the run
+ * @param elements
+ * child elements that are within the run
+ */
+ static Node[] createNodeArray(Content content, int startOffset,
+ int endOffset, Element[] elements) {
- }
-
-
- /**
- * Represents an insertion of a fragment into the document.
- */
- private class InsertFragmentEdit implements IUndoableEdit {
+ List nodes = new ArrayList();
+ int offset = startOffset;
+ for (int i = 0; i < elements.length; i++) {
+ int start = elements[i].getStartOffset();
+ if (offset < start) {
+ nodes.add(new Text(content, offset, start));
+ }
+ nodes.add(elements[i]);
+ offset = elements[i].getEndOffset() + 1;
+ }
- private int offset;
- private DocumentFragment frag;
-
- public InsertFragmentEdit(int offset, DocumentFragment frag) {
- this.offset = offset;
- this.frag = frag;
- }
+ if (offset < endOffset) {
+ nodes.add(new Text(content, offset, endOffset));
+ }
- public boolean combine(IUndoableEdit edit) {
- return false;
- }
+ return (Node[]) nodes.toArray(new Node[nodes.size()]);
+ }
- public void undo() throws CannotUndoException {
- try {
- setUndoEnabled(false);
- int length = this.frag.getContent().getLength();
- delete(this.offset, this.offset + length);
- } catch (DocumentValidationException ex) {
- throw new CannotUndoException();
- } finally {
- setUndoEnabled(true);
- }
- }
+ /**
+ * Returns the public ID of the document type.
+ */
+ public String getPublicID() {
+ return this.publicID;
+ }
- public void redo() throws CannotRedoException {
- try {
- setUndoEnabled(false);
- insertFragment(this.offset, this.frag);
- } catch (DocumentValidationException ex) {
- throw new CannotUndoException();
- } finally {
- setUndoEnabled(true);
- }
- }
+ /**
+ * Returns the text between the two given offsets. Unlike getText, sentinel
+ * characters are not removed.
+ *
+ * @param startOffset
+ * character offset of the start of the text
+ * @param endOffset
+ * character offset of the end of the text
+ */
+ public String getRawText(int startOffset, int endOffset) {
+ return this.content.getString(startOffset, endOffset - startOffset);
+ }
- }
-
-
- /**
- * Represents an insertion of text into the document.
- */
- private class InsertTextEdit implements IUndoableEdit {
+ /**
+ * Returns the root element of this document.
+ */
+ public Element getRootElement() {
+ return this.rootElement;
+ }
- private int offset;
- private String text;
-
- public InsertTextEdit(int offset, String text) {
- this.offset = offset;
- this.text = text;
- }
+ /**
+ * Returns the system ID of the document type.
+ */
+ public String getSystemID() {
+ return this.systemID;
+ }
- public boolean combine(IUndoableEdit edit) {
- if (edit instanceof InsertTextEdit) {
- InsertTextEdit ite = (InsertTextEdit) edit;
- if (ite.offset == this.offset + this.text.length()) {
- this.text = this.text + ite.text;
- return true;
- }
- }
- return false;
- }
+ /**
+ * Returns the text between the two given offsets. Sentinal characters are
+ * removed.
+ *
+ * @param startOffset
+ * character offset of the start of the text
+ * @param endOffset
+ * character offset of the end of the text
+ */
+ public String getText(int startOffset, int endOffset) {
+ String raw = this.content.getString(startOffset, endOffset
+ - startOffset);
+ StringBuffer sb = new StringBuffer(raw.length());
+ for (int i = 0; i < raw.length(); i++) {
+ char c = raw.charAt(i);
+ if (c != '\0') {
+ sb.append(c);
+ }
+ }
+ return sb.toString();
+ }
- public void undo() throws CannotUndoException {
- try {
- setUndoEnabled(false);
- delete(this.offset, this.offset + this.text.length());
- } catch (DocumentValidationException ex) {
- throw new CannotUndoException();
- } finally {
- setUndoEnabled(true);
- }
- }
+ /**
+ * Returns the validator used to validate the document, or null if a
+ * validator has not been set. Note that the DocumentFactory does not
+ * automatically create a validator.
+ */
+ public Validator getValidator() {
+ return this.validator;
+ }
- public void redo() throws CannotRedoException {
- try {
- setUndoEnabled(false);
- insertText(this.offset, this.text);
- } catch (DocumentValidationException ex) {
- throw new CannotUndoException();
- } finally {
- setUndoEnabled(true);
- }
- }
+ /**
+ * Inserts an element at the given position.
+ *
+ * @param offset
+ * character offset at which the element is to be inserted. Must
+ * be greater or equal to 1 and less than the current length of
+ * the document, i.e. it must be within the range of the root
+ * element.
+ * @param element
+ * element to insert
+ * @throws DocumentValidationException
+ * if the change would result in an invalid document.
+ */
+ public void insertElement(int offset, Element element)
+ throws DocumentValidationException {
- }
-
- /**
- * Assert that the given offset is within the given range,
- * throwing IllegalArgumentException if not.
- */
- private static void assertOffset(int offset, int min, int max) {
- if (offset < min || offset > max) {
- throw new IllegalArgumentException("Bad offset " + offset +
- "must be between " + min +
- " and " + max);
- }
- }
+ if (offset < 1 || offset >= this.getLength()) {
+ throw new IllegalArgumentException("Error inserting element <"
+ + element.getName() + ">: offset is " + offset
+ + ", but it must be between 1 and "
+ + (this.getLength() - 1));
+ }
+ Validator validator = this.getValidator();
+ if (validator != null) {
+ Element parent = this.getElementAt(offset);
+ String[] seq1 = this.getNodeNames(parent.getStartOffset() + 1,
+ offset);
+ String[] seq2 = new String[] { element.getName() };
+ String[] seq3 = this.getNodeNames(offset, parent.getEndOffset());
+ if (!validator.isValidSequence(parent.getName(), seq1, seq2, seq3,
+ true)) {
+ throw new DocumentValidationException("Cannot insert element "
+ + element.getName() + " at offset " + offset);
+ }
+ }
+ // find the parent, and the index into its children at which
+ // this element should be inserted
+ Element parent = this.rootElement;
+ int childIndex = -1;
+ while (childIndex == -1) {
+ boolean tryAgain = false;
+ Element[] children = parent.getChildElements();
+ for (int i = 0; i < children.length; i++) {
+ Element child = children[i];
+ if (offset <= child.getStartOffset()) {
+ childIndex = i;
+ break;
+ } else if (offset <= child.getEndOffset()) {
+ parent = child;
+ tryAgain = true;
+ break;
+ }
+ }
+ if (!tryAgain && childIndex == -1) {
+ childIndex = children.length;
+ break;
+ }
+ }
- /**
- * Clone an element tree, pointing to a new Content object.
- *
- * @param original Element to be cloned
- * @param content new Content object to which the clone will point
- * @param shift amount to shift offsets to be valid in the new Content.
- * @param parent parent for the cloned Element
- */
- private Element cloneElement(
- Element original,
- Content content,
- int shift,
- Element parent) {
-
- Element clone = new Element(original.getName());
- clone.setContent(
- content,
- original.getStartOffset() + shift,
- original.getEndOffset() + shift);
- String[] attrNames = original.getAttributeNames();
- for (int i = 0; i < attrNames.length; i++) {
- try {
- clone.setAttribute(attrNames[i], original.getAttribute(attrNames[i]));
- } catch (DocumentValidationException ex) {
- throw new RuntimeException("Unexpected exception: " + ex);
- }
- }
- clone.setParent(parent);
+ this.fireBeforeContentInserted(new DocumentEvent(this, parent, offset,
+ 2, null));
- Element[] children = original.getChildElements();
- for (int i = 0; i < children.length; i++) {
- Element cloneChild =
- this.cloneElement(children[i], content, shift, clone);
- clone.insertChild(i, cloneChild);
- }
+ this.content.insertString(offset, "\0\0");
- return clone;
- }
-
- void fireAttributeChanged(DocumentEvent e) {
- this.listeners.fireEvent("attributeChanged", e);
- }
-
- private void fireBeforeContentDeleted(DocumentEvent e) {
- this.listeners.fireEvent("beforeContentDeleted", e);
- }
+ element.setContent(this.content, offset, offset + 1);
+ element.setParent(parent);
+ parent.insertChild(childIndex, element);
- private void fireBeforeContentInserted(DocumentEvent e) {
- this.listeners.fireEvent("beforeContentInserted", e);
- }
+ IUndoableEdit edit = this.undoEnabled ? new InsertElementEdit(offset,
+ element) : null;
- private void fireContentDeleted(DocumentEvent e) {
- this.listeners.fireEvent("contentDeleted", e);
- }
+ this.fireContentInserted(new DocumentEvent(this, parent, offset, 2,
+ edit));
+ }
- private void fireContentInserted(DocumentEvent e) {
- this.listeners.fireEvent("contentInserted", e);
- }
+ /**
+ * Inserts a document fragment at the given position.
+ *
+ * @param offset
+ * character offset at which the element is to be inserted. Must
+ * be greater or equal to 1 and less than the current length of
+ * the document, i.e. it must be within the range of the root
+ * element.
+ * @param fragment
+ * fragment to insert
+ * @throws DocumentValidationException
+ * if the change would result in an invalid document.
+ */
+ public void insertFragment(int offset, DocumentFragment fragment)
+ throws DocumentValidationException {
+ if (offset < 1 || offset >= this.getLength()) {
+ throw new IllegalArgumentException(
+ "Error inserting document fragment");
+ }
+
+ Element parent = this.getElementAt(offset);
+
+ if (this.validator != null) {
+ String[] seq1 = this.getNodeNames(parent.getStartOffset() + 1,
+ offset);
+ String[] seq2 = fragment.getNodeNames();
+ String[] seq3 = this.getNodeNames(offset, parent.getEndOffset());
+ if (!validator.isValidSequence(parent.getName(), seq1, seq2, seq3,
+ true)) {
+
+ throw new DocumentValidationException(
+ "Cannot insert document fragment");
+ }
+ }
+
+ this.fireBeforeContentInserted(new DocumentEvent(this, parent, offset,
+ 2, null));
+
+ Content c = fragment.getContent();
+ String s = c.getString(0, c.getLength());
+ this.content.insertString(offset, s);
+
+ Element[] children = parent.getChildElements();
+ int index = 0;
+ while (index < children.length
+ && children[index].getEndOffset() < offset) {
+ index++;
+ }
+
+ Element[] elements = fragment.getElements();
+ for (int i = 0; i < elements.length; i++) {
+ Element newElement = this.cloneElement(elements[i], this.content,
+ offset, parent);
+ parent.insertChild(index, newElement);
+ index++;
+ }
+
+ IUndoableEdit edit = this.undoEnabled ? new InsertFragmentEdit(offset,
+ fragment) : null;
+
+ this.fireContentInserted(new DocumentEvent(this, parent, offset,
+ fragment.getContent().getLength(), edit));
+ }
+
+ /**
+ * Inserts text at the given position.
+ *
+ * @param offset
+ * character offset at which the text is to be inserted. Must be
+ * greater or equal to 1 and less than the current length of the
+ * document, i.e. it must be within the range of the root
+ * element.
+ * @param text
+ * text to insert
+ * @return UndoableEdit that can be used to undo the deletion
+ * @throws DocumentValidationException
+ * if the change would result in an invalid document.
+ */
+ public void insertText(int offset, String text)
+ throws DocumentValidationException {
+
+ if (offset < 1 || offset >= this.getLength()) {
+ throw new IllegalArgumentException(
+ "Offset must be between 1 and n-1");
+ }
+
+ Element parent = this.getElementAt(offset);
+
+ boolean isValid = false;
+ if (this.getCharacterAt(offset - 1) != '\0') {
+ isValid = true;
+ } else if (this.getCharacterAt(offset) != '\0') {
+ isValid = true;
+ } else {
+ Validator validator = this.getValidator();
+ if (validator != null) {
+ String[] seq1 = this.getNodeNames(parent.getStartOffset() + 1,
+ offset);
+ String[] seq2 = new String[] { Validator.PCDATA };
+ String[] seq3 = this
+ .getNodeNames(offset, parent.getEndOffset());
+ isValid = validator.isValidSequence(parent.getName(), seq1,
+ seq2, seq3, true);
+ } else {
+ isValid = tr