use of javax.swing.text.html.HTMLDocument 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.HTMLDocument 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.HTMLDocument in project adempiere by adempiere.
the class HelpInfo method createAndShowGui.
// METHODS
// =======
/**
* Create the GUI and show it
* @param component the calling component
*/
public void createAndShowGui(Component component) {
// title
setTitle(s_logger.localizeMessage("guiHelpTitle"));
// load icons
ArrayList<Image> images = new ArrayList<Image>();
images.add(getImage("AD16.png"));
images.add(getImage("AD32.png"));
setIconImages(images);
// content pane
Container pane = getContentPane();
Locale locale = Locale.getDefault();
pane.setComponentOrientation(ComponentOrientation.getOrientation(locale));
pane.setLayout(new GridBagLayout());
// help text
JEditorPane info = new JEditorPane();
info.setEditable(false);
info.setContentType("text/html");
HTMLDocument htmlDoc = (HTMLDocument) info.getEditorKit().createDefaultDocument();
info.setDocument(htmlDoc);
info.setText(getHelpText());
info.setCaretPosition(0);
// scrollable pane for help text
JScrollPane infoPane = new JScrollPane();
infoPane.setBorder(BorderFactory.createLoweredBevelBorder());
infoPane.setPreferredSize(new Dimension(500, 400));
infoPane.getViewport().add(info, null);
pane.add(infoPane, getInfoPaneConstraints());
// close button
m_buttonClose = new JButton(s_logger.localizeMessage("guiButtonClose"));
m_buttonClose.setMnemonic(new Integer(s_logger.localizeMessage("guiButtonCloseMnemonic")));
m_buttonClose.setIcon(new ImageIcon(getImage("Cancel16.png")));
m_buttonClose.addActionListener(this);
pane.add(m_buttonClose, getCloseConstraints());
// show dialog
pack();
validate();
m_buttonClose.requestFocusInWindow();
setLocationRelativeTo(component);
setVisible(true);
}
use of javax.swing.text.html.HTMLDocument in project intellij-community by JetBrains.
the class DocumentationComponent method getLinkCount.
private int getLinkCount() {
HTMLDocument document = (HTMLDocument) myEditorPane.getDocument();
int linkCount = 0;
for (HTMLDocument.Iterator it = document.getIterator(HTML.Tag.A); it.isValid(); it.next()) {
if (it.getAttributes().isDefined(HTML.Attribute.HREF))
linkCount++;
}
return linkCount;
}
use of javax.swing.text.html.HTMLDocument in project intellij-community by JetBrains.
the class DocumentationComponent method getLink.
@Nullable
private HTMLDocument.Iterator getLink(int n) {
if (n >= 0) {
HTMLDocument document = (HTMLDocument) myEditorPane.getDocument();
int linkCount = 0;
for (HTMLDocument.Iterator it = document.getIterator(HTML.Tag.A); it.isValid(); it.next()) {
if (it.getAttributes().isDefined(HTML.Attribute.HREF) && linkCount++ == n)
return it;
}
}
return null;
}
Aggregations