Ejemplo n.º 1
0
  /**
   * Convert the token into a hash map. This is used to ship all of the properties for the token to
   * other apps that do need access to the <code>Token</code> class.
   *
   * @return A map containing the properties of the token.
   */
  public TokenTransferData toTransferData() {
    TokenTransferData td = new TokenTransferData();
    td.setName(name);
    td.setPlayers(ownerList);
    td.setVisible(isVisible);
    td.setLocation(new Point(x, y));
    td.setFacing(facing);

    // Set the properties
    td.put(TokenTransferData.ID, id.toString());
    td.put(TokenTransferData.ASSET_ID, imageAssetMap.get(null));
    td.put(TokenTransferData.Z, z);
    td.put(TokenTransferData.SNAP_TO_SCALE, snapToScale);
    td.put(TokenTransferData.WIDTH, scaleX);
    td.put(TokenTransferData.HEIGHT, scaleY);
    td.put(TokenTransferData.SNAP_TO_GRID, snapToGrid);
    td.put(TokenTransferData.OWNER_TYPE, ownerType);
    td.put(TokenTransferData.VISIBLE_OWNER_ONLY, visibleOnlyToOwner);
    td.put(TokenTransferData.TOKEN_TYPE, tokenShape);
    td.put(TokenTransferData.NOTES, notes);
    td.put(TokenTransferData.GM_NOTES, gmNotes);
    td.put(TokenTransferData.GM_NAME, gmName);

    // Put all of the serializable state into the map
    for (String key : getStatePropertyNames()) {
      Object value = getState(key);
      if (value instanceof Serializable) td.put(key, value);
    }
    td.putAll(state);

    // Create the image from the asset and add it to the map
    Image image = ImageManager.getImageAndWait(imageAssetMap.get(null));
    if (image != null) td.setToken(new ImageIcon(image)); // Image icon makes it serializable.
    return td;
  }
Ejemplo n.º 2
0
 public Icon getIcon(int width, int height) {
   ImageIcon icon = new ImageIcon(ImageManager.getImageAndWait(getImageAssetId()));
   Image image = icon.getImage().getScaledInstance(width, height, Image.SCALE_DEFAULT);
   return new ImageIcon(image);
 }