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: package org.netbeans.modules.visualweb.css2;
042:
043: import java.awt.Graphics;
044: import java.awt.Graphics2D;
045: import java.awt.Image;
046: import java.awt.geom.AffineTransform;
047:
048: import org.w3c.dom.Element;
049:
050: import org.netbeans.modules.visualweb.designer.WebForm;
051: import org.netbeans.modules.visualweb.designer.html.HtmlAttribute;
052: import org.netbeans.modules.visualweb.designer.html.HtmlTag;
053:
054: /**
055: * ObjectBox represents an <object> tag, or an
056: * <applet> tag, in the jsp markup.
057: *
058: * @author Tor Norbye
059: */
060: public class ObjectBox extends ContainerBox {
061: private static final int IMGWIDTH = 48;
062: private static final int IMGHEIGHT = 90;
063: private static Image appletlogo;
064: boolean isApplet;
065:
066: /** Use the "getObjectBox" factory method instead */
067: private ObjectBox(WebForm webform, Element element,
068: BoxType boxType, boolean inline, boolean replaced) {
069: super (webform, element, boxType, inline, replaced);
070: }
071:
072: /** Create a new framebox, or provide one from a cache */
073: public static CssBox getObjectBox(WebForm webform, Element element,
074: BoxType boxType, HtmlTag tag, boolean inline) {
075: // Is this an image?
076: // If so I should look up the type and look for mime types,
077: // then delegate to the ImageBox factory method. However,
078: // that's not yet common usage of <object> so worry about it later.
079: //String type = element.getAttribute(HtmlAttribute.TYPE);
080: ObjectBox box = new ObjectBox(webform, element, boxType,
081: inline, tag.isReplacedTag());
082: String codeType = element.getAttribute(HtmlAttribute.CODETYPE);
083: String classId = element.getAttribute(HtmlAttribute.CLASSID);
084:
085: // For now we do no previews of any kind
086: if ((tag == HtmlTag.APPLET) || "java".equals(codeType) || // NOI18N
087: classId.endsWith(".class")) { // NOI18N
088: box.isApplet = true;
089: }
090:
091: return box;
092: }
093:
094: /** What should the default intrinsic width be? Mozilla 1.6 seems
095: * to use 300x150.
096: */
097: public int getIntrinsicWidth() {
098: return 300;
099: }
100:
101: /** What should the default intrinsic height be? Mozilla 1.6 seems
102: * to use 300x150.
103: */
104: public int getIntrinsicHeight() {
105: return 150;
106: }
107:
108: // public String toString() {
109: // return "ObjectBox[" + paramString() + "]";
110: // }
111:
112: /*
113: protected String paramString() {
114: return super.paramString() + ", " + markup;
115: }
116: */
117: protected void createChildren(CreateContext context) {
118: // No valid children for objects
119: }
120:
121: public void paint(Graphics g, int px, int py) {
122: super .paint(g, px, py);
123:
124: if (hidden) {
125: return;
126: }
127:
128: px += leftMargin;
129: py += effectiveTopMargin;
130:
131: if (isApplet) {
132: int x = (px + getX() + (width / 2)) - (IMGWIDTH / 2);
133: int y = (py + getY() + (height / 2)) - (IMGHEIGHT / 2);
134:
135: Image appletlogo = getAppletLogo();
136:
137: if ((appletlogo != null) && (g instanceof Graphics2D)) {
138: Graphics2D g2d = (Graphics2D) g;
139: AffineTransform t = new AffineTransform();
140:
141: //t.translate((float) getX(), (float) getY());
142: t.translate((float) x, (float) y);
143: g2d.drawImage(appletlogo, t, null);
144: }
145: }
146:
147: //paintFacesWatermark(g, px+getX()+leftMargin, py+getY()+effectiveTopMargin);
148: }
149:
150: private static Image getAppletLogo() {
151: if (appletlogo == null) {
152: appletlogo = org.openide.util.Utilities
153: .loadImage("org/netbeans/modules/visualweb/designer/resources/applet.gif");
154:
155: // NOI18N
156: }
157:
158: return appletlogo;
159: }
160: }
|