示例#1
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();
      }
    }
示例#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;
  }