本文整理匯總了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);
}
}
示例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));
}
}
示例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();
}
}
示例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);
}
}
示例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;
}