예제 #1
0
  /**
   * Draw some graphics into an Graphics2D object.
   *
   * @param image the image to draw into
   * @throws NoninvertibleTransformException in transform errors.
   */
  private void draw(Graphics2D gr) throws NoninvertibleTransformException {
    gr.setPaint(Color.WHITE);
    gr.fill(new Rectangle(0, 0, tileWidth, tileHeight));

    // AffineTransform[[0.318755336305853, 0.0, 420.03106689453125],
    //                 [0.0, 0.318755336305853, 245.5029296875]]
    AffineTransform transform =
        new AffineTransform(
            0.318755336305853, 0.0, 0.0, 0.318755336305853, 420.03106689453125, 245.5029296875);
    gr.setTransform(transform);

    Shape s = new Rectangle(0, 0, 96, 83);

    // create an enbedded graphics
    Graphics2D grr = (Graphics2D) gr.create();
    // AffineTransform[[1.0, 0.0, -343.9285583496093],
    //                 [0.0, 1.0, -502.5158386230469]]
    grr.clip(s.getBounds());
    transform = new AffineTransform(1.0, 0.0, 0.0, 1.0, -343.9285583496093, -502.5158386230469);
    grr.transform(transform);

    AffineTransform t = transform.createInverse();
    s = t.createTransformedShape(s);

    assertTrue(s.getBounds().intersects(grr.getClip().getBounds2D()));

    grr.setPaint(Color.BLUE);
    grr.draw(s);

    grr.dispose();
    gr.dispose();
  }
예제 #2
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;
 }
예제 #3
0
  public boolean checkWorldCollision(Shape s) {
    if (s == null) return false;
    Point area = Globals.findTile(s.getBounds().x, s.getBounds().y);

    int areaX = area.x;
    int areaY = area.y;
    areaX--;
    areaY--;
    if (areaX < 0) areaX = 0;
    if (areaY < 0) areaY = 0;
    int areaXEnd = areaX + 21;
    int areaYEnd = areaY + 21;
    if (areaXEnd > xLength) areaXEnd = xLength;
    if (areaYEnd > yHeight) areaYEnd = yHeight;

    for (int x = areaX; x < areaXEnd; x++) {
      for (int y = areaY; y < areaYEnd; y++) {
        if (walls[x][y] == null) continue;
        if (s.intersects(walls[x][y].getPhysicsShape())) {
          // walls[x][y].printName();
          return true;
        }
      }
    }
    return false;
  }
 public boolean contains(int x, int y) {
   // If the button has changed size,
   // make a new shape object.
   if (shape == null || !shape.getBounds().equals(getBounds())) {
     shape = new Ellipse2D.Float(0, 0, getWidth(), getHeight());
   }
   return shape.contains(x, y);
 }
예제 #5
0
 /**
  * Constructs a ShapeIcon.
  *
  * @param shape the shape to draw
  * @param decoration a decorating shape to draw
  * @param width width of the icon
  * @param height height of the icon
  */
 public ShapeIcon(Shape shape, Shape decoration, int width, int height) {
   w = width;
   h = height;
   this.shape = shape;
   this.decoration = decoration;
   Rectangle rect = shape == null ? new Rectangle() : shape.getBounds();
   if (decoration != null) rect = rect.union(decoration.getBounds());
   offsetX = w / 2 - rect.width / 2 - rect.x;
   offsetY = h / 2 - rect.height / 2 - rect.y;
 }
