Skip to content

Commit

Permalink
Derive line colour from fill colour is per element
Browse files Browse the repository at this point in the history
- The global setting is now the default for new objects
- Add "Derive from fill colour" drop-down option to colour chooser
  • Loading branch information
Phillipus committed Sep 27, 2023
1 parent 92040f6 commit 738b346
Show file tree
Hide file tree
Showing 21 changed files with 144 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
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_DERIVE_ELEMENT_LINE_COLOR ||
featureName == IDiagramModelObject.FEATURE_GRADIENT) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -88,39 +90,36 @@ 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
group.setGradient(ArchiPlugin.PREFERENCES.getInt(IPreferenceConstants.DEFAULT_GRADIENT));
}

// 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);
}

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> themeColors = List.of(VIEW_BACKGROUND_COLOR,
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -107,14 +110,15 @@ 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();
}
}
};

private ColorChooser fColorChooser;
private Action fDeriveLineColorAction;


@Override
protected void createControls(Composite parent) {
Expand All @@ -131,14 +135,35 @@ 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
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();
}
}
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 738b346

Please sign in to comment.