예제 #1
0
파일: Grid.java 프로젝트: jankotek/asterope
 /** Dessine l'icone de la grille */
 protected static void drawGrid(Graphics g, int x, int y, Color c) {
   g.setColor(c);
   for (int i = 0; i < TX.length; i++)
     g.drawLine(TX[i][0] + x, TX[i][2] + y, TX[i][1] + x, TX[i][2] + y);
   for (int i = 0; i < TY.length; i++)
     g.drawLine(TY[i][2] + x, TY[i][0] + y, TY[i][2] + x, TY[i][1] + y);
 }
예제 #2
0
파일: View.java 프로젝트: kaschenko/lab3
    private void drawSquare(Graphics g, int x, int y, Tetrominoes shape) {

      int squareWidth = (int) getSize().getWidth() / model.getWidth();
      int squareHeight = (int) getSize().getHeight() / model.getHeight();

      Color colors[] = {
        new Color(0, 0, 0),
        new Color(204, 102, 102),
        new Color(102, 204, 102),
        new Color(102, 102, 204),
        new Color(204, 204, 102),
        new Color(204, 102, 204),
        new Color(102, 204, 204),
        new Color(218, 170, 0)
      };

      Color color = colors[shape.ordinal()];
      g.setColor(color);
      g.fillRect(x + 1, y + 1, squareWidth - 2, squareHeight - 2);
      g.setColor(color.brighter());
      g.drawLine(x, y + squareHeight - 1, x, y);
      g.drawLine(x, y, x + squareWidth - 1, y);

      g.setColor(color.darker());
      g.drawLine(x + 1, y + squareHeight - 1, x + squareWidth - 1, y + squareHeight - 1);
      g.drawLine(x + squareWidth - 1, y + squareHeight - 1, x + squareWidth - 1, y + 1);
    }
예제 #3
0
파일: Grapher.java 프로젝트: afisher/School
  private void drawAxes(Graphics g) {
    g.drawLine(padding, height, width + padding, height);
    g.drawLine(padding, 0, padding, height);

    g.drawString("time", padding + width / 2, height + padding - 5);
    g.drawString("pop", 5, height / 2);
  }
예제 #4
0
 public void paint(Graphics g) {
   super.paint(g);
   if (!isEditing) return;
   Dimension psize = getPreferredSize();
   if (isFocused) g.setColor(Color.yellow);
   else g.setColor(Color.green);
   g.drawLine(0, 0, psize.width, 0);
   g.drawLine(0, 0, 0, psize.height);
   g.drawLine(0, psize.height - 1, psize.width - 1, psize.height - 1);
   g.drawLine(psize.width - 1, 0, psize.width - 1, psize.height - 1);
 }
예제 #5
0
파일: Grapher.java 프로젝트: afisher/School
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    calcSizes();
    drawAxes(g);
    calcMaxes();
    calcTickIncrements();
    drawXTicks(g);
    drawYTicks(g);

    int t = 0;
    int prevX = 0, prevY1 = 0, prevY2 = 0;

    for (DataPair pair : data) {

      int h = pair.getH();
      int p = pair.getP();

      // calculate where to put the dots
      int x = xVal(t, maxT);
      int y1 = yVal(h, maxH);
      int y2 = yVal(p, maxP);

      // draw herbivore dot
      g.setColor(Color.BLUE);
      g.fillOval(x, y1, 2 * r, 2 * r);

      // draw a line connecting this dot to the last
      if (prevX != 0) {
        g.drawLine(prevX + r, prevY1 + r, x + r, y1 + r);
      }

      // draw predator dot
      g.setColor(Color.RED);
      g.fillOval(x, y2, 2 * r, 2 * r);

      // draw a line connecting this dot to the last
      if (prevX != 0) {
        g.drawLine(prevX + r, prevY2 + r, x + r, y2 + r);
      }

      // remember these dots
      prevX = x;
      prevY1 = y1;
      prevY2 = y2;

      g.setColor(Color.BLACK);

      t++;
    }
  }
예제 #6
0
 void drawLine(Graphics g, DrawObject L) {
   if (L == null) {
     return;
   }
   if ((sequencingOn) && (L.sequenceNum != currentSequenceNumDisplay)) {
     return;
   }
   Graphics2D g2 = (Graphics2D) g;
   g2.setStroke(L.drawStroke);
   int x1 = (int) ((L.x - minX) / (maxX - minX) * (D.width - 2 * inset));
   int y1 = (int) ((L.y - minY) / (maxY - minY) * (D.height - 2.0 * inset));
   int x2 = (int) ((L.x2 - minX) / (maxX - minX) * (D.width - 2 * inset));
   int y2 = (int) ((L.y2 - minY) / (maxY - minY) * (D.height - 2.0 * inset));
   if (L.isArrow) {
     drawArrow(
         (Graphics2D) g,
         inset + x1,
         D.height - y1 - inset,
         inset + x2,
         D.height - y2 - inset,
         1.0f,
         L.drawStroke);
   } else {
     g.drawLine(inset + x1, D.height - y1 - inset, inset + x2, D.height - y2 - inset);
   }
 }
예제 #7
0
  void displayCharacterMap(Graphics g) {
    if (currentChars != null) {
      g.setColor(0xffffff);
      g.fillRect(0, getHeight() - inputHeight - 2, getWidth(), inputHeight + 2);
      g.setColor(0x000000);
      g.drawLine(0, getHeight() - inputHeight - 2, getWidth(), getHeight() - inputHeight - 2);
      for (int i = 0; i < currentChars.length; i++) {
        char ch = currentChars[i];
        if (isUppercase) {
          ch = String.valueOf(currentChars[i]).toUpperCase().charAt(0);
        }

        // TODO: if i*12 > getWidth() ?

        g.drawChar(ch, i * 12, getHeight() - inputHeight, Graphics.LEFT | Graphics.TOP);
        if (currentChars[currentKeyStep] == currentChars[i]) {
          g.drawRect(
              i * 12 - 2,
              getHeight() - inputHeight - 2,
              inputFont.charWidth(ch) + 4,
              inputHeight + 4);
        }
      }
    }
  }
 public void showLine(WorldEntity e, Color c) {
   Graphics g = getGObject().getEditor().getGraphics();
   Point cme = getGObject().getCenter();
   Point ce = e.getGObject().getCenter();
   g.setColor(c);
   g.drawLine(cme.x, cme.y, ce.x, ce.y);
 }