예제 #6
0
  /**
   * @param shape
   * @param rotation
   * @return
   */
  public static Shape getRotatedShape(Shape shape, double rotation) {
    AffineTransform localAT = null;
    Shape localShape = null;
    localAT =
        AffineTransform.getRotateInstance(
            Math.toRadians(rotation), shape.getBounds().getX(), shape.getBounds().getY());
    localShape = localAT.createTransformedShape(shape);

    return localShape;
  }
 @Override
 public boolean contains(int x, int y) {
   if (shape == null || !shape.getBounds().equals(getBounds())) {
     shape = new Area(makeStarDesign(5, new Point(50, 50), 50, 30));
   }
   return shape.contains(x, y);
 }
  /**
   * 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);
        }
      }
    }
  }
    /**
     * Paints a highlight.
     *
     * @param g the graphics context
     * @param offs0 the starting model offset &gt;= 0
     * @param offs1 the ending model offset &gt;= offs1
     * @param bounds the bounding box for the highlight
     * @param c the editor
     */
    public void paint(Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c) {
      Rectangle alloc = bounds.getBounds();
      try {
        // --- determine locations ---
        TextUI mapper = c.getUI();
        Rectangle p0 = mapper.modelToView(c, offs0);
        Rectangle p1 = mapper.modelToView(c, offs1);

        // --- render ---
        Color color = getColor();

        if (color == null) {
          g.setColor(c.getSelectionColor());
        } else {
          g.setColor(color);
        }
        if (p0.y == p1.y) {
          // same line, render a rectangle
          Rectangle r = p0.union(p1);
          g.fillRect(r.x, r.y, r.width, r.height);
        } else {
          // different lines
          int p0ToMarginWidth = alloc.x + alloc.width - p0.x;
          g.fillRect(p0.x, p0.y, p0ToMarginWidth, p0.height);
          if ((p0.y + p0.height) != p1.y) {
            g.fillRect(alloc.x, p0.y + p0.height, alloc.width, p1.y - (p0.y + p0.height));
          }
          g.fillRect(alloc.x, p1.y, (p1.x - alloc.x), p1.height);
        }
      } catch (BadLocationException e) {
        // can't render
      }
    }
예제 #10
0
    /**
     * Much of this code is copied from GlyphPainter1's implementation.
     *
     * @see javax.swing.text.GlyphView.GlyphPainter#paint(javax.swing.text.GlyphView,
     *     java.awt.Graphics, java.awt.Shape, int, int)
     */
    @Override
    public void paint(GlyphView v, Graphics g, Shape a, int p0, int p1) {
      sync(v);
      Segment text;
      TabExpander expander = v.getTabExpander();
      Rectangle alloc = (a instanceof Rectangle) ? (Rectangle) a : a.getBounds();

      // determine the x coordinate to render the glyphs
      int x = alloc.x;
      int p = v.getStartOffset();
      if (p != p0) {
        text = v.getText(p, p0);
        int width = Utilities.getTabbedTextWidth(text, metrics, x, expander, p);
        x += width;
      } // endif

      // determine the y coordinate to render the glyphs
      int y = alloc.y + metrics.getHeight() - metrics.getDescent();

      // Calculate the background highlight, it gets painted first.
      Color bg = TwoToneTextPane.getTwoToneColor(v.getElement().getAttributes());
      Color fg = g.getColor();
      if (bg == null) { // No color set, guess black or white
        float[] hsb = Color.RGBtoHSB(fg.getRed(), fg.getGreen(), fg.getBlue(), null);
        bg = hsb[2] > 0.7 ? Color.BLACK : Color.WHITE;
      } // endif
      g.setColor(bg);

      // render the glyphs, first in bg highlight, then in fg
      text = v.getText(p0, p1);
      g.setFont(metrics.getFont());
      Utilities.drawTabbedText(text, x + HORIZONTAL_OFFSET, y + VERTICAL_OFFSET, g, expander, p0);
      g.setColor(fg);
      Utilities.drawTabbedText(text, x, y, g, expander, p0);
    }
