001: /*
002: * SQLeonardo :: java database frontend
003: * Copyright (C) 2004 nickyb@users.sourceforge.net
004: *
005: * This program is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU General Public License
007: * as published by the Free Software Foundation; either version 2
008: * of the License, or (at your option) any later version.
009: *
010: * This program is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: * GNU General Public License for more details.
014: *
015: * You should have received a copy of the GNU General Public License
016: * along with this program; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
018: *
019: */
020:
021: package nickyb.sqleonardo.environment.ctrl.content;
022:
023: import java.awt.Component;
024:
025: import javax.swing.JLabel;
026: import javax.swing.JTable;
027: import javax.swing.table.DefaultTableCellRenderer;
028: import javax.swing.table.JTableHeader;
029:
030: import nickyb.sqleonardo.common.util.Appearance;
031:
032: public class LineNumberView extends JTable {
033: private int block = 1;
034: private int rows = 0;
035:
036: public LineNumberView() {
037: super (0, 1);
038: setAutoscrolls(false);
039: setAutoCreateColumnsFromModel(false);
040:
041: getColumnModel().getColumn(0).setPreferredWidth(50);
042: getColumnModel().getColumn(0).setCellRenderer(
043: new InternalCellRenderer());
044:
045: setPreferredScrollableViewportSize(getPreferredSize());
046: }
047:
048: public boolean isCellEditable(int row, int column) {
049: return false;
050: }
051:
052: public Class getColumnClass(int idx) {
053: return Object.class;
054: }
055:
056: public int getColumnCount() {
057: return 1;
058: }
059:
060: public String getColumnName(int idx) {
061: return "#";
062: }
063:
064: public int getRowCount() {
065: return rows;
066: }
067:
068: public void setRowCount(int rows) {
069: this .rows = rows;
070: }
071:
072: void setBlock(int idx) {
073: block = idx;
074: }
075:
076: public Object getValueAt(int row, int column) {
077: return new Integer(
078: (ContentModel.MAX_BLOCK_RECORDS * (block - 1))
079: + (row + 1));
080: }
081:
082: private class InternalCellRenderer extends DefaultTableCellRenderer {
083: public Component getTableCellRendererComponent(JTable table,
084: Object value, boolean isSelected, boolean hasFocus,
085: int row, int column) {
086: if (table != null) {
087: JTableHeader header = table.getTableHeader();
088: if (header != null) {
089: setForeground(header.getForeground());
090: setBackground(header.getBackground());
091: }
092: }
093:
094: setHorizontalAlignment(JLabel.CENTER);
095: setText((value == null) ? "" : value.toString());
096: setFont(isSelected ? Appearance.fontBOLD
097: : Appearance.fontPLAIN);
098:
099: return this;
100: }
101: }
102: }
|