Java 类com.intellij.ui.ScrollingUtil 实例源码

项目:intellij-ce-playground    文件:ExcludeTable.java   
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);
}
项目:intellij-ce-playground    文件:JdkChooserPanel.java   
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;
}
项目:intellij-ce-playground    文件:ListPopupImpl.java   
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;
}
项目:intellij-ce-playground    文件:LookupActionHandler.java   
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);

}
项目:intellij-ce-playground    文件:ClickNavigator.java   
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;
}
项目:intellij-ce-playground    文件:CreateTaskFileDialog.java   
@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;
}
项目:intellij-ce-playground    文件:GroupList.java   
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);
}
项目:intellij-ce-playground    文件:UIPropertyBinding.java   
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);
}
项目:consulo    文件:FileTypeChooser.java   
@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;
}
项目:consulo    文件:ListPopupImpl.java   
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;
}
项目:consulo    文件:LookupActionHandler.java   
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);

}
项目:consulo    文件:ClickNavigator.java   
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;
}
项目:consulo-java    文件:ExcludeTable.java   
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);
}
项目:intellij-ce-playground    文件:TreeUtil.java   
@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);
  }
}
项目:intellij-ce-playground    文件:ListPopupImpl.java   
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;
}
项目:intellij-ce-playground    文件:EndHandler.java   
@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);
}
项目:intellij-ce-playground    文件:HomeHandler.java   
@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());
}
项目:intellij-ce-playground    文件:NavBarListWrapper.java   
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;
}
项目:intellij-ce-playground    文件:AbstractNewProjectDialog.java   
@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;
}
项目:intellij-ce-playground    文件:AnActionListEditor.java   
public void setItems(Collection<T> items) {
  DefaultListModel model = myForm.getListModel();
  model.removeAllElements();
  for (T item : items) {
    model.addElement(item);
  }
  ScrollingUtil.ensureSelectionExists(getList());
}
项目:intellij-ce-playground    文件:AnActionListEditor.java   
public void select(T item) {
  if (item != null) {
    ScrollingUtil.selectItem(myList, item);
  }
  else {
    ScrollingUtil.ensureSelectionExists(myList);
  }
}
项目:intellij-ce-playground    文件:UIPropertyBinding.java   
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());
}
项目:consulo    文件:PopupChooserBuilder.java   
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;
}
项目:consulo    文件:TreeUtil.java   
@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);
  }
}
项目:consulo    文件:ShowCommitTooltipAction.java   
@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);
  }
}
项目:consulo    文件:ListPopupImpl.java   
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;
}
项目:consulo    文件:EndHandler.java   
@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);
}
项目:consulo    文件:HomeHandler.java   
@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());
}
项目:consulo    文件:NavBarListWrapper.java   
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;
}
项目:consulo-java    文件:MethodListDlg.java   
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();
}
项目:intellij-ce-playground    文件:LookupActionHandler.java   
@Override
protected void executeInLookup(final LookupImpl lookup, DataContext context, Caret caret) {
  lookup.setFocusDegree(LookupImpl.FocusDegree.FOCUSED);
  ScrollingUtil.movePageDown(lookup.getList());
}
项目:intellij-ce-playground    文件:LookupActionHandler.java   
@Override
protected void executeInLookup(final LookupImpl lookup, DataContext context, Caret caret) {
  lookup.setFocusDegree(LookupImpl.FocusDegree.FOCUSED);
  ScrollingUtil.movePageUp(lookup.getList());
}
项目:intellij-ce-playground    文件:ConfigurationSettingsEditor.java   
public void addExecutorComponent(Executor executor, JComponent component) {
  myRunnerPanel.add(component, executor.getId());
  myListModel.addElement(executor);
  ScrollingUtil.ensureSelectionExists(myRunnersList);
}
项目:intellij-ce-playground    文件:AbstractListBuilder.java   
protected void selectItem(int i) {
  ScrollingUtil.selectItem(myList, i);
}
项目:intellij-ce-playground    文件:AbstractListBuilder.java   
protected void ensureSelectionExist() {
  ScrollingUtil.ensureSelectionExists(myList);
}
项目:intellij-ce-playground    文件:NavBarListener.java   
private static boolean shouldSkipAction(AnAction action) {
  return action instanceof PopupAction
         || action instanceof CopyAction
         || action instanceof CutAction
         || action instanceof ScrollingUtil.ListScrollAction;
}
项目:intellij-ce-playground    文件:UIPropertyBinding.java   
public void loadValues(AbstractProperty.AbstractPropertyContainer container) {
  getModel().setAll(getProperty().get(container));
  ScrollingUtil.ensureSelectionExists(getList());
}
项目:consulo    文件:LookupActionHandler.java   
@Override
protected void executeInLookup(final LookupImpl lookup, DataContext context, Caret caret) {
  lookup.setFocusDegree(LookupImpl.FocusDegree.FOCUSED);
  ScrollingUtil.movePageDown(lookup.getList());
}
项目:consulo    文件:LookupActionHandler.java   
@Override
protected void executeInLookup(final LookupImpl lookup, DataContext context, Caret caret) {
  lookup.setFocusDegree(LookupImpl.FocusDegree.FOCUSED);
  ScrollingUtil.movePageUp(lookup.getList());
}
项目:consulo    文件:ConfigurationSettingsEditor.java   
public void addExecutorComponent(Executor executor, JComponent component) {
  myRunnerPanel.add(component, executor.getId());
  myListModel.addElement(executor);
  ScrollingUtil.ensureSelectionExists(myRunnersList);
}