本文整理汇总了Java中org.netbeans.api.editor.EditorRegistry.lastFocusedComponent方法的典型用法代码示例。如果您正苦于以下问题:Java EditorRegistry.lastFocusedComponent方法的具体用法?Java EditorRegistry.lastFocusedComponent怎么用?Java EditorRegistry.lastFocusedComponent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.api.editor.EditorRegistry
的用法示例。
在下文中一共展示了EditorRegistry.lastFocusedComponent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: propertyChange
import org.netbeans.api.editor.EditorRegistry; //导入方法依赖的package包/类
public void propertyChange(PropertyChangeEvent e) {
JTextComponent active = EditorRegistry.lastFocusedComponent();
if (getComponent() != active) {
removeHints();
setComponent(active);
if (getComponent() != null) {
getComponent().removeFocusListener(this);
}
if (active != null) {
active.addFocusListener(this);
}
}
}
示例2: implement
import org.netbeans.api.editor.EditorRegistry; //导入方法依赖的package包/类
@Override
public ChangeInfo implement() throws Exception {
final FileObject file = handle.getFileObject();
final JTextComponent comp = EditorRegistry.lastFocusedComponent();
if (file != null && file == getFileObject(comp)) {
final int[] pos = new int[]{-1};
JavaSource.forFileObject(file).runUserActionTask(new Task<CompilationController>(){
@Override
public void run(CompilationController info) throws Exception {
info.toPhase(JavaSource.Phase.PARSED);
final TreePath tp = handle.resolve(info);
if (tp != null && tp.getLeaf().getKind() == Tree.Kind.VARIABLE) {
pos[0] = (int) info.getTrees().getSourcePositions().getEndPosition(
tp.getCompilationUnit(),
((VariableTree)tp.getLeaf()).getType()) + 1;
}
}
}, true);
invokeRefactoring (comp, pos[0]);
}
return null;
}
示例3: implement
import org.netbeans.api.editor.EditorRegistry; //导入方法依赖的package包/类
@Override
public ChangeInfo implement() throws Exception {
final FileObject file = handle.getFileObject();
final JTextComponent component = EditorRegistry.lastFocusedComponent();
if (file != null && file == getFileObject(component)) {
final int[] position = new int[] {-1};
JavaSource.forFileObject(file).runUserActionTask(new Task<CompilationController>() {
@Override
public void run(CompilationController controller) throws Exception {
controller.toPhase(JavaSource.Phase.PARSED);
final TreePath tp = handle.resolve(controller);
if (tp != null && TreeUtilities.CLASS_TREE_KINDS.contains(tp.getLeaf().getKind())) {
position[0] = (int) controller.getTrees().getSourcePositions().getStartPosition(
tp.getCompilationUnit(),
(ClassTree)tp.getLeaf())+1;
}
}
}, true);
invokeRefactoring(component, position[0]);
}
return null;
}
示例4: insertSQL
import org.netbeans.api.editor.EditorRegistry; //导入方法依赖的package包/类
private void insertSQL() {
try {
JEditorPane pane = (JEditorPane) EditorRegistry.lastFocusedComponent();
String mime = pane.getContentType();
if (mime.equals(SQLDataLoader.SQL_MIME_TYPE)) {
editorPane = pane;
}
int min = sqlTableSelektion.getMinSelectionIndex();
int max = sqlTableSelektion.getMaxSelectionIndex();
for (int i = min; i <= max; i++) {
if (sqlHistoryTable.isRowSelected(i)) {
int modelIndex = sqlHistoryTable.convertRowIndexToModel(i);
String sql = ((String) htm.getValueAt(modelIndex, 1)).trim();
insertIntoDocument(sql, editorPane);
}
}
} catch (BadLocationException ex) {
Exceptions.printStackTrace(ex);
}
}
示例5: update
import org.netbeans.api.editor.EditorRegistry; //导入方法依赖的package包/类
void update () {
DefaultComboBoxModel model = new DefaultComboBoxModel();
for (String mimeType : controller.getMimeTypes()) {
model.addElement(mimeType);
}
languageCombo.setModel(model);
lastSelectedMimeType = controller.getSavedSelectedLanguage();
if (lastSelectedMimeType != null && model.getSize() > 0) {
languageCombo.setSelectedItem(lastSelectedMimeType);
return;
}
JTextComponent pane = EditorRegistry.lastFocusedComponent();
String preSelectMimeType = pane != null ? (String)pane.getDocument().getProperty("mimeType") : ""; // NOI18N
languageCombo.setSelectedItem(preSelectMimeType);
if (!preSelectMimeType.equals (languageCombo.getSelectedItem()) && model.getSize() > 0) {
languageCombo.setSelectedIndex(0);
}
}
示例6: getCurrentFile
import org.netbeans.api.editor.EditorRegistry; //导入方法依赖的package包/类
private JTextComponent getCurrentFile(int[] span) {
JTextComponent pane = EditorRegistry.lastFocusedComponent();
if (pane == null) return null;
Document doc = pane.getDocument();
Object stream = doc != null ? doc.getProperty(Document.StreamDescriptionProperty) : null;
if (!(stream instanceof DataObject))
return null;
if (!"text/x-java".equals(NbEditorUtilities.getMimeType(doc))) //NOI18N
return null;
TopComponent tc = TopComponent.getRegistry().getActivated();
Component c = pane;
while (c != null) {
if (c == tc) break;
c = c.getParent();
}
if (c == null) return null;
if (span != null) {
span[0] = pane.getSelectionStart();
span[1] = pane.getSelectionEnd();
if (span[0] == span[1] && requiresSelection())
return null;
}
return pane;
}
示例7: start
import org.netbeans.api.editor.EditorRegistry; //导入方法依赖的package包/类
public static void start() {
JTextComponent jtc = EditorRegistry.lastFocusedComponent();
doc = jtc != null ? Utilities.getDocument(jtc) : null;
if (doc != null) {
doc.addDocumentListener(listener);
}
modified = false;
active = true;
}
示例8: initialize
import org.netbeans.api.editor.EditorRegistry; //导入方法依赖的package包/类
public synchronized void initialize() {
EditorRegistry.addPropertyChangeListener(this);
JTextComponent newComponent = EditorRegistry.lastFocusedComponent();
currentDocument = newComponent != null ? newComponent.getDocument() : null;
if (currentDocument != null) {
currentDocument.addDocumentListener(this);
}
}
示例9: setSelector
import org.netbeans.api.editor.EditorRegistry; //导入方法依赖的package包/类
public void setSelector(OnSaveTabSelector selector) {
if (selector == null) {
storedMimeType = (String)cboLanguage.getSelectedItem();
}
if (this.selector != null) {
this.selector.removePropertyChangeListener(weakListener);
}
this.selector = selector;
if (this.selector != null) {
this.weakListener = WeakListeners.propertyChange(this, this.selector);
this.selector.addPropertyChangeListener(weakListener);
DefaultComboBoxModel model = new DefaultComboBoxModel();
String preSelectMimeType = null;
for (String mimeType : this.selector.getMimeTypes()) {
model.addElement(mimeType);
if (mimeType.equals(storedMimeType)) {
preSelectMimeType = mimeType;
}
}
cboLanguage.setModel(model);
// Pre-select a language
if (preSelectMimeType == null) {
JTextComponent pane = EditorRegistry.lastFocusedComponent();
preSelectMimeType = pane != null ? (String)pane.getDocument().getProperty("mimeType") : ""; // NOI18N
}
cboLanguage.setSelectedItem(preSelectMimeType);
if (!preSelectMimeType.equals(cboLanguage.getSelectedItem())) {
cboLanguage.setSelectedIndex(0);
}
} else {
cboLanguage.setModel(new DefaultComboBoxModel());
}
}
示例10: getHyperlinkSpan
import org.netbeans.api.editor.EditorRegistry; //导入方法依赖的package包/类
public int[] getHyperlinkSpan(Document doc, int offset) {
JTextComponent target = EditorRegistry.lastFocusedComponent();
final StyledDocument styledDoc = (StyledDocument) target.getDocument();
if (styledDoc == null) {
return null;
}
// Return the position, which was set in the isHyperlink method:
return new int[]{startOffset, endOffset};
}
示例11: isEnabled
import org.netbeans.api.editor.EditorRegistry; //导入方法依赖的package包/类
@Override
public boolean isEnabled() {
if (component != null) {
return true;
} else {
if (EditorRegistry.lastFocusedComponent() == null) {
return false;
} else {
return true;
}
}
}
示例12: getLastActiveComponent
import org.netbeans.api.editor.EditorRegistry; //导入方法依赖的package包/类
/** Returns last activated component. If the component was closed,
* then previous component is returned */
public static JTextComponent getLastActiveComponent() {
return EditorRegistry.lastFocusedComponent();
}
示例13: performGoto
import org.netbeans.api.editor.EditorRegistry; //导入方法依赖的package包/类
/** Perform the goto operation.
* @return whether the dialog should be made invisible or not
*/
protected boolean performGoto() {
JTextComponent c = EditorRegistry.lastFocusedComponent();
if (c != null) {
try {
int line = Integer.parseInt(getGotoValueText());
//issue 188976
if (line==0)
line = 1;
//end of issue 188976
BaseDocument doc = Utilities.getDocument(c);
if (doc != null) {
int rowCount = Utilities.getRowCount(doc);
if (line > rowCount)
line = rowCount;
// Obtain the offset where to jump
int pos = Utilities.getRowStartFromLineOffset(doc, line - 1);
BaseKit kit = Utilities.getKit(c);
if (kit != null) {
Action a = kit.getActionByName(ExtKit.gotoAction);
if (a instanceof ExtKit.GotoAction) {
pos = ((ExtKit.GotoAction)a).getOffsetFromLine(doc, line - 1);
}
}
if (pos != -1) {
Caret caret = c.getCaret();
caret.setDot(pos);
} else {
c.getToolkit().beep();
return false;
}
}
} catch (NumberFormatException e) {
c.getToolkit().beep();
return false;
}
}
return true;
}
示例14: propertyChange
import org.netbeans.api.editor.EditorRegistry; //导入方法依赖的package包/类
public void propertyChange(PropertyChangeEvent evt) {
if (EditorRegistry.FOCUS_GAINED_PROPERTY.equals(evt.getPropertyName())) {
JTextComponent focusedTextComponent = (JTextComponent) evt.getNewValue();
SearchableEditorKit oldActiveKit = activeKit();
EditorKit kit = null;
if (focusedTextComponent != null) {
TextUI ui = focusedTextComponent.getUI();
if (ui != null) {
kit = ui.getEditorKit(focusedTextComponent);
}
}
synchronized (PresenterEditorAction.class) {
SearchableEditorKit newActiveKit = (kit != null)
? EditorActionUtilities.getSearchableKit(kit)
: null;
boolean kitChanged;
if (newActiveKit != oldActiveKit) {
if (oldActiveKit != null) {
oldActiveKit.removeActionsChangeListener(actionsChangeListener);
}
activeKitRef = (newActiveKit != null)
? new WeakReference<SearchableEditorKit>(newActiveKit)
: null;
if (newActiveKit != null) {
newActiveKit.addActionsChangeListener(actionsChangeListener);
}
kitChanged = true;
} else {
kitChanged = false;
}
boolean focusChanged = (activeKitLastFocused == false);
activeKitLastFocused = true;
if (focusChanged || kitChanged) {
refreshActiveKitActions(newActiveKit, kitChanged);
}
}
} else if (EditorRegistry.FOCUS_LOST_PROPERTY.equals(evt.getPropertyName())) {
synchronized (PresenterEditorAction.class) {
boolean newActiveKitLastFocused = (EditorRegistry.lastFocusedComponent() != null);
if (newActiveKitLastFocused != activeKitLastFocused) {
activeKitLastFocused = newActiveKitLastFocused;
for (PresenterEditorAction a : presenterActions) {
a.refreshActiveKitAction(null, false);
}
}
}
}
}
示例15: createDocumentationTask
import org.netbeans.api.editor.EditorRegistry; //导入方法依赖的package包/类
@Override
public CompletionTask createDocumentationTask() {
return new AsyncCompletionTask(new JavaElementDocQuery(elemHandle), EditorRegistry.lastFocusedComponent());
}