예제 #9
0
파일: Grapher.java 프로젝트: afisher/School
  private void drawYTicks(Graphics g) {
    int hPos = 0;
    int pPos = 0;
    for (int i = 0; i < yTicks; i++) {
      int drawPos = yVal(hPos, maxH) + r;

      if (hPos % hInc == 0) {

        // draw line
        g.setColor(Color.BLACK);
        g.drawLine(padding - 10, drawPos, padding, drawPos);

        // draw tick values for herbivores
        g.setColor(Color.BLUE);
        g.drawString("" + hPos, padding - 50, drawPos + r);

        // draw tick values for predators
        g.setColor(Color.RED);
        g.drawString("" + pPos, padding - 50, drawPos + r + 20);
      }

      hPos += hInc;
      pPos += pInc;
    }
  }
예제 #10
0
 void displayStatus(Graphics g) {
   if (statusString != null) {
     g.setColor(0xffffff);
     g.fillRect(0, getHeight() - inputHeight - 2, getWidth(), inputHeight + 2);
     g.setColor(0x000000);
     g.drawLine(0, getHeight() - inputHeight - 2, getWidth(), getHeight() - inputHeight - 2);
     g.drawString(statusString, 0, getHeight() - inputHeight - 2, Graphics.LEFT | Graphics.TOP);
   }
 }
예제 #11
0
 private static void drawVerticalLine(Rectangle rStart, Rectangle rEnd, Graphics g) {
   if (rStart == null || rEnd == null) return;
   int yStart = rStart.y + rStart.height;
   int yEnd = rEnd.y + (rEnd.height / 2);
   if (yStart < yEnd) {
     int xbase = rStart.x + TDHelper.minBoxWidth / 2;
     g.drawLine(xbase, yStart, xbase, yEnd);
   }
 }
예제 #12
0
 void displayCurrentCommand(Graphics g) {
   g.setColor(0xffffff);
   g.fillRect(0, getHeight() - inputHeight - 2, getWidth(), inputHeight + 2);
   g.setColor(0x000000);
   g.drawLine(0, getHeight() - inputHeight - 2, getWidth(), getHeight() - inputHeight - 2);
   g.drawString(
       "Ctrl" + " + " + currentCharCommand,
       0,
       getHeight() - inputHeight,
       Graphics.LEFT | Graphics.TOP);
 }
 /* (non-Javadoc)
  * @see java.awt.print.Printable#print(java.awt.Graphics, java.awt.print.PageFormat, int)
  */
 public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
   int ret = PAGE_EXISTS;
   String line = null;
   try {
     if (fph.knownPage(page)) {
       in.seek(fph.getFileOffset(page));
       line = in.readLine();
     } else {
       long offset = in.getFilePointer();
       line = in.readLine();
       if (line == null) {
         ret = NO_SUCH_PAGE;
       } else {
         fph.createPage(page);
         fph.setFileOffset(page, offset);
       }
     }
     if (ret == PAGE_EXISTS) {
       // Seite ausgeben, Grafikkontext vorbereiten
       Graphics2D g2 = (Graphics2D) g;
       g2.scale(1.0 / RESMUL, 1.0 / RESMUL);
       int ypos = (int) pf.getImageableY() * RESMUL;
       int xpos = ((int) pf.getImageableX() + 2) * RESMUL;
       int yd = 12 * RESMUL;
       int ymax = ypos + (int) pf.getImageableHeight() * RESMUL - yd;
       // Seitentitel ausgeben
       ypos += yd;
       g2.setColor(Color.black);
       g2.setFont(new Font("Monospaced", Font.BOLD, 10 * RESMUL));
       g.drawString(fbname + " Seite " + (page + 1), xpos, ypos);
       g.drawLine(
           xpos,
           ypos + 6 * RESMUL,
           xpos + (int) pf.getImageableWidth() * RESMUL,
           ypos + 6 * RESMUL);
       ypos += 2 * yd;
       // Zeilen ausgeben
       g2.setColor(new Color(0, 0, 127));
       g2.setFont(new Font("Monospaced", Font.PLAIN, 10 * RESMUL));
       while (line != null) {
         g.drawString(line, xpos, ypos);
         ypos += yd;
         if (ypos >= ymax) {
           break;
         }
         line = in.readLine();
       }
     }
   } catch (IOException e) {
     throw new PrinterException(e.toString());
   }
   return ret;
 }
예제 #14
0
 void displayCursor(Graphics g) {
   int x = getCursorX();
   int y = getCursorY();
   if (x >= 0 && x <= vectorLines.elementAt(y).toString().length()) {
     if (isSelected(x, y)) {
       g.setColor(0xffffff);
     } else {
       g.setColor(0x000000);
     }
     g.drawLine(caretLeft, (y) * inputHeight, caretLeft, (y + 1) * inputHeight);
   }
 }
예제 #15
0
  void displayScrollBar(Graphics g) {
    int x = getCursorX();
    int y = getCursorY();
    g.setColor(0xffffff);
    g.fillRect(getWidth() - 5, 0, 5, getHeight());
    g.setColor(0x000000);
    g.drawLine(getWidth() - 5, 0, getWidth() - 5, getHeight());

    int hScrollMin = inputHeight;

    int yScroll = (((linesOnScreen - 1) * y) * inputHeight) / getLinesCount();

    g.fillRect(getWidth() - 5, yScroll, 5, hScrollMin);
  }
예제 #16
0
    /**
     * Draws this polywire on the screen. If a point is not visible (ie. behind the camera) then do
     * not attempt to draw the line connecting that point.
     *
     * <p>Loop thru the list and draw a line connecting each point to the next.
     */
    void draw(Graphics g) {
      int x1, y1, x2, y2;
      if (n <= 1) return;
      g.setColor(this.getColor());

      for (int i = 0; i < n - 1; i++) {
        x1 = (int) ps_[points[i] + 1];
        y1 = (int) ps_[points[i] + 2];
        x2 = (int) ps_[points[i + 1] + 1];
        y2 = (int) ps_[points[i + 1] + 2];
        if (visibles[points[i] / 3] && visibles[points[i + 1] / 3]) {
          g.drawLine(x1, y1, x2, y2);
        }
      }
    }
