示例#1
0
 /**
  * Remove the specified zone from the zone picker
  *
  * @param zone the zone to remove
  * @return The zone that was removed
  */
 public Zone remove(Zone zone) {
   Color color = zone.getPickColor();
   int pixelColor = color.getAlpha() + (color.getRGB() << 8);
   Zone removed = zoneMap.remove(pixelColor);
   zone.setPickColor(null);
   return removed;
 }
示例#2
0
  /**
   * Add a zone to the zone picker.
   *
   * @param zone the zone to enable picking on.
   */
  public void add(Zone zone) {
    // check if we already have this zone
    if (zoneMap.containsValue(zone)) return;

    if (zoneMap.size() == POSSIBLE_COLORS) {
      // We've run out of pick colours :( oh no
      System.err.printf(
          "The number of zones has exceeded the maximum number of pickable zones (%d). This recently added zone (%s) will not be pickable.",
          POSSIBLE_COLORS, zone);
      return;
    }

    // get a new colour
    zone.setPickColor(new Color(currentColor, false));
    int pixelColor = 0xff + (currentColor << 8);
    zoneMap.put(pixelColor, zone);

    // dont bother searching if we're out of colours anyways
    if (zoneMap.size() < POSSIBLE_COLORS) {
      while (zoneMap.containsKey(pixelColor)) {
        currentColor += 1;
        pixelColor = 0xff + (currentColor << 8);
      }
    }

    // add all of the zone's child zones
    for (Zone child : zone.getChildren()) this.add(child);
  }