ソースを参照

Console boys, not in the viewport yet

Kevin Trometer 7 年 前
コミット
37e07da582
1 ファイル変更55 行追加0 行削除
  1. 55 0
      src/ui/view/Console.java

+ 55 - 0
src/ui/view/Console.java

@@ -0,0 +1,55 @@
+package ui.view;
+import java.awt.Color;
+
+import javax.swing.JScrollPane;
+
+import java.awt.BorderLayout;
+import javax.swing.JTextPane;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Style;
+import javax.swing.text.StyleConstants;
+import javax.swing.text.StyledDocument;
+import javax.swing.JPanel;
+
+public class Console extends JScrollPane {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+	private final JTextPane consoleText = new JTextPane();
+	private final JPanel panel = new JPanel();
+	private Style style;
+	private StyledDocument doc;
+
+	public Console() {
+		super();
+		this.setBackground(Color.WHITE);
+		consoleText.setForeground(Color.BLACK);
+		consoleText.setEditable(false);
+
+		doc = consoleText.getStyledDocument();
+
+		style = consoleText.addStyle("I'm a Style", null);
+
+		this.setViewportView(panel);
+		panel.setLayout(new BorderLayout(0, 0));
+		panel.setBackground(Color.WHITE);
+		panel.add(consoleText);
+		setViewportView(panel);
+
+	}
+
+	public void addText(String t, Color c, int p) {
+		StyleConstants.setForeground(style, c);
+		StyleConstants.setFontSize(style, p);
+
+		try {
+			if (consoleText.getText().length() != 0) {
+				doc.insertString(doc.getLength(), "\n", style);
+			}
+			doc.insertString(doc.getLength(), t, style);
+		} catch (BadLocationException e) {
+		}
+	}
+}