edu.wisc.ssec.mcidasv.startupmanager.options
Class LoggerLevelOption

java.lang.Object
  extended by edu.wisc.ssec.mcidasv.startupmanager.options.AbstractOption
      extended by edu.wisc.ssec.mcidasv.startupmanager.options.LoggerLevelOption
All Implemented Interfaces:
Option

public class LoggerLevelOption
extends AbstractOption

Representation of a choice allowing the user to select the global McIDAS-V logging level.


Field Summary
private  JComboBox comboBox
          JComboBox that will eventually contain logging levels to select.
private  String currentChoice
          String representation of the user's selection, or the default value provided to the constructor.
private static String DEBUG
          String representation of Logback's "DEBUG" logging level.
private static String ERROR
          String representation of Logback's "ERROR" logging level.
private static String INFO
          String representation of Logback's "INFO" logging level.
private static String OFF
          String representation of Logback's "OFF" logging level.
private static String TRACE
          String representation of Logback's "TRACE" logging level.
private static String WARN
          String representation of Logback's "WARN" logging level.
 
Constructor Summary
LoggerLevelOption(String id, String label, String defaultValue, OptionMaster.OptionPlatform optionPlatform, OptionMaster.Visibility optionVisibility)
          Create a startup option that allows the user to manipulate the global McIDAS-V logging level.
 
Method Summary
 JComboBox getComponent()
          Builds a JComboBox containing the logging levels to select.
 String getValue()
          Returns the user's current selection (or the default value).
private static boolean isValidValue(String value)
          Tests a String value to see if it has a corresponding logging level.
 void setValue(String value)
          Stores the user's selected logging level.
private static ch.qos.logback.classic.Level stringToLogback(String value)
          Converts a String value to the corresponding logging level.
 String toString()
          String representation of the user's logging level selection.
 
Methods inherited from class edu.wisc.ssec.mcidasv.startupmanager.options.AbstractOption
fromPrefsFormat, getLabel, getOptionId, getOptionPlatform, getOptionType, getOptionVisibility, onValidPlatform, toPrefsFormat
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TRACE

private static final String TRACE
String representation of Logback's "TRACE" logging level.


DEBUG

private static final String DEBUG
String representation of Logback's "DEBUG" logging level.


INFO

private static final String INFO
String representation of Logback's "INFO" logging level.


WARN

private static final String WARN
String representation of Logback's "WARN" logging level.


ERROR

private static final String ERROR
String representation of Logback's "ERROR" logging level.


OFF

private static final String OFF
String representation of Logback's "OFF" logging level.


comboBox

private JComboBox comboBox
JComboBox that will eventually contain logging levels to select. May be null.


currentChoice

private String currentChoice
String representation of the user's selection, or the default value provided to the constructor.

Constructor Detail

LoggerLevelOption

public LoggerLevelOption(String id,
                         String label,
                         String defaultValue,
                         OptionMaster.OptionPlatform optionPlatform,
                         OptionMaster.Visibility optionVisibility)
Create a startup option that allows the user to manipulate the global McIDAS-V logging level. NOTE: null is not a permitted value for any of this constructor's parameters.

Parameters:
id - Identifier for this startup option.
label - Brief description suitable for a GUI label.
defaultValue - Default value for this startup option.
optionPlatform - Platforms where this option may be applied.
optionVisibility - Whether or not the option is presented via the GUI.
Throws:
IllegalArgumentException - if defaultValue failed isValidValue(String).
Method Detail

getComponent

public JComboBox getComponent()
Builds a JComboBox containing the logging levels to select. Defaults to the String specified in the constructor.

Specified by:
getComponent in interface Option
Specified by:
getComponent in class AbstractOption
Returns:
JComboBox to present to the user.

getValue

public String getValue()
Returns the user's current selection (or the default value).

Specified by:
getValue in interface Option
Specified by:
getValue in class AbstractOption
Returns:
Current selection or default value.

setValue

public void setValue(String value)
Stores the user's selected logging level. Note that this can be called from third-party or the GUI! If the call originates from the GUI, an infinite loop is avoided by using the JComboBox.setSelectedItem(Object) behavior that does not generate ItemEvents if the selection did not actually change.

Specified by:
setValue in interface Option
Specified by:
setValue in class AbstractOption
Parameters:
value - String representation of the desired logging level. Should not be null.
Throws:
IllegalArgumentException - if value failed isValidValue(String).

stringToLogback

private static ch.qos.logback.classic.Level stringToLogback(String value)
Converts a String value to the corresponding logging level.

This functionality is similar to Level.toLevel(String, Level), but for this use case it is preferable to know if an invalid value was provided.

Parameters:
value - Value to convert.
Returns:
Logging level.
Throws:
IllegalArgumentException - if value did not have a corresponding logging level.

isValidValue

private static boolean isValidValue(String value)
Tests a String value to see if it has a corresponding logging level.

Parameters:
value - Value to test.
Returns:
true if-and-only-if passes a String.equalsIgnoreCase(String) check against TRACE, DEBUG, INFO, WARN, ERROR, or OFF.

toString

public String toString()
String representation of the user's logging level selection.

Specified by:
toString in interface Option
Specified by:
toString in class AbstractOption
Returns:
String that looks something like "[LoggerLevel@7825114a: currentChoice=INFO]".
See Also:
TextOption.toString(), BooleanOption.toString()