From: lempinen Date: Mon, 28 Oct 2013 13:47:45 +0000 (+0000) Subject: Preference page for modifying element fonts and colors X-Git-Tag: 1.8.1~215 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=4b01925ac09176d6f2d2939db219d3eb4a71bb75;p=simantics%2Fsysdyn.git Preference page for modifying element fonts and colors refs #4481 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@28139 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/InputFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/InputFactory.java index e480fd2a..34896576 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/InputFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/InputFactory.java @@ -163,7 +163,7 @@ public class InputFactory extends SysdynElementFactory { SysdynElementUtils.setInputReference(e, inputReference); Font font = ElementUtils.getTextFont(e); - font = font.deriveFont(font.getStyle() + Font.ITALIC); + font = font.deriveFont(font.getStyle()); ElementUtils.setTextFont(e, font); ElementUtils.setHover(e, false); } @@ -189,7 +189,7 @@ public class InputFactory extends SysdynElementFactory { TextNode node = ElementUtils.getOrCreateNode(e, parent, INPUT_SG_NODE, "input", TextNode.class); Font font = ElementUtils.getTextFont(e); font = font.deriveFont((float) 10.0); - font = font.deriveFont(Font.ITALIC); +// font = font.deriveFont(Font.ITALIC); Color color = new Color(150, 150, 150); Color fillColor = ElementUtils.getFillColor(e); Color borderColor = ElementUtils.getBorderColor(e, Color.BLACK); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPreferencePage.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPreferencePage.java index 64303968..4f9639da 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPreferencePage.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPreferencePage.java @@ -12,9 +12,20 @@ package org.simantics.sysdyn.ui.preferences; +import java.util.HashMap; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.preference.BooleanFieldEditor; import org.eclipse.jface.preference.ColorFieldEditor; +import org.eclipse.jface.preference.FieldEditor; import org.eclipse.jface.preference.FieldEditorPreferencePage; import org.eclipse.jface.preference.FontFieldEditor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; import org.simantics.sysdyn.ui.Activator; @@ -26,10 +37,14 @@ import org.simantics.sysdyn.ui.Activator; */ public class SysdynDiagramPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { + + private HashMap fieldParents; + private Group colorEditors, fontEditors; public SysdynDiagramPreferencePage() { super(GRID); setDescription("System dynamics diagram preferences"); + fieldParents = new HashMap(); } @Override @@ -39,26 +54,120 @@ IWorkbenchPreferencePage { @Override protected void createFieldEditors() { - addField(new ColorFieldEditor(SysdynDiagramPreferences.DEFAULT_COLOR, "Default", getFieldEditorParent())); - addField(new FontFieldEditor(SysdynDiagramPreferences.DEFAULT_FONT, "Default", getFieldEditorParent())); + Composite parent = new Composite(getFieldEditorParent(), SWT.NONE); + GridLayoutFactory.fillDefaults().numColumns(1).applyTo(parent); + GridDataFactory.fillDefaults().grab(true, true).applyTo(parent); + + // DEFAULTS + Group defaults = new Group(parent, SWT.NONE); + defaults.setText("Default settings"); + GridDataFactory.fillDefaults().grab(true, false).applyTo(defaults); + addField(new ColorFieldEditor(SysdynDiagramPreferences.DEFAULT_COLOR, "Color", defaults)); + addField(new CustomFontFieldEditor(SysdynDiagramPreferences.DEFAULT_FONT, "Font", defaults)); + GridLayout layout = (GridLayout) defaults.getLayout(); + layout.marginHeight = 3; + layout.marginWidth = 3; + defaults.setLayout(layout); + // COLORS + colorEditors = new Group(parent, SWT.NONE); + colorEditors.setText("Colors"); + GridDataFactory.fillDefaults().applyTo(colorEditors); + GridDataFactory.fillDefaults().applyTo(colorEditors); + Label label = new Label(colorEditors, SWT.NONE); + GridDataFactory.fillDefaults().span(3, 1).applyTo(label); + label = new Label(colorEditors, SWT.NONE); + label.setText("Use default"); + GridDataFactory.fillDefaults().applyTo(label); - addField(new ColorFieldEditor(SysdynDiagramPreferences.ARROW_COLOR, "&Dependency", getFieldEditorParent())); - addField(new ColorFieldEditor(SysdynDiagramPreferences.FLOW_COLOR, "&Flow", getFieldEditorParent())); - addField(new ColorFieldEditor(SysdynDiagramPreferences.AUXILIARY_COLOR, "&Auxiliary", getFieldEditorParent())); - addField(new ColorFieldEditor(SysdynDiagramPreferences.STOCK_COLOR, "&Stock", getFieldEditorParent())); - addField(new ColorFieldEditor(SysdynDiagramPreferences.VALVE_COLOR, "&Valve", getFieldEditorParent())); - addField(new ColorFieldEditor(SysdynDiagramPreferences.CLOUD_COLOR, "&Cloud", getFieldEditorParent())); - addField(new ColorFieldEditor(SysdynDiagramPreferences.MODULE_COLOR, "&Module", getFieldEditorParent())); + addColorFieldEditor(SysdynDiagramPreferences.ARROW_COLOR, "&Dependency", SysdynDiagramPreferences.ARROW_USE_DEFAULT_COLOR); + addColorFieldEditor(SysdynDiagramPreferences.FLOW_COLOR, "&Flow", SysdynDiagramPreferences.FLOW_USE_DEFAULT_COLOR); + addColorFieldEditor(SysdynDiagramPreferences.AUXILIARY_COLOR, "&Auxiliary", SysdynDiagramPreferences.AUXILIARY_USE_DEFAULT_COLOR); + addColorFieldEditor(SysdynDiagramPreferences.STOCK_COLOR, "&Stock", SysdynDiagramPreferences.STOCK_USE_DEFAULT_COLOR); + addColorFieldEditor(SysdynDiagramPreferences.VALVE_COLOR, "&Valve", SysdynDiagramPreferences.VALVE_USE_DEFAULT_COLOR); + addColorFieldEditor(SysdynDiagramPreferences.INPUT_COLOR, "&Input", SysdynDiagramPreferences.VALVE_USE_DEFAULT_COLOR); + addColorFieldEditor(SysdynDiagramPreferences.CLOUD_COLOR, "&Cloud", SysdynDiagramPreferences.CLOUD_USE_DEFAULT_COLOR); + addColorFieldEditor(SysdynDiagramPreferences.MODULE_COLOR, "&Module", SysdynDiagramPreferences.MODULE_USE_DEFAULT_COLOR); + // FONTS + fontEditors = new Group(parent, SWT.NONE); + fontEditors.setText("Fonts"); + GridDataFactory.fillDefaults().applyTo(fontEditors); + GridLayoutFactory.fillDefaults().applyTo(fontEditors); - addField(new FontFieldEditor(SysdynDiagramPreferences.ARROW_FONT, "Dependency", getFieldEditorParent())); - addField(new FontFieldEditor(SysdynDiagramPreferences.AUXILIARY_FONT, "Auxiliary", getFieldEditorParent())); - addField(new FontFieldEditor(SysdynDiagramPreferences.STOCK_FONT, "Stock", getFieldEditorParent())); - addField(new FontFieldEditor(SysdynDiagramPreferences.VALVE_FONT, "Valve", getFieldEditorParent())); - addField(new FontFieldEditor(SysdynDiagramPreferences.CLOUD_FONT, "Cloud", getFieldEditorParent())); - addField(new FontFieldEditor(SysdynDiagramPreferences.MODULE_FONT, "Module", getFieldEditorParent())); - } + label = new Label(fontEditors, SWT.NONE); + GridDataFactory.fillDefaults().span(3, 1).applyTo(label); + + label = new Label(fontEditors, SWT.NONE); + label.setText("Use default"); + GridDataFactory.fillDefaults().applyTo(label); + addFontFieldEditor(SysdynDiagramPreferences.ARROW_FONT, "Dependency", SysdynDiagramPreferences.ARROW_USE_DEFAULT_FONT); + addFontFieldEditor(SysdynDiagramPreferences.AUXILIARY_FONT, "Auxiliary", SysdynDiagramPreferences.AUXILIARY_USE_DEFAULT_FONT); + addFontFieldEditor(SysdynDiagramPreferences.STOCK_FONT, "Stock", SysdynDiagramPreferences.STOCK_USE_DEFAULT_FONT); + addFontFieldEditor(SysdynDiagramPreferences.VALVE_FONT, "Valve", SysdynDiagramPreferences.VALVE_USE_DEFAULT_FONT); + addFontFieldEditor(SysdynDiagramPreferences.INPUT_FONT, "Input", SysdynDiagramPreferences.INPUT_USE_DEFAULT_FONT); + addFontFieldEditor(SysdynDiagramPreferences.CLOUD_FONT, "Cloud", SysdynDiagramPreferences.CLOUD_USE_DEFAULT_FONT); + addFontFieldEditor(SysdynDiagramPreferences.MODULE_FONT, "Module", SysdynDiagramPreferences.MODULE_USE_DEFAULT_FONT); + + GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(4).applyTo(colorEditors); + GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(4).applyTo(fontEditors); + } + + + private void addColorFieldEditor(String property, String label, String defaultBoolean) { + ColorFieldEditor colorField = new ColorFieldEditor(property, label, colorEditors); + colorField.setEnabled(!getPreferenceStore().getBoolean(defaultBoolean), colorEditors); + Composite c = new Composite(colorEditors, SWT.NONE); + GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(c); + GridLayoutFactory.fillDefaults().applyTo(c); + BooleanFieldEditor useDefault = new DefaultBooleanFiedEditor(colorField, defaultBoolean, c); + fieldParents.put(colorField, colorEditors); + addField(useDefault); + addField(colorField); + } + + private void addFontFieldEditor(String property, String label, String defaultBoolean) { + CustomFontFieldEditor fontField = new CustomFontFieldEditor(property, label, fontEditors); + fontField.setEnabled(!getPreferenceStore().getBoolean(defaultBoolean), fontEditors); + Composite c = new Composite(fontEditors, SWT.NONE); + GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(c); + GridLayoutFactory.fillDefaults().applyTo(c); + BooleanFieldEditor useDefault = new DefaultBooleanFiedEditor(fontField, defaultBoolean, c); + + + + fieldParents.put(fontField, fontEditors); + addField(useDefault); + addField(fontField); + } + + private class DefaultBooleanFiedEditor extends BooleanFieldEditor { + private FieldEditor fieldEditor; + + public DefaultBooleanFiedEditor(FieldEditor fieldEditor, String name, Composite parent) { + super(name, "", parent); + this.fieldEditor = fieldEditor; + } + + @Override + protected void valueChanged(boolean oldValue, boolean newValue) { + super.valueChanged(oldValue, newValue); + fieldEditor.setEnabled(!newValue, fieldParents.get(fieldEditor)); + } + } + + private class CustomFontFieldEditor extends FontFieldEditor { + + public CustomFontFieldEditor(String name, String labelText, Composite parent) { + super(name, labelText, parent); + + GridDataFactory.fillDefaults().applyTo(getChangeControl(parent)); + setChangeButtonText("..."); + getChangeControl(parent).setToolTipText("Change"); + + + } + } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPreferences.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPreferences.java index 4fc11f8e..94c4bcab 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPreferences.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPreferences.java @@ -13,11 +13,13 @@ package org.simantics.sysdyn.ui.preferences; import java.util.HashMap; +import org.eclipse.jface.preference.IPreferenceStore; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; import org.simantics.layer0.Layer0; import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.Activator; /** * @@ -26,25 +28,71 @@ import org.simantics.sysdyn.SysdynResource; */ public class SysdynDiagramPreferences { + public static String DEFAULT_COLOR = "Default color"; + public static String DEFAULT_FONT = "Default font"; + public static String ARROW_COLOR = "Arrow color"; public static String FLOW_COLOR = "Flow color"; public static String AUXILIARY_COLOR = "Auxiliary color"; public static String CLOUD_COLOR = "Cloud color"; public static String STOCK_COLOR = "Stock color"; public static String VALVE_COLOR = "Valve color"; + public static String INPUT_COLOR = "Input color"; public static String MODULE_COLOR = "Module color"; + + public static HashMap colorPreferenceNames; + + static { + colorPreferenceNames = new HashMap(); + colorPreferenceNames.put(SysdynResource.URIs.DependencyConnection, ARROW_COLOR); + colorPreferenceNames.put(SysdynResource.URIs.FlowConnection, FLOW_COLOR); + colorPreferenceNames.put(SysdynResource.URIs.AuxiliarySymbol, AUXILIARY_COLOR); + colorPreferenceNames.put(SysdynResource.URIs.CloudSymbol, CLOUD_COLOR); + colorPreferenceNames.put(SysdynResource.URIs.StockSymbol, STOCK_COLOR); + colorPreferenceNames.put(SysdynResource.URIs.ValveSymbol, VALVE_COLOR); + colorPreferenceNames.put(SysdynResource.URIs.InputSymbol, INPUT_COLOR); + colorPreferenceNames.put(SysdynResource.URIs.ModuleSymbol, MODULE_COLOR); + } + + public static String getColorPreferenceName(ReadGraph graph, Resource resource) + throws DatabaseException { + String preference = colorPreferenceNames.get(getSymbolUri(graph, resource)); + return preference; + } + + public static String ARROW_USE_DEFAULT_COLOR = "Arrow use default color"; + public static String FLOW_USE_DEFAULT_COLOR = "Flow use default color"; + public static String AUXILIARY_USE_DEFAULT_COLOR = "Auxiliary use default color"; + public static String CLOUD_USE_DEFAULT_COLOR = "Cloud use default color"; + public static String STOCK_USE_DEFAULT_COLOR = "Stock use default color"; + public static String VALVE_USE_DEFAULT_COLOR = "Valve use default color"; + public static String INPUT_USE_DEFAULT_COLOR = "Input use default color"; + public static String MODULE_USE_DEFAULT_COLOR = "Module use default color"; + + public static HashMap colorDefaults; + + static { + colorDefaults = new HashMap(); + colorDefaults.put(ARROW_COLOR, ARROW_USE_DEFAULT_COLOR); + colorDefaults.put(FLOW_COLOR, FLOW_USE_DEFAULT_COLOR); + colorDefaults.put(AUXILIARY_COLOR, AUXILIARY_USE_DEFAULT_COLOR); + colorDefaults.put(CLOUD_COLOR, CLOUD_USE_DEFAULT_COLOR); + colorDefaults.put(STOCK_COLOR, STOCK_USE_DEFAULT_COLOR); + colorDefaults.put(VALVE_COLOR, VALVE_USE_DEFAULT_COLOR); + colorDefaults.put(INPUT_COLOR, INPUT_USE_DEFAULT_COLOR); + colorDefaults.put(MODULE_COLOR, MODULE_USE_DEFAULT_COLOR); - public static String DEFAULT_COLOR = "Default color"; - public static String DEFAULT_FONT = "Default font"; + } public static String ARROW_FONT = "Arrow font"; public static String AUXILIARY_FONT = "Auxiliary font"; public static String CLOUD_FONT = "Cloud font"; public static String STOCK_FONT = "Stock font"; public static String VALVE_FONT = "Valve font"; + public static String INPUT_FONT = "Input font"; public static String MODULE_FONT = "Module font"; - private static HashMap fontPreferenceNames; + public static HashMap fontPreferenceNames; static { fontPreferenceNames = new HashMap(); @@ -53,32 +101,40 @@ public class SysdynDiagramPreferences { fontPreferenceNames.put(SysdynResource.URIs.CloudSymbol, CLOUD_FONT); fontPreferenceNames.put(SysdynResource.URIs.StockSymbol, STOCK_FONT); fontPreferenceNames.put(SysdynResource.URIs.ValveSymbol, VALVE_FONT); + fontPreferenceNames.put(SysdynResource.URIs.InputSymbol, INPUT_FONT); fontPreferenceNames.put(SysdynResource.URIs.ModuleSymbol, MODULE_FONT); - } public static String getFontPreferenceName(ReadGraph graph, Resource resource) throws DatabaseException { - return fontPreferenceNames.get(getSymbolUri(graph, resource)); + + String preference = fontPreferenceNames.get(getSymbolUri(graph, resource)); + return preference; } - private static HashMap colorPreferenceNames; + public static String ARROW_USE_DEFAULT_FONT = "Arrow use default font"; + public static String AUXILIARY_USE_DEFAULT_FONT = "Auxiliary use default font"; + public static String CLOUD_USE_DEFAULT_FONT = "Cloud use default font"; + public static String STOCK_USE_DEFAULT_FONT = "Stock use default font"; + public static String VALVE_USE_DEFAULT_FONT = "Valve use default font"; + public static String INPUT_USE_DEFAULT_FONT = "Input use default font"; + public static String MODULE_USE_DEFAULT_FONT = "Module use default font"; + + + public static HashMap fontDefaults; static { - colorPreferenceNames = new HashMap(); - colorPreferenceNames.put(SysdynResource.URIs.DependencyConnection, ARROW_COLOR); - colorPreferenceNames.put(SysdynResource.URIs.FlowConnection, FLOW_COLOR); - colorPreferenceNames.put(SysdynResource.URIs.AuxiliarySymbol, AUXILIARY_COLOR); - colorPreferenceNames.put(SysdynResource.URIs.CloudSymbol, CLOUD_COLOR); - colorPreferenceNames.put(SysdynResource.URIs.StockSymbol, STOCK_COLOR); - colorPreferenceNames.put(SysdynResource.URIs.ValveSymbol, VALVE_COLOR); - colorPreferenceNames.put(SysdynResource.URIs.ModuleSymbol, MODULE_COLOR); + fontDefaults = new HashMap(); + fontDefaults.put(ARROW_FONT, ARROW_USE_DEFAULT_FONT); + fontDefaults.put(AUXILIARY_FONT, AUXILIARY_USE_DEFAULT_FONT); + fontDefaults.put(CLOUD_FONT, CLOUD_USE_DEFAULT_FONT); + fontDefaults.put(STOCK_FONT, STOCK_USE_DEFAULT_FONT); + fontDefaults.put(VALVE_FONT, VALVE_USE_DEFAULT_FONT); + fontDefaults.put(INPUT_FONT, INPUT_USE_DEFAULT_FONT); + fontDefaults.put(MODULE_FONT, MODULE_USE_DEFAULT_FONT); } - public static String getColorPreferenceName(ReadGraph graph, Resource resource) - throws DatabaseException { - return colorPreferenceNames.get(getSymbolUri(graph, resource)); - } + private static String getSymbolUri(ReadGraph graph, Resource resource) throws DatabaseException { @@ -92,5 +148,36 @@ public class SysdynDiagramPreferences { return graph.getURI(symbol); } - + /** + * Get the name of the property that decides whether to use default value or not + * @param property + * @return + */ + public static String getUseDefaultProperty(String property) { + String result = colorDefaults.get(property); + if(result == null) + result = fontDefaults.get(property); + return result; + } + + /** + * Returns default property if USE DEFAULT is set, otherwise returns the + * same property as given as argument. + * @param property + * @return + */ + public static String getPreferenceName(String property) { + String useDefault = fontDefaults.get(property); + IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + if(useDefault != null && store.getBoolean(useDefault)) { + return DEFAULT_FONT; + } + + useDefault = colorDefaults.get(property); + if(useDefault != null && store.getBoolean(useDefault)) { + return DEFAULT_COLOR; + } + + return property; + } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPreferencesInitializer.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPreferencesInitializer.java index 0539888f..cd5c8f50 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPreferencesInitializer.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPreferencesInitializer.java @@ -13,10 +13,13 @@ package org.simantics.sysdyn.ui.preferences; import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.resource.StringConverter; +import org.eclipse.jface.preference.PreferenceConverter; +import org.eclipse.swt.graphics.FontData; import org.eclipse.swt.graphics.RGB; import org.simantics.sysdyn.ui.Activator; +import com.lowagie.text.Font; + /** * * @author Teemu Lempinen @@ -26,13 +29,51 @@ public class SysdynDiagramPreferencesInitializer extends AbstractPreferenceIniti @Override public void initializeDefaultPreferences() { + RGB black = new RGB(0, 0, 0); + RGB arrow = new RGB(0,128,192); + IPreferenceStore store = Activator.getDefault().getPreferenceStore(); - store.setDefault(SysdynDiagramPreferences.ARROW_COLOR, StringConverter.asString(new RGB(0, 0, 255))); - store.setDefault(SysdynDiagramPreferences.FLOW_COLOR, StringConverter.asString(new RGB(0, 0, 0))); - store.setDefault(SysdynDiagramPreferences.AUXILIARY_COLOR, StringConverter.asString(new RGB(0, 0, 0))); - store.setDefault(SysdynDiagramPreferences.STOCK_COLOR, StringConverter.asString(new RGB(0, 0, 0))); - store.setDefault(SysdynDiagramPreferences.VALVE_COLOR, StringConverter.asString(new RGB(0, 0, 0))); - store.setDefault(SysdynDiagramPreferences.CLOUD_COLOR, StringConverter.asString(new RGB(0, 0, 0))); + + PreferenceConverter.setDefault(store, SysdynDiagramPreferences.DEFAULT_COLOR, black); + PreferenceConverter.setDefault(store, SysdynDiagramPreferences.ARROW_COLOR, arrow); + PreferenceConverter.setDefault(store, SysdynDiagramPreferences.FLOW_COLOR, black); + PreferenceConverter.setDefault(store, SysdynDiagramPreferences.AUXILIARY_COLOR, black); + PreferenceConverter.setDefault(store, SysdynDiagramPreferences.STOCK_COLOR, black); + PreferenceConverter.setDefault(store, SysdynDiagramPreferences.VALVE_COLOR, black); + PreferenceConverter.setDefault(store, SysdynDiagramPreferences.INPUT_COLOR, black); + PreferenceConverter.setDefault(store, SysdynDiagramPreferences.CLOUD_COLOR, black); + PreferenceConverter.setDefault(store, SysdynDiagramPreferences.MODULE_COLOR, black); + + + store.setDefault(SysdynDiagramPreferences.ARROW_USE_DEFAULT_COLOR, false); + store.setDefault(SysdynDiagramPreferences.FLOW_USE_DEFAULT_COLOR, true); + store.setDefault(SysdynDiagramPreferences.AUXILIARY_USE_DEFAULT_COLOR, true); + store.setDefault(SysdynDiagramPreferences.STOCK_USE_DEFAULT_COLOR, true); + store.setDefault(SysdynDiagramPreferences.VALVE_USE_DEFAULT_COLOR, true); + store.setDefault(SysdynDiagramPreferences.INPUT_USE_DEFAULT_COLOR, true); + store.setDefault(SysdynDiagramPreferences.CLOUD_USE_DEFAULT_COLOR, true); + store.setDefault(SysdynDiagramPreferences.MODULE_USE_DEFAULT_COLOR, true); + + FontData[] basicFont = new FontData[] {new FontData("Tahoma", 12, Font.NORMAL)}; + FontData[] italicFont = new FontData[] {new FontData("Tahoma", 12, Font.ITALIC)}; + FontData[] moduleFont = new FontData[] {new FontData("Tahoma", 16, Font.NORMAL)}; + PreferenceConverter.setDefault(store, SysdynDiagramPreferences.DEFAULT_FONT, basicFont); + PreferenceConverter.setDefault(store, SysdynDiagramPreferences.ARROW_FONT, basicFont); + PreferenceConverter.setDefault(store, SysdynDiagramPreferences.AUXILIARY_FONT, basicFont); + PreferenceConverter.setDefault(store, SysdynDiagramPreferences.STOCK_FONT, basicFont); + PreferenceConverter.setDefault(store, SysdynDiagramPreferences.VALVE_FONT, basicFont); + PreferenceConverter.setDefault(store, SysdynDiagramPreferences.INPUT_FONT, italicFont); + PreferenceConverter.setDefault(store, SysdynDiagramPreferences.CLOUD_FONT, basicFont); + PreferenceConverter.setDefault(store, SysdynDiagramPreferences.MODULE_FONT, moduleFont); + + store.setDefault(SysdynDiagramPreferences.ARROW_USE_DEFAULT_FONT, true); + store.setDefault(SysdynDiagramPreferences.AUXILIARY_USE_DEFAULT_FONT, true); + store.setDefault(SysdynDiagramPreferences.STOCK_USE_DEFAULT_FONT, true); + store.setDefault(SysdynDiagramPreferences.VALVE_USE_DEFAULT_FONT, true); + store.setDefault(SysdynDiagramPreferences.INPUT_USE_DEFAULT_FONT, false); + store.setDefault(SysdynDiagramPreferences.CLOUD_USE_DEFAULT_FONT, true); + store.setDefault(SysdynDiagramPreferences.MODULE_USE_DEFAULT_FONT, false); + } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPropertySupport.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPropertySupport.java index 6b604795..441b7fe5 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPropertySupport.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPropertySupport.java @@ -36,27 +36,22 @@ public class SysdynDiagramPropertySupport { private void add(String property) { diagramProperties.add(property); + String useDefault = SysdynDiagramPreferences.getUseDefaultProperty(property); + if(useDefault != null) + diagramProperties.add(useDefault); } public SysdynDiagramPropertySupport() { diagramProperties = new HashSet(); - add(SysdynDiagramPreferences.ARROW_COLOR); - add(SysdynDiagramPreferences.AUXILIARY_COLOR); - add(SysdynDiagramPreferences.CLOUD_COLOR); - add(SysdynDiagramPreferences.FLOW_COLOR); - add(SysdynDiagramPreferences.STOCK_COLOR); - add(SysdynDiagramPreferences.VALVE_COLOR); - add(SysdynDiagramPreferences.MODULE_COLOR); + for(String property : SysdynDiagramPreferences.colorPreferenceNames.values()) + add(property); add(SysdynDiagramPreferences.DEFAULT_COLOR); add(SysdynDiagramPreferences.DEFAULT_FONT); - add(SysdynDiagramPreferences.ARROW_FONT); - add(SysdynDiagramPreferences.AUXILIARY_FONT); - add(SysdynDiagramPreferences.CLOUD_FONT); - add(SysdynDiagramPreferences.STOCK_FONT); - add(SysdynDiagramPreferences.VALVE_FONT); - add(SysdynDiagramPreferences.MODULE_FONT); + + for(String property : SysdynDiagramPreferences.fontPreferenceNames.values()) + add(property); Activator.getDefault().getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() { @Override @@ -64,9 +59,14 @@ public class SysdynDiagramPropertySupport { String propertyName = event.getProperty(); if(diagramProperties.contains(propertyName)){ for(SysdynDiagramPropertySubscription subscription : getSubscriptionSnapshot()) { - if(propertyName.equals(subscription.getPropertyName())) { + String p = subscription.getPropertyName(); + String p2 = SysdynDiagramPreferences.getPreferenceName(p); + String dp = SysdynDiagramPreferences.getUseDefaultProperty(subscription.getPropertyName()); + if(propertyName.equals(p) || + propertyName.equals(p2) || + propertyName.equals(dp)) { IPreferenceStore store = Activator.getDefault().getPreferenceStore(); - String result = store.getString(subscription.getPropertyName()); + String result = store.getString(p2); subscription.getListener().execute(result); } }