예제 #17
0
  public void drawVertArrow(Graphics g, int x1, int y1, int x2, int y2) {
    g.drawLine(x1, y1, x2, y2);

    int[] axPoints = new int[3];
    int[] ayPoints = new int[3];

    axPoints[0] = x2;
    ayPoints[0] = y2;
    axPoints[1] = x2 - 1;
    ayPoints[1] = y2 - 2;
    axPoints[2] = x2 + 2;
    ayPoints[2] = y2 - 2;

    g.fillPolygon(axPoints, ayPoints, 3);
  }
예제 #18
0
파일: Grapher.java 프로젝트: afisher/School
  private void drawXTicks(Graphics g) {
    int tPos = 0;
    for (int i = 0; i < xTicks; i++) {
      int drawPos = xVal(tPos, maxT) + r;

      if (tPos % tInc == 0) {
        g.setColor(Color.BLACK);

        g.drawLine(drawPos, height, drawPos, height + 10);
        g.drawString("" + tPos, drawPos, height + 30);
      }

      tPos += tInc;
    }
  }
예제 #19
0
파일: InterestOld.java 프로젝트: iuomo/java
  public void paint(Graphics g) {

    // double p = 1000;
    // double m = 100;
    double nr = r / 12;
    double b = 0;
    int v = 0;
    g.setColor(new Color(255, 255, 255));
    g.fillRect(0, 0, 500, 300);

    g.setColor(new Color(0, 0, 255));
    g.drawRect(0, 10, 400, 210);
    g.drawLine(0, 50, 400, 50);
    g.drawLine(0, 85, 400, 85);
    g.drawLine(0, 120, 400, 120);
    g.drawLine(0, 155, 400, 155);
    g.drawLine(0, 190, 400, 190);

    g.setColor(new Color(0, 0, 0));
    g.drawString("INITIAL INVESTMENT = $" + p, 20, 50);
    g.drawString("MONTHY INVESTMENT = $" + m, 20, 85);
    g.drawString("INTEREST RATE = " + r, 20, 120);
    g.drawString("YEARS OF INVESTMENT = " + y, 20, 155);

    double n = 0;
    b = p;
    while (n < (y * 12)) {
      b = (b * (1 + nr)) + m;

      n++;
    }
    n = 0;
    v = (int) b;
    g.setColor(new Color(255, 0, 0));
    g.drawString("ENDING BALANCE= $" + v, 20, 190);
  } // end paint
예제 #20
0
 public static void drawLine(Graphics g, int x1, int y1, int x2, int y2, int lineWidth) {
   if (lineWidth == 1) g.drawLine(x1, y1, x2, y2);
   else {
     double angle;
     double halfWidth = ((double) lineWidth) / 2.0;
     double deltaX = (double) (x2 - x1);
     double deltaY = (double) (y2 - y1);
     if (x1 == x2) angle = Math.PI;
     else angle = Math.atan(deltaY / deltaX) + Math.PI / 2;
     int xOffset = (int) (halfWidth * Math.cos(angle));
     int yOffset = (int) (halfWidth * Math.sin(angle));
     int[] xCorners = {x1 - xOffset, x2 - xOffset + 1, x2 + xOffset + 1, x1 + xOffset};
     int[] yCorners = {y1 - yOffset, y2 - yOffset, y2 + yOffset + 1, y1 + yOffset + 1};
     g.fillPolygon(xCorners, yCorners, 4);
   }
 }
예제 #21
0
 private static void drawBox(
     String str, Rectangle r, Color fillColor, Color textColor, Graphics g) {
   g.setColor(fillColor);
   g.fillRect(r.x, r.y, r.width, r.height);
   g.setColor(Color.black);
   g.drawRect(r.x, r.y, r.width, r.height);
   int xbase = r.x;
   int ybase = r.y;
   int thisBoxHeight = r.height;
   g.drawLine(
       xbase - TDHelper.minBoxWidth / 2,
       ybase + thisBoxHeight / 2,
       xbase,
       ybase + thisBoxHeight / 2);
   g.setFont(ourFont);
   if (str != null) {
     g.setColor(textColor);
     g.drawString(str, xbase + 3, ybase + thisBoxHeight - TDHelper.descenderPixels);
   }
 }
예제 #22
0
  /** This internal method begins a new page and prints the header. */
  protected void newpage() {
    page = job.getGraphics(); // Begin the new page
    linenum = 0;
    charnum = 0; // Reset line and char number
    pagenum++; // Increment page number
    page.setFont(headerfont); // Set the header font.
    page.drawString(jobname, x0, headery); // Print job name left justified

    String s = "- " + pagenum + " -"; // Print the page number centered.
    int w = headermetrics.stringWidth(s);
    page.drawString(s, x0 + (this.width - w) / 2, headery);
    w = headermetrics.stringWidth(time); // Print date right justified
    page.drawString(time, x0 + width - w, headery);

    // Draw a line beneath the header
    int y = headery + headermetrics.getDescent() + 1;
    page.drawLine(x0, y, x0 + width, y);

    // Set the basic monospaced font for the rest of the page.
    page.setFont(font);
  }
예제 #23
0
 void drawScribbles(Graphics g) {
   if ((scribbles == null) || (scribbles.size() == 0)) {
     return;
   }
   DrawObject L = (DrawObject) scribbles.get(0);
   int scribbleCounter = L.scribbleNum;
   g.setColor(scribbleColor);
   ((Graphics2D) g).setStroke(new BasicStroke(2f));
   int prevX = L.scribbleX;
   int prevY = L.scribbleY;
   for (int i = 1; i < scribbles.size(); i++) {
     L = (DrawObject) scribbles.get(i);
     if (L.scribbleNum == scribbleCounter) {
       // Keep drawing.
       g.drawLine(prevX, prevY, L.scribbleX, L.scribbleY);
       prevX = L.scribbleX;
       prevY = L.scribbleY;
     } else {
       scribbleCounter = L.scribbleNum;
       prevX = L.scribbleX;
       prevY = L.scribbleY;
     }
   }
 }
