public void paint(Graphics g, JComponent c) {
    if (grid.getRowCount() <= 0 || grid.getColumnCount() <= 0) {
      return; // nothing to paint
    }

    Rectangle clip = g.getClipBounds();
    Point minLocation = clip.getLocation();
    Point maxLocation = new Point(clip.x + clip.width - 1, clip.y + clip.height - 1);
    int rowMin = grid.rowAtPoint(minLocation);
    int rowMax = grid.rowAtPoint(maxLocation);
    // This should never happen.
    if (rowMin == -1) {
      rowMin = 0;
    }
    // If the spread does not have enough rows to fill the view we'll get -1.
    // Replace this with the index of the last row.
    if (rowMax == -1) {
      rowMax = grid.getRowCount() - 1;
    }
    int colMin = grid.columnAtPoint(minLocation);
    int colMax = grid.columnAtPoint(maxLocation);
    // This should never happen.
    if (colMin == -1) {
      colMin = 0;
    }
    // If the spread does not have enough columns to fill the view we'll get -1.
    // Replace this with the index of the last column.
    if (colMax == -1) {
      colMax = grid.getColumnCount() - 1;
    }

    // Paint cells
    paintCells(g, rowMin, rowMax, colMin, colMax);

    // Paint grid
    paintGrid(g, rowMin, rowMax, colMin, colMax);

    // Paint spans
    paintSpans(g, rowMin, rowMax, colMin, colMax);

    // Paint borders
    paintBorders(g, rowMin, rowMax, colMin, colMax);

    // Paint editor
    paintEditor(g);
  }
  public void paint(Graphics g) {
    // repaint the whole transformer in case the view component was repainted
    Rectangle clipBounds = g.getClipBounds();
    if (clipBounds != null && !clipBounds.equals(visibleRect)) {
      repaint();
    }
    // clear the background
    g.setColor(getBackground());
    g.fillRect(0, 0, getWidth(), getHeight());

    if (view != null && at.getDeterminant() != 0) {
      Graphics2D g2 = (Graphics2D) g.create();
      Insets insets = getInsets();
      Rectangle bounds = getBounds();

      // don't forget about insets
      bounds.x += insets.left;
      bounds.y += insets.top;
      bounds.width -= insets.left + insets.right;
      bounds.height -= insets.top + insets.bottom;
      double centerX1 = bounds.getCenterX();
      double centerY1 = bounds.getCenterY();

      Rectangle tb = getTransformedSize();
      double centerX2 = tb.getCenterX();
      double centerY2 = tb.getCenterY();

      // set antialiasing by default
      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      if (renderingHints != null) {
        g2.addRenderingHints(renderingHints);
      }
      // translate it to the center of the view component again
      double tx = centerX1 - centerX2 - getX();
      double ty = centerY1 - centerY2 - getY();
      g2.translate((int) tx, (int) ty);
      g2.transform(at);
      view.paint(g2);
      g2.dispose();
    }
    // paint the border
    paintBorder(g);
  }
  /** special paint handler for merged cell regions */
  protected void paintSpans(Graphics g, int rowMin, int rowMax, int colMin, int colMax) {
    Rectangle clip = g.getClipBounds();
    Iterator cell = grid.getSpanModel().getSpanIterator();
    while (cell.hasNext()) {
      CellSpan span = (CellSpan) cell.next();
      Rectangle cellBounds = grid.getCellBounds(span.getRow(), span.getColumn());

      // Only paint cell if visible
      if (span.getLastRow() >= rowMin
          && span.getLastColumn() >= colMin
          && span.getFirstRow() <= rowMax
          && span.getFirstColumn() <= colMax) {
        paintCell(g, cellBounds, span.getRow(), span.getColumn());
        // Paint grid line around cell
        if (grid.getShowGrid()) {
          g.setColor(grid.getGridColor());
          g.drawRect(cellBounds.x, cellBounds.y, cellBounds.width, cellBounds.height);
        }
      }
    }
  }
