private JComponent createTab( final int id )
{
final JPanel tab;
final LayoutManager lay;
final JTable table;
final AbstractTableModel tm;
final SortedTableModel stm;
final JTableHeader th;
final TableCellRenderer tcr;
final JScrollPane scroll;
final JTextArea lbTextArea;
final Box b;
final AbstractButton ggPlus, ggMinus;
tab = new JPanel();
lay = new BorderLayout();
tab.setLayout( lay );
lbTextArea = new JTextArea( getResourceString( KEY_INFOTEXT[ id ]));
lbTextArea.setEditable( false );
lbTextArea.setBackground( null );
lbTextArea.setColumns( 32 );
lbTextArea.setLineWrap( true );
lbTextArea.setWrapStyleWord( true );
tab.add( lbTextArea, BorderLayout.NORTH );
lbTextArea.setBorder( BorderFactory.createEmptyBorder( 8, 2, 8, 2 ));
tm = new TableModel( id );
stm = new SortedTableModel( tm );
table = new JTable( stm );
th = table.getTableHeader();
stm.setTableHeader( th );
th.setReorderingAllowed( false );
th.setResizingAllowed( true );
table.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );
table.setCellSelectionEnabled( true );
table.setColumnSelectionAllowed( false );
table.setDragEnabled( true );
table.setShowGrid( true );
table.setGridColor( Color.lightGray );
table.setSelectionMode( ListSelectionModel.SINGLE_INTERVAL_SELECTION );
table.setTransferHandler( new MapTransferHandler( id ));
stm.setSortedColumn( 0, SortedTableModel.ASCENDING );
tcr = new MappingRenderer();
setColumnRenderersAndWidths( table, stm, tcr );
scroll = new JScrollPane( table, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS );
tab.add( scroll, BorderLayout.CENTER );
b = Box.createHorizontalBox();
ggPlus = new ModificationButton( ModificationButton.SHAPE_PLUS );
ggMinus = new ModificationButton( ModificationButton.SHAPE_MINUS );
ggMinus.setEnabled( false );
ggPlus.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e )
{
// int row = table.getSelectedRow() + table.getSelectedRowCount();
// if( row <= 0 ) row = collConfigs[ ID ].size();
final int modelIndex = collConfigs[ id ].size();
final int viewIndex;
final RoutingConfig cfg = createUniqueConfig( id );
// collConfigs[ ID ].add( row, cfg );
collConfigs[ id ].add( cfg );
setConfigIDs[ id ].add( cfg.id );
setConfigNames[ id ].add( cfg.name );
setDirtyConfigs[ id ].add( cfg.id );
tm.fireTableRowsInserted( modelIndex, modelIndex );
viewIndex = stm.getViewIndex( modelIndex );
table.setRowSelectionInterval( viewIndex, viewIndex );
}
});
ggMinus.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e )
{
final int firstRow = Math.max( 0, table.getSelectedRow() );
final int lastRow = Math.min( table.getRowCount(), firstRow + table.getSelectedRowCount() ) - 1;
RoutingConfig cfg;
final int[] modelIndices;
if( firstRow <= lastRow ) {
modelIndices = new int[ lastRow - firstRow + 1 ];
for( int i = 0, viewIndex = firstRow; viewIndex <= lastRow; i++, viewIndex++ ) {
modelIndices[ i ] = stm.getModelIndex( viewIndex );
}
Arrays.sort( modelIndices );
for( int i = modelIndices.length - 1; i >= 0; i-- ) {
cfg = (RoutingConfig) collConfigs[ id ].remove( modelIndices[ i ]);
setConfigNames[ id ].remove( cfg.name );
// never remove the id during one editing session,
// because that will confuse the prefs listeners
// and the setDirtyConfigs approach
// setConfigIDs[ id ].remove( cfg.id );
setDirtyConfigs[ id ].add( cfg.id );
}
// tm.fireTableRowsDeleted( firstRow, lastRow );
tm.fireTableDataChanged();
}
}
});
b.add( ggPlus );
b.add( ggMinus );