示例#1
0
 @Override
 public void elementRemoved(ListEvent<CompanionFacade> e) {
   String type = e.getElement().getCompanionType();
   int index = Collections.binarySearch(types, type, Comparators.toStringIgnoreCaseCollator());
   CompanionTypeNode child = (CompanionTypeNode) getChildAt(index);
   child.removeCompanion(e.getElement());
 }
示例#2
0
 private void addCompanion(CompanionFacade companion, boolean silently) {
   companion.getNameRef().addReferenceListener(this);
   CompanionNode child = new CompanionNode(companion);
   if (children == null) {
     children = new Vector();
   }
   @SuppressWarnings("unchecked")
   int insertIndex =
       Collections.binarySearch(children, child, Comparators.toStringIgnoreCaseCollator());
   if (insertIndex < 0) {
     if (silently) {
       insert(child, -(insertIndex + 1));
     } else {
       insertNodeInto(child, this, -(insertIndex + 1));
     }
   } else {
     if (silently) {
       insert(child, insertIndex);
     } else {
       insertNodeInto(child, this, insertIndex);
     }
   }
   if (!silently) {
     nodeChanged(this);
   }
 }
示例#3
0
 private void removeCompanion(CompanionFacade companion) {
   companion.getNameRef().removeReferenceListener(this);
   // we create a dummy child for comparison
   CompanionNode child = new CompanionNode(companion);
   @SuppressWarnings("unchecked")
   int index =
       Collections.binarySearch(children, child, Comparators.toStringIgnoreCaseCollator());
   removeNodeFromParent((CompanionNode) getChildAt(index));
   nodeChanged(this);
 }
示例#4
0
 @Override
 public void keyAdded(MapEvent<String, Integer> e) {
   int insertIndex =
       Collections.binarySearch(types, e.getKey(), Comparators.toStringIgnoreCaseCollator());
   if (insertIndex < 0) {
     insertIndex = -(insertIndex + 1);
   }
   types.add(insertIndex, e.getKey());
   CompanionTypeNode child = new CompanionTypeNode(e.getKey());
   insertNodeInto(child, this, insertIndex);
 }
示例#5
0
  /**
   * Set the layer that a given shape will be displayed in. Since the shapes in this game are two
   * dimensional, it must be decided which will appear "on top" when two shapes overlap. The shape
   * in the higher layer will appear on top.
   *
   * <p>Setting a shape's layer will only affect how it is displayed; a shape's layer has no effect
   * on how it interacts with other shapes. (For example, two shapes can touch even if they are in
   * different layers. See {@link Shape#isTouching(Shape)}.)
   *
   * @param shape the shape whose layer is being set.
   * @param layer the layer into which this shape will be moved.
   */
  static void setLayer(Shape shape, int layer) {
    removeFromLayers(shape);

    // add new stuff
    if (!layerContents.containsKey(layer)) {
      layerContents.put(layer, new CopyOnWriteArrayList<Shape>());
      int insertionPoint = ~Collections.binarySearch(layers, layer);
      layers.add(insertionPoint, layer);
    }
    layerContents.get(layer).add(shape);
    layerOf.put(shape, layer);
  }
示例#6
0
 private void addCompanion(CompanionFacade companion, boolean silently) {
   String type = companion.getCompanionType();
   int index = Collections.binarySearch(types, type, Comparators.toStringIgnoreCaseCollator());
   if (index < 0) {
     Logging.errorPrint(
         "Unable to add companion "
             + companion
             + " as the type "
             + type
             + " could not be found.");
     return;
   }
   CompanionTypeNode child = (CompanionTypeNode) getChildAt(index);
   child.addCompanion(companion, silently);
 }
示例#7
0
    public void removeItem(String name, int ticketNumber) {
      int idx = Collections.binarySearch(data, new RentedItem(name));
      if (idx < 0) {
        throw new WtfException("Item " + name + " not present in model");
      }
      RentedItem item = data.get(idx);
      if (!item.tickets.remove(Integer.valueOf(ticketNumber))) {
        throw new WtfException(
            "Item " + name + " does not have ticket #" + ticketNumber + " assigned");
      }

      if (item.tickets.size() == 0) {
        data.remove(idx);
        fireIntervalRemoved(this, idx, idx);
      }
    }
示例#8
0
    public void addItem(String name, int ticketNumber) {
      int idx = Collections.binarySearch(data, new RentedItem(name));
      RentedItem item;
      if (idx >= 0) {
        item = data.get(idx);
      } else {
        item = new RentedItem(name);
      }
      item.tickets.add(ticketNumber);

      // add the item if necessary and fire model change events
      if (idx < 0) {
        idx = Math.abs(idx + 1);
        data.add(idx, item);
        fireIntervalAdded(this, idx, idx);
      }
    }