示例#4
0
  public void paint(Graphics g) {
    Rectangle r = g.getClipBounds();

    showStatus("x: " + r.x + " y: " + r.y + " w: " + r.width + " h: " + r.height);

    for (int i = 0; i < numRects; i++) {
      Point lhc = randomPoint(); // left hand corner
      Dimension size = randomDimension();

      g.setColor(colors[(int) (Math.random() * 10)]);

      if (round) {
        if (fill)
          g.fillRoundRect(
              lhc.x,
              lhc.y,
              size.width,
              size.height,
              (int) (Math.random() * 250),
              (int) (Math.random() * 250));
        else
          g.drawRoundRect(
              lhc.x,
              lhc.y,
              size.width,
              size.height,
              (int) (Math.random() * 250),
              (int) (Math.random() * 250));
      } else if (threeD) {
        g.setColor(Color.lightGray);

        if (fill) g.fill3DRect(lhc.x, lhc.y, size.width, size.height, raise);
        else g.draw3DRect(lhc.x, lhc.y, size.width, size.height, raise);
      } else {
        if (fill) g.fillRect(lhc.x, lhc.y, size.width, size.height);
        else g.drawRect(lhc.x, lhc.y, size.width, size.height);
      }
      raise = raise ? false : true;
    }
  }
示例#5
0
  /** Draw the line numbers */
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    //	Determine the width of the space available to draw the line number

    FontMetrics fontMetrics = component.getFontMetrics(component.getFont());
    Insets insets = getInsets();
    int availableWidth = getSize().width - insets.left - insets.right;

    //  Determine the rows to draw within the clipped bounds.

    Rectangle clip = g.getClipBounds();
    int rowStartOffset = component.viewToModel(new Point(0, clip.y));
    int endOffset = component.viewToModel(new Point(0, clip.y + clip.height));

    while (rowStartOffset <= endOffset) {
      try {
        if (isCurrentLine(rowStartOffset)) g.setColor(getCurrentLineForeground());
        else g.setColor(getForeground());

        //  Get the line number as a string and then determine the
        //  "X" and "Y" offsets for drawing the string.

        String lineNumber = getTextLineNumber(rowStartOffset);
        int stringWidth = fontMetrics.stringWidth(lineNumber);
        int x = getOffsetX(availableWidth, stringWidth) + insets.left;
        int y = getOffsetY(rowStartOffset, fontMetrics);
        g.drawString(lineNumber, x, y);

        //  Move to the next row

        rowStartOffset = Utilities.getRowEnd(component, rowStartOffset) + 1;
      } catch (Exception e) {
      }
    }
  }
示例#6
0
  /* (non-Javadoc)
   * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
   */
  protected void paintComponent(Graphics arg0) {
    // long time1 = System.currentTimeMillis();
    try {
      super.paintComponent(arg0);
      if (this.isOpaque()) {
        Rectangle clipBounds = arg0.getClipBounds();
        arg0.setColor(this.getBackground());
        arg0.fillRect(clipBounds.x, clipBounds.y, clipBounds.width, clipBounds.height);
      }
      this.rblock.paint(arg0);

      // Paint FrameContext selection

      RenderablePoint start = this.startSelection;
      RenderablePoint end = this.endSelection;
      if (start != null && end != null && !start.equals(end)) {
        this.rblock.paintSelection(arg0, false, start, end);
      }
    } finally {
      // long time2 = System.currentTimeMillis();
      // System.out.println("NonScrollableHtmlPanel.paintComponent(): numRenderables=" +
      // numRenderables + ",time=" + (time2 - time1) + " ms.");
    }
  }
