| 1 |
package org.astrogrid.samp.gui; |
| 2 |
|
| 3 |
import java.awt.BorderLayout; |
| 4 |
import java.awt.Dimension; |
| 5 |
import javax.swing.BorderFactory; |
| 6 |
import javax.swing.JPanel; |
| 7 |
import javax.swing.JScrollPane; |
| 8 |
import javax.swing.JSplitPane; |
| 9 |
import javax.swing.JTable; |
| 10 |
import javax.swing.ListModel; |
| 11 |
import javax.swing.ListSelectionModel; |
| 12 |
import javax.swing.border.BevelBorder; |
| 13 |
import javax.swing.event.ListSelectionEvent; |
| 14 |
import javax.swing.event.ListSelectionListener; |
| 15 |
import javax.swing.table.DefaultTableColumnModel; |
| 16 |
|
| 17 |
/** |
| 18 |
* Displays a set of transmissions in a table model, |
| 19 |
* along with a detail panel for the selected one. |
| 20 |
* |
| 21 |
* @author Mark Taylor |
| 22 |
* @since 5 Dec 2008 |
| 23 |
*/ |
| 24 |
class TransmissionView extends JPanel { |
| 25 |
|
| 26 |
/** |
| 27 |
* Constructor. |
| 28 |
* |
| 29 |
* @param transModel table model containing transmissions |
| 30 |
*/ |
| 31 |
public TransmissionView( final TransmissionTableModel transModel ) { |
| 32 |
super( new BorderLayout() ); |
| 33 |
final TransmissionPanel transPanel = new TransmissionPanel(); |
| 34 |
transPanel.setBorder( BorderFactory |
| 35 |
.createBevelBorder( BevelBorder.LOWERED ) ); |
| 36 |
final JTable table = new JTable( transModel ); |
| 37 |
Dimension tableSize = table.getPreferredScrollableViewportSize(); |
| 38 |
tableSize.height = 80; |
| 39 |
table.setPreferredScrollableViewportSize( tableSize ); |
| 40 |
DefaultTableColumnModel tcolModel = new DefaultTableColumnModel(); |
| 41 |
for ( int icol = 0; icol < transModel.getColumnCount(); icol++ ) { |
| 42 |
tcolModel.addColumn( transModel.getTableColumn( icol ) ); |
| 43 |
} |
| 44 |
table.setColumnModel( tcolModel ); |
| 45 |
final ListSelectionModel selModel = table.getSelectionModel(); |
| 46 |
selModel.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); |
| 47 |
selModel.addListSelectionListener( new ListSelectionListener() { |
| 48 |
public void valueChanged( ListSelectionEvent evt ) { |
| 49 |
Object src = evt.getSource(); |
| 50 |
if ( ! selModel.getValueIsAdjusting() && |
| 51 |
! selModel.isSelectionEmpty() ) { |
| 52 |
Transmission trans = |
| 53 |
transModel.getTransmission( table.getSelectedRow() ); |
| 54 |
transPanel.setTransmission( trans ); |
| 55 |
} |
| 56 |
} |
| 57 |
} ); |
| 58 |
JSplitPane splitter = new JSplitPane( JSplitPane.VERTICAL_SPLIT ); |
| 59 |
add( splitter, BorderLayout.CENTER ); |
| 60 |
splitter.setTopComponent( new JScrollPane( table ) ); |
| 61 |
splitter.setBottomComponent( transPanel ); |
| 62 |
Dimension splitSize = splitter.getPreferredSize(); |
| 63 |
splitSize.height = 180; |
| 64 |
splitter.setPreferredSize( splitSize ); |
| 65 |
} |
| 66 |
} |