// $Id: Status.java,v 1.2 2007/02/05 04:11:33 Sasha Buzko Exp $ // // Copyright (c) 2000-2002 San Diego Supercomputer Center (SDSC), // a facility operated jointly by the University of California, // San Diego (UCSD) and General Atomics, San Diego, California, USA. // // Users and possessors of this source code are hereby granted a // nonexclusive, royalty-free copyright and design patent license to // use this code in individual software. License is not granted for // commercial resale, in whole or in part, without prior written // permission from SDSC. This source is provided "AS IS" without express // or implied warranty of any kind. // // For further information, please see: http://mbt.sdsc.edu // // History: // $Log: Status.java,v $ // Revision 1.2 2007/02/05 04:11:33 Sasha Buzko // *** empty log message *** // // Revision 1.1 2006/05/20 17:02:03 Sasha Buzko // Updated version // // Revision 1.1 2006/04/30 20:13:59 Sasha Buzko // New version of the app // // Revision 1.1 2006/04/15 19:42:27 Sasha Buzko // Initial commit // // Revision 1.1 2005/11/13 04:35:06 Administrator // *** empty log message *** // // Revision 1.4 2003/04/03 22:40:33 moreland // Added "progress" handling support. // // Revision 1.3 2003/02/27 21:23:04 moreland // Corrected javadoc "see" reference paths. // // Revision 1.2 2003/02/03 21:50:28 moreland // Added some introspection methods to facilitate building GUI components. // // Revision 1.1 2003/01/31 21:15:50 moreland // Added classes to provide a toolkit-wide static status message output mechanism. // // Revision 1.0 2002/10/24 17:54:01 moreland // First revision. // package edu.sdsc.mbt.util; import java.util.Vector; /** * Provides a toolkit-wide static status message output mechanism. * This should be used to produce textual status messages to the user. * By default, messages are printed to the current terminal, but * authors may elect to add StatusListener objects in order to capture * the output for display in scrolling status GUIs, output logs, etc. *
* @see edu.sdsc.mbt.util.StatusListener * @see edu.sdsc.mbt.util.StatusEvent *
* @author John L. Moreland */ public class Status { private static boolean enabled = true; // // Public output LEVEL values. // /** * On a scale of 1 to 5, how important is the message. * A status level is passed to the output method in order for an * application to specify the intent level of the message, and, * the level is also used to set the constraint level for output. * Only messages at or above this level will be output. * Default terminal output is not generated. */ public static final int LEVEL_QUIET = 0; /** * On a scale of 1 to 5, how important is the message. * A status level is passed to the output method in order for an * application to specify the intent level of the message, and, * the level is also used to set the constraint level for output. * Only messages at or above this level will be output. * Default terminal output is sent to STDERR. */ public static final int LEVEL_ERROR = 1; /** * On a scale of 1 to 5, how important is the message. * A status level is passed to the output method in order for an * application to specify the intent level of the message, and, * the level is also used to set the constraint level for output. * Only messages at or above this level will be output. * Default terminal output is sent to STDOUT. */ public static final int LEVEL_WARNING = 2; /** * On a scale of 1 to 5, how important is the message. * A status level is passed to the output method in order for an * application to specify the intent level of the message, and, * the level is also used to set the constraint level for output. * Only messages at or above this level will be output. * Default terminal output is sent to STDOUT. */ public static final int LEVEL_REMARK = 3; /** * On a scale of 1 to 5, how important is the message. * A status level is passed to the output method in order for an * application to specify the intent level of the message, and, * the level is also used to set the constraint level for output. * Only messages at or above this level will be output. * Default terminal output is sent to STDERR. */ public static final int LEVEL_DEBUG = 4; /** * On a scale of 1 to 5, how important is the message. * A status level is passed to the output method in order for an * application to specify the intent level of the message, and, * the level is also used to set the constraint level for output. * Only messages at or above this level will be output. * Default terminal output is sent to STDERR. */ public static final int LEVEL_DUMP = 5; public static void disableStatus(){ enabled = false; } public static void enableStatus(){ enabled = true; } // // Private variables. // /** * A Vector of human-readable level names corresponding to level numbers. */ private static Vector level_names = null; static { level_names = new Vector( ); level_names.add( "Quiet" ); level_names.add( "Error" ); level_names.add( "Warning" ); level_names.add( "Remark" ); level_names.add( "Debug" ); level_names.add( "Dump" ); }; /** * Only messages at or above this level will be output. */ private static int output_level = LEVEL_REMARK; // Default to REMARK /** * Listener objects to which output will be sent. */ private static Vector statusListeners = null; /** * A singled shared StatusEvent object. */ private static StatusEvent statusEvent = new StatusEvent(); // // StatusListener methods. // /** * Add a StatusListener object in order to start recieving StatusEvent * messages. If one or more StatusListener objects are registered, then * no messages are printed to the terminal by the output method. *
*/ public static void addStatusListener( StatusListener statusListener ) { if ( statusListener == null ) return; if ( statusListeners == null ) statusListeners = new Vector( ); if ( statusEvent == null ) statusEvent = new StatusEvent(); statusListeners.add( statusListener ); } /** * Remove a StatusListener object in order to stop recieving StatusEvent * messages. If one or more StatusListener objects are registered, then * no messages are printed to the terminal by the output method. *
*/ public static void removeStatusListener( StatusListener statusListener ) { if ( statusListener == null ) return; if ( statusListeners == null ) return; statusListeners.remove( statusListener ); if ( statusListeners.size() <= 0 ) statusListeners = null; } // // OutputLevel methods. // /** * Set the output level for subsequent calls to the output method. * Only messages at or above this level will be output. *
*/ public static void setOutputLevel( int level ) { output_level = level; } /** * Set the output level for subsequent calls to the output method. * Only messages at or above this level will be output. *
*/
public static void setOutputLevel( String level_name )
{
int levelCount = getLevelCount( );
for ( int level=0; level
*/
public static int getLevelCount( )
{
return level_names.size( );
}
/**
* Get the human-reable name corresponding to the given level number.
*
*/
public static String getLevelName( int level )
{
return (String) level_names.elementAt( level );
}
//
// Output methods.
//
/**
* Output a message at the given status level.
*
*/
public static void output( int level, String message )
{
if (!enabled)return;
if ( level <= output_level )
{
if ( (statusEvent == null) || (statusListeners == null) )
{
if ( level == LEVEL_REMARK )
System.out.println( "Status(" + level + "): " + message );
else
System.err.println( "Status(" + level + "): " + message );
}
else
{
statusEvent.type = StatusEvent.TYPE_OUTPUT;
statusEvent.level = level;
statusEvent.message = message + "\n";
statusEvent.percent = 1.0f;
for ( int i=0; i