示例#7
0
  /**
   * Paint the image onto a Graphics object. The painting is performed tile-by-tile, and includes a
   * grey region covering the unused portion of image tiles as well as the general background. At
   * this point the image must be byte data.
   */
  public synchronized void paintComponent(Graphics g) {

    Graphics2D g2D = null;
    if (g instanceof Graphics2D) {
      g2D = (Graphics2D) g;
    } else {
      return;
    }

    // if source is null, it's just a component
    if (source == null) {
      g2D.setColor(getBackground());
      g2D.fillRect(0, 0, componentWidth, componentHeight);
      return;
    }

    int transX = -originX;
    int transY = -originY;

    // Get the clipping rectangle and translate it into image coordinates.
    Rectangle clipBounds = g.getClipBounds();

    if (clipBounds == null) {
      clipBounds = new Rectangle(0, 0, componentWidth, componentHeight);
    }

    // clear the background (clip it) [minimal optimization here]
    if (transX > 0
        || transY > 0
        || transX < (componentWidth - source.getWidth())
        || transY < (componentHeight - source.getHeight())) {
      g2D.setColor(getBackground());
      g2D.fillRect(0, 0, componentWidth, componentHeight);
    }

    clipBounds.translate(-transX, -transY);

    // Determine the extent of the clipping region in tile coordinates.
    int txmin, txmax, tymin, tymax;
    int ti, tj;

    txmin = XtoTileX(clipBounds.x);
    txmin = Math.max(txmin, minTileX);
    txmin = Math.min(txmin, maxTileX);

    txmax = XtoTileX(clipBounds.x + clipBounds.width - 1);
    txmax = Math.max(txmax, minTileX);
    txmax = Math.min(txmax, maxTileX);

    tymin = YtoTileY(clipBounds.y);
    tymin = Math.max(tymin, minTileY);
    tymin = Math.min(tymin, maxTileY);

    tymax = YtoTileY(clipBounds.y + clipBounds.height - 1);
    tymax = Math.max(tymax, minTileY);
    tymax = Math.min(tymax, maxTileY);
    Insets insets = getInsets();

    // Loop over tiles within the clipping region
    for (tj = tymin; tj <= tymax; tj++) {
      for (ti = txmin; ti <= txmax; ti++) {
        int tx = TileXtoX(ti);
        int ty = TileYtoY(tj);

        Raster tile = source.getTile(ti, tj);
        if (tile != null) {
          DataBuffer dataBuffer = tile.getDataBuffer();

          WritableRaster wr = tile.createWritableRaster(sampleModel, dataBuffer, null);

          BufferedImage bi =
              new BufferedImage(colorModel, wr, colorModel.isAlphaPremultiplied(), null);

          // correctly handles band offsets
          if (brightnessEnabled == true) {
            SampleModel sm =
                sampleModel.createCompatibleSampleModel(tile.getWidth(), tile.getHeight());

            WritableRaster raster = RasterFactory.createWritableRaster(sm, null);

            BufferedImage bimg =
                new BufferedImage(colorModel, raster, colorModel.isAlphaPremultiplied(), null);

            // don't move this code
            ByteLookupTable lutTable = new ByteLookupTable(0, lutData);
            LookupOp lookup = new LookupOp(lutTable, null);
            lookup.filter(bi, bimg);

            g2D.drawImage(bimg, biop, tx + transX + insets.left, ty + transY + insets.top);
          } else {
            AffineTransform transform;

            transform =
                AffineTransform.getTranslateInstance(
                    tx + transX + insets.left, ty + transY + insets.top);

            g2D.drawRenderedImage(bi, transform);
          }
        }
      }
    }
  }
  public void paint(Graphics g, JComponent c) {
    if ((header == null)
        || (header.getTable() == null)
        || header.getColumnModel().getColumnCount() <= 0) {
      return;
    }

    boolean ltr = header.getComponentOrientation().isLeftToRight();
    Rectangle clip = g.getClipBounds();
    Point left = clip.getLocation();
    Point right = new Point(clip.x + clip.width - 1, clip.y);
    TableColumnModel cm = header.getColumnModel();
    int cMin = header.columnAtPoint(ltr ? left : right);
    int cMax = header.columnAtPoint(ltr ? right : left);
    // This should never happen.
    if (cMin == -1) {
      cMin = 0;
    }
    // If the table does not have enough columns to fill the view we'll get -1.
    // Replace this with the index of the last column.
    if (cMax == -1) {
      cMax = cm.getColumnCount() - 1;
    }

    TableColumn draggedColumn = header.getDraggedColumn();
    Rectangle cellRect = header.getHeaderRect(ltr ? cMin : cMax);
    int columnWidth;
    TableColumn aColumn;
    if (ltr) {
      for (int column = cMin; column <= cMax; column++) {
        aColumn = cm.getColumn(column);
        columnWidth = aColumn.getWidth();
        cellRect.width = columnWidth;
        if (aColumn != draggedColumn) {
          paintCell(g, cellRect, column);
        }
        cellRect.x += columnWidth;
      }
    } else {
      for (int column = cMax; column >= cMin; column--) {
        aColumn = cm.getColumn(column);
        columnWidth = aColumn.getWidth();
        cellRect.width = columnWidth;
        if (aColumn != draggedColumn) {
          paintCell(g, cellRect, column);
        }
        cellRect.x += columnWidth;
      }
    }

    // Paint the dragged column if we are dragging.
    if (draggedColumn != null) {
      int draggedColumnIndex = viewIndexForColumn(draggedColumn);
      Rectangle draggedCellRect = header.getHeaderRect(draggedColumnIndex);
      // Draw a gray well in place of the moving column.
      g.setColor(header.getParent().getBackground());
      g.fillRect(
          draggedCellRect.x, draggedCellRect.y, draggedCellRect.width, draggedCellRect.height);
      draggedCellRect.x += header.getDraggedDistance();

      // Fill the background.
      g.setColor(header.getBackground());
      g.fillRect(
          draggedCellRect.x, draggedCellRect.y, draggedCellRect.width, draggedCellRect.height);
      paintCell(g, draggedCellRect, draggedColumnIndex);
    }

    // Remove all components in the rendererPane.
    rendererPane.removeAll();
  }
