KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > i18n > form > FormI18nStringEditor


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20
21 package org.netbeans.modules.i18n.form;
22
23
24 import java.awt.Component JavaDoc;
25 import java.awt.Container JavaDoc;
26 import java.beans.PropertyEditorSupport JavaDoc;
27 import java.io.IOException JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.Map JavaDoc;
30 import java.util.ResourceBundle JavaDoc;
31 import javax.swing.*;
32 import javax.swing.event.ChangeEvent JavaDoc;
33 import javax.swing.event.ChangeListener JavaDoc;
34 import org.jdesktop.layout.GroupLayout;
35 import org.netbeans.api.java.classpath.ClassPath;
36
37 import org.netbeans.modules.form.FormModel;
38 import org.netbeans.modules.form.FormAwareEditor;
39 import org.netbeans.modules.form.FormDataObject;
40 import org.netbeans.modules.form.I18nValue;
41 import org.netbeans.modules.form.NamedPropertyEditor;
42 import org.netbeans.modules.form.FormEditorSupport;
43 import org.netbeans.modules.i18n.I18nPanel;
44 import org.netbeans.modules.i18n.I18nString;
45 import org.netbeans.modules.i18n.I18nUtil;
46 import org.netbeans.modules.i18n.java.JavaI18nSupport;
47
48 import org.openide.explorer.propertysheet.editors.EnhancedCustomPropertyEditor;
49 import org.openide.explorer.propertysheet.editors.XMLPropertyEditor;
50 import org.openide.filesystems.FileObject;
51 import org.openide.loaders.DataObject;
52 import org.openide.ErrorManager;
53 import org.openide.util.HelpCtx;
54 import org.openide.util.MapFormat;
55 import org.openide.util.NbBundle;
56 import org.openide.awt.Mnemonics;
57 import org.netbeans.api.project.Project;
58
59 import org.w3c.dom.Element JavaDoc;
60 import org.w3c.dom.Document JavaDoc;
61 import org.w3c.dom.DOMException JavaDoc;
62 import org.w3c.dom.NamedNodeMap JavaDoc;
63 import org.w3c.dom.Node JavaDoc;
64 import org.w3c.dom.NodeList JavaDoc;
65
66
67 /**
68  * Property editor for editing <code>FormI18nString</code> value in form editor.
69  * This editor is registered during installing i18n module
70  * as editor for form properties of type <code>String</code>.
71  * It provides also a capability to store such object in XML form.
72  * <B>Note: </B>This class should be named FormI18nStringEditor, but due to forward compatibility
73  * remains that name.
74  *
75  * @author Petr Jiricka
76  * @see FormI18nString
77  * @see org.netbeans.modules.form.RADComponent
78  * @see org.netbeans.modules.form.RADProperty
79  */

