Exemplo n.º 1
0
  private void drawShape(Shuttle shuttle) {
    Graphics2D g = shuttle.g;
    Shape oldclip = shuttle.g.getClip();
    g.setClip(shuttle.clip);
    Composite oldcomposite = g.getComposite();
    if (shuttle.opacity != 1f) {
      g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, shuttle.opacity));
    }

    AffineTransform oldtr = g.getTransform();
    g.setTransform(shuttle.transform);

    Stroke oldStroke = g.getStroke();
    Stroke newStroke =
        new BasicStroke(shuttle.strokeWidth, shuttle.linecap.stroke(), shuttle.linejoin.stroke());
    g.setStroke(newStroke);

    if (shuttle.fill != null) {
      g.setPaint(shuttle.fill);
      g.fill(shuttle.shape);
    }
    if (shuttle.stroke != null) {
      g.setPaint(shuttle.stroke);
      g.draw(shuttle.shape);
    }
    g.setClip(oldclip);
    g.setStroke(oldStroke);
    g.setTransform(oldtr);
    g.setComposite(oldcomposite);
  }
  @Override
  public void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    //		System.out.println("GamePadPanel : paintComponent\t" + g2d.getClip().getBounds());

    // Use anti-aliasing
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    // Paint gamepad.png canvas.
    g2d.drawImage(biGamePad, 0, 0, null);

    // Next, paint screenshot image for currently selected game in shaped window.

    if (bLoadScreenshot) {
      // => Either program has just been loaded
      //	  Or user has changed selected game in Games listbox
      //	  Or user has installed a new game
      bLoadScreenshot = false;
      LoadScreenshotImage();
    }

    if (biScreenshot != null) {
      Shape correctClip = g2d.getClip();
      g2d.setClip(shapedScreenshot);
      g2d.drawImage(
          biScreenshot, scaledScrLeft, scaledScrTop, scaledScrWidth, scaledScrHeight, null);
      g2d.setClip(correctClip);
    }

    // No need to call super.paintComponent() as entire client area Gamepad panel will
    // be overwritten with gamepad.png. In other words, we are completely responsible
    // for drawing the client area.
  }
Exemplo n.º 3
0
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    int ptrPos = (int) (SIDE_PAD + (getWidth() - 2 * SIDE_PAD) * callback.getVolume() / MAX_VOLUME);

    final int x = 0;
    final int y = (PTR_HEIGHT - BAR_HEIGHT) / 2;
    int right = getWidth();

    g2.setClip(new RoundRectangle2D.Float(x, y, right - x, BAR_HEIGHT, ROUND, ROUND));
    g2.setPaint(new GradientPaint(0, y, Color.DARK_GRAY, 0, y + BAR_HEIGHT, Color.GRAY));
    g2.fillRect(x, y, ptrPos - x, BAR_HEIGHT);

    g2.setPaint(new GradientPaint(0, y, Color.LIGHT_GRAY, 0, y + BAR_HEIGHT, Color.WHITE));
    g2.fillRect(ptrPos, y, right - ptrPos, BAR_HEIGHT);
    g2.setClip(null);

    g2.setColor(Color.BLACK);
    g2.drawRoundRect(x, y, right - x - 1, BAR_HEIGHT, ROUND, ROUND);

    // Pointer
    int left = ptrPos - PTR_WIDTH / 2;

    final Color PTR_COLOR_1 = Color.WHITE;
    final Color PTR_COLOR_2 = Color.LIGHT_GRAY;

    g2.setPaint(new GradientPaint(left, 0, PTR_COLOR_1, left + PTR_WIDTH, 0, PTR_COLOR_2));
    g2.fillOval(left, 0, PTR_WIDTH, PTR_HEIGHT);
    g2.setColor(Color.BLACK);
    g2.drawOval(left, 0, PTR_WIDTH - 1, PTR_HEIGHT - 1);
  }
Exemplo n.º 4
0
  public void paintText(Graphics g, int x, int y, String title) {
    x += paintIcon(g, x, y);
    Graphics2D g2D = (Graphics2D) g;
    Shape savedClip = g2D.getClip();
    Color fc = AbstractLookAndFeel.getWindowTitleForegroundColor();
    if (fc.equals(Color.white)) {
      Color bc = AbstractLookAndFeel.getWindowTitleColorDark();
      g2D.setColor(bc);
      JTattooUtilities.drawString(rootPane, g, title, x - 1, y - 1);
      g2D.setColor(ColorHelper.darker(bc, 30));
      JTattooUtilities.drawString(rootPane, g, title, x + 1, y + 1);
    }
    g.setColor(fc);

    Area clipArea = new Area(new Rectangle2D.Double(x, 0, getWidth(), getHeight() / 2));
    clipArea.intersect(new Area(savedClip));
    g2D.setClip(clipArea);
    JTattooUtilities.drawString(rootPane, g, title, x, y);

    clipArea = new Area(new Rectangle2D.Double(x, (getHeight() / 2), getWidth(), getHeight()));
    clipArea.intersect(new Area(savedClip));
    g2D.setClip(clipArea);
    g.setColor(ColorHelper.darker(fc, 20));
    JTattooUtilities.drawString(rootPane, g, title, x, y);

    g2D.setClip(savedClip);
  }
