version 1.5, 2004/03/23 11:57:06
|
version 1.8, 2004/11/18 11:17:43
|
Line 41 public class TableComponent extends JPan
|
Line 41 public class TableComponent extends JPan
|
int selIndex = 0; |
int selIndex = 0; |
Icon trueIcon = null, falseIcon = null, empty = null; |
Icon trueIcon = null, falseIcon = null, empty = null; |
TableComponent tableComp = this; |
TableComponent tableComp = this; |
|
BooleanRenderer booleanRenderer = new BooleanRenderer(); |
/** |
/** |
* Constructs an empty table with default header and dummy data |
* Constructs an empty table with default header and dummy data |
*/ |
*/ |
Line 165 public class TableComponent extends JPan
|
Line 166 public class TableComponent extends JPan
|
{ |
{ |
tableComp.row = row; |
tableComp.row = row; |
boolean value = false; |
boolean value = false; |
if (getColumnClass(column) == ArrayList.class || getColumnClass(column) == JComboBox.class || getColumnClass(column) == SQLCommand.class || getColumnClass(column) == IDComboBox.class) |
if (getColumnClass(column) == ArrayList.class || getColumnClass(column) == JComboBox.class || getColumnClass(column) == SQLCommand.class || getColumnClass(column) == IDComboBox.class|| getColumnClass(column) == Boolean.class) |
value = true; |
value = true; |
//System.out.println("tried to edit at row "+row+" column "+column+" "+value); |
//System.out.println("tried to edit at row "+row+" column "+column+" "+value); |
|
|
Line 209 public class TableComponent extends JPan
|
Line 210 public class TableComponent extends JPan
|
});*/ |
});*/ |
table.setDefaultEditor(SQLCommand.class, new SQLCommandEditor()); |
table.setDefaultEditor(SQLCommand.class, new SQLCommandEditor()); |
|
|
table.setDefaultRenderer(Boolean.class, new TableCellRenderer() |
table.setDefaultRenderer(Boolean.class, booleanRenderer); |
{ |
|
JCheckBox checkBox = new JCheckBox(); |
|
JLabel label = new JLabel(); |
|
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) |
|
{ |
|
if (value instanceof Integer) |
|
{ |
|
label.setText(value.toString()); |
|
label.setHorizontalAlignment(JLabel.RIGHT); |
|
|
|
return label; |
|
} else if (value instanceof String) |
|
{ |
|
label.setText(value.toString()); |
|
label.setHorizontalAlignment(JLabel.CENTER); |
|
return label; |
|
} |
|
checkBox.setHorizontalAlignment(JLabel.CENTER); |
|
checkBox.setVerticalAlignment(JLabel.CENTER); |
|
|
|
checkBox.setSelectedIcon(trueIcon); |
|
if (value == null) |
|
checkBox.setIcon(empty); |
|
else |
|
checkBox.setIcon(falseIcon); |
|
checkBox.setForeground(table.getForeground()); |
|
checkBox.setBackground(table.getBackground()); |
|
|
|
checkBox.setSelected((value != null && ((Boolean) value).booleanValue())); |
|
return checkBox; |
|
|
|
} |
|
|
|
}); |
|
|
|
table.setRowHeight(20); |
table.setRowHeight(20); |
|
|
Line 324 public class TableComponent extends JPan
|
Line 291 public class TableComponent extends JPan
|
|
|
// Class tre=table.getColumnModel().getColumn(1).getHeaderValue().getClass(); |
// Class tre=table.getColumnModel().getColumn(1).getHeaderValue().getClass(); |
//Graphics2D g2=((Graphics2D)getGraphics()); |
//Graphics2D g2=((Graphics2D)getGraphics()); |
table.setAutoResizeMode(table.AUTO_RESIZE_OFF); |
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); |
|
|
TableColumnModel model = table.getColumnModel(); |
TableColumnModel model = table.getColumnModel(); |
for (int i = 0; i < model.getColumnCount(); ++i) |
for (int i = 0; i < model.getColumnCount(); ++i) |
{ |
{ |
label = new JLabel(model.getColumn(i).getHeaderValue().toString()); |
label = new JLabel(model.getColumn(i).getHeaderValue().toString()); |
|
//System.out.println("labelWith "+label.getPreferredSize().width); |
|
if(label.getText().equals(" ")) |
|
model.getColumn(i).setPreferredWidth(20); |
|
else |
model.getColumn(i).setPreferredWidth(label.getPreferredSize().width + 50); |
model.getColumn(i).setPreferredWidth(label.getPreferredSize().width + 50); |
|
|
} |
} |
Line 1098 public class TableComponent extends JPan
|
Line 1069 public class TableComponent extends JPan
|
} |
} |
return alterMe; |
return alterMe; |
} |
} |
|
public static class BooleanRenderer implements TableCellRenderer |
|
{ |
|
Icon trueIcon,falseIcon,empty; |
|
// renders false state with empty icon |
|
boolean renderFalseEmpty=false; |
|
public BooleanRenderer(){ |
|
try |
|
{ |
|
trueIcon = new ImageIcon(getClass().getResource("icons/ok.gif")); |
|
|
|
falseIcon = new Icon() |
|
{ |
|
public int getIconHeight() |
|
{ |
|
return 23; |
|
} |
|
public int getIconWidth() |
|
{ |
|
return 27; |
|
} |
|
public void paintIcon(Component c, Graphics g, int x, int y) |
|
{ |
|
Graphics2D g2 = (Graphics2D) g; |
|
g2.setColor(Color.blue); |
|
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
|
g2.setStroke(new BasicStroke(2.0f)); |
|
int xr = x + 20, yr = y + 15; |
|
int xl = x + 5, yl = y + 5; |
|
g2.drawLine(xl, yl, xr, yr); |
|
g2.drawLine(xl, yr, xr, yl); |
|
|
|
} |
|
}; |
|
empty = new Icon() |
|
{ |
|
public int getIconHeight() |
|
{ |
|
return 23; |
|
} |
|
public int getIconWidth() |
|
{ |
|
return 27; |
|
} |
|
public void paintIcon(Component c, Graphics g, int x, int y) |
|
{ |
|
|
|
} |
|
}; |
|
|
|
} catch (Exception e) |
|
{ |
|
System.out.println("Error while loading ok.gif"); |
|
} |
|
|
|
|
|
} |
|
JCheckBox checkBox = new JCheckBox(); |
|
JLabel label = new JLabel(); |
|
|
|
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) |
|
{ |
|
if (value instanceof Integer) |
|
{ |
|
label.setText(value.toString()); |
|
label.setHorizontalAlignment(JLabel.RIGHT); |
|
|
|
return label; |
|
} else if (value instanceof String) |
|
{ |
|
label.setText(value.toString()); |
|
label.setHorizontalAlignment(JLabel.CENTER); |
|
return label; |
|
} |
|
checkBox.setHorizontalAlignment(JLabel.CENTER); |
|
checkBox.setVerticalAlignment(JLabel.CENTER); |
|
|
|
checkBox.setSelectedIcon(trueIcon); |
|
if(renderFalseEmpty|| value==null) |
|
checkBox.setIcon(empty); |
|
else checkBox.setIcon(falseIcon); |
|
checkBox.setForeground(table.getForeground()); |
|
checkBox.setBackground(table.getBackground()); |
|
|
|
checkBox.setSelected((value != null && ((Boolean) value).booleanValue())); |
|
return checkBox; |
|
|
|
} |
|
} |
public static class SQLCommand |
public static class SQLCommand |
{ |
{ |
String command = ""; |
String command = ""; |