예제 #24
0
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    int width = getWidth() - rightMargin - leftMargin - 10;
    int height = getHeight() - topMargin - bottomMargin;
    if (width <= 0 || height <= 0) {
      // not enough room to paint anything
      return;
    }

    Color oldColor = g.getColor();
    Font oldFont = g.getFont();
    Color fg = getForeground();
    Color bg = getBackground();
    boolean bgIsLight = (bg.getRed() > 200 && bg.getGreen() > 200 && bg.getBlue() > 200);

    ((Graphics2D) g)
        .setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    if (smallFont == null) {
      smallFont = oldFont.deriveFont(9.0F);
    }

    r.x = leftMargin - 5;
    r.y = topMargin - 8;
    r.width = getWidth() - leftMargin - rightMargin;
    r.height = getHeight() - topMargin - bottomMargin + 16;

    if (border == null) {
      // By setting colors here, we avoid recalculating them
      // over and over.
      border =
          new BevelBorder(
              BevelBorder.LOWERED,
              getBackground().brighter().brighter(),
              getBackground().brighter(),
              getBackground().darker().darker(),
              getBackground().darker());
    }

    border.paintBorder(this, g, r.x, r.y, r.width, r.height);

    // Fill background color
    g.setColor(bgColor);
    g.fillRect(r.x + 2, r.y + 2, r.width - 4, r.height - 4);
    g.setColor(oldColor);

    long tMin = Long.MAX_VALUE;
    long tMax = Long.MIN_VALUE;
    long vMin = Long.MAX_VALUE;
    long vMax = 1;

    int w = getWidth() - rightMargin - leftMargin - 10;
    int h = getHeight() - topMargin - bottomMargin;

    if (times.size > 1) {
      tMin = Math.min(tMin, times.time(0));
      tMax = Math.max(tMax, times.time(times.size - 1));
    }
    long viewRangeMS;
    if (viewRange > 0) {
      viewRangeMS = viewRange * MINUTE;
    } else {
      // Display full time range, but no less than a minute
      viewRangeMS = Math.max(tMax - tMin, 1 * MINUTE);
    }

    // Calculate min/max values
    for (Sequence seq : seqs) {
      if (seq.size > 0) {
        for (int i = 0; i < seq.size; i++) {
          if (seq.size == 1 || times.time(i) >= tMax - viewRangeMS) {
            long val = seq.value(i);
            if (val > Long.MIN_VALUE) {
              vMax = Math.max(vMax, val);
              vMin = Math.min(vMin, val);
            }
          }
        }
      } else {
        vMin = 0L;
      }
      if (unit == Unit.BYTES || !seq.isPlotted) {
        // We'll scale only to the first (main) value set.
        // TODO: Use a separate property for this.
        break;
      }
    }

    // Normalize scale
    vMax = normalizeMax(vMax);
    if (vMin > 0) {
      if (vMax / vMin > 4) {
        vMin = 0;
      } else {
        vMin = normalizeMin(vMin);
      }
    }

    g.setColor(fg);

    // Axes
    // Draw vertical axis
    int x = leftMargin - 18;
    int y = topMargin;
    FontMetrics fm = g.getFontMetrics();

    g.drawLine(x, y, x, y + h);

    int n = 5;
    if (("" + vMax).startsWith("2")) {
      n = 4;
    } else if (("" + vMax).startsWith("3")) {
      n = 6;
    } else if (("" + vMax).startsWith("4")) {
      n = 4;
    } else if (("" + vMax).startsWith("6")) {
      n = 6;
    } else if (("" + vMax).startsWith("7")) {
      n = 7;
    } else if (("" + vMax).startsWith("8")) {
      n = 8;
    } else if (("" + vMax).startsWith("9")) {
      n = 3;
    }

    // Ticks
    ArrayList<Long> tickValues = new ArrayList<Long>();
    tickValues.add(vMin);
    for (int i = 0; i < n; i++) {
      long v = i * vMax / n;
      if (v > vMin) {
        tickValues.add(v);
      }
    }
    tickValues.add(vMax);
    n = tickValues.size();

    String[] tickStrings = new String[n];
    for (int i = 0; i < n; i++) {
      long v = tickValues.get(i);
      tickStrings[i] = getSizeString(v, vMax);
    }

    // Trim trailing decimal zeroes.
    if (decimals > 0) {
      boolean trimLast = true;
      boolean removedDecimalPoint = false;
      do {
        for (String str : tickStrings) {
          if (!(str.endsWith("0") || str.endsWith("."))) {
            trimLast = false;
            break;
          }
        }
        if (trimLast) {
          if (tickStrings[0].endsWith(".")) {
            removedDecimalPoint = true;
          }
          for (int i = 0; i < n; i++) {
            String str = tickStrings[i];
            tickStrings[i] = str.substring(0, str.length() - 1);
          }
        }
      } while (trimLast && !removedDecimalPoint);
    }

    // Draw ticks
    int lastY = Integer.MAX_VALUE;
    for (int i = 0; i < n; i++) {
      long v = tickValues.get(i);
      y = topMargin + h - (int) (h * (v - vMin) / (vMax - vMin));
      g.drawLine(x - 2, y, x + 2, y);
      String s = tickStrings[i];
      if (unit == Unit.PERCENT) {
        s += "%";
      }
      int sx = x - 6 - fm.stringWidth(s);
      if (y < lastY - 13) {
        if (checkLeftMargin(sx)) {
          // Wait for next repaint
          return;
        }
        g.drawString(s, sx, y + 4);
      }
      // Draw horizontal grid line
      g.setColor(Color.lightGray);
      g.drawLine(r.x + 4, y, r.x + r.width - 4, y);
      g.setColor(fg);
      lastY = y;
    }

    // Draw horizontal axis
    x = leftMargin;
    y = topMargin + h + 15;
    g.drawLine(x, y, x + w, y);

    long t1 = tMax;
    if (t1 <= 0L) {
      // No data yet, so draw current time
      t1 = System.currentTimeMillis();
    }
    long tz = timeDF.getTimeZone().getOffset(t1);
    long tickInterval = calculateTickInterval(w, 40, viewRangeMS);
    if (tickInterval > 3 * HOUR) {
      tickInterval = calculateTickInterval(w, 80, viewRangeMS);
    }
    long t0 = tickInterval - (t1 - viewRangeMS + tz) % tickInterval;
    while (t0 < viewRangeMS) {
      x = leftMargin + (int) (w * t0 / viewRangeMS);
      g.drawLine(x, y - 2, x, y + 2);

      long t = t1 - viewRangeMS + t0;
      String str = formatClockTime(t);
      g.drawString(str, x, y + 16);
      // if (tickInterval > (1 * HOUR) && t % (1 * DAY) == 0) {
      if ((t + tz) % (1 * DAY) == 0) {
        str = formatDate(t);
        g.drawString(str, x, y + 27);
      }
      // Draw vertical grid line
      g.setColor(Color.lightGray);
      g.drawLine(x, topMargin, x, topMargin + h);
      g.setColor(fg);
      t0 += tickInterval;
    }

    // Plot values
    int start = 0;
    int nValues = 0;
    int nLists = seqs.size();
    if (nLists > 0) {
      nValues = seqs.get(0).size;
    }
    if (nValues == 0) {
      g.setColor(oldColor);
      return;
    } else {
      Sequence seq = seqs.get(0);
      // Find starting point
      for (int p = 0; p < seq.size; p++) {
        if (times.time(p) >= tMax - viewRangeMS) {
          start = p;
          break;
        }
      }
    }

    // Optimization: collapse plot of more than four values per pixel
    int pointsPerPixel = (nValues - start) / w;
    if (pointsPerPixel < 4) {
      pointsPerPixel = 1;
    }

    // Draw graphs
    // Loop backwards over sequences because the first needs to be painted on top
    for (int i = nLists - 1; i >= 0; i--) {
      int x0 = leftMargin;
      int y0 = topMargin + h + 1;

      Sequence seq = seqs.get(i);
      if (seq.isPlotted && seq.size > 0) {
        // Paint twice, with white and with color
        for (int pass = 0; pass < 2; pass++) {
          g.setColor((pass == 0) ? Color.white : seq.color);
          int x1 = -1;
          long v1 = -1;
          for (int p = start; p < nValues; p += pointsPerPixel) {
            // Make sure we get the last value
            if (pointsPerPixel > 1 && p >= nValues - pointsPerPixel) {
              p = nValues - 1;
            }
            int x2 = (int) (w * (times.time(p) - (t1 - viewRangeMS)) / viewRangeMS);
            long v2 = seq.value(p);
            if (v2 >= vMin && v2 <= vMax) {
              int y2 = (int) (h * (v2 - vMin) / (vMax - vMin));
              if (x1 >= 0 && v1 >= vMin && v1 <= vMax) {
                int y1 = (int) (h * (v1 - vMin) / (vMax - vMin));

                if (y1 == y2) {
                  // fillrect is much faster
                  g.fillRect(x0 + x1, y0 - y1 - pass, x2 - x1, 1);
                } else {
                  Graphics2D g2d = (Graphics2D) g;
                  Stroke oldStroke = null;
                  if (seq.transitionStroke != null) {
                    oldStroke = g2d.getStroke();
                    g2d.setStroke(seq.transitionStroke);
                  }
                  g.drawLine(x0 + x1, y0 - y1 - pass, x0 + x2, y0 - y2 - pass);
                  if (oldStroke != null) {
                    g2d.setStroke(oldStroke);
                  }
                }
              }
            }
            x1 = x2;
            v1 = v2;
          }
        }

        // Current value
        long v = seq.value(seq.size - 1);
        if (v >= vMin && v <= vMax) {
          if (bgIsLight) {
            g.setColor(seq.color);
          } else {
            g.setColor(fg);
          }
          x = r.x + r.width + 2;
          y = topMargin + h - (int) (h * (v - vMin) / (vMax - vMin));
          // a small triangle/arrow
          g.fillPolygon(new int[] {x + 2, x + 6, x + 6}, new int[] {y, y + 3, y - 3}, 3);
        }
        g.setColor(fg);
      }
    }

    int[] valueStringSlots = new int[nLists];
    for (int i = 0; i < nLists; i++) valueStringSlots[i] = -1;
    for (int i = 0; i < nLists; i++) {
      Sequence seq = seqs.get(i);
      if (seq.isPlotted && seq.size > 0) {
        // Draw current value

        // TODO: collapse values if pointsPerPixel >= 4

        long v = seq.value(seq.size - 1);
        if (v >= vMin && v <= vMax) {
          x = r.x + r.width + 2;
          y = topMargin + h - (int) (h * (v - vMin) / (vMax - vMin));
          int y2 = getValueStringSlot(valueStringSlots, y, 2 * 10, i);
          g.setFont(smallFont);
          if (bgIsLight) {
            g.setColor(seq.color);
          } else {
            g.setColor(fg);
          }
          String curValue = getFormattedValue(v, true);
          if (unit == Unit.PERCENT) {
            curValue += "%";
          }
          int valWidth = fm.stringWidth(curValue);
          String legend = (displayLegend ? seq.name : "");
          int legendWidth = fm.stringWidth(legend);
          if (checkRightMargin(valWidth) || checkRightMargin(legendWidth)) {
            // Wait for next repaint
            return;
          }
          g.drawString(legend, x + 17, Math.min(topMargin + h, y2 + 3 - 10));
          g.drawString(curValue, x + 17, Math.min(topMargin + h + 10, y2 + 3));

          // Maybe draw a short line to value
          if (y2 > y + 3) {
            g.drawLine(x + 9, y + 2, x + 14, y2);
          } else if (y2 < y - 3) {
            g.drawLine(x + 9, y - 2, x + 14, y2);
          }
        }
        g.setFont(oldFont);
        g.setColor(fg);
      }
    }
    g.setColor(oldColor);
  }
