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.timezone;
043:
044: import org.netbeans.modules.vmd.api.model.PropertyValue;
045: import org.netbeans.modules.vmd.midp.components.MidpTypes;
046: import org.netbeans.modules.vmd.midp.propertyeditors.api.usercode.PropertyEditorElement;
047: import org.netbeans.modules.vmd.midp.propertyeditors.api.usercode.PropertyEditorUserCode;
048: import org.openide.awt.Mnemonics;
049: import org.openide.util.NbBundle;
050:
051: import javax.swing.*;
052: import java.awt.event.ActionEvent;
053: import java.awt.event.ActionListener;
054: import java.util.Collections;
055:
056: /**
057: *
058: * @author Anton Chechel
059: */
060: public class PropertyEditorTimeZone extends PropertyEditorUserCode {
061:
062: private PropertyEditorTimeZone.TimeZoneEditor timeZoneEditor;
063:
064: private PropertyEditorTimeZone() {
065: super (NbBundle.getMessage(PropertyEditorTimeZone.class,
066: "LBL_TIME_ZONE_UCLABEL")); // NOI18N
067:
068: timeZoneEditor = new TimeZoneEditor();
069: initElements(Collections
070: .<PropertyEditorElement> singleton(timeZoneEditor));
071: }
072:
073: public static PropertyEditorTimeZone createInstance() {
074: return new PropertyEditorTimeZone();
075: }
076:
077: @Override
078: public String getAsText() {
079: String super Text = super .getAsText();
080: if (super Text != null) {
081: return super Text;
082: }
083:
084: PropertyValue value = (PropertyValue) super .getValue();
085: return (String) value.getPrimitiveValue();
086: }
087:
088: private void saveValue(String text) {
089: if (text.length() > 0) {
090: super .setValue(MidpTypes.createStringValue(text));
091: }
092: }
093:
094: @Override
095: public void customEditorOKButtonPressed() {
096: super .customEditorOKButtonPressed();
097: if (timeZoneEditor.getRadioButton().isSelected())
098: saveValue(timeZoneEditor.getTextForPropertyValue());
099: }
100:
101: private final class TimeZoneEditor implements
102: PropertyEditorElement, ActionListener {
103: private JRadioButton radioButton;
104: private TimeZoneComboboxModel model;
105: private JComboBox combobox;
106:
107: public TimeZoneEditor() {
108: radioButton = new JRadioButton();
109: Mnemonics.setLocalizedText(radioButton, NbBundle
110: .getMessage(PropertyEditorTimeZone.class,
111: "LBL_TIMEZONE")); // NOI18N
112: model = new TimeZoneComboboxModel();
113: combobox = new JComboBox(model);
114: combobox.setEditable(true);
115: combobox.addActionListener(this );
116: }
117:
118: public void updateState(PropertyValue value) {
119: if (!isCurrentValueANull() && value != null) {
120: String timeZone;
121: for (int i = 0; i < model.getSize(); i++) {
122: timeZone = (String) model.getElementAt(i);
123: if (timeZone.equals(value.getPrimitiveValue())) {
124: model.setSelectedItem(timeZone);
125: break;
126: }
127: }
128: }
129: }
130:
131: public void setTextForPropertyValue(String text) {
132: saveValue(text);
133: }
134:
135: public String getTextForPropertyValue() {
136: return (String) combobox.getSelectedItem();
137: }
138:
139: public JComponent getCustomEditorComponent() {
140: return combobox;
141: }
142:
143: public JRadioButton getRadioButton() {
144: return radioButton;
145: }
146:
147: public boolean isInitiallySelected() {
148: return true;
149: }
150:
151: public boolean isVerticallyResizable() {
152: return false;
153: }
154:
155: public void actionPerformed(ActionEvent evt) {
156: radioButton.setSelected(true);
157: }
158: }
159:
160: }
|