javax.swing.text.html.HTML Java Examples
The following examples show how to use
javax.swing.text.html.HTML.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WrapHTMLFactory.java From SmartIM4IntelliJ with Apache License 2.0 | 6 votes |
@Override public View create(Element elem) { View v = super.create(elem); if (v instanceof LabelView) { // the javax.swing.text.html.BRView (representing <br> tag) is a // LabelView but must not be handled // by a WrapLabelView. As BRView is private, check the html tag from // elem attribute Object o = elem.getAttributes().getAttribute(StyleConstants.NameAttribute); if ((o instanceof HTML.Tag) && o == HTML.Tag.BR) { return new BRView(elem); } } if (v instanceof InlineView) { return new WrapInlineView(elem); } else if (v instanceof ParagraphView) { return new WrapParagraphView(elem); } return v; }
Example #2
Source File: HTMLEditor.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
/** * The operation to perform when this action is triggered. * * @param e the action event */ public void actionPerformed(ActionEvent e) { JTextComponent target = getTextComponent(e); if ((target != null) && (e != null)) { String[] temp = res.getImageResourceNames(); Arrays.sort(temp, String.CASE_INSENSITIVE_ORDER); JComboBox jc = new JComboBox(temp); final com.codename1.ui.Image img = res.getImage((String)jc.getSelectedItem()); JOptionPane.showMessageDialog(HTMLEditor.this, jc, "Pick", JOptionPane.PLAIN_MESSAGE); if ((! target.isEditable()) || (! target.isEnabled()) && img != null) { UIManager.getLookAndFeel().provideErrorFeedback(target); return; } try { ((HTMLEditorKit)wysiwyg.getEditorKit()).insertHTML((HTMLDocument)wysiwyg.getDocument(), wysiwyg.getCaret().getDot(), "<img width=\"" + img.getWidth() + "\" height=\"" + img.getHeight() + "\" src=\"local://" + jc.getSelectedItem()+ "\" />", 0, 0, HTML.Tag.IMG); //target.getDocument().insertString(target.getSelectionStart(), "<img src=\"local://" + jc.getSelectedItem() + "\" />", null); //target.replaceSelection("<img src=\"local://" + jc.getSelectedItem() + "\" />"); } catch (Exception ex) { ex.printStackTrace(); } } }
Example #3
Source File: HtmlDocumentHandler.java From gate-core with GNU Lesser General Public License v3.0 | 6 votes |
/** This method analizes the tag t and adds some \n chars and spaces to the * tmpDocContent.The reason behind is that we need to have a readable form * for the final document. This method modifies the content of tmpDocContent. * @param t the Html tag encounted by the HTML parser */ protected void customizeAppearanceOfDocumentWithSimpleTag(HTML.Tag t){ boolean modification = false; // if the HTML tag is BR then we add a new line character to the document if (HTML.Tag.BR == t){ tmpDocContent.append("\n"); modification = true; }// End if if (modification == true){ Long end = new Long (tmpDocContent.length()); Iterator<CustomObject> anIterator = stack.iterator(); while (anIterator.hasNext ()){ // get the object and move to the next one CustomObject obj = anIterator.next(); // sets its End index obj.setEnd(end); }// End while }//End if }
Example #4
Source File: TableView.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Determines the number of rows occupied by * the table cell represented by given element. */ /*protected*/ int getRowsOccupied(View v) { // PENDING(prinz) this code should be in the html // paragraph, but we can't add api to enable it. AttributeSet a = v.getElement().getAttributes(); String s = (String) a.getAttribute(HTML.Attribute.ROWSPAN); if (s != null) { try { return Integer.parseInt(s); } catch (NumberFormatException nfe) { // fall through to one row } } return 1; }
Example #5
Source File: TableView.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * Determines the number of rows occupied by * the table cell represented by given element. */ /*protected*/ int getRowsOccupied(View v) { // PENDING(prinz) this code should be in the html // paragraph, but we can't add api to enable it. AttributeSet a = v.getElement().getAttributes(); String s = (String) a.getAttribute(HTML.Attribute.ROWSPAN); if (s != null) { try { return Integer.parseInt(s); } catch (NumberFormatException nfe) { // fall through to one row } } return 1; }
Example #6
Source File: REditorPane.java From marathonv5 with Apache License 2.0 | 6 votes |
public void setHRef(int pos, Document doc) { hRef = null; text = null; if (!(doc instanceof HTMLDocument)) { return; } HTMLDocument hdoc = (HTMLDocument) doc; Iterator iterator = hdoc.getIterator(HTML.Tag.A); while (iterator.isValid()) { if (pos >= iterator.getStartOffset() && pos < iterator.getEndOffset()) { AttributeSet attributes = iterator.getAttributes(); if (attributes != null && attributes.getAttribute(HTML.Attribute.HREF) != null) { try { text = hdoc.getText(iterator.getStartOffset(), iterator.getEndOffset() - iterator.getStartOffset()).trim(); hRef = attributes.getAttribute(HTML.Attribute.HREF).toString(); setIndexOfHrefAndText(hdoc, pos, text, hRef); } catch (BadLocationException e) { e.printStackTrace(); } return; } } iterator.next(); } }
Example #7
Source File: TableView.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Determines the number of rows occupied by * the table cell represented by given element. */ /*protected*/ int getRowsOccupied(View v) { // PENDING(prinz) this code should be in the html // paragraph, but we can't add api to enable it. AttributeSet a = v.getElement().getAttributes(); String s = (String) a.getAttribute(HTML.Attribute.ROWSPAN); if (s != null) { try { return Integer.parseInt(s); } catch (NumberFormatException nfe) { // fall through to one row } } return 1; }
Example #8
Source File: TableView.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * Determines the number of rows occupied by * the table cell represented by given element. */ /*protected*/ int getRowsOccupied(View v) { // PENDING(prinz) this code should be in the html // paragraph, but we can't add api to enable it. AttributeSet a = v.getElement().getAttributes(); String s = (String) a.getAttribute(HTML.Attribute.ROWSPAN); if (s != null) { try { return Integer.parseInt(s); } catch (NumberFormatException nfe) { // fall through to one row } } return 1; }
Example #9
Source File: TableView.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Determines the number of rows occupied by * the table cell represented by given element. */ /*protected*/ int getRowsOccupied(View v) { // PENDING(prinz) this code should be in the html // paragraph, but we can't add api to enable it. AttributeSet a = v.getElement().getAttributes(); String s = (String) a.getAttribute(HTML.Attribute.ROWSPAN); if (s != null) { try { return Integer.parseInt(s); } catch (NumberFormatException nfe) { // fall through to one row } } return 1; }
Example #10
Source File: HtmlRichTextConverter.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
private HTML.Tag findTag( final AttributeSet attr ) { final Enumeration names = attr.getAttributeNames(); while ( names.hasMoreElements() ) { final Object name = names.nextElement(); final Object o = attr.getAttribute( name ); if ( o instanceof HTML.Tag ) { if ( HTML.Tag.CONTENT == o ) { continue; } if ( HTML.Tag.COMMENT == o ) { continue; } return (HTML.Tag) o; } } return null; }
Example #11
Source File: TableView.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Determines the number of columns occupied by * the table cell represented by given element. */ /*protected*/ int getColumnsOccupied(View v) { // PENDING(prinz) this code should be in the html // paragraph, but we can't add api to enable it. AttributeSet a = v.getElement().getAttributes(); String s = (String) a.getAttribute(HTML.Attribute.COLSPAN); if (s != null) { try { return Integer.parseInt(s); } catch (NumberFormatException nfe) { // fall through to one column } } return 1; }
Example #12
Source File: TableView.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Determines the number of columns occupied by * the table cell represented by given element. */ /*protected*/ int getColumnsOccupied(View v) { // PENDING(prinz) this code should be in the html // paragraph, but we can't add api to enable it. AttributeSet a = v.getElement().getAttributes(); String s = (String) a.getAttribute(HTML.Attribute.COLSPAN); if (s != null) { try { return Integer.parseInt(s); } catch (NumberFormatException nfe) { // fall through to one column } } return 1; }
Example #13
Source File: TableView.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
/** * Determines the number of rows occupied by * the table cell represented by given element. */ /*protected*/ int getRowsOccupied(View v) { // PENDING(prinz) this code should be in the html // paragraph, but we can't add api to enable it. AttributeSet a = v.getElement().getAttributes(); String s = (String) a.getAttribute(HTML.Attribute.ROWSPAN); if (s != null) { try { return Integer.parseInt(s); } catch (NumberFormatException nfe) { // fall through to one row } } return 1; }
Example #14
Source File: HtmlDocumentHandler.java From gate-core with GNU Lesser General Public License v3.0 | 6 votes |
/** This method analizes the tag t and adds some \n chars and spaces to the * tmpDocContent.The reason behind is that we need to have a readable form * for the final document. This method modifies the content of tmpDocContent. * @param t the Html tag encounted by the HTML parser */ protected void customizeAppearanceOfDocumentWithStartTag(HTML.Tag t){ boolean modification = false; if (HTML.Tag.P == t){ int tmpDocContentSize = tmpDocContent.length(); if ( tmpDocContentSize >= 2 && '\n' != tmpDocContent.charAt(tmpDocContentSize - 2) ) { tmpDocContent.append("\n"); modification = true;} }// End if if (modification == true){ Long end = new Long (tmpDocContent.length()); Iterator<CustomObject> anIterator = stack.iterator(); while (anIterator.hasNext ()){ // get the object and move to the next one CustomObject obj = anIterator.next(); // sets its End index obj.setEnd(end); }// End while }//End if }
Example #15
Source File: TableView.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Determines the number of columns occupied by * the table cell represented by given element. */ /*protected*/ int getColumnsOccupied(View v) { // PENDING(prinz) this code should be in the html // paragraph, but we can't add api to enable it. AttributeSet a = v.getElement().getAttributes(); String s = (String) a.getAttribute(HTML.Attribute.COLSPAN); if (s != null) { try { return Integer.parseInt(s); } catch (NumberFormatException nfe) { // fall through to one column } } return 1; }
Example #16
Source File: MainPanel.java From java-swing-tips with MIT License | 6 votes |
@Override public void actionPerformed(ActionEvent e) { textArea.append(String.format("----%n%s%n", getValue(Action.NAME))); String id = field.getText().trim(); String text = editorPane.getText(); ParserDelegator delegator = new ParserDelegator(); try { delegator.parse(new StringReader(text), new HTMLEditorKit.ParserCallback() { @Override public void handleStartTag(HTML.Tag tag, MutableAttributeSet a, int pos) { Object attrId = a.getAttribute(HTML.Attribute.ID); textArea.append(String.format("%s@id=%s%n", tag, attrId)); if (id.equals(attrId)) { textArea.append(String.format("found: pos=%d%n", pos)); int endOffs = text.indexOf('>', pos); textArea.append(String.format("%s%n", text.substring(pos, endOffs + 1))); } } }, Boolean.TRUE); } catch (IOException ex) { ex.printStackTrace(); textArea.append(String.format("%s%n", ex.getMessage())); UIManager.getLookAndFeel().provideErrorFeedback(textArea); } }
Example #17
Source File: SearchThreadJdk12.java From netbeans with Apache License 2.0 | 6 votes |
public @Override void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos) { if ( t == HTML.Tag.DT ) { where = IN_DT; currentDii = null; } else if ( t == HTML.Tag.A && where == IN_DT ) { where = IN_AREF; Object val = a.getAttribute( HTML.Attribute.HREF ); if ( val != null ) { hrefVal = val.toString(); currentDii = new DocIndexItem( null, null, contextURL, hrefVal ); } } else if ( t == HTML.Tag.A && (where == IN_DESCRIPTION_SUFFIX || where == IN_DESCRIPTION) ) { // Just ignore } else if ( (t == HTML.Tag.B || t == HTML.Tag.SPAN)/* && where == IN_AREF */) { /*where = IN_AREF;*/ // Ignore formatting } else { where = IN_BALAST; } }
Example #18
Source File: TableView.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
/** * Determines the number of rows occupied by * the table cell represented by given element. */ /*protected*/ int getRowsOccupied(View v) { // PENDING(prinz) this code should be in the html // paragraph, but we can't add api to enable it. AttributeSet a = v.getElement().getAttributes(); String s = (String) a.getAttribute(HTML.Attribute.ROWSPAN); if (s != null) { try { return Integer.parseInt(s); } catch (NumberFormatException nfe) { // fall through to one row } } return 1; }
Example #19
Source File: TableView.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * Determines the number of columns occupied by * the table cell represented by given element. */ /*protected*/ int getColumnsOccupied(View v) { // PENDING(prinz) this code should be in the html // paragraph, but we can't add api to enable it. AttributeSet a = v.getElement().getAttributes(); String s = (String) a.getAttribute(HTML.Attribute.COLSPAN); if (s != null) { try { return Integer.parseInt(s); } catch (NumberFormatException nfe) { // fall through to one column } } return 1; }
Example #20
Source File: TableView.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
/** * Determines the number of columns occupied by * the table cell represented by given element. */ /*protected*/ int getColumnsOccupied(View v) { // PENDING(prinz) this code should be in the html // paragraph, but we can't add api to enable it. AttributeSet a = v.getElement().getAttributes(); String s = (String) a.getAttribute(HTML.Attribute.COLSPAN); if (s != null) { try { return Integer.parseInt(s); } catch (NumberFormatException nfe) { // fall through to one column } } return 1; }
Example #21
Source File: HTMLSuiteResult.java From selenium with Apache License 2.0 | 5 votes |
@Override public void handleStartTag(Tag tag, MutableAttributeSet attributes, int pos) { if (Tag.A.equals(tag)) { String href = (String) attributes.getAttribute(HTML.Attribute.HREF); hrefList.add(href.replace('\\', '/')); tagPositions.add(pos); } }
Example #22
Source File: TagElement.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public TagElement (Element elem, boolean fictional) { this.elem = elem; htmlTag = HTML.getTag(elem.getName()); if (htmlTag == null) { htmlTag = new HTML.UnknownTag(elem.getName()); } insertedByErrorRecovery = fictional; }
Example #23
Source File: DocumentationComponent.java From consulo with Apache License 2.0 | 5 votes |
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; }
Example #24
Source File: bug8058120.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { createAndShowGUI(); } }); toolkit.realSync(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { try { document.insertAfterEnd(document.getElement("ab"), textToInsert); } catch (Exception ex) { throw new RuntimeException(ex); } } }); toolkit.realSync(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { Element parent = document.getElement("ab").getParentElement(); int count = parent.getElementCount(); if (count != 2) { throw new RuntimeException("Test Failed! Unexpected Element count = "+count); } Element insertedElement = parent.getElement(count - 1); if (!HTML.Tag.IMPLIED.toString().equals(insertedElement.getName())) { throw new RuntimeException("Test Failed! Inserted text is not wrapped by " + HTML.Tag.IMPLIED + " tag"); } } }); }
Example #25
Source File: HTMLTextArea.java From netbeans with Apache License 2.0 | 5 votes |
protected void emptyTag(Element elem) throws BadLocationException, IOException { if (isSupportedBreakFlowTag(elem.getAttributes())) { writeLineSeparator(); } if (matchNameAttribute(elem.getAttributes(), HTML.Tag.CONTENT)) { text(elem); } }
Example #26
Source File: TagElement.java From JDKSourceCode1.8 with MIT License | 5 votes |
public TagElement (Element elem, boolean fictional) { this.elem = elem; htmlTag = HTML.getTag(elem.getName()); if (htmlTag == null) { htmlTag = new HTML.UnknownTag(elem.getName()); } insertedByErrorRecovery = fictional; }
Example #27
Source File: MainPanel.java From java-swing-tips with MIT License | 5 votes |
private Optional<String> getSpanTitleAttribute(HTMLDocument doc, int pos) { // HTMLDocument doc = (HTMLDocument) editor.getDocument(); Element elem = doc.getCharacterElement(pos); // if (!doesElementContainLocation(editor, elem, pos, e.getX(), e.getY())) { // elem = null; // } // if (elem != null) { AttributeSet a = elem.getAttributes(); AttributeSet span = (AttributeSet) a.getAttribute(HTML.Tag.SPAN); return Optional.ofNullable(span).map(s -> Objects.toString(s.getAttribute(HTML.Attribute.TITLE))); }
Example #28
Source File: HTMLTextArea.java From visualvm with GNU General Public License v2.0 | 5 votes |
protected void emptyTag(Element elem) throws BadLocationException, IOException { if (isSupportedBreakFlowTag(elem.getAttributes())) { writeLineSeparator(); } if (matchNameAttribute(elem.getAttributes(), HTML.Tag.CONTENT)) { text(elem); } }
Example #29
Source File: SwingForm.java From teamengine with Apache License 2.0 | 5 votes |
public javax.swing.text.View create(javax.swing.text.Element elem) { AttributeSet as = elem.getAttributes(); HTML.Tag tag = (HTML.Tag) (as .getAttribute(StyleConstants.NameAttribute)); if (tag == HTML.Tag.INPUT) { String type = ""; String name = ""; Enumeration e = as.getAttributeNames(); while (e.hasMoreElements()) { Object key = e.nextElement(); if (key == HTML.Attribute.TYPE) { type = as.getAttribute(key).toString(); } if (key == HTML.Attribute.NAME) { name = as.getAttribute(key).toString(); } } if (type.equalsIgnoreCase("submit")) { return new CustomFormView(elem); } if (type.equalsIgnoreCase("file")) { fileFields.add(name); } } return super.create(elem); }
Example #30
Source File: HTMLTextArea.java From visualvm with GNU General Public License v2.0 | 5 votes |
protected boolean isSupportedBreakFlowTag(AttributeSet attr) { Object o = attr.getAttribute(StyleConstants.NameAttribute); if (o instanceof HTML.Tag) { HTML.Tag tag = (HTML.Tag) o; if ((tag == HTML.Tag.HTML) || (tag == HTML.Tag.HEAD) || (tag == HTML.Tag.BODY) || (tag == HTML.Tag.HR)) { return false; } return (tag).breaksFlow(); } return false; }