X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.threadlog%2Fsrc%2Forg%2Fsimantics%2Fthreadlog%2Fui%2FThreadLogController.java;fp=bundles%2Forg.simantics.threadlog%2Fsrc%2Forg%2Fsimantics%2Fthreadlog%2Fui%2FThreadLogController.java;h=36a605db74b4c79e678d9e7eada4f8e2bd99614c;hp=0000000000000000000000000000000000000000;hb=2531cdf245f42bce854d43f4d49a23983c79db96;hpb=857dbc869796d772864327ce02f19dc252b159fc diff --git a/bundles/org.simantics.threadlog/src/org/simantics/threadlog/ui/ThreadLogController.java b/bundles/org.simantics.threadlog/src/org/simantics/threadlog/ui/ThreadLogController.java new file mode 100644 index 000000000..36a605db7 --- /dev/null +++ b/bundles/org.simantics.threadlog/src/org/simantics/threadlog/ui/ThreadLogController.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 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.threadlog.ui; + +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.IOException; + +import javax.swing.JButton; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.filechooser.FileNameExtensionFilter; + +import org.simantics.threadlog.ThreadLog; + +public class ThreadLogController extends JFrame { + + private static final long serialVersionUID = -2487997716157625672L; + + boolean isLogging = false; + JButton logButton; + JButton loadButton; + + public ThreadLogController() { + super("Thread log controller"); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + + logButton = new JButton("Start logging"); + logButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + if(isLogging) { + logButton.setText("Start logging"); + isLogging = false; + ThreadLog log = ThreadLog.setDefaultThreadLog(null); + + ThreadLogVisualizer visualizer = new ThreadLogVisualizer(); + visualizer.setLog(log); + visualizer.setVisible(true); + } + else { + logButton.setText("Stop logging"); + isLogging = true; + ThreadLog.setDefaultThreadLog(new ThreadLog()); + } + } + + }); + loadButton = new JButton("Load log"); + loadButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + JFileChooser chooser = new JFileChooser(); + FileNameExtensionFilter filter = new FileNameExtensionFilter( + "Thread Logs (*.tlog)", "tlog", "tlog"); + chooser.setFileFilter(filter); + int returnVal = chooser.showOpenDialog(ThreadLogController.this); + if (returnVal != JFileChooser.APPROVE_OPTION) + return; + + try { + ThreadLog log = ThreadLog.deserialize(chooser.getSelectedFile()); + ThreadLogVisualizer visualizer = new ThreadLogVisualizer(); + visualizer.setLog(log); + visualizer.setVisible(true); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + }); + getContentPane().setLayout(new GridLayout(2, 1)); + getContentPane().add(logButton); + getContentPane().add(loadButton); + + setSize(200, 100); + } + + public static void start() { + javax.swing.SwingUtilities.invokeLater(new Runnable() { + public void run() { + new ThreadLogController().setVisible(true); + } + }); + } + + public static void main(String[] args) { + start(); + } + +}