Skip to content

Commit

Permalink
Line Style 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Phillipus committed Oct 6, 2024
1 parent 434787c commit ed9a5bb
Show file tree
Hide file tree
Showing 11 changed files with 256 additions and 0 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
7 changes: 7 additions & 0 deletions com.archimatetool.editor/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,13 @@
id="lineOpacitySection"
tab="appearance.tab">
</propertySection>
<propertySection
afterSection="lineOpacitySection"
class="com.archimatetool.editor.propertysections.DiagramObjectLineStyleSection"
filter="com.archimatetool.editor.propertysections.DiagramObjectLineStyleSection$Filter"
id="lineStyleSection"
tab="appearance.tab">
</propertySection>
<propertySection
afterSection="lineOpacitySection"
class="com.archimatetool.editor.propertysections.IconColorSection"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* 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) {
super("Change Line Style", object,
IDiagramModelObject.FEATURE_LINE_STYLE, style, IDiagramModelObject.FEATURE_LINE_STYLE_DEFAULT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,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 0:
default:
graphics.setLineStyle(Graphics.LINE_SOLID);
break;
case 1:
graphics.setLineDash(new float[] { (float)(8 * scale), (float)(4 * scale) });
break;
case 2:
graphics.setLineDash(new float[] { (float)(1 * scale), (float)(4 * scale) });
break;
}
}

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

protected int getLineStyle() {
return fDiagramModelObject.getLineStyle();
}

@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 @@ -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 @@ -212,6 +212,14 @@ CompoundCommand createCommand(IDiagramModelComponent targetComponent) {
result.add(cmd);
}

