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.insync.live;
042:
043: import java.awt.*;
044: import java.awt.event.ItemEvent;
045: import java.awt.event.ItemListener;
046:
047: import javax.swing.*;
048:
049: import org.openide.util.NbBundle;
050:
051: import com.sun.rave.designtime.*;
052:
053: public class EventEditPanel extends JPanel {
054:
055: /**
056: *
057: */
058: private static final long serialVersionUID = 3256728376969606451L;
059: protected EventPropertyEditor epe;
060: protected DesignEvent liveEvent;
061:
062: protected JLabel label = new JLabel();
063: protected JComboBox selectionList = new JComboBox();
064: protected GridBagLayout gridBagLayout1 = new GridBagLayout();
065:
066: public EventEditPanel(EventPropertyEditor epe, DesignEvent le) {
067: this .epe = epe;
068: this .liveEvent = le;
069: try {
070: jbInit();
071: } catch (Exception e) {
072: e.printStackTrace();
073: }
074:
075: // find the current value
076: String current = le.getHandlerName();
077:
078: String[] handlers = epe.getMethods();
079: selectionList.addItem(""); // 0th item is always blank/null/unset
080: int sel = 0; // blank gets selection by default
081: for (int i = 0; i < handlers.length; i++) {
082: selectionList.addItem(handlers[i]);
083: if (handlers[i].equals(current))
084: sel = i + 1; // off by one for first blank
085: }
086:
087: if (sel == 0) {
088: // add the current item if it is set but the method is not in the list
089: if (current != null)
090: selectionList.addItem(current);
091: // provide default name if no handler method currently exists (even if unbound current)
092: selectionList.addItem(liveEvent.getDefaultHandlerName());
093: }
094: selectionList.setSelectedIndex(sel);
095:
096: initializing = false;
097: }
098:
099: protected boolean initializing = true;
100:
101: public void setHandler(String handler) {
102: selectionList.setSelectedItem(handler);
103: if (initializing)
104: return;
105: firePropertyChange(null, null, null);
106: if (epe != null)
107: epe.setValue(handler);
108: }
109:
110: public String getHandler() {
111: Object o = selectionList.getSelectedItem();
112: return o != null ? o.toString() : null;
113: }
114:
115: private void jbInit() throws Exception {
116: this .setLayout(gridBagLayout1);
117: label.setText(NbBundle.getMessage(BeansDesignEvent.class,
118: "Handler")); //NOI18N
119: selectionList.setEditable(true);
120: this .add(label, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0,
121: GridBagConstraints.CENTER,
122: GridBagConstraints.HORIZONTAL, new Insets(8, 8, 2, 8),
123: 0, 0));
124: this .add(selectionList, new GridBagConstraints(0, 1, 1, 1, 1.0,
125: 0.0, GridBagConstraints.WEST,
126: GridBagConstraints.HORIZONTAL, new Insets(0, 8, 4, 8),
127: 0, 0));
128: label.setLabelFor(selectionList);
129: selectionList.getAccessibleContext().setAccessibleName(
130: NbBundle.getMessage(BeansDesignEvent.class,
131: "selectionListAccessibleName"));
132: selectionList.getAccessibleContext().setAccessibleDescription(
133: NbBundle.getMessage(BeansDesignEvent.class,
134: "selectionListAccessibleDescription"));
135: selectionList.addItemListener(new ItemListener() {
136: public void itemStateChanged(ItemEvent e) {
137: if (!initializing && epe != null
138: && e.getStateChange() == ItemEvent.SELECTED) {
139: firePropertyChange(null, null, null);
140: Object item = selectionList.getSelectedItem();
141: epe.setValue(item);
142: }
143: }
144: });
145: }
146: }
|