* Chat / game log - Switched to html output. So mana symbols and html tags are correctly shown. Colors have to be adjusted still a bit.

This commit is contained in:
LevelX2 2014-09-10 17:13:26 +02:00
parent 382223bb90
commit e8f9c0822f
3 changed files with 76 additions and 57 deletions

View file

@ -1,11 +1,9 @@
package mage.client.components;
import javax.swing.*;
import javax.swing.text.AttributeSet;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
import java.awt.*;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
/**
* Enhanced {@link JTextPane} with text highlighting support.
@ -14,6 +12,13 @@ import java.awt.*;
*/
public class ColorPane extends JTextPane {
HTMLEditorKit kit = new HTMLEditorKit();
HTMLDocument doc = new HTMLDocument();
public ColorPane() {
this.setEditorKit(kit);
this.setDocument(doc);
}
/**
* This method solves the known issue with Nimbus LAF background transparency and background color.
* @param color
@ -26,24 +31,27 @@ public class ColorPane extends JTextPane {
add(jPanel);
}
public void append(Color color, String s) {
if (color == null) {
return;
}
@Override
public void setText(String string) {
super.setText(string); //To change body of generated methods, choose Tools | Templates.
}
public void append(String s) {
try {
setEditable(true);
StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, color);
int len = getDocument().getLength();
setCaretPosition(len);
setCharacterAttributes(aset, false);
replaceSelection(s);
setEditable(false);
kit.insertHTML(doc, doc.getLength(), s, 0, 0, null);
// setEditable(true);
//
// StyleContext sc = StyleContext.getDefaultStyleContext();
// AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, color);
//
// int len = getDocument().getLength();
//
// setCaretPosition(len);
// setCharacterAttributes(aset, false);
// replaceSelection(s);
//
// setEditable(false);
} catch (Exception e) {
e.printStackTrace();
}
@ -54,6 +62,7 @@ public class ColorPane extends JTextPane {
*
* @param g
*/
@Override
public void paintChildren(Graphics g) {
super.paintComponent(g);
}
@ -63,6 +72,7 @@ public class ColorPane extends JTextPane {
*
* @param g
*/
@Override
public void paintComponent(Graphics g) {
super.paintChildren(g);
}