private void setHeaderComponent(JComponent c) { boolean doRevalidate = false; if (myHeaderComponent != null) { myHeaderPanel.remove(myHeaderComponent); myHeaderPanel.add(myCaption, BorderLayout.NORTH); myHeaderComponent = null; doRevalidate = true; } if (c != null) { myHeaderPanel.remove(myCaption); myHeaderPanel.add(c, BorderLayout.NORTH); myHeaderComponent = c; final Dimension size = myContent.getSize(); if (size.height < c.getPreferredSize().height * 2) { size.height += c.getPreferredSize().height; setSize(size); } doRevalidate = true; } if (doRevalidate) myContent.revalidate(); }
private void init() { enableEvents(AWTEvent.COMPONENT_EVENT_MASK); final JPanel contentPane = new JPanel(new BorderLayout()); contentPane.add(myHeader, BorderLayout.NORTH); JPanel innerPanel = new JPanel(new BorderLayout()); JComponent toolWindowComponent = myToolWindow.getComponent(); innerPanel.add(toolWindowComponent, BorderLayout.CENTER); final NonOpaquePanel inner = new NonOpaquePanel(innerPanel); inner.setBorder(new EmptyBorder(-1, 0, 0, 0)); contentPane.add(inner, BorderLayout.CENTER); add(contentPane, BorderLayout.CENTER); if (SystemInfo.isMac) { setBackground(new JBColor(Gray._200, Gray._90)); } // Add listeners registerKeyboardAction( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { ToolWindowManager.getInstance(myProject).activateEditorComponent(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); }
private JPanel createToolbarPanel() { RunAction runAction = new RunAction(this); runAction.registerCustomShortcutSet(CommonShortcuts.getRerun(), this); DefaultActionGroup leftActionGroup = new DefaultActionGroup(); leftActionGroup.add(runAction); leftActionGroup.add(new PauseOutputAction(this)); leftActionGroup.add(new StopAction(this)); leftActionGroup.add(new CloseAction()); leftActionGroup.add(new PreviousOccurenceToolbarAction(this)); leftActionGroup.add(new NextOccurenceToolbarAction(this)); leftActionGroup.add(new ContextHelpAction(HelpID.ANT)); DefaultActionGroup rightActionGroup = new DefaultActionGroup(); rightActionGroup.add(new ChangeViewAction(this)); rightActionGroup.add(new VerboseAction(this)); rightActionGroup.add( CommonActionsManager.getInstance().createExpandAllAction(myTreeExpander, this)); rightActionGroup.add( CommonActionsManager.getInstance().createCollapseAllAction(myTreeExpander, this)); rightActionGroup.add(myTreeView.createToggleAutoscrollAction()); myLeftToolbar = ActionManager.getInstance() .createActionToolbar(ActionPlaces.ANT_MESSAGES_TOOLBAR, leftActionGroup, false); JPanel toolbarPanel = new JPanel(new GridLayout(1, 2, 2, 0)); toolbarPanel.add(myLeftToolbar.getComponent()); myRightToolbar = ActionManager.getInstance() .createActionToolbar(ActionPlaces.ANT_MESSAGES_TOOLBAR, rightActionGroup, false); toolbarPanel.add(myRightToolbar.getComponent()); return toolbarPanel; }
private JPanel readSplitter( JPanel panel, Element splitterElement, Ref<EditorWindow> currentWindow) { final boolean orientation = "vertical".equals(splitterElement.getAttributeValue("split-orientation")); final float proportion = Float.valueOf(splitterElement.getAttributeValue("split-proportion")).floatValue(); final Element first = splitterElement.getChild("split-first"); final Element second = splitterElement.getChild("split-second"); Splitter splitter; if (panel == null) { panel = new JPanel(new BorderLayout()); panel.setOpaque(false); splitter = new Splitter(orientation, proportion, 0.1f, 0.9f); panel.add(splitter, BorderLayout.CENTER); splitter.setFirstComponent(readExternalPanel(first, null, currentWindow)); splitter.setSecondComponent(readExternalPanel(second, null, currentWindow)); } else if (panel.getComponent(0) instanceof Splitter) { splitter = (Splitter) panel.getComponent(0); readExternalPanel(first, (JPanel) splitter.getFirstComponent(), currentWindow); readExternalPanel(second, (JPanel) splitter.getSecondComponent(), currentWindow); } else { readExternalPanel(first, panel, currentWindow); readExternalPanel(second, panel, currentWindow); } return panel; }
@NotNull public EditorWindow[] getOrderedWindows() { final ArrayList<EditorWindow> res = new ArrayList<EditorWindow>(); // Collector for windows in tree ordering: class Inner { final void collect(final JPanel panel) { final Component comp = panel.getComponent(0); if (comp instanceof Splitter) { final Splitter splitter = (Splitter) comp; collect((JPanel) splitter.getFirstComponent()); collect((JPanel) splitter.getSecondComponent()); } else if (comp instanceof JPanel || comp instanceof JBTabs) { final EditorWindow window = findWindowWith(comp); if (window != null) { res.add(window); } } } } // get root component and traverse splitters tree: if (getComponentCount() != 0) { final Component comp = getComponent(0); LOG.assertTrue(comp instanceof JPanel); final JPanel panel = (JPanel) comp; if (panel.getComponentCount() != 0) { new Inner().collect(panel); } } LOG.assertTrue(res.size() == myWindows.size()); return res.toArray(new EditorWindow[res.size()]); }
public void writeExternal(final Element element) { if (getComponentCount() != 0) { final Component comp = getComponent(0); LOG.assertTrue(comp instanceof JPanel); final JPanel panel = (JPanel) comp; if (panel.getComponentCount() != 0) { final Element res = writePanel(panel); element.addContent(res); } } }
private void showAntView(boolean treeView) { AntOutputView oldView = getOutputView(treeView); AntOutputView newView = getOutputView(!treeView); myCurrentView = newView; myMessagePanel.remove(oldView.getComponent()); myMessagePanel.add(newView.getComponent(), BorderLayout.CENTER); myMessagePanel.validate(); JComponent component = IdeFocusTraversalPolicy.getPreferredFocusedComponent(myMessagePanel); component.requestFocus(); repaint(); }
@SuppressWarnings({"HardCodedStringLiteral"}) private Element writePanel(final JPanel panel) { final Component comp = panel.getComponent(0); if (comp instanceof Splitter) { final Splitter splitter = (Splitter) comp; final Element res = new Element("splitter"); res.setAttribute("split-orientation", splitter.getOrientation() ? "vertical" : "horizontal"); res.setAttribute("split-proportion", Float.toString(splitter.getProportion())); final Element first = new Element("split-first"); first.addContent(writePanel((JPanel) splitter.getFirstComponent())); final Element second = new Element("split-second"); second.addContent(writePanel((JPanel) splitter.getSecondComponent())); res.addContent(first); res.addContent(second); return res; } else if (comp instanceof JBTabs) { final Element res = new Element("leaf"); final EditorWindow window = findWindowWith(comp); writeWindow(res, window); return res; } else if (comp instanceof EditorWindow.TCompForTablessMode) { final EditorWithProviderComposite composite = ((EditorWindow.TCompForTablessMode) comp).myEditor; final Element res = new Element("leaf"); writeComposite(res, composite.getFile(), composite, false, composite); return res; } else { LOG.error(comp != null ? comp.getClass().getName() : null); return null; } }
@Override public void removeNotify() { super.removeNotify(); if (myDisposable != null && !Disposer.isDisposed(myDisposable)) { Disposer.dispose(myDisposable); } }
@Override protected final void processComponentEvent(final ComponentEvent e) { super.processComponentEvent(e); if (ComponentEvent.COMPONENT_RESIZED == e.getID()) { fireResized(); } }
public void setLocation(@NotNull final Point screenPoint) { if (myPopup == null) { myForcedLocation = screenPoint; } else { moveTo(myContent, screenPoint, myLocateByContent ? myHeaderPanel.getPreferredSize() : null); } }
private void showWelcomeScreen() { myWelcomeScreen = new WelcomeScreen(this); Disposer.register(myDisposable, myWelcomeScreen); myWelcomePane = myWelcomeScreen.getWelcomePanel(); myContentPane.add(myWelcomePane); updateToolbarVisibility(); }
IdeRootPane( ActionManagerEx actionManager, UISettings uiSettings, DataManager dataManager, final Application application, final String[] commandLineArgs, IdeFrame frame) { myActionManager = actionManager; myUISettings = uiSettings; updateToolbar(); myContentPane.add(myNorthPanel, BorderLayout.NORTH); myStatusBarCustomComponentFactories = application.getExtensions(StatusBarCustomComponentFactory.EP_NAME); myApplication = application; createStatusBar(frame); updateStatusBarVisibility(); myContentPane.add(myStatusBar, BorderLayout.SOUTH); myUISettingsListener = new MyUISettingsListenerImpl(); setJMenuBar(new IdeMenuBar(actionManager, dataManager)); final Ref<Boolean> willOpenProject = new Ref<Boolean>(Boolean.FALSE); final AppLifecycleListener lifecyclePublisher = application.getMessageBus().syncPublisher(AppLifecycleListener.TOPIC); lifecyclePublisher.appFrameCreated(commandLineArgs, willOpenProject); LOG.info( "App initialization took " + (System.nanoTime() - PluginManager.startupStart) / 1000000 + " ms"); PluginManager.dumpPluginClassStatistics(); if (!willOpenProject.get()) { showWelcomeScreen(); lifecyclePublisher.welcomeScreenDisplayed(); } myGlassPane = new IdeGlassPaneImpl(this); setGlassPane(myGlassPane); myGlassPaneInitialized = true; myGlassPane.setVisible(false); Disposer.register(application, myDisposable); }
@Override public void addNotify() { super.addNotify(); myGlassPane = IdeGlassPaneUtil.find(this); myDisposable = Disposer.newDisposable(); myGlassPane.addMouseMotionPreprocessor(myListener, myDisposable); myGlassPane.addMousePreprocessor(myListener, myDisposable); }
void updateToolbar() { if (myToolbar != null) { myNorthPanel.remove(myToolbar); } myToolbar = createToolbar(); myNorthPanel.add(myToolbar); updateToolbarVisibility(); myContentPane.revalidate(); }
@Override public Point getLocationOnScreen() { Dimension headerCorrectionSize = myLocateByContent ? myHeaderPanel.getPreferredSize() : null; Point screenPoint = myContent.getLocationOnScreen(); if (headerCorrectionSize != null) { screenPoint.y -= headerCorrectionSize.height; } return screenPoint; }
public void paint(Graphics g) { super.paint(g); if (myResizable && myDrawMacCorner) { g.drawImage( ourMacCorner, getX() + getWidth() - ourMacCorner.getWidth(this), getY() + getHeight() - ourMacCorner.getHeight(this), this); } }
public void removeProgressPanel() { if (myProgressPanel != null) { myMessagePanel.remove(myProgressPanel); // fix of 9377 SwingUtilities.invokeLater( new Runnable() { public void run() { myMessagePanel.validate(); } }); myProgressPanel = null; } }
final void collect(final JPanel panel) { final Component comp = panel.getComponent(0); if (comp instanceof Splitter) { final Splitter splitter = (Splitter) comp; collect((JPanel) splitter.getFirstComponent()); collect((JPanel) splitter.getSecondComponent()); } else if (comp instanceof JPanel || comp instanceof JBTabs) { final EditorWindow window = findWindowWith(comp); if (window != null) { res.add(window); } } }
public void setAdText(@NotNull final String s, int alignment) { if (myAdComponent == null) { myAdComponent = HintUtil.createAdComponent(s, BorderFactory.createEmptyBorder(1, 5, 1, 5), alignment); JPanel wrapper = new JPanel(new BorderLayout()) { @Override protected void paintComponent(Graphics g) { g.setColor(Gray._135); g.drawLine(0, 0, getWidth(), 0); super.paintComponent(g); } }; wrapper.setOpaque(false); wrapper.setBorder(new EmptyBorder(1, 0, 0, 0)); wrapper.add(myAdComponent, BorderLayout.CENTER); myContent.add(wrapper, BorderLayout.SOUTH); pack(false, true); } else { myAdComponent.setText(s); myAdComponent.setHorizontalAlignment(alignment); } }
AbstractPopup init( final Project project, @NotNull final JComponent component, @Nullable final JComponent preferredFocusedComponent, final boolean requestFocus, final boolean focusable, final boolean forceHeavyweight, final boolean movable, final String dimensionServiceKey, final boolean resizable, @Nullable final String caption, @Nullable final Computable<Boolean> callback, final boolean cancelOnClickOutside, @Nullable final Set<JBPopupListener> listeners, final boolean useDimServiceForXYLocation, InplaceButton commandButton, @Nullable final IconButton cancelButton, @Nullable final MouseChecker cancelOnMouseOutCallback, final boolean cancelOnWindow, @Nullable final ActiveIcon titleIcon, final boolean cancelKeyEnabled, final boolean locateBycontent, final boolean placeWithinScreenBounds, @Nullable final Dimension minSize, float alpha, @Nullable MaskProvider maskProvider, boolean inStack, boolean modalContext, @Nullable Component[] focusOwners, @Nullable String adText, int adTextAlignment, final boolean headerAlwaysFocusable, @NotNull List<Pair<ActionListener, KeyStroke>> keyboardActions, Component settingsButtons, @Nullable final Processor<JBPopup> pinCallback, boolean mayBeParent, boolean showShadow) { if (requestFocus && !focusable) { assert false : "Incorrect argument combination: requestFocus=" + requestFocus + " focusable=" + focusable; } myActivityKey = new UiActivity.Focus("Popup:" + this); myProject = project; myComponent = component; myPopupBorder = PopupBorder.Factory.create(true, showShadow); myShadowed = showShadow; myPaintShadow = showShadow && !SystemInfo.isMac && !movable && !resizable && Registry.is("ide.popup.dropShadow"); myContent = createContentPanel(resizable, myPopupBorder, isToDrawMacCorner() && resizable); myMayBeParent = mayBeParent; myContent.add(component, BorderLayout.CENTER); if (adText != null) { setAdText(adText, adTextAlignment); } myCancelKeyEnabled = cancelKeyEnabled; myLocateByContent = locateBycontent; myLocateWithinScreen = placeWithinScreenBounds; myAlpha = alpha; myMaskProvider = maskProvider; myInStack = inStack; myModalContext = modalContext; myFocusOwners = focusOwners; myHeaderAlwaysFocusable = headerAlwaysFocusable; myMovable = movable; ActiveIcon actualIcon = titleIcon == null ? new ActiveIcon(EmptyIcon.ICON_0) : titleIcon; myHeaderPanel = new JPanel(new BorderLayout()); if (caption != null) { if (caption.length() > 0) { myCaption = new TitlePanel(actualIcon.getRegular(), actualIcon.getInactive()); ((TitlePanel) myCaption).setText(caption); } else { myCaption = new CaptionPanel(); } if (pinCallback != null) { myCaption.setButtonComponent( new InplaceButton( new IconButton( "Pin", IconLoader.getIcon("/general/autohideOff.png"), IconLoader.getIcon("/general/autohideOff.png"), IconLoader.getIcon("/general/autohideOffInactive.png")), new ActionListener() { public void actionPerformed(final ActionEvent e) { pinCallback.process(AbstractPopup.this); } })); } else if (cancelButton != null) { myCaption.setButtonComponent( new InplaceButton( cancelButton, new ActionListener() { public void actionPerformed(final ActionEvent e) { cancel(); } })); } else if (commandButton != null) { myCaption.setButtonComponent(commandButton); } } else { myCaption = new CaptionPanel(); myCaption.setBorder(null); myCaption.setPreferredSize(new Dimension(0, 0)); } setWindowActive(myHeaderAlwaysFocusable); myHeaderPanel.add(myCaption, BorderLayout.NORTH); myContent.add(myHeaderPanel, BorderLayout.NORTH); myForcedHeavyweight = true; myResizable = resizable; myPreferredFocusedComponent = preferredFocusedComponent; myRequestFocus = requestFocus; myFocusable = focusable; myDimensionServiceKey = dimensionServiceKey; myCallBack = callback; myCancelOnClickOutside = cancelOnClickOutside; myCancelOnMouseOutCallback = cancelOnMouseOutCallback; myListeners = listeners == null ? new HashSet<JBPopupListener>() : listeners; myUseDimServiceForXYLocation = useDimServiceForXYLocation; myCancelOnWindow = cancelOnWindow; myMinSize = minSize; for (Pair<ActionListener, KeyStroke> pair : keyboardActions) { myContent.registerKeyboardAction( pair.getFirst(), pair.getSecond(), JComponent.WHEN_IN_FOCUSED_WINDOW); } if (settingsButtons != null) { myCaption.addSettingsComponent(settingsButtons); } return this; }
protected final Container createContentPane() { myContentPane = new JPanel(new BorderLayout()); myContentPane.setBackground(Color.GRAY); return myContentPane; }
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(); } }); } }