// -------------------- Column setup ----------------------------------------------
column_setup = new JMenuItem("Column setup", ImgRep.getIcon("columns_setup.png"));
column_setup.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JDialog col_set_frame = new JDialog(parent,"Column setup",true);
JPanel right_panel = new JPanel(); // where the up & down buttons are located
JPanel bottom_panel = new JPanel(); // Cancel, Defaults, Ok buttons
JPanel center_panel = new JPanel(); // the jtable
JButton up_button = new JButton("Up");
JButton down_button = new JButton("Down");
JButton ok_button = new JButton("OK");
JButton cancel_button = new JButton("Cancel");
JButton apply_button = new JButton("Apply");
right_panel.setLayout(new GridLayout(2,1));
right_panel.add(up_button);
right_panel.add(down_button);
bottom_panel.setLayout(new GridLayout(1,3));
bottom_panel.add(ok_button);
bottom_panel.add(apply_button);
bottom_panel.add(cancel_button);
center_panel.setLayout(new GridLayout(1,1));
col_set_frame.setSize(400, 300);
col_set_frame.setLayout(new BorderLayout());
col_set_frame.add(center_panel,BorderLayout.CENTER);
col_set_frame.add(right_panel, BorderLayout.EAST);
col_set_frame.add(bottom_panel, BorderLayout.SOUTH);
final JTable col_set_table = new JTable();
//DefaultTableModel col_set_table_model = new DefaultTableModel();
Object[][] col_set_rows_cols = new Object[14][3];
int i = 0;
// col name -> col obj mapping (easy way to map col names to master cols)
final Map<String,TableColumnExt> cols = new Hashtable<String,TableColumnExt>();
for(TableColumnExt column : table_columns) {
if(column.isVisible()) col_set_rows_cols[i][0] = true;
else col_set_rows_cols[i][0] = false;
col_set_rows_cols[i][1] = column.getHeaderValue();
cols.put(column.getHeaderValue().toString(), column);
++i;
}
col_set_table.setModel(new DefaultTableModel(col_set_rows_cols,
new String[] {
"Visibility", "Name", "Description"
})
{
Class[] types = new Class [] {
java.lang.Boolean.class, java.lang.String.class, java.lang.String.class
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
});
JScrollPane scroll_pane = new JScrollPane();
scroll_pane.setViewportView(col_set_table);
center_panel.add(scroll_pane);
SwingUtils.setWindowLocationRelativeTo(col_set_frame, parent);
apply_button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
for(int i=0; i<14; i++) {
boolean visibility = Boolean.parseBoolean(col_set_table.getModel().getValueAt(i, 0).toString());
String column_name = col_set_table.getModel().getValueAt(i, 1).toString();
//cols.get(column_name).setVisible(visibility);
if(visibility == false) column_model.removeColumn(cols.get(column_name));
System.out.println("Column from set " + cols.get(column_name).getHeaderValue());
System.out.println("<--->" + column_name + "<---->" + visibility);
}
}
});
col_set_frame.setVisible(true);
}
});
}
public void mousePressed(MouseEvent e) {
showPopup(e);