Exemplo n.º 1
0
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    if (drawOverlay) {
      g = g.create();
      AntialiasingManager.activateAntialiasing(g);

      try {
        // Paint a roll over fade out.
        FadeTracker fadeTracker = FadeTracker.getInstance();

        float visibility = 0.0f;
        if (fadeTracker.isTracked(this, FadeKind.ROLLOVER)) {
          visibility = fadeTracker.getFade(this, FadeKind.ROLLOVER);
          visibility /= 4;
        } else visibility = 0.5f;

        // Draw black overlay
        g.setColor(new Color(0.0f, 0.0f, 0.0f, visibility));
        g.fillRoundRect(1, 1, width - 2, height - 2, 10, 10);

        // Draw arrow
        g.setColor(Color.WHITE);

        int[] arrowX = new int[] {width - 17, width - 7, width - 12};
        int[] arrowY = new int[] {height - 12, height - 12, height - 7};
        g.fillPolygon(arrowX, arrowY, arrowX.length);
      } finally {
        g.dispose();
      }
    }
  }
Exemplo n.º 2
0
  public void paint(Graphics g) {
    m_fm = g.getFontMetrics();

    g.setColor(getBackground());
    g.fillRect(0, 0, getWidth(), getHeight());
    getBorder().paintBorder(this, g, 0, 0, getWidth(), getHeight());

    g.setColor(getForeground());
    g.setFont(getFont());
    m_insets = getInsets();
    int x = m_insets.left;
    int y = m_insets.top + m_fm.getAscent();

    StringTokenizer st = new StringTokenizer(getText(), "\t");
    while (st.hasMoreTokens()) {
      String sNext = st.nextToken();
      g.drawString(sNext, x, y);
      x += m_fm.stringWidth(sNext);

      if (!st.hasMoreTokens()) break;
      int index = 0;
      while (x >= getTab(index)) index++;
      x = getTab(index);
    }
  }
Exemplo n.º 3
0
  public void paintComponent(Graphics graphics) {
    Rectangle bounds = getBounds();
    GraphicsUtility graphicsUtility = new GraphicsUtility(graphics);
    graphicsUtility.setStroke(GraphicsUtility.STROKE_BOLD);

    if (isSelected()) {
      graphics.setColor(GraphicsUtility.getSelectedColor());
      graphics.fillRect(0, 0, bounds.width, SELECT_BORDER_SIZE);
      graphics.fillRect(0, 0, SELECT_BORDER_SIZE, bounds.height);
      graphics.fillRect(0, bounds.height - SELECT_BORDER_SIZE, bounds.width, SELECT_BORDER_SIZE);
      graphics.fillRect(bounds.width - SELECT_BORDER_SIZE, 0, SELECT_BORDER_SIZE, bounds.height);
      graphics.setColor(Color.BLACK);
    }
    graphics.drawString(getCaption(), 10, 10);

    graphicsUtility.drawArrow(
        8, BORDER_INSET, BORDER_INSET, BORDER_INSET, bounds.height - BORDER_INSET);
    graphicsUtility.drawArrow(
        8,
        BORDER_INSET,
        bounds.height - BORDER_INSET,
        bounds.width - BORDER_INSET,
        bounds.height - BORDER_INSET);
    graphicsUtility.drawArrow(
        8,
        bounds.width - BORDER_INSET,
        bounds.height - BORDER_INSET,
        bounds.width - BORDER_INSET,
        BORDER_INSET);
    graphicsUtility.drawArrow(
        8, bounds.width - BORDER_INSET, BORDER_INSET, bounds.width - 50, BORDER_INSET);
    graphicsUtility.setStroke(GraphicsUtility.STROKE_NORMAL);
  }
