protected void updateHoverHandles(@Nullable DrawingView view, @Nullable Figure f) {
   if (f != hoverFigure) {
     Rectangle r = null;
     if (hoverFigure != null && hoverFigure.isSelectable()) {
       for (Handle h : hoverHandles) {
         if (r == null) {
           r = h.getDrawingArea();
         } else {
           r.add(h.getDrawingArea());
         }
         h.setView(null);
         h.dispose();
       }
       hoverHandles.clear();
     }
     hoverFigure = f;
     if (hoverFigure != null) {
       hoverHandles.addAll(hoverFigure.createHandles(-1));
       for (Handle h : hoverHandles) {
         h.setView(view);
         if (r == null) {
           r = h.getDrawingArea();
         } else {
           r.add(h.getDrawingArea());
         }
       }
     }
     if (r != null) {
       r.grow(1, 1);
       fireAreaInvalidated(r);
     }
   }
 }
예제 #2
0
 private void minimizeSplitBounds(Split split, Rectangle bounds) {
   Rectangle splitBounds = new Rectangle(bounds.x, bounds.y, 0, 0);
   List<Node> splitChildren = split.getChildren();
   Node lastChild = splitChildren.get(splitChildren.size() - 1);
   Rectangle lastChildBounds = lastChild.getBounds();
   if (split.isRowLayout()) {
     int lastChildMaxX = lastChildBounds.x + lastChildBounds.width;
     splitBounds.add(lastChildMaxX, bounds.y + bounds.height);
   } else {
     int lastChildMaxY = lastChildBounds.y + lastChildBounds.height;
     splitBounds.add(bounds.x + bounds.width, lastChildMaxY);
   }
   split.setBounds(splitBounds);
 }
  /** The mouse was dragged - either draw a marquee or move some classes. */
  public void mouseDragged(MouseEvent evt) {
    if (isButtonOne(evt)) {
      if (marquee.isActive()) {
        Rectangle oldRect = marquee.getRectangle();
        marquee.move(evt.getX(), evt.getY());
        Rectangle newRect = (Rectangle) marquee.getRectangle().clone();
        if (oldRect != null) {
          newRect.add(oldRect);
        }
        newRect.width++;
        newRect.height++;
        graphEditor.repaint(newRect);
      } else if (rubberBand != null) {
        rubberBand.setEnd(evt.getX(), evt.getY());
        graphEditor.repaint();
      } else {
        if (!selection.isEmpty()) {
          int deltaX = snapToGrid(evt.getX() - dragStartX);
          int deltaY = snapToGrid(evt.getY() - dragStartY);

          if (resizing) {
            selection.resize(deltaX, deltaY);
          } else if (moving) {
            selection.move(deltaX, deltaY);
          }
        }
        graphEditor.repaint();
      }
    }
  }
예제 #4
0
  /**
   * Creates a diff of the two layers, <code>ml</code> is considered the significant difference.
   *
   * @param ml
   * @return A new MapLayer that represents the difference between this layer, and the argument, or
   *     <b>null</b> if no difference exists.
   */
  @Override
  public MapLayer createDiff(MapLayer ml) {
    if (ml == null) {
      return null;
    }

    if (ml instanceof TileLayer) {
      Rectangle r = null;

      for (int y = bounds.y; y < bounds.height + bounds.y; y++) {
        for (int x = bounds.x; x < bounds.width + bounds.x; x++) {
          if (((TileLayer) ml).getTileAt(x, y) != getTileAt(x, y)) {
            if (r != null) {
              r.add(x, y);
            } else {
              r = new Rectangle(new Point(x, y));
            }
          }
        }
      }

      if (r != null) {
        MapLayer diff = new TileLayer(new Rectangle(r.x, r.y, r.width + 1, r.height + 1));
        diff.copyFrom(ml);
        return diff;
      } else {
        return new TileLayer();
      }
    } else {
      return null;
    }
  }
