org.opensourcephysics.controls
Class OSPLog

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Window
              extended by java.awt.Frame
                  extended by javax.swing.JFrame
                      extended by org.opensourcephysics.controls.OSPLog
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.RootPaneContainer, javax.swing.WindowConstants

public class OSPLog
extends javax.swing.JFrame

This is a viewable file-based message log for a java package. It displays log records in a text pane and saves them in a temp file.

Version:
1.0
Author:
Douglas Brown, Wolfgang Christian
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JFrame
javax.swing.JFrame.AccessibleJFrame
 
Nested classes/interfaces inherited from class java.awt.Frame
java.awt.Frame.AccessibleAWTFrame
 
Nested classes/interfaces inherited from class java.awt.Window
java.awt.Window.AccessibleAWTWindow
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected static javax.swing.text.Style black
           
protected static javax.swing.text.Style blue
           
protected static java.awt.Color DARK_BLUE
           
protected static java.awt.Color DARK_GREEN
           
protected static java.awt.Color DARK_RED
           
protected static javax.swing.text.Style gray
           
protected static javax.swing.text.Style green
           
static java.util.logging.Level[] levels
           
protected static javax.swing.text.Style magenta
           
protected static javax.swing.text.Style red
           
 
Fields inherited from class javax.swing.JFrame
accessibleContext, EXIT_ON_CLOSE, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
OSPLog(java.lang.Class<?> type)
          Constructs an OSPLog for a specified class.
OSPLog(java.lang.Class<?> type, java.lang.String resourceBundleName)
          Constructs an OSPLog for a specified class and resource bundle.
OSPLog(java.lang.Package pkg)
          Constructs an OSPLog for a specified package.
OSPLog(java.lang.Package pkg, java.lang.String resourceBundleName)
          Constructs an OSPLog for a specified package and resource bundle.
 
Method Summary
 void clear()
          Clears the log.
static void clearLog()
          Clears the Log.
static void config(java.lang.String msg)
          Logs a configuration message.
protected  void createGUI()
          Creates the GUI.
protected  java.util.logging.Logger createLogger()
          Creates and initializes the logger.
protected  void createMenus()
          Creates the popup menu.
static void fine(java.lang.String msg)
          Logs a fine debugging message.
static void finer(java.lang.String msg)
          Logs a finer debugging message.
static void finest(java.lang.String msg)
          Logs a finest debugging message.
protected static javax.swing.JFileChooser getChooser()
          Gets a file chooser.
protected  java.util.logging.Handler getFileHandler()
          Gets the file handler using lazy instantiation.
 java.lang.String getLogDir()
          Gets the directory where the log file will be saved if logging is enabled.
 java.util.logging.Logger getLogger()
          Gets the logger.
 javax.swing.JPanel getLogPanel()
          Gets the log panel so it can be displayed in a dialog or other container.
static OSPLog getOSPLog()
          Gets the OSPLog that can be shared by multiple OSP packages.
static void info(java.lang.String msg)
          Logs an information message.
static boolean isLogVisible()
          Determines if the shared log is visible.
 boolean isVisible()
          Determines if the log is visible.
 java.lang.String open()
          Opens a text file selected with a chooser and writes the contents to the log.
 java.lang.String open(java.lang.String fileName)
          Opens a text file specified by name and writes the contents to the log.
static java.util.logging.Level parseLevel(java.lang.String level)
          Returns the Level with the specified name, or null if none.
protected  java.lang.String read(java.lang.String fileName)
          Reads a file.
 java.lang.String saveLog(java.lang.String fileName)
          Saves the log to a text file specified by name.
 java.lang.String saveLogAs()
          Saves a log to a text file selected with a chooser.
 java.lang.String saveXML(java.lang.String fileName)
          Saves the xml-formatted log records to a file specified by name.
 java.lang.String saveXMLAs()
          Saves the xml-formatted log records to a file selected with a chooser.
static void setLevel(java.util.logging.Level level)
          Sets the logger level.
 void setLogDir(java.lang.String dir)
          Sets the directory where the log file will be saved if logging is enabled.
 void setLogToFile(boolean enable)
          Enables logging to a file.
 void setVisible(boolean visible)
          Sets the visibility of this log.
static void severe(java.lang.String msg)
          Logs a severe error message.
static javax.swing.JFrame showLog()
          Shows the log when it is invoked from the event queue.
static void showLogInvokeLater()
          Shows the log.
static void warning(java.lang.String msg)
          Logs a warning message.
 
Methods inherited from class javax.swing.JFrame
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update
 
Methods inherited from class java.awt.Frame
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setResizable, setState, setTitle, setUndecorated
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOwnedWindows, getOwner, getOwnerlessWindows, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, show, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, 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, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isValid, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resize, resize, setBackground, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Field Detail

black

protected static javax.swing.text.Style black

red

protected static javax.swing.text.Style red

blue

protected static javax.swing.text.Style blue

green

protected static javax.swing.text.Style green

magenta

protected static javax.swing.text.Style magenta

gray

protected static javax.swing.text.Style gray

DARK_GREEN