Exemplo n.º 4
0
  /**
   * This is called to paint within the EditCanvas
   *
   * @param g Graphics
   * @param c DisplayCanvas to paint on.
   */
  public void paint(Graphics g, DisplayCanvas c) {
    Rectangle nb = transformOutput(c, getBounds());
    if (!getActive()) {
      Rectangle r = getBounds();
      g.setColor(Color.lightGray);
      g.fillRect(r.x, r.y, r.width, r.height);
    }

    draw((Graphics2D) g, nb.x, nb.y, nb.width, nb.height);

    if ((c instanceof StationModelCanvas) && ((StationModelCanvas) c).getShowParams()) {
      int xoff = 0;
      FontMetrics fm = g.getFontMetrics();
      g.setColor(Color.black);
      for (int i = 0; i < paramIds.length; i++) {
        String s = paramIds[i];
        if (i > 0) {
          s = ", " + s;
        }
        g.drawString(s, nb.x + xoff, nb.y + nb.height + fm.getMaxDescent() + fm.getMaxAscent() + 4);
        xoff += fm.stringWidth(s);
      }
    }
    if ((c instanceof StationModelCanvas) && ((StationModelCanvas) c).shouldShowAlignmentPoints()) {
      paintRectPoint(g, c);
    }
  }
Exemplo n.º 5
0
  /**
   * Override the pain method do draw the axis lines
   *
   * @param g The graphics to paint to
   */
  public void paint(Graphics g) {
    Rectangle b = getBounds();
    g.setColor(canvasBg);
    g.fillRect(0, 0, b.width, b.height);
    paintGrid(g);

    Point center = getCenter();
    if (g instanceof Graphics2D) {
      ((Graphics2D) g).translate(center.x, center.y);
    }
    super.paint(g);
    if (g instanceof Graphics2D) {
      ((Graphics2D) g).scale(1.0, 1.0);
    }
    g.setColor(Color.gray);
    g.drawLine(0, -10 * b.height, 0, 10 * b.height);
    g.drawLine(-10 * b.width, 0, 10 * b.width, 0);

    MetSymbol tmp = highlightedMetSymbol;
    if (tmp != null) {
      Rectangle tb = tmp.getBounds();
      g.setColor(Color.red);
      g.drawRect(tb.x - 2, tb.y - 2, tb.width + 4, tb.height + 4);
    }
  }
Exemplo n.º 6
0
 public void drawPool(int deepEnd, int shallEnd, int length) {
   Graphics paper = panel.getGraphics();
   paper.setColor(Color.WHITE);
   paper.fillRect(0, 0, 200, 175);
   paper.setColor(Color.BLACK);
   paper.drawLine(50, 50, 50 + length * 15, 50);
   paper.drawLine(50, 50 + deepEnd * 15, 50, 50);
   paper.drawLine(50 + length * 15, 50, 50 + length * 15, 50 + shallEnd * 15);
   paper.drawLine(50, 50 + deepEnd * 15, 50 + length * 15, 50 + shallEnd * 15);
 }
Exemplo n.º 7
0
 void circle(Graphics g, double x, double y, int st) {
   switch (st) {
     case Block.BLANK:
       return;
     case Block.RED_BEAD:
       switch (gst.theme) {
         case 0:
           g.setColor(Color.RED);
           break;
         case 1:
           g.setColor(Color.BLACK);
           break;
         case 2:
           g.drawImage(
               gold,
               (int) (x - bst.scale * r3 / 2 * 0.75),
               (int) (y - bst.scale * r3 / 2 * 0.75),
               (int) (bst.scale * r3 * 0.75),
               (int) (bst.scale * r3 * 0.75),
               Color.WHITE,
               null);
           return;
       }
       break;
     case Block.BLUE_BEAD:
       switch (gst.theme) {
         case 0:
           g.setColor(Color.BLUE);
           break;
         case 1:
           g.setColor(new Color(1, 175, 1));
           break;
         case 2:
           g.drawImage(
               silver,
               (int) (x - bst.scale * r3 / 2 * 0.75),
               (int) (y - bst.scale * r3 / 2 * 0.75),
               (int) (bst.scale * r3 * 0.75),
               (int) (bst.scale * r3 * 0.75),
               Color.WHITE,
               null);
           return;
       }
       break;
     case Block.RED_PATH:
     case Block.BLUE_PATH:
       g.setColor(Color.GREEN);
       break;
   }
   g.fillOval(
       (int) (x - bst.scale * r3 / 2 * 0.75),
       (int) (y - bst.scale * r3 / 2 * 0.75),
       (int) (bst.scale * r3 * 0.75),
       (int) (bst.scale * r3 * 0.75));
 }
