示例#1
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);
  }
示例#2
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);
  }
  public static void renderSurface(
      Graphics g,
      Container c,
      Rectangle rect,
      boolean toSimulateRollover,
      boolean hasTopBorder,
      boolean hasBottomBorder) {
    CellRendererPane buttonRendererPane = new CellRendererPane();
    JButton rendererButton = new JButton("");
    rendererButton.getModel().setRollover(toSimulateRollover);

    buttonRendererPane.setBounds(rect.x, rect.y, rect.width, rect.height);
    Graphics2D g2d = (Graphics2D) g.create();
    g2d.clipRect(rect.x, rect.y, rect.width, rect.height);
    buttonRendererPane.paintComponent(
        g2d,
        rendererButton,
        c,
        rect.x - rect.width / 2,
        rect.y - rect.height / 2,
        2 * rect.width,
        2 * rect.height,
        true);

    g2d.setColor(FlamingoUtilities.getBorderColor());
    if (hasTopBorder) {
      g2d.drawLine(rect.x, rect.y, rect.x + rect.width - 1, rect.y);
    }
    if (hasBottomBorder) {
      g2d.drawLine(
          rect.x, rect.y + rect.height - 1, rect.x + rect.width - 1, rect.y + rect.height - 1);
    }
    g2d.dispose();
  }
    /**
     * Hook for subclassers to paint the background page(s).
     *
     * @param g2 The graphics object to paint the background page(s) on.
     */
    protected void paintBackgroundPages(Graphics2D g2) {
      Point2D p = graph.toScreen(new Point2D.Double(pageFormat.getWidth(), pageFormat.getHeight()));
      Dimension pSize = graph.getPreferredSize();
      int w = (int) (p.getX() * pageScale);
      int h = (int) (p.getY() * pageScale);
      int cols = (int) Math.max(Math.ceil((double) (pSize.width - 5) / (double) w), 1);
      int rows = (int) Math.max(Math.ceil((double) (pSize.height - 5) / (double) h), 1);
      g2.setColor(graph.getHandleColor());

      // Draws the pages.
      Point offset = getViewPosition();
      g2.translate(-offset.x, -offset.y);
      g2.fillRect(0, 0, graph.getWidth(), graph.getHeight());
      g2.setColor(Color.darkGray);
      g2.fillRect(3, 3, cols * w, rows * h);
      g2.setColor(getGraph().getBackground());
      g2.fillRect(1, 1, cols * w - 1, rows * h - 1);

      // Draws the pagebreaks.
      Stroke previousStroke = g2.getStroke();
      g2.setStroke(
          new BasicStroke(
              1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] {1, 2}, 0));
      g2.setColor(Color.darkGray);
      for (int i = 1; i < cols; i++) g2.drawLine(i * w, 1, i * w, rows * h - 1);
      for (int i = 1; i < rows; i++) g2.drawLine(1, i * h, cols * w - 1, i * h);

      // Restores the graphics.
      g2.setStroke(previousStroke);
      g2.translate(offset.x, offset.y);
      g2.clipRect(0, 0, cols * w - 1 - offset.x, rows * h - 1 - offset.y);
    }
示例#5
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);
 }
