@Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { removeAll(); myRightComponentWidth = 0; DefaultListCellRenderer rightRenderer = getRightCellRenderer(value); Component rightCellRendererComponent = null; JPanel spacer = null; if (rightRenderer != null) { rightCellRendererComponent = rightRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); add(rightCellRendererComponent, BorderLayout.EAST); spacer = new JPanel(); spacer.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 2)); add(spacer, BorderLayout.CENTER); myRightComponentWidth = rightCellRendererComponent.getPreferredSize().width; myRightComponentWidth += spacer.getPreferredSize().width; } ListCellRenderer leftRenderer = new LeftRenderer(null, MatcherHolder.getAssociatedMatcher(list)); final Component leftCellRendererComponent = leftRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); add(leftCellRendererComponent, LEFT); final Color bg = isSelected ? UIUtil.getListSelectionBackground() : leftCellRendererComponent.getBackground(); setBackground(bg); if (rightCellRendererComponent != null) { rightCellRendererComponent.setBackground(bg); } if (spacer != null) { spacer.setBackground(bg); } return this; }
@Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { removeAll(); final boolean hasRightRenderer = UISettings.getInstance().getShowIconInQuickNavigation(); final LeftRenderer left = new LeftRenderer(true, MatcherHolder.getAssociatedMatcher(list)); final Component leftCellRendererComponent = left.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); final Color listBg = leftCellRendererComponent.getBackground(); add(leftCellRendererComponent, BorderLayout.WEST); setBackground(isSelected ? UIUtil.getListSelectionBackground() : listBg); if (hasRightRenderer) { final DefaultListCellRenderer moduleRenderer = new PsiElementModuleRenderer(); final Component rightCellRendererComponent = moduleRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); ((JComponent)rightCellRendererComponent).setOpaque(false); rightCellRendererComponent.setBackground(listBg); add(rightCellRendererComponent, BorderLayout.EAST); final JPanel spacer = new NonOpaquePanel(); final Dimension size = rightCellRendererComponent.getSize(); spacer.setSize(new Dimension((int)(size.width * 0.015 + leftCellRendererComponent.getSize().width * 0.015), size.height)); spacer.setBackground(isSelected ? UIUtil.getListSelectionBackground() : listBg); add(spacer, BorderLayout.CENTER); } return this; }
protected void rebuildList(final int pos, final int delay, @NotNull final ModalityState modalityState, @Nullable final Runnable postRunnable) { ApplicationManager.getApplication().assertIsDispatchThread(); if (!myInitialized) { return; } myAlarm.cancelAllRequests(); if (delay > 0) { myAlarm.addRequest(new Runnable() { @Override public void run() { rebuildList(pos, 0, modalityState, postRunnable); } }, delay, ModalityState.stateForComponent(myTextField)); return; } myListUpdater.cancelAll(); final CalcElementsThread calcElementsThread = myCalcElementsThread; if (calcElementsThread != null) { calcElementsThread.cancel(); } final String text = getTrimmedText(); if (!canShowListForEmptyPattern() && text.isEmpty()) { myListModel.clear(); hideList(); myTextFieldPanel.hideHint(); myCard.show(myCardContainer, CHECK_BOX_CARD); return; } ListCellRenderer cellRenderer = myList.getCellRenderer(); if (cellRenderer instanceof ExpandedItemListCellRendererWrapper) { cellRenderer = ((ExpandedItemListCellRendererWrapper)cellRenderer).getWrappee(); } if (cellRenderer instanceof MatcherHolder) { final String pattern = patternToLowerCase(transformPattern(text)); final Matcher matcher = buildPatternMatcher(isSearchInAnyPlace() ? "*" + pattern : pattern); ((MatcherHolder)cellRenderer).setPatternMatcher(matcher); } scheduleCalcElements(text, myCheckBox.isSelected(), modalityState, new Consumer<Set<?>>() { @Override public void consume(Set<?> elements) { ApplicationManager.getApplication().assertIsDispatchThread(); backgroundCalculationFinished(elements, pos); if (postRunnable != null) { postRunnable.run(); } } }); }
protected void rebuildList(final int pos, final int delay, @NotNull final ModalityState modalityState, @Nullable final Runnable postRunnable) { ApplicationManager.getApplication().assertIsDispatchThread(); if (!myInitialized) { return; } myListIsUpToDate = false; myAlarm.cancelAllRequests(); myListUpdater.cancelAll(); cancelCalcElementsThread(); final String text = myTextField.getText(); if (!canShowListForEmptyPattern() && (text == null || text.trim().isEmpty())) { myListModel.clear(); hideList(); myTextFieldPanel.hideHint(); myCard.show(myCardContainer, CHECK_BOX_CARD); return; } ListCellRenderer cellRenderer = myList.getCellRenderer(); if (cellRenderer instanceof ExpandedItemListCellRendererWrapper) { cellRenderer = ((ExpandedItemListCellRendererWrapper)cellRenderer).getWrappee(); } if (cellRenderer instanceof MatcherHolder) { final String pattern = transformPattern(text); final Matcher matcher = buildPatternMatcher(isSearchInAnyPlace() ? "*" + pattern : pattern); ((MatcherHolder)cellRenderer).setPatternMatcher(matcher); } final Runnable request = new Runnable() { @Override public void run() { scheduleCalcElements(text, myCheckBox.isSelected(), postRunnable == null, modalityState, new Consumer<Set<?>>() { @Override public void consume(Set<?> elements) { synchronized (myRebuildMutex) { ApplicationManager.getApplication().assertIsDispatchThread(); if (checkDisposed()) { return; } myListIsUpToDate = true; setElementsToList(pos, elements); myList.repaint(); chosenElementMightChange(); if (elements.isEmpty()) { myTextFieldPanel.hideHint(); } if (postRunnable != null) { postRunnable.run(); } } } }); } }; if (delay > 0) { myAlarm.addRequest(request, delay, ModalityState.stateForComponent(myTextField)); } else { request.run(); } }
@Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Component cmp; PsiElement file; myLocationString = null; String pattern = "*" + myPopupField.getText(); Matcher matcher = NameUtil.buildMatcher(pattern, 0, true, true, pattern.toLowerCase().equals(pattern)); if (isMoreItem(index)) { cmp = More.get(isSelected); } else if (value instanceof VirtualFile && myProject != null && ((((VirtualFile)value).isDirectory() && (file = PsiManager.getInstance(myProject).findDirectory((VirtualFile)value)) != null) || (file = PsiManager.getInstance(myProject).findFile((VirtualFile)value)) != null)) { MatcherHolder.associateMatcher(myFileRenderer, matcher); cmp = myFileRenderer.getListCellRendererComponent(list, file, index, isSelected, cellHasFocus); } else if (value instanceof PsiElement) { MatcherHolder.associateMatcher(myFileRenderer, matcher); cmp = myFileRenderer.getListCellRendererComponent(list, value, index, isSelected, isSelected); } else { cmp = super.getListCellRendererComponent(list, value, index, isSelected, isSelected); final JPanel p = new JPanel(new BorderLayout()); p.setBackground(UIUtil.getListBackground(isSelected)); p.add(cmp, BorderLayout.CENTER); cmp = p; } if (myLocationString != null || value instanceof BooleanOptionDescription) { final JPanel panel = new JPanel(new BorderLayout()); panel.setBackground(UIUtil.getListBackground(isSelected)); panel.add(cmp, BorderLayout.CENTER); final Component rightComponent; if (value instanceof BooleanOptionDescription) { final OnOffButton button = new OnOffButton(); button.setSelected(((BooleanOptionDescription)value).isOptionEnabled()); rightComponent = button; } else { rightComponent = myLocation.getListCellRendererComponent(list, value, index, isSelected, isSelected); } panel.add(rightComponent, BorderLayout.EAST); cmp = panel; } Color bg = cmp.getBackground(); if (bg == null) { cmp.setBackground(UIUtil.getListBackground(isSelected)); bg = cmp.getBackground(); } myMainPanel.setBorder(new CustomLineBorder(bg, 0, 0, 2, 0)); String title = getModel().titleIndex.getTitle(index); myMainPanel.removeAll(); if (title != null) { myTitle.setText(title); myMainPanel.add(createTitle(" " + title), BorderLayout.NORTH); } myMainPanel.add(cmp, BorderLayout.CENTER); final int width = myMainPanel.getPreferredSize().width; if (width > myPopupActualWidth) { myPopupActualWidth = width; //schedulePopupUpdate(); } return myMainPanel; }
protected void rebuildList(final int pos, final int delay, @Nonnull final ModalityState modalityState, @Nullable final Runnable postRunnable) { ApplicationManager.getApplication().assertIsDispatchThread(); if (!myInitialized) { return; } myAlarm.cancelAllRequests(); if (delay > 0) { myAlarm.addRequest(new Runnable() { @Override public void run() { rebuildList(pos, 0, modalityState, postRunnable); } }, delay, ModalityState.stateForComponent(myTextField)); return; } myListUpdater.cancelAll(); final CalcElementsThread calcElementsThread = myCalcElementsThread; if (calcElementsThread != null) { calcElementsThread.cancel(); } final String text = getTrimmedText(); if (!canShowListForEmptyPattern() && text.isEmpty()) { myListModel.clear(); hideList(); myTextFieldPanel.hideHint(); myCard.show(myCardContainer, CHECK_BOX_CARD); return; } ListCellRenderer cellRenderer = myList.getCellRenderer(); if (cellRenderer instanceof ExpandedItemListCellRendererWrapper) { cellRenderer = ((ExpandedItemListCellRendererWrapper)cellRenderer).getWrappee(); } if (cellRenderer instanceof MatcherHolder) { final String pattern = patternToLowerCase(transformPattern(text)); final Matcher matcher = buildPatternMatcher(isSearchInAnyPlace() ? "*" + pattern : pattern); ((MatcherHolder)cellRenderer).setPatternMatcher(matcher); } scheduleCalcElements(text, myCheckBox.isSelected(), modalityState, new Consumer<Set<?>>() { @Override public void consume(Set<?> elements) { ApplicationManager.getApplication().assertIsDispatchThread(); backgroundCalculationFinished(elements, pos); if (postRunnable != null) { postRunnable.run(); } } }); }