Exemplo n.º 5
0
  @Override
  public void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    // Composite oldComposite = g2.getComposite();
    //
    // g2.setComposite(AlphaComposite.SrcOver.derive(0.5f));
    // g2.setColor(Color.darkGray);
    // g2.translate(6, 6);
    // g2.fill(cuadrado);
    //
    // g2.setComposite(oldComposite);
    // g2.translate(-6, -6);

    g2.drawImage(sombra, null, this);

    g2.setClip(new Rectangle2D.Float(0, 0, 262, 33));
    g2.setColor(new Color(0.51f, 0.51f, 0.51f, 0.3f));
    g2.fill(cuadrado);

    g2.setClip(new Rectangle2D.Float(0, 33, 262, 33));
    g2.setColor(new Color(0, 0, 0, 0.7f));
    g2.fill(cuadrado);

    g2.setClip(new Rectangle2D.Float(0, 0, this.getWidth(), this.getHeight()));
    g2.setColor(new Color(153, 153, 153));
    g2.setStroke(new BasicStroke(2));
    g2.draw(cuadrado);
  }
Exemplo n.º 6
0
 public static void fillComponent(Graphics g, Component c, int x, int y, int w, int h) {
   Graphics2D g2D = (Graphics2D) g;
   Shape savedClip = g2D.getClip();
   Area clipArea = new Area(new Rectangle2D.Double(x, y, w, h));
   clipArea.intersect(new Area(savedClip));
   g2D.setClip(clipArea);
   fillComponent(g, c);
   g2D.setClip(savedClip);
 }
Exemplo n.º 7
0
  /**
   * Draw every char in separate terminal cell to guaranty equal width for different lines.
   * Nevertheless to improve kerning we draw word characters as one block for monospaced fonts.
   */
  private void drawChars(int x, int y, CharBuffer buf, TextStyle style, Graphics2D gfx) {
    final int blockLen = 1;
    int offset = 0;
    int drawCharsOffset = 0;

    // workaround to fix Swing bad rendering of bold special chars on Linux
    // TODO required for italic?
    CharBuffer renderingBuffer;
    if (mySettingsProvider.DECCompatibilityMode() && style.hasOption(TextStyle.Option.BOLD)) {
      renderingBuffer = CharUtils.heavyDecCompatibleBuffer(buf);
    } else {
      renderingBuffer = buf;
    }

    while (offset + blockLen <= buf.length()) {
      if (renderingBuffer.getBuf()[buf.getStart() + offset] == CharUtils.DWC) {
        offset += blockLen;
        drawCharsOffset += blockLen;
        continue; // dont' draw second part(fake one) of double width character
      }

      Font font = getFontToDisplay(buf.charAt(offset + blockLen - 1), style);
      //      while (myMonospaced && (offset + blockLen < buf.getLength()) &&
      // isWordCharacter(buf.charAt(offset + blockLen - 1))
      //              && (font == getFontToDisplay(buf.charAt(offset + blockLen - 1), style))) {
      //        blockLen++;
      //      }
      gfx.setFont(font);

      int descent = gfx.getFontMetrics(font).getDescent();
      int baseLine = (y + 1) * myCharSize.height - descent;
      int xCoord = (x + drawCharsOffset) * myCharSize.width;
      int textLength =
          CharUtils.getTextLengthDoubleWidthAware(
              buf.getBuf(),
              buf.getStart() + offset,
              blockLen,
              mySettingsProvider.ambiguousCharsAreDoubleWidth());

      int yCoord = y * myCharSize.height;

      gfx.setClip(
          xCoord,
          yCoord,
          Math.min(textLength * myCharSize.width, getWidth() - xCoord),
          Math.min(myCharSize.height, getHeight() - yCoord));

      gfx.setColor(getPalette().getColor(myStyleState.getForeground(style.getForegroundForRun())));

      gfx.drawChars(renderingBuffer.getBuf(), buf.getStart() + offset, blockLen, xCoord, baseLine);

      drawCharsOffset += blockLen;
      offset += blockLen;
    }
    gfx.setClip(null);
  }
Exemplo n.º 8
0
  private void drawHistogramPane(Graphics2D g2d) {
    Shape oldClip = g2d.getClip();
    g2d.setClip(histoRect.x - 1, histoRect.y - 1, histoRect.width + 2, histoRect.height + 2);

    drawHistogram(g2d);
    drawGradationCurve(g2d);
    drawHistogramBorder(g2d);

    g2d.setClip(oldClip);
  }
