List of usage examples for com.intellij.openapi.ui DialogWrapper findInstance
@Nullable public static DialogWrapper findInstance(Component c)
From source file:automation.RobotControlWindow.java
License:Apache License
private static Window findWindow(Component component) { DialogWrapper dialogWrapper = DialogWrapper.findInstance(component); if (dialogWrapper != null) { return dialogWrapper.getPeer().getWindow(); }//from ww w . j av a 2s .c o m return null; }
From source file:com.chrisrm.idea.ui.MTTitlePane.java
License:Open Source License
private JButton createHelpButton() { Ref<WindowButton> button = Ref.create(); button.set(new WindowButton("Help", AllIcons.Windows.HelpButton, AllIcons.Windows.HelpButton, new AbstractAction("Help") { @Override//ww w . ja v a2 s. c o m public void actionPerformed(final ActionEvent e) { final DialogWrapper dialog = DialogWrapper.findInstance(button.get()); if (dialog != null) { try { final Method getHelpAction = DialogWrapper.class.getDeclaredMethod("getHelpAction"); getHelpAction.setAccessible(true); final Object helpAction = getHelpAction.invoke(dialog); if (helpAction instanceof Action && ((Action) helpAction).isEnabled()) { ((Action) helpAction).actionPerformed(e); } } catch (Exception ex) { } } } }, BUTTON_HOVER_BG) { { setFont(new Font("Segoe UI Regular", Font.PLAIN, JBUI.scale(15))); } @Override public void paint(final Graphics g) { if (isHelpAvailable()) { super.paint(g); } else { g.setColor(getBackground()); g.fillRect(0, 0, getWidth(), getHeight()); } } private boolean isHelpAvailable() { final DialogWrapper dialog = DialogWrapper.findInstance(this); if (dialog != null) { try { final Method getHelpAction = DialogWrapper.class.getDeclaredMethod("getHelpAction"); getHelpAction.setAccessible(true); final Object helpAction = getHelpAction.invoke(dialog); if (helpAction instanceof Action && ((Action) helpAction).isEnabled()) { return true; } } catch (Exception e) { e.printStackTrace(); } } return false; } }); return button.get(); }
From source file:com.intellij.ide.navigationToolbar.NavBarListener.java
License:Apache License
@Override public void focusLost(final FocusEvent e) { if (myPanel.getProject().isDisposed()) { myPanel.setContextComponent(null); myPanel.hideHint();// w ww.j a v a 2 s . c o m return; } final DialogWrapper dialog = DialogWrapper.findInstance(e.getOppositeComponent()); shouldFocusEditor = dialog != null; if (dialog != null) { Disposer.register(dialog.getDisposable(), new Disposable() { @Override public void dispose() { if (dialog.getExitCode() == DialogWrapper.CANCEL_EXIT_CODE) { shouldFocusEditor = false; } } }); } // required invokeLater since in current call sequence KeyboardFocusManager is not initialized yet // but future focused component //noinspection SSBasedInspection SwingUtilities.invokeLater(new Runnable() { @Override public void run() { processFocusLost(e); } }); }
From source file:com.intellij.ide.navigationToolbar.NavBarListener.java
License:Apache License
private void processFocusLost(FocusEvent e) { final Component opposite = e.getOppositeComponent(); if (myPanel.isInFloatingMode() && opposite != null && DialogWrapper.findInstance(opposite) != null) { myPanel.hideHint();/*from ww w . j a v a 2 s .c o m*/ return; } final boolean nodePopupInactive = !myPanel.isNodePopupActive(); boolean childPopupInactive = !JBPopupFactory.getInstance().isChildPopupFocused(myPanel); if (nodePopupInactive && childPopupInactive) { if (opposite != null && opposite != myPanel && !myPanel.isAncestorOf(opposite) && !e.isTemporary()) { myPanel.setContextComponent(null); myPanel.hideHint(); } } myPanel.updateItems(); }
From source file:com.intellij.ide.navigationToolbar.NavBarPopup.java
License:Apache License
private void show(final NavBarItem item, boolean checkRepaint) { final RelativePoint point = new RelativePoint(item, new Point(0, item.getHeight())); final Point p = point.getPoint(myPanel); if (p.x == 0 && p.y == 0 && checkRepaint) { // need repaint of nav bar panel //noinspection SSBasedInspection SwingUtilities.invokeLater(new Runnable() { @Override/* ww w . j a v a 2s .co m*/ public void run() { myPanel.getUpdateQueue().rebuildUi(); //noinspection SSBasedInspection SwingUtilities.invokeLater(new Runnable() { @Override public void run() { show(item, false); // end-less loop protection } }); } }); } else { int offset = NavBarUIManager.getUI().getPopupOffset(item); show(myPanel, p.x - offset, p.y, myPanel, new HintHint(myPanel, p)); final JBList list = getList(); if (0 <= myIndex && myIndex < list.getItemsCount()) { ListScrollingUtil.selectItem(list, myIndex); } } if (myPanel.isInFloatingMode()) { final Window window = SwingUtilities.windowForComponent(getList()); window.addWindowFocusListener(new WindowFocusListener() { @Override public void windowGainedFocus(WindowEvent e) { } @Override public void windowLostFocus(WindowEvent e) { final Window w = e.getOppositeWindow(); if (w != null && DialogWrapper.findInstance(w.getComponent(0)) != null) { myPanel.hideHint(); } } }); } }
From source file:com.intellij.ui.BalloonImpl.java
License:Apache License
private static boolean hasModalDialog(MouseEvent e) { final Component c = e.getComponent(); final DialogWrapper dialog = DialogWrapper.findInstance(c); return dialog != null && dialog.isModal(); }
From source file:com.mbeddr.pluginmanager.com.intellij.ide.plugins.PluginHeaderPanel.java
License:Apache License
private void createUIComponents() { myInstallButton = new JButton() { {/*from w w w.j a v a 2s .c o m*/ setOpaque(false); setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } @Override public Dimension getPreferredSize() { final FontMetrics metrics = getFontMetrics(getFont()); final int textWidth = metrics.stringWidth(getText()); final int width = 8 + 16 + 4 + textWidth + 8; final int height = 2 + Math.max(16, metrics.getHeight()) + 2; return new Dimension(width, height); } @Override public void paint(Graphics g2) { final Graphics2D g = (Graphics2D) g2; final GraphicsConfig config = GraphicsUtil.setupAAPainting(g); final int w = g.getClipBounds().width; final int h = g.getClipBounds().height; g.setPaint(getBackgroundBorderPaint()); g.fillRoundRect(0, 0, w, h, 7, 7); g.setPaint(getBackgroundPaint()); g.fillRoundRect(1, 1, w - 2, h - 2, 6, 6); g.setColor(getButtonForeground()); int offset = 8; g.drawString(getText(), offset + 16 + 4, getBaseline(w, h)); getIcon().paintIcon(this, g, offset, (getHeight() - getIcon().getIconHeight()) / 2); config.restore(); } private Color getButtonForeground() { switch (myActionId) { case UPDATE: return new JBColor(Gray._240, Gray._210); case INSTALL: return new JBColor(Gray._240, Gray._210); case RESTART: case UNINSTALL: return new JBColor(Gray._0, Gray._210); } return new JBColor(Gray._80, Gray._60); } private Paint getBackgroundPaint() { switch (myActionId) { case UPDATE: return new JBGradientPaint(this, new JBColor(new Color(98, 158, 225), new Color(98, 158, 225)), new JBColor(new Color(58, 91, 181), new Color(58, 91, 181))); case INSTALL: return new JBGradientPaint(this, new JBColor(new Color(96, 204, 105), new Color(81, 149, 87)), new JBColor(new Color(50, 101, 41), new Color(40, 70, 47))); case RESTART: case UNINSTALL: return UIUtil.isUnderDarcula() ? new JBGradientPaint(this, UIManager.getColor("Button.darcula.color1"), UIManager.getColor("Button.darcula.color2")) : Gray._240; } return Gray._238; } private Paint getBackgroundBorderPaint() { switch (myActionId) { case UPDATE: return new JBColor(new Color(166, 180, 205), Gray._85); case INSTALL: return new JBColor(new Color(201, 223, 201), Gray._70); case RESTART: case UNINSTALL: return new JBColor(Gray._220, Gray._100.withAlpha(180)); } return Gray._208; } @Override public String getText() { switch (myActionId) { case UPDATE: return "Update"; case INSTALL: return "Install"; case UNINSTALL: return "Uninstall"; case RESTART: return "Restart " + ApplicationNamesInfo.getInstance().getFullProductName(); } return super.getText(); } @Override public Icon getIcon() { switch (myActionId) { case UPDATE: return AllIcons.General.DownloadPlugin; case INSTALL: return AllIcons.General.DownloadPlugin; case UNINSTALL: return AllIcons.Actions.Delete; case RESTART: return AllIcons.Actions.Restart; } return super.getIcon(); } }; myInstallButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { switch (myActionId) { case UPDATE: case INSTALL: new InstallPluginAction(myManager.getAvailable(), myManager.getInstalled()) .install(new Runnable() { @Override public void run() { setPlugin(myPlugin); } }, true); break; case UNINSTALL: UninstallPluginAction.uninstall(myManager.getInstalled(), true, myPlugin); break; case RESTART: if (myManager != null) { myManager.apply(); } final DialogWrapper dialog = DialogWrapper .findInstance(KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()); if (dialog != null && dialog.isModal()) { dialog.close(DialogWrapper.OK_EXIT_CODE); } //noinspection SSBasedInspection SwingUtilities.invokeLater(new Runnable() { @Override public void run() { final DialogWrapper settings = DialogWrapper .findInstance(IdeFocusManager.findInstance().getFocusOwner()); if (settings instanceof SettingsDialog) { ((SettingsDialog) settings).doOKAction(); ApplicationManager.getApplication().restart(); } else { ApplicationManager.getApplication().restart(); } } }); break; } setPlugin(myPlugin); } }); }