public class MemoryController
extends javax.swing.JPanel
implements java.awt.event.ActionListener
recycle_16.png
take care about
the image size. It should be exactly 14x14 pixels in size.
The controller offers the possibility to automatically run the garbage
collector if the used memory exceeds a certain threshold. This threshold
is specified as percentage of the maximum heap size. Common values for
this parameter are 80 - 90 %. The garbage collector is called only once
if the used memory exceeds the threshold value and not again and again
if the threshold is constantly exceeded. The automatic garbage collecting
functionality will additionally make a pause of certain seconds then so
that there will not be any blocking (penalty parameter in seconds).
Threshold values must be in the range between 10 and 100 % (default is 80 %).
The penalty must be a value at least of 1 second (default is 5 seconds).
The timeout for the controller update is passed in milliseconds and must
be a value greater equal 100 milliseconds.
If the auto-gc functionality is activated each manual garbage collection
initiated by the user will reset the auto-gc counter. This keeps the
garbage collector from doing unnecessary work.
javax.swing.JPanel.AccessibleJPanel
javax.swing.JComponent.AccessibleJComponent
Modifier and Type | Field and Description |
---|---|
static java.net.URL |
ICON_CANCEL
Icon representing a memory controller button to cancel the operation (external use).
|
static java.net.URL |
ICON_GO
Icon representing an functional memory controller button.
|
static int |
IDLE_CONTROLLER
Idle mode where the memory controller is displayed.
|
static int |
IDLE_PROGRESS
Idle mode where the (empty) progress bar without gc button is displayed.
|
protected java.util.Vector<ThresholdListener> |
thresholdListeners
Container holding the external threshold listeners.
|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Constructor and Description |
---|
MemoryController()
Constructor of this form.
|
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(java.awt.event.ActionEvent e)
This method is called automatically if an event comes along.
|
void |
addMouseListener(java.awt.event.MouseListener listener)
Adds a mouse listener for the status bar (only labels on the left side).
|
void |
addThresholdListener(ThresholdListener listener)
Adds a listener to be informed when a certain threshold was reached.
|
protected void |
finalize()
Clean-up method to help the gc.
|
javax.swing.JButton |
getAndRemoveButtonGC()
Provides the JVM garbage collector button, component is removed from layout.
|
javax.swing.JProgressBar |
getAndRemoveProgressBar()
Provides the progress bar, component is removed from layout.
|
javax.swing.JButton |
getButtonGC()
Provides the JVM garbage collector button.
|
int |
getIdleMode()
Determines the current display mode for the component.
|
int |
getPenalty()
Gets the penalty value on-the-fly (in seconds).
|
int |
getPriority()
Gets the priority for the update task.
|
javax.swing.JProgressBar |
getProgressBar()
Provides the progress bar.
|
java.lang.Runnable |
getTask(boolean infinite)
Provides the instance doing the controller update task.
|
int |
getThreshold()
Allows to get the timeout interval on-the-fly (in milliseconds).
|
int |
getTimeout()
Allows to get the timeout interval on-the-fly (in milliseconds).
|
int |
getVisibilityThreshold()
Provides the percentage which must be reached to make the memory controller be shown.
|
boolean |
isAutogc()
Gets the auto garbage collecting functionality setting.
|
void |
removeThresholdListener(ThresholdListener listener)
Removes a listener to be informed when a certain threshold was reached.
|
void |
runGC()
Explicitely runs the JVM garbage collector by clicking the button.
|
boolean |
setAutoGC(boolean autogc)
Allows to (de)activate the auto garbage collecting functionality.
|
boolean |
setPenalty(int penalty)
Allows to set the penalty value on-the-fly (in seconds).
|
boolean |
setPriority(int priority)
Sets the priority for the update task.
|
boolean |
setThreshold(int threshold)
Allows to set the auto-gc threshold on-the-fly (percentage).
|
boolean |
setTimeout(int timeout)
Allows to set the timeout interval on-the-fly (in milliseconds).
|
boolean |
setVisibilityThreshold(int threshold)
Sets the percentage which must be reached to make the memory controller be shown.
|
void |
startController()
Starts the update thread based on the current configuration.
|
void |
startExternalOp()
Configures the component to be utilized externally as progress bar.
|
void |
startExternalOp(java.awt.event.ActionListener listener)
Configures the component to be utilized externally as progress bar.
|
void |
startExternalOp(javax.swing.ImageIcon icon,
java.lang.String tooltip,
java.awt.event.ActionListener listener)
Configures the component to be utilized externally as progress bar.
|
void |
stopController()
Call this method if you like the update thread be terminated properly.
|
void |
stopExternalOp()
Configures the component not to be utilized externally as progress bar any longer.
|
void |
updateController()
Performs an explicit update of the data presented by the controller.
|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
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, isPaintingOrigin, 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
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, transferFocusDownCycle, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, 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, transferFocusBackward, transferFocusUpCycle
public static final java.net.URL ICON_GO
public static final java.net.URL ICON_CANCEL
public static final int IDLE_CONTROLLER
public static final int IDLE_PROGRESS
protected java.util.Vector<ThresholdListener> thresholdListeners
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
public void updateController()
ThresholdListener
instances are informed if the
given threshold values have been reached.
public void startController()
public void stopController()
public java.lang.Runnable getTask(boolean infinite)
startController()
and stopController()
at the right times.
Applications can delegate this regularly task to other threads like the status bar
which updates date and time. This allows for saving JVM memory and performance since
the dedicated thread must not be installed.
infinite
- Update task never returns except for errorspublic void runGC()
public javax.swing.JButton getButtonGC()
public javax.swing.JButton getAndRemoveButtonGC()
public javax.swing.JProgressBar getProgressBar()
public javax.swing.JProgressBar getAndRemoveProgressBar()
public boolean setTimeout(int timeout)
timeout
- The new timeout for controller refreshpublic int getTimeout()
public boolean setThreshold(int threshold)
threshold
- The new threshold for the auto-gc functionalitypublic int getThreshold()
public boolean setPenalty(int penalty)
penalty
- The new penalty for the auto-gc functionalitypublic int getPenalty()
public boolean setAutoGC(boolean autogc)
autogc
- Shall garbage collecting be automated?public boolean isAutogc()
public boolean setPriority(int priority)
priority
- Thread prioritypublic int getPriority()
public boolean setVisibilityThreshold(int threshold)
threshold
- The new threshold value (percentage in the range from 0 to 100)public int getVisibilityThreshold()
public void startExternalOp()
stopExternalOp()
in order to switch back to idle mode showing either the controller or the progress bar.
public void startExternalOp(java.awt.event.ActionListener listener)
stopExternalOp()
in order to switch back to idle mode showing either the controller or the progress bar.
listener
- The callback object, may be null
public void startExternalOp(javax.swing.ImageIcon icon, java.lang.String tooltip, java.awt.event.ActionListener listener)
stopExternalOp()
in order to switch back to idle mode showing either the controller or the progress bar.
icon
- The icon to be displayed instead of gc icon, null
deactivates buttontooltip
- The tooltip of the button, may be null
listener
- The callback object, may be null
public void stopExternalOp()
public void addMouseListener(java.awt.event.MouseListener listener)
addMouseListener
in class java.awt.Component
listener
- Listener for the componentpublic int getIdleMode()
public void addThresholdListener(ThresholdListener listener)
listener
- The listener instancejava.lang.NullPointerException
- If parameter is null
java.lang.IllegalArgumentException
- If threshold is not between 10% and 100%public void removeThresholdListener(ThresholdListener listener)
listener
- The listener instancejava.lang.NullPointerException
- If parameter is null
public void actionPerformed(java.awt.event.ActionEvent e)
actionPerformed
in interface java.awt.event.ActionListener
e
- Event object referenceCopyright © 2005-2013 Leisenfels UG (haftungsbeschränkt). All rights reserved.