* updated.
*/
public mxRectangle updateBoundingBox(mxCellState state)
{
// Gets the cell bounds and adds shadows and markers
mxRectangle rect = new mxRectangle(state);
Map<String, Object> style = state.getStyle();
// Adds extra pixels for the marker and stroke assuming
// that the border stroke is centered around the bounds
// and the first pixel is drawn inside the bounds
double strokeWidth = Math.max(
1,
Math.round(mxUtils.getInt(style, mxConstants.STYLE_STROKEWIDTH,
1) * scale));
strokeWidth -= Math.max(1, strokeWidth / 2);
if (graph.getModel().isEdge(state.getCell()))
{
int ms = 0;
if (style.containsKey(mxConstants.STYLE_ENDARROW)
|| style.containsKey(mxConstants.STYLE_STARTARROW))
{
ms = (int) Math.round(mxConstants.DEFAULT_MARKERSIZE * scale);
}
// Adds the strokewidth
rect.grow(ms + strokeWidth);
// Adds worst case border for an arrow shape
if (mxUtils.getString(style, mxConstants.STYLE_SHAPE, "").equals(
mxConstants.SHAPE_ARROW))
{
rect.grow(mxConstants.ARROW_WIDTH / 2);
}
}
else
{
rect.grow(strokeWidth);
}
// Adds extra pixels for the shadow
if (mxUtils.isTrue(style, mxConstants.STYLE_SHADOW))
{
rect.setWidth(rect.getWidth() + mxConstants.SHADOW_OFFSETX);
rect.setHeight(rect.getHeight() + mxConstants.SHADOW_OFFSETY);
}
// Adds oversize images in labels
if (mxUtils.getString(style, mxConstants.STYLE_SHAPE, "").equals(
mxConstants.SHAPE_LABEL))
{
if (mxUtils.getString(style, mxConstants.STYLE_IMAGE) != null)
{
double w = mxUtils.getInt(style, mxConstants.STYLE_IMAGE_WIDTH,
mxConstants.DEFAULT_IMAGESIZE) * scale;
double h = mxUtils.getInt(style,
mxConstants.STYLE_IMAGE_HEIGHT,
mxConstants.DEFAULT_IMAGESIZE)
* scale;
double x = state.getX();
double y = 0;
String imgAlign = mxUtils.getString(style,
mxConstants.STYLE_IMAGE_ALIGN, mxConstants.ALIGN_LEFT);
String imgValign = mxUtils.getString(style,
mxConstants.STYLE_IMAGE_VERTICAL_ALIGN,
mxConstants.ALIGN_MIDDLE);
if (imgAlign.equals(mxConstants.ALIGN_RIGHT))
{
x += state.getWidth() - w;
}
else if (imgAlign.equals(mxConstants.ALIGN_CENTER))
{
x += (state.getWidth() - w) / 2;
}
if (imgValign.equals(mxConstants.ALIGN_TOP))
{
y = state.getY();
}
else if (imgValign.equals(mxConstants.ALIGN_BOTTOM))
{
y = state.getY() + state.getHeight() - h;
}
else
// MIDDLE
{
y = state.getY() + (state.getHeight() - h) / 2;
}
rect.add(new mxRectangle(x, y, w, h));
}
}
// Adds the rotated bounds to the bounding box if the
// shape is rotated
double rotation = mxUtils.getDouble(style, mxConstants.STYLE_ROTATION);
mxRectangle bbox = mxUtils.getBoundingBox(rect, rotation);
// Add the rotated bounding box to the non-rotated so
// that all handles are also covered
rect.add(bbox);