Home » openjdk-7 » net.sourceforge » neurosdbm » [javadoc | source]

    1   //
    2   //  Neuros Database Manipulator
    3   //  Copyright (C) 2003  Neuros Database Manipulator
    4   //
    5   //  This program is free software; you can redistribute it and/or modify
    6   //  it under the terms of the GNU General Public License as published by
    7   //  the Free Software Foundation; either version 2 of the License, or
    8   //  (at your option) any later version.
    9   //
   10   //  This program is distributed in the hope that it will be useful,
   11   //  but WITHOUT ANY WARRANTY; without even the implied warranty of
   12   //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13   //  GNU General Public License for more details.
   14   //
   15   //  You should have received a copy of the GNU General Public License
   16   //  along with this program; if not, write to the Free Software
   17   //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   18   //
   19   //  For information about Neuros Database Manipulator and its authors,
   20   //  please contact the Neuros Database Manipulator Web Site at
   21   //  http://neurosdbm.sourceforge.net
   22   //
   23   //
   24   
   25   package net.sourceforge.neurosdbm;
   26   
   27   
   28   import java.awt.GridBagLayout;
   29   import java.awt.GridBagConstraints;
   30   import java.awt.Insets;
   31   import java.awt.event.ActionListener;
   32   import java.awt.event.ActionEvent;
   33   import javax.swing.JDialog;
   34   import javax.swing.JScrollPane;
   35   import javax.swing.JTable;
   36   import javax.swing.JButton;
   37   import javax.swing.event.ChangeEvent;
   38   import javax.swing.table.TableModel;
   39   import javax.swing.table.AbstractTableModel;
   40   import net.sourceforge.neurosdbm.db.FullTrackInfo;
   41   
   42   
   43   class ColumnChooser extends JDialog implements ActionListener {
   44   
   45     private Boolean enabled[];
   46   
   47     private ColumnTable columnTable;
   48     private JButton okButton;
   49     private JButton cancelButton;
   50     
   51     ColumnChooser(MainFrame parent) {
   52       super(parent, true);
   53   
   54       enabled = NeurosProperties.getColumnChooser();
   55   
   56       setTitle("Select Table Columns To Be Displayed");
   57   
   58       GridBagLayout layout = new GridBagLayout();
   59       getContentPane().setLayout(layout);
   60       GridBagConstraints constraints;
   61   
   62       constraints = new GridBagConstraints();
   63       constraints.fill = GridBagConstraints.BOTH;
   64       constraints.gridwidth = GridBagConstraints.REMAINDER;
   65       constraints.weightx = 1.0;
   66       constraints.weighty = 1.0;
   67       constraints.insets = new Insets(5, 5, 5, 5);
   68       columnTable = new ColumnTable(new ColumnTableModel());
   69       columnTable.setCellSelectionEnabled(false);
   70       JScrollPane columnTableScrollPane = new JScrollPane(columnTable);
   71       layout.setConstraints(columnTableScrollPane, constraints);
   72       getContentPane().add(columnTableScrollPane);
   73   
   74       constraints = new GridBagConstraints();
   75       constraints.anchor = GridBagConstraints.EAST;
   76       constraints.insets = new Insets(5, 5, 5, 5);
   77       constraints.weightx = 1.0;
   78       okButton = new JButton("OK");
   79       okButton.addActionListener(this);
   80       layout.setConstraints(okButton, constraints);
   81       getContentPane().add(okButton);
   82       
   83       constraints = new GridBagConstraints();
   84       constraints.anchor = GridBagConstraints.EAST;
   85       constraints.gridwidth = GridBagConstraints.REMAINDER;
   86       constraints.insets = new Insets(5, 5, 5, 5);
   87       cancelButton = new JButton("Cancel");
   88       cancelButton.addActionListener(this);
   89       layout.setConstraints(cancelButton, constraints);
   90       getContentPane().add(cancelButton);
   91   
   92       setLocationRelativeTo(parent);
   93       pack();
   94       
   95       enabled = NeurosProperties.getColumnChooser();
   96     }
   97   
   98   
   99     public void actionPerformed(ActionEvent evt) {
  100       if (evt.getSource() == okButton) {
  101         NeurosProperties.setColumnChooser(enabled);
  102         NeurosProperties.save();
  103         dispose();
  104       }
  105       if (evt.getSource() == cancelButton) {
  106         dispose();
  107       }
  108     }
  109     
  110   
  111     private class ColumnTable extends JTable {
  112       ColumnTable(TableModel model) {
  113         super(model);
  114       }
  115       
  116       public void editingStopped(ChangeEvent e) {
  117         int rowEdited = getEditingRow();
  118         enabled[rowEdited] = new Boolean(!enabled[rowEdited].booleanValue());
  119         ((AbstractTableModel)getModel()).fireTableDataChanged();
  120         super.editingStopped(e);
  121       }
  122     }
  123     
  124     private class ColumnTableModel extends AbstractTableModel {
  125   
  126       public int getRowCount() {
  127         return FullTrackInfo.NUMBER_COLUMNS;
  128       }
  129       
  130       public int getColumnCount() {
  131         return 2;
  132       }
  133   
  134       public String getColumnName(int column) {
  135         switch (column) {
  136         case 0:
  137           return "Table Column Name";
  138         case 1:
  139           return "Enabled";
  140         }
  141         return null;
  142       }
  143   
  144       public Class getColumnClass(int column) {
  145         switch (column) {
  146         case 0:
  147           return String.class;
  148         case 1:
  149           return Boolean.class;
  150         }
  151         return null;
  152       }
  153   
  154       public boolean isCellEditable(int rowIndex, int columnIndex) {
  155         switch (columnIndex) {
  156         case 0:
  157           return false;
  158         case 1:
  159           return true;
  160         }
  161         return false;
  162       }
  163       
  164       public Object getValueAt(int row, int column) {
  165         switch (column) {
  166         case 0:
  167           return FullTrackInfo.columnHeaders[row];
  168         case 1:
  169           return enabled[row];
  170         }
  171         return null;
  172       }
  173     
  174     }
  175   }

Home » openjdk-7 » net.sourceforge » neurosdbm » [javadoc | source]