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-2006 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.vmd.midpnb.components.items;
042:
043: import org.netbeans.modules.vmd.api.model.Debug;
044: import org.netbeans.modules.vmd.api.model.DesignComponent;
045: import org.netbeans.modules.vmd.api.model.DesignEventFilter;
046: import org.netbeans.modules.vmd.api.model.PropertyValue;
047: import org.netbeans.modules.vmd.api.model.presenters.InfoPresenter;
048: import org.netbeans.modules.vmd.api.model.presenters.InfoPresenter.IconType;
049: import org.netbeans.modules.vmd.api.model.presenters.InfoPresenter.NameType;
050: import org.netbeans.modules.vmd.api.model.presenters.InfoPresenter.Resolver;
051: import org.netbeans.modules.vmd.midp.components.MidpTypes;
052: import org.netbeans.modules.vmd.midp.components.MidpValueSupport;
053: import org.netbeans.modules.vmd.midpnb.components.sources.SVGMenuElementEventSourceCD;
054: import org.openide.util.NbBundle;
055: import org.openide.util.Utilities;
056:
057: import java.awt.*;
058:
059: /**
060: *
061: * @author Anton Chechel
062: */
063: public class ItemSupport {
064:
065: private static final Resolver SVG_MENU_ELEMENT_RESOLVER = new ElementResolver(
066: SVGMenuElementEventSourceCD.PROP_STRING,
067: SVGMenuElementEventSourceCD.ICON_PATH);
068:
069: public static Resolver createSVGMenuElementInfoResolver() {
070: return SVG_MENU_ELEMENT_RESOLVER;
071: }
072:
073: private static class ElementResolver implements
074: InfoPresenter.Resolver {
075:
076: private String propertyName;
077: private Image icon;
078:
079: private ElementResolver(String propertyName, String iconResource) {
080: this .propertyName = propertyName;
081: this .icon = Utilities.loadImage(iconResource);
082: }
083:
084: public DesignEventFilter getEventFilter(
085: DesignComponent component) {
086: return new DesignEventFilter().addComponentFilter(
087: component, false);
088: }
089:
090: public String getDisplayName(DesignComponent component,
091: NameType nameType) {
092: switch (nameType) {
093: case PRIMARY:
094: return resolveName(component);
095: case SECONDARY:
096: return NbBundle.getMessage(ItemSupport.class,
097: "TYPE_Element"); // NOI18N
098: case TERTIARY:
099: return null;
100: default:
101: throw Debug.illegalState();
102: }
103: }
104:
105: private String resolveName(DesignComponent component) {
106: return MidpValueSupport.getHumanReadableString(component
107: .readProperty(propertyName));
108: }
109:
110: public boolean isEditable(DesignComponent component) {
111: return true;
112: }
113:
114: public String getEditableName(DesignComponent component) {
115: PropertyValue value = component.readProperty(propertyName);
116: if (value.getKind() == PropertyValue.Kind.VALUE) {
117: return MidpTypes.getString(value);
118: } else {
119: return ""; // NOI18N
120: }
121: }
122:
123: public void setEditableName(DesignComponent component,
124: String enteredName) {
125: assert enteredName != null;
126: component.writeProperty(propertyName, MidpTypes
127: .createStringValue(enteredName));
128: }
129:
130: public Image getIcon(DesignComponent component,
131: IconType iconType) {
132: return iconType == IconType.COLOR_16x16 ? icon : null;
133: }
134:
135: }
136:
137: }
|