Search in sources :

Example 1 with IIconic

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

the class FormatPainterTool method createCommand.

protected CompoundCommand createCommand(PaintFormat pf, IDiagramModelComponent targetComponent) {
    CompoundCommand result = new CompoundCommand(Messages.FormatPainterTool_0);
    // IFontAttribute
    if (pf.getSourceComponent() instanceof IFontAttribute && targetComponent instanceof IFontAttribute) {
        IFontAttribute source = (IFontAttribute) pf.getSourceComponent();
        IFontAttribute target = (IFontAttribute) targetComponent;
        Command cmd = new FontStyleCommand(target, source.getFont());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
        cmd = new FontColorCommand(target, source.getFontColor());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
    }
    // ILineObject
    if (pf.getSourceComponent() instanceof ILineObject && targetComponent instanceof ILineObject) {
        ILineObject source = (ILineObject) pf.getSourceComponent();
        ILineObject target = (ILineObject) targetComponent;
        Command cmd = new LineColorCommand(target, source.getLineColor());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
        cmd = new LineWidthCommand(target, source.getLineWidth());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
    }
    // IBorderObject
    if (pf.getSourceComponent() instanceof IBorderObject && targetComponent instanceof IBorderObject) {
        IBorderObject source = (IBorderObject) pf.getSourceComponent();
        IBorderObject target = (IBorderObject) targetComponent;
        Command cmd = new BorderColorCommand(target, source.getBorderColor());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
    }
    // ITextPosition
    if (pf.getSourceComponent() instanceof ITextPosition && targetComponent instanceof ITextPosition) {
        ITextPosition source = (ITextPosition) pf.getSourceComponent();
        ITextPosition target = (ITextPosition) targetComponent;
        Command cmd = new TextPositionCommand(target, source.getTextPosition());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
    }
    // ITextAlignment
    if (pf.getSourceComponent() instanceof ITextAlignment && targetComponent instanceof ITextAlignment) {
        ITextAlignment source = (ITextAlignment) pf.getSourceComponent();
        ITextAlignment target = (ITextAlignment) targetComponent;
        Command cmd = new TextAlignmentCommand(target, source.getTextAlignment());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
    }
    // IDiagramModelObject
    if (pf.getSourceComponent() instanceof IDiagramModelObject && targetComponent instanceof IDiagramModelObject) {
        IDiagramModelObject source = (IDiagramModelObject) pf.getSourceComponent();
        IDiagramModelObject target = (IDiagramModelObject) targetComponent;
        // Source fill colour is null which is "default"
        String fillColorString = source.getFillColor();
        if (fillColorString == null) {
            fillColorString = ColorFactory.convertColorToString(ColorFactory.getDefaultFillColor(source));
        }
        Command cmd = new FillColorCommand(target, fillColorString);
        if (cmd.canExecute()) {
            result.add(cmd);
        }
        // Alpha fill opacity
        cmd = new DiagramModelObjectAlphaCommand(target, source.getAlpha());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
        // Alpha line opacity
        cmd = new DiagramModelObjectOutlineAlphaCommand(target, source.getLineAlpha());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
        // Gradient
        // $NON-NLS-1$
        cmd = new FeatureCommand("", target, IDiagramModelObject.FEATURE_GRADIENT, source.getGradient(), IDiagramModelObject.FEATURE_GRADIENT_DEFAULT);
        if (cmd.canExecute()) {
            result.add(cmd);
        }
        // Icon Visibility, but paste only if the target object has an icon
        IObjectUIProvider provider = ObjectUIFactory.INSTANCE.getProvider(target);
        if (provider instanceof IGraphicalObjectUIProvider && ((IGraphicalObjectUIProvider) provider).hasIcon()) {
            // $NON-NLS-1$
            cmd = new FeatureCommand("", target, IDiagramModelObject.FEATURE_ICON_VISIBLE, source.getIconVisibleState(), IDiagramModelObject.FEATURE_ICON_VISIBLE_DEFAULT);
            if (cmd.canExecute()) {
                result.add(cmd);
            }
        }
    }
    // Archimate objects
    if (pf.getSourceComponent() instanceof IDiagramModelArchimateObject && targetComponent instanceof IDiagramModelArchimateObject) {
        IDiagramModelArchimateObject source = (IDiagramModelArchimateObject) pf.getSourceComponent();
        IDiagramModelArchimateObject target = (IDiagramModelArchimateObject) targetComponent;
        // Image Source
        Command cmd = new // $NON-NLS-1$
        FeatureCommand(// $NON-NLS-1$
        "", // $NON-NLS-1$
        target, // $NON-NLS-1$
        IDiagramModelArchimateObject.FEATURE_IMAGE_SOURCE, source.getImageSource(), IDiagramModelArchimateObject.FEATURE_IMAGE_SOURCE_DEFAULT);
        if (cmd.canExecute()) {
            result.add(cmd);
        }
    }
    // IDiagramModelConnection
    if (pf.getSourceComponent() instanceof IDiagramModelConnection && targetComponent instanceof IDiagramModelConnection) {
        IDiagramModelConnection source = (IDiagramModelConnection) pf.getSourceComponent();
        IDiagramModelConnection target = (IDiagramModelConnection) targetComponent;
        // Connection text position
        Command cmd = new ConnectionTextPositionCommand(target, source.getTextPosition());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
        // If a non-Archimate connection, connection line type
        if (!(target instanceof IDiagramModelArchimateConnection)) {
            cmd = new ConnectionLineTypeCommand(target, source.getType());
            if (cmd.canExecute()) {
                result.add(cmd);
            }
        }
    }
    // IIconic
    if (pf.getSourceComponent() instanceof IIconic && targetComponent instanceof IIconic) {
        IIconic source = (IIconic) pf.getSourceComponent();
        IIconic target = (IIconic) targetComponent;
        // If we have an image path and the source and target models are different, copy the image bytes
        String imagePath = source.getImagePath();
        if (imagePath != null && source.getArchimateModel() != target.getArchimateModel()) {
            IArchiveManager sourceArchiveManager = (IArchiveManager) source.getAdapter(IArchiveManager.class);
            IArchiveManager targetArchiveManager = (IArchiveManager) target.getAdapter(IArchiveManager.class);
            try {
                imagePath = targetArchiveManager.copyImageBytes(sourceArchiveManager, imagePath);
            } catch (IOException ex) {
                ex.printStackTrace();
                // $NON-NLS-1$
                Logger.logError("Could not copy image bytes when copying and pasting objects.", ex);
            }
        }
        // $NON-NLS-1$
        Command cmd = new EObjectFeatureCommand("", target, IArchimatePackage.Literals.DIAGRAM_MODEL_IMAGE_PROVIDER__IMAGE_PATH, imagePath);
        if (cmd.canExecute()) {
            result.add(cmd);
        }
        // Image position
        // $NON-NLS-1$
        cmd = new EObjectFeatureCommand("", target, IArchimatePackage.Literals.ICONIC__IMAGE_POSITION, source.getImagePosition());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
    }
    return result;
}
Also used : FillColorCommand(com.archimatetool.editor.diagram.commands.FillColorCommand) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) FontColorCommand(com.archimatetool.editor.diagram.commands.FontColorCommand) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) FeatureCommand(com.archimatetool.editor.model.commands.FeatureCommand) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) IFontAttribute(com.archimatetool.model.IFontAttribute) LineWidthCommand(com.archimatetool.editor.diagram.commands.LineWidthCommand) FontStyleCommand(com.archimatetool.editor.diagram.commands.FontStyleCommand) DiagramModelObjectOutlineAlphaCommand(com.archimatetool.editor.diagram.commands.DiagramModelObjectOutlineAlphaCommand) ConnectionTextPositionCommand(com.archimatetool.editor.diagram.commands.ConnectionTextPositionCommand) TextAlignmentCommand(com.archimatetool.editor.diagram.commands.TextAlignmentCommand) LineColorCommand(com.archimatetool.editor.diagram.commands.LineColorCommand) ITextPosition(com.archimatetool.model.ITextPosition) IIconic(com.archimatetool.model.IIconic) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IOException(java.io.IOException) IArchiveManager(com.archimatetool.editor.model.IArchiveManager) DiagramModelObjectAlphaCommand(com.archimatetool.editor.diagram.commands.DiagramModelObjectAlphaCommand) ILineObject(com.archimatetool.model.ILineObject) BorderColorCommand(com.archimatetool.editor.diagram.commands.BorderColorCommand) IBorderObject(com.archimatetool.model.IBorderObject) ITextAlignment(com.archimatetool.model.ITextAlignment) FontStyleCommand(com.archimatetool.editor.diagram.commands.FontStyleCommand) DiagramModelObjectAlphaCommand(com.archimatetool.editor.diagram.commands.DiagramModelObjectAlphaCommand) ConnectionTextPositionCommand(com.archimatetool.editor.diagram.commands.ConnectionTextPositionCommand) DiagramModelObjectOutlineAlphaCommand(com.archimatetool.editor.diagram.commands.DiagramModelObjectOutlineAlphaCommand) BorderColorCommand(com.archimatetool.editor.diagram.commands.BorderColorCommand) TextPositionCommand(com.archimatetool.editor.diagram.commands.TextPositionCommand) LineWidthCommand(com.archimatetool.editor.diagram.commands.LineWidthCommand) FontColorCommand(com.archimatetool.editor.diagram.commands.FontColorCommand) TextAlignmentCommand(com.archimatetool.editor.diagram.commands.TextAlignmentCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) ConnectionLineTypeCommand(com.archimatetool.editor.diagram.commands.ConnectionLineTypeCommand) FillColorCommand(com.archimatetool.editor.diagram.commands.FillColorCommand) LineColorCommand(com.archimatetool.editor.diagram.commands.LineColorCommand) FeatureCommand(com.archimatetool.editor.model.commands.FeatureCommand) Command(org.eclipse.gef.commands.Command) ConnectionLineTypeCommand(com.archimatetool.editor.diagram.commands.ConnectionLineTypeCommand) IGraphicalObjectUIProvider(com.archimatetool.editor.ui.factory.IGraphicalObjectUIProvider) ConnectionTextPositionCommand(com.archimatetool.editor.diagram.commands.ConnectionTextPositionCommand) TextPositionCommand(com.archimatetool.editor.diagram.commands.TextPositionCommand) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IObjectUIProvider(com.archimatetool.editor.ui.factory.IObjectUIProvider)

