/*
 This file is part of the software framework JStatCom, 
 a library for building applications for data based analysis.

 Copyright (C) 2000-2005  Alexander Benkwitz

 This library is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as
 published by the Free Software Foundation; either version 2.1 of the
 License, or (at your option) any later version.

 This library is distributed in the hope that it will be useful, but
 WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 USA
 */

package com.jstatcom.table;

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Insets;

import javax.swing.JTable;
import javax.swing.border.AbstractBorder;

/**
 * Most inner border for BorderTables.
 * A BorderTable always has an instance of this
 * border set. Event when setting a new border
 * it effectively creates a combined border
 * with an instance of this border as the inner border.
 *
 * @author Alexander Benkwitz
 */
public class BorderTableBorder extends AbstractBorder {
	private int topInset = 1;
	private int leftInset = 1;
	private int bottomInset = 0;
	private int rightInset = 0;
/**
 * Creates a new BorderTableBorder.
 */
public BorderTableBorder() {
	super();
}
/**
 * Overloads method from superclass.
 * Gets the insets for this border.
 *
 * @param  c ignored, can be null
 * @return insets
 */
public Insets getBorderInsets(Component c) {
    return new Insets(topInset, leftInset, bottomInset, rightInset);
}
/**
 * Overloads method from superclass.
 * Reinitializes the insets with this Border's current insets.
 *
 * @param  c ignored, can be null
 * @param  insets parameter to be reinitialized with border insets
 * @return the insets parameter after it was reinitialized
 */
public Insets getBorderInsets(Component c, Insets insets) {
    insets.left = leftInset;
    insets.top = topInset;
    insets.right = rightInset;
    insets.bottom = bottomInset;
    return insets;
}
/**
 * Never changes, returns false.
 *
 * @return false
 */
public boolean isBorderOpaque() {
    return false;
}
/**
 * Overloads superclass method to paint this border.
 */
public void paintBorder(
    Component c,
    Graphics g,
    int x,
    int y,
    int width,
    int height) {
   
    Color oldColor = g.getColor();
    Color newColor = Color.gray;
    boolean hL = true;
    boolean vL = true;
    if (c instanceof JTable) {
        JTable table = (JTable) c;
        newColor = table.getGridColor();
        hL = table.getShowHorizontalLines();
        vL = table.getShowVerticalLines();
    }
    g.setColor(newColor);
    if (hL)
        g.drawLine(x, y, x + width - 1, y);
    if (vL)
        g.drawLine(x, y, x, y + height - 1);
    g.setColor(oldColor);
}
}

 

Ads help maintain this website.