예제 #25
0
파일: Board.java 프로젝트: ankeshs/hex
  public void drawHexBoard(Graphics g) {
    g.setColor(Color.BLACK);
    double mx1, mx2, mx3, mx4, my1, my2, my3, my4; // Margin attributes

    mx1 = data.a[0][0].x - bst.scale * (r3 / 2 + 0.5);
    mx2 = data.a[0][bst.getOrder() - 1].x + bst.scale * (r3 + 1);
    mx3 = data.a[bst.getOrder() - 1][0].x - bst.scale * (r3 + 1);
    mx4 = data.a[bst.getOrder() - 1][bst.getOrder() - 1].x + bst.scale * (r3 / 2 + 0.5);
    my1 = data.a[0][0].y - bst.scale * 1.5;
    my2 = data.a[0][bst.getOrder() - 1].y - bst.scale * 1.5;
    my3 = data.a[bst.getOrder() - 1][0].y + bst.scale * 1.5;
    my4 = data.a[bst.getOrder() - 1][bst.getOrder() - 1].y + bst.scale * 1.5;

    g.fillPolygon(
        getIntArray(new double[] {mx1, mx2, mx4, mx3}),
        getIntArray(new double[] {my1, my2, my4, my3}),
        4);
    switch (gst.theme) {
      case 0:
        g.setColor(Color.RED);
        break;
      case 1:
        g.setColor(Color.BLACK);
        break;
      case 2:
        g.setColor(Color.YELLOW);
        break;
    }
    g.fillPolygon(
        getIntArray(new double[] {mx1 + 1, mx3 + 1, (mx2 + mx3) / 2}),
        getIntArray(new double[] {my1 + 1, my3 - 1, (my2 + my3) / 2}),
        3);
    g.fillPolygon(
        getIntArray(new double[] {mx2 - 1, mx4 - 1, (mx2 + mx3) / 2}),
        getIntArray(new double[] {my2 + 1, my4 - 1, (my2 + my3) / 2}),
        3);
    switch (gst.theme) {
      case 0:
        g.setColor(Color.BLUE);
        break;
      case 1:
        g.setColor(new Color(1, 175, 1));
        break;
      case 2:
        g.setColor(Color.lightGray);
    }
    g.fillPolygon(
        getIntArray(new double[] {mx1 + 1, mx2 - 1, (mx2 + mx3) / 2}),
        getIntArray(new double[] {my1 + 1, my2 + 1, (my2 + my3) / 2}),
        3);
    g.fillPolygon(
        getIntArray(new double[] {mx3 + 1, mx4 - 1, (mx2 + mx3) / 2}),
        getIntArray(new double[] {my3 - 1, my4 - 1, (my2 + my3) / 2}),
        3);

    for (int i = 0; i < bst.getOrder(); i++)
      for (int j = 0; j < bst.getOrder(); j++) {
        g.setColor(Color.BLACK);
        g.fillPolygon(getIntArray(data.a[i][j].polyX), getIntArray(data.a[i][j].polyY), 6);
        g.setColor(Color.WHITE);
        g.fillPolygon(getIntArray(data.a[i][j].polyXIn()), getIntArray(data.a[i][j].polyYIn()), 6);
        g.setColor(Color.BLACK);
        double x = data.a[i][j].x, y = data.a[i][j].y;
        g.drawLine((int) x, (int) y, (int) x + 1, (int) y + 1);
        circle(g, x, y, data.a[i][j].getState());
      }
    if (ptm == null) return;
    if (ptm.length == 0) return;
    for (int i = 0; i < ptm.length; i++) {
      g.setColor(Color.YELLOW);
      g.fillPolygon(
          getIntArray(data.a[ptm[i][0]][ptm[i][1]].polyXIn()),
          getIntArray(data.a[ptm[i][0]][ptm[i][1]].polyYIn()),
          6);
      g.setColor(Color.BLACK);
      double x = data.a[ptm[i][0]][ptm[i][1]].x, y = data.a[ptm[i][0]][ptm[i][1]].y;
      circle(g, x, y, data.a[ptm[i][0]][ptm[i][1]].getState());
    }
  }