protected static final java.awt.Color DARK_GREEN

DARK_BLUE

protected static final java.awt.Color DARK_BLUE

DARK_RED

protected static final java.awt.Color DARK_RED

levels

public static final java.util.logging.Level[] levels
Constructor Detail

OSPLog

public OSPLog(java.lang.Package pkg)
Constructs an OSPLog for a specified package.

Parameters:
pkg - the package

OSPLog

public OSPLog(java.lang.Package pkg,
              java.lang.String resourceBundleName)
Constructs an OSPLog for a specified package and resource bundle.

Parameters:
pkg - the package
resourceBundleName - the name of the resource bundle

OSPLog

public OSPLog(java.lang.Class<?> type)
Constructs an OSPLog for a specified class.

Parameters:
type - the class

OSPLog

public OSPLog(java.lang.Class<?> type,
              java.lang.String resourceBundleName)
Constructs an OSPLog for a specified class and resource bundle.

Parameters:
type - the class
resourceBundleName - the name of the resource bundle
Method Detail

getOSPLog

public static OSPLog getOSPLog()
Gets the OSPLog that can be shared by multiple OSP packages.

Returns:
the shared OSPLog

setLogDir

public void setLogDir(java.lang.String dir)
Sets the directory where the log file will be saved if logging is enabled.

Parameters:
dir - String

getLogDir

public java.lang.String getLogDir()
Gets the directory where the log file will be saved if logging is enabled.

Parameters:
dir - String

isLogVisible

public static boolean isLogVisible()
Determines if the shared log is visible.

Returns:
true if visible

setVisible

public void setVisible(boolean visible)
Sets the visibility of this log.

Overrides:
setVisible in class java.awt.Window
Parameters:
true - to set visible

isVisible

public boolean isVisible()
Determines if the log is visible.

Overrides:
isVisible in class java.awt.Component
Returns:
true if visible

showLog

public static javax.swing.JFrame showLog()
Shows the log when it is invoked from the event queue.


showLogInvokeLater

public static void showLogInvokeLater()
Shows the log.


setLevel

public static void setLevel(java.util.logging.Level level)
Sets the logger level.

Parameters:
level - the Level

parseLevel

public static java.util.logging.Level parseLevel(java.lang.String level)
Returns the Level with the specified name, or null if none.

Parameters:
level - the Level

severe

public static void severe(java.lang.String msg)
Logs a severe error message.

Parameters:
msg - the message

warning

public static void warning(java.lang.String msg)
Logs a warning message.

Parameters:
msg - the message

info

public static void info(java.lang.String msg)
Logs an information message.

Parameters:
msg - the message

config

public static void config(java.lang.String msg)
Logs a configuration message.

Parameters:
msg - the message

fine

public static void fine(java.lang.String msg)
Logs a fine debugging message.

Parameters:
msg - the message

clearLog

public static void clearLog()
Clears the Log.

Parameters:
msg - the message

finer

public static void finer(java.lang.String msg)
Logs a finer debugging message.

Parameters:
msg - the message

finest

public static void finest(java.lang.String msg)
Logs a finest debugging message.

Parameters:
msg - the message

getLogPanel

public javax.swing.JPanel getLogPanel()
Gets the log panel so it can be displayed in a dialog or other container.

Returns:
a JPanel containing the log

clear

public void clear()
Clears the log.


saveLog

public java.lang.String saveLog(java.lang.String fileName)
Saves the log to a text file specified by name.

Parameters:
fileName - the file name
Returns:
the name of the file

saveLogAs

public java.lang.String saveLogAs()
Saves a log to a text file selected with a chooser.

Returns:
the name of the file

saveXML

public java.lang.String saveXML(java.lang.String fileName)
Saves the xml-formatted log records to a file specified by name.

Parameters:
fileName - the file name
Returns:
the name of the file

saveXMLAs

public java.lang.String saveXMLAs()
Saves the xml-formatted log records to a file selected with a chooser.

Returns:
the name of the file

open

public java.lang.String open()
Opens a text file selected with a chooser and writes the contents to the log.

Returns:
the name of the file

open

public java.lang.String open(java.lang.String fileName)
Opens a text file specified by name and writes the contents to the log.

Parameters:
fileName - the file name
Returns:
the file name

getLogger

public java.util.logging.Logger getLogger()
Gets the logger.

Returns:
the logger

setLogToFile

public void setLogToFile(boolean enable)
Enables logging to a file.

Parameters:
enable - true to log to a file

createGUI

protected void createGUI()
Creates the GUI.


createLogger

protected java.util.logging.Logger createLogger()
Creates and initializes the logger.

Returns:
the logger

getFileHandler

protected java.util.logging.Handler getFileHandler()
Gets the file handler using lazy instantiation.

Returns:
the Handler

createMenus

protected void createMenus()
Creates the popup menu.


getChooser

protected static javax.swing.JFileChooser getChooser()
Gets a file chooser.

Returns:
the chooser

read

protected java.lang.String read(java.lang.String fileName)
Reads a file.

Parameters:
fileName - the name of the file
Returns:
the file contents as a String