Exemplo n.º 9
0
  /**
   * Paints the icon.
   *
   * @param c the component on which it is painted
   * @param _g the graphics context
   * @param x the x coordinate of the icon
   * @param y the y coordinate of the icon
   */
  public void paintIcon(Component c, Graphics _g, int x, int y) {
    Graphics2D g = (Graphics2D) _g;
    AffineTransform at = AffineTransform.getTranslateInstance(x + offsetX, y + offsetY);

    // save current graphics paint and clip
    Paint gPaint = g.getPaint();
    Shape gClip = g.getClip();

    // render shape(s)
    g.setPaint(color);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.clipRect(x, y, w, h);

    // paint shape, if any
    if (shape != null) {
      g.fill(at.createTransformedShape(shape));
    }

    // paint decoration, if any
    if (decoration != null) {
      g.setPaint(decoColor);
      g.fill(at.createTransformedShape(decoration));
    }
    // restore graphics paint and clip
    g.setPaint(gPaint);
    g.setClip(gClip);
  }
Exemplo n.º 10
0
  /**
   * Draws the background to the specified graphics device. If the dial frame specifies a window,
   * the clipping region will already have been set to this window before this method is called.
   *
   * @param g2 the graphics device (<code>null</code> not permitted).
   * @param plot the plot (ignored here).
   * @param frame the dial frame (ignored here).
   * @param view the view rectangle (<code>null</code> not permitted).
   */
  @Override
  public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    // work out the anchor point
    Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius, this.radius);
    Arc2D arc = new Arc2D.Double(f, this.angle, 0.0, Arc2D.OPEN);
    Point2D pt = arc.getStartPoint();

    // the indicator bounds is calculated from the templateValue (which
    // determines the minimum size), the maxTemplateValue (which, if
    // specified, provides a maximum size) and the actual value
    FontMetrics fm = g2.getFontMetrics(this.font);
    double value = plot.getValue(this.datasetIndex);
    String valueStr = this.formatter.format(value);
    Rectangle2D valueBounds = TextUtilities.getTextBounds(valueStr, g2, fm);

    // calculate the bounds of the template value
    String s = this.formatter.format(this.templateValue);
    Rectangle2D tb = TextUtilities.getTextBounds(s, g2, fm);
    double minW = tb.getWidth();
    double minH = tb.getHeight();

    double maxW = Double.MAX_VALUE;
    double maxH = Double.MAX_VALUE;
    if (this.maxTemplateValue != null) {
      s = this.formatter.format(this.maxTemplateValue);
      tb = TextUtilities.getTextBounds(s, g2, fm);
      maxW = Math.max(tb.getWidth(), minW);
      maxH = Math.max(tb.getHeight(), minH);
    }
    double w = fixToRange(valueBounds.getWidth(), minW, maxW);
    double h = fixToRange(valueBounds.getHeight(), minH, maxH);

    // align this rectangle to the frameAnchor
    Rectangle2D bounds =
        RectangleAnchor.createRectangle(new Size2D(w, h), pt.getX(), pt.getY(), this.frameAnchor);

    // add the insets
    Rectangle2D fb = this.insets.createOutsetRectangle(bounds);

    // draw the background
    g2.setPaint(this.backgroundPaint);
    g2.fill(fb);

    // draw the border
    g2.setStroke(this.outlineStroke);
    g2.setPaint(this.outlinePaint);
    g2.draw(fb);

    // now find the text anchor point
    Shape savedClip = g2.getClip();
    g2.clip(fb);

    Point2D pt2 = RectangleAnchor.coordinates(bounds, this.valueAnchor);
    g2.setPaint(this.paint);
    g2.setFont(this.font);
    TextUtilities.drawAlignedString(
        valueStr, g2, (float) pt2.getX(), (float) pt2.getY(), this.textAnchor);
    g2.setClip(savedClip);
  }
Exemplo n.º 11
0
  public void generarFondo(Component componente) {
    boolean dibujarFondo = false;
    Rectangle med = this.getBounds();
    Rectangle areaDibujo = this.getBounds();
    BufferedImage tmp;
    GraphicsConfiguration gc =
        GraphicsEnvironment.getLocalGraphicsEnvironment()
            .getDefaultScreenDevice()
            .getDefaultConfiguration();

    if (Principal.fondoBlur) {
      dibujarFondo = true;
    }
    if (dibujarFondo) {
      JRootPane root = SwingUtilities.getRootPane(this);
      blurBuffer = GraphicsUtilities.createCompatibleImage(Principal.sysAncho, Principal.sysAlto);
      Graphics2D g2 = blurBuffer.createGraphics();
      g2.setClip(med);
      blurBuffer = blurBuffer.getSubimage(med.x, med.y, med.width, med.height);
      ((Escritorio) Principal.getEscritorio()).getFrameEscritorio().paint(g2);
      g2.dispose();
      backBuffer = blurBuffer;
      // blurBuffer = toGrayScale(blurBuffer);
      blurBuffer = GraphicsUtilities.createThumbnailFast(blurBuffer, getWidth() / 2);
      blurBuffer = new GaussianBlurFilter(4).filter(blurBuffer, null);
      g2 = (Graphics2D) blurBuffer.getGraphics();
      g2.setColor(new Color(0, 0, 0, 195));
      g2.fillRect(0, 0, Principal.sysAncho, Principal.sysAlto);
      listo = true;
    }
  }
  public void exportReportToGraphics2D() throws JRException {
    grx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    // grx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    grx.setRenderingHint(
        RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
    grx.setRenderingHint(
        RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);

    AffineTransform atrans = new AffineTransform();
    atrans.translate(globalOffsetX, globalOffsetY);
    atrans.scale(zoom, zoom);
    grx.transform(atrans);

    java.util.List pages = jasperPrint.getPages();
    if (pages != null) {
      Shape oldClipShape = grx.getClip();

      grx.clip(new Rectangle(0, 0, jasperPrint.getPageWidth(), jasperPrint.getPageHeight()));

      try {
        JRPrintPage page = (JRPrintPage) pages.get(startPageIndex);
        exportPage(page);
      } finally {
        grx.setClip(oldClipShape);
      }
    }
  }
