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;
  }
 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;
 }