Exemplo n.º 8
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);
 }
  protected void paintGrid(Graphics g, int rowMin, int rowMax, int colMin, int colMax) {
    if (!grid.getShowGrid()) {
      return; // do nothing
    }

    int y1 = grid.getRowPosition(rowMin);
    int y2 = grid.getRowPosition(rowMax) + grid.getRowHeight(rowMax);
    int x1 = grid.getColumnPosition(colMin);
    int x2 = grid.getColumnPosition(colMax) + grid.getColumnWidth(colMax);

    g.setColor(grid.getGridColor());

    // Draw the horizontal lines
    for (int row = rowMin; row <= rowMax; row++) {
      int rowY = grid.getRowPosition(row);
      g.drawLine(x1, rowY, x2, rowY);
    }
    g.drawLine(x1, y2, x2, y2);

    // Draw the vertical gridlines
    for (int col = colMin; col <= colMax; col++) {
      int colX = grid.getColumnPosition(col);
      g.drawLine(colX, y1, colX, y2);
    }
    g.drawLine(x2, y1, x2, y2);
  }
Exemplo n.º 10
0
  /**
   * Paints the word-wrapped text.
   *
   * @param g The graphics context in which to paint.
   * @param a The shape (usually a rectangle) in which to paint.
   */
  public void paint(Graphics g, Shape a) {

    Rectangle alloc = (a instanceof Rectangle) ? (Rectangle) a : a.getBounds();
    tabBase = alloc.x;

    Graphics2D g2d = (Graphics2D) g;
    host = (RSyntaxTextArea) getContainer();
    int ascent = host.getMaxAscent();
    int fontHeight = host.getLineHeight();
    FoldManager fm = host.getFoldManager();
    TokenPainter painter = host.getTokenPainter();
    Element root = getElement();

    // Whether token styles should always be painted, even in selections
    int selStart = host.getSelectionStart();
    int selEnd = host.getSelectionEnd();
    boolean useSelectedTextColor = host.getUseSelectedTextColor();

    int n = getViewCount(); // Number of lines.
    int x = alloc.x + getLeftInset();
    tempRect.y = alloc.y + getTopInset();
    Rectangle clip = g.getClipBounds();
    for (int i = 0; i < n; i++) {

      tempRect.x = x + getOffset(X_AXIS, i);
      // tempRect.y = y + getOffset(Y_AXIS, i);
      tempRect.width = getSpan(X_AXIS, i);
      tempRect.height = getSpan(Y_AXIS, i);
      // System.err.println("For line " + i + ": tempRect==" + tempRect);

      if (tempRect.intersects(clip)) {
        Element lineElement = root.getElement(i);
        int startOffset = lineElement.getStartOffset();
        int endOffset = lineElement.getEndOffset() - 1; // Why always "-1"?
        View view = getView(i);
        if (!useSelectedTextColor
            || selStart == selEnd
            || (startOffset >= selEnd || endOffset < selStart)) {
          drawView(painter, g2d, alloc, view, fontHeight, tempRect.y + ascent);
        } else {
          // System.out.println("Drawing line with selection: " + i);
          drawViewWithSelection(
              painter, g2d, alloc, view, fontHeight, tempRect.y + ascent, selStart, selEnd);
        }
      }

      tempRect.y += tempRect.height;

      Fold possibleFold = fm.getFoldForLine(i);
      if (possibleFold != null && possibleFold.isCollapsed()) {
        i += possibleFold.getCollapsedLineCount();
        // Visible indicator of collapsed lines
        Color c = RSyntaxUtilities.getFoldedLineBottomColor(host);
        if (c != null) {
          g.setColor(c);
          g.drawLine(x, tempRect.y - 1, alloc.width, tempRect.y - 1);
        }
      }
    }
  }
  public void draw(Graphics page) // draws letter on screen
      {

    page.setColor(color);
    page.setFont(new Font("TimesRoman", Font.PLAIN, 24));
    page.drawString(testString, x, y);
  }
Exemplo n.º 12
0
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   if (uneHashtable.get(unEtat) != null) {
     g.setColor((Color) uneHashtable.get(unEtat));
     g.fillRect(100, 20, 40, 40);
   }
 }
