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());
}
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;
}
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;
}
Aggregations