コード例 #1
0
  /**
   * Shows a view for <code>note</code>. The view will be positioned at the same location the last
   * view for <code>note</code> was shown. If this is the first time that the view is shown, it will
   * be positioned at the same location as the last focused view.
   *
   * @param note the <code>Note</code> whose view should be shown
   */
  public void show(Note note) {
    Tuple<DockStation, DockableProperty> location = locations.remove(note);

    if (location != null) show(note, location.getA(), location.getB());
    else if (focusedViews.isEmpty()) show(note, null);
    else show(note, focusedViews.getFirst());
  }
コード例 #2
0
  /**
   * Rebuilds the list of actions, introducing new actions if necessary, removing old actions if no
   * longer needed.
   *
   * @param force whether the entire list has to be updated or optimizations are allowed
   */
  private void updateActionList(boolean force) {
    if (onUpdateList) {
      return;
    }
    try {
      onUpdateList = true;
      if (listener != null && !force) {
        return;
      }

      List<Dockable> list = new ArrayList<Dockable>();
      fill(dockable, list);
      sort(list);

      // assume the list does not change much, i.e. an item was added or removed
      int i = 0, n = list.size();
      int j = 0, m = actions.size();

      Set<Dockable> pendingActions = new HashSet<Dockable>();
      for (Tuple<Dockable, DockAction> item : actions) {
        pendingActions.add(item.getA());
      }

      while (i < n && j < m) {
        Dockable dockable = list.get(i);
        if (actions.get(j).getA() == dockable) {
          i++;
          j++;
        } else if (pendingActions.contains(dockable)) {
          actions.remove(j);
          m--;
          fireRemoved(j, j);
        } else {
          actions.add(j, new Tuple<Dockable, DockAction>(dockable, createActionFor(dockable)));
          m++;
          fireAdded(j, j);
          i++;
          j++;
        }

        pendingActions.remove(dockable);
      }

      if (j < m) {
        int length = m;
        while (j < m) {
          actions.remove(--m);
        }
        fireRemoved(j, length - 1);
      }

      if (i < n) {
        int index = i;
        while (i < n) {
          Dockable dockable = list.get(i++);
          actions.add(new Tuple<Dockable, DockAction>(dockable, createActionFor(dockable)));
        }
        fireAdded(index, actions.size() - 1);
      }
    } finally {
      onUpdateList = false;
    }
  }