示例#9
0
    public void paintComponent(Graphics g) {
      Rectangle selection = g.getClipBounds();

      // clear out the image
      Graphics2D g2 = (Graphics2D) g;
      g2.setBackground(backgroundColor);
      g2.clearRect(
          (int) selection.getX(),
          (int) selection.getY(),
          (int) selection.getWidth(),
          (int) selection.getHeight());

      // draw the selection if it exists
      if (selBeginPixel != -1 && selEndPixel != -1) {
        g2.setBackground(selectionColor);
        g2.clearRect(selBeginPixel, 0, selEndPixel - selBeginPixel + 1, this.getHeight());
      }

      if (this.points.size() > 0) {
        g2.setColor(waveColor);
        // draw the lines
        if (this.points.size() > stemThresh) {
          if (points.size() > frameWidth) { // draw contour
            // g2.setStroke(thickerStroke);
            for (int i = 0; i < this.points.size() - 1; i += 4) {
              Point2D.Float pt1 = points.get(i).getDispPoint();
              // Point2D.Float pt2  = new Point2D.Float(pt1.x, pt1.y/2);
              Point2D.Float pt2 = points.get(i + 1).getDispPoint();
              Point2D.Float pt3 = points.get(i + 2).getDispPoint();
              Point2D.Float pt4 = points.get(i + 3).getDispPoint();

              //							//Point2D.Float pt4  = new Point2D.Float(pt2.x, pt2.y/2);
              g2.draw(new Line2D.Float(pt1, pt2));
              // g2.setColor(waveLiteColor);
              g.setColor(waveLiteColor);
              g2.draw(new Line2D.Float(pt2, pt3));
              g2.setColor(waveColor);
              g2.draw(new Line2D.Float(pt3, pt4));
              //							g2.draw(new Line2D.Float(this.points.get(i).getDispPoint(),
              //									this.points.get(i+1).getDispPoint()));
              //							g2.draw(new Line2D.Float(this.points.get(i).getDispPoint(),
              //									this.points.get(i+1).getDispPoint()));
              //							g2.draw(new Line2D.Float(this.points.get(i).getDispPoint(),
              //									this.points.get(i+1).getDispPoint()));
            }

          } else { // draw line
            g2.setStroke(stroke);
            for (int i = 0; i < this.points.size() - 1; i++) {
              g2.draw(
                  new Line2D.Float(
                      this.points.get(i).getDispPoint(), this.points.get(i + 1).getDispPoint()));
            }
          }
        } else { // stem plot
          for (int i = 0; i < this.points.size(); i++) {
            // draw the stem
            SoundSample sample = this.points.get(i);
            g2.setStroke(thickerStroke);
            Point2D.Double base =
                new Point2D.Double(
                    sample.getDispPoint().getX() + 10, Math.floor(this.getHeight()) / 2);
            Point2D.Double pt =
                new Point2D.Double(sample.getDispPoint().getX() + 10, sample.getDispPoint().getY());
            g2.draw(new Line2D.Float(base, pt));

            if (this.points.size() < zoomThresh) {
              // draw the sample value
              float sampleValue = (float) sample.getSampleValue();
              float y = (float) sample.getDispPoint().getY();
              g2.setFont(textFont);
              if (y < Math.floor(this.getHeight()) / 2) y = y - 10;
              else y = y + 10;
              // if (sample.getDispPoint().getX() > 0)
              g2.drawString(formatter.format(sampleValue), (float) sample.getDispPoint().getX(), y);
            }

            // draw the vertical bar in the array
            //						g2.setStroke(thickerStroke);
            //						base = new Point2D.Double(base.getX()-8, this.getHeight() - 10);
            //						pt = new Point2D.Double(base.getX(), this.getHeight() - 50);
            //						g2.draw(new Line2D.Double(base, pt));
            //						g2.drawString(formatter.format(points.get(i).getSampleIndex()),
            // (float)base.getX(), (float)base.getY() - 10 );
          }
          //
          //					g2.setStroke(wideStroke);
          //					//draw the array cells
          //					g2.draw(new Line2D.Double(selection.getX(),
          //							Math.floor(this.getHeight() - 30),
          //							selection.getX()+selection.getWidth()-1,
          //							Math.floor(this.getHeight() - 30)));
          //					//draw the array cells
          //					g2.draw(new Line2D.Double(selection.getX(),
          //							Math.floor(this.getHeight() - 10),
          //							selection.getX()+selection.getWidth()-1,
          //							Math.floor(this.getHeight() - 10)));
        }
      }

      // draw the center line
      g2.setColor(barColor);
      g2.setStroke(new BasicStroke(1));
      g2.draw(
          new Line2D.Double(
              selection.getX(),
              Math.floor(this.getHeight() / 2),
              selection.getX() + selection.getWidth() - 1,
              Math.floor(this.getHeight() / 2)));

      //			//draw the current position
      //			if (selection.getX()<currentPixelPosition &&
      //					currentPixelPosition<(selection.getX()+selection.getWidth()-1))
      //			{
      //				g2.setColor(barColor);
      //				g2.setStroke(new BasicStroke(1));
      //				g2.draw(new Line2D.Double(currentPixelPosition, 0,
      //						currentPixelPosition, frameHeight));
      //			}
    }
    /**
     * Paints the border for the specified component with the specified position and size.
     *
     * @param c the component for which this border is being painted
     * @param g the paint graphics
     * @param x the x position of the painted border
     * @param y the y position of the painted border
     * @param width the width of the painted border
     * @param height the height of the painted border
     */
    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {

      Border border = getBorder();

      if (label == null) {
        if (border != null) {
          border.paintBorder(c, g, x, y, width, height);
        }
        return;
      }

      Rectangle grooveRect =
          new Rectangle(
              x + EDGE_SPACING,
              y + EDGE_SPACING,
              width - (EDGE_SPACING * 2),
              height - (EDGE_SPACING * 2));

      Dimension labelDim = label.getPreferredSize();
      int baseline = label.getBaseline(labelDim.width, labelDim.height);
      int ascent = Math.max(0, baseline);
      int descent = labelDim.height - ascent;
      int diff;
      Insets insets;

      if (border != null) {
        insets = border.getBorderInsets(c);
      } else {
        insets = new Insets(0, 0, 0, 0);
      }

      diff = Math.max(0, ascent / 2 + TEXT_SPACING - EDGE_SPACING);
      grooveRect.y += diff;
      grooveRect.height -= diff;
      compLoc.y = grooveRect.y + insets.top / 2 - (ascent + descent) / 2 - 1;

      int justification;
      if (c.getComponentOrientation().isLeftToRight()) {
        justification = LEFT;
      } else {
        justification = RIGHT;
      }

      switch (justification) {
        case LEFT:
          compLoc.x = grooveRect.x + TEXT_INSET_H + insets.left;
          break;
        case RIGHT:
          compLoc.x =
              (grooveRect.x + grooveRect.width - (labelDim.width + TEXT_INSET_H + insets.right));
          break;
      }

      // If title is positioned in middle of border AND its fontsize
      // is greater than the border's thickness, we'll need to paint
      // the border in sections to leave space for the component's background
      // to show through the title.
      //
      if (border != null) {
        if (grooveRect.y > compLoc.y - ascent) {
          Rectangle clipRect = new Rectangle();

          // save original clip
          Rectangle saveClip = g.getClipBounds();

          // paint strip left of text
          clipRect.setBounds(saveClip);
          if (computeIntersection(clipRect, x, y, compLoc.x - 1 - x, height)) {
            g.setClip(clipRect);
            border.paintBorder(
                c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height);
          }

          // paint strip right of text
          clipRect.setBounds(saveClip);
          if (computeIntersection(
              clipRect,
              compLoc.x + labelDim.width + 1,
              y,
              x + width - (compLoc.x + labelDim.width + 1),
              height)) {
            g.setClip(clipRect);
            border.paintBorder(
                c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height);
          }

          // paint strip below text
          clipRect.setBounds(saveClip);
          if (computeIntersection(
              clipRect,
              compLoc.x - 1,
              compLoc.y + ascent + descent,
              labelDim.width + 2,
              y + height - compLoc.y - ascent - descent)) {
            g.setClip(clipRect);
            border.paintBorder(
                c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height);
          }

          // restore clip
          g.setClip(saveClip);

        } else {
          border.paintBorder(c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height);
        }

        label.setLocation(compLoc);
        label.setSize(labelDim);
      }
    }