// Line Style
if(targetUIProvider != null && targetUIProvider.shouldExposeFeature(IDiagramModelObject.FEATURE_LINE_STYLE)) {
cmd = new FeatureCommand("", target, IDiagramModelObject.FEATURE_LINE_STYLE, source.getLineStyle(), IDiagramModelObject.FEATURE_LINE_STYLE_DEFAULT); //$NON-NLS-1$
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/**
* 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.propertysections;

import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.PlatformUI;

import com.archimatetool.editor.diagram.commands.DiagramModelObjectLineStyleCommand;
import com.archimatetool.editor.ui.IArchiImages;
import com.archimatetool.model.IArchimatePackage;
import com.archimatetool.model.IDiagramModelObject;



/**
* Diagram Object Line Style Property Section
*
* @author Phillip Beauvoir
*/
public class DiagramObjectLineStyleSection extends AbstractECorePropertySection {

private static final String HELP_ID = "com.archimatetool.help.elementPropertySection"; //$NON-NLS-1$

/**
* Filter to show or reject this section depending on input value
*/
public static class Filter extends ObjectFilter {
@Override
public boolean isRequiredType(Object object) {
return object instanceof IDiagramModelObject dmo && shouldExposeFeature(dmo, IDiagramModelObject.FEATURE_LINE_STYLE);
}

@Override
public Class<?> getAdaptableType() {
return IDiagramModelObject.class;
}
}

private Button button;

@Override
protected void createControls(Composite parent) {
createLabel(parent, "Line Style:", ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.CENTER);

button = getWidgetFactory().createButton(parent, null, SWT.PUSH);

button.addSelectionListener(widgetSelectedAdapter(event -> {
MenuManager menuManager = new MenuManager();

menuManager.add(createAction("Solid", 0, IArchiImages.ImageFactory.getImageDescriptor(IArchiImages.LINE_SOLID)));
menuManager.add(createAction("Dashed", 1, IArchiImages.ImageFactory.getImageDescriptor(IArchiImages.LINE_DASHED)));
menuManager.add(createAction("Dotted", 2, IArchiImages.ImageFactory.getImageDescriptor(IArchiImages.LINE_DOTTED)));

Menu menu = menuManager.createContextMenu(button.getShell());
Rectangle buttonBounds = button.getBounds();
Point p = button.getParent().toDisplay(buttonBounds.x, buttonBounds.y + buttonBounds.height);
menu.setLocation(p);
menu.setVisible(true);
}));

// Help ID
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
}

private IAction createAction(String text, final int value, final ImageDescriptor imageDesc) {
IAction action = new Action(text, IAction.AS_RADIO_BUTTON) {
@Override
public void run() {
CompoundCommand result = new CompoundCommand();

for(EObject object : getEObjects()) {
if(isAlive(object)) {
Command cmd = new DiagramModelObjectLineStyleCommand((IDiagramModelObject)object, value);
if(cmd.canExecute()) {
result.add(cmd);
}
}
}

executeCommand(result.unwrap());
}

@Override
public ImageDescriptor getImageDescriptor() {
return imageDesc;
}
};

action.setChecked(((IDiagramModelObject)getFirstSelectedObject()).getLineStyle() == value);

return action;
}


@Override
protected void notifyChanged(Notification msg) {
if(msg.getNotifier() == getFirstSelectedObject()) {
Object feature = msg.getFeature();

if(isFeatureNotification(msg, IDiagramModelObject.FEATURE_LINE_STYLE) ||
feature == IArchimatePackage.Literals.LOCKABLE__LOCKED) {
update();
}
}
}

@Override
protected void update() {
int lineStyle = ((IDiagramModelObject)getFirstSelectedObject()).getLineStyle();

switch(lineStyle) {
case 0:
default:
button.setImage(IArchiImages.ImageFactory.getImage(IArchiImages.LINE_SOLID));
break;
case 1:
button.setImage(IArchiImages.ImageFactory.getImage(IArchiImages.LINE_DASHED));
break;
case 2:
button.setImage(IArchiImages.ImageFactory.getImage(IArchiImages.LINE_DOTTED));
break;
}

boolean enabled = !isLocked(getFirstSelectedObject());
button.setEnabled(enabled);
}

@Override
protected IObjectFilter getFilter() {
return new Filter();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public interface IDiagramModelObject extends IConnectable, IFontAttribute, ILine
String FEATURE_DERIVE_ELEMENT_LINE_COLOR = "deriveElementLineColor";
boolean FEATURE_DERIVE_ELEMENT_LINE_COLOR_DEFAULT = true;

String FEATURE_LINE_STYLE = "lineStyle";
int FEATURE_LINE_STYLE_DEFAULT = 0;

/**
* @return the value of FEATURE_LINE_ALPHA
*/
Expand Down Expand Up @@ -100,6 +103,17 @@ public interface IDiagramModelObject extends IConnectable, IFontAttribute, ILine
*/
void setDeriveElementLineColor(boolean value);

/**
* @return the value of feature FEATURE_LINE_STYLE
*/
int getLineStyle();

/**
* Set the value of feature FEATURE_LINE_STYLE
* @param lineStyle
*/
void setLineStyle(int lineStyle);

/**
* Returns the value of the '<em><b>Bounds</b></em>' containment reference.
* <!-- begin-user-doc -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,16 @@ public void setDeriveElementLineColor(boolean value) {
getFeatures().putBoolean(FEATURE_DERIVE_ELEMENT_LINE_COLOR, value, FEATURE_DERIVE_ELEMENT_LINE_COLOR_DEFAULT);
}

@Override
public int getLineStyle() {
return getFeatures().getInt(FEATURE_LINE_STYLE, FEATURE_LINE_STYLE_DEFAULT);
}

@Override
public void setLineStyle(int lineStyle) {
getFeatures().putInt(FEATURE_LINE_STYLE, lineStyle, FEATURE_LINE_STYLE_DEFAULT);
}

/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ public void testGetLineColor() {
assertEquals("#ffffff", object.getLineColor());
}

@Test
public void testGetLineStyle() {
assertEquals(0, object.getLineStyle());
object.setLineStyle(1);
assertEquals(1, object.getLineStyle());
}

@Test
public void testAddConnection_Null_ThrowsException() {
assertThrows(IllegalArgumentException.class, () -> {
Expand Down

0 comments on commit ed9a5bb

Please sign in to comment.