예제 #1
0
    /**
     * Returns the tree path of geo
     *
     * @return returns null if geo is not in tree
     */
    private TreePath getTreePath(GeoElement geo) {
      DefaultMutableTreeNode typeNode = typeNodesMap.get(geo.getObjectType());
      if (typeNode == null) return null;

      // find pos of geo
      int pos = AlgebraView.binarySearchGeo(typeNode, geo.getLabel());
      if (pos == -1) return null;

      return new TreePath(((DefaultMutableTreeNode) typeNode.getChildAt(pos)).getPath());
    }
예제 #2
0
    /** returns geo's TreePath */
    private TreePath getGeoPath(GeoElement geo) {
      String typeString = geo.getObjectType();
      DefaultMutableTreeNode typeNode = typeNodesMap.get(typeString);
      if (typeNode == null) return null;

      int pos = AlgebraView.binarySearchGeo(typeNode, geo.getLabel());
      if (pos == -1) return null;
      else {
        // add to selection
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) typeNode.getChildAt(pos);

        //	expand typenode
        TreePath tp = new TreePath(node.getPath());

        return tp;
      }
    }
예제 #3
0
    /** @param binarySearch true for binary, false for linear search */
    public void remove(GeoElement geo, boolean binarySearch) {
      // get type node
      DefaultMutableTreeNode typeNode = typeNodesMap.get(geo.getObjectType());
      if (typeNode == null) return;

      int pos =
          binarySearch
              ? AlgebraView.binarySearchGeo(typeNode, geo.getLabel())
              : AlgebraView.linearSearchGeo(typeNode, geo.getLabel());
      if (pos > -1) {
        DefaultMutableTreeNode child = (DefaultMutableTreeNode) typeNode.getChildAt(pos);
        treeModel.removeNodeFromParent(child);

        if (typeNode.getChildCount() == 0) {
          // last child
          typeNodesMap.remove(geo.getObjectType());
          treeModel.removeNodeFromParent(typeNode);
        }
      }
    }
예제 #4
0
    /** adds a new element to the list */
    public final void add(GeoElement geo) {
      if (!geo.isLabelSet() || !geo.hasProperties()) return;

      // get type node
      String typeString = geo.getObjectType();
      DefaultMutableTreeNode typeNode = typeNodesMap.get(typeString);

      // init type node
      boolean initing = typeNode == null;
      if (initing) {
        String transTypeString = geo.translatedTypeString();
        typeNode = new DefaultMutableTreeNode(transTypeString);
        typeNodesMap.put(typeString, typeNode);

        // find insert pos
        int pos = root.getChildCount();
        for (int i = 0; i < pos; i++) {
          DefaultMutableTreeNode child = (DefaultMutableTreeNode) root.getChildAt(i);
          if (transTypeString.compareTo(child.toString()) < 0) {
            pos = i;
            break;
          }
        }

        treeModel.insertNodeInto(typeNode, root, pos);
      }

      // check if already present in type node
      int pos = AlgebraView.binarySearchGeo(typeNode, geo.getLabel());
      if (pos >= 0) return;

      // add geo to type node
      DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(geo);
      pos = AlgebraView.getInsertPosition(typeNode, geo, AlgebraView.SortMode.DEPENDENCY);
      treeModel.insertNodeInto(newNode, typeNode, pos);

      // make sure something is selected
      if (getSelectionModel().isSelectionEmpty()) {
        selectFirstElement();
      }
    }