-/*******************************************************************************\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.trend;\r
-\r
-import java.awt.Color;\r
-import java.util.concurrent.Executor;\r
-\r
-import org.simantics.g2d.canvas.Hints;\r
-import org.simantics.g2d.canvas.ICanvasContext;\r
-import org.simantics.g2d.canvas.impl.CanvasContext;\r
-import org.simantics.g2d.participant.BackgroundPainter;\r
-import org.simantics.g2d.participant.CanvasBoundsParticipant;\r
-import org.simantics.g2d.participant.CanvasGrab;\r
-import org.simantics.g2d.participant.KeyToCommand;\r
-import org.simantics.g2d.participant.KeyUtil;\r
-import org.simantics.g2d.participant.MouseUtil;\r
-import org.simantics.g2d.participant.PanZoomRotateHandler;\r
-import org.simantics.g2d.participant.PointerPainter;\r
-import org.simantics.g2d.participant.RulerPainter;\r
-import org.simantics.g2d.participant.SymbolUtil;\r
-import org.simantics.g2d.participant.TimeParticipant;\r
-import org.simantics.g2d.participant.TransformUtil;\r
-import org.simantics.g2d.tooltip.TooltipParticipant;\r
-import org.simantics.history.Collector;\r
-import org.simantics.history.HistoryManager;\r
-import org.simantics.scenegraph.g2d.events.command.CommandKeyBinding;\r
-import org.simantics.simulation.data.Datasource;\r
-import org.simantics.simulation.data.Datasource.DatasourceListener;\r
-import org.simantics.trend.configuration.TrendSpec;\r
-import org.simantics.trend.impl.TrendNode;\r
-import org.simantics.trend.impl.TrendParticipant;\r
-import org.simantics.utils.datastructures.disposable.IDisposable;\r
-import org.simantics.utils.datastructures.disposable.IDisposeListener;\r
-import org.simantics.utils.datastructures.hints.IHintContext;\r
-import org.simantics.utils.threads.IThreadWorkQueue;\r
-\r
-public class TrendInitializer {\r
-\r
- public static CanvasContext defaultInitializeCanvas(CanvasContext cvsCtx, HistoryManager historian, Collector collector, final Datasource simulation, TrendSpec trendSpec)\r
- {\r
- // Create canvas context and a layer of interactors\r
- IHintContext h = cvsCtx.getDefaultHintContext();\r
-\r
- h.setHint(PanZoomRotateHandler.KEY_ADAPT_VIEWPORT_TO_RESIZED_CONTROL, false);\r
- h.setHint(PanZoomRotateHandler.KEY_DISABLE_PAN, true);\r
- h.setHint(PanZoomRotateHandler.KEY_DISABLE_ZOOM, true);\r
- cvsCtx.add( new PanZoomRotateHandler( false ) ); // Must be before TransformUtil\r
-\r
- // Support & Util Participants\r
- cvsCtx.add( new TransformUtil() );\r
- cvsCtx.add( new MouseUtil() );\r
- cvsCtx.add( new KeyUtil() );\r
- cvsCtx.add( new CanvasGrab() );\r
- cvsCtx.add( new SymbolUtil() );\r
- cvsCtx.add( new TimeParticipant() );\r
- cvsCtx.add( new CanvasBoundsParticipant() );\r
-\r
- // Add trend node\r
- TrendNode trendNode = cvsCtx.getSceneGraph().addNode(TrendNode.class);\r
- trendNode.setHistorian( historian, collector );\r
- trendNode.setTrendSpec( trendSpec );\r
-\r
- // Add trend participant/interactor\r
- TrendParticipant tp = new TrendParticipant();\r
- tp.setTrend( trendNode );\r
- cvsCtx.add( tp );\r
-\r
- if (simulation != null)\r
- attachStepListener(simulation, cvsCtx, tp);\r
-\r
- // Debug participant(s)\r
- //canvasContext.add( new PointerPainter() );\r
-// canvasContext.add( new HandPainter() );\r
- h.setHint(PointerPainter.KEY_PAINT_POINTER, true);\r
-\r
- // Pan & Zoom & Rotate\r
- //canvasContext.add( new MousePanZoomInteractor() );\r
- //canvasContext.add( new MultitouchPanZoomRotateInteractor() );\r
- //canvasContext.add( new OrientationRestorer() );\r
-\r
- // Grid & Ruler & Background\r
- //cvsCtx.add( new GridPainter() );\r
- //cvsCtx.add( new RulerPainter() );\r
- cvsCtx.add( new BackgroundPainter() );\r
-\r
- h.setHint(Hints.KEY_GRID_COLOR, new Color(0.95f, 0.95f, 0.95f));\r
- h.setHint(Hints.KEY_BACKGROUND_COLOR, Color.WHITE);\r
- h.setHint(RulerPainter.KEY_RULER_BACKGROUND_COLOR, new Color(0.9f, 0.9f, 0.9f, 0.75f));\r
- h.setHint(RulerPainter.KEY_RULER_TEXT_COLOR, Color.BLACK);\r
- h.setHint(TimeParticipant.KEY_TIME_PULSE_INTERVAL, 50L);\r
- h.setHint(TimeParticipant.KEY_TIMER_ENABLED, true);\r
- h.setHint(TrendParticipant.KEY_TREND_DRAW_INTERVAL, 100L);\r
-\r
- // Key bindings\r
- cvsCtx.add( new KeyToCommand( CommandKeyBinding.DEFAULT_BINDINGS ) );\r
-\r
- ////// Diagram Participants //////\r
-\r
- cvsCtx.add( new TooltipParticipant());\r
-\r
- h.setHint(Hints.KEY_TOOL, Hints.POINTERTOOL);\r
-\r
- //NodeUtil.printSceneGraph( cvsCtx.getSceneGraph() );\r
-\r
- cvsCtx.assertParticipantDependencies();\r
-\r
- return cvsCtx;\r
- }\r
- \r
- public static TrendNode getTrendNode(CanvasContext ctx)\r
- {\r
- TrendParticipant tp = ctx.getSingleItem( TrendParticipant.class );\r
- return tp.getTrend();\r
- }\r
-\r
- public static void attachStepListener(final Datasource datasource, ICanvasContext context, TrendParticipant tp) {\r
- // Add simulation listener - Note listener must be removed when trend is closed\r
- final DatasourceListener stepListener = new StepListener( tp );\r
- datasource.addListener( stepListener );\r
- context.addDisposeListener(new IDisposeListener() {\r
- @Override\r
- public void onDisposed(IDisposable sender) {\r
- datasource.removeListener(stepListener);\r
- }\r
- });\r
- }\r
-\r
- /**\r
- *\r
- */\r
- public static class StepListener implements DatasourceListener {\r
- private final TrendParticipant trendParticipant;\r
-\r
- public StepListener(TrendParticipant trendParticipant) {\r
- this.trendParticipant = trendParticipant;\r
- }\r
-\r
- @Override\r
- public void onStep(Datasource source) {\r
- TrendNode node = trendParticipant.getTrend();\r
- if (!node.allPast()) node.datadirty = true;\r
- }\r
-\r
- @Override\r
- public Executor getExecutor() {\r
- return null;\r
- }\r
- }\r
-\r
- public static CanvasContext createDefaultCanvas(IThreadWorkQueue threadAccess, HistoryManager historian, Collector collector, Datasource simulation, TrendSpec trendSpec) {\r
- return defaultInitializeCanvas(new CanvasContext(threadAccess), historian, collector, simulation, trendSpec);\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2011 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:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.trend;
+
+import java.awt.Color;
+import java.util.concurrent.Executor;
+
+import org.simantics.g2d.canvas.Hints;
+import org.simantics.g2d.canvas.ICanvasContext;
+import org.simantics.g2d.canvas.impl.CanvasContext;
+import org.simantics.g2d.participant.BackgroundPainter;
+import org.simantics.g2d.participant.CanvasBoundsParticipant;
+import org.simantics.g2d.participant.CanvasGrab;
+import org.simantics.g2d.participant.KeyToCommand;
+import org.simantics.g2d.participant.KeyUtil;
+import org.simantics.g2d.participant.MouseUtil;
+import org.simantics.g2d.participant.PanZoomRotateHandler;
+import org.simantics.g2d.participant.PointerPainter;
+import org.simantics.g2d.participant.RulerPainter;
+import org.simantics.g2d.participant.SymbolUtil;
+import org.simantics.g2d.participant.TimeParticipant;
+import org.simantics.g2d.participant.TransformUtil;
+import org.simantics.g2d.tooltip.TooltipParticipant;
+import org.simantics.history.Collector;
+import org.simantics.history.HistoryManager;
+import org.simantics.scenegraph.g2d.events.command.CommandKeyBinding;
+import org.simantics.simulation.data.Datasource;
+import org.simantics.simulation.data.Datasource.DatasourceListener;
+import org.simantics.trend.configuration.TrendSpec;
+import org.simantics.trend.impl.TrendNode;
+import org.simantics.trend.impl.TrendParticipant;
+import org.simantics.utils.datastructures.disposable.IDisposable;
+import org.simantics.utils.datastructures.disposable.IDisposeListener;
+import org.simantics.utils.datastructures.hints.IHintContext;
+import org.simantics.utils.threads.IThreadWorkQueue;
+
+public class TrendInitializer {
+
+ public static CanvasContext defaultInitializeCanvas(CanvasContext cvsCtx, HistoryManager historian, Collector collector, final Datasource simulation, TrendSpec trendSpec)
+ {
+ // Create canvas context and a layer of interactors
+ IHintContext h = cvsCtx.getDefaultHintContext();
+
+ h.setHint(PanZoomRotateHandler.KEY_ADAPT_VIEWPORT_TO_RESIZED_CONTROL, false);
+ h.setHint(PanZoomRotateHandler.KEY_DISABLE_PAN, true);
+ h.setHint(PanZoomRotateHandler.KEY_DISABLE_ZOOM, true);
+ cvsCtx.add( new PanZoomRotateHandler( false ) ); // Must be before TransformUtil
+
+ // Support & Util Participants
+ cvsCtx.add( new TransformUtil() );
+ cvsCtx.add( new MouseUtil() );
+ cvsCtx.add( new KeyUtil() );
+ cvsCtx.add( new CanvasGrab() );
+ cvsCtx.add( new SymbolUtil() );
+ cvsCtx.add( new TimeParticipant() );
+ cvsCtx.add( new CanvasBoundsParticipant() );
+
+ // Add trend node
+ TrendNode trendNode = cvsCtx.getSceneGraph().addNode(TrendNode.class);
+ trendNode.setHistorian( historian, collector );
+ trendNode.setTrendSpec( trendSpec );
+
+ // Add trend participant/interactor
+ TrendParticipant tp = new TrendParticipant();
+ tp.setTrend( trendNode );
+ cvsCtx.add( tp );
+
+ if (simulation != null)
+ attachStepListener(simulation, cvsCtx, tp);
+
+ // Debug participant(s)
+ //canvasContext.add( new PointerPainter() );
+// canvasContext.add( new HandPainter() );
+ h.setHint(PointerPainter.KEY_PAINT_POINTER, true);
+
+ // Pan & Zoom & Rotate
+ //canvasContext.add( new MousePanZoomInteractor() );
+ //canvasContext.add( new MultitouchPanZoomRotateInteractor() );
+ //canvasContext.add( new OrientationRestorer() );
+
+ // Grid & Ruler & Background
+ //cvsCtx.add( new GridPainter() );
+ //cvsCtx.add( new RulerPainter() );
+ cvsCtx.add( new BackgroundPainter() );
+
+ h.setHint(Hints.KEY_GRID_COLOR, new Color(0.95f, 0.95f, 0.95f));
+ h.setHint(Hints.KEY_BACKGROUND_COLOR, Color.WHITE);
+ h.setHint(RulerPainter.KEY_RULER_BACKGROUND_COLOR, new Color(0.9f, 0.9f, 0.9f, 0.75f));
+ h.setHint(RulerPainter.KEY_RULER_TEXT_COLOR, Color.BLACK);
+ h.setHint(TimeParticipant.KEY_TIME_PULSE_INTERVAL, 50L);
+ h.setHint(TimeParticipant.KEY_TIMER_ENABLED, true);
+ h.setHint(TrendParticipant.KEY_TREND_DRAW_INTERVAL, 100L);
+
+ // Key bindings
+ cvsCtx.add( new KeyToCommand( CommandKeyBinding.DEFAULT_BINDINGS ) );
+
+ ////// Diagram Participants //////
+
+ cvsCtx.add( new TooltipParticipant());
+
+ h.setHint(Hints.KEY_TOOL, Hints.POINTERTOOL);
+
+ //NodeUtil.printSceneGraph( cvsCtx.getSceneGraph() );
+
+ cvsCtx.assertParticipantDependencies();
+
+ return cvsCtx;
+ }
+
+ public static TrendNode getTrendNode(CanvasContext ctx)
+ {
+ TrendParticipant tp = ctx.getSingleItem( TrendParticipant.class );
+ return tp.getTrend();
+ }
+
+ public static void attachStepListener(final Datasource datasource, ICanvasContext context, TrendParticipant tp) {
+ // Add simulation listener - Note listener must be removed when trend is closed
+ final DatasourceListener stepListener = new StepListener( tp );
+ datasource.addListener( stepListener );
+ context.addDisposeListener(new IDisposeListener() {
+ @Override
+ public void onDisposed(IDisposable sender) {
+ datasource.removeListener(stepListener);
+ }
+ });
+ }
+
+ /**
+ *
+ */
+ public static class StepListener implements DatasourceListener {
+ private final TrendParticipant trendParticipant;
+
+ public StepListener(TrendParticipant trendParticipant) {
+ this.trendParticipant = trendParticipant;
+ }
+
+ @Override
+ public void onStep(Datasource source) {
+ TrendNode node = trendParticipant.getTrend();
+ if (!node.allPast()) node.datadirty = true;
+ }
+
+ @Override
+ public Executor getExecutor() {
+ return null;
+ }
+ }
+
+ public static CanvasContext createDefaultCanvas(IThreadWorkQueue threadAccess, HistoryManager historian, Collector collector, Datasource simulation, TrendSpec trendSpec) {
+ return defaultInitializeCanvas(new CanvasContext(threadAccess), historian, collector, simulation, trendSpec);
+ }
+
+}