1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
/** BEGIN COPYRIGHT BLOCK
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
* Copyright (C) 2005 Red Hat, Inc.
* All rights reserved.
*
* 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 version
* 2.1 of the License.
*
* 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* END COPYRIGHT BLOCK **/
package com.netscape.management.client.components;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.border.*;
import javax.swing.event.*;
import com.netscape.management.nmclf.*;
/**
* TODO: improve Javadocs
*/
public class DetailTableTest
{
public static void main(String argv[])
{
try
{
SuiLookAndFeel nmclf = new SuiLookAndFeel();
UIManager.setLookAndFeel(nmclf);
FontFactory.initializeLFFonts(); // load default customized fonts for login/splash
}
catch (Exception e)
{
System.err.println("cannot load lf: " + e);
}
JFrame frame = new JFrame();
frame.addWindowListener
(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
DetailTable table = new DetailTable(new TextTableModel(), true);
//DetailTable table = new DetailTable(new NumericTableModel(), true);
table.getTable().setPreferredScrollableViewportSize(new Dimension(600,100));
frame.getContentPane().add(table);
//JDialog d = new TableCustomizationDialog(frame, table.getJTable());
//d.show();
//System.exit(0);
frame.pack();
frame.show();
}
}
class NumericTableModel extends AbstractTableModel
{
public int getColumnCount()
{
return 5;
}
public int getRowCount()
{
return 50;
}
public Object getValueAt(int row, int col)
{
if(col == 2 && row == 4)
return new Integer(1234567);
return new Integer((1+row)*(1+col));
}
public String getColumnName(int col)
{
String[] cols = { "Grand", "Splendiferous", "Magnificent", "Splendid", "Ostentatious" };
return cols[col];
}
public Class getColumnClass(int c)
{
return getValueAt(0, c).getClass();
}
}
class TextTableModel extends AbstractTableModel
{
final String[] columnNames = {"First Name",
"Last Name",
"Sport",
"# of Years",
"Vegetarian"};
final Object[][] data =
{
{"Mary", "Campione",
"Snowboarding", new Integer(5), new Boolean(false)},
{"Alison", "Huml",
"Rowing", new Integer(3), new Boolean(true)},
{"Kathy", "Walrath",
"Chasing toddlers", new Integer(2), new Boolean(false)},
{"Mark", "Andrews",
"Speed reading", new Integer(20), new Boolean(true)},
{"Angela", "Lih",
"Teaching high school", new Integer(4), new Boolean(false)}
};
public int getColumnCount()
{
return columnNames.length;
}
public int getRowCount()
{
return data.length;
}
public String getColumnName(int col)
{
return columnNames[col];
}
public Object getValueAt(int row, int col)
{
return data[row][col];
}
public Class getColumnClass(int c)
{
return getValueAt(0, c).getClass();
}
public boolean isCellEditable(int row, int col)
{
//Note that the data/cell address is constant,
//no matter where the cell appears onscreen.
if (col < 2) {
return false;
} else {
return true;
}
}
}
|