Exemplo n.º 13
0
 @Override
 public void draw(
     Graphics2D gfx,
     float dx,
     float dy,
     float dw,
     float dh,
     float sx,
     float sy,
     float sw,
     float sh) {
   // adjust our source rect to account for the scale factor
   sx *= scale.factor;
   sy *= scale.factor;
   sw *= scale.factor;
   sh *= scale.factor;
   // now render the image through a clip and with a scaling transform, so that only the desired
   // source rect is rendered, and is rendered into the desired target region
   float scaleX = dw / sw, scaleY = dh / sh;
   Shape oclip = gfx.getClip();
   gfx.clipRect(MathUtil.ifloor(dx), MathUtil.ifloor(dy), MathUtil.iceil(dw), MathUtil.iceil(dh));
   gfx.drawImage(
       img, new AffineTransform(scaleX, 0f, 0f, scaleY, dx - sx * scaleX, dy - sy * scaleY), null);
   gfx.setClip(oclip);
 }
Exemplo n.º 14
0
  public void paint(Graphics g) {
    if (scale == 0.0f) getScaledImages();
    double rollRad = roll * Math.PI / 180;
    // Center of Horizon Image
    Point ptRotation = new Point(125, 360);
    // Center of Instrument
    Point ptCenter = new Point(150, 150);
    // Modified Center of Rotation
    Point ptModRot = new Point(ptCenter.x - 2 * ptRotation.x, ptCenter.y - 2 * ptRotation.y);
    Graphics2D g2d = (Graphics2D) g;

    // Set bounds
    g2d.setClip(
        0,
        0,
        (int) (attitudeBackground.getWidth(null)),
        (int) (attitudeBackground.getHeight(null)));
    RotateAndTranslate(g2d, attitudeSky, rollRad, 0.0, ptModRot, 4 * pitch, ptRotation, scale);
    g2d.drawImage(
        attitudeMarker,
        Math.round(
            (float)
                ((0.5 * attitudeBackground.getWidth(null) - 0.5 * attitudeMarker.getWidth(null)))),
        Math.round(
            (float)
                ((0.5 * attitudeBackground.getHeight(null)
                    - 0.5 * attitudeMarker.getHeight(null)))),
        Math.round(attitudeMarker.getWidth(null)),
        Math.round(attitudeMarker.getHeight(null)),
        null);

    g2d.dispose();
    g.dispose();
  }
Exemplo n.º 15
0
  private void paintString(
      Graphics g, int x, int y, int width, int height, int fillStart, int amountFull, Insets b) {
    if (!(g instanceof Graphics2D)) {
      return;
    }

    Graphics2D g2D = (Graphics2D) g;
    String progressString = progressBar.getString();
    g2D.setFont(progressBar.getFont());
    Point renderLocation = getStringPlacement(g2D, progressString, x, y, width, height);
    Rectangle savedClip = g2D.getClipBounds();

    if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
      g2D.setColor(getSelectionBackground());
      Utilities.drawString(progressBar, g2D, progressString, renderLocation.x, renderLocation.y);
      g2D.setColor(getSelectionForeground());
      g2D.clipRect(fillStart, y, amountFull, height);
      Utilities.drawString(progressBar, g2D, progressString, renderLocation.x, renderLocation.y);
    } else { // VERTICAL
      g2D.setColor(getSelectionBackground());
      AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2);
      g2D.setFont(progressBar.getFont().deriveFont(rotate));
      renderLocation = getStringPlacement(g2D, progressString, x, y, width, height);
      Utilities.drawString(progressBar, g2D, progressString, renderLocation.x, renderLocation.y);
      g2D.setColor(getSelectionForeground());
      g2D.clipRect(x, fillStart, width, amountFull);
      Utilities.drawString(progressBar, g2D, progressString, renderLocation.x, renderLocation.y);
    }
    g2D.setClip(savedClip);
  }
