1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.threadlog.ui;
\r
14 import java.awt.GridLayout;
\r
15 import java.awt.event.ActionEvent;
\r
16 import java.awt.event.ActionListener;
\r
17 import java.io.IOException;
\r
19 import javax.swing.JButton;
\r
20 import javax.swing.JFileChooser;
\r
21 import javax.swing.JFrame;
\r
22 import javax.swing.filechooser.FileNameExtensionFilter;
\r
24 import org.simantics.threadlog.ThreadLog;
\r
26 public class ThreadLogController extends JFrame {
\r
28 private static final long serialVersionUID = -2487997716157625672L;
\r
30 boolean isLogging = false;
\r
34 public ThreadLogController() {
\r
35 super("Thread log controller");
\r
36 setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
\r
38 logButton = new JButton("Start logging");
\r
39 logButton.addActionListener(new ActionListener() {
\r
42 public void actionPerformed(ActionEvent e) {
\r
44 logButton.setText("Start logging");
\r
46 ThreadLog log = ThreadLog.setDefaultThreadLog(null);
\r
48 ThreadLogVisualizer visualizer = new ThreadLogVisualizer();
\r
49 visualizer.setLog(log);
\r
50 visualizer.setVisible(true);
\r
53 logButton.setText("Stop logging");
\r
55 ThreadLog.setDefaultThreadLog(new ThreadLog());
\r
60 loadButton = new JButton("Load log");
\r
61 loadButton.addActionListener(new ActionListener() {
\r
63 public void actionPerformed(ActionEvent e) {
\r
64 JFileChooser chooser = new JFileChooser();
\r
65 FileNameExtensionFilter filter = new FileNameExtensionFilter(
\r
66 "Thread Logs (*.tlog)", "tlog", "tlog");
\r
67 chooser.setFileFilter(filter);
\r
68 int returnVal = chooser.showOpenDialog(ThreadLogController.this);
\r
69 if (returnVal != JFileChooser.APPROVE_OPTION)
\r
73 ThreadLog log = ThreadLog.deserialize(chooser.getSelectedFile());
\r
74 ThreadLogVisualizer visualizer = new ThreadLogVisualizer();
\r
75 visualizer.setLog(log);
\r
76 visualizer.setVisible(true);
\r
77 } catch (IOException ex) {
\r
78 ex.printStackTrace();
\r
82 getContentPane().setLayout(new GridLayout(2, 1));
\r
83 getContentPane().add(logButton);
\r
84 getContentPane().add(loadButton);
\r
89 public static void start() {
\r
90 javax.swing.SwingUtilities.invokeLater(new Runnable() {
\r
92 new ThreadLogController().setVisible(true);
\r
97 public static void main(String[] args) {
\r