@Override public Insets getBorderInsets(final Component c) { if (myProject == null) return new Insets(0, 0, 0, 0); ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(myProject); if (!(toolWindowManager instanceof ToolWindowManagerImpl) || !((ToolWindowManagerImpl) toolWindowManager).isToolWindowRegistered(myInfo.getId()) || myWindow.getType() == ToolWindowType.FLOATING) { return new Insets(0, 0, 0, 0); } ToolWindowAnchor anchor = myWindow.getAnchor(); Component component = myWindow.getComponent(); Container parent = component.getParent(); while (parent != null) { if (parent instanceof Splitter) { Splitter splitter = (Splitter) parent; boolean isFirst = splitter.getFirstComponent() == component; boolean isVertical = splitter.isVertical(); return new Insets( 0, anchor == ToolWindowAnchor.RIGHT || (!isVertical && !isFirst) ? 1 : 0, (isVertical && isFirst) ? 1 : 0, anchor == ToolWindowAnchor.LEFT || (!isVertical && isFirst) ? 1 : 0); } component = parent; parent = component.getParent(); } return new Insets( 0, anchor == ToolWindowAnchor.RIGHT ? 1 : 0, anchor == ToolWindowAnchor.TOP ? 1 : 0, anchor == ToolWindowAnchor.LEFT ? 1 : 0); }
private static boolean isHorizontalScrolling(Component c, MouseEvent e) { if (c != null && e instanceof MouseWheelEvent && (!SystemInfo.isMac || isDiagramViewComponent(c.getParent()))) { final MouseWheelEvent mwe = (MouseWheelEvent) e; return mwe.isShiftDown() && mwe.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL && findHorizontalScrollBar(c) != null; } return false; }
@Override public Balloon getParentBalloonFor(@Nullable Component c) { if (c == null) return null; Component eachParent = c; while (eachParent != null) { if (eachParent instanceof JComponent) { Object balloon = ((JComponent) eachParent).getClientProperty(Balloon.KEY); if (balloon instanceof Balloon) { return (Balloon) balloon; } } eachParent = eachParent.getParent(); } return null; }
@Nullable private static Container getContainer(@Nullable final Component focusOwner) { if (focusOwner == null) return null; if (focusOwner.isLightweight()) { Container container = focusOwner.getParent(); while (container != null) { final Container parent = container.getParent(); if (parent instanceof JLayeredPane) break; if (parent != null && parent.isLightweight()) { container = parent; } else { break; } } return container; } return SwingUtilities.windowForComponent(focusOwner); }
@Nullable private static JScrollBar findHorizontalScrollBar(Component c) { if (c == null) return null; if (c instanceof JScrollPane) { return ((JScrollPane) c).getHorizontalScrollBar(); } if (isDiagramViewComponent(c)) { final JComponent view = (JComponent) c; for (int i = 0; i < view.getComponentCount(); i++) { if (view.getComponent(i) instanceof JScrollBar) { final JScrollBar scrollBar = (JScrollBar) view.getComponent(i); if (scrollBar.getOrientation() == Adjustable.HORIZONTAL) { return scrollBar; } } } } return findHorizontalScrollBar(c.getParent()); }
@Override public void createToolWindowContent(final Project project, ToolWindow toolWindow) { Component component = toolWindow.getComponent(); changeListPanel = new GerritChangeListPanel(Lists.<ChangeInfo>newArrayList(), null); SimpleToolWindowPanel panel = new SimpleToolWindowPanel(false, true); ActionToolbar toolbar = createToolbar(); toolbar.setTargetComponent(changeListPanel); panel.setToolbar(toolbar.getComponent()); myRepositoryChangesBrowser = createRepositoryChangesBrowser(project); myDetailsSplitter = new Splitter(true, 0.6f); myDetailsSplitter.setShowDividerControls(true); changeListPanel.setBorder( IdeBorderFactory.createBorder(SideBorder.TOP | SideBorder.RIGHT | SideBorder.BOTTOM)); myDetailsSplitter.setFirstComponent(changeListPanel); myDetailsPanel = new GerritChangeDetailsPanel(project); JPanel details = myDetailsPanel.getComponent(); details.setBorder(IdeBorderFactory.createBorder(SideBorder.TOP | SideBorder.RIGHT)); myDetailsSplitter.setSecondComponent(details); Splitter myHorizontalSplitter = new Splitter(false, 0.7f); myHorizontalSplitter.setShowDividerControls(true); myHorizontalSplitter.setFirstComponent(myDetailsSplitter); myHorizontalSplitter.setSecondComponent(myRepositoryChangesBrowser); panel.setContent(myHorizontalSplitter); component.getParent().add(panel); reloadChanges(project, false); setupRefreshTask(project); }
/** * This method fills <code>myActions</code> list. * * @return true if there is a shortcut with second stroke found. */ public KeyProcessorContext updateCurrentContext( Component component, Shortcut sc, boolean isModalContext) { myContext.setFoundComponent(null); myContext.getActions().clear(); if (isControlEnterOnDialog(component, sc)) return myContext; boolean hasSecondStroke = false; // here we try to find "local" shortcuts for (; component != null; component = component.getParent()) { if (!(component instanceof JComponent)) { continue; } ArrayList listOfActions = (ArrayList) ((JComponent) component).getClientProperty(AnAction.ourClientProperty); if (listOfActions == null) { continue; } for (Object listOfAction : listOfActions) { if (!(listOfAction instanceof AnAction)) { continue; } AnAction action = (AnAction) listOfAction; hasSecondStroke |= addAction(action, sc); } // once we've found a proper local shortcut(s), we continue with non-local shortcuts if (!myContext.getActions().isEmpty()) { myContext.setFoundComponent((JComponent) component); break; } } // search in main keymap Keymap keymap = KeymapManager.getInstance().getActiveKeymap(); String[] actionIds = keymap.getActionIds(sc); ActionManager actionManager = ActionManager.getInstance(); for (String actionId : actionIds) { AnAction action = actionManager.getAction(actionId); if (action != null) { if (isModalContext && !action.isEnabledInModalContext()) { continue; } hasSecondStroke |= addAction(action, sc); } } if (!hasSecondStroke && sc instanceof KeyboardShortcut) { // little trick to invoke action which second stroke is a key w/o modifiers, but user still // holds the modifier key(s) of the first stroke final KeyboardShortcut keyboardShortcut = (KeyboardShortcut) sc; final KeyStroke firstKeyStroke = keyboardShortcut.getFirstKeyStroke(); final KeyStroke secondKeyStroke = keyboardShortcut.getSecondKeyStroke(); if (secondKeyStroke != null && secondKeyStroke.getModifiers() != 0 && firstKeyStroke.getModifiers() != 0) { final KeyboardShortcut altShortCut = new KeyboardShortcut( firstKeyStroke, KeyStroke.getKeyStroke(secondKeyStroke.getKeyCode(), 0)); final String[] additionalActions = keymap.getActionIds(altShortCut); for (final String actionId : additionalActions) { AnAction action = actionManager.getAction(actionId); if (action != null) { if (isModalContext && !action.isEnabledInModalContext()) { continue; } hasSecondStroke |= addAction(action, altShortCut); } } } } myContext.setHasSecondStroke(hasSecondStroke); Comparator<? super AnAction> comparator = PlatformDataKeys.ACTIONS_SORTER.getData(myContext.getDataContext()); if (comparator != null) { Collections.sort(myContext.getActions(), comparator); } return myContext; }