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;
   }
 }
 public void setSelectedItem(Object obj) {
   selectedSourceLevel = (obj == null ? null : ((SourceLevelKey) obj).getSourceLevel());
   fireContentsChanged(this, -1, -1);
   SourceLevelKey key = (SourceLevelKey) obj;
   if (key != null) {
     props.setJavacSourceLevel(key.getSourceLevel().toString());
     props.setJavacTargetLevel(key.getSourceLevel().toString());
   }
 }
 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;
 }
  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;
  }