Beispiel #1
0
  /** adds a new node to the tree */
  public void add(GeoElement geo) {
    cancelEditing();

    if (geo.isLabelSet() && geo.showInAlgebraView() && geo.isSetAlgebraVisible()) {
      // don't add auxiliary objects if the tree is categorized by type
      if (!getTreeMode().equals(SortMode.DEPENDENCY)
          && !showAuxiliaryObjects()
          && geo.isAuxiliaryObject()) {
        return;
      }

      DefaultMutableTreeNode parent, node;
      node = new DefaultMutableTreeNode(geo);
      parent = getParentNode(geo);

      // add node to model (alphabetically ordered)
      int pos = getInsertPosition(parent, geo, treeMode);

      model.insertNodeInto(node, parent, pos);
      nodeTable.put(geo, node);

      // ensure that the leaf with the new object is visible
      expandPath(new TreePath(new Object[] {model.getRoot(), parent}));
    }
  }
Beispiel #2
0
  /**
   * @param geo
   * @return parent node of this geo
   */
  protected DefaultMutableTreeNode getParentNode(GeoElement geo) {
    DefaultMutableTreeNode parent;

    switch (treeMode) {
      case DEPENDENCY:
        if (geo.isAuxiliaryObject()) {
          parent = auxiliaryNode;
        } else if (geo.isIndependent()) {
          parent = indNode;
        } else {
          parent = depNode;
        }
        break;
      case TYPE:
        // get type node
        String typeString = geo.getObjectType();
        parent = (DefaultMutableTreeNode) typeNodesMap.get(typeString);

        // do we have to create the parent node?
        if (parent == null) {
          String transTypeString = geo.translatedTypeString();
          parent = new DefaultMutableTreeNode(transTypeString);
          typeNodesMap.put(typeString, parent);

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

          model.insertNodeInto(parent, rootType, pos);
        }
        break;
      case LAYER:
        // get type node
        int layer = geo.getLayer();
        parent = (DefaultMutableTreeNode) layerNodesMap.get(layer);

        // do we have to create the parent node?
        if (parent == null) {
          String layerStr = layer + "";
          parent = new DefaultMutableTreeNode(layer);
          layerNodesMap.put(layer, parent);

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

          model.insertNodeInto(parent, rootLayer, pos);
        }
        break;
      case ORDER:
        parent = rootOrder;

        break;
      default:
        parent = null;
    }

    return parent;
  }