]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.threadlog/src/org/simantics/threadlog/ui/ThreadLogController.java
Missing arguments in SCLFunctions.evaluate
[simantics/platform.git] / bundles / org.simantics.threadlog / src / org / simantics / threadlog / ui / ThreadLogController.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.threadlog.ui;
13
14 import java.awt.GridLayout;
15 import java.awt.event.ActionEvent;
16 import java.awt.event.ActionListener;
17 import java.io.IOException;
18
19 import javax.swing.JButton;
20 import javax.swing.JFileChooser;
21 import javax.swing.JFrame;
22 import javax.swing.filechooser.FileNameExtensionFilter;
23
24 import org.simantics.threadlog.ThreadLog;
25
26 public class ThreadLogController extends JFrame {
27
28     private static final long serialVersionUID = -2487997716157625672L;
29     
30     boolean isLogging = false;
31     JButton logButton;
32     JButton loadButton;
33
34     public ThreadLogController() {
35         super("Thread log controller");
36         setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
37
38         logButton = new JButton("Start logging");
39         logButton.addActionListener(new ActionListener() {
40
41             @Override
42             public void actionPerformed(ActionEvent e) {
43                 if(isLogging) {
44                     logButton.setText("Start logging");
45                     isLogging = false;
46                     ThreadLog log = ThreadLog.setDefaultThreadLog(null);
47
48                     ThreadLogVisualizer visualizer = new ThreadLogVisualizer();
49                     visualizer.setLog(log);
50                     visualizer.setVisible(true);
51                 }
52                 else {
53                     logButton.setText("Stop logging");
54                     isLogging = true;
55                     ThreadLog.setDefaultThreadLog(new ThreadLog());
56                 }
57             }
58
59         });
60         loadButton = new JButton("Load log");
61         loadButton.addActionListener(new ActionListener() {
62             @Override
63             public void actionPerformed(ActionEvent e) {
64                 JFileChooser chooser = new JFileChooser();
65                 FileNameExtensionFilter filter = new FileNameExtensionFilter(
66                         "Thread Logs (*.tlog)", "tlog", "tlog");
67                 chooser.setFileFilter(filter);
68                 int returnVal = chooser.showOpenDialog(ThreadLogController.this);
69                 if (returnVal != JFileChooser.APPROVE_OPTION)
70                     return;
71
72                 try {
73                     ThreadLog log = ThreadLog.deserialize(chooser.getSelectedFile());
74                     ThreadLogVisualizer visualizer = new ThreadLogVisualizer();
75                     visualizer.setLog(log);
76                     visualizer.setVisible(true);
77                 } catch (IOException ex) {
78                     ex.printStackTrace();
79                 }
80             }
81         });
82         getContentPane().setLayout(new GridLayout(2, 1));
83         getContentPane().add(logButton);
84         getContentPane().add(loadButton);
85
86         setSize(200, 100);
87     }
88
89     public static void start() {
90         javax.swing.SwingUtilities.invokeLater(new Runnable() {
91             public void run() {
92                 new ThreadLogController().setVisible(true);
93             }
94         });
95     }
96
97     public static void main(String[] args) {
98         start();
99     }
100
101 }