/* nixonFTP
* FTP client version 0.1
* Copyright (C) 2010 NIXON Development Corporation.
* All rights reserved.
* http://members.shaw.ca/nixon.com
*/
package nixonftp.ui;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Vector;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.JToggleButton;
import javax.swing.JViewport;
import javax.swing.text.BadLocationException;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
import javax.swing.text.StyledDocument;
/**
*
* @author Billy
*/
public class NXLogPanel extends JPanel {
private JTextPane a;
private JScrollPane spa;
private int initialLeft;
public NXLogPanel() {
super();
setLayout(new BorderLayout());
setUp();
}
public void setUp() {
a = new JTextPane();
//a.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
addStyles(a.getStyledDocument());
a.setEditable(false);
a.setBackground(Color.WHITE);
a.setOpaque(true);
spa = new JScrollPane(a);
add(spa);
//add(spb);
spa.setBorder(null);
}
private void addStyles(StyledDocument doc) {
Style def = StyleContext.getDefaultStyleContext().
getStyle(StyleContext.DEFAULT_STYLE);
Style command = doc.addStyle("command", def);
StyleConstants.setFontFamily(def, "SansSerif");
StyleConstants.setForeground(command, Color.BLACK);
//responses
Style regular = doc.addStyle("regular", command);
StyleConstants.setForeground(regular, Color.GRAY);
Style s = doc.addStyle("tryagain", command);
StyleConstants.setForeground(s, Color.ORANGE);
s = doc.addStyle("pending", command);
StyleConstants.setForeground(s, new Color(51, 102, 153));
s = doc.addStyle("error", command);
StyleConstants.setForeground(s, Color.RED);
s = doc.addStyle("done", command);
StyleConstants.setForeground(s, new Color(0, 153, 0));
}
public JTextPane getLog() {
return a;
}
public void displayText(Vector<String> s) {
if (s == null) {
a.setText("");
return;
}
Object[] lines = s.toArray();
String line;
boolean eraseControl = false;
try {
for (int x = 0; x < lines.length; x++) {
line = (String) lines[x];
appendText(line);
}
} catch (Exception e) {
}
setUp();
}
public void appendText(String text) {
String style;
boolean eraseControl;
StyledDocument doc = a.getStyledDocument();
if (text.startsWith("\u3000")) {
style = "error";
eraseControl = true;
} else if (text.startsWith("\u3001")) {
style = "tryagain";
eraseControl = true;
} else if (text.startsWith("\u3002")) {
style = "pending";
eraseControl = true;
} else if (text.startsWith("\u3003")) {
style = "done";
eraseControl = true;
} else if (text.startsWith("\u3004")) {
style = "regular";
eraseControl = true;
} else {
style = "";
eraseControl = false;
}
if (eraseControl) {
text = text.substring(1);
}
try {
doc.insertString(doc.getLength(), text + '\n', doc.getStyle(style));
} catch (BadLocationException ex) {
}
}
}