コード例 #1
0
  /**
   * Paints the grid lines within <I>aRect</I>, using the grid color set with <I>setGridColor</I>.
   * Paints vertical lines if <code>
   * getShowVerticalLines()</code> returns true and paints horizontal lines if <code>
   * getShowHorizontalLines()</code> returns true. TODO See if we want to remove this method.
   *
   * @param context the Synth context.
   * @param g the Graphics context.
   * @param rMin DOCUMENT ME!
   * @param rMax DOCUMENT ME!
   * @param cMin DOCUMENT ME!
   * @param cMax DOCUMENT ME!
   */
  @SuppressWarnings("unused")
  private void paintGrid(
      SeaGlassContext context, Graphics g, int rMin, int rMax, int cMin, int cMax) {
    g.setColor(table.getGridColor());

    Rectangle minCell = table.getCellRect(rMin, cMin, true);
    Rectangle maxCell = table.getCellRect(rMax, cMax, true);
    Rectangle damagedArea = minCell.union(maxCell);
    SynthGraphicsUtils synthG = context.getStyle().getGraphicsUtils(context);

    if (table.getShowHorizontalLines()) {
      int tableWidth = damagedArea.x + damagedArea.width;
      int y = damagedArea.y;

      for (int row = rMin; row <= rMax; row++) {
        y += table.getRowHeight(row);
        synthG.drawLine(context, "Table.grid", g, damagedArea.x, y - 1, tableWidth - 1, y - 1);
      }
    }

    if (table.getShowVerticalLines()) {
      TableColumnModel cm = table.getColumnModel();
      int tableHeight = damagedArea.y + damagedArea.height;
      int x;

      if (table.getComponentOrientation().isLeftToRight()) {
        x = damagedArea.x;
        for (int column = cMin; column <= cMax; column++) {
          int w = cm.getColumn(column).getWidth();

          x += w;
          synthG.drawLine(context, "Table.grid", g, x - 1, 0, x - 1, tableHeight - 1);
        }
      } else {
        x = damagedArea.x;
        for (int column = cMax; column >= cMin; column--) {
          int w = cm.getColumn(column).getWidth();

          x += w;
          synthG.drawLine(context, "Table.grid", g, x - 1, 0, x - 1, tableHeight - 1);
        }
      }
    }
  }
コード例 #2
0
  /**
   * DOCUMENT ME!
   *
   * @param context DOCUMENT ME!
   * @param g DOCUMENT ME!
   * @param rMin DOCUMENT ME!
   * @param rMax DOCUMENT ME!
   * @param draggedColumn DOCUMENT ME!
   * @param distance DOCUMENT ME!
   */
  private void paintDraggedArea(
      SeaGlassContext context,
      Graphics g,
      int rMin,
      int rMax,
      TableColumn draggedColumn,
      int distance) {
    int draggedColumnIndex = viewIndexForColumn(draggedColumn);

    Rectangle minCell = table.getCellRect(rMin, draggedColumnIndex, true);
    Rectangle maxCell = table.getCellRect(rMax, draggedColumnIndex, true);

    Rectangle vacatedColumnRect = minCell.union(maxCell);

    // Paint a gray well in place of the moving column.
    g.setColor(table.getParent().getBackground());
    g.fillRect(
        vacatedColumnRect.x,
        vacatedColumnRect.y,
        vacatedColumnRect.width,
        vacatedColumnRect.height);

    // Move to the where the cell has been dragged.
    vacatedColumnRect.x += distance;

    // Fill the background.
    g.setColor(context.getStyle().getColor(context, ColorType.BACKGROUND));
    g.fillRect(
        vacatedColumnRect.x,
        vacatedColumnRect.y,
        vacatedColumnRect.width,
        vacatedColumnRect.height);

    SynthGraphicsUtils synthG = context.getStyle().getGraphicsUtils(context);

    // Paint the vertical grid lines if necessary.
    if (table.getShowVerticalLines()) {
      g.setColor(table.getGridColor());
      int x1 = vacatedColumnRect.x;
      int y1 = vacatedColumnRect.y;
      int x2 = x1 + vacatedColumnRect.width - 1;
      int y2 = y1 + vacatedColumnRect.height - 1;
      // Left
      synthG.drawLine(context, "Table.grid", g, x1 - 1, y1, x1 - 1, y2);
      // Right
      synthG.drawLine(context, "Table.grid", g, x2, y1, x2, y2);
    }

    for (int row = rMin; row <= rMax; row++) {
      // Render the cell value
      Rectangle r = table.getCellRect(row, draggedColumnIndex, false);

      r.x += distance;
      paintCell(context, g, r, row, draggedColumnIndex);

      // Paint the (lower) horizontal grid line if necessary.
      if (table.getShowHorizontalLines()) {
        g.setColor(table.getGridColor());
        Rectangle rcr = table.getCellRect(row, draggedColumnIndex, true);

        rcr.x += distance;
        int x1 = rcr.x;
        int y1 = rcr.y;
        int x2 = x1 + rcr.width - 1;
        int y2 = y1 + rcr.height - 1;

        synthG.drawLine(context, "Table.grid", g, x1, y2, x2, y2);
      }
    }
  }
コード例 #3
0
  /**
   * Paint the stripes and grid.
   *
   * @param context the Synth context.
   * @param g the Graphics context.
   * @param c the component.
   * @param width the width of the table.
   * @param height the height of the table.
   * @param top the top row to paint (for viewports).
   */
  public void paintStripesAndGrid(
      SeaGlassContext context, Graphics g, JComponent c, int width, int height, int top) {
    int rh = table.getRowHeight();
    int n = table.getRowCount();
    int row = Math.abs(top / rh);
    // if (true) return;

    // TableCellRenderer renderer =
    // table.getDefaultRenderer(java.lang.Object.class);

    // Paint the background, including stripes if requested.
    if (alternateColor != null) {
      // Fill the viewport with background color.
      g.setColor(table.getBackground());
      g.fillRect(0, 0, width, height);

      // Now check if we need to paint some stripes
      g.setColor(alternateColor);

      // Paint table rows to fill the viewport.
      for (int y = top + row * rh, ymax = height; y < ymax; y += rh) {
        if (row % 2 == 0) {
          g.fillRect(0, y, width, rh);
        }

        row++;
      }
    } else {
      // Fill the viewport with the background color of the table
      g.setColor(table.getBackground());
      g.fillRect(0, 0, c.getWidth(), c.getHeight());
    }

    SynthGraphicsUtils synthG = context.getStyle().getGraphicsUtils(context);

    // Paint the horizontal grid lines
    if (table.getShowHorizontalLines()) {
      g.setColor(table.getGridColor());
      row = Math.abs(top / rh);
      int y = top + row * rh + rh - 1;

      while (y < height) {
        synthG.drawLine(context, "Table.grid", g, 0, y, width, y);
        y += rh;
      }
    }

    // Paint the vertical grid lines
    if (table.getShowVerticalLines()) {
      g.setColor(table.getGridColor());
      TableColumnModel cm = table.getColumnModel();

      n = cm.getColumnCount();
      int y = top + row * rh;

      ;
      int x = -1;

      for (int i = 0; i < n; i++) {
        TableColumn col = cm.getColumn(i);

        x += col.getWidth();
        synthG.drawLine(context, "Table.grid", g, x, y, x, height);
      }
    }
  }