예제 #5
0
  /**
   * See TextObject's getLocalBoundingPolygon() description for details.
   *
   * <p>Do not modify the returned Polygon, because it may be cached.
   *
   * <p>XXXBUG: This method always returns a rectangle unless we write some convex hull
   * calculations.
   *
   * @return A bounding polygon; the polygon could be empty if the group has no glyph descendants.
   * @see net.nexttext.TextObject#getLocalBoundingPolygon()
   */
  public synchronized Polygon getLocalBoundingPolygon() {

    if (localBoundingPolygonValidToFrame >= getFrameCount()) {
      return localBoundingPolygon;
    }
    localBoundingPolygonValidToFrame = Long.MAX_VALUE;

    TextObject to = getLeftMostChild();

    // if to has no children and is a group, then return an empty polygon
    if (to == null) {
      localBoundingPolygon = new Polygon();
      return localBoundingPolygon;
    }

    Rectangle bounds = to.getRelativeBoundingPolygon().getBounds();

    while ((to = to.getRightSibling()) != null) {
      bounds.add(to.getRelativeBoundingPolygon().getBounds());
    }

    // Return the box as a polygon object

    int[] x = new int[] {bounds.x, bounds.x + bounds.width, bounds.x + bounds.width, bounds.x};
    int[] y = new int[] {bounds.y, bounds.y, bounds.y + bounds.height, bounds.y + bounds.height};

    localBoundingPolygon = new Polygon(x, y, 4);
    return localBoundingPolygon;
  }
  private void renderGridCoverage(
      Graphics2D graphics,
      Envelope bounds,
      Dimension dimension,
      ReferencedEnvelope requestBBox,
      BufferedImage image)
      throws Exception {
    CoordinateReferenceSystem destinationCRS = getContext().getCRS();

    Envelope envelope = bounds;
    if (envelope == null || envelope.isNull()) {
      // get the bounds from the context
      envelope = getContext().getImageBounds();
    }
    Point upperLeft =
        getContext().worldToPixel(new Coordinate(envelope.getMinX(), envelope.getMinY()));
    Point bottomRight =
        getContext().worldToPixel(new Coordinate(envelope.getMaxX(), envelope.getMaxY()));
    Rectangle screenSize = new Rectangle(upperLeft);
    screenSize.add(bottomRight);

    GridCoverage2D coverage = convertImageToGridCoverage(requestBBox, image);

    AffineTransform worldToScreen =
        RendererUtilities.worldToScreenTransform(envelope, screenSize, destinationCRS);
    GridCoverageRenderer paint =
        new GridCoverageRenderer(destinationCRS, envelope, screenSize, worldToScreen);

    RasterSymbolizer symbolizer =
        CommonFactoryFinder.getStyleFactory(null).createRasterSymbolizer();

    paint.paint(graphics, coverage, symbolizer);
  }
