当前位置: 首页>>代码示例>>Java>>正文


Java JPopupMenu.getComponent方法代码示例

本文整理汇总了Java中javax.swing.JPopupMenu.getComponent方法的典型用法代码示例。如果您正苦于以下问题:Java JPopupMenu.getComponent方法的具体用法?Java JPopupMenu.getComponent怎么用?Java JPopupMenu.getComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JPopupMenu的用法示例。


在下文中一共展示了JPopupMenu.getComponent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPopupMenuItem

import javax.swing.JPopupMenu; //导入方法依赖的package包/类
/**
 * Returns the index of an item in a popup menu.
 * 
 * @param menu  the menu.
 * @param text  the label.
 * 
 * @return The item index.
 */
private int getPopupMenuItem(JPopupMenu menu, String text) {
    int index = -1;
    for (int i = 0; (index == -1) && (i < menu.getComponentCount()); i++) {
        Component comp = menu.getComponent(i);
        if (comp instanceof JMenuItem) {
            JMenuItem item = (JMenuItem) comp;
            if (text.equals(item.getText())) {
                index = i;
            }
        }
   }
   return index;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:22,代码来源:PolarChartPanel.java

示例2: actionPerformed

import javax.swing.JPopupMenu; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent evt){
  if(annotationEditor == null) return;
  //this action either creates a new annotation or starts editing an 
  //existing one. In either case we need first to make sure that the current
  //annotation is finished editing.
  if(!annotationEditor.editingFinished()) return;
  if(textLocation == -1) return;
  JPopupMenu popup = new JPopupMenu();

  //check for selection hovering
  if(textPane.getSelectedText() != null
      && textPane.getSelectionStart() <= textLocation
      && textPane.getSelectionEnd() >= textLocation){
    //add 'New annotation' to the popup menu
    popup.add(new NewAnnotationAction(textPane.getSelectedText()));
    popup.addSeparator();
  }

  //check for annotations at location
  for(SetHandler setHandler : setHandlers) {
    for(Annotation ann : setHandler.set.get(
          Math.max(0l, textLocation-1),
          Math.min(document.getContent().size(), textLocation+1))) {
      if(setHandler.getTypeHandler(ann.getType()).isSelected()) {
        AnnotationDataImpl annotAtPoint =
          new AnnotationDataImpl(setHandler.set, ann);
        //add annotations to edit to the popup menu
        popup.add(new HighlightMenuItem(
          new EditAnnotationAction(annotAtPoint),
          annotAtPoint.getAnnotation().getStartNode().getOffset().intValue(),
          annotAtPoint.getAnnotation().getEndNode().getOffset().intValue(),
          popup));
      }
    }
  }

  if (popup.getComponentCount() == 0) {
    // nothing to do
  } else if(popup.getComponentCount() == 1
    || (popup.getComponentCount() == 2
     && popup.getComponent(1) instanceof JSeparator)) {
    //only one annotation, start the editing directly
    //or only one selection, add new annotation
    ((JMenuItem)popup.getComponent(0)).getAction().actionPerformed(evt);
  } else { //mouse hover a selection AND annotation(s)
    try{
      Rectangle rect =  textPane.modelToView(textLocation);
      //display the popup
      popup.show(textPane, rect.x + 10, rect.y);
    }catch(BadLocationException ble){
      throw new GateRuntimeException(ble);
    }
  }
}
 
开发者ID:GateNLP,项目名称:gate-core,代码行数:56,代码来源:AnnotationSetsView.java


注:本文中的javax.swing.JPopupMenu.getComponent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。