Search in sources :

Example 1 with IGraphicalObjectUIProvider

use of com.archimatetool.editor.ui.factory.IGraphicalObjectUIProvider in project archi by archimatetool.

the class FixDefaultSizesHandler method getDefaultSize.

Dimension getDefaultSize(IDiagramModelObject dmo) {
    IBounds bounds = dmo.getBounds();
    if (bounds.getWidth() != -1 && bounds.getHeight() != -1) {
        return new Dimension(bounds.getWidth(), bounds.getHeight());
    }
    // Legacy size of ArchiMate figure
    if (dmo instanceof IDiagramModelArchimateObject) {
        if (!(((IDiagramModelArchimateObject) dmo).getArchimateElement() instanceof IJunction)) {
            return new Dimension(120, 55);
        }
    }
    IGraphicalObjectUIProvider provider = (IGraphicalObjectUIProvider) ObjectUIFactory.INSTANCE.getProvider(dmo);
    return provider != null ? provider.getUserDefaultSize() : new Dimension(120, 55);
}
Also used : IBounds(com.archimatetool.model.IBounds) IGraphicalObjectUIProvider(com.archimatetool.editor.ui.factory.IGraphicalObjectUIProvider) Dimension(org.eclipse.draw2d.geometry.Dimension) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IJunction(com.archimatetool.model.IJunction)

Example 2 with IGraphicalObjectUIProvider

use of com.archimatetool.editor.ui.factory.IGraphicalObjectUIProvider in project archi by archimatetool.

the class ArchimateDiagramModelFactory method createDiagramModelArchimateObject.

/**
 * Factory method for creating a new IDiagramModelArchimateObject for an IArchimateElement
 * @param element
 * @return a new IDiagramModelArchimateObject
 */
public static IDiagramModelArchimateObject createDiagramModelArchimateObject(IArchimateElement element) {
    IDiagramModelArchimateObject dmo = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
    dmo.setArchimateElement(element);
    // Figure Type
    dmo.setType(Preferences.STORE.getInt(IPreferenceConstants.DEFAULT_FIGURE_PREFIX + element.eClass().getName()));
    // Add new bounds with a default user size
    IGraphicalObjectUIProvider provider = (IGraphicalObjectUIProvider) ObjectUIFactory.INSTANCE.getProvider(dmo);
    Dimension size = provider.getUserDefaultSize();
    dmo.setBounds(0, 0, size.width, size.height);
    dmo.setTextPosition(ITextPosition.TEXT_POSITION_TOP);
    // Set user default colors as set in prefs
    ColorFactory.setDefaultColors(dmo);
    return dmo;
}
Also used : IGraphicalObjectUIProvider(com.archimatetool.editor.ui.factory.IGraphicalObjectUIProvider) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) Dimension(org.eclipse.draw2d.geometry.Dimension)

Example 3 with IGraphicalObjectUIProvider

use of com.archimatetool.editor.ui.factory.IGraphicalObjectUIProvider in project archi by archimatetool.

the class AbstractDiagramModelObjectFigureTests method testGetDefaultSize.

@Test
public void testGetDefaultSize() {
    IGraphicalObjectUIProvider provider = (IGraphicalObjectUIProvider) ObjectUIFactory.INSTANCE.getProvider(abstractFigure.getDiagramModelObject());
    assertEquals(provider.getUserDefaultSize(), abstractFigure.getDefaultSize());
}
Also used : IGraphicalObjectUIProvider(com.archimatetool.editor.ui.factory.IGraphicalObjectUIProvider) Test(org.junit.Test)

Example 4 with IGraphicalObjectUIProvider

use of com.archimatetool.editor.ui.factory.IGraphicalObjectUIProvider in project archi by archimatetool.

the class DiagramImageFigureTests method testGetDefaultSize.

@Override
@Test
public void testGetDefaultSize() {
    IGraphicalObjectUIProvider provider = (IGraphicalObjectUIProvider) ObjectUIFactory.INSTANCE.getProvider(figure.getDiagramModelObject());
    Dimension defaultSize = provider.getDefaultSize();
    assertEquals(defaultSize, figure.getDefaultSize());
    // Add image
    try {
        File file = new File(TestSupport.getTestDataFolder().getPath(), "img/img1.png");
        addImage(file);
        Image image = getPrivateImageField();
        assertEquals(new Dimension(image), figure.getDefaultSize());
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    // Reset
    dmImage.setImagePath(null);
    assertEquals(defaultSize, figure.getDefaultSize());
}
Also used : IGraphicalObjectUIProvider(com.archimatetool.editor.ui.factory.IGraphicalObjectUIProvider) Dimension(org.eclipse.draw2d.geometry.Dimension) Image(org.eclipse.swt.graphics.Image) IDiagramModelImage(com.archimatetool.model.IDiagramModelImage) File(java.io.File) IOException(java.io.IOException) Test(org.junit.Test)

Example 5 with IGraphicalObjectUIProvider

use of com.archimatetool.editor.ui.factory.IGraphicalObjectUIProvider in project archi by archimatetool.

the class CreateDiagramObjectCommand method addChild.

protected void addChild() {
    fChild = (IDiagramModelObject) fRequest.getNewObject();
    // Default size
    if (fBounds.width == -1 && fBounds.height == -1) {
        IGraphicalObjectUIProvider provider = (IGraphicalObjectUIProvider) ObjectUIFactory.INSTANCE.getProvider(fChild);
        if (provider != null) {
            Dimension size = provider.getUserDefaultSize();
            fBounds.width = size.width;
            fBounds.height = size.height;
        }
    }
    fChild.setBounds(fBounds.x, fBounds.y, fBounds.width, fBounds.height);
    redo();
}
Also used : IGraphicalObjectUIProvider(com.archimatetool.editor.ui.factory.IGraphicalObjectUIProvider) Dimension(org.eclipse.draw2d.geometry.Dimension)

Aggregations

IGraphicalObjectUIProvider (com.archimatetool.editor.ui.factory.IGraphicalObjectUIProvider)5 Dimension (org.eclipse.draw2d.geometry.Dimension)4 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)2 Test (org.junit.Test)2 IBounds (com.archimatetool.model.IBounds)1 IDiagramModelImage (com.archimatetool.model.IDiagramModelImage)1 IJunction (com.archimatetool.model.IJunction)1 File (java.io.File)1 IOException (java.io.IOException)1 Image (org.eclipse.swt.graphics.Image)1