private void updateInBackground(Editor editor, @Nullable PsiElement element, @NotNull ImplementationViewComponent component, String title, @NotNull AbstractPopup popup, @NotNull Ref<UsageView> usageView) { final ImplementationsUpdaterTask updaterTask = SoftReference.dereference(myTaskRef); cancelTask(updaterTask); if (element == null) return; //already found final ImplementationsUpdaterTask task = new ImplementationsUpdaterTask(element, editor, title, isIncludeAlwaysSelf()); task.init(popup, component, usageView); myTaskRef = new WeakReference<ImplementationsUpdaterTask>(task); ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, new BackgroundableProcessIndicator(task)); }
@Nullable public static DocumentationComponent getActiveDocComponent(@NotNull Project project) { DocumentationManager documentationManager = DocumentationManager.getInstance(project); DocumentationComponent component; JBPopup hint = documentationManager.getDocInfoHint(); if (hint != null) { component = (DocumentationComponent)((AbstractPopup)hint).getComponent(); } else if (documentationManager.hasActiveDockedDocWindow()) { ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.DOCUMENTATION); Content selectedContent = toolWindow == null ? null : toolWindow.getContentManager().getSelectedContent(); component = selectedContent == null ? null : (DocumentationComponent)selectedContent.getComponent(); } else { component = null; } return component; }
private void updateInBackground(Editor editor, @Nullable PsiElement element, ImplementationViewComponent component, String title, AbstractPopup popup, Ref<UsageView> usageView) { if (myTaskRef != null) { final BackgroundUpdaterTask updaterTask = myTaskRef.get(); if (updaterTask != null) { updaterTask.setCanceled(); } } if (element == null) return; //already found final ImplementationsUpdaterTask task = new ImplementationsUpdaterTask(element, editor, title, isIncludeAlwaysSelf()); task.init(popup, component, usageView); myTaskRef = new WeakReference<BackgroundUpdaterTask>(task); ProgressManager.getInstance().run(task); }
private void updateInBackground(Editor editor, @Nullable PsiElement element, @Nonnull ImplementationViewComponent component, String title, @Nonnull AbstractPopup popup, @Nonnull Ref<UsageView> usageView) { final ImplementationsUpdaterTask updaterTask = SoftReference.dereference(myTaskRef); if (updaterTask != null) { updaterTask.cancelTask(); } if (element == null) return; //already found final ImplementationsUpdaterTask task = new ImplementationsUpdaterTask(element, editor, title, isIncludeAlwaysSelf()); task.init(popup, component, usageView); myTaskRef = new WeakReference<>(task); ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, new BackgroundableProcessIndicator(task)); }
@Nullable public static DocumentationComponent getActiveDocComponent(@Nonnull Project project) { DocumentationManager documentationManager = DocumentationManager.getInstance(project); DocumentationComponent component; JBPopup hint = documentationManager.getDocInfoHint(); if (hint != null) { component = (DocumentationComponent)((AbstractPopup)hint).getComponent(); } else if (documentationManager.hasActiveDockedDocWindow()) { ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.DOCUMENTATION); Content selectedContent = toolWindow == null ? null : toolWindow.getContentManager().getSelectedContent(); component = selectedContent == null ? null : (DocumentationComponent)selectedContent.getComponent(); } else { component = null; } return component; }
private static boolean isHintsAllowed(Window window) { if (window instanceof RootPaneContainer) { final JRootPane pane = ((RootPaneContainer)window).getRootPane(); if (pane != null) { return Boolean.TRUE.equals(pane.getClientProperty(AbstractPopup.SHOW_HINTS)); } } return false; }
private boolean isChildFor(final Component parent) { final Component toFocus = queryToFocus(getCleanStack(), this, false); if (toFocus == null) return false; if (parent == toFocus) return true; if (SwingUtilities.isDescendingFrom(toFocus, parent)) return true; Component eachToFocus = getFocusOwner(); FocusTrackback eachTrackback = this; while (true) { if (eachToFocus == null) { break; } if (SwingUtilities.isDescendingFrom(eachToFocus, parent)) return true; if (eachTrackback.getRequestor() instanceof AbstractPopup) { FocusTrackback newTrackback = ((AbstractPopup)eachTrackback.getRequestor()).getFocusTrackback(); if (newTrackback == null || eachTrackback == newTrackback) break; if (eachTrackback == null || eachTrackback.isConsumed()) break; eachTrackback = newTrackback; eachToFocus = eachTrackback.getFocusOwner(); } else { break; } } return false; }
public LookupImpl(Project project, Editor editor, @NotNull LookupArranger arranger) { super(new JPanel(new BorderLayout())); setForceShowAsPopup(true); setCancelOnClickOutside(false); setResizable(true); AbstractPopup.suppressMacCornerFor(getComponent()); myProject = project; myEditor = editor; myArranger = arranger; myPresentableArranger = arranger; DaemonCodeAnalyzer.getInstance(myProject).disableUpdateByTimer(this); myCellRenderer = new LookupCellRenderer(this); myList.setCellRenderer(myCellRenderer); myList.setFocusable(false); myList.setFixedCellWidth(50); myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); myList.setBackground(LookupCellRenderer.BACKGROUND_COLOR); myList.getExpandableItemsHandler(); myAdComponent = new Advertiser(); myOffsets = new LookupOffsets(editor); final CollectionListModel<LookupElement> model = getListModel(); addEmptyItem(model); updateListHeight(model); addListeners(); }
AsyncResult<RelativePoint> getHintContainerShowPoint() { final AsyncResult<RelativePoint> result = new AsyncResult<RelativePoint>(); if (myLocationCache == null) { if (myHintContainer != null) { final Point p = AbstractPopup.getCenterOf(myHintContainer, this); p.y -= myHintContainer.getVisibleRect().height / 4; myLocationCache = RelativePoint.fromScreen(p); } else { if (myContextComponent != null) { myLocationCache = JBPopupFactory.getInstance().guessBestPopupLocation(DataManager.getInstance().getDataContext(myContextComponent)); } else { DataManager.getInstance().getDataContextFromFocus().doWhenDone(new Consumer<DataContext>() { @Override public void consume(DataContext dataContext) { myContextComponent = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext); myLocationCache = JBPopupFactory.getInstance().guessBestPopupLocation(DataManager.getInstance().getDataContext(myContextComponent)); } }); } } } final Component c = myLocationCache.getComponent(); if (!(c instanceof JComponent && c.isShowing())) { //Yes. It happens sometimes. // 1. Empty frame. call nav bar, select some package and open it in Project View // 2. Call nav bar, then Esc // 3. Hide all tool windows (Ctrl+Shift+F12), so we've got empty frame again // 4. Call nav bar. NPE. ta da final JComponent ideFrame = WindowManager.getInstance().getIdeFrame(getProject()).getComponent(); final JRootPane rootPane = UIUtil.getRootPane(ideFrame); myLocationCache = JBPopupFactory.getInstance().guessBestPopupLocation(rootPane); } result.setDone(myLocationCache); return result; }
public void mouseDragged(MouseEvent e) { if (e.isConsumed()) return; AbstractPopup.setDefaultCursor(myComponent); if (myStartPoint != null) { final Point draggedTo = new RelativePoint(e).getScreenPoint(); draggedTo.x -= myStartPoint.x; draggedTo.y -= myStartPoint.y; AbstractPopup.moveTo(myComponent, draggedTo, null); e.consume(); } }
public void init(@NotNull AbstractPopup popup, T component, Ref<UsageView> usageView) { myPopup = popup; myComponent = component; myUsageView = usageView; myPopup.addPopupListener(new JBPopupAdapter() { @Override public void onClosed(LightweightWindowEvent event) { setCanceled(); } }); }
private void rebuildPopup(@NotNull final UsageViewImpl usageView, @NotNull final List<Usage> usages, @NotNull List<UsageNode> nodes, @NotNull final JTable table, @NotNull final JBPopup popup, @NotNull final UsageViewPresentation presentation, @NotNull final RelativePoint popupPosition, boolean findUsagesInProgress) { ApplicationManager.getApplication().assertIsDispatchThread(); boolean shouldShowMoreSeparator = usages.contains(MORE_USAGES_SEPARATOR); if (shouldShowMoreSeparator) { nodes.add(MORE_USAGES_SEPARATOR_NODE); } String title = presentation.getTabText(); String fullTitle = getFullTitle(usages, title, shouldShowMoreSeparator, nodes.size() - (shouldShowMoreSeparator ? 1 : 0), findUsagesInProgress); ((AbstractPopup)popup).setCaption(fullTitle); List<UsageNode> data = collectData(usages, nodes, usageView, presentation); MyModel tableModel = setTableModel(table, usageView, data); List<UsageNode> existingData = tableModel.getItems(); int row = table.getSelectedRow(); int newSelection = updateModel(tableModel, existingData, data, row == -1 ? 0 : row); if (newSelection < 0 || newSelection >= tableModel.getRowCount()) { TableScrollingUtil.ensureSelectionExists(table); newSelection = table.getSelectedRow(); } else { table.getSelectionModel().setSelectionInterval(newSelection, newSelection); } TableScrollingUtil.ensureIndexIsVisible(table, newSelection, 0); setSizeAndDimensions(table, popup, popupPosition, data); }
AsyncResult<RelativePoint> getHintContainerShowPoint() { final AsyncResult<RelativePoint> result = new AsyncResult<RelativePoint>(); if (myLocationCache == null) { if (myHintContainer != null) { final Point p = AbstractPopup.getCenterOf(myHintContainer, this); p.y -= myHintContainer.getVisibleRect().height / 4; myLocationCache = RelativePoint.fromScreen(p); } else { if (myContextComponent != null) { myLocationCache = JBPopupFactory.getInstance().guessBestPopupLocation(DataManager.getInstance().getDataContext(myContextComponent)); } else { DataManager.getInstance().getDataContextFromFocus().doWhenDone(new AsyncResult.Handler<DataContext>() { @Override public void run(DataContext dataContext) { myContextComponent = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext); myLocationCache = JBPopupFactory.getInstance().guessBestPopupLocation(DataManager.getInstance().getDataContext(myContextComponent)); } }); } } } final Component c = myLocationCache.getComponent(); if (!(c instanceof JComponent && c.isShowing())) { //Yes. It happens sometimes. // 1. Empty frame. call nav bar, select some package and open it in Project View // 2. Call nav bar, then Esc // 3. Hide all tool windows (Ctrl+Shift+F12), so we've got empty frame again // 4. Call nav bar. NPE. ta da final JComponent ideFrame = WindowManager.getInstance().getIdeFrame(getProject()).getComponent(); final JRootPane rootPane = UIUtil.getRootPane(ideFrame); myLocationCache = JBPopupFactory.getInstance().guessBestPopupLocation(rootPane); } result.setDone(myLocationCache); return result; }
private void rebuildPopup(@NotNull final UsageViewImpl usageView, @NotNull final List<Usage> usages, @NotNull List<UsageNode> nodes, @NotNull final JTable table, @NotNull final JBPopup popup, @NotNull final UsageViewPresentation presentation, @NotNull final RelativePoint popupPosition, boolean findUsagesInProgress) { ApplicationManager.getApplication().assertIsDispatchThread(); boolean shouldShowMoreSeparator = usages.contains(MORE_USAGES_SEPARATOR); if (shouldShowMoreSeparator) { nodes.add(MORE_USAGES_SEPARATOR_NODE); } String title = presentation.getTabText(); String fullTitle = getFullTitle(usages, title, shouldShowMoreSeparator, nodes.size() - (shouldShowMoreSeparator ? 1 : 0), findUsagesInProgress); ((AbstractPopup) popup).setCaption(fullTitle); List<UsageNode> data = collectData(usages, nodes, usageView, presentation); MyModel tableModel = setTableModel(table, usageView, data); List<UsageNode> existingData = tableModel.getItems(); int row = table.getSelectedRow(); int newSelection = updateModel(tableModel, existingData, data, row == -1 ? 0 : row); if (newSelection < 0 || newSelection >= tableModel.getRowCount()) { TableScrollingUtil.ensureSelectionExists(table); newSelection = table.getSelectedRow(); } else { table.getSelectionModel().setSelectionInterval(newSelection, newSelection); } TableScrollingUtil.ensureIndexIsVisible(table, newSelection, 0); setSizeAndDimensions(table, popup, popupPosition, data); }
public List<JBPopup> getChildPopups(@Nonnull final Component component) { return AbstractPopup.all.toStrongList().stream().filter(popup -> { Component owner = popup.getOwner(); while (owner != null) { if (owner.equals(component)) { return true; } owner = owner.getParent(); } return false; }).collect(Collectors.toList()); }
private void doShowJavaDocInfo(@NotNull final PsiElement element, boolean requestFocus, PopupUpdateProcessor updateProcessor, final PsiElement originalElement, @Nullable final Runnable closeCallback) { Project project = getProject(element); if (!project.isOpen()) return; storeOriginalElement(project, originalElement, element); myPreviouslyFocused = WindowManagerEx.getInstanceEx().getFocusedComponent(project); JBPopup _oldHint = getDocInfoHint(); if (PreviewManager.SERVICE.preview(myProject, DocumentationPreviewPanelProvider.ID, Couple.of(element, originalElement), requestFocus) != null) { return; } if (myToolWindow == null && PropertiesComponent.getInstance().isTrueValue(SHOW_DOCUMENTATION_IN_TOOL_WINDOW)) { createToolWindow(element, originalElement); } else if (myToolWindow != null) { Content content = myToolWindow.getContentManager().getSelectedContent(); if (content != null) { DocumentationComponent component = (DocumentationComponent)content.getComponent(); boolean sameElement = element.getManager().areElementsEquivalent(component.getElement(), element); if (sameElement) { JComponent preferredFocusableComponent = content.getPreferredFocusableComponent(); // focus toolwindow on the second actionPerformed boolean focus = requestFocus || CommandProcessor.getInstance().getCurrentCommand() != null; if (preferredFocusableComponent != null && focus) { IdeFocusManager.getInstance(myProject).requestFocus(preferredFocusableComponent, true); } } if (!sameElement || !component.isUpToDate()) { content.setDisplayName(getTitle(element, true)); fetchDocInfo(getDefaultCollector(element, originalElement), component, true); } } if (!myToolWindow.isVisible()) { myToolWindow.show(null); } } else if (_oldHint != null && _oldHint.isVisible() && _oldHint instanceof AbstractPopup) { DocumentationComponent oldComponent = (DocumentationComponent)((AbstractPopup)_oldHint).getComponent(); fetchDocInfo(getDefaultCollector(element, originalElement), oldComponent); } else { showInPopup(element, requestFocus, updateProcessor, originalElement, closeCallback); } }
public void init(@NotNull AbstractPopup popup, @NotNull T component, @NotNull Ref<UsageView> usageView) { myPopup = popup; myComponent = component; myUsageView = usageView; }
private void rebuildTable(@NotNull final UsageViewImpl usageView, @NotNull final List<Usage> usages, @NotNull List<UsageNode> nodes, @NotNull final JTable table, @Nullable final JBPopup popup, @NotNull final UsageViewPresentation presentation, @NotNull final RelativePoint popupPosition, boolean findUsagesInProgress, @NotNull AtomicInteger outOfScopeUsages, @NotNull SearchScope searchScope) { ApplicationManager.getApplication().assertIsDispatchThread(); boolean shouldShowMoreSeparator = usages.contains(MORE_USAGES_SEPARATOR); if (shouldShowMoreSeparator) { nodes.add(MORE_USAGES_SEPARATOR_NODE); } boolean hasOutsideScopeUsages = usages.contains(USAGES_OUTSIDE_SCOPE_SEPARATOR); if (hasOutsideScopeUsages && !shouldShowMoreSeparator) { nodes.add(USAGES_OUTSIDE_SCOPE_NODE); } String title = presentation.getTabText(); String fullTitle = getFullTitle(usages, title, shouldShowMoreSeparator || hasOutsideScopeUsages, nodes.size() - (shouldShowMoreSeparator || hasOutsideScopeUsages ? 1 : 0), findUsagesInProgress); if (popup != null) { ((AbstractPopup)popup).setCaption(fullTitle); } List<UsageNode> data = collectData(usages, nodes, usageView, presentation); MyModel tableModel = setTableModel(table, usageView, data, outOfScopeUsages, searchScope); List<UsageNode> existingData = tableModel.getItems(); int row = table.getSelectedRow(); int newSelection = updateModel(tableModel, existingData, data, row == -1 ? 0 : row); if (newSelection < 0 || newSelection >= tableModel.getRowCount()) { ScrollingUtil.ensureSelectionExists(table); newSelection = table.getSelectedRow(); } else { table.getSelectionModel().setSelectionInterval(newSelection, newSelection); } ScrollingUtil.ensureIndexIsVisible(table, newSelection, 0); if (popup != null) { setSizeAndDimensions(table, popup, popupPosition, data); } }
private void setSizeAndDimensions(@NotNull JTable table, @NotNull JBPopup popup, @NotNull RelativePoint popupPosition, @NotNull List<UsageNode> data) { JComponent content = popup.getContent(); Window window = SwingUtilities.windowForComponent(content); Dimension d = window.getSize(); int width = calcMaxWidth(table); width = (int)Math.max(d.getWidth(), width); Dimension headerSize = ((AbstractPopup)popup).getHeaderPreferredSize(); width = Math.max((int)headerSize.getWidth(), width); width = Math.max(myWidth, width); if (myWidth == -1) myWidth = width; int newWidth = Math.max(width, d.width + width - myWidth); myWidth = newWidth; int rowsToShow = Math.min(30, data.size()); Dimension dimension = new Dimension(newWidth, table.getRowHeight() * rowsToShow); Rectangle rectangle = fitToScreen(dimension, popupPosition, table); if (!data.isEmpty()) { ScrollingUtil.ensureSelectionExists(table); } table.setSize(rectangle.getSize()); //table.setPreferredSize(dimension); //table.setMaximumSize(dimension); //table.setPreferredScrollableViewportSize(dimension); Dimension footerSize = ((AbstractPopup)popup).getFooterPreferredSize(); rectangle.height += headerSize.height + footerSize.height + 4/* invisible borders, margins etc*/; ScreenUtil.fitToScreen(rectangle); Dimension newDim = rectangle.getSize(); window.setBounds(rectangle); window.setMinimumSize(newDim); window.setMaximumSize(newDim); window.validate(); window.repaint(); }
protected void showTextFieldPanel() { final JLayeredPane layeredPane = getLayeredPane(); final Dimension preferredTextFieldPanelSize = myTextFieldPanel.getPreferredSize(); final int x = (layeredPane.getWidth() - preferredTextFieldPanelSize.width) / 2; final int paneHeight = layeredPane.getHeight(); final int y = paneHeight / 3 - preferredTextFieldPanelSize.height / 2; VISIBLE_LIST_SIZE_LIMIT = Math.max (10, (paneHeight - (y + preferredTextFieldPanelSize.height)) / (preferredTextFieldPanelSize.height / 2) - 1); ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(myTextFieldPanel, myTextField); builder.setLocateWithinScreenBounds(false); builder.setKeyEventHandler(new BooleanFunction<KeyEvent>() { @Override public boolean fun(KeyEvent event) { if (myTextPopup == null || !AbstractPopup.isCloseRequest(event) || !myTextPopup.isCancelKeyEnabled()) { return false; } IdeFocusManager focusManager = IdeFocusManager.getInstance(myProject); if (isDescendingFromTemporarilyFocusableToolWindow(focusManager.getFocusOwner())) { focusManager.requestFocus(myTextField, true); return false; } else { myTextPopup.cancel(event); return true; } } }).setCancelCallback(new Computable<Boolean>() { @Override public Boolean compute() { myTextPopup = null; close(false); return Boolean.TRUE; } }).setFocusable(true).setRequestFocus(true).setModalContext(false).setCancelOnClickOutside(false); Point point = new Point(x, y); SwingUtilities.convertPointToScreen(point, layeredPane); Rectangle bounds = new Rectangle(point, new Dimension(preferredTextFieldPanelSize.width + 20, preferredTextFieldPanelSize.height)); myTextPopup = builder.createPopup(); myTextPopup.setSize(bounds.getSize()); myTextPopup.setLocation(bounds.getLocation()); MnemonicHelper.init(myTextFieldPanel); if (myProject != null && !myProject.isDefault()) { DaemonCodeAnalyzer.getInstance(myProject).disableUpdateByTimer(myTextPopup); } Disposer.register(myTextPopup, new Disposable() { @Override public void dispose() { cancelListUpdater(); } }); myTextPopup.show(layeredPane); if (myTextPopup instanceof AbstractPopup) { Window window = ((AbstractPopup)myTextPopup).getPopupWindow(); if (window instanceof JDialog) { ((JDialog)window).getRootPane().putClientProperty(WindowAction.NO_WINDOW_ACTIONS, Boolean.TRUE); } } }
private void endOperation() { AbstractPopup.setDefaultCursor(myComponent); myStartPoint = null; }
public void mouseMoved(MouseEvent e) { if (e.isConsumed()) return; AbstractPopup.setDefaultCursor(myComponent); }
public ResizeComponentListener(final AbstractPopup popup, IdeGlassPane glassPane) { myPopup = popup; myComponent = (AbstractPopup.MyContentPanel)popup.getContent(); myGlassPane = glassPane; }
public LookupImpl(Project project, Editor editor, @NotNull LookupArranger arranger) { super(new JPanel(new BorderLayout())); setForceShowAsPopup(true); setCancelOnClickOutside(false); setResizable(true); AbstractPopup.suppressMacCornerFor(getComponent()); myProject = project; myEditor = editor; myArranger = arranger; myPresentableArranger = arranger; myIconPanel.setVisible(false); myCellRenderer = new LookupCellRenderer(this); myList.setCellRenderer(myCellRenderer); myList.setFocusable(false); myList.setFixedCellWidth(50); myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); myList.setBackground(LookupCellRenderer.BACKGROUND_COLOR); myList.getExpandableItemsHandler(); myScrollBarIncreaseButton = new JButton(); myScrollBarIncreaseButton.setFocusable(false); myScrollBarIncreaseButton.setRequestFocusEnabled(false); myScrollPane = new JBScrollPane(myList); myScrollPane.setViewportBorder(new EmptyBorder(0, 0, 0, 0)); myScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); myScrollPane.getVerticalScrollBar().setPreferredSize(new Dimension(13, -1)); myScrollPane.getVerticalScrollBar().setUI(new ButtonlessScrollBarUI() { @Override protected JButton createIncreaseButton(int orientation) { return myScrollBarIncreaseButton; } }); getComponent().add(myLayeredPane, BorderLayout.CENTER); //IDEA-82111 fixMouseCheaters(); myLayeredPane.mainPanel.add(myScrollPane, BorderLayout.CENTER); myScrollPane.setBorder(null); myAdComponent = new Advertiser(); JComponent adComponent = myAdComponent.getAdComponent(); adComponent.setBorder(new EmptyBorder(0, 1, 1, 2 + AllIcons.Ide.LookupRelevance.getIconWidth())); myLayeredPane.mainPanel.add(adComponent, BorderLayout.SOUTH); getComponent().setBorder(new BegPopupMenuBorder()); myIconPanel.setBackground(Color.LIGHT_GRAY); myIconPanel.add(myProcessIcon); myOffsets = new LookupOffsets(editor); final CollectionListModel<LookupElement> model = getListModel(); addEmptyItem(model); updateListHeight(model); addListeners(); mySortingLabel.setBorder(new LineBorder(new JBColor(Color.LIGHT_GRAY, JBColor.background()))); mySortingLabel.setOpaque(true); new ChangeLookupSorting().installOn(mySortingLabel); updateSorting(); myModalityState = ModalityState.stateForComponent(getComponent()); }
private void setSizeAndDimensions(@NotNull JTable table, @NotNull JBPopup popup, @NotNull RelativePoint popupPosition, @NotNull List<UsageNode> data) { JComponent content = popup.getContent(); Window window = SwingUtilities.windowForComponent(content); Dimension d = window.getSize(); int width = calcMaxWidth(table); width = (int)Math.max(d.getWidth(), width); Dimension headerSize = ((AbstractPopup)popup).getHeaderPreferredSize(); width = Math.max((int)headerSize.getWidth(), width); width = Math.max(myWidth, width); if (myWidth == -1) myWidth = width; int newWidth = Math.max(width, d.width + width - myWidth); myWidth = newWidth; int rowsToShow = Math.min(30, data.size()); Dimension dimension = new Dimension(newWidth, table.getRowHeight() * rowsToShow); Rectangle rectangle = fitToScreen(dimension, popupPosition, table); dimension = rectangle.getSize(); Point location = window.getLocation(); if (!location.equals(rectangle.getLocation())) { window.setLocation(rectangle.getLocation()); } if (!data.isEmpty()) { TableScrollingUtil.ensureSelectionExists(table); } table.setSize(dimension); //table.setPreferredSize(dimension); //table.setMaximumSize(dimension); //table.setPreferredScrollableViewportSize(dimension); Dimension footerSize = ((AbstractPopup)popup).getFooterPreferredSize(); int newHeight = (int)(dimension.height + headerSize.getHeight() + footerSize.getHeight()) + 4/* invisible borders, margins etc*/; Dimension newDim = new Dimension(dimension.width, newHeight); window.setSize(newDim); window.setMinimumSize(newDim); window.setMaximumSize(newDim); window.validate(); window.repaint(); table.revalidate(); table.repaint(); }
private void setSizeAndDimensions(@NotNull JTable table, @NotNull JBPopup popup, @NotNull RelativePoint popupPosition, @NotNull List<UsageNode> data) { JComponent content = popup.getContent(); Window window = SwingUtilities.windowForComponent(content); Dimension d = window.getSize(); int width = calcMaxWidth(table); width = (int) Math.max(d.getWidth(), width); Dimension headerSize = ((AbstractPopup) popup).getHeaderPreferredSize(); width = Math.max((int) headerSize.getWidth(), width); width = Math.max(myWidth, width); if (myWidth == -1) myWidth = width; int newWidth = Math.max(width, d.width + width - myWidth); myWidth = newWidth; int rowsToShow = Math.min(30, data.size()); Dimension dimension = new Dimension(newWidth, table.getRowHeight() * rowsToShow); Rectangle rectangle = fitToScreen(dimension, popupPosition, table); dimension = rectangle.getSize(); Point location = window.getLocation(); if (!location.equals(rectangle.getLocation())) { window.setLocation(rectangle.getLocation()); } if (!data.isEmpty()) { TableScrollingUtil.ensureSelectionExists(table); } table.setSize(dimension); //table.setPreferredSize(dimension); //table.setMaximumSize(dimension); //table.setPreferredScrollableViewportSize(dimension); Dimension footerSize = ((AbstractPopup) popup).getFooterPreferredSize(); int newHeight = (int) (dimension.height + headerSize.getHeight() + footerSize.getHeight()) + 4/* invisible borders, margins etc*/; Dimension newDim = new Dimension(dimension.width, newHeight); window.setSize(newDim); window.setMinimumSize(newDim); window.setMaximumSize(newDim); window.validate(); window.repaint(); table.revalidate(); table.repaint(); }
private void doShowJavaDocInfo(@Nonnull final PsiElement element, boolean requestFocus, PopupUpdateProcessor updateProcessor, final PsiElement originalElement, @Nullable final Runnable closeCallback) { Project project = getProject(element); if (!project.isOpen()) return; storeOriginalElement(project, originalElement, element); myPreviouslyFocused = WindowManagerEx.getInstanceEx().getFocusedComponent(project); JBPopup _oldHint = getDocInfoHint(); if (myToolWindow == null && PropertiesComponent.getInstance().isTrueValue(SHOW_DOCUMENTATION_IN_TOOL_WINDOW)) { createToolWindow(element, originalElement); } else if (myToolWindow != null) { Content content = myToolWindow.getContentManager().getSelectedContent(); if (content != null) { DocumentationComponent component = (DocumentationComponent)content.getComponent(); boolean sameElement = element.getManager().areElementsEquivalent(component.getElement(), element); if (sameElement) { JComponent preferredFocusableComponent = content.getPreferredFocusableComponent(); // focus toolwindow on the second actionPerformed boolean focus = requestFocus || CommandProcessor.getInstance().getCurrentCommand() != null; if (preferredFocusableComponent != null && focus) { IdeFocusManager.getInstance(myProject).requestFocus(preferredFocusableComponent, true); } } if (!sameElement || !component.isUpToDate()) { content.setDisplayName(getTitle(element, true)); fetchDocInfo(getDefaultCollector(element, originalElement), component, true); } } if (!myToolWindow.isVisible()) { myToolWindow.show(null); } } else if (_oldHint != null && _oldHint.isVisible() && _oldHint instanceof AbstractPopup) { DocumentationComponent oldComponent = (DocumentationComponent)((AbstractPopup)_oldHint).getComponent(); fetchDocInfo(getDefaultCollector(element, originalElement), oldComponent); } else { showInPopup(element, requestFocus, updateProcessor, originalElement, closeCallback); } }
public void init(@Nonnull AbstractPopup popup, @Nonnull T component, @Nonnull Ref<UsageView> usageView) { myPopup = popup; myComponent = component; myUsageView = usageView; }
public LookupImpl(Project project, Editor editor, @Nonnull LookupArranger arranger) { super(new JPanel(new BorderLayout())); setForceShowAsPopup(true); setCancelOnClickOutside(false); setResizable(true); AbstractPopup.suppressMacCornerFor(getComponent()); myProject = project; myEditor = InjectedLanguageUtil.getTopLevelEditor(editor); myArranger = arranger; myPresentableArranger = arranger; myEditor.getColorsScheme().getFontPreferences().copyTo(myFontPreferences); DaemonCodeAnalyzer.getInstance(myProject).disableUpdateByTimer(this); myCellRenderer = new LookupCellRenderer(this); myList.setCellRenderer(myCellRenderer); myList.setFocusable(false); myList.setFixedCellWidth(50); // a new top level frame just got the focus. This is important to prevent screen readers // from announcing the title of the top level frame when the list is shown (or hidden), // as they usually do when a new top-level frame receives the focus. AccessibleContextUtil.setParent(myList, myEditor.getContentComponent()); myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); myList.setBackground(LookupCellRenderer.BACKGROUND_COLOR); myList.getExpandableItemsHandler(); myAdComponent = new Advertiser(); myOffsets = new LookupOffsets(myEditor); final CollectionListModel<LookupElement> model = getListModel(); addEmptyItem(model); updateListHeight(model); addListeners(); }
private void rebuildTable(@Nonnull final UsageViewImpl usageView, @Nonnull final List<Usage> usages, @Nonnull List<UsageNode> nodes, @Nonnull final JTable table, @Nullable final JBPopup popup, @Nonnull final UsageViewPresentation presentation, @Nonnull final RelativePoint popupPosition, boolean findUsagesInProgress, @Nonnull AtomicInteger outOfScopeUsages, @Nonnull SearchScope searchScope) { ApplicationManager.getApplication().assertIsDispatchThread(); boolean shouldShowMoreSeparator = usages.contains(MORE_USAGES_SEPARATOR); if (shouldShowMoreSeparator) { nodes.add(MORE_USAGES_SEPARATOR_NODE); } boolean hasOutsideScopeUsages = usages.contains(USAGES_OUTSIDE_SCOPE_SEPARATOR); if (hasOutsideScopeUsages && !shouldShowMoreSeparator) { nodes.add(USAGES_OUTSIDE_SCOPE_NODE); } String title = presentation.getTabText(); String fullTitle = getFullTitle(usages, title, shouldShowMoreSeparator || hasOutsideScopeUsages, nodes.size() - (shouldShowMoreSeparator || hasOutsideScopeUsages ? 1 : 0), findUsagesInProgress); if (popup != null) { ((AbstractPopup)popup).setCaption(fullTitle); } List<UsageNode> data = collectData(usages, nodes, usageView, presentation); MyModel tableModel = setTableModel(table, usageView, data, outOfScopeUsages, searchScope); List<UsageNode> existingData = tableModel.getItems(); int row = table.getSelectedRow(); int newSelection = updateModel(tableModel, existingData, data, row == -1 ? 0 : row); if (newSelection < 0 || newSelection >= tableModel.getRowCount()) { ScrollingUtil.ensureSelectionExists(table); newSelection = table.getSelectedRow(); } else { // do not pre-select the usage under caret by default if (newSelection == 0 && table.getModel().getRowCount() > 1) { Object valueInTopRow = table.getModel().getValueAt(0, 0); if (valueInTopRow instanceof UsageNode && usageView.isOriginUsage(((UsageNode)valueInTopRow).getUsage())) { newSelection++; } } table.getSelectionModel().setSelectionInterval(newSelection, newSelection); } ScrollingUtil.ensureIndexIsVisible(table, newSelection, 0); if (popup != null) { setSizeAndDimensions(table, popup, popupPosition, data); } }
private void setSizeAndDimensions(@Nonnull JTable table, @Nonnull JBPopup popup, @Nonnull RelativePoint popupPosition, @Nonnull List<UsageNode> data) { JComponent content = popup.getContent(); Window window = SwingUtilities.windowForComponent(content); Dimension d = window.getSize(); int width = calcMaxWidth(table); width = (int)Math.max(d.getWidth(), width); Dimension headerSize = ((AbstractPopup)popup).getHeaderPreferredSize(); width = Math.max((int)headerSize.getWidth(), width); width = Math.max(myWidth, width); if (myWidth == -1) myWidth = width; int newWidth = Math.max(width, d.width + width - myWidth); myWidth = newWidth; int rowsToShow = Math.min(30, data.size()); Dimension dimension = new Dimension(newWidth, table.getRowHeight() * rowsToShow); Rectangle rectangle = fitToScreen(dimension, popupPosition, table); if (!data.isEmpty()) { ScrollingUtil.ensureSelectionExists(table); } table.setSize(rectangle.getSize()); //table.setPreferredSize(dimension); //table.setMaximumSize(dimension); //table.setPreferredScrollableViewportSize(dimension); Dimension footerSize = ((AbstractPopup)popup).getFooterPreferredSize(); int footer = footerSize.height; int footerBorder = footer == 0 ? 0 : 1; Insets insets = ((AbstractPopup)popup).getPopupBorder().getBorderInsets(content); rectangle.height += headerSize.height + footer + footerBorder + insets.top + insets.bottom; ScreenUtil.fitToScreen(rectangle); Dimension newDim = rectangle.getSize(); window.setBounds(rectangle); window.setMinimumSize(newDim); window.setMaximumSize(newDim); window.validate(); window.repaint(); }