]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Chart elements for diagrams
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 15 Dec 2011 08:42:25 +0000 (08:42 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 15 Dec 2011 08:42:25 +0000 (08:42 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@23568 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/adapters.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/DiagramViewer.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYPlot.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartBoundsOutline.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartElementFactory.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartElementWriter.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartNode.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartSceneGraph.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/PopulateChartDropParticipant.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ResizeListener.java [new file with mode: 0644]

index 336f926863365dd4e98f0f37231631fa489f6661..390ea2d9b15384af7af797ac2baf68ac3fb141df 100644 (file)
@@ -10,5 +10,5 @@
         VTT Technical Research Centre of Finland - initial API and implementation\r
  -->\r
 
-<adapters>\r\r   <target interface="org.simantics.db.layer0.adapter.Realization">\r               <type uri="http://www.simantics.org/Sysdyn-0.0/Module"\r                 class="org.simantics.structural2.realization.StructuralRealization">\r                   <this />\r               </type>\r        </target>\r\r     <target interface="org.simantics.layer0.utils.triggers.ITrigger">\r      <type uri = "http://www.simantics.org/Sysdyn-0.0/DiagramToCompositeMapping"\r          class = "org.simantics.sysdyn.ui.editor.DiagramToCompositeMapping3">\r         <graph/>\r           <this />\r       </type>\r        </target>\r      \r       <target interface="org.simantics.structural.ui.modelBrowser.nodes.AbstractNode">\r               <type uri="http://www.simantics.org/Sysdyn-0.0/SysdynModel"\r                    class="org.simantics.structural.ui.modelBrowser.nodes.ModelNode">\r                      <this />\r               </type>\r        </target>               \r               \r\r      <target\r                interface="org.simantics.browsing.ui.common.node.AbstractNode">\r                <type\r                  uri="http://www.simantics.org/Sysdyn-0.0/SysdynModel"\r                  class="org.simantics.sysdyn.ui.browser.nodes.ModelNode">\r                       <this />\r               </type>\r\r               <resource\r                      uri="http://www.simantics.org/Sysdyn-0.0/ModuleSymbol"\r                 class="org.simantics.sysdyn.ui.browser.nodes.SymbolNode">\r                      <this />\r               </resource>\r\r           <type\r                  uri="http://www.simantics.org/Simulation-1.0/Experiment"\r                       class="org.simantics.sysdyn.ui.browser.nodes.ExperimentNode">\r                  <this />\r               </type>\r                \r               <type\r                  uri="http://www.simantics.org/Sysdyn-0.0/Result"\r                       class="org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode">\r                    <this />\r               </type>\r                \r       </target>\r\r     <!-- Inject default connection routing algorithm for sysdyn diagrams -->\r       <target interface="org.simantics.g2d.diagram.DiagramClass">\r            <adapter uri="http://www.simantics.org/Sysdyn-0.0/ConfigurationDiagram"\r                        adapterClass="org.simantics.sysdyn.ui.elements2.ConfigurationDiagramClassAdapter" />\r   </target>\r\r     <!-- Sysdyn symbols -->\r        <target interface="org.simantics.diagram.adapter.ElementFactory">\r              <resource uri="http://www.simantics.org/Sysdyn-0.0/StockSymbol"\r                        class="org.simantics.sysdyn.ui.elements2.StockFactory" />\r              <resource uri="http://www.simantics.org/Sysdyn-0.0/ModuleSymbol"\r                       class="org.simantics.sysdyn.ui.elements2.ModuleFactory" />\r             <resource uri="http://www.simantics.org/Sysdyn-0.0/ValveSymbol"\r                        class="org.simantics.sysdyn.ui.elements2.ValveFactory" />\r              <resource uri="http://www.simantics.org/Sysdyn-0.0/AuxiliarySymbol"\r                    class="org.simantics.sysdyn.ui.elements2.AuxiliaryFactory" />\r          <resource uri="http://www.simantics.org/Sysdyn-0.0/CloudSymbol"\r                        class="org.simantics.sysdyn.ui.elements2.CloudFactory" />\r              <resource uri="http://www.simantics.org/Sysdyn-0.0/InputSymbol"\r                        class="org.simantics.sysdyn.ui.elements2.InputFactory" />\r\r             <type uri="http://www.simantics.org/Sysdyn-0.0/StockSymbol"\r                    class="org.simantics.sysdyn.ui.elements2.StockFactory" />\r              <type uri="http://www.simantics.org/Sysdyn-0.0/ModuleSymbol"\r                   class="org.simantics.sysdyn.ui.elements2.ModuleFactory" />\r             <type uri="http://www.simantics.org/Sysdyn-0.0/ValveSymbol"\r                    class="org.simantics.sysdyn.ui.elements2.ValveFactory" />\r              <type uri="http://www.simantics.org/Sysdyn-0.0/AuxiliarySymbol"\r                        class="org.simantics.sysdyn.ui.elements2.AuxiliaryFactory" />\r          <type uri="http://www.simantics.org/Sysdyn-0.0/CloudSymbol"\r                    class="org.simantics.sysdyn.ui.elements2.CloudFactory" />\r              <type uri="http://www.simantics.org/Sysdyn-0.0/InputSymbol"\r                    class="org.simantics.sysdyn.ui.elements2.InputFactory" />                       \r       </target>\r      \r       <!-- Sysdyn connections -->\r    <target interface="org.simantics.diagram.adapter.ElementFactory">\r              <!-- Edges -->       \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/FlowConnection"\r            class="org.simantics.sysdyn.ui.elements2.connections.RouteFlowEdgeFactory" />\r        <type uri="http://www.simantics.org/Sysdyn-0.0/FlowConnection"\r            class="org.simantics.sysdyn.ui.elements2.connections.RouteFlowEdgeFactory" />            \r        <type uri="http://www.simantics.org/Sysdyn-0.0/FlowConnection"\r            class="org.simantics.sysdyn.ui.elements2.connections.RouteFlowConnectionFactory">\r            <graph/>\r        </type>                       \r                       \r               <resource uri="http://www.simantics.org/Sysdyn-0.0/DependencyConnection"\r                       class="org.simantics.sysdyn.ui.elements2.connections.DependencyEdgeFactory" />\r         <type uri="http://www.simantics.org/Sysdyn-0.0/DependencyConnection"\r                   class="org.simantics.sysdyn.ui.elements2.connections.DependencyEdgeFactory" />\r         <type uri="http://www.simantics.org/Sysdyn-0.0/DependencyConnection"\r                   class="org.simantics.sysdyn.ui.elements2.connections.DependencyConnectionFactory" />\r   </target>\r      \r       <target interface="org.simantics.g2d.connection.EdgeVisualsConfigurer">\r          <baseType uri="http://www.simantics.org/Diagram-0.0/HasConnector" />\r   <resource uri="http://www.simantics.org/Diagram-0.0/HasPlainConnector"\r          class="org.simantics.diagram.content.ArrowConfigurer">\r         <string>none 0</string>\r       </resource>\r    <resource uri="http://www.simantics.org/Diagram-0.0/HasArrowConnector"\r          class="org.simantics.diagram.content.ArrowConfigurer">\r         <string>fill 1</string>\r       </resource>\r  </target>\r      \r       <!-- ModelBrowser2 -->\r \r       <target interface="org.simantics.browsing.ui.model.children.ChildRule">\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectBrowseContext/ModuleTypeChildRule"\r            class="org.simantics.sysdyn.ui.browser.childrules.ModuleTypeChildRule"/>\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectBrowseContext/ModuleContentChildRule"\r            class="org.simantics.sysdyn.ui.browser.childrules.ModuleContentChildRule"/>     \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ChartAxisAndVariablesBrowseContext/AxisChildRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.AxisChildRule"/>     \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ChartAxisAndVariablesBrowseContext/VariableChildRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.VariableChildRule"/>  \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/BarSeriesBrowseContext/SeriesChildRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesChildRule"/>           \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/PieSeriesBrowseContext/SeriesChildRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesChildRule"/>                          \r    </target>\r    \r    <target interface="org.simantics.browsing.ui.model.visuals.VisualsRule">\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectBrowseContext/ModuleTypeLabelRule"\r            class="org.simantics.sysdyn.ui.browser.labelrules.ModuleTypeLabelRule"/>\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ChartAxisAndVariablesBrowseContext/SeriesLabelRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesLabelRule"/>         \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ChartAxisAndVariablesBrowseContext/AxisLabelRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.AxisLabelRule"/> \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/BarSeriesBrowseContext/SeriesLabelRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesLabelRule"/>         \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/PieSeriesBrowseContext/SeriesLabelRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesLabelRule"/>       \r                     \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ChartAxisAndVariablesBrowseContext/SeriesLabelDecorationRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesLabelDecorationRule"/>   \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/BarSeriesBrowseContext/SeriesLabelDecorationRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesLabelDecorationRule"/>         \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/PieSeriesBrowseContext/SeriesLabelDecorationRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesLabelDecorationRule"/>       \r                                               \r    </target>    \r    \r    <target interface="org.simantics.db.layer0.adapter.ActionFactory">\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectActionContext/Actions/NewModuleType"\r            class="org.simantics.sysdyn.ui.browser.actions.NewModuleTypeAction" />\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectActionContext/Actions/NewEnumeration"\r            class="org.simantics.sysdyn.ui.browser.actions.NewEnumerationAction" />\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectActionContext/Actions/OpenWorkbook"\r            class="org.simantics.sysdyn.ui.browser.actions.OpenWorkbookAction" />\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectActionContext/Actions/NewFunction"\r            class="org.simantics.sysdyn.ui.browser.actions.NewFunctionAction" />\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectActionContext/Actions/NewFunctionLibrary"\r            class="org.simantics.sysdyn.ui.browser.actions.NewFunctionLibraryAction" />\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectActionContext/Actions/NewSharedFunctionLibrary"\r            class="org.simantics.sysdyn.ui.browser.actions.NewSharedFunctionLibraryAction" />            \r    </target>         \r    \r   <target interface="org.simantics.db.layer0.adapter.DropActionFactory">\r        <resource\r            uri="http://www.simantics.org/Sysdyn-0.0/ChartAxisAndVariablesActionContext/Actions/SeriesDropAction"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesDropAction" />\r        <resource\r            uri="http://www.simantics.org/Sysdyn-0.0/ChartAxisAndVariablesActionContext/Actions/AxisDropAction"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.AxisDropAction" />            \r    </target>     \r  \r  <!-- PROFILES -->\r    <target interface="org.simantics.scenegraph.profile.Style">\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/SimulationPlaybackStyle"\r            class="org.simantics.sysdyn.ui.elements2.profiles.SimulationPlaybackStyle">\r        </resource>\r                <resource uri="http://www.simantics.org/Sysdyn-0.0/IssueStyle"\r            class="org.simantics.sysdyn.ui.elements2.profiles.IssueDecorationStyle">\r        </resource>\r    </target>\r    \r  <!-- Charts -->\r    <target interface="org.simantics.sysdyn.ui.trend.chart.IJFreeChart">\r        <type uri="http://www.simantics.org/JFreeChart-1.0/Chart"\r            class="org.simantics.sysdyn.ui.trend.chart.JFreeChart">\r            <graph />\r            <this />\r        </type>\r    </target>  \r    \r    <target interface="org.simantics.sysdyn.ui.trend.chart.IDataset">\r        <type uri="http://www.simantics.org/JFreeChart-1.0/XYDataset"\r            class="org.simantics.sysdyn.ui.trend.chart.XYDataset">\r            <graph />\r            <this />\r        </type>\r        <type uri="http://www.simantics.org/JFreeChart-1.0/CategoryDataset"\r            class="org.simantics.sysdyn.ui.trend.chart.CategoryDataset">\r            <graph />\r            <this />\r        </type>        \r        <type uri="http://www.simantics.org/JFreeChart-1.0/PieDataset"\r            class="org.simantics.sysdyn.ui.trend.chart.PieDataset">\r            <graph />\r            <this />\r        </type>          \r    </target>\r    \r     <target interface="org.simantics.sysdyn.ui.trend.chart.ITitle">\r        <type uri="http://www.simantics.org/JFreeChart-1.0/TextTitle"\r            class="org.simantics.sysdyn.ui.trend.chart.TextTitle">\r            <graph />\r            <this />\r        </type>\r    </target>\r    \r    <target interface="org.simantics.sysdyn.ui.trend.chart.IAxis">\r        <type uri="http://www.simantics.org/JFreeChart-1.0/NumberAxis"\r            class="org.simantics.sysdyn.ui.trend.chart.NumberAxis">\r            <graph />\r            <this />\r        </type>\r        <type uri="http://www.simantics.org/JFreeChart-1.0/CategoryAxis"\r            class="org.simantics.sysdyn.ui.trend.chart.CategoryAxis">\r            <graph />\r            <this />\r        </type>        \r    </target>\r       \r    <target interface="org.simantics.sysdyn.ui.trend.chart.IPlot">\r        <type uri="http://www.simantics.org/JFreeChart-1.0/XYPlot"\r            class="org.simantics.sysdyn.ui.trend.chart.XYPlot">\r            <graph />\r            <this />\r        </type>\r        <type uri="http://www.simantics.org/JFreeChart-1.0/CategoryPlot"\r            class="org.simantics.sysdyn.ui.trend.chart.CategoryPlot">\r            <graph />\r            <this />\r        </type>      \r        <type uri="http://www.simantics.org/JFreeChart-1.0/PiePlot"\r            class="org.simantics.sysdyn.ui.trend.chart.PiePlot">\r            <graph />\r            <this />\r        </type>               \r    </target>\r    \r     <target interface="org.simantics.sysdyn.ui.trend.chart.IRenderer">\r        <type uri="http://www.simantics.org/JFreeChart-1.0/BarRenderer"\r            class="org.simantics.sysdyn.ui.trend.chart.BarRenderer">\r            <graph />\r            <this />\r        </type>\r        <type uri="http://www.simantics.org/JFreeChart-1.0/StackedBarRenderer"\r            class="org.simantics.sysdyn.ui.trend.chart.StackedBarRenderer">\r            <graph />\r            <this />\r        </type>        \r    </target>    \r       \r
+<adapters>\r\r   <target interface="org.simantics.db.layer0.adapter.Realization">\r               <type uri="http://www.simantics.org/Sysdyn-0.0/Module"\r                 class="org.simantics.structural2.realization.StructuralRealization">\r                   <this />\r               </type>\r        </target>\r\r     <target interface="org.simantics.layer0.utils.triggers.ITrigger">\r      <type uri = "http://www.simantics.org/Sysdyn-0.0/DiagramToCompositeMapping"\r          class = "org.simantics.sysdyn.ui.editor.DiagramToCompositeMapping3">\r         <graph/>\r           <this />\r       </type>\r        </target>\r      \r       <target interface="org.simantics.structural.ui.modelBrowser.nodes.AbstractNode">\r               <type uri="http://www.simantics.org/Sysdyn-0.0/SysdynModel"\r                    class="org.simantics.structural.ui.modelBrowser.nodes.ModelNode">\r                      <this />\r               </type>\r        </target>               \r               \r\r      <target\r                interface="org.simantics.browsing.ui.common.node.AbstractNode">\r                <type\r                  uri="http://www.simantics.org/Sysdyn-0.0/SysdynModel"\r                  class="org.simantics.sysdyn.ui.browser.nodes.ModelNode">\r                       <this />\r               </type>\r\r               <resource\r                      uri="http://www.simantics.org/Sysdyn-0.0/ModuleSymbol"\r                 class="org.simantics.sysdyn.ui.browser.nodes.SymbolNode">\r                      <this />\r               </resource>\r\r           <type\r                  uri="http://www.simantics.org/Simulation-1.0/Experiment"\r                       class="org.simantics.sysdyn.ui.browser.nodes.ExperimentNode">\r                  <this />\r               </type>\r                \r               <type\r                  uri="http://www.simantics.org/Sysdyn-0.0/Result"\r                       class="org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode">\r                    <this />\r               </type>\r                \r       </target>\r\r     <!-- Inject default connection routing algorithm for sysdyn diagrams -->\r       <target interface="org.simantics.g2d.diagram.DiagramClass">\r            <adapter uri="http://www.simantics.org/Sysdyn-0.0/ConfigurationDiagram"\r                        adapterClass="org.simantics.sysdyn.ui.elements2.ConfigurationDiagramClassAdapter" />\r   </target>\r\r     <!-- Sysdyn symbols -->\r        <target interface="org.simantics.diagram.adapter.ElementFactory">\r              <resource uri="http://www.simantics.org/Sysdyn-0.0/StockSymbol"\r                        class="org.simantics.sysdyn.ui.elements2.StockFactory" />\r              <resource uri="http://www.simantics.org/Sysdyn-0.0/ModuleSymbol"\r                       class="org.simantics.sysdyn.ui.elements2.ModuleFactory" />\r             <resource uri="http://www.simantics.org/Sysdyn-0.0/ValveSymbol"\r                        class="org.simantics.sysdyn.ui.elements2.ValveFactory" />\r              <resource uri="http://www.simantics.org/Sysdyn-0.0/AuxiliarySymbol"\r                    class="org.simantics.sysdyn.ui.elements2.AuxiliaryFactory" />\r          <resource uri="http://www.simantics.org/Sysdyn-0.0/CloudSymbol"\r                        class="org.simantics.sysdyn.ui.elements2.CloudFactory" />\r              <resource uri="http://www.simantics.org/Sysdyn-0.0/InputSymbol"\r                        class="org.simantics.sysdyn.ui.elements2.InputFactory" />\r\r             <type uri="http://www.simantics.org/Sysdyn-0.0/StockSymbol"\r                    class="org.simantics.sysdyn.ui.elements2.StockFactory" />\r              <type uri="http://www.simantics.org/Sysdyn-0.0/ModuleSymbol"\r                   class="org.simantics.sysdyn.ui.elements2.ModuleFactory" />\r             <type uri="http://www.simantics.org/Sysdyn-0.0/ValveSymbol"\r                    class="org.simantics.sysdyn.ui.elements2.ValveFactory" />\r              <type uri="http://www.simantics.org/Sysdyn-0.0/AuxiliarySymbol"\r                        class="org.simantics.sysdyn.ui.elements2.AuxiliaryFactory" />\r          <type uri="http://www.simantics.org/Sysdyn-0.0/CloudSymbol"\r                    class="org.simantics.sysdyn.ui.elements2.CloudFactory" />\r              <type uri="http://www.simantics.org/Sysdyn-0.0/InputSymbol"\r                    class="org.simantics.sysdyn.ui.elements2.InputFactory" />                       \r       </target>\r      \r       <!-- Sysdyn connections -->\r    <target interface="org.simantics.diagram.adapter.ElementFactory">\r              <!-- Edges -->       \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/FlowConnection"\r            class="org.simantics.sysdyn.ui.elements2.connections.RouteFlowEdgeFactory" />\r        <type uri="http://www.simantics.org/Sysdyn-0.0/FlowConnection"\r            class="org.simantics.sysdyn.ui.elements2.connections.RouteFlowEdgeFactory" />            \r        <type uri="http://www.simantics.org/Sysdyn-0.0/FlowConnection"\r            class="org.simantics.sysdyn.ui.elements2.connections.RouteFlowConnectionFactory">\r            <graph/>\r        </type>                       \r                       \r               <resource uri="http://www.simantics.org/Sysdyn-0.0/DependencyConnection"\r                       class="org.simantics.sysdyn.ui.elements2.connections.DependencyEdgeFactory" />\r         <type uri="http://www.simantics.org/Sysdyn-0.0/DependencyConnection"\r                   class="org.simantics.sysdyn.ui.elements2.connections.DependencyEdgeFactory" />\r         <type uri="http://www.simantics.org/Sysdyn-0.0/DependencyConnection"\r                   class="org.simantics.sysdyn.ui.elements2.connections.DependencyConnectionFactory" />\r   </target>\r      \r       <target interface="org.simantics.g2d.connection.EdgeVisualsConfigurer">\r          <baseType uri="http://www.simantics.org/Diagram-0.0/HasConnector" />\r   <resource uri="http://www.simantics.org/Diagram-0.0/HasPlainConnector"\r          class="org.simantics.diagram.content.ArrowConfigurer">\r         <string>none 0</string>\r       </resource>\r    <resource uri="http://www.simantics.org/Diagram-0.0/HasArrowConnector"\r          class="org.simantics.diagram.content.ArrowConfigurer">\r         <string>fill 1</string>\r       </resource>\r  </target>\r      \r       <!-- ModelBrowser2 -->\r \r       <target interface="org.simantics.browsing.ui.model.children.ChildRule">\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectBrowseContext/ModuleTypeChildRule"\r            class="org.simantics.sysdyn.ui.browser.childrules.ModuleTypeChildRule"/>\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectBrowseContext/ModuleContentChildRule"\r            class="org.simantics.sysdyn.ui.browser.childrules.ModuleContentChildRule"/>     \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ChartAxisAndVariablesBrowseContext/AxisChildRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.AxisChildRule"/>     \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ChartAxisAndVariablesBrowseContext/VariableChildRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.VariableChildRule"/>  \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/BarSeriesBrowseContext/SeriesChildRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesChildRule"/>           \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/PieSeriesBrowseContext/SeriesChildRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesChildRule"/>                          \r    </target>\r    \r    <target interface="org.simantics.browsing.ui.model.visuals.VisualsRule">\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectBrowseContext/ModuleTypeLabelRule"\r            class="org.simantics.sysdyn.ui.browser.labelrules.ModuleTypeLabelRule"/>\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ChartAxisAndVariablesBrowseContext/SeriesLabelRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesLabelRule"/>         \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ChartAxisAndVariablesBrowseContext/AxisLabelRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.AxisLabelRule"/> \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/BarSeriesBrowseContext/SeriesLabelRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesLabelRule"/>         \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/PieSeriesBrowseContext/SeriesLabelRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesLabelRule"/>       \r                     \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ChartAxisAndVariablesBrowseContext/SeriesLabelDecorationRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesLabelDecorationRule"/>   \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/BarSeriesBrowseContext/SeriesLabelDecorationRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesLabelDecorationRule"/>         \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/PieSeriesBrowseContext/SeriesLabelDecorationRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesLabelDecorationRule"/>       \r                                               \r    </target>    \r    \r    <target interface="org.simantics.db.layer0.adapter.ActionFactory">\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectActionContext/Actions/NewModuleType"\r            class="org.simantics.sysdyn.ui.browser.actions.NewModuleTypeAction" />\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectActionContext/Actions/NewEnumeration"\r            class="org.simantics.sysdyn.ui.browser.actions.NewEnumerationAction" />\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectActionContext/Actions/OpenWorkbook"\r            class="org.simantics.sysdyn.ui.browser.actions.OpenWorkbookAction" />\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectActionContext/Actions/NewFunction"\r            class="org.simantics.sysdyn.ui.browser.actions.NewFunctionAction" />\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectActionContext/Actions/NewFunctionLibrary"\r            class="org.simantics.sysdyn.ui.browser.actions.NewFunctionLibraryAction" />\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectActionContext/Actions/NewSharedFunctionLibrary"\r            class="org.simantics.sysdyn.ui.browser.actions.NewSharedFunctionLibraryAction" />            \r    </target>         \r    \r   <target interface="org.simantics.db.layer0.adapter.DropActionFactory">\r        <resource\r            uri="http://www.simantics.org/Sysdyn-0.0/ChartAxisAndVariablesActionContext/Actions/SeriesDropAction"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesDropAction" />\r        <resource\r            uri="http://www.simantics.org/Sysdyn-0.0/ChartAxisAndVariablesActionContext/Actions/AxisDropAction"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.AxisDropAction" />            \r    </target>     \r  \r  <!-- PROFILES -->\r    <target interface="org.simantics.scenegraph.profile.Style">\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/SimulationPlaybackStyle"\r            class="org.simantics.sysdyn.ui.elements2.profiles.SimulationPlaybackStyle">\r        </resource>\r                <resource uri="http://www.simantics.org/Sysdyn-0.0/IssueStyle"\r            class="org.simantics.sysdyn.ui.elements2.profiles.IssueDecorationStyle">\r        </resource>\r    </target>\r    \r  <!-- Charts -->\r    <target interface="org.simantics.diagram.adapter.ElementFactory">\r        <resource uri="http://www.simantics.org/JFreeChart-1.0/ChartElement"\r            class="org.simantics.sysdyn.ui.trend.chart.element.ChartElementFactory" />\r            \r        <type uri="http://www.simantics.org/JFreeChart-1.0/ChartElement"\r            class="org.simantics.sysdyn.ui.trend.chart.element.ChartElementFactory" />\r    </target>\r                \r    <target interface="org.simantics.diagram.synchronization.graph.ElementWriter">\r        <resource uri="http://www.simantics.org/JFreeChart-1.0/ChartElement"\r            class="org.simantics.sysdyn.ui.trend.chart.element.ChartElementWriter" />\r    </target>\r                    \r    <target interface="org.simantics.sysdyn.ui.trend.chart.IJFreeChart">\r        <type uri="http://www.simantics.org/JFreeChart-1.0/Chart"\r            class="org.simantics.sysdyn.ui.trend.chart.JFreeChart">\r            <graph />\r            <this />\r        </type>\r    </target>  \r    \r    <target interface="org.simantics.sysdyn.ui.trend.chart.IDataset">\r        <type uri="http://www.simantics.org/JFreeChart-1.0/XYDataset"\r            class="org.simantics.sysdyn.ui.trend.chart.XYDataset">\r            <graph />\r            <this />\r        </type>\r        <type uri="http://www.simantics.org/JFreeChart-1.0/CategoryDataset"\r            class="org.simantics.sysdyn.ui.trend.chart.CategoryDataset">\r            <graph />\r            <this />\r        </type>        \r        <type uri="http://www.simantics.org/JFreeChart-1.0/PieDataset"\r            class="org.simantics.sysdyn.ui.trend.chart.PieDataset">\r            <graph />\r            <this />\r        </type>          \r    </target>\r    \r     <target interface="org.simantics.sysdyn.ui.trend.chart.ITitle">\r        <type uri="http://www.simantics.org/JFreeChart-1.0/TextTitle"\r            class="org.simantics.sysdyn.ui.trend.chart.TextTitle">\r            <graph />\r            <this />\r        </type>\r    </target>\r    \r    <target interface="org.simantics.sysdyn.ui.trend.chart.IAxis">\r        <type uri="http://www.simantics.org/JFreeChart-1.0/NumberAxis"\r            class="org.simantics.sysdyn.ui.trend.chart.NumberAxis">\r            <graph />\r            <this />\r        </type>\r        <type uri="http://www.simantics.org/JFreeChart-1.0/CategoryAxis"\r            class="org.simantics.sysdyn.ui.trend.chart.CategoryAxis">\r            <graph />\r            <this />\r        </type>        \r    </target>\r       \r    <target interface="org.simantics.sysdyn.ui.trend.chart.IPlot">\r        <type uri="http://www.simantics.org/JFreeChart-1.0/XYPlot"\r            class="org.simantics.sysdyn.ui.trend.chart.XYPlot">\r            <graph />\r            <this />\r        </type>\r        <type uri="http://www.simantics.org/JFreeChart-1.0/CategoryPlot"\r            class="org.simantics.sysdyn.ui.trend.chart.CategoryPlot">\r            <graph />\r            <this />\r        </type>      \r        <type uri="http://www.simantics.org/JFreeChart-1.0/PiePlot"\r            class="org.simantics.sysdyn.ui.trend.chart.PiePlot">\r            <graph />\r            <this />\r        </type>               \r    </target>\r    \r     <target interface="org.simantics.sysdyn.ui.trend.chart.IRenderer">\r        <type uri="http://www.simantics.org/JFreeChart-1.0/BarRenderer"\r            class="org.simantics.sysdyn.ui.trend.chart.BarRenderer">\r            <graph />\r            <this />\r        </type>\r        <type uri="http://www.simantics.org/JFreeChart-1.0/StackedBarRenderer"\r            class="org.simantics.sysdyn.ui.trend.chart.StackedBarRenderer">\r            <graph />\r            <this />\r        </type>        \r    </target>    \r       \r
 </adapters>
\ No newline at end of file
index e6c5107af9116b0ffe91d4f1f77611dbebc9d2fc..34dd82e502f137138230e705ccc401a49f7030ab 100644 (file)
@@ -48,7 +48,6 @@ import org.simantics.g2d.participant.GridPainter;
 import org.simantics.g2d.participant.RulerPainter;\r
 import org.simantics.modeling.mapping.ElementCopyAdvisor;\r
 import org.simantics.modeling.mapping.MappedElementCopyAdvisor;\r
-import org.simantics.modeling.ui.diagramEditor.PopulateElementMonitorDropParticipant;\r
 import org.simantics.modeling.ui.diagramEditor.handlers.LinkBrowsingHandler;\r
 import org.simantics.structural2.modelingRules.IModelingRules;\r
 import org.simantics.sysdyn.SysdynResource;\r
@@ -63,6 +62,7 @@ import org.simantics.sysdyn.ui.elements2.connections.ConnectionClasses;
 import org.simantics.sysdyn.ui.elements2.connections.RouteFlowEdgeClass;\r
 import org.simantics.sysdyn.ui.elements2.connections.SysdynConnectionClass;\r
 import org.simantics.sysdyn.ui.properties.SysdynPropertyPage;\r
+import org.simantics.sysdyn.ui.trend.chart.element.PopulateChartDropParticipant;\r
 import org.simantics.ui.workbench.IPropertyPage;\r
 import org.simantics.utils.datastructures.hints.HintContext;\r
 import org.simantics.utils.datastructures.hints.IHintContext;\r
@@ -206,7 +206,7 @@ public class DiagramViewer extends org.simantics.modeling.ui.diagramEditor.Diagr
         ctx.getDefaultHintContext().setHint(Hints.KEY_ALLOWED_DRAG_ACTIONS, DnDConstants.ACTION_COPY);\r
 \r
         ctx.add(new SysdynPopulateElementDropParticipant(synchronizer));\r
-        ctx.add(new PopulateElementMonitorDropParticipant(synchronizer, 0.5, 0.5));\r
+        ctx.add(new PopulateChartDropParticipant(synchronizer));\r
     }\r
 \r
        @Override\r
index 7b8ac685b96588617c95577e53af6f186c248484..6ba81d708b0d40731f421cbbc878ca99b31235e4 100644 (file)
@@ -315,6 +315,11 @@ public class ResourceSelectionProcessor implements SelectionProcessor<Object, Re
                         "Function library"));\r
             }\r
 \r
