package org.salamanca.ui;
import java.awt.BorderLayout;
import javax.swing.*;
import javax.swing.JScrollPane;
import javax.swing.BorderFactory;
import javax.swing.JTextPane;
import java.util.logging.Logger;
import javax.swing.text.StyledDocument;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import java.awt.Color;
import javax.swing.text.*;
import java.io.*;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class LogFrame extends JFrame {
private static String lineSeparator = System.getProperty("line.separator");
BorderLayout borderLayout1 = new BorderLayout();
JScrollPane jScrollPane1 = new JScrollPane();
JTextPane jTextPane1 = new JTextPane();
public LogFrame() {
try {
jbInit();
load();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(borderLayout1);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
jScrollPane1.getViewport().add(jTextPane1);
jScrollPane1.setBorder(BorderFactory.createEtchedBorder());
}
private void load() {
// Get the text pane's document
StyledDocument doc = (StyledDocument) jTextPane1.getDocument();
// Create a style object and then set the style attributes
Style style = doc.addStyle("StyleName", null);
// Italic
StyleConstants.setItalic(style, true);
// Bold
StyleConstants.setBold(style, false);
// Font family
StyleConstants.setFontFamily(style, "SansSerif");
// Font size
StyleConstants.setFontSize(style, 11);
// Background color
StyleConstants.setBackground(style, Color.white);
// Foreground color
StyleConstants.setForeground(style, Color.BLACK);
// Append to document
try {
BufferedReader in = new BufferedReader(new FileReader(org.salamanca.
commands.CommandLogger.getLogFilePath()));
String str;
while ((str = in.readLine()) != null) {
doc.insertString(doc.getLength(), str+lineSeparator, style);
}
in.close();
} catch (IOException e) {
} catch (BadLocationException ex) {
/** @todo Handle this exception */
}
}
}