]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Unit parser of Sysdyn to match equivalents in reducing units (refs #4704).
authormiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 7 Feb 2014 08:03:36 +0000 (08:03 +0000)
committermiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 7 Feb 2014 08:03:36 +0000 (08:03 +0000)
Centered the text in auxiliary, input, stock and module.

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@28789 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/AuxiliaryFactory.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/InputFactory.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ModuleFactory.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/StockFactory.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java
org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/UnitResult.java

index 40e523b1860d804bbdf79660c74c29e5dc7bc1cb..ab3bbd30a809dafd9a1cdee93177e380d6226093 100644 (file)
@@ -52,7 +52,7 @@ public class AuxiliaryFactory extends SysdynElementFactory {
                 new StaticObjectAdapter(elementType),\r
                 new StaticSymbolImpl(AUX_STATIC_IMAGE),\r
                 StaticSymbolImageInitializer.INSTANCE,\r
-                new SysdynTextElementHandler(0, 0, Alignment.LEADING, 0, 1.5, 1.5, true),\r
+                new SysdynTextElementHandler(0, 0, Alignment.CENTER, 0, 1.5, 1.5, true),\r
                 BoundsOutline.INSTANCE,\r
                 ResizeRectangularSceneGraph.INSTANCE,\r
                 RESIZE_PROPERTY_SETTER,   \r
index 7f0aca6abab2a2835d78923c3c243f0068979a8d..b19f43da00b20c19580bc7ce1165372501e46b83 100644 (file)
@@ -90,7 +90,7 @@ public class InputFactory extends SysdynElementFactory {
                 new StaticSymbolImpl(INPUT_IMAGE),\r
                 StaticSymbolImageInitializer.INSTANCE,\r
                 Input.INSTANCE,\r
-                new InputSceneGraph(0, 0, Alignment.LEADING, 0, 1.5, 1.5, true),\r
+                new InputSceneGraph(0, 0, Alignment.CENTER, 0, 1.5, 1.5, true),\r
                 BoundsOutline.INSTANCE,\r
                 ResizeRectangularSceneGraph.INSTANCE,\r
                 RESIZE_PROPERTY_SETTER,                    \r
index be30fe1ff326166cd3ba5d1d1cf4ca66541ab8b4..175a95d58ef1c03eee8c86dae2a0b548e192db93 100644 (file)
@@ -58,7 +58,7 @@ public class ModuleFactory extends SysdynElementFactory {
                 new StaticObjectAdapter(elementType),\r
                 new StaticSymbolImpl(DEFAULT_IMAGE),\r
                 StaticSymbolImageInitializer.INSTANCE,\r
-                new ModuleSceneGraph(0, 0, Alignment.LEADING, 1f , 2, 3, true),\r
+                new ModuleSceneGraph(0, 0, Alignment.CENTER, 1f , 2, 3, true),\r
                 BoundsOutline.INSTANCE,\r
                 new BorderColorImpl(Color.BLACK),\r
                 ResizeRectangularSceneGraph.INSTANCE,\r
index a821104cbe06ee5e24685f15a8bd20592e179555..96b689510f754cee0bdeb0ebab6e5d0124471379 100644 (file)
@@ -58,7 +58,7 @@ public class StockFactory extends SysdynElementFactory {
                 new StaticObjectAdapter(elementType),\r
                 new StaticSymbolImpl(STOCK_IMAGE),\r
                 StaticSymbolImageInitializer.INSTANCE,\r
-                new SysdynTextElementHandler(0, 0, Alignment.LEADING, 1f, 1.0, 1.0, true),\r
+                new SysdynTextElementHandler(0, 0, Alignment.CENTER, 1f, 1.0, 1.0, true),\r
                 BoundsOutline.INSTANCE,\r
                 new BorderColorImpl(Color.BLACK),\r
                 ResizeRectangularSceneGraph.INSTANCE,\r
index 8db3657c809c9cc891f0e18cc0fe4101f7ce9ff3..1fb36162a2c5dd822dbacfcca4d94fd03f6afa94 100644 (file)
@@ -95,8 +95,8 @@ public class ResourceSelectionProcessor implements SelectionProcessor<Object, Re
                     \r
                     if(r != null) {\r
                         if(model == null)\r
-                            model = backend.getSingleObject(r, Layer0.getInstance(backend).PartOf);\r
-                        if(model.equals( backend.getSingleObject(r, Layer0.getInstance(backend).PartOf))) {\r
+                            model = backend.getPossibleObject(r, Layer0.getInstance(backend).PartOf);\r
+                        if(model != null && model.equals( backend.getSingleObject(r, Layer0.getInstance(backend).PartOf))) {\r
                                if (backend.isInstanceOf(r, sr.Variable)) {\r
                                        variables.add(r);\r
                                } else if (backend.isInstanceOf(r, sr.Dependency)) {\r
index 7daf08acc175da654fed710f48c6417761463a79..c5920af50dd5378de61c8e5445f74f42fb5a3f8f 100644 (file)
@@ -46,8 +46,8 @@ public class UnitResult {
                new Equivalent("$","$s","dollar","dollars","usd"),\r
                new Equivalent("\u20ac","\u20acs","eur","euro","euros","e","ecu"),\r
                new Equivalent("£","£s","pound","pounds","gbp"),\r
-               new Equivalent("Unit","Units"),\r
-               new Equivalent("Person","People","Persons"),\r
+               new Equivalent("unit","units"),\r
+               new Equivalent("person","people","persons"),\r
                new Equivalent("second","seconds","sec","s"),\r
                new Equivalent("minute","minutes","min"),\r
                new Equivalent("hour","hours","h","hr"),\r
@@ -144,7 +144,7 @@ public class UnitResult {
         \r
         ArrayList<String> copyDividers1 = new ArrayList<String>(dividers);\r
         ArrayList<String> copyDividents1 = new ArrayList<String>(dividents);\r
-        reduceUnitLists(dividents, copyDividents1, copyDividers1);\r
+        reduceUnitLists(dividents, copyDividents1, copyDividers1, allowEquivalents);\r
         \r
         StringBuilder sb = new StringBuilder();\r
         Iterator<String> iterator = copyDividents1.iterator();\r
@@ -190,11 +190,11 @@ public class UnitResult {
         \r
         ArrayList<String> copyDividers1 = new ArrayList<String>(dividers);\r
         ArrayList<String> copyDividents1 = new ArrayList<String>(dividents);\r
-        reduceUnitLists(dividents, copyDividents1, copyDividers1);\r
+        reduceUnitLists(dividents, copyDividents1, copyDividers1, allowEquivalents);\r
 \r
         ArrayList<String> copyDividers2 = new ArrayList<String>(other.dividers);\r
         ArrayList<String> copyDividents2 = new ArrayList<String>(other.dividents);    \r
-        reduceUnitLists(other.dividents, copyDividents2, copyDividers2);\r
+        reduceUnitLists(other.dividents, copyDividents2, copyDividers2, allowEquivalents);\r
 \r
         if(copyDividents1.size() != copyDividents2.size())\r
             return false;\r
@@ -247,11 +247,26 @@ public class UnitResult {
        return unit;\r
        }\r
 \r
-       public void reduceUnitLists(ArrayList<String> originalDividents, ArrayList<String> copyDividents, ArrayList<String> copyDividers) {\r
+       public void reduceUnitLists(\r
+                       ArrayList<String> originalDividents, \r
+                       ArrayList<String> copyDividents,\r
+                       ArrayList<String> copyDividers,\r
+                       boolean allowEquivalents) {\r
+               if (allowEquivalents) {\r
+                   // Replace equivalents\r
+                   for(int i = 0; i < originalDividents.size(); i++) {\r
+                       copyDividents.set(i, getDefaultForm(copyDividents.get(i)));\r
+                   }\r
+                   for(int i = 0; i < copyDividers.size(); i++) {\r
+                       copyDividers.set(i, getDefaultForm(copyDividers.get(i)));\r
+                   }\r
+        }\r
+               \r
         for(String s : originalDividents) {\r
-            if(copyDividers.contains(s)) {\r
-                copyDividers.remove(s);\r
-                copyDividents.remove(s);\r
+               String equiv = allowEquivalents ? getDefaultForm(s) : s;\r
+            if(copyDividers.contains(equiv)) {\r
+                copyDividers.remove(equiv);\r
+                copyDividents.remove(equiv);\r
             }\r
         }\r
         \r