예제 #11
0
  /** Paints the glyphs representing the given range. */
  public void paint(GlyphView v, Graphics g, Shape a, int p0, int p1) {
    sync(v);
    Segment text;
    TabExpander expander = v.getTabExpander();
    Rectangle alloc = (a instanceof Rectangle) ? (Rectangle) a : a.getBounds();

    // determine the x coordinate to render the glyphs
    int x = alloc.x;
    int p = v.getStartOffset();
    int[] justificationData = getJustificationData(v);
    if (p != p0) {
      text = v.getText(p, p0);
      int width = Utilities.getTabbedTextWidth(v, text, metrics, x, expander, p, justificationData);
      x += width;
      SegmentCache.releaseSharedSegment(text);
    }

    // determine the y coordinate to render the glyphs
    int y = alloc.y + metrics.getHeight() - metrics.getDescent();

    // render the glyphs
    text = v.getText(p0, p1);
    g.setFont(metrics.getFont());

    Utilities.drawTabbedText(v, text, x, y, g, expander, p0, justificationData);
    SegmentCache.releaseSharedSegment(text);
  }
예제 #12
0
  @Override
  public int viewToModel(float x, float y, Shape a, Position.Bias[] bias) {

    int offs = -1;

    if (!isAllocationValid()) {
      Rectangle alloc = a.getBounds();
      setSize(alloc.width, alloc.height);
    }

    // Get the child view for the line at (x,y), and ask it for the
    // specific offset.
    Rectangle alloc = getInsideAllocation(a);
    View v = getViewAtPoint((int) x, (int) y, alloc);
    if (v != null) {
      offs = v.viewToModel(x, y, alloc, bias);
    }

    // Code folding may have hidden the last line.  If so, return the last
    // visible offset instead of the last offset.
    if (host.isCodeFoldingEnabled()
        && v == getView(getViewCount() - 1)
        && offs == v.getEndOffset() - 1) {
      offs = host.getLastVisibleOffset();
    }

    return offs;
  }
  private double calculateWidth(V v) {
    double childrenWidthSum = 0;
    int childrenNum = graph.getSuccessors(v).size();
    if (childrenNum != 0) {
      boolean first = true;
      for (V element : graph.getSuccessors(v)) {
        if (!first) {
          childrenWidthSum += MARGIN;
        }
        childrenWidthSum += calculateWidth(element);
        first = false;
      }
    }

    double width = DEFAULT_WIDTH;
    if (this.shapeTransformer != null) {
      Shape shape = this.shapeTransformer.transform(v);
      if (shape != null) {
        width = shape.getBounds().getWidth();
      }
    }
    double size = Math.max(width, childrenWidthSum);
    size = Math.max(0, size);
    return size;
  }
예제 #14
0
    /**
     * @see javax.swing.text.GlyphView.GlyphPainter#modelToView(javax.swing.text.GlyphView, int,
     *     javax.swing.text.Position.Bias, java.awt.Shape)
     */
    @Override
    public Shape modelToView(GlyphView v, int pos, Position.Bias bias, Shape a)
        throws BadLocationException {

      sync(v);
      Rectangle alloc = (a instanceof Rectangle) ? (Rectangle) a : a.getBounds();
      int p0 = v.getStartOffset();
      int p1 = v.getEndOffset();
      TabExpander expander = v.getTabExpander();
      Segment text;

      Rectangle r = new Rectangle();
      if (pos == p1) {
        // The caller of this is left to right and borders a right to
        // left view, return our end location.
        r.setBounds(alloc.x + alloc.width, alloc.y, 0, metrics.getHeight() + VERTICAL_OFFSET);
      } else if ((pos >= p0) && (pos <= p1)) {
        // determine range to the left of the position
        text = getText(v, p0, pos);
        int width = Utilities.getTabbedTextWidth(text, metrics, alloc.x, expander, p0);
        r.setBounds(alloc.x + width, alloc.y, 0, metrics.getHeight() + VERTICAL_OFFSET);
      } else {
        throw new BadLocationException("modelToView - can't convert", p1);
      } // endif
      return r;
    }
