use of com.archimatetool.editor.diagram.commands.SetConstraintObjectCommand 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 DiagramImageEditPart) {
DiagramImageEditPart part = (DiagramImageEditPart) object;
IDiagramModelObject model = part.getModel();
// Locked
if (model instanceof ILockable && ((ILockable) model).isLocked()) {
continue;
}
IBounds modelBounds = model.getBounds().getCopy();
int currentHeight = modelBounds.getHeight();
int currentWidth = modelBounds.getWidth();
// Already set to default height and width
if (currentHeight == -1 && currentWidth == -1) {
continue;
}
// Get original default size
DiagramImageFigure figure = part.getFigure();
Dimension size = figure.getDefaultSize();
if (size.height == 0 || size.width == 0) {
continue;
}
float originalRatio = ((float) size.height / (float) size.width);
float currentRatio = ((float) currentHeight / (float) currentWidth);
// If the ratio is different within tolerance
if (Math.abs(originalRatio - currentRatio) > 0.01) {
int width = currentWidth;
int height = currentHeight;
if (currentWidth < currentHeight) {
width = (int) (currentHeight / originalRatio);
} else {
height = (int) (currentWidth * originalRatio);
}
modelBounds.setWidth(width);
modelBounds.setHeight(height);
Command cmd = new SetConstraintObjectCommand(model, modelBounds);
result.add(cmd);
}
}
}
return result.unwrap();
}
use of com.archimatetool.editor.diagram.commands.SetConstraintObjectCommand 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 GraphicalEditPart) {
GraphicalEditPart part = (GraphicalEditPart) object;
if (part.getModel() instanceof IDiagramModelObject) {
IDiagramModelObject model = (IDiagramModelObject) part.getModel();
if (model instanceof ILockable && ((ILockable) model).isLocked()) {
continue;
}
IFigure figure = part.getFigure();
if (figure instanceof IDiagramModelObjectFigure) {
Dimension defaultSize = ((IDiagramModelObjectFigure) figure).getDefaultSize();
IBounds bounds = model.getBounds().getCopy();
if (bounds.getWidth() != defaultSize.width || bounds.getHeight() != defaultSize.height) {
bounds.setWidth(defaultSize.width);
bounds.setHeight(defaultSize.height);
Command cmd = new SetConstraintObjectCommand(model, bounds);
command.add(cmd);
}
}
}
}
}
return command.unwrap();
}
Aggregations