2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.form.editors2;
44
import java.beans.PropertyEditor;
45
import java.io.IOException;
46
import org.netbeans.modules.form.NamedPropertyEditor;
47
import org.netbeans.modules.form.ResourceValue;
48
import org.netbeans.modules.form.ResourceWrapperEditor;
49
import org.netbeans.modules.form.editors.IconEditor.NbImageIcon;
50
import org.openide.explorer.propertysheet.editors.XMLPropertyEditor;
51
import org.openide.util.NbBundle;
52
import org.w3c.dom.Document;
53
import org.w3c.dom.Node;
56
* Resource wrapper for IconEditor from editors package.
58
public class IconEditor extends ResourceWrapperEditor implements NamedPropertyEditor, XMLPropertyEditor {
61
super(new org.netbeans.modules.form.editors.IconEditor());
64
public PropertyEditor getDelegatedPropertyEditor() {
65
// hack for saving: for compatibility we want this editor to be used
66
// for saving (its class name to be written to .form file);
67
// so the delegate editor is not exposed
71
protected void setValueToDelegate(Object value) {
72
if (value instanceof ResourceValue) {
73
ResourceValue resVal = (ResourceValue) value;
74
value = resVal.getValue();
75
if (value instanceof NbImageIcon)
76
delegateEditor.setValue(value);
78
delegateEditor.setAsText(resVal.getClassPathResourceName());
80
else delegateEditor.setValue(value);
83
protected void setValueToResourcePanel() {
84
Object value = delegateEditor.getValue();
85
if (value instanceof NbImageIcon || value == null) {
86
NbImageIcon nbIcon = (NbImageIcon) value;
87
String stringValue = nbIcon != null ? nbIcon.getName() : "${null}"; // NOI18N
88
String resName = (nbIcon != null && nbIcon.getType() == org.netbeans.modules.form.editors.IconEditor.TYPE_CLASSPATH)
89
? nbIcon.getName() : null;
90
resourcePanel.setValue(nbIcon, stringValue, resName);
94
// NamedPropertyEditor implementation
95
public String getDisplayName() {
96
return NbBundle.getMessage(IconEditor.class, "IconEditor_DisplayName"); // NOI18N
99
// XMLPropertyEditor implementation
100
public void readFromXML(Node element) throws IOException {
101
((org.netbeans.modules.form.editors.IconEditor)delegateEditor).readFromXML(element);
104
// XMLPropertyEditor implementation
105
public Node storeToXML(Document doc) {
106
return ((org.netbeans.modules.form.editors.IconEditor)delegateEditor).storeToXML(doc);