예제 #15
0
 /**
  * Renders using the given rendering surface and area on that surface.
  *
  * @param g the rendering surface to use
  * @param allocation the allocated region to render into
  * @see View#paint
  */
 public void paint(Graphics g, Shape allocation) {
   super.paint(g, allocation);
   Rectangle alloc = allocation.getBounds();
   Rectangle clip = g.getClipBounds();
   // Since listPainter paints in the insets we have to check for the
   // case where the child is not painted because the paint region is
   // to the left of the child. This assumes the ListPainter paints in
   // the left margin.
   if ((clip.x + clip.width) < (alloc.x + getLeftInset())) {
     Rectangle childRect = alloc;
     alloc = getInsideAllocation(allocation);
     int n = getViewCount();
     int endY = clip.y + clip.height;
     for (int i = 0; i < n; i++) {
       childRect.setBounds(alloc);
       childAllocation(i, childRect);
       if (childRect.y < endY) {
         if ((childRect.y + childRect.height) >= clip.y) {
           listPainter.paint(
               g, childRect.x, childRect.y, childRect.width, childRect.height, this, i);
         }
       } else {
         break;
       }
     }
   }
 }
예제 #16
0
  public Shape modelToView(GlyphView v, int pos, Position.Bias bias, Shape a)
      throws BadLocationException {

    sync(v);
    Rectangle alloc = (a instanceof Rectangle) ? (Rectangle) a : a.getBounds();
    int p0 = v.getStartOffset();
    int p1 = v.getEndOffset();
    TabExpander expander = v.getTabExpander();
    Segment text;

    if (pos == p1) {
      // The caller of this is left to right and borders a right to
      // left view, return our end location.
      return new Rectangle(alloc.x + alloc.width, alloc.y, 0, metrics.getHeight());
    }
    if ((pos >= p0) && (pos <= p1)) {
      // determine range to the left of the position
      text = v.getText(p0, pos);
      int[] justificationData = getJustificationData(v);
      int width =
          Utilities.getTabbedTextWidth(v, text, metrics, alloc.x, expander, p0, justificationData);
      SegmentCache.releaseSharedSegment(text);
      return new Rectangle(alloc.x + width, alloc.y, 0, metrics.getHeight());
    }
    throw new BadLocationException("modelToView - can't convert", p1);
  }
  public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException {

    if (!isAllocationValid()) {
      Rectangle alloc = a.getBounds();
      setSize(alloc.width, alloc.height);
    }

    boolean isBackward = (b == Position.Bias.Backward);
    int testPos = (isBackward) ? Math.max(0, pos - 1) : pos;
    if (isBackward && testPos < getStartOffset()) {
      return null;
    }

    int vIndex = getViewIndexAtPosition(testPos);
    if ((vIndex != -1) && (vIndex < getViewCount())) {
      View v = getView(vIndex);
      if (v != null && testPos >= v.getStartOffset() && testPos < v.getEndOffset()) {
        Shape childShape = getChildAllocation(vIndex, a);
        if (childShape == null) {
          // We are likely invalid, fail.
          return null;
        }
        Shape retShape = v.modelToView(pos, childShape, b);
        if (retShape == null && v.getEndOffset() == pos) {
          if (++vIndex < getViewCount()) {
            v = getView(vIndex);
            retShape = v.modelToView(pos, getChildAllocation(vIndex, a), b);
          }
        }
        return retShape;
      }
    }

    throw new BadLocationException("Position not represented by view", pos);
  }
예제 #18
0
  @Override
  public Shape getShape(SVGHandle handle, Element element, boolean isOutline) {

    Shape shape = handle.getSvgElementsManager().getGeometryOutline(element);

    if (shape == null || shape.getBounds().getWidth() == 0 || shape.getBounds().getHeight() == 0) {

      // getting the location of the text
      double x = EditorToolkit.getAttributeValue(element, xAtt);
      double y = EditorToolkit.getAttributeValue(element, yAtt);

      shape = new Rectangle2D.Double(x, y, 1, 1);
    }

    return shape;
  }