80 public class FormI18nStringEditor extends PropertyEditorSupport JavaDoc implements FormAwareEditor, NamedPropertyEditor, XMLPropertyEditor {
81
82     /** Value of <code>ResourceBundleString</code> this editor is currently editing. */
83 // private FormI18nString formI18nString;
84

85     /** <code>DataObject</code> which have <code>SourceCookie</code>, and which document contains
86      * going-to-be-internatioanlized string.
87      */

88     private FormDataObject sourceDataObject;
89
90     /** Name of resource string XML element. */
91     public static final String JavaDoc XML_RESOURCESTRING = "ResourceString"; // NOI18N
92
/** Name of plain string XML element (string not internationalized). */
93     private static final String JavaDoc XML_PLAINSTRING = "PlainString"; // NOI18N
94
/** Name of argument XML element (child element of resource string element). */
95     public static final String JavaDoc XML_ARGUMENT = "Argument"; // NOI18N
96
/** Name of attribute bundle of resource string XML element. */
97     public static final String JavaDoc ATTR_BUNDLE = "bundle"; // NOI18N
98
/** Name of attribute key of resource string XML element. */
99     public static final String JavaDoc ATTR_KEY = "key"; // NOI18N
100
/** Name of attribute storing value of non-internationalized string. */
101     private static final String JavaDoc ATTR_VALUE = "value"; // NOI18N
102
/** Name of attribute identifier of resource string XML element. */
103     public static final String JavaDoc ATTR_IDENTIFIER = "identifier"; // NOI18N
104
/** Name of attribute replace format XML element. */
105     public static final String JavaDoc ATTR_REPLACE_FORMAT = "replaceFormat"; // NOI18N
106
/** Name of attribute index of argument XML element. */
107     public static final String JavaDoc ATTR_INDEX = "index"; // NOI18N
108
/** Name of attribute java code of argument XML element. */
109     public static final String JavaDoc ATTR_JAVACODE = "javacode"; // NOI18N
110

111     /** Maximal index of arguments in one argument XML element. */
112     private static final int MAX_INDEX = 1000;
113     
114     private final ResourceBundle JavaDoc bundle;
115
116     /** Constructor. Creates new <code>ResourceBundleStringFormEditor</code>. */
117     public FormI18nStringEditor() {
118         bundle = NbBundle.getBundle(FormI18nStringEditor.class);
119     }
120
121
122     /** Overrides superclass method.
123      * @return null as we don't support this feature */

124     public String JavaDoc[] getTags() {
125         return null;
126     }
127
128     /** Sets as text. Overrides superclass method to be dummy -> don't throw
129      * <code>IllegalArgumentException</code> . */

130     public void setAsText(String JavaDoc text) {
131         setValue(text);
132     }
133         
134     
135     /** Overrides superclass method.
136      * @return text for the current value */

137     public String JavaDoc getAsText() {
138         Object JavaDoc value = getValue();
139         if (value instanceof String JavaDoc)
140             return (String JavaDoc) value;
141
142         FormI18nString i18nString = (FormI18nString) value;
143         return i18nString.getValue();
144 // DataObject dataObject = formI18nString.getSupport().getResourceHolder().getResource();
145
//
146
// if (dataObject == null || formI18nString.getKey() == null) {
147
// return bundle.getString("TXT_InvalidValue");
148
// } else {
149
// DataObject sourceDataObject = formI18nString.getSupport().getSourceDataObject();
150
// return MessageFormat.format(
151
// bundle.getString("TXT_Key"),
152
// new Object[] {
153
// formI18nString.getKey(),
154
// org.netbeans.modules.i18n.Util.
155
// getResourceName(sourceDataObject.getPrimaryFile(),
156
// dataObject.getPrimaryFile(), '/', false ), // NOI18N
157
// }
158
// );
159
// }
160
}
161
162     /** Overrides superclass method. Gets string, piece of code which will replace the hardcoded
163      * non-internationalized string in the source. The default form is:
164      * <p>
165      * <b><identifier name>.getString("<key name>")</b>
166      * or if arguments for the ResoureBundleStrin are set the form:
167      * <p>
168      * <b>java.text.MessageFormat.format(<identifier name>getString("<key name>"), new Object[] {<code set in Parameters and Comments panel>})</b>
169      */

170     public String JavaDoc getJavaInitializationString() {
171         FormI18nString i18nString = (FormI18nString) getValue();
172         String JavaDoc javaString;
173         if (i18nString.getKey() != I18nValue.NOI18N_KEY) {
174             javaString = i18nString.getReplaceString();
175             if (javaString == null) { // some problem, return plain string (better than null)
176
return "\"" + FormI18nSupport.toAscii(i18nString.getValue()) + "\""; // NOI18N
177
}
178         }
179         else { // intentionally hardcoded string (with NOI18N comment)
180
javaString = "\"" + FormI18nSupport.toAscii(i18nString.getValue()) + "\""; // NOI18N
181
}
182             
183         return "*/\n\\1NOI18N*/\n\\0" + javaString; // NOI18N
184
// */\n\\1 is a special code mark for line comment
185
// */\n\\0 is a special code mark to indicate that a real code follows
186
}
187
188     /** Overrides superclass method.
189      * @return <code>ResourceBundlePanel</code> fed with <code>FormI18nString</code> value. */

190     public Component JavaDoc getCustomEditor() {
191         FormI18nString formI18nString;
192         Object JavaDoc value = getValue();
193         boolean noI18n;
194         if (value instanceof FormI18nString) {
195             formI18nString = new FormI18nString((FormI18nString)value);
196             if (formI18nString.getKey() == I18nValue.NOI18N_KEY) {
197                 formI18nString.setKey(null);
198                 noI18n = true;
199             }
200             else noI18n = false;
201         }
202         else {
203             formI18nString = createFormI18nString();
204             if (value instanceof String JavaDoc)
205                 formI18nString.setValue((String JavaDoc)value);
206             DataObject lastResource = I18nUtil.getOptions().getLastResource2();
207             if (lastResource != null) {
208                 FileObject sourceFile = sourceDataObject.getPrimaryFile();
209                 FileObject bundleFile = lastResource.getPrimaryFile();
210                 ClassPath sourceClassPath = ClassPath.getClassPath(
211                                                 sourceFile, ClassPath.SOURCE);
212                 if (sourceClassPath.contains(bundleFile)) {
213                     formI18nString.getSupport().getResourceHolder().setResource(
214                             lastResource);
215                 }
216             }
217             noI18n = false;
218         }
219         return new CustomEditor(formI18nString, getProject(), sourceDataObject.getPrimaryFile(), noI18n);
220 // return new CustomEditor(new FormI18nString((FormI18nString)getValue()), getProject(), sourceDataObject.getPrimaryFile());
221
}
222     
223     private Project getProject() {
224       return org.netbeans.modules.i18n.Util.getProjectFor(sourceDataObject);
225     }
226
227
228     /** Overrides superclass method.
229      * @return true since we support this feature */

230     public boolean supportsCustomEditor() {
231         return true;
232     }
233
234     /** Overrides superclass method.
235      * @return <code>formI18nString</code> */

236 // public Object getValue() {
237
// if(formI18nString == null) {
238
// formI18nString = createFormI18nString();
239
//
240
// if(I18nUtil.getOptions().getLastResource2() != null)
241
// formI18nString.getSupport().getResourceHolder().setResource(I18nUtil.getOptions().getLastResource2());
242
// }
243
//
244
// return formI18nString;
245
// }
246

247     /** Overrides superclass method.
248      * @param value sets the new value for this editor */

249     public void setValue(Object JavaDoc object) {
250         if (object instanceof String JavaDoc && getValue() instanceof FormI18nString) {
251             FormI18nString i18nString = new FormI18nString((FormI18nString)getValue());
252             i18nString.setValue((String JavaDoc)object);
253             object = i18nString;
254         }
255         super.setValue(object);
256 // if(object instanceof FormI18nString)
257
// formI18nString = (FormI18nString)object;
258
// else {
259
// formI18nString = createFormI18nString();
260
// DataObject lastResource = I18nUtil.getOptions().getLastResource2();
261
// if (lastResource != null) {
262
// formI18nString.getSupport().getResourceHolder()
263
// .setResource(lastResource);
264
// }
265
// }
266
}
267
268     /** Creates <code>FormI18nString</code> instance. Helper method. */
269     private FormI18nString createFormI18nString() {
270         // Note: Only here we can have support without possible document loading.
271
return new FormI18nString(sourceDataObject);
272     }
273     
274     /**
275      * Implements <code>FormAwareEditor</code> method.
276      * If a property editor implements the <code>FormAwareEditor</code>
277      * interface, this method is called immediately after the PropertyEditor
278      * instance is created or the custom editor is obtained from getCustomEditor().
279      * @param model the <code>FormModel</code> representing meta-data of current form */

280     public void setFormModel(FormModel model) {
281         sourceDataObject = FormEditorSupport.getFormDataObject(model);
282     }
283
284     /**
285      * Implements <code>NamePropertyEditor</code> interface method.
286      * @return Display name of the property editor
287      */

288     public String JavaDoc getDisplayName () {
289         return NbBundle.getMessage(FormI18nStringEditor.class, "CTL_PropertyEditorName"); // NOI18N
290
}
291
292
293     /**
294      * Implements <code>XMLPropertyEditor</code> interface method.
295      * Called to load property value from specified XML subtree. If succesfully loaded,
296      * the value should be available via the getValue method.
297      * An IOException should be thrown when the value cannot be restored from the specified XML element
298      * @param element the XML DOM element representing a subtree of XML from which the value should be loaded
299      * @exception IOException thrown when the value cannot be restored from the specified XML element
300      * @see org.w3c.dom.Node
301      */

302     public void readFromXML(Node JavaDoc domNode) throws IOException JavaDoc {
303         FormI18nString formI18nString = createFormI18nString();
304         NamedNodeMap JavaDoc namedNodes = domNode.getAttributes ();
305
306         if (XML_PLAINSTRING.equals(domNode.getNodeName())) {
307             // plain string
308
Node JavaDoc node = namedNodes.getNamedItem(ATTR_VALUE);
309             if (node != null) {
310                 formI18nString.setKey(I18nValue.NOI18N_KEY);
311                 formI18nString.setValue(node.getNodeValue());
312                 setValue(formI18nString);
313             }
314             return;
315         }
316
317         if(!XML_RESOURCESTRING.equals (domNode.getNodeName ())) {
318             throw new IOException JavaDoc ();
319         }
320
321         try {
322             Node JavaDoc node;
323             // Retrieve bundle name.
324
node = namedNodes.getNamedItem(ATTR_BUNDLE);
325             String JavaDoc bundleName = (node == null) ? null : node.getNodeValue();
326
327             // Retrieve key name.
328
node = namedNodes.getNamedItem(ATTR_KEY);
329             String JavaDoc key = (node == null) ? null : node.getNodeValue();
330
331             // Set the resource bundle.
332
if(bundleName != null) {
333                 DataObject resourceDO = null;
334                 FileObject sourceFo = sourceDataObject.getPrimaryFile();
335                 if ( sourceFo != null ) {
336                     FileObject fileObject = org.netbeans.modules.i18n.Util.
337                         getResource(sourceFo, bundleName);
338                     
339                     if(fileObject != null) {
340                         try {
341                             resourceDO = DataObject.find(fileObject);
342                             if( resourceDO.getClass().equals(formI18nString.getSupport().getResourceHolder().getResourceClasses()[0])) // PENDING
343
formI18nString.getSupport().getResourceHolder().setResource(resourceDO);
344                         }
345                         catch (IOException JavaDoc e) {
346                         }
347                     }
348                 }
349                 if (resourceDO == null)
350                     formI18nString.bundleName = bundleName;
351             }
352
353             // Set the key property.
354
if(key != null && key.length() > 0) {
355                 formI18nString.setKey(key);
356                 
357                 // Set value and comment.
358
formI18nString.setValue(formI18nString.getSupport().getResourceHolder().getValueForKey(key));
359                 formI18nString.setComment(formI18nString.getSupport().getResourceHolder().getCommentForKey(key));
360             }
361
362             // Try to get identifier value.
363
((JavaI18nSupport)formI18nString.getSupport()).createIdentifier();
364             
365             node = namedNodes.getNamedItem(ATTR_IDENTIFIER);
366             if(node != null) {
367                 String JavaDoc identifier = (node == null) ? null : node.getNodeValue();
368                 
369                 if(identifier != null)
370                     ((JavaI18nSupport)formI18nString.getSupport()).setIdentifier(identifier);
371             }
372             
373             // Try to get init format string value.
374
node = namedNodes.getNamedItem(ATTR_REPLACE_FORMAT);
375             if(node != null) {
376                 String JavaDoc replaceFormat = node.getNodeValue();
377                 
378                 if(replaceFormat != null && replaceFormat.length() > 0) {
379                     
380                     // Note: This part of code is only due to use in some development builds of MessageFormat
381
// instead of MapFormat. If somebidy used those builds the replace code is in MessageFormat
382
// so we will convert it to MapFormat.
383
// This could be later extracted.
384
// Note if the replace form at was in the MessageFormat convert to MapFormat
385
// Don't throw away.
386
Map JavaDoc map = new HashMap JavaDoc(6);
387                     map.put("0", "{identifier}"); // NOI18N
388
map.put("1", "{key}"); // NOI18N
389
map.put("2", "{bundleNameSlashes}"); // NOI18N
390
map.put("3", "{bundleNameDots}"); // NOI18N
391
map.put("4", "{sourceFileName}"); // NOI18N
392
map.put("fileName", "{sourceFileName}"); // NOI18N
393

394                     String JavaDoc newReplaceFormat = MapFormat.format(replaceFormat, map);
395                     
396                     formI18nString.setReplaceFormat(newReplaceFormat);
397                 }
398             } else {
399                 // Read was not succesful (old form or error) -> set old form replace format.
400
formI18nString.setReplaceFormat((String JavaDoc)I18nUtil.getDefaultReplaceFormat(false));
401             }
402         } catch(NullPointerException JavaDoc npe) {
403             throw new IOException JavaDoc ();
404         }
405
406         // Retrieve the arguments.
407
if(domNode instanceof Element JavaDoc) {
408             Element JavaDoc domElement = (Element JavaDoc)domNode;
409             NodeList JavaDoc argNodeList = domElement.getElementsByTagName(XML_ARGUMENT);
410
411             // Find out the highest index.
412
int highest = -1;
413             for(int i = 0; i < argNodeList.getLength(); i++) {
414                 NamedNodeMap JavaDoc attributes = argNodeList.item(i).getAttributes();
415                 
416                 Node JavaDoc indexNode = attributes.getNamedItem (ATTR_INDEX);
417                 String JavaDoc indexString = (indexNode == null) ? null : indexNode.getNodeValue ();
418
419                 if(indexString != null) {
420                     try {
421                         int index = Integer.parseInt(indexString);
422                         if (index > highest && index < MAX_INDEX)
423                             highest = index;
424                     } catch (Exception JavaDoc e) {}
425                 }
426             }
427
428             // Construct the array.
429
String JavaDoc[] parameters = new String JavaDoc[highest + 1];
430
431             // Fill the array.
432
for (int i = 0; i < argNodeList.getLength(); i++) {
433                 NamedNodeMap JavaDoc attr = argNodeList.item(i).getAttributes ();
434                 
435                 Node JavaDoc indexNode = attr.getNamedItem (ATTR_INDEX);
436                 String JavaDoc indexString = (indexNode == null) ? null : indexNode.getNodeValue ();
437                 if (indexString != null) {
438                     try {
439                         int index = Integer.parseInt(indexString);
440                         if (index < MAX_INDEX) {
441                             Node JavaDoc javaCodeNode = attr.getNamedItem (ATTR_JAVACODE);
442                             String JavaDoc javaCode = (javaCodeNode == null) ? null : javaCodeNode.getNodeValue ();
443                             parameters[index] = javaCode;
444                         }
445                     } catch (Exception JavaDoc e) {}
446                 }
447             }
448
449             // Fill all the values in case some are missing - make it really foolproof.
450
for (int i = 0; i < parameters.length; i++)
451                 if (parameters[i] == null)
452                     parameters[i] = ""; // NOI18N
453

454             // Set the parameters.
455
formI18nString.setArguments(parameters);
456         }
457
458         // Set the value for this editor.
459
setValue(formI18nString);
460     }
461
462     /**
463      * Implements <code>XMLPropertyEditor</code> interface method.
464      * Called to store current property value into XML subtree. The property value should be set using the
465      * setValue method prior to calling this method.
466      * @param doc The XML document to store the XML in - should be used for creating nodes only
467      * @return the XML DOM element representing a subtree of XML from which the value should be loaded
468      */

469     public Node JavaDoc storeToXML(Document JavaDoc doc) {
470         FormI18nString formI18nString = (FormI18nString) getValue();
471         Element JavaDoc element;
472         if (formI18nString.getKey() != I18nValue.NOI18N_KEY) {
473             element = doc.createElement (XML_RESOURCESTRING);
474
475             String JavaDoc bundleName;
476             if (formI18nString.getSupport().getResourceHolder().getResource() == null) {
477                 bundleName = formI18nString.bundleName;
478             } else {
479                 bundleName = org.netbeans.modules.i18n.Util.
480                     getResourceName(formI18nString.getSupport().getSourceDataObject().getPrimaryFile(),
481                                     formI18nString.getSupport().getResourceHolder().getResource().getPrimaryFile(),'/', true);
482                 if (bundleName == null) bundleName = ""; // NOI18N
483
}
484
485             // Set bundle and key property.
486
element.setAttribute(ATTR_BUNDLE, bundleName);
487             element.setAttribute(ATTR_KEY, (formI18nString.getKey() == null) ? "" : formI18nString.getKey()); // NOI18N
488
// Don't save identifier, replace the identifier argument with actual value in format.
489
JavaI18nSupport support = (JavaI18nSupport)formI18nString.getSupport();
490             if(support.getIdentifier() == null)
491                 support.createIdentifier();
492             Map JavaDoc map = new HashMap JavaDoc(1);
493             map.put("identifier", support.getIdentifier()); // NOI18N
494
element.setAttribute(ATTR_REPLACE_FORMAT, formI18nString.getReplaceFormat() == null ? "" : MapFormat.format(formI18nString.getReplaceFormat(), map) ); // NOI18N
495

496             // Append subelements corresponding to parameters.
497
String JavaDoc[] arguments = formI18nString.getArguments();
498             for (int i = 0; i < arguments.length; i++) {
499                 Element JavaDoc childElement = doc.createElement (XML_ARGUMENT);
500                 childElement.setAttribute (ATTR_INDEX, "" + i); // NOI18N
501
childElement.setAttribute (ATTR_JAVACODE, arguments[i]);
502                 try {
503                     element.appendChild(childElement);
504                 } catch (DOMException JavaDoc de) {}
505             }
506         }
507         else { // this string is explicitly marked as not internationalized
508
element = doc.createElement (XML_PLAINSTRING);
509             element.setAttribute(ATTR_VALUE, formI18nString.getValue());
510         }
511
512         return element;
513     }
514
515     /** Custom editor for this property editor. */
516     private static class CustomEditor extends JPanel implements EnhancedCustomPropertyEditor, ChangeListener JavaDoc {
517         private I18nPanel i18nPanel;
518         private StringPanel stringPanel;
519         private JCheckBox noI18nCheckBox;
520         
521         /** Constructor. */
522         public CustomEditor(I18nString i18nString, Project project, FileObject file, boolean noI18n) {
523             i18nPanel = new I18nPanel(i18nString.getSupport().getPropertyPanel(), false, project, file);
524             noI18nCheckBox = new JCheckBox();
525             Mnemonics.setLocalizedText(noI18nCheckBox,
526                     NbBundle.getMessage(FormI18nStringEditor.class, "CTL_NOI18NCheckBox")); // NOI18N
527

528             GroupLayout layout = new GroupLayout(this);
529             setLayout(layout);
530             layout.setHorizontalGroup(layout.createParallelGroup()
531                 .add(i18nPanel)
532                 .add(layout.createSequentialGroup()
533                     .addContainerGap()
534                     .add(noI18nCheckBox)
535                     .addContainerGap()));
536             layout.setVerticalGroup(layout.createSequentialGroup()
537                 .add(i18nPanel)
538                 .add(noI18nCheckBox));
539
540             i18nPanel.setI18nString(i18nString);
541             setNoI18n(noI18n);
542             noI18nCheckBox.setSelected(noI18n);
543             noI18nCheckBox.addChangeListener(this);
544
545             HelpCtx.setHelpIDString(this, I18nUtil.HELP_ID_FORMED);
546         }
547
548         /** Implements <code>EnhancedCustomPropertyEditor</code> interface. */
549         public Object JavaDoc getPropertyValue() throws IllegalStateException JavaDoc {
550             I18nString i18nString = i18nPanel.getI18nString();
551
552             if (isNoI18n() && i18nString != null) {
553                 i18nString.setKey(I18nValue.NOI18N_KEY);
554                 i18nString.setValue(stringPanel.getString());
555                 return i18nString;
556             }
557
558             if(i18nString == null
559                 || !(i18nString instanceof FormI18nString)
560                 || i18nString.getSupport().getResourceHolder().getResource() == null
561                 || i18nString.getKey() == null) {
562
563                 // Notify user that invalid value set.
564
IllegalStateException JavaDoc ise = new IllegalStateException JavaDoc();
565                 String JavaDoc message = NbBundle.getMessage(FormI18nStringEditor.class, "MSG_InvalidValue"); // NOI18N
566
ErrorManager.getDefault().annotate(
567                      ise, ErrorManager.WARNING, message,
568                      message, null, null);
569                 throw ise;
570             }
571
572             return i18nString;
573         }
574
575         public void stateChanged(ChangeEvent JavaDoc e) {
576             setNoI18n(noI18nCheckBox.isSelected());
577         }
578
579         private boolean isNoI18n() {
580             return noI18nCheckBox.isSelected();
581         }
582
583         private void setNoI18n(boolean noI18n) {
584             if (noI18n) {
585                 if (getPlainStringPanel().getParent() == null) {
586                     ((GroupLayout)getLayout()).replace(i18nPanel, stringPanel);
587                     revalidate();
588                     repaint();
589                 }
590             }
591             else if (i18nPanel.getParent() == null) {
592                 ((GroupLayout)getLayout()).replace(stringPanel, i18nPanel);
593                 revalidate();
594                 repaint();
595             }
596         }
597
598         private JComponent getPlainStringPanel() {
599             if (stringPanel == null) {
600                 stringPanel = new StringPanel();
601                 stringPanel.setString(i18nPanel.getI18nString().getValue());
602             }
603             return stringPanel;
604         }
605     }
606
607     /**
608      * Panel containing a text area for editing plain text. Used for editing
609      * not internationalized strings - replacing the I18nPanel.
610      */

611     private static class StringPanel extends JPanel {
612         private JTextArea textArea;
613
614         private StringPanel() {
615             textArea = new JTextArea();
616             JScrollPane scroll = new JScrollPane(textArea);
617             GroupLayout layout = new GroupLayout(this);
618             layout.setAutocreateContainerGaps(true);
619             setLayout(layout);
620             layout.setHorizontalGroup(layout.createSequentialGroup().add(scroll));
621             layout.setVerticalGroup(layout.createSequentialGroup().add(scroll));
622         }
623
624         String JavaDoc getString() {
625             return textArea.getText();
626         }
627
628         void setString(String JavaDoc str) {
629             textArea.setText(str);
630         }
631     }
632
633 }
634
Popular Tags