version 1.4, 2004/02/19 10:35:06
|
version 1.8, 2004/11/18 11:17:43
|
Line 1
|
Line 1
|
|
/* |
|
* TableComponent.java -- GUI Table class |
|
* Filemake to SQL Converter |
|
* Copyright (C) 2004 Robert Gordesch (rogo@mpiwg-berlin.mpg.de) |
|
* This program is free software; you can redistribute it and/or modify it |
|
* under the terms of the GNU General Public License as published by the Free |
|
* Software Foundation; either version 2 of the License, or (at your option) |
|
* any later version. Please read license.txt for the full details. A copy of |
|
* the GPL may be found at http://www.gnu.org/copyleft/lgpl.html You should |
|
* have received a copy of the GNU General Public License along with this |
|
* program; if not, write to the Free Software Foundation, Inc., 59 Temple |
|
* Place, Suite 330, Boston, MA 02111-1307 USA Created on 15.09.2003 by |
|
* rogo |
|
*/ |
import javax.swing.*; |
import javax.swing.*; |
import java.awt.event.*; |
import java.awt.event.*; |
|
|
Line 27 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 151 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 195 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 310 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 1084 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 = ""; |