Search in sources :

Example 6 with IIconic

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

the class ValueFigure method drawFigure.

@Override
public void drawFigure(Graphics graphics) {
    graphics.pushState();
    Rectangle bounds = getBounds().getCopy();
    bounds.width--;
    bounds.height--;
    // Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
    setLineWidth(graphics, 1, bounds);
    graphics.setAlpha(getAlpha());
    if (!isEnabled()) {
        setDisabledState(graphics);
    }
    graphics.setBackgroundColor(getFillColor());
    Pattern gradient = applyGradientPattern(graphics, bounds);
    graphics.fillOval(bounds);
    disposeGradientPattern(graphics, gradient);
    // Outline
    graphics.setAlpha(getLineAlpha());
    graphics.setForegroundColor(getLineColor());
    graphics.drawOval(bounds);
    // Icon
    // drawIconImage(graphics, bounds);
    int top = 0, right = 0, left = 0, bottom = 0;
    int offset = 6;
    switch(((IIconic) getDiagramModelObject()).getImagePosition()) {
        case IIconic.ICON_POSITION_TOP_LEFT:
            top = bounds.height / offset;
            left = bounds.width / offset;
            break;
        case IIconic.ICON_POSITION_TOP_RIGHT:
            top = bounds.height / offset;
            right = -(bounds.width / offset);
            break;
        case IIconic.ICON_POSITION_BOTTOM_LEFT:
            bottom = -(bounds.height / offset);
            left = bounds.width / offset;
            break;
        case IIconic.ICON_POSITION_BOTTOM_RIGHT:
            bottom = -(bounds.height / offset);
            right = -(bounds.width / offset);
            break;
    }
    drawIconImage(graphics, bounds, top, right, bottom, left);
    // Rectangle iconArea = new Rectangle(bounds.x + (bounds.width / 6), bounds.y + (bounds.height / 6),
    // bounds.width - (bounds.width / 3), bounds.height - (bounds.height / 3));
    // drawIconImage(graphics, iconArea, 0, 0, 0, 0);
    graphics.popState();
}
Also used : Pattern(org.eclipse.swt.graphics.Pattern) IIconic(com.archimatetool.model.IIconic) Rectangle(org.eclipse.draw2d.geometry.Rectangle)

Example 7 with IIconic

use of com.archimatetool.model.IIconic 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 AbstractConnectedEditPart) {
            AbstractConnectedEditPart editPart = (AbstractConnectedEditPart) object;
            IDiagramModelObject model = editPart.getModel();
            // Locked
            if (model instanceof ILockable && ((ILockable) model).isLocked()) {
                continue;
            }
            AbstractDiagramModelObjectFigure figure = (AbstractDiagramModelObjectFigure) editPart.getFigure();
            IBounds bounds = model.getBounds().getCopy();
            // If the object has an icon image and set to image fill and isn't a container with childrem
            if (model instanceof IIconic && ((IIconic) model).getImagePosition() == IIconic.ICON_POSITION_FILL && figure.hasIconImage() && !(model instanceof IDiagramModelContainer && !((IDiagramModelContainer) model).getChildren().isEmpty())) {
                Rectangle imageBounds = figure.getIconicDelegate().getImage().getBounds();
                bounds.setWidth(imageBounds.width);
                bounds.setHeight(imageBounds.height);
            } else {
                Dimension defaultSize = ((IDiagramModelObjectFigure) figure).getDefaultSize();
                bounds.setWidth(defaultSize.width);
                bounds.setHeight(defaultSize.height);
            }
            if (bounds.getWidth() != model.getBounds().getWidth() || bounds.getHeight() != model.getBounds().getHeight()) {
                Command cmd = new SetConstraintObjectCommand(model, bounds);
                command.add(cmd);
            }
        }
    }
    return command.unwrap();
}
Also used : IIconic(com.archimatetool.model.IIconic) AbstractDiagramModelObjectFigure(com.archimatetool.editor.diagram.figures.AbstractDiagramModelObjectFigure) AbstractConnectedEditPart(com.archimatetool.editor.diagram.editparts.AbstractConnectedEditPart) IBounds(com.archimatetool.model.IBounds) Rectangle(org.eclipse.swt.graphics.Rectangle) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) Dimension(org.eclipse.draw2d.geometry.Dimension) IDiagramModelObjectFigure(com.archimatetool.editor.diagram.figures.IDiagramModelObjectFigure) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) 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) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) ILockable(com.archimatetool.model.ILockable)

