private void _scrollPaneContactList_scrollDown(ActionEvent actionEvent) {
   if (_listContactList.getLastVisibleIndex() + _listContactList.getVisibleRowCount()
       < _listContactList.getModel().getSize())
     _listContactList.ensureIndexIsVisible(
         _listContactList.getLastVisibleIndex() + _listContactList.getVisibleRowCount());
   else _listContactList.ensureIndexIsVisible(_listContactList.getModel().getSize());
 }
Пример #2
0
  /**
   * Shows a string message in the client's log with the specified priority
   *
   * @param message
   * @param priority
   */
  public void show(String message, Priority priority) {
    switch (priority) {
      case LOW:
        backGC.add(Color.white);
        break;
      case NORMAL:
        backGC.add(Color.LIGHT_GRAY);
        break;
      case HIGH:
        backGC.add(Color.red);
        break;
      case SEVERE:
        backGC.add(Color.red);
        break;
    }

    if (priority.equals(Priority.SEVERE)) {
      foreGC.add(Color.white);
    } else {
      foreGC.add(Color.black);
    }

    lastMessage = message;

    listModel.addElement(formatMsg(message));
    render.setElements(backGC, foreGC);
    counter++;

    logText.ensureIndexIsVisible(logText.getLastVisibleIndex() + 1);
  }
Пример #3
0
  /**
   * Shows a string message in the client's log with the specified color
   *
   * @param message
   * @param color
   */
  public void show(String message, Color color) {
    backGC.add(Color.LIGHT_GRAY);
    foreGC.add(color);

    lastMessage = message;

    listModel.addElement(formatMsg(message));
    render.setElements(backGC, foreGC);
    counter++;

    logText.ensureIndexIsVisible(logText.getLastVisibleIndex() + 1);
  }
 private static void ensureEverythingVisibleAdded(
     LookupImpl lookup,
     final LinkedHashSet<LookupElement> model,
     Iterator<LookupElement> byRelevance) {
   JList list = lookup.getList();
   final boolean testMode = ApplicationManager.getApplication().isUnitTestMode();
   final int limit =
       Math.max(list.getLastVisibleIndex(), model.size())
           + ourUISettings.MAX_LOOKUP_LIST_HEIGHT * 3;
   addSomeItems(
       model,
       byRelevance,
       new Condition<LookupElement>() {
         @Override
         public boolean value(LookupElement lastAdded) {
           return !testMode && model.size() >= limit;
         }
       });
 }
  @NotNull
  @Override
  public RelativePoint guessBestPopupLocation(@NotNull final JComponent component) {
    Point popupMenuPoint = null;
    final Rectangle visibleRect = component.getVisibleRect();
    if (component instanceof JList) { // JList
      JList list = (JList) component;
      int firstVisibleIndex = list.getFirstVisibleIndex();
      int lastVisibleIndex = list.getLastVisibleIndex();
      int[] selectedIndices = list.getSelectedIndices();
      for (int index : selectedIndices) {
        if (firstVisibleIndex <= index && index <= lastVisibleIndex) {
          Rectangle cellBounds = list.getCellBounds(index, index);
          popupMenuPoint =
              new Point(visibleRect.x + visibleRect.width / 4, cellBounds.y + cellBounds.height);
          break;
        }
      }
    } else if (component instanceof JTree) { // JTree
      JTree tree = (JTree) component;
      int[] selectionRows = tree.getSelectionRows();
      if (selectionRows != null) {
        Arrays.sort(selectionRows);
        for (int i = 0; i < selectionRows.length; i++) {
          int row = selectionRows[i];
          Rectangle rowBounds = tree.getRowBounds(row);
          if (visibleRect.contains(rowBounds)) {
            popupMenuPoint = new Point(rowBounds.x + 2, rowBounds.y + rowBounds.height - 1);
            break;
          }
        }
        if (popupMenuPoint == null) { // All selected rows are out of visible rect
          Point visibleCenter =
              new Point(
                  visibleRect.x + visibleRect.width / 2, visibleRect.y + visibleRect.height / 2);
          double minDistance = Double.POSITIVE_INFINITY;
          int bestRow = -1;
          Point rowCenter;
          double distance;
          for (int i = 0; i < selectionRows.length; i++) {
            int row = selectionRows[i];
            Rectangle rowBounds = tree.getRowBounds(row);
            rowCenter =
                new Point(rowBounds.x + rowBounds.width / 2, rowBounds.y + rowBounds.height / 2);
            distance = visibleCenter.distance(rowCenter);
            if (minDistance > distance) {
              minDistance = distance;
              bestRow = row;
            }
          }

          if (bestRow != -1) {
            Rectangle rowBounds = tree.getRowBounds(bestRow);
            tree.scrollRectToVisible(
                new Rectangle(
                    rowBounds.x,
                    rowBounds.y,
                    Math.min(visibleRect.width, rowBounds.width),
                    rowBounds.height));
            popupMenuPoint = new Point(rowBounds.x + 2, rowBounds.y + rowBounds.height - 1);
          }
        }
      }
    } else if (component instanceof JTable) {
      JTable table = (JTable) component;
      int column = table.getColumnModel().getSelectionModel().getLeadSelectionIndex();
      int row =
          Math.max(
              table.getSelectionModel().getLeadSelectionIndex(),
              table.getSelectionModel().getAnchorSelectionIndex());
      Rectangle rect = table.getCellRect(row, column, false);
      if (!visibleRect.intersects(rect)) {
        table.scrollRectToVisible(rect);
      }
      popupMenuPoint = new Point(rect.x, rect.y + rect.height);
    } else if (component instanceof PopupOwner) {
      popupMenuPoint = ((PopupOwner) component).getBestPopupPosition();
    }
    if (popupMenuPoint == null) {
      popupMenuPoint =
          new Point(visibleRect.x + visibleRect.width / 2, visibleRect.y + visibleRect.height / 2);
    }

    return new RelativePoint(component, popupMenuPoint);
  }