diff --git a/com.archimatetool.canvas/src/com/archimatetool/canvas/factory/CanvasBlockUIProvider.java b/com.archimatetool.canvas/src/com/archimatetool/canvas/factory/CanvasBlockUIProvider.java index 2895dc956..77ddb94d1 100644 --- a/com.archimatetool.canvas/src/com/archimatetool/canvas/factory/CanvasBlockUIProvider.java +++ b/com.archimatetool.canvas/src/com/archimatetool/canvas/factory/CanvasBlockUIProvider.java @@ -61,7 +61,8 @@ public ImageDescriptor getImageDescriptor() { @Override public boolean shouldExposeFeature(String featureName) { if(featureName == IArchimatePackage.Literals.LINE_OBJECT__LINE_COLOR.getName() || - featureName == IDiagramModelObject.FEATURE_GRADIENT) { + featureName == IDiagramModelObject.FEATURE_GRADIENT || + featureName == IDiagramModelObject.FEATURE_DERIVE_ELEMENT_LINE_COLOR) { return false; } diff --git a/com.archimatetool.canvas/src/com/archimatetool/canvas/factory/CanvasStickyUIProvider.java b/com.archimatetool.canvas/src/com/archimatetool/canvas/factory/CanvasStickyUIProvider.java index 3e8dbf056..576c56627 100644 --- a/com.archimatetool.canvas/src/com/archimatetool/canvas/factory/CanvasStickyUIProvider.java +++ b/com.archimatetool.canvas/src/com/archimatetool/canvas/factory/CanvasStickyUIProvider.java @@ -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_DERIVE_ELEMENT_LINE_COLOR || featureName == IDiagramModelObject.FEATURE_GRADIENT) { return false; } diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/actions/LineColorAction.java b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/actions/LineColorAction.java index 1d52b4466..e42886611 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/actions/LineColorAction.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/actions/LineColorAction.java @@ -14,9 +14,7 @@ import org.eclipse.swt.graphics.RGB; import org.eclipse.ui.IWorkbenchPart; -import com.archimatetool.editor.ArchiPlugin; import com.archimatetool.editor.diagram.commands.LineColorCommand; -import com.archimatetool.editor.preferences.IPreferenceConstants; import com.archimatetool.editor.ui.ColorFactory; import com.archimatetool.editor.ui.components.CustomColorDialog; import com.archimatetool.editor.ui.factory.IObjectUIProvider; @@ -117,9 +115,9 @@ private boolean shouldEnable(Object model) { return false; } - if(model instanceof IDiagramModelObject) { + if(model instanceof IDiagramModelObject dmo) { // Disable if diagram model object line colours are derived from fill colours as set in Prefs - if(ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.DERIVE_ELEMENT_LINE_COLOR)) { + if(dmo.getDeriveElementLineColor()) { return false; } } diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/AbstractBaseEditPart.java b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/AbstractBaseEditPart.java index d9c1253b6..02b99a1f9 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/AbstractBaseEditPart.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/editparts/AbstractBaseEditPart.java @@ -79,8 +79,7 @@ protected void applicationPreferencesChanged(PropertyChangeEvent event) { // Default font or colour preferences changed if(IPreferenceConstants.DEFAULT_VIEW_FONT.equals(event.getProperty()) || event.getProperty().startsWith(IPreferenceConstants.DEFAULT_FILL_COLOR_PREFIX) || - event.getProperty().equals(IPreferenceConstants.DEFAULT_ELEMENT_LINE_COLOR) || - event.getProperty().startsWith(IPreferenceConstants.DERIVE_ELEMENT_LINE_COLOR)) { + event.getProperty().equals(IPreferenceConstants.DEFAULT_ELEMENT_LINE_COLOR)) { refreshFigure(); } diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/figures/AbstractDiagramModelObjectFigure.java b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/figures/AbstractDiagramModelObjectFigure.java index 670d8d9b9..e9f6ee091 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/figures/AbstractDiagramModelObjectFigure.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/figures/AbstractDiagramModelObjectFigure.java @@ -227,9 +227,8 @@ protected void setLineColor() { public Color getLineColor() { if(fLineColor == null) { // User preference to derive element line colour - if(ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.DERIVE_ELEMENT_LINE_COLOR)) { - fLineColor = ColorFactory.getDarkerColor(getFillColor(), - ArchiPlugin.PREFERENCES.getInt(IPreferenceConstants.DERIVE_ELEMENT_LINE_COLOR_FACTOR) / 10f); + if(fDiagramModelObject.getDeriveElementLineColor()) { + fLineColor = ColorFactory.getDerivedLineColor(getFillColor()); } else { fLineColor = ColorFactory.get(fDiagramModelObject.getLineColor()); diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/sketch/SketchModelFactory.java b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/sketch/SketchModelFactory.java index 41941ab63..3b0adf591 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/sketch/SketchModelFactory.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/sketch/SketchModelFactory.java @@ -64,20 +64,22 @@ public Object getNewObject() { EObject object = IArchimateFactory.eINSTANCE.create(fTemplate); // Actor - if(object instanceof ISketchModelActor) { - ((ISketchModelActor)object).setName(ArchiLabelProvider.INSTANCE.getDefaultName(fTemplate)); + if(object instanceof ISketchModelActor actor) { + actor.setName(ArchiLabelProvider.INSTANCE.getDefaultName(fTemplate)); } // Sticky - else if(object instanceof ISketchModelSticky) { - ISketchModelSticky sticky = (ISketchModelSticky)object; + else if(object instanceof ISketchModelSticky sticky) { sticky.setName(ArchiLabelProvider.INSTANCE.getDefaultName(fTemplate)); + // Derive element line color + sticky.setDeriveElementLineColor(ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.DERIVE_ELEMENT_LINE_COLOR)); + // Gradient sticky.setGradient(ArchiPlugin.PREFERENCES.getInt(IPreferenceConstants.DEFAULT_GRADIENT)); - if(fParam instanceof RGB) { - String color = ColorFactory.convertRGBToString((RGB)fParam); + if(fParam instanceof RGB rgb) { + String color = ColorFactory.convertRGBToString(rgb); sticky.setFillColor(color); Color lineColor = ColorFactory.getDefaultLineColor(sticky); @@ -88,8 +90,7 @@ else if(object instanceof ISketchModelSticky) { } // Group - else if(object instanceof IDiagramModelGroup) { - IDiagramModelGroup group = (IDiagramModelGroup)object; + else if(object instanceof IDiagramModelGroup group) { group.setName(ArchiLabelProvider.INSTANCE.getDefaultName(fTemplate)); ColorFactory.setDefaultColors(group); // Gradient @@ -97,11 +98,9 @@ else if(object instanceof IDiagramModelGroup) { } // Connection - else if(object instanceof IDiagramModelConnection) { - IDiagramModelConnection connection = (IDiagramModelConnection)object; - - if(fParam instanceof Integer) { - connection.setType((Integer)fParam); + else if(object instanceof IDiagramModelConnection connection) { + if(fParam instanceof Integer i) { + connection.setType(i); } ColorFactory.setDefaultColors(connection); @@ -109,18 +108,18 @@ else if(object instanceof IDiagramModelConnection) { IGraphicalObjectUIProvider provider = (IGraphicalObjectUIProvider)ObjectUIFactory.INSTANCE.getProvider(object); - if(object instanceof ITextAlignment) { - ((ITextAlignment)object).setTextAlignment(provider.getDefaultTextAlignment()); + if(object instanceof ITextAlignment ta) { + ta.setTextAlignment(provider.getDefaultTextAlignment()); } - if(object instanceof ITextPosition) { - ((ITextPosition)object).setTextPosition(provider.getDefaultTextPosition()); + if(object instanceof ITextPosition tp) { + tp.setTextPosition(provider.getDefaultTextPosition()); } // Add new bounds with a default user size - if(object instanceof IDiagramModelObject) { + if(object instanceof IDiagramModelObject dmo) { Dimension size = provider.getDefaultSize(); - ((IDiagramModelObject)object).setBounds(0, 0, size.width, size.height); + dmo.setBounds(0, 0, size.width, size.height); } return object; diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/tools/FormatPainterTool.java b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/tools/FormatPainterTool.java index e6f775f68..1c4cdec49 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/tools/FormatPainterTool.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/tools/FormatPainterTool.java @@ -211,6 +211,14 @@ protected CompoundCommand createCommand(PaintFormat pf, IDiagramModelComponent t } } + // Derive line color + if(provider != null && provider.shouldExposeFeature(IDiagramModelObject.FEATURE_DERIVE_ELEMENT_LINE_COLOR)) { + cmd = new FeatureCommand("", target, IDiagramModelObject.FEATURE_DERIVE_ELEMENT_LINE_COLOR, source.getDeriveElementLineColor(), IDiagramModelObject.FEATURE_DERIVE_ELEMENT_LINE_COLOR_DEFAULT); //$NON-NLS-1$ + if(cmd.canExecute()) { + result.add(cmd); + } + } + // Icon Visibility and Color, but paste only if the target object has an icon if(provider instanceof IGraphicalObjectUIProvider && ((IGraphicalObjectUIProvider)provider).hasIcon()) { // Icon visible diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/preferences/ColoursPreferencePage.java b/com.archimatetool.editor/src/com/archimatetool/editor/preferences/ColoursPreferencePage.java index 33086e56d..9dc862ae4 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/preferences/ColoursPreferencePage.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/preferences/ColoursPreferencePage.java @@ -40,9 +40,7 @@ import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Spinner; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; import org.eclipse.ui.PlatformUI; @@ -87,14 +85,9 @@ public class ColoursPreferencePage private Button fResetFillColorButton; private Button fDeriveElementLineColorsButton; - // Spinner - private Spinner fElementLineColorContrastSpinner; - // Tree private TreeViewer fTreeViewer; - private Label fContrastFactorLabel; - private IPropertyChangeListener themeChangeListener; private static List themeColors = List.of(VIEW_BACKGROUND_COLOR, @@ -381,37 +374,14 @@ public void widgetSelected(SelectionEvent e) { } }); - Group elementColorGroup = new Group(client, SWT.NULL); - elementColorGroup.setLayout(new GridLayout(2, false)); - elementColorGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - elementColorGroup.setText(Messages.ColoursPreferencePage_17); - // Derive element line colours - fDeriveElementLineColorsButton = new Button(elementColorGroup, SWT.CHECK); + fDeriveElementLineColorsButton = new Button(client, SWT.CHECK); fDeriveElementLineColorsButton.setText(Messages.ColoursPreferencePage_18); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = 2; fDeriveElementLineColorsButton.setLayoutData(gd); fDeriveElementLineColorsButton.setSelection(getPreferenceStore().getBoolean(DERIVE_ELEMENT_LINE_COLOR)); - fDeriveElementLineColorsButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - fElementLineColorContrastSpinner.setEnabled(fDeriveElementLineColorsButton.getSelection()); - fContrastFactorLabel.setEnabled(fDeriveElementLineColorsButton.getSelection()); - } - }); - - fContrastFactorLabel = new Label(elementColorGroup, SWT.NULL); - fContrastFactorLabel.setText(Messages.ColoursPreferencePage_19); - - fElementLineColorContrastSpinner = new Spinner(elementColorGroup, SWT.BORDER); - fElementLineColorContrastSpinner.setMinimum(1); - fElementLineColorContrastSpinner.setMaximum(10); - fElementLineColorContrastSpinner.setSelection(getPreferenceStore().getInt(DERIVE_ELEMENT_LINE_COLOR_FACTOR)); - label = new Label(elementColorGroup, SWT.NULL); - label.setText(Messages.ColoursPreferencePage_20); - gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = 2; @@ -585,7 +555,6 @@ private void resetColorsCache(boolean useInbuiltDefaults) { @Override public boolean performOk() { getPreferenceStore().setValue(DERIVE_ELEMENT_LINE_COLOR, fDeriveElementLineColorsButton.getSelection()); - getPreferenceStore().setValue(DERIVE_ELEMENT_LINE_COLOR_FACTOR, fElementLineColorContrastSpinner.getSelection()); getPreferenceStore().setValue(SAVE_USER_DEFAULT_COLOR, fPersistUserDefaultColors.getSelection()); saveColors(getPreferenceStore(), true); @@ -599,8 +568,6 @@ protected void performDefaults() { fDeriveElementLineColorsButton.setSelection(getPreferenceStore().getDefaultBoolean(DERIVE_ELEMENT_LINE_COLOR)); fPersistUserDefaultColors.setSelection(getPreferenceStore().getDefaultBoolean(SAVE_USER_DEFAULT_COLOR)); - fElementLineColorContrastSpinner.setSelection(getPreferenceStore().getDefaultInt(DERIVE_ELEMENT_LINE_COLOR_FACTOR)); - // Set color cache to inbuilt defaults resetColorsCache(true); diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/preferences/IPreferenceConstants.java b/com.archimatetool.editor/src/com/archimatetool/editor/preferences/IPreferenceConstants.java index cb9907c50..61ea97748 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/preferences/IPreferenceConstants.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/preferences/IPreferenceConstants.java @@ -30,7 +30,6 @@ public interface IPreferenceConstants { String FOLDER_COLOUR_PREFIX = "folderColour_"; String DERIVE_ELEMENT_LINE_COLOR = "deriveElementLineColor"; - String DERIVE_ELEMENT_LINE_COLOR_FACTOR = "deriveElementLineColorFactor"; String SAVE_USER_DEFAULT_COLOR = "saveUserDefaultFillColorInFile"; // Theme Color Definition IDs diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/preferences/Messages.java b/com.archimatetool.editor/src/com/archimatetool/editor/preferences/Messages.java index bcc2abcac..b0aed305a 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/preferences/Messages.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/preferences/Messages.java @@ -39,16 +39,10 @@ public class Messages extends NLS { public static String ColoursPreferencePage_16; - public static String ColoursPreferencePage_17; - public static String ColoursPreferencePage_18; - public static String ColoursPreferencePage_19; - public static String ColoursPreferencePage_2; - public static String ColoursPreferencePage_20; - public static String ColoursPreferencePage_21; public static String ColoursPreferencePage_22; diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/preferences/PreferenceInitializer.java b/com.archimatetool.editor/src/com/archimatetool/editor/preferences/PreferenceInitializer.java index d19f30c97..990e72c99 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/preferences/PreferenceInitializer.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/preferences/PreferenceInitializer.java @@ -42,7 +42,6 @@ public void initializeDefaultPreferences() { // Colours store.setDefault(DERIVE_ELEMENT_LINE_COLOR, true); - store.setDefault(DERIVE_ELEMENT_LINE_COLOR_FACTOR, 7); store.setDefault(SAVE_USER_DEFAULT_COLOR, false); // Fonts diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/preferences/messages.properties b/com.archimatetool.editor/src/com/archimatetool/editor/preferences/messages.properties index 86c330e5b..88ccc57eb 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/preferences/messages.properties +++ b/com.archimatetool.editor/src/com/archimatetool/editor/preferences/messages.properties @@ -13,11 +13,8 @@ ColoursPreferencePage_13=Edit... ColoursPreferencePage_14=Reset ColoursPreferencePage_15=Import Scheme... ColoursPreferencePage_16=Export Scheme... -ColoursPreferencePage_17=Element line colour -ColoursPreferencePage_18=Derive element line colours from fill colours -ColoursPreferencePage_19=Contrast factor: +ColoursPreferencePage_18=Derive element line colours from fill colours (default for new objects) ColoursPreferencePage_2=Business elements -ColoursPreferencePage_20=Disabling this option will enable user element line colours ColoursPreferencePage_21=Save the default colours for elements in the model file ColoursPreferencePage_22=Import ColoursPreferencePage_23=Export diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineColorSection.java b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineColorSection.java index f93c2729f..d36190a73 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineColorSection.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/LineColorSection.java @@ -10,6 +10,8 @@ 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.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.swt.SWT; @@ -20,6 +22,7 @@ import com.archimatetool.editor.ArchiPlugin; import com.archimatetool.editor.diagram.commands.LineColorCommand; +import com.archimatetool.editor.model.commands.FeatureCommand; import com.archimatetool.editor.preferences.IPreferenceConstants; import com.archimatetool.editor.ui.ColorFactory; import com.archimatetool.editor.ui.components.ColorChooser; @@ -107,7 +110,6 @@ else if(event.getProperty() == ColorChooser.PROP_COLORDEFAULT) { public void propertyChange(PropertyChangeEvent event) { if(event.getProperty().equals(IPreferenceConstants.DEFAULT_ELEMENT_LINE_COLOR) || event.getProperty().equals(IPreferenceConstants.DEFAULT_CONNECTION_LINE_COLOR) || - event.getProperty().equals(IPreferenceConstants.DERIVE_ELEMENT_LINE_COLOR) || event.getProperty().equals(IPreferenceConstants.SAVE_USER_DEFAULT_COLOR)) { // This will affect the "Default" menu in color chooser update(); } @@ -115,6 +117,8 @@ public void propertyChange(PropertyChangeEvent event) { }; private ColorChooser fColorChooser; + private Action fDeriveLineColorAction; + @Override protected void createControls(Composite parent) { @@ -131,6 +135,26 @@ private void createColorControl(Composite parent) { fColorChooser = new ColorChooser(parent, getWidgetFactory()); fColorChooser.addListener(colorListener); + + // Derive line color from fill color action + fDeriveLineColorAction = new Action(Messages.LineColorSection_3, IAction.AS_CHECK_BOX) { + @Override + public void run() { + CompoundCommand result = new CompoundCommand(); + + for(EObject object : getEObjects()) { + if(isAlive(object) && object instanceof IDiagramModelObject dmo) { + Command cmd = new FeatureCommand(Messages.LineColorSection_4, dmo, IDiagramModelObject.FEATURE_DERIVE_ELEMENT_LINE_COLOR, + fDeriveLineColorAction.isChecked(), IDiagramModelObject.FEATURE_DERIVE_ELEMENT_LINE_COLOR_DEFAULT); + if(cmd.canExecute()) { + result.add(cmd); + } + } + } + + executeCommand(result.unwrap()); + } + }; } @Override @@ -138,7 +162,8 @@ protected void notifyChanged(Notification msg) { if(msg.getNotifier() == getFirstSelectedObject()) { Object feature = msg.getFeature(); - if(feature == FEATURE || feature == IArchimatePackage.Literals.LOCKABLE__LOCKED) { + if(feature == FEATURE || feature == IArchimatePackage.Literals.LOCKABLE__LOCKED || + isFeatureNotification(msg, IDiagramModelObject.FEATURE_DERIVE_ELEMENT_LINE_COLOR)) { update(); } } @@ -172,12 +197,15 @@ protected void update() { } fColorChooser.setIsDefaultColor(isDefaultColor); - // If this is an element line disable some things - if(lineObject instanceof IDiagramModelObject) { - boolean deriveElementLineColor = ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.DERIVE_ELEMENT_LINE_COLOR); + // If this is an element line enable or disable some things + if(lineObject instanceof IDiagramModelObject dmo) { + boolean deriveElementLineColor = dmo.getDeriveElementLineColor(); fColorChooser.setDoShowColorImage(!deriveElementLineColor); fColorChooser.getColorButton().setEnabled(!deriveElementLineColor); fColorChooser.setDoShowDefaultMenuItem(!deriveElementLineColor); + + fColorChooser.addMenuAction(fDeriveLineColorAction); + fDeriveLineColorAction.setChecked(deriveElementLineColor); } else { fColorChooser.setDoShowColorImage(true); diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/Messages.java b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/Messages.java index 84b034804..03281495d 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/Messages.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/Messages.java @@ -239,6 +239,10 @@ public class Messages extends NLS { public static String LineColorSection_2; + public static String LineColorSection_3; + + public static String LineColorSection_4; + public static String LineWidthSection_0; public static String LineWidthSection_1; diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/messages.properties b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/messages.properties index f8bcd280f..9931209a1 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/messages.properties +++ b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/messages.properties @@ -125,6 +125,8 @@ LabelRendererSection_2=Set expression LineColorSection_0=Line Colour: LineColorSection_1=Default LineColorSection_2=Enable in Preferences +LineColorSection_3=Derive from fill colour +LineColorSection_4=Derive line colour LineWidthSection_0=Line Width: LineWidthSection_1=Normal LineWidthSection_2=Medium diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/ui/ColorFactory.java b/com.archimatetool.editor/src/com/archimatetool/editor/ui/ColorFactory.java index 693509c57..a09cb6a32 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/ui/ColorFactory.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/ui/ColorFactory.java @@ -69,26 +69,27 @@ public static Color get(String rgbValue) { * Set user default colors as set in prefs for a model object */ public static void setDefaultColors(IDiagramModelComponent component) { - // If user Prefs is to *not* save default colours in file - if(!ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.SAVE_USER_DEFAULT_COLOR)) { - return; + // Derived line color + if(component instanceof IDiagramModelObject dmo) { + dmo.setDeriveElementLineColor(ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.DERIVE_ELEMENT_LINE_COLOR)); } - - // Fill color - if(component instanceof IDiagramModelObject) { - IDiagramModelObject dmo = (IDiagramModelObject)component; - Color fillColor = getDefaultFillColor(dmo); - if(fillColor != null) { - dmo.setFillColor(convertColorToString(fillColor)); + + // If user Prefs is set to save default colours in file + if(ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.SAVE_USER_DEFAULT_COLOR)) { + // Fill color + if(component instanceof IDiagramModelObject dmo) { + Color fillColor = getDefaultFillColor(dmo); + if(fillColor != null) { + dmo.setFillColor(convertColorToString(fillColor)); + } } - } - - // Line color - if(component instanceof ILineObject) { - ILineObject lo = (ILineObject)component; - Color lineColor = getDefaultLineColor(lo); - if(lineColor != null) { - lo.setLineColor(convertColorToString(lineColor)); + + // Line color + if(component instanceof ILineObject lo) { + Color lineColor = getDefaultLineColor(lo); + if(lineColor != null) { + lo.setLineColor(convertColorToString(lineColor)); + } } } } @@ -341,4 +342,20 @@ public static Color getLighterColor(Color color, float factor) { return get(convertRGBToString(rgb)); } + /** + * Return a color based on the suppled one for elements + * @param color The color to base this one on + * @return the new color + */ + public static Color getDerivedLineColor(Color color) { + if(color == null) { + return null; + } + + float contrastFactor = 0.7f; + + RGB rgb = new RGB((int)(color.getRed() * contrastFactor), (int)(color.getGreen() * contrastFactor), (int)(color.getBlue() * contrastFactor)); + + return get(convertRGBToString(rgb)); + } } diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/ui/FigureImagePreviewFactory.java b/com.archimatetool.editor/src/com/archimatetool/editor/ui/FigureImagePreviewFactory.java index d832e5426..d36bbecc3 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/ui/FigureImagePreviewFactory.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/ui/FigureImagePreviewFactory.java @@ -68,6 +68,7 @@ public static Image getPreviewImage(EClass eClass, int type) { dmo.setArchimateElement((IArchimateElement)IArchimateFactory.eINSTANCE.create(eClass)); dmo.setName(provider.getDefaultName()); dmo.setType(type); + dmo.setDeriveElementLineColor(false); // Special case for text alignment if(eClass == IArchimatePackage.eINSTANCE.getGrouping()) { diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/ui/factory/sketch/SketchActorUIProvider.java b/com.archimatetool.editor/src/com/archimatetool/editor/ui/factory/sketch/SketchActorUIProvider.java index d55141098..0ad30e4d5 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/ui/factory/sketch/SketchActorUIProvider.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/ui/factory/sketch/SketchActorUIProvider.java @@ -67,6 +67,7 @@ public Color getDefaultColor() { public boolean shouldExposeFeature(String featureName) { if(featureName == IArchimatePackage.Literals.TEXT_ALIGNMENT__TEXT_ALIGNMENT.getName() || featureName == IArchimatePackage.Literals.LINE_OBJECT__LINE_COLOR.getName() || + featureName == IDiagramModelObject.FEATURE_DERIVE_ELEMENT_LINE_COLOR || featureName == IDiagramModelObject.FEATURE_LINE_ALPHA || featureName == IArchimatePackage.Literals.DIAGRAM_MODEL_OBJECT__ALPHA.getName() || featureName == IDiagramModelObject.FEATURE_GRADIENT) { diff --git a/com.archimatetool.model/src/com/archimatetool/model/IDiagramModelObject.java b/com.archimatetool.model/src/com/archimatetool/model/IDiagramModelObject.java index 611fdfab8..f421d000e 100644 --- a/com.archimatetool.model/src/com/archimatetool/model/IDiagramModelObject.java +++ b/com.archimatetool.model/src/com/archimatetool/model/IDiagramModelObject.java @@ -23,23 +23,27 @@ * @model abstract="true" * @generated */ +@SuppressWarnings("nls") public interface IDiagramModelObject extends IConnectable, IFontAttribute, ILineObject, ITextAlignment { - String FEATURE_LINE_ALPHA = "lineAlpha"; //$NON-NLS-1$ + String FEATURE_LINE_ALPHA = "lineAlpha"; int FEATURE_LINE_ALPHA_DEFAULT = 255; - String FEATURE_GRADIENT = "gradient"; //$NON-NLS-1$ + String FEATURE_GRADIENT = "gradient"; int GRADIENT_NONE = -1; int FEATURE_GRADIENT_DEFAULT = GRADIENT_NONE; - String FEATURE_ICON_VISIBLE = "iconVisible"; //$NON-NLS-1$ + String FEATURE_ICON_VISIBLE = "iconVisible"; int ICON_VISIBLE_IF_NO_IMAGE_DEFINED = 0; int ICON_VISIBLE_ALWAYS = 1; int ICON_VISIBLE_NEVER = 2; int FEATURE_ICON_VISIBLE_DEFAULT = ICON_VISIBLE_IF_NO_IMAGE_DEFINED; - String FEATURE_ICON_COLOR = "iconColor"; //$NON-NLS-1$ - String FEATURE_ICON_COLOR_DEFAULT = ""; //$NON-NLS-1$ + String FEATURE_ICON_COLOR = "iconColor"; + String FEATURE_ICON_COLOR_DEFAULT = ""; + + String FEATURE_DERIVE_ELEMENT_LINE_COLOR = "deriveElementLineColor"; + boolean FEATURE_DERIVE_ELEMENT_LINE_COLOR_DEFAULT = true; /** * @return the value of FEATURE_LINE_ALPHA @@ -64,7 +68,7 @@ public interface IDiagramModelObject extends IConnectable, IFontAttribute, ILine void setGradient(int type); /** - * @return true if the icon is visible (if this object has an icon) + * @return the icon visible state */ int getIconVisibleState(); @@ -85,6 +89,17 @@ public interface IDiagramModelObject extends IConnectable, IFontAttribute, ILine */ void setIconColor(String iconColor); + /** + * @return true if this element derives its line color from its fill color + */ + boolean getDeriveElementLineColor(); + + /** + * Set whether this element derives its line color from its fill color + * @param value value + */ + void setDeriveElementLineColor(boolean value); + /** * Returns the value of the 'Bounds' containment reference. * diff --git a/com.archimatetool.model/src/com/archimatetool/model/impl/DiagramModelObject.java b/com.archimatetool.model/src/com/archimatetool/model/impl/DiagramModelObject.java index 168b88f89..cbf6d6183 100644 --- a/com.archimatetool.model/src/com/archimatetool/model/impl/DiagramModelObject.java +++ b/com.archimatetool.model/src/com/archimatetool/model/impl/DiagramModelObject.java @@ -251,6 +251,16 @@ public void setIconColor(String iconColor) { getFeatures().putString(FEATURE_ICON_COLOR, iconColor, FEATURE_ICON_COLOR_DEFAULT); } + @Override + public boolean getDeriveElementLineColor() { + return getFeatures().getBoolean(FEATURE_DERIVE_ELEMENT_LINE_COLOR, FEATURE_DERIVE_ELEMENT_LINE_COLOR_DEFAULT); + } + + @Override + public void setDeriveElementLineColor(boolean value) { + getFeatures().putBoolean(FEATURE_DERIVE_ELEMENT_LINE_COLOR, value, FEATURE_DERIVE_ELEMENT_LINE_COLOR_DEFAULT); + } + /** * * diff --git a/tests/com.archimatetool.editor.tests/src/com/archimatetool/editor/diagram/figures/AbstractDiagramModelObjectFigureTests.java b/tests/com.archimatetool.editor.tests/src/com/archimatetool/editor/diagram/figures/AbstractDiagramModelObjectFigureTests.java index 2bab9a84b..3c027ab44 100644 --- a/tests/com.archimatetool.editor.tests/src/com/archimatetool/editor/diagram/figures/AbstractDiagramModelObjectFigureTests.java +++ b/tests/com.archimatetool.editor.tests/src/com/archimatetool/editor/diagram/figures/AbstractDiagramModelObjectFigureTests.java @@ -107,7 +107,7 @@ public void testSetFontColor() { @Test public void testSetLineColor() { - ArchiPlugin.PREFERENCES.setValue(IPreferenceConstants.DERIVE_ELEMENT_LINE_COLOR, false); + diagramModelObject.setDeriveElementLineColor(false); assertEquals(ColorFactory.getDefaultLineColor(diagramModelObject), abstractFigure.getLineColor());