List of usage examples for javax.swing.text.html HTMLDocument getStyleSheet
public StyleSheet getStyleSheet()
StyleSheet
with the document-specific display rules (CSS) that were specified in the HTML document itself. From source file:Main.java
/** * Sets the font used for HTML displays to the specified font. Components * that display HTML do not necessarily honor font properties, since the * HTML document can override these values. Calling {@code setHtmlFont} * after the data is set will force the HTML display to use the font * specified to this method./*w w w . j a v a 2 s . c om*/ * * @param doc * the HTML document to update * @param font * the font to use * @throws NullPointerException * if any parameter is {@code null} */ public static void setHtmlFont(HTMLDocument doc, Font font) { String stylesheet = String.format(STYLESHEET, font.getName(), font.getSize(), font.getName(), font.getSize()); try { doc.getStyleSheet().loadRules(new StringReader(stylesheet), null); } catch (IOException e) { //this should never happen with our sheet throw new IllegalStateException(e); } }
From source file:EditorPaneExample15.java
public void loadNewPage(Object page) { try {//www .jav a 2 s . c o m loadingPage = true; // Check if the new page and the old // page are the same. URL url; if (page instanceof URL) { url = (URL) page; } else { url = new URL((String) page); } urlCombo.setSelectedItem(page); URL loadedURL = pane.getPage(); if (loadedURL != null && loadedURL.sameFile(url)) { return; } // Try to display the page urlCombo.setEnabled(false); // Disable input urlCombo.paintImmediately(0, 0, urlCombo.getSize().width, urlCombo.getSize().height); setCursor(waitCursor); // Busy cursor loadingState.setText("Loading..."); loadingState.paintImmediately(0, 0, loadingState.getSize().width, loadingState.getSize().height); loadedType.setText(""); loadedType.paintImmediately(0, 0, loadedType.getSize().width, loadedType.getSize().height); timeLabel.setText(""); timeLabel.paintImmediately(0, 0, timeLabel.getSize().width, timeLabel.getSize().height); // Display an empty tree while loading tree.setModel(emptyModel); tree.paintImmediately(0, 0, tree.getSize().width, tree.getSize().height); startTime = System.currentTimeMillis(); // Choose the loading method if (onlineLoad.isSelected()) { // Usual load via setPage pane.setPage(url); loadedType.setText(pane.getContentType()); } else { pane.setContentType("text/html"); loadedType.setText(pane.getContentType()); if (loader == null) { loader = new HTMLDocumentLoader(); } HTMLDocument doc = loader.loadDocument(url); // Modify styles for this document only modifyStyleSheet(doc.getStyleSheet()); loadComplete(); pane.setDocument(doc); displayLoadTime(); populateCombo(findLinks(doc, null)); TreeNode node = buildHeadingTree(doc); tree.setModel(new DefaultTreeModel(node)); enableInput(); loadingPage = false; } } catch (Exception e) { System.out.println(e); JOptionPane.showMessageDialog(pane, new String[] { "Unable to open file", page.toString() }, "File Open Error", JOptionPane.ERROR_MESSAGE); loadingState.setText("Failed"); enableInput(); loadingPage = false; } }
From source file:com.hexidec.ekit.component.RelativeImageView.java
protected StyleSheet getStyleSheet() { HTMLDocument doc = (HTMLDocument) getDocument(); return doc.getStyleSheet(); }
From source file:de.ailis.xadrian.components.ComplexEditor.java
/** * Constructor//from w w w .j av a 2 s . c om * * @param complex * The complex to edit * @param file * The file from which the complex was loaded. Null if it not * loaded from a file. */ public ComplexEditor(final Complex complex, final File file) { super(); setLayout(new BorderLayout()); this.complex = complex; this.file = file; // Create the text pane this.textPane = new JTextPane(); this.textPane.setEditable(false); this.textPane.setBorder(null); this.textPane.setContentType("text/html"); this.textPane.setDoubleBuffered(true); this.textPane.addHyperlinkListener(this); this.textPane.addCaretListener(this); // Create the popup menu for the text pane final JPopupMenu popupMenu = new JPopupMenu(); popupMenu.add(new CopyAction(this)); popupMenu.add(new SelectAllAction(this)); popupMenu.addSeparator(); popupMenu.add(new AddFactoryAction(this)); popupMenu.add(new ChangeSectorAction(this.complex, this, "complex")); popupMenu.add(new ChangeSunsAction(this)); popupMenu.add(new ChangePricesAction(this)); popupMenu.add(new JCheckBoxMenuItem(new ToggleBaseComplexAction(this))); SwingUtils.setPopupMenu(this.textPane, popupMenu); final HTMLDocument document = (HTMLDocument) this.textPane.getDocument(); // Set the base URL of the text pane document.setBase(Main.class.getResource("templates/")); // Modify the body style so it matches the system font final Font font = UIManager.getFont("Label.font"); final String bodyRule = "body { font-family: " + font.getFamily() + "; font-size: " + font.getSize() + "pt; }"; document.getStyleSheet().addRule(bodyRule); // Create the scroll pane final JScrollPane scrollPane = new JScrollPane(this.textPane); add(scrollPane); // Redraw the content redraw(); fireComplexState(); }
From source file:org.pmedv.core.components.RelativeImageView.java
/** * @return returns the stylesheet for this document *///w w w . j a va2 s .com protected StyleSheet getStyleSheet() { HTMLDocument doc = (HTMLDocument) getDocument(); return doc.getStyleSheet(); }