Example 2 with IIconic

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

the class AbstractTextControlContainerFigure method setUI.

@Override
protected void setUI() {
    setLayoutManager(new DelegatingLayout());
    Locator textLocator = new Locator() {

        @Override
        public void relocate(IFigure target) {
            Rectangle bounds = calculateTextControlBounds();
            if (bounds == null) {
                bounds = getBounds().getCopy();
            }
            translateFromParent(bounds);
            target.setBounds(bounds);
        }
    };
    fTextControl = createTextControl(textLocator);
    Locator mainLocator = new Locator() {

        @Override
        public void relocate(IFigure target) {
            Rectangle bounds = getBounds().getCopy();
            translateFromParent(bounds);
            target.setBounds(bounds);
        }
    };
    add(getMainFigure(), mainLocator);
    // If the model object is IIconic
    if (getDiagramModelObject() instanceof IIconic) {
        setIconicDelegate(new IconicDelegate((IIconic) getDiagramModelObject()));
    }
}
Also used : Locator(org.eclipse.draw2d.Locator) DelegatingLayout(org.eclipse.draw2d.DelegatingLayout) IIconic(com.archimatetool.model.IIconic) Rectangle(org.eclipse.draw2d.geometry.Rectangle) IFigure(org.eclipse.draw2d.IFigure)