예제 #19
0
 public Shape getShape(double mw, double mh) {
   // now scale the path so it has proper w and h.
   Rectangle r = sh.getBounds();
   AffineTransform at = new AffineTransform();
   at.translate(-r.x, -r.y);
   at.scale(mw / r.width, mh / r.height);
   return at.createTransformedShape(sh);
 }
예제 #20
0
    public void paintJaggedLine(Graphics g, Shape a) {
      int y = (int) (a.getBounds().getY() + a.getBounds().getHeight());
      int x1 = (int) a.getBounds().getX();
      int x2 = (int) (a.getBounds().getX() + a.getBounds().getWidth());
      Color old = g.getColor();
      g.setColor(Color.RED);

      for (int x = x1; x <= x2; x++) {
        if (x % 2 == 0) {
          g.drawLine(x, y - 1, x, y - 1);
        } else if (x % 4 == 1) {
          g.drawLine(x, y - 2, x, y - 2);
        } else {
          g.drawLine(x, y, x, y);
        }
      }
      g.setColor(old);
    }
  /**
   * Provides a mapping from the view coordinate space to the logical coordinate space of the model.
   *
   * @param fx the X coordinate &gt;= 0
   * @param fy the Y coordinate &gt;= 0
   * @param a the allocated region to render into
   * @return the location within the model that best represents the given point in the view &gt;= 0
   */
  @Override
  public int viewToModel(float fx, float fy, Shape a, Position.Bias[] bias) {

    bias[0] = Position.Bias.Forward;

    Rectangle alloc = a.getBounds();
    RSyntaxDocument doc = (RSyntaxDocument) getDocument();
    int x = (int) fx;
    int y = (int) fy;

    // If they're asking about a view position above the area covered by
    // this view, then the position is assumed to be the starting position
    // of this view.
    if (y < alloc.y) {
      return getStartOffset();
    }

    // If they're asking about a position below this view, the position
    // is assumed to be the ending position of this view.
    else if (y > alloc.y + alloc.height) {
      return host.getLastVisibleOffset();
    }

    // They're asking about a position within the coverage of this view
    // vertically.  So, we figure out which line the point corresponds to.
    // If the line is greater than the number of lines contained, then
    // simply use the last line as it represents the last possible place
    // we can position to.
    else {

      Element map = doc.getDefaultRootElement();
      int lineIndex = Math.abs((y - alloc.y) / lineHeight); // metrics.getHeight() );
      FoldManager fm = host.getFoldManager();
      // System.out.print("--- " + lineIndex);
      lineIndex += fm.getHiddenLineCountAbove(lineIndex, true);
      // System.out.println(" => " + lineIndex);
      if (lineIndex >= map.getElementCount()) {
        return host.getLastVisibleOffset();
      }

      Element line = map.getElement(lineIndex);

      // If the point is to the left of the line...
      if (x < alloc.x) {
        return line.getStartOffset();
      } else if (x > alloc.x + alloc.width) {
        return line.getEndOffset() - 1;
      } else {
        // Determine the offset into the text
        int p0 = line.getStartOffset();
        Token tokenList = doc.getTokenListForLine(lineIndex);
        tabBase = alloc.x;
        int offs = tokenList.getListOffset((RSyntaxTextArea) getContainer(), this, tabBase, x);
        return offs != -1 ? offs : p0;
      }
    } // End of else.
  }
  /**
   * Paints the View.
   *
   * @param g the rendering surface to use
   * @param a the allocated region to render into
   * @see View#paint
   */
  @Override
  public void paint(Graphics g, Shape a) {
    sync();

    Rectangle rect = (a instanceof Rectangle) ? (Rectangle) a : a.getBounds();

    Image image = getImage();
    Rectangle clip = g.getClipBounds();

    fBounds.setBounds(rect);
    paintHighlights(g, a);
    paintBorder(g, rect);
    if (clip != null) {
      g.clipRect(
          rect.x + leftInset,
          rect.y + topInset,
          rect.width - leftInset - rightInset,
          rect.height - topInset - bottomInset);
    }
    if (image != null) {
      if (!hasPixels(image)) {
        // No pixels yet, use the default
        Icon icon = (image == null) ? getNoImageIcon() : getLoadingImageIcon();

        if (icon != null) {
          icon.paintIcon(getContainer(), g, rect.x + leftInset, rect.y + topInset);
        }
      } else {
        // Draw the image
        g.drawImage(image, rect.x + leftInset, rect.y + topInset, width, height, imageObserver);
      }
    } else {
      Icon icon = getNoImageIcon();

      if (icon != null) {
        icon.paintIcon(getContainer(), g, rect.x + leftInset, rect.y + topInset);
      }
      View view = getAltView();
      // Paint the view representing the alt text, if its non-null
      if (view != null && ((state & WIDTH_FLAG) == 0 || width > DEFAULT_WIDTH)) {
        // Assume layout along the y direction
        Rectangle altRect =
            new Rectangle(
                rect.x + leftInset + DEFAULT_WIDTH,
                rect.y + topInset,
                rect.width - leftInset - rightInset - DEFAULT_WIDTH,
                rect.height - topInset - bottomInset);

        view.paint(g, altRect);
      }
    }
    if (clip != null) {
      // Reset clip.
      g.setClip(clip.x, clip.y, clip.width, clip.height);
    }
  }
  /**
   * 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;
  }
  /** redefined paint method to paint breakpoint area */
  public void paint(Graphics g, Shape allocation) {
    Rectangle bounds = allocation.getBounds();

    // paint the lines
    super.paint(g, allocation);

    // paint the tag separator line
    g.setColor(Color.lightGray);
    g.drawLine(bounds.x + TAG_WIDTH, 0, bounds.x + TAG_WIDTH, bounds.y + bounds.height);
  }
