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

项目:tools-idea    文件: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 {
    ListScrollingUtil.ensureSelectionExists(jdkChooserPanel.myList);
  }
  new DoubleClickListener() {
    @Override
    protected boolean onDoubleClick(MouseEvent e) {
      dialog.clickDefaultButton();
      return true;
    }
  }.installOn(jdkChooserPanel.myList);
  dialog.show();
  return dialog.isOK() ? jdkChooserPanel.getChosenJdk() : null;
}
项目:tools-idea    文件: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) {
      ListScrollingUtil.selectItem(myList, mostUsedValue);
      return true;
    }
  }

  return false;
}
项目:tools-idea    文件: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) {
    ListScrollingUtil.moveUp(lookup.getList(), 0);
  } else {
    ListScrollingUtil.moveDown(lookup.getList(), 0);
  }
  lookup.markSelectionTouched();
  lookup.refreshUi(false, true);

}
项目:tools-idea    文件: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) {
          ListScrollingUtil.selectItem(myOptionsList, i);
        }
        return true;
      }
    }
  }
  return false;
}
项目:tools-idea    文件:OptionsPanelImpl.java   
private void fillOptionsList() {
  int selIndex = myOptionsList.getSelectedIndex();

  DefaultListModel listModel = (DefaultListModel)myOptionsList.getModel();
  listModel.removeAllElements();

  EditorSchemeAttributeDescriptor[] descriptions = myOptions.getCurrentDescriptions();

  for (EditorSchemeAttributeDescriptor description : descriptions) {
    if (description.getGroup().equals(myCategoryName)) {
      listModel.addElement(description);
    }
  }
  if (selIndex >= 0) {
    myOptionsList.setSelectedIndex(selIndex);
  }
  ListScrollingUtil.ensureSelectionExists(myOptionsList);

  Object selected = myOptionsList.getSelectedValue();
  if (selected instanceof EditorSchemeAttributeDescriptor) {
    myDispatcher.getMulticaster().selectedOptionChanged(selected);
  }
}
项目:tools-idea    文件:OptionsPanelImpl.java   
@Override
public Runnable showOption(final String option) {
  final String lowerCaseOption = option.toLowerCase();
  DefaultListModel model = (DefaultListModel)myOptionsList.getModel();

  for (int i = 0; i < model.size(); i++) {
    Object o = model.get(i);
    if (o instanceof EditorSchemeAttributeDescriptor) {
      String type = ((EditorSchemeAttributeDescriptor)o).getType();
      if (type.toLowerCase().contains(lowerCaseOption) ||
          o.toString().toLowerCase().contains(lowerCaseOption)) {
        final int i1 = i;
        return new Runnable() {
          @Override
          public void run() {
            ListScrollingUtil.selectItem(myOptionsList, i1);
          }
        };

      }
    }
  }

  return null;
}
项目:tools-idea    文件: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);
    ListScrollingUtil.ensureSelectionExists(list);
}
项目:tools-idea    文件: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);
        ListScrollingUtil.selectItem(getList(), item);
      }
    }
  });
  addComponent(button);
}
项目:consulo-apache-ant    文件: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);
        ListScrollingUtil.selectItem(getList(), item);
      }
    }
  });
  addComponent(button);
}
项目:tools-idea    文件:JavaAutoImportOptions.java   
public void addExcludePackage(String packageName) {
  if (packageName == null) {
    return;
  }
  int index = -Arrays.binarySearch(myExcludePackagesModel.toArray(), packageName) - 1;
  if (index < 0) return;

  myExcludePackagesModel.add(index, packageName);
  myExcludePackagesList.setSelectedValue(packageName, true);
  ListScrollingUtil.ensureIndexIsVisible(myExcludePackagesList, index, 0);
  IdeFocusManager.getGlobalInstance().requestFocus(myExcludePackagesList, false);
}
项目:tools-idea    文件: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 - ListScrollingUtil.ROW_PADDING, row + ListScrollingUtil.ROW_PADDING, row, -1);
  }
}
项目:tools-idea    文件: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) {
      ListScrollingUtil.ensureIndexIsVisible(myList, indices[0], 0);
      myList.setSelectedIndices(indices);
      selected = true;
    }
  }
  else {
    final int defaultIndex = listStep.getDefaultOptionIndex();
    if (defaultIndex >= 0 && defaultIndex < myList.getModel().getSize()) {
      ListScrollingUtil.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;
}
项目:tools-idea    文件:EndHandler.java   
@Override
public void execute(Editor editor, DataContext dataContext){
  LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor);
  if (lookup == null || !lookup.isFocused()) {
    myOriginalHandler.execute(editor, dataContext);
    return;
  }

  lookup.markSelectionTouched();
  ListScrollingUtil.moveEnd(lookup.getList());
  lookup.refreshUi(false, true);
}
项目:tools-idea    文件:HomeHandler.java   
@Override
public void execute(Editor editor, DataContext dataContext){
  LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor);
  if (lookup == null || !lookup.isFocused()) {
    myOriginalHandler.execute(editor, dataContext);
    return;
  }

  lookup.markSelectionTouched();
  ListScrollingUtil.moveHome(lookup.getList());
}
项目:tools-idea    文件:OptionsPanelImpl.java   
@Override
public void selectOption(final String typeToSelect) {
  DefaultListModel model = (DefaultListModel)myOptionsList.getModel();

  for (int i = 0; i < model.size(); i++) {
    Object o = model.get(i);
    if (o instanceof EditorSchemeAttributeDescriptor) {
      if (typeToSelect.equals(((EditorSchemeAttributeDescriptor)o).getType())) {
        ListScrollingUtil.selectItem(myOptionsList, i);
        return;
      }
    }
  }

}
项目:tools-idea    文件: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;
      }
    }
  });

  ListScrollingUtil.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;
}
项目:tools-idea    文件:AnActionListEditor.java   
public void setItems(Collection<T> items) {
  DefaultListModel model = myForm.getListModel();
  model.removeAllElements();
  for (T item : items) {
    model.addElement(item);
  }
  ListScrollingUtil.ensureSelectionExists(getList());
}
项目:tools-idea    文件:AnActionListEditor.java   
public void select(T item) {
  if (item != null) {
    ListScrollingUtil.selectItem(myList, item);
  }
  else {
    ListScrollingUtil.ensureSelectionExists(myList);
  }
}
项目:tools-idea    文件: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);
  }
  ListScrollingUtil.ensureSelectionExists(getList());
}
项目:consulo-apache-ant    文件:AnActionListEditor.java   
public void setItems(Collection<T> items) {
  DefaultListModel model = myForm.getListModel();
  model.removeAllElements();
  for (T item : items) {
    model.addElement(item);
  }
  ListScrollingUtil.ensureSelectionExists(getList());
}
项目:consulo-apache-ant    文件:AnActionListEditor.java   
public void select(T item) {
  if (item != null) {
    ListScrollingUtil.selectItem(myList, item);
  }
  else {
    ListScrollingUtil.ensureSelectionExists(myList);
  }
}
项目:consulo-apache-ant    文件: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);
  }
  ListScrollingUtil.ensureSelectionExists(getList());
}
项目:tools-idea    文件:PopupChooserBuilder.java   
private MyListWrapper(final JList list) {
  super(UIUtil.isUnderAquaLookAndFeel() ? 0 : -1);
  JBViewport viewport = new JBViewport() {
    @Override
    protected LayoutManager createLayoutManager() {
      return new ViewportLayout() {
        @Override
        public Dimension preferredLayoutSize(Container parent) {
          int size = list.getModel().getSize();
          if (size >= 0 && size <= 20) {
            return list.getPreferredSize();
          } else {
            final Dimension sz = super.preferredLayoutSize(parent);
            final Point p = RelativePoint.getNorthWestOf(myList).getScreenPoint();
            final Rectangle screen = ScreenUtil.getScreenRectangle(p);

            final int bordersEtc = 20;
            final int maxWidth = Math.abs(screen.x + screen.width - p.x) - 2 * bordersEtc;
            return new Dimension(Math.min(maxWidth, sz.width) + bordersEtc, sz.height + list.getCellBounds(0, 0).height / 2);
          }
        }
      };
    }
  };
  list.setVisibleRowCount(15);
  setViewport(viewport);
  setViewportView(list);


  if (myAutoselectOnMouseMove) {
    list.addMouseMotionListener(new MouseMotionAdapter() {
      boolean myIsEngaged = false;
      public void mouseMoved(MouseEvent e) {
        if (myIsEngaged && !UIUtil.isSelectionButtonDown(e)) {
          Point point = e.getPoint();
          int index = list.locationToIndex(point);
          list.putClientProperty(SELECTED_BY_MOUSE_EVENT, Boolean.TRUE);
          list.setSelectedIndex(index);
          list.putClientProperty(SELECTED_BY_MOUSE_EVENT, Boolean.FALSE);
        }
        else {
          myIsEngaged = true;
        }
      }
    });
  }

  ListScrollingUtil.installActions(list);

  setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
  myList = list;
}
项目:tools-idea    文件:LookupActionHandler.java   
@Override
protected void executeInLookup(final LookupImpl lookup, DataContext context) {
  lookup.setFocusDegree(LookupImpl.FocusDegree.FOCUSED);
  ListScrollingUtil.movePageDown(lookup.getList());
}
项目:tools-idea    文件:LookupActionHandler.java   
@Override
protected void executeInLookup(final LookupImpl lookup, DataContext context) {
  lookup.setFocusDegree(LookupImpl.FocusDegree.FOCUSED);
  ListScrollingUtil.movePageUp(lookup.getList());
}
项目:tools-idea    文件:ConfigurationSettingsEditor.java   
public void addExecutorComponent(Executor executor, JComponent component) {
  myRunnerPanel.add(component, executor.getId());
  myListModel.addElement(executor);
  ListScrollingUtil.ensureSelectionExists(myRunnersList);
}
项目:tools-idea    文件:AbstractListBuilder.java   
protected void selectItem(int i) {
  ListScrollingUtil.selectItem(myList, i);
}
项目:tools-idea    文件:AbstractListBuilder.java   
protected void ensureSelectionExist() {
  ListScrollingUtil.ensureSelectionExists(myList);
}
项目:tools-idea    文件:NavBarListener.java   
private static boolean shouldSkipAction(AnAction action) {
  return action instanceof PopupAction
         || action instanceof CopyAction
         || action instanceof CutAction
         || action instanceof ListScrollingUtil.ListScrollAction;
}
项目:tools-idea    文件:UIPropertyBinding.java   
public void loadValues(AbstractProperty.AbstractPropertyContainer container) {
  getModel().setAll(getProperty().get(container));
  ListScrollingUtil.ensureSelectionExists(getList());
}
项目:intellij-xquery    文件:DataSourceListPanel.java   
private void addNewDataSourceConfigurationToModelAndSelectIt(XQueryDataSourceConfiguration newItem) {
    dataSourcesListModel.addElement(newItem);
    dataSourceList.clearSelection();
    ListScrollingUtil.selectItem(dataSourceList, newItem);
}
项目:consulo-apache-ant    文件:UIPropertyBinding.java   
public void loadValues(AbstractProperty.AbstractPropertyContainer container) {
  getModel().setAll(getProperty().get(container));
  ListScrollingUtil.ensureSelectionExists(getList());
}