Package de.sciss.gui

Examples of de.sciss.gui.SortedTableModel


    final ModificationButton  ggPlus, ggMinus;
    final JButton        ggAssistent;
    final JTable        table;
    final JPanel        p;
    final JTableHeader      th;
    final SortedTableModel    stm;
   
    audioBoxesFromPrefs();
   
    p      = new JPanel( new BorderLayout() );
   
    abtm    = new AudioBoxTableModel();
    stm      = new SortedTableModel( abtm );
    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.setShowGrid( true );
    table.setGridColor( Color.lightGray );
    table.setSelectionMode( ListSelectionModel.SINGLE_INTERVAL_SELECTION );
    table.setPreferredScrollableViewportSize( new Dimension( 256, 64 )); // XXX
    for( int i = 0; i < 4; i++ ) table.getColumnModel().getColumn( i ).setPreferredWidth( i == 0 ? 180 : 60 );

    stm.setSortedColumn( 0, SortedTableModel.ASCENDING );

    ggScroll  = new JScrollPane( table, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                                       ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER );
   
    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 )
      {
        final int modelIndex = collAudioBoxConfigs.size();
        final int viewIndex;
        final AudioBoxConfig cfg = createUniqueAudioBox();
        addAudioBox( cfg );
        abtm.fireTableRowsInserted( modelIndex, modelIndex );
        viewIndex = stm.getViewIndex( modelIndex );
        table.setRowSelectionInterval( viewIndex, viewIndex );
        triggerCtrlRoomRefill();
      }
    });
    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;
        AudioBoxConfig 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 );
       
          try {
            for( int i = modelIndices.length - 1; i >= 0; i-- ) {
View Full Code Here


  {
    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 ]);
View Full Code Here

     */
    public boolean importData( JComponent c, Transferable t )
    {
      MapTransferable      mt;
      final JTable      table  = (JTable) c;
      final SortedTableModel  stm    = (SortedTableModel) table.getModel();
      final int        row    = table.getSelectedRow();
      final int        mapCh  = table.getSelectedColumn() - staticColNames.length;
      final int        modelIndex;
      RoutingConfig      cfg;
      int            temp;
   
      try {
        if( mapCh >= 0 && (row < table.getRowCount()) && t.isDataFlavorSupported( mapFlavor )) {
          modelIndex  = stm.getModelIndex( row );
          cfg      = (RoutingConfig) collConfigs[ id ].get( modelIndex );
          mt      = (MapTransferable) t.getTransferData( mapFlavor );
          // only allowed within same config
          if( mt.cfg == cfg ) {
//System.err.println( "original mapping : "+(mt.idx+1)+"->"+(mt.cfg.mapping[ mt.idx ]+1)+"; new target " +(mapCh+1));
            for( int i = 0; i < cfg.numChannels; i++ ) {
              // dragged onto already mapped spot
              if( cfg.mapping[ i ] == mapCh ) {
                if( i == mt.idx ) return false; // source == target, no action
                temp          = cfg.mapping[ mt.idx ];
                cfg.mapping[ mt.idx = mapCh;
                cfg.mapping[ i ]    = temp;  // simply swapped for now
                ((AbstractTableModel) stm.getTableModel()).fireTableRowsUpdated( modelIndex, modelIndex );
                return true;
              }
            }
            // dragged onto empty spot
            cfg.mapping[ mt.idx ] = mapCh;
            setDirtyConfigs[ id ].add( cfg.id );
            ((AbstractTableModel) stm.getTableModel()).fireTableRowsUpdated( modelIndex, modelIndex );
            return true;
          }
        }
      }
      catch( UnsupportedFlavorException e1 ) { e1.printStackTrace(); }
View Full Code Here

    }
   
    protected Transferable createTransferable( JComponent c )
    {
      final JTable      table  = (JTable) c;
      final SortedTableModel  stm    = (SortedTableModel) table.getModel();
      final int        row    = table.getSelectedRow();
      final int        mapCh  = table.getSelectedColumn() - staticColNames.length;
      final int        modelIndex;
      RoutingConfig      cfg;
     
      if( mapCh >= 0 && (row < table.getRowCount()) ) {
        modelIndex  = stm.getModelIndex( row );
        cfg      = (RoutingConfig) collConfigs[ id ].get( modelIndex );
        for( int i = 0; i < cfg.numChannels; i++ ) {
          if( cfg.mapping[ i ] == mapCh ) {
            return new MapTransferable( cfg, i );
          }
View Full Code Here

TOP

Related Classes of de.sciss.gui.SortedTableModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.