Example 3 with IIconic

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

the class IconSection method refreshButton.

@Override
protected void refreshButton() {
    super.refreshButton();
    IArchimateModelObject selected = getFirstSelectedObject();
    // If this is an ArchiMate element and we are not using a custom image then disable this
    if (selected instanceof IDiagramModelArchimateObject) {
        int source = ((IDiagramModelArchimateObject) selected).getImageSource();
        fImageButton.setEnabled(source == IDiagramModelArchimateObject.IMAGE_SOURCE_CUSTOM && !isLocked(selected));
    }
    int position = ((IIconic) selected).getImagePosition();
    if (position < IIconic.ICON_POSITION_TOP_LEFT || position > IIconic.ICON_POSITION_FILL) {
        position = IIconic.ICON_POSITION_TOP_RIGHT;
    }
    if (!fIsExecutingCommand) {
        fComboPosition.select(position);
        fComboPosition.setEnabled(!isLocked(selected));
    }
}
Also used : IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) IIconic(com.archimatetool.model.IIconic) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject)

Example 4 with IIconic

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

the class ValueStreamFigure method drawFigure.

@Override
protected void drawFigure(Graphics graphics) {
    if (getFigureDelegate() != null) {
        getFigureDelegate().drawFigure(graphics);
        drawIcon(graphics);
        return;
    }
    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);
    int indent = Math.min(bounds.height / 2, bounds.width / 2);
    int centre_y = bounds.y + bounds.height / 2;
    int point_startx = bounds.x + bounds.width - indent;
    graphics.setAlpha(getAlpha());
    if (!isEnabled()) {
        setDisabledState(graphics);
    }
    // Shape
    Path path = new Path(null);
    path.moveTo(bounds.x, bounds.y);
    path.lineTo(bounds.x + indent, centre_y);
    path.lineTo(bounds.x, bounds.y + bounds.height);
    path.lineTo(point_startx, bounds.y + bounds.height);
    path.lineTo(bounds.x + bounds.width, centre_y);
    path.lineTo(point_startx, bounds.y);
    path.lineTo(bounds.x, bounds.y);
    path.lineTo(bounds.x + indent, centre_y);
    // Fill
    graphics.setBackgroundColor(getFillColor());
    Pattern gradient = applyGradientPattern(graphics, bounds);
    graphics.fillPath(path);
    disposeGradientPattern(graphics, gradient);
    // Outline
    graphics.setForegroundColor(getLineColor());
    graphics.drawPath(path);
    path.dispose();
    // Icon
    // drawIconImage(graphics, bounds);
    int top = 0, right = 0, left = 0, bottom = 0;
    switch(((IIconic) getDiagramModelObject()).getImagePosition()) {
        case IIconic.ICON_POSITION_TOP_LEFT:
        case IIconic.ICON_POSITION_BOTTOM_LEFT:
            left = 10;
            break;
        case IIconic.ICON_POSITION_TOP_RIGHT:
        case IIconic.ICON_POSITION_BOTTOM_RIGHT:
            right = -indent;
            break;
        case IIconic.ICON_POSITION_MIDDLE_LEFT:
            left = indent;
            break;
        case IIconic.ICON_POSITION_MIDDLE_RIGHT:
            right = -10;
            break;
    }
    drawIconImage(graphics, bounds, 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)

