public String getDisplayName() {
   String tmp = sourceLevel.toString();
   if (JDK_1_5.compareTo(sourceLevel) <= 0) {
     tmp = tmp.replaceFirst("^1\\.([5-9]|\\d\\d+)$", "$1"); // NOI18N
   }
   return NbBundle.getMessage(PlatformUiSupport.class, "LBL_JDK", tmp); // NOI18N
 }
 private boolean shouldChangePlatform(
     SpecificationVersion selectedSourceLevel, SpecificationVersion platformSourceLevel) {
   JButton changeOption =
       new JButton(NbBundle.getMessage(PlatformUiSupport.class, "CTL_ChangePlatform")); // NOI18N
   changeOption
       .getAccessibleContext()
       .setAccessibleDescription(
           NbBundle.getMessage(PlatformUiSupport.class, "AD_ChangePlatform")); // NOI18N
   String message =
       MessageFormat.format(
           NbBundle.getMessage(PlatformUiSupport.class, "TXT_ChangePlatform"), // NOI18N
           selectedSourceLevel.toString(),
           platformSourceLevel.toString());
   return DialogDisplayer.getDefault()
           .notify(
               new NotifyDescriptor(
                   message,
                   NbBundle.getMessage(
                       PlatformUiSupport.class, "TXT_ChangePlatformTitle"), // NOI18N
                   NotifyDescriptor.DEFAULT_OPTION,
                   NotifyDescriptor.WARNING_MESSAGE,
                   new Object[] {changeOption, NotifyDescriptor.CANCEL_OPTION},
                   changeOption))
       == changeOption;
 }
  private SourceLevelKey[] getSourceLevels() {
    if (sourceLevelCache == null) {
      JavacardPlatform platform = props.getPlatform();
      List<SourceLevelKey> sLevels = new ArrayList<SourceLevelKey>();
      // if platform == null => broken platform, the source level range is unknown
      // the source level combo box should be empty and disabled
      boolean selSourceLevelValid = false;
      SpecificationVersion version =
          platform == null
              ? new SpecificationVersion("9.9")
              : // NOI18N
              platform.getSpecification().getVersion();
      Pattern p = Pattern.compile("\\d*.\\.(\\d).*?"); // NOI18N
      int maxVersion = 6;
      Matcher m = p.matcher(version.toString());
      if (m.find() && m.groupCount() > 0) {
        maxVersion = Integer.parseInt(m.group(1));
      }

      int min = getMinimalIndex(version);
      for (int i = min; i < maxVersion + 1; i++) {
        SpecificationVersion ver = new SpecificationVersion("1." + i); // NOI18N
        sLevels.add(new SourceLevelKey(ver));
        selSourceLevelValid |= ver.equals(selectedSourceLevel);
      }
      sourceLevelCache = sLevels.toArray(new SourceLevelKey[sLevels.size()]);
      if (!selSourceLevelValid) {
        selectedSourceLevel =
            sourceLevelCache.length == 0
                ? null
                : sourceLevelCache[sourceLevelCache.length - 1].getSourceLevel();
      }
    }
    return sourceLevelCache;
  }
 public Object getSelectedItem() {
   for (SourceLevelKey key : getSourceLevels()) {
     SpecificationVersion ver = key.getSourceLevel();
     if (ver.toString()
         .equals(selectedSourceLevel == null ? "" : selectedSourceLevel.toString())) {
       return key;
     }
   }
   return null;
 }
 private int getMinimalIndex(SpecificationVersion platformVersion) {
   int index = INITIAL_VERSION_MINOR;
   if (minimalSpecificationVersion != null) {
     SpecificationVersion min = new SpecificationVersion(VERSION_PREFIX + Integer.toString(index));
     while (min.compareTo(platformVersion) <= 0) {
       if (min.equals(minimalSpecificationVersion)) {
         return index;
       }
       min = new SpecificationVersion(VERSION_PREFIX + Integer.toString(++index));
     }
   }
   return index;
 }
 public SourceLevelComboBoxModel(
     JCProjectProperties props,
     String initialSourceLevel,
     String initialTargetLevel,
     SpecificationVersion minimalSpecificationVersion) {
   activePlatform = props.getPlatform();
   this.props = props;
   if (initialSourceLevel != null && initialSourceLevel.length() > 0) {
     try {
       originalSourceLevel = new SpecificationVersion(initialSourceLevel);
     } catch (NumberFormatException nfe) {
       // if the javac.source has invalid value, do not preselect and log it.
       LOGGER.warning("Invalid javac.source: " + initialSourceLevel); // NOI18N
     }
   }
   if (initialTargetLevel != null && initialTargetLevel.length() > 0) {
     try {
       SpecificationVersion originalTargetLevel = new SpecificationVersion(initialTargetLevel);
       if (originalSourceLevel == null || originalSourceLevel.compareTo(originalTargetLevel) < 0) {
         originalSourceLevel = originalTargetLevel;
       }
     } catch (NumberFormatException nfe) {
       // if the javac.target has invalid value, do not preselect and log it
       LOGGER.warning("Invalid javac.target: " + initialTargetLevel); // NOI18N
     }
   }
   selectedSourceLevel = originalSourceLevel;
   this.minimalSpecificationVersion = minimalSpecificationVersion;
 }
 public void platformChanged() {
   if (inPlatformChanged) {
     return;
   }
   inPlatformChanged = true;
   try {
     JavacardPlatform platform = activePlatform;
     if (platform != null) {
       SpecificationVersion version = platform.getSpecification().getVersion();
       if (selectedSourceLevel != null
           && selectedSourceLevel.compareTo(version) > 0
           && !shouldChangePlatform(selectedSourceLevel, version)) {
         props.setPlatformName(platform.getSystemName());
         // restore original
         return;
       } else {
         originalSourceLevel = null;
       }
     }
     activePlatform = props.getPlatform();
     resetCache();
   } finally {
     inPlatformChanged = false;
   }
 }