Skip to content

Commit

Permalink
Support Line Style on diagram objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Phillipus committed Nov 13, 2024
1 parent 77829ba commit 0e1d5fe
Show file tree
Hide file tree
Showing 37 changed files with 595 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public ImageDescriptor getImageDescriptor() {
public boolean shouldExposeFeature(String featureName) {
if(featureName == IArchimatePackage.Literals.LINE_OBJECT__LINE_COLOR.getName() ||
featureName == IArchimatePackage.Literals.LINE_OBJECT__LINE_WIDTH.getName() ||
featureName == IDiagramModelObject.FEATURE_LINE_STYLE ||
featureName == IDiagramModelObject.FEATURE_DERIVE_ELEMENT_LINE_COLOR ||
featureName == IDiagramModelObject.FEATURE_GRADIENT) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ private void drawFigure(Graphics graphics, Color background) {
// Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
setLineWidth(graphics, bounds);

setLineStyle(graphics);

graphics.setBackgroundColor(background);
graphics.fillRectangle(bounds);

Expand Down
12 changes: 6 additions & 6 deletions com.archimatetool.editor/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,13 @@
</propertySection>
<propertySection
afterSection="lineSection"
class="com.archimatetool.editor.propertysections.LineOpacitySection"
filter="com.archimatetool.editor.propertysections.LineOpacitySection$Filter"
id="lineOpacitySection"
class="com.archimatetool.editor.propertysections.LineSection2"
filter="com.archimatetool.editor.propertysections.LineSection2$Filter"
id="lineSection2"
tab="appearance.tab">
</propertySection>
<propertySection
afterSection="lineOpacitySection"
afterSection="lineSection2"
class="com.archimatetool.editor.propertysections.IconColorSection"
filter="com.archimatetool.editor.propertysections.IconColorSection$Filter"
id="iconColorSection"
Expand All @@ -451,7 +451,7 @@
tab="appearance.tab">
</propertySection>
<propertySection
afterSection="lineOpacitySection"
afterSection="lineSection2"
class="com.archimatetool.editor.propertysections.GroupBorderTypeSection"
filter="com.archimatetool.editor.propertysections.GroupBorderTypeSection$Filter"
id="groupBorderTypeSection"
Expand Down Expand Up @@ -491,7 +491,7 @@
tab="appearance.tab">
</propertySection>
<propertySection
afterSection="lineOpacitySection"
afterSection="lineSection2"
class="com.archimatetool.editor.propertysections.NoteBorderTypeSection"
filter="com.archimatetool.editor.propertysections.NoteBorderTypeSection$Filter"
id="noteBorderTypeSection"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* This program and the accompanying materials
* are made available under the terms of the License
* which accompanies this distribution in the file LICENSE.txt
*/
package com.archimatetool.editor.diagram.commands;

import com.archimatetool.editor.model.commands.FeatureCommand;
import com.archimatetool.model.IDiagramModelObject;



/**
* Line Style Command
*
* @author Phillip Beauvoir
*/
public class DiagramModelObjectLineStyleCommand extends FeatureCommand {

public DiagramModelObjectLineStyleCommand(IDiagramModelObject object, int style, int defaultValue) {
super(Messages.DiagramModelObjectLineStyleCommand_0, object, IDiagramModelObject.FEATURE_LINE_STYLE, style, defaultValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class Messages extends NLS {

public static String DiagramModelObjectAlphaCommand_0;

public static String DiagramModelObjectLineStyleCommand_0;

public static String DiagramModelObjectOutlineAlphaCommand_0;

public static String FillColorCommand_0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ CreateDiagramObjectCommand_0=Create {0}
DeleteBendpointCommand_0=Remove Bendpoint
DiagramModelObjectAlphaCommand_0=Change Opacity
DiagramModelObjectLineStyleCommand_0=Change Line Style
DiagramModelObjectOutlineAlphaCommand_0=Change Opacity
FillColorCommand_0=Change Fill Colour
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.archimatetool.editor.ui.FontFactory;
import com.archimatetool.editor.ui.ImageFactory;
import com.archimatetool.editor.ui.factory.IGraphicalObjectUIProvider;
import com.archimatetool.editor.ui.factory.IObjectUIProvider;
import com.archimatetool.editor.ui.factory.ObjectUIFactory;
import com.archimatetool.editor.utils.StringUtils;
import com.archimatetool.model.IArchimateElement;
Expand Down Expand Up @@ -142,6 +143,27 @@ protected void setDisabledState(Graphics graphics) {
//graphics.setLineStyle(SWT.LINE_DASH);
//graphics.setLineDash(new int[] { 4, 3 });
}

/**
* Set the line style
* @param graphics
*/
protected void setLineStyle(Graphics graphics) {
double scale = Math.min(FigureUtils.getFigureScale(this), 1.0); // only scale below 1.0

switch(getLineStyle()) {
case IDiagramModelObject.LINE_STYLE_SOLID:
default:
graphics.setLineStyle(Graphics.LINE_SOLID);
break;
case IDiagramModelObject.LINE_STYLE_DASHED:
graphics.setLineDash(new float[] { (float)(8 * scale), (float)(4 * scale) });
break;
case IDiagramModelObject.LINE_STYLE_DOTTED:
graphics.setLineDash(new float[] { (float)(2 * scale), (float)(4 * scale) });
break;
}
}

/**
* Set the UI
Expand Down Expand Up @@ -247,6 +269,11 @@ protected int getLineWidth() {
return fDiagramModelObject.getLineWidth();
}

protected int getLineStyle() {
IObjectUIProvider provider = ObjectUIFactory.INSTANCE.getProvider(getDiagramModelObject());
return provider != null && provider.getFeatureValue(IDiagramModelObject.FEATURE_LINE_STYLE) instanceof Integer val ? val : IDiagramModelObject.LINE_STYLE_SOLID;
}

@Override
public void updateIconImage() {
if(getIconicDelegate() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ protected void setLineWidth(Graphics graphics, int lineWidth, Rectangle bounds)
getOwner().setLineWidth(graphics, lineWidth, bounds);
}

/**
* Set line style
* @param graphics
*/
protected void setLineStyle(Graphics graphics) {
getOwner().setLineStyle(graphics);
}

/**
* Apply a gradient to the given Graphics instance and bounds using current fill color, alpha and gradient settings
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public void drawFigure(Graphics graphics) {
// Line Width
setLineWidth(graphics, bounds);

setLineStyle(graphics);

graphics.setAlpha(getAlpha());

if(!isEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public void drawFigure(Graphics graphics) {

// Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
setLineWidth(graphics, bounds);

setLineStyle(graphics);

graphics.setAlpha(getAlpha());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public void drawFigure(Graphics graphics) {

// Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
setLineWidth(graphics, bounds);

setLineStyle(graphics);

graphics.setAlpha(getAlpha());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ protected void paintFigure(Graphics graphics) {
// Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
setLineWidth(graphics, bounds);

setLineStyle(graphics);

if(fImage != null) {
// Faster but no transparency
if(useScaledImage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ protected void drawFigure(Graphics graphics) {
// Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
setLineWidth(graphics, bounds);

setLineStyle(graphics);

graphics.setAlpha(getAlpha());

if(getDiagramModelObject().getBorderType() == IDiagramModelGroup.BORDER_TABBED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ protected void paintFigure(Graphics graphics) {
// Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
if(getDiagramModelObject().getBorderType() != IDiagramModelNote.BORDER_NONE) {
setLineWidth(graphics, bounds);
setLineStyle(graphics);
}

// Fill
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ protected void drawFigure(Graphics graphics) {

// Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
setLineWidth(graphics, bounds);

setLineStyle(graphics);

PointList points = new PointList();
points.addPoint(bounds.x + FLANGE, bounds.y);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ protected void drawFigure(Graphics graphics) {
// Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
setLineWidth(graphics, bounds);

// Scale line dashes below 1.0
double scale = Math.min(FigureUtils.getGraphicsScale(graphics), 1.0);

graphics.setLineDash(new float[] { (float)(8 * scale), (float)(4 * scale) });
setLineStyle(graphics);

graphics.setBackgroundColor(getFillColor());
graphics.setForegroundColor(getLineColor());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ protected void drawFigure(Graphics graphics) {

// Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
setLineWidth(graphics, bounds);

setLineStyle(graphics);

graphics.setBackgroundColor(getFillColor());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.archimatetool.editor.diagram.commands.ConnectionLineTypeCommand;
import com.archimatetool.editor.diagram.commands.ConnectionTextPositionCommand;
import com.archimatetool.editor.diagram.commands.DiagramModelObjectAlphaCommand;
import com.archimatetool.editor.diagram.commands.DiagramModelObjectLineStyleCommand;
import com.archimatetool.editor.diagram.commands.DiagramModelObjectOutlineAlphaCommand;
import com.archimatetool.editor.diagram.commands.FillColorCommand;
import com.archimatetool.editor.diagram.commands.FontColorCommand;
Expand Down Expand Up @@ -112,6 +113,8 @@ CompoundCommand createCommand(IDiagramModelComponent targetComponent) {
CompoundCommand result = new CompoundCommand(Messages.FormatPainterTool_0);

IDiagramModelComponent sourceComponent = FormatPainterInfo.INSTANCE.getSourceComponent();

IObjectUIProvider sourceUIProvider = ObjectUIFactory.INSTANCE.getProvider(sourceComponent);
IObjectUIProvider targetUIProvider = ObjectUIFactory.INSTANCE.getProvider(targetComponent);

// IFontAttribute
Expand Down Expand Up @@ -212,6 +215,15 @@ CompoundCommand createCommand(IDiagramModelComponent targetComponent) {
result.add(cmd);
}

// Line Style
if(targetUIProvider != null && sourceUIProvider != null && targetUIProvider.shouldExposeFeature(IDiagramModelObject.FEATURE_LINE_STYLE)) {
cmd = new DiagramModelObjectLineStyleCommand(target, (int)sourceUIProvider.getFeatureValue(IDiagramModelObject.FEATURE_LINE_STYLE),
(int)targetUIProvider.getDefaultFeatureValue(IDiagramModelObject.FEATURE_LINE_STYLE));
if(cmd.canExecute()) {
result.add(cmd);
}
}

// Gradient
if(targetUIProvider != null && targetUIProvider.shouldExposeFeature(IDiagramModelObject.FEATURE_GRADIENT)) {
cmd = new FeatureCommand("", target, IDiagramModelObject.FEATURE_GRADIENT, source.getGradient(), IDiagramModelObject.FEATURE_GRADIENT_DEFAULT); //$NON-NLS-1$
Expand Down

This file was deleted.

Loading

0 comments on commit 0e1d5fe

Please sign in to comment.