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.web.ui.dt.component;
042:
043: import java.awt.Image;
044: import java.beans.BeanDescriptor;
045: import java.beans.EventSetDescriptor;
046: import java.beans.PropertyDescriptor;
047: import java.lang.reflect.Method;
048:
049: import javax.faces.event.ActionEvent;
050:
051: import com.sun.rave.faces.event.Action;
052: import com.sun.rave.designtime.*;
053: import com.sun.rave.designtime.Constants;
054: import org.netbeans.modules.visualweb.web.ui.dt.component.util.DesignMessageUtil;
055:
056: /**
057: * BeanCreateInfo which creates a Tab with an embedded Grid Positioning
058: * Panel
059: *
060: * @author Tor Norbye
061: */
062: public class TabGridBeanCreateInfo implements BeanCreateInfo {
063: public TabGridBeanCreateInfo() {
064: }
065:
066: public String getBeanClassName() {
067: return "org.netbeans.modules.visualweb.web.ui.dt.component.Tab";
068: }
069:
070: public Result beanCreatedSetup(DesignBean bean) {
071: DesignContext context = bean.getDesignContext();
072: DesignBean panel = context
073: .createBean(
074: "org.netbeans.modules.visualweb.web.ui.dt.component.PanelGroup",
075: bean, new Position());
076:
077: if (panel == null) {
078: return Result.FAILURE;
079: }
080:
081: // Force to block (div)
082: DesignProperty property = panel.getProperty("block");
083:
084: if (property != null) {
085: property.setValue(Boolean.TRUE);
086: }
087:
088: // Style
089: property = panel.getProperty("style");
090:
091: if (property != null) {
092: String s = "-rave-layout: grid; position: relative; background-color: white; border: solid 1px gray; height: 200px;";
093: String style = (String) property.getValue();
094:
095: if ((style != null) && (style.length() > 0)) {
096: s = s + style;
097: }
098:
099: property.setValue(s);
100: }
101:
102: return Result.SUCCESS;
103: }
104:
105: public String getDisplayName() {
106: return DesignMessageUtil.getMessage(
107: TabGridBeanCreateInfo.class, "tabPanel.name");
108: }
109:
110: public String getDescription() {
111: return DesignMessageUtil.getMessage(
112: TabGridBeanCreateInfo.class, "tabPanel.tip");
113: }
114:
115: public Image getLargeIcon() {
116: return null;
117: }
118:
119: // XXX Copied from java.beans.BeanInfo.
120: public static java.awt.Image loadImage(final String resourceName) {
121: try {
122: //final Class c = getClass();
123: final Class c = TabGridBeanCreateInfo.class;
124: java.awt.image.ImageProducer ip = (java.awt.image.ImageProducer) java.security.AccessController
125: .doPrivileged(new java.security.PrivilegedAction() {
126: public Object run() {
127: java.net.URL url;
128:
129: if ((url = c.getResource(resourceName)) == null) {
130: return null;
131: } else {
132: try {
133: return url.getContent();
134: } catch (java.io.IOException ioe) {
135: return null;
136: }
137: }
138: }
139: });
140:
141: if (ip == null) {
142: return null;
143: }
144:
145: java.awt.Toolkit tk = java.awt.Toolkit.getDefaultToolkit();
146:
147: return tk.createImage(ip);
148: } catch (Exception ex) {
149: return null;
150: }
151: }
152:
153: public Image getSmallIcon() {
154: String iconFileName_C16 = "Tab_C16";
155:
156: String name;
157: name = iconFileName_C16;
158:
159: if (name == null) {
160: return null;
161: }
162:
163: Image image = loadImage(name + ".png");
164:
165: if (image == null) {
166: image = loadImage(name + ".gif");
167: }
168:
169: return image;
170:
171: //return null;
172: }
173:
174: public String getHelpKey() {
175: return null;
176: }
177: }
|