Esempio n. 1
0
  /**
   * Gibt den Platzbedarf aller Felder als Dimension zurueck.
   *
   * @param width int
   * @param height int
   * @param maxX int
   * @param maxY int
   * @return int[]
   * @see FieldFormat#getField(int, int, double, double, boolean, int, int, int, int, boolean)
   */
  public int[] getBoardsize(final int width, final int height, final int maxX, final int maxY) {

    double maxWidth = 0.0D;
    double maxHeight = 0.0D;
    GeneralPath poly;
    for (int j = 0; j < maxY; j++) {
      for (int i = 0; i < maxX; i++) {
        poly = getPolygon(width, height, true, i, j, maxX, maxY, true);
        maxWidth = Math.max(maxWidth, poly.getBounds().getMaxX());
        maxHeight = Math.max(maxHeight, poly.getBounds().getMaxY());
      }
    }

    return new int[] {(int) Math.rint(maxWidth) + 1, (int) Math.rint(maxHeight) + 1};
  }
Esempio n. 2
0
  public void setLocation(GeneralPath gp) {
    if (gp != null) {
      Rectangle rect = gp.getBounds();

      double x = rect.getX();
      double y = rect.getY();

      if (anchor == ANCHOR_TOP || anchor == ANCHOR_CENTER || anchor == ANCHOR_BOTTOM) {
        x += rect.getWidth() / 2;
      } else if (anchor == ANCHOR_TOPRIGHT
          || anchor == ANCHOR_RIGHT
          || anchor == ANCHOR_BOTTOMRIGHT) {
        x += rect.getWidth();
      }

      if (anchor == ANCHOR_LEFT || anchor == ANCHOR_CENTER || anchor == ANCHOR_RIGHT) {
        y += rect.getHeight() / 2;
      } else if (anchor == ANCHOR_BOTTOMLEFT
          || anchor == ANCHOR_BOTTOM
          || anchor == ANCHOR_BOTTOMRIGHT) {
        y += rect.getHeight();
      }

      setLocation(new Point((int) x, (int) y));
    }
  }
Esempio n. 3
0
 private void scrollToCenterPath(final GeneralPath geoBoundaryPath, final JViewport viewport) {
   final GeneralPath pixelPath =
       ProductUtils.convertToPixelPath(geoBoundaryPath, wmPainter.getGeoCoding());
   final Rectangle viewRect = viewport.getViewRect();
   final Rectangle pathBounds = pixelPath.getBounds();
   setCenter(viewRect, new Point((int) pathBounds.getCenterX(), (int) pathBounds.getCenterY()));
   final Dimension bounds =
       new Dimension(scaledImage.getWidth(null), scaledImage.getHeight(null));
   ensureRectIsInBounds(viewRect, bounds);
   viewport.scrollRectToVisible(viewRect);
 }
  public void createTextMarkupAnnotation(ArrayList<Shape> highlightBounds) {
    // mke sure we don't create a highlight annotation for every word in the
    // document when first selecting the tool for highlighted next. .
    if (documentViewModel.isSelectAll()) {
      documentViewController.clearSelectedText();
    }

    // get the geometric path of the selected text
    if (highlightBounds == null) {
      highlightBounds = getSelectedTextBounds();
    }
    // grab the selected text
    String contents = enableHighlightContents && highlightBounds != null ? getSelectedText() : "";

    // clear the selected text
    documentViewController.clearSelectedText();

    if (highlightBounds != null) {

      // bound of the selected text
      GeneralPath highlightPath = new GeneralPath();
      for (Shape bounds : highlightBounds) {
        highlightPath.append(bounds, false);
      }
      // get the bounds before convert to page space
      Rectangle bounds = highlightPath.getBounds();

      Rectangle tBbox = convertToPageSpace(highlightBounds, highlightPath);

      // create annotations types that that are rectangle based;
      // which is actually just link annotations
      TextMarkupAnnotation annotation =
          (TextMarkupAnnotation)
              AnnotationFactory.buildAnnotation(
                  documentViewModel.getDocument().getPageTree().getLibrary(), highLightType, tBbox);

      // pass outline shapes and bounds to create the highlight shapes
      if (TextMarkupAnnotation.SUBTYPE_HIGHLIGHT.equals(highLightType)) {
        annotation.setOpacity(TextMarkupAnnotation.HIGHLIGHT_ALPHA);
      }
      annotation.setContents(
          contents != null && enableHighlightContents ? contents : highLightType.toString());
      annotation.setColor(annotation.getTextMarkupColor());
      annotation.setCreationDate(PDate.formatDateTime(new Date()));
      annotation.setTitleText(System.getProperty("user.name"));
      annotation.setMarkupBounds(highlightBounds);
      annotation.setMarkupPath(highlightPath);
      annotation.setBBox(tBbox);
      // finalized the appearance properties.
      annotation.resetAppearanceStream(getPageTransform());

      // create new annotation given the general path
      AbstractAnnotationComponent comp =
          AnnotationComponentFactory.buildAnnotationComponent(
              annotation, documentViewController, pageViewComponent, documentViewModel);

      // convert to user rect to page space along with the bounds.
      comp.setBounds(bounds);
      comp.refreshAnnotationRect();

      // create component and add it to the page.
      // add them to the container, using absolute positioning.
      if (documentViewController.getAnnotationCallback() != null) {
        AnnotationCallback annotationCallback = documentViewController.getAnnotationCallback();
        annotationCallback.newAnnotation(pageViewComponent, comp);
      }
    }
    pageViewComponent.repaint();
  }
