1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
package ca.spaz.cron.targets; |
5 |
|
|
6 |
|
import java.awt.*; |
7 |
|
import java.util.List; |
8 |
|
|
9 |
|
import javax.swing.*; |
10 |
|
import javax.swing.event.*; |
11 |
|
import javax.swing.table.*; |
12 |
|
|
13 |
|
import ca.spaz.cron.user.User; |
14 |
|
import ca.spaz.gui.PrettyTable; |
15 |
|
|
16 |
|
public class TargetEditorTable extends JScrollPane { |
17 |
|
|
18 |
|
TargetEditorTableModel model; |
19 |
|
PrettyTable nutrientTable; |
20 |
|
|
21 |
0 |
public TargetEditorTable(User user, List nutrients) { |
22 |
0 |
model = new TargetEditorTableModel(user, nutrients); |
23 |
0 |
setViewportView(getTable()); |
24 |
0 |
getViewport().setBackground(Color.WHITE); |
25 |
0 |
setPreferredSize(new Dimension(300, 200)); |
26 |
0 |
} |
27 |
|
|
28 |
|
private JTable getTable() { |
29 |
0 |
if (null == nutrientTable) { |
30 |
0 |
nutrientTable = new PrettyTable(); |
31 |
0 |
nutrientTable.setModel(model); |
32 |
0 |
nutrientTable.getSelectionModel().setSelectionMode( |
33 |
|
ListSelectionModel.SINGLE_SELECTION); |
34 |
0 |
nutrientTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); |
35 |
0 |
nutrientTable.getTableHeader().setReorderingAllowed(false); |
36 |
0 |
nutrientTable.getSelectionModel().addListSelectionListener( |
37 |
|
new ListSelectionListener() { |
38 |
|
public void valueChanged(ListSelectionEvent e) { |
39 |
|
if (e.getValueIsAdjusting()) |
40 |
|
return; |
41 |
|
ListSelectionModel lsm = (ListSelectionModel) e |
42 |
|
.getSource(); |
43 |
|
if (!lsm.isSelectionEmpty()) { |
44 |
|
int selectedRow = lsm.getMinSelectionIndex(); |
45 |
|
} |
46 |
|
} |
47 |
|
}); |
48 |
|
|
49 |
0 |
TableColumnModel tcm = nutrientTable.getColumnModel(); |
50 |
0 |
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); |
51 |
0 |
TableColumn column = tcm.getColumn(0); |
52 |
0 |
renderer.setHorizontalAlignment(SwingConstants.RIGHT); |
53 |
0 |
column.setCellRenderer(renderer); |
54 |
|
} |
55 |
0 |
return nutrientTable; |
56 |
|
} |
57 |
|
|
58 |
|
public void fireTargetsChanged() { |
59 |
0 |
model.fireTableDataChanged(); |
60 |
0 |
} |
61 |
|
|
62 |
|
} |