示例#6
0
 /** Restrict the draw area to the valid base coordinate space. */
 public void clip() {
   int x = (int) (projection.canvas.getWidth() * projection.canvas.margin);
   int y = (int) (projection.canvas.getHeight() * projection.canvas.margin);
   int w = (int) (projection.canvas.getWidth() * (1 - 2 * projection.canvas.margin));
   int h = (int) (projection.canvas.getHeight() * (1 - 2 * projection.canvas.margin));
   originalClip = g2d.getClip();
   g2d.clipRect(x, y, w, h);
 }
    @Override
    public void paint(Graphics2D graphics) {
      // Apply scroll bar styles to the button
      ScrollButton scrollButton = (ScrollButton) getComponent();
      ScrollBar scrollBar = (ScrollBar) TerraScrollBarSkin.this.getComponent();
      Orientation orientation = scrollBar.getOrientation();

      int width = getWidth();
      int height = getHeight();

      Color backgroundColor;
      if (scrollButton.isEnabled()) {
        if (pressed) {
          backgroundColor = scrollButtonPressedBackgroundColor;
        } else if (highlighted) {
          backgroundColor = scrollButtonHighlightedBackgroundColor;
        } else {
          backgroundColor = scrollButtonBackgroundColor;
        }
      } else {
        backgroundColor = scrollButtonDisabledBackgroundColor;
      }

      Color brightBackgroundColor = TerraTheme.brighten(backgroundColor);

      // Paint the background
      Color gradientStartColor = pressed ? backgroundColor : brightBackgroundColor;
      Color gradientEndColor = pressed ? brightBackgroundColor : backgroundColor;

      if (orientation == Orientation.HORIZONTAL) {
        graphics.setPaint(
            new GradientPaint(0, 1, gradientStartColor, 0, height - 2, gradientEndColor));
      } else {
        graphics.setPaint(
            new GradientPaint(1, 0, gradientStartColor, width - 2, 0, gradientEndColor));
      }

      graphics.fillRect(1, 1, width - 2, height - 2);

      // Paint the border
      graphics.setPaint(borderColor);
      GraphicsUtilities.drawRect(graphics, 0, 0, width, height);

      // Determine the button image size
      ScrollButtonImage buttonImage = scrollButton.getButtonImage();
      int buttonImageWidth = buttonImage.getWidth();
      int buttonImageHeight = buttonImage.getHeight();

      // Paint the image
      Graphics2D imageGraphics = (Graphics2D) graphics.create();
      int buttonImageX = (width - buttonImageWidth) / 2;
      int buttonImageY = (height - buttonImageHeight) / 2;
      imageGraphics.translate(buttonImageX, buttonImageY);
      imageGraphics.clipRect(0, 0, buttonImageWidth, buttonImageHeight);
      buttonImage.paint(imageGraphics);
      imageGraphics.dispose();
    }
示例#8
0
 public void paintChildren(ParentPanelBase panel, Graphics2D graphics) {
   if (panel.hasChildren()) {
     Box innards =
         panel instanceof PropPanel
             ? ((PropPanel) panel).getPaddedBounds()
             : panel.getChildConsumableBounds();
     graphics.clipRect(innards.x, innards.y, innards.width, innards.height);
     for (Panel child : panel.getChildren()) if (!child.isFloater()) paintChild(graphics, child);
     for (Panel child : panel.getChildren()) if (child.isFloater()) paintChild(graphics, child);
   }
 }
  /*
   * (non-Javadoc)
   *
   * @see javax.swing.Icon#paintIcon(java.awt.Component, java.awt.Graphics,
   * int, int)
   */
  @Override
  public void paintIcon(Component c, Graphics g, int x, int y) {
    Graphics2D g2d = (Graphics2D) g.create();
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.translate(x, y);

    double coef1 = (double) this.width / (double) getOrigWidth();
    double coef2 = (double) this.height / (double) getOrigHeight();
    double coef = Math.min(coef1, coef2);
    g2d.clipRect(0, 0, this.width, this.height);
    g2d.scale(coef, coef);
    paint(g2d);
    g2d.dispose();
  }
示例#10
0
  public static final void drawRoundImageV(
      Graphics2D g, Image src, int x, int y, int width, int height) {
    Shape rect = g.getClip();

    g.clipRect(x, y, width, height);

    int h = src.getHeight(null);

    for (int dy = 0; dy < height; ) {
      g.drawImage(src, x, y + dy, width, h, null);
      dy += h;
    }

    g.setClip(rect);
  }
示例#11
0
  public static final void drawRoundImageH(
      Graphics2D g, Image src, int x, int y, int width, int height) {
    Shape rect = g.getClip();

    g.clipRect(x, y, width, height);

    int w = src.getWidth(null);

    for (int dx = 0; dx < width; ) {
      g.drawImage(src, x + dx, y, w, height, null);
      dx += w;
    }

    g.setClip(rect);
  }
