javax.swing.text.html.HTML.Tag Java Examples

The following examples show how to use javax.swing.text.html.HTML.Tag. 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: GHelpHTMLEditorKit.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/** Generates a new event with a URL based upon Ghidra's resources if needed. */
private HyperlinkEvent maybeCreateNewHyperlinkEventWithUpdatedURL(HyperlinkEvent event) {
	Element element = event.getSourceElement();
	if (element == null) {
		return event;// this shouldn't happen since we were triggered from an A tag
	}

	AttributeSet a = element.getAttributes();
	AttributeSet anchor = (AttributeSet) a.getAttribute(HTML.Tag.A);
	if (anchor == null) {
		return event;// this shouldn't happen since we were triggered from an A tag
	}

	String HREF = (String) anchor.getAttribute(HTML.Attribute.HREF);
	Msg.trace(this, "HREF of <a> tag: " + HREF);
	URL newUrl = getURLForHREFFromResources(HREF);
	if (newUrl == null) {
		return event;// unable to locate a resource by the name--bad link!
	}

	return new HyperlinkEvent(event.getSource(), event.getEventType(), newUrl,
		event.getDescription(), event.getSourceElement());
}
 
Example #2
Source File: GHelpHTMLEditorKit.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public View create(Element e) {

	AttributeSet attributes = e.getAttributes();
	Object elementName = attributes.getAttribute(AbstractDocument.ElementNameAttribute);
	if (elementName != null) {
		// not an HTML element
		return super.create(e);
	}

	Object html = attributes.getAttribute(StyleConstants.NameAttribute);
	if (html instanceof HTML.Tag) {
		HTML.Tag tag = (Tag) html;
		if (tag == HTML.Tag.IMG) {
			return new GHelpImageView(e);
		}
	}

	return super.create(e);
}
 
Example #3
Source File: JEditorPaneTagJavaElement.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public int getTextIndex() {
    return EventQueueWait.exec(new Callable<Integer>() {
        @Override
        public Integer call() throws Exception {
            String href = getText();
            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;
                }
                String attribute = ((HTMLDocument) ((JEditorPane) parent.getComponent()).getDocument())
                        .getText(iterator.getStartOffset(), iterator.getEndOffset() - iterator.getStartOffset());
                if (attribute != null && attribute.equals(href)) {
                    hRefIndex++;
                }
                iterator.next();
            }
            return -1;
        }
    });
}
 
Example #4
Source File: JEditorPaneJavaElement.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
private List<IJavaElement> selectByProperties(final ArrayList<IJavaElement> r, JSONObject o) {
    final Properties p;
    if (o.has("select")) {
        String spec = o.getString("select");
        if (!spec.startsWith("text=") && !spec.startsWith("link=")) {
            int pos = Integer.parseInt(spec);
            return Arrays.asList((IJavaElement) new JEditorPanePosJavaElement(this, pos));
        }
        p = parseSelectProperties(spec);
    } else {
        p = PropertyHelper.asProperties(o);
    }
    EventQueueWait.exec(new Runnable() {
        @Override
        public void run() {
            fillElements(Tag.A, r, new PropertyPredicate(p));
        }
    });
    return r;
}
 
Example #5
Source File: JEditorPaneTagJavaElement.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
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 #6
Source File: JEditorPaneJavaElement.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private void fillElements(Tag tag, ArrayList<IJavaElement> r, Predicate predicate) {
    HTMLDocument document = (HTMLDocument) ((JEditorPane) getComponent()).getDocument();
    Iterator iterator = document.getIterator(tag);
    int index = 0;
    while (iterator.isValid()) {
        JEditorPaneTagJavaElement e = new JEditorPaneTagJavaElement(this, tag, index++);
        if (predicate.isValid(e)) {
            r.add(e);
        }
        iterator.next();
    }
}
 
Example #7
Source File: JEditorPaneJavaElement.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private Tag findTag(String tagName) {
    for (Tag tag : allTags) {
        if (tagName.toUpperCase().equals(tag.toString().toUpperCase())) {
            return tag;
        }
    }
    return null;
}
 
Example #8
Source File: HTMLSuiteResult.java    From selenium with Apache License 2.0 5 votes vote down vote up
@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 #9
Source File: JEditorPaneTagJavaElement.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public JEditorPaneTagJavaElement(JEditorPaneJavaElement parent, Tag tag, int index) {
    super(parent);
    this.parent = parent;
    this.tag = tag;
    this.index = index;
}
 
Example #10
Source File: ClientResponseParser.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
public void handleStartTag(Tag t, MutableAttributeSet a, int p) {
}
 
Example #11
Source File: ClientResponseParser.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
public void handleStartTag(Tag t, MutableAttributeSet a, int p) {
}
 
Example #12
Source File: ClientResponseParser.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
public void handleStartTag(Tag t, MutableAttributeSet a, int p) {
}
 
