/** * Fetches the attributes to use when rendering. This is implemented to multiplex the attributes * specified in the model with a StyleSheet. */ public AttributeSet getAttributes() { if (attr == null) { StyleSheet sheet = getStyleSheet(); attr = sheet.getViewAttributes(this); } return attr; }
/** * Sets up the paragraph from css attributes instead of the values found in StyleConstants (i.e. * which are used by the superclass). Since */ protected void setPropertiesFromAttributes() { StyleSheet sheet = getStyleSheet(); attr = sheet.getViewAttributes(this); painter = sheet.getBoxPainter(attr); if (attr != null) { super.setPropertiesFromAttributes(); setInsets( (short) painter.getInset(TOP, this), (short) painter.getInset(LEFT, this), (short) painter.getInset(BOTTOM, this), (short) painter.getInset(RIGHT, this)); Object o = attr.getAttribute(CSS.Attribute.TEXT_ALIGN); if (o != null) { // set horizontal alignment String ta = o.toString(); if (ta.equals("left")) { setJustification(StyleConstants.ALIGN_LEFT); } else if (ta.equals("center")) { setJustification(StyleConstants.ALIGN_CENTER); } else if (ta.equals("right")) { setJustification(StyleConstants.ALIGN_RIGHT); } else if (ta.equals("justify")) { setJustification(StyleConstants.ALIGN_JUSTIFIED); } } // Get the width/height cssWidth = (CSS.LengthValue) attr.getAttribute(CSS.Attribute.WIDTH); cssHeight = (CSS.LengthValue) attr.getAttribute(CSS.Attribute.HEIGHT); } }
protected StyleRule(final StyleSheet parentStyle, final StyleRule parentRule) { if (parentStyle == null) { throw new NullPointerException(); } this.styleKeyRegistry = parentStyle.getStyleKeyRegistry(); this.parentStyle = parentStyle; this.parentRule = parentRule; }
/** * Build a local image with its local path. * * @param ss the local image params * @return the JavaFX image object */ private URL buildStyleSheetUrl(final StyleSheet ss) { final StringBuilder sb = new StringBuilder(); sb.append(JRebirthParameters.STYLE_FOLDER.get()).append(Resources.PATH_SEP); if (!ss.path().isEmpty()) { sb.append(ss.path()).append(Resources.PATH_SEP); } sb.append(ss.name()); if (!ss.name().endsWith(CSS_EXT)) { sb.append(CSS_EXT); } return buildUrl(sb.toString()); }
private MainPanel() { super(new GridLayout(3, 1)); add(makePanel("Default", HREF)); // [Customize detault html link color in java swing - Stack Overflow] // http://stackoverflow.com/questions/26749495/customize-detault-html-link-color-in-java-swing HTMLEditorKit kit = new HTMLEditorKit(); StyleSheet styleSheet = kit.getStyleSheet(); styleSheet.addRule("a{color:#FF0000;}"); add(makePanel("styleSheet.addRule(\"a{color:#FF0000;}\")", HREF)); add( makePanel( "<a style='color:#00FF00'...", "<html><a style='color:#00FF00' href='" + MYSITE + "'>" + MYSITE + "</a>")); setPreferredSize(new Dimension(320, 240)); }
/** * @see com.itextpdf.text.xml.simpleparser.SimpleXMLDocHandler#startElement(java.lang.String, * java.util.Map) */ public void startElement(final String tag, final Map<String, String> attrs) { HTMLTagProcessor htmlTag = tags.get(tag); if (htmlTag == null) { return; } // apply the styles to attrs style.applyStyle(tag, attrs); // deal with the style attribute StyleSheet.resolveStyleAttribute(attrs, chain); // process the tag try { htmlTag.startElement(this, tag, attrs); } catch (DocumentException e) { throw new ExceptionConverter(e); } catch (IOException e) { throw new ExceptionConverter(e); } }
/** * Outputs the styles as a single element. Styles are not stored as elements, but part of the * document. For the time being styles are written out as a comment, inside a style tag. */ void writeStyles(StyleSheet sheet) throws IOException { if (sheet != null) { Enumeration styles = sheet.getStyleNames(); if (styles != null) { boolean outputStyle = false; while (styles.hasMoreElements()) { String name = (String) styles.nextElement(); // Don't write out the default style. if (!StyleContext.DEFAULT_STYLE.equals(name) && writeStyle(name, sheet.getStyle(name), outputStyle)) { outputStyle = true; } } if (outputStyle) { writeStyleEndTag(); } } } }
public void testWhiteSpaceInvalid() { ss.addCSSAttribute(simple, Attribute.WHITE_SPACE, "no-wrap"); cssValue = simple.getAttribute(Attribute.WHITE_SPACE); if (BasicSwingTestCase.isHarmony()) { assertEquals(0, simple.getAttributeCount()); assertNull(cssValue); } else { assertEquals(1, simple.getAttributeCount()); assertEquals("no-wrap", cssValue.toString()); } }
/** Update any cached values that come from attributes. */ protected void setPropertiesFromAttributes() { // update attributes StyleSheet sheet = getStyleSheet(); attr = sheet.getViewAttributes(this); // Reset the painter painter = sheet.getBoxPainter(attr); if (attr != null) { setInsets( (short) painter.getInset(TOP, this), (short) painter.getInset(LEFT, this), (short) painter.getInset(BOTTOM, this), (short) painter.getInset(RIGHT, this)); } // Get the width/height cssWidth = (CSS.LengthValue) attr.getAttribute(CSS.Attribute.WIDTH); cssHeight = (CSS.LengthValue) attr.getAttribute(CSS.Attribute.HEIGHT); }
public void testReadWriteFromNonZeroOffset() throws Exception { HWPFFileSystem fileSys = new HWPFFileSystem(); HWPFOutputStream tableOut = fileSys.getStream("1Table"); tableOut.write(new byte[20]); // 20 bytes of whatever at the front. _styleSheet.writeTo(tableOut); byte[] newTableStream = tableOut.toByteArray(); StyleSheet newStyleSheet = new StyleSheet(newTableStream, 20); assertEquals(newStyleSheet, _styleSheet); }
/** * Builds the style sheet used in the internal help browser * * @return the style sheet */ protected StyleSheet buildStyleSheet() { StyleSheet ss = new StyleSheet(); BufferedReader reader = new BufferedReader( new InputStreamReader(getClass().getResourceAsStream("/data/help-browser.css"))); StringBuffer css = new StringBuffer(); try { String line = null; while ((line = reader.readLine()) != null) { css.append(line); css.append("\n"); } reader.close(); } catch (Exception e) { System.err.println( tr("Failed to read CSS file ''help-browser.css''. Exception is: {0}", e.toString())); e.printStackTrace(); return ss; } ss.addRule(css.toString()); return ss; }
public void testReadWrite() throws Exception { HWPFFileSystem fileSys = new HWPFFileSystem(); HWPFOutputStream tableOut = fileSys.getStream("1Table"); HWPFOutputStream mainOut = fileSys.getStream("WordDocument"); _styleSheet.writeTo(tableOut); byte[] newTableStream = tableOut.toByteArray(); StyleSheet newStyleSheet = new StyleSheet(newTableStream, 0); assertEquals(newStyleSheet, _styleSheet); }
@Test public void shouldCreateProcessorPoolsOnConfigUpdate() throws Exception { TranslationConfig config = new TranslationConfig(); RequestTranslations requestTranslations = new RequestTranslations(); ResponseTranslations responseTranslations = new ResponseTranslations(); RequestTranslation trans1 = new RequestTranslation(); StyleSheets sheets = new StyleSheets(); StyleSheet sheet = new StyleSheet(); sheet.setId("sheet1"); sheet.setHref("classpath:///style.xsl"); sheets.getStyle().add(sheet); trans1.setAccept(xml); trans1.setContentType(xml); trans1.setTranslatedContentType(xml); trans1.setStyleSheets(sheets); requestTranslations.getRequestTranslation().add(trans1); ResponseTranslation trans2 = new ResponseTranslation(); trans2.setAccept(xml); trans2.setContentType(xml); trans2.setCodeRegex("4[\\d]{2}"); trans2.setTranslatedContentType(xml); trans2.setStyleSheets(sheets); responseTranslations.getResponseTranslation().add(trans2); config.setRequestTranslations(requestTranslations); config.setResponseTranslations(responseTranslations); factory.configurationUpdated(config); TranslationHandler handler = factory.buildHandler(); assertNotNull(handler); assertEquals(1, handler.getRequestProcessors().size()); assertEquals(1, handler.getResponseProcessors().size()); }
protected void build() { jepMessage = new JEditorPane("text/html", ""); jepMessage.setOpaque(false); jepMessage.setEditable(false); jepMessage.addHyperlinkListener(this); Font f = UIManager.getFont("Label.font"); StyleSheet ss = new StyleSheet(); String rule = MessageFormat.format( "font-family: ''{0}'';font-size: {1,number}pt; font-weight: {2}; font-style: {3}", f.getName(), f.getSize(), f.isBold() ? "bold" : "normal", f.isItalic() ? "italic" : "normal"); rule = "body {" + rule + "}"; rule = MessageFormat.format( "font-family: ''{0}'';font-size: {1,number}pt; font-weight: {2}; font-style: {3}", f.getName(), f.getSize(), "bold", f.isItalic() ? "italic" : "normal"); rule = "strong {" + rule + "}"; ss.addRule(rule); ss.addRule("a {text-decoration: underline; color: blue}"); HTMLEditorKit kit = new HTMLEditorKit(); kit.setStyleSheet(ss); jepMessage.setEditorKit(kit); setLayout(new BorderLayout()); add(jepMessage, BorderLayout.CENTER); lblWarning = new JLabel(""); lblWarning.setVisible(false); lblWarning.setIcon(ImageProvider.get("warning-small.png")); lblWarning.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); JPanel pnl = new JPanel(new BorderLayout()); pnl.add(lblWarning, BorderLayout.NORTH); add(pnl, BorderLayout.WEST); }
/** * Creates a new view that represents an IMG element. * * @param elem the element to create a view for */ public MyImageView(Element elem) { super(elem); initialize(elem); StyleSheet sheet = getStyleSheet(); attr = sheet.getViewAttributes(this); }
public boolean semanticEventAfter(SemanticEvent se, String msg) { // System.out.println("outlineOpen on active_="+active_+", msg="+msg); if (Outliner.MSG_MADE == msg) { Object o = se.getArg(); if (o instanceof Node) { active_ = true; ((Node) o).addObserver(this); Browser br = getBrowser(); br.eventq(new SemanticEvent(br, Executive.MSG_SUMMARY, "ON")); } } else if (!active_) { // nothing -- page fully on screen } else if (DocumentPopup.MSG_CREATE_DOCPOPUP == msg && se.getIn() != getBrowser().getSelectionSpan()) { // null)) { -- just plain-doc popup // System.out.println("**** f/b createMenu "+super.toString()+", in="+se.getIn()); INode menu = (INode) se.getOut(); createUI( "button", "Fully Collapse Outline", "event " + OutlineSpan.MSG_CLOSE_ALL, menu, "SPECIFIC", false); createUI( "button", "Fully Open (or Space to smart scroll)", "event " + Executive.MSG_SUMMARY + " OFF; event outlineOpenAll", menu, "SPECIFIC", false); /* } else if (msg.startsWith("outline")) { //if (first_/* && false* /) { CLGeneral gs = (CLGeneral)getDocument().getStyleSheet().get("excerpt"); if (gs.getSize()!=CLGeneral.INVALID) { gs.setElide(CLGeneral.BOOLINVALID); gs.setSize(CLGeneral.INVALID); for (Iterator<> i=excerptSpans_.iterator(); i.hasNext(); ) ((Span)i.next()).markDirty(); // Span class only marks dirty if set } //} */ } else if (OutlineSpan.MSG_OPEN == msg) { Object o = se.getArg(); if (o instanceof OutlineSpan) outActive_ = (OutlineSpan) o; // System.out.println("outlineOpen on "+o+" / "+outActive_.getStart().leaf.getNextLeaf()); } else if (Executive.MSG_SUMMARY == msg) { Object o = se.getArg(); if (o instanceof String) { // CLGeneral gs = (CLGeneral)getDocument().getStyleSheet().get("excerpt"); /* if ("ON".equalsIgnoreCase((String)o)) { gs.setElide(CLGeneral.FALSE); gs.setSize(10); outActive_=null; } else { gs.setElide(CLGeneral.BOOLINVALID); gs.setSize(CLGeneral.INVALID); }*/ StyleSheet ss = getDocument().getStyleSheet(); if (ssl_ == null) { ssl_ = new ArrayList<Object>(6); for (StyleSheet ssn = ss; ssn != null; ssn = ssn.getCascade()) { Object sse = ssn.get("excerpt"); if (sse != null) { ssl_.add(ssn); ssl_.add(sse); } } // if (excerpt_==null) excerpt_ = (CLGeneral)ss.get("excerpt"); } // System.out.println(ss.getName()+" => excerpt "+excerpt_); if ("ON".equalsIgnoreCase((String) o)) { for (int i = 0, imax = ssl_.size(); i < imax; i += 2) ((StyleSheet) ssl_.get(i)).put("excerpt", (ContextListener) ssl_.get(i + 1)); // ss.put("excerpt", excerpt_); outActive_ = null; // System.out.println("putting excerpt in "+getDocument().getFirstLeaf()+" // "+excerpt_.getSize()+" / "+excerpt_.getElide()); } else { // ss.remove("excerpt"); for (int i = 0, imax = ssl_.size(); i < imax; i += 2) ((StyleSheet) ssl_.get(i)).remove("excerpt"); } // for (Iterator<> i=excerptSpans_.iterator(); i.hasNext(); ) ((Span)i.next()).markDirty(); // -- execsum already reformats whole tree } } else if (Document.MSG_CLOSE == msg) { for (int i = 0, imax = ssl_.size(); i < imax; i += 2) ((StyleSheet) ssl_.get(i)).put("excerpt", (ContextListener) ssl_.get(i + 1)); // getDocument().getStyleSheet().put("excerpt", excerpt_); // stylesheet shared, so // restore! } return super.semanticEventAfter(se, msg); }
/** * Create a new DocumentParser * * @exception Exception An error */ public DocumentParser(ApplContext ac, String urlString) throws Exception { this.htmlURL = HTTPURL.getURL(urlString); this.ac = ac; urlString = htmlURL.toString(); String urlLower = urlString.toLowerCase(); String media = ac.getMedium(); String urlProtocol = htmlURL.getProtocol(); if (!"http".equals(urlProtocol) && !"https".equals(urlProtocol)) { if (urlLower.endsWith(".css")) { StyleSheetParser parser = new StyleSheetParser(); parser.parseURL(ac, htmlURL, null, null, media, StyleSheetOrigin.AUTHOR); style = parser.getStyleSheet(); } else if (urlLower.endsWith(".html") || urlLower.endsWith(".shtml") || urlLower.endsWith("/")) { TagSoupStyleSheetHandler handler = new TagSoupStyleSheetHandler(htmlURL, ac); handler.parse(htmlURL); style = handler.getStyleSheet(); if (style != null) { style.setType("text/html"); } } else if (urlLower.endsWith(".xhtml") || urlLower.endsWith(".xml")) { // Seems like we need to use tagsout in this case as well XMLStyleSheetHandler handler = new XMLStyleSheetHandler(htmlURL, ac); handler.parse(htmlURL); style = handler.getStyleSheet(); if (style != null) { style.setType("text/xml"); } } else { throw new Exception("Unknown file"); } } else { URLConnection connection = null; try { boolean isXML = false; String cType; // @@ hum, maybe? (plh, yes probably :-) ) String credential = ac.getCredential(); connection = HTTPURL.getConnection(htmlURL, ac); htmlURL = connection.getURL(); String httpCL = connection.getHeaderField("Content-Location"); if (httpCL != null) { htmlURL = HTTPURL.getURL(htmlURL, httpCL); } cType = connection.getContentType(); if (cType == null) { cType = "unknown/unknown"; } MimeType contentType = null; try { contentType = new MimeType(cType); } catch (MimeTypeFormatException ex) { } if (Util.onDebug) { System.err.println("[DEBUG] content type is [" + contentType + ']'); } if (contentType.match(MimeType.TEXT_HTML) == MimeType.MATCH_SPECIFIC_SUBTYPE) { TagSoupStyleSheetHandler handler; handler = new TagSoupStyleSheetHandler(htmlURL, ac); handler.parse(urlString, connection); style = handler.getStyleSheet(); if (style != null) { style.setType("text/html"); } } else if (contentType.match(MimeType.TEXT_CSS) == MimeType.MATCH_SPECIFIC_SUBTYPE) { StyleSheetParser parser = new StyleSheetParser(); parser.parseURL(ac, htmlURL, null, null, media, StyleSheetOrigin.AUTHOR); style = parser.getStyleSheet(); } else if ((contentType.match(MimeType.TEXT_XML) == MimeType.MATCH_SPECIFIC_SUBTYPE) || (contentType.match(MimeType.APPLICATION_XHTML_XML) == MimeType.MATCH_SPECIFIC_SUBTYPE) || (contentType.match(wap) == MimeType.MATCH_SPECIFIC_SUBTYPE)) { // TagSoup ? XMLStyleSheetHandler handler = new XMLStyleSheetHandler(htmlURL, ac); handler.parse(urlString, connection); style = handler.getStyleSheet(); if (style != null) { style.setType("text/xml"); } } else { throw new IOException("Unknown mime type : " + contentType); } } finally { try { connection.getInputStream().close(); } catch (Exception e) { } } } }
public void testWhiteSpaceNowrap() { ss.addCSSAttribute(simple, Attribute.WHITE_SPACE, "nowrap"); cssValue = simple.getAttribute(Attribute.WHITE_SPACE); assertEquals("nowrap", cssValue.toString()); }
/** @see com.itextpdf.text.xml.simpleparser.SimpleXMLDocHandler#startDocument() */ public void startDocument() { HashMap<String, String> attrs = new HashMap<String, String>(); style.applyStyle(HtmlTags.BODY, attrs); chain.addToChain(HtmlTags.BODY, attrs); }