From c7ddd7671fe151550cf4efc36408eaab1ee28e05 Mon Sep 17 00:00:00 2001 From: lempinen Date: Fri, 25 Oct 2013 12:40:00 +0000 Subject: [PATCH] Default color and font selection for all component types. refs #4481 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@28122 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/ui/elements/CloudFactory.java | 12 +- .../sysdyn/ui/elements/ModuleFactory.java | 3 + .../sysdyn/ui/elements/ModuleNode.java | 2 +- .../sysdyn/ui/elements/StockFactory.java | 10 +- .../ui/elements/SysdynElementFactory.java | 46 +++- .../DependencyConnectionFactory.java | 242 ++++++++++-------- .../RouteFlowConnectionFactory.java | 26 +- .../SysdynDiagramPreferencePage.java | 53 +--- .../preferences/SysdynDiagramPreferences.java | 67 +++++ .../SysdynDiagramPropertyExternalRead.java | 7 +- .../SysdynDiagramPropertySupport.java | 20 +- 11 files changed, 299 insertions(+), 189 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/CloudFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/CloudFactory.java index e9280c6e..63453a38 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/CloudFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/CloudFactory.java @@ -22,8 +22,6 @@ import java.util.Collection; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; -import org.simantics.diagram.G2DUtils; -import org.simantics.diagram.stubs.G2DResource; import org.simantics.g2d.canvas.ICanvasContext; import org.simantics.g2d.diagram.IDiagram; import org.simantics.g2d.element.ElementClass; @@ -54,9 +52,9 @@ import org.simantics.scenegraph.g2d.events.MouseEvent; import org.simantics.scenegraph.g2d.events.MouseEvent.MouseEnterEvent; import org.simantics.scenegraph.g2d.events.MouseEvent.MouseExitEvent; import org.simantics.scenegraph.g2d.nodes.ShapeNode; +import org.simantics.utils.datastructures.hints.IHintContext.Key; import org.simantics.utils.datastructures.hints.IHintListener; import org.simantics.utils.datastructures.hints.IHintObservable; -import org.simantics.utils.datastructures.hints.IHintContext.Key; public class CloudFactory extends SysdynElementFactory { @@ -111,13 +109,7 @@ public class CloudFactory extends SysdynElementFactory { public void load(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource element, IElement e) throws DatabaseException { super.load(graph, canvas, diagram, element, e); - - Resource colorResource = graph.getPossibleObject(element, G2DResource.getInstance(graph).HasColor); - Color color = null; - if(colorResource != null) { - color = G2DUtils.getColor(graph, colorResource); - e.setHint(ElementHints.KEY_BORDER_COLOR, color); - } + e.setHint(ElementHints.KEY_BORDER_COLOR, e.getHint(ElementHints.KEY_TEXT_COLOR)); } @Override diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ModuleFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ModuleFactory.java index b480b943..93f0779e 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ModuleFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ModuleFactory.java @@ -12,6 +12,7 @@ package org.simantics.sysdyn.ui.elements; import java.awt.BasicStroke; +import java.awt.Color; import java.awt.Font; import java.awt.geom.Rectangle2D; import java.util.Collection; @@ -21,6 +22,7 @@ import org.simantics.g2d.element.ElementClass; import org.simantics.g2d.element.ElementUtils; import org.simantics.g2d.element.IElement; import org.simantics.g2d.element.handler.InternalSize; +import org.simantics.g2d.element.handler.impl.BorderColorImpl; import org.simantics.g2d.element.handler.impl.BoundsOutline; import org.simantics.g2d.element.handler.impl.DefaultTransform; import org.simantics.g2d.element.handler.impl.ObjectTerminal; @@ -56,6 +58,7 @@ public class ModuleFactory extends SysdynElementFactory { StaticSymbolImageInitializer.INSTANCE, new ModuleSceneGraph(0, 0, Alignment.LEADING, 1f , 4, 4, true), BoundsOutline.INSTANCE, + new BorderColorImpl(Color.BLACK), new WholeElementTerminals(terminals) ).setId(ModuleFactory.class.getSimpleName()); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ModuleNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ModuleNode.java index 2e0bb077..ad0431d8 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ModuleNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ModuleNode.java @@ -66,7 +66,7 @@ public class ModuleNode extends HoverTextNode { g.translate(x, y); g.setStroke(new BasicStroke((float) (scale*borderWidth))); - g.setColor(Color.GRAY); + g.setColor(borderColor); g.draw(path); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/StockFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/StockFactory.java index 765f25b2..1aa0f971 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/StockFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/StockFactory.java @@ -19,8 +19,6 @@ import java.util.Collection; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; -import org.simantics.diagram.G2DUtils; -import org.simantics.diagram.stubs.G2DResource; import org.simantics.g2d.canvas.ICanvasContext; import org.simantics.g2d.diagram.IDiagram; import org.simantics.g2d.element.ElementClass; @@ -69,13 +67,7 @@ public class StockFactory extends SysdynElementFactory { @Override public void load(ReadGraph graph, final ICanvasContext canvas, final IDiagram diagram, final Resource element, final IElement e) throws DatabaseException { super.load(graph, canvas, diagram, element, e); - - Resource colorResource = graph.getPossibleObject(element, G2DResource.getInstance(graph).HasColor); - Color color = null; - if(colorResource != null) { - color = G2DUtils.getColor(graph, colorResource); - e.setHint(ElementHints.KEY_BORDER_COLOR, color); - } + e.setHint(ElementHints.KEY_BORDER_COLOR, e.getHint(ElementHints.KEY_TEXT_COLOR)); } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/SysdynElementFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/SysdynElementFactory.java index 61415eca..36996ec3 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/SysdynElementFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/SysdynElementFactory.java @@ -11,12 +11,17 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.elements; +import java.awt.Color; import java.awt.Font; import java.awt.geom.AffineTransform; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import org.eclipse.jface.preference.PreferenceConverter; +import org.eclipse.jface.resource.StringConverter; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.RGB; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.Statement; @@ -45,6 +50,9 @@ import org.simantics.layer0.Layer0; import org.simantics.modeling.ModelingResources; import org.simantics.structural.stubs.StructuralResource2; import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.preferences.SysdynDiagramPreferences; +import org.simantics.sysdyn.ui.preferences.SysdynDiagramPropertyExternalRead; +import org.simantics.utils.datastructures.Pair; /** * An ElementFactory that gathers common functionality for system dynamics symbols. @@ -97,16 +105,40 @@ public abstract class SysdynElementFactory extends SyncElementFactory { ModelingResources mr = ModelingResources.getInstance(graph); if (graph.isInstanceOf(element, dr.FontProvider)) { - Resource fontResource = graph.getPossibleObject(element, g2d.HasFont); - if (fontResource != null && graph.hasStatement(fontResource)) - ElementUtils.setTextFont(e, G2DUtils.getFont(graph, fontResource)); + Statement fontStatement = graph.getPossibleStatement(element, g2d.HasFont); + if(fontStatement != null && !fontStatement.isAsserted(element)) { + ElementUtils.setTextFont(e, G2DUtils.getFont(graph, fontStatement.getObject())); + } else { + String fontdata = graph.syncRequest(new SysdynDiagramPropertyExternalRead(new Pair(element, SysdynDiagramPreferences.getFontPreferenceName(graph, element)))); + if(fontdata != null) { + FontData[] fdArray = PreferenceConverter.basicGetFontData(fontdata); + if(fdArray != null) { + if(fdArray.length == 1) { + FontData fd = fdArray[0]; + if(fd != null) { + Font font = new Font(fd.getName(), fd.getStyle(), fd.getHeight()); + e.setHint(ElementHints.KEY_FONT, font); + } + } + } + } + } } if (graph.isInstanceOf(element, dr.ColorProvider)) { Statement colorStatement = graph.getPossibleStatement(element, g2d.HasColor); - if (colorStatement != null && !colorStatement.isAsserted(element)) - ElementUtils.setTextColor(e, G2DUtils.getColor(graph, colorStatement.getObject())); - else { - + if(colorStatement != null && !colorStatement.isAsserted(element)) { + e.setHint(ElementHints.KEY_TEXT_COLOR, G2DUtils.getColor(graph, colorStatement.getObject())); + } else { + String color = graph.syncRequest(new SysdynDiagramPropertyExternalRead(new Pair(element, SysdynDiagramPreferences.getColorPreferenceName(graph, element)))); + if(color != null) { + RGB rgb = StringConverter.asRGB(color, null); + if(rgb != null) { + Color c = new Color(rgb.red, rgb.green, rgb.blue); + e.setHint(ElementHints.KEY_TEXT_COLOR, c); + e.setHint(ElementHints.KEY_BORDER_COLOR, c); + } + } + } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/DependencyConnectionFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/DependencyConnectionFactory.java index b521dd4b..3f757a08 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/DependencyConnectionFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/DependencyConnectionFactory.java @@ -12,11 +12,14 @@ package org.simantics.sysdyn.ui.elements.connections; import java.awt.Color; +import java.awt.Font; import java.util.HashMap; import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.atomic.AtomicInteger; +import org.eclipse.jface.preference.PreferenceConverter; import org.eclipse.jface.resource.StringConverter; +import org.eclipse.swt.graphics.FontData; import org.eclipse.swt.graphics.RGB; import org.simantics.databoard.Bindings; import org.simantics.db.AsyncReadGraph; @@ -67,12 +70,12 @@ public class DependencyConnectionFactory extends ElementFactoryAdapter { @Override public void load(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, final Resource elementResource, final IElement element, final AsyncProcedure procedure) { - - final AtomicInteger ready = new AtomicInteger(1); - final ConcurrentSkipListMap> properties = new ConcurrentSkipListMap>(); - + + final AtomicInteger ready = new AtomicInteger(1); + final ConcurrentSkipListMap> properties = new ConcurrentSkipListMap>(); + element.setHint(DiagramHints.ROUTE_ALGORITHM, DependencyRouter.INSTANCE); - + G2DResource G2D; try { G2D = G2DResource.getInstance(graph.getSession()); @@ -80,14 +83,29 @@ public class DependencyConnectionFactory extends ElementFactoryAdapter { e.printStackTrace(); return; } - + // Find possible font - graph.forPossibleObject(elementResource, G2D.HasFont, new SyncProcedure() { + graph.forPossibleStatement(elementResource, G2D.HasFont, new SyncProcedure() { @Override - public void execute(ReadGraph graph, Resource result) throws DatabaseException { - if(result != null) { - element.setHint(ElementHints.KEY_FONT, G2DUtils.getFont(graph, result)); + public void execute(ReadGraph graph, Statement result) throws DatabaseException { + if(result != null && !result.isAsserted(elementResource)) { + element.setHint(ElementHints.KEY_FONT, G2DUtils.getFont(graph, result.getObject())); + } else { + String fontdata = graph.syncRequest(new SysdynDiagramPropertyExternalRead(new Pair(elementResource, SysdynDiagramPreferences.ARROW_FONT))); + if(fontdata != null) { + FontData[] fdArray = PreferenceConverter.basicGetFontData(fontdata); + if(fdArray != null) { + if(fdArray.length == 1) { + FontData fd = fdArray[0]; + if(fd != null) { + Font font = new Font(fd.getName(), fd.getStyle(), fd.getHeight()); + element.setHint(ElementHints.KEY_FONT, font); + } + } + } + } + } } @@ -96,7 +114,7 @@ public class DependencyConnectionFactory extends ElementFactoryAdapter { throwable.printStackTrace(); } }); - + // Find possible color graph.forPossibleStatement(elementResource, G2D.HasColor, new SyncProcedure() { @@ -122,109 +140,109 @@ public class DependencyConnectionFactory extends ElementFactoryAdapter { throwable.printStackTrace(); } }); - + // A complicated-looking procedure for obtaining all HasProperties to properties map - graph.forEachPredicate(elementResource, new AsyncMultiProcedure() { - - @Override - public void exception(AsyncReadGraph graph, Throwable throwable) { - throwable.printStackTrace(); - } - - @Override - public void execute(AsyncReadGraph graph, final Resource property) { - - ready.incrementAndGet(); - Layer0 l0; - try { - l0 = Layer0.getInstance(graph.getSession()); - } catch (DatabaseException e) { - e.printStackTrace(); - return; - } - - graph.forIsSubrelationOf(property, l0.HasProperty, new AsyncProcedure() { - - @Override - public void exception(AsyncReadGraph graph, Throwable throwable) { - throwable.printStackTrace(); - } - - @Override - public void execute(AsyncReadGraph graph, final Boolean isProperty) { - - if(isProperty) { - - graph.forPossibleRelatedValue(elementResource, property, new AsyncProcedure() { - - @Override - public void exception(AsyncReadGraph graph, Throwable throwable) { - throwable.printStackTrace(); - } - - @Override - public void execute(AsyncReadGraph graph, final Object value) { - - Layer0 l0; - try { - l0 = Layer0.getInstance(graph.getSession()); - } catch (DatabaseException e) { - e.printStackTrace(); - return; - } - - graph.forPossibleRelatedValue(property, l0.HasName, Bindings.STRING, new AsyncProcedure() { - - @Override - public void exception(AsyncReadGraph graph, Throwable throwable) { - throwable.printStackTrace(); - } - - @Override - public void execute(AsyncReadGraph graph, String name) { - - properties.put(name, Pair.make(property, value)); - if(ready.decrementAndGet() == 0) { - element.setHint(DiagramHints.PROPERTIES, new HashMap>(properties)); - procedure.execute(graph, element); - } - - } - - }); - - } - - }); - - - } else { - - if(ready.decrementAndGet() == 0) { - element.setHint(DiagramHints.PROPERTIES, new HashMap>(properties)); - procedure.execute(graph, element); - } - - } - - } - - }); - } - - @Override - public void finished(AsyncReadGraph graph) { - - if(ready.decrementAndGet() == 0) { - element.setHint(DiagramHints.PROPERTIES, new HashMap(properties)); - procedure.execute(graph, element); - } - - } - - }); - + graph.forEachPredicate(elementResource, new AsyncMultiProcedure() { + + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + throwable.printStackTrace(); + } + + @Override + public void execute(AsyncReadGraph graph, final Resource property) { + + ready.incrementAndGet(); + Layer0 l0; + try { + l0 = Layer0.getInstance(graph.getSession()); + } catch (DatabaseException e) { + e.printStackTrace(); + return; + } + + graph.forIsSubrelationOf(property, l0.HasProperty, new AsyncProcedure() { + + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + throwable.printStackTrace(); + } + + @Override + public void execute(AsyncReadGraph graph, final Boolean isProperty) { + + if(isProperty) { + + graph.forPossibleRelatedValue(elementResource, property, new AsyncProcedure() { + + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + throwable.printStackTrace(); + } + + @Override + public void execute(AsyncReadGraph graph, final Object value) { + + Layer0 l0; + try { + l0 = Layer0.getInstance(graph.getSession()); + } catch (DatabaseException e) { + e.printStackTrace(); + return; + } + + graph.forPossibleRelatedValue(property, l0.HasName, Bindings.STRING, new AsyncProcedure() { + + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + throwable.printStackTrace(); + } + + @Override + public void execute(AsyncReadGraph graph, String name) { + + properties.put(name, Pair.make(property, value)); + if(ready.decrementAndGet() == 0) { + element.setHint(DiagramHints.PROPERTIES, new HashMap>(properties)); + procedure.execute(graph, element); + } + + } + + }); + + } + + }); + + + } else { + + if(ready.decrementAndGet() == 0) { + element.setHint(DiagramHints.PROPERTIES, new HashMap>(properties)); + procedure.execute(graph, element); + } + + } + + } + + }); + } + + @Override + public void finished(AsyncReadGraph graph) { + + if(ready.decrementAndGet() == 0) { + element.setHint(DiagramHints.PROPERTIES, new HashMap(properties)); + procedure.execute(graph, element); + } + + } + + }); + } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/RouteFlowConnectionFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/RouteFlowConnectionFactory.java index 8935085e..3ad51509 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/RouteFlowConnectionFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/RouteFlowConnectionFactory.java @@ -25,6 +25,8 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +import org.eclipse.jface.resource.StringConverter; +import org.eclipse.swt.graphics.RGB; import org.simantics.databoard.Bindings; import org.simantics.db.AsyncReadGraph; import org.simantics.db.ReadGraph; @@ -81,6 +83,9 @@ import org.simantics.structural2.modelingRules.IAttachmentRelationMap; import org.simantics.structural2.modelingRules.IModelingRules; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.elements.ValveFactory.ValveSceneGraph; +import org.simantics.sysdyn.ui.preferences.SysdynDiagramPreferences; +import org.simantics.sysdyn.ui.preferences.SysdynDiagramPropertyExternalRead; +import org.simantics.utils.datastructures.Pair; /** * An element class for Sysdyn Flow elements. * Copied from RouteGraphConnectionClassFactory and adapted to Flow needs @@ -128,11 +133,24 @@ public class RouteFlowConnectionFactory extends SyncElementFactory { // FIXME: With undo this seems to happen, don't know why yet! return; - Resource colorResource = graph.getPossibleObject(connection, G2DResource.getInstance(graph).HasColor); Color color = null; - if(colorResource != null) { - color = G2DUtils.getColor(graph, colorResource); - element.setHint(ElementHints.KEY_TEXT_COLOR, color); + DiagramResource DR = DiagramResource.getInstance(graph); + G2DResource G2D = G2DResource.getInstance(graph); + if (graph.isInstanceOf(connection, DR.ColorProvider)) { + Statement colorStatement = graph.getPossibleStatement(connection, G2D.HasColor); + if(colorStatement != null && !colorStatement.isAsserted(connection)) { + element.setHint(ElementHints.KEY_TEXT_COLOR, G2DUtils.getColor(graph, colorStatement.getObject())); + } else { + String colorString = graph.syncRequest(new SysdynDiagramPropertyExternalRead(new Pair(connection, SysdynDiagramPreferences.getColorPreferenceName(graph, connection)))); + if(colorString != null) { + RGB rgb = StringConverter.asRGB(colorString, null); + if(rgb != null) { + color = new Color(rgb.red, rgb.green, rgb.blue); + element.setHint(ElementHints.KEY_TEXT_COLOR, color); + } + } + + } } RouteGraph rg = new RouteGraph(); 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 ce357b73..64303968 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 @@ -14,15 +14,9 @@ package org.simantics.sysdyn.ui.preferences; import org.eclipse.jface.preference.ColorFieldEditor; import org.eclipse.jface.preference.FieldEditorPreferencePage; -import org.eclipse.ui.IEditorPart; +import org.eclipse.jface.preference.FontFieldEditor; import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPreferencePage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.simantics.g2d.diagram.DiagramUtils; -import org.simantics.g2d.diagram.IDiagram; -import org.simantics.modeling.ui.diagramEditor.DiagramEditor; import org.simantics.sysdyn.ui.Activator; /** @@ -45,45 +39,26 @@ IWorkbenchPreferencePage { @Override protected void createFieldEditors() { + addField(new ColorFieldEditor(SysdynDiagramPreferences.DEFAULT_COLOR, "Default", getFieldEditorParent())); + addField(new FontFieldEditor(SysdynDiagramPreferences.DEFAULT_FONT, "Default", getFieldEditorParent())); + + + 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())); - } - - @Override - public boolean performOk() { - IEditorPart editor = null; - IWorkbench workbench = PlatformUI.getWorkbench(); - IWorkbenchWindow[] windows = workbench.getWorkbenchWindows(); - // To ask for the active window doesn't work, so browse through all - // windows and when an active editor is found, use that - for (IWorkbenchWindow window : windows) { - IWorkbenchPage page = window.getActivePage(); - if (page != null) { - editor = (IEditorPart)page.getActiveEditor(); - if (editor != null) - break; - } - } - if (editor != null) { - if (editor instanceof DiagramEditor) { - DiagramEditor diagramEditor = (DiagramEditor) editor; - IDiagram o = (IDiagram) diagramEditor.getViewer().getAdapter(IDiagram.class); -// ICanvasContext o = (ICanvasContext) diagramEditor.getViewer().getAdapter(ICanvasContext.class); - if(o != null) { - DiagramUtils.invalidate(o); - DiagramUtils.validateAndFix(o, o.getElements()); - -// o.getContentContext().setDirty(); - } - } - } - + addField(new ColorFieldEditor(SysdynDiagramPreferences.MODULE_COLOR, "&Module", getFieldEditorParent())); + - return super.performOk(); + 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())); } } 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 5ab40e62..4fc11f8e 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 @@ -11,6 +11,14 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.preferences; +import java.util.HashMap; + +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; + /** * * @author Teemu Lempinen @@ -24,6 +32,65 @@ public class SysdynDiagramPreferences { public static String CLOUD_COLOR = "Cloud color"; public static String STOCK_COLOR = "Stock color"; public static String VALVE_COLOR = "Valve color"; + public static String MODULE_COLOR = "Module 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 MODULE_FONT = "Module font"; + + private static HashMap fontPreferenceNames; + + static { + fontPreferenceNames = new HashMap(); + fontPreferenceNames.put(SysdynResource.URIs.DependencyConnection, ARROW_FONT); + fontPreferenceNames.put(SysdynResource.URIs.AuxiliarySymbol, AUXILIARY_FONT); + 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.ModuleSymbol, MODULE_FONT); + + } + + public static String getFontPreferenceName(ReadGraph graph, Resource resource) + throws DatabaseException { + return fontPreferenceNames.get(getSymbolUri(graph, resource)); + } + + private 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.ModuleSymbol, MODULE_COLOR); + } + + 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 { + Layer0 L0 = Layer0.getInstance(graph); + Resource symbol = graph.getSingleObject(resource, L0.InstanceOf); + + SysdynResource SR = SysdynResource.getInstance(graph); + if(graph.isInheritedFrom(symbol, SR.ModuleSymbol)) + symbol = SR.ModuleSymbol; + + return graph.getURI(symbol); + } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPropertyExternalRead.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPropertyExternalRead.java index 4d76f611..afd856a1 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPropertyExternalRead.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPropertyExternalRead.java @@ -11,6 +11,7 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.preferences; +import org.eclipse.jface.preference.IPreferenceStore; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.request.ParametrizedPrimitiveRead; @@ -35,7 +36,11 @@ public class SysdynDiagramPropertyExternalRead extends ParametrizedPrimitiveRead public void register(ReadGraph graph, Listener procedure) { subscription = new SysdynDiagramPropertySubscription(procedure, parameter.second); SysdynDiagramPropertySupport.INSTANCE.register(subscription); - procedure.execute(Activator.getDefault().getPreferenceStore().getString(parameter.second)); + IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + if(store.contains(parameter.second)) { + procedure.execute(store.getString(parameter.second)); + } else + procedure.execute(null); } @Override 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 1e5d5b53..6b604795 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 @@ -16,10 +16,9 @@ import gnu.trove.set.hash.THashSet; import java.util.HashSet; import java.util.Set; -import org.eclipse.jface.resource.StringConverter; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; -import org.eclipse.swt.graphics.RGB; import org.simantics.sysdyn.ui.Activator; /** @@ -47,6 +46,17 @@ public class SysdynDiagramPropertySupport { add(SysdynDiagramPreferences.FLOW_COLOR); add(SysdynDiagramPreferences.STOCK_COLOR); add(SysdynDiagramPreferences.VALVE_COLOR); + add(SysdynDiagramPreferences.MODULE_COLOR); + + 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); Activator.getDefault().getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() { @Override @@ -55,10 +65,8 @@ public class SysdynDiagramPropertySupport { if(diagramProperties.contains(propertyName)){ for(SysdynDiagramPropertySubscription subscription : getSubscriptionSnapshot()) { if(propertyName.equals(subscription.getPropertyName())) { - Object newValue = event.getNewValue(); - String result = newValue.toString(); - if(newValue instanceof RGB) - result = StringConverter.asString((RGB)newValue); + IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + String result = store.getString(subscription.getPropertyName()); subscription.getListener().execute(result); } } -- 2.47.1