Exemplo n.º 1
0
  public void calcDimsAndStartPts(LinkedList llist, draw d) {
    /*  Determines the following variables Lenx, Leny, Startx, Starty,
    TitleStarty   */
    // Task: Calculate the length and height of a node and its starting point.
    //   It also computes the y-coordinate of the title

    double TitleToSSGap, MinGt, MaxGt, Diam, MinTitlex, MaxTitlex;
    int NumNodes, NumLines;
    super.calcDimsAndStartPts(llist, d);
    // With circular nodes, not adding Textheight works better to finetune the circle size
    Lenx = Maxstringlength - .02;
    Leny = ((linespernode + 1) * Textheight) + ((linespernode - 1) * (0.5 * Textheight));
    TDx = (Lenx + Leny) / 5.0; // Height is a third of their average *)
    TDy = TDx / Math.sqrt(3);
    TitleToSSGap = 2 * Titleheight;
    NumLines = title.size();
    Startx = 0.0;
    Starty =
        Topy
            - IconHeight
            - IconToTitleGap
            - (NumLines * Titleheight)
            - ((NumLines - 1) * (0.5 * Titleheight))
            - TitleToSSGap
            - (Lenx / 2.0)
            - .15;
    TitleStarty = (Topy - IconHeight - IconToTitleGap - Titleheight) + .05;
  }
Exemplo n.º 2
0
  //                 PROCEDURE DrawGeneralTree                            *)
  //                                                                      *)
  // This procedure calls on xCoord to obtain the x coordinate of each    *)
  // node in the tree, and then calls on ApplyModifier to to make any     *)
  // adjustments to the node positions that couldn't be made in xCoord.   *)
  // Finally, it does a pre-order traversal of the tree and draws each    *)
  // node to its rightful place in the tree, and connects appropriate     *)
  // nodes to form the binary tree.                                       *)
  void drawStructure(LinkedList llist, draw d) {
    int x;
    double TempLoc, xline[], yline[];
    double scootch = 0.0;
    GTN gtn = new GTN();
    String text, c;
    StringTokenizer checkCommand;

    super.drawStructure(llist, d);
    xline = new double[2];
    yline = new double[2];
    yline[0] = TitleEndy - .05;
    yline[1] = yline[0];
    xline[0] = 0;
    xline[1] = 1;
    // The polyline is drawn immediately under the title/caption
    LGKS.polyline(2, xline, yline, llist, d);

    if (emptyStruct()) {
      super.drawStructure(llist, d); // to handle empty structure
      return;
    }
    for (x = 0; x < MaxLevels; ++x) {
      Modifier[x] = 0.0;
      NextPos[x] =
          0.1; // 0.025;//TreeSideBorder+(Lenx/2.0); // The rightmost position at which we can plot
      // a node *)
    }

    // Scale drawings for more then 10 items
    if (nn >= 10) {
      xspacing -= (nn - 9) * .065;
    }

    // adjust the node starting position so that the sets don't overlap
    Starty -= ((nn / 7 + 2)) * .05;

    nodelist.reset();
    while (nodelist.hasMoreElements()) {
      if (nodelist.hasMoreElements()) gtn = (GTN) (nodelist.nextElement());
      else gtn = (GTN) (nodelist.currentElement());
      TempLoc = xCoord(gtn);
      ApplyModifier(gtn);
    }

    if (maxXCord + (Lenx / 2) < 1.0) {
      ModifierSum = Lenx / 2;
      if (nodelist.size() > 2)
        scootch = ((.975 - (maxXCord + (Lenx / 2))) / ((double) nodelist.size() - 1.0));
      else {
        scootch = ((1.0 - (maxXCord + (Lenx / 2))) / (double) nodelist.size());
        ModifierSum = scootch / 2;
      }
    } else ModifierSum = (((maxXCord - minXCord) / 2) - .5) * -1;

    nodelist.reset();
    x = 0;
    while (nodelist.hasMoreElements()) {
      if (nodelist.hasMoreElements()) gtn = (GTN) (nodelist.nextElement());
      else gtn = (GTN) (nodelist.currentElement());

      ApplyModifier(gtn);
      if (x == (nodelist.size() / 2) && badCommand == 1) {
        LGKS.set_text_align(0, 2, llist, d);
        LGKS.set_textline_color(4, llist, d);
        text = "Bad command!  No action taken.";
        LGKS.text(CenterScreen, (gtn.Gy + .13), text, llist, d);
        LGKS.set_text_align(1, 2, llist, d);
      }
      // The factor needed to shift the tree to the center *)
      xMin = CenterScreen - (0.5 * Maxtitlelength);
      xMax = CenterScreen + (0.5 * Maxtitlelength);
      yMax = Topy - IconHeight - IconToTitleGap;
      yMin = yMax;
      drawWalk(gtn, llist, d);
      Xcenter = (xMin + xMax) / 2.0;
      Ycenter = (yMin + yMax) / 2;
      snapheight = yMax - yMin;
      snapwidth = xMax - xMin;

      ModifierSum += scootch;
      x++;
    }

    LGKS.set_text_align(1, 2, llist, d);
    // Print Text info to screen
    if (weight == 0) text = "Weighted Union: On";
    else text = "Weighted Union: Off";
    LGKS.text(.0, (TitleEndy - .06), text, llist, d);

    if (path == 0) text = "Path Compresion: On";
    else text = "Path Compresion: Off";
    LGKS.text(.45, (TitleEndy - .06), text, llist, d);

    text = "Current Command:";
    LGKS.set_textline_color(2, llist, d);
    LGKS.text(.0, (TitleEndy - .11), text, llist, d);
    LGKS.text(.0, (TitleEndy - .15), command, llist, d);
    LGKS.set_textline_color(3, llist, d);
    text = "Average Comparsions Per Find: " + cpf;
    LGKS.text(.45, (TitleEndy - .11), text, llist, d);
    text = "Average Comparsions Per Union: " + cpu;
    LGKS.text(.45, (TitleEndy - .15), text, llist, d);

    LGKS.set_textline_color(1, llist, d);
    drawSets(llist, d);
  }