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.form.editors2;
043:
044: import java.awt.Component;
045: import java.beans.PropertyChangeEvent;
046: import java.beans.PropertyVetoException;
047: import javax.swing.JCheckBox;
048: import javax.swing.JPanel;
049: import org.jdesktop.layout.GroupLayout;
050: import org.jdesktop.layout.LayoutStyle;
051: import org.netbeans.modules.form.NamedPropertyEditor;
052: import org.netbeans.modules.form.ResourceSupport;
053: import org.netbeans.modules.form.ResourceWrapperEditor;
054: import org.openide.awt.Mnemonics;
055: import org.openide.explorer.propertysheet.PropertyEnv;
056: import org.openide.util.NbBundle;
057:
058: /**
059: * Property editor wrapping StringEditor in a resource editor, allowing to
060: * produce resource values (ResourceValue) from strings.
061: *
062: * @author Tomas Pavek
063: */
064: public class StringEditor extends ResourceWrapperEditor implements
065: NamedPropertyEditor {
066:
067: private JCheckBox noI18nCheckbox;
068:
069: public StringEditor() {
070: super (new org.netbeans.modules.form.editors.StringEditor());
071: }
072:
073: public String getDisplayName() {
074: return NbBundle.getMessage(StringEditor.class,
075: "StringEditor_DisplayName"); // NOI18N
076: }
077:
078: @Override
079: public String getJavaInitializationString() {
080: String javaStr = super .getJavaInitializationString();
081: if (getValue() instanceof String
082: && ResourceSupport.isResourceableProperty(property)
083: && ResourceSupport.isExcludedProperty(property)) { // intentionally excluded from resourcing/internationalization - add NOI18N comment
084: javaStr = "*/\n\\1NOI18N*/\n\\0" + javaStr; // NOI18N
085: // */\n\\1 is a special code mark for line comment
086: // */\n\\0 is a special code mark to indicate that a real code follows
087: }
088: return javaStr;
089: }
090:
091: @Override
092: public Component getCustomEditor() {
093: Component customEd = super .getCustomEditor();
094: if (noI18nCheckbox != null) {
095: noI18nCheckbox.setSelected(ResourceSupport
096: .isExcludedProperty(property));
097: }
098: return customEd;
099: }
100:
101: @Override
102: protected Component createCustomEditorGUI(Component resourcePanelGUI) {
103: if (resourcePanelGUI == null
104: && ResourceSupport.isResourceableProperty(property)) {
105: // not usable for full resourcing, only for internationalization
106: // add a NOI18N checkbox so the user can mark the property as not to be internationalized
107: Component customEd = delegateEditor.getCustomEditor();
108: JPanel panel = new JPanel();
109: GroupLayout layout = new GroupLayout(panel);
110: panel.setLayout(layout);
111: noI18nCheckbox = new JCheckBox();
112: Mnemonics.setLocalizedText(noI18nCheckbox, NbBundle
113: .getMessage(StringEditor.class,
114: "CTL_NOI18NCheckBox")); // NOI18N
115: layout.setHorizontalGroup(layout.createParallelGroup().add(
116: customEd).add(
117: layout.createSequentialGroup().addContainerGap()
118: .add(noI18nCheckbox).addContainerGap()));
119: layout.setVerticalGroup(layout.createSequentialGroup().add(
120: customEd).addPreferredGap(LayoutStyle.UNRELATED)
121: .add(noI18nCheckbox));
122: return panel;
123: } else {
124: noI18nCheckbox = null;
125: return super .createCustomEditorGUI(resourcePanelGUI);
126: }
127: }
128:
129: // called when OK button is pressed in the custom editor dialog
130: @Override
131: public void vetoableChange(PropertyChangeEvent ev)
132: throws PropertyVetoException {
133: super .vetoableChange(ev);
134: if (PropertyEnv.PROP_STATE.equals(ev.getPropertyName())
135: && resourcePanel == null && noI18nCheckbox != null) { // no resourcing, just internationalizing
136: // mark the property excluded if the NOI18N checkbox is checked
137: ResourceSupport.setExcludedProperty(property,
138: noI18nCheckbox.isSelected());
139: }
140: }
141: }
|