Example #13
Source File: ChatHtmlUtils.java    From jitsi with Apache License 2.0 4 votes vote down vote up
/**
 * Creates an incoming message tag.
 *
 * @param messageID the identifier
 * @param contactName the name of the contact sending the message
 * @param contactDisplayName the display name of the contact sending the
 * message
 * @param avatarPath the path to the avatar file
 * @param date the date, when the message was sent
 * @param message the message content
 * @param contentType the content type HTML or PLAIN_TEXT
 * @param isHistory indicates if this is a message coming from history
 * @return the created incoming message tag
 */
private static String createSimpleIncomingMessageTag(
    String messageID,
    String contactName,
    String contactDisplayName,
    String avatarPath,
    Date date,
    String message,
    String contentType,
    boolean isHistory)
{
    StringBuilder headerBuffer = new StringBuilder();


    SimpleDateFormat sdf = new SimpleDateFormat(HistoryService.DATE_FORMAT);
    headerBuffer.append("<h2 id=\"").append(MESSAGE_HEADER_ID).append("\" ");
    headerBuffer.append(DATE_ATTRIBUTE).append("=\"")
        .append(sdf.format(date)).append("\">");
    headerBuffer.append("<a style=\"color:");
    headerBuffer.append(MSG_IN_NAME_FOREGROUND).append(";");
    headerBuffer.append("font-weight:bold;");
    headerBuffer.append("text-decoration:none;\" ");
    headerBuffer.append("href=\"").append(contactName).append("\">");
    headerBuffer.append(
        contactDisplayName).append(createEditedAtTag(messageID, -1));
    headerBuffer.append("</a>");
    headerBuffer.append("</h2>");

    final StringBuilder messageBuff = new StringBuilder();

    messageBuff.append("<table width=\"100%\" ");
    messageBuff.append(NAME_ATTRIBUTE).append("=\"")
        .append(Tag.TABLE.toString())
        .append("\" id=\"messageHeader\" ");
    messageBuff.append("style=\"background-color:");
    messageBuff.append(MSG_NAME_BACKGROUND).append(";\">");
    messageBuff.append("<tr>");
    messageBuff.append("<td align=\"left\" >");
    messageBuff.append(headerBuffer.toString());
    messageBuff.append("</td>");
    messageBuff.append("<td align=\"right\"><h2>");
    messageBuff.append(getDateString(date))
        .append(GuiUtils.formatTime(date));
    messageBuff.append("</h2></td>");
    messageBuff.append("</tr>");
    messageBuff.append("</table>");
    messageBuff.append(
        createSimpleMessageTag( messageID,
                                contactName,
                                message,
                                contentType,
                                date,
                                false,
                                isHistory));

    return messageBuff.toString();
}
 
Example #14
Source File: ChatHtmlUtils.java    From jitsi with Apache License 2.0 4 votes vote down vote up
/**
 * Create an outgoing message tag.
 *
 * @param messageID the identifier of the message
 * @param contactName the name of the account sending the message
 * @param contactDisplayName the display name of the account sending the
 * message
 * @param avatarPath the path to the avatar image
 * @param date the date, when the message was sent
 * @param message the content of the message
 * @param contentType the content type HTML or PLAIN_TEXT
 * @param isHistory indicates if this is a message coming from history
 * @return the created outgoing message tag
 */
private static String createSimpleOutgoingMessageTag( String messageID,
                                                String contactName,
                                                String contactDisplayName,
                                                String avatarPath,
                                                Date date,
                                                String message,
                                                String contentType,
                                                boolean isHistory)
{
    StringBuilder headerBuffer = new StringBuilder();


    SimpleDateFormat sdf = new SimpleDateFormat(HistoryService.DATE_FORMAT);
    headerBuffer.append("<h3 id=\"").append(MESSAGE_HEADER_ID).append("\" ");
    headerBuffer.append(DATE_ATTRIBUTE).append("=\"")
        .append(sdf.format(date)).append("\">");
    headerBuffer.append("<a style=\"color:#535353;");
    headerBuffer.append("font-weight:bold;");
    headerBuffer.append("text-decoration:none;\" ");
    headerBuffer.append("href=\"").append(contactName).append("\">");
    headerBuffer.append(contactDisplayName)
        .append(createEditedAtTag(messageID, -1));
    headerBuffer.append("</a>");
    headerBuffer.append("</h3>");

    StringBuffer messageBuff = new StringBuffer();

    messageBuff.append("<table width=\"100%\" ");
    messageBuff.append(NAME_ATTRIBUTE).append("=\"")
        .append(Tag.TABLE.toString())
        .append("\" id=\"messageHeader\"");
    messageBuff.append("style=\"background-color:");
    messageBuff.append(MSG_NAME_BACKGROUND).append(";\">");
    messageBuff.append("<tr>");
    messageBuff.append("<td align=\"left\" >");
    messageBuff.append(headerBuffer.toString());
    messageBuff.append("</td>");
    messageBuff.append("<td align=\"right\"><h3>");
    messageBuff.append(getDateString(date))
        .append(GuiUtils.formatTime(date));
    messageBuff.append("</h3></td>");
    messageBuff.append("</tr>");
    messageBuff.append("</table>");
    messageBuff.append(
        createSimpleMessageTag( messageID,
                                contactName,
                                message,
                                contentType,
                                date,
                                false,
                                isHistory));

    return messageBuff.toString();
}