KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > j2seproject > ui > customizer > PlatformUiSupport


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 package org.netbeans.modules.java.j2seproject.ui.customizer;
21
22 import java.awt.Color JavaDoc;
23 import java.awt.Component JavaDoc;
24 import java.beans.PropertyChangeEvent JavaDoc;
25 import java.beans.PropertyChangeListener JavaDoc;
26 import java.text.MessageFormat JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.Arrays JavaDoc;
29 import java.util.List JavaDoc;
30 import java.util.Set JavaDoc;
31 import java.util.TreeSet JavaDoc;
32 import javax.swing.AbstractListModel JavaDoc;
33 import javax.swing.ComboBoxModel JavaDoc;
34 import javax.swing.DefaultComboBoxModel JavaDoc;
35 import javax.swing.JButton JavaDoc;
36 import javax.swing.JList JavaDoc;
37 import javax.swing.ListCellRenderer JavaDoc;
38 import javax.swing.event.ListDataEvent JavaDoc;
39 import javax.swing.event.ListDataListener JavaDoc;
40 import org.netbeans.api.java.platform.JavaPlatform;
41 import org.netbeans.api.java.platform.JavaPlatformManager;
42 import org.netbeans.api.java.platform.Specification;
43 import org.netbeans.modules.java.j2seproject.J2SEProjectType;
44 import org.netbeans.modules.java.j2seproject.UpdateHelper;
45 import org.netbeans.spi.project.support.ant.EditableProperties;
46 import org.openide.DialogDisplayer;
47 import org.openide.ErrorManager;
48 import org.openide.NotifyDescriptor;
49 import org.openide.awt.HtmlRenderer;
50 import org.openide.modules.SpecificationVersion;
51 import org.openide.util.NbBundle;
52 import org.openide.util.WeakListeners;
53 import org.w3c.dom.Element JavaDoc;
54 import org.w3c.dom.NodeList JavaDoc;
55
56 /**
57  * Support class for {@link JavaPlatform} manipulation in j2seproject customizer.
58  * @author tzezula
59  */

