/*
* Copyright (c) 2014 tabletoptool.com team.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* rptools.com team - initial implementation
* tabletoptool.com team - further development
*/
package com.t3.client.ui.token;
import java.awt.Rectangle;
import com.t3.MD5Key;
import com.t3.model.Token;
import com.t3.xstreamversioned.version.SerializationVersion;
/**
* An overlay that allows multiple images to be placed on the token so that they
* do not interfere with any tokens on the same grid.
*
* @author Jay
*/
@SerializationVersion(0)
public class FlowImageTokenOverlay extends ImageTokenOverlay {
/**
* Size of the grid used to place a token with this state.
*/
private int grid;
/**
* Flow used to define position of states
*/
private transient TokenOverlayFlow flow;
/**
* Needed for serialization
*/
public FlowImageTokenOverlay() {
this(BooleanTokenOverlay.DEFAULT_STATE_NAME, null, -1);
}
/**
* Create the image overlay flow for the name, asset and grid
*
* @param name Name of the new state
* @param assetId Asset displayed for the state
* @param aGrid Size of the overlay grid for this state. All states with the
* same grid size share the same overlay.
*/
public FlowImageTokenOverlay(String name, MD5Key assetId, int aGrid) {
super(name, assetId);
grid = aGrid;
}
/**
* Get the flow used to position the states.
*
* @return Flow used to position the states
*/
protected TokenOverlayFlow getFlow() {
if (flow == null && grid > 0)
flow = TokenOverlayFlow.getInstance(grid);
return flow;
}
/**
* @see com.t3.client.ui.token.ImageTokenOverlay#getImageBounds(java.awt.Rectangle, Token)
*/
@Override
protected Rectangle getImageBounds(Rectangle bounds, Token token) {
return getFlow().getStateBounds(bounds, token, getName());
}
/**
* @see com.t3.client.ui.token.BooleanTokenOverlay#clone()
*/
@Override
public Object clone() {
BooleanTokenOverlay overlay = new FlowImageTokenOverlay(getName(), getAssetId(), grid);
overlay.setOrder(getOrder());
overlay.setGroup(getGroup());
overlay.setMouseover(isMouseover());
overlay.setOpacity(getOpacity());
overlay.setShowGM(isShowGM());
overlay.setShowOwner(isShowOwner());
overlay.setShowOthers(isShowOthers());
return overlay;
}
/** @return Getter for grid */
public int getGrid() {
return grid;
}
}