示例#12
0
  private void print() {
    Document document = new Document(PageSize.A4.rotate());
    try {
      PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("jTable.pdf"));

      document.open();
      PdfContentByte cb = writer.getDirectContent();

      cb.saveState();
      Graphics2D g2 = cb.createGraphicsShapes(500, 500);

      Shape oldClip = g2.getClip();
      g2.clipRect(0, 0, 500, 500);

      table.print(g2);
      g2.setClip(oldClip);

      g2.dispose();
      cb.restoreState();
    } catch (Exception e) {
      System.err.println(e.getMessage());
    }
    document.close();
  }
  protected void paintTab(
      Graphics g,
      int tabPlacement,
      Rectangle[] rects,
      int tabIndex,
      Rectangle iconRect,
      Rectangle textRect) {
    Rectangle tabRect = rects[tabIndex];
    int selectedIndex = tabPane.getSelectedIndex();
    boolean isSelected = selectedIndex == tabIndex;
    boolean isOver = overTabIndex == tabIndex;
    Graphics2D g2 = null;
    Shape save = null;
    boolean cropShape = false;
    int cropx = 0;
    int cropy = 0;

    if (g instanceof Graphics2D) {
      g2 = (Graphics2D) g;

      // Render visual for cropped tab edge...
      Rectangle viewRect = tabScroller.viewport.getViewRect();
      int cropline;

      cropline = viewRect.x + viewRect.width;
      if ((tabRect.x < cropline) && (tabRect.x + tabRect.width > cropline)) {

        cropx = cropline - 1;
        cropy = tabRect.y;
        cropShape = true;
      }

      if (cropShape) {
        save = g2.getClip();
        g2.clipRect(tabRect.x, tabRect.y, tabRect.width, tabRect.height);
      }
    }

    paintTabBackground(
        g, tabPlacement, tabIndex, tabRect.x, tabRect.y, tabRect.width, tabRect.height, isSelected);

    paintTabBorder(
        g, tabPlacement, tabIndex, tabRect.x, tabRect.y, tabRect.width, tabRect.height, isSelected);

    String title = tabPane.getTitleAt(tabIndex);
    Font font = tabPane.getFont();
    FontMetrics metrics = g.getFontMetrics(font);
    Icon icon = getIconForTab(tabIndex);

    layoutLabel(
        tabPlacement, metrics, tabIndex, title, icon, tabRect, iconRect, textRect, isSelected);

    paintText(g, tabPlacement, font, metrics, tabIndex, title, textRect, isSelected);

    paintIcon(g, tabPlacement, tabIndex, icon, iconRect, isSelected);

    paintFocusIndicator(g, tabPlacement, rects, tabIndex, iconRect, textRect, isSelected);

    if (cropShape) {
      paintCroppedTabEdge(g, tabPlacement, tabIndex, isSelected, cropx, cropy);
      g2.setClip(save);

    } else if (isOver || isSelected) {

      int dx = tabRect.x + tabRect.width - BUTTONSIZE - WIDTHDELTA;
      int dy = (tabRect.y + tabRect.height) / 2 - 6;

      if (isCloseButtonEnabled) paintCloseIcon(g2, dx, dy, isOver);
      if (isMaxButtonEnabled) paintMaxIcon(g2, dx, dy, isOver);
    }
  }
