Пример #1
0
  /**
   * Unregisters <code>station</code>, the associated controller will no longer support drag and
   * drop operations for <code>station</code>.<br>
   * Clients and subclasses should not call this method.
   *
   * @param station the station to remove
   */
  protected void unregister(DockStation station) {
    if (stations.remove(station)) {
      station.setController(null);
      station.removeDockStationListener(stationListener);

      fireDockStationUnregistered(station);
    }
  }
Пример #2
0
  /**
   * Gets a list of stations which have no parent and are therefore the roots of the dock-trees.
   *
   * @return the roots
   */
  public DockStation[] listRoots() {
    List<DockStation> list = new LinkedList<DockStation>();
    for (DockStation station : stations) {
      Dockable dockable = station.asDockable();
      if (dockable == null || dockable.getDockParent() == null) list.add(station);
    }

    return list.toArray(new DockStation[list.size()]);
  }
 public void remove(Dockable dockable) {
   DockStation station = dockable.asDockStation();
   if (station != null) {
     station.removeDockStationListener(this);
     for (int i = 0, n = station.getDockableCount(); i < n; i++) {
       remove(station.getDockable(i));
     }
   }
 }
 private void fill(Dockable dockable, List<Dockable> list) {
   if (shouldShow(dockable)) {
     list.add(dockable);
   }
   DockStation station = dockable.asDockStation();
   if (station != null) {
     for (int i = 0, n = station.getDockableCount(); i < n; i++) {
       fill(station.getDockable(i), list);
     }
   }
 }
 public void hierarchyChanged(DockHierarchyEvent event) {
   if (bound > 0) {
     if (parent != null) {
       parent.removeDockStationListener(adapter);
     }
     parent = dockable.getDockParent();
     if (parent != null) {
       parent.addDockStationListener(adapter);
     }
     checkState();
   }
 }
Пример #6
0
  /**
   * Closes the view that shows <code>note</code>. Stores the location of the view in order to open
   * the view again at the same location.
   *
   * @param note the <code>Note</code> whose view should be closed
   */
  public void hide(Note note) {
    NoteView view = noteViews.remove(note);
    if (view != null) {
      DockStation root = DockUtilities.getRoot(view);
      DockableProperty location = DockUtilities.getPropertyChain(root, view);
      locations.put(note, new Tuple<DockStation, DockableProperty>(root, location));

      DockStation parent = view.getDockParent();
      parent.drag(view);
      view.setNote(null);
      focusedViews.remove(view);
    }
  }
Пример #7
0
  /**
   * Registers <code>station</code>, the associated controller will support drag and drop for <code>
   * station</code>.<br>
   * Clients and subclasses should not call this method.
   *
   * @param station the station to add
   * @param requiresListener if <code>true</code>, then the {@link DockStationListener} of this
   *     {@link DockRegister} will be added to <code>station</code>, if <code>false</code> the
   *     listener will not be added
   */
  protected void register(DockStation station, boolean requiresListener) {
    if (!stations.contains(station)) {
      fireDockStationRegistering(station);

      stations.add(station);

      station.setController(controller);
      station.updateTheme();

      if (requiresListener) {
        station.addDockStationListener(stationListener);
      }

      fireDockStationRegistered(station);
    }
  }
Пример #8
0
    @Override
    public void dockableRemoved(DockStation station, Dockable dockable) {
      if (dockable.getDockParent() != null && dockable.getDockParent() != station) {
        throw new IllegalStateException(
            "the parent of dockable is wrong: it is neither null nor '" + station + "'");
      }
      dockable.setDockParent(null);

      DockStation asStation = dockable.asDockStation();
      if (asStation != null) {
        asStation.removeDockStationListener(StationListener.this);
      }

      if (stalled == 0) {
        removeDockable(dockable);
      }
    }
    private void checkState() {
      if (!onChange) {
        try {
          onChange = true;

          DockStation parent = dockable.getDockParent();
          boolean select = false;

          if (parent != null) {
            select = parent.isChildShowing(dockable) && parent.getFrontDockable() == dockable;
          }

          setSelected(select);
        } finally {
          onChange = false;
        }
      }
    }
