org.openide.cookies.EditorCookie.getOpenedPanes()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(107)

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

EditorCookie.getOpenedPanes介绍

[英]Get a list of all editor panes opened on this object. The first item in the array should represent the component that is currently selected or that was most recently selected. (Typically, multiple panes will only be open as a result of cloning the editor component.)

The resulting panes are useful for a range of tasks; most commonly, getting the current cursor position or text selection, including the Caret object.

This method may also be used to test whether an object is already open in an editor, without actually opening it.
[中]获取在此对象上打开的所有编辑器窗格的列表。数组中的第一项应表示当前选定或最近选定的组件。(通常,多个窗格仅在克隆编辑器组件后才会打开。)
生成的窗格可用于一系列任务;最常见的是获取当前光标位置或文本选择,包括Caret对象。
此方法还可用于测试对象是否已在编辑器中打开,而不实际打开它。

代码示例

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-languages

public void run () {
    if (ec.getOpenedPanes () != null && 
      ec.getOpenedPanes ().length > 0
    ) 
      setCurrentEditor (ec.getOpenedPanes () [0]);
    else
      setCurrentEditor (null);
  }
});

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-languages

public JTextComponent getJTextComponent () {
  if (component == null) {
    DataObject dob = NbEditorUtilities.getDataObject (doc);
    EditorCookie ec = dob.getLookup ().lookup (EditorCookie.class);
    if (ec.getOpenedPanes ().length > 0)
      component = ec.getOpenedPanes () [0];
  }
  return component;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-debugger-common2

private static JEditorPane getCurrentEditor(EditorCookie e) {
if (e == null)
  e = getCurrentEditorCookie();
if (e == null)
  return null;
JEditorPane[] op = e.getOpenedPanes();
if (op == null || op.length < 1)
  return null;
return op[0];
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-debugger-common2

public void propertyChange(PropertyChangeEvent evt) {
    if (EditorCookie.Observable.PROP_OPENED_PANES.equals(evt.getPropertyName())) {
      if (editorCookie.getOpenedPanes() == null) {
        opened = false;
        ((EditorCookie.Observable)editorCookie).removePropertyChangeListener(this);
      }
    }
  }
});

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-project

private int getOffset(EditorCookie editorCookie) {
    if (editorCookie == null) {
      return DEFAULT_OFFSET;
    }
    JEditorPane[] openedPanes = editorCookie.getOpenedPanes();
    if (openedPanes == null || openedPanes.length == 0) {
      return DEFAULT_OFFSET;
    }
    return openedPanes[0].getCaretPosition();
  }
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-languages