60 public class PlatformUiSupport {
61     
62     
63     private PlatformUiSupport() {
64     }
65     
66     /**
67      * Creates {@link ComboBoxModel} of J2SE platforms.
68      * The model listens on the {@link JavaPlatformManager} and update its
69      * state according to changes
70      * @param activePlatform the active project's platform
71      * @return {@link ComboBoxModel}
72      */

73     public static ComboBoxModel JavaDoc createPlatformComboBoxModel (String JavaDoc activePlatform) {
74         return new PlatformComboBoxModel (activePlatform);
75     }
76     
77     
78     /**
79      * Creates a {@link ListCellRenderer} for rendering items of the {@link ComboBoxModel}
80      * created by the {@link PlatformUiSupport#createPlatformComboBoxModel} method.
81      * @return {@link ListCellRenderer}
82      */

83     public static ListCellRenderer JavaDoc createPlatformListCellRenderer () {
84         return new PlatformListCellRenderer ();
85     }
86        
87     /**
88      * Stores active platform, javac.source and javac.target into the project's metadata
89      * @param props project's shared properties
90      * @param helper to read/update project.xml
91      * @param platformKey the PatformKey got from the platform model
92      * @param sourceLevel source level
93      */

94     public static void storePlatform (EditableProperties props, UpdateHelper helper, Object JavaDoc platformKey, Object JavaDoc sourceLevelKey) {
95         assert platformKey instanceof PlatformKey;
96         PlatformKey pk = (PlatformKey) platformKey;
97         JavaPlatform platform = getPlatform(pk);
98         //null means active broken (unresolved) platform, no need to do anything
99
if (platform != null) {
100             SpecificationVersion jdk13 = new SpecificationVersion ("1.3"); //NOI18N
101
String JavaDoc platformAntName = (String JavaDoc) platform.getProperties().get("platform.ant.name"); //NOI18N
102
assert platformAntName != null;
103             props.put(J2SEProjectProperties.JAVA_PLATFORM, platformAntName);
104             Element JavaDoc root = helper.getPrimaryConfigurationData(true);
105             boolean defaultPlatform = pk.isDefaultPlatform();
106             boolean changed = false;
107             NodeList JavaDoc explicitPlatformNodes = root.getElementsByTagNameNS (J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE,"explicit-platform"); //NOI18N
108
if (defaultPlatform) {
109                 if (explicitPlatformNodes.getLength()==1) {
110                     root.removeChild(explicitPlatformNodes.item(0));
111                     changed = true;
112                 }
113             }
114             else {
115                 Element JavaDoc explicitPlatform;
116                 switch (explicitPlatformNodes.getLength()) {
117                     case 0:
118                         explicitPlatform = root.getOwnerDocument().createElementNS(J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE, "explicit-platform"); //NOI18N
119
NodeList JavaDoc sourceRootNodes = root.getElementsByTagNameNS (J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots"); //NOI18N
120
assert sourceRootNodes.getLength() == 1 : "Broken project.xml file"; //NOI18N
121
root.insertBefore(explicitPlatform, sourceRootNodes.item(0));
122                         changed = true;
123                         break;
124                     case 1:
125                         explicitPlatform = (Element JavaDoc)explicitPlatformNodes.item(0);
126                         break;
127                     default:
128                         throw new AssertionError JavaDoc("Broken project.xml file"); //NOI18N
129
}
130                 String JavaDoc explicitSourceAttrValue = explicitPlatform.getAttribute("explicit-source-supported"); //NOI18N
131
if (jdk13.compareTo(platform.getSpecification().getVersion())>=0 &&
132                     !"false".equals(explicitSourceAttrValue)) { //NOI18N
133
explicitPlatform.setAttribute("explicit-source-supported","false"); //NOI18N
134
changed = true;
135                 }
136                 else if (jdk13.compareTo(platform.getSpecification().getVersion())<0 &&
137                     !"true".equals(explicitSourceAttrValue)) { //NOI18N
138
explicitPlatform.setAttribute("explicit-source-supported","true"); //NOI18N
139
changed = true;
140                 }
141             }
142             
143             SpecificationVersion sourceLevel;
144             if (sourceLevelKey == null) {
145                 sourceLevel = platform.getSpecification().getVersion();
146             }
147             else {
148                 assert sourceLevelKey instanceof SourceLevelKey;
149                 sourceLevel = ((SourceLevelKey)sourceLevelKey).getSourceLevel();
150             }
151             String JavaDoc javacSource = sourceLevel.toString();
152             String JavaDoc javacTarget = jdk13.compareTo(sourceLevel)>=0 ? "1.1" : javacSource; //NOI18N
153
if (!javacSource.equals(props.getProperty(J2SEProjectProperties.JAVAC_SOURCE))) {
154                 props.setProperty (J2SEProjectProperties.JAVAC_SOURCE, javacSource);
155             }
156             if (!javacTarget.equals(props.getProperty(J2SEProjectProperties.JAVAC_TARGET))) {
157                 props.setProperty (J2SEProjectProperties.JAVAC_TARGET, javacTarget);
158             }
159                         
160             if (changed) {
161                 helper.putPrimaryConfigurationData(root, true);
162             }
163         }
164     }
165     
166     
167     /**
168      * Returns a {@link JavaPlatform} for an item obtained from the ComboBoxModel created by
169      * the {@link PlatformUiSupport#createComboBoxModel} method
170      * @param platformKey an item obtained from ComboBoxModel created by {@link PlatformUiSupport#createComboBoxModel}
171      * @return JavaPlatform or null in case when platform is broken
172      * @exception {@link IllegalArgumentException} is thrown in case when parameter in not an object created by
173      * platform combobox model.
174      */

175     public static JavaPlatform getPlatform (Object JavaDoc platformKey) {
176        if (platformKey instanceof PlatformKey) {
177            return getPlatform ((PlatformKey)platformKey);
178        }
179        else {
180            throw new IllegalArgumentException JavaDoc ();
181        }
182     }
183     
184     /**
185      * Creates {@link ComboBoxModel} of source levels for active platform.
186      * The model listens on the platform's {@link ComboBoxModel} and update its
187      * state according to changes
188      * @param platformComboBoxModel the platform's model used for listenning
189      * @param initialValue initial source level value
190      * @return {@link ComboBoxModel} of {@link SpecificationVersion}
191      */

192     public static ComboBoxModel JavaDoc createSourceLevelComboBoxModel (ComboBoxModel JavaDoc platformComboBoxModel, String JavaDoc initialValue) {
193         return new SourceLevelComboBoxModel (platformComboBoxModel, initialValue);
194     }
195     
196     
197     public static ListCellRenderer JavaDoc createSourceLevelListCellRenderer () {
198         return new SourceLevelListCellRenderer ();
199     }
200     
201     
202     private static JavaPlatform getPlatform (PlatformKey platformKey) {
203         return platformKey.platform;
204     }
205     
206     
207     /**
208      * This class represents a JavaPlatform in the {@link ListModel}
209      * created by the {@link PlatformUiSupport#createPlatformComboBoxModel}
210      * method.
211      */

212     private static class PlatformKey implements Comparable JavaDoc {
213         
214         private String JavaDoc name;
215         private JavaPlatform platform;
216         
217         /**
218          * Creates a PlatformKey for a broken platform
219          * @param name the ant name of the broken platform
220          */

221         public PlatformKey (String JavaDoc name) {
222             assert name != null;
223             this.name = name;
224         }
225         
226         /**
227          * Creates a PlatformKey for a platform
228          * @param platform the {@link JavaPlatform}
229          */

230         public PlatformKey (JavaPlatform platform) {
231             assert platform != null;
232             this.platform = platform;
233         }
234
235         public int compareTo(Object JavaDoc o) {
236             return this.getDisplayName().compareTo(((PlatformKey)o).getDisplayName());
237         }
238         
239         public boolean equals (Object JavaDoc other) {
240             if (other instanceof PlatformKey) {
241                 PlatformKey otherKey = (PlatformKey)other;
242                 return (this.platform == null ? otherKey.platform == null : this.platform.equals(otherKey.platform)) &&
243                        otherKey.getDisplayName().equals (this.getDisplayName());
244             }
245             else {
246                 return false;
247             }
248         }
249         
250         public int hashCode () {
251             return getDisplayName ().hashCode ();
252         }
253         
254         public String JavaDoc toString () {
255             return getDisplayName ();
256         }
257         
258         public synchronized String JavaDoc getDisplayName () {
259             if (this.name == null) {
260                 this.name = this.platform.getDisplayName();
261             }
262             return this.name;
263         }
264         
265         public boolean isDefaultPlatform () {
266             if (this.platform == null) {
267                 return false;
268             }
269             return this.platform.equals(JavaPlatformManager.getDefault().getDefaultPlatform());
270         }
271         
272         public boolean isBroken () {
273             return this.platform == null;
274         }
275         
276     }
277     
278     private static final class SourceLevelKey implements Comparable JavaDoc {
279         
280         final SpecificationVersion sourceLevel;
281         final boolean broken;
282         
283         public SourceLevelKey (final SpecificationVersion sourceLevel) {
284             this (sourceLevel, false);
285         }
286         
287         public SourceLevelKey (final SpecificationVersion sourceLevel, final boolean broken) {
288             assert sourceLevel != null : "Source level cannot be null"; //NOI18N
289
this.sourceLevel = sourceLevel;
290             this.broken = broken;
291         }
292         
293         public SpecificationVersion getSourceLevel () {
294             return this.sourceLevel;
295         }
296         
297         public boolean isBroken () {
298             return this.broken;
299         }
300         
301         public int compareTo (final Object JavaDoc other) {
302             assert other instanceof SourceLevelKey : "Illegal argument of SourceLevelKey.compareTo()"; //NOI18N
303
SourceLevelKey otherKey = (SourceLevelKey) other;
304             return this.sourceLevel.compareTo(otherKey.sourceLevel);
305         }
306         
307         public /*@Override*/ boolean equals (final Object JavaDoc other) {
308             return (other instanceof SourceLevelKey) &&
309                    ((SourceLevelKey)other).sourceLevel.equals(this.sourceLevel);
310         }
311         
312         public /*@Override*/ int hashCode () {
313             return this.sourceLevel.hashCode();
314         }
315         
316         public /*@Override*/ String JavaDoc toString () {
317             StringBuffer JavaDoc buffer = new StringBuffer JavaDoc ();
318             if (this.broken) {
319                 buffer.append("Broken: "); //NOI18N
320
}
321             buffer.append(this.sourceLevel.toString());
322             return buffer.toString();
323         }
324         
325     }
326     
327     private static class PlatformComboBoxModel extends AbstractListModel JavaDoc implements ComboBoxModel JavaDoc, PropertyChangeListener JavaDoc {
328         
329         private JavaPlatformManager pm;
330         private PlatformKey[] platformNamesCache;
331         private String JavaDoc initialPlatform;
332         private PlatformKey selectedPlatform;
333         
334         public PlatformComboBoxModel (String JavaDoc initialPlatform) {
335             this.pm = JavaPlatformManager.getDefault();
336             this.pm.addPropertyChangeListener(WeakListeners.propertyChange(this, this.pm));
337             this.initialPlatform = initialPlatform;
338         }
339         
340         public int getSize () {
341             PlatformKey[] platformNames = getPlatformNames ();
342             return platformNames.length;
343         }
344         
345         public Object JavaDoc getElementAt (int index) {
346             PlatformKey[] platformNames = getPlatformNames ();
347             assert index >=0 && index< platformNames.length;
348             return platformNames[index];
349         }
350         
351         public Object JavaDoc getSelectedItem () {
352             this.getPlatformNames(); //Force setting of selectedPlatform if it is not alredy done
353
return this.selectedPlatform;
354         }
355         
356         public void setSelectedItem (Object JavaDoc obj) {
357             this.selectedPlatform = (PlatformKey) obj;
358             this.fireContentsChanged(this, -1, -1);
359         }
360         
361         public void propertyChange (PropertyChangeEvent JavaDoc event) {
362             if (JavaPlatformManager.PROP_INSTALLED_PLATFORMS.equals(event.getPropertyName())) {
363                 synchronized (this) {
364                     this.platformNamesCache = null;
365                 }
366                 this.fireContentsChanged(this, -1, -1);
367             }
368         }
369         
370         private synchronized PlatformKey[] getPlatformNames () {
371             if (this.platformNamesCache == null) {
372                 JavaPlatform[] platforms = pm.getPlatforms (null, new Specification("j2se",null)); //NOI18N
373
JavaPlatform defaultPlatform = pm.getDefaultPlatform ();
374                 Set JavaDoc/*<PlatformKey>*/ orderedNames = new TreeSet JavaDoc ();
375                 boolean activeFound = false;
376                 for (int i=0; i< platforms.length; i++) {
377                     if (platforms[i].getInstallFolders().size()>0) {
378                         PlatformKey pk = new PlatformKey(platforms[i]);
379                         orderedNames.add (pk);
380                         if (!activeFound && initialPlatform != null) {
381                             String JavaDoc antName = (String JavaDoc) platforms[i].getProperties().get("platform.ant.name"); //NOI18N
382
if (initialPlatform.equals(antName)) {
383                                 if (this.selectedPlatform == null) {
384                                     this.selectedPlatform = pk;
385                                     initialPlatform = null;
386                                 }
387                                 activeFound = true;
388                             }
389                         }
390                     }
391                 }
392                 if (!activeFound) {
393                     if (initialPlatform == null) {
394                         if (this.selectedPlatform == null || !orderedNames.contains(this.selectedPlatform)) {
395                             this.selectedPlatform = new PlatformKey (JavaPlatformManager.getDefault().getDefaultPlatform());
396                         }
397                     }
398                     else {
399                         PlatformKey pk = new PlatformKey (this.initialPlatform);
400                         orderedNames.add (pk);
401                         if (this.selectedPlatform == null) {
402                             this.selectedPlatform = pk;
403                         }
404                     }
405                 }
406                 this.platformNamesCache = (PlatformKey[]) orderedNames.toArray(new PlatformKey[orderedNames.size()]);
407             }
408             return this.platformNamesCache;
409         }
410         
411     }
412     
413     private static class PlatformListCellRenderer implements ListCellRenderer JavaDoc {
414         
415         private ListCellRenderer JavaDoc delegate;
416         
417         public PlatformListCellRenderer () {
418             this.delegate = HtmlRenderer.createRenderer ();
419         }
420
421         public Component JavaDoc getListCellRendererComponent(JList JavaDoc list, Object JavaDoc value, int index, boolean isSelected, boolean cellHasFocus) {
422             String JavaDoc name;
423             if (value == null) {
424                 name = ""; //NOI18N
425
}
426             else {
427                 assert value instanceof PlatformKey : "Wrong model"; //NOI18N
428
PlatformKey key = (PlatformKey) value;
429                 if (key.isBroken()) {
430                     name = "<html><font color=\"#A40000\">" + //NOI18N
431
NbBundle.getMessage (PlatformUiSupport.class,"TXT_BrokenPlatformFmt", key.getDisplayName());
432                 }
433                 else {
434                     name = key.getDisplayName();
435                 }
436             }
437             return this.delegate.getListCellRendererComponent(list, name, index, isSelected, cellHasFocus);
438         }
439     }
440     
441     private static class SourceLevelComboBoxModel extends AbstractListModel JavaDoc implements ComboBoxModel JavaDoc, ListDataListener JavaDoc {
442         
443         private static final String JavaDoc VERSION_PREFIX = "1."; //The version prefix
444
private static final int INITIAL_VERSION_MINOR = 2; //1.2
445

446         private SpecificationVersion selectedSourceLevel;
447         private SpecificationVersion originalSourceLevel;
448         private SourceLevelKey[] sourceLevelCache;
449         private final ComboBoxModel JavaDoc platformComboBoxModel;
450         private PlatformKey activePlatform;
451         
452         public SourceLevelComboBoxModel (ComboBoxModel JavaDoc platformComboBoxModel, String JavaDoc initialValue) {
453             this.platformComboBoxModel = platformComboBoxModel;
454             this.activePlatform = (PlatformKey) this.platformComboBoxModel.getSelectedItem();
455             this.platformComboBoxModel.addListDataListener (this);
456             if (initialValue != null && initialValue.length()>0) {
457                 try {
458                     this.originalSourceLevel = this.selectedSourceLevel = new SpecificationVersion (initialValue);
459                 } catch (NumberFormatException JavaDoc nfe) {
460                     //If the javac.source has invalid value, do not preselect and log it
461
ErrorManager.getDefault().log("Invalid javac.source: "+initialValue);
462                 }
463             }
464         }
465                 
466         public int getSize () {
467             SourceLevelKey[] sLevels = getSourceLevels ();
468             return sLevels.length;
469         }
470         
471         public Object JavaDoc getElementAt (int index) {
472             SourceLevelKey[] sLevels = getSourceLevels ();
473             assert index >=0 && index< sLevels.length;
474             return sLevels[index];
475         }
476         
477         public Object JavaDoc getSelectedItem () {
478             SourceLevelKey[] keys = getSourceLevels ();
479             for (int i=0; i<keys.length; i++) {
480                 if (keys[i].getSourceLevel().equals(this.selectedSourceLevel)) {
481                     return keys[i];
482                 }
483             }
484             return null;
485         }
486         
487         public void setSelectedItem (Object JavaDoc obj) {
488             this.selectedSourceLevel = (obj == null ? null : ((SourceLevelKey)obj).getSourceLevel());
489             this.fireContentsChanged(this, -1, -1);
490         }
491         
492         public void intervalAdded(ListDataEvent JavaDoc e) {
493         }
494
495         public void intervalRemoved(ListDataEvent JavaDoc e) {
496         }
497
498         public void contentsChanged(ListDataEvent JavaDoc e) {
499             PlatformKey selectedPlatform = (PlatformKey) this.platformComboBoxModel.getSelectedItem();
500             JavaPlatform platform = getPlatform(selectedPlatform);
501             if (platform != null) {
502                 SpecificationVersion version = platform.getSpecification().getVersion();
503                 if (this.selectedSourceLevel != null && this.selectedSourceLevel.compareTo(version)>0 &&
504                     !shouldChangePlatform (selectedSourceLevel, version)) {
505                     //Restore original
506
this.platformComboBoxModel.setSelectedItem(this.activePlatform);
507                    return;
508                 }
509                 else {
510                     this.originalSourceLevel = null;
511                 }
512             }
513             this.activePlatform = selectedPlatform;
514             resetCache ();
515         }
516         
517         private void resetCache () {
518             synchronized (this) {
519                 this.sourceLevelCache = null;
520             }
521             this.fireContentsChanged(this, -1, -1);
522         }
523         
524         private SourceLevelKey[] getSourceLevels () {
525             if (this.sourceLevelCache == null) {
526                 PlatformKey selectedPlatform = (PlatformKey) this.platformComboBoxModel.getSelectedItem();
527                 JavaPlatform platform = getPlatform(selectedPlatform);
528                 List JavaDoc/*<SpecificationVersion>*/ sLevels = new ArrayList JavaDoc ();
529                 //If platform == null broken platform, the source level range is unknown
530
//The source level combo box should be empty and disabled
531
boolean selSourceLevelValid = false;
532                 if (platform != null) {
533                     SpecificationVersion version = platform.getSpecification().getVersion();
534                     int index = INITIAL_VERSION_MINOR;
535                     SpecificationVersion template = new SpecificationVersion (VERSION_PREFIX + Integer.toString (index++));
536                     boolean origSourceLevelValid = false;
537                     
538                     while (template.compareTo(version)<=0) {
539                         if (template.equals(this.originalSourceLevel)) {
540                             origSourceLevelValid = true;
541                         }
542                         if (template.equals(this.selectedSourceLevel)) {
543                             selSourceLevelValid = true;
544                         }
545                         sLevels.add (new SourceLevelKey (template));
546                         template = new SpecificationVersion (VERSION_PREFIX + Integer.toString (index++));
547                     }
548                     if (this.originalSourceLevel != null && !origSourceLevelValid) {
549                         if (originalSourceLevel.equals(this.selectedSourceLevel)) {
550                             selSourceLevelValid = true;
551                         }
552                         sLevels.add (new SourceLevelKey(this.originalSourceLevel,true));
553                     }
554                 }
555                 this.sourceLevelCache = (SourceLevelKey[]) sLevels.toArray(new SourceLevelKey[sLevels.size()]);
556                 if (!selSourceLevelValid) {
557                     this.selectedSourceLevel = this.sourceLevelCache.length == 0 ?
558                         null : this.sourceLevelCache[this.sourceLevelCache.length-1].getSourceLevel();
559                 }
560             }
561             return this.sourceLevelCache;
562         }
563         
564         private static boolean shouldChangePlatform (SpecificationVersion selectedSourceLevel, SpecificationVersion platformSourceLevel) {
565             JButton JavaDoc changeOption = new JButton JavaDoc (NbBundle.getMessage(PlatformUiSupport.class, "CTL_ChangePlatform"));
566             changeOption.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(PlatformUiSupport.class, "AD_ChangePlatform"));
567             String JavaDoc message = MessageFormat.format (NbBundle.getMessage(PlatformUiSupport.class,"TXT_ChangePlatform"),new Object JavaDoc[] {
568                 selectedSourceLevel.toString(),
569                 platformSourceLevel.toString(),
570             });
571             return DialogDisplayer.getDefault().notify(
572                 new NotifyDescriptor (message,
573                         NbBundle.getMessage(PlatformUiSupport.class,"TXT_ChangePlatformTitle"),
574                         NotifyDescriptor.DEFAULT_OPTION,
575                         NotifyDescriptor.WARNING_MESSAGE,
576                         new Object JavaDoc[] {
577                             changeOption,
578                             NotifyDescriptor.CANCEL_OPTION
579                         },
580                         changeOption)) == changeOption;
581         }
582     }
583     
584     private static class SourceLevelListCellRenderer implements ListCellRenderer JavaDoc {
585         
586         ListCellRenderer JavaDoc delegate;
587         
588         public SourceLevelListCellRenderer () {
589             this.delegate = HtmlRenderer.createRenderer();
590         }
591         
592         public Component JavaDoc getListCellRendererComponent(JList JavaDoc list, Object JavaDoc value, int index, boolean isSelected, boolean cellHasFocus) {
593             String JavaDoc message;
594             if (value == null) {
595                 message = ""; //NOI18N
596
}
597             else {
598                 assert value instanceof SourceLevelKey;
599                 SourceLevelKey key = (SourceLevelKey) value;
600                 if (key.isBroken()) {
601                     message = "<html><font color=\"#A40000\">" + //NOI18N
602
NbBundle.getMessage(PlatformUiSupport.class,"TXT_InvalidSourceLevel",key.getSourceLevel().toString());
603                 }
604                 else {
605                     message = key.getSourceLevel().toString();
606                 }
607             }
608             return this.delegate.getListCellRendererComponent(list, message, index, isSelected, cellHasFocus);
609         }
610     }
611     
612 }
613
Popular Tags