List of usage examples for javax.swing.text.html StyleSheet StyleSheet
public StyleSheet()
From source file:com.hexidec.ekit.component.ExtendedHTMLEditorKit.java
public Document createDefaultDocument() { StyleSheet styles = getStyleSheet(); StyleSheet ss = new StyleSheet(); ss.addStyleSheet(styles);//from ww w . j av a 2 s.c o m ExtendedHTMLDocument doc = new ExtendedHTMLDocument(ss); doc.setParser(getParser()); doc.setAsynchronousLoadPriority(4); doc.setTokenThreshold(100); return doc; }
From source file:ja.lingo.application.JaLingo.java
private void applyJEditorPaneStyleHack(int fontSize, String fontFace) { StyleSheet ss = new StyleSheet(); try {/*w w w . j av a2s .c o m*/ ss.loadRules(new StringReader(new CssHelper(fontSize, fontFace).asString()), null); } catch (IOException e) { States.shouldNeverReachHere(e); } // set static style, so all JEditorPanes wil have new style new HTMLEditorKit().getStyleSheet().addStyleSheet(ss); }
From source file:com.hexidec.ekit.component.ExtendedHTMLEditorKit.java
public StyleSheet getStyleSheet() { try {//from ww w . j a v a 2 s . c om StyleSheet defaultStyles = new StyleSheet(); InputStream is = getClass().getResourceAsStream("/ekit.css"); Reader r = new BufferedReader(new InputStreamReader(is, "ISO-8859-1")); defaultStyles.loadRules(r, null); r.close(); return defaultStyles; } catch (Throwable e) { log.error("Falha ao ler ekit.css. Utilizando estilos padro.", e); return super.getStyleSheet(); } }
From source file:EditorPaneExample14.java
public StyleSheet loadStyleSheet(InputStream is) throws IOException { StyleSheet s = new StyleSheet(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); s.loadRules(reader, null);/*from w w w . j av a 2 s .c om*/ reader.close(); return s; }
From source file:net.pms.newgui.LanguageSelection.java
private JComponent buildComponent() { // UIManager manages to get the background color wrong for text // components on OS X, so we apply the color manually Color backgroundColor = UIManager.getColor("Panel.background"); rootPanel.setLayout(new BoxLayout(rootPanel, BoxLayout.PAGE_AXIS)); // It needs to be something in the title text, or the size calculation for the border will be wrong. selectionPanelBorder.setTitle(" "); selectionPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5), BorderFactory.createCompoundBorder(selectionPanelBorder, BorderFactory.createEmptyBorder(10, 5, 10, 5)))); selectionPanel.setLayout(new BoxLayout(selectionPanel, BoxLayout.PAGE_AXIS)); descriptionText.setEditable(false);/*from ww w . j a v a 2 s .c om*/ descriptionText.setBackground(backgroundColor); descriptionText.setFocusable(false); descriptionText.setLineWrap(true); descriptionText.setWrapStyleWord(true); descriptionText.setBorder(BorderFactory.createEmptyBorder(5, 15, 10, 15)); selectionPanel.add(descriptionText); jLanguage = new JComboBox<>(keyedModel); jLanguage.setEditable(false); jLanguage.setPreferredSize(new Dimension(50, jLanguage.getPreferredSize().height)); jLanguage.addActionListener(new LanguageComboBoxActionListener()); languagePanel.setLayout(new BoxLayout(languagePanel, BoxLayout.PAGE_AXIS)); languagePanel.setBorder(BorderFactory.createEmptyBorder(5, 15, 5, 15)); languagePanel.add(jLanguage); selectionPanel.add(languagePanel); warningText.setEditable(false); warningText.setFocusable(false); warningText.setBackground(backgroundColor); warningText.setFont(warningText.getFont().deriveFont(Font.BOLD)); warningText.setLineWrap(true); warningText.setWrapStyleWord(true); warningText.setBorder(BorderFactory.createEmptyBorder(5, 15, 0, 15)); selectionPanel.add(warningText); // It needs to be something in the title text, or the size calculation for the border will be wrong. infoTextBorder.setTitle(" "); infoText.setBorder( BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5), BorderFactory .createCompoundBorder(infoTextBorder, BorderFactory.createEmptyBorder(15, 20, 20, 20)))); infoText.setEditable(false); infoText.setFocusable(false); infoText.setBackground(backgroundColor); infoText.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE); // This exercise is to avoid using the default shared StyleSheet with padding CustomHTMLEditorKit editorKit = new CustomHTMLEditorKit(); StyleSheet styleSheet = new StyleSheet(); styleSheet.addRule("a { color: #0000EE; text-decoration:underline; }"); editorKit.setStyleSheet(styleSheet); infoText.setEditorKit(editorKit); infoText.addHyperlinkListener(new HyperlinkListener() { @Override public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { boolean error = false; if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().browse(new URI(e.getDescription())); } catch (IOException | URISyntaxException ex) { LOGGER.error("Language selection failed to open translation page hyperlink: ", ex.getMessage()); LOGGER.trace("", ex); error = true; } } else { LOGGER.warn("Desktop is not supported, the clicked translation page link can't be opened"); error = true; } if (error) { JOptionPane.showOptionDialog(dialog, String.format(buildString("LanguageSelection.6", true), PMS.CROWDIN_LINK), buildString("Dialog.Error"), JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, null, null); } } } }); rootPanel.add(selectionPanel); rootPanel.add(infoText); applyButton.addActionListener(new ApplyButtonActionListener()); applyButton.setActionCommand("apply"); selectButton.addActionListener(new SelectButtonActionListener()); selectButton.setActionCommand("select"); return rootPanel; }
From source file:net.ftb.util.OSUtils.java
public static StyleSheet makeStyleSheet(String name) { try {//from w w w. jav a 2 s. co m StyleSheet sheet = new StyleSheet(); Reader reader = new InputStreamReader(System.class.getResourceAsStream("/css/" + name + ".css")); sheet.loadRules(reader, null); reader.close(); return sheet; } catch (Exception ex) { ex.printStackTrace(); return null; } }
From source file:com.vladsch.idea.multimarkdown.editor.MultiMarkdownPreviewEditor.java
public static void setStyleSheet(JEditorPane jEditorPane) { HTMLEditorKit htmlKit = new HTMLEditorKit(); final StyleSheet style = new StyleSheet(); if (!MultiMarkdownGlobalSettings.getInstance().useCustomCss(false)) { style.importStyleSheet(MultiMarkdownGlobalSettings.getInstance().getCssFileURL(false)); } else {// w ww .ja va 2 s. co m try { style.loadRules(new StringReader(MultiMarkdownGlobalSettings.getInstance().getCssText(false)), null); } catch (IOException e) { e.printStackTrace(); } } htmlKit.setStyleSheet(style); jEditorPane.setEditorKit(htmlKit); }
From source file:org.pmedv.core.components.ExtendedHTMLEditorKit.java
/** * creates a default document and sets the base url to the given value. * @param baseUrl creates the default document and sets the base url * of the html-document to the given value. if base url is null, * no base url will be set.//from w w w . j a v a2s. c o m * @return returns a Document */ public Document createDefaultDocument(URL baseUrl) { StyleSheet styles = getStyleSheet(); StyleSheet ss = new StyleSheet(); ss.addStyleSheet(styles); ExtendedHTMLDocument doc = new ExtendedHTMLDocument(ss); if (baseUrl != null) doc.setBase(baseUrl); doc.setParser(getParser()); doc.setAsynchronousLoadPriority(4); doc.setTokenThreshold(100); return doc; }