Obtain the html view in the chat window from an external css.

cusax-fix
Yana Stamcheva 20 years ago
parent ec62b5ac00
commit d628acb046

@ -10,11 +10,16 @@
import java.awt.Color;
import java.awt.Font;
import java.awt.Image;
import java.util.ArrayList;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.Map;
import javax.swing.text.html.StyleSheet;
import net.java.sip.communicator.service.protocol.PresenceStatus;
import net.java.sip.communicator.service.protocol.icqconstants.IcqStatusEnum;
@ -325,4 +330,25 @@ public static Map getProtocolStatusIcons(String protocolName) {
public static Image getStatusIcon(PresenceStatus status) {
return (Image)mainStatusSet.get(status);
}
/**
* Temporary method to load the css style used in the chat window.
*
* @param style
*/
public static void loadStyle(StyleSheet style){
InputStream is = Constants.class.getClassLoader()
.getResourceAsStream
("net/java/sip/communicator/impl/gui/resources/styles/defaultStyle.css");
Reader r = new BufferedReader(new InputStreamReader(is));
try {
style.loadRules(r, null);
r.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

@ -7,15 +7,18 @@
package net.java.sip.communicator.impl.gui.main.utils;
import javax.swing.text.Document;
import javax.swing.text.Element;
import javax.swing.text.StyleConstants;
import javax.swing.text.View;
import javax.swing.text.ViewFactory;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.StyleSheet;
public class MyHTMLEditorKit extends HTMLEditorKit {
public ViewFactory getViewFactory() {
return new HTMLFactoryX();
}
@ -39,5 +42,23 @@ public View create(Element elem) {
return super.create( elem );
}
}
/**
* Create an uninitialized text storage model
* that is appropriate for this type of editor.
*
* @return the model
*/
public Document createDefaultDocument() {
StyleSheet styles = getStyleSheet();
StyleSheet ss = new StyleSheet();
ss.addStyleSheet(styles);
HTMLDocument doc = new HTMLDocument(ss);
doc.setParser(getParser());
doc.setAsynchronousLoadPriority(4);
doc.setTokenThreshold(100);
return doc;
}
}

Loading…
Cancel
Save