(
false ) ;. setEnabled (
false );
}
}
});= new JTable ( new ContainerTableModel (containers)) ;. setRowSorter ( new TableRowSorter lt; ContainerTableModel gt; ((ContainerTableModel) containersTable. getModel ()));= new JButton ( Створити пару ) ;. addActionListener ( new ActionListener () {
@ Override
public void actionPerformed (ActionEvent e) {
int [] selectedRowIndices=itemTable. getSelectedRows (); i1=((ItemTableModel) itemTable. getModel ()). getElement (selectedRowIndices [0]); i2=((ItemTableModel) itemTable. getModel ()). getElement (selectedRowIndices [1]) ;. this . packer. createPair (i1, i2) ;. setText (ItemsViewer. this . packer. countPairs (((ItemTableModel) itemTable. getModel ()). getElements ()) + ) ;. repaint ();
((JButton) e. getSource ()). setEnabled ( false );
}
}) ;. setEnabled ( false );= new JButton ( Розбити пару ) ;. addMouseListener ( new MouseAdapter () {
@ Override
public void mousePressed (MouseEvent e) {i1=( (ItemTableModel) itemTable. getModel ()). getElement (itemTable. getSelectedRows () [0]); i2=i1. getPair () ;. this . packer. breakPair (i1, i2) ;. repaint ();
((JButton) e. getSource ()). setEnabled ( false ) ;. setText (ItemsViewer. this . packer. countPairs (((ItemTableModel) itemTable. getModel ()). getElements ()) + );
}
}) ;. setEnabled ( false );= new JLabel ( Кількість пар: );= new JLabel (packer. countPairs (((ItemTableModel) itemTable. getModel ()). getElements ()) + ); buttons= new JPanel () ;. add (createPairButton) ;. add (breakPairButton); labels= new JPanel () ;. add (pairsNum) ;. add (pairsCount) ;. add ( new JScrollPane (itemTable), new GridBagConstraints (0, 0, 1, 1, 1, 1, GridBagConstraints. < i align="justify"> NORTHWEST , GridBagConstraints. VERTICAL , new Insets (5, 5, 5, 5), 0, 0)) ;. add ( new JScrollPane (containersTable), new GridBagConstraints (1, 0, 1, 1, 1, 1, GridBagConstraints. < i align="justify"> NORTHWEST , GridBagConstraints. VERTICAL , new Insets (5, 5, 5, 5), 0, 0)) ;. add (buttons, new GridBagConstraints (0, 2, 1, 1, 1, 0, GridBagConstraints. SOUTHWEST , GridBagConstraints. < i align="justify"> NONE , new Insets (5, 5, 5,5), 0, 0)) ;. add (labels, new GridBagConstraints (1, 2, 1, 1, 1, 0, GridBagConstraints. SOUTHWEST , GridBagConstraints. < i align="justify"> NONE , new Insets (5, 5, 5,5), 0, 0));
}
public void refreshTables (List lt; Container gt; containers, List lt ; Item gt; items) {. setModel ( new ItemTableModel (items)) ;. setModel ( new ContainerTableModel (containers));
}
/**
* @ return the viewer
*/
public JPanel getViewer () {
return viewer;
}
}. java
package gui;
import java. awt. GridBagConstraints;
import java. awt. GridBagLayout;
import java. awt. Insets;
import java. awt. event. ActionEvent;
import java. awt. event. ActionListener;
import java. util. HashSet;
import java. util. List;
import java...