de.qfs.apps.qflog.logview
Class LogView

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--de.qfs.apps.qflog.logview.LogView

public class LogView
extends javax.swing.JPanel
implements java.util.Observer

This is a complex view for displaying log messages. It is composed of a LogTableView, a LogFilterView and a LogLevelView and connects those in useful ways.

A LogView can either be used directly by an application to display its log messages and change its log levels by calling logToView, or it can be used with a log server to handle these tasks over RMI.

The LogView must be initialized by a call to init after creation. It uses its own resources for localization, which can be modified via setResources.

The Configurator of the LogView contains all Configurable parts of the subviews as well as the LogView's own configuration. It should be registered with the Configuration even when the LogView is not being displayed initially, since it contains the settings for the log levels of an application.

Version:
$Revision: 1.45 $
Author:
Gregor Schmid
See Also:
Serialized Form

Inner classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Field Summary
protected  de.qfs.lib.option.OptionSet options
          The Options used by the LogView.
static int STATE_CONNECTED
          Identifier for view connected to a LogListener.
static int STATE_DISCONNECTED
          Identifier for a view disconnected from a former connected LogListener.
static int STATE_FILE
          Identifier for a file view.
static int STATE_INTERNAL
          Identifier for an internal view.
static int STATE_UNKNOWN
          Identifier for an unknown state.
 
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
 
Constructor Summary
LogView()
          Create a new LogView.
 
Method Summary
 void cleanup()
          Try to remove everything that might prevent the LogView from being garbage collected.
 void finalize()
          Finalize the LogView.
 java.lang.String getClientName()
          Get the name of the LogView's client.
 java.io.File getConfigurationDirectory()
          Get the default directory to save the LogView's configuration in.
 de.qfs.lib.config.Configurator getConfigurator()
          Get the Configurator for the LogView.
 java.io.File getFile()
          Get the file of the view.
 LogFilterView getFilterView()
          Get the filter view part.
 LogFrame getFrame()
          Get a LogFrame for the view, creating one if necessary.
 LogLevelView getLevelView()
          Get the level view part.
 int getLogCount()
          Get the total number of log entries for this LogView, including current and deleted entries.
 de.qfs.lib.option.OptionSet getOptions()
          Get the options of the LogView.
 de.qfs.lib.util.MapResourceBundle getResources()
          Get the resources used by the LogView.
 int getState()
          Get the state of the view.
 de.qfs.lib.gui.StatusLine getStatusLine()
          Get the StatusLine of the LogView.
 LogTableModel getTableModel()
          Get the LogTableModel of the LogView.
 LogTableView getTableView()
          Get the table view part.
 void init()
          Initialize the components of the view.
 boolean isLoggingEnabled()
          Query whether logging is enabled for LogView related classes.
static LogView logToView(java.lang.String name)
          Convenience method that takes care of everything to create a LogView and install it directly inside an application's logging system.
 javax.swing.JMenu makeViewMenu()
          Create the view menu for the LogView.
 void setClientName(java.lang.String clientName)
          Set the name of the LogView's client.
 void setConfigurationDirectory(java.io.File dir)
          Set the default directory to save the LogView's configuration in.
 void setFile(java.io.File file)
          Set the file of the view.
 void setLoggingEnabled(boolean enable)
          Enable or disable logging output caused directly or indirectly by LogView methods.
 void setLogLevels(LogLevelTreeModel model)
          Set the log level model for the LogView.
 void setResources(java.util.ResourceBundle rb)
          Override the default resources used by the LogView.
 void setState(int state)
          Set the state of the view.
 void showDetailView(boolean show)
          Set whether the detail view should be displayed.
 void showFilterView(boolean show)
          Set whether the filter view should be displayed.
 void showLevelView(boolean show)
          Set whether the log levels view should be displayed.
 void showStatusLine(boolean show)
          Set whether the status line should be displayed.
 void startLogging()
          Insert the LogView into the Log filter chain.
 void startLogging(de.qfs.lib.log.LogSource source)
          Add the LogView to the filter chain of a LogSource.
 void stopLogging()
          Remove the LogView from the Log filer chain.
 void stopLogging(de.qfs.lib.log.LogSource source)
          Remove the LogView from the filter chain of a LogSource.
 void update(java.util.Observable obj, java.lang.Object arg)
          Notify the LogView that one of its Observables has changed.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUIClassID, paramString, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInsets, getInsets, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, processComponentKeyEvent, processFocusEvent, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setCursor, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hide, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

STATE_UNKNOWN

public static final int STATE_UNKNOWN
Identifier for an unknown state.

STATE_INTERNAL

public static final int STATE_INTERNAL
Identifier for an internal view.

STATE_FILE

public static final int STATE_FILE
Identifier for a file view.

STATE_CONNECTED

public static final int STATE_CONNECTED
Identifier for view connected to a LogListener.

STATE_DISCONNECTED

public static final int STATE_DISCONNECTED
Identifier for a view disconnected from a former connected LogListener.

options

protected transient de.qfs.lib.option.OptionSet options
The Options used by the LogView.
Constructor Detail

LogView

public LogView()
Create a new LogView.
Method Detail

logToView

public static LogView logToView(java.lang.String name)
Convenience method that takes care of everything to create a LogView and install it directly inside an application's logging system. Initialization is handled as well as registering the LogView's resources with the Configuration, so its state is saved together with the application's state. To display the LogView, just call logView.getFrame().show();.
Parameters:
name - The client name to use for saved log files.
Returns:
The new LogView.

