当前位置: 首页>>代码示例>>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;未经允许,请勿转载。