Search in sources :

Example 1 with DiagramImageEditPart

use of com.archimatetool.editor.diagram.editparts.diagram.DiagramImageEditPart 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();
}
Also used : SetConstraintObjectCommand(com.archimatetool.editor.diagram.commands.SetConstraintObjectCommand) DiagramImageFigure(com.archimatetool.editor.diagram.figures.diagram.DiagramImageFigure) SetConstraintObjectCommand(com.archimatetool.editor.diagram.commands.SetConstraintObjectCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) IBounds(com.archimatetool.model.IBounds) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) DiagramImageEditPart(com.archimatetool.editor.diagram.editparts.diagram.DiagramImageEditPart) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) Dimension(org.eclipse.draw2d.geometry.Dimension) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) ILockable(com.archimatetool.model.ILockable)

Example 2 with DiagramImageEditPart

use of com.archimatetool.editor.diagram.editparts.diagram.DiagramImageEditPart in project archi by archimatetool.

the class DiagramModelImageUIProviderTests method testCreateEditPart.

@Override
public void testCreateEditPart() {
    EditPart editPart = provider.createEditPart();
    assertTrue(editPart instanceof DiagramImageEditPart);
}
Also used : DiagramImageEditPart(com.archimatetool.editor.diagram.editparts.diagram.DiagramImageEditPart) EditPart(org.eclipse.gef.EditPart) DiagramImageEditPart(com.archimatetool.editor.diagram.editparts.diagram.DiagramImageEditPart)

Example 3 with DiagramImageEditPart

use of com.archimatetool.editor.diagram.editparts.diagram.DiagramImageEditPart in project archi by archimatetool.

the class CanvasImageUIProviderTests method testCreateEditPart.

@Override
public void testCreateEditPart() {
    EditPart editPart = provider.createEditPart();
    assertTrue(editPart instanceof DiagramImageEditPart);
}
Also used : DiagramImageEditPart(com.archimatetool.editor.diagram.editparts.diagram.DiagramImageEditPart) EditPart(org.eclipse.gef.EditPart) DiagramImageEditPart(com.archimatetool.editor.diagram.editparts.diagram.DiagramImageEditPart)

Example 4 with DiagramImageEditPart

use of com.archimatetool.editor.diagram.editparts.diagram.DiagramImageEditPart in project archi by archimatetool.

the class CanvasModelEditPartFactoryTests method testDiagramImageEditPart.

@Test
public void testDiagramImageEditPart() {
    IDiagramModelImage image = IArchimateFactory.eINSTANCE.createDiagramModelImage();
    EditPart editPart = editPartFactory.createEditPart(null, image);
    assertTrue(editPart instanceof DiagramImageEditPart);
    assertEquals(image, editPart.getModel());
}
Also used : DiagramImageEditPart(com.archimatetool.editor.diagram.editparts.diagram.DiagramImageEditPart) DiagramConnectionEditPart(com.archimatetool.editor.diagram.editparts.DiagramConnectionEditPart) EditPart(org.eclipse.gef.EditPart) EmptyEditPart(com.archimatetool.editor.diagram.editparts.diagram.EmptyEditPart) IDiagramModelImage(com.archimatetool.model.IDiagramModelImage) DiagramImageEditPart(com.archimatetool.editor.diagram.editparts.diagram.DiagramImageEditPart) Test(org.junit.Test)

Aggregations

DiagramImageEditPart (com.archimatetool.editor.diagram.editparts.diagram.DiagramImageEditPart)4 EditPart (org.eclipse.gef.EditPart)3 SetConstraintObjectCommand (com.archimatetool.editor.diagram.commands.SetConstraintObjectCommand)1 DiagramConnectionEditPart (com.archimatetool.editor.diagram.editparts.DiagramConnectionEditPart)1 EmptyEditPart (com.archimatetool.editor.diagram.editparts.diagram.EmptyEditPart)1 DiagramImageFigure (com.archimatetool.editor.diagram.figures.diagram.DiagramImageFigure)1 IBounds (com.archimatetool.model.IBounds)1 IDiagramModelImage (com.archimatetool.model.IDiagramModelImage)1 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)1 ILockable (com.archimatetool.model.ILockable)1 Dimension (org.eclipse.draw2d.geometry.Dimension)1 Command (org.eclipse.gef.commands.Command)1 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)1 Test (org.junit.Test)1