Example 5 with IIconic

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

the class ArtifactFigure method drawFigure.

@Override
public 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 path1 = new Path(null);
    path1.moveTo(rect.x, rect.y);
    path1.lineTo(rect.x + rect.width - FOLD_HEIGHT, rect.y);
    path1.lineTo(rect.x + rect.width, rect.y + FOLD_HEIGHT);
    path1.lineTo(rect.x + rect.width, rect.y + rect.height);
    path1.lineTo(rect.x, rect.y + rect.height);
    path1.close();
    graphics.fillPath(path1);
    disposeGradientPattern(graphics, gradient);
    // Fold
    graphics.setBackgroundColor(ColorFactory.getDarkerColor(getFillColor()));
    Path path2 = new Path(null);
    path2.moveTo(rect.x + rect.width - FOLD_HEIGHT, rect.y);
    path2.lineTo(rect.x + rect.width, rect.y + FOLD_HEIGHT);
    path2.lineTo(rect.x + rect.width - FOLD_HEIGHT, rect.y + FOLD_HEIGHT);
    graphics.fillPath(path2);
    path2.dispose();
    // Lines
    graphics.setAlpha(getLineAlpha());
    graphics.setForegroundColor(getLineColor());
    graphics.drawPath(path1);
    path1.dispose();
    Path path3 = new Path(null);
    path3.moveTo(rect.x + rect.width, rect.y + FOLD_HEIGHT);
    path3.lineTo(rect.x + rect.width - FOLD_HEIGHT, rect.y + FOLD_HEIGHT);
    path3.lineTo(rect.x + rect.width - FOLD_HEIGHT, rect.y);
    graphics.drawPath(path3);
    path3.dispose();
    // Icon
    // drawIconImage(graphics, bounds);
    int rightOffset = ((IIconic) getDiagramModelObject()).getImagePosition() == IIconic.ICON_POSITION_TOP_RIGHT ? -(FOLD_HEIGHT + 1) : 0;
    // int rightOffset = -(FOLD_HEIGHT + 1);
    drawIconImage(graphics, rect, 0, rightOffset, 0, 0);
    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