Exemplo n.º 13
0
 @Override
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   for (int x = 0; x < 255; x++) {
     g.setColor(new Color(x, 0, 255 - x));
     g.fillRect(x, 10, 1, 100);
   }
 }
Exemplo n.º 14
0
 public void paint(Graphics g) {
   Dimension size = getSize();
   int top = VGAP;
   int bottom = size.height - 1 - VGAP;
   int height = bottom - top;
   g.setColor(getBackground());
   for (int i = 0, x = HGAP; i < columns; i++, x += WIDTH + STEP) {
     g.draw3DRect(x, top, WIDTH, height, true);
   }
 }
Exemplo n.º 15
0
  /**
   * Draw the line numbers
   *
   * @param g
   */
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    ((Graphics2D) g)
        .setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    //	Determine the width of the space available to draw the line number

    FontMetrics fontMetrics = component.getFontMetrics(component.getFont());
    Insets insets = getInsets();
    int availableWidth = getSize().width - insets.left - insets.right;

    //  Determine the rows to draw within the clipped bounds.

    Rectangle clip = g.getClipBounds();
    int rowStartOffset = component.viewToModel(new Point(0, clip.y));
    int endOffset = component.viewToModel(new Point(0, clip.y + clip.height));

    while (rowStartOffset <= endOffset) {
      try {
        if (isCurrentLine(rowStartOffset)) g.setColor(getCurrentLineForeground());
        else g.setColor(getForeground());

        //  Get the line number as a string and then determine the
        //  "X" and "Y" offsets for drawing the string.

        String lineNumber = getTextLineNumber(rowStartOffset);
        int stringWidth = fontMetrics.stringWidth(lineNumber);
        int x = getOffsetX(availableWidth, stringWidth) + insets.left;
        int y = getOffsetY(rowStartOffset, fontMetrics);
        g.drawString(lineNumber, x, y);

        //  Move to the next row

        rowStartOffset = Utilities.getRowEnd(component, rowStartOffset) + 1;
      } catch (Exception e) {
        break;
      }
    }
  }
 @Override
 protected void paintComponent(Graphics g) {
   g.setColor(myColor);
   g.fillRect(0, 0, ROOT_INDICATOR_WIDTH - 1, HEIGHT_CELL);
   UIUtil.drawLine(
       (Graphics2D) g,
       ROOT_INDICATOR_WIDTH - 1,
       0,
       ROOT_INDICATOR_WIDTH - 1,
       HEIGHT_CELL,
       null,
       myUi.getColorManager().getRootIndicatorBorder());
 }
Exemplo n.º 17
0
    public void paint(Graphics g) {
      g.setColor(getBackground());
      g.fillRect(0, 0, getWidth(), getHeight());

      for (int i = 0; i < numImages; i++) {
        if (x[i] > 3 * i) {
          nudge(i);
          squish(g, icon[i], xh[i], yh[i], scale[i]);
        } else {
          x[i] += .05;
          y[i] += .05;
        }
      }
    }
Exemplo n.º 18
0
 /**
  * Repaint the drawing panel
  *
  * @param g The Graphics context
  */
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   // Draw the background that will be beside the board
   g.drawImage(background, 0, 0, this);
   for (int row = 0; row < 16; row++) {
     for (int col = 0; col < 16; col++) {
       board[row][col].draw(g);
     }
   }
   int seconds = (time / 10);
   g.setColor(Color.WHITE);
   g.setFont(new Font("Century Gothic", Font.BOLD, 65));
   g.drawString("" + seconds, 1075, 205);
 } // paint component method
Exemplo n.º 19
0
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   int maxWidth = getWidth();
   double hstep = (double) maxWidth / (double) points;
   int maxHeight = getHeight();
   for (int i = 0; i < points; i++)
     pts[i] = (int) (sines[i] * maxHeight / 2 * .95 + maxHeight / 2);
   g.setColor(Color.red);
   for (int i = 1; i < points; i++) {
     int x1 = (int) ((i - 1) * hstep);
     int x2 = (int) (i * hstep);
     int y1 = pts[i - 1];
     int y2 = pts[i];
     g.drawLine(x1, y1, x2, y2);
   }
 }
