Search in sources :

Example 1 with DarkTableScrollPaneBorder

use of com.github.weisj.darklaf.ui.table.DarkTableScrollPaneBorder in project darklaf by weisJ.

the class DarkTableHeaderUI method paint.

@Override
public void paint(final Graphics g2, final JComponent c) {
    final Graphics2D g = (Graphics2D) g2;
    final GraphicsContext config = new GraphicsContext(g);
    int x = 0;
    int y = 0;
    int h = c.getHeight();
    int w = c.getWidth();
    g.setColor(getHeaderBackground());
    g.fillRect(x, y, w, h);
    if (header.getColumnModel().getColumnCount() <= 0) {
        return;
    }
    boolean ltr = header.getComponentOrientation().isLeftToRight();
    Rectangle clip = g.getClipBounds();
    Point leftClip = clip.getLocation();
    Point rightCip = new Point(clip.x + clip.width - 1, clip.y);
    TableColumnModel cm = header.getColumnModel();
    int cMin = Math.max(header.columnAtPoint(ltr ? leftClip : rightCip), 0);
    int cMax = header.columnAtPoint(ltr ? rightCip : leftClip);
    // Replace this with the index of the last column.
    if (cMax == -1) {
        cMax = cm.getColumnCount() - 1;
    }
    Rectangle bounds = c.getVisibleRect();
    Point left = bounds.getLocation();
    Point right = new Point(bounds.x + bounds.width - 1, bounds.y);
    int cMinVisible = Math.max(header.columnAtPoint(ltr ? left : right), 0);
    int cMaxVisible = header.columnAtPoint(ltr ? right : left);
    if (cMaxVisible == -1) {
        cMaxVisible = cm.getColumnCount() - 1;
    }
    Color borderColor = c.getBorder() instanceof DarkTableScrollPaneBorder ? ((DarkTableScrollPaneBorder) c.getBorder()).getBorderColor() : getBorderColor();
    g.setColor(borderColor);
    TableColumn draggedColumn = header.getDraggedColumn();
    Rectangle cellRect = header.getHeaderRect(ltr ? cMin : cMax);
    paintCells(g, h, ltr, cm, cMin, cMax, cMinVisible, cMaxVisible, borderColor, draggedColumn, cellRect);
    // Paint the dragged column if we are dragging.
    if (draggedColumn != null) {
        paintDraggedArea(g, ltr, cMin, cMax, borderColor, draggedColumn);
    }
    // Remove all components in the rendererPane.
    rendererPane.removeAll();
    config.restore();
    /*
         * If the table is in a scroll pane which uses buffer backed viewports scrolling leads to the
         * previously last cell missing part of its border. We manually repaint it to prevent the appearance
         * of joint cells.
         */
    if (lastMaxVisible != cMaxVisible) {
        if (lastMaxVisible >= 0) {
            Rectangle r = header.getHeaderRect(lastMaxVisible);
            SwingUtilities.invokeLater(() -> header.repaint(r));
        }
        lastMaxVisible = cMaxVisible;
    }
}
Also used : GraphicsContext(com.github.weisj.darklaf.util.graphics.GraphicsContext) TableColumnModel(javax.swing.table.TableColumnModel) DarkTableScrollPaneBorder(com.github.weisj.darklaf.ui.table.DarkTableScrollPaneBorder) TableColumn(javax.swing.table.TableColumn)

Aggregations

DarkTableScrollPaneBorder (com.github.weisj.darklaf.ui.table.DarkTableScrollPaneBorder)1 GraphicsContext (com.github.weisj.darklaf.util.graphics.GraphicsContext)1 TableColumn (javax.swing.table.TableColumn)1 TableColumnModel (javax.swing.table.TableColumnModel)1