예제 #7
0
 /**
  * Provides a mapping, for a given region, from the document model coordinate space to the view
  * coordinate space. The specified region is created as a union of the first and last character
  * positions.
  *
  * @param p0 the position of the first character (>=0)
  * @param b0 the bias of the first character position, toward the previous character or the next
  *     character represented by the offset, in case the position is a boundary of two views;
  *     <code>b0</code> will have one of these values:
  *     <ul>
  *       <li><code>Position.Bias.Forward</code>
  *       <li><code>Position.Bias.Backward</code>
  *     </ul>
  *
  * @param p1 the position of the last character (>=0)
  * @param b1 the bias for the second character position, defined one of the legal values shown
  *     above
  * @param a the area of the view, which encompasses the requested region
  * @return the bounding box which is a union of the region specified by the first and last
  *     character positions
  * @exception BadLocationException if the given position does not represent a valid location in
  *     the associated document
  * @exception IllegalArgumentException if <code>b0</code> or <code>b1</code> are not one of the
  *     legal <code>Position.Bias</code> values listed above
  * @see View#viewToModel
  */
 public Shape modelToView(int p0, Position.Bias b0, int p1, Position.Bias b1, Shape a)
     throws BadLocationException {
   Shape s0 = modelToView(p0, a, b0);
   Shape s1;
   if (p1 == getEndOffset()) {
     try {
       s1 = modelToView(p1, a, b1);
     } catch (BadLocationException ble) {
       s1 = null;
     }
     if (s1 == null) {
       // Assume extends left to right.
       Rectangle alloc = (a instanceof Rectangle) ? (Rectangle) a : a.getBounds();
       s1 = new Rectangle(alloc.x + alloc.width - 1, alloc.y, 1, alloc.height);
     }
   } else {
     s1 = modelToView(p1, a, b1);
   }
   Rectangle r0 = s0.getBounds();
   Rectangle r1 = (s1 instanceof Rectangle) ? (Rectangle) s1 : s1.getBounds();
   if (r0.y != r1.y) {
     // If it spans lines, force it to be the width of the view.
     Rectangle alloc = (a instanceof Rectangle) ? (Rectangle) a : a.getBounds();
     r0.x = alloc.x;
     r0.width = alloc.width;
   }
   r0.add(r1);
   return r0;
 }
  /**
   * Sets the index of the current animation frame to the specified value and requests that the
   * progress bar be repainted. Subclasses that don't use the default painting code might need to
   * override this method to change the way that the <code>repaint</code> method is invoked.
   *
   * @param newValue the new animation index; no checking is performed on its value
   * @see #incrementAnimationIndex
   * @since 1.4
   */
  protected void setAnimationIndex(int newValue) {
    if (animationIndex != newValue) {
      if (sizeChanged()) {
        animationIndex = newValue;
        maxPosition = 0; // needs to be recalculated
        delta = 0.0; // needs to be recalculated
        progressBar.repaint();
        return;
      }

      // Get the previous box drawn.
      nextPaintRect = getBox(nextPaintRect);

      // Update the frame number.
      animationIndex = newValue;

      // Get the next box to draw.
      if (nextPaintRect != null) {
        boxRect = getBox(boxRect);
        if (boxRect != null) {
          nextPaintRect.add(boxRect);
        }
      }
    } else { // animationIndex == newValue
      return;
    }

    if (nextPaintRect != null) {
      progressBar.repaint(nextPaintRect);
    } else {
      progressBar.repaint();
    }
  }
예제 #9
0
 private Rectangle getBounds(FigureEnumeration fe) {
   Rectangle r = fe.nextFigure().displayBox();
   while (fe.hasNextFigure()) {
     r.add(fe.nextFigure().displayBox());
   }
   return r;
 }
예제 #10
0
 /**
  * Overrides Step getBounds method.
  *
  * @param trackerPanel the tracker panel drawing the step
  * @return the bounding rectangle
  */
 public Rectangle getBounds(TrackerPanel trackerPanel) {
   Rectangle bounds = getMark(trackerPanel).getBounds(false);
   Rectangle layoutRect = layoutBounds.get(trackerPanel);
   if (layoutRect != null) {
     bounds.add(layoutRect);
   }
   return bounds;
 }
예제 #11
0
 public Rectangle getBounds(Rectangle rect, Graphics g) {
   rect.setBounds(x - RADIUS, y - RADIUS, 2 * RADIUS, 2 * RADIUS);
   rect.grow(2, 2);
   if (isInitial()) {
     double dx = x - RADIUS / Math.sqrt(2.0);
     double dy = y + RADIUS / Math.sqrt(2.0);
     rect.add(dx - INITARROW_LEN - 2, dy + INITARROW_LEN + 2);
   }
   return rect;
 }
예제 #12
0
파일: DiffRowTable.java 프로젝트: sprig/MPS
 @Override
 public void valueChanged(ListSelectionEvent e) {
   int firstIndex = e.getFirstIndex();
   int lastIndex = e.getLastIndex();
   if (firstIndex == -1 && lastIndex == -1) {
     repaint();
   }
   Rectangle dirtyRegion = getCellRect(firstIndex, 0, false);
   int numColumns = getColumnCount();
   int index = firstIndex;
   for (int i = 0; i < numColumns; i++) {
     dirtyRegion.add(getCellRect(index, i, false));
   }
   index = lastIndex;
   for (int i = 0; i < numColumns; i++) {
     dirtyRegion.add(getCellRect(index, i, false));
   }
   repaint(dirtyRegion.x, dirtyRegion.y, dirtyRegion.width, dirtyRegion.height);
 }
