[Jarspy-commits] CVS: JarSpy/src/com/ociweb/gui MemoryMeter.java,1.3,1.4
Status: Beta
Brought to you by:
brown_j
|
From: Jeff B. <br...@us...> - 2002-09-18 00:08:20
|
Update of /cvsroot/jarspy/JarSpy/src/com/ociweb/gui
In directory usw-pr-cvs1:/tmp/cvs-serv18930
Modified Files:
MemoryMeter.java
Log Message:
add popup menu to trigger gc and add some comments
Index: MemoryMeter.java
===================================================================
RCS file: /cvsroot/jarspy/JarSpy/src/com/ociweb/gui/MemoryMeter.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** MemoryMeter.java 17 Sep 2002 23:51:36 -0000 1.3
--- MemoryMeter.java 18 Sep 2002 00:08:16 -0000 1.4
***************
*** 20,25 ****
--- 20,31 ----
import java.awt.BorderLayout;
+ import java.awt.event.ActionEvent;
+ import java.awt.event.ActionListener;
+ import java.awt.event.MouseAdapter;
+ import java.awt.event.MouseEvent;
import java.text.DecimalFormat;
+ import javax.swing.JMenuItem;
import javax.swing.JPanel;
+ import javax.swing.JPopupMenu;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;
***************
*** 30,49 ****
public class MemoryMeter extends JPanel {
!
public static final long DEFAULT_REFRESH_INTERVAL = 4000;
private JProgressBar progressBar = new JProgressBar();
private Thread refreshThread;
private long refreshInterval;
private DecimalFormat kFormatter = new DecimalFormat("#,##0.#K");
private DecimalFormat mFormatter = new DecimalFormat("###,###,###.#M");
private Runnable updateRunnable;
public MemoryMeter() {
this(DEFAULT_REFRESH_INTERVAL);
}
public MemoryMeter(long refreshInterval) {
super(new BorderLayout());
--- 36,92 ----
public class MemoryMeter extends JPanel {
! /**
! * the default amount of time between automatic updates to the display
! */
public static final long DEFAULT_REFRESH_INTERVAL = 4000;
+ /**
+ * displays current memory utilization
+ */
private JProgressBar progressBar = new JProgressBar();
+
+ /**
+ * thread used to constantly run and update the ui
+ * @see #DEFAULT_REFRESH_INTERVAL
+ */
private Thread refreshThread;
+
+ /**
+ * The amount of time between automatic updates to the display
+ */
private long refreshInterval;
+ /**
+ * used to format memory figures represented in kBytes
+ */
private DecimalFormat kFormatter = new DecimalFormat("#,##0.#K");
+
+ /**
+ * used to format memory figures represented in mBytes
+ */
private DecimalFormat mFormatter = new DecimalFormat("###,###,###.#M");
+ /**
+ * a runnable that is executed each time the display needs to be updated
+ */
private Runnable updateRunnable;
+ /**
+ * popup menu used to trigger gc
+ */
+ private JPopupMenu gcPopup;
+
+ /**
+ * default constructor uses DEFAULT_REFRESH_INTERVAL
+ */
public MemoryMeter() {
this(DEFAULT_REFRESH_INTERVAL);
}
+ /**
+ *
+ * @param refreshInterval the number of milliseconds between
+ * updates to the display
+ */
public MemoryMeter(long refreshInterval) {
super(new BorderLayout());
***************
*** 56,69 ****
}
};
! }
!
! public void addNotify() {
! super.addNotify();
! start();
! }
!
! public void removeNotify() {
! stop();
! super.removeNotify();
}
--- 99,119 ----
}
};
! gcPopup = new JPopupMenu();
! JMenuItem mi = new JMenuItem("Run GC");
! gcPopup.add(mi);
! mi.addActionListener(new ActionListener() {
! public void actionPerformed(ActionEvent ae) {
! System.runFinalization();
! System.gc();
! SwingUtilities.invokeLater(updateRunnable);
! }
! });
! progressBar.addMouseListener(new MouseAdapter() {
! public void mouseClicked(MouseEvent me) {
! if (me.getButton() != 1) {
! gcPopup.show(MemoryMeter.this, me.getX(), me.getY());
! }
! }
! });
}
***************
*** 119,122 ****
--- 169,181 ----
return kFormatter.format(value / 1000f);
}
+ }
+ public void addNotify() {
+ super.addNotify();
+ start();
+ }
+
+ public void removeNotify() {
+ stop();
+ super.removeNotify();
}
}
|