* Refresh the log.
*/
private void refreshLog()
{
enableComponents(false);
final CursorChanger cursorChg = new CursorChanger(getAwtContainer());
cursorChg.show();
try
{
try
{
SwingUtilities.invokeAndWait(new Runnable()
{
public void run()
{
_logContentsTxt.setText("");
}
});
}
catch (final Exception ex)
{
// i18n[ViewLogsSheet.error.clearlogcontents=Error clearing the log contents]
s_log.error(s_stringMgr.getString("ViewLogsSheet.error.clearlogcontents"), ex);
}
final File logFile = (File) _logDirCmb.getSelectedItem();
if (logFile != null)
{
try
{
if (logFile.exists() && logFile.canRead())
{
final BufferedReader rdr = new BufferedReader(new FileReader(logFile));
try
{
String line = null;
StringBuilder chunk = new StringBuilder(16384);
while ((line = rdr.readLine()) != null)
{
if (_closing) { return; }
if (chunk.length() > 16000)
{
final String finalLine = chunk.toString();
SwingUtilities.invokeAndWait(new Runnable()
{
public void run()
{
if (!_closing)
{
_logContentsTxt.append(finalLine);
}
}
});
chunk = new StringBuilder(16384);
}
else
{
if (shouldAppendLineToChunk(line))
{
chunk.append(line).append('\n');
}
}
}
if (_closing) { return; }
final String finalLine = chunk.toString();
SwingUtilities.invokeAndWait(new Runnable()
{
public void run()
{
if (!_closing)
{
_logContentsTxt.append(finalLine);
}
}
});
}
finally
{
rdr.close();
}
}
}
catch (final Exception ex)
{
// i18n[ViewLogsSheet.error.processinglogfile=Error occured processing log file]
final String msg = s_stringMgr.getString("ViewLogsSheet.error.processinglogfile");
s_log.error(msg, ex);
}
}
else
{
if (s_log.isDebugEnabled()) {
// i18n[ViewLogsSheet.info.nulllogfile=Null log file name]
s_log.debug(s_stringMgr.getString("ViewLogsSheet.info.nulllogfile"));
}
}
if (_closing) { return; }
// Position to the start of the last line in log.
try
{
final int pos = Math.max(0, _logContentsTxt.getText().length() - 1);
final int line = _logContentsTxt.getLineOfOffset(pos);
final int finalpos = _logContentsTxt.getLineStartOffset(line);
SwingUtilities.invokeAndWait(new Runnable()
{
public void run()
{
_logContentsTxt.setCaretPosition(finalpos);
}
});
}
catch (final Exception ex)
{
// i18n[ViewLogsSheet.error.setcaret=Error positioning caret in log text component]
s_log.error(s_stringMgr.getString("ViewLogsSheet.error.setcaret"), ex);
}
}
finally
{
enableComponents(true);
_refreshing = false;
cursorChg.restore();
}
}