|
From: Lukas P. <pe...@us...> - 2002-07-26 09:38:23
|
Update of /cvsroot/javaprofiler/test/module
In directory usw-pr-cvs1:/tmp/cvs-serv14675
Modified Files:
MainThreads.java
Log Message:
visually changed
Index: MainThreads.java
===================================================================
RCS file: /cvsroot/javaprofiler/test/module/MainThreads.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** MainThreads.java 16 Jul 2002 22:15:48 -0000 1.2
--- MainThreads.java 26 Jul 2002 09:38:19 -0000 1.3
***************
*** 1,100 ****
! //package net.sourceforge.javaprofiler.module.views;
!
! import javax.swing.*;
! import java.awt.*;
! import java.awt.event.*;
! import java.util.Timer;
! import java.util.TimerTask;
!
! import net.sourceforge.javaprofiler.jpiimpl.commun.*;
! import net.sourceforge.javaprofiler.jpiimpl.realtime.*;
import net.sourceforge.javaprofiler.module.views.*;
!
!
! /** Example of using TimeSeriesGraph to show number of running threads.
! * Please supply the name of profiled computer as a command-line parameter.
! * Default: localhost
! * @author Lukas Petru
! */
! public class MainThreads
! {
! static TimeSeriesGraph component;
!
! public static void main (String[] args) {
! connectAndRun(args);
! }
!
! private static void launchGui (final ImageR image, final IProf iprof) {
! JFrame frame=new JFrame("Main");
! frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
! frame.addWindowListener(new WindowAdapter() {
! public void windowClosing(WindowEvent e) {
! iprof.stop();
! System.exit(0);
! }
! });
!
! component=new TimeSeriesGraph();
! component.setBorder(BorderFactory.createLineBorder(Color.yellow));
! component.setBackground(Color.white);
! frame.getContentPane().add(component, BorderLayout.NORTH);
!
! frame.pack();
! frame.show();
!
! // Using java.util.Timer instead that of swing, because we don't
! // want the task to run in the event-dispatching thread.
! Timer timer=new Timer();
! TimerTask task=new TimerTask() {
! public void run() {
! final TimeSeriesModel m=component.getModel();
! final int[] data=m.copyData();
! // roll data
! System.arraycopy(data,1,data,0,data.length-1);
! image.refreshThreads();
! // get last value
! int val=image.getThreads().size();
! data[data.length-1]=val>0 ? val : 0;
!
! // set data in event-dispatching thread
! SwingUtilities.invokeLater(new Runnable() {
! public void run() {
! m.setData(data);
! }
! });
! }
! };
! timer.schedule(task, 1000, 500);
! }
!
! private static ImageR getImage(IProf iprof) {
! ImageR image=new ImageR(iprof, false);
! return image;
! }
!
! private static IProf connect (String hostName) {
! IProf iprof = new IProf(new CommunSetupSocket(CommunSetupSocket.
! CLIENT_MODE, hostName, 25595));
! try {
! iprof.run();
! return iprof;
! } catch (IProfException e) {
! System.out.println(e);
! return null;
! }
! }
!
! private static void connectAndRun(String[] arg) {
! String hostName = "localhost";
! if (arg.length >= 1)
! hostName = arg[0];
! System.out.println("host: " + hostName);
!
! IProf iprof = connect(hostName);
! if (iprof != null) {
! ImageR image=getImage(iprof);
! launchGui(image, iprof);
! }
! else System.out.println("Error connecting.");
! }
! }
--- 1,109 ----
! //package net.sourceforge.javaprofiler.module.views;
!
! import javax.swing.*;
! import javax.swing.event.ChangeListener;
! import javax.swing.event.ChangeEvent;
! import java.awt.*;
! import java.awt.event.*;
! import java.util.Timer;
! import java.util.TimerTask;
!
! import net.sourceforge.javaprofiler.jpiimpl.commun.*;
! import net.sourceforge.javaprofiler.jpiimpl.realtime.*;
import net.sourceforge.javaprofiler.module.views.*;
!
! /** Example of using TimeSeriesGraph to show number of running threads.
! * Please supply the name of profiled computer as a command-line parameter.
! * Default: localhost
! * @author Lukas Petru
! */
! public class MainThreads
! {
! static TimeSeriesGraph component;
!
! public static void main (String[] args) {
! connectAndRun(args);
! }
!
! private static void launchGui (final ImageR image, final IProf iprof) {
! JFrame frame=new JFrame("Main");
! frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
! frame.addWindowListener(new WindowAdapter() {
! public void windowClosing(WindowEvent e) {
! iprof.stop();
! System.exit(0);
! }
! });
!
! component=new TimeSeriesGraph();
! component.setBorder(BorderFactory.createLineBorder(Color.yellow));
! frame.getContentPane().add(component, BorderLayout.NORTH);
!
! final TimeSeriesModel m=component.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);
! frame.getContentPane().add(sPanel, BorderLayout.SOUTH);
!
! frame.pack();
! frame.show();
!
! // Using java.util.Timer instead that of swing, because we don't
! // want the task to run in the event-dispatching thread.
! Timer timer=new Timer();
! TimerTask task=new TimerTask() {
! public void run() {
! final TimeSeriesModel m=component.getModel();
! image.refreshThreads();
! // get last value
! final int val=image.getThreads().size();
! // set data in event-dispatching thread
! SwingUtilities.invokeLater(new Runnable() {
! public void run() {
! m.shift(val);
! }
! });
! }
! };
! timer.schedule(task, 1000, 500);
! }
!
! private static ImageR getImage(IProf iprof) {
! ImageR image=new ImageR(iprof, false);
! return image;
! }
!
! private static IProf connect (String hostName) {
! IProf iprof = new IProf(new CommunSetupSocket(CommunSetupSocket.
! CLIENT_MODE, hostName, 25595));
! try {
! iprof.run();
! return iprof;
! } catch (IProfException e) {
! System.out.println(e);
! return null;
! }
! }
!
! private static void connectAndRun(String[] arg) {
! String hostName = "localhost";
! if (arg.length >= 1)
! hostName = arg[0];
! System.out.println("host: " + hostName);
!
! IProf iprof = connect(hostName);
! if (iprof != null) {
! ImageR image=getImage(iprof);
! launchGui(image, iprof);
! }
! else System.out.println("Error connecting.");
! }
! }
|