Exemplo n.º 16
0
  /**
   * Paint to an offscreen graphic, e.g. a graphic for an image or svg file.
   *
   * @param g
   * @param rect
   */
  public void paintOffscreen(Graphics2D g, Rectangle rect) {

    // Get the components of the sort by X position.
    Component[] components = getComponents();
    Arrays.sort(
        components,
        new Comparator<Component>() {
          public int compare(Component component, Component component1) {
            return component.getX() - component1.getX();
          }
        });

    for (Component c : this.getComponents()) {

      if (c instanceof DataPanel) {
        Graphics2D g2d = (Graphics2D) g.create();
        Rectangle clipRect = new Rectangle(c.getBounds());
        clipRect.height = rect.height;
        g2d.setClip(clipRect);
        g2d.translate(c.getX(), 0);
        ((DataPanel) c).paintOffscreen(g2d, rect);
      }
    }
    // super.paintBorder(g);
  }
Exemplo n.º 17
0
  public void paintComponent(Graphics comp) {
    if (m_Image == null) {
      Cursor currentCursor = getCursor();
      try {
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        Dimension size = m_WorldMap.getMapSize();
        m_Image = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);
        Graphics2D g = (Graphics2D) m_Image.getGraphics();
        g.setClip(0, 0, size.width, size.height);
        m_WorldMap.draw(g, 0, 0, getDrawMode());
      } finally {
        setCursor(currentCursor);
      }
    }

    Graphics2D g2D = (Graphics2D) comp;
    g2D.drawImage(m_Image, null, 0, 0);

    boolean ShowHexNeighbours = true;
    if (m_CurrentSegment != -1) m_WorldMap.HighlightSegment(comp, m_CurrentSegment, true);
    if (m_CurrentSector != -1)
      m_WorldMap.HighlightSector(g2D, m_CurrentSector, true, ShowHexNeighbours);
    if (m_CurrentPath != null)
      m_WorldMap.HighlightPath(g2D, m_CurrentPath, true, ShowHexNeighbours);
  }
Exemplo n.º 18
0
  // documentation inherited
  protected void layout() {
    super.layout();

    // if we have no view yet, stop now
    if (_view == null) {
      return;
    }

    // avoid rerendering our HTML unless something changed
    int vwidth = getWidth() - getInsets().getHorizontal();
    int vheight = getHeight() - getInsets().getVertical();
    if (_rendered != null && _rsize != null && _rsize.width == vwidth && _rsize.height == vheight) {
      return;
    }

    BufferedImage image = new BufferedImage(vwidth, vheight, BufferedImage.TYPE_4BYTE_ABGR);
    Graphics2D gfx = image.createGraphics();
    _rsize = new Rectangle(0, 0, vwidth, vheight);
    try {
      gfx.setClip(_rsize);
      if (_antialias) {
        gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      }
      _view.paint(gfx, _rsize);
    } finally {
      gfx.dispose();
    }

    // TODO: render into a properly sized image in the first place and
    // create a JME Image directly
    _rendered = new Image(image);
  }
  /** paints the DrawComponent into the Graphics of the BufferedImage */
  protected void paintDrawComponent() {
    long startTime = 0;
    if (debugPaint) startTime = System.currentTimeMillis();

    if (bufferedImage != null) {
      Graphics2D g2d = (Graphics2D) bufferedImage.getGraphics();
      g2d.setRenderingHints(renderingHintsManager.getRenderingHints());
      g2d.setBackground(bgColor);
      g2d.setPaint(bgColor);
      g2d.translate(-bufferBounds.x, -bufferBounds.y);
      g2d.setClip(bufferBounds);
      g2d.fillRect(bufferBounds.x, bufferBounds.y, bufferBounds.width, bufferBounds.height);

      if (debugPaint) {
        drawRealRectangle(g2d);
        drawBufferRectangle(g2d);
        drawViewRectangle(g2d);
      }

      g2d.scale(scale, scale);
      DrawComponentPaintable.paintDrawComponent(dc, g2d);
    }

    if (debugPaint) {
      long endTime = System.currentTimeMillis() - startTime;
      logger.debug("paintDrawComponent took " + endTime + " ms!"); // $NON-NLS-1$ //$NON-NLS-2$
    }
  }
Exemplo n.º 20
0
  public void applyOn(IGraphics graphics) {
    Graphics2D g = ((DisplayGraphics) graphics).getGraphics2D();

    if (clippingArea != null) {
      g.setClip(Geometry2AWT.toAWTPath(clippingArea.toPath()));
    }
    g.setTransform(new java.awt.geom.AffineTransform(affineTransform.getMatrix()));
  }
Exemplo n.º 21
0
 protected void paintBackground(Graphics g, AbstractButton b) {
   if (!b.isContentAreaFilled() || (b.getParent() instanceof JMenuBar)) {
     return;
   }
   int width = b.getWidth();
   int height = b.getHeight();
   Graphics2D g2D = (Graphics2D) g;
   Shape savedClip = g.getClip();
   if ((b.getBorder() != null) && b.isBorderPainted() && (b.getBorder() instanceof UIResource)) {
     Area clipArea = new Area(new Rectangle2D.Double(1, 1, width - 2, height - 2));
     if (savedClip != null) {
       clipArea.intersect(new Area(savedClip));
     }
     g2D.setClip(clipArea);
   }
   super.paintBackground(g, b);
   g2D.setClip(savedClip);
 }
