use of javax.swing.text.html.HTMLEditorKit in project adempiere by adempiere.
the class HTMLRenderer method get.
/**
* Get View from HTML String
* @param html html string
* @return renderer view
*/
public static HTMLRenderer get(String html) {
HTMLEditorKit kit = new HTMLEditorKit();
HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
try {
doc.remove(0, doc.getLength());
Reader r = new StringReader(html);
kit.read(r, doc, 0);
} catch (Exception e) {
log.log(Level.SEVERE, "", e);
}
// Create Renderer
Element element = doc.getDefaultRootElement();
ViewFactory factory = kit.getViewFactory();
// Y_AXIS is main
View view = factory.create(element);
HTMLRenderer renderer = new HTMLRenderer(factory, view);
renderer.preferenceChanged(null, true, true);
return renderer;
}
use of javax.swing.text.html.HTMLEditorKit in project adempiere by adempiere.
the class Worker method run.
/**
* Worker: Read available Online Help Pages
*/
public void run() {
if (m_links == null)
return;
URL url = null;
try {
url = new URL(m_urlString);
} catch (Exception e) {
System.err.println("OnlineHelp.Worker.run (url) - " + e);
}
if (url == null)
return;
// Read Reference Page
try {
URLConnection conn = url.openConnection();
InputStream is = conn.getInputStream();
HTMLEditorKit kit = new HTMLEditorKit();
HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
doc.putProperty("IgnoreCharsetDirective", new Boolean(true));
kit.read(new InputStreamReader(is), doc, 0);
// Get The Links to the Help Pages
HTMLDocument.Iterator it = doc.getIterator(HTML.Tag.A);
Object target = null;
Object href = null;
while (it != null && it.isValid()) {
AttributeSet as = it.getAttributes();
// key keys
if (target == null || href == null) {
Enumeration en = as.getAttributeNames();
while (en.hasMoreElements()) {
Object o = en.nextElement();
if (target == null && o.toString().equals("target"))
// javax.swing.text.html.HTML$Attribute
target = o;
else if (href == null && o.toString().equals("href"))
href = o;
}
}
if (target != null && "Online".equals(as.getAttribute(target))) {
// Format: /help/<AD_Window_ID>/index.html
String hrefString = (String) as.getAttribute(href);
if (hrefString != null) {
try {
// System.err.println(hrefString);
String AD_Window_ID = hrefString.substring(hrefString.indexOf('/', 1), hrefString.lastIndexOf('/'));
m_links.put(AD_Window_ID, hrefString);
} catch (Exception e) {
System.err.println("OnlineHelp.Worker.run (help) - " + e);
}
}
}
it.next();
}
is.close();
} catch (ConnectException e) {
// System.err.println("OnlineHelp.Worker.run URL=" + url + " - " + e);
} catch (UnknownHostException uhe) {
// System.err.println("OnlineHelp.Worker.run " + uhe);
} catch (Exception e) {
System.err.println("OnlineHelp.Worker.run (e) " + e);
// e.printStackTrace();
} catch (Throwable t) {
System.err.println("OnlineHelp.Worker.run (t) " + t);
// t.printStackTrace();
}
// System.out.println("OnlineHelp - Links=" + m_links.size());
}
use of javax.swing.text.html.HTMLEditorKit in project intellij-community by JetBrains.
the class Messages method configureMessagePaneUi.
@NotNull
public static JTextPane configureMessagePaneUi(@NotNull JTextPane messageComponent, @Nullable String message, @Nullable UIUtil.FontSize fontSize) {
UIUtil.FontSize fixedFontSize = fontSize == null ? UIUtil.FontSize.NORMAL : fontSize;
messageComponent.setFont(UIUtil.getLabelFont(fixedFontSize));
if (BasicHTML.isHTMLString(message)) {
HTMLEditorKit editorKit = UIUtil.getHTMLEditorKit();
Font font = UIUtil.getLabelFont(fixedFontSize);
editorKit.getStyleSheet().addRule(UIUtil.displayPropertiesToCSS(font, UIUtil.getLabelForeground()));
messageComponent.setEditorKit(editorKit);
}
messageComponent.setText(message);
messageComponent.setEditable(false);
if (messageComponent.getCaret() != null) {
messageComponent.setCaretPosition(0);
}
if (UIUtil.isUnderNimbusLookAndFeel()) {
messageComponent.setOpaque(false);
messageComponent.setBackground(UIUtil.TRANSPARENT_COLOR);
} else {
messageComponent.setBackground(UIUtil.getOptionPaneBackground());
}
messageComponent.setForeground(UIUtil.getLabelForeground());
return messageComponent;
}
use of javax.swing.text.html.HTMLEditorKit in project intellij-community by JetBrains.
the class JBLabel method updateStyle.
private void updateStyle(@NotNull JEditorPane pane) {
EditorKit kit = pane.getEditorKit();
if (kit instanceof HTMLEditorKit) {
StyleSheet css = ((HTMLEditorKit) kit).getStyleSheet();
css.addRule("body, p {" + "color:#" + ColorUtil.toHex(getForeground()) + ";" + "font-family:" + getFont().getFamily() + ";" + "font-size:" + getFont().getSize() + "pt;" + "white-space:nowrap;}");
}
}
use of javax.swing.text.html.HTMLEditorKit in project sling by apache.
the class WebloaderJob method getDocumentUrlsFromGoogle.
private URL[] getDocumentUrlsFromGoogle(String currentFiletype, int start) throws IOException, BadLocationException {
final List urls = new ArrayList();
String query = webQuery + " filetype:" + currentFiletype;
final URL google = new URL("http://www.google.com/search?q=" + URLEncoder.encode(query, "UTF-8") + "&start=" + start);
log.debug("Querying {}", google.toString());
statusInfo = "Querying " + google.toString();
statusDetails = "";
URLConnection con = google.openConnection();
con.setRequestProperty("User-Agent", "");
InputStream in = con.getInputStream();
try {
HTMLEditorKit kit = new HTMLEditorKit();
HTMLDocument doc = new HTMLDocument();
doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
kit.read(new InputStreamReader(in, "UTF-8"), doc, 0);
HTMLDocument.Iterator it = doc.getIterator(HTML.Tag.A);
while (it.isValid()) {
if (it.getAttributes() != null) {
String href = (String) it.getAttributes().getAttribute(HTML.Attribute.HREF);
if (href != null && href.endsWith("." + currentFiletype)) {
URL url = new URL(new URL("http", "www.google.com", "dummy"), href);
if (url.getHost().indexOf("google") == -1) {
log.debug("Got document URL from google: {}", url);
statusDetails = "Got URL " + url;
urls.add(url);
}
}
}
it.next();
}
} finally {
in.close();
}
return (URL[]) urls.toArray(new URL[urls.size()]);
}
Aggregations