private JEditorPane getCurrentEditor () {
  Node[] ns = TopComponent.getRegistry ().getActivatedNodes ();
  if (ns.length != 1) return null;
  EditorCookie editorCookie = ns [0].getLookup ().
    lookup (EditorCookie.class);
  if (editorCookie == null) return null;
  if (editorCookie.getOpenedPanes () == null) return null;
  if (editorCookie.getOpenedPanes ().length < 1) return null;
  return editorCookie.getOpenedPanes () [0];
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-languages

public JTextComponent getJTextComponent () {
  if (component == null) {
    DataObject dob = NbEditorUtilities.getDataObject (doc);
    EditorCookie ec = dob.getLookup ().lookup (EditorCookie.class);
    if (ec.getOpenedPanes ().length > 0)
      component = ec.getOpenedPanes () [0];
  }
  return component;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-core

public javax.swing.JEditorPane[] getOpenedPanes() {
  return currentEditorCookie().getOpenedPanes();
}

代码示例来源:origin: org.netbeans.api/org-openide-text

/**
 * Gets recently selected editor pane opened by editor cookie
 * Can be called from AWT event thread only.
 *
 * @param ec EditorCookie used to find out recently selected editor pane
 * @return pane or null
 *
 * @since 6.24
 *
 */
public static JEditorPane findRecentEditorPane (EditorCookie ec) {
  // expected in AWT only
  assert SwingUtilities.isEventDispatchThread()
      : "NbDocument.findInitializedPaneForActiveTC must be called from AWT thread only"; // NOI18N
  if (ec instanceof CloneableEditorSupport) {
    // find if initialized or return null immediately
    JEditorPane pane = ((CloneableEditorSupport) ec).getRecentPane();
    return pane;
  } else {
    JEditorPane [] panes = ec.getOpenedPanes();
    if (panes != null) {
      return panes[0];
    }
    return null;
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-css-prep

private static boolean isFromEditor(EditorCookie ec) {
  if (ec != null && ec.getOpenedPanes() != null) {
    TopComponent activetc = TopComponent.getRegistry().getActivated();
    if (activetc instanceof CloneableEditorSupport.Pane) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-editor

public static boolean isFromEditor(EditorCookie ec) {
  if (ec != null && ec.getOpenedPanes() != null) {
    TopComponent activetc = TopComponent.getRegistry().getActivated();
    if (activetc instanceof CloneableEditorSupport.Pane) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-javascript-refactoring

private static boolean isFromEditor(EditorCookie ec) {
    if (ec != null && ec.getOpenedPanes() != null) {
      TopComponent activetc = TopComponent.getRegistry().getActivated();
      if (activetc instanceof CloneableEditorSupport.Pane) {
        return true;
      }
    }
    return false;
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-css-prep

public TextComponentTask(EditorCookie ec) {
  JTextComponent textC = ec.getOpenedPanes()[0];
  this.document = textC.getDocument();
  this.caretOffset = textC.getCaretPosition();
  this.selectionStart = textC.getSelectionStart();
  this.selectionEnd = textC.getSelectionEnd();
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-javascript-refactoring

public TextComponentTask(EditorCookie ec) {
  this.textC = ec.getOpenedPanes()[0];
  this.caret = textC.getCaretPosition();
  this.start = textC.getSelectionStart();
  this.end = textC.getSelectionEnd();
  assert caret != -1;
  assert start != -1;
  assert end != -1;
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-languages

public void run() {
    Iterator it = TopComponent.getRegistry ().getOpened ().iterator ();
    while (it.hasNext ()) {
      TopComponent tc = (TopComponent) it.next ();
      EditorCookie ec = tc.getLookup ().lookup (EditorCookie.class);
      if (ec == null) continue;
      JEditorPane[] eps = ec.getOpenedPanes ();
      if (eps == null) continue;
      int i, k = eps.length;
      for (i = 0; i < k; i++) {
        if (eps [i].getDocument () == doc) {
          final JEditorPane ep = eps [i];
          if (ep != null)
            try {
              ep.scrollRectToVisible (ep.modelToView (offset));
            } catch (BadLocationException ex) {
              ErrorManager.getDefault ().notify (ex);
            }
        }
      }
    }
  }
});

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

@Override
protected void performContextAction(Node[] nodes) {
  if (visible(nodes)) {
    JEditorPane pane = activatedEditorPane(nodes);
    AnnotationBarManager.hideAnnotationBar(pane);
  } else {
    EditorCookie ec = activatedEditorCookie(nodes);
    if (ec == null) return;
    final File file = activatedFile(nodes);
    JEditorPane[] panes = ec.getOpenedPanes();
    if (panes == null) {
      ec.open();
      panes = ec.getOpenedPanes();
    }
    if (panes == null) {
      return;
    }
    final JEditorPane currentPane = panes[0];
    showAnnotations(currentPane, file, null, true);
  }
}

代码示例来源:origin: dcaoyuan/nbscala

/** Add the line offset into the jump history */
private void addPositionToJumpList(String url, Line l, int column) {
  DataObject dataObject = getDataObject(url);
  if (dataObject != null) {
    EditorCookie ec = dataObject.getLookup().lookup(EditorCookie.class);
    if (ec != null) {
      try {
        StyledDocument doc = ec.openDocument();
        JEditorPane[] eps = ec.getOpenedPanes();
        if (eps != null && eps.length > 0) {
          JumpList.addEntry(eps[0], NbDocument.findLineOffset(doc, l.getLineNumber()) + column);
        }
      } catch (java.io.IOException ioex) {
        ErrorManager.getDefault().notify(ioex);
      }
    }
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-debugger-jpda-projectsui

/** Add the line offset into the jump history */
private void addPositionToJumpList(String url, Line l, int column) {
  DataObject dataObject = getDataObject (url);
  if (dataObject != null) {
    EditorCookie ec = dataObject.getLookup().lookup(EditorCookie.class);
    if (ec != null) {
      try {
        StyledDocument doc = ec.openDocument();
        JEditorPane[] eps = ec.getOpenedPanes();
        if (eps != null && eps.length > 0) {
          JumpList.addEntry(eps[0], NbDocument.findLineOffset(doc, l.getLineNumber()) + column);
        }
      } catch (java.io.IOException ioex) {
        ErrorManager.getDefault().notify(ioex);
      }
    }
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-debugger-jpda-projects

/** Add the line offset into the jump history */
private void addPositionToJumpList(String url, Line l, int column) {
  DataObject dataObject = getDataObject (url);
  if (dataObject != null) {
    EditorCookie ec = dataObject.getLookup().lookup(EditorCookie.class);
    if (ec != null) {
      try {
        StyledDocument doc = ec.openDocument();
        JEditorPane[] eps = ec.getOpenedPanes();
        if (eps != null && eps.length > 0) {
          JumpList.addEntry(eps[0], NbDocument.findLineOffset(doc, l.getLineNumber()) + column);
        }
      } catch (java.io.IOException ioex) {
        ErrorManager.getDefault().notify(ioex);
      }
    }
  }
}

代码示例来源:origin: AlexFalappa/nb-springboot

@Override
  public void valueChanged(ListSelectionEvent event) {
    final int selectedRow = ((ListSelectionModel) event.getSource()).getMinSelectionIndex();
    if (event.getValueIsAdjusting() || selectedRow < 0) {
      return;
    }
    final MappedElement mappedElement = mappedElementsModel.getElementAt(table.convertRowIndexToModel(selectedRow));
    ElementOpen.open(mappedElement.getFileObject(), mappedElement.getHandle());
    try {
      final DataObject dataObject = DataObject.find(mappedElement.getFileObject());
      final EditorCookie editorCookie = dataObject.getLookup().lookup(EditorCookie.class);
      if (editorCookie != null) {
        editorCookie.openDocument();
        JEditorPane[] p = editorCookie.getOpenedPanes();
        if (p.length > 0) {
          p[0].requestFocus();
        }
      }
    } catch (IOException e) {
    }
  }
});

相关文章