diff options
Diffstat (limited to 'jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2')
141 files changed, 0 insertions, 20140 deletions
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/CSSTempUtil.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/CSSTempUtil.java deleted file mode 100644 index 38310c30a..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/CSSTempUtil.java +++ /dev/null @@ -1,134 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.jst.pagedesigner.IHTMLConstants; -import org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetAdapter; -import org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetListAdapter; -import org.eclipse.wst.html.core.internal.provisional.HTML40Namespace; -import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter; -import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.stylesheets.StyleSheet; -import org.w3c.dom.stylesheets.StyleSheetList; - -/** - * @author mengbo - * @version 1.5 - */ -public class CSSTempUtil { - /** - * the default implementation of (IStyleSheetListAdapter) - * docnotifier.getAdapterFor(IStyleSheetListAdapter.class) will only get - * those style tags under certain tags like "html", "head", etc. - * - * But datawindow is generating style tag and is not putting them into - * "head". So we can't handle them using the default SSE mechanism. - * - * We have another problem: currently the converted element is also using - * the original document, not generating another document, and these - * elements is not really adding into the document, so they can't be reached - * from the document. - * - * @param ele - * @return - * @see org.eclipse.wst.html.core.htmlcss.HTMLDocumentAdapter#addStyleSheet(org.w3c.dom.Element) - */ - public static List getStyleSheets(Element element) { - List styleSheets = new ArrayList(); - INodeNotifier docnotifier = (INodeNotifier) element.getOwnerDocument(); - IStyleSheetListAdapter adapter = (IStyleSheetListAdapter) docnotifier - .getAdapterFor(IStyleSheetListAdapter.class); - - StyleSheetList ssl = (adapter == null ? null : adapter.getStyleSheets()); - - if (ssl != null) { - for (int i = 0, numStyles = ssl.getLength(); i < numStyles; i++) { - // loop for styles (<style> and <link>) - org.w3c.dom.stylesheets.StyleSheet ss = ssl.item(i); - styleSheets.add(ss); - } - } - - // now is our work-around part for support datawindow. - Node parent = element.getParentNode(); - Element rootEle = element; - while (parent != null && parent instanceof Element) { - rootEle = (Element) parent; - parent = parent.getParentNode(); - } - addStyleSheet(rootEle, styleSheets); - return styleSheets; - } - - /** - */ - private static void addStyleSheet(Element node, List result) { - IDOMElement element = (IDOMElement) node; - String tagName = element.getTagName(); - if (tagName == null) { - return; - } - boolean isContainer = false; - - if (element.isCommentTag()) { - Node parent = element.getParentNode(); - if (parent == element.getOwnerDocument()) { - // This condition is too severe, actually do not work for JSF - // template. - // But above (! globalTag() && isContainer()) cover JSF template - // + tpl template - isContainer = true; - } else if (parent.getNodeType() == Node.ELEMENT_NODE) { - tagName = ((Element) parent).getTagName(); - if (tagName != null - && tagName - .equalsIgnoreCase(HTML40Namespace.ElementName.HEAD)) { - isContainer = true; - } - } - } else { - INodeNotifier notifier = element; - - // (lium) Increase performance: since this method is called tooooo - // many times, - // and getAdapterFor() is slow, so add a check on the tagName to - // filter - // those stylesheet stuff first. - if (IHTMLConstants.TAG_LINK.equalsIgnoreCase(tagName) - || IHTMLConstants.TAG_STYLE.equalsIgnoreCase(tagName)) { - INodeAdapter adapter = notifier - .getAdapterFor(IStyleSheetAdapter.class); - if (adapter != null && adapter instanceof IStyleSheetAdapter) { - StyleSheet sheet = ((IStyleSheetAdapter) adapter) - .getSheet(); - result.add(sheet); - } - } - - isContainer = true; - } - if (isContainer) { - for (Node child = element.getFirstChild(); child != null; child = child - .getNextSibling()) { - if (child.getNodeType() != Node.ELEMENT_NODE) - continue; - addStyleSheet((Element) child, result); - } - } - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/CSSUtil.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/CSSUtil.java deleted file mode 100644 index edd0ffeff..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/CSSUtil.java +++ /dev/null @@ -1,241 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2; - -import java.io.IOException; -import java.io.InputStream; -import java.io.UnsupportedEncodingException; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import org.eclipse.jst.jsf.common.ui.internal.logging.Logger; -import org.eclipse.jst.jsf.common.ui.internal.utils.ResourceUtils; -import org.eclipse.jst.pagedesigner.IJMTConstants; -import org.eclipse.jst.pagedesigner.PDPlugin; -import org.eclipse.jst.pagedesigner.css2.font.CSSFont; -import org.eclipse.jst.pagedesigner.css2.style.DefaultStyle; -import org.eclipse.swt.graphics.Color; -import org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetListAdapter; -import org.eclipse.wst.css.core.internal.provisional.document.ICSSModel; -import org.eclipse.wst.css.core.internal.provisional.document.ICSSNode; -import org.eclipse.wst.css.core.internal.util.CSSClassTraverser; -import org.eclipse.wst.html.core.internal.htmlcss.CSSQueryTraverser; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.css.CSSStyleDeclaration; -import org.w3c.dom.stylesheets.StyleSheet; -import org.w3c.dom.stylesheets.StyleSheetList; - -/** - * @author mengbo - */ -public class CSSUtil { - private static StyleSheet _userAgentDefault; - - public static String[] getCSSClasses(Document doc) { - Collection c = Collections.EMPTY_SET; - if (doc instanceof INodeNotifier) { - IStyleSheetListAdapter adapter = (IStyleSheetListAdapter) ((INodeNotifier) doc) - .getAdapterFor(IStyleSheetListAdapter.class); - StyleSheetList ssl = (adapter == null ? null : adapter - .getStyleSheets()); - - CSSClassTraverser traverser = new CSSClassTraverser(); - if (ssl != null) { - for (int i = 0, numStyles = ssl.getLength(); i < numStyles; i++) { - // loop for styles (<style> and <link>) - org.w3c.dom.stylesheets.StyleSheet ss = ssl.item(i); - - try { - traverser.apply((ICSSNode) ss); - } catch (ClassCastException ex) { - Logger log = PDPlugin - .getLogger(CSSStyleDeclaration.class); - log.error("Error.CSSUtil.0", ex); //$NON-NLS-1$ - // FIXME: should this continue to be processed? - } - } - c = traverser.getClassNames(); - } - } - String[] result = new String[c.size()]; - c.toArray(result); - return result; - } - - /** - * Get the css style of a node. - * - * @param node - * @return - */ - public static ICSSStyle getCSSStyle(Element node) { - ICSSStyle style = null; - if (node instanceof IDOMElement) { - style = (ICSSStyle) ((IDOMElement) node) - .getAdapterFor(ICSSStyle.class); - } - if (style == null) { - return DefaultStyle.getInstance(); - } - return style; - } - - /** - * Resolve the css style string from css style elements. - * - * @param node - * @return - */ - public static String resolveCSSStyle(ICSSStyle style) { - StringBuffer sb = new StringBuffer(); - Object object1 = style.getColor(); - if (object1 instanceof Color) { - sb.append("color:"); - - sb.append("#").append( - Integer.toHexString(((Color) object1).getRed())); - sb.append("#").append( - Integer.toHexString(((Color) object1).getGreen())); - sb.append("#").append( - Integer.toHexString(((Color) object1).getBlue())); - sb.append(";"); - } - Object object2 = style.getCSSFont(); - if (object2 instanceof CSSFont) { - sb.append(((CSSFont) object2).getCSSString()); - } - return sb.toString(); - } - - /** - * Many of this method implementation copied from HTMLDocumentAdapter, - * mainly add support for user agent default style sheet. - * - * @param element - * the element. - * @param pseudoName - * the pseudoname of the element - * @return - */ - public static CSSStyleDeclaration getCSSDeclaration(Element element, - String pseudoName) { - // please reference comments in CSSTempUtil. - List styleSheets = CSSTempUtil.getStyleSheets(element); - // INodeNotifier docnotifier = (INodeNotifier) - // element.getOwnerDocument(); - // IStyleSheetListAdapter adapter = (IStyleSheetListAdapter) - // docnotifier.getAdapterFor(IStyleSheetListAdapter.class); - // - // StyleSheetList ssl = (adapter == null ? null : - // adapter.getStyleSheets()); - - CSSQueryTraverser query = new CSSQueryTraverser(); - query.setTraverseImported(true); - query.setTraverseImportFirst(true); - query.setElement(element, pseudoName); - - // if (ssl != null) - // { - // for (int i = 0, numStyles = ssl.getLength(); i < numStyles; i++) - // { - // // loop for styles (<style> and <link>) - // org.w3c.dom.stylesheets.StyleSheet ss = ssl.item(i); - if (styleSheets != null) { - for (int i = 0, numStyles = styleSheets.size(); i < numStyles; i++) { - StyleSheet ss = (StyleSheet) styleSheets.get(i); - try { - query.apply((ICSSNode) ss); - } catch (ClassCastException ex) { - Logger log = PDPlugin.getLogger(CSSStyleDeclaration.class); - log.error("Error.CSSUtil.0", ex); //$NON-NLS-1$ - // FIXME: should this continue to be processed? - } - } - } - CSSStyleDeclaration declare = query.getDeclaration(); - // FIXME: when do we need to apply the user agent style sheet? - return declare; - } - - /** - * Many of this method implementation copied from HTMLDocumentAdapter, - * mainly add support for user agent default style sheet. - * - * @param element - * the element. - * @param pseudoName - * the pseudoname of the element - * @return - */ - public static CSSStyleDeclaration getDefaultCSSDeclaration(Element element, - String pseudoName) { - CSSQueryTraverser query = new CSSQueryTraverser(); - query.setTraverseImported(true); - query.setTraverseImportFirst(true); - - query.setElement(element, pseudoName); - - // FIXME: when do we need to apply the user agent style sheet? - try { - getUserAgentDefaultStyleSheet(element); - } catch (UnsupportedEncodingException e) { - Logger log = PDPlugin.getLogger(CSSStyleDeclaration.class); - log.error("Error.CSSUtil.1", e); //$NON-NLS-1$ - } catch (IOException e) { - Logger log = PDPlugin.getLogger(CSSStyleDeclaration.class); - log.error("Error.CSSUtil.2", e); //$NON-NLS-1$ - } - if (_userAgentDefault != null) { - try { - query.apply((ICSSNode) _userAgentDefault); - } catch (ClassCastException ex) { - Logger log = PDPlugin.getLogger(CSSStyleDeclaration.class); - log.error("Error.CSSUtil.3", ex); //$NON-NLS-1$ - } - } - CSSStyleDeclaration declare = query.getDeclaration(); - return declare; - } - - /** - * Get the user agent default style sheet. - * - * @param element - * @return - * @throws IOException - * @throws UnsupportedEncodingException - */ - // XXX: in the future, we may get user agent default style sheet based on - // device type. - private static StyleSheet getUserAgentDefaultStyleSheet(Element element) - throws UnsupportedEncodingException, IOException { - if (_userAgentDefault == null) { - InputStream input = CSSUtil.class - .getResourceAsStream(IJMTConstants.USERAGENT); - IStructuredModel model = StructuredModelManager.getModelManager() - .getModelForEdit(IJMTConstants.USERAGENT, input, null); - ICSSModel cssmodel = (ICSSModel) model; - _userAgentDefault = (StyleSheet) cssmodel.getDocument(); - - ResourceUtils.ensureClosed(input); - } - - return _userAgentDefault; - } - -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/ICSSStyle.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/ICSSStyle.java deleted file mode 100644 index 190d5ee70..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/ICSSStyle.java +++ /dev/null @@ -1,128 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2; - -import java.util.Map; - -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.draw2d.geometry.Insets; -import org.eclipse.jst.pagedesigner.css2.font.ICSSFont; -import org.eclipse.jst.pagedesigner.css2.list.ICounterValueGenerator; -import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter; - -/** - * The style declaration for an element can be cached. - * - * @author mengbo - */ -public interface ICSSStyle extends INodeAdapter, IAdaptable { - public static final int INHERIT = Integer.MIN_VALUE; - - public static final String TOP = "top"; - - public static final String RIGHT = "right"; - - public static final String LEFT = "left"; - - public static final String BOTTOM = "bottom"; - - public void reset(); - - public ICSSFont getCSSFont(); - - public Object getStyleProperty(String property); - - public Insets getMarginInsets(); - - public Insets getBorderInsets(); - - public Insets getPaddingInsets(); - - /** - * shortcut method to get the CSS display. - * - * @see http://www.w3.org/TR/REC-CSS2/visuren.html#propdef-display - * @return - */ - public String getDisplay(); - - /** - * null means transparent. - * - * @return - */ - public Object getBackgroundColor(); - - public Object getColor(); - - /** - * @return - */ - public boolean isSizeIncludeBorderPadding(); - - public void dispose(); - - /** - * @return - */ - public ICSSStyle getParentStyle(); - - /** - * Get counters declared on this style. the counters are either created by - * counter-reset or refered by counter-increment - * - * @return - */ - public Map getCounters(); - - /** - * Search a named counter declared on this style or its ancestors' styles - * - * @param name - * @param must - * @return - */ - public ICounterValueGenerator findCounter(String name, boolean must); - - /** - * Currently, rowspan and colspan are not CSS property. But based on the CSS - * specification, it is expected in the future this two will be added as CSS - * property, so we also include them into ICSSStyle - * - * @return - */ - public int getRowSpan(); - - /** - * @return - */ - public int getColSpan(); - - /** - * Normally, when layout a figure and its children. We'll reset the counters - * declared on this style. And if there are "counter-increment" on this - * style, they'll also be processed. - * - */ - public void processCounters(); - - /** - * Whether the corresponding figure should be draw in selected mode. This is - * not a real CSS property. This is a shortcut method. implemented through - * getAdapter() on IRangeSelectionProxy - * - * @return - */ - public boolean isInSelection(); - - public Object getHTMLelementInitValue(String propertyName); -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/border/CSSBorder.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/border/CSSBorder.java deleted file mode 100644 index b2afe44df..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/border/CSSBorder.java +++ /dev/null @@ -1,526 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.border; - -import java.util.Arrays; - -import org.eclipse.draw2d.AbstractBorder; -import org.eclipse.draw2d.ColorConstants; -import org.eclipse.draw2d.Graphics; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.geometry.Insets; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyID; -import org.eclipse.jst.pagedesigner.editors.pagedesigner.MessageFormater; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.swt.widgets.Display; - -/** - * @author mengbo - */ -public class CSSBorder extends AbstractBorder { - - private static final String BODER_QUERY_TEMPLETE = "border-{0}-style"; - - private static final String COLOR_QUERY_TEMPLETE = "border-{0}-color"; - - private ICSSStyle _style; - - protected Rectangle _innerRect = new Rectangle(); - - public CSSBorder(ICSSStyle style) { - this._style = style; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.draw2d.Border#getInsets(org.eclipse.draw2d.IFigure) - */ - public Insets getInsets(IFigure figure) { - return _style.getBorderInsets(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.draw2d.Border#paint(org.eclipse.draw2d.IFigure, - * org.eclipse.draw2d.Graphics, org.eclipse.draw2d.geometry.Insets) - */ - public void paint(IFigure figure, Graphics graphics, Insets insets) { - tempRect.setBounds(getPaintRectangle(figure, insets)); - _innerRect.setBounds(tempRect); - _innerRect.crop(_style.getBorderInsets()); - paintEdge(graphics, tempRect, _innerRect, ICSSStyle.LEFT); - paintEdge(graphics, tempRect, _innerRect, ICSSStyle.RIGHT); - paintEdge(graphics, tempRect, _innerRect, ICSSStyle.TOP); - paintEdge(graphics, tempRect, _innerRect, ICSSStyle.BOTTOM); - } - - /** - * @param style - * @return - */ - private boolean shouldDraw(String style) { - return style != null && !ICSSPropertyID.VAL_NONE.equals(style) - && !ICSSPropertyID.VAL_HIDDEN.equals(style); - } - - /** - * Fetchs the color array used to draw the given edge under the given style - * - * @param graphics - * @param style - * @param edge - * @return - */ - private RGB[] getEdgeColors(Graphics graphics, String style, String edge) { - String property = MessageFormater.format(COLOR_QUERY_TEMPLETE, edge); - Object obj = _style.getStyleProperty(property); - if (obj instanceof RGB) { - return getCustomColors(graphics, style, edge, (RGB) obj); - } else if (obj instanceof Color) { - return getCustomColors(graphics, style, edge, ((Color) obj) - .getRGB()); - } else { - return getDefaultColors(graphics, style, edge); - } - } - // TODO: needs refactoring - private RGB[] getDefaultColors(Graphics graphics, String style, String edge) { - if (ICSSPropertyID.VAL_OUTSET.equals(style)) { - if (ICSSStyle.TOP.equals(edge) || ICSSStyle.LEFT.equals(edge)) { - return new RGB[] { ColorConstants.button.getRGB(), - ColorConstants.buttonLightest.getRGB() }; - } - return new RGB[] { ColorConstants.buttonDarkest.getRGB(), - ColorConstants.buttonDarker.getRGB() }; - } else if (ICSSPropertyID.VAL_INSET.equals(style)) { - if (ICSSStyle.TOP.equals(edge) || ICSSStyle.LEFT.equals(edge)) { - return new RGB[] { ColorConstants.buttonDarker.getRGB(), - ColorConstants.buttonDarkest.getRGB() }; - } - return new RGB[] { ColorConstants.buttonLightest.getRGB(), - ColorConstants.button.getRGB() }; - } else if (ICSSPropertyID.VAL_TDBORDERSTYLE.equals(style)) { - if (ICSSStyle.TOP.equals(edge) || ICSSStyle.LEFT.equals(edge)) { - return new RGB[] { ColorConstants.buttonDarker.getRGB() }; - } - return new RGB[] { ColorConstants.button.getRGB() }; - } else if (ICSSPropertyID.VAL_RIDGE.equals(style)) { - if (ICSSStyle.TOP.equals(edge) || ICSSStyle.LEFT.equals(edge)) { - return new RGB[] { ColorConstants.button.getRGB(), - ColorConstants.buttonDarkest.getRGB() }; - } - return new RGB[] { ColorConstants.buttonDarkest.getRGB(), - ColorConstants.button.getRGB() }; - } else if (ICSSPropertyID.VAL_GROOVE.equals(style)) { - if (ICSSStyle.TOP.equals(edge) || ICSSStyle.LEFT.equals(edge)) { - return new RGB[] { ColorConstants.buttonDarker.getRGB(), - ColorConstants.buttonLightest.getRGB() }; - } - return new RGB[] { ColorConstants.buttonLightest.getRGB(), - ColorConstants.buttonDarker.getRGB(), }; - } else if (ICSSPropertyID.VAL_DOUBLE.equals(style)) { - return new RGB[] { ColorConstants.buttonDarkest.getRGB(), - graphics.getBackgroundColor().getRGB(), - ColorConstants.buttonDarkest.getRGB() }; - } else if (ICSSPropertyID.VAL_SOLID.equals(style)) { - return new RGB[] { ColorConstants.black.getRGB() }; - } - - return new RGB[] { ColorConstants.black.getRGB() }; - } - - // TODO: needs refactoring - private RGB[] getCustomColors(Graphics graphics, String style, String edge, - RGB baseColor) { - if (ICSSPropertyID.VAL_OUTSET.equals(style)) { - if (ICSSStyle.TOP.equals(edge) || ICSSStyle.LEFT.equals(edge)) { - return new RGB[] { - new RGB(baseColor.red * 3 / 4, - baseColor.green * 3 / 4, - baseColor.blue * 3 / 4), - new RGB(baseColor.red, baseColor.green, baseColor.blue) }; - } - return new RGB[] { - new RGB(baseColor.red / 2, - baseColor.green / 2, - baseColor.blue / 2), - new RGB(baseColor.red / 4, - baseColor.green / 4, - baseColor.blue / 4) }; - } else if (ICSSPropertyID.VAL_INSET.equals(style)) { - if (ICSSStyle.TOP.equals(edge) || ICSSStyle.LEFT.equals(edge)) { - return new RGB[] { - new RGB(baseColor.red / 4, - baseColor.green / 4, - baseColor.blue / 4), - new RGB(baseColor.red / 2, - baseColor.green / 2, - baseColor.blue / 2) }; - } - return new RGB[] { - new RGB(baseColor.red, baseColor.green, baseColor.blue), - new RGB(baseColor.red * 3 / 4, - baseColor.green * 3 / 4, - baseColor.blue * 3 / 4), }; - } else if (ICSSPropertyID.VAL_TDBORDERSTYLE.equals(style)) { - if (ICSSStyle.TOP.equals(edge) || ICSSStyle.LEFT.equals(edge)) { - return new RGB[] { new RGB(baseColor.red / 4, - baseColor.green / 4, baseColor.blue / 4) }; - } - return new RGB[] { new RGB(baseColor.red, baseColor.green, - baseColor.blue) }; - } else if (ICSSPropertyID.VAL_RIDGE.equals(style)) { - if (ICSSStyle.TOP.equals(edge) || ICSSStyle.LEFT.equals(edge)) { - return new RGB[] { - new RGB(baseColor.red * 3 / 4, - baseColor.green * 3 / 4, - baseColor.blue * 3 / 4), - new RGB(baseColor.red / 2, - baseColor.green / 2, - baseColor.blue / 2) }; - } - return new RGB[] { - new RGB(baseColor.red / 2, - baseColor.green / 2, - baseColor.blue / 2), - new RGB(baseColor.red * 3 / 4, - baseColor.green * 3 / 4, - baseColor.blue * 3 / 4) }; - } else if (ICSSPropertyID.VAL_GROOVE.equals(style)) { - if (ICSSStyle.TOP.equals(edge) || ICSSStyle.LEFT.equals(edge)) { - return new RGB[] { - new RGB(baseColor.red / 4, - baseColor.green / 4, - baseColor.blue / 4), - new RGB(baseColor.red, baseColor.green, baseColor.blue) }; - - } - return new RGB[] { - new RGB(baseColor.red, baseColor.green, baseColor.blue), - new RGB(baseColor.red / 4, - baseColor.green / 4, - baseColor.blue / 4) }; - } else if (ICSSPropertyID.VAL_DOUBLE.equals(style)) { - return new RGB[] { - new RGB(baseColor.red, baseColor.green, baseColor.blue), - graphics.getBackgroundColor().getRGB(), - new RGB(baseColor.red, baseColor.green, baseColor.blue) }; - } else if (ICSSPropertyID.VAL_SOLID.equals(style)) { - return new RGB[] { new RGB(baseColor.red, baseColor.green, - baseColor.blue) }; - } - return new RGB[] { new RGB(baseColor.red, baseColor.green, - baseColor.blue) }; - } - - public void paintEdge(Graphics graphics, Rectangle rect, - Rectangle innerRect, String edge, String style) { - if (!shouldDraw(style)) { - return; - } - RGB[] rgbs = getEdgeColors(graphics, style, edge); - - if (ICSSStyle.TOP.equals(edge)) { - paintTopEdge(graphics, rgbs, style, rect, innerRect); - } else if (ICSSStyle.BOTTOM.equals(edge)) { - paintBottomEdge(graphics, rgbs, style, rect, innerRect); - } else if (ICSSStyle.LEFT.equals(edge)) { - paintLeftEdge(graphics, rgbs, style, rect, innerRect); - } else if (ICSSStyle.RIGHT.equals(edge)) { - paintRightEdge(graphics, rgbs, style, rect, innerRect); - } - } - - protected void paintEdge(Graphics graphics, Rectangle rect, - Rectangle innerRect, String edge) { - String property = MessageFormater.format(BODER_QUERY_TEMPLETE, edge); - Object obj = _style.getStyleProperty(property); - String style = obj.toString(); - paintEdge(graphics, rect, innerRect, edge, style); - } - - private void paintTopEdge(Graphics graphics, RGB[] rgbs, String style, - Rectangle rect, Rectangle innerRect) { - int leftX = rect.x; - int rightX = rect.right() - 1; - int y = rect.y; - int width = innerRect.y - rect.y; - - if (ICSSPropertyID.VAL_DOTTED.equals(style)) { - drawDottedBorder(graphics, rgbs, ICSSStyle.TOP, rect, width); - } else if (ICSSPropertyID.VAL_DASHED.equals(style)) { - drawDashedBorder(graphics, rgbs, ICSSStyle.TOP, rect, width); - } else { - double xLeftRate = ((double) (innerRect.x - rect.x)) / width; - double xRightRate = ((double) (rect.right() - innerRect.right())) - / width; - graphics.pushState(); - for (int i = 0; i < width; i++) { - Color color = new Color(Display.getCurrent(), rgbs[rgbs.length - * i / width]); - graphics.setForegroundColor(color); - graphics.drawLine((int) (leftX + i * xLeftRate), y + i, - (int) (rightX - i * xRightRate), y + i); - color.dispose(); - } - graphics.popState(); - } - } - - private void paintBottomEdge(Graphics graphics, RGB[] rgbs, String style, - Rectangle rect, Rectangle innerRect) { - int leftX = rect.x; - int rightX = rect.right() - 1; - int y = rect.bottom() - 1; - int width = rect.bottom() - innerRect.bottom(); - - if (ICSSPropertyID.VAL_DOTTED.equals(style)) { - drawDottedBorder(graphics, rgbs, ICSSStyle.BOTTOM, rect, width); - } else if (ICSSPropertyID.VAL_DASHED.equals(style)) { - drawDashedBorder(graphics, rgbs, ICSSStyle.BOTTOM, rect, width); - } else { - double xLeftRate = ((double) (innerRect.x - rect.x)) / width; - double xRightRate = ((double) (rect.right() - innerRect.right())) - / width; - graphics.pushState(); - for (int i = 0; i < width; i++) { - Color color = new Color(Display.getCurrent(), rgbs[rgbs.length - * i / width]); - graphics.setForegroundColor(color); - graphics.drawLine(leftX + (int) (i * xLeftRate), y - i, rightX - - (int) (i * xRightRate), y - i); - color.dispose(); - } - graphics.popState(); - } - } - - private void paintLeftEdge(Graphics graphics, RGB[] rgbs, String style, - Rectangle rect, Rectangle innerRect) { - int x = rect.x; - int topY = rect.y; - int bottomY = rect.bottom() - 1; - int width = innerRect.x - rect.x; - - if (ICSSPropertyID.VAL_DOTTED.equals(style)) { - drawDottedBorder(graphics, rgbs, ICSSStyle.LEFT, rect, width); - } else if (ICSSPropertyID.VAL_DASHED.equals(style)) { - drawDashedBorder(graphics, rgbs, ICSSStyle.LEFT, rect, width); - } else { - double yTopRate = ((double) (innerRect.y - rect.y)) / width; - double yBottomRate = ((double) (rect.bottom() - innerRect.bottom())) - / width; - graphics.pushState(); - for (int i = 0; i < width; i++) { - Color color = new Color(Display.getCurrent(), rgbs[rgbs.length - * i / width]); - graphics.setForegroundColor(color); - graphics.drawLine(x + i, topY + (int) (i * yTopRate), x + i, - bottomY - (int) (i * yBottomRate)); - color.dispose(); - } - graphics.popState(); - } - - } - - private void paintRightEdge(Graphics graphics, RGB[] rgbs, String style, - Rectangle rect, Rectangle innerRect) { - int x = rect.right() - 1; - int topY = rect.y; - int bottomY = rect.bottom() - 1; - int width = rect.right() - innerRect.right(); - - if (ICSSPropertyID.VAL_DOTTED.equals(style)) { - drawDottedBorder(graphics, rgbs, ICSSStyle.RIGHT, rect, width); - } else if (ICSSPropertyID.VAL_DASHED.equals(style)) { - drawDashedBorder(graphics, rgbs, ICSSStyle.RIGHT, rect, width); - } else { - graphics.pushState(); - for (int i = 0; i < width; i++) { - double yTopRate = ((double) (innerRect.y - rect.y)) / width; - double yBottomRate = ((double) (rect.bottom() - innerRect - .bottom())) - / width; - Color color = new Color(Display.getCurrent(), rgbs[rgbs.length - * i / width]); - graphics.setForegroundColor(color); - graphics.drawLine(x - i, topY + (int) (i * yTopRate), x - i, - bottomY - (int) (i * yBottomRate)); - color.dispose(); - } - graphics.popState(); - } - } - - private void drawDottedBorder(Graphics graphics, RGB[] rgbs, String style, - Rectangle rect, int width) { - if (width == 0 || 3 * width > rect.width) { - return; - } - - int beginX = 0; - int beginY = 0; - int xRate = 0; - int yRate = 0; - int span = 0; - - if (ICSSStyle.TOP.equals(style)) { - beginX = rect.x; - beginY = rect.y; - xRate = 1; - yRate = 0; - span = rect.width; - } else if (ICSSStyle.LEFT.equals(style)) { - beginX = rect.x; - beginY = rect.y; - xRate = 0; - yRate = 1; - span = rect.height; - } else if (ICSSStyle.BOTTOM.equals(style)) { - beginX = rect.x; - beginY = rect.y + rect.height - width; - xRate = 1; - yRate = 0; - span = rect.width; - } else if (ICSSStyle.RIGHT.equals(style)) { - beginX = rect.x + rect.width - width; - beginY = rect.y; - xRate = 0; - yRate = 1; - span = rect.height; - } - - int dottedCount = (span + width) / (2 * width); - if (dottedCount < 2) { - dottedCount = 2; - } - int averagePad = (span - dottedCount * width) / (dottedCount - 1); - int leftPad = (span - dottedCount * width) % (dottedCount - 1); - int[] paddings = new int[dottedCount - 1]; - Arrays.fill(paddings, averagePad); - for (int i = 0; i < leftPad; i++) { - paddings[i] = paddings[i] + 1; - } - - int pad = 0; - Color color = new Color(Display.getCurrent(), rgbs[0]); - graphics.pushState(); - graphics.setBackgroundColor(color); - for (int i = 0; i < dottedCount; i++) { - graphics.fillOval(beginX + (pad + width * i) * xRate, beginY - + (pad + width * i) * yRate, width, width); - if (i != dottedCount - 1) { - pad += paddings[i]; - } - } - graphics.popState(); - color.dispose(); - - } - - private void drawDashedBorder(Graphics graphics, RGB[] rgbs, String style, - Rectangle rect, int borderThick) { - if (borderThick == 0 || 5 * borderThick > rect.width) { - return; - } - - if ((5 * borderThick > rect.height) - && (ICSSStyle.LEFT.equals(style) || ICSSStyle.RIGHT - .equals(style))) { - return; - } - - int width = 0; - int height = 0; - int edgeLength = 0; - int beginX = 0; - int beginY = 0; - int xRate = 0; - int yRate = 0; - int span = 0; - - if (ICSSStyle.TOP.equals(style)) { - width = borderThick * 2; - height = borderThick; - beginX = rect.x; - beginY = rect.y; - xRate = 1; - yRate = 0; - - span = rect.width; - edgeLength = width; - } else if (ICSSStyle.LEFT.equals(style)) { - width = borderThick; - height = borderThick * 2; - beginX = rect.x; - beginY = rect.y; - xRate = 0; - yRate = 1; - - span = rect.height; - edgeLength = height; - } else if (ICSSStyle.BOTTOM.equals(style)) { - width = borderThick * 2; - height = borderThick; - beginX = rect.x; - beginY = rect.y + rect.height - height; - xRate = 1; - yRate = 0; - - span = rect.width; - edgeLength = width; - } else if (ICSSStyle.RIGHT.equals(style)) { - width = borderThick; - height = borderThick * 2; - beginX = rect.x + rect.width - width; - beginY = rect.y; - xRate = 0; - yRate = 1; - - span = rect.height; - edgeLength = height; - } - - int dottedCount = (span + borderThick) / (edgeLength + borderThick); - if (dottedCount < 2) { - dottedCount = 2; - } - int averagePad = (span - dottedCount * edgeLength) / (dottedCount - 1); - int leftPad = (span - dottedCount * edgeLength) % (dottedCount - 1); - int[] paddings = new int[dottedCount - 1]; - Arrays.fill(paddings, averagePad); - for (int i = 0; i < leftPad; i++) { - paddings[i] = paddings[i] + 1; - } - - int pad = 0; - graphics.pushState(); - Color color = new Color(Display.getCurrent(), rgbs[0]); - graphics.setBackgroundColor(color); - for (int i = 0; i < dottedCount; i++) { - graphics.fillRectangle(beginX + (pad + width * i) * xRate, beginY - + (pad + height * i) * yRate, width, height); - if (i != dottedCount - 1) { - pad += paddings[i]; - } - } - graphics.popState(); - color.dispose(); - } - -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/color/CSSColorConverter.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/color/CSSColorConverter.java deleted file mode 100644 index 3e6e57a5f..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/color/CSSColorConverter.java +++ /dev/null @@ -1,129 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.color; - -import java.util.StringTokenizer; - -import org.eclipse.jst.jsf.common.ui.internal.logging.Logger; -import org.eclipse.jst.pagedesigner.PDPlugin; -import org.eclipse.swt.graphics.RGB; - -/** - * @author mengbo - */ -public class CSSColorConverter { - private static final String PREFIX_RGB = "rgb"; //$NON-NLS-1$ - - private static Logger _log = PDPlugin.getLogger(CSSColorConverter.class); - - private static CSSColorConverter _instance = new CSSColorConverter(); - - public static CSSColorConverter getInstantce() { - if (_instance == null) { - _instance = new CSSColorConverter(); - } - return _instance; - } - - protected Object getCSSColor(String CSSText) { - if (CSSText == null) { - return null; - } - - CSSText = CSSText.trim().toLowerCase(); - if (CSSText.length() == 0) { - return null; - } - if (CSSColorDefaults.SYSTEM_DEFAULT_COLORS.containsKey(CSSText)) { - Object result = null; - result = CSSColorDefaults.SYSTEM_DEFAULT_COLORS.get(CSSText); - return result; - } else if (CSSColorDefaults.EXTENDED_COLORS.containsKey(CSSText)) { - Object result = null; - result = CSSColorDefaults.EXTENDED_COLORS.get(CSSText); - return result; - } else { - return convertStringToRGB(CSSText); - } - } - - private RGB convertStringToRGB(String CSSText) { - StringBuffer sb = new StringBuffer(CSSText); - int value; - try { - if (sb.indexOf("#") == 0) //$NON-NLS-1$ - { - if (sb.length() == 4) { - sb.insert(1, sb.charAt(1)); - sb.insert(3, sb.charAt(3)); - sb.insert(5, sb.charAt(5)); - value = Integer.parseInt(sb.substring(1, sb.length()) - .toString(), 16); - return new RGB(value >>> 16 & 0xff, value >>> 8 & 0xff, - value & 0xff); - } else if (sb.length() == 7) { - value = Integer.parseInt(sb.substring(1, sb.length()), 16); - return new RGB(value >>> 16 & 0xff, value >>> 8 & 0xff, - value & 0xff); - } - } else if (CSSText.startsWith(PREFIX_RGB)) { - return convertRgbToRGB(sb.substring( - sb.indexOf("(") + 1, sb.indexOf(")"))); //$NON-NLS-1$ //$NON-NLS-2$ - } - } catch (Exception e) { - _log.info("CSSColorConverter.0", CSSText, null); //$NON-NLS-1$ - return null; - } - return null; - } - - private RGB convertRgbToRGB(String text) { - text = text.trim(); - try { - StringTokenizer tokenizer = new StringTokenizer(text, ",");//$NON-NLS-1$ - - if (tokenizer.countTokens() != 3) { - return null; - } - String[] rgbText = new String[3]; - for (int i = 0; i < 3; i++) { - rgbText[i] = tokenizer.nextToken(); - } - - int[] intRGB = new int[] { 0, 0, 0 }; - for (int i = 0; i < 3; i++) { - int intValue = -1; - String textValue = rgbText[i].trim(); - - if (textValue.endsWith("%"))//$NON-NLS-1$ - { - textValue = textValue.substring(0, textValue.length() - 1); - - intValue = Integer.parseInt(textValue) * 255 / 100; - } else { - intValue = Integer.parseInt(textValue); - } - if (intValue < 0) { - intValue = 0; - } else if (intValue > 255) { - intValue = 255; - } - intRGB[i] = intValue; - } - return new RGB(intRGB[0], intRGB[1], intRGB[2]); - } catch (Exception e) { - // notify - _log.info("CSSColorConverter.1", text, null); //$NON-NLS-1$ - return null; - } - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/color/CSSColorDefaults.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/color/CSSColorDefaults.java deleted file mode 100644 index 4e3f477e0..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/color/CSSColorDefaults.java +++ /dev/null @@ -1,278 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.color; - -import java.util.HashMap; - -import org.eclipse.draw2d.ColorConstants; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.widgets.Display; - -/** - * @author mengbo - */ -public class CSSColorDefaults { - public static final HashMap SYSTEM_DEFAULT_COLORS = new HashMap(20); - - public static final HashMap EXTENDED_COLORS = new HashMap(20); - - static { - SYSTEM_DEFAULT_COLORS.put("black", ColorConstants.black); - SYSTEM_DEFAULT_COLORS.put("blue", ColorConstants.blue); - SYSTEM_DEFAULT_COLORS.put("gray", ColorConstants.gray); - SYSTEM_DEFAULT_COLORS.put("green", new Color(null, 0, 128, 0)); - SYSTEM_DEFAULT_COLORS.put("orange", ColorConstants.orange); - SYSTEM_DEFAULT_COLORS.put("red", ColorConstants.red); - SYSTEM_DEFAULT_COLORS.put("white", ColorConstants.white); - SYSTEM_DEFAULT_COLORS.put("yellow", new Color(null, 255, 255, 0)); - SYSTEM_DEFAULT_COLORS.put("aqua", ColorConstants.cyan); - SYSTEM_DEFAULT_COLORS.put("fuchsia", new Color(null, 255, 0, 255)); - SYSTEM_DEFAULT_COLORS.put("lime", ColorConstants.green); - SYSTEM_DEFAULT_COLORS.put("maroon", new Color(null, 128, 0, 0)); - SYSTEM_DEFAULT_COLORS.put("navy", new Color(null, 0, 0, 128)); - SYSTEM_DEFAULT_COLORS.put("olive", new Color(null, 128, 128, 0)); - SYSTEM_DEFAULT_COLORS.put("purple", new Color(null, 128, 0, 128)); - SYSTEM_DEFAULT_COLORS.put("silver", ColorConstants.lightGray); - SYSTEM_DEFAULT_COLORS.put("teal", new Color(null, 0, 128, 128)); - - SYSTEM_DEFAULT_COLORS.put("activeborder", Display.getCurrent() - .getSystemColor(SWT.COLOR_WIDGET_BORDER)); - // Active window border. - SYSTEM_DEFAULT_COLORS.put("activecaption", - ColorConstants.titleBackground); - // Active window caption. - SYSTEM_DEFAULT_COLORS - .put("appworkspace", ColorConstants.listBackground); - // Background color of multiple document interface. - SYSTEM_DEFAULT_COLORS.put("background", ColorConstants.listBackground); - // Desktop background. - SYSTEM_DEFAULT_COLORS.put("buttonface", ColorConstants.button); - // Face color for three-dimensional display elements. - SYSTEM_DEFAULT_COLORS.put("buttonhighlight", - ColorConstants.buttonLightest); - // Dark shadow for three-dimensional display elements (for edges facing - // away from the light source). - SYSTEM_DEFAULT_COLORS.put("buttonshadow", ColorConstants.buttonDarker); - // Shadow color for three-dimensional display elements. - SYSTEM_DEFAULT_COLORS.put("buttontext", Display.getCurrent() - .getSystemColor(SWT.COLOR_WIDGET_FOREGROUND)); - // Text on push buttons. - SYSTEM_DEFAULT_COLORS - .put("captiontext", ColorConstants.titleForeground); - // Text in caption, size box, and scrollbar arrow box. - SYSTEM_DEFAULT_COLORS.put("graytext", - ColorConstants.titleInactiveForeground); - // Grayed (disabled) text. This color is set to #000 if the current - // display driver does not support a solid gray color. - SYSTEM_DEFAULT_COLORS.put("highlight", - ColorConstants.menuBackgroundSelected); - // Item(s) selected in a control. - SYSTEM_DEFAULT_COLORS.put("highlighttext", - ColorConstants.menuForegroundSelected); - // Text of item(s) selected in a control. - SYSTEM_DEFAULT_COLORS.put("inactiveborder", Display.getCurrent() - .getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT)); - // Inactive window border. - SYSTEM_DEFAULT_COLORS.put("inactivecaption", - ColorConstants.titleInactiveBackground); - // Inactive window caption. - SYSTEM_DEFAULT_COLORS.put("inactivecaptiontext", - ColorConstants.titleInactiveForeground); - // Color of text in an inactive caption. - SYSTEM_DEFAULT_COLORS.put("infobackground", - ColorConstants.tooltipBackground); - // Background color for tooltip controls. - SYSTEM_DEFAULT_COLORS.put("infotext", ColorConstants.tooltipForeground); - // Text color for tooltip controls. - SYSTEM_DEFAULT_COLORS.put("menu", ColorConstants.menuBackground); - // Menu background. - SYSTEM_DEFAULT_COLORS.put("menutext", ColorConstants.menuForeground); - // Text in menus. - SYSTEM_DEFAULT_COLORS.put("scrollbar", Display.getCurrent() - .getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); - // Scroll bar gray area. - SYSTEM_DEFAULT_COLORS.put("threeddarkshadow", Display.getCurrent() - .getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW)); - // Dark shadow for three-dimensional display elements. - SYSTEM_DEFAULT_COLORS.put("threedface", Display.getCurrent() - .getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); - // Face color for three-dimensional display elements. - SYSTEM_DEFAULT_COLORS.put("threedhighlight", Display.getCurrent() - .getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW)); - // Highlight color for three-dimensional display elements. - SYSTEM_DEFAULT_COLORS.put("threedlightshadow", Display.getCurrent() - .getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW)); - // Light color for three-dimensional display elements (for edges facing - // the light source). - SYSTEM_DEFAULT_COLORS.put("threedshadow", Display.getCurrent() - .getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW)); - // Dark shadow for three-dimensional display elements. - SYSTEM_DEFAULT_COLORS.put("window", Display.getCurrent() - .getSystemColor(SWT.COLOR_LIST_BACKGROUND)); - // Window background. - SYSTEM_DEFAULT_COLORS.put("windowframe", Display.getCurrent() - .getSystemColor(SWT.COLOR_WIDGET_BORDER)); - // Window frame. - SYSTEM_DEFAULT_COLORS.put("windowtext", Display.getCurrent() - .getSystemColor(SWT.COLOR_LIST_FOREGROUND)); - // Window text - SYSTEM_DEFAULT_COLORS.put("hyperlink", ColorConstants.blue); - } - - static { - EXTENDED_COLORS.put("aliceblue", new Color(null, 240, 248, 255)); - EXTENDED_COLORS.put("antiquewhite", new Color(null, 250, 235, 215)); - EXTENDED_COLORS.put("aqua", new Color(null, 0, 255, 255)); - EXTENDED_COLORS.put("aquamarine", new Color(null, 127, 255, 212)); - EXTENDED_COLORS.put("azure", new Color(null, 240, 255, 255)); - EXTENDED_COLORS.put("beige", new Color(null, 245, 245, 220)); - EXTENDED_COLORS.put("bisque", new Color(null, 255, 228, 196)); - EXTENDED_COLORS.put("black", new Color(null, 0, 0, 0)); - EXTENDED_COLORS.put("blanchedalmond", new Color(null, 255, 235, 205)); - EXTENDED_COLORS.put("blue", new Color(null, 0, 0, 255)); - EXTENDED_COLORS.put("blueviolet", new Color(null, 138, 43, 226)); - EXTENDED_COLORS.put("brown", new Color(null, 165, 42, 42)); - EXTENDED_COLORS.put("burlywood", new Color(null, 222, 184, 135)); - EXTENDED_COLORS.put("cadetblue", new Color(null, 95, 158, 160)); - EXTENDED_COLORS.put("chartreuse", new Color(null, 127, 255, 0)); - EXTENDED_COLORS.put("chocolate", new Color(null, 210, 105, 30)); - EXTENDED_COLORS.put("coral", new Color(null, 255, 127, 80)); - EXTENDED_COLORS.put("cornflowerblue", new Color(null, 100, 149, 237)); - EXTENDED_COLORS.put("cornsilk", new Color(null, 255, 248, 220)); - EXTENDED_COLORS.put("crimson", new Color(null, 220, 20, 60)); - EXTENDED_COLORS.put("cyan", new Color(null, 0, 255, 255)); - EXTENDED_COLORS.put("darkblue", new Color(null, 0, 0, 139)); - EXTENDED_COLORS.put("darkcyan", new Color(null, 0, 139, 139)); - EXTENDED_COLORS.put("darkgoldenrod", new Color(null, 184, 134, 11)); - EXTENDED_COLORS.put("darkgray", new Color(null, 169, 169, 169)); - EXTENDED_COLORS.put("darkgreen", new Color(null, 0, 100, 0)); - EXTENDED_COLORS.put("darkkhaki", new Color(null, 189, 183, 107)); - EXTENDED_COLORS.put("darkmagenta", new Color(null, 139, 0, 139)); - EXTENDED_COLORS.put("darkolivegreen", new Color(null, 85, 107, 47)); - EXTENDED_COLORS.put("darkorange", new Color(null, 255, 140, 0)); - EXTENDED_COLORS.put("darkorchid", new Color(null, 153, 50, 204)); - EXTENDED_COLORS.put("darkred", new Color(null, 139, 0, 0)); - EXTENDED_COLORS.put("darksalmon", new Color(null, 233, 150, 122)); - EXTENDED_COLORS.put("darkseagreen", new Color(null, 143, 188, 143)); - EXTENDED_COLORS.put("darkslateblue", new Color(null, 72, 61, 139)); - EXTENDED_COLORS.put("darkslategray", new Color(null, 47, 79, 79)); - EXTENDED_COLORS.put("darkturquoise", new Color(null, 0, 206, 209)); - EXTENDED_COLORS.put("darkviolet", new Color(null, 148, 0, 211)); - EXTENDED_COLORS.put("deeppink", new Color(null, 255, 20, 147)); - EXTENDED_COLORS.put("deepskyblue", new Color(null, 0, 191, 255)); - EXTENDED_COLORS.put("dimgray", new Color(null, 105, 105, 105)); - EXTENDED_COLORS.put("dodgerblue", new Color(null, 30, 144, 255)); - EXTENDED_COLORS.put("feldspar", new Color(null, 209, 146, 117)); - EXTENDED_COLORS.put("firebrick", new Color(null, 178, 34, 34)); - EXTENDED_COLORS.put("floralwhite", new Color(null, 255, 250, 240)); - EXTENDED_COLORS.put("forestgreen", new Color(null, 34, 139, 34)); - EXTENDED_COLORS.put("fuchsia", new Color(null, 255, 0, 255)); - EXTENDED_COLORS.put("gainsboro", new Color(null, 220, 220, 220)); - EXTENDED_COLORS.put("ghostwhite", new Color(null, 248, 248, 255)); - EXTENDED_COLORS.put("gold", new Color(null, 255, 215, 0)); - EXTENDED_COLORS.put("goldenrod", new Color(null, 218, 165, 32)); - EXTENDED_COLORS.put("gray", new Color(null, 128, 128, 128)); - EXTENDED_COLORS.put("green", new Color(null, 0, 128, 0)); - EXTENDED_COLORS.put("greenyellow", new Color(null, 173, 255, 47)); - EXTENDED_COLORS.put("honeydew", new Color(null, 240, 255, 240)); - EXTENDED_COLORS.put("hotpink", new Color(null, 255, 105, 180)); - EXTENDED_COLORS.put("indianred", new Color(null, 205, 92, 92)); - EXTENDED_COLORS.put("indigo", new Color(null, 75, 0, 130)); - EXTENDED_COLORS.put("ivory", new Color(null, 255, 255, 240)); - EXTENDED_COLORS.put("khaki", new Color(null, 240, 230, 140)); - EXTENDED_COLORS.put("lavender", new Color(null, 230, 230, 250)); - EXTENDED_COLORS.put("lavenderblush", new Color(null, 255, 240, 245)); - EXTENDED_COLORS.put("lawngreen", new Color(null, 124, 252, 0)); - EXTENDED_COLORS.put("lemonchiffon", new Color(null, 255, 250, 205)); - EXTENDED_COLORS.put("lightblue", new Color(null, 173, 216, 230)); - EXTENDED_COLORS.put("lightcoral", new Color(null, 240, 128, 128)); - EXTENDED_COLORS.put("lightcyan", new Color(null, 224, 255, 255)); - EXTENDED_COLORS.put("lightgoldenrodyellow", new Color(null, 250, 250, - 210)); - EXTENDED_COLORS.put("lightgrey", new Color(null, 211, 211, 211)); - EXTENDED_COLORS.put("lightgreen", new Color(null, 144, 238, 144)); - EXTENDED_COLORS.put("lightpink", new Color(null, 255, 182, 193)); - EXTENDED_COLORS.put("lightsalmon", new Color(null, 255, 160, 122)); - EXTENDED_COLORS.put("lightseagreen", new Color(null, 32, 178, 170)); - EXTENDED_COLORS.put("lightskyblue", new Color(null, 135, 206, 250)); - EXTENDED_COLORS.put("lightslateblue", new Color(null, 132, 112, 255)); - EXTENDED_COLORS.put("lightslategray", new Color(null, 119, 136, 153)); - EXTENDED_COLORS.put("lightsteelblue", new Color(null, 176, 196, 222)); - EXTENDED_COLORS.put("lightyellow", new Color(null, 255, 255, 224)); - EXTENDED_COLORS.put("lime", new Color(null, 0, 255, 0)); - EXTENDED_COLORS.put("limegreen", new Color(null, 50, 205, 50)); - EXTENDED_COLORS.put("linen", new Color(null, 250, 240, 230)); - EXTENDED_COLORS.put("magenta", new Color(null, 255, 0, 255)); - EXTENDED_COLORS.put("maroon", new Color(null, 128, 0, 0)); - EXTENDED_COLORS.put("mediumaquamarine", new Color(null, 102, 205, 170)); - EXTENDED_COLORS.put("mediumblue", new Color(null, 0, 0, 205)); - EXTENDED_COLORS.put("mediumorchid", new Color(null, 186, 85, 211)); - EXTENDED_COLORS.put("mediumpurple", new Color(null, 147, 112, 216)); - EXTENDED_COLORS.put("mediumseagreen", new Color(null, 60, 179, 113)); - EXTENDED_COLORS.put("mediumslateblue", new Color(null, 123, 104, 238)); - EXTENDED_COLORS.put("mediumspringgreen", new Color(null, 0, 250, 154)); - EXTENDED_COLORS.put("mediumturquoise", new Color(null, 72, 209, 204)); - EXTENDED_COLORS.put("mediumvioletred", new Color(null, 199, 21, 133)); - EXTENDED_COLORS.put("midnightblue", new Color(null, 25, 25, 112)); - EXTENDED_COLORS.put("mintcream", new Color(null, 245, 255, 250)); - EXTENDED_COLORS.put("mistyrose", new Color(null, 255, 228, 225)); - EXTENDED_COLORS.put("moccasin", new Color(null, 255, 228, 181)); - EXTENDED_COLORS.put("navajowhite", new Color(null, 255, 222, 173)); - EXTENDED_COLORS.put("navy", new Color(null, 0, 0, 128)); - EXTENDED_COLORS.put("oldlace", new Color(null, 253, 245, 230)); - EXTENDED_COLORS.put("olive", new Color(null, 128, 128, 0)); - EXTENDED_COLORS.put("olivedrab", new Color(null, 107, 142, 35)); - EXTENDED_COLORS.put("orange", new Color(null, 255, 165, 0)); - EXTENDED_COLORS.put("orangeted", new Color(null, 255, 69, 0)); - EXTENDED_COLORS.put("orchid", new Color(null, 218, 112, 214)); - EXTENDED_COLORS.put("ralegoldenrod", new Color(null, 238, 232, 170)); - EXTENDED_COLORS.put("palegreen", new Color(null, 152, 251, 152)); - EXTENDED_COLORS.put("paleturquoise", new Color(null, 175, 238, 238)); - EXTENDED_COLORS.put("palevioletred", new Color(null, 216, 112, 147)); - EXTENDED_COLORS.put("papayawhip", new Color(null, 255, 239, 213)); - EXTENDED_COLORS.put("peachpuff", new Color(null, 255, 218, 185)); - EXTENDED_COLORS.put("peru", new Color(null, 205, 133, 63)); - EXTENDED_COLORS.put("pink", new Color(null, 255, 192, 203)); - EXTENDED_COLORS.put("plum", new Color(null, 221, 160, 221)); - EXTENDED_COLORS.put("powderblue", new Color(null, 176, 224, 230)); - EXTENDED_COLORS.put("purple", new Color(null, 128, 0, 128)); - EXTENDED_COLORS.put("red", new Color(null, 255, 0, 0)); - EXTENDED_COLORS.put("rosybrown", new Color(null, 188, 143, 143)); - EXTENDED_COLORS.put("royalblue", new Color(null, 65, 105, 225)); - EXTENDED_COLORS.put("saddlebrown", new Color(null, 139, 69, 19)); - EXTENDED_COLORS.put("salmon", new Color(null, 250, 128, 114)); - EXTENDED_COLORS.put("sandybrown", new Color(null, 244, 164, 96)); - EXTENDED_COLORS.put("seagreen", new Color(null, 46, 139, 87)); - EXTENDED_COLORS.put("seashell", new Color(null, 255, 245, 238)); - EXTENDED_COLORS.put("sienna", new Color(null, 160, 82, 45)); - EXTENDED_COLORS.put("silver", new Color(null, 192, 192, 192)); - EXTENDED_COLORS.put("skyblue", new Color(null, 135, 206, 235)); - EXTENDED_COLORS.put("slateblue", new Color(null, 106, 90, 205)); - EXTENDED_COLORS.put("slategray", new Color(null, 112, 128, 144)); - EXTENDED_COLORS.put("snow", new Color(null, 255, 250, 250)); - EXTENDED_COLORS.put("springgreen", new Color(null, 0, 255, 127)); - EXTENDED_COLORS.put("steelblue", new Color(null, 70, 130, 180)); - EXTENDED_COLORS.put("tan", new Color(null, 210, 180, 140)); - EXTENDED_COLORS.put("teal", new Color(null, 0, 128, 128)); - EXTENDED_COLORS.put("thistle", new Color(null, 216, 191, 216)); - EXTENDED_COLORS.put("tomato", new Color(null, 255, 99, 71)); - EXTENDED_COLORS.put("turquoise", new Color(null, 64, 224, 208)); - EXTENDED_COLORS.put("violet", new Color(null, 238, 130, 238)); - EXTENDED_COLORS.put("violetred", new Color(null, 208, 32, 144)); - EXTENDED_COLORS.put("wheat", new Color(null, 245, 222, 179)); - EXTENDED_COLORS.put("white", new Color(null, 255, 255, 255)); - EXTENDED_COLORS.put("whitesmoke", new Color(null, 245, 245, 245)); - EXTENDED_COLORS.put("yellow", new Color(null, 255, 255, 0)); - EXTENDED_COLORS.put("yellowgreen", new Color(null, 154, 205, 50)); - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/color/CSSColorManager.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/color/CSSColorManager.java deleted file mode 100644 index 042bb300d..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/color/CSSColorManager.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.color; - -/** - * @author mengbo - */ -public class CSSColorManager { - private static CSSColorManager _instance; - - private CSSColorManager() { - // no external instantiation - } - - public static CSSColorManager getInstance() { - if (_instance == null) { - _instance = new CSSColorManager(); - } - return _instance; - } - - /** - * return Color or RGB. If return color, then the returned color is system - * color, caller should NOT dispose the returned color - * - * @param cssText - * @return - */ - public Object getColor(String cssText) { - return CSSColorConverter.getInstantce().getCSSColor(cssText); - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/font/CSSFont.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/font/CSSFont.java deleted file mode 100644 index 44e3e4de1..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/font/CSSFont.java +++ /dev/null @@ -1,116 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.font; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Font; - -/** - * @author mengbo - */ -public class CSSFont implements ICSSFont { - private String _family; - - private int _size; - - private int _style; - - private int _weight; - - private String _cssString; - - /** - * - */ - public CSSFont(String family, int size, int style, int weight, - String cssString) { - this._family = family; - this._size = size; - this._style = style; - this._weight = weight; - _cssString = cssString; - } - - public String getFontFamily() { - return _family; - } - - public int getFontSize() { - return _size; - } - - public int getFontStyle() { - return _style; - } - - public String getCSSString() { - return _cssString; - } - - public int getWeight() { - return _weight; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals(Object obj) { - if (obj instanceof CSSFont) { - CSSFont fd = (CSSFont) obj; - return this._family.equals(fd._family) && this._size == fd._size - && this._style == fd._style && this._weight == fd._weight; - } - return false; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ - public int hashCode() { - return _family.hashCode() + _size + _style + _weight; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.font.ICSSFont#getSwtFont() - */ - public Font getSwtFont() { - // return FontPoolManager.getInstance().getFont(this); - return CSSFontManager.getInstance().getSwtFont(this); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.font.ICSSFont#getXHeight() - */ - public int getXHeight() { - return getFontSize(); - } - - /** - * @return - */ - public int getSwtFontStyle() { - int style = SWT.NONE; - // see:http://www.htmlhelp.com/reference/css/font/font-weight.html - if (getWeight() >= 600) - style |= SWT.BOLD; - style |= getFontStyle(); - return style; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/font/CSSFontManager.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/font/CSSFontManager.java deleted file mode 100644 index 3034ed8e3..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/font/CSSFontManager.java +++ /dev/null @@ -1,195 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.font; - -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.property.FontFamilyMeta; -import org.eclipse.jst.pagedesigner.css2.property.FontSizeMeta; -import org.eclipse.jst.pagedesigner.css2.property.FontWeightMeta; -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyID; -import org.eclipse.jst.pagedesigner.css2.value.Length; -import org.eclipse.jst.pagedesigner.utils.CacheManager; -import org.eclipse.jst.pagedesigner.utils.ICacheEntryCreator; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.widgets.Display; - -/** - * @author mengbo - */ -public class CSSFontManager implements ICSSFontManager { - private static CSSFontManager _instance; - - private static final boolean DEBUG = false; - - private int _totalFont = 0; - - // private static FontPoolManager _fontPoolManager; - // Map _cache = new HashMap(); - - private static final int CACHESIZE = 100; // we cache 100 font. - - // the scale to convert the px to pt. - private final static double FONT_SCALE = ((double) Display.getCurrent() - .getDPI().x) / 72; - - static String cssFontToLocalFont(String original) { - if ("serif".equalsIgnoreCase(original)) { - return "Georgia"; - } else if ("sans-serif".equalsIgnoreCase(original)) { - return "Arial"; - } else if ("cursive".equalsIgnoreCase(original)) { - // FIXME: MS windows does not support the alternative fonts that - // match cursive defined at - // http://www.w3.org/TR/REC-CSS2/fonts.html#generic-font-families, - // We use Comic Sans MS font family - // because it is MS alternative. - return "Comic Sans MS"; - } else if ("fantasy".equalsIgnoreCase(original)) { - return cssFontToLocalFont("serif"); - } else if ("monospace".equalsIgnoreCase(original)) { - return "Courier New"; - } else { - return original; - } - } - - private CacheManager _cacheManager = new CacheManager( - new ICacheEntryCreator() { - public Object createEntry(Object key) { - if (DEBUG) { - _totalFont++; - System.out.println("TotalFont++: " + _totalFont); - } - CSSFont cssfont = (CSSFont) key; - - Font font = new Font(null, cssFontToLocalFont(cssfont - .getFontFamily()), (int) Math.round(cssfont - .getFontSize() - / FONT_SCALE), cssfont.getSwtFontStyle()); - return font; - } - - public void dispose(Object key, Object entry) { - if (DEBUG) { - _totalFont--; - System.out.println("TotalFont--: " + _totalFont); - } - ((Font) entry).dispose(); - - } - }, CACHESIZE); - - /** - * constructor - */ - private CSSFontManager() { - super(); - } - - private String resolveFontStyleString(ICSSStyle style) { - StringBuffer sb = new StringBuffer(); - sb.append(ICSSPropertyID.ATTR_FONT_FAMILY).append(":"); - sb.append("'").append( - (String) style - .getStyleProperty(ICSSPropertyID.ATTR_FONT_FAMILY)) - .append("'"); - sb.append(";"); - sb.append(ICSSPropertyID.ATTR_FONT_STYLE).append(":"); - sb - .append( - (String) style - .getStyleProperty(ICSSPropertyID.ATTR_FONT_STYLE)) - .append(";"); - sb.append(ICSSPropertyID.ATTR_FONT_WEIGHT).append(":"); - sb.append( - ((Integer) style - .getStyleProperty(ICSSPropertyID.ATTR_FONT_WEIGHT)) - .toString()).append(";"); - sb.append(ICSSPropertyID.ATTR_FONT_SIZE).append(":"); - int fontSize = getFontSize(style, style - .getStyleProperty(ICSSPropertyID.ATTR_FONT_SIZE)); - sb.append(Integer.toString(fontSize)); - return sb.toString(); - } - - public ICSSFont createFont(ICSSStyle style) { - String fontfamily = (String) style - .getStyleProperty(ICSSPropertyID.ATTR_FONT_FAMILY); - Object fontsizeobj = style - .getStyleProperty(ICSSPropertyID.ATTR_FONT_SIZE); - int fontsize; - fontsize = getFontSize(style, fontsizeobj); - int fontstyle = getFontStyle(style); - int fontweight = ((Integer) style - .getStyleProperty(ICSSPropertyID.ATTR_FONT_WEIGHT)).intValue(); - - return new CSSFont(fontfamily, fontsize, fontstyle, fontweight, - resolveFontStyleString(style)); - } - - private int getFontSize(ICSSStyle style, Object fontsizeobj) { - int fontsize; - if (fontsizeobj instanceof Length) { - fontsize = ((Length) fontsizeobj).getValue(); - } else { - fontsize = style.getParentStyle().getCSSFont().getFontSize(); - } - return fontsize; - } - - /** - * @param style - */ - private int getFontStyle(ICSSStyle style) { - int fontstyle; - String fontstylestr = (String) style - .getStyleProperty(ICSSPropertyID.ATTR_FONT_STYLE); - if (ICSSPropertyID.VAL_ITALIC.equals(fontstylestr) - || ICSSPropertyID.VAL_OBLIQUE.equals(fontstylestr)) { - fontstyle = SWT.ITALIC; - } else { - fontstyle = SWT.NORMAL; - } - return fontstyle; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.font.ICSSFontManager#dispose() - */ - public void dispose() { - _cacheManager.disposeAll(); - } - - public ICSSFont createDefaultFont() { - CSSFont result = new CSSFont(FontFamilyMeta.DEFAULT_FONT, - (int) FontSizeMeta.MEDIUM_VAL_INT, SWT.NORMAL, - FontWeightMeta.NORMAL_WEIGHT.intValue(), ""); - return result; - } - - public Font getSwtFont(CSSFont f) { - return (Font) _cacheManager.getEntry(f); - } - - /** - * @return - */ - public static CSSFontManager getInstance() { - if (_instance == null) { - _instance = new CSSFontManager(); - } - return _instance; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/font/ICSSFont.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/font/ICSSFont.java deleted file mode 100644 index 1dff0bc9b..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/font/ICSSFont.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.font; - -import org.eclipse.swt.graphics.Font; - -/** - * XXX: this class should be renamed to CSSFontDescriptor. Since now it is only - * used to describe a CSSFont. - * - * @author mengbo - */ -public interface ICSSFont { - /** - * Will get a Font system resource from a pool. - * - * The caller should NOT dispose the returned Font object. - * - * The caller should not hold reference on the returned Font object, since - * system may dispose it at any time. - * - * @return - */ - public Font getSwtFont(); - - public String getFontFamily(); - - /** - * get font size in pixel - * - * @return - */ - public int getFontSize(); - - /** - * get font x height in pixel - * - * @return - */ - public int getXHeight(); - - /** - * @return - */ - public int getWeight(); - - /** - * - * @return could be SWT.NONE or SWT.ITALIC - */ - public int getFontStyle(); - - public String getCSSString(); -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/font/ICSSFontManager.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/font/ICSSFontManager.java deleted file mode 100644 index 2d0720412..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/font/ICSSFontManager.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.font; - -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; - -/** - * @author mengbo - */ -public interface ICSSFontManager { - public ICSSFont createFont(ICSSStyle style); - - public void dispose(); -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/html4.css b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/html4.css deleted file mode 100644 index e91e5de0d..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/html4.css +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Basic HTML style information. - */ -html, -address, -blockquote,listing, -body, dd, div, -dl, dt, fieldset, legend,form, -frame, frameset, -h1, h2, h3, h4, -h5, h6, noframes,noscript, -ol, p, ul, center, -dir, hr, menu, pre, plaintext, xmp { display: block } - -ol {counter-reset: _anonymous; list-style-type: decimal} -ul,dir,menu {counter-reset: _anonymous; list-style-type: disc} -li {display: list-item} -li {counter-increment: _anonymous} - -head { display: none } -table { display: table } -tr { display: table-row } -thead { display: table-header-group } -tbody { display: table-row-group } -tfoot { display: table-footer-group } -col { display: table-column } -colgroup { display: table-column-group } -td, th { display: table-cell; } -caption { display: table-caption } -th { font-weight: bolder;} -caption { text-align: center;horizontal-align:top } -button, textarea, -input, object, -select, img { display:inline-block; } -pre,plaintext, xmp { white-space: pre } -h1, h2, h3, h4, -h5, h6, b, -strong { font-weight: bold } -i, cite, em,dfn, -var, address { font-style: italic } -pre, tt, code,plaintext, xmp, -kbd, samp { font-family: monospace } -ol { list-style-type: decimal } -br:before { content: "\A" } -center { text-align: center } -sub { vertical-align: sub } -sup { vertical-align: super } -u, ins { text-decoration: underline } -input { text-decoration: none } -button { white-space: nowrap } -a[href] { text-decoration: underline } - -/* - * styles that may be different for different user agent. - * This part may need to move out and put into different css files. - */ -body { line-height: 1.12em } -h1 { font-size: 2em; margin: .67em 0 } -h2 { font-size: 1.5em; margin: .75em 0 } -h3 { font-size: 1.17em; margin: .83em 0 } -h4, p,ul, -fieldset, form, -ol, dl, dir, -menu { margin: 1.12em 0 } -blockquote { margin: 1em 40px } -h5 { font-size: .83em; margin: 1.5em 0 } -h6 { font-size: .75em; margin: 1.67em 0 } -blockquote { margin-left: 40px; margin-right: 40px } -big { font-size: larger } -small, sub, sup { font-size: smaller } -s, strike, del { text-decoration: line-through } -hr { border: 1px inset } -ol, ul, dir, -menu, dd { margin-left: 40px;border:0px } -ol ul, ul ol, -ul ul, ol ol { margin-top: 0; margin-bottom: 0 } -abbr, acronym { font-variant: small-caps; letter-spacing: 0.1em } -a[href] { color:blue;} -select {background-color: window;font-family:sans-serif;font-size:13px;font-weight: normal;} -textarea {border: 2px inset;font-size:13px;font-family:monospace} -textarea, -input {background-color: window} -input, -input[type=text], -input[type=password] {border: 2px inset;font-size:13px;font-family:sans-serif;font-weight: normal;} -/* following upcased TYPE is for workaround the WTP M2 bug of not setting default content type */ -input[TYPE=submit],input[TYPE=reset],input[TYPE=button],input[TYPE=cancel], -button, -input[type=button], -input[type=reset], -input[type=cancel], -input[type=submit] {background-color: ButtonFace; border: 2px outset; font-size:13px; - font-family:sans-serif;text-align: center;font-weight: normal;} -input[type=image], -input[type=checkbox], -input[type=radio] {border: none } -input[type=hidden] {border: none } -img {border: 0px none} -listing {font-family:monospace;font-size: medium;white-space: pre; margin: 1em 0;} -tbody,thead,tfoot {vertical-align: middle;} -blink {text-decoration: blink;} - -hr {margin: 0.5em auto 0.5em auto;} -caption {border: 0px none;margin: 0px; padding:0px 0px 4px 0px;} -td, th, -table {border: 4px none;} -button {padding: 3px 5px;text-align: center;vertical-align: middle;} -button,textarea,input {vertical-align: text-bottom;color:black;font-style:none;} -select {vertical-align: text-bottom;} -input[type=image] {vertical-align: baseline;} -li {min-height:1.2em} -button {min-height:1.8em} -div,tr,form {min-height:1.2em} -table,td {min-width:1.2em;min-height:1.2em} - -/* nested lists have no top/bottom margins */ -ul ul, ul ol, ul dir, ul menu, ul dl, -ol ul, ol ol, ol dir, ol menu, ol dl, -dir ul, dir ol, dir dir, dir menu, dir dl, -menu ul, menu ol, menu dir, menu menu, menu dl, -dl ul, dl ol, dl dir, dl menu, dl dl {margin-top: 0; margin-bottom: 0;} - -/* 2 deep unordered lists use a circle */ -ol ul, ul ul, menu ul, dir ul, -ol menu, ul menu, menu menu, dir menu, -ol dir, ul dir, menu dir, dir dir {list-style-type: circle;} - -/* 3 deep (or more) unordered lists use a square */ -ol ol ul, ol ul ul, ol menu ul, ol dir ul, -ol ol menu, ol ul menu, ol menu menu, ol dir menu, -ol ol dir, ol ul dir, ol menu dir, ol dir dir, -ul ol ul, ul ul ul, ul menu ul, ul dir ul, -ul ol menu, ul ul menu, ul menu menu, ul dir menu, -ul ol dir, ul ul dir, ul menu dir, ul dir dir, -menu ol ul, menu ul ul, menu menu ul, menu dir ul, -menu ol menu, menu ul menu, menu menu menu, menu dir menu, -menu ol dir, menu ul dir, menu menu dir, menu dir dir, -dir ol ul, dir ul ul, dir menu ul, dir dir ul, -dir ol menu, dir ul menu, dir menu menu, dir dir menu, -dir ol dir, dir ul dir, dir menu dir, dir dir dir { list-style-type: square;} - -/** - * We do not write codes to support some elements. This part defines properties for them - * to improve the look of these elements. - */ -applet {border: 1px solid;} -fieldset {border: 2px groove;} -applet,iframe {display:inline-block; border:3px inset; } -object {display:inline-block;border:0px none;} - - -/* - * Sets right margin to have gap between widgets. - */ -input,textarea,button { margin-right: 2px;}
\ No newline at end of file diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/BlockBox.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/BlockBox.java deleted file mode 100644 index 7c635a59c..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/BlockBox.java +++ /dev/null @@ -1,101 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import org.eclipse.draw2d.geometry.Rectangle; - -/** - * A CompositeBox suitable for containing multiple LineBox fragments. Based on - * BlockBox of draw2d. - * - * @author mengbo - */ -public class BlockBox extends CompositeBox { - // internalContent dimension is for the closure of the FlowBox(es) added - // into the BlockBox. - private int _internalContentWidth = -1; - - private int _internalContentHeight = -1; - - Rectangle toRectangle() { - return new Rectangle(_x, _y, Math.max(_width, _recommendedWidth), - _height); - } - - /** - * Sets the height. - * - * @param h - * The height - */ - public void setHeight(int h) { - _height = h; - } - - /** - * Unions the dimensions of this with the dimensions of the passed FlowBox. - * For BlockBox, each time unionInfo is called, the passed in object - * represents a line. - * - * @param box - * The FlowBox to union this with - */ - protected void unionInfo(FlowBox box) { - _width = Math.max(_width, box._width + this.getBorderPaddingWidth()); - _height = Math.max(_height, box._y + box._height - + this.getBorderPaddingHeight()); - - _internalContentWidth = Math.max(_internalContentWidth, box._width); - _internalContentHeight = Math.max(_internalContentHeight, box._y - + box._height); - } - - public int getInternalContentWidth() { - return _internalContentWidth; - } - - public int getInternalContentHeight() { - return _internalContentHeight; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowBox#getAscent() - */ - public int getAscent() { - // XXX: some hard coded things here. If the blockbox is only for a - // single widget, and if that widget support ascent, then we'll - // delegate to that widget for ascent support. - // if (_fragments.size()==1) - // { - // FlowBox box = (FlowBox) _fragments.get(0); - // if (box instanceof LineBox) - // { - // List linecomponents = ((LineBox) box).getFragments(); - // if (linecomponents != null && linecomponents.size() == 1) - // { - // FlowBox box2 = (FlowBox) linecomponents.get(0); - // if (box2 instanceof WidgetBox) - // { - // WidgetBox widgetBox = (WidgetBox) box2; - // if (widgetBox.supportAscent()) - // { - // return widgetBox.getAscent() + this.getBorderPaddingInsets().top; - // } - // } - // } - // } - // } - return super.getAscent(); - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/BlockFlow.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/BlockFlow.java deleted file mode 100644 index 35eb4c7c2..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/BlockFlow.java +++ /dev/null @@ -1,112 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import java.util.List; - -import org.eclipse.draw2d.PositionConstants; - -/** - * A <code>FlowFigure</code> represented by a single {@link BlockBox}fragment - * containing one or more lines. A BlockFlow is a creator of LineBoxes, which - * its children require during layout. A BlockFlow can be thought of as a - * paragraph. - * <P> - * BlockFlows should be nested inside other BlockFlows, but it is also valid to - * place them in InlineFlows. {@link FlowPage}can be used as a "root" block and - * can be added to normal draw2d Figures. - * <P> - * Only {@link FlowFigure}s can be added to a BlockFlow. - */ -public class BlockFlow extends FlowFigure { - - final BlockBox _blockBox; - - private int _aligment; - - /** - * Constructs a new BlockFlow. - */ - public BlockFlow() { - setLayoutManager(createDefaultFlowLayout()); - _blockBox = createBlockBox(); - } - - BlockBox createBlockBox() { - return new BlockBox(); - } - - /** - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowFigure#createDefaultFlowLayout() - */ - protected FlowFigureLayout createDefaultFlowLayout() { - return new BlockFlowLayout(this); - } - - /** - * Returns the BlockBox associated with this. - * - * @return This BlockFlow's BlockBox - */ - protected BlockBox getBlockBox() { - return _blockBox; - } - - /** - * Returns the horizontal aligment. - * - * @return the hotizontal aligment - */ - public int getHorizontalAligment() { - return _aligment & PositionConstants.LEFT_CENTER_RIGHT; - } - - /** - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowFigure#postValidate() - */ - public void postValidate() { - setBounds(getBlockBox().toRectangle().expand(getInsets())); - List v = getChildren(); - for (int i = 0, n = v.size(); i < n; i++) { - ((FlowFigure) v.get(i)).postValidate(); - } - } - - /** - * Sets the horitontal aligment of the block. Valid values are: - * <UL> - * <LI>{@link org.eclipse.draw2d.PositionConstants#LEFT} - * <LI>{@link org.eclipse.draw2d.PositionConstants#RIGHT} - * <LI>{@link org.eclipse.draw2d.PositionConstants#CENTER} - * - * @param value - * the aligment - */ - public void setHorizontalAligment(int value) { - if (!(value == PositionConstants.LEFT - || value == PositionConstants.RIGHT || value == PositionConstants.CENTER)) { - throw new IllegalArgumentException( - "Horizontal Aligment must be one of: LEFT, CENTER, RIGHT"); - } - this._aligment &= ~PositionConstants.LEFT_CENTER_RIGHT; - this._aligment |= value; - revalidate(); - } - - /** - * @see org.eclipse.draw2d.Figure#useLocalCoordinates() - */ - protected boolean useLocalCoordinates() { - return true; - } - -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/BlockFlowContext.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/BlockFlowContext.java deleted file mode 100644 index 7cb5efdf4..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/BlockFlowContext.java +++ /dev/null @@ -1,283 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyID; -import org.eclipse.jst.pagedesigner.css2.value.Length; - -/** - * When doing absolute positioning, we need to create a block. But that block - * don't have a corresponding figure. So we need a block without corresponding - * figure. - * - * @author mengbo - * @version 1.5 - */ -public class BlockFlowContext implements FlowContext { - protected LineBox _currentLine; - - private LineBox _previousLine = null; - - protected BlockBox _blockBox; - - protected FlowContext _originalContext; - - protected ICSSStyle _style; - - /** - * - */ - public BlockFlowContext(FlowContext originalContext, ICSSStyle style) { - this._originalContext = originalContext; - this._style = style; - setup(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContext#getContainerWidth() - */ - public int getContainerWidth() { - - return _originalContext.getContainerWidth(); - } - - public void setup() { - _blockBox = new BlockBox(); - _blockBox.setRecommendedWidth(getRecommendedWidth()); - _currentLine = this.getCurrentLine(); - _previousLine = null; - } - - private int getRecommendedWidth() { - int containerWidth = getContainerWidth(); - Object leftObj = _style.getStyleProperty(ICSSPropertyID.ATTR_LEFT); - if (leftObj != null && leftObj instanceof Length) { - Length left = (Length) leftObj; - int intLeft = left.getValue(); - if (left.isPercentage()) { - intLeft = containerWidth * intLeft / 100; - } - if (intLeft < containerWidth) { - return containerWidth - intLeft; - } - } - return containerWidth; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContext#addToCurrentLine(org.eclipse.jst.pagedesigner.css2.layout.FlowBox) - */ - public void addToCurrentLine(FlowBox block) { - getCurrentLine().add(block); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContext#endLine() - */ - public void endLine() { - // this is called from child layouts. - // If there is no current line, state is equivalent to new line - if (_currentLine == null) - return; - if (_currentLine.isOccupied()) - layoutLine(); // finalize the current line layout - else - return; - - LineBox box = _currentLine; - // _currentLine = _previousLine; //XXX: ???? why (yang) - _previousLine = box; - - _currentLine = null; - // setupLine(getCurrentLine()); - - } - - /** - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContext#getCurrentLine() - */ - public LineBox getCurrentLine() { - if (_currentLine == null) - createNewLine(); - return _currentLine; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContext#getCurrentLine(int) - */ - public LineBox getCurrentLine(int topMargin) { - if (_currentLine == null) - createNewLine(topMargin); - return _currentLine; - } - - /** - * @param topMargin - */ - private void createNewLine(int topMargin) { - createNewLine(); - } - - protected void createNewLine() { - _currentLine = new LineBox(); - setupLine(_currentLine, Integer.MIN_VALUE); - } - - /** - * Override to setup the line's x, remaining, and available width. - * - * @param line - * the LineBox to set up - */ - protected void setupLine(LineBox line, int topMargin) { - line.clear(); - - // the caller of getCurrentLine() may add leftMargin and leftPadding and - // leftBorder to line.x - line._x = _blockBox._borderInsets.left + _blockBox._paddingInsets.left; - - // FIXME: here should check the floating boxes, and minus the width of - // them from - // current line. - // XXX: the RecommendedContentWidth is related with the RecommendedWidth - // of container that - // usually larger than it needed.here we do not set the RecommendedWidth - // for the sake of - // layouting right absolute position. - // /shortcoming:the box will break into multi-line after every white - // space. - // line.setRecommendedWidth(_blockBox.getRecommendedContentWidth()); - if (_previousLine == null) { - line._y = _blockBox._borderInsets.top - + _blockBox._paddingInsets.top; - if (topMargin != Integer.MIN_VALUE) - line._y += topMargin; - } else { - if (topMargin == Integer.MIN_VALUE) - line._y = _previousLine._y + _previousLine.getHeight() - + getLinePadding() + _previousLine._marginInsets.bottom; // XXX: - // should - // add - // previous - // margin - // bottom? - else - line._y = _previousLine._y - + _previousLine.getHeight() - + Math.max(topMargin, - _previousLine._marginInsets.bottom); - } - // line.validate(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContext#getCurrentY() - */ - public int getCurrentY() { - return getCurrentLine()._y; // FIXME: margin of previous block? - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContext#isCurrentLineOccupied() - */ - public boolean isCurrentLineOccupied() { - return _currentLine != null && _currentLine.isOccupied(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContext#getLastMarginRight() - */ - public int getLastMarginRight() { - if (_currentLine == null || !_currentLine.isOccupied()) { - return 0; - } - FlowBox box = (FlowBox) _currentLine.getFragments().get( - _currentLine.getFragments().size() - 1); - if (box != null) { - return box._marginInsets.right; - } - return 0; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContext#isCalculatingMaxWidth() - */ - public boolean isCalculatingMaxWidth() { - return false; - } - - /** - * Adjust all fragments in the current line to have the same baseline. Do - * any additional adjustments, such as horizontal alignment. - */ - protected void layoutLine() { - // currentLine.x = 0; //XXX: comment out, don't understand why set to 0, - // because it has already - // been set when setupLine(). And if do need, should - // set to getBorderPaddingInsets().left - // if (!isInlineBlock() && shouldExpand()) - // { - // // FIXME: currently we are using getRecommendedContentWidth, - // // what happen if after adding the new line, the new width is bigger - // than - // // recommendedContentWidth? should we use getWidth() instead of - // // recommendedcontentWidth? - // - // Object textalign = - // (getCSSStyle().getStyleProperty(ICSSPropertyID.ATTR_TEXTALIGN)); - // if (textalign == ICSSPropertyID.VAL_RIGHT) - // { - // _currentLine._x = _blockBox.getRecommendedContentWidth() + - // _blockBox.getBorderPaddingInsets().left - _currentLine.getWidth(); - // } - // else if (textalign == ICSSPropertyID.VAL_CENTER) - // { - // - // _currentLine._x = _blockBox.getBorderPaddingInsets().left + - // (_blockBox.getRecommendedContentWidth() - _currentLine.getWidth()) / - // 2; - // } - // if (_currentLine._x < 0) - // _currentLine._x = 0; - // } - - // FIXME: should check vertical alignment here? - _currentLine.commit(); - _blockBox.add(_currentLine); - } - - public void endBlock() { - endLine(); - } - - int getLinePadding() { - return 0; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/BlockFlowLayout.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/BlockFlowLayout.java deleted file mode 100644 index f50ee6093..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/BlockFlowLayout.java +++ /dev/null @@ -1,252 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import org.eclipse.draw2d.PositionConstants; -import org.eclipse.draw2d.geometry.Insets; - -/** - * The layout for {@link BlockFlow}figures. - * <P> - * WARNING: This class is not intended to be subclassed by clients. - * - * @author mengbo - * @since 2.1 - */ -public class BlockFlowLayout extends FlowContainerLayout { - private LineBox _previousLine = null; - - BlockBox _blockBox; - - /** - * Creates a new BlockFlowLayout with the given BlockFlow. - * - * @param blockFlow - * the BlockFlow - */ - public BlockFlowLayout(BlockFlow blockFlow) { - super(blockFlow); - } - - /** - * @see FlowContainerLayout#cleanup() - */ - protected void cleanup() { - _currentLine = _previousLine = null; - } - - /** - * @see FlowContainerLayout#createNewLine() - */ - protected void createNewLine() { - _currentLine = new LineBox(); - setupLine(_currentLine, Integer.MIN_VALUE); - } - - protected void createNewLine(int topmargin) { - _currentLine = new LineBox(); - setupLine(_currentLine, topmargin); - } - - /** - * Override to setup the line's x, remaining, and available width. - * - * @param line - * the LineBox to set up - */ - protected void setupLine(LineBox line, int topMargin) { - line.clear(); - - // the caller of getCurrentLine() may add leftMargin and leftPadding and - // leftBorder to line.x - line._x = 0; - - // FIXME: here should check the floating boxes, and minus the width of - // them from - // current line. - line.setRecommendedWidth(_blockBox.getRecommendedContentWidth()); - if (_previousLine == null) { - line._y = 0; - if (topMargin != Integer.MIN_VALUE) { - line._y += topMargin; - } - } else { - if (topMargin == Integer.MIN_VALUE) { - line._y = _previousLine._y + _previousLine.getHeight() - + getLinePadding() + _previousLine._marginInsets.bottom; // XXX: - // should - // add - // previous - // margin - // bottom? - } else { - line._y = _previousLine._y - + _previousLine.getHeight() - + Math.max(topMargin, - _previousLine._marginInsets.bottom); - } - } - // line.validate(); - } - - /** - * Called by flush(), adds the BlockBox associated with this BlockFlowLayout - * to the current line and then ends the line. - */ - protected void endBlock() { - getFlowContext().addToCurrentLine(_blockBox); - - // FIXME: here should tell the context the bottom margin. - getFlowContext().endLine(); - } - - /** - * @see FlowContext#endLine() - */ - public void endLine() { - // this is called from child layouts. - // If there is no current line, state is equivalent to new line - if (_currentLine == null) { - return; - } - if (_currentLine.isOccupied()) { - layoutLine(); // finalize the current line layout - } else { - _currentLine = null; - return; - } - LineBox box = _currentLine; - _previousLine = box; - _currentLine = null;// _previousLine; //XXX: ???? why (yang) - - // setupLine(getCurrentLine()); - } - - /** - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContext#getCurrentY() - */ - public int getCurrentY() { - return getCurrentLine()._y; // FIXME: margin of previous block? - } - - /** - * Returns the BlockFlow associated with this BlockFlowLayout - * - * @return the BlockFlow - */ - protected final BlockFlow getBlockFlow() { - return (BlockFlow) getFlowFigure(); - } - - /** - * Adjust all fragments in the current line to have the same baseline. Do - * any additional adjustments, such as horizontal alignment. - */ - protected void layoutLine() { - // currentLine.x = 0; //XXX: comment out, don't understand why set to 0, - // because it has already - // been set when setupLine(). And if do need, should - // set to getBorderPaddingInsets().left - switch (getBlockFlow().getHorizontalAligment()) { - case PositionConstants.RIGHT: - _currentLine._x = _blockBox.getContentWidth() - - getBorderPaddingInsets().right - _currentLine.getWidth(); - break; - case PositionConstants.CENTER: - _currentLine._x = (_blockBox.getContentWidth() - + getBorderPaddingInsets().left - - getBorderPaddingInsets().right - _currentLine.getWidth()) / 2; - break; - } - // FIXME: should check vertical alignment here? - _currentLine.commit(); - _blockBox.add(_currentLine); - } - - /** - * @see FlowContainerLayout#flush() - */ - protected void flush() { - if (_currentLine != null) - layoutLine(); - endBlock(); - } - - /** - * @see FlowContainerLayout#preLayout() - */ - protected void preLayout() { - _blockBox = getBlockFlow().getBlockBox(); - setupBlock(); - // Probably could setup current and previous line here, or just previous - } - - /** - * sets up the single block that contains all of the lines. - */ - protected void setupBlock() { - // Ask for a new line, in case we are in the middle of a line - - // FIXME: the endLine() should tell context the top margin of this - // block. - getFlowContext().endLine(); - - LineBox line = getFlowContext().getCurrentLine(); - // int recommended = line.getAvailableWidth(); - // if (recommended != previousRecommendedWidth) - // Remove all current Fragments - _blockBox.clear(); - - // Setup the one fragment for this Block with the correct X and - // available width - - // FIXME: here should check whether the CSS already set recommended - // width for this - // block. - _blockBox.setRecommendedWidth(line.getAvailableWidth()); - - _blockBox._y = getFlowContext().getCurrentY(); - - // FIXME: blockBox.x should be context.getBorderPaddingInsets().left - // or just line.x ? - _blockBox._x = 0; - } - - Insets getBorderPaddingInsets() { - // FIXME: - return new Insets(); - } - - int getLinePadding() { - return 0; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowFigureLayout#dispose() - */ - public void dispose() { - // TODO: anything to dispose? - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContext#getContainerWidth() - */ - public int getContainerWidth() { - int width = Math.max(0, Math.max(_blockBox.getWidth(), _blockBox - .getRecommendedWidth())); - return width; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/BoxUtil.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/BoxUtil.java deleted file mode 100644 index 54978d145..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/BoxUtil.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import org.eclipse.draw2d.ColorConstants; -import org.eclipse.draw2d.Graphics; -import org.eclipse.draw2d.geometry.Insets; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.swt.graphics.Color; - -/** - * @author mengbo - */ -public class BoxUtil { - /** - * @param box - * @param style - */ - public static void setupBorderPaddingMargin(FlowBox box, ICSSStyle style) { - box._marginInsets = new Insets(style.getMarginInsets()); - box._borderInsets = new Insets(style.getBorderInsets()); - box._paddingInsets = new Insets(style.getPaddingInsets()); - - if (box.getBorderPaddingHeight() > box.getHeight()) { - box.setHeight(box.getBorderPaddingHeight()); - } - if (box.getBorderPaddingWidth() > box.getWidth()) { - box.setWidth(box.getBorderPaddingWidth()); - } - } - - /** - * Debug code. - * - * @param g - * @param box - */ - public static void drawBox(Graphics g, FlowBox box) { - Color color = null; - if (box instanceof BlockBox) { - // color = ColorConstants.red; - } else if (box instanceof LineBox) { - color = ColorConstants.blue; - } else if (box instanceof TextFragmentBox) { - color = ColorConstants.green; - } else { - color = ColorConstants.darkGreen; - } - if (color != null) { - g.setForegroundColor(color); - g.setLineStyle(Graphics.LINE_DASH); - g.setLineWidth(1); - g.drawRectangle(box._x, box._y, box.getWidth(), box.getHeight()); - } - } - -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSBlockFlowLayout.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSBlockFlowLayout.java deleted file mode 100644 index 8e6fa4c2b..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSBlockFlowLayout.java +++ /dev/null @@ -1,722 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.draw2d.FigureUtilities; -import org.eclipse.draw2d.Graphics; -import org.eclipse.draw2d.geometry.Insets; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyID; -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta; -import org.eclipse.jst.pagedesigner.css2.style.ITagEditInfo; -import org.eclipse.jst.pagedesigner.css2.value.Length; -import org.eclipse.jst.pagedesigner.css2.widget.BorderUtil; -import org.eclipse.swt.graphics.FontMetrics; - -/** - * The block layout for {@link CSSFigure}figures. Basic code structure is from - * BlockFlowLayout. - * - * @author mengbo - */ -public class CSSBlockFlowLayout extends CSSLayout implements ICSSPainter2 { - private LineBox _previousLine = null; - - protected BlockBox _blockBox = null; - - protected FontMetrics _fontMetrices; - - int _userSpecifiedWidth; - - int _userSpecifiedHeight; - - /* - * whether we need HScroll and VScroll when overflow is set to "scroll". - * will be updated in "endBlock" and used in "paintFigurePostClientArea" - */ - boolean _needHScroll = false; - - boolean _needVScroll = false; - - /** - * Creates a new CSSBlockFlowLayout with the given BlockFlow. - */ - public CSSBlockFlowLayout(CSSFigure cssfigure) { - super(cssfigure); - } - - protected boolean hasMoreThanOneLine() { - return _previousLine != null; - } - - public boolean isInlineBlock() { - String obj = getCSSStyle().getDisplay(); - return ICSSPropertyID.VAL_INLINE_BLOCK.equals(obj) - || ICSSPropertyID.VAL_INLINE_TABLE.equals(obj); - } - - /** - * whether should expand the width to all available width. - * - * @return - */ - public boolean shouldExpand() { - ICSSStyle style = getCSSStyle(); - if (style == null) { - return false; - } - return "block".equalsIgnoreCase(style.getDisplay()) - || "list-item".equalsIgnoreCase(style.getDisplay()); - } - - // --------------------------------------------------------------------------------------------------- - // preLayout stage. Major job is get the top-left corner information of the - // new block. - - /** - * sets up the single block that contains all of the lines. - */ - protected void setupBlock() { - // int recommended = line.getAvailableWidth(); - // if (recommended != previousRecommendedWidth) - // Remove all current Fragments - _blockBox.clear(); - // Ask for a new line, in case we are in the middle of a line - - if (!isInlineBlock()) { - LineBox lineBox = getFlowContext().getCurrentLine(); - if (lineBox != null && !lineBox.isEmptyStringLine()) { - getFlowContext().endLine(); - } - } - - ICSSStyle style = getCSSStyle(); - - // endLine will result in context create a new line, so we are in the - // new line now. - // passing in the top margin, and context will consider that when create - // the new line. - int marginTop = style.getMarginInsets().top; - LineBox line = getFlowContext().getCurrentLine(marginTop); - - // Setup the one fragment for this Block with the correct X and - // available width - - // FIXME: according to spec, when using percentage width/height, should - // percentage to - // the "containing block". But we don't have very good "containing - // block" resolution - // implementation yet. - - // calculate the min size - // int minWidth = 0; - // int minHeight = 0; - // if (style != null) - // { - // // try to see whether there is any designer specified min size - // ITagEditInfo info = (ITagEditInfo) - // style.getAdapter(ITagEditInfo.class); - // if (info != null) - // { - // minWidth = info.getMinWidth(); - // minHeight = info.getMinHeight(); - // } - // - // // CSS also has the min-width/min-height property. We should also get - // that, - // // and using the max of the "min-width" css property and the designer - // specified min size. - // int height = getLengthValue(style,ICSSPropertyID.ATTR_MIN_HEIGHT); - // if(height > minHeight) - // { - // minHeight = height; - // } - // int width = getLengthValue(style,ICSSPropertyID.ATTR_MIN_WIDTH); - // if(width > minWidth) - // { - // minWidth = width; - // } - // } - - // keep track of user specified size, this will be used when handling - // the "overflow" CSS property. - _userSpecifiedWidth = 0; - _userSpecifiedHeight = 0; - - { - int width = getLengthValue(style, ICSSPropertyID.ATTR_WIDTH); - - int availableWidth = line.getAvailableWidth() - - style.getMarginInsets().getWidth(); - if (width <= 0) { - // no width setting - if (isCalculatingMaxWidth()) { - _blockBox.setRecommendedWidth(Integer.MAX_VALUE); - // _blockBox.setWidth( (minWidth>0?minWidth:0)); - } else { - _blockBox.setRecommendedWidth(availableWidth); - if (shouldExpand()) { - _blockBox.setWidth(availableWidth); - } else { - // _blockBox.setWidth( (minWidth>0?minWidth:0)); - } - } - } else { - int w = width; - if (!style.isSizeIncludeBorderPadding()) { - w += style.getBorderInsets().getWidth() - + style.getPaddingInsets().getWidth(); - } - // XXX: should we use minWidth or follow user's choice? - // if (w < minWidth) - // { - // w = minWidth; - // } - _userSpecifiedWidth = w; - _blockBox.setWidth(w); - _blockBox.setRecommendedWidth(w); - } - } - - { - int height = getLengthValue(style, ICSSPropertyID.ATTR_HEIGHT); - // Object height = - // style.getStyleProperty(ICSSPropertyID.ATTR_HEIGHT); - // Length heightLength = (height instanceof Length) ? (Length) - // height : null; - - if (height <= 0) { - // if (minHeight > 0) - // { - // // _blockBox.setHeight(minHeight); - // _blockBox.setRecommendedHeight(minHeight); - // } - // else - { - _blockBox.setHeight(0); - _blockBox.setRecommendedHeight(0); - } - } else { - int h = height; - if (handlingBorderForBlock() - && !style.isSizeIncludeBorderPadding()) { - h += style.getBorderInsets().getHeight() - + style.getPaddingInsets().getHeight(); - } - // XXX: should we follow minHeight or user's choice? - // if (minHeight > h) - // { - // h = minHeight; - // } - _userSpecifiedHeight = h; - _blockBox.setHeight(h); - _blockBox.setRecommendedHeight(h); - } - } - _blockBox._marginInsets = new Insets(style.getMarginInsets()); - if (handlingBorderForBlock()) { - BoxUtil.setupBorderPaddingMargin(_blockBox, getCSSStyle()); - } - - // as in designer, we don't want to the element to have zero size, so - // set a minimun size here. - // _blockBox.setWidth(Math.max(20, _blockBox.getWidth())); - // int minHeight = getCSSStyle().getCSSFont().getFontSize() + - // _blockBox.getBorderPaddingHeight(); - // _blockBox.setHeight(Math.max(minHeight, _blockBox.getHeight())); - - _blockBox._y = line._y; - _blockBox._x = line._x; - - setBlockVerticalAlign(_blockBox); - } - - protected int getLengthValue(ICSSStyle style, String property) { - int lengthValue = 0; - if (style != null) { - Object object = style.getStyleProperty(property); - Length lengthObj = (object instanceof Length) ? (Length) object - : null; - - if (lengthObj != null) { - lengthValue = lengthObj.getValue(); - if (lengthObj.isPercentage()) { - if (ICSSPropertyID.ATTR_WIDTH.equalsIgnoreCase(property) - || ICSSPropertyID.ATTR_MIN_WIDTH - .equalsIgnoreCase(property)) { - lengthValue = this.getFlowContext().getContainerWidth() - * lengthValue / 100; - } else if (ICSSPropertyID.ATTR_HEIGHT - .equalsIgnoreCase(property) - || ICSSPropertyID.ATTR_MIN_HEIGHT - .equalsIgnoreCase(property)) { - // XXX: we should omit it because we don't support - // percentage height now. - lengthValue = 0; - } - } - } - } - return lengthValue; - } - - private void setBlockVerticalAlign(BlockBox box) { - ICSSStyle style = getCSSStyle(); - if (style != null) { - box.setVerticalAlignData(style - .getStyleProperty(ICSSPropertyID.ATTR_VERTICAL_ALIGN)); - } - } - - /** - * @see FlowContainerLayout#preLayout() - */ - protected void preLayout() { - super.preLayout(); - _blockBox = new BlockBox(); - setupBlock(); - // Probably could setup current and previous line here, or just previous - } - - // ------------------------------------------------------------------------------------------------------- - protected void layoutLines() { - List lines = _blockBox.getFragments(); - if (lines != null) { - for (int i = 0; i < lines.size(); i++) { - if (lines.get(i) instanceof LineBox) { - layoutLine((LineBox) lines.get(i)); - } - } - } - } - - /** - * Called by flush(), adds the BlockBox associated with this BlockFlowLayout - * to the current line and then ends the line. - */ - protected void endBlock() { - layoutLines(); - ICSSStyle style = getCSSStyle(); - if (style != null) { - int minWidth = 0; - int minHeight = 0; - // try to see whether there is any designer specified min size - ITagEditInfo info = (ITagEditInfo) style - .getAdapter(ITagEditInfo.class); - if (info != null) { - minWidth = info.getMinWidth(); - minHeight = info.getMinHeight(); - } - - // CSS also has the min-width/min-height property. We should also - // get that, - // and using the max of the "min-width" css property and the - // designer specified min size. - int height = getLengthValue(style, ICSSPropertyID.ATTR_MIN_HEIGHT); - if (height > minHeight) { - minHeight = height; - } - int width = getLengthValue(style, ICSSPropertyID.ATTR_MIN_WIDTH); - if (width > minWidth) { - minWidth = width; - } - if (minHeight > _blockBox.getHeight()) { - _blockBox.setHeight(minHeight); - } - if (minWidth > _blockBox.getWidth()) { - _blockBox.setWidth(minWidth); - } - } - - // reset scroll information. - this._needHScroll = this._needVScroll = false; - - // ok, now we need to adjust the _blockBox's size according to the - // "overflow" setting. - // depends on different "overflow" style of this block, different sizing - // policy may apply. - // ICSSStyle style = this.getCSSStyle(); - if (style != null) { - Object overflow = style - .getStyleProperty(ICSSPropertyID.ATTR_OVERFLOW); - if (ICSSPropertyID.VAL_HIDDEN.equals(overflow)) { - if (_userSpecifiedWidth > 0) { - _blockBox.setWidth(_userSpecifiedWidth); - } - if (_userSpecifiedHeight > 0) { - _blockBox.setHeight(_userSpecifiedHeight); - } - } else if (ICSSPropertyID.VAL_SCROLL.equals(overflow) - || ICSSPropertyID.VAL_AUTO.equals(overflow)) { - // adjust _needHScroll and _needVScroll - if (_userSpecifiedWidth > 0 - && _userSpecifiedWidth < _blockBox.getWidth()) { - _needHScroll = true; - } - if (_userSpecifiedHeight > 0 - && _userSpecifiedHeight < _blockBox.getHeight()) { - _needVScroll = true; - } - if (_needHScroll && !_needVScroll) { - if (_userSpecifiedHeight > 0 - && _blockBox.getInternalContentHeight() >= 0 - && _userSpecifiedHeight < _blockBox - .getInternalContentHeight() - + _blockBox._paddingInsets.getHeight() - + BorderUtil.SCROLL_WIDTH) { - _needVScroll = true; - } - } - if (!_needHScroll && _needVScroll) { - if (_userSpecifiedWidth > 0 - && _blockBox.getInternalContentWidth() >= 0 - && _userSpecifiedWidth < _blockBox - .getInternalContentWidth() - + _blockBox._paddingInsets.getWidth() - + BorderUtil.SCROLL_WIDTH) { - _needHScroll = true; - } - } - - if (_userSpecifiedWidth > 0) { - _blockBox.setWidth(_userSpecifiedWidth); - } - if (_userSpecifiedHeight > 0) { - _blockBox.setHeight(_userSpecifiedHeight); - } - } - } - - if (getFlowContext().isCurrentLineOccupied() - && getFlowContext().getCurrentLine().getAvailableWidth() < _blockBox._width - + _blockBox._marginInsets.getWidth()) { - getFlowContext().endLine(); - } - if (!isInlineBlock()) { - LineBox line = getFlowContext().getCurrentLine(); - line.setHorizonalData(getCSSStyle().getStyleProperty( - ICSSPropertyID.ATTR_HORIZONTAL_ALIGN)); - line.setHtmlInitData(getCSSStyle().getHTMLelementInitValue( - ICSSPropertyID.ATTR_HORIZONTAL_ALIGN)); - line.add(_blockBox); - // getFlowContext().addToCurrentLine(_blockBox); - } else { - getFlowContext().addToCurrentLine(_blockBox); - } - getFlowContext().getCurrentLine()._marginInsets.bottom = getCSSStyle() - .getMarginInsets().bottom; - - if (!isInlineBlock()) { - getFlowContext().endLine(); - } - } - - protected void layoutLine(LineBox line) { - // currentLine.x = 0; //XXX: comment out, don't understand why set to 0, - // because it has already - // been set when setupLine(). And if do need, should - // set to getBorderPaddingInsets().left - // if (!isInlineBlock() && shouldExpand()) - // { - // FIXME: currently we are using getRecommendedContentWidth, - // what happen if after adding the new line, the new width is bigger - // than - // recommendedContentWidth? should we use getWidth() instead of - // recommendedcontentWidth? - Object textalign = line.getHorizonalData(); - if (textalign == null - || ICSSPropertyMeta.NOT_SPECIFIED.equals(textalign)) { - textalign = (getCSSStyle() - .getStyleProperty(ICSSPropertyID.ATTR_TEXTALIGN)); - } - if (textalign == null - || ICSSPropertyMeta.NOT_SPECIFIED.equals(textalign)) { - textalign = line.getHtmlInitData(); - } - if (ICSSPropertyID.VAL_RIGHT.equals(textalign)) { - line._x = _blockBox.getContentWidth() - line.getWidth(); - } else if (ICSSPropertyID.VAL_CENTER.equals(textalign)) { - line._x = (_blockBox.getContentWidth() - line.getWidth()) / 2; - } - - if (line._x < 0) { - line._x = 0; - } - line.commit(); - } - - /** - * Adjust all fragments in the current line to have the same baseline. Do - * any additional adjustments, such as horizontal alignment. - */ - protected void addCurrentLine() { - // The follow code is commented out, and moved into layoutLine(line) - // called by endBlock(). - // since only when endBlock is called we really know how big is this - // block box, and then can - // do horizontal alignment. - // // currentLine.x = 0; //XXX: comment out, don't understand why set to - // 0, because it has already - // // been set when setupLine(). And if do need, should - // // set to getBorderPaddingInsets().left - // if (!isInlineBlock() && shouldExpand()) - // { - // // FIXME: currently we are using getRecommendedContentWidth, - // // what happen if after adding the new line, the new width is bigger - // than - // // recommendedContentWidth? should we use getWidth() instead of - // // recommendedcontentWidth? - // - // Object textalign = - // (getCSSStyle().getStyleProperty(ICSSPropertyID.ATTR_TEXTALIGN)); - // if (textalign == ICSSPropertyID.VAL_RIGHT) - // { - // _currentLine._x = _blockBox.getContentWidth() + - // _blockBox.getBorderPaddingInsets().left - _currentLine.getWidth(); - // } - // else if (textalign == ICSSPropertyID.VAL_CENTER) - // { - // - // _currentLine._x = _blockBox.getBorderPaddingInsets().left + - // (_blockBox.getContentWidth() - _currentLine.getWidth()) / 2; - // } - // if (_currentLine._x < 0) - // _currentLine._x = 0; - // } - // - // // FIXME: should check vertical alignment here? - // _currentLine.commit(); - - // layoutLine(_currentLine); - _blockBox.add(_currentLine); - } - - /** - * @see FlowContainerLayout#flush() - */ - protected void flush() { - if (_currentLine != null && _currentLine.isOccupied()) { - addCurrentLine(); - } - endBlock(); - } - - /** - * @see FlowContainerLayout#cleanup() - */ - protected void cleanup() { - _currentLine = _previousLine = null; - _fontMetrices = null; - } - - // ---------------------------------------------------------------------------------- - - /** - * Override to setup the line's x, remaining, and available width. - * - * @param line - * the LineBox to set up - */ - protected void setupLine(LineBox line, int topMargin) { - line.clear(); - - // the caller of getCurrentLine() may add leftMargin and leftPadding and - // leftBorder to line.x - line._x = 0; - - // FIXME: here should check the floating boxes, and minus the width of - // them from - // current line. - line.setRecommendedWidth(_blockBox.getRecommendedContentWidth()); - if (_previousLine == null) { - line._y = 0; - if (topMargin != Integer.MIN_VALUE) { - line._y += topMargin; - } - } else { - if (topMargin == Integer.MIN_VALUE) { - line._y = _previousLine._y + _previousLine.getHeight() - + getLinePadding() + _previousLine._marginInsets.bottom; // XXX: - // should - // add - // previous - // margin - // bottom? - } else { - line._y = _previousLine._y - + _previousLine.getHeight() - + Math.max(topMargin, - _previousLine._marginInsets.bottom); - } - } - setFontinfoForLine(line); - // line.validate(); - } - - private void setFontinfoForLine(LineBox line) { - - ICSSStyle style = getCSSStyle(); - if (style != null) { - if (_fontMetrices == null) { - // as getSwtFont is resource consuming, so we cache the - // _fontMetrics. - _fontMetrices = FigureUtilities.getFontMetrics(style - .getCSSFont().getSwtFont()); - } - line.setFontMetrics(_fontMetrices); - } - } - - /** - * @see FlowContainerLayout#createNewLine() - */ - protected void createNewLine() { - _currentLine = new LineBox(); - setupLine(_currentLine, Integer.MIN_VALUE); - } - - protected void createNewLine(int topmargin) { - _currentLine = new LineBox(); - setupLine(_currentLine, topmargin); - } - - /** - * @see FlowContext#endLine() - */ - public void endLine() { - // this is called from child layouts. - // If there is no current line, state is equivalent to new line - if (_currentLine == null) { - return; - } - if (_currentLine.isOccupied()) { - addCurrentLine(); // finalize the current line layout - } else { - _currentLine = null; - return; - } - - LineBox box = _currentLine; - // _currentLine = _previousLine; //XXX: ???? why (yang) - _previousLine = box; - - _currentLine = null; - // setupLine(getCurrentLine()); - } - - /** - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContext#getCurrentY() - */ - public int getCurrentY() { - return getCurrentLine()._y; // FIXME: margin of previous block? - } - - int getLinePadding() { - return 0; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.CSSLayout#useLocalCoordinates() - */ - public boolean useLocalCoordinates() { - return true; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowFigureLayout#dispose() - */ - public void dispose() { - // - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.ICSSLayout#getFragmentsForRead() - */ - public List getFragmentsForRead() { - List r = new ArrayList(1); - r.add(_blockBox); - return r; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.ICSSLayout#postValidate() - */ - public void postValidate() { - - Rectangle r = new Rectangle(_blockBox._x, _blockBox._y, _blockBox - .getWidth(), _blockBox.getHeight()); - getCSSFigure().setBounds(r); - List list = getCSSFigure().getChildren(); - for (int i = 0; i < list.size(); i++) { - ((FlowFigure) list.get(i)).postValidate(); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContext#getContainerWidth() - */ - public int getContainerWidth() { - int width = Math.max(0, Math.max(_blockBox.getWidth(), _blockBox - .getRecommendedWidth())); - return width; - } - - /** - * when the "overflow" is "scroll", we need to paint the scrollbar - */ - public void paintFigurePostClientArea(Graphics g) { - ICSSStyle style = this.getCSSStyle(); - if (style != null) { - Object overflow = style - .getStyleProperty(ICSSPropertyID.ATTR_OVERFLOW); - if (ICSSPropertyID.VAL_SCROLL.equals(overflow) - || ICSSPropertyID.VAL_AUTO.equals(overflow)) { - if (this._needHScroll || this._needVScroll) { - // as this is using localCoordinate, so translate to - // relative to left/up corder of whole - // blockbox. - g.translate(-_blockBox.getBorderPaddingInsets().left, - -_blockBox.getBorderPaddingInsets().top); - - Rectangle rect = new Rectangle(0, 0, _blockBox.getWidth(), - _blockBox.getHeight()); - rect.crop(_blockBox._borderInsets); - - if (this._needHScroll && this._needVScroll) { - BorderUtil.drawScrollBar(g, BorderUtil.SCROLL_WIDTH, - rect, BorderUtil.BOTH); - } else if (this._needHScroll) { - BorderUtil.drawScrollBar(g, BorderUtil.SCROLL_WIDTH, - rect, BorderUtil.HORIZONTAL_BAR); - } else if (this._needVScroll) { - BorderUtil.drawScrollBar(g, BorderUtil.SCROLL_WIDTH, - rect, BorderUtil.VERTICAL_BAR); - } - } - } - } - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSBrFlowLayout.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSBrFlowLayout.java deleted file mode 100644 index b343aaea9..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSBrFlowLayout.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import java.util.List; - -import org.eclipse.draw2d.Graphics; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.jst.pagedesigner.PDPlugin; -import org.eclipse.swt.graphics.Image; - -/** - * @author mengbo - */ -public class CSSBrFlowLayout extends CSSInlineFlowLayout implements ICSSPainter { - /** - * @param flow - */ - public CSSBrFlowLayout(CSSFigure flow) { - super(flow); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.CSSInlineFlowLayout#flush() - */ - protected void flush() { - FlowBox forcedBox = new FlowBox(); - forcedBox.setWidth(16); - forcedBox.setHeight(getCSSStyle().getCSSFont().getXHeight()); - addToCurrentLine(forcedBox); - endLine(); - - FlowBox flowbox = new FlowBox(); - flowbox.setHeight(getCSSStyle().getCSSFont().getFontSize()); - getCurrentLine().add(flowbox); - - super.flush(); - } - - public void paintFigure(Graphics g) { - List fragments = getFragmentsForRead(); - if (!fragments.isEmpty()) { - FlowBox box = (FlowBox) fragments.get(0); - g.drawImage(getSharedHTMLImage(), new Point(box._x, box._y)); - } - } - - private static Image getSharedHTMLImage() { - return PDPlugin.getDefault().getImage("palette/HTML/small/HTML_BR.gif"); - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSFigure.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSFigure.java deleted file mode 100644 index e45e070ba..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSFigure.java +++ /dev/null @@ -1,515 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import java.util.List; - -import org.eclipse.draw2d.Border; -import org.eclipse.draw2d.ColorConstants; -import org.eclipse.draw2d.Graphics; -import org.eclipse.draw2d.LayoutManager; -import org.eclipse.draw2d.geometry.Insets; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.jst.jsf.common.ui.internal.logging.Logger; -import org.eclipse.jst.pagedesigner.PDPlugin; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.border.CSSBorder; -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyID; -import org.eclipse.jst.pagedesigner.css2.property.VisibilityMeta; -import org.eclipse.jst.pagedesigner.css2.style.DefaultStyle; -import org.eclipse.jst.pagedesigner.css2.style.ITagEditInfo; -import org.eclipse.jst.pagedesigner.css2.widget.BorderUtil; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.RGB; - -/** - * Normally a CSSFigure is a container. It's layout will be driven by different - * display type information from the style. - * - * Each CSSFigure will be driven by ICSSStyle, the display type of the ICSSStyle - * will decide the layout to be used for the figure. - * - * @author mengbo - */ -public class CSSFigure extends FlowFigure implements ICSSFigure { - private static Logger _log = PDPlugin.getLogger(CSSFigure.class); - - private static final Rectangle PRIVATE_RECT = new Rectangle(); - - ICSSStyle _style; - - // NOTE: here keep the element is only for debug use. CSSFigure shouldn't - // require an element. - // Element _element; - - // if this field is set, then regetLayout() will still return this layout, - // without going through the CSS resolution - CSSLayout _fixedLayout; - - public CSSFigure() { - _style = DefaultStyle.getInstance(); - invalidateCSS(); - } - - public CSSFigure(ICSSStyle style) { - _style = style; - // _element = element; - invalidateCSS(); - } - - public ICSSStyle getCSSStyle() { - return _style; - } - - public void setCSSStyle(ICSSStyle style) { - _style = style; - invalidateCSS(); - } - - public void revalidate() { - CSSLayout layout = (CSSLayout) getLayoutManager(); - layout.figureRevalidate(); - super.revalidate(); - } - - /** - * this method is called when the css source noticed style change. So tell - * the figure should invalidate its cached data. - */ - public void invalidateCSS() { - // maybe we changed from inline to block or block to inline - // XXX: or even to table? - CSSLayout layout = regetLayout(getLayoutManager()); - this.setLayoutManager(layout); - } - - public void setFixedLayoutManager(CSSLayout layout) { - this._fixedLayout = layout; - this.setLayoutManager(regetLayout(getLayoutManager())); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.draw2d.Figure#setLayoutManager(org.eclipse.draw2d.LayoutManager) - */ - public void setLayoutManager(LayoutManager manager) { - LayoutManager old = getLayoutManager(); - if (old != manager) { - FlowContext context = null; - if (old instanceof FlowFigureLayout) { - context = ((FlowFigureLayout) old).getOriginalFlowContext(); - } - if (manager instanceof FlowFigureLayout) { - ((FlowFigureLayout) manager).setOriginalFlowContext(context); - } - - if (manager instanceof FlowContext) { - List list = getChildren(); - for (int i = 0, size = list.size(); i < size; i++) { - try { - ((FlowFigure) list.get(i)) - .setOriginalFlowContext((FlowContext) manager); - } catch (ClassCastException classcastexception) { - // Error in flowContext setting. - _log.error("Error.CSSFigure.0", classcastexception); //$NON-NLS-1$ - } - } - } - } - super.setLayoutManager(manager); - } - - protected CSSLayout regetLayout(LayoutManager old) { - if (_fixedLayout != null) { - return _fixedLayout; - } - CSSLayout layout = DisplayToLayout.displayToLayout(this, getCSSStyle() - .getDisplay(), old); - if (layout != null) { - return layout; - } - return new CSSInlineFlowLayout(this); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.draw2d.Figure#containsPoint(int, int) - */ - public boolean containsPoint(int x, int y) { - // check whether any float figure contains it. - // FIXME: need check floating figure here!!! - if (!super.containsPoint(x, y)) { - return false; - } - List frags = getFragmentsForRead(); - // Here we should not get void pointer. - if (frags != null) { - for (int i = 0; i < frags.size(); i++) { - FlowBox box = (FlowBox) frags.get(i); - if (box != null && box.containsPoint(x, y)) { - return true; - } - } - } - return false; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.ICSSFigure#getFragmentsForRead() - */ - public List getFragmentsForRead() { - CSSLayout layout = (CSSLayout) getLayoutManager(); - return layout.getFragmentsForRead(); - } - - /** - * this method is a shortcut to getFragmentsForRead - * - * @return - */ - public Rectangle[] getFragmentsBounds() { - List list = getFragmentsForRead(); - if (list == null || list.size() == 0) { - // should not happen. but still handle it. - return new Rectangle[] { getBounds() }; - } - Rectangle[] ret = new Rectangle[list.size()]; - for (int i = 0, size = list.size(); i < size; i++) { - FlowBox box = (FlowBox) list.get(i); - ret[i] = new Rectangle(box._x, box._y, box.getWidth(), box - .getHeight()); - } - return ret; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.draw2d.IFigure#setBounds(org.eclipse.draw2d.geometry.Rectangle) - */ - public void setBounds(Rectangle r) { - if (getBounds().equals(r)) { - return; - } - boolean invalidate = getBounds().width != r.width - || getBounds().height != r.height; - super.setBounds(r); - - CSSLayout layout = (CSSLayout) this.getLayoutManager(); - layout.setBoundsCalled(r, invalidate); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowFigure#postValidate() - */ - public void postValidate() { - CSSLayout layout = (CSSLayout) getLayoutManager(); - layout.postValidateForAbsolute(); - layout.postValidate(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.draw2d.IFigure#validate() - */ - public void validate() { - super.validate(); - // should not call this.postValidate() here. PostValidate() should - // only be started from the FlowPage. Otherwise it will be called - // multiple times on a figure. - // this.postValidate(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.draw2d.Figure#useLocalCoordinates() - */ - protected boolean useLocalCoordinates() { - CSSLayout layout = (CSSLayout) getLayoutManager(); - if (layout == null) { - return false; - } - return layout.useLocalCoordinates(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.draw2d.IFigure#paint(org.eclipse.draw2d.Graphics) - */ - public void paint(Graphics graphics) { - ICSSStyle style = getCSSStyle(); - if (style != null) { - Object visibility = style - .getStyleProperty(ICSSPropertyID.ATTR_VISIBILITY); - // handle visibility: hidden here. - // TODO: "collapse" is not supported yet! - if (VisibilityMeta.HIDDEN.equals(visibility)) { - return; - } - } - - CSSLayout layout = (CSSLayout) this.getLayoutManager(); - graphics.pushState(); - try { - paintFigure(graphics); - graphics.restoreState(); - paintClientArea(graphics); - if (layout instanceof ICSSPainter2) { - if (useLocalCoordinates()) { - graphics.translate(getBounds().x + getInsets().left, - getBounds().y + getInsets().top); - ((ICSSPainter2) layout).paintFigurePostClientArea(graphics); - graphics.restoreState(); - } else { - ((ICSSPainter2) layout).paintFigurePostClientArea(graphics); - } - } - paintBorder(graphics); - } finally { - graphics.popState(); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowFigure#paintFigure(org.eclipse.draw2d.Graphics) - */ - protected void paintFigure(Graphics g) { - Color rgbColor = null; - boolean fillArea = false; - Object bg = getCSSStyle().getBackgroundColor(); - if (bg instanceof RGB) { - rgbColor = new Color(null, (RGB) bg); - g.setBackgroundColor(rgbColor); - fillArea = true; - } else if (bg instanceof Color) { - g.setBackgroundColor((Color) bg); - fillArea = true; - } - if (fillArea) { - List fragments = getFragmentsForRead(); - - for (int i = 0, n = fragments.size(); i < n; i++) { - Object obj = fragments.get(i); - if (obj instanceof FlowBox) { - FlowBox box = (FlowBox) obj; - g.fillRectangle(box._x, box._y, box.getWidth(), box - .getHeight()); - } - } - } - if (rgbColor != null) { - rgbColor.dispose(); - } - g.restoreState(); - - LayoutManager layout = getLayoutManager(); - if (layout instanceof ICSSPainter) { - if (useLocalCoordinates()) { - g.translate(getBounds().x + getInsets().left, getBounds().y - + getInsets().top); - ((ICSSPainter) layout).paintFigure(g); - g.restoreState(); - } else { - ((ICSSPainter) layout).paintFigure(g); - } - } - - // paint selected mode here. - paintSelection(g); - - if (Debug.DEBUG_BOX) { - // draw two levels of boxes. Since normally each figure will only - // have two levels of boxes. - List fragments = this.getFragmentsForRead(); - for (int i = 0, size = fragments.size(); i < size; i++) { - FlowBox box = (FlowBox) fragments.get(i); - BoxUtil.drawBox(g, box); - if (box instanceof BlockBox) { - BlockBox compositeBox = (BlockBox) box; - List list = compositeBox.getFragments(); - for (int j = 0; j < list.size(); j++) { - g.translate(this.getInsets().left, - this.getInsets().right); - BoxUtil.drawBox(g, (FlowBox) list.get(j)); - g.restoreState(); - } - } - } - } - if (Debug.DEBUG_BASELINE) { - List fragments = this.getFragmentsForRead(); - for (int i = 0, size = fragments.size(); i < size; i++) { - Object obj = fragments.get(i); - if (obj instanceof LineBox) { - LineBox linebox = (LineBox) obj; - g.setForegroundColor(ColorConstants.red); - g.drawLine(linebox._x, linebox._y + linebox.getAscent(), - linebox._x + linebox.getWidth(), linebox._y - + linebox.getAscent()); - } - } - } - - if (Debug.DEBUG_BORDERPADDING) { - if (this.getLayoutManager() instanceof CSSBlockFlowLayout) { - g.setLineWidth(1); - Rectangle rect = getBounds().getCopy().crop(getInsets()); - g.setForegroundColor(ColorConstants.green); - g.drawRectangle(rect); - g.setForegroundColor(ColorConstants.red); - g.drawRectangle(getBounds()); - } - } - - if (Debug.DEBUG_BOX) { - CSSLayout csslayout = (CSSLayout) this.getLayoutManager(); - if (csslayout._absoluteContext != null) { - BlockBox blockbox = csslayout._absoluteContext._blockBox; - g.setLineWidth(1); - g.setForegroundColor(ColorConstants.green); - g.drawRectangle(blockbox._x, blockbox._y, blockbox.getWidth(), - blockbox.getHeight()); - } - } - } - - /** - * Paints this Figure's client area. The client area is typically defined as - * the anything inside the Figure's {@link Border} or {@link Insets}, and - * by default includes the children of this Figure. On return, this method - * must leave the given Graphics in its initial state. - * - * @param graphics - * The Graphics used to paint - * @since 2.0 - */ - protected void paintClientArea(Graphics graphics) { - if (this.getChildren().isEmpty()) { - return; - } - - Object overflow = ICSSPropertyID.VAL_VISIBLE; - ICSSStyle style = this.getCSSStyle(); - if (style != null) { - overflow = style.getStyleProperty(ICSSPropertyID.ATTR_OVERFLOW); - } - - boolean optimizeClip = ICSSPropertyID.VAL_VISIBLE.equals(overflow); - - if (useLocalCoordinates()) { - graphics.translate(getBounds().x + getInsets().left, getBounds().y - + getInsets().top); - if (!optimizeClip) { - graphics.clipRect(getClientArea(PRIVATE_RECT)); - } - graphics.pushState(); - paintChildren(graphics); - graphics.popState(); - graphics.restoreState(); - } else { - if (optimizeClip) { - paintChildren(graphics); - } else { - graphics.clipRect(getClientArea(PRIVATE_RECT)); - graphics.pushState(); - paintChildren(graphics); - graphics.popState(); - graphics.restoreState(); - } - } - } - - /** - * @param g - */ - protected void paintSelection(Graphics g) { - ICSSStyle style = this.getCSSStyle(); - if (style != null) { - if (style.isInSelection()) { - ITagEditInfo editInfo = (ITagEditInfo) style - .getAdapter(ITagEditInfo.class); - if (editInfo != null && editInfo.isWidget()) { - BorderUtil.maskFigure(this, g); - } - } - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.draw2d.Figure#paintBorder(org.eclipse.draw2d.Graphics) - */ - protected void paintBorder(Graphics graphics) { - CSSLayout layout = (CSSLayout) getLayoutManager(); - if (layout != null && !layout.handlingBorderForBlock()) { - return; - } - - ICSSStyle style = this.getCSSStyle(); - if (style != null) { - CSSBorder border1 = new CSSBorder(this.getCSSStyle()); - border1.paint(this, graphics, NO_INSETS); - - // draw a border for those special elements like <h:form>, etc. - ITagEditInfo editInfo = (ITagEditInfo) style - .getAdapter(ITagEditInfo.class); - if (editInfo != null && editInfo.needBorderDecorator()) { - BorderUtil.drawBorderDecorator(this, graphics); - } - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.draw2d.IFigure#getInsets() - */ - public Insets getInsets() { - CSSLayout layout = (CSSLayout) getLayoutManager(); - if (layout != null && !layout.handlingBorderForBlock()) { - return new Insets(); - } - ICSSStyle style = this.getCSSStyle(); - if (style != null) { - return style.getBorderInsets().getAdded(style.getPaddingInsets()); - } - return new Insets(); - } - - /** - * FIXME: need trace the implementation of Figure.invalidate() We want to - * just mark this figure as invalid, but don't want to the layout get - * invalidated. - * - */ - public void invalidate2() { - if (!isValid()) - return; - // if (getLayoutManager() != null) - // getLayoutManager().invalidate(); - setValid(false); - - } - -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSInlineFlowLayout.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSInlineFlowLayout.java deleted file mode 100644 index 97f4571c0..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSInlineFlowLayout.java +++ /dev/null @@ -1,319 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.draw2d.FigureUtilities; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyID; -import org.eclipse.jst.pagedesigner.css2.style.ITagEditInfo; - -/** - * The layout manager for {@link CSSFigure}figures. This class is based on - * InlineFlowLayout of draw2d. - * - * @author mengbo - */ -public class CSSInlineFlowLayout extends CSSLayout { - List _fragments = new ArrayList(); - - /** - * Creates a new InlineFlowLayout with the given FlowFigure. - * - * @param flow - * The FlowFigure - */ - public CSSInlineFlowLayout(CSSFigure flow) { - super(flow); - } - - /** - * Clears out all fragments prior to the call to layoutChildren(). - */ - public void preLayout() { - super.preLayout(); - _fragments.clear(); - // force creating of the first line. avoid empty element don't have - // fragments. - // createFirstLine(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContainerLayout#layoutChildren() - */ - protected void layoutChildren() { - // For designer, to make it to have some size. otherwise can't - // be found on screen. - // List children = getCSSFigure().getChildren(); - // if (children.size() == 0) - // { - // FlowBox box = new FlowBox(); - // box._height = getCSSStyle().getCSSFont().getFontSize(); - // box._width = 2; - // addToCurrentLine(box); - // - // } - super.layoutChildren(); - } - - /** - * Adds the given FlowBox to the current line of this InlineFlowLayout. - * - * @param block - * the FlowBox to add to the current line - */ - public void addToCurrentLine(FlowBox block) { - getCurrentLine().add(block); - // XXX: ???: will currentLine be added multiple times to fragments? - // (yang) - // _fragments.add(_currentLine); - } - - private void createFirstLine() { - _currentLine = new LineBox(); - setupLine(_currentLine, true); - _fragments.add(_currentLine); - } - - /** - * @see FlowContainerLayout#createNewLine() - */ - protected void createNewLine() { - _currentLine = new LineBox(); - setupLine(_currentLine, false); - _fragments.add(_currentLine); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContainerLayout#createNewLine(int) - */ - protected void createNewLine(int topMargin) { - // inline flow don't support vertical margin. - createNewLine(); - } - - /** - * @see FlowContainerLayout#cleanup() - */ - protected void cleanup() { - _currentLine = null; - } - - /** - * @see FlowContainerLayout#flush() - */ - protected void flush() { - if (_fragments.isEmpty()) { - createFirstLine(); - } else if (_fragments.size() == 1) { - - ICSSStyle style = getCSSStyle(); - int minWidth = 0, minHeight = 0; - // try to see whether there is any designer specified min size - ITagEditInfo info = (ITagEditInfo) style - .getAdapter(ITagEditInfo.class); - if (info != null) { - minWidth = info.getMinWidth(); - minHeight = info.getMinHeight(); - } - FlowBox box = (FlowBox) _fragments.get(0); - if (minWidth > box._width) { - box._width = minWidth; - } - if (minHeight > box._height) { - box._height = minHeight; - } - } - - if (_currentLine != null /* && _currentLine.isOccupied() */) { - _currentLine._marginInsets.right = getCSSStyle().getMarginInsets().right; - getFlowContext().addToCurrentLine(_currentLine); - } - - } - - /** - * @see FlowContext#endLine() - */ - public void endLine() { - if (_currentLine == null) { - getFlowContext().endLine(); - return; - } - // If nothing was ever placed in the line, ignore it. and if the line is - // the first line, just remove it. - if (_currentLine.isOccupied()) { - getFlowContext().addToCurrentLine(_currentLine); - } else if (_fragments.size() == 1) { - _fragments.remove(0); - } - getFlowContext().endLine(); - _currentLine = null; - } - - /** - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContext#getCurrentY() - */ - public int getCurrentY() { - return getCurrentLine()._y; - } - - /** - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContainerLayout#isCurrentLineOccupied() - */ - public boolean isCurrentLineOccupied() { - if (_currentLine == null) { - return getFlowContext().isCurrentLineOccupied(); - } else if (_currentLine.getFragments().isEmpty()) { - return getFlowContext().isCurrentLineOccupied(); - } else { - return true; - } - } - - /** - * Initializes the given LineBox. Called by createNewLine(). - * - * @param line - * The LineBox to initialize. - */ - protected void setupLine(LineBox line, boolean firstline) { - LineBox parent = getFlowContext().getCurrentLine(); - line._x = 0; - line._y = getFlowContext().getCurrentY(); - - line.setRecommendedWidth(parent.getAvailableWidth()); - - setLineVerticalAlign(line); - setFontinfoForLine(line); - - if (firstline && getCSSStyle() != null) { - ICSSStyle style = getCSSStyle(); - int minWidth = 0, minHeight = 0; - // try to see whether there is any designer specified min size - ITagEditInfo info = (ITagEditInfo) style - .getAdapter(ITagEditInfo.class); - if (info != null) { - minWidth = info.getMinWidth(); - minHeight = info.getMinHeight(); - } - - // // CSS also has the min-width/min-height property. We should also - // get that, - // // and using the max of the "min-width" css property and the - // designer specified min size. - // int height = - // getLengthValue(style,ICSSPropertyID.ATTR_MIN_HEIGHT); - // if(height > minHeight) - // { - // minHeight = height; - // } - // int width = getLengthValue(style,ICSSPropertyID.ATTR_MIN_WIDTH); - // if(width > minWidth) - // { - // minWidth = width; - // } - if (minWidth > 0) { - line.setWidth(minWidth); - } - int fontHeight = this.getCSSStyle().getCSSFont().getXHeight(); - if (minHeight > 0 && minHeight > fontHeight) { - line.setHeight(minHeight); - } else { - line.setHeight(fontHeight); - } - } - } - - private void setLineVerticalAlign(LineBox box) { - ICSSStyle style = getCSSStyle(); - if (style != null) { - box.setVerticalAlignData(style - .getStyleProperty(ICSSPropertyID.ATTR_VERTICAL_ALIGN)); - } - } - - private void setFontinfoForLine(LineBox line) { - - ICSSStyle style = getCSSStyle(); - if (style != null) { - line.setFontMetrics(FigureUtilities.getFontMetrics(style - .getCSSFont().getSwtFont())); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowFigureLayout#dispose() - */ - public void dispose() { - // - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.ICSSLayout#getFragmentsForRead() - */ - public List getFragmentsForRead() { - return _fragments; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.ICSSLayout#postValidate() - */ - public void postValidate() { - List list = _fragments; - - FlowBox box; - int left = Integer.MAX_VALUE, top = left; - int right = Integer.MIN_VALUE, bottom = right; - for (int i = 0; i < list.size(); i++) { - box = (FlowBox) list.get(i); - // if (box instanceof LineBox && !((LineBox) box).isOccupied()) - // { - // continue; // skip unoccupied line - // } - left = Math.min(left, box._x); - right = Math.max(right, box._x + box._width); - top = Math.min(top, box._y); - bottom = Math.max(bottom, box._y + box._height); - } - getCSSFigure().setBounds( - new Rectangle(left, top, right - left, bottom - top)); - list = getCSSFigure().getChildren(); - for (int i = 0; i < list.size(); i++) { - ((FlowFigure) list.get(i)).postValidate(); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContext#getContainerWidth() - */ - public int getContainerWidth() { - // FIXME: don't really understand what means for inline - return this.getFlowContext().getContainerWidth(); - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSLayout.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSLayout.java deleted file mode 100644 index 99081a798..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSLayout.java +++ /dev/null @@ -1,456 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import java.util.List; - -import org.eclipse.draw2d.Figure; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyID; -import org.eclipse.jst.pagedesigner.css2.property.PositionMeta; -import org.eclipse.jst.pagedesigner.css2.property.VerticalAlignMeta; -import org.eclipse.jst.pagedesigner.css2.value.Length; - -/** - * CSSLayout is the base layout manager for different CSS layouts, such as block - * layout, inline layout (possible in the future table layout, etc) - * - * @author mengbo - */ -public abstract class CSSLayout extends FlowFigureLayout implements FlowContext { - protected BlockFlowContext _absoluteContext; - - // when doing absolute layout, and if top/left are both "auto", it will be - // relating to the normaly flow position. The following two fields try to - // catch normal flow layout position. - // int _xForAbsolute; - // int _yForAbsolute; - private FlowBox _boxForAbsolute; - - /** - * the current line - */ - protected LineBox _currentLine; - - private boolean _calculatingMaxWidth = false; - - /** - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowFigureLayout#FlowFigureLayout(FlowFigure) - */ - protected CSSLayout(CSSFigure flowFigure) { - super(flowFigure); - } - - /** - * a shortcut method to get the style associated with the figure. - * - * @return - */ - public ICSSStyle getCSSStyle() { - return getCSSFigure().getCSSStyle(); - } - - /** - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContext#addToCurrentLine(FlowBox) - */ - public void addToCurrentLine(FlowBox block) { - getCurrentLine().add(block); - } - - /** - * Used by getCurrentLine(). - */ - protected abstract void createNewLine(); - - /** - * Used by getCurrentLine(int topmargin) - * - * @param topMargin - */ - protected void createNewLine(int topMargin) { - createNewLine(); - } - - /** - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContext#getCurrentLine() - */ - public LineBox getCurrentLine() { - if (_currentLine == null) { - createNewLine(); - } - return _currentLine; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContext#getCurrentLine(int) - */ - public LineBox getCurrentLine(int topMargin) { - if (_currentLine == null) { - createNewLine(topMargin); - } - // if the current line only contains an empty string, reset the current - // line using the given margin. - else if (_currentLine.isEmptyStringLine()) { - List list = _currentLine.getFragments(); - createNewLine(topMargin); - _currentLine._fragments.addAll(list); - } - return _currentLine; - } - - /** - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContext#isCurrentLineOccupied - */ - public boolean isCurrentLineOccupied() { - return _currentLine != null && _currentLine.isOccupied(); - } - - /** - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowFigureLayout#layout() - */ - protected void layout() { - preLayout(); - layoutChildren(); - flush(); - cleanup(); - } - - protected boolean isAbsolutePosition() { - ICSSStyle style = getCSSStyle(); - - // FIXME: Some layout don't support absolute, need check here - if (style != null) { - Object obj = style.getStyleProperty(ICSSPropertyID.ATTR_POSITION); - if (PositionMeta.ABSOLUTE.equals(obj) - || PositionMeta.FIXED.equals(obj)) { - return supportAbsolutePosition(); - } - } - return false; - } - - /** - * Child class could override this method. - * - * @return - */ - protected boolean supportAbsolutePosition() { - if (findContainingPositionedFigure() == null) { - return false; - } - return true; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContainerLayout#preLayout() - */ - protected void preLayout() { - ICSSStyle style = this.getCSSStyle(); - if (style != null) { - style.processCounters(); - } - - if (isAbsolutePosition()) { - FlowContext parentFigureContext = getParentFigureContext(); - _absoluteContext = new BlockFlowContext(parentFigureContext, style); - _boxForAbsolute = new FlowBox();// size is 0. Just as a flag, so - // later we - // could figure out where will this figure be - // be put in case of not absolute - _boxForAbsolute.setVerticalAlignData(VerticalAlignMeta.TOP); - parentFigureContext.addToCurrentLine(_boxForAbsolute); - } else { - _absoluteContext = null; - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowFigureLayout#getFlowContext() - */ - public FlowContext getFlowContext() { - if (_absoluteContext != null) { - return _absoluteContext; - } - return getOriginalFlowContext(); - } - - public FlowContext getParentFigureContext() { - return super.getFlowContext(); - } - - public void postValidateForAbsolute() { - if (_absoluteContext != null) { - ICSSStyle style = this.getCSSStyle(); - - _absoluteContext.endBlock(); - - int xOffset; - int yOffset; - - ICSSFigure containingPositionedFigure = findContainingPositionedFigure(); - IFigure parentFigure = this.getCSSFigure().getParent(); - - xOffset = calculatePositionRelativeToParent(style, - containingPositionedFigure, parentFigure, true); - yOffset = calculatePositionRelativeToParent(style, - containingPositionedFigure, parentFigure, false); - move(_absoluteContext._blockBox, xOffset, yOffset); - } - } - - /** - * @param style - * @param containingPositionedFigure - * @param parentFigure - * @return - */ - private int calculatePositionRelativeToParent(ICSSStyle style, - ICSSFigure containingPositionedFigure, IFigure parentFigure, - boolean horizontal) { - int xOffset; - Object left = horizontal ? style - .getStyleProperty(ICSSPropertyID.ATTR_LEFT) : style - .getStyleProperty(ICSSPropertyID.ATTR_TOP); - Object right = horizontal ? style - .getStyleProperty(ICSSPropertyID.ATTR_RIGHT) : style - .getStyleProperty(ICSSPropertyID.ATTR_BOTTOM); - - if (!(left instanceof Length) && !(right instanceof Length)) { - // _boxForAbsolute partipated the layout of the parent figure, and - // is already relative to parent. - return horizontal ? _boxForAbsolute._x : _boxForAbsolute._y; - } - - // ok, user specified left or right. let's calculate the left - int leftValue; - if (left instanceof Length) { - Length leftLength = (Length) left; - leftValue = leftLength.getValue(); - if (leftLength.isPercentage()) { - leftValue = (horizontal ? containingPositionedFigure - .getBounds().width : containingPositionedFigure - .getBounds().height) - * leftValue / 100; - } - } else { - Length rightLength = (Length) right; - int lengthValue = rightLength.getValue(); - if (rightLength.isPercentage()) { - lengthValue = (horizontal ? containingPositionedFigure - .getBounds().width : containingPositionedFigure - .getBounds().height) - * lengthValue / 100; - } - - if (horizontal) { - leftValue = containingPositionedFigure.getBounds().width - - _absoluteContext._blockBox.getWidth() - lengthValue; - } else { - leftValue = containingPositionedFigure.getBounds().height - - _absoluteContext._blockBox.getHeight() - lengthValue; - } - - } - - // xOffset is relative to the first box of the containing figure - List fragments = containingPositionedFigure - .getFragmentsForRead(); - if (fragments.size() > 0) { - FlowBox box = (FlowBox) fragments.get(0); - // box._x is the x location relative to containingPositionedFigure's - // parent. - // so now xOffset is relative to containingPositionedFigure's - // parent. - xOffset = (horizontal ? box._x : box._y) + leftValue; - } else { - xOffset = leftValue; // should not happen. - } - Point p; - if (horizontal) { - p = new Point(xOffset, 0); - } else { - p = new Point(0, xOffset); - } - containingPositionedFigure.translateFromParent(p); - containingPositionedFigure.translateToAbsolute(p); - parentFigure.translateToRelative(p); - return horizontal ? p.x : p.y; - } - - /** - * @return - */ - private ICSSFigure findContainingPositionedFigure() { - IFigure figure = this.getCSSFigure().getParent(); - while (figure instanceof ICSSFigure) { - return (ICSSFigure) figure; - // ICSSStyle style = ((ICSSFigure) figure).getCSSStyle(); - // if (DisplayToLayout.isPositioned(style)) - // { - // return (ICSSFigure) figure; - // } - // figure = figure.getParent(); - } - return null; - - } - - /** - * @param resultBox - * @param x - * @param y - */ - private void move(CompositeBox compBox, int x, int y) { - compBox._x += x; - compBox._y += y; - List list = compBox.getFragments(); - for (int i = 0; i < list.size(); i++) { - FlowBox box = (FlowBox) list.get(i); - - if (box instanceof CompositeBox && !(box instanceof BlockBox)) { - move((CompositeBox) box, x, y); - } else { - box._x += x; - box._y += y; - } - } - } - - /** - * Layout all children. - */ - protected void layoutChildren() { - List children = getFlowFigure().getChildren(); - for (int i = 0; i < children.size(); i++) { - Figure f = (Figure) children.get(i); - f.invalidate(); - f.validate(); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContext#getLastMarginRight() - */ - public int getLastMarginRight() { - if (_currentLine == null || !_currentLine.isOccupied()) { - return 0; - } - FlowBox box = (FlowBox) _currentLine.getFragments().get( - _currentLine.getFragments().size() - 1); - if (box != null) { - return box._marginInsets.right; - } - return 0; - } - - public void setCalculatingMaxWidth(boolean c) { - _calculatingMaxWidth = c; - } - - public boolean getCalcuatingMaxWidth() { - return _calculatingMaxWidth; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContext#isCalculatingMaxWidth() - */ - public boolean isCalculatingMaxWidth() { - if (_calculatingMaxWidth) { - return true; - } else if (this.getFlowContext() == null) { - return false; - } else { - return this.getFlowContext().isCalculatingMaxWidth(); - } - } - - /** - * Called after {@link #layoutChildren()}when all children have been laid - * out. This method exists to flush the last line. - */ - protected abstract void flush(); - - /** - * Flush anything pending and free all temporary data used during layout. - */ - protected abstract void cleanup(); - - // ------------------------------------------------------------------------------------ - - public CSSFigure getCSSFigure() { - return (CSSFigure) getFlowFigure(); - } - - /** - * - * @return - */ - public abstract List getFragmentsForRead(); - - /** - * postValidate the child figures of this CSSFigure. Normally layout fall - * into the first category need implement this method. - */ - public abstract void postValidate(); - - /** - * setBounds is called on the CSSFigure. Normally layout fall into the - * second category need implement this method. - * - * @param rect - * @param invalidate - */ - public void setBoundsCalled(Rectangle rect, boolean invalidate) { - // TODO: dead? - } - - /** - * Child class can override this. Normally block figure will return true. - * - * @return - */ - public boolean useLocalCoordinates() { - return false; - } - - /** - * If CSSLayout will call paint rountine to draw Border for its box, this - * method will return true, else return false, for example,the input file - * will return false. - * - * @return - */ - public boolean handlingBorderForBlock() { - return true; - } - - /** - * This method is called when the corresponding figure is revalidated. - * - */ - public void figureRevalidate() { - // child class can override. - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSListItemLayout.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSListItemLayout.java deleted file mode 100644 index a3608ddad..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSListItemLayout.java +++ /dev/null @@ -1,185 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import java.util.List; - -import org.eclipse.draw2d.FigureUtilities; -import org.eclipse.draw2d.Graphics; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.list.CounterHelper; -import org.eclipse.jst.pagedesigner.css2.list.ICounterValueGenerator; -import org.eclipse.jst.pagedesigner.css2.marker.CounterUtil; -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyID; -import org.eclipse.jst.pagedesigner.css2.style.DefaultStyle; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.swt.widgets.Display; - -/** - * @author mengbo - */ -public class CSSListItemLayout extends CSSBlockFlowLayout implements - ICSSPainter { - private static final String DEFAULT_LIST_COUNTER = "_anonymous"; - - private static final int CIRCLE_DIAMETER = 6; - - private static final int DISC_DIAMETER = 5; - - private static final int ROUNDRECT_ARC = 2; - - private static final int TEXT_PADDING = 16; - - private int _count; - - /** - * @param cssfigure - */ - public CSSListItemLayout(CSSFigure cssfigure) { - super(cssfigure); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.ICSSPainter#paintFigure(org.eclipse.draw2d.Graphics) - */ - public void paintFigure(Graphics g) { - ICSSStyle style = this.getCSSStyle(); - if (style == null) { - style = DefaultStyle.getInstance(); - } - - Rectangle drawArea = null; - Font font = getCSSStyle().getCSSFont().getSwtFont(); - - // draw the marker box - Object styleType = style - .getStyleProperty(ICSSPropertyID.ATTR_LIST_STYLE_TYPE); - - g.pushState(); - - Color newColor = null; - Object color = style.getColor(); - if (color instanceof Color) { - g.setForegroundColor((Color) color); - g.setBackgroundColor((Color) color); - } else if (color instanceof RGB) { - newColor = new Color(Display.getCurrent(), (RGB) color); - g.setForegroundColor(newColor); - g.setBackgroundColor(newColor); - } - - if (styleType instanceof String) { - int type = CounterHelper.toTypeInt((String) styleType); - switch (type) { - case CounterHelper.LIST_T_UPPER_ALPHA: - case CounterHelper.LIST_T_LOWER_ALPHA: - case CounterHelper.LIST_T_LOWER_ROMAN: - case CounterHelper.LIST_T_UPPER_ROMAN: - case CounterHelper.LIST_T_DECIMAL: - g.setFont(font); - String displayString = CounterUtil.convertCount(_count, type); - Point point = getDrawPointForText(displayString); - g.drawString(displayString, point); - break; - case CounterHelper.LIST_T_CIRCLE: - drawArea = getDrawAreaForGraph(CIRCLE_DIAMETER, CIRCLE_DIAMETER); - g.drawArc(drawArea, 0, 360); - break; - case CounterHelper.LIST_T_SQUARE: - drawArea = getDrawAreaForGraph(DISC_DIAMETER, DISC_DIAMETER); - g.fillRectangle(drawArea); - case CounterHelper.LIST_T_DECIMAL_LEADING_ZERO: - case CounterHelper.LIST_T_LOWER_GREEK: - case CounterHelper.LIST_T_ARMENIAN: - case CounterHelper.LIST_T_GEORGIAN: - case CounterHelper.LIST_T_IMAGE: - case CounterHelper.LIST_T_NONE: - default: - drawArea = getDrawAreaForGraph(DISC_DIAMETER, DISC_DIAMETER); - g.fillRoundRectangle(drawArea, ROUNDRECT_ARC, ROUNDRECT_ARC); - break; - } - } - g.popState(); - - if (newColor != null) { - newColor.dispose(); - } - } - - /** - * @param g - * @return - */ - private Rectangle getDrawAreaForGraph(int width, int height) { - Rectangle drawArea; - - int x = 0; - int y = 0; - - List list = _blockBox.getFragments(); - Rectangle box = _blockBox.toRectangle().getCopy().expand( - _blockBox.getBorderPaddingInsets().getAdded( - _blockBox._marginInsets)); - if (list != null && !list.isEmpty()) { - LineBox line = (LineBox) list.get(0); - y = line.getBaseline() - CIRCLE_DIAMETER; - x = box.x; - } else { - x = box.x; - y = box.height / 2 - CIRCLE_DIAMETER; - } - drawArea = new Rectangle(x - CIRCLE_DIAMETER * 5 / 2, y, width, height); - return drawArea; - } - - private Point getDrawPointForText(String displayString) { - Font font = getCSSStyle().getCSSFont().getSwtFont(); - - int x = 0; - int y = 0; - - Rectangle box = _blockBox.toRectangle().getCopy().expand( - _blockBox.getBorderPaddingInsets().getAdded( - _blockBox._marginInsets)); - - x = box.x - FigureUtilities.getTextWidth(displayString, font); - x = x - - (TEXT_PADDING - FigureUtilities.getFontMetrics(font) - .getDescent()); - - return new Point(x, y); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContainerLayout#layoutChildren() - */ - protected void layoutChildren() { - ICounterValueGenerator counter = this.getCSSStyle().findCounter( - DEFAULT_LIST_COUNTER, true); - if (counter != null) { - _count = counter.getCurrentCount(); - } else { - // should not happen. - _count = 1; // use 1 as the default value - } - super.layoutChildren(); - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSPageFlowLayout.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSPageFlowLayout.java deleted file mode 100644 index c74963a58..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSPageFlowLayout.java +++ /dev/null @@ -1,186 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import java.util.List; - -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.geometry.Dimension; -import org.eclipse.draw2d.geometry.Rectangle; - -/** - * This layout if for those thigns that it's parent will decide its size. Such - * as table cell. - * - * @author mengbo - * @version 1.5 - */ -public class CSSPageFlowLayout extends CSSBlockFlowLayout { - private Dimension _pageSize = new Dimension(); - - private int _recommendedWidth; - - private int _pageSizeCacheKeys[] = new int[4]; - - private Dimension _pageSizeCacheValues[] = new Dimension[4]; - - private Dimension _cacheMaxWidthSize = null; - - /** - * @param cssfigure - */ - public CSSPageFlowLayout(CSSFigure cssfigure) { - super(cssfigure); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowFigureLayout#invalidate() - */ - public void invalidate() { - super.invalidate(); - _pageSizeCacheKeys = new int[4]; - _pageSizeCacheValues = new Dimension[4]; - _pageSize = new Dimension(); - _recommendedWidth = 0; - _cacheMaxWidthSize = null; - } - - protected void endBlock() { - layoutLines(); - } - - /** - * TODO: This method is not being called. - */ - public void postValidate() { - Rectangle r = new Rectangle(_blockBox._x, _blockBox._y, _blockBox - .getWidth(), _blockBox.getHeight()); - r = r.expand(getCSSFigure().getInsets()); - _pageSize.width = r.width; - _pageSize.height = r.height; - - List list = getCSSFigure().getChildren(); - for (int i = 0; i < list.size(); i++) { - ((FlowFigure) list.get(i)).postValidate(); - } - - } - - /** - * Setup blockBox to the initial bounds of the Page - */ - protected void setupBlock() { - // Remove all current Fragments - _blockBox.clear(); - - // Setup the one fragment for this Block with the correct X and - // available width - int recommendedWidth = getRecommendedWidth(); - _blockBox.setRecommendedWidth(recommendedWidth); - - if (recommendedWidth > 0 && recommendedWidth != Integer.MAX_VALUE) { - _blockBox.setWidth(recommendedWidth); - } - - _blockBox._x = 0; - } - - public int getRecommendedWidth() { - return _recommendedWidth; - } - - private void setRecommendedWidth(int width) { - if (_recommendedWidth == width) { - return; - } - _recommendedWidth = width; - getCSSFigure().invalidate2(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.CSSLayout#setBoundsCalled(org.eclipse.jst.pagedesigner.css2.layout.CSSFigure, - * org.eclipse.draw2d.geometry.Rectangle, boolean) - */ - public void setBoundsCalled(Rectangle r, boolean invalidate) { - super.setBoundsCalled(r, invalidate); - CSSFigure figure = getCSSFigure(); - int newWidth = r.width - figure.getInsets().getWidth(); - if (invalidate || getRecommendedWidth() != newWidth) { - setRecommendedWidth(newWidth); - figure.getUpdateManager().addInvalidFigure(figure); - } - } - - /** - * @see org.eclipse.draw2d.Figure#getPreferredSize(int, int) - */ - public Dimension getPreferredSize(IFigure container, int width, int h) { - if (width >= 0) { - width = Math.max(0, width - container.getInsets().getWidth()); - } - - for (int i = 0; i < 4; i++) { - if (_pageSizeCacheKeys[i] == width - && _pageSizeCacheValues[i] != null) { - return _pageSizeCacheValues[i]; - } - } - - _pageSizeCacheKeys[3] = _pageSizeCacheKeys[2]; - _pageSizeCacheKeys[2] = _pageSizeCacheKeys[1]; - _pageSizeCacheKeys[1] = _pageSizeCacheKeys[0]; - _pageSizeCacheKeys[0] = width; - - _pageSizeCacheValues[3] = _pageSizeCacheValues[2]; - _pageSizeCacheValues[2] = _pageSizeCacheValues[1]; - _pageSizeCacheValues[1] = _pageSizeCacheValues[0]; - - // Flowpage must temporarily layout to determine its preferred size - int oldWidth = getRecommendedWidth(); - setRecommendedWidth(width); - container.validate(); - _pageSizeCacheValues[0] = _pageSize.getExpanded(container.getInsets() - .getWidth(), container.getInsets().getHeight()); - - if (width != oldWidth) { - setRecommendedWidth(oldWidth); - container.getUpdateManager().addInvalidFigure(container); - } - return _pageSizeCacheValues[0]; - } - - public Dimension getMaxContentWidthSize(IFigure container) { - if (this._cacheMaxWidthSize == null) { - boolean b = getCalcuatingMaxWidth(); - setCalculatingMaxWidth(true); - - // Flowpage must temporarily layout to determine its preferred size - int oldWidth = getRecommendedWidth(); - setRecommendedWidth(Integer.MAX_VALUE); - container.validate(); - _cacheMaxWidthSize = _pageSize.getExpanded(container.getInsets() - .getWidth(), container.getInsets().getHeight()); - - if (0 != oldWidth) { - setRecommendedWidth(oldWidth); - container.getUpdateManager().addInvalidFigure(container); - } - - setCalculatingMaxWidth(b); - } - return _cacheMaxWidthSize; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSTextFigure.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSTextFigure.java deleted file mode 100644 index 9994cbbe5..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSTextFigure.java +++ /dev/null @@ -1,299 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.draw2d.ColorConstants; -import org.eclipse.draw2d.Graphics; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyID; -import org.eclipse.jst.pagedesigner.css2.provider.ICSSTextProvider; -import org.eclipse.jst.pagedesigner.css2.style.DefaultStyle; -import org.eclipse.jst.pagedesigner.css2.style.StyleUtil; -import org.eclipse.jst.pagedesigner.viewer.CaretPositionResolver; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.RGB; - -/** - * @author mengbo - */ -public class CSSTextFigure extends FlowFigure implements ICSSFigure { - private ICSSTextProvider _provider; - - private List _fragments = new ArrayList(1); - - public CSSTextFigure(ICSSTextProvider provider) { - _provider = provider; - this.setLayoutManager(createDefaultFlowLayout()); - } - - public ICSSStyle getCSSStyle() { - IFigure parentFigure = this.getParent(); - if (parentFigure instanceof ICSSFigure) { - ICSSStyle style = ((ICSSFigure) parentFigure).getCSSStyle(); - if (style != null) { - return style; - } - } - return DefaultStyle.getInstance(); - } - - /** - * @see org.eclipse.draw2d.IFigure#containsPoint(int, int) - */ - public boolean containsPoint(int x, int y) { - if (!super.containsPoint(x, y)) { - return false; - } - List frags = getFragments(); - for (int i = 0, n = frags.size(); i < n; i++) { - if (((FlowBox) frags.get(i)).containsPoint(x, y)) { - return true; - } - } - return false; - } - - /** - * @see FlowFigure#createDefaultFlowLayout() - */ - protected FlowFigureLayout createDefaultFlowLayout() { - return new CSSTextLayout(this); - } - - /** - * Returns the <code>LineBox</code> fragments contained in this InlineFlow - * - * @return The fragments - */ - public List getFragments() { - return _fragments; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.ICSSFigure#getFragmentsForRead() - */ - public List getFragmentsForRead() { - return getFragments(); - } - - public String getText() { - return _provider.getTextData(); - } - - /** - * @see FlowFigure#postValidate() - */ - public void postValidate() { - List list = getFragments(); - FlowBox box; - int left = Integer.MAX_VALUE, top = left; - int right = Integer.MIN_VALUE, bottom = right; - for (int i = 0, n = list.size(); i < n; i++) { - box = (FlowBox) list.get(i); - left = Math.min(left, box._x); - right = Math.max(right, box._x + box._width); - top = Math.min(top, box._y); - bottom = Math.max(bottom, box._y + box._height); - } - setBounds(new Rectangle(left, top, right - left, bottom - top)); - list = getChildren(); - for (int i = 0, n = list.size(); i < n; i++) { - ((FlowFigure) list.get(i)).postValidate(); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.draw2d.Figure#paintBorder(org.eclipse.draw2d.Graphics) - */ - protected void paintBorder(Graphics graphics) { - if (Debug.DEBUG_TEXTBORDER) { - if (_fragments != null) { - graphics.setForegroundColor(ColorConstants.darkBlue); - for (int i = 0, size = _fragments.size(); i < size; i++) { - FlowBox box = (FlowBox) _fragments.get(i); - BoxUtil.drawBox(graphics, box); - } - graphics.restoreState(); - } - } - } - - /** - * @see org.eclipse.draw2d.Figure#paintFigure(Graphics) - */ - protected void paintFigure(Graphics g) { - Object result = this.getCSSStyle().getColor(); - Color color; - if (result instanceof Color) { - color = (Color) result; - } else if (result instanceof RGB) { - color = new Color(null, (RGB) result); - } else { - color = null; - } - int[] range = null; - if (!StyleUtil.isInWidget(this.getCSSStyle())) { - range = _provider.getSelectedRange(); - } - if (range == null || range[0] == range[1]) { - // we are not in selection - TextLayoutSupport.paintTextFigure(g, _fragments, getCSSStyle() - .getCSSFont().getSwtFont(), color, ((Integer) getCSSStyle() - .getStyleProperty(ICSSPropertyID.ATTR_TEXTDECORATION)) - .intValue()); - } else { - TextLayoutSupport.paintTextFigureWithSelection(g, _fragments, - _provider.getTextData(), getCSSStyle().getCSSFont() - .getSwtFont(), color, ((Integer) getCSSStyle() - .getStyleProperty( - ICSSPropertyID.ATTR_TEXTDECORATION)) - .intValue(), range[0], range[1], - ColorConstants.white, ColorConstants.blue); - } - if (color != result && color != null) { - color.dispose(); - } - } - - /** - * Find out lines which has closer y coordinate to point, and then line - * which has closer x coordinate. - * - * @param relative - * @return - */ - // TODO: refactoring? - public int getNewInsertionOffset(Point relative) { - TextFragmentBox closestBox = null; - // if there is one which are at the same line with relative, calculate - // that line first; - for (int i = 0, n = _fragments.size(); i < n; i++) { - TextFragmentBox box = (TextFragmentBox) _fragments.get(i); - if (box.containsPoint(relative.x, relative.y)) { - int index = FlowUtilities.getTextInWidth(box.getTextData(), - getCSSStyle().getCSSFont().getSwtFont(), relative.x - - box._x, TextLayoutSupport - .getAverageCharWidth(box)); - return box._offset + index; - } - if (closestBox == null) { - closestBox = box; - } else { - // box is above point - TextFragmentBox tempBox = box; - int offset1 = Math - .abs(CaretPositionResolver.getYDistance( - new Rectangle(tempBox._x, tempBox._y, - tempBox._width, tempBox._height), - relative)); - tempBox = closestBox; - int offset2 = Math - .abs(CaretPositionResolver.getYDistance( - new Rectangle(tempBox._x, tempBox._y, - tempBox._width, tempBox._height), - relative)); - if (offset1 < offset2) { - closestBox = box; - } - } - // at the same line - if (box.containsPoint(box._x, relative.y)) { - TextFragmentBox tempBox = box; - int offset1 = Math - .abs(CaretPositionResolver.getXDistance( - new Rectangle(tempBox._x, tempBox._y, - tempBox._width, tempBox._height), - relative)); - tempBox = closestBox; - int offset2 = Math - .abs(CaretPositionResolver.getXDistance( - new Rectangle(tempBox._x, tempBox._y, - tempBox._width, tempBox._height), - relative)); - if (offset1 < offset2) { - closestBox = box; - } - } - } - - if (closestBox.containsPoint(closestBox._x, relative.y) - || closestBox.containsPoint(relative.x, closestBox._y)) { - int offset = relative.x - closestBox._x; - int index = FlowUtilities.getTextInWidth(closestBox.getTextData(), - getCSSStyle().getCSSFont().getSwtFont(), offset, - TextLayoutSupport.getAverageCharWidth(closestBox)); - return closestBox._offset + index; - } - return -1; - } - - public int getInsertionOffset(Point relative) { - for (int i = 0, n = _fragments.size(); i < n; i++) { - TextFragmentBox box = (TextFragmentBox) _fragments.get(i); - if (box.containsPoint(relative.x, relative.y)) { - int index = FlowUtilities.getTextInWidth(box.getTextData(), - getCSSStyle().getCSSFont().getSwtFont(), relative.x - - box._x, TextLayoutSupport - .getAverageCharWidth(box)); - return box._offset + index; - } - } - return -1; - } - - /** - * the returned rectangle will be relative to this text figure. - * - * @param offset - * @return - */ - public Rectangle calculateCaretPosition(int offset) { - // search reverse order, find the latest box that has _offset small than - // the specified one - if (offset > 0) { - for (int i = _fragments.size() - 1; i >= 0; i--) { - TextFragmentBox box = (TextFragmentBox) _fragments.get(i); - if (box._offset <= offset) { - // ok, we find the box. - if (box._offset + box._length < offset) { - return new Rectangle(box._x + box._width, box._y, 1, - box._height); - } - String s = box.getTextData().substring(0, - offset - box._offset); - int width = FlowUtilities.getTextExtents(s, - getCSSStyle().getCSSFont().getSwtFont()).width; - return new Rectangle(box._x + width, box._y, 1, - box._height); - } - } - } else { - if (_fragments.size() > 0) { - TextFragmentBox box = (TextFragmentBox) _fragments.get(0); - return new Rectangle(box._x, box._y, 1, box._height); - } - } - // should only reach here when there is no fragments. - return new Rectangle(getBounds().x, getBounds().y, 1, getBounds().height); - } - -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSTextLayout.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSTextLayout.java deleted file mode 100644 index d452e0dc2..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSTextLayout.java +++ /dev/null @@ -1,177 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import java.util.List; - -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyID; -import org.eclipse.swt.graphics.Font; - -/** - * @author mengbo - */ -// NOTE: CSSTextLayout does not extends CSSFlowLayout. Since text is a little -// special, -// we don't want to do things like "preLayout()" as in CSSFlowLayout. -public class CSSTextLayout extends FlowFigureLayout { - /** - * Wrapping will ONLY occur at valid line breaks - */ - public static final int WORD_WRAP_HARD = 0; - - /** - * Wrapping will always occur at the end of the available space, breaking in - * the middle of a word. - */ - public static final int WORD_WRAP_SOFT = 1; - - /** - * Wrapping will always occur at the end of available space, truncating a - * word if it doesn't fit. - */ - // don't support this flag - // public static final int WORD_WRAP_TRUNCATE = 2; - private int _wrappingStyle = WORD_WRAP_HARD; - - public CSSTextLayout(CSSTextFigure textfigure) { - super(textfigure); - } - - // -------------------------------------------------------------------------------------------------- - FlowBox findLastNonLineBox(LineBox box) { - List fragments = box.getFragments(); - for (int i = fragments.size() - 1; i >= 0; i--) { - FlowBox item = (FlowBox) fragments.get(i); - if (item instanceof LineBox) { - FlowBox found = findLastNonLineBox((LineBox) item); - if (found != null) { - return found; - } - } else { - return item; - } - } - return null; - } - - // boolean isElementContentWhitespaceEnding() - // { - // if (!this._context.isCurrentLineOccupied()) - // return true; - // LineBox line = this._context.getCurrentLine(); - // FlowBox lastNoneLinebox = findLastNonLineBox(line); - // if (lastNoneLinebox instanceof TextFragmentBox) - // return ((TextFragmentBox) lastNoneLinebox)._isLastCharWhitespace; - // else - // return true; - // } - // - // String normalize(String text) - // { - // text = EntityMap.translateAndCompact(text); - // if (text.length() > 0 && - // Character.isElementContentWhitespace(text.charAt(0)) && - // isElementContentWhitespaceEnding()) - // return text.substring(1); - // else - // return text; - // } - - private void layoutEmptyString(List fragments, Font font) { - // empty node! we want to create a fake fragment, so things can be - // consistent - // that all the CSSTextFigure will have something inside, also in this - // way, even - // empty text node will have a position, thus we can support showing - // caret associated - // with this text figure. - fragments.clear(); - TextFragmentBox box = TextLayoutSupport.getFragment(0, fragments); - box._length = 0; - box._offset = 0; - box._height = 0; - box._width = 0; - box.setTextData(""); - - // {following comments deprecated XXX: If is empty string, we only want - // to this figure to have a size, but don't - // want to it to be added into current line. Otherwise, a line with only - // a empty string - // will also take a line's space.} - - // please reference LineBox.isOccupied() - // now we treat a line with only an empty text as not occupied. - getFlowContext().getCurrentLine().add(box); - } - - /** - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowFigureLayout#layout() - */ - protected void layout() { - CSSTextFigure flowFigure = (CSSTextFigure) getFlowFigure(); - - List fragments = flowFigure.getFragments();// Reuse the previous List - // of fragments - String text = flowFigure.getText(); - Font font = flowFigure.getCSSStyle().getCSSFont().getSwtFont(); - Object whitespace = flowFigure.getCSSStyle().getStyleProperty( - ICSSPropertyID.ATTR_WHITESPACE); - - if (whitespace == ICSSPropertyID.VAL_PRE) { - if (text == null || text.length() == 0) - layoutEmptyString(fragments, font); - else - TextLayoutSupport.layoutNoWrap(getFlowContext(), text, - fragments, font); - } else if (whitespace == ICSSPropertyID.VAL_NOWRAP) { - if (text == null || text.length() == 0) - layoutEmptyString(fragments, font); - else - TextLayoutSupport.layoutNoWrap(getFlowContext(), text, - fragments, font); - } else { - if (text == null || text.length() == 0) - layoutEmptyString(fragments, font); - else { - boolean trimLeadingChar = (text.charAt(0) == ' ' && shouldTrimLeadingWhitespace(getFlowContext())); - TextLayoutSupport.layoutNormal(getFlowContext(), text, - fragments, font, _wrappingStyle, trimLeadingChar); - } - } - } - - // XXX: maybe should move to TextSupport later. - public boolean shouldTrimLeadingWhitespace(FlowContext context) { - if (!context.isCurrentLineOccupied()) { - return true; - } - while (context instanceof CSSInlineFlowLayout) { - context = ((CSSInlineFlowLayout) context).getFlowContext(); - } - LineBox line = context.getCurrentLine(); - if (line == null || !line.isOccupied()) { - return true; - } - FlowBox lastNoneLinebox = findLastNonLineBox(line); - if (lastNoneLinebox == null || lastNoneLinebox.getWidth() == 0) { - return true; - } else if (lastNoneLinebox instanceof TextFragmentBox) { - return ((TextFragmentBox) lastNoneLinebox)._isLastCharWhitespace; - } else { - return false; - } - } - - public void dispose() { - // TODO: anything to dispose? - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSWidgetLayout.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSWidgetLayout.java deleted file mode 100644 index ef573ee78..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CSSWidgetLayout.java +++ /dev/null @@ -1,221 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import org.eclipse.draw2d.Graphics; -import org.eclipse.draw2d.geometry.Dimension; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.jst.pagedesigner.css2.provider.DimensionInfo; -import org.eclipse.jst.pagedesigner.css2.provider.ICSSWidgetProvider; - -/** - * @author mengbo - */ -public class CSSWidgetLayout extends CSSBlockFlowLayout implements ICSSPainter { - private WidgetBox _widgetBox; - - private ICSSWidgetProvider _provider; - - /** - * @param flowfigure - */ - public CSSWidgetLayout(CSSFigure flowfigure, ICSSWidgetProvider provider) { - super(flowfigure); - _provider = provider; - } - - /** - * normally this method is called directly after constructor - * - * @param provider - */ - public void setProvider(ICSSWidgetProvider provider) { - _provider = provider; - } - - public ICSSWidgetProvider getProvider() { - // return ((CSSWidgetFigure)this.getFlowFigure()).getProvider(); - return _provider; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.CSSBlockFlowLayout#isInlineBlock() - */ - public boolean isInlineBlock() { - ICSSWidgetProvider provider = getProvider(); - return provider.isInline(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowFigureLayout#layout() - */ - protected void layoutChildren() { - ICSSWidgetProvider provider = getProvider(); - - // if we did endLine, then will result in context create a new line, so - // we may in the new line now. - // passing in the top margin, and context will consider that when - // creating the new line. - - int suggestedWith = _blockBox.getContentWidth(); - int suggestedHeight = _blockBox.getContentHeight(); - // int suggestedWith = getSuggestedWidth(line, style, provider); - // int suggestedHeight = getSuggestedHeight(line, style, provider); - - DimensionInfo resultInfo = provider.getPreferredDimension( - suggestedWith, suggestedHeight); - Dimension resultSize = resultInfo.getDimension(); - - _widgetBox = new WidgetBox(); // ((CSSWidgetFigure)getFlowFigure()).getWidgetBox(); - // if (provider.isHandlingBorder() || style == null) - // { - _widgetBox.setWidth(resultSize.width); - _widgetBox.setHeight(resultSize.height); - _widgetBox.setAscent(resultInfo.getAscent()); - // } - // else - // { - // widgetBox.setWidth(resultSize.width + - // style.getBorderInsets().getWidth()); - // widgetBox.setHeight(resultSize.height + - // style.getBorderInsets().getHeight()); - // widgetBox.setAscent(resultInfo.getAscent()+style.getBorderInsets().top); - // } - this.addToCurrentLine(_widgetBox); - // if (!provider.isInline()) - // { - // context.endLine(); - // } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowFigureLayout#dispose() - */ - public void dispose() { - // TODO: anything to dispose? - } - - // public int getSuggestedWidth(LineBox line, ICSSStyle style, - // ICSSWidgetProvider provider) - // { - // if (style == null) return -1; - // - // Object width = style.getStyleProperty(ICSSPropertyID.ATTR_WIDTH); - // Length recommendedWidth = (width instanceof Length) ? (Length) width : - // null; - // - // int rw = 0; - // if (recommendedWidth == null || recommendedWidth.getValue() <= 0) - // { - // return -1; - // } - // else - // { - // if (recommendedWidth.isPercentage()) - // { - // rw = line.getAvailableWidth() * recommendedWidth.getValue() / 100; - // } - // else - // { - // rw = recommendedWidth.getValue(); - // } - // - // if (!style.isSizeIncludeBorderPadding() && provider.isHandlingBorder()) - // { - // rw += style.getBorderInsets().getWidth() + - // style.getPaddingInsets().getWidth(); - // } - // else if (style.isSizeIncludeBorderPadding() && - // !provider.isHandlingBorder()) - // { - // rw -= style.getBorderInsets().getWidth() + - // style.getPaddingInsets().getWidth(); - // } - // } - // - // return rw; - // } - // - // public int getSuggestedHeight(LineBox line, ICSSStyle style, - // ICSSWidgetProvider provider) - // { - // if (style == null) return -1; - // - // Object height = style.getStyleProperty(ICSSPropertyID.ATTR_HEIGHT); - // Length recommendedHeight = (height instanceof Length) ? (Length) height : - // null; - // - // int rh = 0; - // if (recommendedHeight == null || recommendedHeight.getValue() <= 0) - // { - // return -1; - // } - // else - // { - // if (recommendedHeight.isPercentage()) - // { - // // we don't support percentage height for this version, ignore - // return -1; - // } - // else - // { - // rh = recommendedHeight.getValue(); - // } - // - // if (!style.isSizeIncludeBorderPadding() && provider.isHandlingBorder()) - // { - // rh += style.getBorderInsets().getHeight() + - // style.getPaddingInsets().getHeight(); - // } - // else if (style.isSizeIncludeBorderPadding() && - // !provider.isHandlingBorder()) - // { - // rh -= style.getBorderInsets().getHeight() + - // style.getPaddingInsets().getHeight(); - // } - // } - // - // return rh; - // } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.ICSSPainter#paintFigure(org.eclipse.draw2d.Graphics) - */ - public void paintFigure(Graphics g) { - ICSSWidgetProvider provider = this.getProvider(); - if (provider != null && _widgetBox != null) { - provider.paintFigure(g, new Rectangle(_widgetBox._x, _widgetBox._y, - _widgetBox.getWidth(), _widgetBox.getHeight())); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.CSSLayout#handlingBorderForBlock() - */ - public boolean handlingBorderForBlock() { - ICSSWidgetProvider provider = this.getProvider(); - if (provider != null) { - return provider.isHandlingBorder(); - } - return super.handlingBorderForBlock(); - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CompositeBox.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CompositeBox.java deleted file mode 100644 index 6cce9545a..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/CompositeBox.java +++ /dev/null @@ -1,148 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import java.util.ArrayList; -import java.util.List; - -/** - * A FlowBox that can contain other BlockInfos. The contained BlockInfos are - * called <i>fragments </i>. - * - * @author mengbo - * @since 2.1 - */ -public abstract class CompositeBox extends FlowBox { - - /** - * The contained fragments. - */ - protected List _fragments = new ArrayList(); - - int _recommendedWidth; - - int _recommendedHeight; - - /** - * Adds the specified FlowBox. Updates the width, height, and ascent - * properties. - * - * @param block - * the FlowBox being added - */ - public void add(FlowBox block) { - // The order is critical.see the first "if" block in the unionInfo() - // method. - unionInfo(block); - _fragments.add(block); - } - - /** - * Removes all owned fragments and invalidates this CompositeBox. - */ - public void clear() { - _fragments.clear(); - resetInfo(); - } - - /** - * Overridden to ensure that the CompositeBox is valid. - * - * @see FlowBox#getBounds() - */ - // public Rectangle getBounds() { - // validate(); - // return this; - // } - /** - * @return the List of fragments - */ - public List getFragments() { - return _fragments; - } - - /** - * Returns the recommended width for this CompositeBox. - * - * @return the recommended width - */ - public int getRecommendedWidth() { - return _recommendedWidth; - } - - /** - * Returns the recommended height for this compositebox. - * - * @return - */ - public int getRecommendedHeight() { - return _recommendedHeight; - } - - // public int getInnerTop() { - // validate(); - // return y; - // } - - /** - * resets fields before unioning the data from the fragments. - */ - protected void resetInfo() { - _width = _height = 0; - } - - /** - * Sets the recommended width for this CompositeBox. - * - * @param w - * the width - */ - public void setRecommendedWidth(int w) { - _recommendedWidth = w; - } - - public void setRecommendedHeight(int h) { - _recommendedHeight = h; - } - - /** - * unions the fragment's width, height, and ascent into this composite. - * - * @param box - * the fragment - */ - protected void unionInfo(FlowBox box) { - int right = Math.max(_x + _width, box._x + box._width); - int bottom = Math.max(_y + _height, box._y + box._height); - _x = Math.min(_x, box._x); - _y = Math.min(_y, box._y); - _width = right - _x; - _height = bottom - _y; - } - - public int getContentWidth() { - return getWidth() - getBorderPaddingWidth(); - } - - public int getContentHeight() { - return getHeight() - getBorderPaddingHeight(); - } - - public int getRecommendedContentWidth() { - return Math.max(0, getRecommendedWidth() - getBorderPaddingWidth()); - } - // - // public int getRecommendedContentHeight() - // { - // return Math.max(0, getRecommendedHeight() - getBorderPaddingHeight()); - // } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/Debug.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/Debug.java deleted file mode 100644 index c15f21da0..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/Debug.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -/** - * Debug constants. - * - * @author mengbo - * @version 1.5 - */ -public class Debug { - public static final boolean DEBUG_BASELINE = false; - - public static final boolean DEBUG_BOX = false; - - public static final boolean DEBUG_BORDERPADDING = false; - - public static final boolean DEBUG_TEXTBORDER = false; -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/DisplayToLayout.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/DisplayToLayout.java deleted file mode 100644 index d67849b11..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/DisplayToLayout.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import org.eclipse.draw2d.LayoutManager; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.layout.table.CSSTRGroupLayout; -import org.eclipse.jst.pagedesigner.css2.layout.table.CSSTRLayout; -import org.eclipse.jst.pagedesigner.css2.layout.table.CSSTableCaptionLayout; -import org.eclipse.jst.pagedesigner.css2.layout.table.CSSTableCellLayout; -import org.eclipse.jst.pagedesigner.css2.layout.table.CSSTableLayout2; -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyID; -import org.eclipse.jst.pagedesigner.css2.property.PositionMeta; - -/** - * @author mengbo - */ -public class DisplayToLayout { - /** - * @param figure - * @param display - * @param old - * @return - */ - public static CSSLayout displayToLayout(CSSFigure figure, String display, - LayoutManager old) { - if ("block".equalsIgnoreCase(display)) //$NON-NLS-1$ - { - return new CSSBlockFlowLayout(figure); - } else if ("inline".equalsIgnoreCase(display)) //$NON-NLS-1$ - { - return new CSSInlineFlowLayout(figure); - } else if ("table".equalsIgnoreCase(display) || "inline-table".equalsIgnoreCase(display)) //$NON-NLS-1$ $NON-NLS-2$ - { - return new CSSTableLayout2(figure); - } else if ("table-row".equalsIgnoreCase(display)) //$NON-NLS-1$ - { - return new CSSTRLayout(figure); - } else if ("table-row-group".equalsIgnoreCase(display) //$NON-NLS-1$ - || "table-header-group".equalsIgnoreCase(display) //$NON-NLS-1$ - || "table-footer-group".equalsIgnoreCase(display)) //$NON-NLS-1$ - { - return new CSSTRGroupLayout(figure); - } else if ("table-cell".equalsIgnoreCase(display)) //$NON-NLS-1$ - { - return new CSSTableCellLayout(figure); - } else if (display.equalsIgnoreCase("table-caption")) //$NON-NLS-1$ - { - return new CSSTableCaptionLayout(figure); - } else if ("inline-block".equalsIgnoreCase(display)) //$NON-NLS-1$ - { - return new CSSBlockFlowLayout(figure) { - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.CSSBlockFlowLayout#isInlineBlock() - */ - public boolean isInlineBlock() { - return true; - } - }; - } else if (ICSSPropertyID.VAL_LIST_ITEM.equalsIgnoreCase(display)) { - return new CSSListItemLayout(figure); - } - return null; - } - - /** - * @param figure - * @param display - * @param old - * @return - */ - public static boolean isInline(String display) { - return "inline".equalsIgnoreCase(display) //$NON-NLS-1$ - || "inline-block".equalsIgnoreCase(display); //$NON-NLS-1$ - } - - /** - * @param style - * @return - */ - public static boolean isPositioned(ICSSStyle style) { - Object position = style.getStyleProperty(ICSSPropertyID.ATTR_POSITION); - if (PositionMeta.STATIC.equalsIgnoreCase((String) position)) { - return false; - } - return true; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/FigureUtil.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/FigureUtil.java deleted file mode 100644 index 60e3f6fcb..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/FigureUtil.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.geometry.Translatable; - -/** - * @author mengbo - * @version 1.5 - */ -public class FigureUtil { - // XXX: - // seemed Figure.translateToRelative is bug? - public static final void translateToRelative(IFigure figure, Translatable t) { - if (figure.getParent() != null) { - translateToRelative(figure.getParent(), t); - // figure.getParent().translateToRelative(t); - figure.translateFromParent(t); - } - } - - // XXX: - // seemed Figure.translateToAbsolute is bug? - public static final void translateToAbsolute(IFigure figure, Translatable t) { - if (figure.getParent() != null) { - figure.translateToParent(t); - translateToAbsolute(figure.getParent(), t); - // figure.getParent().translateToAbsolute(t); - } - - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/FlowBox.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/FlowBox.java deleted file mode 100644 index 149fbd9a4..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/FlowBox.java +++ /dev/null @@ -1,161 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import org.eclipse.draw2d.geometry.Insets; -import org.eclipse.draw2d.geometry.Rectangle; - -/** - * This class represents the CSS box model. See chapter 8 of CSS2 spec. - * - * @see http://www.w3.org/TR/REC-CSS2/box.html - */ -public class FlowBox { - private Object _verticalAlignData = null; - - /** - * The x location - */ - public int _x; - - /** - * The y location - */ - public int _y; - - int _width; - - int _height; - - public Insets _marginInsets = new Insets(); - - public Insets _borderInsets = new Insets(); - - public Insets _paddingInsets = new Insets(); - - /** - * This method must be called on a block that is completely positioned and - * committed. - * - * @param x - * X - * @param y - * Y - * @return <code>true</code> if the FlowBox contains the point - */ - public boolean containsPoint(int x, int y) { - return x >= this._x && y >= this._y && x < this._x + this._width - && y < this._y + this._height; - } - - /** - * By default, a FlowBox is all ascent, and no descent, so the height is - * returned. - * - * @return the <i>ascent </i> in pixels above the baseline - */ - public int getAscent() { - return getHeight(); - } - - /** - * By default, a simple FlowBox is all ascent, and no descent. Zero is - * returned. - * - * @return the <i>descent </i> in pixels below the baseline - */ - public final int getDescent() { - return getHeight() - getAscent(); - } - - /** - * Returns the height - * - * @return height - */ - public int getHeight() { - return _height; - } - - /** - * Returns the width - * - * @return width - */ - public int getWidth() { - return _width; - } - - public void setWidth(int w) { - _width = w; - } - - public void setHeight(int h) { - _height = h; - } - - /** - * Used to set the baseline of this FlowBox to the specified value. - * - * @param value - * the new baseline - */ - public void makeBaseline(int value) { - _y = (value - getAscent()); - } - - public int getBorderPaddingWidth() { - return _borderInsets.getWidth() + _paddingInsets.getWidth(); - } - - /** - * @return - */ - public int getBorderPaddingHeight() { - return _borderInsets.getHeight() + _paddingInsets.getHeight(); - } - - /** - * @return - */ - public Insets getBorderPaddingInsets() { - Insets temp = new Insets(_borderInsets); - return temp.add(_paddingInsets); - } - - public void setXYWidthHeight(Rectangle rect) { - this._x = rect.x; - this._y = rect.y; - this.setWidth(rect.width); - this.setHeight(rect.height); - } - - /** - * @return Returns the _verticalAlignData. - */ - public Object getVerticalAlignData() { - return _verticalAlignData; - } - - /** - * @param alignData - * The _verticalAlignData to set. - */ - public void setVerticalAlignData(Object alignData) { - _verticalAlignData = alignData; - } - - public Rectangle getRectangle() { - return new Rectangle(this._x, this._y, this.getWidth(), this - .getHeight()); - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/FlowContainerLayout.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/FlowContainerLayout.java deleted file mode 100644 index aa17d120a..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/FlowContainerLayout.java +++ /dev/null @@ -1,177 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import java.util.List; - -import org.eclipse.draw2d.Figure; - -/** - * A layout for FlowFigures with children. - * <P> - * WARNING: This class is not intended to be subclassed by clients. - * - * @author mengbo - * @since 2.1 - */ -public abstract class FlowContainerLayout extends FlowFigureLayout implements - FlowContext { -// private static Logger _log = PDPlugin.getLogger(FlowContainerLayout.class); - - /** - * the current line - */ - protected LineBox _currentLine; - - private boolean _calculatingMaxWidth = false; - - /** - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowFigureLayout#FlowFigureLayout(FlowFigure) - */ - protected FlowContainerLayout(FlowFigure flowFigure) { - super(flowFigure); - } - - /** - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContext#addToCurrentLine(FlowBox) - */ - public void addToCurrentLine(FlowBox block) { - getCurrentLine().add(block); - } - - /** - * Used by getCurrentLine(). - */ - protected abstract void createNewLine(); - - /** - * Used by getCurrentLine(int topmargin) - * - * @param topMargin - */ - protected void createNewLine(int topMargin) { - createNewLine(); - } - - /** - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContext#getCurrentLine() - */ - public LineBox getCurrentLine() { - if (_currentLine == null) - createNewLine(); - return _currentLine; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContext#getCurrentLine(int) - */ - public LineBox getCurrentLine(int topMargin) { - if (_currentLine == null) { - createNewLine(topMargin); - } - // if the current line only contains an empty string, reset the current - // line using the given margin. - else if (_currentLine.isEmptyStringLine()) { - List list = _currentLine.getFragments(); - createNewLine(topMargin); - _currentLine._fragments.addAll(list); - } - return _currentLine; - } - - /** - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContext#isCurrentLineOccupied - */ - public boolean isCurrentLineOccupied() { - return _currentLine != null && _currentLine.isOccupied(); - } - - /** - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowFigureLayout#layout() - */ - protected void layout() { - preLayout(); - layoutChildren(); - flush(); - cleanup(); - } - - /** - * Layout all children. - */ - protected void layoutChildren() { - List children = getFlowFigure().getChildren(); - for (int i = 0; i < children.size(); i++) { - Figure f = (Figure) children.get(i); - f.invalidate(); - f.validate(); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContext#getLastMarginRight() - */ - public int getLastMarginRight() { - if (_currentLine == null || !_currentLine.isOccupied()) { - return 0; - } - FlowBox box = (FlowBox) _currentLine.getFragments().get( - _currentLine.getFragments().size() - 1); - if (box != null) { - return box._marginInsets.right; - } - return 0; - } - - public void setCalculatingMaxWidth(boolean c) { - _calculatingMaxWidth = c; - } - - public boolean getCalcuatingMaxWidth() { - return _calculatingMaxWidth; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowContext#isCalculatingMaxWidth() - */ - public boolean isCalculatingMaxWidth() { - if (_calculatingMaxWidth) { - return true; - } else if (this.getFlowContext() == null) { - return false; - } else { - return this.getFlowContext().isCalculatingMaxWidth(); - } - } - - /** - * Called before layoutChildren() to setup any necessary state. - */ - protected abstract void preLayout(); - - /** - * Called after {@link #layoutChildren()}when all children have been laid - * out. This method exists to flush the last line. - */ - protected abstract void flush(); - - /** - * Flush anything pending and free all temporary data used during layout. - */ - protected abstract void cleanup(); -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/FlowContext.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/FlowContext.java deleted file mode 100644 index dbca0dd53..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/FlowContext.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -/** - * Copied from draw2d. Enhanced to meet page designer's needs. The context that - * a {@link FlowFigureLayout}uses to perform its layout. - * <P> - * WARNING: This interface is not intended to be implemented by clients. It - * exists to define the API between the layout and its context. - */ -public interface FlowContext { - - /** - * Adds the given box into the current line. - * - * @param box - * the FlowBox to add - */ - void addToCurrentLine(FlowBox box); - - /** - * The current line should be committed if it is occupied, and then set to - * <code>null</code>. Otherwise, do nothing. - */ - void endLine(); - - /** - * Obtains the current line, creating a new line if there is no current - * line. if create a new line, the new line's x will be set correctly - * without considering the new element's left margin. Also, if create new - * line, it will treat as the new line's top margin is 0. - * - * @return the current line - */ - LineBox getCurrentLine(); - - /** - * if create a new line, the new line's x will be set correctly without - * considering the new element's left margin. - * - * @param topMargin - * @return - */ - LineBox getCurrentLine(int topMargin); - - /** - * Returns the current Y value. - * - * @return the current Y value - */ - int getCurrentY(); - - /** - * @return <code>true</code> if the current line contains any fragments - */ - boolean isCurrentLineOccupied(); - - /** - * @return - */ - int getLastMarginRight(); - - /** - * when layout table, we need to calculate max width of a cell. This is done - * by don't break line (other than explicit required). Currently, the - * solution is to make the recommended width to be very big, and when create - * block element we don't set the block element's size to be recommended - * width. Please see CSSBlockFlowLayout - * - * @return - */ - boolean isCalculatingMaxWidth(); - - /** - * when calculating percentage width, we need the container width - * - * @return - */ - int getContainerWidth(); -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/FlowFigure.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/FlowFigure.java deleted file mode 100644 index e231a6f76..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/FlowFigure.java +++ /dev/null @@ -1,191 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import java.util.List; - -import org.eclipse.draw2d.Figure; -import org.eclipse.draw2d.Graphics; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.geometry.Rectangle; - -/** - * The base implementation for text flow figures. A flow figure is used to - * render a document in which elements are laid out horizontally within a "line" - * until that line is filled. Layout continues on the next line. - * <p> - * WARNING: This class is not intended to be subclassed by clients. Future - * versions may contain additional abstract methods. - * - * @author mengbo - * @since 2.1 - */ -public abstract class FlowFigure extends Figure { - - // static final boolean SHOW_BASELINE = true; - - /** - * Constructs a new FlowFigure. - */ - public FlowFigure() { - // setLayoutManager(createDefaultFlowLayout()); - } - - /** - * If the child is a <code>FlowFigure</code>, its FlowContext is passed - * to it. - * - * @see org.eclipse.draw2d.IFigure#add(IFigure, Object, int) - */ - public void add(IFigure child, Object constraint, int index) { - super.add(child, constraint, index); - if (child instanceof FlowFigure) { - FlowFigure ff = (FlowFigure) child; - if (getLayoutManager() instanceof FlowContext) { - ff.setOriginalFlowContext((FlowContext) getLayoutManager()); - } else { - // should not happen - // FIXME: logging - System.err.println("layout is not FlowContext"); - } - } - } - - /** - * Creates the default layout manager - * - * @return The default layout - */ - // protected abstract FlowFigureLayout createDefaultFlowLayout(); - /** - * @see Figure#paintFigure(Graphics) - */ - protected void paintFigure(Graphics g) { - super.paintFigure(g); - // g.drawRectangle(getBounds().getResized(-1,-1)); - } - - /** - * Called after validate has occurred. This is used to update the bounds of - * the FlowFigure to encompass its new flow boxed created during validate. - */ - public abstract void postValidate(); - - /** - * FlowFigures override setBounds() to prevent translation of children. - * "bounds" is a derived property for FlowFigures, calculated from the - * fragments that make up the FlowFigure. - * - * @see Figure#setBounds(Rectangle) - */ - public void setBounds(Rectangle r) { - if (getBounds().equals(r)) - return; - erase(); - bounds.x = r.x; - bounds.y = r.y; - bounds.width = r.width; - bounds.height = r.height; - fireFigureMoved(); - repaint(); - } - - /** - * Sets the flow context. - * - * @param flowContext - * the flow context for this flow figure - */ - public void setOriginalFlowContext(FlowContext flowContext) { - ((FlowFigureLayout) getLayoutManager()) - .setOriginalFlowContext(flowContext); - } - - public void setDisplayString(String s) { - _displayString = s; - } - - public String toString() { - if (_displayString == null) - { - return super.toString(); - } - return _displayString + " " + getClass().getName(); - } - - String _displayString; // for debug - - /** - * @return - */ - public FlowContext getFlowContext() { - return ((FlowFigureLayout) getLayoutManager()).getFlowContext(); - } - - // ---------------------------------------------------------------------- - // as absolute positioning and relative positioning may have children - // out-side - // of parent bounds, so we want to disable clipping when drawing figures - /* - * (non-Javadoc) - * - * @see org.eclipse.draw2d.Figure#paintChildren(org.eclipse.draw2d.Graphics) - */ - protected void paintChildren(Graphics graphics) { - IFigure child; - - Rectangle clip = Rectangle.SINGLETON; - List children = this.getChildren(); - for (int i = 0; i < children.size(); i++) { - child = (IFigure) children.get(i); - if (child.isVisible() && child.intersects(graphics.getClip(clip))) { - // graphics.clipRect(child.getBounds()); - child.paint(graphics); - graphics.restoreState(); - } - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.draw2d.Figure#paintClientArea(org.eclipse.draw2d.Graphics) - */ - protected void paintClientArea(Graphics graphics) { - if (this.getChildren().isEmpty()) - return; - - // boolean optimizeClip = getBorder() == null || getBorder().isOpaque(); - - if (useLocalCoordinates()) { - graphics.translate(getBounds().x + getInsets().left, getBounds().y - + getInsets().top); - // if (!optimizeClip) - // graphics.clipRect(getClientArea(PRIVATE_RECT)); - graphics.pushState(); - paintChildren(graphics); - graphics.popState(); - graphics.restoreState(); - } else { - // if (optimizeClip) - paintChildren(graphics); - // else { - // graphics.clipRect(getClientArea(PRIVATE_RECT)); - // graphics.pushState(); - // paintChildren(graphics); - // graphics.popState(); - // graphics.restoreState(); - // } - } - - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/FlowFigureLayout.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/FlowFigureLayout.java deleted file mode 100644 index 3f80478cf..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/FlowFigureLayout.java +++ /dev/null @@ -1,116 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import org.eclipse.draw2d.AbstractLayout; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.geometry.Dimension; - -public abstract class FlowFigureLayout extends AbstractLayout { - - /** - * <code>true</code> if the context has changed, and a layout is needed. - */ - protected boolean _invalid = true; - - /** - * The flow context in which this LayoutManager exists. - */ - private FlowContext _context; - - /** - * The figure passed by layout(Figure) is held for convenience. - */ - private final FlowFigure _flowFigure; - - /** - * Constructs a new FlowFigureLayout with the given FlowFigure. - * - * @param flowfigure - * the FlowFigure - */ - protected FlowFigureLayout(FlowFigure flowfigure) { - this._flowFigure = flowfigure; - } - - /** - * TextFlowLayouts do not calculate a preferred size because it is too - * expensive. {@link FlowPage}will actually layout itself in order to - * calculate preferredSize. - * - * @see AbstractLayout#calculatePreferredSize(IFigure) - */ - public Dimension calculatePreferredSize(IFigure f, int w, int h) { - return null; - } - - /** - * @return the FlowFigure - */ - protected FlowFigure getFlowFigure() { - return _flowFigure; - } - - /** - * Marks this layout as invalid. - * - * @see org.eclipse.draw2d.LayoutManager#invalidate() - */ - public void invalidate() { - _invalid = true; - super.invalidate(); - } - - /** - * @see org.eclipse.draw2d.LayoutManager#layout(IFigure) - */ - public final void layout(IFigure figure) { - layout(); - _invalid = false; - } - - /** - * Called during {@link #layout(IFigure)}. The {@link #_invalid}flag is - * reset after this method is called. - */ - protected abstract void layout(); - - /** - * Sets the context for this layout manager. - * - * @param flowContext - * the context of this layout - */ - public void setOriginalFlowContext(FlowContext flowContext) { - _context = flowContext; - } - - public FlowContext getOriginalFlowContext() { - return _context; - } - - /** - * get flow context. - * - * @return - */ - public FlowContext getFlowContext() { - return _context; - } - - public String toString() { - // for debug purpose. - return _flowFigure.toString(); - } - - abstract public void dispose(); -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/FlowPage.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/FlowPage.java deleted file mode 100644 index 31d44de44..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/FlowPage.java +++ /dev/null @@ -1,160 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import java.util.List; - -import org.eclipse.draw2d.geometry.Dimension; -import org.eclipse.draw2d.geometry.Insets; -import org.eclipse.draw2d.geometry.Rectangle; - -/** - * The root of a Flow hierarchy. A flow page can be treated as a normal figure, - * but contains FlowFigures. - * <P> - * A FlowPage will not have a defined width unless it is inside a figure whose - * layout provides width hints when calling - * {@link org.eclipse.draw2d.IFigure#getPreferredSize(int, int)}. - * <P> - * WARNING: This class is not intended to be subclassed by clients. - */ -public class FlowPage extends BlockFlow { - - private Dimension _pageSize = new Dimension(); - - private int _recommendedWidth; - - private int _pageSizeCacheKeys[] = new int[4]; - - private Dimension _pageSizeCacheValues[] = new Dimension[4]; - - /** - * @see org.eclipse.jst.pagedesigner.css2.layout.BlockFlow#createDefaultFlowLayout() - */ - protected FlowFigureLayout createDefaultFlowLayout() { - return new PageFlowLayout(this); - } - - /** - * @see org.eclipse.draw2d.Figure#getMinimumSize() - */ - public Dimension getMinimumSize(int w, int h) { - return getPreferredSize(w, h); - } - - /** - * @see org.eclipse.draw2d.Figure#invalidate() - */ - public void invalidate() { - _pageSizeCacheValues = new Dimension[4]; - super.invalidate(); - } - - /** - * @see org.eclipse.draw2d.Figure#getPreferredSize(int, int) - */ - public Dimension getPreferredSize(int width, int h) { - if (width >= 0) - width = Math.max(0, width - getInsets().getWidth()); - - for (int i = 0; i < 4; i++) { - if (_pageSizeCacheKeys[i] == width - && _pageSizeCacheValues[i] != null) - return _pageSizeCacheValues[i]; - } - - _pageSizeCacheKeys[3] = _pageSizeCacheKeys[2]; - _pageSizeCacheKeys[2] = _pageSizeCacheKeys[1]; - _pageSizeCacheKeys[1] = _pageSizeCacheKeys[0]; - _pageSizeCacheKeys[0] = width; - - _pageSizeCacheValues[3] = _pageSizeCacheValues[2]; - _pageSizeCacheValues[2] = _pageSizeCacheValues[1]; - _pageSizeCacheValues[1] = _pageSizeCacheValues[0]; - - // Flowpage must temporarily layout to determine its preferred size - int oldWidth = getRecommendedWidth(); - setRecommendedWidth(width); - validate(); - _pageSizeCacheValues[0] = _pageSize.getExpanded(getInsets().getWidth(), - getInsets().getHeight()); - - if (width != oldWidth) { - setRecommendedWidth(oldWidth); - getUpdateManager().addInvalidFigure(this); - } - return _pageSizeCacheValues[0]; - } - - int getRecommendedWidth() { - return _recommendedWidth; - } - - /** - * @see BlockFlow#postValidate() - */ - public void postValidate() { - Rectangle r = getBlockBox().toRectangle(); - _pageSize.width = r.width; - _pageSize.height = r.height; - List v = getChildren(); - for (int i = 0; i < v.size(); i++) - ((FlowFigure) v.get(i)).postValidate(); - } - - /** - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowFigure#setBounds(Rectangle) - */ - public void setBounds(Rectangle r) { - if (getBounds().equals(r)) - return; - boolean invalidate = getBounds().width != r.width - || getBounds().height != r.height; - super.setBounds(r); - int newWidth = r.width - getInsets().getWidth(); - if (invalidate || getRecommendedWidth() != newWidth) { - setRecommendedWidth(newWidth); - getUpdateManager().addInvalidFigure(this); - } - } - - private void setRecommendedWidth(int width) { - if (_recommendedWidth == width) - return; - _recommendedWidth = width; - super.invalidate(); - } - - /** - * @see org.eclipse.draw2d.Figure#validate() - */ - public void validate() { - if (isValid()) - return; - super.validate(); - postValidate(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.draw2d.Figure#setValid(boolean) - */ - public void setValid(boolean value) { - super.setValid(value); - } - - public Insets getInsets() { - return new Insets(8); - } - -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/FlowUtilities.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/FlowUtilities.java deleted file mode 100644 index 5ebde828b..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/FlowUtilities.java +++ /dev/null @@ -1,260 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import java.text.BreakIterator; - -import org.eclipse.draw2d.FigureUtilities; -import org.eclipse.draw2d.geometry.Dimension; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.FontMetrics; - -/** - * Utility class for FlowFigures. - * - */ -public class FlowUtilities extends FigureUtilities { - /** - * Returns the number of characters from the specified String that will fit - * in the available amount of space. An average character width can be - * provided as a hint for faster calculation. - * - * @param frag - * the TextFragmentBox - * @param string - * the String - * @param font - * the Font used for measuring - * @param availableWidth - * the available width in pixels - * @param avg - * 0.0, or an avg character width to use during calculation - * @param wrapping - * the word wrap style - * @return the number of characters that will fit in the space - */ - public static int setupFragmentBasedOnTextSpace(TextFragmentBox frag, - String string, Font font, int availableWidth, float avg, - int wrapping) { - int result = getTextForSpace(string, font, availableWidth, avg, - wrapping); - frag._length = result; - setupFragment(frag, font, string); - return result; - } - - /** - * given the text string, font and available width and wrapping mode. - * Calculate how much text can fit into. - * - * @param string - * @param font - * @param availableWidth - * @param avg - * @param wrapping - * @return - */ - public static int getTextForSpace(String string, Font font, - int availableWidth, float avg, int wrapping) { - if (string.length() == 0) { - return 0; - } - - FontMetrics metrics = getFontMetrics(font); - BreakIterator breakItr = BreakIterator.getLineInstance(); - breakItr.setText(string); - int MIN, min, max; - if (avg == 0.0) { - avg = metrics.getAverageCharWidth(); - } - - int firstBreak = breakItr.next(); - - int winNL = string.indexOf("\r\n"); //$NON-NLS-1$ - int macNL = string.indexOf('\r'); - int unixNL = string.indexOf('\n'); - - MIN = min = (wrapping == CSSTextLayout.WORD_WRAP_HARD) ? firstBreak : 1; - if (macNL == winNL) { - macNL = -1; // If the Mac newline is just the prefix to the win NL, - // ignore it - } - - max = string.length() + 1; - - if (winNL != -1) { - max = Math.min(max, winNL); - min = Math.min(min, winNL); - } - if (unixNL != -1) { - max = Math.min(max, unixNL); - min = Math.min(min, unixNL); - } - if (macNL != -1) { - max = Math.min(max, macNL); - min = Math.min(min, macNL); - } - - int origMax = max; - // The size of the current guess - int guess = 0, guessSize = 0; - - while ((max - min) > 1) { - // Pick a new guess size - // New guess is the last guess plus the missing width in pixels - // divided by the average character size in pixels - guess = guess + (int) ((availableWidth - guessSize) / avg); - - if (guess >= max) { - guess = max - 1; - } - if (guess <= min) { - guess = min + 1; - } - - // Measure the current guess - guessSize = getStringExtents2(string.substring(0, guess), font).width; - - if (guessSize <= availableWidth) { - // We did not use the available width - min = guess; - } else { - // We exceeded the available width - max = guess; - } - } - - int result = string.length(); - switch (wrapping) { - case CSSTextLayout.WORD_WRAP_HARD: - if (min == string.length() || min == winNL || min == unixNL - || min == macNL) { - result = min; - } else if (max == origMax - && getStringExtents2(string.substring(0, max), font).width <= availableWidth) { - result = max; - } else { - result = Math.max(MIN, breakItr.preceding(Math.min(max, string - .length() - 1))); - } - break; - - case CSSTextLayout.WORD_WRAP_SOFT: - if (min == string.length() || min == winNL || min == unixNL - || min == macNL) { - result = min; - } else if (max == origMax - && getStringExtents2(string.substring(0, max), font).width <= availableWidth) { - result = max; - } else if (breakItr.isBoundary(min)) { - result = min; - } else if (breakItr.isBoundary(Math.min(max, string.length() - 1))) { - result = max; - } else { - result = breakItr.preceding(Math.min(max, string.length() - 1)); - } - if (result <= 0) { - result = min; - } - break; - // case CSSTextLayout.WORD_WRAP_TRUNCATE: - // if (min == string.length() || min == winNL || min == unixNL || min == - // macNL) - // { - // result = frag._length = min; - // setupFragment(frag, font, string); - // if (frag.getWidth() <= availableWidth) - // return result; - // min -= 1; - // } - // else if (max == origMax && getStringExtents(string.substring(0, max), - // font).width <= availableWidth) - // { - // result = frag._length = max; - // setupFragment(frag, font, string); - // return result; - // } - // result = breakItr.preceding(Math.min(max + 1, string.length() - 1)); - // if (result <= 0) - // { - // ELLIPSIS_SIZE = - // FigureUtilities.getStringExtents(CSSTextFigure.ELLIPSIS, font); - // getTextForSpace(frag, string, font, availableWidth - - // ELLIPSIS_SIZE.width, avg, CSSTextLayout.WORD_WRAP_SOFT); - // //frag.length = min; - // frag._truncated = true; - // result = breakItr.following(min); - // if (result == BreakIterator.DONE) - // result = string.length(); - // } - // else - // { - // frag._length = result; - // } - } - - return result; - } - - public static int getTextInWidth(String string, Font font, - int availableWidth, float avg) { - if (string.length() == 0) { - return 0; - } - int guess = 0; - while (true) { - Dimension a = getTextExtents(string.substring(0, guess), font); - if (a.width >= availableWidth) { - return guess; - } - guess++; - if (guess == string.length()) { - return guess; - } - } - } - - /** - * change the parent implementation of getStringExtents(). Don't expend the - * 1 width. So empty string will not have any width. - * - * @param s - * @param f - * @return - */ - public static Dimension getStringExtents2(String s, Font f) { - return new Dimension(getStringDimension(s, f)); - } - - static void setupFragment(TextFragmentBox frag, Font f, String s) { - // if (frag.length != s.length()) - // we don't skip whitespace here. since already truncated in - // CSSTextLayout - - // while (frag.length > 0 && - // Character.isElementContentWhitespace(s.charAt(frag.length - 1))) - // frag.length--; - frag.setTextData(s.substring(0, frag._length)); - Dimension d = getStringExtents2(s.substring(0, frag._length), f); - FontMetrics fm = getFontMetrics(f); - frag.setHeight(fm.getHeight()); - frag.setAscent(fm.getAscent() + fm.getLeading()); - if (frag._length > 0 - && Character.isWhitespace(s.charAt(frag._length - 1))) { - frag._isLastCharWhitespace = true; - } else { - frag._isLastCharWhitespace = false; - } - frag.setWidth(d.width); - } - -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/ICSSFigure.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/ICSSFigure.java deleted file mode 100644 index b0a193562..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/ICSSFigure.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import java.util.List; - -import org.eclipse.draw2d.IFigure; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; - -/** - * @author mengbo - */ -public interface ICSSFigure extends IFigure { - /** - * get fragments of this figure. Each item of the list will be a FlowBox. - * Note, this method is for read only, caller should not change the returned - * list and items in the returned list. - * - * @return - */ - public List getFragmentsForRead(); - - /** - * get the CSSStyle of this CSS figure. - * - * @return - */ - public ICSSStyle getCSSStyle(); -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/ICSSLayout.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/ICSSLayout.java deleted file mode 100644 index 1320103f3..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/ICSSLayout.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import org.eclipse.draw2d.LayoutManager; - -/** - * There are several kinds of layout involved. 1. the layout need let the child - * figures do certain layouting of themselves first, then decide the final - * result based on child information. 2. the layout could decide the size - * information of this figure without child information. - * - * @author mengbo - * @version 1.5 - */ -public interface ICSSLayout extends LayoutManager { - /** - * Each ICSSLayout is dedicated to a single CSSFigure. - * - * @return - */ - public ICSSFigure getICSSFigure(); - - /** - * - * @return - */ - // public List getFragmentsForRead(); - /** - * postValidate the child figures of this CSSFigure. Normally layout fall - * into the first category need implement this method. - */ - // public void postValidate(); - /** - * setBounds is called on the CSSFigure. Normally layout fall into the - * second category need implement this method. - * - * @param rect - * @param invalidate - */ - // public void setBoundsCalled(Rectangle rect, boolean invalidate); - /** - * @return - */ - // public boolean useLocalCoordinates(); -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/ICSSPainter.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/ICSSPainter.java deleted file mode 100644 index 5f83cb868..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/ICSSPainter.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import org.eclipse.draw2d.Graphics; - -/** - * @author mengbo - */ -public interface ICSSPainter { - /** - * this method is called in the figure's <code>paintFigure</code> method, - * before <code>paintClientArea</code>. So it is called before children. - * Thus, children may override its effects. - * - * @param g - */ - public void paintFigure(Graphics g); - -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/ICSSPainter2.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/ICSSPainter2.java deleted file mode 100644 index f93fb8447..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/ICSSPainter2.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import org.eclipse.draw2d.Graphics; - -/** - * If the layout implements this interface, then it will have chance to paint - * something to override children effect. - * - * @see org.eclipse.jst.pagedesigner.css2.layout.ICSSPainter - * @see org.eclipse.jst.pagedesigner.css2.layout.CSSFigure - * - * @author mengbo - * @version 1.5 - */ -public interface ICSSPainter2 { - /** - * this method is called after <code>paintClientArea</code>. So it is - * called after children. Thus, it could override some children effects. - * - * @param g - */ - public void paintFigurePostClientArea(Graphics g); -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/LineBox.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/LineBox.java deleted file mode 100644 index 5ab842f2f..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/LineBox.java +++ /dev/null @@ -1,414 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import org.eclipse.jst.pagedesigner.css2.property.VerticalAlignMeta; -import org.eclipse.jst.pagedesigner.css2.value.Length; -import org.eclipse.swt.graphics.FontMetrics; - -/** - * A composite box representing a single line. LineBox calculates its ascent and - * descent from the child boxes it contains. Clients can call - * {@link #getAscent()}or {@link#getHeight()}at any time and expect valid - * values. The child boxes that are added to a line have unspecied locations - * until {@link #commit()}is called, at which time the child boxes are layed - * out in left-to-right order, and their baselines are all aligned vertically. - * - */ -public class LineBox extends CompositeBox { - private final static int BASELINE = 0; - - private final static int MIDDLE = 1; - - private final static int SUB = 2; - - private final static int SUPER = 3; - - private final static int TEXT_TOP = 4; - - private final static int TEXT_BOTTOM = 5; - - private final static int TOP = 6; - - private final static int BOTTOM = 7; - - private final static int LENGTH = 8; - - private int _ascent = 0; - - private int _descent = 0; - - private int _fontAscent = 0; - - private int _fontDescent = 0; - - private int _fontLeading = 0; - - private Object _horizonalData = null; - - private Object _htmlInitData = null; - - private int _accumlatedWidth = 0; - - /** - * Removes all owned fragments and invalidates this CompositeBox. - */ - public void clear() { - super.clear(); - _horizonalData = null; - _htmlInitData = null; - } - - /** - * Committing a LineBox will position its children correctly. All children - * boxes are made to have the same baseline, and are layed out from - * left-to-right. - */ - public void commit() { - int baseline = getBaseline(); - int xLocation = _x; - for (int i = 0; i < _fragments.size(); i++) { - FlowBox block = (FlowBox) _fragments.get(i); - block._x = xLocation + block._marginInsets.left; - xLocation = block._x + block._width + block._marginInsets.right; - - if (_fragments.size() > 1 && block instanceof TextFragmentBox) { - TextFragmentBox textBox = (TextFragmentBox) block; - if (textBox.getTextData().length() == 0) { - textBox._height = _fontAscent + _fontDescent + _fontLeading; - textBox.setAscent(_fontAscent + _fontLeading); - block._y = this._y; - continue; - } - } - - switch (getVerticalAlignType(block)) { - case TOP: - block._y = this._y; - break; - case BOTTOM: - block._y = this.getBaseline() - (block.getHeight() - _descent); - break; - case MIDDLE: - int halfXHeight = getHalfXHeight(); - block._y = this.getBaseline() - halfXHeight - - (block.getHeight() + 1) / 2; - break; - case TEXT_TOP: - block._y = this.getBaseline() - _fontAscent - _fontLeading; - break; - case TEXT_BOTTOM: - block._y = this.getBaseline() - (block._height - _fontDescent); - break; - case LENGTH: - block._y = this.getBaseline() + getIncrement(block); - break; - case SUPER: - block._y = this.getBaseline() - getHalfXHeight() * 2 - - block._height; - break; - case SUB: - block._y = this.getBaseline() - block._height * _fontLeading - / getFontHeight(); - break; - case BASELINE: - default: - block.makeBaseline(baseline); - break; - } - if (block instanceof LineBox) { - ((LineBox) block).commit(); - } - } - } - - protected int getVerticalAlignType(FlowBox box) { - Object data = box.getVerticalAlignData(); - - if (data != null) { - if (data instanceof Length) { - return LENGTH; - } else if (VerticalAlignMeta.BASELINE.equals(data)) { - return BASELINE; - } else if (VerticalAlignMeta.MIDDLE.equals(data)) { - return MIDDLE; - } else if (VerticalAlignMeta.SUB.equals(data)) { - return SUB; - } else if (VerticalAlignMeta.SUPER.equals(data)) { - return SUPER; - } else if (VerticalAlignMeta.TEXT_TOP.equals(data)) { - return TEXT_TOP; - } else if (VerticalAlignMeta.TEXT_BOTTOM.equals(data)) { - return TEXT_BOTTOM; - } else if (VerticalAlignMeta.TOP.equals(data)) { - return TOP; - } else if (VerticalAlignMeta.BOTTOM.equals(data)) { - return BOTTOM; - } - return BASELINE; - } - return BASELINE; - } - - /** - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowBox#getAscent() - */ - public int getAscent() { - // because at initial, ascent is 0. And the linebox - // could have some size setting without children. In - // that case, we need handle differently. - if (_ascent == 0 && _fragments.isEmpty()) { - return getHeight(); - } - return _ascent; - } - - /** - * Returns the width available to child fragments. - * - * @return the width in pixels - */ - public int getAvailableWidth() { - if (_recommendedWidth < 0) { - return Integer.MAX_VALUE; - } - int availableWidth = _recommendedWidth - _accumlatedWidth; - if (availableWidth < 0) { - availableWidth = 0; - } - return availableWidth; - } - - /** - * Returns the baseline of this LineBox, which is the y value plus the - * ascent. - * - * @return the baseline value. - */ - public int getBaseline() { - return _y + getAscent(); - } - - /** - * @see CompositeBox#resetInfo() - */ - protected void resetInfo() { - super.resetInfo(); - _accumlatedWidth = 0; - _ascent = 0; - } - - /** - * @see CompositeBox#unionInfo(FlowBox) - */ - protected void unionInfo(FlowBox blockInfo) { - if (blockInfo instanceof TextFragmentBox) { - if (((TextFragmentBox) blockInfo).getTextData().length() == 0) { - return; - } - } - - if (_fragments == null || _fragments.isEmpty()) { - this._ascent = 0; - this._descent = 0; - this._height = 0; - } - - int valign = getVerticalAlignType(blockInfo); - - if (valign == BASELINE) { - _ascent = Math.max(_ascent, blockInfo.getAscent()); - if (blockInfo instanceof WidgetBox) { - _descent = 0; - } else { - _descent = Math.max(_descent, blockInfo.getDescent()); - } - _height = Math.max(_height, _ascent + _descent); - } else if (valign == MIDDLE) { - int halfXHeight = getHalfXHeight(); - _ascent = Math.max(_ascent, (blockInfo.getHeight() + 1) / 2 - + halfXHeight); - _descent = Math.max(_descent, blockInfo.getHeight() / 2 - - halfXHeight); - _height = Math.max(_height, _ascent + _descent); - } else if (valign == TEXT_TOP) { - _ascent = Math.max(_ascent, _fontAscent + _fontLeading); - _descent = Math.max(_descent, blockInfo.getHeight() - _fontAscent - - _fontLeading); - _height = Math.max(_height, _ascent + _descent); - } else if (valign == TEXT_BOTTOM) { - _ascent = Math.max(_ascent, blockInfo.getHeight() - _fontDescent); - _descent = Math.max(_descent, _fontDescent); - _height = Math.max(_height, _ascent + _descent); - } else if (valign == SUB) { - int blockTop = blockInfo._height * _fontLeading / getFontHeight(); - _ascent = Math.max(_ascent, blockTop); - _descent = Math.max(_descent, blockInfo.getHeight() - blockTop); - _height = Math.max(_height, _ascent + _descent); - } else if (valign == SUPER) { - int blockTop = blockInfo._height; - _ascent = Math.max(_ascent, getHalfXHeight() * 2 + blockTop); - _height = Math.max(_height, _ascent + _descent); - } else if (valign == LENGTH) { - int increment = getIncrement(blockInfo); - _ascent = Math.max(_ascent, blockInfo.getAscent() + increment); - _descent = Math.max(_descent, blockInfo.getDescent() - increment); - _height = Math.max(_height, _ascent + _descent); - } else if (valign == TOP) { - _descent = Math.max(_descent, blockInfo.getHeight() - _ascent); - _height = Math.max(_height, _ascent + _descent); - } else if (valign == BOTTOM) { - // XXX:the render of IE is not consistent with spec, mozilla is. so - // we follow mozilla's implementation. - _ascent = Math.max(_ascent, blockInfo.getHeight() - _descent); - _height = Math.max(_height, _ascent + _descent); - } else { - _ascent = Math.max(_ascent, blockInfo.getAscent()); - _descent = Math.max(_descent, blockInfo.getDescent()); - _height = Math.max(_height, blockInfo.getHeight()); - } - - _accumlatedWidth += blockInfo._width - + blockInfo._marginInsets.getWidth(); - if (_accumlatedWidth > _width) { - _width = _accumlatedWidth; - } - } - - private int getIncrement(FlowBox blockInfo) { - int valign = getVerticalAlignType(blockInfo); - if (valign == LENGTH) { - int increment = 0; - Length length = (Length) blockInfo.getVerticalAlignData(); - if (length.isPercentage()) { - increment = length.getValue() * getFontHeight() / 100; - } else { - increment = length.getValue(); - } - return increment; - } - return 0; - } - - /** - * @see org.eclipse.draw2d.geometry.Rectangle#isEmpty() - */ - public boolean isOccupied() { - if (_width > 0) { - return true; - } - - if (_fragments.isEmpty()) { - return false; - } - // int size = _fragments.size(); - // if (size > 1) - // { - // return true; - // } - // ok, we have one segment - // FlowBox box = (FlowBox) _fragments.get(0); - // if (box instanceof TextFragmentBox) - // { - // if (((TextFragmentBox) box).getTextData().length() == 0) - // { - // // this is an empty string text box. - // return false; - // } - // } - return true; - } - - public boolean isEmptyStringLine() { - // if(this.getWidth() == 0) - // { - // return true; - // } - // else - // { - // return false; - // } - if (_fragments.size() == 1) { - FlowBox box = (FlowBox) _fragments.get(0); - if (box instanceof TextFragmentBox) { - if (box instanceof TextFragmentBox) { - if (((TextFragmentBox) box).getTextData().length() == 0) { - return true; - } - } - } - } - return false; - } - - /** - * @param fontMetrics - */ - public void setFontMetrics(FontMetrics fontMetrics) { - if (fontMetrics != null) { - _fontAscent = fontMetrics.getAscent(); - _fontDescent = fontMetrics.getDescent(); - _fontLeading = fontMetrics.getLeading(); - // if (_fragments == null || _fragments.isEmpty()) - // { - // this._ascent = _fontAscent + _fontLeading; - // this._descent = _fontDescent; - // if (this._height < this._ascent + this._descent) - // { - // this._height = this._ascent + this._descent; - // } - // } - } else { - _fontAscent = 0; - _fontDescent = 0; - _fontLeading = 0; - } - } - - private int getHalfXHeight() { - return (_fontAscent + _fontDescent + _fontLeading) / 5; - } - - private int getFontHeight() { - return _fontAscent + _fontDescent + _fontLeading; - } - - /** - * @return Returns the horizonalData. - */ - public Object getHorizonalData() { - return _horizonalData; - } - - /** - * @param horizonalData - * The horizonalData to set. - */ - public void setHorizonalData(Object horizonalData) { - this._horizonalData = horizonalData; - } - - /** - * @return Returns the htmlInitData. - */ - public Object getHtmlInitData() { - return _htmlInitData; - } - - /** - * @param htmlInitData - * The htmlInitData to set. - */ - public void setHtmlInitData(Object htmlInitData) { - this._htmlInitData = htmlInitData; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/MultiLineLabel.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/MultiLineLabel.java deleted file mode 100644 index 4ea41d981..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/MultiLineLabel.java +++ /dev/null @@ -1,126 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import org.eclipse.draw2d.FigureUtilities; -import org.eclipse.draw2d.Graphics; -import org.eclipse.draw2d.Label; -import org.eclipse.draw2d.geometry.Dimension; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.FontMetrics; - -public class MultiLineLabel extends Label { - private static String ELLIPSIS = "..."; //$NON-NLS-1$ - - protected void paintFigure(Graphics graphics) { - if (isOpaque()) { - graphics.fillRectangle(getBounds()); - } - Rectangle bounds1 = getBounds(); - graphics.translate(bounds1.x, bounds1.y); - drawText(graphics); - graphics.translate(-bounds1.x, -bounds1.y); - } - - private void drawText(Graphics graphics) { - String[] strings = splitString(getText()); - int y = 0; - int lineHeight = FigureUtilities.getFontMetrics(getFont()).getHeight(); - for (int i = 0; i < strings.length; i++) { - graphics.drawText(getSubStringText(strings[i]), 0, y); - y += lineHeight; - } - - } - - private String[] splitString(String text) { - String[] lines = new String[1]; - int start = 0, pos; - do { - pos = text.indexOf('\n', start); - if (pos == -1) { - lines[lines.length - 1] = text.substring(start); - } else { - boolean crlf = (pos > 0) && (text.charAt(pos - 1) == '\r'); - lines[lines.length - 1] = text.substring(start, pos - - (crlf ? 1 : 0)); - start = pos + 1; - String[] newLines = new String[lines.length + 1]; - System.arraycopy(lines, 0, newLines, 0, lines.length); - lines = newLines; - } - } while (pos != -1); - return lines; - } - - public String getSubStringText(String text) { - String subStringText = text; - - Font currentFont = getFont(); - int textWidth = FigureUtilities.getTextWidth(text, currentFont); - if (textWidth - getSize().width <= 0) { - return subStringText; - } - - Dimension effectiveSize = new Dimension(getSize().width, 0); - - int dotsWidth = FigureUtilities.getTextWidth(ELLIPSIS, currentFont); - - if (effectiveSize.width < dotsWidth) { - effectiveSize.width = dotsWidth; - } - - int subStringLength = getLargestSubstringConfinedTo(text, currentFont, - effectiveSize.width - dotsWidth); - subStringText = new String(text.substring(0, subStringLength) - + ELLIPSIS); - return subStringText; - } - - int getLargestSubstringConfinedTo(String s, Font f, int availableWidth) { - FontMetrics metrics = FigureUtilities.getFontMetrics(f); - int min, max; - float avg = metrics.getAverageCharWidth(); - min = 0; - max = s.length() + 1; - - // The size of the current guess - int guess = 0, guessSize = 0; - while ((max - min) > 1) { - // Pick a new guess size - // New guess is the last guess plus the missing width in pixels - // divided by the average character size in pixels - guess = guess + (int) ((availableWidth - guessSize) / avg); - - if (guess >= max) { - guess = max - 1; - } - if (guess <= min) { - guess = min + 1; - } - - // Measure the current guess - guessSize = FigureUtilities - .getTextExtents(s.substring(0, guess), f).width; - - if (guessSize < availableWidth) { - // We did not use the available width - min = guess; - } else { - // We exceeded the available width - max = guess; - } - } - return min; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/PageFlowLayout.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/PageFlowLayout.java deleted file mode 100644 index 33ff6a106..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/PageFlowLayout.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import org.eclipse.draw2d.FigureUtilities; -import org.eclipse.jst.pagedesigner.css2.font.CSSFont; -import org.eclipse.jst.pagedesigner.css2.font.CSSFontManager; -import org.eclipse.swt.graphics.Font; - -/** - * A block layout which requires no FlowContext to perform its layout. This - * class is used by {@link FlowPage}. - * <p> - * WARNING: This class is not intended to be subclassed by clients. - */ -public class PageFlowLayout extends BlockFlowLayout { - - /** - * Creates a new PageFlowLayout with the given FlowPage - * - * @param page - * the FlowPage - */ - public PageFlowLayout(FlowPage page) { - super(page); - } - - /** - * @see BlockFlowLayout#endBlock() - */ - protected void endBlock() { - // do nothing - } - - /** - * - */ - public void postValidate() { - // TODO: This method is not being called. - } - - protected void setupLine(LineBox line, int topMargin) { - super.setupLine(line, topMargin); - - CSSFontManager fontManager = CSSFontManager.getInstance(); - Font font = fontManager.getSwtFont((CSSFont) fontManager - .createDefaultFont()); - line.setFontMetrics(FigureUtilities.getFontMetrics(font)); - } - - /** - * Setup blockBox to the initial bounds of the Page - */ - protected void setupBlock() { - // Remove all current Fragments - _blockBox.clear(); - - // Setup the one fragment for this Block with the correct X and - // available width - _blockBox.setRecommendedWidth(((FlowPage) getFlowFigure()) - .getRecommendedWidth()); - _blockBox._x = 0; - } - -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/TextFragmentBox.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/TextFragmentBox.java deleted file mode 100644 index 80907513f..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/TextFragmentBox.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -/** - * A Geometric object for representing a TextFragment region on a line of Text. - */ -public class TextFragmentBox extends FlowBox { - - /** The offset in pixels * */ - public int _offset; - - /** The length in pixels * */ - public int _length; - - private int _ascent; - - // boolean _truncated; - - public boolean _isLastCharWhitespace = false; - - private String _textData; - - /** - * Creates a new TextFragmentBox - */ - public TextFragmentBox() { - // do nothgin - } - - /** - * Returns the ascent of this TextFragmentBox - * - * @return the ascent - */ - public int getAscent() { - return _ascent; - } - - /** - * Sets the ascent of this TextFragmentBox to the given value - * - * @param a - * the ascent - */ - public void setAscent(int a) { - _ascent = a; - } - - /** - * Sets the height of this TextFragmentBox to the given value - * - * @param h - * the height - */ - public void setHeight(int h) { - _height = h; - } - - /** - * Sets the width of this TextFragmentBox to the given value - * - * @param w - * the width - */ - public void setWidth(int w) { - _width = w; - } - - public String getTextData() { - return _textData; - } - - public void setTextData(String txt) { - _textData = txt; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/TextLayoutSupport.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/TextLayoutSupport.java deleted file mode 100644 index 0a4a35200..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/TextLayoutSupport.java +++ /dev/null @@ -1,386 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -import java.util.List; - -import org.eclipse.draw2d.Graphics; -import org.eclipse.draw2d.geometry.Dimension; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.jst.jsf.common.ui.internal.logging.Logger; -import org.eclipse.jst.pagedesigner.PDPlugin; -import org.eclipse.jst.pagedesigner.css2.property.TextDecorationMeta; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; - -/** - * @author mengbo - */ -public class TextLayoutSupport { - private static final Logger _log = PDPlugin - .getLogger(TextLayoutSupport.class); - - private static final String[] DELIMITERS = { "\r\n", //$NON-NLS-1$ - "\n", //$NON-NLS-1$ - "\r" //$NON-NLS-1$ - }; //$NON-NLS-1$ - - static private int delimeterLength; - - /** - * Reuses an existing <code>TextFragmentBox</code>, or creates a new one. - * - * @param i - * the index - * @param fragments - * the original list of fragments - * @return a TextFragmentBox - */ - // copied from TextLayout - protected static TextFragmentBox getFragment(int i, List fragments) { - if (fragments.size() > i) { - return (TextFragmentBox) fragments.get(i); - } - TextFragmentBox box = new TextFragmentBox(); - fragments.add(box); - return box; - } - - /** - * Returns the average character width of given TextFragmentbox - * - * @param fragment - * the TextFragmentBox - * @return the average character width - */ - public static float getAverageCharWidth(TextFragmentBox fragment) { - if (fragment._width != 0 && fragment._length != 0) { - return fragment._width / (float) fragment._length; - } - return 0.0f; - } - - // ---------------------------------------------------------------------------------------- - /** - * this method will create a set of TextFragment. Each fragment will offset - * to the original text (whole text for the text figure). - */ - public static void layoutNormal(FlowContext context, String text, - List fragments, Font font, int wrappingStyle, boolean trimLeading) { - int i = 0; // The index of the current fragment; - int offset = 0; - if (trimLeading) { - offset = 1; - text = text.substring(1); - } - - int length = 0; // The length of the current fragment - float prevAvgCharWidth; - LineBox currentLine; - TextFragmentBox fragment; - - while (text.length() > 0) { - fragment = null; - prevAvgCharWidth = 0f; - fragment = getFragment(i, fragments); - prevAvgCharWidth = getAverageCharWidth(fragment); - - // Check for newline, if it exists, call context.endLine and skip - // over the newline - // Exccept for first time through, don't do this. - if (i != 0) { - boolean changed = false; - if (text.charAt(0) == '\r') { - text = text.substring(1); - changed = true; - offset += 1; - } - if (text.length() != 0 && text.charAt(0) == '\n') { - text = text.substring(1); - changed = true; - offset += 1; - } - if (changed) { - context.endLine(); - } - } - - fragment._offset = offset; - - // This loop is done at most twice. - // The second time through, a context.endLine() - // was requested, and the loop will break. - while (true) { - currentLine = context.getCurrentLine(); - length = FlowUtilities.setupFragmentBasedOnTextSpace(fragment, - text, font, currentLine.getAvailableWidth(), - prevAvgCharWidth, wrappingStyle); - - if (fragment._width <= currentLine.getAvailableWidth() - || !context.isCurrentLineOccupied()) { - break; - } - context.endLine(); - } - // fragment.x = context.getCurrentX(); - context.addToCurrentLine(fragment); - text = text.substring(length); - offset += length; - if (text.length() > 0) { - context.endLine(); - } - i++; - } - - // Remove the remaining unused fragments. - while (i < fragments.size()) { - fragments.remove(fragments.size() - 1); - } - } - - public static void layoutNoWrap(FlowContext context, String text, - List fragments, Font font) { - TextFragmentBox fragment; - int i = 0; - int offset = 0; - - while (offset < text.length()) { - int result = nextLineBreak(text, offset); - fragment = getFragment(i++, fragments); - fragment._length = result - offset; - fragment._offset = offset; - FlowUtilities.setupFragment(fragment, font, text.substring(offset)); - context.getCurrentLine().add(fragment); - offset = result + delimeterLength; - if (delimeterLength != 0) { - // in nextLineBreak we fo - context.endLine(); - } - - } - // Remove the remaining unused fragments. - while (i < fragments.size()) { - fragments.remove(i++); - } - } - - private static int nextLineBreak(String text, int offset) { - int result = text.length(); - delimeterLength = 0; - int current; - for (int i = 0; i < DELIMITERS.length; i++) { - current = text.indexOf(DELIMITERS[i], offset); - if (current != -1 && current < result) { - result = current; - delimeterLength = DELIMITERS[i].length(); - } - } - return result; - } - - public static void paintTextFigure(Graphics g, List fragments, Font font, - int textDecoration) { - paintTextFigure(g, fragments, font, null, textDecoration); - } - - public static void paintTextDecoration(Graphics g, Rectangle rect, - int textDecoration) { - if ((textDecoration & TextDecorationMeta.UNDERLINE) != 0) { - g.drawLine(rect.x, rect.y + rect.height - 1, rect.x + rect.width - - 1, rect.y + rect.height - 1); - } - if ((textDecoration & TextDecorationMeta.OVERLINE) != 0) { - g.drawLine(rect.x, rect.y + 1, rect.x + rect.width - 1, rect.y + 1); - } - if ((textDecoration & TextDecorationMeta.LINETHROUGH) != 0) { - g.drawLine(rect.x, rect.y + rect.height / 2, rect.x + rect.width - - 1, rect.y + rect.height / 2); - } - } - - public static void paintTextFigure(Graphics g, List fragments, Font font, - Color color, int textDecoration) { - // FIXME: It happens there is problem in this method's parameters. what - // exception should be catched? - try { - TextFragmentBox frag; - // XXX: adjust font. Here is not using setFont(), because that will - // result in revalidate - g.setFont(font); - - for (int i = 0; i < fragments.size(); i++) { - frag = (TextFragmentBox) fragments.get(i); - // if (!g.getClip(Rectangle.SINGLETON).intersects(frag)) - // continue; - String draw; - draw = frag.getTextData(); - - if (color != null) { - g.setForegroundColor(color); - } - g.drawText(draw, frag._x, frag._y); - if ((textDecoration & TextDecorationMeta.UNDERLINE) != 0) { - g.drawLine(frag._x, frag._y + frag.getHeight() - 1, frag._x - + frag.getWidth(), frag._y + frag.getHeight() - 1); - } - if ((textDecoration & TextDecorationMeta.OVERLINE) != 0) { - g.drawLine(frag._x, frag._y, frag._x + frag.getWidth(), - frag._y); - } - if ((textDecoration & TextDecorationMeta.LINETHROUGH) != 0) { - g.drawLine(frag._x, frag._y + frag.getHeight() / 2, frag._x - + frag.getWidth(), frag._y + frag.getHeight() / 2); - } - - if (Debug.DEBUG_BASELINE) { - g.drawLine(frag._x, frag._y + frag.getAscent(), frag._x - + frag.getWidth(), frag._y + frag.getAscent()); - } - } - } catch (Exception e) { - // "Error in text painting:" - _log.info("TextLayoutSupport.Info.1", e); //$NON-NLS-1$ - } - } - - /** - * - * @param g - * @param fragments - * @param text - * all the text in the Text figure. - * @param font - * @param color - * @param textDecoration - * @param start - * @param end - * @param selectionForeColor - * @param selectionBackColor - */ - public static void paintTextFigureWithSelection(Graphics g, List fragments, - String text, Font font, Color color, int textDecoration, int start, - int end, Color selectionForeColor, Color selectionBackColor) { - // FIXME: It happens there is problem in this method's parameters. what - // exception should be catched? - try { - TextFragmentBox frag; - - Color originalForeground = g.getForegroundColor(); - Color originalBackgroud = g.getBackgroundColor(); - - // XXX: adjust font. Here is not using setFont(), because that will - // result in revalidate - g.setFont(font); - - for (int i = 0, n = fragments.size(); i < n; i++) { - frag = (TextFragmentBox) fragments.get(i); - - // to make things simpler, we always draw the line using default - // color - if (color != null) { - g.setForegroundColor(color); - } - - // if (!g.getClip(Rectangle.SINGLETON).intersects(frag)) - // continue; - String draw; - draw = frag.getTextData(); - if (frag._offset >= end || frag._offset + frag._length <= start) { - // we are not in selection. no need to change color - g.drawText(draw, frag._x, frag._y); - paintTextDecoration(g, frag.getRectangle(), textDecoration); - } else if (frag._offset >= start - && frag._offset + frag._length <= end) { - // we are fully in selection - g.setForegroundColor(selectionForeColor); - g.setBackgroundColor(selectionBackColor); - g - .fillRectangle(frag._x, frag._y, FlowUtilities - .getTextExtents(draw, font).width, frag - .getHeight()); - g.drawText(draw, frag._x, frag._y); - paintTextDecoration(g, frag.getRectangle(), textDecoration); - } else { - // partial of the fragment's text is in selection. - - // draw the original string first - g.drawText(draw, frag._x, frag._y); - // then override with the selected parts. - g.setForegroundColor(selectionForeColor); - g.setBackgroundColor(selectionBackColor); - int partialStart = frag._offset > start ? frag._offset - : start; - int partialEnd = (frag._offset + frag._length > end) ? end - : (frag._offset + frag._length); - int x = 0; - String skip = text.substring(frag._offset, partialStart); - x = FlowUtilities.getTextExtents(skip, font).width; - String todraw = text.substring(partialStart, partialEnd); - if (todraw.length() > 0) { - Dimension dimension = FlowUtilities.getTextExtents(skip - + todraw, font); - g.fillRectangle(frag._x + x, frag._y, dimension.width - - x, dimension.height); - g.drawText(skip + todraw, frag._x, frag._y); - if (color != null) { - g.setForegroundColor(color); - } else { - g.setForegroundColor(originalForeground); - } - g.drawText(skip, frag._x, frag._y); - paintTextDecoration(g, frag.getRectangle(), - textDecoration); - g.setForegroundColor(selectionForeColor); - paintTextDecoration(g, - new Rectangle(frag._x + x, frag._y, - dimension.width - x, dimension.height), - textDecoration); - } - } - - // we do this in each loop, to make sure we are using correct - // color - g.setForegroundColor(originalForeground); - g.setBackgroundColor(originalBackgroud); - - } - } catch (Exception e) { - // "Error in text painting:" - _log.info("TextLayoutSupport.Info.1", e); //$NON-NLS-1$ - } - } - - public static int getBeginX(Object textAlign, Rectangle rect, int textWidth) { - int x = rect.x; - if (textAlign != null) { - String align = textAlign.toString(); - if ("left".equalsIgnoreCase(align)) //$NON-NLS-1$ - { - x = rect.x + 1; - } else if ("right".equalsIgnoreCase(align)) //$NON-NLS-1$ - { - x = rect.x + rect.width - textWidth - 1; - if (x < 1) { - x = 1; - } - } else if ("center".equalsIgnoreCase(align)) //$NON-NLS-1$ - { - int offset = (rect.width - textWidth) / 2; - if (offset <= 0) { - offset = 0; - } - x = x + offset + 1; - } - } - return x; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/WidgetBox.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/WidgetBox.java deleted file mode 100644 index 5be873bb9..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/WidgetBox.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout; - -/** - * Simple box support ascent. - * - * @author mengbo - * @version 1.5 - */ -public class WidgetBox extends FlowBox { - private int _ascent = -1; - - public int getAscent() { - if (_ascent < 0) { - return super.getAscent(); - } - return _ascent; - } - - public void setAscent(int ascent) { - _ascent = ascent; - } - - /** - * @return - */ - public boolean supportAscent() { - return _ascent > 0; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/CSSTRGroupLayout.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/CSSTRGroupLayout.java deleted file mode 100644 index febcc180e..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/CSSTRGroupLayout.java +++ /dev/null @@ -1,178 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout.table; - -import java.util.List; - -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.LayoutManager; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.jst.pagedesigner.css2.layout.CSSBlockFlowLayout; -import org.eclipse.jst.pagedesigner.css2.layout.CSSFigure; -import org.eclipse.jst.pagedesigner.css2.layout.FlowFigure; - -/** - * @author mengbo - * @version 1.5 - */ -public class CSSTRGroupLayout extends CSSBlockFlowLayout { - - /** - * @param cssfigure - */ - public CSSTRGroupLayout(CSSFigure cssfigure) { - super(cssfigure); - } - - /** - * the parent figure of TRGroup should be table figure. If so, return the - * corresponding table layout. - * - * @return - */ - public CSSTableLayout2 getTableLayoutContext() { - IFigure parent = getCSSFigure().getParent(); - if (parent != null) { - LayoutManager parentLayout = parent.getLayoutManager(); - if (parentLayout instanceof CSSTableLayout2) { - return (CSSTableLayout2) parentLayout; - } - } - - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.CSSBlockFlowLayout#postValidate() - */ - public void postValidate() { - CSSTableLayout2 tableLayout = getTableLayoutContext(); - if (tableLayout == null) { - super.postValidate(); - } else { - Rectangle r = getTRGroupRect(tableLayout); - if (r != null) { - _blockBox.setXYWidthHeight(r); - getCSSFigure().setBounds(r); - List list = getCSSFigure().getChildren(); - for (int i = 0; i < list.size(); i++) { - ((FlowFigure) list.get(i)).postValidate(); - } - } else { - super.postValidate(); - } - } - } - - /** - * @return - */ - private Rectangle getTRGroupRect(CSSTableLayout2 tableLayout) { - TableRowGroupInfo groupinfo = tableLayout.getGroupInfo(this - .getCSSFigure()); - int rowIndex = groupinfo.getRowIndex(); - int rowCount = groupinfo.getRowCount(); - int y = (rowIndex + 1) * tableLayout.getVSpacing(); - for (int k = 0; k < rowIndex; k++) { - y += tableLayout.getRowHeights()[k]; - } - if (tableLayout.getCaptionInfo() != null - && "top".equalsIgnoreCase(tableLayout.getCaptionInfo().getAlign())) //$NON-NLS-1$ - { - y += tableLayout.getCaptionSize().height; - } - - int height = (rowCount - 1) * tableLayout.getVSpacing(); - for (int k = 0; k < rowCount; k++) { - height += tableLayout.getRowHeights()[rowIndex + k]; - } - //ICSSFigure figure = groupinfo.getFigure(); - return new Rectangle(tableLayout.getRowX(), y, tableLayout - .getRowWidth(), height); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.CSSBlockFlowLayout#useLocalCoordinates() - */ - public boolean useLocalCoordinates() { - // if is in table, we don't use local coordinates. - return getTableLayoutContext() == null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.CSSBlockFlowLayout#endBlock() - */ - protected void endBlock() { - if (getTableLayoutContext() == null) { - super.endBlock(); - } else { - layoutLines(); - } - } - - // /* (non-Javadoc) - // * @see - // org.eclipse.jst.pagedesigner.css2.layout.FlowContainerLayout#layout() - // */ - // protected void layout() - // { - // CSSTableLayout2 tableLayout = getTableLayoutContext(); - // if (tableLayout == null) - // { - // // we are not in table? treat as block. - // super.layout(); - // } - // else - // { - // // ok, we are in table. we need to layout our children. - // TableRowGroupInfo groupInfo = - // tableLayout.getGroupInfo(this.getCSSFigure()); - // int[] rowHeights = tableLayout.getRowHeights(); - // int vspacing = tableLayout.getVSpacing(); - // int rowwidth = getCSSFigure().getBounds().width;// XXX: get from table - // layout? - // int grouprowindex = groupInfo.getRowIndex(); - // List rows = groupInfo.getRowList(); - // for (int i=0, size=rows.size(); i<size; i++) - // { - // TableRowInfo rowinfo = (TableRowInfo) rows.get(i); - // ICSSFigure figure = rowinfo.getFigure(); - // - // int y = 0; - // int rowindex = rowinfo.getRowIndex(); - // for (int row=grouprowindex; row<rowindex; row++) - // { - // y += rowHeights[row]; - // y += vspacing; - // } - // int height = rowHeights[rowindex]; - // Rectangle rect = new Rectangle(0, y, rowwidth, height); - // figure.setBounds(rect); - // } - // } - // } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.CSSLayout#handlingBorderForBlock() - */ - public boolean handlingBorderForBlock() { - return false; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/CSSTRLayout.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/CSSTRLayout.java deleted file mode 100644 index 9bf3fc6a0..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/CSSTRLayout.java +++ /dev/null @@ -1,192 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout.table; - -import java.util.List; - -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.LayoutManager; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.jst.pagedesigner.css2.layout.CSSBlockFlowLayout; -import org.eclipse.jst.pagedesigner.css2.layout.CSSFigure; -import org.eclipse.jst.pagedesigner.css2.layout.FlowFigure; - -/** - * @author mengbo - * @version 1.5 - */ -public class CSSTRLayout extends CSSBlockFlowLayout { - /** - * @param cssfigure - */ - public CSSTRLayout(CSSFigure cssfigure) { - super(cssfigure); - } - - /** - * the parent figure of TRGroup should be table figure. If so, return the - * corresponding table layout. - * - * @return - */ - public CSSTableLayout2 getTableLayoutContext() { - IFigure parent = getCSSFigure().getParent(); - if (parent != null) { - LayoutManager parentLayout = parent.getLayoutManager(); - if (parentLayout instanceof CSSTableLayout2) { - return (CSSTableLayout2) parentLayout; - } else if (parentLayout instanceof CSSTRGroupLayout) { - return ((CSSTRGroupLayout) parentLayout) - .getTableLayoutContext(); - } - } - - return null; - } - - public CSSTRGroupLayout getTRGroupLayout() { - IFigure parent = getCSSFigure().getParent(); - if (parent != null) { - LayoutManager parentLayout = parent.getLayoutManager(); - if (parentLayout instanceof CSSTRGroupLayout) { - return ((CSSTRGroupLayout) parentLayout); - } - } - - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.CSSBlockFlowLayout#postValidate() - */ - public void postValidate() { - CSSTableLayout2 tableLayout = getTableLayoutContext(); - if (tableLayout == null) { - // we are not in table? treat as block. - super.postValidate(); - } else { - Rectangle r = getTRRect(tableLayout, getTRGroupLayout()); - if (r != null) { - _blockBox.setXYWidthHeight(r); - getCSSFigure().setBounds(r); - List list = getCSSFigure().getChildren(); - for (int i = 0; i < list.size(); i++) { - ((FlowFigure) list.get(i)).postValidate(); - } - } else { - super.postValidate(); - } - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.CSSBlockFlowLayout#endBlock() - */ - protected void endBlock() { - if (this.getTableLayoutContext() == null) { - super.endBlock(); - } else { - layoutLines(); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.CSSBlockFlowLayout#useLocalCoordinates() - */ - public boolean useLocalCoordinates() { - return this.getTableLayoutContext() == null; - } - - private Rectangle getTRRect(CSSTableLayout2 tableLayout, - CSSTRGroupLayout groupLayout) { - TableRowInfo rowinfo = tableLayout.getRowInfo(this.getCSSFigure()); - int rowIndex = rowinfo.getRowIndex(); - int y = (rowIndex + 1) * tableLayout.getVSpacing(); - for (int k = 0; k < rowIndex; k++) { - y += tableLayout.getRowHeights()[k]; - } - if (tableLayout.getCaptionInfo() != null - && "top".equalsIgnoreCase(tableLayout.getCaptionInfo().getAlign())) //$NON-NLS-1$ - { - y += tableLayout.getCaptionSize().height; - } - - int height = tableLayout.getRowHeights()[rowIndex]; - //ICSSFigure figure = rowinfo.getFigure(); - return new Rectangle(tableLayout.getRowX(), y, tableLayout - .getRowWidth(), height); - } - - /** - * @param tableLayout - * @param groupLayout - * @return - */ - // private Rectangle getTRRect(CSSTableLayout2 tableLayout, CSSTRGroupLayout - // groupLayout) - // { - // TableRowGroupInfo groupInfo = null; - // if (groupLayout != null) - // { - // groupInfo = tableLayout.getGroupInfo(groupLayout.getCSSFigure()); - // } - // if (groupInfo != null) - // { - // // This TR is in tr group - // int[] rowHeights = tableLayout.getRowHeights(); - // int vspacing = tableLayout.getVSpacing(); - // int rowwidth = tableLayout.getRowWidth(); - // int grouprowindex = groupInfo.getRowIndex(); - // TableRowInfo rowinfo = tableLayout.getRowInfo(this.getCSSFigure()); - // ICSSFigure figure = rowinfo.getFigure(); - // - // int y = 0; - // int rowindex = rowinfo.getRowIndex(); - // for (int row = grouprowindex; row < rowindex; row++) - // { - // y += rowHeights[row]; - // y += vspacing; - // } - // int height = rowHeights[rowindex]; - // Rectangle rect = new Rectangle(0, y, rowwidth, height); - // return rect; - // } - // else - // { - // TableRowInfo rowinfo = tableLayout.getRowInfo(this.getCSSFigure()); - // int rowIndex = rowinfo.getRowIndex(); - // int y = (rowIndex+1) * tableLayout.getVSpacing(); - // int rowHeights[] = tableLayout.getRowHeights(); - // for (int k=0; k<rowIndex; k++) - // { - // y += rowHeights[k]; - // } - // int height = rowHeights[rowIndex]; - // return new Rectangle(tableLayout.getRowX(), y, tableLayout.getRowWidth(), - // height); - // } - // } - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.CSSLayout#handlingBorderForBlock() - */ - public boolean handlingBorderForBlock() { - return false; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/CSSTableCaptionLayout.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/CSSTableCaptionLayout.java deleted file mode 100644 index 27d15717c..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/CSSTableCaptionLayout.java +++ /dev/null @@ -1,110 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout.table; - -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.LayoutManager; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.jst.pagedesigner.css2.layout.CSSFigure; - -/** - * @author mengbo - * @version 1.5 - */ -public class CSSTableCaptionLayout extends CachedTableCellLayout { - private CSSTableLayout2 _tableLayout; - - private TableCaptionInfo _caption; - - /** - * @param cssfigure - */ - public CSSTableCaptionLayout(CSSFigure cssfigure) { - super(cssfigure); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowFigureLayout#invalidate() - */ - public void invalidate() { - super.invalidate(); - - _tableLayout = null; - _caption = null; - } - - public Rectangle getCellRect() { - int x = 0; - - int[] rowHeights = _tableLayout.getRowHeights(); - int vspacing = _tableLayout.getVSpacing(); - int y = vspacing; - if (_caption != null && "bottom".equalsIgnoreCase(_caption.getAlign())) //$NON-NLS-1$ - { - for (int row = 0; row < rowHeights.length; row++) { - y += rowHeights[row]; - y += vspacing; - } - } - - int height = 0; - height = _tableLayout.getCaptionSize().height; - int width = _tableLayout.getCaptionSize().width; - Rectangle rect = new Rectangle(x, y, width, height); - return rect; - } - - /** - * the parent figure of TRGroup should be table figure. If so, return the - * corresponding table layout. - * - * @return - */ - public CSSTableLayout2 getTableLayoutContext() { - IFigure parent = getCSSFigure().getParent(); - if (parent != null) { - LayoutManager parentLayout = parent.getLayoutManager(); - if (parentLayout instanceof CSSTableLayout2) { - return (CSSTableLayout2) parentLayout; - } - } - return null; - } - - /** - * @return - */ - public boolean initializeTableInfo() { - _caption = null; - _tableLayout = getTableLayoutContext(); - if (_tableLayout != null) { - _caption = _tableLayout.getCaptionInfo(); - return _caption != null; - } - return false; - } - - public CSSTableLayout2 getTableLayout() { - return _tableLayout; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.CSSLayout#isCalculatingMaxWidth() - */ - public boolean isCalculatingMaxWidth() { - return false; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/CSSTableCellLayout.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/CSSTableCellLayout.java deleted file mode 100644 index f09529ef0..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/CSSTableCellLayout.java +++ /dev/null @@ -1,199 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout.table; - -import java.util.List; - -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.LayoutManager; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.layout.CSSFigure; -import org.eclipse.jst.pagedesigner.css2.layout.FlowBox; -import org.eclipse.jst.pagedesigner.css2.layout.LineBox; -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyID; -import org.eclipse.jst.pagedesigner.css2.property.VerticalAlignMeta; - -/** - * This layout is for those thigns that it's parent will decide its size. Such - * as table cell. - * - * @author mengbo - * @version 1.5 - */ -public class CSSTableCellLayout extends CachedTableCellLayout { - private CSSTableLayout2 _tableLayout; - - private TableRowInfo _rowinfo; - - private TableCellInfo _cellinfo; - - /** - * @param cssfigure - */ - public CSSTableCellLayout(CSSFigure cssfigure) { - super(cssfigure); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.FlowFigureLayout#invalidate() - */ - public void invalidate() { - super.invalidate(); - - _tableLayout = null; - _rowinfo = null; - _cellinfo = null; - } - - protected void endBlock() { - if (isTable()) { - verticalLayoutLines(); - layoutLines(); - } else { - super.endBlock(); - } - } - - protected void verticalLayoutLines() { - List lines = _blockBox.getFragments(); - - String verticalStyle = getVerticalAlign(); - int linesHeight = 0; - - if (lines != null && !lines.isEmpty()) { - FlowBox bottomBox = ((FlowBox) lines.get(lines.size() - 1)); - FlowBox topBox = ((FlowBox) lines.get(0)); - linesHeight = bottomBox._y + bottomBox.getHeight() - topBox._y; - } - int movement = 0; - if (VerticalAlignMeta.BOTTOM.equals(verticalStyle)) { - movement = _blockBox.getHeight() - linesHeight - - _blockBox.getBorderPaddingHeight() / 2; - } else if (VerticalAlignMeta.TOP.equals(verticalStyle)) { - movement = 0; - } - // else if (VerticalAlignMeta.BASELINE.equals(verticalStyle)) - // { - // movement = _blockBox.getHeight() - linesHeight; - // } - else // if (VerticalAlignMeta.MIDDLE.equals(verticalStyle)) - { - movement = (_blockBox.getHeight() - linesHeight - _blockBox - .getBorderPaddingHeight()) / 2; - } - // VerticalAlignMeta.TOP, ICSSPropertyID.VAL_AUTO and others - // else - // { - // movement = 0; - // } - if (lines != null) { - for (int i = 0, n = lines.size(); i < n; i++) { - if (lines.get(i) instanceof LineBox) { - LineBox lineBox = (LineBox) lines.get(i); - int LineMovement = Math.max(lineBox._marginInsets - .getHeight(), movement); - lineBox._y = lineBox._y + LineMovement - - lineBox._marginInsets.getHeight(); - } - } - } - } - - private String getVerticalAlign() { - ICSSStyle style = getCSSStyle(); - if (style != null) { - return style.getStyleProperty(ICSSPropertyID.ATTR_VERTICAL_ALIGN) - .toString(); - } - return VerticalAlignMeta.MIDDLE; - } - - public Rectangle getCellRect() { - int columnIndex = _cellinfo.getColumnIndex(); - int rowIndex = _cellinfo.getRowIndex(); - int[] columnWidths = _tableLayout.getColumnWidths(); - int hspacing = _tableLayout.getHSpacing(); - int x = hspacing; - for (int col = 0; col < columnIndex; col++) { - x += columnWidths[col]; - x += hspacing; - } - - int[] rowHeights = _tableLayout.getRowHeights(); - int vspacing = _tableLayout.getVSpacing(); - int y = vspacing; - for (int row = 0; row < rowIndex; row++) { - y += rowHeights[row]; - y += vspacing; - } - if (_tableLayout.getCaptionInfo() != null - && "top".equalsIgnoreCase(_tableLayout.getCaptionInfo().getAlign())) //$NON-NLS-1$ - { - y += _tableLayout.getCaptionSize().height; - } - - int width = _tableLayout.getCellWidth(_cellinfo, columnWidths); - int height = _tableLayout.getCellHeight(_cellinfo, rowHeights); - - Rectangle rect = new Rectangle(x, y, width, height); - return rect; - } - - /** - * the parent figure of TRGroup should be table figure. If so, return the - * corresponding table layout. - * - * @return - */ - public CSSTableLayout2 getTableLayoutContext() { - IFigure parent = getCSSFigure().getParent(); - if (parent != null) { - LayoutManager parentLayout = parent.getLayoutManager(); - if (parentLayout instanceof CSSTRLayout) { - return ((CSSTRLayout) parentLayout).getTableLayoutContext(); - } - } - - return null; - } - - /** - * @return - */ - public boolean initializeTableInfo() { - _rowinfo = null; - _cellinfo = null; - _tableLayout = getTableLayoutContext(); - if (_tableLayout != null) { - _rowinfo = _tableLayout.getRowInfo((CSSFigure) this.getCSSFigure() - .getParent()); - if (_rowinfo != null) { - _cellinfo = _rowinfo.getCellInfo(this.getCSSFigure()); - if (_cellinfo != null) { - return true; - } - } - } - return false; - } - - public CSSTableLayout2 getTableLayout() { - return _tableLayout; - } - - public TableCellInfo getTableCellInfo() { - return _cellinfo; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/CSSTableLayout2.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/CSSTableLayout2.java deleted file mode 100644 index ac6b004e7..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/CSSTableLayout2.java +++ /dev/null @@ -1,627 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout.table; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.draw2d.ColorConstants; -import org.eclipse.draw2d.Graphics; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.geometry.Dimension; -import org.eclipse.draw2d.geometry.Insets; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.jst.jsf.common.ui.internal.logging.Logger; -import org.eclipse.jst.pagedesigner.PDPlugin; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.layout.CSSBlockFlowLayout; -import org.eclipse.jst.pagedesigner.css2.layout.CSSFigure; -import org.eclipse.jst.pagedesigner.css2.layout.ICSSPainter; -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyID; -import org.eclipse.jst.pagedesigner.css2.style.ITagEditInfo; -import org.eclipse.swt.SWT; - -/** - * @see http://www.w3.org/TR/REC-CSS2/tables.html - * - * @author mengbo - * @version 1.5 - */ -public class CSSTableLayout2 extends CSSBlockFlowLayout implements ICSSPainter { - static Logger _log = PDPlugin.getLogger(CSSTableLayout2.class); - - int _hspacing; - - int _vspacing; - - int[] _columnWidths; - - int[] _rowHeights; - - Dimension _captionSize; - - // _tableInfo will be initialized in preLayout - TableInfo _tableInfo; - - private int _internalTableWidth; - - private int _internalTableHeight; - - private int _rowx; - - private int _rowwidth; - - /** - * @param flowfigure - */ - public CSSTableLayout2(CSSFigure flowfigure) { - super(flowfigure); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.CSSBlockFlowLayout#preLayout() - */ - protected void preLayout() { - // super.preLayout will setup the block box. - super.preLayout(); - - ICSSStyle style = this.getCSSStyle(); - - _hspacing = _vspacing = 3; // default value - - if (style != null) { - Object borderspacing = style - .getStyleProperty(ICSSPropertyID.ATTR_BORDER_SPACING); - if (borderspacing instanceof int[]) { - int[] intvalues = (int[]) borderspacing; - _hspacing = intvalues[0]; - _vspacing = intvalues[1]; - } else { - ITagEditInfo info = (ITagEditInfo) style - .getAdapter(ITagEditInfo.class); - if (info != null && info.needTableDecorator()) { - // default decorating value. to make things look more - // separated. - if (_hspacing < 5) { - _hspacing = 5; - } - if (_vspacing < 5) { - _vspacing = 5; - } - } - } - } - - // TODO: support caption - _tableInfo = new TableInfo(getCSSFigure()); - - // construct the table structure. - _tableInfo.constructTable(); - - // calculate the user specified width/height for table and cells. - // contentWidth is the user specified content width. If <= 0 means no - // user - // specification. - int contentWidth = this._blockBox.getContentWidth(); - int availableWidth = this._blockBox.getRecommendedContentWidth(); - int contentHeight = this._blockBox.getContentHeight(); - - _tableInfo.calculateWidth(contentWidth, availableWidth); - _tableInfo.calculateHeight(contentHeight); - - int columnCount = _tableInfo.getColumnCount(); - - int columnMinWidths[] = new int[columnCount]; - int columnMaxWidths[] = new int[columnCount]; - - // For each column, determine a maximum and minimum column width from - // the cells that span only that column. The minimum is that required by - // the cell with the largest minimum cell width (or the column 'width', - // whichever is larger). The maximum is that required by the cell with - // the - // largest maximum cell width (or the column 'width', whichever is - // larger). - List cells = _tableInfo.getCells(); - for (int i = 0, size = cells.size(); i < size; i++) { - TableCellInfo cellinfo = (TableCellInfo) cells.get(i); - if (cellinfo.getColSpan() == 1) { - int column = cellinfo.getColumnIndex(); - Dimension mincw = cellinfo.getMinCWDimension(); - Dimension maxcw = cellinfo.getMaxCWDimension(); - if (maxcw.width < mincw.width) { - maxcw.width = mincw.width; - } - if (mincw.width > columnMinWidths[column]) { - columnMinWidths[column] = mincw.width; - } - if (maxcw.width > columnMaxWidths[column]) { - columnMaxWidths[column] = maxcw.width; - } - } - } - // For caption, determine a maximum and minimum width from it. - int captionWidth = 0; - if (_tableInfo._caption != null) { - captionWidth = _tableInfo._caption.getDimension().width; - } - - // For each cell that spans more than one column, increase the - // minimum widths of the columns it spans so that together, they - // are at least as wide as the cell. Do the same for the maximum - // widths. If possible, widen all spanned columns by approximately - // the same amount. - for (int i = 0, size = cells.size(); i < size; i++) { - TableCellInfo cellinfo = (TableCellInfo) cells.get(i); - int colspan = cellinfo.getColSpan(); - if (colspan > 1) { - int column = cellinfo.getColumnIndex(); - Dimension mincw = cellinfo.getMinCWDimension(); - Dimension maxcw = cellinfo.getMaxCWDimension(); - - adjustWidth(column, colspan, mincw.width, columnMinWidths); - adjustWidth(column, colspan, maxcw.width, columnMaxWidths); - } - } - - int sigmaMinWidth = 0; - int sigmaMaxWidth = 0; - for (int i = 0; i < columnMinWidths.length; i++) { - sigmaMinWidth += columnMinWidths[i]; - if (columnMaxWidths[i] == Integer.MAX_VALUE) { - sigmaMaxWidth = Integer.MAX_VALUE; - } else if (sigmaMaxWidth != Integer.MAX_VALUE) { - sigmaMaxWidth += columnMaxWidths[i]; - if (sigmaMaxWidth < 0) { - sigmaMaxWidth = Integer.MAX_VALUE; - } - } - } - int spacingall = (columnMinWidths.length + 1) * _hspacing; - sigmaMinWidth += spacingall; - if (sigmaMaxWidth != Integer.MAX_VALUE) { - sigmaMaxWidth += spacingall; - if (sigmaMaxWidth < 0) { - sigmaMaxWidth = Integer.MAX_VALUE; - } - } - - int tableWidth = _tableInfo.getTableWidth(); - if (tableWidth > 0) { - // If the 'table' or 'inline-table' element's 'width' property has a - // specified value (W) other than 'auto', the property's computed - // value - // is the greater of W and the minimum width required by all the - // columns - // plus cell spacing or borders (MIN). If W is greater than MIN, the - // extra - // width should be distributed over the columns. - int maxMin = Math.max(captionWidth, sigmaMinWidth); - if (maxMin >= tableWidth) { - tableWidth = maxMin; - } - distribute(tableWidth - sigmaMinWidth, columnMinWidths, - columnMaxWidths); - } else { - // If the 'table' or 'inline-table' element has 'width: auto', the - // computed - // table width is the greater of the table's containing block width - // and MIN. - // However, if the maximum width required by the columns plus cell - // spacing or - // borders (MAX) is less than that of the containing block, use MAX. - // int availableWidth = this.getCurrentLine().getAvailableWidth(); - int maxMin = Math.max(captionWidth, sigmaMaxWidth); - if (maxMin <= availableWidth) { - // TODO: if _tableInfo.hasWidthPercentage, then we need take - // that into consideration - // to distribute the column width. Left to next version. - tableWidth = maxMin; - // columnMinWidths = columnMaxWidths; - } else { - tableWidth = availableWidth; - } - distribute(tableWidth - sigmaMinWidth, columnMinWidths, - columnMaxWidths); - } - - // now columnMinWidths contains width for each column - _columnWidths = columnMinWidths; - - // ok, we have finished calculating column width. - // next we need to find out row heights. - _rowHeights = new int[_tableInfo.getRowCount()]; - - // first find out those TR that has height settings and use them. - List rows = _tableInfo.getRows(); - for (int i = 0, size = rows.size(); i < size && i < _rowHeights.length; i++) { - TableRowInfo rowInfo = (TableRowInfo) rows.get(i); - if (rowInfo.getSpecifiedRowHeight() > 0) { - _rowHeights[i] = rowInfo.getSpecifiedRowHeight(); - } - } - - // First the cells don't span multiple rows. - cells = _tableInfo.getCells(); - for (int i = 0, size = cells.size(); i < size; i++) { - TableCellInfo cellinfo = (TableCellInfo) cells.get(i); - IFigure figure = cellinfo.getFigure(); - int rowspan = cellinfo.getRowSpan(); - if (rowspan == 1) { - int cellWidth = getCellWidth(cellinfo, _columnWidths); - Dimension d = figure.getPreferredSize(cellWidth, cellinfo - .getHeight()); - if (d.height > _rowHeights[cellinfo.getRowIndex()]) { - _rowHeights[cellinfo.getRowIndex()] = d.height; - } - } - } - - // Next those cells span multiple rows. - cells = _tableInfo.getCells(); - for (int i = 0, size = cells.size(); i < size; i++) { - TableCellInfo cellinfo = (TableCellInfo) cells.get(i); - IFigure figure = cellinfo.getFigure(); - int rowspan = cellinfo.getRowSpan(); - if (rowspan > 1) { - int cellWidth = getCellWidth(cellinfo, _columnWidths); - Dimension d = figure.getPreferredSize(cellWidth, cellinfo - .getHeight()); - if (d.height > getCellHeight(cellinfo, _rowHeights)) { - adjustHeight(cellinfo.getRowIndex(), rowspan, d.height, - _rowHeights); - } - } - } - - // Next we may need distribute height. - int sigmaHeight = (_tableInfo.getRowCount() + 1) * _vspacing; - for (int i = 0; i < _rowHeights.length; i++) { - sigmaHeight += _rowHeights[i]; - } - if (sigmaHeight < contentHeight) { - distributeHeights(contentHeight - sigmaHeight, _rowHeights); - } - - // now we have calculated the width and height of all cells. - // FIXME: border? - Insets insets = (style == null ? new Insets() : style.getBorderInsets() - .getAdded(style.getPaddingInsets())); - _internalTableWidth = (_tableInfo.getColumnCount() + 1) * _hspacing; - for (int i = 0; i < _columnWidths.length; i++) { - _internalTableWidth += _columnWidths[i]; - } - int minWidth = getLengthValue(style, ICSSPropertyID.ATTR_MIN_WIDTH); - _internalTableWidth = _internalTableWidth > minWidth ? _internalTableWidth - : minWidth; - - _blockBox.setWidth(_internalTableWidth + insets.getWidth()); - _internalTableHeight = (_tableInfo.getRowCount() + 1) * _vspacing; - for (int i = 0; i < _rowHeights.length; i++) { - _internalTableHeight += _rowHeights[i]; - } - int minHeight = getLengthValue(style, ICSSPropertyID.ATTR_MIN_HEIGHT); - _internalTableHeight = _internalTableHeight > minHeight ? _internalTableHeight - : minHeight; - - int captionHeight = 0; - if (_tableInfo._caption != null) { - _captionSize = _tableInfo._caption.getFigure().getPreferredSize( - _internalTableWidth, SWT.DEFAULT); - captionHeight = _captionSize.height; - } else { - _captionSize = null; - } - _internalTableHeight += captionHeight; - - _blockBox.setHeight(_internalTableHeight + insets.getHeight()); - - _rowwidth = _internalTableWidth - 2 * _hspacing; - _rowx = _hspacing; // XXX: table border width left? - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.CSSBlockFlowLayout#endBlock() - */ - protected void endBlock() { - _blockBox.setWidth(_internalTableWidth - + _blockBox.getBorderPaddingWidth()); - _blockBox.setHeight(_internalTableHeight - + _blockBox.getBorderPaddingHeight()); - super.endBlock(); - } - - // - // /** - // * when some of the column has percentage width, and sigmaMax smaller than - // container, - // * @param containerWidth - // * @param columnMinWidths - // * @param columnMaxWidths - // * @return - // */ - // private int distribute2(int containerWidth, int[] columnMinWidths, int[] - // columnMaxWidths) - // { - // - // } - // - /** - * Distribute the additional width to columnMinWidths, using max width as a - * possible reference on how to distribute. - * - * @param toDistribute - * @param columnMinWidths - * @param columnMaxWidths - */ - private void distribute(int toDistribute, int[] columnMinWidths, - int[] columnMaxWidths) { - if (toDistribute <= 0) - return; - if (columnMinWidths.length == 0) - return; - - int[] delta = new int[columnMinWidths.length]; - int sigmaDelta = 0; - for (int i = 0; i < columnMinWidths.length && toDistribute > 0; i++) { - if (_tableInfo._widthSpecified[i]) { - delta[i] = 0; - } else { - delta[i] = columnMaxWidths[i] - columnMinWidths[i]; - if (delta[i] <= 0) { - delta[i] = 0; - } - sigmaDelta += delta[i]; - } - } - if (sigmaDelta == 0) { - // should not happen, but anyway, distribute all to the last column - // columnMinWidths[columnMinWidths.length-1] += toDistribute; - averageDeltaToCell(columnMinWidths, toDistribute); - } else { - int left = toDistribute; - for (int i = 0; i < columnMinWidths.length - 1; i++) { - if (delta[i] > 0) { - int add = delta[i] * toDistribute / sigmaDelta; - left -= add; - columnMinWidths[i] += add; - } - } - columnMinWidths[columnMinWidths.length - 1] += left; - } - } - - private void averageDeltaToCell(int[] columnMinWidths, int toDistribute) { - - if (toDistribute <= 0) { - return; - } - ArrayList list = new ArrayList(); - for (int i = 0; i < columnMinWidths.length; i++) { - if (!_tableInfo._widthSpecified[i]) { - list.add(new Integer(i)); - } - } - if (list.size() == 0) { - for (int i = 0; i < columnMinWidths.length; i++) { - list.add(new Integer(i)); - } - } - int padding = toDistribute / list.size(); - int left = toDistribute % list.size(); - for (int i = 0, n = list.size(); i < n; i++) { - columnMinWidths[((Integer) list.get(i)).intValue()] += padding; - } - if (left > 0) { - for (int i = 0; i < left; i++) { - columnMinWidths[((Integer) list.get(i)).intValue()] += 1; - } - } - } - - /** - * @param i - * @param heights - */ - private void distributeHeights(int toDistribute, int[] heights) { - if (heights.length == 0) - return; - int eachDelta = toDistribute / heights.length; - for (int i = 0; i < heights.length - 1; i++) { - heights[i] += eachDelta; - } - heights[heights.length - 1] += toDistribute - (heights.length - 1) - * eachDelta; - } - - /** - * @param cellinfo - * @param heights - * @return - */ - public int getCellHeight(TableCellInfo cellinfo, int[] heights) { - int rowIndex = cellinfo.getRowIndex(); - int rowspan = cellinfo.getRowSpan(); - int h = 0; - for (int i = 0; i < rowspan; i++) { - h += heights[rowIndex + i]; - } - h += (rowspan - 1) * _vspacing; - return h; - } - - /** - * @param cellinfo - * @param widths - * @return - */ - public int getCellWidth(TableCellInfo cellinfo, int[] widths) { - int columnIndex = cellinfo.getColumnIndex(); - int colspan = cellinfo.getColSpan(); - int w = 0; - for (int i = 0; i < colspan; i++) { - w += widths[columnIndex + i]; - } - w += (colspan - 1) * _hspacing; - return w; - } - - /** - * @param column - * the start column - * @param colspan - * number of columns - * @param width - * desired width - * @param columnWidths - * current columns widths. After the adjust, need make sure the - * columnWidths to be bigger than desired width - */ - private void adjustWidth(int column, int colspan, int width, - int[] columnWidths) { - adjustSpan(column, colspan, width, columnWidths, _hspacing); - } - - /** - * @see #adjustWidth(int, int, int, int[]) - */ - private void adjustHeight(int rowIndex, int rowspan, int height, - int[] heights) { - adjustSpan(rowIndex, rowspan, height, heights, _vspacing); - } - - static private void adjustSpan(int column, int colspan, int width, - int[] columnWidths, int spacing) { - int spanwidth = 0; - for (int i = 0; i < colspan; i++) { - spanwidth += columnWidths[column + i]; - } - // XXX: vspacing here? - spanwidth += (colspan - 1) * spacing; - - if (spanwidth >= width) { - return; - } - int delta = width - spanwidth; - int deltaeach = delta / colspan; - for (int i = 0; i < colspan - 1; i++) { - columnWidths[column + i] += deltaeach; - } - columnWidths[column + colspan - 1] += (delta - (colspan - 1) - * deltaeach); - } - - /** - * @return - */ - public int[] getRowHeights() { - return _rowHeights; - } - - /** - * @return - */ - public int[] getColumnWidths() { - return _columnWidths; - } - - /** - * @return - */ - public int getVSpacing() { - return _vspacing; - } - - /** - * @return - */ - public int getHSpacing() { - return _hspacing; - } - - /** - * @param figure - * @return - */ - public TableRowInfo getRowInfo(CSSFigure figure) { - return _tableInfo.findRowInfo(figure); - } - - public TableCaptionInfo getCaptionInfo() { - return _tableInfo._caption; - } - - /** - * @param figure - * @return - */ - public TableRowGroupInfo getGroupInfo(CSSFigure figure) { - return _tableInfo.findGroupInfo(figure); - } - - /** - * @return - */ - public int getRowX() { - return _rowx; - } - - /** - * @return - */ - public int getRowWidth() { - return _rowwidth; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.CSSBlockFlowLayout#shouldExpand() - */ - public boolean shouldExpand() { - return false; - } - - public Dimension getCaptionSize() { - return _captionSize; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.ICSSPainter#paintFigure(org.eclipse.draw2d.Graphics) - */ - public void paintFigure(Graphics g) { - ICSSStyle style = this.getCSSStyle(); - if (style != null) { - ITagEditInfo info = (ITagEditInfo) style - .getAdapter(ITagEditInfo.class); - if (info != null && info.needTableDecorator()) { - List cells = _tableInfo.getCells(); - for (int i = 0, size = cells.size(); i < size; i++) { - TableCellInfo cellInfo = (TableCellInfo) cells.get(i); - IFigure cellfigure = cellInfo.getFigure(); - Rectangle rect = cellfigure.getBounds().getCopy(); - rect = rect.expand(1, 1); - g.setLineStyle(Graphics.LINE_SOLID); - g.setLineWidth(1); - g.setForegroundColor(ColorConstants.lightBlue); - g.drawRectangle(rect); - } - } - } - } - -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/CachedTableCellLayout.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/CachedTableCellLayout.java deleted file mode 100644 index 6a6ac4d6a..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/CachedTableCellLayout.java +++ /dev/null @@ -1,250 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout.table; - -import java.util.List; - -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.geometry.Dimension; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.jst.pagedesigner.css2.layout.BoxUtil; -import org.eclipse.jst.pagedesigner.css2.layout.CSSBlockFlowLayout; -import org.eclipse.jst.pagedesigner.css2.layout.CSSFigure; -import org.eclipse.jst.pagedesigner.css2.layout.FlowFigure; - -/** - * @author mengbo - * @version 1.5 - */ -public abstract class CachedTableCellLayout extends CSSBlockFlowLayout { - protected Dimension _pageSize = new Dimension(); - - protected boolean _calculatingSize = false; - - private int _pageSizeCacheKeys[] = new int[4]; - - private Dimension _pageSizeCacheValues[] = new Dimension[4]; - - private int _recommendedWidth; - - private Dimension _cacheMaxWidthSize = null; - - private boolean _isTable; - - /** - * @param cssfigure - */ - public CachedTableCellLayout(CSSFigure cssfigure) { - super(cssfigure); - } - - /** - * when figure revalidated, means some child or itself get changed somehow, - * so clear the cache information here. - */ - public void figureRevalidate() { - super.figureRevalidate(); - _pageSizeCacheKeys = new int[4]; - _pageSizeCacheValues = new Dimension[4]; - _pageSize = new Dimension(); - _recommendedWidth = 0; - _cacheMaxWidthSize = null; - _isTable = false; - } - - /** - * TODO: This method is not being called. - */ - public void postValidate() { - if (_isTable) { - if (_calculatingSize) { - _pageSize.width = _blockBox.getWidth(); - _pageSize.height = _blockBox.getHeight(); - } else { - if (_isTable) { - Rectangle rect = getCellRect(); - _blockBox.setXYWidthHeight(rect); - this.getCSSFigure().setBounds(rect); - } - } - List list = getCSSFigure().getChildren(); - for (int i = 0, n = list.size(); i < n; i++) { - ((FlowFigure) list.get(i)).postValidate(); - } - } else { - super.postValidate(); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.layout.CSSBlockFlowLayout#preLayout() - */ - protected void preLayout() { - _isTable = initializeTableInfo(); - if (_isTable) { - if (!_calculatingSize) { - // XXX: I don't know why need to call setValid(false) here, if I - // don't call - // it, the layout will be wrong. - getCSSFigure().setValid(false); - } - } - super.preLayout(); - } - - public abstract Rectangle getCellRect(); - - public abstract boolean initializeTableInfo(); - - protected void setupBlock() { - if (_isTable) { - // Remove all current Fragments - _blockBox.clear(); - - if (_calculatingSize) { - // we are not in the real layout - // Setup the one fragment for this Block with the correct X and - // available width - int recommendedWidth = getRecommendedWidth(); - _blockBox.setRecommendedWidth(recommendedWidth); - - if (recommendedWidth > 0 - && recommendedWidth != Integer.MAX_VALUE) { - _blockBox.setWidth(recommendedWidth); - } - } else { - Rectangle rect = getCellRect(); - _blockBox.setWidth(rect.width); - _blockBox.setRecommendedWidth(rect.width); - _blockBox.setHeight(rect.height); - _blockBox.setRecommendedHeight(rect.height); - } - - BoxUtil.setupBorderPaddingMargin(_blockBox, getCSSStyle()); - } else { - super.setupBlock(); - } - } - - /** - * @see org.eclipse.draw2d.Figure#getPreferredSize(int, int) - */ - public Dimension getPreferredSize(IFigure container, int width, int h) { - if (this.isCalculatingMaxWidth()) { - return getMaxContentWidthSize(container, width, h); - } - try { - _calculatingSize = true; - // if (width >= 0) - // { - // width = Math.max(0, width - container.getInsets().getWidth()); - // } - - for (int i = 0; i < 4; i++) { - if (_pageSizeCacheKeys[i] == width - && _pageSizeCacheValues[i] != null) { - if (h > _pageSizeCacheValues[i].height) { - return new Dimension(_pageSizeCacheValues[i].width, h); - } - return _pageSizeCacheValues[i]; - } - } - - _pageSizeCacheKeys[3] = _pageSizeCacheKeys[2]; - _pageSizeCacheKeys[2] = _pageSizeCacheKeys[1]; - _pageSizeCacheKeys[1] = _pageSizeCacheKeys[0]; - _pageSizeCacheKeys[0] = width; - - _pageSizeCacheValues[3] = _pageSizeCacheValues[2]; - _pageSizeCacheValues[2] = _pageSizeCacheValues[1]; - _pageSizeCacheValues[1] = _pageSizeCacheValues[0]; - - // Flowpage must temporarily layout to determine its preferred size - int oldWidth = getRecommendedWidth(); - setRecommendedWidth(width); - ((CSSFigure) container).setValid(false); - container.validate(); - ((CSSFigure) container).postValidate(); - _pageSizeCacheValues[0] = new Dimension(_pageSize); - - if (width != oldWidth) { - setRecommendedWidth(oldWidth); - // container.getUpdateManager().addInvalidFigure(container); - } - if (h > _pageSizeCacheValues[0].height) { - return new Dimension(_pageSizeCacheValues[0].width, h); - } - return _pageSizeCacheValues[0]; - } finally { - _calculatingSize = false; - } - } - - public int getRecommendedWidth() { - return _recommendedWidth; - } - - private void setRecommendedWidth(int width) { - if (_recommendedWidth == width) { - return; - } - _recommendedWidth = width; - } - - public Dimension getMaxContentWidthSize(IFigure container, int width, - int height) { - try { - _calculatingSize = true; - - if (this._cacheMaxWidthSize == null) { - boolean b = getCalcuatingMaxWidth(); - setCalculatingMaxWidth(true); - - // Flowpage must temporarily layout to determine its preferred - // size - int oldWidth = getRecommendedWidth(); - if (width <= 0) { - setRecommendedWidth(Integer.MAX_VALUE); - } else { - setRecommendedWidth(width); - } - ((CSSFigure) container).setValid(false); - container.validate(); - - ((CSSFigure) container).postValidate(); - _cacheMaxWidthSize = new Dimension(_pageSize); - if (height > _pageSize.height) { - _cacheMaxWidthSize.height = height; - } - - if (0 != oldWidth) { - setRecommendedWidth(oldWidth); - // container.getUpdateManager().addInvalidFigure(container); - } - - setCalculatingMaxWidth(b); - } - return _cacheMaxWidthSize; - } finally { - _calculatingSize = false; - } - } - - /** - * @return Returns the _isTable. - */ - protected boolean isTable() { - return _isTable; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/TableCaptionInfo.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/TableCaptionInfo.java deleted file mode 100644 index 985aba4d5..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/TableCaptionInfo.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout.table; - -import org.eclipse.draw2d.geometry.Dimension; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.layout.ICSSFigure; -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyID; -import org.eclipse.swt.SWT; - -/** - * @author mengbo - * @version 1.5 - */ -public class TableCaptionInfo extends TableItemInfo { - String _align; - - /** - * @param figure - */ - public TableCaptionInfo(ICSSFigure figure) { - super(figure); - ICSSStyle style = figure.getCSSStyle(); - if (style != null) { - _align = style.getStyleProperty( - ICSSPropertyID.ATTR_HORIZONTAL_ALIGN).toString(); - } - } - - /** - * @return - */ - public Dimension getDimension(int width, int height) { - return getFigure().getPreferredSize(width, height); - } - - public Dimension getDimension() { - return getDimension(SWT.DEFAULT, SWT.DEFAULT); - } - - /** - * @return Returns the align. - */ - public String getAlign() { - // TODO:We do not support left/right align of caption currently. so we - // treat them as top. - if ("bottom".equalsIgnoreCase(_align)) //$NON-NLS-1$ - { - return _align; - } - return "top"; //$NON-NLS-1$ - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/TableCellInfo.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/TableCellInfo.java deleted file mode 100644 index 72172c846..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/TableCellInfo.java +++ /dev/null @@ -1,216 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout.table; - -import org.eclipse.draw2d.LayoutManager; -import org.eclipse.draw2d.geometry.Dimension; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.layout.ICSSFigure; -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyID; -import org.eclipse.jst.pagedesigner.css2.value.Length; -import org.eclipse.jst.pagedesigner.utils.IntFlexArray; - -/** - * @author mengbo - * @version 1.5 - */ -public class TableCellInfo extends TableItemInfo { - int _rowSpan = 1; - - int _colSpan = 1; - - int _colIndex; - - int _rowIndex; - - int _cellWidth = 0; - - int _cellHeight = 0; - - /** - * @param childfigure - */ - public TableCellInfo(ICSSFigure childfigure) { - super(childfigure); - } - - /** - * @return - */ - public int getColSpan() { - return _colSpan; - } - - /** - * @return - */ - public int getRowSpan() { - return _rowSpan; - } - - /** - * @return - */ - public int getRowIndex() { - return _rowIndex; - } - - /** - * @return - */ - public int getColumnIndex() { - return _colIndex; - } - - /** - * @return - */ - public Dimension getMinCWDimension() { - return getFigure().getPreferredSize(_cellWidth, _cellHeight); - } - - /** - * @return - */ - public Dimension getMaxCWDimension() { - ICSSFigure figure = getFigure(); - LayoutManager layout = figure.getLayoutManager(); - if (layout instanceof CSSTableCellLayout) { - Dimension d = ((CSSTableCellLayout) layout).getMaxContentWidthSize( - figure, _cellWidth, _cellHeight); - return d; - } - - // should not happen - return getMinCWDimension(); - } - - /** - * @param context - */ - public void calculateCellInfo(TableInfoContext context) { - ICSSStyle style = this.getStyle(); - _rowSpan = style.getRowSpan(); - _colSpan = style.getColSpan(); - - // FIXME: we don't support rowspan and colspan to be 0. - // by spec, 0 means span from current col/row to end. - if (_rowSpan <= 0) { - _rowSpan = 1; - } - if (_colSpan <= 0) { - _colSpan = 1; - } - - _rowIndex = context.getCurrentRow(); - - IntFlexArray array = context.getIntFlexArray(); - int currentCol = context.getCurrentCol(); - - // find a cell that is not occupied by cells in previous rows. - while (array.getAt(currentCol) > 0) { - currentCol++; - } - - // ok, now array.getAt(currentCol) == 0 - _colIndex = currentCol; - - for (int i = 0; i < _colSpan; i++, currentCol++) { - array.setAt(currentCol, _rowSpan); - } - context.setCurrentCol(currentCol); - } - - /** - * @param tablewidth - * table width - */ - public void calculateWidth(TableInfo tableInfo, int tablewidth) { - ICSSStyle style = this.getFigure().getCSSStyle(); - if (style == null) { - _cellWidth = -1; - } else { - Object width = style.getStyleProperty(ICSSPropertyID.ATTR_WIDTH); - Length recommendedWidth = (width instanceof Length) ? (Length) width - : null; - - int rw = 0; - if (recommendedWidth == null || recommendedWidth.getValue() <= 0) { - rw = 0; - } else { - if (recommendedWidth.isPercentage()) { - // percentage width is used for remaining width - // distribution, so not used here. - int colspan = this.getColSpan(); - for (int i = 0; i < colspan; i++) { - tableInfo.setWidthPercentage(this.getColumnIndex() + i, - recommendedWidth.getValue() / colspan); - } - } else { - rw = recommendedWidth.getValue(); - if (!style.isSizeIncludeBorderPadding()) { - rw += style.getBorderInsets().getWidth() - + style.getPaddingInsets().getWidth(); - } - if (this.getColSpan() == 1) { - tableInfo._widthSpecified[this.getColumnIndex()] = true; - } - } - - } - _cellWidth = rw; - } - - } - - /** - * @param height - */ - public void calculateHeight(TableInfo tableInfo, int tableheight) { - ICSSStyle style = this.getFigure().getCSSStyle(); - if (style == null) { - _cellHeight = -1; - } else { - Object height = style.getStyleProperty(ICSSPropertyID.ATTR_HEIGHT); - Length recommendedHeight = (height instanceof Length) ? (Length) height - : null; - - int rh = 0; - if (recommendedHeight == null || recommendedHeight.getValue() <= 0) { - rh = 0; - } else { - if (recommendedHeight.isPercentage()) { - int rowspan = this.getRowSpan(); - for (int i = 0; i < rowspan; i++) { - tableInfo.setHeightPercentage(this.getRowIndex() + i, - recommendedHeight.getValue() / rowspan); - } - } else { - rh = recommendedHeight.getValue(); - } - if (!style.isSizeIncludeBorderPadding()) { - rh += style.getBorderInsets().getHeight() - + style.getPaddingInsets().getHeight(); - } - } - _cellHeight = rh; - } - - } - - /** - * @return - */ - public int getHeight() { - return _cellHeight; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/TableInfo.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/TableInfo.java deleted file mode 100644 index a458c0e62..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/TableInfo.java +++ /dev/null @@ -1,368 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout.table; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.draw2d.IFigure; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.layout.CSSFigure; -import org.eclipse.jst.pagedesigner.css2.layout.ICSSFigure; - -/** - * @author mengbo - * @version 1.5 - */ -public class TableInfo extends TableItemInfo { - List _tableHeaderGroups = new ArrayList(); - - List _tableTRandTRGs = new ArrayList(); - - List _tableFooterGroups = new ArrayList(); - - TableCaptionInfo _caption; - - int _columnCount; - - int _rowCount; - - List _cells = null; - - private List _rows = null; - - int _tableWidth; // calculated table width, valid after calling to - - // calculateTableWidth - - int _availableWidth; - - int _tableHeight; - - private int[] _widthPercentage; - - private int[] _heightPercentage; - - boolean[] _widthSpecified; - - /** - * @param figure - */ - public TableInfo(ICSSFigure figure) { - super(figure); - } - - public List getTableHeaderGroups() { - return _tableHeaderGroups; - } - - public List getTRandTRGs() { - return _tableTRandTRGs; - } - - public List getTableFooterGroups() { - return _tableFooterGroups; - } - - public int getColumnCount() { - return _columnCount; - } - - public int getRowCount() { - return _rowCount; - } - - protected void constructTable() { - List child = getFigure().getChildren(); - for (int i = 0, size = child.size(); i < size; i++) { - IFigure childfigure = (IFigure) child.get(i); - if (childfigure instanceof ICSSFigure) { - ICSSStyle style = ((ICSSFigure) childfigure).getCSSStyle(); - if (style != null) { - String display = style.getDisplay(); - if ("table-caption".equalsIgnoreCase(display)) //$NON-NLS-1$ - { - _caption = new TableCaptionInfo( - (ICSSFigure) childfigure); - } else if ("table-row".equalsIgnoreCase(display)) //$NON-NLS-1$ - { - TableRowInfo rowInfo = new TableRowInfo( - (ICSSFigure) childfigure); - _tableTRandTRGs.add(rowInfo); - } else if ("table-row-group".equalsIgnoreCase(display)) //$NON-NLS-1$ - { - TableRowGroupInfo groupInfo = new TableRowGroupInfo( - (ICSSFigure) childfigure); - _tableTRandTRGs.add(groupInfo); - } else if ("table-header-group".equalsIgnoreCase(display)) //$NON-NLS-1$ - { - TableRowGroupInfo groupInfo = new TableRowGroupInfo( - (ICSSFigure) childfigure); - _tableHeaderGroups.add(groupInfo); - } else if ("table-footer-group".equalsIgnoreCase(display)) //$NON-NLS-1$ - { - TableRowGroupInfo groupInfo = new TableRowGroupInfo( - (ICSSFigure) childfigure); - _tableFooterGroups.add(groupInfo); - } else { - // something unexpected inside table - } - } else { - // something unexpected inside table - } - } else { - // something unexpected inside table - } - } - - TableInfoContext context = new TableInfoContext(); - // now we have the rows ordered, need to calculate row details now. - for (int i = 0, size = _tableHeaderGroups.size(); i < size; i++) { - TableRowGroupInfo groupInfo = (TableRowGroupInfo) _tableHeaderGroups - .get(i); - groupInfo.calculateRowGroup(context); - } - for (int i = 0, size = _tableTRandTRGs.size(); i < size; i++) { - Object obj = _tableTRandTRGs.get(i); - if (obj instanceof TableRowGroupInfo) { - TableRowGroupInfo groupInfo = (TableRowGroupInfo) obj; - groupInfo.calculateRowGroup(context); - } else { - TableRowInfo rowInfo = (TableRowInfo) obj; - rowInfo.calculateRow(context); - } - } - for (int i = 0, size = _tableFooterGroups.size(); i < size; i++) { - TableRowGroupInfo groupInfo = (TableRowGroupInfo) _tableFooterGroups - .get(i); - groupInfo.calculateRowGroup(context); - } - context.finishTable(); - - _columnCount = context.getColumnCount(); - _rowCount = context.getRowCount(); - - this._widthPercentage = new int[_columnCount]; - this._heightPercentage = new int[_rowCount]; - - this._widthSpecified = new boolean[_columnCount]; - for (int i = 0; i < _columnCount; i++) { - this._widthSpecified[i] = false; - } - } - - public void setWidthPercentage(int columnIndex, int percentageValue) { - if (percentageValue > this._widthPercentage[columnIndex]) { - this._widthPercentage[columnIndex] = percentageValue; - } - } - - public void setHeightPercentage(int rowIndex, int percentageValue) { - if (percentageValue > this._heightPercentage[rowIndex]) { - this._heightPercentage[rowIndex] = percentageValue; - } - } - - /** - * width percentage will be used to calculate remaining width distribution. - * - * @return - */ - public int[] getWidthPercentages() { - return this._widthPercentage; - } - - public int[] getHeightPercentages() { - return this._heightPercentage; - } - - public List getRows() { - if (_rows == null) { - this._rows = new ArrayList(); - - for (int i = 0, size = _tableHeaderGroups.size(); i < size; i++) { - TableRowGroupInfo groupInfo = (TableRowGroupInfo) _tableHeaderGroups - .get(i); - _rows.addAll(groupInfo.getRowList()); - } - for (int i = 0, size = _tableTRandTRGs.size(); i < size; i++) { - Object obj = _tableTRandTRGs.get(i); - if (obj instanceof TableRowGroupInfo) { - TableRowGroupInfo groupInfo = (TableRowGroupInfo) obj; - _rows.addAll(groupInfo.getRowList()); - } else { - TableRowInfo rowInfo = (TableRowInfo) obj; - _rows.add(rowInfo); - } - } - for (int i = 0, size = _tableFooterGroups.size(); i < size; i++) { - TableRowGroupInfo groupInfo = (TableRowGroupInfo) _tableFooterGroups - .get(i); - _rows.addAll(groupInfo.getRowList()); - } - } - return _rows; - } - - public List getCells() { - if (_cells == null) { - _cells = new ArrayList(); - - for (int i = 0, size = _tableHeaderGroups.size(); i < size; i++) { - TableRowGroupInfo groupInfo = (TableRowGroupInfo) _tableHeaderGroups - .get(i); - groupInfo.getCells(_cells); - } - for (int i = 0, size = _tableTRandTRGs.size(); i < size; i++) { - Object obj = _tableTRandTRGs.get(i); - if (obj instanceof TableRowGroupInfo) { - TableRowGroupInfo groupInfo = (TableRowGroupInfo) obj; - groupInfo.getCells(_cells); - } else { - TableRowInfo rowInfo = (TableRowInfo) obj; - rowInfo.getCells(_cells); - } - } - for (int i = 0, size = _tableFooterGroups.size(); i < size; i++) { - TableRowGroupInfo groupInfo = (TableRowGroupInfo) _tableFooterGroups - .get(i); - groupInfo.getCells(_cells); - } - } - return _cells; - } - - /** - * @param containerWidth - * if the width specification is percentage, then will use - * container width. - */ - public void calculateWidth(int contentWidth, int availableWidth) { - _tableWidth = contentWidth; - _availableWidth = availableWidth; - - // next calculate cell width - List cells = getCells(); - for (int i = 0, size = cells.size(); i < size; i++) { - TableCellInfo cellinfo = (TableCellInfo) cells.get(i); - cellinfo.calculateWidth(this, _tableWidth); - } - } - - public void calculateHeight(int contentHeight) { - _tableHeight = contentHeight; - - List rows = getRows(); - for (int i = 0, size = rows.size(); i < size; i++) { - TableRowInfo rowinfo = (TableRowInfo) rows.get(i); - rowinfo.calculateHeight(this, _tableHeight); - } - - // next calculate cell width - List cells = getCells(); - for (int i = 0, size = cells.size(); i < size; i++) { - TableCellInfo cellinfo = (TableCellInfo) cells.get(i); - cellinfo.calculateHeight(this, _tableHeight); - } - } - - /** - * @return - */ - public int getTableWidth() { - return _tableWidth; - } - - /** - * @param figure - * @return - */ - public TableRowGroupInfo findGroupInfo(CSSFigure figure) { - for (int i = 0, size = _tableHeaderGroups.size(); i < size; i++) { - TableRowGroupInfo groupInfo = (TableRowGroupInfo) _tableHeaderGroups - .get(i); - if (figure == groupInfo.getFigure()) { - return groupInfo; - } - } - for (int i = 0, size = _tableTRandTRGs.size(); i < size; i++) { - Object obj = _tableTRandTRGs.get(i); - if (obj instanceof TableRowGroupInfo) { - TableRowGroupInfo groupInfo = (TableRowGroupInfo) obj; - if (figure == groupInfo.getFigure()) { - return groupInfo; - } - - } - } - for (int i = 0, size = _tableFooterGroups.size(); i < size; i++) { - TableRowGroupInfo groupInfo = (TableRowGroupInfo) _tableFooterGroups - .get(i); - if (figure == groupInfo.getFigure()) { - return groupInfo; - } - } - return null; // should not happen. - } - - /** - * @param figure - * @return - */ - public TableRowInfo findRowInfo(CSSFigure figure) { - for (int i = 0, size = _tableHeaderGroups.size(); i < size; i++) { - TableRowGroupInfo groupInfo = (TableRowGroupInfo) _tableHeaderGroups - .get(i); - TableRowInfo rowinfo = groupInfo.findRowInfo(figure); - if (rowinfo != null) { - return rowinfo; - } - } - for (int i = 0, size = _tableTRandTRGs.size(); i < size; i++) { - Object obj = _tableTRandTRGs.get(i); - if (obj instanceof TableRowGroupInfo) { - TableRowGroupInfo groupInfo = (TableRowGroupInfo) obj; - TableRowInfo rowinfo = groupInfo.findRowInfo(figure); - if (rowinfo != null) { - return rowinfo; - } - } else if (obj instanceof TableRowInfo) { - TableRowInfo info = (TableRowInfo) obj; - if (figure == info.getFigure()) { - return info; - } - } - } - for (int i = 0, size = _tableFooterGroups.size(); i < size; i++) { - TableRowGroupInfo groupInfo = (TableRowGroupInfo) _tableFooterGroups - .get(i); - TableRowInfo rowinfo = groupInfo.findRowInfo(figure); - if (rowinfo != null) { - return rowinfo; - } - } - return null; // should not happen. - } - - /** - * - * @return - */ - public boolean hasWidthPercentage() { - for (int i = 0; i < this._widthPercentage.length; i++) { - if (this._widthPercentage[i] > 0) { - return true; - } - } - return false; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/TableInfoContext.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/TableInfoContext.java deleted file mode 100644 index 87ffa6897..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/TableInfoContext.java +++ /dev/null @@ -1,114 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout.table; - -import org.eclipse.jst.jsf.common.ui.internal.logging.Logger; -import org.eclipse.jst.pagedesigner.PDPlugin; -import org.eclipse.jst.pagedesigner.utils.IntFlexArray; - -/** - * @author mengbo - * @version 1.5 - */ -public class TableInfoContext { - static Logger _log = PDPlugin.getLogger(TableInfoContext.class); - - int _currentCol = 0; - - int _currentRow = 0; - - IntFlexArray _array = new IntFlexArray(); - - int _colCount = 0; - - int _rowCount = 0; - - /** - * - */ - public TableInfoContext() { - // do nothing - } - - /** - * @return - */ - public IntFlexArray getIntFlexArray() { - return _array; - } - - /** - * @return - */ - public int getCurrentCol() { - return _currentCol; - } - - public void setCurrentCol(int currentcol) { - _currentCol = currentcol; - } - - public int getCurrentRow() { - return _currentRow; - } - - /** - * @return - */ - public int getColumnCount() { - return _colCount; - } - - /** - * - */ - public void finishRow() { - if (_currentCol > _colCount) { - _colCount = _currentCol; - } - _currentCol = 0; - _currentRow++; - for (int i = 0; i < _colCount; i++) { - if (_array.getAt(i) > 0) { - _array.setAt(i, _array.getAt(i) - 1); - } - } - } - - /** - * - */ - public void finishTable() { - // do some checking here. - int additionalRow = 0; - for (int i = 0; i < _colCount; i++) { - if (_array.getAt(i) > additionalRow) { - additionalRow = _array.getAt(i); - } - } - _rowCount = _currentRow + additionalRow; - } - - /** - * - */ - public void finishRowGroup() { - // TODO: does nothing; only called in one places - } - - /** - * @return - */ - public int getRowCount() { - return _rowCount; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/TableItemInfo.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/TableItemInfo.java deleted file mode 100644 index 33c6e12e3..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/TableItemInfo.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout.table; - -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.layout.ICSSFigure; - -/** - * @author mengbo - * @version 1.5 - */ -public class TableItemInfo { - public ICSSFigure _figure; - - /** - * - */ - public TableItemInfo(ICSSFigure figure) { - _figure = figure; - } - - public ICSSFigure getFigure() { - return _figure; - } - - public ICSSStyle getStyle() { - return _figure.getCSSStyle(); - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/TableRowGroupInfo.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/TableRowGroupInfo.java deleted file mode 100644 index d9ae2feb3..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/TableRowGroupInfo.java +++ /dev/null @@ -1,103 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout.table; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.draw2d.IFigure; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.layout.CSSFigure; -import org.eclipse.jst.pagedesigner.css2.layout.ICSSFigure; - -/** - * @author mengbo - * @version 1.5 - */ -public class TableRowGroupInfo extends TableItemInfo { - List _rowList = new ArrayList(); - - private int _rowIndex; - - private int _rowCount; - - /** - * @param figure - */ - public TableRowGroupInfo(ICSSFigure figure) { - super(figure); - } - - public List getRowList() { - return _rowList; - } - - public int getRowIndex() { - return _rowIndex; - } - - public int getRowCount() { - return this._rowCount; - } - - /** - * @param context - */ - public void calculateRowGroup(TableInfoContext context) { - this._rowIndex = context.getCurrentRow(); - List children = getFigure().getChildren(); - for (int i = 0, size = children.size(); i < size; i++) { - IFigure childfigure = (IFigure) children.get(i); - if (childfigure instanceof ICSSFigure) { - ICSSStyle childstyle = ((ICSSFigure) childfigure).getCSSStyle(); - if (childstyle != null - && "table-row" - .equalsIgnoreCase(childstyle.getDisplay())) { - TableRowInfo rowInfo = new TableRowInfo( - (ICSSFigure) childfigure); - _rowList.add(rowInfo); - rowInfo.calculateRow(context); - } else { - // skip - } - } else { - // skip - } - } - context.finishRowGroup(); - this._rowCount = context.getCurrentRow() - this._rowIndex; - } - - /** - * @param _cells - */ - public void getCells(List _cells) { - for (int i = 0, size = _rowList.size(); i < size; i++) { - TableRowInfo rowInfo = (TableRowInfo) _rowList.get(i); - rowInfo.getCells(_cells); - } - } - - /** - * @param figure - * @return - */ - public TableRowInfo findRowInfo(CSSFigure figure) { - for (int i = 0, size = _rowList.size(); i < size; i++) { - TableRowInfo rowInfo = (TableRowInfo) _rowList.get(i); - if (figure == rowInfo.getFigure()) { - return rowInfo; - } - } - return null; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/TableRowInfo.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/TableRowInfo.java deleted file mode 100644 index f305d0dfd..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/layout/table/TableRowInfo.java +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.layout.table; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.draw2d.IFigure; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.layout.CSSFigure; -import org.eclipse.jst.pagedesigner.css2.layout.ICSSFigure; -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyID; -import org.eclipse.jst.pagedesigner.css2.value.Length; - -/** - * @author mengbo - * @version 1.5 - */ -public class TableRowInfo extends TableItemInfo { - List _cells = new ArrayList(); - - int _rowIndex; - - private int _rowHeight; - - /** - * @param figure - */ - public TableRowInfo(ICSSFigure figure) { - super(figure); - } - - public List getCells() { - return _cells; - } - - public int getRowIndex() { - return _rowIndex; - } - - public int getSpecifiedRowHeight() { - return _rowHeight; - } - - /** - * @param context - */ - public void calculateRow(TableInfoContext context) { - this._rowIndex = context.getCurrentRow(); - - List children = getFigure().getChildren(); - for (int i = 0, size = children.size(); i < size; i++) { - IFigure childfigure = (IFigure) children.get(i); - if (childfigure instanceof ICSSFigure) { - ICSSStyle childstyle = ((ICSSFigure) childfigure).getCSSStyle(); - if (childstyle != null) { - String display = childstyle.getDisplay(); - if ("table-cell".equalsIgnoreCase(display)) { - TableCellInfo cellInfo = new TableCellInfo( - (ICSSFigure) childfigure); - cellInfo.calculateCellInfo(context); - _cells.add(cellInfo); - } else { - // skip - } - } - } else { - // skip - } - } - // ok, we have finished a row - context.finishRow(); - } - - /** - * @param _cells2 - */ - public void getCells(List cells) { - cells.addAll(this._cells); - } - - /** - * @param figure - * @return - */ - public TableCellInfo getCellInfo(CSSFigure figure) { - for (int i = 0, size = _cells.size(); i < size; i++) { - TableCellInfo cellinfo = (TableCellInfo) _cells.get(i); - if (cellinfo.getFigure() == figure) { - return cellinfo; - } - } - return null; - } - - /** - * @param info - * @param height - */ - public void calculateHeight(TableInfo info, int tableHeight) { - ICSSStyle style = this.getFigure().getCSSStyle(); - if (style == null) { - this._rowHeight = -1; - } else { - Object height = style.getStyleProperty(ICSSPropertyID.ATTR_HEIGHT); - Length recommendedHeight = (height instanceof Length) ? (Length) height - : null; - - int rh = 0; - if (recommendedHeight == null || recommendedHeight.getValue() <= 0) { - rh = 0; - } else { - if (recommendedHeight.isPercentage()) { - // not supported. - } else { - rh = recommendedHeight.getValue(); - } - if (rh > 0 && !style.isSizeIncludeBorderPadding()) { - rh += style.getBorderInsets().getHeight() - + style.getPaddingInsets().getHeight(); - } - } - this._rowHeight = rh; - } - - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/CSSHtmlListStyleData.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/CSSHtmlListStyleData.java deleted file mode 100644 index 971199224..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/CSSHtmlListStyleData.java +++ /dev/null @@ -1,127 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.list; - -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyID; -import org.eclipse.swt.graphics.Image; - -/** - * @author mengbo - */ -public class CSSHtmlListStyleData { - public final static int LIST_T_IMAGE = 0; - - public final static int LIST_T_DISC = 1; - - public final static int LIST_T_CIRCLE = 2; - - public final static int LIST_T_SQUARE = 3; - - public final static int LIST_T_DECIMAL = 0x11; - - public final static int LIST_T_DECIMAL_LEADING_ZERO = 0x12; - - public final static int LIST_T_LOWER_ALPHA = 0x13; - - public final static int LIST_T_LOWER_ROMAN = 0x14; - - public final static int LIST_T_UPPER_ALPHA = 0x15; - - public final static int LIST_T_UPPER_ROMAN = 0x16; - - //private CSSMarkerStyleData _markerStyleData; - - private Image _markerImage; - - private int _type; - - public boolean isDefaultPicture() { - return (_type & 0xf) != 0; - } - - private String getResolvedURL() { - //String textValue = _markerStyleData.getTextContent(); - // TODO: when I found this, resolver was not being set and would either - // have thrown NPE or returned "".. so I've "improved it :) - //URIResolver resolver = null;// FIXME: this is not implemented yet. - // DesignerPropertyTool.getModel().getResolver(); - //if (textValue != null && textValue.length() > 0) { - // return resolver.getLocationByURI(textValue); - //} - return ""; - } - - /** - * @return Returns the markerImage. - */ - public Image getMarkerImage() { - if (!this.isImage()) { - return null; - } - if (_markerImage == null) { - String uri = this.getResolvedURL(); - _markerImage = new Image(null, uri); - } - return _markerImage; - } - - /** - * @return Returns the type. - */ - public int getType() { - return _type; - } - - public void setType(String type) { - - this._type = toTypeInt(type); - } - - /** - * @return Returns the markerString. - */ - public String getTextValue(int index) { - if (!this.isText()) { - return null; - } - // ICounter counter = CounterFactory.getInstance().getCounter(_type); - return ""; - - } - - public boolean isText() { - return (_type & 0xf0) != 0; - } - - public boolean isImage() { - return (_type == LIST_T_IMAGE); - } - - public static int toTypeInt(String type) { - if (type.equalsIgnoreCase(ICSSPropertyID.VAL_DECIMAL)) { - return LIST_T_DECIMAL; - } else if (type - .equalsIgnoreCase(ICSSPropertyID.VAL_DECIMAL_LEADING_ZERO)) { - return LIST_T_DECIMAL_LEADING_ZERO; - } else if (type.equalsIgnoreCase(ICSSPropertyID.VAL_DISC)) { - return LIST_T_DISC; - } else if (type.equalsIgnoreCase(ICSSPropertyID.VAL_CIRCLE)) { - return LIST_T_CIRCLE; - } else if (type.equalsIgnoreCase(ICSSPropertyID.VAL_SQUARE)) { - return LIST_T_SQUARE; - } else if (type.equalsIgnoreCase(ICSSPropertyID.VAL_IMAGE)) { - return LIST_T_IMAGE; - } - - return 0; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/CSSMarkerStyleData.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/CSSMarkerStyleData.java deleted file mode 100644 index 0fcbb6e39..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/CSSMarkerStyleData.java +++ /dev/null @@ -1,89 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.list; - -import java.util.Vector; - -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyID; - -/** - * @author mengbo - */ -public class CSSMarkerStyleData { - private Vector _content; - - private String _textContent; - - private int _Offset; - - private boolean _isOutside; - - /** - * @return Returns the isBefore. - */ - public boolean isOutside() { - return _isOutside; - } - - /** - * @param isOutside - * The isBefore to set. - */ - public void setPosition(String position) { - if (position == ICSSPropertyID.VAL_INSIDE) { - _isOutside = false; - } else if (position == ICSSPropertyID.VAL_OUTSIDE) { - _isOutside = true; - } - } - - /** - * @return Returns the _Offset. - */ - public int getOffset() { - return _Offset; - } - - /** - * @param offset - * The _Offset to set. - */ - public void setOffset(int offset) { - _Offset = offset; - } - - /** - * @return Returns the _textValue. - */ - public String getTextContent() { - return _textContent; - } - - /** - * @param value - * The _textValue to set. - */ - public void setTextContent(String value) { - _textContent = value; - } - - public Object getNextElement() { - if (_content == null || _content.size() == 0) { - return null; - } - return _content.remove(0); - } - - public void setContent(Vector content) { - _content = content; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/ContentObject.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/ContentObject.java deleted file mode 100644 index 5d666f725..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/ContentObject.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.list; - -/** - * A simple template objec, when we resole content in detail, we will create - * more complicated object reference structure. - * - * @author mengbo - */ -public class ContentObject { - private ICounterValueGenerator _counter; - - /** - * @return Returns the _counter. - */ - public ICounterValueGenerator getCounter() { - return _counter; - } - - /** - * @param _counter - * The _counter to set. - */ - public void setCounter(ICounterValueGenerator counter) { - this._counter = counter; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/CounterHelper.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/CounterHelper.java deleted file mode 100644 index 6f7ab71c1..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/CounterHelper.java +++ /dev/null @@ -1,297 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.list; - -import java.util.HashMap; -import java.util.List; - -import org.eclipse.jface.text.Assert; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyID; -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta; -import org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue; -import org.w3c.dom.css.CSSPrimitiveValue; - -/** - * @author mengbo - */ -public class CounterHelper { - public final static int LIST_T_IMAGE = 0; - - public final static int LIST_T_DISC = 1; - - public final static int LIST_T_CIRCLE = 2; - - public final static int LIST_T_SQUARE = 3; - - public final static int LIST_T_DECIMAL = 0x11; - - public final static int LIST_T_DECIMAL_LEADING_ZERO = 0x12; - - public final static int LIST_T_LOWER_ALPHA = 0x13; - - public final static int LIST_T_LOWER_ROMAN = 0x14; - - public final static int LIST_T_UPPER_ALPHA = 0x15; - - public final static int LIST_T_UPPER_ROMAN = 0x16; - - public final static int LIST_T_LOWER_GREEK = 0x21; - - public final static int LIST_T_ARMENIAN = 0x22; - - public final static int LIST_T_GEORGIAN = 0x23; - - public final static int LIST_T_NONE = 0x24; - - // /** - // * Collect counters declaration from node and its parents - // * - // * @param style - // * @param counters - // * @return - // */ - // public static void getCounters(ICSSStyle style, HashMap counters) - // { - // processCounterReset(style, counters); - // Object content = style.getStyleProperty(ICSSPropertyID.ATTR_CONTENT); - // // content counter could be reference or creation of new one. - // if (content != null && content != ICSSPropertyMeta.NOT_SPECIFIED) - // { - // // XXX: what 's the content. - // ContentObject contentObject = null; - // Object counter = null; - // if (content instanceof List) - // { - // // TODO: we only deal with one currently. - // contentObject = (ContentObject) ((List) content).get(0); - // } - // else if (content instanceof ContentObject) - // { - // contentObject = (ContentObject) content; - // } - // if (style.getParentStyle() != null) - // { - // String identifier = contentObject.getCounter().getIdentifier(); - // counter = style.getParentStyle().findCounter(identifier, false); - // if (counter == null) - // { - // // no reference, then create it. - // counter = contentObject.getCounter(); - // } - // } - // Assert.isTrue(counter != null); - // ((Counter2) counter).regist(style); - // counters.put(((Counter2) counter).getIdentifier(), counter); - // } - // // counter-increment is reference. - // processCounterIncrement(style/* , counters */); - // } - - /** - * @param style - * @param counters - */ - public static void processCounterReset(ICSSStyle style, HashMap counters) { - Assert.isTrue(style != null && counters != null); - // counter-reset will create new one. - Object counterResets = style - .getStyleProperty(ICSSPropertyID.ATTR_COUNTER_RESET); - if ((counterResets) != null - && counterResets != ICSSPropertyMeta.NOT_SPECIFIED) { - if (counterResets instanceof List) { - List crList = (List) counterResets; - for (int i = 0, n = crList.size(); i < n; i++) { - ResetObject rObject = (ResetObject) crList.get(i); - String name = rObject.getCounterName(); - Object counter = null; - if (counters.size() > 0 && counters.containsKey(name)) { - // Already resolved - counter = counters.get(name); - } - if (counter != null) { - if (rObject.getInitial() != null) { - ((ICounterValueGenerator) counter) - .resetCount(rObject.getInitial().intValue()); - } else { - counter = ((ICounterValueGenerator) counter) - .resetCount(); - } - counters.put(((ICounterValueGenerator) counter) - .getIdentifier(), counter); - } else { - // create new one - Object listStyle = style - .getStyleProperty(ICSSPropertyID.ATTR_LIST_STYLE_TYPE); - if (listStyle instanceof String) { - counter = new CounterValueGenerator(name, - (String) listStyle, null, style); - if (rObject.getInitial() != null) { - ((ICounterValueGenerator) counter) - .resetCount(rObject.getInitial() - .intValue()); - } else { - counter = ((ICounterValueGenerator) counter) - .resetCount(); - } - } - counters.put(((ICounterValueGenerator) counter) - .getIdentifier(), counter); - } - } - } - } - } - - /** - * @param style - * @param counters - */ - public static void processCounterIncrement(ICSSStyle style/* - * , HashMap - * counters - */) { - Object counterIncrements = style - .getStyleProperty(ICSSPropertyID.ATTR_COUNTER_INCREMENT); - if (counterIncrements != null - && counterIncrements != ICSSPropertyMeta.NOT_SPECIFIED) { - if (counterIncrements instanceof List) { - List crList = (List) counterIncrements; - for (int i = 0, n = crList.size(); i < n; i++) { - IncrementObject rObject = (IncrementObject) crList.get(i); - String name = rObject.getCounterName(); - Object counter = null; - counter = style.findCounter(name, true); - if (counter != null) { - if (HTMLListInfoHelper.getValueInt(style) == null) { - if (rObject.getIncrement() != null) { - ((ICounterValueGenerator) counter) - .increase(rObject.getIncrement() - .intValue()); - } else { - ((ICounterValueGenerator) counter).increase(); - } - } else { - ((ICounterValueGenerator) counter) - .setCount(HTMLListInfoHelper - .getValueInt(style)); - } - } - } - } - } - } - - public static boolean isImage(ICSSStyle style) { - return false; - } - - public static boolean isText(ICSSStyle style) { - String display = style.getDisplay(); - Object styleType = style - .getStyleProperty(ICSSPropertyID.ATTR_LIST_STYLE_TYPE); - return (display - .equalsIgnoreCase(ICSSPropertyID.VAL_LIST_ITEM) // - && styleType instanceof String // - && !CounterValueGenerator.NON_STRING_TYPES.contains(styleType)); - } - - public static boolean isNodeImage(ICSSStyle style) { - return false; - } - - public static int getType(ICSSStyle style) { - Object type = style - .getStyleProperty(ICSSPropertyID.ATTR_LIST_STYLE_TYPE); - if (type instanceof String) { - return toTypeInt((String) type); - } - return -1; - } - - public static int toTypeInt(String type) { - - if (type.equalsIgnoreCase(ICSSPropertyID.VAL_DECIMAL)) { - return LIST_T_DECIMAL; - } else if (type - .equalsIgnoreCase(ICSSPropertyID.VAL_DECIMAL_LEADING_ZERO)) { - return LIST_T_DECIMAL_LEADING_ZERO; - } else if (type.equalsIgnoreCase(ICSSPropertyID.VAL_DISC)) { - return LIST_T_DISC; - } else if (type.equalsIgnoreCase(ICSSPropertyID.VAL_CIRCLE)) { - return LIST_T_CIRCLE; - } else if (type.equalsIgnoreCase(ICSSPropertyID.VAL_SQUARE)) { - return LIST_T_SQUARE; - } else if (type.equalsIgnoreCase(ICSSPropertyID.VAL_IMAGE)) { - return LIST_T_IMAGE; - } else if (type.equalsIgnoreCase(ICSSPropertyID.VAL_UPPER_LATIN)) { - return LIST_T_UPPER_ALPHA; - } else if (type.equalsIgnoreCase(ICSSPropertyID.VAL_UPPER_ALPHA)) { - return LIST_T_UPPER_ALPHA; - } else if (type.equalsIgnoreCase(ICSSPropertyID.VAL_LOWER_LATIN)) { - return LIST_T_LOWER_ALPHA; - } else if (type.equalsIgnoreCase(ICSSPropertyID.VAL_LOWER_ALPHA)) { - return LIST_T_LOWER_ALPHA; - } else if (type.equalsIgnoreCase(ICSSPropertyID.VAL_UPPER_ROMAN)) { - return LIST_T_UPPER_ROMAN; - } else if (type.equalsIgnoreCase(ICSSPropertyID.VAL_LOWER_ROMAN)) { - return LIST_T_LOWER_ROMAN; - } else if (type.equalsIgnoreCase(ICSSPropertyID.VAL_LOWER_GREEK)) { - return LIST_T_LOWER_GREEK; - } else if (type.equalsIgnoreCase(ICSSPropertyID.VAL_ARMENIAN)) { - return LIST_T_ARMENIAN; - } else if (type.equalsIgnoreCase(ICSSPropertyID.VAL_GEORGIAN)) { - return LIST_T_GEORGIAN; - } else if (type.equalsIgnoreCase(ICSSPropertyID.VAL_NONE)) { - return LIST_T_NONE; - } - return 0; - } - - // TODO: for future use we need a new ContentObject to hold other objects - // declares in css style. - - // public static ContentObject getContentObject(ICSSStyle style) - // { - // // TODO: currently we only fetch first counter in case there are more - // than one counters. - // if (style.getStyleProperty(ICSSPropertyID.ATTR_CONTENT) != - // ICSSPropertyMeta.NOT_SPECIFIED) - // { - // Object content = style.getStyleProperty(ICSSPropertyID.ATTR_CONTENT); - // Object object = null; - // if (content instanceof List) - // { - // object = ((List) content).get(0); - // } - // else if (content instanceof ContentObject) - // { - // object = content; - // } - // if (object instanceof ContentObject) - // { - // return (ContentObject) content; - // } - // } - // return null; - // } - - public static boolean isIdentifier(Object cssValue) { - return (cssValue instanceof ICSSPrimitiveValue) - && ((ICSSPrimitiveValue) cssValue).getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT; - } - - public static boolean isNumber(Object cssValue) { - return cssValue instanceof ICSSPrimitiveValue - && ((ICSSPrimitiveValue) cssValue).getPrimitiveType() == ICSSPrimitiveValue.CSS_INTEGER; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/CounterValueGenerator.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/CounterValueGenerator.java deleted file mode 100644 index a13399e94..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/CounterValueGenerator.java +++ /dev/null @@ -1,441 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.list; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.eclipse.jface.text.Assert; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyID; -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta; - -/** - * The counter is used to generate automatic conters and numbering for list - * item. XXX: what do we deal with psedo? and we need to refer to web tools - * content to consult for style content. - * - * @author mengbo - */ -public class CounterValueGenerator implements ICounterValueGenerator { - private final static int DEFAULT_INITIAL_VALUE = 0; - - public static final Set STRING_TYPES = new HashSet(); - - public static final Set NON_STRING_TYPES = new HashSet(); - static { - NON_STRING_TYPES.add("disc"); - NON_STRING_TYPES.add("circle"); - NON_STRING_TYPES.add("square"); - STRING_TYPES.add("decimal"); - STRING_TYPES.add("decimal-leading-zero"); - STRING_TYPES.add("lower-roman"); - STRING_TYPES.add("upper-roman"); - STRING_TYPES.add("lower-greek"); - STRING_TYPES.add("lower-alpha"); - STRING_TYPES.add("lower-latin"); - STRING_TYPES.add("upper-alpha"); - STRING_TYPES.add("upper-latin"); - STRING_TYPES.add("hebrew"); - STRING_TYPES.add("armenian"); - STRING_TYPES.add("georgian"); - STRING_TYPES.add("cjk-ideographic"); - STRING_TYPES.add("hiragana"); - STRING_TYPES.add("katakana"); - STRING_TYPES.add("hiragana-iroha"); - STRING_TYPES.add("katakana-iroha"); - } - - private final static int DEFAULT_INCREMENT = 1; - - private boolean _first = true; - - private Integer _initial; - - private List _visitors; - - private int _count; - - private String _identifier; - - private String _styleType; - - private String _seperator; - - private ICSSStyle _style; - - public CounterValueGenerator(String identifier, String styleType, - String seperator, ICSSStyle style) { - _identifier = identifier; - _styleType = styleType; - _seperator = seperator; - _style = style; - if (HTMLListInfoHelper.getStartInt(style) != null) { - _count = HTMLListInfoHelper.getStartInt(style).intValue(); - } else { - _count = DEFAULT_INITIAL_VALUE; - } - } - - /* - * (non-Javadoc) - * - * @see org.w3c.dom.css.Counter#getIdentifier() - */ - public String getIdentifier() { - return _identifier; - } - - /* - * (non-Javadoc) - * - * @see org.w3c.dom.css.Counter#getListStyle() - */ - public String getListStyle() { - return _styleType; - } - - /* - * (non-Javadoc) - * - * @see org.w3c.dom.css.Counter#getSeparator() - */ - public String getSeparator() { - return _seperator; - } - - // /** - // * @return Returns the type. - // */ - // public String getType() - // { - // return _styleType; - // } - - // /** - // * @return Returns the markerString. - // */ - // public String getTextValue() - // { - // Assert.isTrue(this.isText()); - // _index = getDeclaredIndex(); - // Node container = findParentComtainer(); - // if (container == null) - // { - // // what condition? - // return ""; - // } - // String exp = ""; - // int startIndex = getStartIndex(container); - // int maxLength = calculateMaxlength(container, 0) + startIndex - 1; - // Assert.isTrue(maxLength > 0); - // if (_index == -1) - // { - // // no declared value - // calculateIndex(container); - // Assert.isTrue(_index > -1); - // exp = Integer.toString(_index + startIndex); - // } - // else - // { - // exp = Integer.toString(_index); - // } - // if (getType() == CounterHelper.LIST_T_DECIMAL) - // { - // exp = appendSuffix(exp, Integer.toString(maxLength).length() - - // exp.length()); - // } - // else if (getType() == CounterHelper.LIST_T_DECIMAL_LEADING_ZERO) - // { - // exp = addPrefix(exp, maxLength - exp.length()); - // } - // return exp + "."; - // - // } - - // private String addPrefix(String exp, int length) - // { - // while (length > 0) - // { - // exp = "0" + exp; - // length--; - // } - // return exp; - // } - // - // private String appendSuffix(String exp, int length) - // { - // while (length > 0) - // { - // exp = exp + " "; - // length--; - // } - // return exp; - // } - - // private boolean calculateIndex(Node node) - // { - // if (node == _node) - // { - // _index++; - // return true; - // } - // String name = node.getNodeName(); - // if (name != null && name.equalsIgnoreCase("li")) - // { - // _index++; - // } - // if (!node.hasChildNodes()) - // { - // return false; - // } - // node = node.getFirstChild(); - // while (node != null) - // { - // name = node.getNodeName(); - // if (name != null && !(name.equalsIgnoreCase("ul") || - // name.equalsIgnoreCase("ol"))) - // { - // if (calculateIndex(node)) - // { - // return true; - // } - // } - // node = node.getNextSibling(); - // } - // return false; - // } - - // This method may be refered for the zero-leading calculation. - // private int calculateMaxlength(Node node, int index) - // { - // String name = node.getNodeName(); - // if (name != null && name.equalsIgnoreCase("li")) - // { - // index++; - // } - // if (!node.hasChildNodes()) - // { - // return index; - // } - // node = node.getFirstChild(); - // while (node != null) - // { - // name = node.getNodeName(); - // if (name != null && !(name.equalsIgnoreCase("ul") || - // name.equalsIgnoreCase("ol"))) - // { - // index = calculateMaxlength(node, index); - // } - // node = node.getNextSibling(); - // } - // return index; - // } - // - - // private int getStartIndex(Node container) - // { - // String value = ((Element) container).getAttribute("start"); - // try - // { - // int index = Integer.parseInt(value); - // if (index < 0) - // { - // return 1; - // } - // return index; - // } - // catch (Exception e) - // { - // return 1; - // } - // } - - // private boolean isStringTyped(ICSSStyle style) - // { - // style.getStyleProperty("list-style-type"); - // return true; - // } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#clone() - */ - protected Object clone() throws CloneNotSupportedException { - CounterValueGenerator newInstance = new CounterValueGenerator( - _identifier, _styleType, _seperator, _style); - return newInstance; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.list.Counter2#increase() - */ - public void increase(int increment) { - if (!_first || HTMLListInfoHelper.getStartInt(_style) == null) { - _count += increment; - } - _first = false; - } - - public void increase() { - increase(DEFAULT_INCREMENT); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.list.Counter2#setCount() - */ - public ICounterValueGenerator resetCount() { - try { - ICounterValueGenerator counter = (ICounterValueGenerator) this - .clone(); - _initial = null; - _count = HTMLListInfoHelper.getStartInt(_style) != null ? HTMLListInfoHelper - .getStartInt(_style).intValue() - : DEFAULT_INITIAL_VALUE; - return counter; - } catch (CloneNotSupportedException e) { - return null; - } - } - - /** - * @return Returns the _initial. - */ - public int getInitial() { - if (HTMLListInfoHelper.getStartInt(_style) != null) { - return HTMLListInfoHelper.getStartInt(_style).intValue(); - } - return _initial != null ? _initial.intValue() - : DEFAULT_INITIAL_VALUE; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.list.Counter2#setCount() - */ - public ICounterValueGenerator resetCount(int initial) { - try { - CounterValueGenerator counter = (CounterValueGenerator) this - .clone(); - _initial = new Integer(initial); - _count = initial; - return counter; - } catch (CloneNotSupportedException e) { - return null; - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.list.ICounterValueGenerator#setCount(org.eclipse.jst.pagedesigner.css2.list.HTMLListInfo) - */ - public void setCount(Integer value) { - if (value != null) { - _count = value.intValue(); - _first = false; - } - } - - // /** - // * The clients of this counter need to regist them. - // * - // * @see - // org.eclipse.jst.pagedesigner.css2.list.Counter2#regist(java.lang.Object) - // */ - // public void regist(Object caller) - // { - // Assert.isTrue(caller instanceof ICSSStyle); - // if (_visitors == null) - // { - // _visitors = new LinkedList(); - // } - // if (!_visitors.contains(caller)) - // { - // _visitors.add(caller); - // } - // } - // - // /** - // * (non-Javadoc) - // * - // * @see - // org.eclipse.jst.pagedesigner.css2.list.Counter2#unregist(java.lang.Object) - // */ - // public void unregist(Object caller) - // { - // if (_visitors.contains(caller)) - // { - // _visitors.remove(caller); - // } - // } - - /** - * Return the int value. - * - * @author mengbo - */ - public int getCurrentCount() { - return _count; - } - - /** - * Currently we recalculate the count, to enhance the performance, we may - * use _count, but this requires delicate synchronization when the - * calculation is looped. - */ - public Integer getCount(Object oCaller) { - Assert.isTrue(oCaller instanceof ICSSStyle && _visitors != null - && _visitors.size() > 0); - ICSSStyle caller = (ICSSStyle) oCaller; - if (!_visitors.contains(caller)) { - return null; - } - int result = getInitial(); - - for (int i = 0, n = _visitors.size(); i < n; i++) { - ICSSStyle style = (ICSSStyle) _visitors.get(i); - // get the count; - Object counterIncrements = style - .getStyleProperty(ICSSPropertyID.ATTR_COUNTER_INCREMENT); - if (counterIncrements != null - && counterIncrements != ICSSPropertyMeta.NOT_SPECIFIED) { - if (counterIncrements instanceof List) { - List crList = (List) counterIncrements; - for (int j = 0, nn = crList.size(); j < nn; j++) { - IncrementObject rObject = (IncrementObject) crList - .get(j); - String name = rObject.getCounterName(); - if (getIdentifier().equalsIgnoreCase(name)) { - if (rObject.getIncrement() != null) { - result += rObject.getIncrement().intValue(); - } else { - result += DEFAULT_INCREMENT; - } - } - } - } - } - if (style == caller) { - return new Integer(result); - } - } - return null; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/HTMLListInfoHelper.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/HTMLListInfoHelper.java deleted file mode 100644 index 01b660fdf..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/HTMLListInfoHelper.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.list; - -import org.eclipse.jst.pagedesigner.IHTMLConstants; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.style.AbstractStyle; -import org.eclipse.jst.pagedesigner.dom.EditModelQuery; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -/** - * Resolve the attrbites 'start' on 'ol' and 'value' on 'li'. - * - * @author mengbo - */ -public class HTMLListInfoHelper { - /** - * @return Returns the start. - */ - private static String getStart(ICSSStyle _style) { - if (_style instanceof AbstractStyle) { - Element element = ((AbstractStyle) _style).getElement(); - Node parent = null; - if ((parent = EditModelQuery.getParent(IHTMLConstants.TAG_OL, - element, true)) != null) { - return ((Element) parent) - .getAttribute(IHTMLConstants.ATTR_START); - } - } - return null; - } - - public static Integer getStartInt(ICSSStyle style) { - try { - return new Integer(getStart(style)); - } catch (Exception e) { - return null; - } - } - - /** - * @return Returns the value. - */ - private static String getValue(ICSSStyle _style) { - if (_style instanceof AbstractStyle) { - Element element = ((AbstractStyle) _style).getElement(); - if (element != null) { - return element.getAttribute(IHTMLConstants.ATTR_VALUE); - } - } - return null; - } - - public static Integer getValueInt(ICSSStyle style) { - try { - return Integer.valueOf(getValue(style)); - } catch (NumberFormatException ex) { - return null; - } - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/ICounterValueGenerator.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/ICounterValueGenerator.java deleted file mode 100644 index 86c979302..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/ICounterValueGenerator.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.list; - -/** - * @author mengbo - */ -public interface ICounterValueGenerator { - public String getIdentifier(); - - public ICounterValueGenerator resetCount(int initial); - - public ICounterValueGenerator resetCount(); - - /* - * Set the counter based on value. - */ - public void setCount(Integer value); - - // public void regist(Object caller); - // public void unregist(Object caller); - - /* - * Increase counter based on declared increment number - */ - public void increase(int increment); - - /* - * Increase counter with default increment number(1) - */ - public void increase(); - - public Integer getCount(Object caller); - - public int getCurrentCount(); -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/IIndexConverter.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/IIndexConverter.java deleted file mode 100644 index 152d1dd8f..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/IIndexConverter.java +++ /dev/null @@ -1,19 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.list; - -/** - * @author mengbo - */ -public interface IIndexConverter { - String getString(int index); -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/IncrementObject.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/IncrementObject.java deleted file mode 100644 index 4b2ac8ac3..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/IncrementObject.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.list; - -/** - * @author mengbo - */ -public class IncrementObject { - private String _counterName; - - private Integer _increment; - - public IncrementObject(String name, Integer increment) { - _counterName = name; - _increment = increment; - } - - /** - * @return Returns the _counterName. - */ - public String getCounterName() { - return _counterName; - } - - /** - * @param name - * The _counterName to set. - */ - public void setCounterName(String name) { - _counterName = name; - } - - /** - * @return Returns the _increment. - */ - public Integer getIncrement() { - return _increment; - } - - /** - * @param _increment - * The _increment to set. - */ - public void setIncrement(Integer _increment) { - this._increment = _increment; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/ListStyleUtil.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/ListStyleUtil.java deleted file mode 100644 index 5412580b3..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/ListStyleUtil.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.list; - -/** - * @author mengbo - */ -public class ListStyleUtil { - public static String convertTypeToString(int type, int index) { - if (type == CSSHtmlListStyleData.LIST_T_LOWER_ROMAN - || type == CSSHtmlListStyleData.LIST_T_UPPER_ROMAN) { - // TODO: to implement roman. - // return decimalToRoman(index); - } else if (type == CSSHtmlListStyleData.LIST_T_DECIMAL - || type == CSSHtmlListStyleData.LIST_T_DECIMAL_LEADING_ZERO) { - return Integer.toString(index); - } - return null; - } - -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/ResetObject.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/ResetObject.java deleted file mode 100644 index bfaabf55a..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/list/ResetObject.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.list; - -/** - * @author mengbo - */ -public class ResetObject { - private String _counterName; - - private Integer _initial; - - public ResetObject(String name, Integer initial) { - _counterName = name; - _initial = initial; - } - - /** - * @return Returns the _counterName. - */ - public String getCounterName() { - return _counterName; - } - - /** - * @param name - * The _counterName to set. - */ - public void setCounterName(String name) { - _counterName = name; - } - - /** - * @return Returns the _increment. - */ - public Integer getInitial() { - return _initial; - } - - /** - * @param _initial - * The _increment to set. - */ - public void setInitial(Integer _initial) { - this._initial = _initial; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/marker/CounterFactory.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/marker/CounterFactory.java deleted file mode 100644 index 9a08dd3b4..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/marker/CounterFactory.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.marker; - -import org.eclipse.jst.pagedesigner.css2.list.CSSHtmlListStyleData; - -/** - * @author mengbo - */ -public class CounterFactory { - private static DecimalCounter _decimalCounterInstance; - - private static RomanCounter _romanCounterInstance; - - private static CounterFactory _instance; - - public static CounterFactory getInstance() { - if (_instance == null) { - _instance = new CounterFactory(); - } - return _instance; - } - - public ICounter getCounter(int type) { - switch (type) { - case CSSHtmlListStyleData.LIST_T_DECIMAL: - case CSSHtmlListStyleData.LIST_T_DECIMAL_LEADING_ZERO: - if (_decimalCounterInstance == null) { - _decimalCounterInstance = new DecimalCounter(); - } - return _decimalCounterInstance; - case CSSHtmlListStyleData.LIST_T_LOWER_ROMAN: - case CSSHtmlListStyleData.LIST_T_UPPER_ROMAN: - if (_romanCounterInstance == null) { - _romanCounterInstance = new RomanCounter(); - } - return _romanCounterInstance; - default: - return null; - - } - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/marker/CounterUtil.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/marker/CounterUtil.java deleted file mode 100644 index d1627c7e5..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/marker/CounterUtil.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.marker; - -import org.eclipse.jst.pagedesigner.css2.list.CounterHelper; - -/** - * @author mengbo - */ -public class CounterUtil { - public static String convertCount(int count, int type) { - // XXX: currently we only support style that IE supported.for type that - // does not - // support we return an empty String. - StringBuffer buffer = new StringBuffer(); - switch (type) { - case CounterHelper.LIST_T_DECIMAL: - buffer.append(count); - buffer.append('.'); - break; - case CounterHelper.LIST_T_UPPER_ALPHA: - case CounterHelper.LIST_T_LOWER_ALPHA: - char charA = 'a'; - if (type == CounterHelper.LIST_T_UPPER_ALPHA) { - charA = 'A'; - } - int index = count; - while (index > 0 && index > 26) { - buffer.append((char) (charA + (index / 26) - 1)); - index = index % 26; - } - buffer.append((char) (charA + (index - 1))); - buffer.append("."); - break; - case CounterHelper.LIST_T_UPPER_ROMAN: - case CounterHelper.LIST_T_LOWER_ROMAN: - String string = new RomanCounter().getString(count); - if (type == CounterHelper.LIST_T_LOWER_ROMAN) { - buffer.append(string.toLowerCase()); - } else { - buffer.append(string); - } - buffer.append("."); - break; - case CounterHelper.LIST_T_ARMENIAN: - break; - case CounterHelper.LIST_T_DECIMAL_LEADING_ZERO: - break; - case CounterHelper.LIST_T_LOWER_GREEK: - break; - case CounterHelper.LIST_T_GEORGIAN: - break; - default: - break; - } - return buffer.toString(); - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/marker/DecimalCounter.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/marker/DecimalCounter.java deleted file mode 100644 index 4e8c88f06..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/marker/DecimalCounter.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.marker; - -import org.eclipse.jst.pagedesigner.css2.list.CSSHtmlListStyleData; - -/** - * @author mengbo - */ -public class DecimalCounter extends EnumerableCounter { - protected DecimalCounter() { - // do nothing; restrict construction to child classes - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.list.EnumerableCounter#getString(int) - */ - public String getNextString(int index, int type) { - //String result; - switch (type) { - case CSSHtmlListStyleData.LIST_T_DECIMAL: - return Integer.toString(index); - - case CSSHtmlListStyleData.LIST_T_DECIMAL_LEADING_ZERO: - StringBuffer sb = new StringBuffer(); - int count = getChildrenCount(); - for (int i = sb.length(); i < count; i++) { - sb.append('0'); - } - sb.append(Integer.toString(index)); - return sb.toString(); - default: - return null; - } - } - - public int getChildrenCount() { - return 1; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/marker/EnumerableCounter.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/marker/EnumerableCounter.java deleted file mode 100644 index 190d9a31b..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/marker/EnumerableCounter.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.marker; - -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -/** - * @author mengbo - */ -public abstract class EnumerableCounter implements ICounter { - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.list.ICounter#getNextObject(org.w3c.dom.Element, - * java.lang.String) - */ - public Object getNextObject(Element element, int type) { - int index = calculateIndex(element); - return getNextString(index, type); - } - - public int calculateIndex(Element element) { - String tag = element.getLocalName(); - Node parent = element.getParentNode(); - NodeList children = parent.getChildNodes(); - int index = 1; - for (int i = 0; i < children.getLength(); i++) { - Node child = children.item(i); - if (child == element) { - break; - } - if (child.getLocalName().equalsIgnoreCase(tag)) { - index++; - } - } - return index; - } - - public abstract String getNextString(int index, int type); -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/marker/ICounter.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/marker/ICounter.java deleted file mode 100644 index 93d06bbdf..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/marker/ICounter.java +++ /dev/null @@ -1,21 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.marker; - -import org.w3c.dom.Element; - -/** - * @author mengbo - */ -public interface ICounter { - public Object getNextObject(Element element, int type); -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/marker/RomanCounter.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/marker/RomanCounter.java deleted file mode 100644 index b9e9c41ea..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/marker/RomanCounter.java +++ /dev/null @@ -1,121 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.marker; - -import org.eclipse.jst.pagedesigner.css2.list.CSSHtmlListStyleData; - -/** - * @author mengbo - */ -public class RomanCounter extends EnumerableCounter { - protected RomanCounter() { - // do nothing; restrict construction to sub-classes - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.list.EnumerableCounter#getString(int, - * boolean) - */ - public String getNextString(int index, int type) { - switch (type) { - case CSSHtmlListStyleData.LIST_T_LOWER_ROMAN: - return getString(index).toLowerCase(); - case CSSHtmlListStyleData.LIST_T_UPPER_ROMAN: - return getString(index); - default: - return null; - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.list.NumberCounter#getString(int) - */ - public String getString(int index) { - // FIXME: Need to enhance more. - StringBuffer roman = new StringBuffer(); - int a, b, c, d; - a = (index / 1000) * 1000; - b = ((index / 100) % 10) * 100; - c = ((index / 10) % 10) * 10; - d = ((index / 1) % 10) * 1; - - if (a == 1000) - roman.append("M"); - else if (a == 2000) - roman.append("MM"); - else if (a == 3000) - roman.append("MMM"); - - if (b == 100) - roman.append("C"); - else if (b == 200) - roman.append("CC"); - else if (b == 300) - roman.append("CCC"); - else if (b == 400) - roman.append("CD"); - else if (b == 500) - roman.append("D"); - else if (b == 600) - roman.append("DC"); - else if (b == 700) - roman.append("DCC"); - else if (b == 800) - roman.append("DCCC"); - else if (b == 900) - roman.append("CM"); - - if (c == 10) - roman.append("X"); - else if (c == 20) - roman.append("XX"); - else if (c == 30) - roman.append("XXX"); - else if (c == 40) - roman.append("XL"); - else if (c == 50) - roman.append("L"); - else if (c == 60) - roman.append("LX"); - else if (c == 70) - roman.append("LXX"); - else if (c == 80) - roman.append("LXXX"); - else if (c == 90) - roman.append("XC"); - - if (d == 1) - roman.append("I"); - else if (d == 2) - roman.append("II"); - else if (d == 3) - roman.append("III"); - else if (d == 4) - roman.append("IV"); - else if (d == 5) - roman.append("V"); - else if (d == 6) - roman.append("VI"); - else if (d == 7) - roman.append("VII"); - else if (d == 8) - roman.append("VIII"); - else if (d == 9) - roman.append("IX"); - - return roman.toString(); - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/BackgroundColorMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/BackgroundColorMeta.java deleted file mode 100644 index d2674e65b..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/BackgroundColorMeta.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.color.CSSColorManager; -import org.eclipse.jst.pagedesigner.utils.DOMUtil; -import org.w3c.dom.Element; -import org.w3c.dom.css.CSSValue; - -/** - * @author mengbo - */ -public class BackgroundColorMeta extends CSSPropertyMeta { - private static final String[] _keywords = new String[] { ICSSPropertyID.VAL_TRANSPARENT }; - - /** - * @param inherit - * @param initvalue - */ - public BackgroundColorMeta() { - super(false, ICSSPropertyID.VAL_TRANSPARENT); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta#calculateCSSValueResult(org.w3c.dom.css.CSSValue, - * java.lang.String, - * org.eclipse.jst.pagedesigner.css2.property.AbstractStyle) - */ - public Object calculateCSSValueResult(CSSValue value, String propertyName, - ICSSStyle style) { - String text = value.getCssText(); - Object result = CSSColorManager.getInstance().getColor(text); - if (result != null) { - return result; - } - return getInitialValue(propertyName, style); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues() - */ - protected String[] getKeywordValues() { - return _keywords; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta#calculateHTMLAttributeOverride(org.w3c.dom.Element, - * java.lang.String, java.lang.String, - * org.eclipse.jst.pagedesigner.css2.ICSSStyle) - */ - public Object calculateHTMLAttributeOverride(Element element, - String htmltag, String propertyName, ICSSStyle style) { - Object result; - String colorAttr = null; - if (ICSSPropertyID.ATTR_BACKGROUND_COLOR.equalsIgnoreCase(propertyName)) { - colorAttr = DOMUtil.getAttributeIgnoreCase(element, - ICSSPropertyID.ATTR_BGCOLOR); - } - if (colorAttr != null && colorAttr.trim().length() != 0) { - colorAttr = colorAttr.trim(); - result = CSSColorManager.getInstance().getColor(colorAttr); - return result; - } - return null; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/BorderCollapseMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/BorderCollapseMeta.java deleted file mode 100644 index 874a137ef..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/BorderCollapseMeta.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -/** - * @author mengbo - */ -public class BorderCollapseMeta extends CSSPropertyMeta { - static String[] keywords = new String[] { ICSSPropertyID.VAL_COLLAPSE, - ICSSPropertyID.VAL_SEPARATE }; - - /** - * @param inherit - * @param initvalue - */ - public BorderCollapseMeta() { - // XXX: the spec says COLLAPSE is initial value, but seemed that IE - // is using separate as default - super(true, ICSSPropertyID.VAL_SEPARATE); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues() - */ - protected String[] getKeywordValues() { - return keywords; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/BorderColorMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/BorderColorMeta.java deleted file mode 100644 index e91fdbfd8..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/BorderColorMeta.java +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -import org.eclipse.jst.pagedesigner.IHTMLConstants; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.color.CSSColorManager; -import org.eclipse.jst.pagedesigner.utils.DOMUtil; -import org.w3c.dom.Element; -import org.w3c.dom.css.CSSValue; - -/** - * @author mengbo - */ -public class BorderColorMeta extends CSSPropertyMeta { - - private static final String[] _keywords = new String[] { ICSSPropertyID.VAL_TRANSPARENT }; - - /** - * @param inherit - * @param initvalue - */ - public BorderColorMeta() { - super(false, ICSSPropertyID.VAL_TRANSPARENT); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta#calculateCSSValueResult(org.w3c.dom.css.CSSValue, - * java.lang.String, - * org.eclipse.jst.pagedesigner.css2.property.AbstractStyle) - */ - public Object calculateCSSValueResult(CSSValue value, String propertyName, - ICSSStyle style) { - String text = value.getCssText(); - Object result = CSSColorManager.getInstance().getColor(text); - if (result != null) { - return result; - } - return getInitialValue(propertyName, style); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues() - */ - protected String[] getKeywordValues() { - return _keywords; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta#calculateHTMLAttributeOverride(org.w3c.dom.Element, - * java.lang.String, java.lang.String, - * org.eclipse.jst.pagedesigner.css2.ICSSStyle) - */ - public Object calculateHTMLAttributeOverride(Element element, - String htmltag, String propertyName, ICSSStyle style) { - Object result; - String colorAttr = null; - if (IHTMLConstants.TAG_HR.equalsIgnoreCase(htmltag)) { - colorAttr = DOMUtil.getAttributeIgnoreCase(element, - ICSSPropertyID.ATTR_COLOR); - } else if (ICSSPropertyID.ATTR_BACKGROUND_COLOR - .equalsIgnoreCase(propertyName)) { - colorAttr = DOMUtil.getAttributeIgnoreCase(element, - ICSSPropertyID.ATTR_BGCOLOR); - } - if (colorAttr != null && colorAttr.trim().length() != 0) { - colorAttr = colorAttr.trim(); - result = CSSColorManager.getInstance().getColor(colorAttr); - return result; - } - return null; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/BorderSpacingMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/BorderSpacingMeta.java deleted file mode 100644 index 601ec79e8..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/BorderSpacingMeta.java +++ /dev/null @@ -1,119 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -import org.eclipse.jst.pagedesigner.IHTMLConstants; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.value.Length; -import org.eclipse.jst.pagedesigner.utils.DOMUtil; -import org.w3c.dom.Element; -import org.w3c.dom.css.CSSValue; -import org.w3c.dom.css.CSSValueList; - -/** - * The value will always be of type int[2] - * - * @author mengbo - */ -public class BorderSpacingMeta extends CSSPropertyMeta { - public static final int[] INITIAL_SPACING = new int[] { 3, 3 }; - - /** - * @param inherit - * @param initvalue - */ - public BorderSpacingMeta() { - // the specification says "border-spacing" is inherited. But seemed - // browse is not treating it as inherited. So we treat is as not - // inherited. - super(false, INITIAL_SPACING); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues() - */ - protected String[] getKeywordValues() { - return EMPTY_KEYWORDS; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#calculateCSSValueResult(org.w3c.dom.css.CSSValue, - * java.lang.String, - * org.eclipse.jst.pagedesigner.css2.style.AbstractStyle) - */ - public Object calculateCSSValueResult(CSSValue value, String propertyName, - ICSSStyle style) { - if (value == null || value.getCssValueType() == CSSValue.CSS_CUSTOM) { - return INITIAL_SPACING; - } - if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { - int intvalue = toIntValue(value.getCssText(), style); - if (intvalue >= 0) { - return new int[] { intvalue, intvalue }; - } - return INITIAL_SPACING; - } else if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) { - CSSValueList list = (CSSValueList) value; - if (list.getLength() >= 2) { - int i1 = toIntValue(list.item(0).getCssText(), style); - int i2 = toIntValue(list.item(1).getCssText(), style); - if (i1 < 0) { - i1 = 0; - } - if (i2 < 0) { - i2 = 0; - } - return new int[] { i1, i2 }; - } - return INITIAL_SPACING; - } else { - return INITIAL_SPACING; - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#calculateHTMLAttributeOverride(org.w3c.dom.Element, - * java.lang.String, java.lang.String, - * org.eclipse.jst.pagedesigner.css2.ICSSStyle) - */ - public Object calculateHTMLAttributeOverride(Element element, - String htmltag, String propertyName, ICSSStyle style) { - if (IHTMLConstants.TAG_TABLE.equalsIgnoreCase(htmltag)) { - String spacing = DOMUtil.getAttributeIgnoreCase(element, - IHTMLConstants.ATTR_CELLSPACING); - if (spacing != null) { - int intvalue = toIntValue(spacing, style); - if (intvalue >= 0) { - return new int[] { intvalue, intvalue }; - } - } - } - - return super.calculateHTMLAttributeOverride(element, htmltag, - propertyName, style); - } - - protected int toIntValue(String valuetext, ICSSStyle style) { - Object length = LengthMeta.toLength(valuetext, style, PERCENTAGE_NONE, - style.getCSSFont()); - if (length instanceof Length && !((Length) length).isPercentage()) { - return ((Length) length).getValue(); - } - return Integer.MIN_VALUE; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/BorderStyleMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/BorderStyleMeta.java deleted file mode 100644 index e71ff7608..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/BorderStyleMeta.java +++ /dev/null @@ -1,183 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -import org.eclipse.jst.pagedesigner.IHTMLConstants; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.utils.DOMUtil; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -/** - * @author mengbo - */ -public class BorderStyleMeta extends CSSPropertyMeta { - static final String[] KEYWORDS = new String[] { ICSSPropertyID.VAL_NONE, - ICSSPropertyID.VAL_HIDDEN, ICSSPropertyID.VAL_DOTTED, - ICSSPropertyID.VAL_DASHED, ICSSPropertyID.VAL_SOLID, - ICSSPropertyID.VAL_DOUBLE, ICSSPropertyID.VAL_GROOVE, - ICSSPropertyID.VAL_RIDGE, ICSSPropertyID.VAL_INSET, - ICSSPropertyID.VAL_OUTSET }; - - /** - * @param inherit - * @param initvalue - */ - public BorderStyleMeta() { - super(false, ICSSPropertyID.VAL_NONE); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues() - */ - protected String[] getKeywordValues() { - return KEYWORDS; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#calculateHTMLAttributeOverride(org.w3c.dom.Element, - * java.lang.String, java.lang.String, - * org.eclipse.jst.pagedesigner.css2.ICSSStyle) - */ - public Object calculateHTMLAttributeOverride(Element element, - String htmltag, String propertyName, ICSSStyle style) { - if (IHTMLConstants.TAG_TABLE.equalsIgnoreCase(htmltag)) { - return calculateTableOverride(element, propertyName); - } else if (IHTMLConstants.TAG_TD.equalsIgnoreCase(htmltag) - || IHTMLConstants.TAG_TH.equalsIgnoreCase(htmltag)) { - return calculateTDOverride(element, propertyName, style); - } else if (IHTMLConstants.TAG_IMG.equalsIgnoreCase(htmltag)) { - String border = DOMUtil.getAttributeIgnoreCase(element, - IHTMLConstants.ATTR_BORDER); - if (border != null) { - return ICSSPropertyID.VAL_SOLID; - } - } - return super.calculateHTMLAttributeOverride(element, htmltag, - propertyName, style); - } - - /** - * @param element - * @param propertyName - * @return - */ - private Object calculateTDOverride(Element element, String propertyName, - ICSSStyle style) { - // if element is empty, and "empty-cells" property is hide, then we - // don't display border. - Object obj = style.getStyleProperty(ICSSPropertyID.ATTR_EMPTY_CELLS); - if (EmptyCellsMeta.HIDE.equals(obj) && TableUtil.isEmptyCell(element)) { - return ICSSPropertyID.VAL_NONE; - } - - // find containing table first - Node parent = element; - Element tableEle = null; - while ((parent = parent.getParentNode()) != null - && parent instanceof Element) { - if (((Element) parent).getTagName().equalsIgnoreCase( - IHTMLConstants.TAG_TABLE)) { - tableEle = (Element) parent; - break; - } - - } - if (tableEle != null) { - String rules = DOMUtil.getAttributeIgnoreCase(tableEle, - IHTMLConstants.ATTR_RULES); - String borderstr = DOMUtil.getAttributeIgnoreCase(tableEle, - IHTMLConstants.ATTR_BORDER); - if (rules == null || rules.length() == 0) { - if (borderstr == null || "0".equals(borderstr.trim())) { - return ICSSPropertyID.VAL_NONE; - } - return ICSSPropertyID.VAL_TDBORDERSTYLE; - } - // ok, we got a value for rules - if (TableUtil.matchRules(extractEdge(propertyName), rules)) { - return ICSSPropertyID.VAL_TDBORDERSTYLE; - } - return ICSSPropertyID.VAL_NONE; - } - return null; - } - - /** - * @param element - * @param propertyName - * @return - */ - private Object calculateTableOverride(Element element, String propertyName) { - String frame = DOMUtil.getAttributeIgnoreCase(element, - IHTMLConstants.ATTR_FRAME); - String borderstr = DOMUtil.getAttributeIgnoreCase(element, - IHTMLConstants.ATTR_BORDER); - // border="0" implies frame="void" - if ("0".equals(borderstr)) { - return ICSSPropertyID.VAL_NONE; - } - if (frame == null || frame.length() == 0) { - if (borderstr == null) { - return ICSSPropertyID.VAL_NONE; - } else if (borderstr.trim().length() == 0) { - frame = IHTMLConstants.ATTR_BORDER; - } else { - try { - Integer.parseInt(borderstr); - frame = IHTMLConstants.ATTR_BORDER; - } catch (Exception ex) { - frame = borderstr; - } - } - } - // ok, we got a value for frame. - if (TableUtil.matchFrame(extractEdge(propertyName), frame)) { - return ICSSPropertyID.VAL_OUTSET; - } - return ICSSPropertyID.VAL_NONE; - } - - static String extractEdge(String propertyName) { - if (ICSSPropertyID.ATTR_BORDER_BOTTOM_STYLE - .equalsIgnoreCase(propertyName)) { - return "bottom"; - } else if (ICSSPropertyID.ATTR_BORDER_LEFT_STYLE - .equalsIgnoreCase(propertyName)) { - return "left"; - } else if (ICSSPropertyID.ATTR_BORDER_RIGHT_STYLE - .equalsIgnoreCase(propertyName)) { - return "right"; - } else { - return "top"; - } - } - - /** - * @param propertyName - * @return - */ - public static boolean isBorderStyle(String propertyName) { - return ICSSPropertyID.ATTR_BORDER_BOTTOM_STYLE - .equalsIgnoreCase(propertyName) - || ICSSPropertyID.ATTR_BORDER_LEFT_STYLE - .equalsIgnoreCase(propertyName) - || ICSSPropertyID.ATTR_BORDER_RIGHT_STYLE - .equalsIgnoreCase(propertyName) - || ICSSPropertyID.ATTR_BORDER_TOP_STYLE - .equalsIgnoreCase(propertyName); - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/BorderWidthMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/BorderWidthMeta.java deleted file mode 100644 index 8de7cf289..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/BorderWidthMeta.java +++ /dev/null @@ -1,240 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.value.Length; -import org.eclipse.jst.pagedesigner.utils.DOMUtil; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.css.CSSValue; - -/** - * - * @author mengbo - */ -// FIXME: when the border-style is none, how should we treat border-width? -public class BorderWidthMeta extends LengthMeta { - - private static final Length LENGTH_4 = new Length(4, false); - - static final String[] KEYWORDS = new String[] { ICSSPropertyID.VAL_AUTO, - ICSSPropertyID.VAL_THIN, ICSSPropertyID.VAL_MEDIUM, - ICSSPropertyID.VAL_THICK }; - - /** - * @param inherit - * @param initvalue - */ - public BorderWidthMeta() { - super(false, LENGTH_4); // medium length. - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.LengthMeta#getKeywordValues() - */ - protected String[] getKeywordValues() { - return KEYWORDS; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getPercentageType() - */ - public int getPercentageType() { - return PERCENTAGE_NONE; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.LengthMeta#calculateCSSValueResult(org.w3c.dom.css.CSSValue, - * java.lang.String, - * org.eclipse.jst.pagedesigner.css2.style.AbstractStyle) - */ - public Object calculateCSSValueResult(CSSValue value, String propertyName, - ICSSStyle style) { - // Computed value: absolute length; '0' if the border style is 'none' or - // 'hidden' - Object stylevalue = style.getStyleProperty("border-" - + extractEdge(propertyName) + "-style"); - if (ICSSPropertyID.VAL_NONE.equals(stylevalue) - || ICSSPropertyID.VAL_HIDDEN.equals(stylevalue)) { - return Length.LENGTH_0; - } - - Object obj = super.calculateCSSValueResult(value, propertyName, style); - if (ICSSPropertyID.VAL_THIN.equals(obj)) { - return Length.LENGTH_1; - } else if (ICSSPropertyID.VAL_MEDIUM.equals(obj)) { - return Length.LENGTH_3; - } else if (ICSSPropertyID.VAL_THICK.equals(obj)) { - return Length.LENGTH_8; - } - return obj; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#calculateHTMLAttributeOverride(org.w3c.dom.Element, - * java.lang.String, java.lang.String, - * org.eclipse.jst.pagedesigner.css2.ICSSStyle) - */ - public Object calculateHTMLAttributeOverride(Element element, - String htmltag, String propertyName, ICSSStyle style) { - if ("table".equalsIgnoreCase(htmltag)) { - return calculateTableOverride(element, propertyName); - } else if ("td".equalsIgnoreCase(htmltag) - || "th".equalsIgnoreCase(htmltag)) { - return calculateTDOverride(element, propertyName); - } else if ("img".equalsIgnoreCase(htmltag)) { - String border = DOMUtil.getAttributeIgnoreCase(element, "border");// ICSSPropertyID.ATTR_BORDERSIZE); - if (border != null) { - try { - return new Length(Integer.parseInt(border), false); - } catch (Exception ex) { - // Integer processing, no need to report. - } - } - } - - return super.calculateHTMLAttributeOverride(element, htmltag, - propertyName, style); - } - - /** - * @param element - * @param propertyName - * @return - */ - private Object calculateTDOverride(Element element, String propertyName) { - // find containing table first - Node parent = element; - Element tableEle = null; - while ((parent = parent.getParentNode()) != null - && parent instanceof Element) { - if (((Element) parent).getTagName().equalsIgnoreCase("table")) { - tableEle = (Element) parent; - break; - } - - } - if (tableEle != null) { - String rules = DOMUtil.getAttributeIgnoreCase(tableEle, "rules"); - String borderstr = DOMUtil.getAttributeIgnoreCase(tableEle, - "border"); - if (rules == null || rules.length() == 0) { - if (borderstr == null || "0".equals(borderstr.trim())) { - return null; - } - return Length.LENGTH_1; - } - // ok, we got a value for rules - if (TableUtil.matchRules(extractEdge(propertyName), rules)) { - return Length.LENGTH_1; - } - return Length.LENGTH_0; - } - return Length.LENGTH_0; - } - - /** - * @param element - * @param propertyName - * @return - */ - private Object calculateTableOverride(Element element, String propertyName) { - String frame = DOMUtil.getAttributeIgnoreCase(element, "frame"); - String borderstr = DOMUtil.getAttributeIgnoreCase(element, "border"); - // border="0" implies frame="void" - if ("0".equals(borderstr)) { - return Length.LENGTH_0; - } - if (frame == null || frame.length() == 0) { - if (borderstr == null) { - return null; - } else if (borderstr.trim().length() == 0) { - return Length.LENGTH_1; - } else { - try { - return new Length(Integer.parseInt(borderstr), false); - } catch (Exception ex) { - frame = borderstr; - } - } - } - // ok, we got a value for frame. - if (TableUtil.matchFrame(extractEdge(propertyName), frame)) { - if (borderstr != null) { - try { - return new Length(Integer.parseInt(borderstr), false); - } catch (Exception ex) { - // ignore. pass through to return length_1 - } - } - return Length.LENGTH_1; - } - return Length.LENGTH_0; - } - - static String extractEdge(String propertyName) { - if (ICSSPropertyID.ATTR_BORDER_BOTTOM_WIDTH - .equalsIgnoreCase(propertyName)) { - return "bottom"; - } else if (ICSSPropertyID.ATTR_BORDER_LEFT_WIDTH - .equalsIgnoreCase(propertyName)) { - return "left"; - } else if (ICSSPropertyID.ATTR_BORDER_RIGHT_WIDTH - .equalsIgnoreCase(propertyName)) { - return "right"; - } else { - return "top"; - } - } - - /** - * @param propertyName - * @return - */ - public static boolean isBorderWidth(String propertyName) { - return ICSSPropertyID.ATTR_BORDER_BOTTOM_WIDTH - .equalsIgnoreCase(propertyName) - || ICSSPropertyID.ATTR_BORDER_LEFT_WIDTH - .equalsIgnoreCase(propertyName) - || ICSSPropertyID.ATTR_BORDER_RIGHT_WIDTH - .equalsIgnoreCase(propertyName) - || ICSSPropertyID.ATTR_BORDER_TOP_WIDTH - .equalsIgnoreCase(propertyName); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getInitialValue(java.lang.String, - * org.eclipse.jst.pagedesigner.css2.ICSSStyle) - */ - public Object getInitialValue(String propertyName, ICSSStyle style) { - // Computed value: absolute length; '0' if the border style is 'none' or - // 'hidden' - Object stylevalue = style.getStyleProperty("border-" - + extractEdge(propertyName) + "-style"); - if (ICSSPropertyID.VAL_NONE.equals(stylevalue) - || ICSSPropertyID.VAL_HIDDEN.equals(stylevalue)) { - return Length.LENGTH_0; - } - return super.getInitialValue(propertyName, style); - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/CSSMetaRegistry.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/CSSMetaRegistry.java deleted file mode 100644 index be3e05bda..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/CSSMetaRegistry.java +++ /dev/null @@ -1,118 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -import java.util.HashMap; -import java.util.Map; - -/** - * @author mengbo - */ -public class CSSMetaRegistry { - Map _map = new HashMap(); - - private static CSSMetaRegistry _instance; - - private CSSMetaRegistry() { - initialize(); - } - - public void initialize() { - _map.put(ICSSPropertyID.ATTR_DISPLAY, new DisplayMeta()); - _map.put(ICSSPropertyID.ATTR_TEXTALIGN, new TextAlignMeta()); - _map.put(ICSSPropertyID.ATTR_HORIZONTAL_ALIGN, - new HorizontalAlignMeta()); - _map.put(ICSSPropertyID.ATTR_TEXTDECORATION, new TextDecorationMeta()); - _map.put(ICSSPropertyID.ATTR_WHITESPACE, new WhiteSpaceMeta()); - _map.put(ICSSPropertyID.ATTR_WIDTH, new WidthMeta()); - _map.put(ICSSPropertyID.ATTR_MIN_WIDTH, new WidthMeta()); - _map.put(ICSSPropertyID.ATTR_HEIGHT, new HeightMeta()); - _map.put(ICSSPropertyID.ATTR_MIN_HEIGHT, new HeightMeta()); - - _map.put(ICSSPropertyID.ATTR_BORDER_LEFT_WIDTH, new BorderWidthMeta()); - _map.put(ICSSPropertyID.ATTR_BORDER_RIGHT_WIDTH, new BorderWidthMeta()); - _map - .put(ICSSPropertyID.ATTR_BORDER_BOTTOM_WIDTH, - new BorderWidthMeta()); - _map.put(ICSSPropertyID.ATTR_BORDER_TOP_WIDTH, new BorderWidthMeta()); - - _map.put(ICSSPropertyID.ATTR_BORDER_LEFT_STYLE, new BorderStyleMeta()); - _map.put(ICSSPropertyID.ATTR_BORDER_RIGHT_STYLE, new BorderStyleMeta()); - _map - .put(ICSSPropertyID.ATTR_BORDER_BOTTOM_STYLE, - new BorderStyleMeta()); - _map.put(ICSSPropertyID.ATTR_BORDER_TOP_STYLE, new BorderStyleMeta()); - - _map.put(ICSSPropertyID.ATTR_BORDER_LEFT_COLOR, new BorderColorMeta()); - _map.put(ICSSPropertyID.ATTR_BORDER_RIGHT_COLOR, new BorderColorMeta()); - _map - .put(ICSSPropertyID.ATTR_BORDER_BOTTOM_COLOR, - new BorderColorMeta()); - _map.put(ICSSPropertyID.ATTR_BORDER_TOP_COLOR, new BorderColorMeta()); - - _map.put(ICSSPropertyID.ATTR_PADDING_LEFT, new PaddingWidthMeta()); - _map.put(ICSSPropertyID.ATTR_PADDING_RIGHT, new PaddingWidthMeta()); - _map.put(ICSSPropertyID.ATTR_PADDING_BOTTOM, new PaddingWidthMeta()); - _map.put(ICSSPropertyID.ATTR_PADDING_TOP, new PaddingWidthMeta()); - - _map.put(ICSSPropertyID.ATTR_MARGIN_LEFT, new MarginWidthMeta()); - _map.put(ICSSPropertyID.ATTR_MARGIN_RIGHT, new MarginWidthMeta()); - _map.put(ICSSPropertyID.ATTR_MARGIN_BOTTOM, new MarginWidthMeta()); - _map.put(ICSSPropertyID.ATTR_MARGIN_TOP, new MarginWidthMeta()); - - _map.put(ICSSPropertyID.ATTR_FONT_FAMILY, new FontFamilyMeta()); - _map.put(ICSSPropertyID.ATTR_FONT_SIZE, new FontSizeMeta()); - _map.put(ICSSPropertyID.ATTR_FONT_STYLE, new FontStyleMeta()); - _map.put(ICSSPropertyID.ATTR_FONT_WEIGHT, new FontWeightMeta()); - - _map.put(ICSSPropertyID.ATTR_BACKGROUND_COLOR, - new BackgroundColorMeta()); - _map.put(ICSSPropertyID.ATTR_COLOR, new ColorPropertyMeta()); - _map.put(ICSSPropertyID.ATTR_TEXTCOLOR, new ColorPropertyMeta()); - - _map.put(ICSSPropertyID.ATTR_BORDER_COLLAPSE, new BorderCollapseMeta()); - _map.put(ICSSPropertyID.ATTR_BORDER_SPACING, new BorderSpacingMeta()); - - _map.put(ICSSPropertyID.ATTR_LIST_STYLE_TYPE, new ListStyleTypeMeta()); - _map - .put(ICSSPropertyID.ATTR_LIST_STYLE_IMAGE, - new ListStyleImageMeta()); - _map.put(ICSSPropertyID.ATTR_LIST_STYLE_POSITION, - new ListStylePositionMeta()); - _map.put(ICSSPropertyID.ATTR_COUNTER_RESET, new CounterResetMeta()); - _map.put(ICSSPropertyID.ATTR_COUNTER_INCREMENT, - new CounterIncrementMeta()); - - _map.put(ICSSPropertyID.ATTR_TOP, new PositionOffsetMeta()); - _map.put(ICSSPropertyID.ATTR_RIGHT, new PositionOffsetMeta()); - _map.put(ICSSPropertyID.ATTR_BOTTOM, new PositionOffsetMeta()); - _map.put(ICSSPropertyID.ATTR_LEFT, new PositionOffsetMeta()); - _map.put(ICSSPropertyID.ATTR_POSITION, new PositionMeta()); - - _map.put(ICSSPropertyID.ATTR_EMPTY_CELLS, new EmptyCellsMeta()); - _map.put(ICSSPropertyID.ATTR_VISIBILITY, new VisibilityMeta()); - _map.put(ICSSPropertyID.ATTR_VERTICAL_ALIGN, new VerticalAlignMeta()); - - _map.put(ICSSPropertyID.ATTR_OVERFLOW, new OverflowMeta()); - } - - public ICSSPropertyMeta getMeta(String property) { - return (ICSSPropertyMeta) _map.get(property); - } - - public static final CSSMetaRegistry getInstance() { - if (_instance == null) { - _instance = new CSSMetaRegistry(); - } - return _instance; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/CSSPropertyMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/CSSPropertyMeta.java deleted file mode 100644 index 110b9947b..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/CSSPropertyMeta.java +++ /dev/null @@ -1,124 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.w3c.dom.Element; -import org.w3c.dom.css.CSSValue; - -/** - * @author mengbo - */ -public abstract class CSSPropertyMeta implements ICSSPropertyMeta { - public static final String[] EMPTY_KEYWORDS = new String[0]; - - boolean _inherited; - - Object _initialValue; - - public CSSPropertyMeta(boolean inherit, Object initvalue) { - this._inherited = inherit; - this._initialValue = initvalue; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta#isInherited() - */ - public boolean isInherited() { - return _inherited; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta#getHTMLElementInitialValue(org.w3c.dom.Element, - * java.lang.String, java.lang.String) - */ - public Object getHTMLElementInitialValue(Element element, String htmltag, - String propertyName) { - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta#getInitialValue() - */ - public Object getInitialValue(String propertyName, ICSSStyle style) { - return _initialValue; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta#getPercentageType() - */ - public int getPercentageType() { - return PERCENTAGE_NONE; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta#calculateHTMLAttributeOverride(org.w3c.dom.Element, - * java.lang.String, java.lang.String, - * org.eclipse.jst.pagedesigner.css2.ICSSStyle) - */ - public Object calculateHTMLAttributeOverride(Element element, - String htmltag, String propertyName, ICSSStyle style) { - // child class should override this method!!! - return null; - } - - /** - * for many properties, they have a set of keyword property values. - * - * @return - */ - protected abstract String[] getKeywordValues(); - - /** - * @param value - * @return null if is not a keyword. - */ - protected String checkKeywordValues(String value) { - if (value == null) - return null; - String[] keywords = getKeywordValues(); - if (keywords != null) { - for (int i = 0; i < keywords.length; i++) { - if (keywords[i].equalsIgnoreCase(value)) { - return keywords[i]; - } - } - } - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta#calculateCSSValueResult(org.w3c.dom.css.CSSValue, - * java.lang.String, - * org.eclipse.jst.pagedesigner.css2.property.AbstractStyle) - */ - public Object calculateCSSValueResult(CSSValue value, String propertyName, - ICSSStyle style) { - String s = checkKeywordValues(value.getCssText()); - if (s != null) { - return s; - } - return this.getInitialValue(propertyName, style); - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/ColorPropertyMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/ColorPropertyMeta.java deleted file mode 100644 index 776b1ce65..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/ColorPropertyMeta.java +++ /dev/null @@ -1,111 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -import java.util.Arrays; - -import org.eclipse.draw2d.ColorConstants; -import org.eclipse.jst.pagedesigner.IHTMLConstants; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.color.CSSColorManager; -import org.eclipse.jst.pagedesigner.utils.DOMUtil; -import org.eclipse.swt.graphics.Color; -import org.w3c.dom.Element; -import org.w3c.dom.css.CSSValue; - -/** - * "color" will be in this type - * - * @author mengbo - */ -public class ColorPropertyMeta extends CSSPropertyMeta { - private static final Object DEFAULT_COLOR = ColorConstants.black; - - private static final String[] KEYWORDS = new String[] {}; - - private final static String[] NOTSUPPORT_TAG = { IHTMLConstants.TAG_H1, - IHTMLConstants.TAG_H2, IHTMLConstants.TAG_H3, - IHTMLConstants.TAG_H4, IHTMLConstants.TAG_H5, IHTMLConstants.TAG_H6 }; - - public Color getDefaultColor() { - return null; - } - - /** - * @param inherit - * @param initvalue - */ - public ColorPropertyMeta() { - super(true, DEFAULT_COLOR); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta#calculateCSSValueResult(org.w3c.dom.css.CSSValue, - * java.lang.String, - * org.eclipse.jst.pagedesigner.css2.property.AbstractStyle) - */ - public Object calculateCSSValueResult(CSSValue value, String propertyName, - ICSSStyle style) { - - String text = value.getCssText(); - Object result = CSSColorManager.getInstance().getColor(text); - if (result != null) { - return result; - } - return this.getInitialValue(propertyName, style); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues() - */ - protected String[] getKeywordValues() { - return KEYWORDS; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta#calculateHTMLAttributeOverride(org.w3c.dom.Element, - * java.lang.String, java.lang.String, - * org.eclipse.jst.pagedesigner.css2.ICSSStyle) - */ - public Object calculateHTMLAttributeOverride(Element element, - String htmltag, String propertyName, ICSSStyle style) { - if (Arrays.asList(NOTSUPPORT_TAG).contains(htmltag.toLowerCase())) { - return null; - } - Object result; - String colorAttr = null; - // There are some conditions need to be dealt with hyperlink and text - // properties. - if (ICSSPropertyID.ATTR_COLOR.equalsIgnoreCase(propertyName)) { - colorAttr = DOMUtil.getAttributeIgnoreCase(element, - ICSSPropertyID.ATTR_COLOR); - if (colorAttr == null - && element.getLocalName().equalsIgnoreCase( - IHTMLConstants.TAG_BODY)) { - colorAttr = DOMUtil.getAttributeIgnoreCase(element, - ICSSPropertyID.ATTR_TEXT); - } - } - if (colorAttr != null) { - colorAttr = colorAttr.trim(); - result = CSSColorManager.getInstance().getColor(colorAttr); - return result; - } - return null; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/ContentMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/ContentMeta.java deleted file mode 100644 index 01e9652a9..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/ContentMeta.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -/** - * @author mengbo - */ -public class ContentMeta extends CSSPropertyMeta { - /** - * @param inherit - * @param initvalue - */ - public ContentMeta() { - // why inherit this?? - super(false, null); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues() - */ - protected String[] getKeywordValues() { - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta#calculateCSSValueResult(org.w3c.dom.css.CSSValue, - * java.lang.String, - * org.eclipse.jst.pagedesigner.css2.style.AbstractStyle) - */ - /* - * public Object calculateCSSValueResult(CSSValue value, String - * propertyName, AbstractStyle style) { if (value instanceof Counter) { - * Counter c = (Counter)value; ContentObject object = new ContentObject(); - * - * MyCounter counter = new MyCounter(c.getIdentifier(), c.getListStyle(), - * c.getSeparator()); object.setCounter(counter); return object; } return - * value; } - */ -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/CounterIncrementMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/CounterIncrementMeta.java deleted file mode 100644 index c6e2012a4..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/CounterIncrementMeta.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.list.CounterHelper; -import org.eclipse.jst.pagedesigner.css2.list.IncrementObject; -import org.eclipse.wst.css.core.internal.provisional.document.ICSSNode; -import org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue; -import org.w3c.dom.css.CSSValue; - -/** - * For CounterIncrementMeta, the valid value could be the following: 1. NULL 2. - * NOT_SPECIFIED 3. a List of IncrementObject. - * - * @author mengbo - */ -public class CounterIncrementMeta extends CSSPropertyMeta { - public CounterIncrementMeta() { - super(false, null); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues() - */ - protected String[] getKeywordValues() { - // TODO Auto-generated method stub - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta#calculateCSSValueResult(org.w3c.dom.css.CSSValue, - * java.lang.String, - * org.eclipse.jst.pagedesigner.css2.style.AbstractStyle) - */ - public Object calculateCSSValueResult(CSSValue value, String propertyName, - ICSSStyle style) { - return getCounter(value); - } - - public List getCounter(CSSValue value) { - if (value == null) { - return null; - } - List result = new ArrayList(); - IncrementObject incrementObject = null; - String identifier = null; - Integer increment = null; - ICSSNode cssValue = (ICSSNode) value; - while (cssValue != null) { - // find next idetifier. - while (cssValue != null && !CounterHelper.isIdentifier(cssValue)) { - cssValue = cssValue.getNextSibling(); - } - if (cssValue == null) { - return null; - } - // identifier: - identifier = ((ICSSPrimitiveValue) value).getStringValue(); - cssValue = cssValue.getNextSibling(); - // value: - if (CounterHelper.isNumber(cssValue)) { - increment = new Integer((int) ((ICSSPrimitiveValue) value) - .getFloatValue(ICSSPrimitiveValue.CSS_INTEGER)); - } - - if (identifier != null) { - incrementObject = new IncrementObject(identifier, increment); - result.add(incrementObject); - } - } - return result; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/CounterResetMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/CounterResetMeta.java deleted file mode 100644 index a362774ab..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/CounterResetMeta.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.list.CounterHelper; -import org.eclipse.jst.pagedesigner.css2.list.ResetObject; -import org.eclipse.wst.css.core.internal.provisional.document.ICSSNode; -import org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue; -import org.w3c.dom.css.CSSValue; - -/** - * @author mengbo - */ -public class CounterResetMeta extends CSSPropertyMeta { - public CounterResetMeta() { - super(false, null); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues() - */ - protected String[] getKeywordValues() { - // TODO Auto-generated method stub - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta#calculateCSSValueResult(org.w3c.dom.css.CSSValue, - * java.lang.String, - * org.eclipse.jst.pagedesigner.css2.style.AbstractStyle) - */ - public Object calculateCSSValueResult(CSSValue value, String propertyName, - ICSSStyle style) { - return getCounter(value); - } - - public List getCounter(CSSValue value) { - if (value == null) { - return null; - } - List result = new ArrayList(); - ResetObject resetObject = null; - String identifier = null; - Integer initial = null; - ICSSNode cssValue = (ICSSNode) value; - while (cssValue != null) { - // find next idetifier. - while (cssValue != null && !CounterHelper.isIdentifier(cssValue)) { - cssValue = cssValue.getNextSibling(); - } - if (cssValue == null) { - return null; - } - // identifier: - identifier = ((ICSSPrimitiveValue) value).getStringValue(); - cssValue = cssValue.getNextSibling(); - // value: - if (CounterHelper.isNumber(cssValue)) { - initial = new Integer((int) ((ICSSPrimitiveValue) value) - .getFloatValue(ICSSPrimitiveValue.CSS_INTEGER)); - } - - if (identifier != null) { - resetObject = new ResetObject(identifier, initial); - result.add(resetObject); - } - } - return result; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/DisplayMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/DisplayMeta.java deleted file mode 100644 index c72f9276b..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/DisplayMeta.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.w3c.dom.css.CSSValue; - -/** - * @author mengbo - */ -public class DisplayMeta extends CSSPropertyMeta { - static final String[] KEYWORDS = new String[] { ICSSPropertyID.VAL_INLINE, - ICSSPropertyID.VAL_BLOCK, ICSSPropertyID.VAL_INLINE_BLOCK, - ICSSPropertyID.VAL_LIST_ITEM, ICSSPropertyID.VAL_RUN_IN, - ICSSPropertyID.VAL_COMPACT, ICSSPropertyID.VAL_MARKER, - ICSSPropertyID.VAL_TABLE, ICSSPropertyID.VAL_INLINE_TABLE, - ICSSPropertyID.VAL_TABLE_ROW_GROUP, - ICSSPropertyID.VAL_TABLE_HEADER_GROUP, - ICSSPropertyID.VAL_TABLE_FOOTER_GROUP, - ICSSPropertyID.VAL_TABLE_ROW, - ICSSPropertyID.VAL_TABLE_COLUMN_GROUP, - ICSSPropertyID.VAL_TABLE_COLUMN, ICSSPropertyID.VAL_TABLE_CELL, - ICSSPropertyID.VAL_TABLE_CAPTION, ICSSPropertyID.VAL_NONE }; - - /** - * @param inherit - * @param initvalue - */ - public DisplayMeta() { - super(false, ICSSPropertyID.VAL_INLINE); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues() - */ - protected String[] getKeywordValues() { - return KEYWORDS; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta#calculateCSSValueResult(org.w3c.dom.css.CSSValue, - * java.lang.String, - * org.eclipse.jst.pagedesigner.css2.property.AbstractStyle) - */ - public Object calculateCSSValueResult(CSSValue value, String propertyName, - ICSSStyle style) { - String text = value.getCssText(); - if (text == null) - return ICSSPropertyID.VAL_INLINE; - String key = this.checkKeywordValues(text); - if (key != null) - return key; - return ICSSPropertyID.VAL_INLINE; - } - -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/EmptyCellsMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/EmptyCellsMeta.java deleted file mode 100644 index 50785b3d4..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/EmptyCellsMeta.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -/** - * @author mengbo - * @version 1.5 - */ -public class EmptyCellsMeta extends CSSPropertyMeta { - public static final String SHOW = "show"; - - public static final String HIDE = "hide"; - - public static final String[] _keywords = new String[] { SHOW, HIDE }; - - /** - * @param inherit - * @param initvalue - */ - public EmptyCellsMeta() { - // FIXME: on CSS spec, initial value should be "show". - // but seemed IE's default is hide. - super(true, HIDE); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues() - */ - protected String[] getKeywordValues() { - return _keywords; - } - -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/FloatInfo.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/FloatInfo.java deleted file mode 100644 index 12ad19f23..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/FloatInfo.java +++ /dev/null @@ -1,149 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -import org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue; -import org.w3c.dom.css.CSSPrimitiveValue; - -/** - * copied from wtp's internal code. - * - * @author mengbo - */ -public final class FloatInfo { - /** - * - */ - public FloatInfo(String text) { - parse(text); - } - - /** - * - */ - void parse(String text) { - StringBuffer bufValue = new StringBuffer(); - StringBuffer bufIdent = new StringBuffer(); - boolean bNum = true; - int len = text.length(); - for (int i = 0; i < len; i++) { - char c = text.charAt(i); - if (bNum) { - if ('0' <= c && c <= '9' || c == '.' || c == '+' || c == '-') { - bufValue.append(c); - } else { - bufIdent.append(c); - bNum = false; - } - } else { - bufIdent.append(c); - } - } - String valueStr = bufValue.toString(); - _value = Float.valueOf(valueStr).floatValue(); - _identifier = bufIdent.toString(); - _type = getFloatValueType(valueStr, _identifier); - } - - /** - * - */ - public float getValue() { - return _value; - } - - /** - * - */ - String getIdentifier() { - return _identifier; - } - - /** - * - */ - public short getValueType() { - return _type; - } - - /** - * - */ - static short getFloatValueType(String value, String ident) { - ident = ident.toLowerCase(); - short valueType; - if (ident.length() == 0) { - if (0 <= value.indexOf('.')) { - valueType = CSSPrimitiveValue.CSS_NUMBER; - } else { - valueType = ICSSPrimitiveValue.CSS_INTEGER; - } - } else if (ident.equals("%")) { - //$NON-NLS-1$ - valueType = CSSPrimitiveValue.CSS_PERCENTAGE; - } else if (ident.equalsIgnoreCase("em")) { - //$NON-NLS-1$ - valueType = CSSPrimitiveValue.CSS_EMS; - } else if (ident.equalsIgnoreCase("ex")) { - //$NON-NLS-1$ - valueType = CSSPrimitiveValue.CSS_EXS; - } else if (ident.equalsIgnoreCase("px")) { - //$NON-NLS-1$ - valueType = CSSPrimitiveValue.CSS_PX; - } else if (ident.equalsIgnoreCase("cm")) { - //$NON-NLS-1$ - valueType = CSSPrimitiveValue.CSS_CM; - } else if (ident.equalsIgnoreCase("mm")) { - //$NON-NLS-1$ - valueType = CSSPrimitiveValue.CSS_MM; - } else if (ident.equalsIgnoreCase("in")) { - //$NON-NLS-1$ - valueType = CSSPrimitiveValue.CSS_IN; - } else if (ident.equalsIgnoreCase("pt")) { - //$NON-NLS-1$ - valueType = CSSPrimitiveValue.CSS_PT; - } else if (ident.equalsIgnoreCase("pc")) { - //$NON-NLS-1$ - valueType = CSSPrimitiveValue.CSS_PC; - } else if (ident.equalsIgnoreCase("deg")) { - //$NON-NLS-1$ - valueType = CSSPrimitiveValue.CSS_DEG; - } else if (ident.equalsIgnoreCase("rad")) { - //$NON-NLS-1$ - valueType = CSSPrimitiveValue.CSS_RAD; - } else if (ident.equalsIgnoreCase("grad")) { - //$NON-NLS-1$ - valueType = CSSPrimitiveValue.CSS_GRAD; - } else if (ident.equalsIgnoreCase("ms")) { - //$NON-NLS-1$ - valueType = CSSPrimitiveValue.CSS_MS; - } else if (ident.equalsIgnoreCase("s")) { - //$NON-NLS-1$ - valueType = CSSPrimitiveValue.CSS_S; - } else if (ident.equalsIgnoreCase("hz")) { - //$NON-NLS-1$ - valueType = CSSPrimitiveValue.CSS_HZ; - } else if (ident.equalsIgnoreCase("khz")) { - //$NON-NLS-1$ - valueType = CSSPrimitiveValue.CSS_KHZ; - } else { - valueType = CSSPrimitiveValue.CSS_DIMENSION; - } - return valueType; - } - - private float _value = 0.0f; - - private String _identifier = null; - - private short _type = CSSPrimitiveValue.CSS_UNKNOWN; -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/FontFamilyMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/FontFamilyMeta.java deleted file mode 100644 index 68cfc8b47..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/FontFamilyMeta.java +++ /dev/null @@ -1,138 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.StringTokenizer; - -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.utils.DOMUtil; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.widgets.Display; -import org.w3c.dom.Element; -import org.w3c.dom.css.CSSValue; -import org.w3c.dom.css.CSSValueList; - -/** - * @author mengbo - */ -public class FontFamilyMeta extends CSSPropertyMeta { - public static final String DEFAULT_FONT = "Times New Roman"; - - private static FontData[] _FontData; - - private static FontData[] getFontData() { - if (_FontData == null) { - ArrayList list = new ArrayList(); - list.addAll(Arrays.asList(Display.getCurrent().getFontList(null, - false))); - list.addAll(Arrays.asList(Display.getCurrent().getFontList(null, - true))); - _FontData = (FontData[]) list.toArray(new FontData[list.size()]); - } - return _FontData; - } - - /** - * @param inherit - * @param initvalue - */ - public FontFamilyMeta() { - super(true, DEFAULT_FONT); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues() - */ - protected String[] getKeywordValues() { - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#calculateCSSValueResult(org.w3c.dom.css.CSSValue, - * java.lang.String, - * org.eclipse.jst.pagedesigner.css2.style.AbstractStyle) - */ - public Object calculateCSSValueResult(CSSValue value, String propertyName, - ICSSStyle style) { - if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) { - CSSValueList valueList = (CSSValueList) value; - for (int i = 0, count = valueList.getLength(); i < count; i++) { - String name = valueList.item(i).getCssText(); - name = trimPadding(name); - if (isSupportedFont(name)) { - return name; - } - } - } - return trimPadding(value.getCssText()); - } - - private String trimPadding(String name) { - String value = name; - if (value != null) { - value = value.replaceAll("\"", ""); - value = value.replaceAll("'", ""); - } - return value; - } - - private boolean isSupportedFont(String name) { - FontData[] fontData = getFontData(); - for (int i = 0; i < fontData.length; i++) { - if (fontData[i].getName().equalsIgnoreCase(name)) { - return true; - } - } - return false; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#calculateHTMLAttributeOverride(org.w3c.dom.Element, - * java.lang.String, java.lang.String, - * org.eclipse.jst.pagedesigner.css2.ICSSStyle) - */ - public Object calculateHTMLAttributeOverride(Element element, - String htmltag, String propertyName, ICSSStyle style) { - if ("FONT".equalsIgnoreCase(htmltag) - || "BASEFONT".equalsIgnoreCase(htmltag)) { - String face = DOMUtil.getAttributeIgnoreCase(element, "face"); - if (face != null) { - String[] names = getFontNameList(face); - for (int i = 0; i < names.length; i++) { - if (isSupportedFont(names[i])) { - return names[i]; - } - } - } else { - return null; - } - } - return null; - } - - private String[] getFontNameList(String face) { - StringTokenizer tokenizer = new StringTokenizer(face, ","); - String[] names = new String[tokenizer.countTokens()]; - for (int i = 0; i < names.length; i++) { - names[i] = trimPadding(tokenizer.nextToken()); - } - return names; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/FontSizeMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/FontSizeMeta.java deleted file mode 100644 index 774204ba9..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/FontSizeMeta.java +++ /dev/null @@ -1,188 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -import org.eclipse.jst.pagedesigner.IHTMLConstants; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.font.ICSSFont; -import org.eclipse.jst.pagedesigner.css2.value.Length; -import org.eclipse.jst.pagedesigner.utils.DOMUtil; -import org.w3c.dom.Element; -import org.w3c.dom.css.CSSValue; - -/** - * The result value should be Length object only. - * - * @author mengbo - */ -// XXX: in the future, we may add "unit" into Length, the one unit will be -// "MEDIUM" -// and specific for font. Means the relative size to MEDIUM. Then it is possible -// for -// the caller to decide the actual font size based on the style specific MEDIUM -// size. -public class FontSizeMeta extends LengthMeta { - private static final String[] KEYWORDS = { ICSSPropertyID.VAL_XX_SMALL, - ICSSPropertyID.VAL_X_SMALL, ICSSPropertyID.VAL_SMALL, - ICSSPropertyID.VAL_MEDIUM, ICSSPropertyID.VAL_LARGE, - ICSSPropertyID.VAL_X_LARGE, ICSSPropertyID.VAL_XX_LARGE, - ICSSPropertyID.VAL_LARGER, ICSSPropertyID.VAL_SMALLER }; - - public static final double MEDIUM_VAL_INT = 16; - - public static final double SCALING_FACTOR = 1.2; - - public static final double FACTORS[] = { 0.6, 0.89, 1, 1.2, 1.5, 2.0, 3.0 }; - - // The scaling factors in IE is different from CSS definition. Here we - // follow IE. - public static final double CSS_ABSOLUTE_FACTORS[] = { 0.63, 0.82, 1, 1.12, - 1.5, 2.0, 3.0 }; - - public static final int MIN_SIZE_FOR_SMALLER = 1; - - public static final int MIN_SIZE_FOR_LARGER = 9; - - /** - * @param inherit - * @param initvalue - */ - public FontSizeMeta() { - super(true, new Length((int) MEDIUM_VAL_INT, false)); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.LengthMeta#getBaseFont(org.eclipse.jst.pagedesigner.css2.property.AbstractStyle) - */ - protected ICSSFont getBaseFont(ICSSStyle style) { - return style.getParentStyle().getCSSFont(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues() - */ - protected String[] getKeywordValues() { - return KEYWORDS; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getPercentageType() - */ - public int getPercentageType() { - return PERCENTAGE_FONT; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.LengthMeta#calculateCSSValueResult(org.w3c.dom.css.CSSValue, - * java.lang.String, - * org.eclipse.jst.pagedesigner.css2.style.AbstractStyle) - */ - public Object calculateCSSValueResult(CSSValue value, String propertyName, - ICSSStyle style) { - Object obj = super.calculateCSSValueResult(value, propertyName, style); - if (obj instanceof Length) { - return obj; - } - // otherwise, it is keyword. - return convertKeyword(obj, style); - } - - protected Length convertKeyword(Object fontsizeobj, ICSSStyle style) { - int fontsize; - int parentfontsize = style.getParentStyle().getCSSFont().getFontSize(); - if (fontsizeobj instanceof Length) { - fontsize = ((Length) fontsizeobj).getValue(); - } else if (ICSSPropertyID.VAL_XX_SMALL.equals(fontsizeobj)) { - fontsize = (int) (MEDIUM_VAL_INT * CSS_ABSOLUTE_FACTORS[0]); - } else if (ICSSPropertyID.VAL_X_SMALL.equals(fontsizeobj)) { - fontsize = (int) (MEDIUM_VAL_INT * CSS_ABSOLUTE_FACTORS[1]); - } else if (ICSSPropertyID.VAL_SMALL.equals(fontsizeobj)) { - fontsize = (int) (MEDIUM_VAL_INT * CSS_ABSOLUTE_FACTORS[2]); - } else if (ICSSPropertyID.VAL_MEDIUM.equals(fontsizeobj)) { - fontsize = (int) Math.round(MEDIUM_VAL_INT - * CSS_ABSOLUTE_FACTORS[3]); - } else if (ICSSPropertyID.VAL_LARGE.equals(fontsizeobj)) { - fontsize = (int) (MEDIUM_VAL_INT * CSS_ABSOLUTE_FACTORS[4]); - } else if (ICSSPropertyID.VAL_X_LARGE.equals(fontsizeobj)) { - fontsize = (int) (MEDIUM_VAL_INT * CSS_ABSOLUTE_FACTORS[5]); - } else if (ICSSPropertyID.VAL_XX_LARGE.equals(fontsizeobj)) { - fontsize = (int) (MEDIUM_VAL_INT * CSS_ABSOLUTE_FACTORS[6]); - } else if (ICSSPropertyID.VAL_SMALLER.equals(fontsizeobj)) { - fontsize = (int) (parentfontsize / SCALING_FACTOR); - if (fontsize < MIN_SIZE_FOR_SMALLER) { - fontsize = MIN_SIZE_FOR_SMALLER; - } - } else if (ICSSPropertyID.VAL_LARGER.equals(fontsizeobj)) { - fontsize = (int) (parentfontsize * SCALING_FACTOR); - if (fontsize < MIN_SIZE_FOR_LARGER) { - fontsize = MIN_SIZE_FOR_LARGER; - } - } else { - fontsize = parentfontsize; - } - - return new Length(fontsize, false); - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#calculateHTMLAttributeOverride(org.w3c.dom.Element, - * java.lang.String, java.lang.String, - * org.eclipse.jst.pagedesigner.css2.ICSSStyle) - */ - public Object calculateHTMLAttributeOverride(Element element, - String htmltag, String propertyName, ICSSStyle style) { - if (IHTMLConstants.TAG_FONT.equalsIgnoreCase(htmltag) - || ICSSPropertyID.ATTR_BASEFONT.equalsIgnoreCase(htmltag)) { - String size = DOMUtil.getAttributeIgnoreCase(element, - ICSSPropertyID.ATTR_SIZE); - if (size != null) { - size = size.trim(); - try { - int fontSize = 0; - if (size.startsWith("+")) //$NON-NLS-1$ - { - fontSize = Integer.parseInt(size.substring(1)) + 3; - } else if (size.startsWith("-")) //$NON-NLS-1$ - { - fontSize = 3 - Integer.parseInt(size.substring(1)); - } else { - fontSize = Integer.parseInt(size); - } - if (fontSize < 1) { - fontSize = 1; - } - if (fontSize > 7) { - fontSize = 7; - } - return new Length((int) (Math.round(FACTORS[fontSize - 1] - * MEDIUM_VAL_INT)), false); - } catch (Exception ex) { - // Error in tag font attr calculating. - // _log.error("Error.FontSizeMeta.0", ex); //$NON-NLS-1$ - return null; - } - } - } - return null; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/FontStyleMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/FontStyleMeta.java deleted file mode 100644 index 8464868b0..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/FontStyleMeta.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -/** - * @author mengbo - */ -public class FontStyleMeta extends CSSPropertyMeta { - static final String[] KEYWORDS = new String[] { ICSSPropertyID.VAL_NORMAL, - ICSSPropertyID.VAL_ITALIC, ICSSPropertyID.VAL_OBLIQUE }; - - /** - * @param inherit - * @param initvalue - */ - public FontStyleMeta() { - super(true, ICSSPropertyID.VAL_NORMAL); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues() - */ - protected String[] getKeywordValues() { - return KEYWORDS; - } - -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/FontWeightMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/FontWeightMeta.java deleted file mode 100644 index 3163be9be..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/FontWeightMeta.java +++ /dev/null @@ -1,105 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -import org.eclipse.jst.jsf.common.ui.internal.logging.Logger; -import org.eclipse.jst.pagedesigner.PDPlugin; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.w3c.dom.css.CSSValue; - -/** - * The result value will always be integer, range 100-900 This class has already - * translate things like "normal", "bold", "bolder", "lighter" into integer - * value. - * - * @author mengbo - */ -public class FontWeightMeta extends CSSPropertyMeta { - - public static final Integer NORMAL_WEIGHT = new Integer(400); - - public static final Integer BOLD_WEIGHT = new Integer(700); - - static final String[] KEYWORDS = new String[] { ICSSPropertyID.VAL_NORMAL, - ICSSPropertyID.VAL_BOLD, ICSSPropertyID.VAL_BOLDER, - ICSSPropertyID.VAL_LIGHTER }; - - private Logger _log = PDPlugin.getLogger(FontWeightMeta.class); - - /** - * @param inherit - * @param initvalue - */ - public FontWeightMeta() { - super(true, NORMAL_WEIGHT); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues() - */ - protected String[] getKeywordValues() { - return KEYWORDS; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#calculateCSSValueResult(org.w3c.dom.css.CSSValue, - * java.lang.String, - * org.eclipse.jst.pagedesigner.css2.style.AbstractStyle) - */ - public Object calculateCSSValueResult(CSSValue value, String propertyName, - ICSSStyle style) { - String text = value.getCssText(); - String result = checkKeywordValues(text); - if (result == null) { - try { - int i = Integer.parseInt(text); - if (i < 100) { - i = 100; - } - if (i > 900) { - i = 900; - } - return new Integer(i); - } catch (Exception ex) { - // Error in integer processing. - _log.error("Info.FontWeightMeta.0", ex); //$NON-NLS-1$ - return NORMAL_WEIGHT; - } - } else if (ICSSPropertyID.VAL_NORMAL.equals(result)) { - return NORMAL_WEIGHT; - } else if (ICSSPropertyID.VAL_BOLD.equals(result)) { - return BOLD_WEIGHT; - } else if (ICSSPropertyID.VAL_BOLDER.equals(result)) { - // int i = style.getParentStyle().getCSSFont().getWeight() + 100; - // if (i < 100) - // i = 100; - // if (i > 900) - // i = 900; - // return new Integer(i); - return BOLD_WEIGHT; - } else if (ICSSPropertyID.VAL_LIGHTER.equals(result)) { - int i = style.getParentStyle().getCSSFont().getWeight() - 100; - if (i < 100) { - i = 100; - } - if (i > 900) { - i = 900; - } - return new Integer(i); - } - return NORMAL_WEIGHT; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/HeightMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/HeightMeta.java deleted file mode 100644 index 2c635ff2b..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/HeightMeta.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.utils.DOMUtil; -import org.w3c.dom.Element; - -/** - * @author mengbo - */ -public class HeightMeta extends LengthMeta { - /** - * @param inherit - * @param initvalue - */ - public HeightMeta() { - super(false, ICSSPropertyID.VAL_AUTO); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#calculateHTMLAttributeOverride(org.w3c.dom.Element, - * java.lang.String, java.lang.String, - * org.eclipse.jst.pagedesigner.css2.ICSSStyle) - */ - public Object calculateHTMLAttributeOverride(Element element, - String htmltag, String propertyName, ICSSStyle style) { - if (!"input".equalsIgnoreCase(htmltag)) //$NON-NLS-1$ - { - String attributeName = ICSSPropertyID.ATTR_HEIGHT; - if ("hr".equalsIgnoreCase(htmltag)) { - attributeName = ICSSPropertyID.ATTR_SIZE; - } - - String height = DOMUtil.getAttributeIgnoreCase(element, - attributeName); - if (height != null) { - return LengthMeta.toLength(height, style, this - .getPercentageType(), getBaseFont(style)); - } - } - return super.calculateHTMLAttributeOverride(element, htmltag, - propertyName, style); - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/HorizontalAlignMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/HorizontalAlignMeta.java deleted file mode 100644 index c54952868..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/HorizontalAlignMeta.java +++ /dev/null @@ -1,94 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -import java.util.Arrays; - -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.utils.DOMUtil; -import org.w3c.dom.Element; - -/** - * @author mengbo - */ -public class HorizontalAlignMeta extends CSSPropertyMeta { - static final String[] KEYWORDS = new String[] { ICSSPropertyID.VAL_LEFT, - "bottom", "top", //$NON-NLS-1$ //$NON-NLS-2$ - ICSSPropertyID.VAL_RIGHT, ICSSPropertyID.VAL_CENTER, - ICSSPropertyID.VAL_JUSTIFY }; - - private static final String[] HOR_SLIGN_HTMLTAGS = new String[] { - "TABLE", "HR", "LEGEND", "APPLET", "IFRAME", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ - "IMG", "INPUT", "OBJECT", "CAPTION" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - }; - - /** - * @param inherit - * @param initvalue - */ - public HorizontalAlignMeta() { - super(true, NOT_SPECIFIED); - } - - /** - * @param inherit - * @param initvalue - */ - public HorizontalAlignMeta(boolean inherit, Object initvalue) { - super(inherit, initvalue); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues() - */ - protected String[] getKeywordValues() { - return KEYWORDS; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#calculateHTMLAttributeOverride(org.w3c.dom.Element, - * java.lang.String, java.lang.String, - * org.eclipse.jst.pagedesigner.css2.ICSSStyle) - */ - public Object calculateHTMLAttributeOverride(Element element, - String htmltag, String propertyName, ICSSStyle style) { - - if (Arrays.asList(HOR_SLIGN_HTMLTAGS).contains(htmltag.toUpperCase())) { - String align = DOMUtil.getAttributeIgnoreCase(element, "align"); //$NON-NLS-1$ - return checkKeywordValues(align); - } - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta#getHTMLElementInitialValue(org.w3c.dom.Element, - * java.lang.String, java.lang.String) - */ - public Object getHTMLElementInitialValue(Element element, String htmltag, - String propertyName) { - if ("HR".equalsIgnoreCase(htmltag.toUpperCase())) //$NON-NLS-1$ - { - return ICSSPropertyID.VAL_CENTER; - } else if (Arrays.asList(HOR_SLIGN_HTMLTAGS).contains( - htmltag.toUpperCase())) { - return ICSSPropertyID.VAL_LEFT; - } - - return super.getHTMLElementInitialValue(element, htmltag, propertyName); - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/ICSSPropertyID.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/ICSSPropertyID.java deleted file mode 100644 index 2939923b9..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/ICSSPropertyID.java +++ /dev/null @@ -1,382 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -/** - * @author mengbo - */ -public interface ICSSPropertyID { - public static final String ATTR_DISPLAY = "display"; - - public static final String ATTR_WHITESPACE = "white-space"; - - public static final String ATTR_TEXTDECORATION = "text-decoration"; - - public static final String ATTR_TEXTALIGN = "text-align"; - - public static final String ATTR_WIDTH = "width"; - - public static final String ATTR_MIN_WIDTH = "min-width"; - - public static final String ATTR_HEIGHT = "height"; - - public static final String ATTR_MIN_HEIGHT = "min-height"; - - public static final String ATTR_BORDER_LEFT_WIDTH = "border-left-width"; - - public static final String ATTR_BORDER_RIGHT_WIDTH = "border-right-width"; - - public static final String ATTR_BORDER_BOTTOM_WIDTH = "border-bottom-width"; - - public static final String ATTR_BORDER_TOP_WIDTH = "border-top-width"; - - public static final String ATTR_FONT_FAMILY = "font-family"; - - public static final String ATTR_FONT_SIZE = "font-size"; - - public static final String ATTR_FONT_STYLE = "font-style"; - - public static final String ATTR_FONT_WEIGHT = "font-weight"; - - public static final String ATTR_BORDER_LEFT_STYLE = "border-left-style"; - - public static final String ATTR_BORDER_RIGHT_STYLE = "border-right-style"; - - public static final String ATTR_BORDER_BOTTOM_STYLE = "border-bottom-style"; - - public static final String ATTR_BORDER_TOP_STYLE = "border-top-style"; - - public static final String ATTR_BORDER_LEFT_COLOR = "border-left-color"; - - public static final String ATTR_BORDER_RIGHT_COLOR = "border-right-color"; - - public static final String ATTR_BORDER_BOTTOM_COLOR = "border-bottom-color"; - - public static final String ATTR_BORDER_TOP_COLOR = "border-top-color"; - - public static final String ATTR_PADDING_RIGHT = "padding-right"; - - public static final String ATTR_PADDING_BOTTOM = "padding-bottom"; - - public static final String ATTR_PADDING_LEFT = "padding-left"; - - public static final String ATTR_PADDING_TOP = "padding-top"; - - public static final String ATTR_MARGIN_RIGHT = "margin-right"; - - public static final String ATTR_MARGIN_BOTTOM = "margin-bottom"; - - public static final String ATTR_MARGIN_LEFT = "margin-left"; - - public static final String ATTR_MARGIN_TOP = "margin-top"; - - public static final String ATTR_BACKGROUND_COLOR = "background-color"; - - public static final String ATTR_COLOR = "color"; - - public static final String ATTR_TEXTCOLOR = "text"; - - public static final String ATTR_BORDER_COLLAPSE = "border-collapse"; - - public static final String ATTR_BORDER_SPACING = "border-spacing"; - - public static final String ATTR_LIST_STYLE_TYPE = "list-style-type"; - - public static final String ATTR_LIST_STYLE_POSITION = "list-style-position"; - - public static final String ATTR_LIST_STYLE_IMAGE = "list-style-image"; - - public static final String ATTR_COUNTER_RESET = "counter-reset"; - - public static final String ATTR_COUNTER_INCREMENT = "counter-increment"; - - public static final String ATTR_EMPTY_CELLS = "empty-cells"; - - public static final String ATTR_VISIBILITY = "visibility"; - - public static final String ATTR_VERTICAL_ALIGN = "vertical-align"; - - public static final String ATTR_HORIZONTAL_ALIGN = "horizontal-align"; - - public static final String ATTR_CONTENT = "content"; - - public static final String ATTR_BGCOLOR = "bgcolor"; - - public static final String ATTR_TEXT = "text"; - - public final static String ATTR_MULTIPLE = "multiple"; - - public final static String ATTR_ITEMLABEL = "itemLabel"; - - public final static String ATTR_BINDING = "binding"; - - public final static String ATTR_ITEMVALUE = "itemValue"; - - public final static String ATTR_VALUE = "value"; - - public static final String ATTR_URI = "uri"; - - public static final String ATTR_PREFIX = "prefix"; - - public static final String ATTR_STYLECLASS = "styleClass"; - - public static final String ATTR_SIZE = "size"; - - public static final String ATTR_BASEFONT = "basefont"; - - public static final String ATTR_ROWSPAN = "rowSpan"; - - public static final String ATTR_COLSPAN = "colSpan"; - - public static final String ATTR_TYPE = "type"; - - public static final String ATTR_URL = "url"; - - public static final String ATTR_SRC = "src"; - - public static final String ATTR_TAGLIB_LOCATION = "taglib-location"; - - public static final String ATTR_TAGLIB_URI = "taglib-uri"; - - public static final String ATTR_IMAGE = "image"; - - public static final String ATTR_RESET = "reset"; - - public static final String ATTR_FOOTER = "footer"; - - public static final String ATTR_HEADER = "header"; - - public static final String ATTR_COLUMNS = "columns"; - - public static final String ATTR_COLUMNCLASSES = "columnClasses"; - - public static final String ATTR_CLASS = "class"; - - public static final String ATTR_STYLE = "style"; - - public static final String ATTR_PAGE = "page"; - - public static final String ATTR_HREF = "href"; - - public static final String ATTR_NAME = "name"; - - public static final String ATTR_BASENAME = "basename"; - - public static final String ATTR_ACTION = "action"; - - public static final String ATTR_TARGET = "target"; - - public static final String ATTR_TOP = "top"; - - public static final String ATTR_BOTTOM = "bottom"; - - public static final String ATTR_LEFT = "left"; - - public static final String ATTR_RIGHT = "right"; - - public static final String ATTR_POSITION = "position"; - - public static final String VAL_TRANSPARENT = "transparent"; - - public static final String VAL_COLLAPSE = "collapse"; - - public static final String VAL_SEPARATE = "separate"; - - public static final String ATTR_OVERFLOW = "overflow"; - - // border style values - public static final String VAL_HIDDEN = "hidden"; - - public static final String VAL_DOTTED = "dotted"; - - public static final String VAL_DASHED = "dashed"; - - public static final String VAL_SOLID = "solid"; - - public static final String VAL_DOUBLE = "double"; - - public static final String VAL_GROOVE = "groove"; - - public static final String VAL_RIDGE = "ridge"; - - public static final String VAL_INSET = "inset"; - - public static final String VAL_OUTSET = "outset"; - - // XXX: we introduce a new style for TD default border style, since it - // seemed IE - // is using none of the above style for td. - public static final String VAL_TDBORDERSTYLE = "__td_border_style__"; - - public static final String VAL_THIN = "thin"; - - public static final String VAL_THICK = "thick"; - - public static final String VAL_INLINE = "inline"; - - public static final String VAL_BLOCK = "block"; - - public static final String VAL_INLINE_BLOCK = "inline-block"; - - public static final String VAL_LIST_ITEM = "list-item"; - - public static final String VAL_RUN_IN = "run-in"; - - public static final String VAL_COMPACT = "compact"; - - public static final String VAL_MARKER = "marker"; - - public static final String VAL_TABLE = "table"; - - public static final String VAL_INLINE_TABLE = "inline-table"; - - public static final String VAL_TABLE_ROW_GROUP = "table-row-group"; - - public static final String VAL_TABLE_HEADER_GROUP = "table-header-group"; - - public static final String VAL_TABLE_FOOTER_GROUP = "table-footer-group"; - - public static final String VAL_TABLE_ROW = "table-row"; - - public static final String VAL_TABLE_COLUMN_GROUP = "table-column-group"; - - public static final String VAL_TABLE_COLUMN = "table-column"; - - public static final String VAL_TABLE_CELL = "table-cell"; - - public static final String VAL_TABLE_CAPTION = "table-caption"; - - public static final String VAL_NONE = "none"; - - public static final String VAL_XX_SMALL = "xx-small"; - - public static final String VAL_X_SMALL = "x-small"; - - public static final String VAL_SMALL = "small"; - - public static final String VAL_MEDIUM = "medium"; - - public static final String VAL_LARGE = "large"; - - public static final String VAL_X_LARGE = "x-large"; - - public static final String VAL_XX_LARGE = "xx-large"; - - public static final String VAL_LARGER = "larger"; - - public static final String VAL_SMALLER = "smaller"; - - public static final String VAL_ITALIC = "italic"; - - public static final String VAL_OBLIQUE = "oblique"; - - public static final String VAL_NORMAL = "normal"; - - public static final String VAL_BOLD = "bold"; - - public static final String VAL_BOLDER = "bolder"; - - public static final String VAL_LIGHTER = "lighter"; - - public static final String VAL_AUTO = "auto"; - - public static final String VAL_OUTSIDE = "outside"; - - public static final String VAL_INSIDE = "inside"; - - public static final String VAL_LEFT = "left"; - - public static final String VAL_RIGHT = "right"; - - public static final String VAL_CENTER = "center"; - - public static final String VAL_JUSTIFY = "justify"; - - public static final String VAL_UNDERLINE = "underline"; - - public static final String VAL_OVERLINE = "overline"; - - public static final String VAL_LINETHROUGH = "line-through"; - - public static final String VAL_BLINK = "blink"; - - public static final String VAL_PRE = "pre"; - - public static final String VAL_NOWRAP = "nowrap"; - - public final static String VAL_DISC = "disc"; //$NON-NLS-1$ - - public final static String VAL_CIRCLE = "circle"; //$NON-NLS-1$ - - public final static String VAL_DECIMAL = "decimal"; //$NON-NLS-1$ - - public final static String VAL_CJK_IDEOGRAPHIC = "cjk-ideographic"; //$NON-NLS-1$ - - public final static String VAL_DECIMAL_LEADING_ZERO = "decimal-leading-zero"; //$NON-NLS-1$ - - public final static String VAL_ARMENIAN = "armenian"; //$NON-NLS-1$ - - public final static String VAL_LOWER_ALPHA = "lower-alpha"; //$NON-NLS-1$ - - public final static String VAL_LOWER_GREEK = "lower-greek"; //$NON-NLS-1$ - - public final static String VAL_LOWER_LATIN = "lower-latin"; //$NON-NLS-1$ - - public final static String VAL_LOWER_ROMAN = "lower-roman"; //$NON-NLS-1$ - - public final static String VAL_UPPER_ALPHA = "upper-alpha"; //$NON-NLS-1$ - - public final static String VAL_UPPER_LATIN = "upper-latin"; //$NON-NLS-1$ - - public final static String VAL_UPPER_ROMAN = "upper-roman"; //$NON-NLS-1$ - - public final static String VAL_HIRAGANA = "hiragana"; //$NON-NLS-1$ - - public final static String VAL_HIRAGANA_IROHA = "hiragana-iroha"; //$NON-NLS-1$ - - public final static String VAL_HEBREW = "hebrew"; //$NON-NLS-1$ - - public final static String VAL_GEORGIAN = "georgian"; //$NON-NLS-1$ - - public final static String VAL_KATAKANA = "katakana"; //$NON-NLS-1$ - - public final static String VAL_KATAKANA_IROHA = "katakana-iroha"; //$NON-NLS-1$ - - public final static String VAL_SQUARE = "square"; //$NON-NLS-1$ - - public final static String VAL_IMAGE = "image"; //$NON-NLS-1$ - - public static final String VAL_MULTIPLE = "multiple"; - - public static final String VAL_BUTTON = "button"; - - public static final String VAL_CHECKBOX = "checkbox"; - - public static final String VAL_RADIO = "radio"; - - public static final String VAL_FILE = "file"; - - public static final String VAL_RESET = "reset"; - - public static final String VAL_SUBMIT = "submit"; - - public static final String VAL_PASSWORD = "password"; - - public static final String VAL_TEXT = "text"; - - public static final String VAL_VISIBLE = "visible"; - - public static final String VAL_SCROLL = "scroll"; - - public static final String TAG_TAGLIB = "taglib"; - -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/ICSSPropertyMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/ICSSPropertyMeta.java deleted file mode 100644 index 6f93c9ac3..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/ICSSPropertyMeta.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.w3c.dom.Element; -import org.w3c.dom.css.CSSValue; - -/** - * @author mengbo - */ -public interface ICSSPropertyMeta { - public static final int PERCENTAGE_NONE = 0; - - public static final int PERCENTAGE_BOXSIZE = 1; - - public static final int PERCENTAGE_HEIGHT_CONTAININGBLOCK = 2; - - public static final int PERCENTAGE_FONT = 3; - - public static final int PERCENTAGE_WIDTH_CONTAININGBLOCK = 4; - - public static final Object NOT_SPECIFIED = "NOT_SPECIFIED"; - - /** - * whether default inherit. - * - * @return - */ - public boolean isInherited(); - - /** - * initial value - * - * @return - */ - public Object getInitialValue(String propertyName, ICSSStyle style); - - public Object getHTMLElementInitialValue(Element element, String htmltag, - String propertyName); - - /** - * what's percentage value based on. - * - * @return - */ - public int getPercentageType(); - - /** - * for many CSS property, there is corresponding HTML attribute can also - * specify value for them. This method should check whether the element has - * corresponding HTML attribute provide value. - * - * @param element - * the element - * @param htmltag - * the html tag name. This is for in case element is jsp/jsf - * element, and have non html tag name. - * @param propertyName - * the property name. - * @param style - * the style - * @return null if no attribute override. - */ - public Object calculateHTMLAttributeOverride(Element element, - String htmltag, String propertyName, ICSSStyle style); - - /** - * @param value - * @param propertyName - * @param style - * @return - */ - public Object calculateCSSValueResult(CSSValue value, String propertyName, - ICSSStyle style); - -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/LengthMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/LengthMeta.java deleted file mode 100644 index 5deb85a90..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/LengthMeta.java +++ /dev/null @@ -1,210 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -import org.eclipse.jst.jsf.common.ui.internal.logging.Logger; -import org.eclipse.jst.pagedesigner.PDPlugin; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.font.ICSSFont; -import org.eclipse.jst.pagedesigner.css2.value.Length; -import org.eclipse.swt.widgets.Display; -import org.w3c.dom.DOMException; -import org.w3c.dom.css.CSSPrimitiveValue; -import org.w3c.dom.css.CSSValue; - -/** - * @author mengbo - */ -public class LengthMeta extends CSSPropertyMeta { - private static final String[] KEYWORDS = new String[] { ICSSPropertyID.VAL_AUTO }; - - private static Logger _log = PDPlugin.getLogger(LengthMeta.class); - - /** - * @param inherit - * @param initvalue - */ - public LengthMeta(boolean inherit, Object initvalue) { - super(inherit, initvalue); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues() - */ - protected String[] getKeywordValues() { - return KEYWORDS; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta#calculateCSSValueResult(org.w3c.dom.css.CSSValue, - * java.lang.String, - * org.eclipse.jst.pagedesigner.css2.property.AbstractStyle) - */ - public Object calculateCSSValueResult(CSSValue value, String propertyName, - ICSSStyle style) { - if (value == null || value.getCssValueType() == CSSValue.CSS_VALUE_LIST - || value.getCssValueType() == CSSValue.CSS_CUSTOM) { - return ICSSPropertyID.VAL_AUTO; - } - if (value.getCssValueType() == CSSValue.CSS_INHERIT) { - return ICSSPropertyID.VAL_AUTO; - } - CSSPrimitiveValue primitive = (CSSPrimitiveValue) value; - String key = checkKeywordValues(primitive.getCssText()); - if (key != null) { - return key; - } - short unitType = primitive.getPrimitiveType(); - float fvalue; - try { - fvalue = primitive.getFloatValue(unitType); - } catch (DOMException ex) { - _log.info("Get length failed, use auto value instead (" - + value.getCssText() + ")"); - return ICSSPropertyID.VAL_AUTO; - } - return toLength(fvalue, unitType, style, this.getPercentageType(), - getBaseFont(style)); - } - - public static Object toLength(String lengthStr, ICSSStyle style, - int percenttype, ICSSFont font) { - try { - FloatInfo floatinfo = new FloatInfo(lengthStr); - return toLength(floatinfo.getValue(), floatinfo.getValueType(), - style, percenttype, font); - } catch (Exception e) { - return ICSSPropertyID.VAL_AUTO; - } - } - - /** - * Will not calculate percentage value. Used for calculate the "width" and - * "height" css property - * - * @param value - * @param parentValue - * @param font - * @return - */ - public static Object toLength(float result, short unitType, - ICSSStyle style, int percenttype, ICSSFont font) { - switch (unitType) { - case CSSPrimitiveValue.CSS_PERCENTAGE: - if (percenttype == PERCENTAGE_FONT) { - result = (int) ((result * font.getFontSize()) / 100.0); - break; - } - return new Length((int) result, true); - case CSSPrimitiveValue.CSS_PX: // no more calculation needed - case CSSPrimitiveValue.CSS_NUMBER: - break; - case CSSPrimitiveValue.CSS_EMS: - result *= font.getFontSize(); - break; - case CSSPrimitiveValue.CSS_EXS: - result *= font.getXHeight(); - break; - case CSSPrimitiveValue.CSS_CM: - result = cmToPixel(result); - break; - case CSSPrimitiveValue.CSS_IN: - result = inToPixel(result); - break; - case CSSPrimitiveValue.CSS_MM: - result = mmToPixel(result); - break; - case CSSPrimitiveValue.CSS_PT: - result = ptToPixel(result); - break; - case CSSPrimitiveValue.CSS_PC: - result = pcToPixel(result); - break; - case CSSPrimitiveValue.CSS_STRING: - return ICSSPropertyID.VAL_AUTO; - // FIXME:every thing is delt with? - } - // ok, when reach here, means we get the float value "result" - return new Length((int) result, false); - } - - /** - * child class can override this method. e.g: font-size style's base font is - * parent style's font. - * - * @param style - * @return - */ - protected ICSSFont getBaseFont(ICSSStyle style) { - return style.getCSSFont(); - } - - private static float pcToPixel(float value) { - return ptToPixel(12 * value); - } - - /** - * @param floatValue - * @return - */ - private static float ptToPixel(float floatValue) { - // the points used by CSS 2.1 are equal to 1/72th of an inch. - return inToPixel(floatValue / 72); - } - - /** - * @param floatValue - * @return - */ - private static float mmToPixel(float floatValue) { - return cmToPixel(floatValue / 10); - } - - /** - * @param floatValue - * @return - */ - private static float inToPixel(float floatValue) { - return getDPI() * floatValue; - } - - /** - * @param floatValue - * @return - */ - private static float cmToPixel(float floatValue) { - // 1 inch is equal to 2.54 centimeters - return inToPixel((float) (floatValue / 2.54)); - } - - /** - * @return - */ - private static float getDPI() { - // XXX: cache the value? - return Display.getCurrent().getDPI().x; - } - - public static boolean isAuto(Object result) { - if (result == ICSSPropertyID.VAL_AUTO) { - return true; - } - if (result instanceof Length && ((Length) result).getValue() <= 0) { - return true; - } - return false; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/ListStyleImageMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/ListStyleImageMeta.java deleted file mode 100644 index e87208009..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/ListStyleImageMeta.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.utils.DOMUtil; -import org.w3c.dom.Element; - -/** - * @author mengbo - */ -public class ListStyleImageMeta extends CSSPropertyMeta { - private static final String INITIAL_VALUE = ICSSPropertyID.VAL_NONE; - - /** - * @param inherit - * @param initvalue - */ - public ListStyleImageMeta() { - super(true, INITIAL_VALUE); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues() - */ - protected String[] getKeywordValues() { - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta#calculateHTMLAttributeOverride(org.w3c.dom.Element, - * java.lang.String, java.lang.String, - * org.eclipse.jst.pagedesigner.css2.ICSSStyle) - */ - public Object calculateHTMLAttributeOverride(Element element, - String htmltag, String propertyName, ICSSStyle style) { - return DOMUtil.getAttributeIgnoreCase(element, - ICSSPropertyID.ATTR_LIST_STYLE_IMAGE); - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/ListStylePositionMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/ListStylePositionMeta.java deleted file mode 100644 index c6c8cef40..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/ListStylePositionMeta.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -/** - * @author mengbo - */ -public class ListStylePositionMeta extends CSSPropertyMeta { - private static final String INITIAL_VALUE = ICSSPropertyID.VAL_OUTSIDE; - - /** - * @param inherit - * @param initvalue - */ - public ListStylePositionMeta() { - super(true, INITIAL_VALUE); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues() - */ - protected String[] getKeywordValues() { - // TODO Auto-generated method stub - return null; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/ListStyleTypeMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/ListStyleTypeMeta.java deleted file mode 100644 index bf6d4641a..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/ListStyleTypeMeta.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.utils.DOMUtil; -import org.w3c.dom.Element; -import org.w3c.dom.css.CSSValue; - -/** - * @author mengbo - */ -public class ListStyleTypeMeta extends CSSPropertyMeta { - private static final String INITIAL_VALUE = ICSSPropertyID.VAL_DISC; - - /** - * @param inherit - * @param initvalue - */ - public ListStyleTypeMeta() { - super(true, INITIAL_VALUE); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues() - */ - protected String[] getKeywordValues() { - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta#calculateCSSValueResult(org.w3c.dom.css.CSSValue, - * java.lang.String, - * org.eclipse.jst.pagedesigner.css2.style.AbstractStyle) - */ - public Object calculateCSSValueResult(CSSValue value, String propertyName, - ICSSStyle style) { - return value.getCssText(); - } - - // /* - // * (non-Javadoc) - // * - // * @see - // org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta#calculateHTMLAttributeOverride(org.w3c.dom.Element, - // java.lang.String, java.lang.String, - // org.eclipse.jst.pagedesigner.css2.ICSSStyle) - // */ - public Object calculateHTMLAttributeOverride(Element element, - String htmltag, String propertyName, ICSSStyle style) { - String listStyle = DOMUtil.getAttributeIgnoreCase(element, "type"); - if (listStyle == null && element != null - && element.getParentNode() != null) { - listStyle = DOMUtil.getAttributeIgnoreCase((Element) element - .getParentNode(), "type"); - } - if (listStyle != null) { - listStyle = listStyle.trim(); - if (listStyle.equals("1")) { - return ICSSPropertyID.VAL_DECIMAL; - } else if (listStyle.equals("a")) { - return ICSSPropertyID.VAL_LOWER_ALPHA; - } else if (listStyle.equals("A")) { - return ICSSPropertyID.VAL_UPPER_ALPHA; - } else if (listStyle.equals("i")) { - return ICSSPropertyID.VAL_LOWER_ROMAN; - } else if (listStyle.equals("I")) { - return ICSSPropertyID.VAL_UPPER_ROMAN; - } - return listStyle; - } - return null; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/MarginWidthMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/MarginWidthMeta.java deleted file mode 100644 index f5d23c470..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/MarginWidthMeta.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -/** - * @author mengbo - */ -public class MarginWidthMeta extends LengthMeta { - - /** - * @param inherit - * @param initvalue - */ - public MarginWidthMeta() { - super(false, ICSSPropertyID.VAL_AUTO); - } - - /** - * @param propertyName - * @return - */ - public static boolean isMarginWidth(String propertyName) { - return ICSSPropertyID.ATTR_MARGIN_BOTTOM.equalsIgnoreCase(propertyName) - || ICSSPropertyID.ATTR_MARGIN_TOP - .equalsIgnoreCase(propertyName) - || ICSSPropertyID.ATTR_MARGIN_LEFT - .equalsIgnoreCase(propertyName) - || ICSSPropertyID.ATTR_MARGIN_RIGHT - .equalsIgnoreCase(propertyName); - } - -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/OverflowMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/OverflowMeta.java deleted file mode 100644 index 6014eb610..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/OverflowMeta.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.w3c.dom.css.CSSValue; - -/** - * - * @author mengbo - * @version 1.5 - */ -public class OverflowMeta extends CSSPropertyMeta { - static final String[] KEYWORDS = new String[] { ICSSPropertyID.VAL_VISIBLE, - ICSSPropertyID.VAL_HIDDEN, ICSSPropertyID.VAL_SCROLL, - ICSSPropertyID.VAL_AUTO }; - - public OverflowMeta() { - super(false, ICSSPropertyID.VAL_VISIBLE); - } - - protected String[] getKeywordValues() { - return KEYWORDS; - } - - public Object calculateCSSValueResult(CSSValue value, String propertyName, - ICSSStyle style) { - String display = style.getDisplay(); - // we only support overflow for "block". Which means we don't support it - // for table/inline-block, etc. - if (!"block".equalsIgnoreCase(display)) { - return ICSSPropertyID.VAL_VISIBLE; - } - return super.calculateCSSValueResult(value, propertyName, style); - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/PaddingWidthMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/PaddingWidthMeta.java deleted file mode 100644 index a91a89260..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/PaddingWidthMeta.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -import org.eclipse.jst.pagedesigner.IHTMLConstants; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.utils.DOMUtil; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -/** - * @author mengbo - */ -public class PaddingWidthMeta extends LengthMeta { - /** - * @param inherit - * @param initvalue - */ - public PaddingWidthMeta() { - super(false, ICSSPropertyID.VAL_AUTO); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#calculateHTMLAttributeOverride(org.w3c.dom.Element, - * java.lang.String, java.lang.String, - * org.eclipse.jst.pagedesigner.css2.ICSSStyle) - */ - public Object calculateHTMLAttributeOverride(Element element, - String htmltag, String propertyName, ICSSStyle style) { - if (IHTMLConstants.TAG_TD.equalsIgnoreCase(htmltag) - || IHTMLConstants.TAG_TH.equalsIgnoreCase(htmltag)) { - Node parent = element; - Element tableEle = null; - while ((parent = parent.getParentNode()) != null - && parent instanceof Element) { - if (((Element) parent).getTagName().equalsIgnoreCase( - IHTMLConstants.TAG_TABLE)) { - tableEle = (Element) parent; - break; - } - } - if (tableEle != null) { - String padding = DOMUtil.getAttributeIgnoreCase(tableEle, - "cellpadding");//$NON-NLS-1$ - if (padding != null) { - return LengthMeta.toLength(padding, style, this - .getPercentageType(), getBaseFont(style)); - } - } - } - return super.calculateHTMLAttributeOverride(element, htmltag, - propertyName, style); - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/PositionMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/PositionMeta.java deleted file mode 100644 index 28cafbaf2..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/PositionMeta.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -/** - * @author mengbo - * @version 1.5 - */ -public class PositionMeta extends CSSPropertyMeta { - public static final String STATIC = "static"; - - public static final String ABSOLUTE = "absolute"; - - public static final String RELATIVE = "relative"; - - public static final String FIXED = "fixed"; - - public static final String[] _keywords = new String[] { STATIC, ABSOLUTE, - RELATIVE, FIXED }; - - /** - * @param inherit - * @param initvalue - */ - public PositionMeta() { - super(false, STATIC); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues() - */ - protected String[] getKeywordValues() { - return _keywords; - } - -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/PositionOffsetMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/PositionOffsetMeta.java deleted file mode 100644 index f96864d5a..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/PositionOffsetMeta.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -/** - * @author mengbo - * @version 1.5 - */ -public class PositionOffsetMeta extends LengthMeta { - /** - * @param inherit - * @param initvalue - */ - public PositionOffsetMeta() { - super(false, ICSSPropertyID.VAL_AUTO); - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/TableUtil.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/TableUtil.java deleted file mode 100644 index 1415cef67..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/TableUtil.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -import org.eclipse.jst.pagedesigner.utils.HTMLUtil; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.Text; - -/** - * @author mengbo - * @version 1.5 - */ -public class TableUtil { - static final String TOP = "top"; - - static final String BOTTOM = "bottom"; - - static final String LEFT = "left"; - - static final String RIGHT = "right"; - - public static boolean matchFrame(String edge, String frame) { - if ("above".equalsIgnoreCase(frame)) { - return TOP.equalsIgnoreCase(edge); - } else if ("below".equalsIgnoreCase(frame)) { - return BOTTOM.equalsIgnoreCase(edge); - } else if ("hsides".equalsIgnoreCase(frame)) { - return TOP.equalsIgnoreCase(edge) || BOTTOM.equalsIgnoreCase(edge); - } else if ("vsides".equalsIgnoreCase(frame)) { - return LEFT.equalsIgnoreCase(edge) || RIGHT.equalsIgnoreCase(edge); - } else if ("lhs".equalsIgnoreCase(frame)) { - return LEFT.equalsIgnoreCase(edge); - } else if ("rhs".equalsIgnoreCase(frame)) { - return RIGHT.equalsIgnoreCase(edge); - } else if ("box".equalsIgnoreCase(frame) - || "border".equalsIgnoreCase(frame)) { - return true; - } else { - return false; - } - } - - /** - * @param string - * @param rules - * @return - */ - public static boolean matchRules(String edge, String rules) { - // TODO: "groups" not supported. - - if ("rows".equalsIgnoreCase(rules)) { - return TOP.equalsIgnoreCase(edge) || BOTTOM.equalsIgnoreCase(edge); - } else if ("cols".equalsIgnoreCase(rules)) { - return LEFT.equalsIgnoreCase(edge) || RIGHT.equalsIgnoreCase(edge); - } else if ("all".equalsIgnoreCase(rules)) { - return true; - } else { - return false; - } - - } - - /** - * @param element - * @return - * @see http://www.w3.org/TR/CSS21/tables.html#empty-cells - */ - public static boolean isEmptyCell(Element element) { - NodeList children = element.getChildNodes(); - if (children.getLength() == 0) { - return true; - } - // we only do simple checking here. When the element has one child - // and is text and is whitespace only, then we also treat as empty cell - if (children.getLength() == 1) { - Node child = children.item(0); - if (child instanceof Text) { - String text = child.getNodeValue(); - if (HTMLUtil.isHTMLWhitespaceString(text)) { - return true; - } - } - } - - return false; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/TextAlignMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/TextAlignMeta.java deleted file mode 100644 index 2e07141dc..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/TextAlignMeta.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -import java.util.Arrays; - -import org.eclipse.jst.pagedesigner.IHTMLConstants; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.utils.DOMUtil; -import org.w3c.dom.Element; - -/** - * @author mengbo - */ -public class TextAlignMeta extends CSSPropertyMeta { - static final String[] KEYWORDS = new String[] { ICSSPropertyID.VAL_LEFT, - ICSSPropertyID.VAL_RIGHT, ICSSPropertyID.VAL_CENTER, - ICSSPropertyID.VAL_JUSTIFY }; - - private static final String[] HOR_SLIGN_HTMLTAGS = new String[] { - IHTMLConstants.TAG_TABLE, IHTMLConstants.TAG_HR, - IHTMLConstants.TAG_LEGEND, IHTMLConstants.TAG_APPLET, - IHTMLConstants.TAG_IFRAME, IHTMLConstants.TAG_IMG, - IHTMLConstants.TAG_INPUT, IHTMLConstants.TAG_OBJECT, - IHTMLConstants.TAG_CAPTION }; - - /** - * @param inherit - * @param initvalue - */ - public TextAlignMeta() { - super(true, NOT_SPECIFIED); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues() - */ - protected String[] getKeywordValues() { - return KEYWORDS; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#calculateHTMLAttributeOverride(org.w3c.dom.Element, - * java.lang.String, java.lang.String, - * org.eclipse.jst.pagedesigner.css2.ICSSStyle) - */ - public Object calculateHTMLAttributeOverride(Element element, - String htmltag, String propertyName, ICSSStyle style) { - // /for td, it may look for the attribute value up to tr, but must stop - // at table. - // so for table,set _inherited=false to stop it. - if (IHTMLConstants.TAG_TABLE.equalsIgnoreCase(htmltag)) { - this._inherited = false; - } else { - this._inherited = true; - } - if (Arrays.asList(HOR_SLIGN_HTMLTAGS).contains(htmltag.toLowerCase())) { - return null; - } - - String align = DOMUtil.getAttributeIgnoreCase(element, - IHTMLConstants.ATTR_ALIGN); - String value = checkKeywordValues(align); - if (value != null) { - return value; - } - if ("middle".equalsIgnoreCase(align)) { - return ICSSPropertyID.VAL_CENTER; - } - - return null; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/TextDecorationMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/TextDecorationMeta.java deleted file mode 100644 index 05b10a4db..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/TextDecorationMeta.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.w3c.dom.css.CSSValue; -import org.w3c.dom.css.CSSValueList; - -/** - * @author mengbo - */ -public class TextDecorationMeta extends CSSPropertyMeta { - public static final int NONE = 0; - - public static final int UNDERLINE = 1; - - public static final int OVERLINE = 1 << 1; - - public static final int LINETHROUGH = 1 << 2; - - public static final int BLINK = 1 << 3; - - static final String[] KEYWORDS = new String[] { ICSSPropertyID.VAL_NONE, - ICSSPropertyID.VAL_UNDERLINE, ICSSPropertyID.VAL_OVERLINE, - ICSSPropertyID.VAL_LINETHROUGH, ICSSPropertyID.VAL_BLINK }; - - /** - * @param inherit - * @param initvalue - */ - public TextDecorationMeta() { - // the spec say text-decoration is not inherited. but the description - // seemed to make use inherit easier. - // It seems that the property is inherited in IE and Mozilla. - super(true, new Integer(NONE)); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues() - */ - protected String[] getKeywordValues() { - return KEYWORDS; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#calculateCSSValueResult(org.w3c.dom.css.CSSValue, - * java.lang.String, - * org.eclipse.jst.pagedesigner.css2.property.AbstractStyle) - */ - public Object calculateCSSValueResult(CSSValue value, String propertyName, - ICSSStyle style) { - String[] decorations = null; - if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) { - CSSValueList valueList = (CSSValueList) value; - decorations = new String[valueList.getLength()]; - for (int i = 0; i < decorations.length; i++) { - decorations[i] = valueList.item(i).getCssText(); - } - } else { - decorations = new String[1]; - decorations[0] = value.getCssText(); - } - - int intvalue = 0; - for (int i = 0; i < decorations.length; i++) { - String key = super.checkKeywordValues(decorations[i]); - if (key == ICSSPropertyID.VAL_NONE) { - intvalue = NONE; - } else if (key == ICSSPropertyID.VAL_UNDERLINE) { - intvalue |= UNDERLINE; - } else if (key == ICSSPropertyID.VAL_OVERLINE) { - intvalue |= OVERLINE; - } else if (key == ICSSPropertyID.VAL_LINETHROUGH) { - intvalue |= LINETHROUGH; - } else if (key == ICSSPropertyID.VAL_BLINK) { - intvalue |= BLINK; - } - } - - return new Integer(intvalue); - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/VerticalAlignMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/VerticalAlignMeta.java deleted file mode 100644 index 5720b8476..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/VerticalAlignMeta.java +++ /dev/null @@ -1,104 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -import org.eclipse.jst.pagedesigner.IHTMLConstants; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.utils.DOMUtil; -import org.w3c.dom.Element; - -/** - * @author mengbo - */ -public class VerticalAlignMeta extends LengthMeta { - public static final String BASELINE = "baseline"; //$NON-NLS-1$ - - public static final String MIDDLE = "middle"; //$NON-NLS-1$ - - public static final String SUB = "sub"; //$NON-NLS-1$ - - public static final String SUPER = "super"; //$NON-NLS-1$ - - public static final String TEXT_TOP = "text-top"; //$NON-NLS-1$ - - public static final String TEXT_BOTTOM = "text-bottom"; //$NON-NLS-1$ - - public static final String TOP = "top"; //$NON-NLS-1$ - - public static final String BOTTOM = "bottom"; //$NON-NLS-1$ - - public static final String CENTER = "center"; //$NON-NLS-1$ - - public static final String DEFAULT_VERTICAL_ALIGN = BASELINE; - - private static final String[] KEYWORDS = new String[] { BASELINE, MIDDLE, - SUB, SUPER, TEXT_TOP, TEXT_BOTTOM, TOP, BOTTOM }; - - private static final String[] htmlAttributes = new String[] { IHTMLConstants.ATTR_VALIGN }; - - /** - * @param inherit - * @param initvalue - */ - public VerticalAlignMeta() { - super(true, DEFAULT_VERTICAL_ALIGN); - } - - /** - * @param inherit - * @param initvalue - */ - public VerticalAlignMeta(boolean inherit, Object initvalue) { - super(inherit, initvalue); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues() - */ - protected String[] getKeywordValues() { - return KEYWORDS; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#calculateHTMLAttributeOverride(org.w3c.dom.Element, - * java.lang.String, java.lang.String, - * org.eclipse.jst.pagedesigner.css2.ICSSStyle) - */ - public Object calculateHTMLAttributeOverride(Element element, - String htmltag, String propertyName, ICSSStyle style) { - for (int i = 0; i < htmlAttributes.length; i++) { - String align = DOMUtil.getAttributeIgnoreCase(element, - htmlAttributes[i]); - if (TOP.equalsIgnoreCase(align)) { - return TOP; - } - if (MIDDLE.equalsIgnoreCase(align)) { - return MIDDLE; - } - if (BOTTOM.equalsIgnoreCase(align)) { - return BOTTOM; - } - if (BASELINE.equalsIgnoreCase(align)) { - return BASELINE; - } - if (CENTER.equalsIgnoreCase(align)) { - return MIDDLE; - } - } - return null; - } - -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/VisibilityMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/VisibilityMeta.java deleted file mode 100644 index 668bbd3ff..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/VisibilityMeta.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -/** - * @author mengbo - * @version 1.5 - */ -public class VisibilityMeta extends CSSPropertyMeta { - public static final String VISIBLE = "visible"; - - public static final String HIDDEN = "hidden"; - - public static final String COLLAPSE = "collapse"; - - public static final String[] KEYWORDS = new String[] { VISIBLE, HIDDEN, - COLLAPSE }; - - /** - * @param inherit - * @param initvalue - */ - public VisibilityMeta() { - super(true, VISIBLE); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues() - */ - protected String[] getKeywordValues() { - return KEYWORDS; - } - -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/WhiteSpaceMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/WhiteSpaceMeta.java deleted file mode 100644 index afcb81ef6..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/WhiteSpaceMeta.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -import org.eclipse.jst.pagedesigner.IHTMLConstants; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.utils.DOMUtil; -import org.w3c.dom.Element; - -/** - * @author mengbo - */ -public class WhiteSpaceMeta extends CSSPropertyMeta { - static final String[] KEYWORDS = new String[] { ICSSPropertyID.VAL_NORMAL, - ICSSPropertyID.VAL_PRE, ICSSPropertyID.VAL_NOWRAP }; - - /** - * @param inherit - * @param initvalue - */ - public WhiteSpaceMeta() { - super(true, ICSSPropertyID.VAL_NORMAL); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues() - */ - protected String[] getKeywordValues() { - return KEYWORDS; - } - - public Object calculateHTMLAttributeOverride(Element element, - String htmltag, String propertyName, ICSSStyle style) { - if (IHTMLConstants.TAG_TD.equalsIgnoreCase(htmltag) - || IHTMLConstants.TAG_TH.equalsIgnoreCase(htmltag)) { - String noWrap = DOMUtil.getAttributeIgnoreCase(element, - IHTMLConstants.ATTR_NOWRAP); - if (Boolean.TRUE.toString().equalsIgnoreCase(noWrap)) { - return ICSSPropertyID.VAL_NOWRAP; - } - } - return super.calculateHTMLAttributeOverride(element, htmltag, - propertyName, style); - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/WidthMeta.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/WidthMeta.java deleted file mode 100644 index 1f5851e13..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/property/WidthMeta.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.property; - -import org.eclipse.jst.pagedesigner.IHTMLConstants; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.utils.DOMUtil; -import org.w3c.dom.Element; - -/** - * @author mengbo - */ -public class WidthMeta extends LengthMeta { - /** - * @param inherit - * @param initvalue - */ - public WidthMeta() { - super(false, ICSSPropertyID.VAL_AUTO); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#calculateHTMLAttributeOverride(org.w3c.dom.Element, - * java.lang.String, java.lang.String, - * org.eclipse.jst.pagedesigner.css2.ICSSStyle) - */ - public Object calculateHTMLAttributeOverride(Element element, - String htmltag, String propertyName, ICSSStyle style) { - if (!IHTMLConstants.TAG_INPUT.equalsIgnoreCase(htmltag) - && !IHTMLConstants.TAG_BUTTON.equalsIgnoreCase(htmltag)) { - String width = DOMUtil - .getAttributeIgnoreCase(element, propertyName); - if (width != null) { - return LengthMeta.toLength(width, style, this - .getPercentageType(), getBaseFont(style)); - } - } - return super.calculateHTMLAttributeOverride(element, htmltag, - propertyName, style); - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/provider/DimensionInfo.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/provider/DimensionInfo.java deleted file mode 100644 index 74454aa65..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/provider/DimensionInfo.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.provider; - -import org.eclipse.draw2d.geometry.Dimension; - -/** - * This is a struct, include a dimension and a ascent info. - * - * @author mengbo - * @version 1.5 - */ -public class DimensionInfo { - Dimension _dimension; - - int _ascent; - - /** - * - * @param d - * @param ascent - * -1 means ascent is same as dimension height - */ - public DimensionInfo(Dimension d, int ascent) { - this._dimension = d; - this._ascent = ascent; - } - - /** - * @param width - * @param height - * @param i - */ - public DimensionInfo(int width, int height, int i) { - this(new Dimension(width, height), i); - } - - public Dimension getDimension() { - return _dimension; - } - - public int getAscent() { - return _ascent; - } - -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/provider/ICSSTextProvider.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/provider/ICSSTextProvider.java deleted file mode 100644 index f5446aead..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/provider/ICSSTextProvider.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.provider; - -/** - * This class behave as the information provider of CSSTextFigure. - * - * @author mengbo - */ -public interface ICSSTextProvider { - /** - * get the style. - * - * @return can't be null - */ - // public ICSSStyle getCSSStyle(); - /** - * this is the final data to be displayed. There is no need for the - * CSSTextFigure to normalize it. - * - * @return - */ - public String getTextData(); - - /** - * get the selected information. - * - * @return - */ - public int[] getSelectedRange(); -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/provider/ICSSWidgetProvider.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/provider/ICSSWidgetProvider.java deleted file mode 100644 index b1b8a12c6..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/provider/ICSSWidgetProvider.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.provider; - -import org.eclipse.draw2d.Graphics; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; - -/** - * @author mengbo - */ -public interface ICSSWidgetProvider { - /** - * can be null - * - * @return - */ - public ICSSStyle getCSSStyle(); - - public boolean isHandlingBorder(); - - /** - * whether the parameter and return value includes border depends on the - * isHandlingBorder - * - * @param width - * -1 means no suggested value - * @param height - * -1 means no suggested value - * @return - */ - public DimensionInfo getPreferredDimension(int width, int height); - - /** - * if isHandlingBorder return false, then "rect" will be the rect without - * border, and this method should not paint border. - * - * If isHandlingBorder returns true, then "rect" include border, and this - * method should also paint its own border. - * - * @param rect - */ - public void paintFigure(Graphics g, Rectangle rect); - - /** - * @return - */ - public boolean isInline(); -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/style/AbstractStyle.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/style/AbstractStyle.java deleted file mode 100644 index 6d2d4b3bf..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/style/AbstractStyle.java +++ /dev/null @@ -1,658 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.style; - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.draw2d.geometry.Insets; -import org.eclipse.jst.pagedesigner.IHTMLConstants; -import org.eclipse.jst.pagedesigner.css2.CSSUtil; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.font.CSSFontManager; -import org.eclipse.jst.pagedesigner.css2.font.ICSSFont; -import org.eclipse.jst.pagedesigner.css2.font.ICSSFontManager; -import org.eclipse.jst.pagedesigner.css2.list.CounterHelper; -import org.eclipse.jst.pagedesigner.css2.list.CounterValueGenerator; -import org.eclipse.jst.pagedesigner.css2.list.ICounterValueGenerator; -import org.eclipse.jst.pagedesigner.css2.property.CSSMetaRegistry; -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyID; -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta; -import org.eclipse.jst.pagedesigner.css2.value.Length; -import org.eclipse.jst.pagedesigner.utils.DOMUtil; -import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.css.CSSStyleDeclaration; -import org.w3c.dom.css.CSSValue; - -/** - * @author mengbo - */ -public class AbstractStyle implements ICSSStyle { - public static final String ATTR_NAME = "name"; - - public static final String ATTR_ID = "id"; - - protected Element _element; - - private Map _cachedValues = new HashMap(); - - private ICSSFont _font = null; - - private CSSStyleDeclaration _cache; - - private CSSStyleDeclaration _defaultCache; - - private boolean _cssDeclareWasSearched = false; - - private boolean _cssDefaultDeclareWasSearched = false; - - private Insets _borderInsets, _marginInsets, _paddingInsets; - - private ICSSStyle _parentStyle; - - private HashMap _counters = null; - - public Element getElement() { - return _element; - } - - public AbstractStyle(Element element) { - _element = element; - } - - /** - * reset all the cache. - */ - public void reset() { - _cachedValues.clear(); - _font = null; - _cache = null; - _defaultCache = null; - _cssDeclareWasSearched = false; - _cssDefaultDeclareWasSearched = false; - // if (_counters != null) - // { - // unregistCounter(); - // _counters.clear(); - // _counters = null; - // } - _borderInsets = _marginInsets = _paddingInsets = null; - } - - /** - * this is a hook method so caller can use it to override default - * calculation. Note, after the call to <code>reset</code>, it will be - * lost. - * - * @param property - * @param value - */ - public void setStyleProperty(String property, Object value) { - _cachedValues.put(property, value); - } - - /** - * get a style property value. - * - * @param property - * @return - */ - public Object getStyleProperty(String property) { - Object value = _cachedValues.get(property); - if (value == null) { - value = calculateProperty(property); - if (value != null) { - _cachedValues.put(property, value); - } - } - return value; - } - - /** - * in this method, should first check the "style" attribute, then combine - * that with document style. - * - * @return - */ - protected CSSStyleDeclaration calculateDeclaration() { - String name = getHtmlElement().getAttribute("id"); - if (name == null || name.length() == 0) { - name = getHtmlElement().getAttribute("name"); - } - return CSSUtil.getCSSDeclaration(this.getHtmlElement(), name); - } - - protected CSSStyleDeclaration calculateDefaultDeclaration() { - return CSSUtil.getDefaultCSSDeclaration(this.getHtmlElement(), null); - } - - public CSSStyleDeclaration getDeclaration() { - // FIXME:may need to be change, boolean variable is not a best way. - if (!_cssDeclareWasSearched) { - _cache = calculateDeclaration(); - _cssDeclareWasSearched = true; - } - return _cache; - } - - public CSSStyleDeclaration getDefaultDeclaration() { - // FIXME:may need to be change, boolean variable is not a best way. - if (!_cssDefaultDeclareWasSearched) { - _defaultCache = calculateDefaultDeclaration(); - _cssDefaultDeclareWasSearched = true; - } - return _defaultCache; - } - - public Object getHTMLelementInitValue(String propertyName) { - ICSSPropertyMeta meta = getPropertyMeta(propertyName); - if (meta != null) { - Object obj = meta.getHTMLElementInitialValue(_element, - getHTMLTag(), propertyName); - if (obj == null) { - obj = meta.getInitialValue(propertyName, this); - } - return obj; - } - return ICSSPropertyMeta.NOT_SPECIFIED; - } - - protected Object calculateProperty(String propertyName) { - ICSSPropertyMeta meta = getPropertyMeta(propertyName); - Object result = null; - // get declaration - CSSStyleDeclaration decl = getDeclaration(); - CSSValue value = decl == null ? null : decl - .getPropertyCSSValue(propertyName); - if (value == null) { - if (meta != null) { - result = meta.calculateHTMLAttributeOverride(_element, - getHTMLTag(), propertyName, this); - if (result != null) { - return result; - } - } - decl = getDefaultDeclaration(); - } - value = decl == null ? null : decl.getPropertyCSSValue(propertyName); - - if (value != null && value.getCssValueType() == CSSValue.CSS_INHERIT) { - result = getParentResultValue(meta, propertyName); - } else if (value == null) { - if (meta != null) { - result = meta.calculateHTMLAttributeOverride(_element, - getHTMLTag(), propertyName, this); - } - if (result == null) { - result = calculateLocalOverride(meta, propertyName); - } - if (result == null) { - if (meta == null) { - result = ICSSPropertyMeta.NOT_SPECIFIED; - } else { - if (meta.isInherited()) { - result = getParentResultValue(meta, propertyName); - } else { - result = meta.getInitialValue(propertyName, this); - } - } - } - } else { - result = calculateCSSValueResult(meta, value, propertyName); - } - return result; - } - - /** - * get the corresponding HTML tag for this style. This is for certain HTML - * tag can also provide style information. - * - * @return - */ - protected String getHTMLTag() { - return _element.getTagName(); - } - - /** - * @param propertyName - * @return - */ - protected ICSSPropertyMeta getPropertyMeta(String propertyName) { - return CSSMetaRegistry.getInstance().getMeta(propertyName); - } - - /** - * convert the CSSValue to the property type specified data result. - * - * @param value - * @param propertyName - * @return should not return null. - */ - protected Object calculateCSSValueResult(ICSSPropertyMeta meta, - CSSValue value, String propertyName) { - if (meta == null) { - return ICSSPropertyMeta.NOT_SPECIFIED; - } - return meta.calculateCSSValueResult(value, propertyName, this); - } - - /** - * it is possible that some attribute of the element may provide style - * information. child class should override this method. Also, some element - * type may have internally build style, such as input-submit may use - * special border. NOTE: it is very important that in calculateLocalOverride - * you don't directly or indirectly call getStyleProperty() to avoid - * deadloop. - * - * @param propertyName - * @return null means no style information in other attributes. Otherwise - * return property specific data result -- normally will use meta to - * convert the attribute. - */ - protected Object calculateLocalOverride(ICSSPropertyMeta meta, - String propertyName) { - // // do some default margin thing. - // if (ICSSPropertyID.ATTR_MARGIN_RIGHT.equalsIgnoreCase(propertyName) - // || ICSSPropertyID.ATTR_MARGIN_BOTTOM.equalsIgnoreCase(propertyName)) - // { - // return MARGIN_LENGTH; - // } - // else if - // (ICSSPropertyID.ATTR_MARGIN_LEFT.equalsIgnoreCase(propertyName)) - // { - // // to make a little room, so it is possible for user to position the - // // mouse before the first element in a block. - // return MARGIN_LEFT; - // } - return null; - } - - /** - * This is only called when inherit value from parent. - * - * @param propertyName - * @return - */ - protected Object getParentResultValue(ICSSPropertyMeta meta, - String propertyName) { - ICSSStyle style = getParentStyle(); - return style.getStyleProperty(propertyName); - } - - public void setParentStyle(ICSSStyle parentStyle) { - this._parentStyle = parentStyle; - reset(); - } - - public ICSSStyle getParentStyle() { - if (_parentStyle != null) { - return _parentStyle; - } - Node node = _element.getParentNode(); - while (node instanceof Element && node instanceof INodeNotifier) { - ICSSStyle parentStyle = (ICSSStyle) ((INodeNotifier) node) - .getAdapterFor(ICSSStyle.class); - if (parentStyle != null) { - return parentStyle; - } - node = node.getParentNode(); - } - return DefaultStyle.getInstance(); - } - - /** - * Will not return null - * - * @return - */ - public ICSSFont getCSSFont() { - if (_font == null) { - _font = getFontManager().createFont(this); - } - return _font; - } - - /** - * @return - */ - private ICSSFontManager getFontManager() { - return CSSFontManager.getInstance(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#dispose() - */ - public void dispose() { - // TODO: anything to dispose? - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#getMarginInsets() - */ - public Insets getMarginInsets() { - if (_marginInsets == null) { - int top = getInsetProperty(ICSSPropertyID.ATTR_MARGIN_TOP); - int left = getInsetProperty(ICSSPropertyID.ATTR_MARGIN_LEFT); - int bottom = getInsetProperty(ICSSPropertyID.ATTR_MARGIN_BOTTOM); - int right = getInsetProperty(ICSSPropertyID.ATTR_MARGIN_RIGHT); - _marginInsets = new Insets(top, left, bottom, right); - } - return _marginInsets; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#getPaddingInsets() - */ - public Insets getPaddingInsets() { - if (_paddingInsets == null) { - int top = getInsetProperty(ICSSPropertyID.ATTR_PADDING_TOP); - int left = getInsetProperty(ICSSPropertyID.ATTR_PADDING_LEFT); - int bottom = getInsetProperty(ICSSPropertyID.ATTR_PADDING_BOTTOM); - int right = getInsetProperty(ICSSPropertyID.ATTR_PADDING_RIGHT); - _paddingInsets = new Insets(top, left, bottom, right); - } - return _paddingInsets; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#getBorderInsets() - */ - public Insets getBorderInsets() { - if (_borderInsets == null) { - int top = getInsetProperty(ICSSPropertyID.ATTR_BORDER_TOP_WIDTH); - int left = getInsetProperty(ICSSPropertyID.ATTR_BORDER_LEFT_WIDTH); - int bottom = getInsetProperty(ICSSPropertyID.ATTR_BORDER_BOTTOM_WIDTH); - int right = getInsetProperty(ICSSPropertyID.ATTR_BORDER_RIGHT_WIDTH); - _borderInsets = new Insets(top, left, bottom, right); - } - return _borderInsets; - } - - /** - * @param border_top_width - * @return - */ - private int getInsetProperty(String propertyName) { - Object obj = this.getStyleProperty(propertyName); - if (obj instanceof Length) { - Length l = (Length) obj; - if (l.isPercentage()) { - return 0; // FIXME: - } - return l.getValue(); - } - - return 0; - } - - public boolean isAdapterForType(Object type) { - return (type == ICSSStyle.class); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#isSizeIncludeBorderPadding() - */ - public boolean isSizeIncludeBorderPadding() { - String display = this.getDisplay(); - if ("table-cell".equalsIgnoreCase(display)) { - return false; - } - String tag = this.getHTMLTag(); - if ("img".equalsIgnoreCase(tag)) { - return false; - } - return true; - } - - /* - * (non-Javadoc) - * - * @see com.ibm.sse.model.INodeAdapter#notifyChanged(com.ibm.sse.model.INodeNotifier, - * int, java.lang.Object, java.lang.Object, java.lang.Object, int) - */ - public void notifyChanged(INodeNotifier notifier, int eventType, - Object changedFeature, Object oldValue, Object newValue, int pos) { - // do nothing - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#getBackgroundColor() - */ - public Object getColor() { - Object _color = null; - if (_color == null) { - _color = getStyleProperty(ICSSPropertyID.ATTR_COLOR); - if (_color == null) { - _color = getStyleProperty(ICSSPropertyID.ATTR_TEXTCOLOR); - } - } - return _color; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#getColor() - */ - public Object getBackgroundColor() { - Object _backgroundColor = null; - if (_backgroundColor == null) { - _backgroundColor = getStyleProperty(ICSSPropertyID.ATTR_BACKGROUND_COLOR); - } - return _backgroundColor; - } - - public Element getHtmlElement() { - // if (_element instanceof IDOMElement) - // { - // EditPart part = (EditPart) ((IDOMElement) - // _element).getAdapterFor(EditPart.class); - // if (part instanceof ElementEditPart) - // { - // ElementEditPart elementPart = (ElementEditPart) part; - // ITagHandler h = elementPart.getTagHandler(); - // if (h != null) - // { - // return h.mapCustomElement(_element); - // } - // } - // - // } - return _element; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#getDisplay() - */ - public String getDisplay() { - Object display = this.getStyleProperty(ICSSPropertyID.ATTR_DISPLAY); - String displayStr; - if (display == null) { - displayStr = ICSSPropertyID.VAL_INLINE; - } else if (display instanceof String) { - displayStr = (String) display; - } else { - displayStr = display.toString(); - } - if (ICSSPropertyID.VAL_INLINE.equalsIgnoreCase(displayStr) - && IHTMLConstants.TAG_TABLE.equalsIgnoreCase(getHTMLTag())) { - return ICSSPropertyID.VAL_INLINE_TABLE; - } - if (ICSSPropertyID.VAL_INLINE.equalsIgnoreCase(displayStr)) { - Object width = this.getStyleProperty(ICSSPropertyID.ATTR_WIDTH); - if (width instanceof Length) { - return ICSSPropertyID.VAL_INLINE_BLOCK; - } - Object height = this.getStyleProperty(ICSSPropertyID.ATTR_HEIGHT); - if (height instanceof Length) { - return ICSSPropertyID.VAL_INLINE_BLOCK; - } - return displayStr; - } - return displayStr; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#getListStyle() - */ - public Map getCounters() { - if (_counters == null) { - _counters = new HashMap(); - CounterHelper.processCounterReset(this, _counters); - } - return _counters; - } - - /** - * Get named counter from counters. - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#getCounter(java.lang.String) - */ - public ICounterValueGenerator findCounter(String name, boolean must) { - Map counters = getCounters(); - if (counters == null || !counters.containsKey(name)) { - if (getParentStyle() != null - && !(getParentStyle() instanceof DefaultStyle)) { - // ensure it is registered somewhere. - return getParentStyle().findCounter(name, must); - } - // must is called by counter-increment - else if (must) { - // the caller should do the other setting. - ICounterValueGenerator counter = new CounterValueGenerator( - name, null, null, this); - counter.resetCount(); - counters.put(name, counter); - } - } - return (ICounterValueGenerator) counters.get(name); - } - - /** - * @param buffer - */ - public void dumpDebugInfo(StringBuffer buffer) { - if (_cache != null) { - buffer.append("cache:\n"); - buffer.append(_cache.getCssText()).append("\n"); - } - if (_defaultCache != null) { - buffer.append("default cache:\n"); - buffer.append(_defaultCache.getCssText()).append("\n"); - } - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#getColSpan() - */ - public int getColSpan() { - int colspan = DOMUtil.getIntAttributeIgnoreCase(getHtmlElement(), - "colspan", 1); - // if span == 0, means span all col from the current column to end - // colume - if (colspan < 0) { - return 1; - } - return colspan; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#getRowSpan() - */ - public int getRowSpan() { - int rowspan = DOMUtil.getIntAttributeIgnoreCase(getHtmlElement(), - "rowspan", 1); - if (rowspan < 0) { - return 1; - } - return rowspan; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#isInSelection() - */ - public boolean isInSelection() { - IRangeSelectionProxy proxy = (IRangeSelectionProxy) getAdapter(IRangeSelectionProxy.class); - if (proxy != null) { - return proxy.isRangeSelected(); - } - ICSSStyle parentStyle = getParentStyle(); - if (parentStyle != null) { - return parentStyle.isInSelection(); - } - return false; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) - */ - public Object getAdapter(Class adapter) { - if (this._element instanceof INodeNotifier) { - Object ret = ((INodeNotifier) _element).getAdapterFor(adapter); - if (ret != null && adapter.isInstance(ret)) { - return ret; - } - } - return null; - } - - // private void unregistCounter() - // { - // if (_counters != null) - // { - // Collection c = _counters.values(); - // Iterator iter = c.iterator(); - // while (iter.hasNext()) - // { - // Counter2 counter = (Counter2) iter.next(); - // counter.unregist(this); - // } - // } - // } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#resetCounters() - */ - public void processCounters() { - this._counters = null; - CounterHelper.processCounterIncrement(this); - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/style/ControlOverrideSupport.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/style/ControlOverrideSupport.java deleted file mode 100644 index d8d67df55..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/style/ControlOverrideSupport.java +++ /dev/null @@ -1,85 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.style; - -import org.eclipse.draw2d.ColorConstants; -import org.eclipse.jst.pagedesigner.css2.property.BorderStyleMeta; -import org.eclipse.jst.pagedesigner.css2.property.BorderWidthMeta; -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyID; -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta; -import org.eclipse.jst.pagedesigner.css2.property.TextDecorationMeta; -import org.eclipse.jst.pagedesigner.css2.value.Length; -import org.eclipse.swt.graphics.Color; - -/** - * This class provides support for setting default styles of certain UI - * controls. - * - * @author mengbo - */ -public class ControlOverrideSupport { - static Color _buttonBackground = ColorConstants.button; - - public static Object handleButtonOverride(ICSSPropertyMeta meta, - String propertyName) { - // if (BorderStyleMeta.isBorderStyle(propertyName)) - // { - // return ICSSPropertyID.VAL_RIDGE; - // } - // else if (BorderWidthMeta.isBorderWidth(propertyName)) - // { - // return Length.LENGTH_3; - // } - // else if - // (ICSSPropertyID.ATTR_TEXTDECORATION.equalsIgnoreCase(propertyName)) - // { - // return new Integer(TextDecorationMeta.NONE); - // } - // else if - // (ICSSPropertyID.ATTR_BACKGROUND_COLOR.equalsIgnoreCase(propertyName)) - // { - // return _buttonBackground; - // } - // else if - // (ICSSPropertyID.ATTR_PADDING_LEFT.equalsIgnoreCase(propertyName) || - // ICSSPropertyID.ATTR_PADDING_RIGHT.equalsIgnoreCase(propertyName)) - // { - // return Length.LENGTH_8; - // } - - return null; - } - - public static Object handleInputTextOverride(ICSSPropertyMeta meta, - String propertyName) { - if (BorderStyleMeta.isBorderStyle(propertyName)) { - return ICSSPropertyID.VAL_GROOVE; - } else if (BorderWidthMeta.isBorderWidth(propertyName)) { - return Length.LENGTH_3; - } else if (ICSSPropertyID.ATTR_TEXTDECORATION - .equalsIgnoreCase(propertyName)) { - return new Integer(TextDecorationMeta.NONE); - } - - return null; - } - - public static Object handleHighlightBorderOverride(ICSSPropertyMeta meta, - String propertyName) { - if (BorderStyleMeta.isBorderStyle(propertyName)) { - return ICSSPropertyID.VAL_DOTTED; - } else if (BorderWidthMeta.isBorderWidth(propertyName)) { - return Length.LENGTH_1; - } - return null; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/style/DefaultStyle.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/style/DefaultStyle.java deleted file mode 100644 index 58ecdbe64..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/style/DefaultStyle.java +++ /dev/null @@ -1,256 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.style; - -import java.util.Map; - -import org.eclipse.draw2d.geometry.Insets; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.font.CSSFontManager; -import org.eclipse.jst.pagedesigner.css2.font.ICSSFont; -import org.eclipse.jst.pagedesigner.css2.list.ICounterValueGenerator; -import org.eclipse.jst.pagedesigner.css2.property.CSSMetaRegistry; -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta; -import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; - -/** - * @author mengbo - */ -public class DefaultStyle implements ICSSStyle { - - private static final Insets EMPTY_INSETS = new Insets(); - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#reset() - */ - public void reset() { - // TODO: dead? - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#getStyleProperty(java.lang.String) - */ - public Object getStyleProperty(String property) { - ICSSPropertyMeta meta = CSSMetaRegistry.getInstance().getMeta(property); - if (meta == null) { - return ICSSPropertyMeta.NOT_SPECIFIED; - } - return meta.getInitialValue(property, this); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#getMarginInsets() - */ - public Insets getMarginInsets() { - return EMPTY_INSETS; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#getBorderInsets() - */ - public Insets getBorderInsets() { - return EMPTY_INSETS; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#getPaddingInsets() - */ - public Insets getPaddingInsets() { - return EMPTY_INSETS; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#isSizeIncludeBorderPadding() - */ - public boolean isSizeIncludeBorderPadding() { - return true; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#dispose() - */ - public void dispose() { - // TODO: anything to dispose - } - - /* - * (non-Javadoc) - * - * @see com.ibm.sse.model.INodeAdapter#isAdapterForType(java.lang.Object) - */ - public boolean isAdapterForType(Object type) { - return type == ICSSStyle.class; - } - - /* - * (non-Javadoc) - * - * @see com.ibm.sse.model.INodeAdapter#notifyChanged(com.ibm.sse.model.INodeNotifier, - * int, java.lang.Object, java.lang.Object, java.lang.Object, int) - */ - public void notifyChanged(INodeNotifier notifier, int eventType, - Object changedFeature, Object oldValue, Object newValue, int pos) { - // TODO: do nothing? - } - - private ICSSFont defaultFont = CSSFontManager.getInstance().createDefaultFont(); - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#getCSSFont() - */ - public ICSSFont getCSSFont() { - return defaultFont; - } - - /** - * @return - */ - public static ICSSStyle getInstance() { - if (_instance == null) { - _instance = new DefaultStyle(); - } - return _instance; - } - - static DefaultStyle _instance; - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#getParentStyle() - */ - public ICSSStyle getParentStyle() { - // return this; - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#getBackgroundColor() - */ - public Object getBackgroundColor() { - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#getColor() - */ - public Object getColor() { - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#getDisplay() - */ - public String getDisplay() { - return "inline"; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#getListStyle() - */ - public Map getCounters() { - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#getCounter(java.lang.String) - */ - public ICounterValueGenerator findCounter(String name, boolean must) { - // TODO Auto-generated method stub - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#getColSpan() - */ - public int getColSpan() { - return 1; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#getRowSpan() - */ - public int getRowSpan() { - return 1; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#isInSelection() - */ - public boolean isInSelection() { - return false; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) - */ - public Object getAdapter(Class adapter) { - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#resetCounters() - */ - public void processCounters() { - // do nothing. - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.ICSSStyle#getHTMLelementValue(java.lang.String) - */ - public Object getHTMLelementInitValue(String propertyName) { - ICSSPropertyMeta meta = CSSMetaRegistry.getInstance().getMeta( - propertyName); - if (meta == null) { - return ICSSPropertyMeta.NOT_SPECIFIED; - } - return meta.getInitialValue(propertyName, this); - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/style/HiddenElementStyle.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/style/HiddenElementStyle.java deleted file mode 100644 index 46c190754..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/style/HiddenElementStyle.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.style; - -import org.eclipse.jst.pagedesigner.parts.EditProxyAdapter; -import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; -import org.w3c.dom.Element; - -public class HiddenElementStyle extends DefaultStyle { - private EditProxyAdapter _editProxyAdapter; - - private Element _convertedElement; - - private static ITagEditInfo _tagEditInfo = new ITagEditInfo() { - - public boolean isWidget() { - return true; - } - - public boolean needBorderDecorator() { - return false; - } - - public boolean needTableDecorator() { - return false; - } - - public int getMinWidth() { - return 0; - } - - public int getMinHeight() { - return 0; - } - }; - - public HiddenElementStyle(EditProxyAdapter adapter) { - this._editProxyAdapter = adapter; - } - - public HiddenElementStyle(Element convertedElement) { - this._convertedElement = convertedElement; - } - - public boolean isInSelection() { - if (_convertedElement instanceof INodeNotifier) { - Object ret = ((INodeNotifier) _convertedElement) - .getAdapterFor(AbstractStyle.class); - if (ret instanceof AbstractStyle) { - return ((AbstractStyle) ret).isInSelection(); - } - } - - if (_editProxyAdapter != null) { - return _editProxyAdapter.isRangeSelected(); - } - - return false; - } - - public Object getAdapter(Class adapter) { - if (_convertedElement instanceof INodeNotifier) { - Object ret = ((INodeNotifier) _convertedElement) - .getAdapterFor(AbstractStyle.class); - if (ret instanceof AbstractStyle) { - return ((AbstractStyle) ret).getAdapter(adapter); - } - } - if (_editProxyAdapter != null && adapter == ITagEditInfo.class) { - return _tagEditInfo; - } - return null; - } - -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/style/IRangeSelectionProxy.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/style/IRangeSelectionProxy.java deleted file mode 100644 index 499193e1f..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/style/IRangeSelectionProxy.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.style; - -/** - * @author mengbo - * @version 1.5 - */ -public interface IRangeSelectionProxy { - - /** - * @return - */ - boolean isRangeSelected(); - -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/style/ITagEditInfo.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/style/ITagEditInfo.java deleted file mode 100644 index d19b98249..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/style/ITagEditInfo.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.style; - -/** - * @author mengbo - * @version 1.5 - */ -public interface ITagEditInfo { - public boolean isWidget(); - - public boolean needBorderDecorator(); - - public boolean needTableDecorator(); - - /** - * for some element in design mode we want to them to have a default min - * size. - * - * @return positive value means an expected min size. - */ - public int getMinWidth(); - - public int getMinHeight(); -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/style/ImageStyleHelper.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/style/ImageStyleHelper.java deleted file mode 100644 index 6072010de..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/style/ImageStyleHelper.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.style; - -import org.eclipse.swt.graphics.Image; -import org.eclipse.wst.sse.core.internal.util.URIResolver; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; -import org.w3c.dom.Element; - -/** - * @author mengbo - */ -public class ImageStyleHelper { - public static Image loadImage(String url, Element source) { - if (source instanceof IDOMElement) { - IDOMModel model = ((IDOMElement) source).getModel(); - // TODO: the new resolver is not compatible with model - URIResolver resolver = model.getResolver(); - if (resolver != null) - url = resolver.getLocationByURI(url); - } - if (url != null) { - return new Image(null, url); - } - return null; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/style/StyleUtil.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/style/StyleUtil.java deleted file mode 100644 index 9f1e0c5c0..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/style/StyleUtil.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.style; - -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; - -/** - * @author mengbo - * @version 1.5 - */ -public class StyleUtil { - public static boolean isInWidget(ICSSStyle style) { - while (style != null && style != DefaultStyle.getInstance()) { - ITagEditInfo info = (ITagEditInfo) style - .getAdapter(ITagEditInfo.class); - if (info != null && info.isWidget()) { - return true; - } - - style = style.getParentStyle(); - } - return false; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/value/Length.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/value/Length.java deleted file mode 100644 index 47afe93dc..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/value/Length.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.value; - -/** - * @author mengbo - */ -public class Length { - public static final Length LENGTH_0 = new Length(0, false); - - public static final Length LENGTH_1 = new Length(1, false); - - public static final Length LENGTH_2 = new Length(2, false); - - public static final Length LENGTH_3 = new Length(3, false); - - public static final Length LENGTH_8 = new Length(8, false); - - boolean _percentage; - - int _value; - - public Length(int value, boolean percentage) { - _value = value; - _percentage = percentage; - } - - public boolean isPercentage() { - return _percentage; - } - - public int getValue() { - return _value; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/AbstractWidgetProvider.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/AbstractWidgetProvider.java deleted file mode 100644 index f380d712d..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/AbstractWidgetProvider.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.widget; - -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.provider.ICSSWidgetProvider; - -/** - * @author mengbo - * @version 1.5 - */ -public abstract class AbstractWidgetProvider implements ICSSWidgetProvider { - public static int BORDERTHICK = 2; - - ICSSStyle _style; - - public AbstractWidgetProvider(ICSSStyle style) { - _style = style; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.provider.ICSSWidgetProvider#getCSSStyle() - */ - public ICSSStyle getCSSStyle() { - return _style; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.provider.ICSSWidgetProvider#isHandlingBorder() - */ - public boolean isHandlingBorder() { - return true; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.provider.ICSSWidgetProvider#isInline() - */ - public boolean isInline() { - return true; - } - -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/BorderUtil.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/BorderUtil.java deleted file mode 100644 index 4a3b06b75..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/BorderUtil.java +++ /dev/null @@ -1,268 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.widget; - -import java.util.List; - -import org.eclipse.draw2d.ColorConstants; -import org.eclipse.draw2d.Graphics; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.jst.pagedesigner.css2.layout.CSSFigure; -import org.eclipse.jst.pagedesigner.css2.layout.FlowBox; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.widgets.Display; - -/** - * @author mengbo - * @version 1.5 - */ -public class BorderUtil { - public final static int VERTICAL_BAR = 0; - - public final static int HORIZONTAL_BAR = 1; - - public final static int BOTH = 2; - - public final static int SCROLL_WIDTH = 16; - - public final static int BORDER_THICK = 2; - - /** - * draw a mask to a rectangle - * - * @param Graphics - * @param Rectangle - * @param Color - */ - public static void maskRectangle(Graphics g, Rectangle rect, Color color) { - // default color is blue - if (color == null) { - color = ColorConstants.blue; - } - - // get old information and keep them - int lineStyle = g.getLineStyle(); - Color foregroundColor = g.getForegroundColor(); - - g.setLineStyle(SWT.LINE_SOLID); - g.setForegroundColor(color); - for (int i = 0, n = rect.height; i < n; i++, i++) { - for (int j = 0, m = rect.width; j < m; j++, j++) { - g.drawLine(rect.x + j, rect.y + i, rect.x + j, rect.y + i); - } - } - - // restore to the old state - g.setLineStyle(lineStyle); - g.setForegroundColor(foregroundColor); - } - - public static void drawBorder(Graphics g, Rectangle rect, int thick, - boolean inset) { - drawBorder(g, rect.x, rect.y, rect.width, rect.height, thick, inset); - } - - /** - * draw a standard border. - * - * @param g - * @param left - * @param top - * @param width - * @param height - * @param thick - * @param inset - */ - public static void drawBorder(Graphics g, int left, int top, int width, - int height, int thick, boolean inset) { - Color[] ltColors = new Color[] { - Display.getCurrent().getSystemColor( - SWT.COLOR_WIDGET_LIGHT_SHADOW), - Display.getCurrent().getSystemColor( - SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW) }; - if (inset) { - ltColors = new Color[] { ColorConstants.buttonDarker, - ColorConstants.buttonDarkest }; - } - for (int i = 0; i < thick; i++) { - g.setForegroundColor(ltColors[ltColors.length * i / thick]); - g.drawLine(left + i, top + i, left + width - 1 - i, top + i); - g.drawLine(left + i, top + i, left + i, top + height - i - i); - } - - Color[] rbColors = new Color[] { - Display.getCurrent().getSystemColor( - SWT.COLOR_WIDGET_DARK_SHADOW), - Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GRAY) }; - if (inset) { - rbColors = new Color[] { ColorConstants.buttonLightest, - ColorConstants.button }; - } - for (int i = 0; i < thick; i++) { - g.setForegroundColor(rbColors[ltColors.length * i / thick]); - g.drawLine(left + i, top - i + height - 1, left + width - 1 - i, - top - i + height - 1); - g.drawLine(left + width - 1 - i, top + i, left + width - 1 - i, top - + height - 1 - i); - } - } - - public static void drawScrollBar(Graphics g, int scrollWidth, - Rectangle rect, int style) { - drawScrollBar(g, scrollWidth, BORDER_THICK, rect, style); - } - - public static void drawScrollBar(Graphics g, int scrollWidth, - int borderThick, Rectangle rect, int style) { - if (style == BOTH) { - int width = scrollWidth; - int left = rect.x + rect.width - width; - int top = rect.y; - int height = rect.height; - Rectangle barRect = new Rectangle(left, top, width, height); - fillBar(g, barRect); - barRect = new Rectangle(left, top, width, height - scrollWidth); - drawVerticalPart(g, scrollWidth, borderThick, barRect); - - left = rect.x + borderThick; - top = top + height - scrollWidth; - width = rect.width; - height = scrollWidth; - barRect = new Rectangle(left, top, width, height); - fillBar(g, barRect); - barRect = new Rectangle(left, top, width - scrollWidth - 2, height); - drawHorizontalPart(g, scrollWidth, borderThick, barRect); - } else if (style == VERTICAL_BAR) { - int width = scrollWidth; - int left = rect.x + rect.width - width; - int top = rect.y; - int height = rect.height; - Rectangle barRect = new Rectangle(left, top, width, height); - fillBar(g, barRect); - drawVerticalPart(g, scrollWidth, borderThick, barRect); - } else if (style == HORIZONTAL_BAR) { - int left = rect.x + borderThick; - int top = rect.y + rect.height - scrollWidth; - int width = rect.width; - int height = scrollWidth; - Rectangle barRect = new Rectangle(left, top, width, height); - fillBar(g, barRect); - drawHorizontalPart(g, scrollWidth, borderThick, barRect); - } - } - - private static void fillBar(Graphics g, Rectangle rect) { - g.setBackgroundColor(ColorConstants.button); - g.fillRectangle(rect); - } - - private static void drawVerticalPart(Graphics g, int arrawLength, - int borderThick, Rectangle rect) { - int left = rect.x; - int top = rect.y; - int width = Math.min(arrawLength, rect.width); - int height = Math.min(arrawLength, rect.height / 2); - - Rectangle borderRect = new Rectangle(left, top, width, height); - BorderUtil.drawBorder(g, borderRect, borderThick, false); - - g.setForegroundColor(ColorConstants.black); - int decoratorWidth = (width - borderThick * 2) / 2; - int length = decoratorWidth / 2 + 1; - int leftX = rect.x + (width - decoratorWidth) / 2 - 1; - int bottomY = rect.y + (height + length) / 2 - 1; - for (int i = 0; i < length; i++) { - g.drawLine(leftX + i, bottomY - i, leftX - i + decoratorWidth, - bottomY - i); - } - - top = rect.y + rect.height - height; - borderRect = new Rectangle(left, top, width, height); - BorderUtil.drawBorder(g, borderRect, borderThick, false); - - int topY = top + (height - length) / 2; - g.setForegroundColor(ColorConstants.black); - for (int i = 0; i < length; i++) { - g.drawLine(leftX + i, topY + i, leftX - i + decoratorWidth, topY - + i); - } - } - - private static void drawHorizontalPart(Graphics g, int arrawLength, - int borderThick, Rectangle rect) { - int left = rect.x; - int top = rect.y; - int width = Math.min(arrawLength, rect.width / 2); - int height = Math.min(arrawLength, rect.height); - - Rectangle borderRect = new Rectangle(left, top, width, height); - BorderUtil.drawBorder(g, borderRect, borderThick, false); - - g.setForegroundColor(ColorConstants.black); - int decoratorHeight = (height - borderThick * 2) / 2; - int length = decoratorHeight / 2 + 1; - int leftX = rect.x + (width + length) / 2 - 1; - int bottomY = rect.y + (height - length) / 2 - 1; - for (int i = 0; i < length; i++) { - g.drawLine(leftX - i, bottomY + i, leftX - i, bottomY - i - + decoratorHeight); - } - - left = rect.x + rect.width - width; - borderRect = new Rectangle(left, top, width, height); - BorderUtil.drawBorder(g, borderRect, borderThick, false); - - leftX = left + (width - length) / 2; - g.setForegroundColor(ColorConstants.black); - for (int i = 0; i < length; i++) { - g.drawLine(leftX + i, bottomY + i, leftX + i, bottomY - i - + decoratorHeight); - } - } - - public static void drawVertialBar(Graphics g, int arrawWidth, - int arrawHeight, int borderThick, Rectangle rect) { - drawScrollBar(g, arrawWidth, borderThick, rect, VERTICAL_BAR); - } - - /** - * @param figure - * @param graphics - */ - public static void drawBorderDecorator(CSSFigure figure, Graphics graphics) { - graphics.setLineWidth(1); - graphics.setLineStyle(Graphics.LINE_DOT); - graphics.setForegroundColor(ColorConstants.lightBlue); - List fragments = figure.getFragmentsForRead(); - for (int i = 0, size = fragments.size(); i < size; i++) { - FlowBox box = (FlowBox) fragments.get(i); - // XXX: why -1? - graphics.drawRectangle(box._x, box._y, box.getWidth() - 1, box - .getHeight() - 1); - } - graphics.restoreState(); - } - - /** - * @param figure - * @param g - */ - public static void maskFigure(CSSFigure figure, Graphics g) { - List fragments = figure.getFragmentsForRead(); - for (int i = 0, size = fragments.size(); i < size; i++) { - FlowBox box = (FlowBox) fragments.get(i); - maskRectangle(g, new Rectangle(box._x, box._y, box.getWidth(), box - .getHeight()), null); - } - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/ButtonWidgetProvider.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/ButtonWidgetProvider.java deleted file mode 100644 index e4a8ed8a1..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/ButtonWidgetProvider.java +++ /dev/null @@ -1,203 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.widget; - -import java.util.StringTokenizer; - -import org.eclipse.draw2d.ColorConstants; -import org.eclipse.draw2d.FigureUtilities; -import org.eclipse.draw2d.Graphics; -import org.eclipse.draw2d.geometry.Dimension; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.font.ICSSFont; -import org.eclipse.jst.pagedesigner.css2.layout.TextLayoutSupport; -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyID; -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta; -import org.eclipse.jst.pagedesigner.css2.provider.DimensionInfo; -import org.eclipse.jst.pagedesigner.css2.style.DefaultStyle; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.swt.widgets.Display; - -/** - * For ButtonWidget, it displays some text value in it. And lays the text with - * nowrap. - * - * @author mengbo - * @version 1.5 - */ -public class ButtonWidgetProvider extends AbstractWidgetProvider { - // The button width should include the label length and padding, - // to let the button looks fine, we set the padding 0.46 width as the label - // length. - private final static double HORIZONTAL_RATE = 1.46; - - // The button height should include the label height and padding, - // to let the button looks fine, we set the padding 0.36 height as the - // character height. - private final static double VERTICAL_PADDING_RATE = 0.36; - - static final String[] DEFAULTLINES = new String[] { " " }; - - private String _value = ""; - - private String[] _lines = DEFAULTLINES; - -// private List _fragments = new ArrayList(); - - /** - * @param style - */ - public ButtonWidgetProvider(ICSSStyle style) { - super(style); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.provider.ICSSWidgetProvider#getPreferredDimension(int, - * int) - */ - public DimensionInfo getPreferredDimension(int width, int height) { - if (width <= 0) { - width = getDefaultWidth(); - } - if (height <= 0) { - height = getDefaultHeight(); - } - return new DimensionInfo(new Dimension(width, height), -1); - } - - /** - * by default, the combo's width will be calculated from the longest option - * value. - * - * @return - */ - public int getDefaultWidth() { - int longestStringWidth = 0; - if (_lines != null) { - ICSSStyle style = this.getCSSStyle(); - if (style == null) { - style = DefaultStyle.getInstance(); - } - ICSSFont font = style.getCSSFont(); - Font swtFont = font.getSwtFont(); - for (int i = 0; i < _lines.length; i++) { - int width = FigureUtilities.getTextWidth(_lines[i], swtFont); - if (width > longestStringWidth) { - longestStringWidth = width; - } - } - } - // text area width + padding - return (int) ((longestStringWidth) * HORIZONTAL_RATE); - } - - /** - * - * @return - * @see TextInputWidgetProvider#getDefaultHeight() - */ - public int getDefaultHeight() { - ICSSStyle style = this.getCSSStyle(); - if (style == null) { - style = DefaultStyle.getInstance(); - } - ICSSFont font = style.getCSSFont(); - Font swtfont = font.getSwtFont(); - int fontHeight = FigureUtilities.getFontMetrics(swtfont).getHeight(); - return (int) ((fontHeight) * (_lines.length + VERTICAL_PADDING_RATE)); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.provider.ICSSWidgetProvider#paintFigure(org.eclipse.draw2d.Graphics, - * org.eclipse.draw2d.geometry.Rectangle) - */ - public void paintFigure(Graphics g, Rectangle rect) { - ICSSStyle style = this.getCSSStyle(); - if (style == null) { - style = DefaultStyle.getInstance(); - } - Object textAlign = style - .getStyleProperty(ICSSPropertyID.ATTR_TEXTALIGN); - if (ICSSPropertyMeta.NOT_SPECIFIED == textAlign) { - textAlign = "center"; - } - Font font = style.getCSSFont().getSwtFont(); - g.setFont(font); - int fontHeight = FigureUtilities.getFontMetrics(font).getHeight(); - - Color newColor = null; - Object color = style.getColor(); - if (color instanceof Color) { - g.setForegroundColor((Color) color); - } else if (color instanceof RGB) { - newColor = new Color(Display.getCurrent(), (RGB) color); - g.setForegroundColor(newColor); - } else { - g.setForegroundColor(ColorConstants.black); - } - - g.clipRect(rect); - - int y = rect.y + (int) (fontHeight * VERTICAL_PADDING_RATE / 2); - if (rect.height > fontHeight * _lines.length) { - y = rect.y + (rect.height - fontHeight * _lines.length) / 2; - } - - for (int i = 0; i < _lines.length && y < rect.y + rect.height; i++) { - int width = FigureUtilities.getTextWidth(_lines[i], font); - int x = TextLayoutSupport.getBeginX(textAlign, rect, width); - g.drawString(_lines[i], x, y); - TextLayoutSupport.paintTextDecoration(g, new Rectangle(x, y, width, - fontHeight), ((Integer) getCSSStyle().getStyleProperty( - ICSSPropertyID.ATTR_TEXTDECORATION)).intValue()); - y += fontHeight; - } - - if (newColor != null) { - newColor.dispose(); - } - } - - public void setValue(String value) { - if (value == null) { - value = ""; - } - _value = value; - _lines = splitValue(_value); - } - - /** - * Split the value to multiple lines. - * - * @param _value2 - * @return - */ - private String[] splitValue(String _value2) { - if (_value2 == null || "".equals(_value2)) { - return DEFAULTLINES; - } - - StringTokenizer tokenizer = new StringTokenizer(_value2, "\r\n"); - String[] result = new String[tokenizer.countTokens()]; - for (int i = 0; i < result.length; i++) { - result[i] = tokenizer.nextToken().replaceAll("\t", " "); - } - return result; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/CheckboxWidgetProvider.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/CheckboxWidgetProvider.java deleted file mode 100644 index 2bbd8f6b4..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/CheckboxWidgetProvider.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.widget; - -import org.eclipse.draw2d.Graphics; -import org.eclipse.draw2d.geometry.Dimension; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.provider.DimensionInfo; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Display; - -/** - * @author mengbo - * @version 1.5 - */ -public class CheckboxWidgetProvider extends AbstractWidgetProvider { - private boolean isChecked; - - public CheckboxWidgetProvider(ICSSStyle style) { - super(style); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.provider.ICSSWidgetProvider#getPreferredDimension(int, - * int) - */ - public DimensionInfo getPreferredDimension(int width, int height) { - if (width <= 0) { - width = getDefaultWidth(); - } - if (height <= 0) { - height = getDefaultWidth(); - } - return new DimensionInfo(new Dimension(width, height), height * 4 / 5); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.provider.ICSSWidgetProvider#paintFigure(org.eclipse.draw2d.Graphics, - * org.eclipse.draw2d.geometry.Rectangle) - */ - public void paintFigure(Graphics g, Rectangle rect) { - int centerX = rect.x + rect.width / 2; - int centerY = rect.y + rect.height / 2; - - // we always draw it as a square. - int width = Math.min(rect.width, rect.height); - int innerWidth = width * 4 / 5; - - int left = centerX - innerWidth / 2; - int top = centerY - innerWidth / 2; - BorderUtil.drawBorder(g, left, top, innerWidth, innerWidth, 2, true); - if (isChecked()) { - g.pushState(); - Display display = Display.getCurrent(); - g.setForegroundColor(display.getSystemColor(SWT.COLOR_BLACK)); - g.drawLine(left + 3, top + 2, left + innerWidth - 3, top - + innerWidth - 4); - g.drawLine(left + 2, top + 2, left + innerWidth - 3, top - + innerWidth - 3); - - g.drawLine(left + innerWidth - 4, top + 2, left + 2, top - + innerWidth - 4); - g.drawLine(left + innerWidth - 3, top + 2, left + 2, top - + innerWidth - 3); - g.popState(); - } - } - - public int getDefaultWidth() { - // FIXME: don't know the how to define the default width yet. - return 15; - } - - /** - * @return Returns the checked. - */ - public boolean isChecked() { - return isChecked; - } - - public void setChecked(boolean checked) { - this.isChecked = checked; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/ComboWidgetProvider.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/ComboWidgetProvider.java deleted file mode 100644 index cd8720f29..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/ComboWidgetProvider.java +++ /dev/null @@ -1,209 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.widget; - -import org.eclipse.draw2d.ColorConstants; -import org.eclipse.draw2d.FigureUtilities; -import org.eclipse.draw2d.Graphics; -import org.eclipse.draw2d.geometry.Dimension; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.font.ICSSFont; -import org.eclipse.jst.pagedesigner.css2.provider.DimensionInfo; -import org.eclipse.jst.pagedesigner.css2.style.DefaultStyle; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.swt.widgets.Display; - -/** - * @author mengbo - * @author mengbo - * @version 1.5 - */ -public class ComboWidgetProvider extends AbstractWidgetProvider { - private static final int VERTICAL_PADDING = 6; - - private static final int HORIZONTAL_PADDING = 12; - - private static int ARRAWWIDTH = 16; - - //private static int ARROWHEIGHT = 16; - - private String _firstString; - - private String _longestString; - - private String _label; - - public ComboWidgetProvider(ICSSStyle style) { - super(style); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.provider.ICSSWidgetProvider#getPreferredDimension(int, - * int) - */ - public DimensionInfo getPreferredDimension(int width, int height) { - if (width <= 0) { - width = getDefaultWidth(); - - } - if (height <= 0) { - height = getDefaultHeight(); - } - return new DimensionInfo(new Dimension(width, height), -1); - } - - /** - * by default, the combo's width will be calculated from the longest option - * value. - * - * @return - */ - public int getDefaultWidth() { - int textareaWidth; - if (this._longestString == null || this._longestString.length() == 0) { - textareaWidth = 20; - } else { - ICSSStyle style = this.getCSSStyle(); - if (style == null) { - style = DefaultStyle.getInstance(); - } - ICSSFont font = style.getCSSFont(); - - textareaWidth = FigureUtilities.getTextWidth(_longestString, font - .getSwtFont()); - } - return textareaWidth + ARRAWWIDTH + HORIZONTAL_PADDING; - } - - /** - * - * @return - * @see TextInputWidgetProvider#getDefaultHeight() - */ - public int getDefaultHeight() { - ICSSStyle style = this.getCSSStyle(); - if (style == null) { - style = DefaultStyle.getInstance(); - } - ICSSFont font = style.getCSSFont(); - Font swtfont = font.getSwtFont(); - int fontSize = FigureUtilities.getFontMetrics(swtfont).getHeight(); - return fontSize + VERTICAL_PADDING; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.provider.ICSSWidgetProvider#paintFigure(org.eclipse.draw2d.Graphics, - * org.eclipse.draw2d.geometry.Rectangle) - */ - public void paintFigure(Graphics g, Rectangle rect) { - if (this._firstString != null) { - ICSSStyle style = this.getCSSStyle(); - if (style == null) { - style = DefaultStyle.getInstance(); - } - ICSSFont font = style.getCSSFont(); - g.setFont(font.getSwtFont()); - - Color newColor = null; - Object color = style.getColor(); - if (color instanceof Color) { - g.setForegroundColor((Color) color); - } else if (color instanceof RGB) { - newColor = new Color(Display.getCurrent(), (RGB) color); - g.setForegroundColor(newColor); - } else { - g.setForegroundColor(ColorConstants.black); - } - g.clipRect(rect); - String label = _label != null ? _label : _firstString; - label = label.replaceAll("[ \r\n]+", " "); - if (label.endsWith(" ")) { - label = label.substring(0, label.length() - 1); - } - g.drawString(label, rect.x + HORIZONTAL_PADDING / 2, rect.y - + VERTICAL_PADDING / 2); - if (newColor != null) { - newColor.dispose(); - } - - } - - BorderUtil.drawBorder(g, rect.x, rect.y, rect.width, rect.height, - BORDERTHICK, true); - // next the drop down button - int width = ARRAWWIDTH; - int left = rect.x + rect.width - width - BORDERTHICK; - int top = rect.y + BORDERTHICK; - int height = rect.height - BORDERTHICK * 2; - g.setBackgroundColor(ColorConstants.button); - g.fillRectangle(left, top, width, height); - - Rectangle borderRect = new Rectangle(left, top, width, height); - BorderUtil.drawBorder(g, borderRect.x, borderRect.y, borderRect.width, - borderRect.height, BORDERTHICK, false); - - g.setForegroundColor(ColorConstants.black); - - int decoratorWidth = (width - BORDERTHICK * 2) / 2; - int length = decoratorWidth / 2 + 1; - int leftX = left + (width - decoratorWidth) / 2 - 1; - int topY = top + (height - length) / 2 + 1; - for (int i = 0; i < length; i++) { - g.drawLine(leftX + i, topY + i, leftX - i + decoratorWidth, topY - + i); - } - } - - /** - * set the options to be displayed in this combo box. Will calculate out the - * first string and the longest string. - * - * @param options - */ - public void setOptions(String[] options) { - if (options == null || options.length == 0) { - this._firstString = null; - this._longestString = null; - } else { - this._firstString = options[0]; - this._longestString = (options[0] == null ? "" : options[0]); - for (int i = 1; i < options.length; i++) { - if (options[i] == null) { - continue; - } - if (options[i].length() > this._longestString.length()) { - this._longestString = options[i]; - } - } - } - } - - public void setSelectedLabel(String label) { - this._label = label; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.provider.ICSSWidgetProvider#isHandlingBorder() - */ - public boolean isHandlingBorder() { - return false; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/HiddenProvider.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/HiddenProvider.java deleted file mode 100644 index 8ca921b16..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/HiddenProvider.java +++ /dev/null @@ -1,135 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.widget; - -import org.eclipse.draw2d.ColorConstants; -import org.eclipse.draw2d.FigureUtilities; -import org.eclipse.draw2d.Graphics; -import org.eclipse.jst.pagedesigner.css2.provider.DimensionInfo; -import org.eclipse.jst.pagedesigner.css2.style.HiddenElementStyle; -import org.eclipse.jst.pagedesigner.parts.EditProxyAdapter; -import org.eclipse.jst.pagedesigner.parts.ElementEditPart; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.FontMetrics; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.w3c.dom.Element; - -/** - * @author mengbo - */ -public class HiddenProvider extends ImageWidgetProvider { - private final static int GAP = 3; - - private String _label = null; - - private boolean _labelVisible = true; - - private FontMetrics _fontMetrics; - - /** - * @param image - * @param style - */ - public HiddenProvider(Image image, Element convertedElement) { - super(image, new HiddenElementStyle(convertedElement)); - } - - public HiddenProvider(Image image, ElementEditPart editPart) { - super(image, new HiddenElementStyle(new EditProxyAdapter(editPart))); - } - - // public HiddenProvider(Image image, String label) - // { - // this(image); - // this._label = label; - // } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.provider.ICSSWidgetProvider#getPreferredDimension(int, - * int) - */ - public DimensionInfo getPreferredDimension(int width, int height) { - int preWidth = width; - int preHeight = height; - _fontMetrics = getFontMetrics(); - if (width <= 0) { - preWidth = getLabelWidth() + _imageWidth; - } - if (height <= 0) { - preHeight = Math.max(getLabelHeight(), _imageHeight); - } - return new DimensionInfo(preWidth, preHeight, -1); - } - - private FontMetrics getFontMetrics() { - Font swtfont = Display.getCurrent().getSystemFont(); - return FigureUtilities.getFontMetrics(swtfont); - } - - private int getLabelHeight() { - if (_labelVisible && (_label != null) && (!_label.equals("")) - && (_fontMetrics != null)) { - return _fontMetrics.getHeight(); - } - return 0; - } - - public int getLabelWidth() { - if (_labelVisible && _label != null && !_label.equals("") - && _fontMetrics != null) { - Font swtfont = Display.getCurrent().getSystemFont(); - return FigureUtilities.getTextWidth(_label, swtfont) + GAP; - } - return 0; - } - - public void paintFigure(Graphics g, - org.eclipse.draw2d.geometry.Rectangle rect) { - g.setBackgroundColor(ColorConstants.cyan); - g.fillRectangle(rect); - g.setClip(rect); - int imageAreaWidth = Math.min(rect.width, _imageWidth); - int imageAreaHeight = Math.min(rect.height, _imageHeight); - if (_image != null) { - g.drawImage(_image, 0, 0, _imageWidth, _imageHeight, rect.x, rect.y - + (rect.height - imageAreaHeight) / 2, imageAreaWidth, - imageAreaHeight); - } - if (_label != null && _labelVisible) { - int leading = 0; - if (_fontMetrics != null) { - leading = _fontMetrics.getLeading(); - } - g.drawString(_label, imageAreaWidth + GAP, rect.y - + (rect.height - getLabelHeight()) / 2 + leading); - } - } - - public String getLabel() { - return _label; - } - - public void setLabel(String label) { - this._label = label; - } - - public boolean isLabelVisible() { - return _labelVisible; - } - - public void setLabelVisible(boolean labelVisible) { - this._labelVisible = labelVisible; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/ImageWidgetProvider.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/ImageWidgetProvider.java deleted file mode 100644 index 510cf42b3..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/ImageWidgetProvider.java +++ /dev/null @@ -1,109 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.widget; - -import org.eclipse.draw2d.Graphics; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jst.pagedesigner.PDPlugin; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.provider.DimensionInfo; -import org.eclipse.swt.graphics.Image; - -/** - * @author mengbo - */ -public class ImageWidgetProvider extends AbstractWidgetProvider { - private static final String NOPIC_IMAGE_NAME = "PD_nopic.jpg"; - - private static Image _noPicImage; - - private static int _noPicWidth; - - private static int _noPicHeight; - - protected Image _image; - - protected int _imageWidth; - - protected int _imageHeight; - - public ImageWidgetProvider(Image image, ICSSStyle style) { - super(style); - - // set up image and image width/height - org.eclipse.swt.graphics.Rectangle rect = null; - if (image != null) { - rect = image.getBounds(); - if (rect.width <= 0 || rect.height <= 0) { - useNoPicImage(); - } else { - _image = image; - _imageWidth = rect.width; - _imageHeight = rect.height; - } - } else { - useNoPicImage(); - } - } - - /** - * - */ - private void useNoPicImage() { - if (_noPicImage == null || _noPicImage.isDisposed()) { - ImageDescriptor noPicImageDesc = PDPlugin.getDefault() - .getImageDescriptor(NOPIC_IMAGE_NAME); - _noPicImage = noPicImageDesc.createImage(); - org.eclipse.swt.graphics.Rectangle rect = _noPicImage.getBounds(); - _noPicWidth = rect.width; - _noPicHeight = rect.height; - } - _image = _noPicImage; - _imageWidth = _noPicWidth; - _imageHeight = _noPicHeight; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.provider.ICSSWidgetProvider#getPreferredDimension(int, - * int) - */ - public DimensionInfo getPreferredDimension(int width, int height) { - if (width <= 0 && height <= 0) { - // we are free, so use image size - org.eclipse.swt.graphics.Rectangle a = _image.getBounds(); - return new DimensionInfo(a.width, a.height, -1); - } else if (width > 0 && height > 0) { - return new DimensionInfo(width, height, -1); - } else if (height > 0) { - width = (int) ((double) _imageWidth * height / _imageHeight); - return new DimensionInfo(width, height, -1); - } else { - height = (int) ((double) _imageHeight * width / _imageWidth); - return new DimensionInfo(width, height, -1); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.provider.ICSSWidgetProvider#paintFigure(org.eclipse.draw2d.geometry.Rectangle) - */ - public void paintFigure(Graphics g, Rectangle rect) { - if (_image != null) { - g.drawImage(_image, 0, 0, _imageWidth, _imageHeight, rect.x, - rect.y, rect.width, rect.height); - } - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/InputFileWidgetProvider.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/InputFileWidgetProvider.java deleted file mode 100644 index c21eb5c00..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/InputFileWidgetProvider.java +++ /dev/null @@ -1,175 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.widget; - -import org.eclipse.draw2d.ColorConstants; -import org.eclipse.draw2d.Graphics; -import org.eclipse.draw2d.geometry.Dimension; -import org.eclipse.draw2d.geometry.Insets; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.border.CSSBorder; -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyID; -import org.eclipse.jst.pagedesigner.css2.provider.DimensionInfo; -import org.eclipse.jst.pagedesigner.css2.provider.ICSSWidgetProvider; -import org.eclipse.jst.pagedesigner.editors.pagedesigner.MessageFormater; - -/** - * @author mengbo - */ -public class InputFileWidgetProvider extends AbstractWidgetProvider { - private static final String BODER_QUERY_TEMPLETE = "border-{0}-style"; - - private static final int GAP = 2; - - private ICSSWidgetProvider _sub1; - - private ICSSWidgetProvider _sub2; - - /** - * @param style - */ - public InputFileWidgetProvider(ICSSStyle style, ICSSWidgetProvider sub1, - ICSSWidgetProvider sub2) { - super(style); - _sub1 = sub1; - _sub2 = sub2; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.provider.ICSSWidgetProvider#getPreferredDimension(int, - * int) - */ - public DimensionInfo getPreferredDimension(int width, int height) { - Insets borderInset = new Insets(); - Insets borderPaddingInset = new Insets(); - ICSSStyle style = getCSSStyle(); - if (style != null) { - borderInset = style.getBorderInsets(); - borderPaddingInset = borderInset.getAdded(style.getPaddingInsets()); - } - - Dimension d1 = _sub1.getPreferredDimension(-1, -1).getDimension(); - Dimension d2 = _sub2.getPreferredDimension(-1, -1).getDimension(); - - int minWidth = d2.width + 2 * (borderInset.left + borderInset.right) - + GAP; - int prefWidth = d1.width + d2.width + 2 - * (borderPaddingInset.left + borderPaddingInset.right) + GAP; - int minHeight = borderInset.top + borderInset.bottom; - int prefHeight = Math.max(d1.height, d2.height) - + borderPaddingInset.top + borderPaddingInset.bottom; - - if (width > 0 && minWidth > width) { - prefWidth = minWidth; - } else if (width != 0) { - prefWidth = width; - } - - if (height > 0 && minHeight > height) { - prefHeight = minHeight; - } else if (height != 0) { - prefHeight = height; - } - return new DimensionInfo(prefWidth, prefHeight, -1); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.provider.ICSSWidgetProvider#paintFigure(org.eclipse.draw2d.Graphics, - * org.eclipse.draw2d.geometry.Rectangle) - */ - public void paintFigure(Graphics g, Rectangle rect) { - Rectangle rect1, rect2; - - Insets borderInset = new Insets(); - Insets paddingInset = new Insets(); - Insets borderPaddingInset = new Insets(); - ICSSStyle style = getCSSStyle(); - if (style != null) { - borderInset = style.getBorderInsets(); - paddingInset = style.getPaddingInsets(); - borderPaddingInset.add(borderInset).add(paddingInset); - } - - Dimension d1 = _sub1.getPreferredDimension(-1, -1).getDimension(); - Dimension d2 = _sub2.getPreferredDimension(-1, -1).getDimension(); - int prefWidth = d1.width + d2.width + 2 * borderPaddingInset.left + 2 - * borderPaddingInset.right + GAP; - if (rect.width < prefWidth) { - paddingInset.left = 0; - paddingInset.right = 0; - } - int prefHeight = Math.max(d1.height, d2.height) - + borderPaddingInset.top + borderPaddingInset.bottom; - if (rect.height < prefHeight) { - paddingInset.top = 0; - paddingInset.bottom = 0; - } - - int width = rect.width - - d2.width - - (borderInset.left + borderInset.right + paddingInset.left + paddingInset.right) - - GAP; - rect1 = new Rectangle(rect.x - 1, rect.y, width, rect.height); - rect2 = new Rectangle(rect.x + rect1.width + 2, rect.y, rect.width - - rect1.width - 3, rect.height); - Rectangle innerRect1 = rect1.getCopy().crop(borderInset); - Rectangle innerRect2 = rect2.getCopy().crop(borderInset); - - g.pushState(); - g.setBackgroundColor(ColorConstants.button); - g.fillRectangle(innerRect2); - g.popState(); - - CSSBorder cssBorder = new CSSBorder(style); - String[] edges = new String[] { ICSSStyle.LEFT, ICSSStyle.RIGHT, - ICSSStyle.TOP, ICSSStyle.BOTTOM }; - for (int i = 0; i < edges.length; i++) { - cssBorder.paintEdge(g, rect1, innerRect1, edges[i], - getBorderStyle(edges[i])); - } - for (int i = 0; i < edges.length; i++) { - String borderStyle = getBorderStyle(edges[i]); - if (ICSSPropertyID.VAL_INSET.equals(borderStyle)) { - borderStyle = ICSSPropertyID.VAL_OUTSET; - } - cssBorder.paintEdge(g, rect2, innerRect2, edges[i], borderStyle); - } - - _sub2.paintFigure(g, innerRect2.getCopy().crop(paddingInset)); - // _sub1.paintFigure(g, innerRect1.crop(paddingInset)); - } - - private String getBorderStyle(String edge) { - ICSSStyle style = getCSSStyle(); - if (style != null) { - String property = MessageFormater - .format(BODER_QUERY_TEMPLETE, edge); - String borderStyle = style.getStyleProperty(property).toString(); - return borderStyle; - } - return ICSSPropertyID.VAL_HIDDEN; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.provider.ICSSWidgetProvider#isHandlingBorder() - */ - public boolean isHandlingBorder() { - return false; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/ListWidgetProvider.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/ListWidgetProvider.java deleted file mode 100644 index 3906425b2..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/ListWidgetProvider.java +++ /dev/null @@ -1,211 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.widget; - -import org.eclipse.draw2d.ColorConstants; -import org.eclipse.draw2d.FigureUtilities; -import org.eclipse.draw2d.Graphics; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.font.ICSSFont; -import org.eclipse.jst.pagedesigner.css2.provider.DimensionInfo; -import org.eclipse.jst.pagedesigner.css2.style.DefaultStyle; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.swt.widgets.Display; - -/** - * @author mengbo - * @version 1.5 - */ -public class ListWidgetProvider extends AbstractWidgetProvider { - private static int DEFAULTSIZE = 4; - - private static final int VERTICAL_PADDING = 6; - - private static final int HORIZONTAL_PADDING = 12; - - private static int ARRAWWIDTH = 16; - - private static int ARROWHEIGHT = 16; - - private String[] _options; - - private int _rows = DEFAULTSIZE; - - public ListWidgetProvider(ICSSStyle style) { - super(style); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.provider.ICSSWidgetProvider#getPreferredDimension(int, - * int) - */ - public DimensionInfo getPreferredDimension(int width, int height) { - if (width <= 0) { - width = getDefaultWidth(); - } - if (height <= 0) { - height = getDefaultHeight(); - } - return new DimensionInfo(width, height, -1); - } - - /** - * by default, the combo's width will be calculated from the longest option - * value. - * - * @return - */ - public int getDefaultWidth() { - int longestStringWidth = 0; - if (_options != null) { - ICSSStyle style = this.getCSSStyle(); - if (style == null) { - style = DefaultStyle.getInstance(); - } - ICSSFont font = style.getCSSFont(); - Font swtFont = font.getSwtFont(); - for (int i = 0; i < _options.length; i++) { - int width = FigureUtilities.getTextWidth(_options[i], swtFont); - if (width > longestStringWidth) { - longestStringWidth = width; - } - } - } - // text area width + borderWidth + vertical scroll width - return (longestStringWidth) + HORIZONTAL_PADDING + ARRAWWIDTH; - } - - /** - * - * @return - * @see TextInputWidgetProvider#getDefaultHeight() - */ - public int getDefaultHeight() { - ICSSStyle style = this.getCSSStyle(); - if (style == null) { - style = DefaultStyle.getInstance(); - } - ICSSFont font = style.getCSSFont(); - Font swtfont = font.getSwtFont(); - int fontHeight = FigureUtilities.getFontMetrics(swtfont).getHeight(); - return (fontHeight) * _rows + VERTICAL_PADDING; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.provider.ICSSWidgetProvider#paintFigure(org.eclipse.draw2d.Graphics, - * org.eclipse.draw2d.geometry.Rectangle) - */ - public void paintFigure(Graphics g, Rectangle rect) { - BorderUtil.drawBorder(g, rect.x, rect.y, rect.width, rect.height, - BORDERTHICK, true); - if (_options != null) { - ICSSStyle style = this.getCSSStyle(); - if (style == null) { - style = DefaultStyle.getInstance(); - } - ICSSFont font = style.getCSSFont(); - Font swtfont = font.getSwtFont(); - g.setFont(swtfont); - - Color newColor = null; - Object color = style.getColor(); - if (color instanceof Color) { - g.setForegroundColor((Color) color); - } else if (color instanceof RGB) { - newColor = new Color(Display.getCurrent(), (RGB) color); - g.setForegroundColor(newColor); - } else { - g.setForegroundColor(ColorConstants.black); - } - int fontHeight = FigureUtilities.getFontMetrics(swtfont) - .getHeight(); - int x = rect.x + HORIZONTAL_PADDING / 2; - int y = rect.y + VERTICAL_PADDING / 2; - - g.clipRect(rect); - for (int i = 0; i < _options.length - && (i * fontHeight < rect.height - VERTICAL_PADDING); i++) { - g.drawString(_options[i], x, y); - y += fontHeight; - } - if (newColor != null) { - newColor.dispose(); - } - - int borderThick = 2; - Rectangle barRect = new Rectangle(rect.x, rect.y + borderThick, - rect.width - borderThick, rect.height - 2 * borderThick); - BorderUtil.drawVertialBar(g, ARRAWWIDTH, ARROWHEIGHT, borderThick, - barRect); - } - } - - /** - * @param string - * @param x - * @param y - * @return - */ - private String normalize(String string) { - if (string == null) { - return ""; - } - int index = string.indexOf('\r'); - if (index >= 0) { - string = string.substring(0, index); - } - index = string.indexOf('\n'); - if (index >= 0) { - string = string.substring(0, index); - } - return string; - } - - /** - * set the options to be displayed in this combo box. - * - * @param options - */ - public void setOptions(String[] options) { - this._options = options; - if (_options != null) { - for (int i = 0; i < _options.length; i++) { - _options[i] = normalize(_options[i]); - } - } - } - - /** - * set the default number of rows to be displayed. - * - * @param rows - */ - public void setRows(int rows) { - _rows = (rows > 0 ? rows : DEFAULTSIZE); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.provider.ICSSWidgetProvider#isHandlingBorder() - */ - public boolean isHandlingBorder() { - return false; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/RadioWidgetProvider.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/RadioWidgetProvider.java deleted file mode 100644 index 195c8605e..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/RadioWidgetProvider.java +++ /dev/null @@ -1,108 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.widget; - -import org.eclipse.draw2d.ColorConstants; -import org.eclipse.draw2d.Graphics; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.provider.DimensionInfo; - -/** - * @author mengbo - * @version 1.5 - */ -public class RadioWidgetProvider extends AbstractWidgetProvider { - private boolean isChecked; - - public RadioWidgetProvider(ICSSStyle style) { - super(style); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.provider.ICSSWidgetProvider#getPreferredDimension(int, - * int) - */ - public DimensionInfo getPreferredDimension(int width, int height) { - if (width <= 0) { - width = getDefaultWidth(); - } - if (height <= 0) { - height = getDefaultWidth(); - } - return new DimensionInfo(width, height, height * 4 / 5); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.provider.ICSSWidgetProvider#paintFigure(org.eclipse.draw2d.Graphics, - * org.eclipse.draw2d.geometry.Rectangle) - */ - public void paintFigure(Graphics g, Rectangle rect) { - int centerX = rect.x + rect.width / 2; - int centerY = rect.y + rect.height / 2; - - // we always draw it as a circle. - int width = Math.min(rect.width, rect.height); - int cycleWidth = width * 3 / 5; - - // FIXME: when the size of the radio is big, the line width may need - // calculate to be bigger. - int lineWidth = 2; - g.setLineWidth(lineWidth); - - g.setForegroundColor(ColorConstants.buttonDarker); - g.drawArc(centerX - cycleWidth / 2, centerY - cycleWidth + 1, - cycleWidth, cycleWidth, 45, 180); - - g.setForegroundColor(ColorConstants.button); - g.drawArc(centerX - cycleWidth / 2, centerY - cycleWidth + 1, - cycleWidth, cycleWidth, 225, 180); - - // since the two cycle may not overlap very well, some space between - // them will be displayed. - // so we make the bigger cycle to be a little thicker. - cycleWidth += (2 * lineWidth - 2); - lineWidth += 1; - - if (cycleWidth < width) { - g.setForegroundColor(ColorConstants.buttonDarkest); - g.drawArc(centerX - cycleWidth / 2, centerY - cycleWidth + 1, - cycleWidth, cycleWidth, 45, 180); - } - - if (isChecked()) { - g.setBackgroundColor(ColorConstants.black); - g.fillArc(centerX - 1, centerY - cycleWidth / 2 - 1, 4, 4, 0, 360); - } - } - - public int getDefaultWidth() { - // FIXME: don't know the how to define the default width yet. - return 15; - } - - /** - * @return Returns the checked. - */ - public boolean isChecked() { - return isChecked; - } - - public void setChecked(boolean checked) { - this.isChecked = checked; - } - -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/TextAreaWidgetProvider.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/TextAreaWidgetProvider.java deleted file mode 100644 index e1b16167e..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/TextAreaWidgetProvider.java +++ /dev/null @@ -1,202 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.widget; - -import org.eclipse.draw2d.ColorConstants; -import org.eclipse.draw2d.FigureUtilities; -import org.eclipse.draw2d.Graphics; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.font.ICSSFont; -import org.eclipse.jst.pagedesigner.css2.layout.TextLayoutSupport; -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyID; -import org.eclipse.jst.pagedesigner.css2.provider.DimensionInfo; -import org.eclipse.jst.pagedesigner.css2.style.DefaultStyle; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.swt.widgets.Display; - -/** - * @author mengbo - * @version 1.5 - */ -public class TextAreaWidgetProvider extends AbstractWidgetProvider { - private static final int DEFAULTCOLUMN = 20; - - private static final int DEFAULTROWS = 2; - - private static final int VERTICAL_PADDING = 2; - - private static final int HORIZONTAL_PADDING = 2; - - private static int ARRAWWIDTH = 16; - - private static int ARROWHEIGHT = 16; - - private int _columns = DEFAULTCOLUMN; - - private int _rows = DEFAULTROWS; - - private String _value; - - /** - * @param style - */ - public TextAreaWidgetProvider(ICSSStyle style) { - super(style); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.provider.ICSSWidgetProvider#getPreferredDimension(int, - * int) - */ - public DimensionInfo getPreferredDimension(int width, int height) { - if (width <= 0) { - width = getDefaultWidth(); - } - if (height <= 0) { - height = getDefaultHeight(); - } - return new DimensionInfo(width, height, -1); - } - - /** - * @return - */ - private int getDefaultHeight() { - ICSSStyle style = this.getCSSStyle(); - if (style == null) { - style = DefaultStyle.getInstance(); - } - ICSSFont font = style.getCSSFont(); - Font swtfont = font.getSwtFont(); - int fontHeight = FigureUtilities.getFontMetrics(swtfont).getHeight(); - - return (fontHeight) * _rows + VERTICAL_PADDING; - } - - /** - * @return - */ - private int getDefaultWidth() { - ICSSStyle style = this.getCSSStyle(); - if (style == null) { - style = DefaultStyle.getInstance(); - } - ICSSFont font = style.getCSSFont(); - - int fontWidth = FigureUtilities.getFontMetrics(font.getSwtFont()) - .getAverageCharWidth(); - return _columns * fontWidth + ARRAWWIDTH + HORIZONTAL_PADDING; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.provider.ICSSWidgetProvider#paintFigure(org.eclipse.draw2d.Graphics, - * org.eclipse.draw2d.geometry.Rectangle) - */ - public void paintFigure(Graphics g, Rectangle rect) { - if (_value != null) { - g.clipRect(rect); - ICSSStyle style = this.getCSSStyle(); - if (style == null) { - style = DefaultStyle.getInstance(); - } - int decoration = ((Integer) style - .getStyleProperty(ICSSPropertyID.ATTR_TEXTDECORATION)) - .intValue(); - ICSSFont font = style.getCSSFont(); - g.setFont(font.getSwtFont()); - - Color newColor = null; - Object color = style.getColor(); - if (color instanceof Color) { - g.setForegroundColor((Color) color); - } else if (color instanceof RGB) { - newColor = new Color(Display.getCurrent(), (RGB) color); - g.setForegroundColor(newColor); - } else { - g.setForegroundColor(ColorConstants.black); - } - - Object textAlign = style - .getStyleProperty(ICSSPropertyID.ATTR_TEXTALIGN); - int begin = 0; - int end = 0; - int fontHeight = FigureUtilities.getFontMetrics(font.getSwtFont()) - .getHeight(); - - int fontWidth = FigureUtilities.getFontMetrics(font.getSwtFont()) - .getAverageCharWidth(); - int columns = (rect.width - HORIZONTAL_PADDING) / fontWidth; - - int i = 0; - while (true) { - int y = rect.y + VERTICAL_PADDING / 2 + fontHeight * i; - if (y >= rect.bottom()) { - break; - } - end += columns; - if (end > _value.length()) { - end = _value.length(); - } - end = getTextCount(begin, end, g.getFont(), rect.width - - ARRAWWIDTH); - - String text = _value.substring(begin, end); - - int width = FigureUtilities.getTextWidth(text, g.getFont()); - int x = TextLayoutSupport.getBeginX(textAlign, rect, width); - g.drawString(text, x, y); - - TextLayoutSupport.paintTextDecoration(g, new Rectangle(x, y, - width, fontHeight), decoration); - begin = end; - - if (end == _value.length()) { - break; - } - i++; - } - if (newColor != null) { - newColor.dispose(); - } - } - int borderThick = 2; - BorderUtil - .drawVertialBar(g, ARRAWWIDTH, ARROWHEIGHT, borderThick, rect); - } - - private int getTextCount(int begin, int end, Font swtFont, int textWidth) { - while (FigureUtilities.getTextWidth(_value.substring(begin, end), - swtFont) > textWidth) { - end--; - } - return end; - } - - public void setColumns(int columns) { - this._columns = (columns > 0 ? columns : DEFAULTCOLUMN); - } - - public void setRows(int rows) { - this._rows = (rows > 0 ? rows : DEFAULTROWS); - } - - public void setValue(String value) { - this._value = value; - } -} diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/TextInputWidgetProvider.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/TextInputWidgetProvider.java deleted file mode 100644 index d4f9508a5..000000000 --- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/css2/widget/TextInputWidgetProvider.java +++ /dev/null @@ -1,164 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Sybase, Inc. and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sybase, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.pagedesigner.css2.widget; - -import org.eclipse.draw2d.ColorConstants; -import org.eclipse.draw2d.FigureUtilities; -import org.eclipse.draw2d.Graphics; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.jst.pagedesigner.css2.ICSSStyle; -import org.eclipse.jst.pagedesigner.css2.font.ICSSFont; -import org.eclipse.jst.pagedesigner.css2.layout.TextLayoutSupport; -import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyID; -import org.eclipse.jst.pagedesigner.css2.provider.DimensionInfo; -import org.eclipse.jst.pagedesigner.css2.style.DefaultStyle; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.swt.widgets.Display; - -/** - * @author mengbo - * @version 1.5 - */ -public class TextInputWidgetProvider extends AbstractWidgetProvider { - private static final int VERTICAL_INCREMENT = 2; - - public static final int PWD_SIZE = 18; - - private int DEFAULTSIZE = 20; - - private int _size = DEFAULTSIZE; - - private String _value; - - public TextInputWidgetProvider(ICSSStyle style) { - this(style, 20); - } - - public TextInputWidgetProvider(ICSSStyle style, int size) { - super(style); - DEFAULTSIZE = size; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.provider.ICSSWidgetProvider#getPreferredDimension(int, - * int) - */ - public DimensionInfo getPreferredDimension(int width, int height) { - if (width <= 0) { - width = getDefaultWidth(); - - } - if (height <= 0) { - height = getDefaultHeight(); - } - return new DimensionInfo(width, height, -1); - } - - /** - * @return - */ - private int getDefaultHeight() { - ICSSStyle style = this.getCSSStyle(); - if (style == null) { - style = DefaultStyle.getInstance(); - } - ICSSFont font = style.getCSSFont(); - Font swtfont = font.getSwtFont(); - int fontSize = FigureUtilities.getFontMetrics(swtfont).getHeight(); - return fontSize + VERTICAL_INCREMENT; - } - - public int getDefaultWidth() { - ICSSStyle style = this.getCSSStyle(); - if (style == null) { - style = DefaultStyle.getInstance(); - } - return computeWidth(style.getCSSFont()); - } - - private int computeWidth(ICSSFont font) { - int fontWidth = FigureUtilities - .getTextWidth("abcde", font.getSwtFont());//$NON-NLS-1$ - return (fontWidth + 1) * _size / 5; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.pagedesigner.css2.provider.ICSSWidgetProvider#paintFigure(org.eclipse.draw2d.Graphics, - * org.eclipse.draw2d.geometry.Rectangle) - */ - public void paintFigure(Graphics g, Rectangle rect) { - String value = getValue(); - if (value != null) { - ICSSStyle style = this.getCSSStyle(); - if (style == null) { - style = DefaultStyle.getInstance(); - } - Object textAlign = style - .getStyleProperty(ICSSPropertyID.ATTR_TEXTALIGN); - - Font font = style.getCSSFont().getSwtFont(); - g.setFont(font); - - Color newColor = null; - Object color = style.getColor(); - if (color instanceof Color) { - g.setForegroundColor((Color) color); - } else if (color instanceof RGB) { - newColor = new Color(Display.getCurrent(), (RGB) color); - g.setForegroundColor(newColor); - } else { - g.setForegroundColor(ColorConstants.black); - } - g.clipRect(rect); - int width = FigureUtilities.getTextWidth(value, g.getFont()); - int x = TextLayoutSupport.getBeginX(textAlign, rect, width); - int y = rect.y + VERTICAL_INCREMENT / 2; - - g.drawString(value, x, y); - TextLayoutSupport.paintTextDecoration(g, new Rectangle(x, y, width, - g.getFontMetrics().getHeight()), ((Integer) getCSSStyle() - .getStyleProperty(ICSSPropertyID.ATTR_TEXTDECORATION)) - .intValue()); - if (newColor != null) { - newColor.dispose(); - } - } - } - - /** - * set the value in this text input control - * - * @param value - */ - public void setValue(String value) { - this._value = value; - } - - public void setSize(int size) { - this._size = (size <= 0 ? DEFAULTSIZE : size); - } - - /** - * get current value in this text input control - * - * @return - */ - public String getValue() { - return _value; - } -} |