Exemplo n.º 20
0
 public synchronized void paintIcon(Component c, Graphics g, int x, int y) {
   g.setColor(Color.white);
   g.fillRect(0, 0, c.getWidth(), c.getHeight());
   if (getImageObserver() == null) {
     g.drawImage(
         getImage(),
         c.getWidth() / 2 - getIconWidth() / 2,
         c.getHeight() / 2 - getIconHeight() / 2,
         c);
   } else {
     g.drawImage(
         getImage(),
         c.getWidth() / 2 - getIconWidth() / 2,
         c.getHeight() / 2 - getIconHeight() / 2,
         getImageObserver());
   }
 }
  /** special paint handler for merged cell regions */
  protected void paintSpans(Graphics g, int rowMin, int rowMax, int colMin, int colMax) {
    Rectangle clip = g.getClipBounds();
    Iterator cell = grid.getSpanModel().getSpanIterator();
    while (cell.hasNext()) {
      CellSpan span = (CellSpan) cell.next();
      Rectangle cellBounds = grid.getCellBounds(span.getRow(), span.getColumn());

      // Only paint cell if visible
      if (span.getLastRow() >= rowMin
          && span.getLastColumn() >= colMin
          && span.getFirstRow() <= rowMax
          && span.getFirstColumn() <= colMax) {
        paintCell(g, cellBounds, span.getRow(), span.getColumn());
        // Paint grid line around cell
        if (grid.getShowGrid()) {
          g.setColor(grid.getGridColor());
          g.drawRect(cellBounds.x, cellBounds.y, cellBounds.width, cellBounds.height);
        }
      }
    }
  }
  /**
   * Paints the word-wrapped text.
   *
   * @param g The graphics context in which to paint.
   * @param a The shape (usually a rectangle) in which to paint.
   */
  public void paint(Graphics g, Shape a) {

    Rectangle alloc = (a instanceof Rectangle) ? (Rectangle) a : a.getBounds();
    tabBase = alloc.x;

    Graphics2D g2d = (Graphics2D) g;
    host = (RSyntaxTextArea) getContainer();
    int ascent = host.getMaxAscent();
    int fontHeight = host.getLineHeight();
    FoldManager fm = host.getFoldManager();

    int n = getViewCount(); // Number of lines.
    int x = alloc.x + getLeftInset();
    tempRect.y = alloc.y + getTopInset();
    Rectangle clip = g.getClipBounds();
    for (int i = 0; i < n; i++) {
      tempRect.x = x + getOffset(X_AXIS, i);
      // tempRect.y = y + getOffset(Y_AXIS, i);
      tempRect.width = getSpan(X_AXIS, i);
      tempRect.height = getSpan(Y_AXIS, i);
      // System.err.println("For line " + i + ": tempRect==" + tempRect);
      if (tempRect.intersects(clip)) {
        View view = getView(i);
        drawView(g2d, alloc, view, fontHeight, tempRect.y + ascent);
      }
      tempRect.y += tempRect.height;
      Fold possibleFold = fm.getFoldForLine(i);
      if (possibleFold != null && possibleFold.isCollapsed()) {
        i += possibleFold.getCollapsedLineCount();
        // Visible indicator of collapsed lines
        Color c = RSyntaxUtilities.getFoldedLineBottomColor(host);
        if (c != null) {
          g.setColor(c);
          g.drawLine(x, tempRect.y - 1, alloc.width, tempRect.y - 1);
        }
      }
    }
  }
Exemplo n.º 23
0
 void draw(Graphics g, int px, int py) {
   g.setColor(color);
   g.fillRect(px, py, 10, 10);
 }
