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.midp.components.handlers;
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.presenters.InfoPresenter;
047: import org.netbeans.modules.vmd.midp.components.displayables.DisplayableCD;
048: import org.netbeans.modules.vmd.midp.components.general.ClassSupport;
049: import org.openide.util.NbBundle;
050: import org.openide.util.Utilities;
051:
052: import java.awt.*;
053:
054: /**
055: * @author David Kaspar
056: */
057: public class EventHandlerSupport {
058:
059: private static final InfoPresenter.Resolver SWITCH_DISPLAYABLE_EVENT_HANDLER_INFO_RESOLVER = new SwitchDisplayableResolver();
060:
061: public static InfoPresenter.Resolver getSwitchDisplayableEventHandlerInfoResolver() {
062: return SWITCH_DISPLAYABLE_EVENT_HANDLER_INFO_RESOLVER;
063: }
064:
065: private static class SwitchDisplayableResolver implements
066: InfoPresenter.Resolver {
067:
068: public DesignEventFilter getEventFilter(
069: DesignComponent component) {
070: return new DesignEventFilter().addDescentFilter(component,
071: SwitchDisplayableEventHandlerCD.PROP_DISPLAYABLE)
072: .addDescentFilter(component,
073: SwitchDisplayableEventHandlerCD.PROP_ALERT);
074: }
075:
076: public String getDisplayName(DesignComponent component,
077: InfoPresenter.NameType nameType) {
078: switch (nameType) {
079: case PRIMARY:
080: DesignComponent displayable = component
081: .readProperty(
082: SwitchDisplayableEventHandlerCD.PROP_DISPLAYABLE)
083: .getComponent();
084: DesignComponent alert = component.readProperty(
085: SwitchDisplayableEventHandlerCD.PROP_ALERT)
086: .getComponent();
087: if (displayable == null)
088: return NbBundle.getMessage(
089: EventHandlerSupport.class,
090: "DISP_Handler_Clear_Display"); // NOI18N
091:
092: String displayableName = ClassSupport
093: .resolveDisplayName(displayable);
094: String alertName = alert != null ? ClassSupport
095: .resolveDisplayName(alert) : null;
096: if (alertName != null)
097: return NbBundle.getMessage(
098: EventHandlerSupport.class,
099: "DISP_Handler_Go_to_displayable_alert",
100: displayableName, alertName); // NOI18N
101: else
102: return NbBundle.getMessage(
103: EventHandlerSupport.class,
104: "DISP_Handler_Go_to_displayable",
105: displayableName); // NOI18N
106: case SECONDARY:
107: return NbBundle.getMessage(EventHandlerSupport.class,
108: "TYPE_Action"); // NOI18N
109: case TERTIARY:
110: return null;
111: default:
112: throw Debug.illegalState();
113: }
114: }
115:
116: public boolean isEditable(DesignComponent component) {
117: return false;
118: }
119:
120: public String getEditableName(DesignComponent component) {
121: return null;
122: }
123:
124: public void setEditableName(DesignComponent component,
125: String enteredName) {
126: }
127:
128: public Image getIcon(DesignComponent component,
129: InfoPresenter.IconType iconType) {
130: switch (iconType) {
131: case COLOR_16x16:
132: return Utilities.loadImage(DisplayableCD.ICON_PATH);
133: case COLOR_32x32:
134: return Utilities
135: .loadImage(DisplayableCD.LARGE_ICON_PATH);
136: default:
137: return null;
138: }
139: }
140:
141: }
142:
143: }
|