2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.j2ee.ejbjarproject.ui.customizer;
44
import java.awt.Component;
45
import java.beans.PropertyChangeEvent;
46
import java.beans.PropertyChangeListener;
47
import java.text.MessageFormat;
48
import java.util.ArrayList;
49
import java.util.List;
51
import java.util.TreeSet;
52
import java.util.logging.Level;
53
import java.util.logging.Logger;
54
import javax.swing.AbstractListModel;
55
import javax.swing.ComboBoxModel;
56
import javax.swing.DefaultListCellRenderer;
57
import javax.swing.JButton;
58
import javax.swing.JList;
59
import javax.swing.ListCellRenderer;
60
import javax.swing.event.ListDataEvent;
61
import javax.swing.event.ListDataListener;
62
import org.netbeans.api.java.platform.JavaPlatform;
63
import org.netbeans.api.java.platform.JavaPlatformManager;
64
import org.netbeans.api.java.platform.Specification;
65
import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProjectType;
66
import org.netbeans.modules.j2ee.ejbjarproject.UpdateHelper;
67
import org.netbeans.spi.project.support.ant.EditableProperties;
68
import org.openide.DialogDisplayer;
69
import org.openide.NotifyDescriptor;
70
import org.openide.awt.HtmlRenderer;
71
import org.openide.modules.SpecificationVersion;
72
import org.openide.util.NbBundle;
73
import org.openide.util.WeakListeners;
74
import org.w3c.dom.Element;
75
import org.w3c.dom.NodeList;
78
* Support class for {@link JavaPlatform} manipulation in ejbjarproject customizer.
81
public class PlatformUiSupport {
83
private static final SpecificationVersion JDK_5 = new SpecificationVersion ("1.5"); //NOI18N
84
private static final SpecificationVersion JDK_6 = new SpecificationVersion ("1.6"); //NOI18N
85
private static final Logger LOGGER = Logger.getLogger(PlatformUiSupport.class.getName());
87
private PlatformUiSupport() {
91
* Creates {@link ComboBoxModel} of J2SE platforms.
92
* The model listens on the {@link JavaPlatformManager} and update its
93
* state according to changes
94
* @param activePlatform the active project's platform
95
* @return {@link ComboBoxModel}
97
public static ComboBoxModel createPlatformComboBoxModel (String activePlatform) {
98
return new PlatformComboBoxModel (activePlatform);
102
* Creates a {@link ListCellRenderer} for rendering items of the {@link ComboBoxModel}
103
* created by the {@link PlatformUiSupport#createPlatformComboBoxModel} method.
104
* @return {@link ListCellRenderer}
106
public static ListCellRenderer createPlatformListCellRenderer () {
107
return new PlatformListCellRenderer ();
111
* Like {@link #storePlatform}, but platformName may be null (in which case the default platform is used)
113
public static void storePlatform (EditableProperties props, UpdateHelper helper, String platformName, SpecificationVersion sourceLevel) {
114
PlatformKey platformKey;
115
if (platformName != null) {
116
platformKey = new PlatformKey(PlatformUiSupport.findPlatform(platformName));
118
platformKey = new PlatformKey(JavaPlatformManager.getDefault().getDefaultPlatform());
120
storePlatform(props, helper, platformKey, sourceLevel == null ? null : new SourceLevelKey(sourceLevel));
124
* Stores active platform, javac.source and javac.target into the project's metadata
125
* @param props project's shared properties
126
* @param helper to read/update project.xml
127
* @param platformKey the PatformKey got from the platform model
128
* @param sourceLevel source level
130
public static void storePlatform (EditableProperties props, UpdateHelper helper, Object platformKey, Object sourceLevelKey) {
131
assert platformKey instanceof PlatformKey;
132
PlatformKey pk = (PlatformKey) platformKey;
133
JavaPlatform platform = getPlatform(pk);
134
//null means active broken (unresolved) platform, no need to do anything
135
if (platform != null) {
136
SpecificationVersion jdk13 = new SpecificationVersion ("1.3"); //NOI18N
137
String platformAntName = platform.getProperties().get("platform.ant.name"); //NOI18N
138
assert platformAntName != null;
139
props.put(EjbJarProjectProperties.JAVA_PLATFORM, platformAntName);
140
Element root = helper.getPrimaryConfigurationData(true);
141
boolean defaultPlatform = pk.isDefaultPlatform();
142
boolean changed = false;
143
NodeList explicitPlatformNodes = root.getElementsByTagNameNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"explicit-platform"); //NOI18N
144
if (defaultPlatform) {
145
if (explicitPlatformNodes.getLength()==1) {
146
root.removeChild(explicitPlatformNodes.item(0));
151
Element explicitPlatform;
152
switch (explicitPlatformNodes.getLength()) {
154
explicitPlatform = root.getOwnerDocument().createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, "explicit-platform"); //NOI18N
155
NodeList sourceRootNodes = root.getElementsByTagNameNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots"); //NOI18N
156
assert sourceRootNodes.getLength() == 1 : "Broken project.xml file"; //NOI18N
157
root.insertBefore(explicitPlatform, sourceRootNodes.item(0));
161
explicitPlatform = (Element)explicitPlatformNodes.item(0);
164
throw new AssertionError("Broken project.xml file"); //NOI18N
166
String explicitSourceAttrValue = explicitPlatform.getAttribute("explicit-source-supported"); //NOI18N
167
if (jdk13.compareTo(platform.getSpecification().getVersion())>=0 &&
168
!"false".equals(explicitSourceAttrValue)) { //NOI18N
169
explicitPlatform.setAttribute("explicit-source-supported","false"); //NOI18N
172
else if (jdk13.compareTo(platform.getSpecification().getVersion())<0 &&
173
!"true".equals(explicitSourceAttrValue)) { //NOI18N
174
explicitPlatform.setAttribute("explicit-source-supported","true"); //NOI18N
179
SpecificationVersion sourceLevel;
180
if (sourceLevelKey == null) {
181
sourceLevel = platform.getSpecification().getVersion();
184
assert sourceLevelKey instanceof SourceLevelKey;
185
sourceLevel = ((SourceLevelKey)sourceLevelKey).getSourceLevel();
187
String javacSource = sourceLevel.toString();
188
String javacTarget = javacSource;
191
// Customizer value | -source | -targer
197
// JDK 7 1.7 1.7 - should bring a new language features
198
if (jdk13.compareTo(sourceLevel)>=0) {
199
javacTarget = "1.1"; //NOI18N
201
else if (JDK_6.equals(sourceLevel)) {
202
javacSource = JDK_5.toString(); //NOI18N
205
// #89131: these levels are not actually distinct from 1.5.
206
if (javacSource.equals("1.6") || javacSource.equals("1.7")) {
209
if (!javacSource.equals(props.getProperty(EjbJarProjectProperties.JAVAC_SOURCE))) {
210
props.setProperty (EjbJarProjectProperties.JAVAC_SOURCE, javacSource);
212
if (!javacTarget.equals(props.getProperty(EjbJarProjectProperties.JAVAC_TARGET))) {
213
props.setProperty (EjbJarProjectProperties.JAVAC_TARGET, javacTarget);
217
helper.putPrimaryConfigurationData(root, true);
222
public static JavaPlatform findPlatform(String displayName) {
223
JavaPlatform[] platforms = JavaPlatformManager.getDefault().getPlatforms(displayName, new Specification("j2se", null)); //NOI18N
224
return platforms.length == 0 ? null : platforms[0];
229
* Returns a {@link JavaPlatform} for an item obtained from the ComboBoxModel created by
230
* the {@link PlatformUiSupport#createComboBoxModel} method
231
* @param platformKey an item obtained from ComboBoxModel created by {@link PlatformUiSupport#createComboBoxModel}
232
* @return JavaPlatform or null in case when platform is broken
233
* @exception {@link IllegalArgumentException} is thrown in case when parameter in not an object created by
234
* platform combobox model.
236
public static JavaPlatform getPlatform (Object platformKey) {
237
if (platformKey instanceof PlatformKey) {
238
return getPlatform ((PlatformKey)platformKey);
241
throw new IllegalArgumentException ();
246
* Creates {@link ComboBoxModel} of source levels for active platform.
247
* The model listens on the platform's {@link ComboBoxModel} and update its
248
* state according to changes
249
* @param platformComboBoxModel the platform's model used for listenning
250
* @param initialSourceLevel initial source level value
251
* @param initialTargetLevel initial target level value
252
* @return {@link ComboBoxModel} of {@link SpecificationVersion}
254
public static ComboBoxModel createSourceLevelComboBoxModel(ComboBoxModel platformComboBoxModel, String initialSourceLevel, String initialTargetLevel, String j2eePlatform) {
255
return new SourceLevelComboBoxModel(platformComboBoxModel, initialSourceLevel, initialTargetLevel, j2eePlatform);
258
public static ListCellRenderer createSourceLevelListCellRenderer() {
259
return new SourceLevelListCellRenderer();
262
private static JavaPlatform getPlatform (PlatformKey platformKey) {
263
return platformKey.platform;
267
* This class represents a JavaPlatform in the {@link ListModel}
268
* created by the {@link PlatformUiSupport#createPlatformComboBoxModel}
271
private static class PlatformKey implements Comparable {
274
private JavaPlatform platform;
277
* Creates a PlatformKey for a broken platform
278
* @param name the ant name of the broken platform
280
public PlatformKey (String name) {
286
* Creates a PlatformKey for a platform
287
* @param platform the {@link JavaPlatform}
289
public PlatformKey (JavaPlatform platform) {
290
assert platform != null;
291
this.platform = platform;
294
public int compareTo(Object o) {
295
return this.getDisplayName().compareTo(((PlatformKey)o).getDisplayName());
298
public boolean equals (Object other) {
299
if (other instanceof PlatformKey) {
300
PlatformKey otherKey = (PlatformKey)other;
301
return (this.platform == null ? otherKey.platform == null : this.platform.equals(otherKey.platform)) &&
302
otherKey.getDisplayName().equals (this.getDisplayName());
309
public int hashCode () {
310
return getDisplayName ().hashCode ();
313
public String toString () {
314
return getDisplayName ();
317
public synchronized String getDisplayName () {
318
if (this.name == null) {
319
this.name = this.platform.getDisplayName();
324
public boolean isDefaultPlatform () {
325
if (this.platform == null) {
328
return this.platform.equals(JavaPlatformManager.getDefault().getDefaultPlatform());
331
public boolean isBroken () {
332
return this.platform == null;
336
private static final class SourceLevelKey implements Comparable {
338
final SpecificationVersion sourceLevel;
339
final boolean broken;
341
public SourceLevelKey (final SpecificationVersion sourceLevel) {
342
this (sourceLevel, false);
345
public SourceLevelKey (final SpecificationVersion sourceLevel, final boolean broken) {
346
assert sourceLevel != null : "Source level cannot be null"; //NOI18N
347
this.sourceLevel = sourceLevel;
348
this.broken = broken;
351
public SpecificationVersion getSourceLevel () {
352
return this.sourceLevel;
355
public boolean isBroken () {
359
public int compareTo (final Object other) {
360
assert other instanceof SourceLevelKey : "Illegal argument of SourceLevelKey.compareTo()"; //NOI18N
361
SourceLevelKey otherKey = (SourceLevelKey) other;
362
return this.sourceLevel.compareTo(otherKey.sourceLevel);
365
public @Override boolean equals (final Object other) {
366
return (other instanceof SourceLevelKey) &&
367
((SourceLevelKey)other).sourceLevel.equals(this.sourceLevel);
370
public @Override int hashCode () {
371
return this.sourceLevel.hashCode();
374
public @Override String toString () {
375
StringBuffer buffer = new StringBuffer ();
377
buffer.append("Broken: "); //NOI18N
379
buffer.append(this.sourceLevel.toString());
380
return buffer.toString();
383
public String getDisplayName () {
384
String _tmp = sourceLevel.toString();
385
if (JDK_5.compareTo(sourceLevel)<=0) {
386
_tmp = _tmp.replaceFirst("^1\\.([5-9]|\\d\\d+)$", "$1"); //NOI18N
388
return NbBundle.getMessage(PlatformUiSupport.class, "LBL_JDK",_tmp);
393
private static class PlatformComboBoxModel extends AbstractListModel implements ComboBoxModel, PropertyChangeListener {
395
private final JavaPlatformManager pm;
396
private PlatformKey[] platformNamesCache;
397
private String initialPlatform;
398
private PlatformKey selectedPlatform;
400
public PlatformComboBoxModel (String initialPlatform) {
401
this.pm = JavaPlatformManager.getDefault();
402
this.pm.addPropertyChangeListener(WeakListeners.propertyChange(this, this.pm));
403
this.initialPlatform = initialPlatform;
406
public int getSize () {
407
PlatformKey[] platformNames = getPlatformNames ();
408
return platformNames.length;
411
public Object getElementAt (int index) {
412
PlatformKey[] platformNames = getPlatformNames ();
413
assert index >=0 && index< platformNames.length;
414
return platformNames[index];
417
public Object getSelectedItem () {
418
this.getPlatformNames(); //Force setting of selectedPlatform if it is not alredy done
419
return this.selectedPlatform;
422
public void setSelectedItem (Object obj) {
423
this.selectedPlatform = (PlatformKey) obj;
424
this.fireContentsChanged(this, -1, -1);
427
public void propertyChange (PropertyChangeEvent event) {
428
if (JavaPlatformManager.PROP_INSTALLED_PLATFORMS.equals(event.getPropertyName())) {
429
synchronized (this) {
430
this.platformNamesCache = null;
432
this.fireContentsChanged(this, -1, -1);
436
private synchronized PlatformKey[] getPlatformNames () {
437
if (this.platformNamesCache == null) {
438
JavaPlatform[] platforms = pm.getPlatforms (null, new Specification("j2se",null)); //NOI18N
439
Set/*<PlatformKey>*/ orderedNames = new TreeSet ();
440
boolean activeFound = false;
441
for (int i=0; i< platforms.length; i++) {
442
if (platforms[i].getInstallFolders().size()>0) {
443
PlatformKey pk = new PlatformKey(platforms[i]);
444
orderedNames.add (pk);
445
if (!activeFound && initialPlatform != null) {
446
String antName = (String) platforms[i].getProperties().get("platform.ant.name"); //NOI18N
447
if (initialPlatform.equals(antName)) {
448
if (this.selectedPlatform == null) {
449
this.selectedPlatform = pk;
450
initialPlatform = null;
458
if (initialPlatform == null) {
459
if (this.selectedPlatform == null || !orderedNames.contains(this.selectedPlatform)) {
460
this.selectedPlatform = new PlatformKey (JavaPlatformManager.getDefault().getDefaultPlatform());
464
PlatformKey pk = new PlatformKey (this.initialPlatform);
465
orderedNames.add (pk);
466
if (this.selectedPlatform == null) {
467
this.selectedPlatform = pk;
471
this.platformNamesCache = (PlatformKey[]) orderedNames.toArray(new PlatformKey[orderedNames.size()]);
473
return this.platformNamesCache;
478
private static class PlatformListCellRenderer extends DefaultListCellRenderer {
480
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
481
assert value instanceof PlatformKey : "Wrong model"; //NOI18N
482
PlatformKey key = (PlatformKey) value;
484
if (key.isBroken()) {
485
name = NbBundle.getMessage (PlatformUiSupport.class,"TXT_BrokenPlatformFmt", key.getDisplayName());
488
name = key.getDisplayName();
490
return super.getListCellRendererComponent(list, name, index, isSelected, cellHasFocus);
494
private static class SourceLevelComboBoxModel extends AbstractListModel implements ComboBoxModel, ListDataListener {
496
private static final String VERSION_PREFIX = "1."; //The version prefix
497
private static final int INITIAL_VERSION_MINOR = 2; //1.2
498
// if project is JAVA EE 5 show only 1.5 and higher
499
private static final int INITIAL_VERSION_MINOR_JAVA_EE_5 = 5; // 1.5
501
private SpecificationVersion selectedSourceLevel;
502
private SpecificationVersion originalSourceLevel;
503
private SourceLevelKey[] sourceLevelCache;
504
private final ComboBoxModel platformComboBoxModel;
505
private PlatformKey activePlatform;
506
private String j2eePlatform = null;
508
public SourceLevelComboBoxModel(ComboBoxModel platformComboBoxModel, String initialSourceLevel, String initialTargetLevel) {
509
this.platformComboBoxModel = platformComboBoxModel;
510
this.activePlatform = (PlatformKey) this.platformComboBoxModel.getSelectedItem();
511
this.platformComboBoxModel.addListDataListener(this);
512
if (initialSourceLevel != null && initialSourceLevel.length()>0) {
514
originalSourceLevel = new SpecificationVersion (initialSourceLevel);
515
} catch (NumberFormatException nfe) {
516
// If the javac.source has invalid value, do not preselect and log it.
517
LOGGER.log(Level.INFO, "Invalid javac.source: " + initialSourceLevel);
520
if (initialTargetLevel != null && initialTargetLevel.length() > 0) {
522
SpecificationVersion originalTargetLevel = new SpecificationVersion (initialTargetLevel);
523
if (this.originalSourceLevel == null || this.originalSourceLevel.compareTo(originalTargetLevel)<0) {
524
this.originalSourceLevel = originalTargetLevel;
526
} catch (NumberFormatException nfe) {
527
//If the javac.target has invalid value, do not preselect and log it
528
LOGGER.warning("Invalid javac.target: "+initialTargetLevel); //NOI18N
531
this.selectedSourceLevel = this.originalSourceLevel;
534
public SourceLevelComboBoxModel(ComboBoxModel platformComboBoxModel, String initialSourceLevel, String initialTargetLevel, String j2eePlatform) {
535
this(platformComboBoxModel, initialSourceLevel, initialTargetLevel);
536
this.j2eePlatform = j2eePlatform;
539
public int getSize() {
540
SourceLevelKey[] sLevels = getSourceLevels();
541
return sLevels.length;
544
public Object getElementAt(int index) {
545
SourceLevelKey[] sLevels = getSourceLevels();
546
assert index >=0 && index< sLevels.length;
547
return sLevels[index];
550
public Object getSelectedItem () {
551
SourceLevelKey[] keys = getSourceLevels();
552
for (int i=0; i<keys.length; i++) {
553
if (keys[i].getSourceLevel().equals(this.selectedSourceLevel)) {
560
public void setSelectedItem (Object obj) {
561
this.selectedSourceLevel = (obj == null ? null : ((SourceLevelKey) obj).getSourceLevel());
562
this.fireContentsChanged(this, -1, -1);
565
public void intervalAdded(ListDataEvent e) {
568
public void intervalRemoved(ListDataEvent e) {
571
public void contentsChanged(ListDataEvent e) {
572
PlatformKey selectedPlatform = (PlatformKey) this.platformComboBoxModel.getSelectedItem();
573
JavaPlatform platform = getPlatform(selectedPlatform);
574
if (platform != null) {
575
SpecificationVersion version = platform.getSpecification().getVersion();
576
if (this.selectedSourceLevel != null && this.selectedSourceLevel.compareTo(version)>0 &&
577
!shouldChangePlatform(selectedSourceLevel, version)) {
579
this.platformComboBoxModel.setSelectedItem(this.activePlatform);
583
this.originalSourceLevel = null;
586
this.activePlatform = selectedPlatform;
590
private void resetCache() {
591
synchronized (this) {
592
this.sourceLevelCache = null;
594
this.fireContentsChanged(this, -1, -1);
597
private SourceLevelKey[] getSourceLevels() {
598
if (this.sourceLevelCache == null) {
599
PlatformKey selectedPlatform = (PlatformKey) this.platformComboBoxModel.getSelectedItem();
600
JavaPlatform platform = getPlatform(selectedPlatform);
601
List<SourceLevelKey> sLevels = new ArrayList<SourceLevelKey>();
602
//If platform == null broken platform, the source level range is unknown
603
//The source level combo box should be empty and disabled
604
boolean selSourceLevelValid = false;
605
if (platform != null) {
606
SpecificationVersion version = platform.getSpecification().getVersion();
607
int index = INITIAL_VERSION_MINOR;
608
// #71619 - source level lower than 1.5 won't be shown for Java EE 5 project
609
if (j2eePlatform != null && j2eePlatform.equals(EjbJarProjectProperties.JAVA_EE_5)) {
610
index = INITIAL_VERSION_MINOR_JAVA_EE_5;
612
SpecificationVersion template = new SpecificationVersion (VERSION_PREFIX + Integer.toString (index++));
613
boolean origSourceLevelValid = false;
615
while (template.compareTo(version)<=0) {
616
if (template.equals(this.originalSourceLevel)) {
617
origSourceLevelValid = true;
619
if (template.equals(this.selectedSourceLevel)) {
620
selSourceLevelValid = true;
622
sLevels.add (new SourceLevelKey (template));
623
template = new SpecificationVersion (VERSION_PREFIX + Integer.toString (index++));
625
if (this.originalSourceLevel != null && !origSourceLevelValid) {
626
if (originalSourceLevel.equals(this.selectedSourceLevel)) {
627
selSourceLevelValid = true;
629
sLevels.add (new SourceLevelKey(this.originalSourceLevel,true));
632
this.sourceLevelCache = sLevels.toArray(new SourceLevelKey[sLevels.size()]);
633
if (!selSourceLevelValid) {
634
this.selectedSourceLevel = this.sourceLevelCache.length == 0 ?
635
null : this.sourceLevelCache[this.sourceLevelCache.length-1].getSourceLevel();
638
return this.sourceLevelCache;
641
private static boolean shouldChangePlatform (SpecificationVersion selectedSourceLevel, SpecificationVersion platformSourceLevel) {
642
JButton changeOption = new JButton (NbBundle.getMessage(PlatformUiSupport.class, "CTL_ChangePlatform"));
643
changeOption.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(PlatformUiSupport.class, "AD_ChangePlatform"));
644
String message = MessageFormat.format (NbBundle.getMessage(PlatformUiSupport.class,"TXT_ChangePlatform"),new Object[] {
645
selectedSourceLevel.toString(),
646
platformSourceLevel.toString(),
648
return DialogDisplayer.getDefault().notify(
649
new NotifyDescriptor (message,
650
NbBundle.getMessage(PlatformUiSupport.class,"TXT_ChangePlatformTitle"),
651
NotifyDescriptor.DEFAULT_OPTION,
652
NotifyDescriptor.WARNING_MESSAGE,
655
NotifyDescriptor.CANCEL_OPTION
657
changeOption)) == changeOption;
661
private static class SourceLevelListCellRenderer implements ListCellRenderer {
663
ListCellRenderer delegate;
665
public SourceLevelListCellRenderer() {
666
this.delegate = HtmlRenderer.createRenderer();
669
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
672
message = ""; //NOI18N
675
assert value instanceof SourceLevelKey;
676
SourceLevelKey key = (SourceLevelKey) value;
677
if (key.isBroken()) {
678
message = "<html><font color=\"#A40000\">" + //NOI18N
679
NbBundle.getMessage(PlatformUiSupport.class,"TXT_InvalidSourceLevel",key.getDisplayName());
682
message = key.getDisplayName();
685
return this.delegate.getListCellRendererComponent(list, message, index, isSelected, cellHasFocus);