javax.swing.JTextPane.viewToModel()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(134)

本文整理了Java中javax.swing.JTextPane.viewToModel()方法的一些代码示例,展示了JTextPane.viewToModel()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextPane.viewToModel()方法的具体详情如下:
包路径:javax.swing.JTextPane
类名称:JTextPane
方法名:viewToModel

JTextPane.viewToModel介绍

暂无

代码示例

代码示例来源:origin: apache/pdfbox

@Override
public void mouseMoved(MouseEvent mouseEvent)
{
  if (tTController != null)
  {
    int offset = textPane.viewToModel(mouseEvent.getPoint());
    textPane.setToolTipText(tTController.getToolTip(offset, textPane));
  }
}

代码示例来源:origin: org.apache.uima/uimaj-tools

@Override
public void mouseClicked(MouseEvent e) {
 int pos = textPane.viewToModel(e.getPoint());
 updateSelectedAnnotationTree(pos);
}

代码示例来源:origin: edu.utah.bmi.nlp/nlp-core

public void mouseClicked(MouseEvent e) {
  int pos = textPane.viewToModel(e.getPoint());
  updateSelectedAnnotationTree(pos);
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-team-commons

private Element element(MouseEvent e) {
  JTextPane pane = (JTextPane)e.getSource();
  StyledDocument doc = pane.getStyledDocument();
  return doc.getCharacterElement(pane.viewToModel(e.getPoint()));
}
private void showMenu(MouseEvent e) {

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-team-commons

private Element element(MouseEvent e) {
  JTextPane pane = (JTextPane)e.getSource();
  StyledDocument doc = pane.getStyledDocument();
  return doc.getCharacterElement(pane.viewToModel(e.getPoint()));
}

代码示例来源:origin: org.gosu-lang.gosu/gosu-lab

private SourceFileAttribute getLinkAtCursor( MouseEvent e )
{
 int caret = _outputPanel.viewToModel( e.getPoint() );
 Element elem = getElementAt( caret );
 if( elem != null )
 {
  return (SourceFileAttribute)((AbstractDocument.LeafElement)elem).getAttribute( HTML.Tag.A );
 }
 return null;
}

代码示例来源:origin: otros-systems/otroslogviewer

private AttributeSet getStyleUnderCursor(MouseEvent e) {
  int i = textPane.viewToModel(e.getPoint());
  return textPane.getStyledDocument().getCharacterElement(i).getAttributes();
 }
}

代码示例来源:origin: Vhati/Slipstream-Mod-Manager

private void showMenu( MouseEvent e ) {
    AttributeSet tmpAttr = doc.getCharacterElement( textPane.viewToModel( e.getPoint() ) ).getAttributes();
    Object targetObj = tmpAttr.getAttribute( ATTR_HYPERLINK_TARGET );
    if ( targetObj != null ) {  // Link menu.
      textPane.requestFocus();
      lastClickedLinkTarget = targetObj.toString();
      int nx = e.getX();
      if ( nx > 500 ) nx = nx - linkPopup.getSize().width;
      linkPopup.show( e.getComponent(), nx, e.getY() - linkPopup.getSize().height );
      e.consume();
    }
  }
};

代码示例来源:origin: net.imagej/imagej-ui-swing

private ActionListener getAction(final MouseEvent event) {
  Element e = document.getCharacterElement(textPane.viewToModel(event.getPoint()));
  ActionListener action = (ActionListener)e.getAttributes().getAttribute(ACTION_ATTRIBUTE);
  return action;
}

代码示例来源:origin: Vhati/Slipstream-Mod-Manager

@Override
public void mouseClicked( MouseEvent e ) {
  if ( e.isConsumed() ) return;
  if ( !SwingUtilities.isLeftMouseButton( e ) ) return;
  AttributeSet tmpAttr = doc.getCharacterElement( textPane.viewToModel( e.getPoint() ) ).getAttributes();
  Object targetObj = tmpAttr.getAttribute( ATTR_HYPERLINK_TARGET );
  if ( targetObj != null ) {
    Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
    if ( desktop != null && desktop.isSupported( Desktop.Action.BROWSE ) ) {
      try {
        desktop.browse( new URI( targetObj.toString() ) );
      }
      catch ( Exception f ) {
        log.error( "Error browsing clicked url: "+ targetObj.toString(), f );
      }
    }
    e.consume();
  }
}

代码示例来源:origin: omegat-org/omegat

@Override
public void mouseClicked(final MouseEvent e) {
  if (e.getButton() == MouseEvent.BUTTON1) {
    final StyledDocument doc = jTextPane.getStyledDocument();
    final Element characterElement = doc.getCharacterElement(jTextPane.viewToModel(e.getPoint()));
    final AttributeSet as = characterElement.getAttributes();
    final Object attr = as.getAttribute(ATTR_LINK);
    if (attr instanceof IAttributeAction) {
      ((IAttributeAction) attr).execute();
    }
  } else {
    super.mouseClicked(e);
  }
}