예제 #26
0
  public void paintComponent(Graphics g) {
    // We request keyboard focus out here so that we can catch events for locking zoom, etc.
    requestFocus();

    // 3 Images are painted each time. The reason we use images rather than directly drawing
    // onto the graphics context is that the drawings of one image can be taking place
    // concurrently with the other using threads into offscreen graphic contexts assoc.
    // with the respective images. While printing we do the opposite

    if (setupComplete && currImg != null) {
      int prevH = getPrev(currImg.imgIdH);
      int nextH = getNext(currImg.imgIdH);

      if (blFlag || !timer.isRunning()) {
        img[prevH].paintStuff1(0, g, this);
        currImg.paintStuff1(_xPix, g, this);
        img[nextH].paintStuff1(_xPix + _xPix, g, this);

        /*g.drawImage (img [prevH].img, 0, 0, this);
        g.drawImage (img [prevH].timeimg, 0, _yPix, this);

        g.drawImage (currImg.img, _xPix, 0, this);
        g.drawImage (currImg.timeimg, _xPix, _yPix, this);

        g.drawImage (img [nextH].img, _xPix + _xPix, 0, this);
        g.drawImage (img [nextH].timeimg, _xPix + _xPix, _yPix, this);*/
      } else {
        img[prevH].paintStuff2(0, g, this);
        currImg.paintStuff2(_xPix, g, this);
        img[nextH].paintStuff2(_xPix + _xPix, g, this);

        /*g.drawImage (img [prevH].img1, 0, 0, this);
        g.drawImage (img [prevH].timeimg, 0, _yPix, this);

        g.drawImage (currImg.img1, _xPix, 0, this);
        g.drawImage (currImg.timeimg, _xPix, _yPix, this);

        g.drawImage (img [nextH].img1, _xPix + _xPix, 0, this);
        g.drawImage (img [nextH].timeimg, _xPix + _xPix, _yPix, this);*/
      }
    }

    if (zoomLkLineDispStatus && zXTime >= begTime && zXTime <= endTime) {
      int xcord = panePosX + getEvtXCord(zXTime - begTime);
      g.setColor(Color.white);
      g.drawLine(xcord, 0, xcord, _yPix);
      g.fillRect(xcord, _yPix - lineSize, zLockStrW + 2, lineSize);
      g.setColor(Color.black);
      g.drawRect(xcord, _yPix - lineSize, zLockStrW + 1, lineSize - 1);
      g.setColor(Color.red);
      g.drawString("Zoom Lock", xcord + 1, _yPix - fDescent);
    }

    if (elTLineDispStatus && elapsedPoint >= begTime && elapsedPoint <= endTime) {
      int xcord = panePosX + getEvtXCord(elapsedPoint - begTime);
      g.setColor(Color.white);
      g.drawLine(xcord, 0, xcord, _yPix);
      g.fillRect(xcord, _yPix - lineSize, elTimeStrW + 2, lineSize);
      g.setColor(Color.black);
      g.drawRect(xcord, _yPix - lineSize, elTimeStrW + 1, lineSize - 1);
      g.setColor(Color.red);
      g.drawString("Elapsed Time", xcord + 1, _yPix - fDescent);
    }
  }