示例#14
0
    public int print(Graphics gc, PageFormat format, int pageIndex)
        throws java.awt.print.PrinterException {
      if (pageIndex > 0) {
        out("page " + pageIndex + " requested, ending print job.");
        return Printable.NO_SUCH_PAGE;
      }

      Dimension page =
          new Dimension(
              (int) format.getImageableWidth() - 1, (int) format.getImageableHeight() - 1);

      Graphics2D g = (Graphics2D) gc;

      out(
          "asked to render page "
              + pageIndex
              + " in "
              + outpf(format)
              + " w/transform "
              + g.getTransform());

      // note: supposedly, perhaps on Windows with JVM's 1.5 and newer, the
      // transform scale provided can actually allow us to derive the DPI of the
      // print device, which we could use for image rendering optimization's
      // during prints.  Mac OS X Snow Leopard w/JVM 1.6 always reports a 1.0
      // scale though.  And operations like "print preview" or "print to PDF"
      // wouldn't have a fixed DPI anyway.

      if (DEBUG.CONTAINMENT) {
        g.setColor(Color.lightGray);
        g.fillRect(0, 0, 9999, 9999);
      }

      g.translate(format.getImageableX(), format.getImageableY());

      // Don't need to clip if printing whole map, as computed zoom
      // should have made sure everything is within page size
      // if (!isPrintingView())
      // g.clipRect(0, 0, page.width, page.height);

      if (DEBUG.CONTAINMENT) {
        // g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
        // draw border outline of page
        g.setColor(Color.gray);
        g.setStroke(VueConstants.STROKE_TWO);
        g.drawRect(0, 0, page.width, page.height);
        // g.setComposite(AlphaComposite.Src);
      }

      // compute zoom & offset for visible map components
      Point2D.Float offset = new Point2D.Float();
      // center vertically only if landscape mode
      // if (format.getOrientation() == PageFormat.LANDSCAPE)
      // TODO: allow horizontal centering, but not vertical centering (handle in computeZoomFit)
      double scale = ZoomTool.computeZoomFit(page, 5, bounds, offset, true);
      out("rendering at scale " + scale);
      // set up the DrawContext
      DrawContext dc =
          new DrawContext(
              g, scale, -offset.x, -offset.y,
              null, // frame would be the PageFormat offset & size rectangle
              focal, false); // todo: absolute links shouldn't be spec'd here

      dc.setMapDrawing();
      dc.setPrintQuality();

      if (isPrintingView() && map == focal)
        g.clipRect(
            (int) Math.floor(bounds.getX()),
            (int) Math.floor(bounds.getY()),
            (int) Math.ceil(bounds.getWidth()),
            (int) Math.ceil(bounds.getHeight()));

      if (DEBUG.CONTAINMENT) {
        g.setColor(Color.red);
        g.setStroke(VueConstants.STROKE_TWO);
        g.draw(bounds);
      }

      // render the map
      if (map == focal) map.draw(dc);
      else focal.draw(dc);

      out("page " + pageIndex + " rendered.");
      return Printable.PAGE_EXISTS;
    }
  /*
   * (non-Javadoc)
   *
   * @see org.jvnet.flamingo.ribbon.ui.BasicRibbonUI#paintTaskArea(java.awt.
   * Graphics , int, int, int, int)
   */
  @Override
  protected void paintTaskArea(Graphics g, int x, int y, int width, int height) {
    if (this.ribbon.getTaskCount() == 0) return;

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

    RibbonTask selectedTask = this.ribbon.getSelectedTask();
    JRibbonTaskToggleButton selectedTaskButton = this.taskToggleButtons.get(selectedTask);
    Rectangle selectedTaskButtonBounds = selectedTaskButton.getBounds();
    Point converted =
        SwingUtilities.convertPoint(
            selectedTaskButton.getParent(), selectedTaskButtonBounds.getLocation(), this.ribbon);
    float radius =
        SubstanceSizeUtils.getClassicButtonCornerRadius(
            SubstanceSizeUtils.getComponentFontSize(this.ribbon));

    float borderDelta = SubstanceSizeUtils.getBorderStrokeWidth() / 2.0f;

    SubstanceBorderPainter borderPainter = SubstanceCoreUtilities.getBorderPainter(this.ribbon);
    float borderThickness = SubstanceSizeUtils.getBorderStrokeWidth();

    AbstractRibbonBand band = (selectedTask.getBandCount() == 0) ? null : selectedTask.getBand(0);
    SubstanceColorScheme borderScheme =
        SubstanceColorSchemeUtilities.getColorScheme(
            band, ColorSchemeAssociationKind.BORDER, ComponentState.ENABLED);

    Rectangle taskToggleButtonsViewportBounds =
        taskToggleButtonsScrollablePanel.getView().getParent().getBounds();
    taskToggleButtonsViewportBounds.setLocation(
        SwingUtilities.convertPoint(
            taskToggleButtonsScrollablePanel,
            taskToggleButtonsViewportBounds.getLocation(),
            this.ribbon));
    int startSelectedX = Math.max(converted.x + 1, (int) taskToggleButtonsViewportBounds.getMinX());
    startSelectedX = Math.min(startSelectedX, (int) taskToggleButtonsViewportBounds.getMaxX());
    int endSelectedX =
        Math.min(
            converted.x + selectedTaskButtonBounds.width - 1,
            (int) taskToggleButtonsViewportBounds.getMaxX());
    endSelectedX = Math.max(endSelectedX, (int) taskToggleButtonsViewportBounds.getMinX());

    Shape outerContour =
        RibbonBorderShaper.getRibbonBorderOutline(
            this.ribbon,
            x + borderDelta,
            x + width - borderDelta,
            startSelectedX - borderThickness,
            endSelectedX + borderThickness,
            converted.y + borderDelta,
            y + borderDelta,
            y + height - borderDelta,
            radius);

    Shape innerContour =
        RibbonBorderShaper.getRibbonBorderOutline(
            this.ribbon,
            x + borderDelta + borderThickness,
            x + width - borderThickness - borderDelta,
            startSelectedX - borderThickness,
            endSelectedX + borderThickness,
            converted.y + borderDelta + borderThickness,
            y + borderDelta + borderThickness,
            y + height - borderThickness - borderDelta,
            radius);

    g2d.setColor(
        SubstanceColorSchemeUtilities.getColorScheme(band, ComponentState.ENABLED)
            .getBackgroundFillColor());
    g2d.clipRect(x, y, width, height + 2);
    g2d.fill(outerContour);

    // g2d.setColor(Color.red);
    // g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
    // RenderingHints.VALUE_ANTIALIAS_ON);
    // g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
    // RenderingHints.VALUE_STROKE_PURE);
    // g2d.setStroke(new BasicStroke(0.5f));
    // g2d.draw(outerContour);
    // g2d.setColor(Color.blue);
    // g2d.draw(innerContour);
    borderPainter.paintBorder(
        g2d,
        this.ribbon,
        width,
        height + selectedTaskButtonBounds.height + 1,
        outerContour,
        innerContour,
        borderScheme);

    // check whether the currently selected task is a contextual task
    RibbonTask selected = selectedTask;
    RibbonContextualTaskGroup contextualGroup = selected.getContextualGroup();
    if (contextualGroup != null) {
      // paint a small gradient directly below the task area
      Insets ins = this.ribbon.getInsets();
      int topY = ins.top + getTaskbarHeight();
      int bottomY = topY + 5;
      Color hueColor = contextualGroup.getHueColor();
      Paint paint =
          new GradientPaint(
              0,
              topY,
              FlamingoUtilities.getAlphaColor(
                  hueColor, (int) (255 * RibbonContextualTaskGroup.HUE_ALPHA)),
              0,
              bottomY,
              FlamingoUtilities.getAlphaColor(hueColor, 0));
      g2d.setPaint(paint);
      g2d.clip(outerContour);
      g2d.fillRect(0, topY, width, bottomY - topY + 1);
    }

    // paint outlines of the contextual task groups
    // paintContextualTaskGroupsOutlines(g);

    g2d.dispose();
  }
示例#16
0
 public void clipRect(int x, int y, int width, int height) {
   g2d.clipRect(x, y, width, height);
 }
 public void clipRect(int x, int y, int width, int height) {
   hostGraphics.clipRect(x, y, width, height);
 }
 @Override
 public void paint(Graphics2D graphics) {
   graphics.translate(-bounds.x, -bounds.y);
   graphics.clipRect(bounds.x, bounds.y, bounds.width, bounds.height);
   tableView.paint(graphics);
 }