Example 8 with IIconic

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

the class FunctionFigure method drawFigure.

@Override
protected void drawFigure(Graphics graphics) {
    if (getFigureDelegate() != null) {
        getFigureDelegate().drawFigure(graphics);
        drawIcon(graphics);
        return;
    }
    graphics.pushState();
    Rectangle rect = getBounds().getCopy();
    rect.width--;
    rect.height--;
    // Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
    setLineWidth(graphics, 1, rect);
    if (!isEnabled()) {
        setDisabledState(graphics);
    }
    graphics.setAlpha(getAlpha());
    graphics.setBackgroundColor(getFillColor());
    Pattern gradient = applyGradientPattern(graphics, rect);
    Path path = getFigurePath(rect);
    graphics.fillPath(path);
    disposeGradientPattern(graphics, gradient);
    // Line
    graphics.setForegroundColor(getLineColor());
    graphics.setAlpha(getLineAlpha());
    graphics.drawPath(path);
    path.dispose();
    // Image Icon
    // drawIconImage(graphics, bounds, 0, 0, 0, 0);
    // drawIconImage(graphics, bounds, bounds.height / 5 + 1, 0, -(bounds.height / 5 + 1), 0);
    int top = 0, right = 0, left = 0, bottom = 0;
    switch(((IIconic) getDiagramModelObject()).getImagePosition()) {
        case IIconic.ICON_POSITION_TOP_LEFT:
        case IIconic.ICON_POSITION_TOP_RIGHT:
            top = rect.height / OFFSET;
            break;
        case IIconic.ICON_POSITION_BOTTOM_CENTRE:
            bottom = -(rect.height / OFFSET);
            break;
        case IIconic.ICON_POSITION_BOTTOM_LEFT:
        case IIconic.ICON_POSITION_BOTTOM_RIGHT:
            bottom = -(rect.height / OFFSET / 3);
            break;
    }
    drawIconImage(graphics, rect, top, right, bottom, left);
    graphics.popState();
}
Also used : Path(org.eclipse.swt.graphics.Path) Pattern(org.eclipse.swt.graphics.Pattern) IIconic(com.archimatetool.model.IIconic) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

IIconic (com.archimatetool.model.IIconic)8 Rectangle (org.eclipse.draw2d.geometry.Rectangle)5 Pattern (org.eclipse.swt.graphics.Pattern)4 Point (org.eclipse.draw2d.geometry.Point)3 Path (org.eclipse.swt.graphics.Path)3 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)2 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)2 Command (org.eclipse.gef.commands.Command)2 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)2 BorderColorCommand (com.archimatetool.editor.diagram.commands.BorderColorCommand)1 ConnectionLineTypeCommand (com.archimatetool.editor.diagram.commands.ConnectionLineTypeCommand)1 ConnectionTextPositionCommand (com.archimatetool.editor.diagram.commands.ConnectionTextPositionCommand)1 DiagramModelObjectAlphaCommand (com.archimatetool.editor.diagram.commands.DiagramModelObjectAlphaCommand)1 DiagramModelObjectOutlineAlphaCommand (com.archimatetool.editor.diagram.commands.DiagramModelObjectOutlineAlphaCommand)1 FillColorCommand (com.archimatetool.editor.diagram.commands.FillColorCommand)1 FontColorCommand (com.archimatetool.editor.diagram.commands.FontColorCommand)1 FontStyleCommand (com.archimatetool.editor.diagram.commands.FontStyleCommand)1 LineColorCommand (com.archimatetool.editor.diagram.commands.LineColorCommand)1 LineWidthCommand (com.archimatetool.editor.diagram.commands.LineWidthCommand)1 SetConstraintObjectCommand (com.archimatetool.editor.diagram.commands.SetConstraintObjectCommand)1