Exemplo n.º 24
0
  /**
   * Actually paints the text area. Only lines that have been damaged are repainted.
   *
   * @param g The graphics context with which to paint.
   * @param a The allocated region in which to render.
   */
  @Override
  public void paint(Graphics g, Shape a) {

    RSyntaxDocument document = (RSyntaxDocument) getDocument();

    Rectangle alloc = a.getBounds();

    tabBase = alloc.x;
    host = (RSyntaxTextArea) getContainer();

    Rectangle clip = g.getClipBounds();
    // An attempt to speed things up for files with long lines.  Note that
    // this will actually slow things down a bit for the common case of
    // regular-length lines, but it doesn't make a perceivable difference.
    clipStart = clip.x;
    clipEnd = clipStart + clip.width;

    lineHeight = host.getLineHeight();
    ascent = host.getMaxAscent(); // metrics.getAscent();
    int heightAbove = clip.y - alloc.y;
    int linesAbove = Math.max(0, heightAbove / lineHeight);

    FoldManager fm = host.getFoldManager();
    linesAbove += fm.getHiddenLineCountAbove(linesAbove, true);
    Rectangle lineArea = lineToRect(a, linesAbove);
    int y = lineArea.y + ascent;
    int x = lineArea.x;
    Element map = getElement();
    int lineCount = map.getElementCount();

    // Whether token styles should always be painted, even in selections
    int selStart = host.getSelectionStart();
    int selEnd = host.getSelectionEnd();

    RSyntaxTextAreaHighlighter h = (RSyntaxTextAreaHighlighter) host.getHighlighter();

    Graphics2D g2d = (Graphics2D) g;
    Token token;
    // System.err.println("Painting lines: " + linesAbove + " to " + (endLine-1));

    TokenPainter painter = host.getTokenPainter();
    int line = linesAbove;
    // int count = 0;
    while (y < clip.y + clip.height + ascent && line < lineCount) {

      Fold fold = fm.getFoldForLine(line);
      Element lineElement = map.getElement(line);
      int startOffset = lineElement.getStartOffset();
      // int endOffset = (line==lineCount ? lineElement.getEndOffset()-1 :
      //							lineElement.getEndOffset()-1);
      int endOffset = lineElement.getEndOffset() - 1; // Why always "-1"?
      h.paintLayeredHighlights(g2d, startOffset, endOffset, a, host, this);

      // Paint a line of text.
      token = document.getTokenListForLine(line);
      if (selStart == selEnd || startOffset >= selEnd || endOffset < selStart) {
        drawLine(painter, token, g2d, x, y, line);
      } else {
        // System.out.println("Drawing line with selection: " + line);
        drawLineWithSelection(painter, token, g2d, x, y, selStart, selEnd);
      }

      if (fold != null && fold.isCollapsed()) {

        // Visible indicator of collapsed lines
        Color c = RSyntaxUtilities.getFoldedLineBottomColor(host);
        if (c != null) {
          g.setColor(c);
          g.drawLine(x, y + lineHeight - ascent - 1, host.getWidth(), y + lineHeight - ascent - 1);
        }

        // Skip to next line to paint, taking extra care for lines with
        // block ends and begins together, e.g. "} else {"
        do {
          int hiddenLineCount = fold.getLineCount();
          if (hiddenLineCount == 0) {
            // Fold parser identified a zero-line fold region.
            // This is really a bug, but we'll be graceful here
            // and avoid an infinite loop.
            break;
          }
          line += hiddenLineCount;
          fold = fm.getFoldForLine(line);
        } while (fold != null && fold.isCollapsed());
      }

      y += lineHeight;
      line++;
      // count++;

    }

    // System.out.println("SyntaxView: lines painted=" + count);

  }
Exemplo n.º 25
0
  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());
    }
  }