예제 #13
0
파일: LiteGroup.java 프로젝트: URMC/i2b2
  /**
   * Compute the bounds of the <code>Lite</code> objets.
   *
   * @return The bounding rectangle.
   */
  public Rectangle getBounds() {
    if (lites.isEmpty()) return new Rectangle();

    Enumeration e = elements();
    Lite l = (Lite) e.nextElement();
    Rectangle r = l.getBounds();
    while (e.hasMoreElements()) {
      l = (Lite) e.nextElement();
      r.add(l.getBounds());
    }
    return r;
  }
예제 #14
0
 public void drawingInvalidated(DrawingChangeEvent e) {
   Rectangle r = e.getInvalidatedRectangle();
   if (getDamage() == null) {
     setDamage(r);
   } else {
     // don't manipulate rectangle returned by getDamage() directly
     // because it could be a cloned rectangle.
     Rectangle damagedR = getDamage();
     damagedR.add(r);
     setDamage(damagedR);
   }
 }
예제 #15
0
 /**
  * Produces a repaint request that covers the old region as it existed last time this method was
  * called, and the new region as of now. It shouldn't be necessary to call this method directly;
  * use {@link #setRegion(Rectangle)}.
  */
 private void repaintRegion() {
   Rectangle newRegion = (region == null) ? null : new Rectangle(region);
   if (oldRegion != null && newRegion == null) {
     repaint(oldRegion.x, oldRegion.y, oldRegion.width + 1, oldRegion.height + 1);
   } else if (oldRegion == null && newRegion != null) {
     repaint(newRegion.x, newRegion.y, newRegion.width + 1, newRegion.height + 1);
   } else if (oldRegion != null && newRegion != null) {
     oldRegion.add(newRegion);
     repaint(oldRegion.x, oldRegion.y, oldRegion.width + 1, oldRegion.height + 1);
   }
   oldRegion = newRegion;
 }
예제 #16
0
    // ~ Methods ------------------------------------------------------------
    @Override
    public Rectangle computeReferenceBox() {
      if (seed == null) {
        throw new NullPointerException("Compound seed has not been set");
      }

      Rectangle pixRect = new Rectangle(seed.getCentroid());
      pixRect.add(
          new Point(
              pixRect.x - (2 * scale.getInterline()), pixRect.y + (3 * scale.getInterline())));

      return pixRect;
    }
  @Override
  public void mouseReleased(MouseEvent evt) {
    dragLocation = new Point(evt.getX(), evt.getY());
    multicaster.trackEnd(anchor, dragLocation, evt.getModifiersEx(), getView());

    // Note: we must not fire "Tool Done" in this method, because then we can not
    // listen to keyboard events for the handle.

    Rectangle r = new Rectangle(anchor.x, anchor.y, 0, 0);
    r.add(evt.getX(), evt.getY());
    maybeFireBoundsInvalidated(r);
    dragLocation = null;
  }
예제 #18
0
  @Override
  public void mouseDragged(
      final MouseEvent me,
      final Layer la,
      final int x_p,
      final int y_p,
      int x_d,
      int y_d,
      int x_d_old,
      int y_d_old) {
    final int tool = ProjectToolbar.getToolId();
    if (ProjectToolbar.PEN != tool) return;

    // transform to the local coordinates
    if (!this.at.isIdentity()) {
      // final Point2D.Double p = inverseTransformPoint(x_p, y_p);
      // x_p = (int)p.x;
      // y_p = (int)p.y;
      final Point2D.Double pd = inverseTransformPoint(x_d, y_d);
      x_d = (int) pd.x;
      y_d = (int) pd.y;
      final Point2D.Double pdo = inverseTransformPoint(x_d_old, y_d_old);
      x_d_old = (int) pdo.x;
      y_d_old = (int) pdo.y;
    }

    if (-1 != index) {
      if (me.isShiftDown()) {
        // resize
        item.radius =
            (int)
                Math.ceil(
                    Math.sqrt(
                        (x_d - item.p[0][index]) * (x_d - item.p[0][index])
                            + (y_d - item.p[1][index]) * (y_d - item.p[1][index])));
        if (item.radius < 1) item.radius = 1;
      } else {
        item.translate(index, x_d - x_d_old, y_d - y_d_old);
      }
      Rectangle repaint_bbox = bbox;
      final Rectangle current_bbox =
          this.at.createTransformedShape(item.getBoundingBox()).getBounds();
      if (null == bbox) repaint_bbox = current_bbox;
      else {
        repaint_bbox = (Rectangle) bbox.clone();
        repaint_bbox.add(current_bbox);
      }
      bbox = current_bbox;
      Display.repaint(layer_set, repaint_bbox);
    }
  }
