Search in sources :

Example 1 with ReferenceEvent

use of pcgen.facade.util.event.ReferenceEvent 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);
}
Also used : JScrollPane(javax.swing.JScrollPane) IntegerEditor(pcgen.gui2.util.table.IntegerEditor) JButton(javax.swing.JButton) JTableHeader(javax.swing.table.JTableHeader) JLabel(javax.swing.JLabel) WindowAdapter(java.awt.event.WindowAdapter) Box(javax.swing.Box) ReferenceListener(pcgen.facade.util.event.ReferenceListener) Container(java.awt.Container) BorderLayout(java.awt.BorderLayout) ReferenceEvent(pcgen.facade.util.event.ReferenceEvent) JTable(javax.swing.JTable) WindowEvent(java.awt.event.WindowEvent) TableCellRenderer(javax.swing.table.TableCellRenderer) TableCellEditor(javax.swing.table.TableCellEditor) AbstractCellEditor(javax.swing.AbstractCellEditor) IntegerEditor(pcgen.gui2.util.table.IntegerEditor)

Aggregations

BorderLayout (java.awt.BorderLayout)1 Container (java.awt.Container)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 AbstractCellEditor (javax.swing.AbstractCellEditor)1 Box (javax.swing.Box)1 JButton (javax.swing.JButton)1 JLabel (javax.swing.JLabel)1 JScrollPane (javax.swing.JScrollPane)1 JTable (javax.swing.JTable)1 JTableHeader (javax.swing.table.JTableHeader)1 TableCellEditor (javax.swing.table.TableCellEditor)1 TableCellRenderer (javax.swing.table.TableCellRenderer)1 ReferenceEvent (pcgen.facade.util.event.ReferenceEvent)1 ReferenceListener (pcgen.facade.util.event.ReferenceListener)1 IntegerEditor (pcgen.gui2.util.table.IntegerEditor)1