當前位置: 首頁>>代碼示例>>Java>>正文


Java StyledDocument.getCharacterElement方法代碼示例

本文整理匯總了Java中javax.swing.text.StyledDocument.getCharacterElement方法的典型用法代碼示例。如果您正苦於以下問題:Java StyledDocument.getCharacterElement方法的具體用法?Java StyledDocument.getCharacterElement怎麽用?Java StyledDocument.getCharacterElement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.text.StyledDocument的用法示例。


在下文中一共展示了StyledDocument.getCharacterElement方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: mouseClicked

import javax.swing.text.StyledDocument; //導入方法依賴的package包/類
@Override
public void mouseClicked(MouseEvent e) {
    try {
        if (SwingUtilities.isLeftMouseButton(e)) {
            JTextPane pane = (JTextPane)e.getSource();
            StyledDocument doc = pane.getStyledDocument();
            Element elem = doc.getCharacterElement(pane.viewToModel(e.getPoint()));
            AttributeSet as = elem.getAttributes();
            Link link = (Link)as.getAttribute(LINK_ATTRIBUTE);
            if (link != null) {
                link.onClick(elem.getDocument().getText(elem.getStartOffset(), elem.getEndOffset() - elem.getStartOffset()));
            }
        }
    } catch(Exception ex) {
        Support.LOG.log(Level.SEVERE, null, ex);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:HyperlinkSupport.java

示例2: mouseMoved

import javax.swing.text.StyledDocument; //導入方法依賴的package包/類
@Override
public void mouseMoved(MouseEvent e) {
    JTextPane pane = (JTextPane)e.getSource();
    StyledDocument doc = pane.getStyledDocument();
    Element elem = doc.getCharacterElement(pane.viewToModel(e.getPoint()));
    AttributeSet as = elem.getAttributes();
    if (StyleConstants.isUnderline(as)) {
        pane.setCursor(new Cursor(Cursor.HAND_CURSOR));
    } else {
        pane.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:13,代碼來源:HyperlinkSupport.java

示例3: setVisible

import javax.swing.text.StyledDocument; //導入方法依賴的package包/類
@Override
public void setVisible(boolean b) {
    if (b) {
        JTextPane pane = (JTextPane) getInvoker();
        StyledDocument doc = pane.getStyledDocument();
        Element elem = doc.getCharacterElement(pane.viewToModel(clickPoint));
        Object l = elem.getAttributes().getAttribute(HyperlinkSupport.LINK_ATTRIBUTE);
        if (l != null && l instanceof AttachmentLink) {
            BugzillaIssue.Attachment attachment = ((AttachmentLink) l).attachment;
            if (attachment != null) {
                add(new JMenuItem(attachment.getOpenAction()));
                add(new JMenuItem(attachment.getSaveAction()));
                Action openInStackAnalyzerAction = attachment.getOpenInStackAnalyzerAction();
                if(openInStackAnalyzerAction != null) {
                    add(new JMenuItem(openInStackAnalyzerAction));
                }
                if (attachment.isPatch()) { 
                    Action a = attachment.getApplyPatchAction();
                    if(a != null) {
                        add(attachment.getApplyPatchAction());
                    }
                }
                super.setVisible(true);
            }
        }
    } else {
        super.setVisible(false);
        removeAll();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:31,代碼來源:CommentsPanel.java

示例4: onContentMouseReleasedEvent

import javax.swing.text.StyledDocument; //導入方法依賴的package包/類
protected void onContentMouseReleasedEvent(MouseEvent e)
{
	Point mousePoint = e.getPoint();
	mousePoint.x -= 0.5F;
	int index = this.textContent.viewToModel(mousePoint);

	if (index == -1) return;

	StyledDocument doc = this.getDocument();
	Element element = doc.getCharacterElement(index);

	LinkHandler handler = LinkHandler.getLinkHandler(element.getAttributes());

	if (handler != null)
	{
		int begin = element.getStartOffset();
		int end = element.getEndOffset();
		String string = null;
		try
		{
			string = doc.getText(begin, end - begin);
		}
		catch (BadLocationException ex)
		{
			ex.printStackTrace();
		}

		if (string == null) return;

		handler.execute(this, doc, string, begin, end, element);
	}
}
 
開發者ID:andykuo1,項目名稱:candlelight,代碼行數:33,代碼來源:Console.java

示例5: click

import javax.swing.text.StyledDocument; //導入方法依賴的package包/類
private boolean click(Point point)
{
	if (!this.canActionEvent) return false;

	point.x -= 0.5F;
	int index = this.pane.viewToModel(point);

	if (index == -1) return false;

	StyledDocument doc = this.pane.getStyledDocument();
	Element element = doc.getCharacterElement(index);

	ActionLink action = ActionLink.getActionFromAttributes(element.getAttributes());

	if (action != null)
	{
		int begin = element.getStartOffset();
		int end = element.getEndOffset();
		String string = null;
		try
		{
			string = doc.getText(begin, end - begin);
		}
		catch (BadLocationException ex)
		{
			ex.printStackTrace();
		}
		if (string == null) return false;

		ActionLinkEvent e = new ActionLinkEvent();
		e.console = this;
		e.action = action;
		e.document = doc;
		e.beginIndex = begin;
		e.endIndex = end;
		e.element = element;
		this.actionEvents.offer(e);
	}
	else
	{
		return false;
	}

	return true;
}
 
開發者ID:andykuo1,項目名稱:candlelight,代碼行數:46,代碼來源:Console.java


注:本文中的javax.swing.text.StyledDocument.getCharacterElement方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。