예제 #19
0
 protected void calculateBounds() {
   bounds.setBounds(0, 0, -1, -1);
   int[] x = new int[4];
   int[] y = new int[4];
   for (int i = 0; i < 4; i++) {
     if (pp[i] == null) continue;
     x[i] = pp[i].getX();
     y[i] = pp[i].getY();
   }
   int p = path.properties.get(PPath.PRECISION);
   int n = (1 << p);
   if (pp[0] == null) {
     px = new int[2];
     py = new int[2];
     px[0] = x[1];
     py[0] = y[1];
     bounds.add(x[1], y[1]);
     pBlend(1, n, 0, Arrays.copyOfRange(x, 1, 4), Arrays.copyOfRange(y, 1, 4));
     bounds.add(px[1], py[1]);
   } else {
     px = new int[n];
     py = new int[n];
     for (int t = 0; t < n - 1; t++) {
       pBlend(t, n, t, x, y);
       bounds.add(px[t], py[t]);
     }
     if (pp[3] == null) {
       px[n - 1] = x[2];
       py[n - 1] = y[2];
     } else pBlend(n - 1, n, 0, Arrays.copyOfRange(x, 1, 4), Arrays.copyOfRange(y, 1, 4));
     bounds.add(px[n - 1], py[n - 1]);
   }
   bounds.grow(HLW, HLW);
   for (int t = 0; t < px.length; t++) {
     px[t] -= bounds.x;
     py[t] -= bounds.y;
   }
 }
예제 #20
0
 protected void calculateBounds() {
   px0 = pp[0].getX();
   py0 = pp[0].getY();
   px1 = pp[1].getX();
   py1 = pp[1].getY();
   bounds.setBounds(0, 0, -1, -1);
   bounds.add(px0, py0);
   bounds.add(px1, py1);
   bounds.grow(HLW, HLW);
   px0 -= bounds.x;
   py0 -= bounds.y;
   px1 -= bounds.x;
   py1 -= bounds.y;
 }
  /**
   * Clears the area of the tile on the graphics
   *
   * @param graphics graphics to draw onto
   * @param style raster symbolizer
   * @throws FactoryException
   * @throws TransformException
   * @throws RenderException
   */
  private void renderBlankTile(Graphics2D graphics, WMTTile tile, WMTRenderJob renderJob)
      throws Exception {

    if (tile == null) {
      return;
    }

    // get the bounds of the tile and convert to necessary viewport projection
    Envelope bnds = renderJob.projectTileToMapCrs(tile.getExtent());

    // determine screen coordinates of tiles
    Point upperLeft = getContext().worldToPixel(new Coordinate(bnds.getMinX(), bnds.getMinY()));
    Point bottomRight = getContext().worldToPixel(new Coordinate(bnds.getMaxX(), bnds.getMaxY()));
    Rectangle tileSize = new Rectangle(upperLeft);
    tileSize.add(bottomRight);

    // render
    try {
      graphics.setBackground(new Color(255, 255, 255, 0)); // set the tile transparent for now
      graphics.clearRect(tileSize.x, tileSize.y, tileSize.width, tileSize.height);

      if (TESTING) {
        /* for testing draw border around tiles */
        graphics.setColor(Color.BLACK);
        graphics.drawLine(
            (int) tileSize.getMinX(),
            (int) tileSize.getMinY(),
            (int) tileSize.getMinX(),
            (int) tileSize.getMaxY());
        graphics.drawLine(
            (int) tileSize.getMinX(),
            (int) tileSize.getMinY(),
            (int) tileSize.getMaxX(),
            (int) tileSize.getMinY());
        graphics.drawLine(
            (int) tileSize.getMaxX(),
            (int) tileSize.getMinY(),
            (int) tileSize.getMaxX(),
            (int) tileSize.getMaxY());
        graphics.drawLine(
            (int) tileSize.getMinX(),
            (int) tileSize.getMaxY(),
            (int) tileSize.getMaxX(),
            (int) tileSize.getMaxY());
      }
    } catch (Throwable t) {
      WMTPlugin.log("Error Rendering Blank tile. Painting Tile: " + tile.getId(), t); // $NON-NLS-1$
    }
  }
  private void addInvalidArea(Rectangle invalidArea) {
    if (invalidArea.x > getWidth() || (invalidArea.x + invalidArea.width < 0)) return;
    if (invalidArea.y > getHeight() || (invalidArea.y + invalidArea.height < 0)) return;

    int origX = invalidArea.x;
    int origY = invalidArea.y;

    invalidArea.x = Math.max(invalidArea.x, 0);
    invalidArea.y = Math.max(invalidArea.y, 0);
    invalidArea.width = Math.min(origX + invalidArea.width, getWidth()) - invalidArea.x;
    invalidArea.height = Math.min(origY + invalidArea.height, getHeight()) - invalidArea.y;

    if (invalidOffscreenArea.isEmpty()) invalidOffscreenArea.setBounds(invalidArea);
    else invalidOffscreenArea.add(invalidArea);
  }
