X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.trend%2Fexample%2Forg%2Fsimantics%2Ftrend%2FDemoTrend.java;h=b2b5f0b3c4ead396e0be9c18d7958ed2356a2b93;hb=2444a7d3ebc4aea7f9899dbf8aa84c8f94e75fd9;hp=97ef30209d133e8b4bf771b075ecded53b35a88e;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.trend/example/org/simantics/trend/DemoTrend.java b/bundles/org.simantics.trend/example/org/simantics/trend/DemoTrend.java index 97ef30209..b2b5f0b3c 100644 --- a/bundles/org.simantics.trend/example/org/simantics/trend/DemoTrend.java +++ b/bundles/org.simantics.trend/example/org/simantics/trend/DemoTrend.java @@ -1,139 +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 DemoTrend { - - 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 = "Multiple Y-Axis DemoTrend"; - trendSpec.axisMode = YAxisMode.MultiAxis; - - trendSpec.items.add( new TrendItem( 1, "Sine", data.subscriptionId, "Sine", new Scale.Manual( -1, 1), TrendItem.Renderer.Analog ) ); - trendSpec.items.add( new TrendItem( 2, "Ramp", data.subscriptionId,"Ramp", new Scale.Manual(-100,100), TrendItem.Renderer.Binary ) ); - trendSpec.items.add( new TrendItem( 3, "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); - } - }); - } - -} +/******************************************************************************* + * 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 DemoTrend { + + 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 = "Multiple Y-Axis DemoTrend"; + trendSpec.axisMode = YAxisMode.MultiAxis; + + trendSpec.items.add( new TrendItem( 1, "Sine", data.subscriptionId, "Sine", new Scale.Manual( -1, 1), TrendItem.Renderer.Analog ) ); + trendSpec.items.add( new TrendItem( 2, "Ramp", data.subscriptionId,"Ramp", new Scale.Manual(-100,100), TrendItem.Renderer.Binary ) ); + trendSpec.items.add( new TrendItem( 3, "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); + } + }); + } + +}