JIDE 3.5.15

com.jidesoft.status
Class MemoryStatusBarItem

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 com.jidesoft.swing.NullPanel
                      extended by com.jidesoft.status.StatusBarItem
                          extended by com.jidesoft.status.MemoryStatusBarItem
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class MemoryStatusBarItem
extends StatusBarItem

MemoryStatusBarItem is used to display current used memory vs total memory in current JVM. It also allows manually running garbage collection by pressing the garbage can button, or double clicking on the memory status area.

MemoryStatusBarItem's item name is "Status". We hardcoded inside this class. So if you add it to StatusBar and want to get it, you just call statusBar.getItemByName("Status"). If you want to change it to something else, you would have to override getItemName method.

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
protected  AbstractButton _button
           
protected  JPanel _buttonPanel
           
protected  JComponent _statusArea
           
 
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
MemoryStatusBarItem()
          Default constructor.
 
Method Summary
protected  AbstractButton createButton()
          Creates a button which will run garbage collector.
 String formatText(long totalMemory, long freeMemory, long maxMemory)
          Gets the text.
protected  String formatTooltip(long freeMemory, long totalMemory, long maxMemory)
          Gets the tooltip.
 Color getFillColor()
          Gets filled color.
protected  long getFreeMemory()
          Gets the free memory.
 Icon getGcIcon()
          Gets the icon of GC.
 String getItemName()
          Gets item name.
protected  long getMaxMemory()
          Returns the maximum amount of memory that the Java virtual machine will attempt to use.
 int getPreferredWidth()
          Gets preferred width.
protected  long getTotalMemory()
          Returns the total amount of memory in the Java virtual machine.
 int getUpdateInterval()
          Gets the update interval in mini-second.
 boolean isShowMaxMemory()
          Gets the flag for showMaxMemory.
 void setFillColor(Color fillColor)
          Set filled color.
 void setGcIcon(Icon gcIcon)
          Sets the icon of GC (Gabage Collection).
 void setShowMaxMemory(boolean showMaxMemory)
          Sets of the upper memory is the actual heap memory or the max memory.
 void setUpdateInterval(int interval)
          Sets update interval, in mini-second.
 void start()
          Starts the timer to repaint the memory status area after certain interval (2 seconds by default).
 void stop()
          Stops the timer.
 void updateUI()
          Resets the UI property with a value from the current look and feel.
 
Methods inherited from class com.jidesoft.status.StatusBarItem
getPreferredSize, setPreferredWidth
 
Methods inherited from class com.jidesoft.swing.NullPanel
setBackground, setFont, setForeground
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI
 
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, 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, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, 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

_statusArea

protected JComponent _statusArea

_button

protected AbstractButton _button

_buttonPanel

protected JPanel _buttonPanel
Constructor Detail

MemoryStatusBarItem

public MemoryStatusBarItem()
Default constructor.

Method Detail

createButton

protected AbstractButton createButton()
Creates a button which will run garbage collector. Subclass can override it to create your own button.

Returns:
the button which will run garbage collector.

getTotalMemory

protected long getTotalMemory()
Returns the total amount of memory in the Java virtual machine.

Returns:
the total amount of memory in the Java virtual machine.

getMaxMemory

protected long getMaxMemory()
Returns the maximum amount of memory that the Java virtual machine will attempt to use.

Returns:
the maximum amount of memory that the Java virtual machine will attempt to use.

getFreeMemory

protected long getFreeMemory()
Gets the free memory.

Returns:
the free memory.

formatText

public String formatText(long totalMemory,
                         long freeMemory,
                         long maxMemory)
Gets the text.

Parameters:
freeMemory - the free memory
totalMemory - the total memory
maxMemory - the max memory as defined in JVM -Xmx.
Returns:
the formatted tooltip.

formatTooltip

protected String formatTooltip(long freeMemory,
                               long totalMemory,
                               long maxMemory)
Gets the tooltip.

Parameters:
freeMemory - the free memory
totalMemory - the total memory
maxMemory - the max memory as defined in JVM -Xmx.
Returns:
the formatted tooltip.

getItemName

public String getItemName()
Description copied from class: StatusBarItem
Gets item name.

Specified by:
getItemName in class StatusBarItem
Returns:
item name

getFillColor

public Color getFillColor()
Gets filled color.

Returns:
filled color

updateUI

public void updateUI()
Description copied from class: StatusBarItem
Resets the UI property with a value from the current look and feel.

Overrides:
updateUI in class StatusBarItem
See Also:
JComponent.updateUI()

setFillColor

public void setFillColor(Color fillColor)
Set filled color.

Parameters:
fillColor - the fill color.

getGcIcon

public Icon getGcIcon()
Gets the icon of GC.

Returns:
the icon for GC

setGcIcon

public void setGcIcon(Icon gcIcon)
Sets the icon of GC (Gabage Collection).

Parameters:
gcIcon - the GC icon

setUpdateInterval

public void setUpdateInterval(int interval)
Sets update interval, in mini-second. Default is 500ms. If you need to display second, make sure it's less than 1000ms.

Parameters:
interval - interval in mini-second

getUpdateInterval

public int getUpdateInterval()
Gets the update interval in mini-second.

Returns:
update interval in mini-second

start

public void start()
Starts the timer to repaint the memory status area after certain interval (2 seconds by default).


stop

public void stop()
Stops the timer. Call this method the main frame is closing.


getPreferredWidth

public int getPreferredWidth()
Description copied from class: StatusBarItem
Gets preferred width. If it is set, the actual width will be kept the same when there is enough space. If not set, the width will be changing when content of the status bar item changes.

Overrides:
getPreferredWidth in class StatusBarItem
Returns:
preferred width

isShowMaxMemory

public boolean isShowMaxMemory()
Gets the flag for showMaxMemory.

Returns:
true or false.

setShowMaxMemory

public void setShowMaxMemory(boolean showMaxMemory)
Sets of the upper memory is the actual heap memory or the max memory.

Parameters:
showMaxMemory - true or false.

JIDE 3.5.15