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.propertyeditors;
042:
043: import java.awt.Component;
044:
045: import java.awt.event.ActionListener;
046: import java.beans.PropertyEditor;
047: import javax.swing.BorderFactory;
048: import javax.swing.JCheckBox;
049: import javax.swing.JComponent;
050: import javax.swing.KeyStroke;
051: import org.netbeans.modules.vmd.api.model.PropertyValue;
052: import org.netbeans.modules.vmd.api.properties.DesignPropertyEditor;
053: import org.openide.explorer.propertysheet.InplaceEditor;
054: import org.openide.explorer.propertysheet.PropertyEnv;
055: import org.openide.explorer.propertysheet.PropertyModel;
056:
057: /**
058: *
059: * @author Karol Harezlak
060: */
061: public class BooleanInplaceEditor implements InplaceEditor {
062:
063: private JCheckBox checkBox;
064: private DesignPropertyEditor propertyEditor;
065: private PropertyModel model;
066:
067: // Do not create this InplaceEditor in PropertyEditor constructor!!!!!!
068: public BooleanInplaceEditor(DesignPropertyEditor propertyEditor) {
069: this .propertyEditor = propertyEditor;
070: checkBox = new JCheckBox();
071: PropertyValue value = (PropertyValue) propertyEditor.getValue();
072: if (value != null
073: && value.getKind() == PropertyValue.Kind.VALUE) {
074: if (!(value.getPrimitiveValue() instanceof Boolean)) {
075: Boolean selected = (Boolean) value.getPrimitiveValue();
076: checkBox.setSelected(selected);
077: }
078: } else if (value == PropertyValue.createNull())
079: checkBox.setSelected(false);
080: }
081:
082: public void connect(PropertyEditor propertyEditor, PropertyEnv env) {
083: }
084:
085: public JComponent getComponent() {
086: checkBox.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 0));
087: if (!propertyEditor.canWrite())
088: checkBox.setEnabled(false);
089: else
090: checkBox.setEnabled(true);
091: return checkBox;
092: }
093:
094: public void clear() {
095: }
096:
097: public Object getValue() {
098: return propertyEditor.getValue();
099: }
100:
101: public void setValue(Object value) {
102: }
103:
104: public boolean supportsTextEntry() {
105: return true;
106: }
107:
108: public void reset() {
109: }
110:
111: public void addActionListener(ActionListener al) {
112: }
113:
114: public void removeActionListener(ActionListener al) {
115: }
116:
117: public KeyStroke[] getKeyStrokes() {
118: return new KeyStroke[0];
119: }
120:
121: public PropertyEditor getPropertyEditor() {
122: return propertyEditor;
123: }
124:
125: public PropertyModel getPropertyModel() {
126: return model;
127: }
128:
129: public void setPropertyModel(PropertyModel model) {
130: this .model = model;
131: }
132:
133: public boolean isKnownComponent(Component c) {
134: return true;
135: }
136:
137: }
|