void addExcludePackage(String packageName) { if (packageName == null) { return; } int index = 0; while (index < getTableView().getListTableModel().getRowCount()) { if (getTableView().getListTableModel().getItem(index).exclude.compareTo(packageName) > 0) { break; } index++; } getTableView().getListTableModel().insertRow(index, new Item(packageName, ExclusionScope.IDE)); getTableView().clearSelection(); getTableView().addRowSelectionInterval(index, index); ScrollingUtil.ensureIndexIsVisible(getTableView(), index, 0); IdeFocusManager.getGlobalInstance().requestFocus(getTableView(), false); }
private static Sdk showDialog(final Project project, String title, final Component parent, Sdk jdkToSelect) { final JdkChooserPanel jdkChooserPanel = new JdkChooserPanel(project); jdkChooserPanel.fillList(null, null); final MyDialog dialog = jdkChooserPanel.new MyDialog(parent); if (title != null) { dialog.setTitle(title); } if (jdkToSelect != null) { jdkChooserPanel.selectJdk(jdkToSelect); } else { ScrollingUtil.ensureSelectionExists(jdkChooserPanel.myList); } new DoubleClickListener() { @Override protected boolean onDoubleClick(MouseEvent e) { dialog.clickDefaultButton(); return true; } }.installOn(jdkChooserPanel.myList); return dialog.showAndGet() ? jdkChooserPanel.getChosenJdk() : null; }
private boolean autoSelectUsingStatistics() { final String filter = getSpeedSearch().getFilter(); if (!StringUtil.isEmpty(filter)) { int maxUseCount = -1; int mostUsedValue = -1; int elementsCount = myListModel.getSize(); for (int i = 0; i < elementsCount; i++) { Object value = myListModel.getElementAt(i); final String text = getListStep().getTextFor(value); final int count = StatisticsManager.getInstance().getUseCount(new StatisticsInfo("#list_popup:" + myStep.getTitle() + "#" + filter, text)); if (count > maxUseCount) { maxUseCount = count; mostUsedValue = i; } } if (mostUsedValue > 0) { ScrollingUtil.selectItem(myList, mostUsedValue); return true; } } return false; }
private static void executeUpOrDown(LookupImpl lookup, boolean up) { if (!lookup.isFocused()) { boolean semiFocused = lookup.getFocusDegree() == LookupImpl.FocusDegree.SEMI_FOCUSED; lookup.setFocusDegree(LookupImpl.FocusDegree.FOCUSED); if (!up && !semiFocused) { return; } } if (up) { ScrollingUtil.moveUp(lookup.getList(), 0); } else { ScrollingUtil.moveDown(lookup.getList(), 0); } lookup.markSelectionTouched(); lookup.refreshUi(false, true); }
private boolean setSelectedItem(String type, boolean select) { DefaultListModel model = (DefaultListModel)myOptionsList.getModel(); for (int i = 0; i < model.size(); i++) { Object o = model.get(i); if (o instanceof EditorSchemeAttributeDescriptor) { if (type.equals(((EditorSchemeAttributeDescriptor)o).getType())) { if (select) { ScrollingUtil.selectItem(myOptionsList, i); } return true; } } } return false; }
@Nullable @Override protected JComponent createCenterPanel() { myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); myList.setCellRenderer(new FileTypeRenderer()); new DoubleClickListener() { @Override protected boolean onDoubleClick(MouseEvent e) { doOKAction(); return true; } }.installOn(myList); CCLanguageManager manager = CCUtils.getStudyLanguageManager(myCourse); if (manager != null) { String extension = manager.getDefaultTaskFileExtension(); ScrollingUtil.selectItem(myList, FileTypeManager.getInstance().getFileTypeByExtension(extension != null ? extension : "txt")); } return myPanel; }
public GroupList(PsiClass[] classes) { super(new BorderLayout()); SortedListModel<String> model = new SortedListModel<String>(new Comparator<String>() { public int compare(String s1, String s2) { return s1.compareTo(s2); } }); list = new JBList(model); Set<String> groups = TestNGUtil.getAnnotationValues("groups", classes); String[] array = ArrayUtil.toStringArray(groups); Arrays.sort(array); model.addAll(array); add(ScrollPaneFactory.createScrollPane(list)); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); ScrollingUtil.ensureSelectionExists(list); }
public void addAddManyFacility(JButton button, final Factory<List<T>> factory) { button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { List<T> items = factory.create(); getList().requestFocusInWindow(); if (items == null || items.size() == 0) { return; } for (final T item : items) { getModel().addElement(item); ScrollingUtil.selectItem(getList(), item); } } }); addComponent(button); }
@Override protected JComponent createCenterPanel() { myTitleLabel.setText(FileTypesBundle.message("filetype.chooser.prompt", myFileName)); myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); myList.setCellRenderer(new FileTypeRenderer()); new DoubleClickListener() { @Override protected boolean onDoubleClick(MouseEvent e) { doOKAction(); return true; } }.installOn(myList); myList.getSelectionModel().addListSelectionListener(e -> updateButtonsState()); ScrollingUtil.selectItem(myList, PlainTextFileType.INSTANCE); return myPanel; }
void addExcludePackage(String packageName) { if(packageName == null) { return; } int index = 0; while(index < getTableView().getListTableModel().getRowCount()) { if(getTableView().getListTableModel().getItem(index).exclude.compareTo(packageName) > 0) { break; } index++; } getTableView().getListTableModel().insertRow(index, new Item(packageName, ExclusionScope.IDE)); getTableView().clearSelection(); getTableView().addRowSelectionInterval(index, index); ScrollingUtil.ensureIndexIsVisible(getTableView(), index, 0); IdeFocusManager.getGlobalInstance().requestFocus(getTableView(), false); }
@NotNull public static ActionCallback selectPath(@NotNull final JTree tree, final TreePath path, boolean center) { tree.makeVisible(path); if (center) { return showRowCentred(tree, tree.getRowForPath(path)); } else { final int row = tree.getRowForPath(path); return showAndSelect(tree, row - ScrollingUtil.ROW_PADDING, row + ScrollingUtil.ROW_PADDING, row, -1); } }
private boolean tryToAutoSelect(boolean handleFinalChoices) { ListPopupStep<Object> listStep = getListStep(); boolean selected = false; if (listStep instanceof MultiSelectionListPopupStep<?>) { int[] indices = ((MultiSelectionListPopupStep)listStep).getDefaultOptionIndices(); if (indices.length > 0) { ScrollingUtil.ensureIndexIsVisible(myList, indices[0], 0); myList.setSelectedIndices(indices); selected = true; } } else { final int defaultIndex = listStep.getDefaultOptionIndex(); if (defaultIndex >= 0 && defaultIndex < myList.getModel().getSize()) { ScrollingUtil.selectItem(myList, defaultIndex); selected = true; } } if (!selected) { selectFirstSelectableItem(); } if (listStep.isAutoSelectionEnabled()) { if (!isVisible() && getSelectableCount() == 1) { return _handleSelect(handleFinalChoices, null); } else if (isVisible() && hasSingleSelectableItemWithSubmenu()) { return _handleSelect(handleFinalChoices, null); } } return false; }
@Override public void doExecute(Editor editor, Caret caret, DataContext dataContext){ LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor); if (lookup == null || !lookup.isFocused()) { myOriginalHandler.execute(editor, caret, dataContext); return; } lookup.markSelectionTouched(); ScrollingUtil.moveEnd(lookup.getList()); lookup.refreshUi(false, true); }
@Override public void doExecute(Editor editor, Caret caret, DataContext dataContext){ LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor); if (lookup == null || !lookup.isFocused()) { myOriginalHandler.execute(editor, caret, dataContext); return; } lookup.markSelectionTouched(); ScrollingUtil.moveHome(lookup.getList()); }
public NavBarListWrapper(final JList list) { super(list); list.addMouseMotionListener(new MouseMotionAdapter() { boolean myIsEngaged = false; @Override public void mouseMoved(MouseEvent e) { if (myIsEngaged && !UIUtil.isSelectionButtonDown(e)) { final Point point = e.getPoint(); final int index = list.locationToIndex(point); list.setSelectedIndex(index); } else { myIsEngaged = true; } } }); ScrollingUtil.installActions(list); final int modelSize = list.getModel().getSize(); setBorder(BorderFactory.createEmptyBorder()); if (modelSize > 0 && modelSize <= MAX_SIZE) { list.setVisibleRowCount(0); getViewport().setPreferredSize(list.getPreferredSize()); } else { list.setVisibleRowCount(MAX_SIZE); } myList = list; }
@Nullable @Override protected JComponent createCenterPanel() { final DirectoryProjectGenerator[] generators = Extensions.getExtensions(DirectoryProjectGenerator.EP_NAME); setTitle(generators.length == 0 ? "Create Project" : "Select Project Type"); final DefaultActionGroup root = createRootStep(); final Pair<JPanel, JBList> panel = FlatWelcomeFrame.createActionGroupPanel(root, getRootPane(), null); final Dimension size = JBUI.size(666, 385); final JPanel component = panel.first; component.setMinimumSize(size); component.setPreferredSize(size); new AnAction() { @Override public void actionPerformed(@NotNull AnActionEvent e) { close(CANCEL_EXIT_CODE); } }.registerCustomShortcutSet(KeyEvent.VK_ESCAPE, 0, component); myList = panel.second; UiNotifyConnector.doWhenFirstShown(myList, new Runnable() { @Override public void run() { ScrollingUtil.ensureSelectionExists(myList); } }); return component; }
public void setItems(Collection<T> items) { DefaultListModel model = myForm.getListModel(); model.removeAllElements(); for (T item : items) { model.addElement(item); } ScrollingUtil.ensureSelectionExists(getList()); }
public void select(T item) { if (item != null) { ScrollingUtil.selectItem(myList, item); } else { ScrollingUtil.ensureSelectionExists(myList); } }
public void loadValues(AbstractProperty.AbstractPropertyContainer container) { DefaultListModel model = getModel(); model.clear(); Iterator iterator = getProperty().getIterator(container); while (iterator.hasNext()) { Object item = iterator.next(); model.addElement(item); } ScrollingUtil.ensureSelectionExists(getList()); }
private MyListWrapper(final JList list) { super(UIUtil.isUnderAquaLookAndFeel() ? 0 : -1); list.setVisibleRowCount(15); setViewportView(list); if (myAutoselectOnMouseMove) { ListUtil.installAutoSelectOnMouseMove(list); } ScrollingUtil.installActions(list); setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); myList = list; }
@Nonnull public static ActionCallback selectPath(@Nonnull final JTree tree, final TreePath path, boolean center) { tree.makeVisible(path); if (center) { return showRowCentred(tree, tree.getRowForPath(path)); } else { final int row = tree.getRowForPath(path); return showAndSelect(tree, row - ScrollingUtil.ROW_PADDING, row + ScrollingUtil.ROW_PADDING, row, -1); } }
@Override public void actionPerformed(@Nonnull AnActionEvent e) { VcsLogGraphTable table = ((VcsLogUiImpl)e.getRequiredData(VcsLogDataKeys.VCS_LOG_UI)).getTable(); int row = table.getSelectedRow(); if (ScrollingUtil.isVisible(table, row)) { table.showTooltip(row); } }
public MethodListDlg(final PsiClass psiClass, final Condition<PsiMethod> filter, final JComponent parent) { super(parent, false); myClass = psiClass; createList(psiClass.getAllMethods(), filter); myWholePanel.add(ScrollPaneFactory.createScrollPane(myList)); myList.setCellRenderer(new ColoredListCellRenderer() { protected void customizeCellRenderer(@NotNull final JList list, final Object value, final int index, final boolean selected, final boolean hasFocus) { final PsiMethod psiMethod = (PsiMethod) value; append(PsiFormatUtil.formatMethod(psiMethod, PsiSubstitutor.EMPTY, PsiFormatUtil.SHOW_NAME, 0), StructureNodeRenderer.applyDeprecation(psiMethod, SimpleTextAttributes .REGULAR_ATTRIBUTES)); final PsiClass containingClass = psiMethod.getContainingClass(); if(!myClass.equals(containingClass)) { append(" (" + containingClass.getQualifiedName() + ")", StructureNodeRenderer.applyDeprecation(containingClass, SimpleTextAttributes.GRAY_ATTRIBUTES)); } } }); myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); new DoubleClickListener() { @Override protected boolean onDoubleClick(MouseEvent e) { MethodListDlg.this.close(OK_EXIT_CODE); return true; } }.installOn(myList); ScrollingUtil.ensureSelectionExists(myList); TreeUIHelper.getInstance().installListSpeedSearch(myList); setTitle(ExecutionBundle.message("choose.test.method.dialog.title")); init(); }
@Override protected void executeInLookup(final LookupImpl lookup, DataContext context, Caret caret) { lookup.setFocusDegree(LookupImpl.FocusDegree.FOCUSED); ScrollingUtil.movePageDown(lookup.getList()); }
@Override protected void executeInLookup(final LookupImpl lookup, DataContext context, Caret caret) { lookup.setFocusDegree(LookupImpl.FocusDegree.FOCUSED); ScrollingUtil.movePageUp(lookup.getList()); }
public void addExecutorComponent(Executor executor, JComponent component) { myRunnerPanel.add(component, executor.getId()); myListModel.addElement(executor); ScrollingUtil.ensureSelectionExists(myRunnersList); }
protected void selectItem(int i) { ScrollingUtil.selectItem(myList, i); }
protected void ensureSelectionExist() { ScrollingUtil.ensureSelectionExists(myList); }
private static boolean shouldSkipAction(AnAction action) { return action instanceof PopupAction || action instanceof CopyAction || action instanceof CutAction || action instanceof ScrollingUtil.ListScrollAction; }
public void loadValues(AbstractProperty.AbstractPropertyContainer container) { getModel().setAll(getProperty().get(container)); ScrollingUtil.ensureSelectionExists(getList()); }