*
* @param cell <mxCell> for which the preferred size should be returned.
*/
public mxRectangle getPreferredSizeForCell(Object cell)
{
mxRectangle result = null;
if (cell != null)
{
mxCellState state = view.getState(cell);
Map<String, Object> style = (state != null) ? state.style
: getCellStyle(cell);
if (style != null && !model.isEdge(cell))
{
double dx = 0;
double dy = 0;
// Adds dimension of image if shape is a label
if (getImage(state) != null
|| mxUtils.getString(style, mxConstants.STYLE_IMAGE) != null)
{
if (mxUtils.getString(style, mxConstants.STYLE_SHAPE, "")
.equals(mxConstants.SHAPE_LABEL))
{
if (mxUtils.getString(style,
mxConstants.STYLE_VERTICAL_ALIGN, "").equals(
mxConstants.ALIGN_MIDDLE))
{
dx += mxUtils.getDouble(style,
mxConstants.STYLE_IMAGE_WIDTH,
mxConstants.DEFAULT_IMAGESIZE);
}
if (mxUtils.getString(style, mxConstants.STYLE_ALIGN,
"").equals(mxConstants.ALIGN_CENTER))
{
dy += mxUtils.getDouble(style,
mxConstants.STYLE_IMAGE_HEIGHT,
mxConstants.DEFAULT_IMAGESIZE);
}
}
}
// Adds spacings
double spacing = mxUtils.getDouble(style,
mxConstants.STYLE_SPACING);
dx += 2 * spacing;
dx += mxUtils.getDouble(style, mxConstants.STYLE_SPACING_LEFT);
dx += mxUtils.getDouble(style, mxConstants.STYLE_SPACING_RIGHT);
dy += 2 * spacing;
dy += mxUtils.getDouble(style, mxConstants.STYLE_SPACING_TOP);
dy += mxUtils
.getDouble(style, mxConstants.STYLE_SPACING_BOTTOM);
// LATER: Add space for collapse/expand icon if applicable
// Adds space for label
String value = getLabel(cell);
if (value != null && value.length() > 0)
{
// FIXME: Check word-wrap style and balance width/height
mxRectangle size = mxUtils.getLabelSize(value, style,
isHtmlLabel(cell), 1);
double width = size.getWidth() + dx;
double height = size.getHeight() + dy;
if (!mxUtils.isTrue(style, mxConstants.STYLE_HORIZONTAL,
true))
{
double tmp = height;
height = width;
width = tmp;
}
if (gridEnabled)
{
width = snap(width + gridSize / 2);
height = snap(height + gridSize / 2);
}
result = new mxRectangle(0, 0, width, height);
}
else
{
double gs2 = 4 * gridSize;
result = new mxRectangle(0, 0, gs2, gs2);
}
}
}
return result;