use of com.archimatetool.editor.diagram.editparts.AbstractConnectedEditPart in project archi by archimatetool.
the class ResetAspectRatioAction method createCommand.
private Command createCommand(List<?> objects) {
CompoundCommand result = new CompoundCommand();
for (Object object : objects) {
if (object instanceof AbstractConnectedEditPart) {
AbstractConnectedEditPart editPart = (AbstractConnectedEditPart) object;
AbstractDiagramModelObjectFigure figure = (AbstractDiagramModelObjectFigure) editPart.getFigure();
IDiagramModelObject dmo = editPart.getModel();
// Diagram Image object with image or Iconic type with image and Fill setting
if (!isDiagramObjectWithImage(dmo) && !isIconicWithImageFill(dmo, figure)) {
continue;
}
// Locked
if (dmo instanceof ILockable && ((ILockable) dmo).isLocked()) {
continue;
}
IBounds modelBounds = dmo.getBounds().getCopy();
int currentHeight = modelBounds.getHeight();
int currentWidth = modelBounds.getWidth();
// Sanity check
if (currentHeight < 1 || currentWidth < 1) {
continue;
}
float currentRatio = ((float) currentHeight / (float) currentWidth);
float otherRatio = 0;
// Image object type
if (dmo instanceof IDiagramModelImage) {
// This will return the image's proper size (unsized) if there is an image, else the object's size
Dimension size = figure.getDefaultSize();
if (size.height == 0 || size.width == 0) {
continue;
}
otherRatio = ((float) size.height / (float) size.width);
} else // Iconic and fill type is fill and has an image
{
Rectangle imageBounds = figure.getIconicDelegate().getImage().getBounds();
otherRatio = ((float) imageBounds.height / (float) imageBounds.width);
}
// If the ratio is different (within tolerance)
if (otherRatio != 0 && Math.abs(otherRatio - currentRatio) > 0.01) {
if (currentWidth < currentHeight) {
currentWidth = (int) (currentHeight / otherRatio);
} else {
currentHeight = (int) (currentWidth * otherRatio);
}
modelBounds.setWidth(currentWidth);
modelBounds.setHeight(currentHeight);
Command cmd = new SetConstraintObjectCommand(dmo, modelBounds);
result.add(cmd);
}
}
}
return result.unwrap();
}
use of com.archimatetool.editor.diagram.editparts.AbstractConnectedEditPart in project archi by archimatetool.
the class DefaultEditPartSizeAction method createDefaultSizeCommand.
private Command createDefaultSizeCommand(List<?> objects) {
CompoundCommand command = new CompoundCommand();
for (Object object : objects) {
if (object instanceof AbstractConnectedEditPart) {
AbstractConnectedEditPart editPart = (AbstractConnectedEditPart) object;
IDiagramModelObject model = editPart.getModel();
// Locked
if (model instanceof ILockable && ((ILockable) model).isLocked()) {
continue;
}
AbstractDiagramModelObjectFigure figure = (AbstractDiagramModelObjectFigure) editPart.getFigure();
IBounds bounds = model.getBounds().getCopy();
// If the object has an icon image and set to image fill and isn't a container with childrem
if (model instanceof IIconic && ((IIconic) model).getImagePosition() == IIconic.ICON_POSITION_FILL && figure.hasIconImage() && !(model instanceof IDiagramModelContainer && !((IDiagramModelContainer) model).getChildren().isEmpty())) {
Rectangle imageBounds = figure.getIconicDelegate().getImage().getBounds();
bounds.setWidth(imageBounds.width);
bounds.setHeight(imageBounds.height);
} else {
Dimension defaultSize = ((IDiagramModelObjectFigure) figure).getDefaultSize();
bounds.setWidth(defaultSize.width);
bounds.setHeight(defaultSize.height);
}
if (bounds.getWidth() != model.getBounds().getWidth() || bounds.getHeight() != model.getBounds().getHeight()) {
Command cmd = new SetConstraintObjectCommand(model, bounds);
command.add(cmd);
}
}
}
return command.unwrap();
}
Aggregations