1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.threadlog.ui;
14 import java.awt.GridLayout;
15 import java.awt.event.ActionEvent;
16 import java.awt.event.ActionListener;
17 import java.io.IOException;
19 import javax.swing.JButton;
20 import javax.swing.JFileChooser;
21 import javax.swing.JFrame;
22 import javax.swing.filechooser.FileNameExtensionFilter;
24 import org.simantics.threadlog.ThreadLog;
26 public class ThreadLogController extends JFrame {
28 private static final long serialVersionUID = -2487997716157625672L;
30 boolean isLogging = false;
34 public ThreadLogController() {
35 super("Thread log controller");
36 setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
38 logButton = new JButton("Start logging");
39 logButton.addActionListener(new ActionListener() {
42 public void actionPerformed(ActionEvent e) {
44 logButton.setText("Start logging");
46 ThreadLog log = ThreadLog.setDefaultThreadLog(null);
48 ThreadLogVisualizer visualizer = new ThreadLogVisualizer();
49 visualizer.setLog(log);
50 visualizer.setVisible(true);
53 logButton.setText("Stop logging");
55 ThreadLog.setDefaultThreadLog(new ThreadLog());
60 loadButton = new JButton("Load log");
61 loadButton.addActionListener(new ActionListener() {
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)
73 ThreadLog log = ThreadLog.deserialize(chooser.getSelectedFile());
74 ThreadLogVisualizer visualizer = new ThreadLogVisualizer();
75 visualizer.setLog(log);
76 visualizer.setVisible(true);
77 } catch (IOException ex) {
82 getContentPane().setLayout(new GridLayout(2, 1));
83 getContentPane().add(logButton);
84 getContentPane().add(loadButton);
89 public static void start() {
90 javax.swing.SwingUtilities.invokeLater(new Runnable() {
92 new ThreadLogController().setVisible(true);
97 public static void main(String[] args) {