Exemplo n.º 26
0
  @Override
  public void paintComponent(Graphics screen) {
    // this data is shared by all EditorToolbar instances
    if (buttonImages == null) {
      loadButtons();
    }

    // this happens once per instance of EditorToolbar
    if (stateImage == null) {
      state = new int[buttonCount];
      stateImage = new Image[buttonCount];
      for (int i = 0; i < buttonCount; i++) {
        setState(i, INACTIVE, false);
      }
      y1 = 0;
      y2 = BUTTON_HEIGHT;
      x1 = new int[buttonCount];
      x2 = new int[buttonCount];
    }

    Dimension size = getSize();
    if ((offscreen == null) ||
        (size.width != width) || (size.height != height)) {
      offscreen = createImage(size.width, size.height);
      width = size.width;
      height = size.height;

      int offsetX = 3;
      for (int i = 0; i < buttonCount; i++) {
        x1[i] = offsetX;
        if (i == 2 || i == 6) x1[i] += BUTTON_GAP;
        x2[i] = x1[i] + BUTTON_WIDTH;
        offsetX = x2[i];
      }
      
      // Serial button must be on the right
      x1[SERIAL] = width - BUTTON_WIDTH - 14;
      x2[SERIAL] = width - 14;
    }
    Graphics g = offscreen.getGraphics();
    g.setColor(bgcolor); //getBackground());
    g.fillRect(0, 0, width, height);

    for (int i = 0; i < buttonCount; i++) {
      g.drawImage(stateImage[i], x1[i], y1, null);
    }

    g.setColor(statusColor);
    g.setFont(statusFont);

    /*
    // if i ever find the guy who wrote the java2d api, i will hurt him.
     * 
     * whereas I love the Java2D API. --jdf. lol.
     * 
    Graphics2D g2 = (Graphics2D) g;
    FontRenderContext frc = g2.getFontRenderContext();
    float statusW = (float) statusFont.getStringBounds(status, frc).getWidth();
    float statusX = (getSize().width - statusW) / 2;
    g2.drawString(status, statusX, statusY);
    */
    if (currentRollover != -1) {
      int statusY = (BUTTON_HEIGHT + g.getFontMetrics().getAscent()) / 2;
      String status = shiftPressed ? titleShift[currentRollover] : (controlPressed ? titleControl[currentRollover] : title[currentRollover]);
           
      if (currentRollover != SERIAL)
        g.drawString(status, (buttonCount-1) * BUTTON_WIDTH + 3 * BUTTON_GAP, statusY);
      else {
      	// Pending
		if(editor.serialMonitor.isOpenPending!=null)
			if(editor.serialMonitor.isOpenPending)
				status += " (Monitor will open after upload)";
  		
        int statusX = x1[SERIAL] - BUTTON_GAP;
        statusX -= g.getFontMetrics().stringWidth(status);
        g.drawString(status, statusX, statusY);
      }
    }

    screen.drawImage(offscreen, 0, 0, null);
    
    if (!isEnabled()) {
      screen.setColor(new Color(0,0,0,100));
      screen.fillRect(0, 0, getWidth(), getHeight());
  	}
  }
Exemplo n.º 27
0
 /**
  * Paint a rectangle point
  *
  * @param g Graphics to use for painting
  * @param c DisplayCanvas to paint on
  */
 private void paintRectPoint(Graphics g, DisplayCanvas c) {
   Rectangle nb = transformOutput(c, getBounds());
   g.setColor(Color.red);
   Point2D rp = getPointOnRect(rectPoint, nb);
   g.fillRect((int) rp.getX() - 3, (int) rp.getY() - 3, 6, 6);
 }
Exemplo n.º 28
0
  public void paintComponent(Graphics g) {
    // clear(g);
    Graphics2D g2d = (Graphics2D) g;

    RenderingHints rh =
        new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2d.setRenderingHints(rh);

    g.setColor(new Color(0, 0, 0));
    g.fillRect(0, 0, getWidth(), getHeight());

    // draw the connectors
    for (int i = 1; i < connections.length; i++) {

      NetworkButton b1 = this.nodeList.get(connections[i][0]);
      NetworkButton b2 = this.nodeList.get(connections[i][1]);

      g2d.setStroke(new BasicStroke(2));

      // grey line
      g2d.setPaint(new Color(50, 50, 50));
      g2d.drawLine(
          b1.x + b1.width / 2, b1.y + b1.height / 2, b2.x + b2.width / 2, b2.y + b2.height / 2);

      g2d.setStroke(new BasicStroke(1));

      // b1 line
      g2d.setPaint(b1.baseColor);
      g2d.drawLine(
          b1.x + b1.width / 2 - 2,
          b1.y - 2 + b1.height / 2,
          b2.x - 2 + b2.width / 2,
          b2.y - 2 + b2.height / 2);
      // b2 line
      g2d.setPaint(b2.baseColor);
      g2d.drawLine(
          b1.x + 2 + b1.width / 2,
          b1.y + 2 + b1.height / 2,
          b2.x + 2 + b2.width / 2,
          b2.y + 2 + b2.height / 2);

      // draw crosshairs around current

      String currentNode = mapPanel.networkPanel.getName();

      NetworkButton current = this.nodeList.get(currentNode);
      int x = current.x;
      int y = current.y;
      int height = current.height;
      int width = current.width;
      int l = (int) (height * 0.2);
      g2d.setStroke(new BasicStroke(6));
      g2d.setPaint(new Color(200, 200, 200));
      g2d.drawLine((int) (x + width * 0.5), y, (int) (x + width * 0.5), y - l);
      g2d.drawLine(x, (int) (y + height * 0.5), x - l, (int) (y + height * 0.5));
      g2d.drawLine((int) (x + width * 0.5), y + height, (int) (x + width * 0.5), y + height + l);
      g2d.drawLine(x + width, (int) (y + height * 0.5), x + width + l, (int) (y + height * 0.5));

      g2d.setStroke(new BasicStroke(4));
      g2d.setPaint(current.baseColor);
      g2d.drawLine((int) (x + width * 0.5), y, (int) (x + width * 0.5), y - l);
      g2d.drawLine(x, (int) (y + height * 0.5), x - l, (int) (y + height * 0.5));
      g2d.drawLine((int) (x + width * 0.5), y + height, (int) (x + width * 0.5), y + height + l);
      g2d.drawLine(x + width, (int) (y + height * 0.5), x + width + l, (int) (y + height * 0.5));
    }
  }
