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:
042: package org.netbeans.modules.vmd.midp.propertyeditors.eventhandler;
043:
044: import java.util.ArrayList;
045: import java.util.Collection;
046: import java.util.List;
047: import javax.swing.DefaultComboBoxModel;
048: import javax.swing.JComponent;
049: import javax.swing.JPanel;
050: import javax.swing.JRadioButton;
051: import org.netbeans.modules.vmd.api.model.DesignComponent;
052: import org.netbeans.modules.vmd.api.model.PropertyValue;
053: import org.netbeans.modules.vmd.api.model.TypeID;
054: import org.netbeans.modules.vmd.midp.components.ListCellRenderer;
055: import org.netbeans.modules.vmd.midp.components.MidpDocumentSupport;
056: import org.netbeans.modules.vmd.midp.components.handlers.CallPointEventHandlerCD;
057: import org.netbeans.modules.vmd.midp.components.handlers.MethodPointEventHandlerCD;
058: import org.netbeans.modules.vmd.midp.propertyeditors.element.PropertyEditorEventHandlerElement;
059: import org.netbeans.modules.vmd.midp.propertyeditors.element.PropertyEditorElementFactory;
060: import org.openide.awt.Mnemonics;
061: import org.openide.util.NbBundle;
062:
063: /**
064: *
065: * @author Anton Chechel
066: */
067: public class CallElement extends JPanel implements
068: PropertyEditorEventHandlerElement {
069: private DefaultComboBoxModel pointsModel;
070: private JRadioButton radioButton;
071: private ListCellRenderer cellRenderer;
072:
073: private CallElement() {
074: radioButton = new JRadioButton();
075: Mnemonics.setLocalizedText(radioButton, NbBundle.getMessage(
076: CallElement.class, "LBL_CALL")); // NOI18N
077: pointsModel = new DefaultComboBoxModel();
078: cellRenderer = new ListCellRenderer();
079:
080: initComponents();
081: }
082:
083: public void setTextForPropertyValue(String text) {
084: }
085:
086: public JComponent getCustomEditorComponent() {
087: return this ;
088: }
089:
090: public JRadioButton getRadioButton() {
091: return radioButton;
092: }
093:
094: public boolean isInitiallySelected() {
095: return false;
096: }
097:
098: public boolean isVerticallyResizable() {
099: return false;
100: }
101:
102: public String getTextForPropertyValue() {
103: return ""; // NOI18N
104: }
105:
106: public void updateState(PropertyValue value) {
107: if (value != null) {
108: DesignComponent eventHandler = value.getComponent();
109: if (eventHandler.getType().equals(
110: CallPointEventHandlerCD.TYPEID)
111: || eventHandler.getType().equals(
112: MethodPointEventHandlerCD.TYPEID)) {
113: radioButton.setSelected(true);
114: }
115: }
116: }
117:
118: public void createEventHandler(DesignComponent eventSource) {
119: if (!radioButton.isSelected()) {
120: return;
121: }
122: DesignComponent callElement = (DesignComponent) pointsModel
123: .getSelectedItem();
124: MidpDocumentSupport.updateEventHandlerFromTarget(eventSource,
125: callElement);
126: }
127:
128: public void updateModel(List<DesignComponent> components,
129: int modelType) {
130: if (modelType == MODEL_TYPE_POINTS) {
131: pointsModel.removeAllElements();
132: for (DesignComponent component : components) {
133: pointsModel.addElement(component);
134: }
135: }
136: }
137:
138: public void setElementEnabled(boolean enabled) {
139: }
140:
141: public Collection<TypeID> getTypes() {
142: List<TypeID> list = new ArrayList<TypeID>(2);
143: list.add(CallPointEventHandlerCD.TYPEID);
144: list.add(MethodPointEventHandlerCD.TYPEID);
145: return list;
146: }
147:
148: public static class CallElementFactory implements
149: PropertyEditorElementFactory {
150: public PropertyEditorEventHandlerElement createElement() {
151: return new CallElement();
152: }
153: }
154:
155: /** This method is called from within the constructor to
156: * initialize the form.
157: * WARNING: Do NOT modify this code. The content of this method is
158: * always regenerated by the Form Editor.
159: */
160: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
161: private void initComponents() {
162:
163: comboBox = new javax.swing.JComboBox();
164:
165: comboBox.setModel(pointsModel);
166: comboBox.setRenderer(cellRenderer);
167: comboBox.addActionListener(new java.awt.event.ActionListener() {
168: public void actionPerformed(java.awt.event.ActionEvent evt) {
169: comboBoxActionPerformed(evt);
170: }
171: });
172:
173: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
174: this );
175: this .setLayout(layout);
176: layout.setHorizontalGroup(layout.createParallelGroup(
177: org.jdesktop.layout.GroupLayout.LEADING).add(comboBox,
178: 0, 300, Short.MAX_VALUE));
179: layout.setVerticalGroup(layout.createParallelGroup(
180: org.jdesktop.layout.GroupLayout.LEADING).add(comboBox,
181: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
182: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
183: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE));
184: }// </editor-fold>//GEN-END:initComponents
185:
186: private void comboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboBoxActionPerformed
187: //radioButton.setSelected(true);
188: }//GEN-LAST:event_comboBoxActionPerformed
189:
190: // Variables declaration - do not modify//GEN-BEGIN:variables
191: private javax.swing.JComboBox comboBox;
192: // End of variables declaration//GEN-END:variables
193: }
|