public EditorsSplitters( final FileEditorManagerImpl manager, DockManager dockManager, boolean createOwnDockableContainer) { super(new BorderLayout()); setOpaque(false); myManager = manager; myFocusWatcher = new MyFocusWatcher(); setFocusTraversalPolicy(new MyFocusTraversalPolicy()); setTransferHandler(new MyTransferHandler()); clear(); if (createOwnDockableContainer) { DockableEditorTabbedContainer dockable = new DockableEditorTabbedContainer(myManager.getProject(), this, false); Disposer.register(manager.getProject(), dockable); dockManager.register(dockable); } UISettings.getInstance() .addUISettingsListener( new UISettingsListener() { @Override public void uiSettingsChanged(UISettings source) { updateBackground(); } }, manager.getProject()); updateBackground(); }
private MyFocusCommand(DialogWrapper wrapper) { myWrapper = getDialogWrapper(); setToInvalidateRequestors(false); Disposer.register( wrapper.getDisposable(), new Disposable() { @Override public void dispose() { if (!myTypeAheadDone.isProcessed()) { myTypeAheadDone.setDone(); } flushEvents(); } }); }
public void cancel(InputEvent e) { if (isDisposed()) return; if (myPopup != null) { if (!canClose()) { return; } storeDimensionSize(myContent.getSize()); if (myUseDimServiceForXYLocation) { final JRootPane root = myComponent.getRootPane(); if (root != null) { final Container popupWindow = root.getParent(); if (popupWindow != null && popupWindow.isShowing()) { storeLocation(popupWindow.getLocationOnScreen()); } } } if (e instanceof MouseEvent) { IdeEventQueue.getInstance().blockNextEvents(((MouseEvent) e)); } myPopup.hide(false); if (ApplicationManagerEx.getApplicationEx() != null) { StackingPopupDispatcher.getInstance().onPopupHidden(this); } if (myInStack) { myFocusTrackback.setForcedRestore(!myOk && myFocusable); myFocusTrackback.restoreFocus(); } disposePopup(); if (myListeners != null) { for (JBPopupListener each : myListeners) { each.onClosed(new LightweightWindowEvent(this, myOk)); } } } Disposer.dispose(this, false); }
private void prepareToShow() { final MouseAdapter mouseAdapter = new MouseAdapter() { public void mousePressed(MouseEvent e) { Point point = (Point) e.getPoint().clone(); SwingUtilities.convertPointToScreen(point, e.getComponent()); final Dimension dimension = myContent.getSize(); dimension.height += myResizable && isToDrawMacCorner() ? ourMacCorner.getHeight(myContent) : 4; dimension.width += 4; Point locationOnScreen = myContent.getLocationOnScreen(); final Rectangle bounds = new Rectangle(new Point(locationOnScreen.x - 2, locationOnScreen.y - 2), dimension); if (!bounds.contains(point)) { cancel(); } } }; myContent.addMouseListener(mouseAdapter); Disposer.register( this, new Disposable() { public void dispose() { myContent.removeMouseListener(mouseAdapter); } }); myContent.registerKeyboardAction( new ActionListener() { public void actionPerformed(ActionEvent e) { if (myCancelKeyEnabled) { cancel(); } } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); mySearchKeyListener = new SpeedSearchKeyListener(); myContent.addKeyListener(mySearchKeyListener); if (myCancelOnMouseOutCallback != null || myCancelOnWindow) { myMouseOutCanceller = new Canceller(); Toolkit.getDefaultToolkit() .addAWTEventListener( myMouseOutCanceller, AWTEvent.MOUSE_EVENT_MASK | WindowEvent.WINDOW_ACTIVATED | AWTEvent.MOUSE_MOTION_EVENT_MASK); } myFocusWatcher = new ChildFocusWatcher(myContent) { protected void onFocusGained(final FocusEvent event) { setWindowActive(true); } protected void onFocusLost(final FocusEvent event) { setWindowActive(false); } }; mySpeedSearchPatternField = new JTextField(); if (SystemInfo.isMac) { Font f = mySpeedSearchPatternField.getFont(); mySpeedSearchPatternField.setFont(f.deriveFont(f.getStyle(), f.getSize() - 2)); } }
public void show(Component owner, int aScreenX, int aScreenY, final boolean considerForcedXY) { if (ApplicationManagerEx.getApplicationEx() != null && ApplicationManager.getApplication().isHeadlessEnvironment()) return; if (isDisposed()) { throw new IllegalStateException( "Popup was already disposed. Recreate a new instance to show again"); } assert ApplicationManager.getApplication().isDispatchThread(); addActivity(); final boolean shouldShow = beforeShow(); if (!shouldShow) { removeActivity(); return; } prepareToShow(); if (myInStack) { myFocusTrackback = new FocusTrackback(this, owner, true); myFocusTrackback.setMustBeShown(true); } Dimension sizeToSet = null; if (myDimensionServiceKey != null) { sizeToSet = DimensionService.getInstance().getSize(myDimensionServiceKey, myProject); } if (myForcedSize != null) { sizeToSet = myForcedSize; } if (myMinSize == null) { myMinSize = myContent.getMinimumSize(); } if (sizeToSet == null) { sizeToSet = myContent.getPreferredSize(); } if (sizeToSet != null) { sizeToSet.width = Math.max(sizeToSet.width, myMinSize.width); sizeToSet.height = Math.max(sizeToSet.height, myMinSize.height); myContent.setSize(sizeToSet); myContent.setPreferredSize(sizeToSet); } Point xy = new Point(aScreenX, aScreenY); boolean adjustXY = true; if (myDimensionServiceKey != null) { final Point storedLocation = DimensionService.getInstance().getLocation(myDimensionServiceKey, myProject); if (storedLocation != null) { xy = storedLocation; adjustXY = false; } } if (adjustXY) { final Insets insets = myContent.getInsets(); if (insets != null) { xy.x -= insets.left; xy.y -= insets.top; } } if (considerForcedXY && myForcedLocation != null) { xy = myForcedLocation; } if (myLocateByContent) { final Dimension captionSize = myHeaderPanel.getPreferredSize(); xy.y -= captionSize.height; } Rectangle targetBounds = new Rectangle(xy, myContent.getPreferredSize()); Insets insets = myPopupBorder.getBorderInsets(myContent); if (insets != null) { targetBounds.x += insets.left; targetBounds.y += insets.top; } Rectangle original = new Rectangle(targetBounds); if (myLocateWithinScreen) { ScreenUtil.moveRectangleToFitTheScreen(targetBounds); } if (myMouseOutCanceller != null) { myMouseOutCanceller.myEverEntered = targetBounds.equals(original); } myOwner = IdeFrameImpl.findNearestModalComponent(owner); if (myOwner == null) { myOwner = owner; } myRequestorComponent = owner; boolean forcedDialog = (SystemInfo.isMac && !(myOwner instanceof IdeFrame)) || myMayBeParent; PopupComponent.Factory factory = getFactory(myForcedHeavyweight || myResizable, forcedDialog); myNativePopup = factory.isNativePopup(); myPopup = factory.getPopup(myOwner, myContent, targetBounds.x, targetBounds.y); if (myResizable) { final JRootPane root = myContent.getRootPane(); final IdeGlassPaneImpl glass = new IdeGlassPaneImpl(root); root.setGlassPane(glass); final ResizeComponentListener resizeListener = new ResizeComponentListener(this, glass); glass.addMousePreprocessor(resizeListener, this); glass.addMouseMotionPreprocessor(resizeListener, this); } if (myCaption != null && myMovable) { final MoveComponentListener moveListener = new MoveComponentListener(myCaption) { public void mousePressed(final MouseEvent e) { super.mousePressed(e); if (e.isConsumed()) return; if (UIUtil.isCloseClick(e)) { if (myCaption.isWithinPanel(e)) { cancel(); } } } }; ListenerUtil.addMouseListener(myCaption, moveListener); ListenerUtil.addMouseMotionListener(myCaption, moveListener); final MyContentPanel saved = myContent; Disposer.register( this, new Disposable() { public void dispose() { ListenerUtil.removeMouseListener(saved, moveListener); ListenerUtil.removeMouseMotionListener(saved, moveListener); } }); } for (JBPopupListener listener : myListeners) { listener.beforeShown(new LightweightWindowEvent(this)); } myPopup.setRequestFocus(myRequestFocus); myPopup.show(); final Window window = SwingUtilities.getWindowAncestor(myContent); myWindowListener = new MyWindowListener(); window.addWindowListener(myWindowListener); if (myFocusable) { window.setFocusableWindowState(true); window.setFocusable(true); } myWindow = updateMaskAndAlpha(window); if (myWindow instanceof JWindow) { ((JWindow) myWindow).getRootPane().putClientProperty(KEY, this); } if (myWindow != null) { // dialogwrapper-based popups do this internally through peer, // for other popups like jdialog-based we should exclude them manually, but // we still have to be able to use IdeFrame as parent if (!myMayBeParent && !(myWindow instanceof Frame)) { WindowManager.getInstance().doNotSuggestAsParent(myWindow); } } final Runnable afterShow = new Runnable() { public void run() { if (myPreferredFocusedComponent != null && myInStack && myFocusable) { myFocusTrackback.registerFocusComponent(myPreferredFocusedComponent); } removeActivity(); afterShow(); } }; if (myRequestFocus) { getFocusManager() .requestFocus( new FocusCommand() { @Override public ActionCallback run() { if (isDisposed()) { removeActivity(); return new ActionCallback.Done(); } _requestFocus(); final ActionCallback result = new ActionCallback(); final Runnable afterShowRunnable = new Runnable() { @Override public void run() { afterShow.run(); result.setDone(); } }; if (myNativePopup) { final FocusRequestor furtherRequestor = getFocusManager().getFurtherRequestor(); SwingUtilities.invokeLater( new Runnable() { @Override public void run() { if (isDisposed()) { result.setRejected(); return; } furtherRequestor .requestFocus( new FocusCommand() { @Override public ActionCallback run() { if (isDisposed()) { return new ActionCallback.Rejected(); } _requestFocus(); afterShowRunnable.run(); return new ActionCallback.Done(); } }, true) .notify(result) .doWhenProcessed( new Runnable() { @Override public void run() { removeActivity(); } }); } }); } else { afterShowRunnable.run(); } return result; } }, true) .doWhenRejected( new Runnable() { @Override public void run() { afterShow.run(); } }); } else { SwingUtilities.invokeLater( new Runnable() { @Override public void run() { if (isDisposed()) { removeActivity(); return; } afterShow.run(); } }); } }
public void dispose() { if (myDisposed) { return; } myDisposed = true; Disposer.dispose(this, false); assert ApplicationManager.getApplication().isDispatchThread(); if (myPopup != null) { cancel(myDisposeEvent); } if (myContent != null) { myContent.removeAll(); myContent.removeKeyListener(mySearchKeyListener); } myContent = null; myPreferredFocusedComponent = null; myComponent = null; myFocusTrackback = null; myCallBack = null; myListeners = null; if (myMouseOutCanceller != null) { final Toolkit toolkit = Toolkit.getDefaultToolkit(); // it may happen, but have no idea how // http://www.jetbrains.net/jira/browse/IDEADEV-21265 if (toolkit != null) { toolkit.removeAWTEventListener(myMouseOutCanceller); } } myMouseOutCanceller = null; if (myFocusWatcher != null) { myFocusWatcher.dispose(); myFocusWatcher = null; } resetWindow(); if (myFinalRunnable != null) { final ActionCallback typeaheadDone = new ActionCallback(); Runnable runFinal = new Runnable() { @Override public void run() { SwingUtilities.invokeLater( new Runnable() { @Override public void run() { typeaheadDone.setDone(); } }); myFinalRunnable.run(); myFinalRunnable = null; } }; IdeFocusManager.getInstance(myProject).typeAheadUntil(typeaheadDone); getFocusManager().doWhenFocusSettlesDown(runFinal); } }
EditorTabbedContainer(final EditorWindow window, Project project, final int tabPlacement) { myWindow = window; myProject = project; final ActionManager actionManager = ActionManager.getInstance(); myTabs = new JBEditorTabs(project, actionManager, IdeFocusManager.getInstance(project), this); myTabs .setDataProvider(new MyDataProvider()) .setPopupGroup( new Getter<ActionGroup>() { public ActionGroup get() { return (ActionGroup) CustomActionsSchema.getInstance() .getCorrectedAction(IdeActions.GROUP_EDITOR_TAB_POPUP); } }, ActionPlaces.EDITOR_TAB_POPUP, false) .setNavigationActionsEnabled(false) .addTabMouseListener(new TabMouseListener()) .getPresentation() .setTabDraggingEnabled(true) .setUiDecorator( new UiDecorator() { @NotNull public UiDecoration getDecoration() { return new UiDecoration( null, new Insets( TabsUtil.TAB_VERTICAL_PADDING, 10, TabsUtil.TAB_VERTICAL_PADDING, 10)); } }) .setTabLabelActionsMouseDeadzone(TimedDeadzone.NULL) .setGhostsAlwaysVisible(true) .setTabLabelActionsAutoHide(false) .setActiveTabFillIn( EditorColorsManager.getInstance().getGlobalScheme().getDefaultBackground()) .setPaintFocus(false) .getJBTabs() .addListener( new TabsListener.Adapter() { public void selectionChanged(final TabInfo oldSelection, final TabInfo newSelection) { final FileEditorManager editorManager = FileEditorManager.getInstance(myProject); final FileEditor oldEditor = oldSelection != null ? editorManager.getSelectedEditor((VirtualFile) oldSelection.getObject()) : null; if (oldEditor != null) { oldEditor.deselectNotify(); } final FileEditor newEditor = editorManager.getSelectedEditor((VirtualFile) newSelection.getObject()); if (newEditor != null) { newEditor.selectNotify(); } } }) .setAdditionalSwitchProviderWhenOriginal(new MySwitchProvider()) .setSelectionChangeHandler( new JBTabs.SelectionChangeHandler() { @Override public ActionCallback execute( TabInfo info, boolean requestFocus, final ActiveRunnable doChangeSelection) { final ActionCallback result = new ActionCallback(); CommandProcessor.getInstance() .executeCommand( myProject, new Runnable() { @Override public void run() { ((IdeDocumentHistoryImpl) IdeDocumentHistory.getInstance(myProject)) .onSelectionChanged(); result.notify(doChangeSelection.run()); } }, "EditorChange", null); return result; } }) .getPresentation() .setRequestFocusOnLastFocusedComponent(true); setTabPlacement(UISettings.getInstance().EDITOR_TAB_PLACEMENT); updateTabBorder(); ((ToolWindowManagerEx) ToolWindowManager.getInstance(myProject)) .addToolWindowManagerListener( new ToolWindowManagerAdapter() { public void stateChanged() { updateTabBorder(); } public void toolWindowRegistered(@NotNull final String id) { updateTabBorder(); } }); UISettings.getInstance() .addUISettingsListener( new UISettingsListener() { public void uiSettingsChanged(UISettings source) { updateTabBorder(); } }, this); Disposer.register(project, this); }