Exemplo n.º 29
0
  public void paintComponent(Graphics screen) {
    if (inactive == null) {
      inactive = new Image[BUTTON_COUNT];
      rollover = new Image[BUTTON_COUNT];
      active = new Image[BUTTON_COUNT];

      int IMAGE_SIZE = 33;

      for (int i = 0; i < BUTTON_COUNT; i++) {
        inactive[i] = createImage(BUTTON_WIDTH, BUTTON_HEIGHT);
        Graphics g = inactive[i].getGraphics();
        g.drawImage(buttons, -(i * IMAGE_SIZE) - 3, -2 * IMAGE_SIZE, null);

        rollover[i] = createImage(BUTTON_WIDTH, BUTTON_HEIGHT);
        g = rollover[i].getGraphics();
        g.drawImage(buttons, -(i * IMAGE_SIZE) - 3, -1 * IMAGE_SIZE, null);

        active[i] = createImage(BUTTON_WIDTH, BUTTON_HEIGHT);
        g = active[i].getGraphics();
        g.drawImage(buttons, -(i * IMAGE_SIZE) - 3, -0 * IMAGE_SIZE, null);
      }

      state = new int[buttonCount];
      stateImage = new Image[buttonCount];
      for (int i = 0; i < buttonCount; i++) {
        setState(i, INACTIVE, false);
      }
    }
    Dimension size = getSize();
    if ((offscreen == null) || (size.width != width) || (size.height != height)) {
      offscreen = createImage(size.width, size.height);
      width = size.width;
      height = size.height;

      y1 = 0;
      y2 = BUTTON_HEIGHT;

      x1 = new int[buttonCount];
      x2 = new int[buttonCount];

      int offsetX = 3;
      for (int i = 0; i < buttonCount; i++) {
        x1[i] = offsetX;
        if (i == 2) x1[i] += BUTTON_GAP;
        x2[i] = x1[i] + BUTTON_WIDTH;
        offsetX = x2[i];
      }
    }
    Graphics g = offscreen.getGraphics();
    g.setColor(bgcolor); // getBackground());
    g.fillRect(0, 0, width, height);

    for (int i = 0; i < buttonCount; i++) {
      g.drawImage(stateImage[i], x1[i], y1, null);
    }

    g.setColor(statusColor);
    g.setFont(statusFont);

    /*
    // if i ever find the guy who wrote the java2d api, i will hurt him.
    Graphics2D g2 = (Graphics2D) g;
    FontRenderContext frc = g2.getFontRenderContext();
    float statusW = (float) statusFont.getStringBounds(status, frc).getWidth();
    float statusX = (getSize().width - statusW) / 2;
    g2.drawString(status, statusX, statusY);
    */
    // int statusY = (BUTTON_HEIGHT + statusFont.getAscent()) / 2;
    int statusY = (BUTTON_HEIGHT + g.getFontMetrics().getAscent()) / 2;
    g.drawString(status, buttonCount * BUTTON_WIDTH + 2 * BUTTON_GAP, statusY);

    screen.drawImage(offscreen, 0, 0, null);
  }
    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));
    }