Example #1
0
 protected Edge project(Edge edge) {
   tempEdge.start = edge.start;
   tempEdge.end = edge.end;
   tempEdge.state = gp.project(edge.state);
   tempEdge.head = edge.head;
   tempEdge.tag = edge.tag;
   return tempEdge;
 }
  public void setEdge(Edge edge_in, Graph graph_in) {
    graph_ = graph_in;
    edge_ = edge_in;
    //  if(edge_ == null)
    //     edge_ = Edge.defaults;

    String title;
    //  if(edge_ == Edge.defaults)
    //     title = "Properties For Newly Created Edges";
    //  else
    title = "Edge " + edge_.tail().id_ + " " + edge_.head().id_;

    setTitle(title);

    style_.select(edge_.getLineStyle());

    //   if(edge_ != Edge.defaults)
    //   {
    labelText_.setText(edge_.getLabel());
    String points_string = new String();
    DPoint3[] points = edge_.points();
    for (int i = 0; i < points.length; i++)
      points_string += points[i].x + " " + points[i].y + " " + points[i].z + "\n";
    pointsText_.setText(points_string);

    // Can't remove items from a Choice in Java 1.0.
    dataPanel_.remove(data_);
    data_ = new Choice();
    dataPanel_.add(data_);
    dataHash_ = (Hashtable) edge_.data_.clone();
    data_.addItem("<NEW>");
    for (Enumeration keys = dataHash_.keys(); keys.hasMoreElements(); ) {
      String key = (String) keys.nextElement();
      data_.addItem(key);
    }
    if (data_.countItems() == 1) // Need at least one item.
    data_.addItem("Data");
    data_.select(1);
    currentData_ = data_.getItem(1);

    String value = (String) dataHash_.get(currentData_);
    if (value == null) value = new String("");
    dataText_.setText(value);

    for (int i = 0; i < ndCount_; i++) notDefault_[i].show();
    //  }
    //  else
    //     for(int i = 0; i < ndCount_; i++)
    //        notDefault_[i].hide();

    pack();
  }
  private boolean setValues_() {
    //   if(edge_ != Edge.defaults)
    //   {
    String points_string = pointsText_.getText();

    // Scan the points string.
    StringTokenizer tokenizer = new StringTokenizer(points_string, " \t\n\r,", false);
    int num_tokens = tokenizer.countTokens();
    a:
    if ((num_tokens % 3) != 0)
      new MessageDialog(frame_, "Error", "Expecting " + "sets of three numbers for points", true);
    else {
      int count = num_tokens / 3;
      DPoint3[] points = new DPoint3[count];

      for (int i = 0; i < count; i++) points[i] = new DPoint3();

      String token;
      int index = 0;
      double val;
      while (tokenizer.hasMoreTokens()) {
        for (int element = 0; element < 3; element++) {
          token = tokenizer.nextToken();
          try {
            val = new Double(token).doubleValue();
          } catch (Exception e) {
            char el = 'X';
            if (element == 1) el = 'Y';
            if (element == 2) el = 'Z';
            new MessageDialog(
                frame_,
                "Error",
                "Element " + el + " of point " + index + " is not" + " a number.",
                true);
            break a;
          }

          if (element == 0) points[index].x = val;
          else if (element == 1) points[index].y = val;
          else points[index].z = val;
        }
        index++;
      }

      dataHash_.put(currentData_, dataText_.getText());

      for (Enumeration keys = dataHash_.keys(); keys.hasMoreElements(); ) {
        String key = (String) keys.nextElement();
        String value = (String) dataHash_.get(key);
        if (value != null && value.length() != 0) edge_.data_.put(key, value);
      }

      // Replace the old edge.
      Edge edge = new Edge(edge_.tail(), edge_.head(), points, false);
      graph_.insertEdge(edge);
      edge.setLabel(labelText_.getText());
      edge.setLineStyle(style_.getSelectedIndex());
      edge.data_ = edge_.data_;

      return true;
    }
    //   }

    return false;
  }