Exemplo n.º 22
0
  @Override
  public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    if (c.getParent() == null) return;

    Graphics2D graphics2d = (Graphics2D) g;
    graphics2d.setRenderingHints(hints);
    graphics2d.setColor(c.getParent().getBackground());

    int padTop = margin.top;
    int padLeft = margin.left;
    int padBottom = margin.bottom;
    int padRight = margin.right;

    // Quick fill of the padding area
    graphics2d.fillRect(0, 0, width, padTop);
    graphics2d.fillRect(0, height - padBottom, width, padBottom);
    graphics2d.fillRect(0, padTop, padLeft, height - padTop - padBottom);
    graphics2d.fillRect(width - padRight, padTop, padRight, height - padTop - padBottom);

    if (!noTopBevel) {
      graphics2d.translate(padLeft, padTop);
      graphics2d.setClip(0, 0, radii, radii);
      graphics2d.fill(clipFull);

      graphics2d.translate(width - padRight - 2 * radii - padLeft, 0);
      graphics2d.setClip(radii, 0, radii, radii);
      graphics2d.fill(clipFull);

      // Restore translation
      graphics2d.translate(-width + padRight + 2 * radii, -padTop);
    }
    if (!noBottomBevel) {
      graphics2d.translate(padLeft, height - padBottom - 2 * radii);
      graphics2d.setClip(0, radii, radii, radii);
      graphics2d.fill(clipFull);

      graphics2d.translate(width - padRight - 2 * radii - padLeft, 0);
      graphics2d.setClip(radii, radii, radii, radii);
      graphics2d.fill(clipFull);

      // Restore translation
      graphics2d.translate(-width + padRight + 2 * radii, -height + padBottom + 2 * radii);
    }
  }
Exemplo n.º 23
0
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    int ptrPos;
    if (seq == null || seq.getLength() == 0) {
      ptrPos = 0;
    } else {
      ptrPos =
          (int) (SIDE_PAD + (getWidth() - 2 * SIDE_PAD) * seq.getThumbPosition() / seq.getLength());
    }

    final int x = SIDE_PAD;
    final int y = (PTR_HEIGHT - BAR_HEIGHT) / 2;
    int right = getWidth() - SIDE_PAD;

    g2.setClip(new RoundRectangle2D.Float(x, y, right - x, BAR_HEIGHT, ROUND, ROUND));
    g2.setPaint(new GradientPaint(0, y, Color.DARK_GRAY, 0, y + BAR_HEIGHT, Color.GRAY));
    g2.fillRect(x, y, ptrPos - x, BAR_HEIGHT);

    g2.setPaint(new GradientPaint(0, y, Color.LIGHT_GRAY, 0, y + BAR_HEIGHT, Color.WHITE));
    g2.fillRect(ptrPos, y, right - ptrPos, BAR_HEIGHT);
    g2.setClip(null);

    g2.setColor(Color.BLACK);
    g2.drawRoundRect(x, y, right - x - 1, BAR_HEIGHT, ROUND, ROUND);

    if ((mouseHovering || seq.isDragging()) && this.isEnabled()) {
      int left = ptrPos - PTR_WIDTH / 2;

      final Color PTR_COLOR_1 = Color.WHITE;
      final Color PTR_COLOR_2 = Color.LIGHT_GRAY;

      g2.setPaint(new GradientPaint(left, 0, PTR_COLOR_1, left + PTR_WIDTH, 0, PTR_COLOR_2));
      g2.fillOval(left, 0, PTR_WIDTH, PTR_HEIGHT);
      g2.setColor(Color.BLACK);
      g2.drawOval(left, 0, PTR_WIDTH - 1, PTR_HEIGHT - 1);
    }
  }
Exemplo n.º 24
0
  public void setProjectionBounds(ProjectionBounds bounds) {
    view_bounds = bounds;

    if (bounds.maxEast - bounds.minEast > max_east_west) {
      max_east_west = bounds.maxEast - bounds.minEast;

      /* We need to set the parent MapView's bounds (i.e.
       * zoom level) to the same as ours max possible
       * bounds to avoid WMSLayer thinking we're zoomed
       * out more than we are or it'll pop up an annoying
       * "requested area is too large" popup.
       */
      EastNorth parent_center = parent.getCenter();
      parent.zoomTo(
          new ProjectionBounds(
              new EastNorth(parent_center.east() - max_east_west / 2, parent_center.north()),
              new EastNorth(parent_center.east() + max_east_west / 2, parent_center.north())));

      /* Request again because NavigatableContent adds
       * a border just to be sure.
       */
      ProjectionBounds new_bounds = parent.getProjectionBounds();
      max_east_west = new_bounds.maxEast - new_bounds.minEast;
    }

    Point vmin = getPoint(bounds.getMin());
    Point vmax = getPoint(bounds.getMax());
    int w = vmax.x + 1;
    int h = vmin.y + 1;

    if (w <= ground_width && h <= ground_height) {
      graphics.setClip(0, 0, w, h);
      return;
    }

    if (w > ground_width) ground_width = w;
    if (h > ground_height) ground_height = h;

    ground_image = new BufferedImage(ground_width, ground_height, BufferedImage.TYPE_INT_RGB);
    graphics = ground_image.createGraphics();
    graphics.setClip(0, 0, w, h);
  }