예제 #27
0
  void drawEqnLine(Graphics g, DrawObject L) {
    if (L == null) {
      return;
    }
    if ((sequencingOn) && (L.sequenceNum != currentSequenceNumDisplay)) {
      return;
    }
    // First, special cases:
    if ((L.a == 0) && (L.b == 0)) {
      return;
    }
    double px = 0, py = 0, qx = 0, qy = 0;
    double leftX = px, rightX = qx, leftY = py, rightY = qy;
    if (L.a == 0) {
      // Case 2: a=0 => horizontal line.
      leftX = minX;
      rightX = maxX;
      py = -L.c / L.b;
      qy = -L.c / L.b;
      if ((py < minY) || (py > maxY)) {
        // Cannot display.
        return;
      }
      leftY = rightY = py;
    } else if (L.b == 0) {
      // Case 3: b=0 => vertical line.
      leftX = -L.c / L.a;
      rightX = -L.c / L.a;
      leftY = minY;
      rightY = maxY;
      if ((leftX < minX) || (leftX > maxX)) {
        return;
      }
    } else {
      // Case 4: regular.
      // Note: the line could intersect the drawable region in weird ways.
      px = (-L.c - L.b * minY) / L.a;
      qx = (-L.c - L.b * maxY) / L.a;
      py = (-L.c - L.a * minX) / L.b;
      qy = (-L.c - L.a * maxX) / L.b;
      // System.out.println ("px=" + px + " qx=" + qx + " py=" + py + " qy=" + qy);
      // Find leftmost point to draw.
      if ((py >= minY) && (py <= maxY)) {
        // Leftmost point is on the x=minX line.
        leftX = minX;
        leftY = py;
        // System.out.println ("case(a): leftmost on minX-line");
      } else {
        // Leftmost point is not on the x=minX line.
        // Find leftmost point intersecting with low or high
        if (px < qx) {
          leftX = px;
          leftY = minY;
          // System.out.println ("case(a.1): on minY-line");
        } else {
          leftX = qx;
          leftY = maxY;
          // System.out.println ("case(a.2): on maxY-line");
        }
      }

      // Now find rightmost point.
      if ((qy >= minY) && (qy <= maxY)) {
        // Rightmost point is on the x=maxX line.
        rightX = maxX;
        rightY = qy;
        // System.out.println ("case(b): rightmost on maxX-line");
      } else {
        if (px > qx) {
          rightX = px;
          rightY = minY;
          // System.out.println ("case(b.1): rightmost on minY-line");
        } else {
          rightX = qx;
          rightY = maxY;
          // System.out.println ("case(b.1): rightmost on maxY-line");
        }
      }
    }

    // System.out.println ("left:(" + leftX + "," + leftY + ")  right:(" + rightX + "," + rightY +
    // ")");

    int x1 = (int) ((leftX - minX) / (maxX - minX) * (D.width - 2 * inset));
    int y1 = (int) ((leftY - minY) / (maxY - minY) * (D.height - 2.0 * inset));
    int x2 = (int) ((rightX - minX) / (maxX - minX) * (D.width - 2 * inset));
    int y2 = (int) ((rightY - minY) / (maxY - minY) * (D.height - 2.0 * inset));
    Graphics2D g2 = (Graphics2D) g;
    g2.setStroke(L.drawStroke);
    g.drawLine(inset + x1, D.height - y1 - inset, inset + x2, D.height - y2 - inset);
  }
예제 #28
0
파일: Grid.java 프로젝트: jankotek/asterope
 /** Dessine l'icone d'un SED */
 protected static void drawSED(Graphics g, int x, int y, Color c) {
   g.setColor(c);
   for (int i = 0; i < SY2.length; i++)
     g.drawLine(SY2[i][0] + x, SY2[i][2] + y, SY2[i][1] + x, SY2[i][2] + y);
 }
