Search in sources :

Example 6 with IBounds

use of com.archimatetool.model.IBounds in project archi by archimatetool.

the class ArchimateFactory method createBounds.

public IBounds createBounds(int x, int y, int width, int height) {
    Bounds bounds = new Bounds();
    bounds.setX(x);
    bounds.setY(y);
    bounds.setWidth(width);
    bounds.setHeight(height);
    return bounds;
}
Also used : IBounds(com.archimatetool.model.IBounds)

Example 7 with IBounds

use of com.archimatetool.model.IBounds in project archi by archimatetool.

the class DiagramModelObject method setBounds.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated NOT
 */
public void setBounds(int x, int y, int width, int height) {
    IBounds bounds = IArchimateFactory.eINSTANCE.createBounds(x, y, width, height);
    setBounds(bounds);
}
Also used : IBounds(com.archimatetool.model.IBounds)

Example 8 with IBounds

use of com.archimatetool.model.IBounds in project archi by archimatetool.

the class DiagramImageFigureTests method testDiagramImageChangesSize.

@Test
public void testDiagramImageChangesSize() throws Exception {
    Image image = getPrivateImageField();
    assertNull(image);
    // Add image
    File file = new File(TestSupport.getTestDataFolder().getPath(), "img/img1.png");
    addImage(file);
    // Check initial Image size
    image = getPrivateImageField();
    assertEquals(new Rectangle(0, 0, 1024, 1024), image.getBounds());
    // Check correct default size of image
    assertEquals(new Dimension(1024, 1024), figure.getDefaultSize());
    assertEquals(new Dimension(1024, 1024), figure.getPreferredSize(-1, -1));
    // Change size of DiagramModelImage and check it was rescaled
    IBounds bounds = IArchimateFactory.eINSTANCE.createBounds(0, 0, 512, 512);
    dmImage.setBounds(bounds);
    // Layout
    editor.layoutPendingUpdates();
    // Force a mock repaint since we are not using a GUI
    figure.paint(mock(Graphics.class));
    // Test image was rescaled
    image = getPrivateImageField();
    assertEquals(new Rectangle(0, 0, 512, 512), image.getBounds());
}
Also used : Graphics(org.eclipse.draw2d.Graphics) IBounds(com.archimatetool.model.IBounds) Rectangle(org.eclipse.swt.graphics.Rectangle) Dimension(org.eclipse.draw2d.geometry.Dimension) Image(org.eclipse.swt.graphics.Image) IDiagramModelImage(com.archimatetool.model.IDiagramModelImage) File(java.io.File) Test(org.junit.Test)

Example 9 with IBounds

use of com.archimatetool.model.IBounds in project archi by archimatetool.

the class CopySnapshot method createPasteObject.

private IDiagramModelObject createPasteObject(IDiagramModelContainer container, IDiagramModelObject snapshotObject) {
    // Don't paste invalid objects
    if (!isValidPasteComponent(fTargetDiagramModel, snapshotObject)) {
        return null;
    }
    IDiagramModelObject pasteObject = (IDiagramModelObject) snapshotObject.getCopy();
    createID(pasteObject);
    // Offset top level objects if container is diagram
    if (container instanceof IDiagramModel) {
        IDiagramModelObject originalObject = (IDiagramModelObject) fOriginalToSnapshotComponentsMapping.getKey(snapshotObject);
        IBounds bounds = originalObject.getBounds().getCopy();
        Point pt = new Point(bounds.getX(), bounds.getY());
        translateToAbsolute(originalObject, pt);
        bounds.setX(pt.x + fXOffSet);
        bounds.setY(pt.y + fYOffSet);
        pasteObject.setBounds(bounds);
    }
    // If Archimate object
    if (pasteObject instanceof IDiagramModelArchimateObject) {
        IDiagramModelArchimateObject dmo = (IDiagramModelArchimateObject) pasteObject;
        // Re-use original ArchiMate components
        if (!fDoCreateNewArchimateComponents) {
            IDiagramModelArchimateObject originalDiagramObject = (IDiagramModelArchimateObject) fOriginalToSnapshotComponentsMapping.getKey(snapshotObject);
            IArchimateElement element = originalDiagramObject.getArchimateElement();
            dmo.setArchimateElement(element);
        }
        // Provide new names if required
        if (fDoCreateNewArchimateComponents && isSourceAndTargetArchiMateModelSame()) {
            String name = dmo.getArchimateElement().getName();
            // $NON-NLS-1$
            dmo.getArchimateElement().setName(name + " " + Messages.CopySnapshot_1);
        }
    }
    // Add to Mapping
    fSnapshotToNewComponentMapping.put(snapshotObject, pasteObject);
    // Object is Container, so recurse
    if (snapshotObject instanceof IDiagramModelContainer) {
        for (IDiagramModelObject child : ((IDiagramModelContainer) snapshotObject).getChildren()) {
            IDiagramModelObject dmo = createPasteObject((IDiagramModelContainer) pasteObject, child);
            if (dmo != null) {
                ((IDiagramModelContainer) pasteObject).getChildren().add(dmo);
            }
        }
    }
    return pasteObject;
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) IBounds(com.archimatetool.model.IBounds) IArchimateElement(com.archimatetool.model.IArchimateElement) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) Point(org.eclipse.draw2d.geometry.Point) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer)

Example 10 with IBounds

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

Aggregations

IBounds (com.archimatetool.model.IBounds)13 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)6 Dimension (org.eclipse.draw2d.geometry.Dimension)6 Test (org.junit.Test)4 SetConstraintObjectCommand (com.archimatetool.editor.diagram.commands.SetConstraintObjectCommand)2 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)2 IDiagramModelContainer (com.archimatetool.model.IDiagramModelContainer)2 IDiagramModelImage (com.archimatetool.model.IDiagramModelImage)2 ILockable (com.archimatetool.model.ILockable)2 Command (org.eclipse.gef.commands.Command)2 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)2 DiagramImageEditPart (com.archimatetool.editor.diagram.editparts.diagram.DiagramImageEditPart)1 IDiagramModelObjectFigure (com.archimatetool.editor.diagram.figures.IDiagramModelObjectFigure)1 DiagramImageFigure (com.archimatetool.editor.diagram.figures.diagram.DiagramImageFigure)1 IGraphicalObjectUIProvider (com.archimatetool.editor.ui.factory.IGraphicalObjectUIProvider)1 IArchimateElement (com.archimatetool.model.IArchimateElement)1 IDiagramModel (com.archimatetool.model.IDiagramModel)1 IDiagramModelConnection (com.archimatetool.model.IDiagramModelConnection)1 IJunction (com.archimatetool.model.IJunction)1 File (java.io.File)1