private static boolean _accept(final JComponent component) { if (!component.isEnabled() || !component.isVisible() || !component.isFocusable()) { return false; } /** TODO[anton,vova] implement Policy in Editor component instead */ if (component instanceof EditorComponentImpl || component instanceof EditorWindowHolder) { return true; } if(component instanceof JTextComponent){ return ((JTextComponent)component).isEditable(); } return component instanceof AbstractButton || component instanceof JList || component instanceof JTree || component instanceof JTable || component instanceof JComboBox; }
@Override protected void focusedComponentChanged(final Component component, final AWTEvent cause) { if (myWindowManager.getCommandProcessor().getCommandCount() > 0 || component == null) { return; } final KeyboardFocusManager mgr = KeyboardFocusManager.getCurrentKeyboardFocusManager(); final Component owner = mgr.getFocusOwner(); if (owner instanceof EditorComponentImpl && cause instanceof FocusEvent) { JFrame frame = WindowManager.getInstance().getFrame(myProject); Component oppositeComponent = ((FocusEvent)cause).getOppositeComponent(); if (oppositeComponent != null && UIUtil.getWindow(oppositeComponent) != frame) { return; } } IdeFocusManager.getInstance(myProject).doWhenFocusSettlesDown(new ExpirableRunnable.ForProject(myProject) { @Override public void run() { if (mgr.getFocusOwner() == owner) { activateEditorComponent(false); } } }); }
@Override public void update(AnActionEvent e) { final LookupEx lookup; if (myInput instanceof EditorTextField) { lookup = LookupManager.getActiveLookup(((EditorTextField)myInput).getEditor()); } else if (myInput instanceof EditorComponentImpl) { lookup = LookupManager.getActiveLookup(((EditorComponentImpl)myInput).getEditor()); } else { lookup = null; } JComboBox comboBox = UIUtil.findComponentOfType(myInput, JComboBox.class); boolean popupMenuVisible = comboBox != null && comboBox.isPopupVisible(); e.getPresentation().setEnabled(lookup == null && !popupMenuVisible); }
private static boolean _accept(final JComponent component) { if (!component.isEnabled() || !component.isVisible() || !component.isFocusable()) { return false; } /* TODO[anton,vova] implement Policy in Editor component instead */ if (component instanceof EditorComponentImpl || component instanceof EditorWindowHolder) { return true; } if (component instanceof JTextComponent) { return ((JTextComponent)component).isEditable(); } return component instanceof AbstractButton || component instanceof JList || component instanceof JTree || component instanceof JTable || component instanceof JComboBox; }
@Override protected void focusedComponentChanged(final Component component, final AWTEvent cause) { if (myCommandProcessor.getCommandCount() > 0 || component == null) { return; } final KeyboardFocusManager mgr = KeyboardFocusManager.getCurrentKeyboardFocusManager(); final Component owner = mgr.getFocusOwner(); if (owner instanceof EditorComponentImpl && cause instanceof FocusEvent) { JFrame frame = WindowManager.getInstance().getFrame(myProject); Component oppositeComponent = ((FocusEvent)cause).getOppositeComponent(); if (oppositeComponent != null && UIUtil.getWindow(oppositeComponent) != frame) { return; } } IdeFocusManager.getInstance(myProject).doWhenFocusSettlesDown(new ExpirableRunnable.ForProject(myProject) { @Override public void run() { if (mgr.getFocusOwner() == owner) { activateEditorComponent(); } } }); }
@Nullable private static Editor getEditorFromFocus() { final Component c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); if (c instanceof EditorComponentImpl) { return ((EditorComponentImpl)c).getEditor(); } return null; }
private static boolean moveFocusOnDelete() { final Window window = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow(); if (window != null) { final Component component = FocusTrackback.getFocusFor(window); if (component != null) { return component instanceof EditorComponentImpl; } return window instanceof IdeFrameImpl; } return true; }
@Nullable private static Editor getEditorFromFocus() { final Component c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); if (c instanceof EditorComponentImpl) { return ((EditorComponentImpl) c).getEditor(); } return null; }
private Point calculate_position(Component component, int imageWidth, int imageHeight) { Point p = new Point(); Rectangle rect = ((EditorComponentImpl) component).getVisibleRect(); int position_x = 0; switch (this.editorSetting.imageHorizonPositionNo) { // 右に表示 case 0: position_x = rect.x; break; // 中央に表示 case 1: position_x = rect.x + (rect.width - imageWidth) / 2; break; // 左に表示 case 2: position_x = rect.x + rect.width - imageWidth; break; } int position_y = 0; switch (this.editorSetting.imageVerticalPositionNo) { // 上に表示 case 0: position_y = rect.y; break; // 中央に表示 case 1: position_y = rect.y + (rect.height - imageHeight) / 2; break; // 下に表示 case 2: position_y = rect.y + rect.height - imageHeight; break; } p.setLocation(position_x, position_y); return p; }
@Override public Object getData(@NonNls String dataId) { if (myProject.isDisposed()) { throw new RuntimeException("TestDataProvider is already disposed for " + myProject + "\n" + "If you closed a project in test, please reset IdeaTestApplication.setDataProvider."); } if (PlatformDataKeys.PROJECT.is(dataId)) { return myProject; } else if (PlatformDataKeys.EDITOR.is(dataId) || OpenFileDescriptor.NAVIGATE_IN_EDITOR.is(dataId)) { return FileEditorManager.getInstance(myProject).getSelectedTextEditor(); } else { Editor editor = (Editor)getData(PlatformDataKeys.EDITOR.getName()); if (editor != null) { FileEditorManagerEx manager = FileEditorManagerEx.getInstanceEx(myProject); Object managerData = manager.getData(dataId, editor, manager.getSelectedFiles()[0]); if (managerData != null) { return managerData; } JComponent component = editor.getContentComponent(); if (component instanceof EditorComponentImpl) { return ((EditorComponentImpl)component).getData(dataId); } } return null; } }
@Override public void update(AnActionEvent e) { final LookupEx lookup; if (myInput instanceof EditorTextField) { lookup = LookupManager.getActiveLookup(((EditorTextField)myInput).getEditor()); } else if (myInput instanceof EditorComponentImpl) { lookup = LookupManager.getActiveLookup(((EditorComponentImpl)myInput).getEditor()); } else { lookup = null; } e.getPresentation().setEnabled(lookup == null); }
@Override public Object getData(@Nonnull Key<?> dataId) { if (myProject.isDisposed()) { throw new RuntimeException("TestDataProvider is already disposed for " + myProject + "\n" + "If you closed a project in test, please reset IdeaTestApplication.setDataProvider."); } if (CommonDataKeys.PROJECT == dataId) { return myProject; } else if (PlatformDataKeys.EDITOR == dataId || OpenFileDescriptor.NAVIGATE_IN_EDITOR == dataId) { return FileEditorManager.getInstance(myProject).getSelectedTextEditor(); } else { Editor editor = (Editor)getData(PlatformDataKeys.EDITOR); if (editor != null) { FileEditorManagerEx manager = FileEditorManagerEx.getInstanceEx(myProject); Object managerData = manager.getData(dataId, editor, editor.getCaretModel().getCurrentCaret()); if (managerData != null) { return managerData; } JComponent component = editor.getContentComponent(); if (component instanceof EditorComponentImpl) { return ((EditorComponentImpl)component).getData(dataId); } } return null; } }
private static String getComponentType(JComponent component) { return component instanceof JTree ? "tree" : component instanceof JList ? "list" : component instanceof JTable ? "table" : component instanceof JViewport ? "viewport" : component instanceof ActionToolbar ? "toolbar" : component instanceof EditorComponentImpl ? "editor" : component instanceof EditorGutterComponentEx ? "editor" : component instanceof JBLoadingPanel ? "loading" : component instanceof JBTabs ? "tabs" : component instanceof JBPanelWithEmptyText ? "panel" : component instanceof JPanel && ourKnownNames.contains(component.getName()) ? component.getName() : null; }
private boolean isEditorComponent(Object source) { return source.getClass() == EditorComponentImpl.class; }
protected boolean showHint(final JComponent component) { myInsideShow = true; if (myCurrentHint != null) { myCurrentHint.hide(); } myCurrentHint = new LightweightHint(component) { @Override protected boolean canAutoHideOn(TooltipEvent event) { InputEvent inputEvent = event.getInputEvent(); if (inputEvent instanceof MouseEvent) { Component comp = inputEvent.getComponent(); if (comp instanceof EditorComponentImpl) { EditorImpl editor = ((EditorComponentImpl)comp).getEditor(); return !isInsideCurrentRange(editor, ((MouseEvent)inputEvent).getPoint()); } } return true; } }; myCurrentHint.addHintListener(new HintListener() { @Override public void hintHidden(EventObject event) { if (myHideRunnable != null && !myInsideShow) { myHideRunnable.run(); } onHintHidden(); } }); // editor may be disposed before later invokator process this action if (myEditor.isDisposed() || myEditor.getComponent().getRootPane() == null) { return false; } Point p = HintManagerImpl.getHintPosition(myCurrentHint, myEditor, myEditor.xyToLogicalPosition(myPoint), HintManager.UNDER); HintHint hint = HintManagerImpl.createHintHint(myEditor, p, myCurrentHint, HintManager.UNDER, true); hint.setShowImmediately(true); HintManagerImpl.getInstanceImpl().showEditorHint(myCurrentHint, myEditor, p, HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING, 0, false, hint); myInsideShow = false; return true; }