Exemplo n.º 25
0
  @Override
  protected void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setColor(new Color(255, 255, 255, 140));
    g2d.fillRoundRect(3, 3, getWidth() - 7, getHeight() - 7, 20, 20);

    g2d.setColor(Color.white);
    g2d.setClip(0, 0, getWidth(), 30);
    g2d.fillRoundRect(1, 3, getWidth() - 2, getHeight() - 1, 20, 20);
    g2d.setClip(null);

    g2d.setColor(Color.DARK_GRAY);
    g2d.setStroke(new BasicStroke(6));
    g2d.drawRoundRect(3, 3, getWidth() - 7, getHeight() - 7, 20, 20);

    g2d.setFont(new Font("Consolas", Font.BOLD, 16));
    g2d.setColor(Color.DARK_GRAY);
    g2d.drawString("Swing UI Test", 15, 24);
  }
  private void renderTile(TileNode tileNode, Graphics2D g, float opacity) {

    // Do the actual Drawing here!
    Polygon tilePolygon = getHexTile(tileNode.pixelPoint);
    g.setColor(Color.BLACK);
    g.drawPolygon(
        tilePolygon); // This part kinda helps the tiles come together. Due to the math involved in
                      // rendering
    // The hex tiles, there are a few points where we have to cast to an int and lose precision.

    // Get the old clip (Should be the entire window).
    Shape oldClip = g.getClip();

    // Set the clip to just the hex tile
    g.setClip(tilePolygon);

    // Set the opacity.
    AlphaComposite acomp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity);
    g.setComposite(acomp);

    // Render the tile image.
    Image tileImage = tileNode.tile.getTileImage();
    int tileX = (int) (tileNode.pixelPoint.getX() - hexWidth / 2);
    int tileY = (int) (tileNode.pixelPoint.getY()) - hexHeight / 2;
    g.drawImage(tileImage, tileX, tileY, hexWidth, hexHeight, getDisplay());

    // Add this entity to list of entities and their locations to render its health later alligator
    if (tileNode.tile.getEntity() != null) {
      Entity entity = tileNode.tile.getEntity();
      Stats stats = entity.getStats();
      this.entityLocationTuples.add(
          new EntityLocationTuple(
              entity,
              new Point((int) tileNode.pixelPoint.getX(), (int) tileNode.pixelPoint.getY())));
      this.entityHealthMap.put(entity, stats.getStat(Stats.Type.HEALTH));
    }

    g.setClip(oldClip);
  }
  /** Part of print code coped from Sun */
  public void printTablePart(Graphics2D g2, PageFormat pageFormat, int rowIndex, int columnIndex) {

    String pageNumber = "Page: " + (rowIndex + 1);
    if (subTableSplitSize > 1) {
      pageNumber += "-" + (columnIndex + 1);
    }

    int pageLeft = subTableSplit[columnIndex];
    int pageRight = subTableSplit[columnIndex + 1];

    int pageWidth = pageRight - pageLeft;

    // page number message (in smaller type)
    g2.setFont(new Font(g2.getFont().getName(), g2.getFont().getStyle(), 8));
    g2.drawString(pageNumber, pageWidth / 2 - 35, (int) (pageHeight - fontHeight));

    double clipHeight =
        Math.min(tableHeightOnFullPage, tableHeight - rowIndex * tableHeightOnFullPage);

    g2.translate(-subTableSplit[columnIndex], 0);
    g2.setClip(pageLeft, 0, pageWidth, (int) headerHeight);

    g2.scale(scale, scale);
    tableHeader.paint(g2); // draw the header on every page
    g2.scale(1 / scale, 1 / scale);
    g2.translate(0, headerHeight);
    g2.translate(0, -tableHeightOnFullPage * rowIndex);

    // cut table image and draw on the page

    g2.setClip(pageLeft, (int) tableHeightOnFullPage * rowIndex, pageWidth, (int) clipHeight);
    g2.scale(scale, scale);
    _table.paint(g2);
    g2.scale(1 / scale, 1 / scale);

    double pageTop = tableHeightOnFullPage * rowIndex - headerHeight;
    //		double pageBottom = pageTop +  clipHeight + headerHeight;
    g2.drawRect(pageLeft, (int) pageTop, pageWidth, (int) (clipHeight + headerHeight));
  }
