Example #1
0
  /**
   * Creates a region (first deleting it if one with that name exists)
   *
   * @param string
   * @param xaxis
   * @return
   * @throws Exception
   */
  public static final IRegion replaceCreateRegion(
      final IRegionSystem system, final String name, final RegionType type) throws Exception {

    if (system.getRegion(name) != null) {
      system.removeRegion(system.getRegion(name));
    }
    return system.createRegion(name, type);
  }
Example #2
0
 /**
  * Call to get a unique region name
  *
  * @param nameStub
  * @param system
  * @return
  */
 public static String getUniqueName(
     final String nameStub, final IRegionSystem system, final String... usedNames) {
   int i = 1;
   @SuppressWarnings("unchecked")
   final List<String> used =
       (List<String>) (usedNames != null ? Arrays.asList(usedNames) : Collections.emptyList());
   while (system.getRegion(nameStub + " " + i) != null || used.contains(nameStub + " " + i)) {
     ++i;
     if (i > 10000) break; // something went wrong!
   }
   return nameStub + " " + i;
 }
Example #3
0
  /**
   * @param plotter
   * @return
   */
  public static Color getUniqueColor(
      IRegion.RegionType type, IRegionSystem plotter, Collection<Color> colours) {

    final Collection<Color> used = new HashSet<Color>(7);
    for (IRegion reg : plotter.getRegions()) {
      if (reg.getRegionType() != type) continue;
      used.add(reg.getRegionColor());
    }

    for (Color color : colours) {
      if (!used.contains(color)) return color;
    }
    return colours.iterator().next();
  }