|
From: Lukas P. <pe...@us...> - 2002-07-29 16:42:04
|
Update of /cvsroot/javaprofiler/module/net/sourceforge/javaprofiler/module/views In directory usw-pr-cvs1:/tmp/cvs-serv29809 Added Files: ActiveThreadsView.java Log Message: Panel showing count of active threads. --- NEW FILE: ActiveThreadsView.java --- /* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"); you may not use this file except * in compliance with the License. A copy of the License is available * at http://www.sun.com/ * * The Original Code is the Java Profiler module. The Initial Developers * of the Original Code are Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. * * Portions created by Jan Stola are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Pavel Vacha are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Michal Pise are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Petr Luner are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Lukas Petru are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Marek Przeczek are Copyright (C) 2000-2001. * All Rights Reserved. * * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. */ package net.sourceforge.javaprofiler.module.views; import javax.swing.*; import javax.swing.event.ChangeListener; import javax.swing.event.ChangeEvent; import java.awt.BorderLayout; import java.util.TimerTask; import java.util.Iterator; import net.sourceforge.javaprofiler.jpiimpl.realtime.*; /** This component provides is a panel containing graph of active threads and * two labels showing the maximum and current count of active threads. * @author Lukas Petru */ public class ActiveThreadsView extends JPanel { /** Component showing a graph. */ private TimeSeriesGraph graph; /** Object returned by getTimerTask. */ private TimerTask task; /** Constructs a panel and an associated TimerTask. The graph is updated * whenewer the associated TimerTask is run. */ public ActiveThreadsView(final ImageR image) { super(new BorderLayout()); graph=new TimeSeriesGraph(); add(graph, BorderLayout.CENTER); final TimeSeriesModel m=graph.getModel(); final JLabel label1=new JLabel("curr: 000"); final JLabel label2=new JLabel("max: 000"); m.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { label1.setText("curr: " + m.getLast()); label2.setText("max: " + m.getMax()); } }); JPanel sPanel=new JPanel(); sPanel.add(label2); sPanel.add(label1); add(sPanel, BorderLayout.SOUTH); task=new TimerTask() { public void run() { image.refreshThreads(); // count active threads int act=0; Iterator it=image.getThreads().iterator(); while (it.hasNext()) { ThreadR th=(ThreadR) it.next(); if (th.isActive()) act++; } final int val=act; // set data in event-dispatching thread SwingUtilities.invokeLater(new Runnable() { public void run() { m.shift(val); } }); } }; } /** Returns associated <code>TimerTask</code>. */ public TimerTask getTimerTask() { return task; } } |