예제 #23
0
  public void updateLine() {
    PBounds sourceBounds = source.getBounds();
    PBounds targetBounds = target.getBounds();
    double x1, y1, x2, y2;

    if (Math.abs(sourceBounds.getCenterX() - targetBounds.getCenterX()) < 1.0) {
      // source and target on the same vertical position
      x1 = x2 = sourceBounds.getCenterX();
      y1 = sourceBounds.getMaxY();
      y2 = targetBounds.getMinY();
      y2 -= STROKE_ARROW.getLineWidth();

      if (y1 > y2) {
        y1 = sourceBounds.getMinY();
        y2 = targetBounds.getMaxY();
        y2 += STROKE_ARROW.getLineWidth();
      }
    } else {
      // source and target in different vertical positions
      x1 = sourceBounds.getMaxX();
      y1 = sourceBounds.getCenterY();
      x2 = targetBounds.getMinX();
      y2 = targetBounds.getCenterY();
      x2 -= STROKE_ARROW.getLineWidth();

      if (x1 > x2) {
        x1 = sourceBounds.getMinX();
        x2 = targetBounds.getMaxX();
        x2 += STROKE_ARROW.getLineWidth();
      }

      // move the ends a bit if we are not in the same vertical position
      int ydi = (int) Math.round((y2 - y1) / (MmfNode.HEIGHT + MmfNode.PADDING_HEIGHT));
      double yd = (ydi < 0 ? -1 : 1) * END_DELTA[Math.min(Math.abs(ydi), END_DELTA.length - 1)];
      y1 += yd;
      y2 -= yd;
    }

    line = new Line2D.Double(x1, y1, x2, y2);
    arrowHead = getArrowHead((int) x1, (int) y1, (int) x2, (int) y2);

    Rectangle bounds = line.getBounds();
    bounds.add(arrowHead.getBounds());
    setBounds(bounds);
  }
  /** This method is taken from inside the source of JLabel (in the inner AccessibleJLabel class) */
  private Rectangle getTextRectangle() {
    final String text = getText();
    final Icon icon = (isEnabled()) ? getIcon() : getDisabledIcon();

    if ((icon == null) && (text == null)) {
      return null;
    }

    final Rectangle paintIconR = new Rectangle();
    final Rectangle paintTextR = new Rectangle();
    final Rectangle paintViewR = new Rectangle();

    Insets paintViewInsets = new Insets(0, 0, 0, 0);
    paintViewInsets = getInsets(paintViewInsets);

    paintViewR.x = paintViewInsets.left;
    paintViewR.y = paintViewInsets.top;
    paintViewR.width = getWidth() - (paintViewInsets.left + paintViewInsets.right);
    paintViewR.height = getHeight() - (paintViewInsets.top + paintViewInsets.bottom);

    final Graphics g = getGraphics();
    if (g == null) {
      return null;
    }

    SwingUtilities.layoutCompoundLabel(
        this,
        g.getFontMetrics(),
        text,
        icon,
        getVerticalAlignment(),
        getHorizontalAlignment(),
        getVerticalTextPosition(),
        getHorizontalTextPosition(),
        paintViewR,
        paintIconR,
        paintTextR,
        getIconTextGap());

    final Rectangle returnValue = new Rectangle(paintTextR);
    returnValue.add(paintIconR);

    return returnValue;
  }
