示例#1
0
  /**
   * Draw the lines connecting fields on the desktop. These lines represent super-/subfield
   * relations.
   *
   * @param g The Graphics context on which to draw the lines
   * @see #linesLayer
   */
  private void drawLines(Graphics g) {
    java.awt.Graphics2D g2 = (Graphics2D) g;

    g2.setRenderingHint(
        java.awt.RenderingHints.KEY_ANTIALIASING, java.awt.RenderingHints.VALUE_ANTIALIAS_ON);

    final Point Q = getCenterLocation(QLabel);

    for (int i = 0; i < towers.size(); i++) {
      Tower t = (Tower) towers.get(i);
      g2.setColor(COLORS[i % COLORS.length]);
      boolean bottom = false;
      for (int j = 0; j < t.floors.size(); j++) {
        if (j == t.floors.size() - 1) bottom = true;
        Tower.Floor f = (Tower.Floor) t.getFloor(j);
        // iterate over all fields this floor
        Component[] fields = f.getComponents();
        for (int k = 0; k < fields.length; k++) {
          NumberField a = (NumberField) fields[k]; // line origin
          Point p1 = getCenterLocation(a.getCenterComponent()); // get center

          for (int l = 0; l < towers.size(); l++) {
            if (i == l) // use different colors for drawing within/without towers
            g2.setStroke(IN_LINE);
            else g2.setStroke(OUT_LINE);
            Tower t2 = (Tower) towers.get(l);
            // pen color changes according to destination tower
            // that way all 'sets of subsets' are monochrome
            // g2.setColor(COLORS[l % COLORS.length]);
            floors:
            for (int m = 0; m < t2.floors.size(); m++) {
              Tower.Floor f2 = (Tower.Floor) t2.getFloor(m);
              // iterate over all fields this floor
              boolean done = false;
              Component[] fields2 = f2.getComponents();
              for (int n = 0; n < fields2.length; n++) {
                NumberField b = (NumberField) fields2[n]; // line destination
                if (i == l & j == m) { // we are within a floor{
                  if (k == n) ; // do nothing (don't draw to yourself)
                  else { // to do, maybe have different lines for isomorphy?
                    Point p2 = getCenterLocation(b.getCenterComponent()); // get center
                    g2.drawLine(p1.x, p1.y, p2.x, p2.y);
                    done = true;
                  }
                } else if (a.hasSubfield(b) && !a.subfieldHasProperSubfield(b)) {
                  Point p2 = getCenterLocation(b.getCenterComponent()); // get center
                  g2.drawLine(p1.x, p1.y, p2.x, p2.y);
                  done = true;
                }
              }
              // go to the next tower; only need to draw to ONE floor per tower
              if (done) break floors;
            }
          }
          if (bottom && a.hasNoProperSubfields()) { // bottom of tower, no lines out of tower...
            g2.setColor(COLORS[i % COLORS.length]);
            g2.setStroke(IN_LINE);
            g2.drawLine(p1.x, p1.y, Q.x, Q.y); // then draw to Q!
          }
        }
      }
    }
  }