예제 #25
0
    /**
     * Provides a mapping from the document model coordinate space to the coordinate space of the
     * view mapped to it.
     *
     * @param pos the position to convert
     * @param a the allocated region to render into
     * @return the bounding box of the given position is returned
     * @exception BadLocationException if the given position does not represent a valid location in
     *     the associated document.
     */
    @Override
    public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException {

      // System.err.println("--- begin modelToView ---");
      Rectangle alloc = a.getBounds();
      RSyntaxTextArea textArea = (RSyntaxTextArea) getContainer();
      alloc.height = textArea.getLineHeight(); // metrics.getHeight();
      alloc.width = 1;
      int p0 = getStartOffset();
      int p1 = getEndOffset();
      int testP = (b == Position.Bias.Forward) ? pos : Math.max(p0, pos - 1);

      // Get the token list for this line so we don't have to keep
      // recomputing it if this logical line spans multiple physical
      // lines.
      RSyntaxDocument doc = (RSyntaxDocument) getDocument();
      Element map = doc.getDefaultRootElement();
      int line = map.getElementIndex(p0);
      Token tokenList = doc.getTokenListForLine(line);
      float x0 = alloc.x; // 0;

      while (p0 < p1) {
        TokenSubList subList =
            TokenUtils.getSubTokenList(
                tokenList, p0, WrappedSyntaxView.this, textArea, x0, lineCountTempToken);
        x0 = subList != null ? subList.x : x0;
        tokenList = subList != null ? subList.tokenList : null;
        int p = calculateBreakPosition(p0, tokenList, x0);
        if ((pos >= p0) && (testP < p)) { // pos < p)) {
          // it's in this line
          alloc =
              RSyntaxUtilities.getLineWidthUpTo(
                  textArea, s, p0, pos, WrappedSyntaxView.this, alloc, alloc.x);
          // System.err.println("--- end modelToView ---");
          return alloc;
        }
        // if (p == p1 && pos == p1) {
        if (p == p1 - 1 && pos == p1 - 1) {
          // Wants end.
          if (pos > p0) {
            alloc =
                RSyntaxUtilities.getLineWidthUpTo(
                    textArea, s, p0, pos, WrappedSyntaxView.this, alloc, alloc.x);
          }
          // System.err.println("--- end modelToView ---");
          return alloc;
        }

        p0 = (p == p0) ? p1 : p;
        // System.err.println("... ... Incrementing y");
        alloc.y += alloc.height;
      }

      throw new BadLocationException(null, pos);
    }
    /**
     * Paints a portion of a highlight.
     *
     * @param g the graphics context
     * @param offs0 the starting model offset &gt;= 0
     * @param offs1 the ending model offset &gt;= offs1
     * @param bounds the bounding box of the view, which is not necessarily the region to paint.
     * @param c the editor
     * @param view View painting for
     * @return region drawing occurred in
     */
    public Shape paintLayer(
        Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c, View view) {
      Color color = getColor();

      if (color == null) {
        g.setColor(c.getSelectionColor());
      } else {
        g.setColor(color);
      }

      Rectangle r;

      if (offs0 == view.getStartOffset() && offs1 == view.getEndOffset()) {
        // Contained in view, can just use bounds.
        if (bounds instanceof Rectangle) {
          r = (Rectangle) bounds;
        } else {
          r = bounds.getBounds();
        }
      } else {
        // Should only render part of View.
        try {
          // --- determine locations ---
          Shape shape =
              view.modelToView(offs0, Position.Bias.Forward, offs1, Position.Bias.Backward, bounds);
          r = (shape instanceof Rectangle) ? (Rectangle) shape : shape.getBounds();
        } catch (BadLocationException e) {
          // can't render
          r = null;
        }
      }

      if (r != null) {
        // If we are asked to highlight, we should draw something even
        // if the model-to-view projection is of zero width (6340106).
        r.width = Math.max(r.width, 1);

        g.fillRect(r.x, r.y, r.width, r.height);
      }

      return r;
    }