예제 #25
0
  @Override
  protected Rectangle calculateClientArea() {
    Rectangle bounds = null;
    if (this.getControlPoints().size() > 0) {
      for (Point p : this.getControlPoints()) {
        if (bounds == null) bounds = new Rectangle(p);
        else bounds.add(p);
      }
      bounds.grow(5, 5);
    }
    if (isReflexive()) {
      Widget related = this.getTargetAnchor().getRelatedWidget();
      bounds = related.convertLocalToScene(related.getBounds());
      bounds.grow(10, 10);
    }
    if (bounds == null) bounds = super.calculateClientArea();

    return bounds;
  }
  /**
   * Provides a mapping, for a given region, from the document model coordinate space to the view
   * coordinate space. The specified region is created as a union of the first and last character
   * positions.
   *
   * <p>This is implemented to subtract the width of the second character, as this view's <code>
   * modelToView</code> actually returns the width of the character instead of "1" or "0" like the
   * View implementations in <code>javax.swing.text</code>. Thus, if we don't override this method,
   * the <code>View</code> implementation will return one character's width too much for its
   * consumers (implementations of <code>javax.swing.text.Highlighter</code>).
   *
   * @param p0 the position of the first character (&gt;=0)
   * @param b0 The bias of the first character position, toward the previous character or the next
   *     character represented by the offset, in case the position is a boundary of two views;
   *     <code>b0</code> will have one of these values:
   *     <ul>
   *       <li><code>Position.Bias.Forward</code>
   *       <li><code>Position.Bias.Backward</code>
   *     </ul>
   *
   * @param p1 the position of the last character (&gt;=0)
   * @param b1 the bias for the second character position, defined one of the legal values shown
   *     above
   * @param a the area of the view, which encompasses the requested region
   * @return the bounding box which is a union of the region specified by the first and last
   *     character positions
   * @exception BadLocationException if the given position does not represent a valid location in
   *     the associated document
   * @exception IllegalArgumentException if <code>b0</code> or <code>b1</code> are not one of the
   *     legal <code>Position.Bias</code> values listed above
   * @see View#viewToModel
   */
  @Override
  public Shape modelToView(int p0, Position.Bias b0, int p1, Position.Bias b1, Shape a)
      throws BadLocationException {

    Shape s0 = modelToView(p0, a, b0);
    Shape s1;
    if (p1 == getEndOffset()) {
      try {
        s1 = modelToView(p1, a, b1);
      } catch (BadLocationException ble) {
        s1 = null;
      }
      if (s1 == null) {
        // Assume extends left to right.
        Rectangle alloc = (a instanceof Rectangle) ? (Rectangle) a : a.getBounds();
        s1 = new Rectangle(alloc.x + alloc.width - 1, alloc.y, 1, alloc.height);
      }
    } else {
      s1 = modelToView(p1, a, b1);
    }
    Rectangle r0 = s0 instanceof Rectangle ? (Rectangle) s0 : s0.getBounds();
    Rectangle r1 = s1 instanceof Rectangle ? (Rectangle) s1 : s1.getBounds();
    if (r0.y != r1.y) {
      // If it spans lines, force it to be the width of the view.
      Rectangle alloc = (a instanceof Rectangle) ? (Rectangle) a : a.getBounds();
      r0.x = alloc.x;
      r0.width = alloc.width;
    }

    r0.add(r1);
    // The next line is the only difference between this method and
    // View's implementation.  We're subtracting the width of the second
    // character.  This is because this method is used by Highlighter
    // implementations to get the area to "highlight", and if we don't do
    // this, one character too many is highlighted thanks to our
    // modelToView() implementation returning the actual width of the
    // character requested!
    if (p1 > p0) {
      r0.width -= r1.width;
    }

    return r0;
  }
