use of pcgen.facade.util.event.ReferenceListener in project pcgen by PCGen.
the class CharacterHPDialog method initComponents.
private void initComponents() {
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
Container pane = getContentPane();
pane.setLayout(new BorderLayout());
JTable table = new JTable(tableModel) {
@Override
public TableCellEditor getCellEditor(int row, int column) {
if (column == 5) {
//TODO: the max roll should be calculated in a different manner
String hd = levels.getClassTaken(levels.getElementAt(row)).getHD();
int max = NumberUtils.toInt(hd);
return new IntegerEditor(1, max);
} else {
return super.getCellEditor(row, column);
}
}
};
table.setDefaultRenderer(JButton.class, new Renderer());
table.setDefaultEditor(JButton.class, new Editor());
table.setCellSelectionEnabled(false);
table.setRowHeight(new IntegerEditor(1, 10).getPreferredSize().height);
JTableHeader header = table.getTableHeader();
header.setReorderingAllowed(false);
JScrollPane scrollPane = new JScrollPane(table);
pane.add(scrollPane, BorderLayout.CENTER);
Box box = Box.createHorizontalBox();
box.add(new JLabel("Total Hp:"));
box.add(Box.createHorizontalStrut(3));
final ReferenceListener<Integer> hpListener = new ReferenceListener<Integer>() {
@Override
public void referenceChanged(ReferenceEvent<Integer> e) {
totalHp.setText(e.getNewReference().toString());
}
};
ReferenceFacade<Integer> hpRef = character.getTotalHPRef();
totalHp.setText(hpRef.get().toString());
hpRef.addReferenceListener(hpListener);
box.add(totalHp);
box.add(Box.createHorizontalStrut(5));
JButton button = new JButton("Reroll All");
button.setActionCommand("Reroll");
button.addActionListener(this);
box.add(button);
box.add(Box.createHorizontalGlue());
button = new JButton("Close");
button.setActionCommand("Close");
button.addActionListener(this);
box.add(button);
pane.add(box, BorderLayout.SOUTH);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
//Make sure to remove the listeners so that the garbage collector can
//dispose of this dialog and prevent a memory leak
levels.removeHitPointListener(tableModel);
character.getTotalHPRef().removeReferenceListener(hpListener);
}
});
Utility.installEscapeCloseOperation(this);
}
Aggregations