hps-java/src/main/java/org/lcsim/hps/monitoring
diff -u -r1.47 -r1.48
--- MonitoringApplication.java 12 May 2012 23:09:05 -0000 1.47
+++ MonitoringApplication.java 17 May 2012 00:18:39 -0000 1.48
@@ -78,6 +78,8 @@
private JobPanel jobPanel;
private JMenuBar menuBar;
private EventButtonsPanel buttonsPanel;
+ private JFrame frame;
+
// References to menu items that will be enabled/disabled depending on application state.
private JMenuItem connectItem;
private JMenuItem disconnectItem;
@@ -93,41 +95,54 @@
private JMenuItem saveJobSettingsItem;
private JMenuItem loadJobSettingsItem;
private JMenuItem resetJobSettingsItem;
+
// Saved references to System.out and System.err in case need to reset.
private final PrintStream sysOut = System.out;
private final PrintStream sysErr = System.err;
+
// ET connection parameters and state.
private ConnectionParameters connectionParameters;
private EtConnection connection;
private int connectionStatus = ConnectionStatus.DISCONNECTED;
+
// Event processing objects.
private JobControlManager jobManager;
private LCSimEventBuilder eventBuilder;
private EtEventProcessor eventProcessor;
private Thread eventProcessingThread;
private HPSCalibrationListener calibListener;
+
// Job timing.
private Timer timer;
private long jobStartTime;
+
// ActionListener for GUI event dispatching.
private ActionListener actionListener;
+
// Logging objects.
private static Logger logger;
private Handler logHandler;
private DefaultTableModel logTableModel;
private JTable logTable;
+ private Level defaultLogMessageLevel = Level.INFO;
+
// Some default GUI size parameters.
private final int logTableWidth = 700;
private final int logTableHeight = 320;
+
// Format for screenshots. Hard-coded to PNG.
private static final String screenshotFormat = "png";
+
// The AIDA remote server.
private AIDAServer server;
+
// Listener for processing EtEvents.
private EtEventListener etListener = new MonitoringApplicationEtListener();
+
// Maximum time in millis to wait for the ET system to disconnect.
// TODO: Make this an option in the JobPanel.
private int maxCleanupTime = 5000;
+
// Format of date field for log.
private final SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM-dd-yyyy HH:mm:ss.SSS");
private static final String LCSIM_FAIL_MESSAGE = "Failed to setup LCSim.";
@@ -144,6 +159,8 @@
// Create the ActionEventListener for event dispatching.
actionListener = new MonitoringApplicationActionListener();
+ // Add a listener to hook into ET system and load correct
+ // calibrations based on time.
calibListener = new HPSCalibrationListener();
// Setup the application menus.
@@ -156,7 +173,7 @@
createLogTable();
// Log that the application started successfully.
- logger.log(Level.INFO, "Application initialized successfully.");
+ log("Application initialized successfully.");
}
/**
@@ -454,7 +471,6 @@
private static final MonitoringApplication createMonitoringApplication() {
final MonitoringApplication app = new MonitoringApplication();
SwingUtilities.invokeLater(new Runnable() {
-
public void run() {
app.createApplicationFrame();
}
@@ -525,14 +541,14 @@
/**
* The ActionListener implementation for handling all GUI events.
*/
- private final class MonitoringApplicationActionListener implements ActionListener {
+ private class MonitoringApplicationActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
if (cmd != MonitoringCommands.updateTimeCmd) {
// Log actions performed. Catch errors in case logging is not initialized yet.
try {
- logger.log(Level.FINEST, "Action performed <" + cmd + ">.");
+ log(Level.FINEST, "Action performed <" + cmd + ">.");
} catch (Exception xx) {
}
}
@@ -613,10 +629,10 @@
JobSettings settings = jobPanel.getJobSettings();
try {
settings.save(f);
- logger.log(Level.INFO, "Saved Job Settings to properties file <" + f.getPath() + ">.");
+ log(Level.INFO, "Saved Job Settings to properties file <" + f.getPath() + ">.");
} catch (IOException e) {
e.printStackTrace();
- logger.log(Level.SEVERE, "Error saving Job Settings to properties file <" + f.getPath() + ">.");
+ log(Level.SEVERE, "Error saving Job Settings to properties file <" + f.getPath() + ">.");
showDialog("Error saving Job Settings to properties file.");
}
}
@@ -630,10 +646,10 @@
File f = fc.getSelectedFile();
try {
jobPanel.setJobSettings(new JobSettings(f));
- logger.log(Level.INFO, "Loaded Job Settings from properties file <" + f.getPath() + ">.");
+ log(Level.INFO, "Loaded Job Settings from properties file <" + f.getPath() + ">.");
} catch (IOException e) {
e.printStackTrace();
- logger.log(Level.SEVERE, "Error loading Job Settings from properties file <" + f.getPath() + ">.");
+ log(Level.SEVERE, "Error loading Job Settings from properties file <" + f.getPath() + ">.");
showDialog("Error loading Job Settings from properties file.");
}
}
@@ -660,7 +676,7 @@
Thread t = new Thread(r, "Session Thread");
t.start();
} else {
- logger.log(Level.SEVERE, "Ignoring connection request. Already connected!");
+ log(Level.SEVERE, "Ignoring connection request. Already connected!");
}
}
@@ -674,13 +690,61 @@
if (eventProcessor != null) {
eventProcessor.setLogLevel(newLevel);
}
- logger.log(Level.INFO, "Log Level was changed to <" + jobPanel.getLogLevel().toString() + ">.");
+
+ log("Log Level was changed to <" + jobPanel.getLogLevel().toString() + ">.");
}
+
+ /*
+ private class DisconnectDialog extends JDialog {
+
+ static final String cmd = "done";
+ volatile boolean done = false;
+
+ DisconnectDialog() {
+ super((JFrame)null, "Disconnecting");
+ setLayout(new GridBagLayout());
+ GridBagConstraints c = new GridBagConstraints();
+ c.gridx = 0;
+ c.gridy = 0;
+ c.fill = GridBagConstraints.NONE;
+ getContentPane().add(new JLabel("You are about to be disconnected."), c);
+ JButton b = new JButton("Ok");
+ b.setActionCommand(cmd);
+ b.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent evt) {
+ if (evt.getActionCommand().equals(cmd)) {
+ done = true;
+ dispose();
+ }
+ }
+ });
+ c = new GridBagConstraints();
+ c.gridx = 0;
+ c.gridy = 1;
+ c.fill = GridBagConstraints.NONE;
+ getContentPane().add(b, c);
+ pack();
+ setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
+ setModal(false);
+ //setMinimumSize(new Dimension(100, 100));
+ setResizable(false);
+ setLocationRelativeTo(null);
+ setVisible(true);
+ toFront();
+ }
+
+ void waitForConfirm() {
+ while (!done) {
+ }
+ return;
+ }
+ }
+ */
/**
* The listener for hooking into the event processor.
*/
- private final class MonitoringApplicationEtListener implements EtEventListener {
+ private class MonitoringApplicationEtListener implements EtEventListener {
/**
* Beginning of job.
@@ -717,7 +781,7 @@
public void errorOnEvent() {
eventPanel.updateBadEventCount();
}
-
+
/**
* End of job.
*/
@@ -726,19 +790,23 @@
// Show a warning dialog box before disconnecting, if this option is selected.
// This needs to go here rather than in disconnect() so that the LCSim plots stay up.
if (warnOnDisconnect()) {
- logger.log(Level.FINEST, "Waiting for user to verify disconnect request.");
- showDialog("You are about to be disconnected.");
+ log(Level.FINEST, "Waiting for user to verify disconnect request.");
+ showDialog("You are about to be disconnected.");
+ //DisconnectDialog d = new DisconnectDialog();
+ //d.waitForConfirm();
}
try {
// Save final AIDA file if option is selected.
if (jobPanel.isAidaAutoSaveEnabled()) {
+ log(Level.INFO, "Auto saving AIDA file <" + jobPanel.getAidaAutoSaveFileName() + ">.");
AIDA.defaultInstance().saveAs(jobPanel.getAidaAutoSaveFileName());
}
// Call cleanup methods of Drivers.
try {
+ log(Level.INFO, "Cleaning up LCSim.");
if (jobManager != null) {
jobManager.finish();
}
@@ -748,6 +816,7 @@
}
// Stop the job timer.
+ log(Level.INFO, "Stopping the job timer.");
timer.stop();
timer = null;
@@ -756,14 +825,14 @@
// Disconnect from remote AIDA session if active.
if (server != null) {
- logger.log(Level.CONFIG, "Closing remote AIDA server.");
+ log(Level.CONFIG, "Closing remote AIDA server.");
server.close();
- server = null;
- logger.log(Level.CONFIG, "Remote AIDA server was closed.");
+ server = null;
+ log(Level.CONFIG, "Remote AIDA server was closed.");
}
} catch (Exception e) {
e.printStackTrace();
- logger.log(Level.WARNING, "Error in finish() method <" + e.getMessage() + ">.");
+ log(Level.WARNING, "Error cleaning up job <" + e.getMessage() + ">.");
}
}
@@ -774,8 +843,8 @@
final long millis = ((long) seconds) * 1000;
eventPanel.setRunNumber(runNumber);
eventPanel.setRunStartTime(millis);
- logger.log(Level.INFO, "Set run number <" + runNumber + "> from Pre Start.");
- logger.log(Level.INFO, "Pre Start time <" + EventPanel.dateFormat.format(new Date(millis)) + ">.");
+ log(Level.INFO, "Set run number <" + runNumber + "> from Pre Start.");
+ log(Level.INFO, "Pre Start time <" + EventPanel.dateFormat.format(new Date(millis)) + ">.");
}
/**
@@ -785,8 +854,8 @@
final long millis = ((long) seconds) * 1000;
eventPanel.setRunEndTime(millis);
eventPanel.setRunEventCount(events);
- logger.log(Level.INFO, "Set number of events in run to <" + events + ">.");
- logger.log(Level.INFO, "End Event time <" + EventPanel.dateFormat.format(new Date(millis)) + ">.");
+ log(Level.INFO, "Set number of events in run to <" + events + ">.");
+ log(Level.INFO, "End Event time <" + EventPanel.dateFormat.format(new Date(millis)) + ">.");
}
}
@@ -798,7 +867,7 @@
private void setConnectionStatus(int status) {
connectionStatus = status;
connectionStatusPanel.setStatus(status);
- logger.log(Level.CONFIG, "Connection status changed to <" + ConnectionStatus.toString(status) + ">.");
+ log("Connection status changed to <" + ConnectionStatus.toString(status) + ">.");
logHandler.flush();
}
@@ -821,12 +890,11 @@
}
/**
- * Setup the frame to run the application. This should be called using
- * Runnable.run() (see MonitoringExample).
+ * Setup the frame to run the application.
*/
private void createApplicationFrame() {
mainPanel.setOpaque(true);
- JFrame frame = new JFrame(getApplicationTitle());
+ frame = new JFrame(getApplicationTitle());
frame.setContentPane(mainPanel);
frame.setJMenuBar(menuBar);
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
@@ -865,10 +933,10 @@
(new JobControlManager()).setup(fileName);
jobPanel.setSteeringFile(fileName.getPath());
jobPanel.setSteeringType(JobPanel.FILE);
- logger.log(Level.INFO, "Steering file set to <" + fileName.getPath() + ">.");
+ log("Steering file set to <" + fileName.getPath() + ">.");
} catch (Exception e) {
e.printStackTrace();
- logger.log(Level.SEVERE, "Failed to read steering file <" + fileName.getPath() + ">.");
+ log(Level.SEVERE, "Failed to read steering file <" + fileName.getPath() + ">.");
showDialog("Failed to read the LCSim XML file.");
}
}
@@ -926,7 +994,7 @@
}
}
}
- logger.log(Level.INFO, "LCSim drivers were reset.");
+ log(Level.INFO, "LCSim drivers were reset.");
}
/**
@@ -961,9 +1029,9 @@
}
});
- logger.log(Level.INFO, "Redirected System output to file <" + logFile.getPath() + ">.");
+ log("Redirected System output to file <" + logFile.getPath() + ">.");
} catch (IOException e) {
- logger.log(Level.SEVERE, "Error redirecting System output to file <" + logFile.getPath() + ">.");
+ log(Level.SEVERE, "Error redirecting System output to file <" + logFile.getPath() + ">.");
showDialog("Error redirecting System output to log file.");
}
}
@@ -993,7 +1061,7 @@
logItem.setEnabled(true);
}
});
- logger.log(Level.INFO, "Redirected print output to terminal.");
+ log("Redirected print output to terminal.");
}
/**
@@ -1007,9 +1075,9 @@
throw new RuntimeException("Event Refresh must be > 0.");
}
eventPanel.setEventRefresh(newEventRefresh);
- logger.log(Level.INFO, "Event refresh set to <" + newEventRefresh + ">.");
+ log("Event refresh set to <" + newEventRefresh + ">.");
} catch (Exception e) {
- logger.log(Level.WARNING, "Ignored invalid event refresh setting.");
+ log(Level.WARNING, "Ignored invalid event refresh setting.");
showDialog("The value " + inputValue + " is not valid for Event Refresh Rate.");
}
}
@@ -1032,9 +1100,9 @@
if (eventProcessor != null) {
eventProcessor.setMaxEvents(newMaxEvents);
}
- logger.log(Level.INFO, "Max events set to <" + newMaxEvents + ">.");
+ log("Max events set to <" + newMaxEvents + ">.");
} catch (Exception e) {
- logger.log(Level.WARNING, "Ignored invalid max events setting <" + inputValue + ">.");
+ log(Level.WARNING, "Ignored invalid max events setting <" + inputValue + ">.");
showDialog("The value " + inputValue + " is not valid for Max Events.");
}
}
@@ -1125,7 +1193,7 @@
fileName = fileName + "." + screenshotFormat;
}
takeScreenshot(fileName);
- logger.log(Level.INFO, "Screenshot saved to <" + fileName + ">.");
+ log("Screenshot saved to <" + fileName + ">.");
}
}
@@ -1181,7 +1249,7 @@
*/
private void session() {
- logger.log(Level.INFO, "Starting a new monitoring session.");
+ log("Starting a new monitoring session.");
int endStatus = ConnectionStatus.DISCONNECTING;
@@ -1206,11 +1274,11 @@
eventProcessingThread.join();
} catch (InterruptedException e) {
}
- logger.log(Level.INFO, "Event processor finished with status <" + ConnectionStatus.toString(eventProcessor.getStatus()) + ">.");
+ log("Event processor finished with status <" + ConnectionStatus.toString(eventProcessor.getStatus()) + ">.");
endStatus = eventProcessor.getStatus();
} catch (Exception e) {
e.printStackTrace();
- logger.log(Level.SEVERE, "Fatal error in monitoring session.");
+ log(Level.SEVERE, "Fatal error in monitoring session.");
endStatus = ConnectionStatus.ERROR;
} finally {
logHandler.flush();
@@ -1220,7 +1288,7 @@
}
}
- logger.log(Level.INFO, "Finished monitoring session.");
+ log("Finished monitoring session.");
}
/**
@@ -1228,14 +1296,14 @@
*/
private void setupRemoteAida() {
if (jobPanel.isAidaServerEnabled()) {
- logger.log(Level.INFO, "Starting remote AIDA server.");
+ log("Starting remote AIDA server.");
this.server = new AIDAServer(jobPanel.getRemoteAidaName());
boolean ok = this.server.start();
if (ok) {
- logger.log(Level.INFO, "Remote AIDA server started with name <" + jobPanel.getRemoteAidaName() + ">.");
+ log("Remote AIDA server started with name <" + jobPanel.getRemoteAidaName() + ">.");
} else {
this.server = null;
- logger.log(Level.SEVERE, "Failed to start remote AIDA server.");
+ log(Level.SEVERE, "Failed to start remote AIDA server.");
}
}
}
@@ -1271,7 +1339,7 @@
// Start the event processing thread.
eventProcessingThread.start();
- logger.log(Level.FINEST, "Started event processing thread.");
+ log(Level.FINEST, "Started event processing thread.");
logHandler.flush();
}
@@ -1281,7 +1349,7 @@
*/
private void connect() {
- logger.log(Level.INFO, "Connecting to ET system.");
+ log("Connecting to ET system.");
setConnectionStatus(ConnectionStatus.CONNECTION_REQUESTED);
@@ -1291,7 +1359,7 @@
// Create a connection to the ET server.
createEtConnection();
- logger.log(Level.INFO, "Successfully connected to ET system.");
+ log("Successfully connected to ET system.");
}
/**
@@ -1328,7 +1396,7 @@
* @return True if warning will occur before disconnect; false if no.
*/
private boolean warnOnDisconnect() {
- return jobPanel.warnBeforeDisconnect();
+ return jobPanel.warnOnDisconnect();
}
/**
@@ -1351,23 +1419,23 @@
*/
synchronized private void disconnect(int status) {
- logger.log(Level.CONFIG, "Disconnecting from ET system with status <" + ConnectionStatus.toString(status) + ">.");
+ log("Disconnecting from ET system with status <" + ConnectionStatus.toString(status) + ">.");
// Check if disconnected already.
if (getConnectionStatus() == ConnectionStatus.DISCONNECTED) {
- logger.log(Level.WARNING, "ET system is already disconnected.");
+ log(Level.WARNING, "ET system is already disconnected.");
return;
}
// Check if in the process of disconnecting.
if (getConnectionStatus() == ConnectionStatus.DISCONNECTING) {
- logger.log(Level.WARNING, "ET system is already disconnecting.");
+ log(Level.WARNING, "ET system is already disconnecting.");
return;
}
// Stop event processing if currently connected.
if (eventProcessor != null) {
- logger.log(Level.FINE, "Stopping the event processor.");
+ log(Level.FINE, "Stopping the event processor.");
eventProcessor.stop();
}
@@ -1383,7 +1451,7 @@
// Finally, change application state to fully disconnected.
setConnectionStatus(ConnectionStatus.DISCONNECTED);
- logger.log(Level.CONFIG, "Disconnected from ET system.");
+ log("Disconnected from ET system.");
}
/**
@@ -1392,7 +1460,7 @@
* forever. So we need to be able to kill it after waiting for X amount of
* time.
*/
- class EtCleanupThread extends Thread {
+ private class EtCleanupThread extends Thread {
boolean succeeded;
@@ -1424,7 +1492,7 @@
// Put cleanup on a separate thread in case it hangs forever.
EtCleanupThread cleanupThread = new EtCleanupThread();
- logger.log(Level.FINEST, "Starting EtCleanupThread to disconnect from ET system.");
+ log(Level.FINEST, "Starting EtCleanupThread to disconnect from ET system.");
logHandler.flush();
cleanupThread.start();
try {
@@ -1434,16 +1502,16 @@
}
if (cleanupThread.succeeded()) {
- logger.log(Level.INFO, "EtCleanupThread succeeded in disconnecting from ET system.");
+ log("EtCleanupThread succeeded in disconnecting from ET system.");
} else {
- logger.log(Level.SEVERE, "EtCleanupThread failed to disconnect. Your station <" + this.connection.stat.getName() + "> is zombified.");
+ log(Level.SEVERE, "EtCleanupThread failed to disconnect. Your station <" + this.connection.stat.getName() + "> is zombified.");
// Make the cleanup thread yield.
cleanupThread.stopCleanup();
// Stop the cleanup thread.
cleanupThread.stop();
// Join to cleanup thread until it dies.
- logger.log(Level.FINEST, "Waiting for EtCleanupThread to die");
- logger.log(Level.FINEST, "EtCleanupThread was killed.");
+ log(Level.FINEST, "Waiting for EtCleanupThread to die");
+ log(Level.FINEST, "EtCleanupThread was killed.");
// The ET connection is now unusable so set it to null.
this.connection = null;
}
@@ -1455,7 +1523,7 @@
*/
private void setupLCSim() {
- logger.log(Level.CONFIG, "Setting up LCSim.");
+ log("Setting up LCSim.");
// Clear the static AIDA tree in case plots are hanging around from previous sessions.
resetAidaTree();
@@ -1463,11 +1531,11 @@
// Get steering resource or file as a String parameter.
String steering = getSteering();
int steeringType = jobPanel.getSteeringType();
- logger.log(Level.FINE, "LCSim using steering <" + steering + "> of type <" + (steeringType == JobPanel.RESOURCE ? "RESOURCE" : "FILE") + ">.");
+ log(Level.FINE, "LCSim using steering <" + steering + "> of type <" + (steeringType == JobPanel.RESOURCE ? "RESOURCE" : "FILE") + ">.");
// Check if the LCSim steering file looks valid.
if (jobPanel.checkSteering() == false) {
- logger.log(Level.SEVERE, "Steering file or resource <" + steering + "> is not valid.");
+ log(Level.SEVERE, "Steering file or resource <" + steering + "> is not valid.");
throw new RuntimeException("Invalid steering file or resource < " + steering + ">.");
}
@@ -1476,12 +1544,12 @@
jobManager = new JobControlManager();
jobManager.setPerformDryRun(true);
if (steeringType == JobPanel.RESOURCE) {
- logger.log(Level.FINE, "Setting up steering resource <" + steering + ">.");
+ log(Level.FINE, "Setting up steering resource <" + steering + ">.");
InputStream is = this.getClass().getClassLoader().getResourceAsStream(steering);
jobManager.setup(is);
is.close();
} else if (getSteeringType() == JobPanel.FILE) {
- logger.log(Level.FINE, "Setting up steering file <" + steering + ">.");
+ log(Level.FINE, "Setting up steering file <" + steering + ">.");
jobManager.setup(new File(steering));
}
@@ -1490,11 +1558,11 @@
} // Catch all other setup exceptions and re-throw them as RuntimeExceptions.
catch (Exception e) {
e.printStackTrace();
- logger.log(Level.SEVERE, LCSIM_FAIL_MESSAGE);
+ log(Level.SEVERE, LCSIM_FAIL_MESSAGE);
throw new RuntimeException(LCSIM_FAIL_MESSAGE, e);
}
- logger.log(Level.CONFIG, "LCSim setup was successful.");
+ log(Level.CONFIG, "LCSim setup was successful.");
}
/**
@@ -1505,7 +1573,7 @@
// Setup the EventBuilder class.
String eventBuilderClassName = getEventBuilderClassName();
- logger.log(Level.CONFIG, "Initializing event builder <" + eventBuilderClassName + ">.");
+ log("Initializing event builder <" + eventBuilderClassName + ">.");
try {
eventBuilder = (LCSimEventBuilder) Class.forName(eventBuilderClassName).newInstance();
@@ -1516,7 +1584,7 @@
// Set the detector name on the event builder so it can find conditions data.
eventBuilder.setDetectorName(getDetectorName());
- logger.log(Level.CONFIG, "Successfully initialized event builder <" + eventBuilderClassName + ">.");
+ log("Successfully initialized event builder <" + eventBuilderClassName + ">.");
}
/**
@@ -1551,11 +1619,11 @@
// Set status to connected as there is now a live ET connection.
setConnectionStatus(ConnectionStatus.CONNECTED);
- logger.log(Level.CONFIG, "Created ET connection to <" + connectionParameters.etName + ">.");
+ log("Created ET connection to <" + connectionParameters.etName + ">.");
} else {
// An error occurred.
setConnectionStatus(ConnectionStatus.ERROR);
- logger.log(Level.SEVERE, "Failed to create ET connection to <" + connectionParameters.etName + ">.");
+ log(Level.SEVERE, "Failed to create ET connection to <" + connectionParameters.etName + ">.");
throw new RuntimeException("Failed to create ET connection.");
}
}
@@ -1568,7 +1636,7 @@
timer.setActionCommand(updateTimeCmd);
jobStartTime = System.currentTimeMillis();
timer.start();
- logger.log(Level.FINE, "Job timer started.");
+ log(Level.FINE, "Job timer started.");
}
/**
@@ -1591,7 +1659,7 @@
}
// Reset event processor.
eventProcessor.resetNumberOfEventsProcessed();
- logger.log(Level.FINE, "Job was reset.");
+ log(Level.FINE, "Job was reset.");
}
/**
@@ -1617,9 +1685,9 @@
BufferedWriter out = new BufferedWriter(new FileWriter(logFile.getPath()));
out.write(buf.toString());
out.close();
- logger.log(Level.FINE, "Saved log to file <" + logFile.getPath() + ">.");
+ log("Saved log to file <" + logFile.getPath() + ">.");
} catch (IOException e) {
- logger.log(Level.SEVERE, "Failed to save log to file <" + logFile.getPath() + ">.");
+ log(Level.SEVERE, "Failed to save log to file <" + logFile.getPath() + ">.");
showDialog("Failed to save log file.");
}
}
@@ -1631,7 +1699,7 @@
*/
private void clearLog() {
logTableModel.setRowCount(0);
- logger.log(Level.INFO, "Log was cleared.");
+ log("Log was cleared.");
}
/**
@@ -1649,10 +1717,10 @@
*/
private void next() {
if (connectionStatus == ConnectionStatus.CONNECTED) {
- logger.log(Level.FINE, "Notifying event processor to get next events.");
+ log(Level.FINE, "Notifying event processor to get next events.");
eventProcessor.nextEvents();
} else {
- logger.log(Level.WARNING, "Ignored next events command because app is disconnected.");
+ log(Level.WARNING, "Ignored next events command because app is disconnected.");
}
}
@@ -1672,7 +1740,7 @@
// Toggle job panel setting.
jobPanel.enablePauseMode(false);
- logger.log(Level.FINEST, "Disabled pause mode and will now process in real-time.");
+ log(Level.FINEST, "Disabled pause mode and will now process in real-time.");
}
}
@@ -1685,7 +1753,7 @@
eventProcessor.pauseMode(true);
buttonsPanel.setPauseModeState(true);
jobPanel.enablePauseMode(false);
- logger.log(Level.FINEST, "Enabled pause mode.");
+ log(Level.FINEST, "Enabled pause mode.");
}
}
@@ -1694,6 +1762,24 @@
*/
private void resetAidaTree() {
AIDA.defaultInstance().clearAll();
- logger.log(Level.FINEST, "Reset default AIDA tree.");
+ log("Reset default AIDA tree.");
+ }
+
+ /**
+ * Send a message to the logger with given level.
+ * @param level The log message's level.
+ * @param m The message.
+ */
+ private void log(Level level, String m) {
+ if (logger != null && logTable != null)
+ logger.log(level, m);
+ }
+
+ /**
+ * Send a message to the logger with the default level.
+ * @param m The message.
+ */
+ private void log(String m) {
+ log(defaultLogMessageLevel, m);
}
}
\ No newline at end of file