Search in sources :

Example 1 with ICanvasModelImage

use of com.archimatetool.canvas.model.ICanvasModelImage in project archi by archimatetool.

the class CanvasModelFactoryTests method testGetNewObjectCanvasImage.

@Test
public void testGetNewObjectCanvasImage() {
    ICreationFactory factory = new CanvasModelFactory(ICanvasPackage.eINSTANCE.getCanvasModelImage());
    ICanvasModelImage image = (ICanvasModelImage) factory.getNewObject();
    assertEquals("#000000", image.getBorderColor());
}
Also used : ICreationFactory(com.archimatetool.editor.diagram.ICreationFactory) ICanvasModelImage(com.archimatetool.canvas.model.ICanvasModelImage) Test(org.junit.Test)

Example 2 with ICanvasModelImage

use of com.archimatetool.canvas.model.ICanvasModelImage in project archi by archimatetool.

the class CanvasModelFactory method getNewObject.

public Object getNewObject() {
    // Create the instance from the registered factory in case of extensions
    Object object = fTemplate.getEPackage().getEFactoryInstance().create(fTemplate);
    // Sticky
    if (object instanceof ICanvasModelSticky) {
        ICanvasModelSticky sticky = (ICanvasModelSticky) object;
        sticky.setTextPosition(ITextPosition.TEXT_POSITION_CENTRE);
        sticky.setTextAlignment(ITextAlignment.TEXT_ALIGNMENT_CENTER);
        if (fParam instanceof Color) {
            String color = ColorFactory.convertColorToString((Color) fParam);
            sticky.setFillColor(color);
        }
        // $NON-NLS-1$
        sticky.setBorderColor("#C0C0C0");
    } else // Block
    if (object instanceof ICanvasModelBlock) {
        ICanvasModelBlock block = (ICanvasModelBlock) object;
        block.setTextPosition(ITextPosition.TEXT_POSITION_TOP);
        block.setTextAlignment(ITextAlignment.TEXT_ALIGNMENT_LEFT);
        // $NON-NLS-1$
        block.setBorderColor("#000000");
    } else // Image
    if (object instanceof ICanvasModelImage) {
        ICanvasModelImage image = (ICanvasModelImage) object;
        // $NON-NLS-1$
        image.setBorderColor("#000000");
    } else // Canvas Connection
    if (object instanceof ICanvasModelConnection) {
        ICanvasModelConnection connection = (ICanvasModelConnection) object;
        if (fParam instanceof Integer) {
            connection.setType((Integer) fParam);
        }
    }
    return object;
}
Also used : ICanvasModelSticky(com.archimatetool.canvas.model.ICanvasModelSticky) ICanvasModelConnection(com.archimatetool.canvas.model.ICanvasModelConnection) Color(org.eclipse.swt.graphics.Color) ICanvasModelBlock(com.archimatetool.canvas.model.ICanvasModelBlock) ICanvasModelImage(com.archimatetool.canvas.model.ICanvasModelImage)

Example 3 with ICanvasModelImage

use of com.archimatetool.canvas.model.ICanvasModelImage in project archi by archimatetool.

the class CanvasDNDEditPolicy method getFileDropCommand.

/**
 * @param request
 * @return
 */
protected Command getFileDropCommand(DiagramDropRequest request) {
    String[] files = (String[]) request.getData();
    // XY drop point
    Point pt = getDropLocation(request);
    int origin = pt.x;
    int x = pt.x;
    int y = pt.y;
    IArchiveManager archiveManager = (IArchiveManager) getTargetContainer().getAdapter(IArchiveManager.class);
    CompoundCommand result = new CompoundCommand(Messages.CanvasDNDEditPolicy_0);
    for (String s : files) {
        File file = new File(s);
        if (!file.canRead()) {
            continue;
        }
        String name = file.getName().toLowerCase();
        if (!(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        name.endsWith(".png") || name.endsWith(".bmp") || name.endsWith(".gif") || name.endsWith(".jpg") || name.endsWith(".jpeg") || // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        name.endsWith(".tif") || name.endsWith(".tiff") || name.endsWith(".ico"))) {
            // $NON-NLS-1$ //$NON-NLS-2$
            continue;
        }
        ICanvasModelImage canvasModelImage = ICanvasFactory.eINSTANCE.createCanvasModelImage();
        canvasModelImage.setName(Messages.CanvasDNDEditPolicy_1);
        String pathName;
        try {
            pathName = archiveManager.addImageFromFile(file);
        } catch (IOException ex) {
            ex.printStackTrace();
            continue;
        }
        canvasModelImage.setImagePath(pathName);
        // Get width and height of the image
        Image image = null;
        try {
            image = archiveManager.createImage(pathName);
        } catch (Exception ex) {
            ex.printStackTrace();
            continue;
        }
        int image_width = image.getBounds().width;
        int image_height = image.getBounds().height;
        image.dispose();
        canvasModelImage.setBounds(x, y, image_width, image_height);
        result.add(new AddDiagramObjectCommand(getTargetContainer(), canvasModelImage));
        // Increase x,y like a Carriage Return
        x += image_width + 10;
        if (x > origin + 1000) {
            x = origin;
            y += image_height + 10;
        }
    }
    return result;
}
Also used : AddDiagramObjectCommand(com.archimatetool.editor.diagram.commands.AddDiagramObjectCommand) Point(org.eclipse.draw2d.geometry.Point) IOException(java.io.IOException) IArchiveManager(com.archimatetool.editor.model.IArchiveManager) ICanvasModelImage(com.archimatetool.canvas.model.ICanvasModelImage) ICanvasModelImage(com.archimatetool.canvas.model.ICanvasModelImage) Image(org.eclipse.swt.graphics.Image) File(java.io.File) Point(org.eclipse.draw2d.geometry.Point) IOException(java.io.IOException) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Aggregations

ICanvasModelImage (com.archimatetool.canvas.model.ICanvasModelImage)3 ICanvasModelBlock (com.archimatetool.canvas.model.ICanvasModelBlock)1 ICanvasModelConnection (com.archimatetool.canvas.model.ICanvasModelConnection)1 ICanvasModelSticky (com.archimatetool.canvas.model.ICanvasModelSticky)1 ICreationFactory (com.archimatetool.editor.diagram.ICreationFactory)1 AddDiagramObjectCommand (com.archimatetool.editor.diagram.commands.AddDiagramObjectCommand)1 IArchiveManager (com.archimatetool.editor.model.IArchiveManager)1 File (java.io.File)1 IOException (java.io.IOException)1 Point (org.eclipse.draw2d.geometry.Point)1 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)1 Color (org.eclipse.swt.graphics.Color)1 Image (org.eclipse.swt.graphics.Image)1 Test (org.junit.Test)1