Пример #10
0
  public Dockable combine(CombinerSource source, CombinerTarget target) {
    if (target instanceof DisplayerTarget) {
      return ((DisplayerTarget) target).execute(source);
    } else {
      DockStation parent = source.getParent();
      PlaceholderMap placeholders = source.getPlaceholders();

      StackDockStation stack = new StackDockStation(parent.getTheme());
      stack.setController(parent.getController());
      if (placeholders != null) {
        stack.setPlaceholders(placeholders);
      }

      stack.drop(source.getOld());
      stack.drop(source.getNew());

      return stack;
    }
  }
 @Override
 public void unbind(Dockable dockable) {
   super.unbind(dockable);
   bound--;
   if (bound == 0) {
     if (parent != null) {
       parent.removeDockStationListener(adapter);
     }
     this.dockable.removeDockHierarchyListener(hierarchy);
     parent = null;
   }
 }
Пример #12
0
  /**
   * Removes a station which was managed by this register.
   *
   * @param station the station to remove
   */
  public void remove(DockStation station) {
    if (stations.contains(station)) {
      setProtected(station, false);
      Dockable dock = station.asDockable();
      if (dock != null) {
        DockStation parent = dock.getDockParent();
        if (parent != null) parent.drag(dock);
      }

      DockUtilities.visit(
          station,
          new DockUtilities.DockVisitor() {
            private Set<DockStation> ignored = new HashSet<DockStation>();

            @Override
            public void handleDockable(Dockable dockable) {
              DockStation station = dockable.asDockStation();
              if (station == null || !isProtected(station)) {
                for (DockStation parent : ignored) {
                  if (DockUtilities.isAncestor(parent, dockable)) {
                    return;
                  }
                }
                unregister(dockable);
              }
            }

            @Override
            public void handleDockStation(DockStation station) {
              if (isProtected(station)) {
                ignored.add(station);
              } else {
                unregister(station);
              }
            }
          });
    }
  }
    private void checkDockable() {
      if (!onChange) {
        try {
          onChange = true;

          if (isSelected()) {
            DockController controller = dockable.getController();
            if (controller != null) {
              controller.setFocusedDockable(dockable, null, true, true, true);
            }
          } else {
            DockStation parent = this.parent;
            Dockable dockable = this.dockable;

            DockStation finalParent = StationChildrenActionSource.this.dockable.getDockParent();

            while (parent != null) {
              if (parent.getFrontDockable() == dockable) {
                parent.setFrontDockable(null);
              }
              if (parent == finalParent) {
                parent = null;
              } else {
                dockable = parent.asDockable();
                if (dockable != null) {
                  parent = dockable.getDockParent();
                } else {
                  parent = null;
                }
              }
            }
          }
        } finally {
          onChange = false;
        }
      }
    }
    @Override
    public void bind(Dockable dockable) {
      bound++;
      if (bound == 1) {
        this.dockable.addDockHierarchyListener(hierarchy);
        parent = this.dockable.getDockParent();

        if (parent != null) {
          parent.addDockStationListener(adapter);
        }

        checkState();
      }
      super.bind(dockable);
    }
Пример #15
0
  /**
   * Shows a view for <code>note</code> at the given location as child of <code>root</code>.
   *
   * @param note the <code>Note</code> for which a view should be opened
   * @param root the preferred parent, might be <code>null</code>
   * @param location the preferred location, relative to <code>root</code>. Might be <code>null
   *     </code>.
   */
  public void show(Note note, DockStation root, DockableProperty location) {
    NoteView view = noteViews.get(note);
    if (view == null) {
      view = new NoteView(this, model);
      view.setNote(note);

      if (root == null || location == null) {
        frontend.getDefaultStation().drop(view);
      } else {
        if (!root.drop(view, location)) {
          frontend.getDefaultStation().drop(view);
        }
      }
      noteViews.put(note, view);
    }
    frontend.getController().setFocusedDockable(view, false);
  }
Пример #16
0
  /**
   * Adds a station to this register. The associated controller allows the user to drag and drop
   * children from and to <code>station</code>. If the children of <code>station</code> are stations
   * itself, then they will be added automatically
   *
   * @param station the new station
   * @param requiresListeners if <code>true</code>, then {@link #stationListener} is added to any
   *     {@link DockStation} encountered in the tree beginning with <code>station</code>
   */
  private void add(DockStation station, final boolean requiresListeners) {
    if (station == null) throw new NullPointerException("Station must not be null");

    if (!stations.contains(station)) {
      DockController other = station.getController();
      if (other != null && other != controller) {
        other.getRegister().remove(station);
      }

      DockUtilities.visit(
          station,
          new DockUtilities.DockVisitor() {
            @Override
            public void handleDockable(Dockable dockable) {
              register(dockable);
            }

            @Override
            public void handleDockStation(DockStation station) {
              register(station, requiresListeners);
            }
          });
    }
  }
Пример #17
0
 public void replace(DockStation old, Dockable next) {
   replace(old.asDockable(), next);
 }