代码示例来源:origin: omegat-org/omegat

@Override
  public void mouseMoved(final MouseEvent e) {
    final StyledDocument doc = jTextPane.getStyledDocument();
    final Element characterElement = doc.getCharacterElement(jTextPane.viewToModel(e.getPoint()));
    final AttributeSet as = characterElement.getAttributes();
    final Object attr = as.getAttribute(ATTR_LINK);
    if (attr instanceof IAttributeAction) {
      jTextPane.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    } else {
      jTextPane.setCursor(Cursor.getDefaultCursor());
    }
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-team-commons

@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));
    }
  }
};

代码示例来源:origin: protegeproject/protege

@Override
  public void mouseMoved(MouseEvent e) {
    int pos = previewText.viewToModel(e.getPoint());
    StyledDocument doc = previewText.getStyledDocument();
    Element element = doc.getCharacterElement(pos);
    AttributeSet addtributes = element.getAttributes();
    Style style = doc.getStyle((String) addtributes
        .getAttribute(StyleConstants.NameAttribute));
    previewText.setToolTipText(
        "Click to change the " + style.getName() + " color");
  }
});

代码示例来源:origin: protegeproject/protege

private static Style getStyleAtPoint(JTextPane text, Point point) {
  int pos = text.viewToModel(point);
  StyledDocument doc = text.getStyledDocument();
  Element element = doc.getCharacterElement(pos);
  AttributeSet addtributes = element.getAttributes();
  return doc.getStyle((String) addtributes
      .getAttribute(StyleConstants.NameAttribute));
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-team-commons

@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);
    }
  }
}

代码示例来源:origin: Vhati/Slipstream-Mod-Manager

@Override
public void mouseMoved( MouseEvent e ) {
  AttributeSet tmpAttr = doc.getCharacterElement( textPane.viewToModel( e.getPoint() ) ).getAttributes();
  Object targetObj = tmpAttr.getAttribute( ATTR_HYPERLINK_TARGET );
  if ( targetObj != null ) {
    textPane.setCursor( linkCursor );
    if ( statusbar != null )
      statusbar.setStatusText( targetObj.toString() );
    wasOverLink = true;
  }
  else {
    if ( wasOverLink ) {
      textPane.setCursor( defaultCursor );
      if ( statusbar != null )
        statusbar.setStatusText( "" );
    }
    wasOverLink = false;
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-team-commons

@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();
        UrlAction urlAction = (UrlAction) as.getAttribute(HyperlinkSupport.URL_ATTRIBUTE);
        if (urlAction != null) {
          int startOffset = elem.getStartOffset();
          int endOffset = elem.getEndOffset();
          int length = endOffset - startOffset;
          String hyperlinkText = doc.getText(startOffset, length);
          urlAction.openUrlHyperlink(hyperlinkText);
          return;
        }
      }
    } catch (Exception ex) {
      Support.LOG.log(Level.SEVERE, null, ex);
    }
  }
};

代码示例来源:origin: protegeproject/protege

@Override
  public void mouseClicked(MouseEvent e) {
    int pos = previewText.viewToModel(e.getPoint());
    Style style = getStyleAtPoint(previewText, e.getPoint());
    Color color = StyleConstants.getForeground(style);
    try {
      int rowStart = getStyleStart(previewText, pos, style);
      int rowEnd = getStyleEnd(previewText, pos, style);
      colorPreview_.setText(previewText.getStyledDocument()
          .getText(rowStart, rowEnd - rowStart));
    } catch (BadLocationException e1) {
      LOGGER_.error("Error creating message preview", e1);
    }
    JOptionPane op = new JOptionPane(colorChooser_,
        JOptionPane.PLAIN_MESSAGE,
        JOptionPane.OK_CANCEL_OPTION);
    JDialog dlg = op.createDialog(previewText, "Choose Text Color");
    dlg.setLocationRelativeTo(previewText);
    colorChooser_.setColor(color);
    dlg.setVisible(true);
    if (op.getValue() != null) {
      color = colorChooser_.getColor();
      StyleConstants.setForeground(style, color);
      refreshPreview();
    }
  }
});

代码示例来源:origin: blurpy/kouchat

/**
 * Updates the mouse cursor when hovering over a link.
 *
 * {@inheritDoc}
 */
@Override
public void mouseMoved(final MouseEvent e) {
  final int mousePos = textPane.viewToModel(e.getPoint());
  final AttributeSet attr = doc.getCharacterElement(mousePos).getAttributes();
  if (StyleConstants.isUnderline(attr)) {
    if (textPane.getCursor() != handCursor) {
      textPane.setCursor(handCursor);
    }
  }
  else {
    if (textPane.getCursor() == handCursor) {
      textPane.setCursor(null);
    }
  }
}

相关文章

JTextPane类方法