From: lempinen Date: Fri, 25 Oct 2013 08:57:16 +0000 (+0000) Subject: PropertyPage for changing default colors of diagram elements. Currently only Dependen... X-Git-Tag: 1.8.1~220 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=9cb9b53b9a5b901839a404801905b89949bc8604;p=simantics%2Fsysdyn.git PropertyPage for changing default colors of diagram elements. Currently only Dependency arrows are supported. Default color is displayed if user has not specified a color for the element. refs #4481 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@28120 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.modelica/src/org/simantics/modelica/data/SimulationResult.java b/org.simantics.modelica/src/org/simantics/modelica/data/SimulationResult.java index 3f187058..315b1fc8 100644 --- a/org.simantics.modelica/src/org/simantics/modelica/data/SimulationResult.java +++ b/org.simantics.modelica/src/org/simantics/modelica/data/SimulationResult.java @@ -410,10 +410,10 @@ public class SimulationResult { */ public DataSet getDataSet(String name) { for(DataSet set : variables) - if(set.name.equals(name)) + if(set.name.equalsIgnoreCase(name)) return set; for(DataSet set : initials) - if(set.name.equals(name)) + if(set.name.equalsIgnoreCase(name)) return set; return null; } diff --git a/org.simantics.sysdyn.ontology/graph.tg b/org.simantics.sysdyn.ontology/graph.tg index 17eab9a3..5046ca49 100644 Binary files a/org.simantics.sysdyn.ontology/graph.tg and b/org.simantics.sysdyn.ontology/graph.tg differ diff --git a/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph b/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph index fa30152a..c209722f 100644 --- a/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph +++ b/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph @@ -24,8 +24,8 @@ SYSDYN.ImportedOntologies : PROJ.NamespaceRequirement "http://www.simantics.org/Sysdyn-1.1" : L0.URI "http://www.simantics.org/Layer0-1.1" : L0.URI "http://www.simantics.org/SelectionView-1.2" : L0.URI -// "http://www.simantics.org/Documentation-1.1" : L0.URI // Experimental documentation tool -// "http://www.simantics.org/DocumentWorkbench-1.0" : L0.URI // Experimental documentation tool + //"http://www.semantum.fi/Simupedia-1.0" : L0.URI // Experimental Simupedia + //"http://www.semantum.fi/SimupediaWorkbench-1.0" : L0.URI // Experimental Simupedia SYSDYN.SharedFunctionOntology -- SYSDYN.ValveSymbol.orientation --> SYSDYN.Orientation + + + + 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 4686cc62..61415eca 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 @@ -19,6 +19,7 @@ import java.util.Collections; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; +import org.simantics.db.Statement; import org.simantics.db.common.utils.OrderedSetUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.exception.ManyObjectsForFunctionalRelationException; @@ -101,9 +102,12 @@ public abstract class SysdynElementFactory extends SyncElementFactory { ElementUtils.setTextFont(e, G2DUtils.getFont(graph, fontResource)); } if (graph.isInstanceOf(element, dr.ColorProvider)) { - Resource colorResource = graph.getPossibleObject(element, g2d.HasColor); - if (colorResource != null) - ElementUtils.setTextColor(e, G2DUtils.getColor(graph, colorResource)); + Statement colorStatement = graph.getPossibleStatement(element, g2d.HasColor); + if (colorStatement != null && !colorStatement.isAsserted(element)) + ElementUtils.setTextColor(e, G2DUtils.getColor(graph, colorStatement.getObject())); + else { + + } } Resource component = graph.getPossibleObject(element, mr.ElementToComponent); 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 fcfb5445..b521dd4b 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 @@ -11,14 +11,18 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.elements.connections; +import java.awt.Color; import java.util.HashMap; import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.atomic.AtomicInteger; +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; import org.simantics.db.Resource; +import org.simantics.db.Statement; import org.simantics.db.exception.DatabaseException; import org.simantics.db.procedure.AsyncMultiProcedure; import org.simantics.db.procedure.AsyncProcedure; @@ -36,6 +40,8 @@ import org.simantics.g2d.element.IElement; import org.simantics.g2d.element.handler.impl.StaticObjectAdapter; import org.simantics.layer0.Layer0; import org.simantics.sysdyn.ui.editor.routing.DependencyRouter; +import org.simantics.sysdyn.ui.preferences.SysdynDiagramPreferences; +import org.simantics.sysdyn.ui.preferences.SysdynDiagramPropertyExternalRead; import org.simantics.utils.datastructures.Pair; /** @@ -92,12 +98,22 @@ public class DependencyConnectionFactory extends ElementFactoryAdapter { }); // Find possible color - graph.forPossibleObject(elementResource, G2D.HasColor, new SyncProcedure() { + graph.forPossibleStatement(elementResource, G2D.HasColor, new SyncProcedure() { @Override - public void execute(ReadGraph graph, Resource result) throws DatabaseException { - if(result != null) { - element.setHint(ElementHints.KEY_TEXT_COLOR, G2DUtils.getColor(graph, result)); + public void execute(ReadGraph graph, Statement result) throws DatabaseException { + if(result != null && !result.isAsserted(elementResource)) { + element.setHint(ElementHints.KEY_TEXT_COLOR, G2DUtils.getColor(graph, result.getObject())); + } else { + String color = graph.syncRequest(new SysdynDiagramPropertyExternalRead(new Pair(elementResource, SysdynDiagramPreferences.ARROW_COLOR))); + if(color != null) { + RGB rgb = StringConverter.asRGB(color, null); + if(rgb != null) { + Color c = new Color(rgb.red, rgb.green, rgb.blue); + element.setHint(ElementHints.KEY_TEXT_COLOR, c); + } + } + } } 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 new file mode 100644 index 00000000..ce357b73 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPreferencePage.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2013 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum Oy + *******************************************************************************/ + +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.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; + +/** + * + * @author Teemu Lempinen + * + */ +public class SysdynDiagramPreferencePage extends FieldEditorPreferencePage implements +IWorkbenchPreferencePage { + + public SysdynDiagramPreferencePage() { + super(GRID); + setDescription("System dynamics diagram preferences"); + } + + @Override + public void init(IWorkbench workbench) { + setPreferenceStore(Activator.getDefault().getPreferenceStore()); + } + + @Override + protected void createFieldEditors() { + 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(); + } + } + } + + + return super.performOk(); + } + +} 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 new file mode 100644 index 00000000..5ab40e62 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPreferences.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2013 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum Oy + *******************************************************************************/ +package org.simantics.sysdyn.ui.preferences; + +/** + * + * @author Teemu Lempinen + * + */ +public class SysdynDiagramPreferences { + + 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"; + + +} 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 new file mode 100644 index 00000000..0539888f --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPreferencesInitializer.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2013 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum Oy + *******************************************************************************/ +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.swt.graphics.RGB; +import org.simantics.sysdyn.ui.Activator; + +/** + * + * @author Teemu Lempinen + * + */ +public class SysdynDiagramPreferencesInitializer extends AbstractPreferenceInitializer { + + @Override + public void initializeDefaultPreferences() { + 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))); + } + + +} 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 new file mode 100644 index 00000000..4d76f611 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPropertyExternalRead.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2013 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum Oy + *******************************************************************************/ +package org.simantics.sysdyn.ui.preferences; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ParametrizedPrimitiveRead; +import org.simantics.db.procedure.Listener; +import org.simantics.sysdyn.ui.Activator; +import org.simantics.utils.datastructures.Pair; + +/** + * + * @author Teemu Lempinen + * + */ +public class SysdynDiagramPropertyExternalRead extends ParametrizedPrimitiveRead, String> { + + private SysdynDiagramPropertySubscription subscription; + + public SysdynDiagramPropertyExternalRead(Pair input) { + super(input); + } + + @Override + 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)); + } + + @Override + public void unregistered() { + if(subscription != null) { + SysdynDiagramPropertySupport.INSTANCE.unregister(subscription); + subscription = null; + } + } +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPropertySubscription.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPropertySubscription.java new file mode 100644 index 00000000..286572cf --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPropertySubscription.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2013 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum Oy + *******************************************************************************/ +package org.simantics.sysdyn.ui.preferences; + +import org.simantics.db.procedure.Listener; + +/** + * + * @author Teemu Lempinen + * + */ +public class SysdynDiagramPropertySubscription { + + private Listener listener; + private String propertyName; + + public SysdynDiagramPropertySubscription(Listener listener, String propertyName) { + this.listener = listener; + this.propertyName = propertyName; + } + + public Listener getListener() { + return listener; + } + + public String getPropertyName() { + return propertyName; + } +} 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 new file mode 100644 index 00000000..1e5d5b53 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SysdynDiagramPropertySupport.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2013 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum Oy + *******************************************************************************/ +package org.simantics.sysdyn.ui.preferences; + +import gnu.trove.set.hash.THashSet; + +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.jface.resource.StringConverter; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.swt.graphics.RGB; +import org.simantics.sysdyn.ui.Activator; + +/** + * + * @author Teemu Lempinen + * + */ +public class SysdynDiagramPropertySupport { + + public static SysdynDiagramPropertySupport INSTANCE = new SysdynDiagramPropertySupport(); + + private Set diagramProperties; + private THashSet subscriptions = new THashSet(); + private SysdynDiagramPropertySubscription[] subscriptionSnapshot = null; + + private void add(String property) { + diagramProperties.add(property); + } + + 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); + + Activator.getDefault().getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent event) { + String propertyName = event.getProperty(); + 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); + subscription.getListener().execute(result); + } + } + } + } + }); + } + + public void register(SysdynDiagramPropertySubscription subscription) { + assert subscription != null; + synchronized (subscriptions) { + subscriptions.add(subscription); + subscriptionSnapshot = null; + } + } + + public void unregister(SysdynDiagramPropertySubscription subscription) { + assert subscription != null; + synchronized (subscriptions) { + subscriptions.remove(subscription); + subscriptionSnapshot = null; + } + + } + + public SysdynDiagramPropertySubscription[] getSubscriptionSnapshot() { + SysdynDiagramPropertySubscription[] snapshot = subscriptionSnapshot; + if (snapshot == null) { + synchronized (subscriptions) { + snapshot = subscriptionSnapshot; + if (snapshot == null) { + snapshot = subscriptionSnapshot = + subscriptions.toArray(new SysdynDiagramPropertySubscription[subscriptions.size()]); + } + } + } + return snapshot; + } + +} diff --git a/org.simantics.sysdyn.ui/sysdyn.product b/org.simantics.sysdyn.ui/sysdyn.product index 921a8d4c..d65c835e 100644 --- a/org.simantics.sysdyn.ui/sysdyn.product +++ b/org.simantics.sysdyn.ui/sysdyn.product @@ -14,7 +14,8 @@ -fixerrors ---launcher.XXMaxPermSize 192m +--launcher.XXMaxPermSize 192m +-data @noDefault -ea -Xmx768M -XX:MaxPermSize=192m -Xshare:off -XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts @@ -30,7 +31,6 @@ - org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6