예제 #27
0
 public void draw(Graphics2D graphic) {
   setForegroundColor(colorString);
   graphic.fill(shape);
   if (text != null) {
     setForegroundColor("black");
     java.awt.Rectangle bounds = shape.getBounds();
     int x = bounds.x + bounds.width / 2;
     int y = bounds.y + bounds.height / 2;
     graphic.drawString(text, x, y);
   }
 }
예제 #28
0
 /**
  * Returns the tooltip text at the specified location. The default implementation returns the
  * value from the child View identified by the passed in location.
  *
  * @since 1.4
  * @see JTextComponent#getToolTipText
  */
 public String getToolTipText(float x, float y, Shape allocation) {
   int viewIndex = getViewIndex(x, y, allocation);
   if (viewIndex >= 0) {
     allocation = getChildAllocation(viewIndex, allocation);
     Rectangle rect =
         (allocation instanceof Rectangle) ? (Rectangle) allocation : allocation.getBounds();
     if (rect.contains(x, y)) {
       return getView(viewIndex).getToolTipText(x, y, allocation);
     }
   }
   return null;
 }
예제 #29
0
 public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException {
   int p0 = getStartOffset();
   int p1 = getEndOffset();
   if ((pos >= p0) && (pos <= p1)) {
     Rectangle r = a.getBounds();
     if (pos == p1) {
       r.x += r.width;
     }
     r.width = 0;
     return r;
   }
   throw new BadLocationException(pos + " not in range " + p0 + "," + p1, pos);
 }
예제 #30
0
파일: Ball.java 프로젝트: reshadf/Java
 public void paint(Graphics2D g2d) {
   Point p = getLocation();
   if (p != null) {
     g2d = (Graphics2D) g2d.create();
     g2d.setColor(Color.BLUE);
     Shape shape = getShape();
     int x = (int) p.x - (shape.getBounds().width / 2);
     int y = (int) p.y - (shape.getBounds().height / 2);
     g2d.translate(x, y);
     g2d.fill(shape);
     g2d.dispose();
   }
 }