예제 #29
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2d = (Graphics2D) g;
    RenderingHints rh = g2d.getRenderingHints();
    rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2d.setRenderingHints(rh);

    // Background.
    D = this.getSize();
    g.setColor(backgroundColor);
    g.fillRect(0, 0, D.width, D.height);
    Graphics2D g2 = (Graphics2D) g;
    g2.setStroke(lineStroke);

    // Axes, bounding box.
    g.setColor(Color.gray);
    g.drawLine(inset, D.height - inset, D.width - inset, D.height - inset);
    g.drawLine(D.width - inset, inset, D.width - inset, D.height - inset);
    g.drawLine(inset, inset, inset, D.height - inset);
    g.drawLine(inset, inset, D.width - inset, inset);

    double xDelta = (maxX - minX) / numIntervals;

    // X-ticks and labels.
    for (int i = 1; i <= numIntervals; i++) {
      double xTickd = i * xDelta;
      int xTick = (int) (xTickd / (maxX - minX) * (D.width - 2 * inset));
      g.drawLine(inset + xTick, D.height - inset - 5, inset + xTick, D.height - inset + 5);
      double x = minX + i * xDelta;
      g.drawString(df.format(x), xTick + inset - 5, D.height - inset + 20);
    }

    // Y-ticks
    double yDelta = (maxY - minY) / numIntervals;
    for (int i = 0; i < numIntervals; i++) {
      int yTick = (i + 1) * (int) ((D.height - 2 * inset) / (double) numIntervals);
      g.drawLine(inset - 5, D.height - yTick - inset, inset + 5, D.height - yTick - inset);
      double y = minY + (i + 1) * yDelta;
      g.drawString(df.format(y), 1, D.height - yTick - inset);
    }

    // Zoom+move
    Font savedFont = g.getFont();
    g.setFont(plusFont);
    g.drawString("+", D.width - 25, 20);
    g.setFont(minusFont);
    g.drawString("-", D.width - 25, 50);
    drawArrow(g2d, D.width - 70, 20, D.width - 70, 0, 1.0f, lineStroke); // Up
    drawArrow(g2d, D.width - 70, 30, D.width - 70, 50, 1.0f, lineStroke); // Down
    drawArrow(g2d, D.width - 65, 25, D.width - 45, 25, 1.0f, lineStroke); // Right
    drawArrow(g2d, D.width - 75, 25, D.width - 95, 25, 1.0f, lineStroke); // Left
    g.setFont(savedFont);

    // See if standard axes are in the middle.
    g.setColor(Color.gray);
    if ((minX < 0) && (maxX > 0) && (drawMiddleAxes)) {
      // Draw y-axis
      int x = (int) ((0 - minX) / (maxX - minX) * (D.width - 2 * inset));
      g.drawLine(inset + x, D.height - inset, inset + x, inset);
    }
    if ((minY < 0) && (maxY > 0) && (drawMiddleAxes)) {
      // Draw x-axis
      int y = (int) ((0 - minY) / (maxY - minY) * (D.height - 2.0 * inset));
      g.drawLine(inset, D.height - y - inset, D.width - inset, D.height - y - inset);
    }

    // Draw the objects.
    drawObjects(g, points, lines, ovals, rectangles, images, labels, eqnLines);
    if (animationMode) {
      drawObjects(g, animPoints, animLines, animOvals, animRectangles, null, labels, eqnLines);
      // No images in animation mode.
    }

    drawScribbles(g);
  }
    public void paint(Graphics g) {
      path = findOptimizedPath(srcID, dstID, type);

      /// Create the drawing board
      Dimension d = getSize();
      g.setColor(Color.white);
      g.fillRect(1, 1, d.width - 2, d.height - 2);

      g.setColor(Color.black);
      g.drawRect(1, 1, d.width - 2, d.height - 2);
      g.setFont(serifFont);

      /// Draw the whole network, including all routers with
      ///     delay and flow level, sources and destinations.
      int numR = 1;
      int w = 95;
      int h = d.height / 5;
      int pos = -1;

      for (int i = 0; i < 3; i++) {
        g.drawOval(w, h + 100 * i, 40, 40);
        g.drawString("S" + String.valueOf(i + 1), w + 13, h + 100 * i - 5);
      }

      for (int i = 0; i < 3; i++) {
        pos++;
        Router temp = statMux.getRouter(pos);
        g.drawOval(w + 110, h + 100 * i, 40, 40);
        g.drawString("R" + String.valueOf(numR++), w + 123, h + 100 * i - 5);
        g.drawString(
            String.valueOf(temp.getDelay() * temp.getPriority(type) + temp.getFlowLevel()),
            w + 125,
            h + 100 * i + 15);
        g.drawString(String.valueOf(temp.getFlowLevel()), w + 125, h + 100 * i + 35);
      }

      h = d.height / 11;
      for (int i = 0; i < 4; i++) {
        pos++;
        Router temp = statMux.getRouter(pos);
        g.drawOval(w + 210, h + 100 * i, 40, 40);
        g.drawString("R" + String.valueOf(numR++), w + 223, h + 100 * i - 5);
        g.drawString(
            String.valueOf(temp.getDelay() * temp.getPriority(type) + temp.getFlowLevel()),
            w + 225,
            h + 100 * i + 15);
        g.drawString(String.valueOf(temp.getFlowLevel()), w + 225, h + 100 * i + 35);
      }

      h = 20;
      for (int i = 0; i < 6; i++) {
        pos++;
        Router temp = statMux.getRouter(pos);
        g.drawOval(w + 310, h + 80 * i, 40, 40);
        g.drawString("R" + String.valueOf(numR++), w + 320, h + 80 * i - 5);
        g.drawString(
            String.valueOf(temp.getDelay() * temp.getPriority(type) + temp.getFlowLevel()),
            w + 325,
            h + 80 * i + 15);
        g.drawString(String.valueOf(temp.getFlowLevel()), w + 325, h + 80 * i + 35);
      }

      for (int i = 0; i < 4; i++) {
        g.drawOval(w + 410, d.height / 11 + 100 * i, 40, 40);
        g.drawString("D" + String.valueOf(i + 1), w + 423, d.height / 11 + 100 * i - 5);
      }

      g.setColor(Color.black);
      int[][] connection = statMux.getConnections();

      /// Check buffer for connections at each step and draw links at layer1
      for (int i = 0; i < connection[path[0] - 1].length; i++) {
        int temp = connection[path[0] - 1][i] - 3;
        g.drawLine(w + 40, (path[0]) * d.height / 5 + 20, w + 110, temp * d.height / 5 + 20);
      }

      /// Check buffer for connections at each step and draw links at layer2
      for (int i = 0; i < connection[path[1] - 1].length; i++) {
        int temp = connection[path[1] - 1][i] - 7;
        g.drawLine(
            w + 150, (path[1] - 3) * d.height / 5 + 20, w + 210, (d.height / 11) + 100 * temp + 20);
      }

      /// Check buffer for connections at each step and draw links at layer3
      for (int i = 0; i < connection[path[2] - 1].length; i++) {
        int temp = connection[path[2] - 1][i] - 11;
        g.drawLine(w + 250, (d.height / 11) + 100 * (path[2] - 7) + 20, w + 310, 80 * temp + 40);
      }

      /// Draw optimized path for packets traveling between source
      /// and destination
      h = d.height / 5;
      Graphics2D g2 = (Graphics2D) g;
      g2.setStroke(new BasicStroke(2));
      g2.setColor(Color.red);

      g2.drawLine(w + 40, h * (path[0]) + 20, w + 110, h * (path[1] - 3) + 20);
      g2.drawLine(
          w + 150, h * (path[1] - 3) + 20, w + 210, (d.height / 11) + 100 * (path[2] - 7) + 20);
      g2.drawLine(
          w + 250, (d.height / 11) + 100 * (path[2] - 7) + 20, w + 310, 80 * (path[3] - 11) + 40);
      g2.drawLine(
          w + 350, 80 * (path[3] - 11) + 40, w + 410, (d.height / 11) + 100 * (path[4] - 17) + 20);

      /// Calculate and display loss, delay, and throughput
      delayTime = getDelay(path, type);
      throughPut = getThroughput(path);

      int numPackLost = getLossRate(numTransfer);

      lossRate = numPackLost / 100000.0 + 0.0005 * delayTime;
      delayVal.setText(String.format("%.2f", delayTime));
      throuVal.setText(String.valueOf(throughPut));
      lossVal.setText(String.format("%.4f", lossRate));
    }