Exemplo n.º 28
0
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   if (w.n == Player) {
     sendInfo();
   }
   if (valid()) {
     if (ok) {
       changePlayer();
       ok = false;
       if (bile[0].bila == null) bile[0] = new Bila(x, y, this);
       if (w.n > 0) sendInfo();
     }
   }
   g.drawImage(masa, 0, 0, null);
   Graphics2D g2 = (Graphics2D) g;
   g2.setColor(new Color(0xC0C0C0));
   g2.fillRect(103, 15, 70, 23);
   g2.setColor(Color.BLACK);
   g2.setFont(new Font("Algerian", Font.ITALIC, 20));
   g2.drawString("Player" + Player, 100, 32);
   g2.setColor(Color.WHITE);
   g2.setFont(new Font("Algerian", Font.BOLD, 40));
   g2.drawString("Russian Billiard", 230, 50);
   g2.setColor(Color.GRAY);
   g2.fillRect(12, 443, 286, 25);
   g2.fillRect(341, 443, 286, 25);
   for (int i = 1; i < bile.length; i++)
     g2.drawImage(bBall, (int) bile[i].xp - dim, (int) bile[i].yp - dim, DIM, DIM, null);
   g2.setColor(Color.DARK_GRAY);
   g2.setStroke(new BasicStroke(6));
   g2.drawRoundRect(12, 443, 286, 25, 3, 3);
   g2.drawRoundRect(341, 443, 286, 25, 3, 3);
   g2.clip(new Ellipse2D.Double(17, 15, 77, 77));
   for (int i = 0; i < Putere; i++) {
     g2.setColor(new Color(6 * i, 200, 255 - 6 * i));
     g2.fill3DRect(17, 91 - i * d, 77, d, true);
   }
   g2.setClip(null);
   g2.setStroke(new BasicStroke());
   if (bile[0].bila != null)
     g2.drawImage(rBall, (int) bile[0].xp - dim, (int) bile[0].yp - dim, DIM, DIM, null);
   if (Tinta != null) {
     g2.rotate(Math.atan2(Tinta.y - bile[0].yp, Tinta.x - bile[0].xp), bile[0].xp, bile[0].yp);
     g2.drawImage(cue, (int) bile[0].xp + dim + Putere, (int) bile[0].yp - dim / 3, 200, 10, null);
   }
   if (player[0] == 6 || player[1] == 6 || (player[0] == 5 && player[1] == 5)) {
     for (int i = 0; i < bile.length; i++) bile[i].stop();
     reset();
   }
 }
Exemplo n.º 29
0
 /*
  *  Create a BufferedImage for Swing components.
  *  All or part of the component can be captured to an image.
  *
  *  @param	 component Swing component to create image from
  *  @param	 region The region of the component to be captured to an image
  *  @param	 fileName name of file to be created or null
  *  @return	image the image for the given region
  *  @exception IOException if an error occurs during writing
  */
 public static BufferedImage createImage(JComponent component, Rectangle region, String fileName)
     throws IOException {
   boolean opaqueValue = component.isOpaque();
   component.setOpaque(true);
   BufferedImage image =
       new BufferedImage(region.width, region.height, BufferedImage.TYPE_INT_RGB);
   Graphics2D g2d = image.createGraphics();
   g2d.setClip(region);
   component.paint(g2d);
   g2d.dispose();
   component.setOpaque(opaqueValue);
   ScreenCapture.writeImage(image, fileName);
   return image;
 }
Exemplo n.º 30
0
  public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    if (!(g instanceof Graphics2D)) {
      return;
    }

    Graphics2D g2 = (Graphics2D) g.create();

    int[] widths = getWidths();

    // Position and size of the border interior.
    int intX = x + widths[LEFT];
    int intY = y + widths[TOP];
    int intWidth = width - (widths[RIGHT] + widths[LEFT]);
    int intHeight = height - (widths[TOP] + widths[BOTTOM]);

    // Coordinates of the interior corners, from NW clockwise.
    int[][] intCorners = {
      {intX, intY},
      {intX + intWidth, intY},
      {intX + intWidth, intY + intHeight},
      {
        intX, intY + intHeight,
      },
    };

    // Draw the borders for all sides.
    for (int i = 0; i < 4; i++) {
      Value style = getBorderStyle(i);
      Polygon shape = getBorderShape(i);
      if ((style != Value.NONE) && (shape != null)) {
        int sideLength = (i % 2 == 0 ? intWidth : intHeight);

        // "stretch" the border shape by the interior area dimension
        shape.xpoints[2] += sideLength;
        shape.xpoints[3] += sideLength;
        Color color = getBorderColor(i);
        BorderPainter painter = getBorderPainter(i);

        double angle = i * Math.PI / 2;
        g2.setClip(g.getClip()); // Restore initial clip
        g2.translate(intCorners[i][0], intCorners[i][1]);
        g2.rotate(angle);
        g2.clip(shape);
        painter.paint(shape, g2, color, i);
        g2.rotate(-angle);
        g2.translate(-intCorners[i][0], -intCorners[i][1]);
      }
    }
    g2.dispose();
  }