init

public void init()
Initialize the components of the view. This method is not called by the constructor to enable further configuration like setting the resources, before the view is initialized.

makeViewMenu

public javax.swing.JMenu makeViewMenu()
Create the view menu for the LogView.
Returns:
The view menu.

cleanup

public void cleanup()
Try to remove everything that might prevent the LogView from being garbage collected.

finalize

public void finalize()
Finalize the LogView.
Overrides:
finalize in class java.lang.Object

getState

public final int getState()
Get the state of the view.
Returns:
The view's state.

setState

public final void setState(int state)
Set the state of the view.
Parameters:
state - The state to set.

getClientName

public final java.lang.String getClientName()
Get the name of the LogView's client.
Returns:
The name of the LogView's client.

setClientName

public final void setClientName(java.lang.String clientName)
Set the name of the LogView's client. As a side effect the LogView registers itself with the Configuration.
Parameters:
clientName - The name to set.

getFile

public final java.io.File getFile()
Get the file of the view.
Returns:
The view's file.

setFile

public final void setFile(java.io.File file)
Set the file of the view.
Parameters:
file - The file to set.

isLoggingEnabled

public boolean isLoggingEnabled()
Query whether logging is enabled for LogView related classes.
Returns:
True if logging is enabled.

setLoggingEnabled

public final void setLoggingEnabled(boolean enable)
Enable or disable logging output caused directly or indirectly by LogView methods. If logging is disabled, all calls to methods that might create log messages will be protected with de.qfs.lib.log.Log.excludeThread. This is necessary, if the LogFilterTreeModel is used inside the application whose logs it is supposed to filter.

The default value is false.

Parameters:
enable - True to enable logging, false to disable it.

getResources

public final de.qfs.lib.util.MapResourceBundle getResources()
Get the resources used by the LogView.
Returns:
The LogView's resources.

setResources

public void setResources(java.util.ResourceBundle rb)
Override the default resources used by the LogView. If this method is not called, the LogView will use its default resource settings.

The resources are not passed on to the subviews of the LogView.

Parameters:
rb - ResourceBundle containing the resources to use.

getConfigurator

public de.qfs.lib.config.Configurator getConfigurator()
Get the Configurator for the LogView. It contains the collected Configurators of the subviews as well as the tree models and its own Configurables.
Returns:
The Configurator of the LogView.

getConfigurationDirectory

public final java.io.File getConfigurationDirectory()
Get the default directory to save the LogView's configuration in.
Returns:
The LogView's configuration save directory.

setConfigurationDirectory

public final void setConfigurationDirectory(java.io.File dir)
Set the default directory to save the LogView's configuration in.
Parameters:
dir - The LogView's configuration save directory.

getTableModel

public final LogTableModel getTableModel()
Get the LogTableModel of the LogView.
Returns:
The LogTableModel.

getLogCount

public int getLogCount()
Get the total number of log entries for this LogView, including current and deleted entries.
Returns:
The total number of entries.

getOptions

public final de.qfs.lib.option.OptionSet getOptions()
Get the options of the LogView.
Returns:
The options of the LogView.

getFrame

public LogFrame getFrame()
Get a LogFrame for the view, creating one if necessary.
Returns:
A LogFrame for the LogView.

getTableView

public final LogTableView getTableView()
Get the table view part.
Returns:
The nested LogTableView.

getFilterView

public final LogFilterView getFilterView()
Get the filter view part.
Returns:
The nested LogFilterView.

getLevelView

public final LogLevelView getLevelView()
Get the level view part.
Returns:
The nested LogLevelView.

getStatusLine

public de.qfs.lib.gui.StatusLine getStatusLine()
Get the StatusLine of the LogView.
Returns:
The StatusLine of the LogView.

setLogLevels

public void setLogLevels(LogLevelTreeModel model)
Set the log level model for the LogView.
Parameters:
model - The LogLevelModel to set.

showFilterView

public void showFilterView(boolean show)
Set whether the filter view should be displayed.
Parameters:
show - True to display the filter view.

showLevelView

public void showLevelView(boolean show)
Set whether the log levels view should be displayed.
Parameters:
show - True to display the log levels view.

showDetailView

public void showDetailView(boolean show)
Set whether the detail view should be displayed.
Parameters:
show - True to display the detail view.

showStatusLine

public void showStatusLine(boolean show)
Set whether the status line should be displayed.
Parameters:
show - True to display the status line.

update

public void update(java.util.Observable obj,
                   java.lang.Object arg)
Notify the LogView that one of its Observables has changed.
Specified by:
update in interface java.util.Observer
Parameters:
obj - The Observable that changed.
arg - Details about the change.

startLogging

public void startLogging()
Insert the LogView into the Log filter chain. Useful if the LogView is used directly inside an application to display its log messages.

stopLogging

public void stopLogging()
Remove the LogView from the Log filer chain.

startLogging

public void startLogging(de.qfs.lib.log.LogSource source)
Add the LogView to the filter chain of a LogSource. Typically used to get the log messages from a LogListener.
Parameters:
source - The LogSource to filter on.

stopLogging

public void stopLogging(de.qfs.lib.log.LogSource source)
Remove the LogView from the filter chain of a LogSource.
Parameters:
source - The LogSource to remove the filter from.