]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.trend/example/org/simantics/trend/DemoTrendSingleAxisShowLegends.java
New trend axis mode SingleAxisShowLegends
[simantics/platform.git] / bundles / org.simantics.trend / example / org / simantics / trend / DemoTrendSingleAxisShowLegends.java
diff --git a/bundles/org.simantics.trend/example/org/simantics/trend/DemoTrendSingleAxisShowLegends.java b/bundles/org.simantics.trend/example/org/simantics/trend/DemoTrendSingleAxisShowLegends.java
new file mode 100644 (file)
index 0000000..bdb22a3
--- /dev/null
@@ -0,0 +1,139 @@
+/*******************************************************************************
+ * 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.BorderLayout;
+import java.awt.Dimension;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.io.File;
+
+import javax.swing.JFrame;
+
+import org.simantics.g2d.canvas.impl.CanvasContext;
+import org.simantics.g2d.chassis.AWTChassis;
+import org.simantics.g2d.image.DefaultImages;
+import org.simantics.history.impl.FileHistory;
+import org.simantics.trend.configuration.Scale;
+import org.simantics.trend.configuration.TrendItem;
+import org.simantics.trend.configuration.TrendSpec;
+import org.simantics.trend.configuration.YAxisMode;
+import org.simantics.trend.impl.Milestone;
+import org.simantics.trend.impl.MilestoneSpec;
+import org.simantics.trend.impl.TrendNode;
+import org.simantics.trend.impl.TrendParticipant;
+import org.simantics.utils.FileUtils;
+import org.simantics.utils.datastructures.hints.IHintContext;
+import org.simantics.utils.threads.AWTThread;
+import org.simantics.utils.threads.IThreadWorkQueue;
+
+public class DemoTrendSingleAxisShowLegends {
+
+       public static void main(String[] args) throws Exception {
+               System.out.println(DefaultImages.HAND);
+
+               // Initialize file history
+               final File workarea = FileUtils.createTmpDir();
+               final TestData data = new TestData(workarea);
+               FileHistory fh = ((FileHistory) data.historyManager);
+               fh.asyncUsage = false;
+               // Memory history
+               // final TestData data = new TestData();
+
+               final TrendSpec trendSpec = new TrendSpec();
+               trendSpec.init();
+               trendSpec.viewProfile.showMilestones = true;
+               trendSpec.name = "SingleAxisShowLegends Y-Axis DemoTrend";
+               trendSpec.axisMode = YAxisMode.SingleAxisShowLegends;
+               trendSpec.singleAxisShowLegendsMaxLegends = 10;
+               
+               trendSpec.items.add(new TrendItem(1, "Sine", data.subscriptionId, "Sine", new Scale.Manual(-100, 100),
+                               TrendItem.Renderer.Analog));
+               trendSpec.items.add(new TrendItem(2, "Random", data.subscriptionId, "Random", new Scale.Auto(), TrendItem.Renderer.Analog));
+               
+               trendSpec.viewProfile.profileName = "Profile";
+//        trendSpec.viewProfile.timeWindow.timeWindowLength = 180.0;
+//        trendSpec.viewProfile.timeWindow.timeWindowStart = 0.0;
+               trendSpec.viewProfile.timeWindow.timeWindowIncrement = 75.0;
+
+               // Alternative spec - Switch with Spacebarman button
+//        TrendSpec altSpec = new TrendSpec();
+//        altSpec.init();
+//        altSpec.viewProfile.showMilestones = true;
+//        altSpec.name = "Single Axis";
+//        altSpec.axisMode = YAxisMode.SingleAxis;
+//        altSpec.items.add( new TrendItem( 1, "Sine", data.subscriptionId,"Sine", new Scale.Auto(), TrendItem.Renderer.Analog, 0, 1 ) );
+//        altSpec.items.add( new TrendItem( 2, "Ramp", data.subscriptionId,"Ramp", new Scale.Auto(), TrendItem.Renderer.Binary ) );
+//        //altSpec.items.add( new TrendItem( "Random", data.subscriptionId,"Random", new Scale.FitAll(), TrendItem.Renderer.Analog, 0, 1, DrawMode.Deviation ) );             
+//        altSpec.viewProfile.profileName = "Profile";
+//        //altSpec.viewProfile.timeWindow.timeWindowLength = 30.0;
+//        //altSpec.viewProfile.timeWindow.timeWindowStart = 0.0;
+//        altSpec.viewProfile.timeWindow.timeWindowIncrement = 25.0;
+
+               // JFrame has double buffering enabled by default
+               JFrame frame = new JFrame("Demo Trend");
+               // Add a window listener for close button
+               frame.addWindowListener(new WindowAdapter() {
+                       @Override
+                       public void windowClosing(WindowEvent e) {
+                               data.dispose();
+                               System.exit(0);
+                       }
+               });
+
+               data.solver.start();
+
+               // This is an empty content area in the frame
+               final AWTChassis chassis = new AWTChassis();
+
+               chassis.setPreferredSize(new Dimension(480, 320));
+
+               frame.getContentPane().add(chassis, BorderLayout.CENTER);
+               frame.pack();
+
+               frame.setVisible(true);
+               chassis.requestFocus();
+
+               IThreadWorkQueue thread = AWTThread.getThreadAccess();
+
+               final CanvasContext ctx = TrendInitializer.createDefaultCanvas(thread, data.historyManager, data.collector,
+                               data.solver, trendSpec);
+               TrendNode node = TrendInitializer.getTrendNode(ctx);
+
+               ctx.getAtMostOneItemOfClass(TrendParticipant.class).setHintAsync(TrendParticipant.KEY_TREND_DRAW_INTERVAL,
+                               1000L);
+
+               MilestoneSpec milestones = new MilestoneSpec();
+               milestones.init();
+               Milestone m1 = new Milestone("1", "1", "Event 1", 50);
+               Milestone m2 = new Milestone("2", "2", "Event 2", 60);
+               Milestone m3 = new Milestone("3", "3", "Event 3", 80);
+               Milestone m4 = new Milestone("4", "4", "Event 4", 90);
+               milestones.milestones.add(m1);
+               milestones.milestones.add(m2);
+               milestones.milestones.add(m3);
+               milestones.milestones.add(m4);
+               milestones.baseline = 2;
+               node.setMilestones(milestones);
+
+               @SuppressWarnings("unused")
+               IHintContext hintCtx = ctx.getDefaultHintContext();
+
+               thread.asyncExec(new Runnable() {
+                       @Override
+                       public void run() {
+                               chassis.setCanvasContext(ctx);
+                       }
+               });
+       }
+
+}