]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.trend/test/org/simantics/trend/TestSetTrendConfig.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.trend / test / org / simantics / trend / TestSetTrendConfig.java
1 package org.simantics.trend;
2
3 import java.awt.BorderLayout;
4 import java.awt.Dimension;
5 import java.awt.event.WindowAdapter;
6 import java.awt.event.WindowEvent;
7
8 import javax.swing.JFrame;
9
10 import org.simantics.g2d.canvas.impl.CanvasContext;
11 import org.simantics.g2d.chassis.AWTChassis;
12 import org.simantics.g2d.image.DefaultImages;
13 import org.simantics.history.HistoryException;
14 import org.simantics.history.HistoryManager;
15 import org.simantics.history.util.subscription.SubscriptionItem;
16 import org.simantics.trend.configuration.Scale;
17 import org.simantics.trend.configuration.TrendItem;
18 import org.simantics.trend.configuration.TrendSamplingFormats;
19 import org.simantics.trend.configuration.TrendSpec;
20 import org.simantics.trend.configuration.YAxisMode;
21 import org.simantics.trend.impl.TrendNode;
22 import org.simantics.trend.impl.TrendParticipant;
23 import org.simantics.utils.datastructures.hints.IHintContext;
24 import org.simantics.utils.threads.AWTThread;
25 import org.simantics.utils.threads.IThreadWorkQueue;
26
27 /**
28  * In thist
29  *
30  * @author toni.kalajainen@semantum.fi
31  */
32 public class TestSetTrendConfig {
33         
34     public static void main(String[] args) throws Exception {
35         System.out.println(DefaultImages.HAND);
36         final TestData data = new TestData();
37         addSomeHistoryItems( data.historyManager );
38
39         final TrendSpec trendSpec = new TrendSpec();
40         trendSpec.init();
41         trendSpec.viewProfile.showMilestones = true;
42         trendSpec.name = "Multiple Y-Axis DemoTrend";
43         trendSpec.axisMode = YAxisMode.MultiAxis;        
44
45         trendSpec.items.add( new TrendItem( 1, "Sine", data.subscriptionId, "Sine", new Scale.Manual( -1, 1), TrendItem.Renderer.Analog ) );
46         trendSpec.items.add( new TrendItem( 2, "Ramp", data.subscriptionId,"Ramp", new Scale.Manual(-100,100), TrendItem.Renderer.Binary ) );
47         trendSpec.items.add( new TrendItem( 3, "Random", data.subscriptionId, "Random", new Scale.Auto(), TrendItem.Renderer.Analog ) );
48         trendSpec.viewProfile.profileName = "Profile";
49         trendSpec.viewProfile.timeWindow.timeWindowIncrement = 75.0;
50
51         // JFrame has double buffering enabled by default
52         JFrame frame = new JFrame("Demo Trend");
53         // Add a window listener for close button
54         frame.addWindowListener(new WindowAdapter() {
55             @Override
56             public void windowClosing(WindowEvent e) {
57                 data.dispose();
58                 System.exit(0);
59             }
60         });
61
62         data.solver.start();
63         
64         // This is an empty content area in the frame
65         AWTChassis chassis = new AWTChassis();
66
67         chassis.setPreferredSize(new Dimension(480, 320));
68         
69         frame.getContentPane().add(chassis, BorderLayout.CENTER);
70         frame.pack();
71
72         frame.setVisible(true);
73         chassis.requestFocus();
74
75         IThreadWorkQueue thread  = AWTThread.getThreadAccess();
76
77         long startTime = System.currentTimeMillis();
78         CanvasContext    ctx     = TrendInitializer.createDefaultCanvas(thread, data.historyManager, data.collector, data.solver, trendSpec);
79         @SuppressWarnings("unused")
80         TrendNode node = TrendInitializer.getTrendNode( ctx );
81         long endTime = System.currentTimeMillis();
82         long elapsedTime = endTime - startTime;
83         System.out.println( elapsedTime );
84         
85         ctx.getAtMostOneItemOfClass(TrendParticipant.class).setHintAsync(TrendParticipant.KEY_TREND_DRAW_INTERVAL, 1000L);
86                 
87         @SuppressWarnings("unused")
88         IHintContext     hintCtx = ctx.getDefaultHintContext();
89
90         chassis.setCanvasContext(ctx);
91     }
92
93         static void addSomeHistoryItems(HistoryManager history) throws HistoryException {
94                 String subscriptionId = "abc";
95                 for (int i=0; i<2000; i++) {
96                     SubscriptionItem[] hi = null;
97                         String id = "id"+i;
98                         hi = SubscriptionItem.createItems( id, subscriptionId, TrendSamplingFormats.createAnalogSamplingFormats(0, 0, "") );
99                         history.create(hi);
100                 }
101         }
102     
103     
104 }