edu.wisc.ssec.mcidasv.util
Class MemoryMonitor

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by edu.wisc.ssec.mcidasv.util.MemoryMonitor
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Runnable, Accessible

public class MemoryMonitor
extends JPanel
implements Runnable

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
private static Font clockFont
           
private static SimpleDateFormat clockFormat
           
private static DecimalFormat fmt
          format
private  JLabel label
          the label
private static long lastTimeRanGC
          Keep track of the last time we ran the gc and cleared the cache
private  String mbString
           
private  String memoryString
           
private  int percentCancel
          percent cancel
private  int percentThreshold
          percent threshold
private  boolean running
          flag for running
private  boolean showClock
           
private  long sleepInterval
          sleep interval
private  StateManager stateManager
           
private  Thread thread
          a thread
private  int timesAboveThreshold
          number of times above the threshold
private  boolean triedToCancel
          have we tried to cancel the load yet
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
MemoryMonitor(StateManager stateManager)
          Default constructor
MemoryMonitor(StateManager stateManager, int percentThreshold, int percentCancel, boolean showClock)
          Create a new MemoryMonitor
 
Method Summary
private  Color doColorThing(int percent)
           
 boolean getRunning()
          Get whether we are running
private  String getToolTip()
          Returns a description of either the clock or memory monitor GUI.
private  void handleMouseEvent(MouseEvent event)
          Handle a mouse event
static void main(String[] args)
          Test routine
private  void popupMenu(MouseEvent event)
          Popup a menu on an event
 void run()
          Run this monitor
 void runGC()
          Run the GC and clear the cache
 void setLabelFont(Font f)
          Set the label font
 void setRunning(boolean r)
          Set whether we are running
private  void showStats()
          Show the statistics.
private  void start()
          Start running
 void stop()
          Stop running
private  void toggleClock()
           
 void toggleRunning()
          Toggle running
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

running

private boolean running
flag for running


sleepInterval

private final long sleepInterval
sleep interval

See Also:
Constant Field Values

thread

private Thread thread
a thread


percentThreshold

private final int percentThreshold
percent threshold


timesAboveThreshold

private int timesAboveThreshold
number of times above the threshold


percentCancel

private final int percentCancel
percent cancel


triedToCancel

private boolean triedToCancel
have we tried to cancel the load yet


fmt

private static DecimalFormat fmt
format


label

private JLabel label
the label


lastTimeRanGC

private static long lastTimeRanGC
Keep track of the last time we ran the gc and cleared the cache


stateManager

private StateManager stateManager

memoryString

private String memoryString

mbString

private String mbString

showClock

private boolean showClock

clockFont

private static final Font clockFont

clockFormat

private static SimpleDateFormat clockFormat
Constructor Detail

MemoryMonitor

public MemoryMonitor(StateManager stateManager)
Default constructor

Parameters:
stateManager -

MemoryMonitor

public MemoryMonitor(StateManager stateManager,
                     int percentThreshold,
                     int percentCancel,
                     boolean showClock)
Create a new MemoryMonitor

Parameters:
stateManager -
percentThreshold - the percentage of use memory before garbage collection is run.
percentCancel -
showClock -
Method Detail

handleMouseEvent

private void handleMouseEvent(MouseEvent event)
Handle a mouse event

Parameters:
event - the event

toggleClock

private void toggleClock()

getToolTip

private String getToolTip()
Returns a description of either the clock or memory monitor GUI.

Returns:
Description of either the clock or memory monitor GUI.

popupMenu

private void popupMenu(MouseEvent event)
Popup a menu on an event

Parameters:
event - the event

toggleRunning

public void toggleRunning()
Toggle running


setLabelFont

public void setLabelFont(Font f)
Set the label font

Parameters:
f - the font

stop

public void stop()
Stop running


start

private void start()
Start running


runGC

public void runGC()
Run the GC and clear the cache


showStats

private void showStats()
                throws IllegalStateException
Show the statistics.

Throws:
IllegalStateException

doColorThing

private Color doColorThing(int percent)

run

public void run()
Run this monitor

Specified by:
run in interface Runnable

setRunning

public void setRunning(boolean r)
Set whether we are running

Parameters:
r - true if we are running

getRunning

public boolean getRunning()
Get whether we are running

Returns:
true if we are

main

public static void main(String[] args)
Test routine

Parameters:
args - not used