Esempio n. 5
0
  public void run() {
    Thread me = Thread.currentThread();
    while (getSize().width <= 0) {
      try {
        anim.sleep(500);
      } catch (InterruptedException e) {
        return;
      }
    }

    Graphics2D g2d = null;
    Graphics2D BufferG2D = null;
    Graphics2D ScreenG2D = null;
    BasicStroke solid = new BasicStroke(9.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 9.0f);
    GeneralPath gp = new GeneralPath(GeneralPath.WIND_NON_ZERO);
    int rule = AlphaComposite.SRC_OVER;
    AlphaComposite opaque = AlphaComposite.SrcOver;
    AlphaComposite blend = AlphaComposite.getInstance(rule, 0.9f);
    AlphaComposite set = AlphaComposite.Src;
    int frame = 0;
    int frametmp = 0;
    Dimension oldSize = getSize();
    Shape clippath = null;
    while (anim == me) {
      Dimension size = getSize();
      if (size.width != oldSize.width || size.height != oldSize.height) {
        img = null;
        clippath = null;
        if (BufferG2D != null) {
          BufferG2D.dispose();
          BufferG2D = null;
        }
        if (ScreenG2D != null) {
          ScreenG2D.dispose();
          ScreenG2D = null;
        }
      }
      oldSize = size;

      if (img == null) {
        img = (BufferedImage) createImage(size.width, size.height);
      }

      if (BufferG2D == null) {
        BufferG2D = img.createGraphics();
        BufferG2D.setRenderingHint(
            RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_DEFAULT);
        BufferG2D.setClip(clippath);
      }
      g2d = BufferG2D;

      float[] ctrlpts;
      for (int i = 0; i < animpts.length; i += 2) {
        animate(animpts, deltas, i + 0, size.width);
        animate(animpts, deltas, i + 1, size.height);
      }
      ctrlpts = animpts;
      int len = ctrlpts.length;
      gp.reset();
      int dir = 0;
      float prevx = ctrlpts[len - 2];
      float prevy = ctrlpts[len - 1];
      float curx = ctrlpts[0];
      float cury = ctrlpts[1];
      float midx = (curx + prevx) / 2.0f;
      float midy = (cury + prevy) / 2.0f;
      gp.moveTo(midx, midy);
      for (int i = 2; i <= ctrlpts.length; i += 2) {
        float x1 = (midx + curx) / 2.0f;
        float y1 = (midy + cury) / 2.0f;
        prevx = curx;
        prevy = cury;
        if (i < ctrlpts.length) {
          curx = ctrlpts[i + 0];
          cury = ctrlpts[i + 1];
        } else {
          curx = ctrlpts[0];
          cury = ctrlpts[1];
        }
        midx = (curx + prevx) / 2.0f;
        midy = (cury + prevy) / 2.0f;
        float x2 = (prevx + midx) / 2.0f;
        float y2 = (prevy + midy) / 2.0f;
        gp.curveTo(x1, y1, x2, y2, midx, midy);
      }
      gp.closePath();

      g2d.setComposite(set);
      g2d.setBackground(backgroundColor);
      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);

      if (bgChanged || bounds == null) {
        bounds = new Rectangle(0, 0, getWidth(), getHeight());
        bgChanged = false;
      }
      // g2d.clearRect(bounds.x-5, bounds.y-5, bounds.x + bounds.width + 5, bounds.y + bounds.height
      // + 5);
      g2d.clearRect(0, 0, getWidth(), getHeight());

      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g2d.setColor(outerColor);
      g2d.setComposite(opaque);
      g2d.setStroke(solid);
      g2d.draw(gp);
      g2d.setPaint(gradient);

      if (!bgChanged) {
        bounds = gp.getBounds();
      } else {
        bounds = new Rectangle(0, 0, getWidth(), getHeight());
        bgChanged = false;
      }
      gradient =
          new GradientPaint(
              bounds.x,
              bounds.y,
              gradientColorA,
              bounds.x + bounds.width,
              bounds.y + bounds.height,
              gradientColorB,
              true);
      g2d.setComposite(blend);
      g2d.fill(gp);

      if (g2d == BufferG2D) {
        repaint();
      }
      ++frame;
      Thread.yield();
    }
    if (g2d != null) {
      g2d.dispose();
    }
  }