javax.swing.text.html.HTML.Attribute Java Examples
The following examples show how to use
javax.swing.text.html.HTML.Attribute.
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: ChatConversationPanel.java From jitsi with Apache License 2.0 | 6 votes |
/** * Inform view creation. * @param view the newly created view. */ protected void viewCreated(ViewFactory factory, View view) { if(view instanceof ImageView) { Element e = findFirstElement(view.getElement(), "img"); if(e == null) return; Object src = e.getAttributes().getAttribute(Attribute.SRC); if(src != null && src instanceof String && ((String)src).endsWith("gif")) { imageViews.add((ImageView)view); } } }
Example #2
Source File: ChatConversationPanel.java From jitsi with Apache License 2.0 | 6 votes |
/** * * @param element * @param attrName * @param matchStrings * @return */ private Element findFirstElement( Element element, HTML.Attribute attrName, String[] matchStrings) { String attr = (String) element.getAttributes().getAttribute(attrName); if(attr != null) for (String matchString : matchStrings) if (attr.startsWith(matchString)) return element; Element resultElement = null; // Count how many messages we have in the document. for (int i = 0; i < element.getElementCount(); i++) { resultElement = findFirstElement(element.getElement(i), attrName, matchStrings); if (resultElement != null) return resultElement; } return null; }
Example #3
Source File: JEditorPaneTagJavaElement.java From marathonv5 with Apache License 2.0 | 6 votes |
@Override public String getAttribute(final String name) { if ("text".equals(name)) { return getText(); } if ("hRefIndex".equals(name)) { return getHRefIndex() + ""; } if ("textIndex".equals(name)) { return getTextIndex() + ""; } return EventQueueWait.exec(new Callable<String>() { @Override public String call() throws Exception { Iterator iterator = findTag((HTMLDocument) ((JEditorPane) parent.getComponent()).getDocument()); AttributeSet attributes = iterator.getAttributes(); Attribute attr = findAttribute(name); if (attr != null && attributes.isDefined(attr)) { return attributes.getAttribute(attr).toString(); } return null; } }); }
Example #4
Source File: FSwingHtml.java From pra with MIT License | 6 votes |
public static VectorX<Element> matchChild(Element e , Attribute ab, String regex){ VectorX<Element> vE= new VectorX<Element>(Element.class); int count = e.getElementCount(); for (int i = 0; i < count; i++) { Element c = e.getElement(i); AttributeSet mAb = c.getAttributes(); String s = (String) mAb.getAttribute(ab); if (s==null)continue; // System.out.println(name+" "+ab+"="+s); if (s.matches(regex)) vE.add(c); } return vE; }
Example #5
Source File: FSwingHtml.java From pra with MIT License | 5 votes |
public static Element findElement(HTMLDocument doc , Attribute ab, String value){ return doc.getElement(doc.getDefaultRootElement(), ab, value); /*ElementIterator it = new ElementIterator(doc); Element e; while ((e = it.next()) != null) if (hasAttribute(e,ab,value))return e; return null;*/ }
Example #6
Source File: ChatConversationPanel.java From jitsi with Apache License 2.0 | 5 votes |
/** * * @param attribute * @param matchStrings * @return */ private Element findElement(HTML.Attribute attribute, String[] matchStrings) { return findFirstElement(document.getDefaultRootElement(), attribute, matchStrings); }
Example #7
Source File: ChatConversationPanel.java From jitsi with Apache License 2.0 | 5 votes |
/** * Ensures that the document won't become too big. When the document reaches * a certain size the first message in the page is removed. */ private void ensureDocumentSize() { if (document.getLength() > Chat.CHAT_BUFFER_SIZE) { String[] ids = new String[] {ChatHtmlUtils.MESSAGE_TEXT_ID, "statusMessage", "systemMessage", "actionMessage"}; Element firstMsgElement = findElement(Attribute.ID, ids); int startIndex = firstMsgElement.getStartOffset(); int endIndex = firstMsgElement.getEndOffset(); try { // Remove the message. this.document.remove(startIndex, endIndex - startIndex); } catch (BadLocationException e) { logger.error("Error removing messages from chat: ", e); } if(firstMsgElement.getName().equals("table")) { // as we have removed a header for maybe several messages, // delete all messages without header deleteAllMessagesWithoutHeader(); } } }
Example #8
Source File: ChatConversationPanel.java From jitsi with Apache License 2.0 | 5 votes |
/** * Retrieves the contents of the sent message with the given ID. * * @param messageUID The ID of the message to retrieve. * @return The contents of the message, or null if the message is not found. */ public String getMessageContents(String messageUID) { Element root = document.getDefaultRootElement(); Element e = document.getElement( root, Attribute.ID, ChatHtmlUtils.MESSAGE_TEXT_ID + messageUID); if (e == null) { logger.warn("Could not find message with ID " + messageUID); return null; } Object original_message = e.getAttributes().getAttribute( ChatHtmlUtils.ORIGINAL_MESSAGE_ATTRIBUTE); if (original_message == null) { logger.warn("Message with ID " + messageUID + " does not have original_message attribute"); return null; } String res = StringEscapeUtils.unescapeXml(original_message.toString()); // Remove all newline characters that were inserted to make copying // newlines from the conversation panel work. // They shouldn't be in the write panel, because otherwise a newline // would consist of two chars, one of them invisible (the ), but // both of them have to be deleted in order to remove it. // On the other hand this means that copying newlines from the write // area produces only spaces, but this seems like the better option. res = res.replace(" ", ""); return res; }
Example #9
Source File: FSwingHtml.java From pra with MIT License | 5 votes |
public static VectorX<Element> findDecendent(Element e , Attribute ab){ VectorX<Element> vE= new VectorX<Element>(Element.class); ElementIterator it = new ElementIterator(e); Element c; while ((c = it.next()) != null){ //System.out.println(ab+"="+FHtml.getAttribute(c, ab)); if (hasAttribute(c,ab)) vE.add(c); } return vE; }
Example #10
Source File: FSwingHtml.java From pra with MIT License | 5 votes |
public static VectorX<Element> findDecendent(Element e , Attribute ab, String value){ VectorX<Element> vE= new VectorX<Element>(Element.class); ElementIterator it = new ElementIterator(e); Element c; while ((c = it.next()) != null){ System.out.println(ab+"="+FSwingHtml.getAttribute(c, ab)); if (hasAttribute(c,ab,value)) vE.add(c); } return vE; }
Example #11
Source File: FSwingHtml.java From pra with MIT License | 5 votes |
public static void extractAll(Element e , Attribute ab, Attribute abExtract,VectorS vs){ //VectorS vs=new VectorS(); for (Element c: findDecendent(e,ab)) vs.add(FSwingHtml.getAttribute(c, abExtract)); //return vs; }
Example #12
Source File: FSwingHtml.java From pra with MIT License | 5 votes |
public static VectorX<Element> findChild(Element e , Attribute ab, String value){ VectorX<Element> vE= new VectorX<Element>(Element.class); int count = e.getElementCount(); for (int i = 0; i < count; i++) { Element c = e.getElement(i); AttributeSet mAb = c.getAttributes(); if (mAb.containsAttribute(HTML.Attribute.ID, value)) vE.add(c); } return vE; }
Example #13
Source File: JEditorPaneTagJavaElement.java From marathonv5 with Apache License 2.0 | 5 votes |
private Attribute findAttribute(String attrName) { for (Attribute attr : allAttributes) { if (attrName.toUpperCase().equals(attr.toString().toUpperCase())) { return attr; } } return null; }
Example #14
Source File: JEditorPaneTagJavaElement.java From marathonv5 with Apache License 2.0 | 5 votes |
public int getHRefIndex() { return EventQueueWait.exec(new Callable<Integer>() { @Override public Integer call() throws Exception { String href = getAttribute("href"); int hRefIndex = 0; int current = 0; JEditorPane editor = (JEditorPane) parent.getComponent(); HTMLDocument document = (HTMLDocument) editor.getDocument(); Iterator iterator = document.getIterator(Tag.A); while (iterator.isValid()) { if (current++ >= index) { return hRefIndex; } AttributeSet attributes = iterator.getAttributes(); if (attributes != null) { Object attributeObject = attributes.getAttribute(HTML.Attribute.HREF); if (attributeObject != null) { String attribute = attributeObject.toString(); if (attribute.equals(href)) { hRefIndex++; } } } iterator.next(); } return -1; } }); }
Example #15
Source File: FSwingHtml.java From pra with MIT License | 5 votes |
public static boolean hasAttribute(Element e, Attribute ab){ AttributeSet mAb=e.getAttributes(); for (Enumeration it = mAb.getAttributeNames() ; it.hasMoreElements() ;) { Object s= it.nextElement(); if (s.equals(ab)) return true; } return false; }
Example #16
Source File: FSwingHtml.java From pra with MIT License | 5 votes |
public static String getAttribute(Element e, Attribute ab){ AttributeSet mAb=e.getAttributes(); for (Enumeration it = mAb.getAttributeNames() ; it.hasMoreElements() ;) { Object s= it.nextElement(); if (s.equals(ab)) return (String) mAb.getAttribute(ab); } return null; }
Example #17
Source File: TxtElementExtractor.java From pra with MIT License | 4 votes |
public Node newID( String value, CallBack f){ return newChild(HTML.Attribute.ID,value,f); }
Example #18
Source File: FSwingHtml.java From pra with MIT License | 4 votes |
public static void extractAll(Element e , Attribute ab, String value , Attribute abExtract,VectorS vs){ for (Element c: findDecendent(e,ab, value)) vs.add(FSwingHtml.getAttribute(c, abExtract)); return; }
Example #19
Source File: FSwingHtml.java From pra with MIT License | 4 votes |
public static void extractAll(Element e , Attribute ab, VectorS vs){ extractAll(e,ab,ab,vs); }
Example #20
Source File: FSwingHtml.java From pra with MIT License | 4 votes |
public static boolean withID(Element e, String value){ return e.getAttributes().containsAttribute( HTML.Attribute.ID, value); }
Example #21
Source File: ChatConversationPanel.java From jitsi with Apache License 2.0 | 4 votes |
/** * Indicates if this is a consecutive message. * * @param chatMessage the message to verify * @return <tt>true</tt> if the given message is a consecutive message, * <tt>false</tt> - otherwise */ private boolean isConsecutiveMessage(ChatMessage chatMessage) { if (lastMessageUID == null) return false; Element lastMsgElement = document.getElement( ChatHtmlUtils.MESSAGE_TEXT_ID + lastMessageUID); if (lastMsgElement == null) { // This will happen if the last message is a non-user message, such // as a system message. For these messages we *do* update the // lastMessageUID, however we do *not* include the new UID in the // newly appended message. logger.info("Could not find message with ID " + lastMessageUID); return false; } String contactAddress = (String) lastMsgElement.getAttributes() .getAttribute(Attribute.NAME); if (contactAddress != null && (chatMessage.getMessageType() .equals(Chat.INCOMING_MESSAGE) || chatMessage.getMessageType() .equals(Chat.OUTGOING_MESSAGE) || chatMessage.getMessageType() .equals(Chat.HISTORY_INCOMING_MESSAGE) || chatMessage.getMessageType() .equals(Chat.HISTORY_OUTGOING_MESSAGE)) && contactAddress.equals(chatMessage.getContactName()) // And if the new message is within a minute from the last one. && ((chatMessage.getDate().getTime() - lastMessageTimestamp.getTime()) < 60000)) { lastMessageTimestamp = chatMessage.getDate(); return true; } return false; }
Example #22
Source File: ChatConversationPanel.java From jitsi with Apache License 2.0 | 4 votes |
/** * Adds a custom component at the end of the conversation. * * @param component the component to add at the end of the conversation. */ public void addComponent(ChatConversationComponent component) { synchronized (scrollToBottomRunnable) { StyleSheet styleSheet = document.getStyleSheet(); Style style = styleSheet .addStyle( StyleConstants.ComponentElementName, styleSheet.getStyle("body")); // The image must first be wrapped in a style style .addAttribute( AbstractDocument.ElementNameAttribute, StyleConstants.ComponentElementName); TransparentPanel wrapPanel = new TransparentPanel(new BorderLayout()); wrapPanel.add(component, BorderLayout.NORTH); style.addAttribute(StyleConstants.ComponentAttribute, wrapPanel); style.addAttribute(Attribute.ID, ChatHtmlUtils.MESSAGE_TEXT_ID); SimpleDateFormat sdf = new SimpleDateFormat(HistoryService.DATE_FORMAT); style.addAttribute(ChatHtmlUtils.DATE_ATTRIBUTE, sdf.format(component.getDate())); scrollToBottomIsPending = true; // We need to reinitialize the last message ID, because we don't // want components to be taken into account. lastMessageUID = null; // Insert the component style at the end of the text try { document .insertString(document.getLength(), "ignored text", style); } catch (BadLocationException e) { logger.error("Insert in the HTMLDocument failed.", e); } } }
Example #23
Source File: ChatConversationPanel.java From jitsi with Apache License 2.0 | 4 votes |
/** * Deletes all messages "div"s that are missing their header the table tag. * The method calls itself recursively. */ private void deleteAllMessagesWithoutHeader() { String[] ids = new String[] {ChatHtmlUtils.MESSAGE_TEXT_ID, "statusMessage", "systemMessage", "actionMessage"}; Element firstMsgElement = findElement(Attribute.ID, ids); if(firstMsgElement == null || !firstMsgElement.getName().equals("div")) { return; } int startIndex = firstMsgElement.getStartOffset(); int endIndex = firstMsgElement.getEndOffset(); try { // Remove the message. if(endIndex - startIndex < document.getLength()) this.document.remove(startIndex, endIndex - startIndex); else { // currently there is a problem of deleting the last message // if it is the last message on the view return; } } catch (BadLocationException e) { logger.error("Error removing messages from chat: ", e); return; } deleteAllMessagesWithoutHeader(); }
Example #24
Source File: FSwingHtml.java From pra with MIT License | 4 votes |
public static boolean hasAttribute(Element e, Attribute ab, String value){ return e.getAttributes().containsAttribute( ab,value); }
Example #25
Source File: FSwingHtml.java From pra with MIT License | 4 votes |
public static String getID(Element e){ return getAttribute(e,HTML.Attribute.ID); }
Example #26
Source File: TxtElementExtractor.java From pra with MIT License | 4 votes |
public Node newName( String value, CallBack f){ return newChild(HTML.Attribute.NAME,value,f); }
Example #27
Source File: FSwingHtml.java From pra with MIT License | 4 votes |
public static boolean hasName(Element e, String name){ return e.getAttributes().containsAttribute(Attribute.NAME,name); }
Example #28
Source File: TxtElementExtractor.java From pra with MIT License | 4 votes |
public Node newClass( String value, CallBack f){ return newChild(HTML.Attribute.CLASS,value,f); }
Example #29
Source File: TxtElementExtractor.java From pra with MIT License | 4 votes |
public Node newChild(Attribute ab, String value){ return newChild(ab,value,null); }
Example #30
Source File: TxtElementExtractor.java From pra with MIT License | 4 votes |
public Node newChild(Attribute ab, String value, CallBack f){ Node n= new Node(ab,value,f); vnC.add(n); return n; }