001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.visualweb.designer.jsf;
043:
044: import org.netbeans.modules.visualweb.spi.designer.cssengine.CssUserAgentInfo;
045: import java.net.URL;
046: import java.util.logging.Level;
047: import java.util.logging.Logger;
048: import org.netbeans.modules.visualweb.api.designer.Designer;
049: import org.netbeans.modules.visualweb.api.designer.Designer.Box;
050: import org.netbeans.modules.visualweb.insync.Util;
051: import org.w3c.dom.Document;
052: import org.w3c.dom.DocumentFragment;
053: import org.w3c.dom.Element;
054:
055: /**
056: * Implementation of <code>CssUserAgentInfo</code>. Delegates to css box model
057: * implementation.
058: *
059: * @author Peter Zavadsky
060: */
061: public class CssUserAgentInfoImpl implements CssUserAgentInfo {
062:
063: /** Creates a new instance of CssUserAgentInfoImpl */
064: public CssUserAgentInfoImpl() {
065: }
066:
067: public float getBlockWidth(Document document, Element element) {
068: Box box = findBoxForDocumentElement(document, element);
069: if (box != null) {
070: return box.getBlockWidth();
071: }
072: log("No containing block available for element " + element); // NOI18N
073: return 0.0f; // if no available containing block, just use 0
074: }
075:
076: public float getBlockHeight(Document document, Element element) {
077: Box box = findBoxForDocumentElement(document, element);
078: if (box != null) {
079: return box.getBlockHeight();
080: }
081: log("No containing block available for element " + element); // NOI18N
082: return 0.0f; // if no available containing block, just use 0
083: }
084:
085: public int getDefaultFontSize() {
086: return JsfDesignerPreferences.getInstance()
087: .getDefaultFontSize();
088: }
089:
090: // XXX Get rid of it.
091: public String computeFileName(Object location) {
092: return Util.computeFileName(location);
093: }
094:
095: // XXX Get rid of it.
096: public int computeLineNumber(Object location, int lineno) {
097: return Util.computeLineNumber(location, lineno);
098: }
099:
100: public URL getDocumentUrl(Document document) {
101: return Util.getDocumentUrl(document);
102: }
103:
104: public void displayErrorForLocation(String message,
105: Object location, int lineno, int column) {
106: Util.displayErrorForLocation(message, location, lineno, column);
107: }
108:
109: public Element getHtmlBodyForDocument(Document document) {
110: return Util.getHtmlBodyForDocument(document);
111: }
112:
113: public DocumentFragment getHtmlDomFragmentForDocument(
114: Document document) {
115: return Util.getHtmlDomFragmentForDocument(document);
116: }
117:
118: // XXX #110849 Be aware that elemnt might be owned by external document (fragments),
119: // not the specified one.
120: private static Box findBoxForDocumentElement(Document document,
121: Element element) {
122: {
123: Designer[] designers = JsfForm
124: .findDesignersForDocument(document);
125: for (Designer designer : designers) {
126: Box box = designer.findBoxForElement(element);
127: if (box != null) {
128: return box;
129: }
130: }
131: }
132:
133: // XXX #119888 There are funky things done with elements from fragment (inside page),
134: // they might be part of different document (engine), try also original document in that case.
135: Document doc = element == null ? null : element
136: .getOwnerDocument();
137: if (doc != document) {
138: Designer[] designers = JsfForm
139: .findDesignersForDocument(doc);
140: for (Designer designer : designers) {
141: Box box = designer.findBoxForElement(element);
142: if (box != null) {
143: return box;
144: }
145: }
146: }
147:
148: return null;
149: }
150:
151: private static void log(String message) {
152: Logger logger = Logger.getLogger(CssUserAgentInfoImpl.class
153: .getName());
154: logger.log(Level.FINE, message);
155: }
156: }
|