Beispiel #1
0
  // createericlist with a String signature is used to process a String
  // containing a sequence of GAIGS structures
  // createericlist creates the list of graphics primitives for these snapshot(s).
  // After creating these lists, that are then appended to l, the list of snapshots,
  // Also must return the number of snapshots loaded from the string
  public /*synchronized*/ int createericlist(String structString) {
    int numsnaps = 0;
    if (debug) System.out.println("In create eric " + structString);
    StringTokenizer st = new StringTokenizer(structString, "\r\n");
    while (st.hasMoreTokens()) {
      numsnaps++; // ??
      String tempString;
      LinkedList tempList = new LinkedList();
      StructureType strct;
      tempString = st.nextToken();
      try {
        boolean headers = true;
        while (headers) {
          headers = false;
          if (tempString.toUpperCase().startsWith("VIEW")) {
            tempString = HandleViewParams(tempString, tempList, st);
            headers = true;
          }
          if (tempString.toUpperCase().startsWith("FIBQUESTION ")
              || tempString.toUpperCase().startsWith("MCQUESTION ")
              || tempString.toUpperCase().startsWith("MSQUESTION ")
              || tempString.toUpperCase().startsWith("TFQUESTION ")) {
            tempString = add_a_question(tempString, st);
            headers = true;
          }
        }

        if (tempString.toUpperCase().equals("STARTQUESTIONS")) {
          numsnaps--; // questions don't count as snapshots
          readQuestions(st);
          break;
        }
        // After returning from HandleViewParams, tempString should now contain
        // the line with the structure type and possible additional text height info
        StringTokenizer structLine = new StringTokenizer(tempString, " \t");
        String structType = structLine.nextToken();
        if (debug) System.out.println("About to assign structure" + structType);
        strct = assignStructureType(structType);
        strct.loadTextHeights(structLine, tempList, this);
        strct.loadLinesPerNodeInfo(st, tempList, this);

        strct.loadTitle(st, tempList, this);
        strct.loadStructure(st, tempList, this);
        strct.calcDimsAndStartPts(tempList, this);
        strct.drawTitle(tempList, this);
        strct.drawStructure(tempList, this);
      } catch (VisualizerLoadException e) {
        System.out.println(e.toString());
      }
      //             // You've just created a snapshot.  Need to insure that "**" is appended
      //             // to the URLList for this snapshot IF no VIEW ALGO line was parsed in the
      //             // string for the snapshot.  This could probably best be done in the
      //             // HandleViewParams method
      list_of_snapshots.append(tempList);
      Snaps++;
    }
    return (numsnaps);
  } // createericlist(string)
Beispiel #2
0
  public int createericlist(Element snap) {
    int numsnaps = 0;

    StructureCollection structs = new StructureCollection();
    LinkedList tempList = new LinkedList();

    try {
      load_snap_from_xml(snap, structs, tempList);

      structs.calcDimsAndStartPts(tempList, this);
      structs.drawTitle(tempList, this);
      structs.drawStructure(tempList, this);

    } catch (VisualizerLoadException e) {
      System.out.println(e.toString());
    }

    list_of_snapshots.append(tempList);
    Snaps++;

    return numsnaps; // this.. isnt used, and isnt what it says it is.
  } // createericlist(element)
Beispiel #3
0
  public static void main(String[] args) throws IOException {
    // list of possible colors
    String[] colorNames = {" ", "Red", "Yellow", "Blue", "Green"};
    // colors represented as integers
    int[] colorList = {0, 1, 2, 3, 4};

    // read in file
    if (args.length == 0) System.out.println("No file specified.");
    else {
      FileReader theFile;
      BufferedReader inFile;
      String oneLine;
      try {
        theFile = new FileReader(args[0]);
        inFile = new BufferedReader(theFile);
        // while not end of input
        while ((oneLine = inFile.readLine()) != null) {
          // build a linked list
          String numNodes[] = oneLine.split(" ");
          System.out.println("Number of nodes: " + numNodes[0]);
          int numOfNodes = Integer.parseInt(numNodes[0]);
          LinkedList v = new LinkedList();
          // add the number of vertex nodes indicated in the input file, all to one linked list
          for (int i = 0; i < numOfNodes; i++) {
            Node y = new Node();
            v.append(y);
          }
          // create adjacency table
          int[][] a = new int[numOfNodes][numOfNodes];
          // Read in the adjacency table
          for (int r = 0; r < numOfNodes; r++) {
            // read in each line of the input table
            oneLine = inFile.readLine();
            String[] line = oneLine.split(" ");
            for (int c = 0; c < numOfNodes; c++) {
              a[r][c] = Integer.parseInt(line[c]);
            }
          }
          // print adjacency table
          printArray(a, numOfNodes);

          // now try to assign colors and check adjacency table as you move along,
          // backtracking when necessary
          boolean valid;
          int colorCount = 0;
          int x;
          int n = 0; // n represents which node I am currently in
          Node p = v.first.getNext();
          while (p.getNext() != null) {
            colorCount++;
            x = colorList[colorCount];
            p.setColor(x);
            // check if current selected color would be valid for this node
            valid = v.checkAdjacency(x, n, a, numOfNodes);
            if (valid == false) {
              if (colorCount < 4 && colorCount > 0) {
                continue; // will try next color when re-enter while loop
              } else { // backtrack to previous node
                if (n > 0) {
                  v.printProgressThusFar(n);
                  p.setColor(0);
                  p = p.getPrevious();
                  n--;
                  int z = p.getColor();
                  while (z
                      == 4) { // if previous node is at last color, then go to previous one, etc.
                    p.setColor(0);
                    if (n > 0) {
                      p = p.getPrevious();
                      n--;
                    } else break;
                    z = p.getColor();
                  } // when you reach a previous node whose color you can increment, go back through
                    // the while loop again
                  colorCount = z;
                }
              }
            } else { // if(good==true) then just keep going with filling in colors
              p = p.getNext();
              n++;
              colorCount = 0; // reset color back to red for next node
            }
          } // while (p.getNext()!=null)
          // print the solution that has been found
          v.printList();
        } // end while loop
      } // end try loop
      catch (Exception e) {
        e.printStackTrace();
        System.out.println("An error has occurred!");
      }
    } // end else
  } // end main