+            // Chart Element\r
+            if(backend.isInstanceOf(r, jfree.ChartElement)) {\r
+                if(backend.hasStatement(r, jfree.ChartElement_component))\r
+                    r = backend.getSingleObject(r, jfree.ChartElement_component);\r
+            }\r
             // Chart\r
             if (backend.isInstanceOf(r, jfree.Chart)) {\r
 \r
index b30c323fb4618072bae2b2168b0479e223d37e09..1babb533010c7869a9fb13959916b3cec96fb3cc 100644 (file)
@@ -86,7 +86,7 @@ public class XYPlot extends AbstractPlot {
         xyplot.setDomainGridlinesVisible(visibleGrid);\r
         \r
         // Cleaner look: no outline borders\r
-        xyplot.setInsets(new RectangleInsets(2,2,2,2), false);\r
+        xyplot.setInsets(new RectangleInsets(2,5,2,10), false);\r
         xyplot.setOutlineVisible(false);\r
     }\r
 \r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartBoundsOutline.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartBoundsOutline.java
new file mode 100644 (file)
index 0000000..ef22ada
--- /dev/null
@@ -0,0 +1,37 @@
+package org.simantics.sysdyn.ui.trend.chart.element;\r
+\r
+import java.awt.geom.Rectangle2D;\r
+\r
+import org.simantics.g2d.diagram.IDiagram;\r
+import org.simantics.g2d.element.ElementHints;\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.g2d.element.handler.LifeCycle;\r
+import org.simantics.g2d.element.handler.impl.BoundsOutline;\r
+\r
+/**\r
+ * Outline with default bounds. Needed to avoid crashing when trying to rotate chart elements.\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class ChartBoundsOutline extends BoundsOutline implements LifeCycle {\r
+    private static final long serialVersionUID = -3819495313008722843L;\r
+    \r
+    Rectangle2D defaultBounds;\r
+    \r
+    public ChartBoundsOutline(Rectangle2D defaultBounds) {\r
+        this.defaultBounds = defaultBounds;\r
+    }\r
+\r
+    @Override\r
+    public void onElementCreated(IElement e) {\r
+        e.setHint(ElementHints.KEY_BOUNDS, defaultBounds);\r
+    }\r
+\r
+    @Override\r
+    public void onElementDestroyed(IElement e) {}\r
+    @Override\r
+    public void onElementActivated(IDiagram d, IElement e) {}\r
+    @Override\r
+    public void onElementDeactivated(IDiagram d, IElement e) {}\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartElementFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartElementFactory.java
new file mode 100644 (file)
index 0000000..1d99461
--- /dev/null
@@ -0,0 +1,170 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.trend.chart.element;\r
+\r
+import java.awt.BasicStroke;\r
+import java.awt.Shape;\r
+import java.awt.geom.AffineTransform;\r
+import java.awt.geom.Path2D;\r
+import java.awt.geom.QuadCurve2D;\r
+import java.awt.geom.Rectangle2D;\r
+\r
+import org.jfree.chart.JFreeChart;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.diagram.adapter.ElementFactory;\r
+import org.simantics.diagram.adapter.SyncElementFactory;\r
+import org.simantics.diagram.elements.ElementPropertySetter;\r
+import org.simantics.diagram.synchronization.CompositeHintSynchronizer;\r
+import org.simantics.diagram.synchronization.IHintSynchronizer;\r
+import org.simantics.diagram.synchronization.SynchronizationHints;\r
+import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;\r
+import org.simantics.diagram.synchronization.graph.TransformSynchronizer;\r
+import org.simantics.g2d.canvas.ICanvasContext;\r
+import org.simantics.g2d.diagram.IDiagram;\r
+import org.simantics.g2d.element.ElementClass;\r
+import org.simantics.g2d.element.ElementUtils;\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.g2d.element.handler.LifeCycle;\r
+import org.simantics.g2d.element.handler.impl.DefaultTransform;\r
+import org.simantics.g2d.element.handler.impl.StaticObjectAdapter;\r
+import org.simantics.g2d.element.handler.impl.StaticSymbolImageInitializer;\r
+import org.simantics.g2d.element.handler.impl.StaticSymbolImpl;\r
+import org.simantics.g2d.image.Image;\r
+import org.simantics.g2d.image.impl.ShapeImage;\r
+import org.simantics.sysdyn.JFreeChartResource;\r
+import org.simantics.sysdyn.ui.trend.chart.IJFreeChart;\r
+import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
+import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;\r
+\r
+/**\r
+ * Element factory for creating chart elements to diagrams\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class ChartElementFactory extends SyncElementFactory {\r
+\r
+    private static final String         CLASS_ID            = "Chart";\r
+    public  static final ElementFactory INSTANCE            = new ChartElementFactory();\r
+    public  static final Image          STATIC_IMAGE        = new ShapeImage(getChartShape(), null, new BasicStroke(1f), true);\r
+    public  static final double         SYMBOL_CHART_SIZE   = 10.0;\r
+    public  static final Key            KEY_CHART_COMPONENT = new KeyOf(Resource.class, "CHART_COMPONENT");     \r
+    public  static final Key            KEY_CHART           = new KeyOf(JFreeChart.class, "CHART");       \r
+    \r
+    static Shape getChartShape() {\r
+        \r
+        Path2D path = new Path2D.Double();\r
+        // First create the axis for a chart symbol\r
+        path.moveTo(-SYMBOL_CHART_SIZE, -SYMBOL_CHART_SIZE);\r
+        path.lineTo(-SYMBOL_CHART_SIZE,  SYMBOL_CHART_SIZE);\r
+        path.lineTo( SYMBOL_CHART_SIZE,  SYMBOL_CHART_SIZE);\r
+\r
+        // Then a curve to the chart\r
+        QuadCurve2D curve = new QuadCurve2D.Double(\r
+                -SYMBOL_CHART_SIZE + 1,  SYMBOL_CHART_SIZE - 1,\r
+                SYMBOL_CHART_SIZE - 5,  SYMBOL_CHART_SIZE - 5,\r
+                SYMBOL_CHART_SIZE - 1, -SYMBOL_CHART_SIZE + 3);\r
+\r
+        // Connect shapes\r
+        path.append(curve, false);\r
+        return path;\r
+    }\r
+\r
+    // Hint synchronizer for synchronizing transform and bounds\r
+    private static final IHintSynchronizer HINT_SYNCHRONIZER = new CompositeHintSynchronizer(\r
+            TransformSynchronizer.INSTANCE);\r
+\r
+    public static ElementClass create(ReadGraph graph, Resource chart) throws DatabaseException {\r
+        return ElementClass.compile(\r
+                new ChartSceneGraph(),\r
+                new Initializer(chart),\r
+                new StaticObjectAdapter(JFreeChartResource.getInstance(graph).ChartElement),\r
+                DefaultTransform.INSTANCE,\r
+                StaticSymbolImageInitializer.INSTANCE,\r
+                new StaticSymbolImpl(STATIC_IMAGE),\r
+                new ChartBoundsOutline(new Rectangle2D.Double(-40, -40, 80, 80)),\r
+                new ElementPropertySetter(ChartSceneGraph.KEY_SG_NODE)\r
+                ).setId(CLASS_ID);\r
+    }\r
+\r
+    public ElementClass create(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType) throws DatabaseException {\r
+        return create(graph, null);\r
+    }\r
+\r
+    @Override\r
+    public void load(ReadGraph g, ICanvasContext canvas, IDiagram diagram, Resource element, IElement e) throws DatabaseException {\r
+\r
+        Resource chartResource;\r
+\r
+        Object o = e.getHint(KEY_CHART_COMPONENT);\r
+        if(o == null || !(o instanceof Resource)) {\r
+            chartResource = g.getPossibleObject(element, JFreeChartResource.getInstance(g).ChartElement_component);\r
+        } else {\r
+            chartResource = (Resource)o;\r
+        }\r
+\r
+        if(chartResource == null || !g.hasStatement(chartResource)) \r
+            return;\r
+\r
+        ElementPropertySetter ps = e.getElementClass().getSingleItem(ElementPropertySetter.class);\r
+        ps.loadProperties(e, element, g);\r
+\r
+        IJFreeChart ichart = g.adapt(chartResource, IJFreeChart.class);\r
+\r
+        if(ichart != null) {\r
+            JFreeChart chart = ichart.getChart();\r
+            e.setHint(KEY_CHART, chart);\r
+        }\r
+\r
+        \r
+        AffineTransform at = DiagramGraphUtil.getAffineTransform(g, element);\r
+        // Hack for disabling all rotations in chart elements\r
+        double x = at.getTranslateX();\r
+        double y = at.getTranslateY();\r
+        at.setToRotation(0);\r
+        at.setToTranslation(x, y);\r
+        ElementUtils.setTransform(e, at); // Set hint transform without rotations\r
+        ps.overrideProperty(e, "Transform", at); // Set property Transform without rotations\r
+        \r
+        e.setHint(SynchronizationHints.HINT_SYNCHRONIZER, HINT_SYNCHRONIZER);\r
+\r
+    }\r
+\r
+\r
+    /**\r
+     * Initializer for setting a chart component for element\r
+     * @author Teemu Lempinen\r
+     *\r
+     */\r
+    static class Initializer implements LifeCycle {\r
+        private static final long serialVersionUID = -5822080013184271204L;\r
+        Object component;\r
+\r
+        Initializer(Object component) {\r
+            this.component = component;\r
+        }\r
+\r
+        @Override\r
+        public void onElementCreated(IElement e) {\r
+            if(component != null) e.setHint(KEY_CHART_COMPONENT, component);\r
+        }\r
+\r
+        @Override\r
+        public void onElementActivated(IDiagram d, IElement e) {}\r
+        @Override\r
+        public void onElementDeactivated(IDiagram d, IElement e) {}\r
+        @Override\r
+        public void onElementDestroyed(IElement e) {}\r
+    };\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartElementWriter.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartElementWriter.java
new file mode 100644 (file)
index 0000000..31ef8da
--- /dev/null
@@ -0,0 +1,43 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.trend.chart.element;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.diagram.synchronization.graph.ElementWriter;\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.sysdyn.JFreeChartResource;\r
+\r
+/**\r
+ * Element writer for chart elements. ChartElementWriter stores\r
+ * the reference to a chart definition into the element resource\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class ChartElementWriter implements ElementWriter {\r
+\r
+    @Override\r
+    public void addToGraph(WriteGraph graph, IElement element, Resource elementResource) throws DatabaseException {\r
+        Resource chartComponent = element.getHint(ChartElementFactory.KEY_CHART_COMPONENT);\r
+        if (chartComponent == null)\r
+            throw new IllegalArgumentException("KEY_CHART_COMPONENT hint not set");\r
+        \r
+        JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
+        graph.claim(elementResource, jfree.ChartElement_component, chartComponent);\r
+    }\r
+\r
+    @Override\r
+    public void removeFromGraph(WriteGraph graph, Resource elementResource) throws DatabaseException {\r
+    }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartNode.java
new file mode 100644 (file)
index 0000000..b12f089
--- /dev/null
@@ -0,0 +1,277 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.trend.chart.element;\r
+\r
+import java.awt.BasicStroke;\r
+import java.awt.Color;\r
+import java.awt.Graphics2D;\r
+import java.awt.Stroke;\r
+import java.awt.geom.AffineTransform;\r
+import java.awt.geom.Line2D;\r
+import java.awt.geom.Point2D;\r
+import java.awt.geom.Rectangle2D;\r
+\r
+import javax.swing.JPanel;\r
+\r
+import org.jfree.chart.ChartPanel;\r
+import org.jfree.chart.JFreeChart;\r
+import org.simantics.scenegraph.ISelectionPainterNode;\r
+import org.simantics.scenegraph.g2d.events.EventTypes;\r
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonPressedEvent;\r
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonReleasedEvent;\r
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseMovedEvent;\r
+import org.simantics.scenegraph.swing.ComponentNode;\r
+import org.simantics.scenegraph.utils.GeometryUtils;\r
+import org.simantics.scenegraph.utils.NodeUtil;\r
+\r
+/**\r
+ * Chart node for displaying jfreechart charts in diagrams\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class ChartNode extends ComponentNode<JPanel> implements ISelectionPainterNode {\r
+\r
+    private static final long serialVersionUID = 5013911689968911010L;\r
+    private boolean hover = false;\r
+    private boolean dragging = false;\r
+\r
+    private ResizeListener resizeListener; \r
+\r
+    protected transient JFreeChart chart = null;\r
+\r
+    public boolean dragging() {\r
+        return dragging;\r
+    }\r
+\r
+    public void setChart(JFreeChart chart) {\r
+        this.chart = chart;\r
+    }\r
+\r
+    public void setResizeListener(ResizeListener listener) {\r
+        this.resizeListener = listener;\r
+    }\r
+\r
+    @SyncField({"hover"})\r
+    public void setHover(boolean hover) {\r
+        this.hover = hover;\r
+        repaint();\r
+    }\r
+\r
+    @Override\r
+    public void cleanup() {\r
+        removeEventHandler(this);\r
+        super.cleanup();\r
+    }\r
+\r
+    @Override\r
+    public void init() {\r
+        super.init();\r
+    }\r
+\r
+    public static void expand(Rectangle2D rectangle, double scaleX, double scaleY) {\r
+        GeometryUtils.expandRectangle(rectangle,\r
+                5 * scaleY > 5 ? 5 * scaleY : 5, \r
+                        3 * scaleY > 3 ? 3 * scaleY : 3, \r
+                                3 * scaleX > 3 ? 3 * scaleX : 3, \r
+                                        3 * scaleX > 3 ? 3 * scaleX : 3);\r
+    }\r
+\r
+    @Override\r
+    public void render(Graphics2D g2d) {\r
+        if (component == null && chart != null) {\r
+            // Need the chart, so this cannot be done during initialization\r
+            component = new ChartPanel(chart, false);\r
+            ((ChartPanel)component).setRefreshBuffer(false);\r
+            component.setIgnoreRepaint(true); \r
+            component.setDoubleBuffered(false);\r
+            if(bounds != null) {\r
+                component.setBounds(0, 0, 0, 0);\r
+            }\r
+            super.init();\r
+            addEventHandler(this);\r
+        }\r
+\r
+        if (component != null) {\r
+            AffineTransform ot = g2d.getTransform();\r
+            g2d.transform(transform);\r
+            double scaleX = g2d.getTransform().getScaleX();\r
+            double scaleY = g2d.getTransform().getScaleY();\r
+\r
+            AffineTransform at = new AffineTransform(transform);\r
+            synchronized(transform) {\r
+                at.setToTranslation(bounds.getMinX(), bounds.getMinY());\r
+                at.scale(1/scaleX, 1/scaleY);\r
+            }\r
+            g2d.transform(at);\r
+            int width = (int)(bounds.getWidth() * scaleX);\r
+            int height = (int)(bounds.getHeight() * scaleY);\r
+\r
+            if(hover || dragging) {\r
+                // Borders\r
+                Color orig = g2d.getColor();\r
+                BasicStroke oldStroke = (BasicStroke) g2d.getStroke();\r
+                g2d.setColor(Color.LIGHT_GRAY);\r
+                Rectangle2D b = new Rectangle2D.Double(0, 0, width, height);\r
+                Rectangle2D r = b.getBounds2D();\r
+                expand(r, 1 * scaleX, 1 * scaleY);\r
+                g2d.fill(r);\r
+\r
+                // Lower right corner for dragging\r
+                double x = r.getMaxX() - (0.33 * scaleX);\r
+                double y = r.getMaxY() - (0.33 * scaleY);\r
+\r
+                if(r.getMaxX() - x > 0.4) {                \r
+                    // if there is enough space, use decorated corner\r
+                    BasicStroke hilightStroke = new BasicStroke(oldStroke.getLineWidth() * 3);\r
+                    for(int i = 1; i < 4; i++) {\r
+                        Line2D line = new Line2D.Double(\r
+                                x - (i * scaleX), \r
+                                y, \r
+                                x, \r
+                                y - (i * scaleY));\r
+\r
+                        g2d.setStroke(hilightStroke);\r
+                        g2d.setColor(Color.GRAY);\r
+                        g2d.draw(line);\r
+\r
+                        g2d.setStroke(oldStroke);\r
+                        g2d.setColor(Color.BLACK);\r
+                        g2d.draw(line);\r
+                    }\r
+\r
+\r
+                } else {\r
+                    // not enough space, use a non-decorated corner\r
+                    float f = 3;\r
+                    Rectangle2D corner = new Rectangle2D.Double(r.getMaxX() - f, r.getMaxY() - f, f, f);\r
+                    g2d.setColor(Color.DARK_GRAY);\r
+                    g2d.fill(corner);\r
+                }\r
+\r
+                g2d.setStroke(oldStroke);\r
+                g2d.setColor(orig);\r
+            }\r
+\r
+            boolean selected = NodeUtil.isSelected(this, 1);\r
+            if (selected) {\r
+                Color orig = g2d.getColor();\r
+                Stroke origStroke = g2d.getStroke();\r
+\r
+                g2d.setColor(Color.RED);\r
+                double s = GeometryUtils.getScale(g2d.getTransform());\r
+                g2d.setStroke(new BasicStroke(1f * s < 1f ? 1f : 1f * (float)s));\r
+\r
+                Rectangle2D b = new Rectangle2D.Double(0, 0, width, height);\r
+                Rectangle2D r = b.getBounds2D();\r
+                expand(r, scaleX, scaleY);\r
+                g2d.draw(r);\r
+\r
+                g2d.setColor(orig);\r
+                g2d.setStroke(origStroke);\r
+            }\r
+\r
+            synchronized(component) {\r
+                component.setLocation((int)g2d.getTransform().getTranslateX(), (int)g2d.getTransform().getTranslateY());\r
+                if(component.getSize().getWidth() != width || component.getSize().getHeight() != height) {\r
+                    component.setSize(width, height);\r
+                }\r
+                component.paint(g2d);\r
+            }\r
+\r
+            g2d.setTransform(ot);\r
+\r
+\r
+        }\r
+    }\r
+\r
+    @Override\r
+    protected boolean mouseButtonPressed(MouseButtonPressedEvent event) {\r
+        Point2D local = controlToLocal( event.controlPosition );\r
+        local = parentToLocal(local);\r
+        Rectangle2D bounds = getBoundsInLocal().getBounds2D();\r
+        expand(bounds, 1, 1);\r
+        double control = 3.0;\r
+        Rectangle2D corner = new Rectangle2D.Double(bounds.getMaxX() - control, bounds.getMaxY() - control, control, control);\r
+        if (hover && corner.contains(local)) {\r
+            dragging = true;\r
+            return true;\r
+        }\r
+        return super.mouseButtonPressed(event);\r
+    }\r
+\r
+\r
+    @Override\r
+    protected boolean mouseMoved(MouseMovedEvent e) {\r
+        if(dragging) {\r
+            Point2D local = controlToLocal( e.controlPosition );\r
+            local = parentToLocal(local);\r
+\r
+            Rectangle2D bounds = getBoundsInLocal().getBounds2D();\r
+\r
+            if(Math.abs(bounds.getMaxX() - local.getX()) > 3 ||\r
+                    Math.abs(bounds.getMaxY() - local.getY()) > 3) {\r
+                resize(local);\r
+            }\r
+            return true;\r
+        }\r
+        return false;\r
+    }\r
+\r
+    public boolean hitCorner(Point2D point) {\r
+        Rectangle2D bounds = getBoundsInLocal().getBounds2D();\r
+        expand(bounds, 1, 1);\r
+        double control = 3.0;\r
+        Rectangle2D corner = new Rectangle2D.Double(bounds.getMaxX() - control, bounds.getMaxY() - control, control, control);\r
+        return corner.contains(point);\r
+    }\r
+\r
+    private void resize(Point2D local) {\r
+        Rectangle2D bounds = getBoundsInLocal().getBounds2D();\r
+        double x = bounds.getX();\r
+        double y = bounds.getY();\r
+        double dx = local.getX() - bounds.getMaxX();\r
+        double dy = local.getY() - bounds.getMaxY();\r
+        double w = bounds.getWidth() + dx;\r
+        double h = bounds.getHeight() + dy;\r
+        bounds.setRect(\r
+                x, \r
+                y, \r
+                w > 20 ? w : 20, \r
+                        h > 20 ? h : 20\r
+                );\r
+        setBounds(bounds);\r
+    }\r
+\r
+    @Override\r
+    protected boolean mouseButtonReleased(MouseButtonReleasedEvent e) {\r
+        if(dragging) {\r
+            Point2D local = controlToLocal( e.controlPosition );\r
+            local = parentToLocal(local);\r
+            if(Math.abs(bounds.getMaxX() - local.getX()) > 3 ||\r
+                    Math.abs(bounds.getMaxY() - local.getY()) > 3) {\r
+                resize(local);\r
+            }\r
+            dragging = false;\r
+            if(resizeListener != null)\r
+                resizeListener.elementResized(bounds);\r
+        }\r
+        return false;\r
+    }\r
+\r
+    @Override\r
+    public int getEventMask() {\r
+        return EventTypes.MouseButtonPressedMask\r
+                | EventTypes.MouseMovedMask\r
+                | EventTypes.MouseButtonReleasedMask\r
+                ;\r
+    }\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartSceneGraph.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartSceneGraph.java
new file mode 100644 (file)
index 0000000..f8ea0c7
--- /dev/null
@@ -0,0 +1,159 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.trend.chart.element;\r
+\r
+import java.awt.Shape;\r
+import java.awt.geom.AffineTransform;\r
+import java.awt.geom.Rectangle2D;\r
+\r
+import org.jfree.chart.JFreeChart;\r
+import org.simantics.g2d.canvas.ICanvasContext;\r
+import org.simantics.g2d.diagram.DiagramUtils;\r
+import org.simantics.g2d.diagram.IDiagram;\r
+import org.simantics.g2d.element.ElementHints;\r
+import org.simantics.g2d.element.ElementUtils;\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.g2d.element.SceneGraphNodeKey;\r
+import org.simantics.g2d.element.handler.HandleMouseEvent;\r
+import org.simantics.g2d.element.handler.InternalSize;\r
+import org.simantics.g2d.element.handler.PropertySetter;\r
+import org.simantics.g2d.element.handler.SceneGraph;\r
+import org.simantics.scenegraph.Node;\r
+import org.simantics.scenegraph.g2d.G2DParentNode;\r
+import org.simantics.scenegraph.g2d.IG2DNode;\r
+import org.simantics.scenegraph.g2d.events.MouseEvent;\r
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseEnterEvent;\r
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseExitEvent;\r
+import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
+import org.simantics.utils.datastructures.hints.IHintListener;\r
+import org.simantics.utils.datastructures.hints.IHintObservable;\r
+\r
+/**\r
+ * Chart scenegraph for chart elements in diagrams\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class ChartSceneGraph  implements SceneGraph, HandleMouseEvent, InternalSize {\r
+    private static final long serialVersionUID = 1875762898776996989L;\r
+\r
+    public static final Key KEY_SG_NODE = new SceneGraphNodeKey(Node.class, "CHART_SG_NODE");\r
+    public static final Key KEY_SG_SELECTION_NODE = new SceneGraphNodeKey(Node.class, "CHART_SG_SELECTION_NODE");\r
+\r
+    protected IHintListener hoverHintListener;\r
+\r
+    public ChartSceneGraph() {\r
+    }\r
+\r
+    /**\r
+     * Expands bounds a little to allow selecting and grabbing a chart element\r
+     * from outside the chart graphics\r
+     */\r
+    @Override\r
+    public Rectangle2D getBounds(IElement e, Rectangle2D s) {\r
+        if (s==null) s = new Rectangle2D.Double();\r
+\r
+        IG2DNode node = (IG2DNode)e.getHint(KEY_SG_NODE);\r
+        AffineTransform at = (AffineTransform)e.getHint(ElementHints.KEY_TRANSFORM);\r
+        if(at != null && node != null && node.getBoundsInLocal() != null) {\r
+            Shape shape = node.getBoundsInLocal();\r
+            Rectangle2D r = shape.getBounds2D();\r
+            double scaleX = at.getScaleX();\r
+            double scaleY = at.getScaleY();\r
+            ChartNode.expand(r, 1 * scaleX, 1 * scaleY);\r
+            shape = r;\r
+            s.setFrame(shape.getBounds2D());\r
+        } else {\r
+            s.setFrame((Rectangle2D)e.getHint(ElementHints.KEY_BOUNDS));\r
+        }\r
+        return s;\r
+    }\r
+\r
+    @Override\r
+    public void cleanup(IElement e) {\r
+        if(hoverHintListener != null)\r
+            e.removeHintListener(hoverHintListener);\r
+\r
+        Node node = e.removeHint(KEY_SG_NODE);\r
+        if (node != null)\r
+            node.remove();\r
+    }\r
+\r
+    @Override\r
+    public void init(final IElement e, G2DParentNode parent) {\r
+        ChartNode node = e.getHint(KEY_SG_NODE);\r
+        if(node == null) {\r
+            // Create a new chart node\r
+            node = parent.getOrCreateNode("chart_"+e.hashCode(), ChartNode.class);\r
+\r
+            Rectangle2D bounds = (Rectangle2D)e.getHint(ElementHints.KEY_BOUNDS);\r
+            if(bounds == null) {\r
+                bounds = new Rectangle2D.Double(-40, -40, 80, 80);\r
+                e.setHint(ElementHints.KEY_BOUNDS, bounds);\r
+            }\r
+            node.setBounds(bounds);\r
+\r
+            JFreeChart chart = e.getHint(ChartElementFactory.KEY_CHART);\r
+            if(chart != null)\r
+                node.setChart(chart);\r
+\r
+            // Add a resize listener for updating bounds information to graph after resizing\r
+            node.setResizeListener(new ResizeListener() {\r
+\r
+                @Override\r
+                public void elementResized(Rectangle2D newBounds) {\r
+                    e.setHint(ElementHints.KEY_BOUNDS, newBounds);\r
+                    IDiagram diagram = ElementUtils.getDiagram(e);\r
+                    DiagramUtils.synchronizeHintsToBackend(diagram, e);\r
+                }\r
+            });\r
+\r
+            e.setHint(KEY_SG_NODE, node);\r
+        }\r
+\r
+        // Hover listening\r
+        hoverHintListener = new IHintListener() {\r
+            @Override\r
+            public void hintRemoved(IHintObservable sender, Key key, Object oldValue) {\r
+\r
+            }\r
+\r
+            @Override\r
+            public void hintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) {\r
+                if(key == ElementHints.KEY_HOVER) {\r
+                    IElement e = (IElement)sender;\r
+                    ChartNode name = (ChartNode) e.getHint(KEY_SG_NODE);\r
+                    if (name != null)\r
+                        name.setHover(Boolean.TRUE.equals(e.getHint(ElementHints.KEY_HOVER)));\r
+                }\r
+            }\r
+        };\r
+        e.addHintListener(hoverHintListener);\r
+\r
+        update(e);\r
+    }\r
+\r
+    public void update(IElement e) {\r
+        PropertySetter setter = e.getElementClass().getSingleItem(PropertySetter.class);\r
+        setter.syncPropertiesToNode(e);\r
+    }\r
+\r
+    \r
+    @Override\r
+    public boolean handleMouseEvent(IElement e, ICanvasContext ctx, MouseEvent me) {\r
+        if (me instanceof MouseEnterEvent) {\r
+            e.setHint(ElementHints.KEY_HOVER, true);\r
+        } else if (me instanceof MouseExitEvent) {\r
+            e.setHint(ElementHints.KEY_HOVER, false);\r
+        }\r
+        return false;\r
+    }\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/PopulateChartDropParticipant.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/PopulateChartDropParticipant.java
new file mode 100644 (file)
index 0000000..168c2a2
--- /dev/null
@@ -0,0 +1,116 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.trend.chart.element;\r
+\r
+import java.awt.datatransfer.Transferable;\r
+import java.awt.datatransfer.UnsupportedFlavorException;\r
+import java.awt.dnd.DnDConstants;\r
+import java.awt.dnd.DropTargetDragEvent;\r
+import java.awt.geom.AffineTransform;\r
+import java.io.IOException;\r
+\r
+import org.eclipse.jface.viewers.IStructuredSelection;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Session;\r
+import org.simantics.db.common.request.UnaryRead;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.diagram.adapter.GraphToDiagramSynchronizer;\r
+import org.simantics.g2d.dnd.DnDHints;\r
+import org.simantics.g2d.dnd.ElementClassDragItem;\r
+import org.simantics.g2d.dnd.IDnDContext;\r
+import org.simantics.g2d.dnd.IDropTargetParticipant;\r
+import org.simantics.g2d.element.ElementHints;\r
+import org.simantics.modeling.ui.diagramEditor.PopulateElementDropParticipant;\r
+import org.simantics.sysdyn.JFreeChartResource;\r
+import org.simantics.ui.dnd.LocalObjectTransfer;\r
+import org.simantics.ui.dnd.LocalObjectTransferable;\r
+import org.simantics.ui.utils.AdaptionUtils;\r
+\r
+/**\r
+ * Drop participant for dropping chart definitions into diagrams\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class PopulateChartDropParticipant extends PopulateElementDropParticipant implements IDropTargetParticipant {\r
+\r
+    public PopulateChartDropParticipant(GraphToDiagramSynchronizer synchronizer) {\r
+        super(synchronizer);\r
+    }\r
+\r
+    @Override\r
+    public void dragEnter(DropTargetDragEvent dtde, final IDnDContext dp) {\r
+        Transferable tr = dtde.getTransferable();\r
+        if (tr.isDataFlavorSupported(LocalObjectTransferable.FLAVOR)) {\r
+\r
+            Session session = synchronizer.getSession();\r
+\r
+            Object obj = null;\r
+\r
+            try {\r
+                obj = tr.getTransferData(LocalObjectTransferable.FLAVOR);\r
+                \r
+                // Create a structural selection from transfer data\r
+                if (!(obj instanceof IStructuredSelection)) {\r
+                    obj = LocalObjectTransfer.getTransfer().getObject();\r
+                }\r
+\r
+                if (obj instanceof IStructuredSelection) {\r
+\r
+                    IStructuredSelection sel = (IStructuredSelection) obj;\r
+                    \r
+                    // Can drop only one chart at the time\r
+                    if (sel.size() == 1) {\r
+                        \r
+                        // Get the chart definition\r
+                        Resource chart = AdaptionUtils.adaptToSingle(sel, Resource.class);\r
+                        if (chart == null)\r
+                            return;\r
+\r
+                        ElementClassDragItem item = session.syncRequest(new UnaryRead<Resource,ElementClassDragItem>(chart) {\r
+\r
+                            @Override\r
+                            public ElementClassDragItem perform(ReadGraph graph) throws DatabaseException {\r
+                                if(graph.isInstanceOf(parameter, JFreeChartResource.getInstance(graph).Chart)) {\r
+                                    ElementClassDragItem item = new ElementClassDragItem(ChartElementFactory.create(graph, parameter));\r
+                                    AffineTransform initialTr = AffineTransform.getScaleInstance(1, 1);\r
+                                    item.getHintContext().setHint(ElementHints.KEY_TRANSFORM, initialTr);\r
+                                    return item;\r
+                                } else {\r
+                                    return null;\r
+                                }\r
+\r
+                            }\r
+                        });\r
+\r
+                        if(item != null) {\r
+                            dp.add(item);\r
+                            dp.getHints().setHint(DnDHints.KEY_DND_GRID_COLUMNS, Integer.valueOf(1));\r
+                        }\r
+\r
+                    }\r
+\r
+                }\r
+\r
+            } catch (UnsupportedFlavorException e) {\r
+                e.printStackTrace();\r
+            } catch (IOException e) {\r
+                e.printStackTrace();\r
+            } catch (DatabaseException e) {\r
+                e.printStackTrace();\r
+            }\r
+\r
+        }\r
+\r
+        dtde.acceptDrag(DnDConstants.ACTION_COPY);\r
+    }\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ResizeListener.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ResizeListener.java
new file mode 100644 (file)
index 0000000..6c4116b
--- /dev/null
@@ -0,0 +1,28 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.trend.chart.element;\r
+\r
+import java.awt.geom.Rectangle2D;\r
+\r
+/**\r
+ * Interface for listeners listening resize events in chart nodes\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public interface ResizeListener {\r
+    \r
+    /**\r
+     * Triggered when a node has been resized\r
+     * @param newBounds new bounds for the node\r
+     */\r
+    public void elementResized(Rectangle2D newBounds);\r
+}\r