예제 #27
0
    void refresh() {

      Rectangle r = new Rectangle(startPoint.asPoint());
      r.add(endPoint.asPoint());
      r.grow(5, 5);
      measurementLine.setBounds(r);

      dir = (startPoint.x - endPoint.x) * (startPoint.y - endPoint.y) < 0;

      groundTruthLabel.setText("" + groundTruth);
      groundTruthLabel.setSize(groundTruthLabel.getPreferredSize());

      int x = (startPoint.asPoint().x + endPoint.asPoint().x) / 2;
      int y = (startPoint.asPoint().y + endPoint.asPoint().y) / 2;
      groundTruthLabel.setLocation(x, y);

      groundTruthEditor.setLocation(groundTruthLabel.getLocation());

      repaint();
    }
예제 #28
0
    @Override
    public boolean consumeEvent(AWTEvent evt, boolean isOutsideEvent) {
      if (!isOutsideEvent && evt.getID() == MouseEvent.MOUSE_DRAGGED) {
        MouseEvent me = (MouseEvent) evt;

        // calculate area to repaint
        Rectangle bBox = m_scaled.getScreenBBox();
        m_scaled.scale(calculateScaleX(me.getX()), calculateScaleY(me.getY()), m_scalePtIdx);
        bBox.add(m_scaled.getScreenBBox());

        m_factory
            .getSceneManager()
            .getScreenManager()
            .repaint(bBox, SVGObjectOutline.SELECTOR_OVERLAP);
      } else if (evt.getID() == MouseEvent.MOUSE_RELEASED) {
        actionCompleted();
        m_scaled.commitChanges();
      }
      return false;
    }
예제 #29
0
 @Override
 protected void validate() {
   if (segment == null) {
     PathPoint p = path.points.get(0);
     PathPoint p2 = path.points.get(1);
     int x = p.getX();
     int y = p.getY();
     calculatePoints(x, y, Math.atan2(y - p2.getY(), p2.getX() - x));
   } else {
     segment.validate();
     if (path.get(PPath.CLOSED)) {
       int i = segment.px.length - 1;
       int x = segment.px[i];
       int y = segment.py[i];
       int i2 = i - 1;
       while (i2 > 0 && sqrdist(segment.px[i2] - x, segment.py[i2] - y) < 4) i2--;
       calculatePoints(
           x + segment.bounds.x,
           y + segment.bounds.y,
           Math.atan2(segment.py[i2] - y, x - segment.px[i2]));
     } else {
       int x = segment.px[0];
       int y = segment.py[0];
       int i = 1;
       while (i < segment.px.length - 1 && sqrdist(segment.px[i] - x, segment.py[i] - y) < 4)
         i++;
       calculatePoints(
           x + segment.bounds.x,
           y + segment.bounds.y,
           Math.atan2(y - segment.py[i], segment.px[i] - x));
     }
   }
   Rectangle bounds = new Rectangle(-1, -1);
   for (int i = 0; i < 4; i++) bounds.add(px[i], py[i]);
   for (int i = 0; i < 4; i++) {
     px[i] -= bounds.x;
     py[i] -= bounds.y;
   }
   setBounds(bounds);
 }
예제 #30
0
 @Override
 protected Rectangle getWorkingRectangle(boolean withPaper) {
   Rectangle working = null;
   if (withPaper) {
     working = paperWidget.getPreferredBounds();
   }
   for (Object o : getObjects()) {
     Widget w = findWidget(o);
     if (w instanceof SubLayoutWidget) {
       Point wLoc = w.getPreferredLocation();
       Rectangle wRect = w.getBounds();
       if (wRect != null) {
         wRect.translate(wLoc.x, wLoc.y);
         if (working == null) {
           working = wRect;
         }
         working.add(wRect);
       }
     }
   }
   return working;
 }