示例#1
0
    private void paintToImage(
        final BufferedImage img, final int x, final int y, final int width, final int height) {
      // clear the prior image
      Graphics2D imgG = (Graphics2D) img.getGraphics();
      imgG.setComposite(AlphaComposite.Clear);
      imgG.setColor(Color.black);
      imgG.fillRect(0, 0, width + blur * 2, height + blur * 2);

      final int adjX = (int) (x + blur + offsetX + (insets.left * distance));
      final int adjY = (int) (y + blur + offsetY + (insets.top * distance));
      final int adjW = (int) (width - (insets.left + insets.right) * distance);
      final int adjH = (int) (height - (insets.top + insets.bottom) * distance);

      // let the delegate paint whatever they want to be blurred
      imgG.setComposite(AlphaComposite.DstAtop);
      if (prePainter != null) prePainter.paint(imgG, adjX, adjY, adjW, adjH);
      imgG.dispose();

      // blur the prior image back into the same pixels
      imgG = (Graphics2D) img.getGraphics();
      imgG.setComposite(AlphaComposite.DstAtop);
      imgG.setRenderingHint(
          RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
      imgG.setRenderingHint(
          RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
      imgG.drawImage(img, blurOp, 0, 0);

      if (postPainter != null) postPainter.paint(imgG, adjX, adjY, adjW, adjH);
      imgG.dispose();
    }
  @Override
  public void paint(Graphics g) {
    float width = getWidth();
    float height = getHeight();

    Graphics2D g2 = (Graphics2D) g;

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

    g2.setColor(Color.black);
    g2.fill(new Rectangle2D.Float(0, 0, width, height));

    g2.setFont(getFont().deriveFont(FONT_SIZE));
    g2.setColor(Color.green);
    FontMetrics fm = g2.getFontMetrics();
    g2.drawString("Input", width / 4f - fm.stringWidth("Input") / 2f, 30);
    g2.setColor(Color.red);
    g2.drawString("Output", width - width / 4f - fm.stringWidth("Output") / 2f, 30);

    g2.setFont(getFont().deriveFont(FONT_SIZE / 2));
    fm = g2.getFontMetrics();
    g2.setColor(new Color(0, 255, 0));
    g2.drawString("response", width / 4f - fm.stringWidth("response") / 2f, 48);
    g2.setColor(new Color(0, 255, 255));
    g2.drawString("request", width / 4f - fm.stringWidth("request") / 2f, 60);

    g2.setColor(new Color(255, 0, 0));
    g2.drawString("request", width - width / 4f - fm.stringWidth("request") / 2f, 48);
    g2.setColor(new Color(255, 0, 255));
    g2.drawString("response", width - width / 4f - fm.stringWidth("response") / 2f, 60);

    synchronized (lock) {
      painter.paint(this, g2);
    }
  }
示例#3
0
  /** {@inheritDoc} */
  @Override
  protected void doPaint(Graphics2D g, T component, int width, int height) {
    for (Painter<T> p : getPainters()) {
      Graphics2D temp = (Graphics2D) g.create();

      try {
        p.paint(temp, component, width, height);
        if (isClipPreserved()) {
          g.setClip(temp.getClip());
        }
      } finally {
        temp.dispose();
      }
    }
  }
示例#4
0
  /** Override the paint method to do custom painting. */
  public synchronized void paint(Graphics g) {

    // Draw the background
    if (image != null) {
      int x = (getWidth() - image.getWidth()) / 2;
      int y = (getHeight() - image.getHeight()) / 2;
      g.drawImage(image, x, y, this);
    }

    // Paint any other painters
    for (Painter p : painters) {
      // System.out.println(p);
      p.paint(g);
    }
  }
示例#5
0
 @Override
 public void paint(Graphics g, JComponent c) {
   Gripper gripper = (Gripper) c;
   paintBackground(g, gripper);
   int state = gripper.isSelected() ? ThemePainter.STATE_SELECTED : ThemePainter.STATE_DEFAULT;
   if (_gripperPainter == null) {
     getPainter()
         .paintGripper(
             c,
             g,
             new Rectangle(0, 0, c.getWidth(), c.getHeight()),
             gripper.getOrientation(),
             state);
   } else {
     _gripperPainter.paint(
         c, g, new Rectangle(0, 0, c.getWidth(), c.getHeight()), gripper.getOrientation(), state);
   }
 }
示例#6
0
 protected void paintChild(Graphics2D g2, Component child) {
   Painter painter = PainterFactory.getPainter(child.getClass());
   painter.paint(g2, child);
 }
示例#7
0
  /**
   * This method will only throw exceptions if some aspect of the test's internal operation fails.
   */
  public TestReport runImpl() throws Exception {
    DefaultTestReport report = new DefaultTestReport(this);

    SVGGraphics2D g2d = buildSVGGraphics2D();
    g2d.setSVGCanvasSize(CANVAS_SIZE);

    //
    // Generate SVG content
    //
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    OutputStreamWriter osw = new OutputStreamWriter(bos, "UTF-8");
    try {
      painter.paint(g2d);
      configureSVGGraphics2D(g2d);
      g2d.stream(osw);
      osw.flush();
      bos.flush();
      bos.close();
    } catch (Exception e) {
      StringWriter trace = new StringWriter();
      e.printStackTrace(new PrintWriter(trace));
      report.setErrorCode(ERROR_CANNOT_GENERATE_SVG);
      report.setDescription(
          new TestReport.Entry[] {
            new TestReport.Entry(
                Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
                Messages.formatMessage(
                    ERROR_CANNOT_GENERATE_SVG,
                    new String[] {
                      painter == null ? "null" : painter.getClass().getName(),
                      e.getClass().getName(),
                      e.getMessage(),
                      trace.toString()
                    }))
          });
      report.setPassed(false);
      return report;
    }

    //
    // Compare with reference SVG
    //
    InputStream refStream = null;
    try {
      refStream = new BufferedInputStream(refURL.openStream());
    } catch (Exception e) {
      report.setErrorCode(ERROR_CANNOT_OPEN_REFERENCE_SVG_FILE);
      report.setDescription(
          new TestReport.Entry[] {
            new TestReport.Entry(
                Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
                Messages.formatMessage(
                    ERROR_CANNOT_OPEN_REFERENCE_SVG_FILE,
                    new Object[] {
                      refURL != null ? refURL.toExternalForm() : "null", e.getMessage()
                    }))
          });
      report.setPassed(false);
      save(bos.toByteArray());
      return report;
    }

    InputStream newStream = new ByteArrayInputStream(bos.toByteArray());

    boolean accurate = true;
    String refLine = null;
    String newLine = null;
    int ln = 1;

    try {
      // accurate = compare(refStream, newStream);
      BufferedReader refReader = new BufferedReader(new InputStreamReader(refStream));
      BufferedReader newReader = new BufferedReader(new InputStreamReader(newStream));
      while ((refLine = refReader.readLine()) != null) {
        newLine = newReader.readLine();
        if (newLine == null || !refLine.equals(newLine)) {
          accurate = false;
          break;
        }
        ln++;
      }

      if (accurate) {
        // need to make sure newLine is null as well
        newLine = newReader.readLine();
        if (newLine != null) {
          accurate = false;
        }
      }

    } catch (IOException e) {
      report.setErrorCode(ERROR_ERROR_WHILE_COMPARING_FILES);
      report.setDescription(
          new TestReport.Entry[] {
            new TestReport.Entry(
                Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
                Messages.formatMessage(
                    ERROR_ERROR_WHILE_COMPARING_FILES,
                    new Object[] {refURL.toExternalForm(), e.getMessage()}))
          });
      report.setPassed(false);
      save(bos.toByteArray());
      return report;
    }

    if (!accurate) {
      save(bos.toByteArray());
      int cn = computeColumnNumber(refLine, newLine);
      String expectedChar = "eol";
      if (cn >= 0 && refLine != null && refLine.length() > cn) {
        expectedChar = (new Character(refLine.charAt(cn))).toString();
      }
      String foundChar = "null";
      if (cn >= 0 && newLine != null && newLine.length() > cn) {
        foundChar = (new Character(newLine.charAt(cn))).toString();
      }

      if (expectedChar.equals(" ")) {
        expectedChar = "' '";
      }
      if (foundChar.equals(" ")) {
        foundChar = "' '";
      }

      report.setErrorCode(ERROR_GENERATED_SVG_INACCURATE);
      report.addDescriptionEntry(
          Messages.formatMessage(ENTRY_KEY_LINE_NUMBER, null), new Integer(ln));
      report.addDescriptionEntry(
          Messages.formatMessage(ENTRY_KEY_COLUMN_NUMBER, null), new Integer(cn));
      report.addDescriptionEntry(
          Messages.formatMessage(ENTRY_KEY_COLUMN_EXPECTED_VALUE, null), expectedChar);
      report.addDescriptionEntry(
          Messages.formatMessage(ENTRY_KEY_COLUMN_FOUND_VALUE, null), foundChar);
      report.addDescriptionEntry(Messages.formatMessage(ENTRY_KEY_REFERENCE_LINE, null), refLine);
      report.addDescriptionEntry(Messages.formatMessage(ENTRY_KEY_NEW_LINE, null), newLine);
      report.setPassed(false);
    } else {
      report.setPassed(true);
    }

    return report;
  }