List of usage examples for javax.swing.event TableModelEvent TableModelEvent
public TableModelEvent(TableModel source)
TableModel
to get the new row count and all the appropriate values. From source file:org.simmi.GeneSetHead.java
License:asdf
public List getSelspecContigs(List<JComponent> complist, final Map<String, List<Sequence>> speccontigMap, final String... selspec) { List<Sequence> contigs = null; final List<String> specs = new ArrayList<String>(speccontigMap.keySet()); final JTable stable = new JTable(); stable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); final TableModel stablemodel = new TableModel() { @Override/*from w w w . ja va 2 s .c o m*/ public int getRowCount() { return specs.size(); } @Override public int getColumnCount() { return 1; } @Override public String getColumnName(int columnIndex) { return "Species"; } @Override public Class<?> getColumnClass(int columnIndex) { return String.class; } @Override public boolean isCellEditable(int rowIndex, int columnIndex) { return false; } @Override public Object getValueAt(int rowIndex, int columnIndex) { if (rowIndex >= 0 && rowIndex < specs.size()) return specs.get(rowIndex); return null; } @Override public void setValueAt(Object aValue, int rowIndex, int columnIndex) { } @Override public void addTableModelListener(TableModelListener l) { } @Override public void removeTableModelListener(TableModelListener l) { } }; stable.setModel(stablemodel); final JTable ctable = new JTable(); ctable.setAutoCreateRowSorter(true); final TableModel ctablemodel = new TableModel() { @Override public int getRowCount() { int r = stable.getSelectedRow(); String spec = selspec.length > 0 ? selspec[0] : (String) stable.getValueAt(r, 0); if (spec != null) { List<Sequence> contigs = geneset.speccontigMap.get(spec); return contigs.size(); } return 0; } @Override public int getColumnCount() { return 1; } @Override public String getColumnName(int columnIndex) { return "Contigs"; } @Override public Class<?> getColumnClass(int columnIndex) { return Sequence.class; } @Override public boolean isCellEditable(int rowIndex, int columnIndex) { return false; } @Override public Object getValueAt(int rowIndex, int columnIndex) { int r = stable.getSelectedRow(); String spec = selspec.length > 0 ? selspec[0] : (String) stable.getValueAt(r, 0); List<Sequence> contigs = geneset.speccontigMap.get(spec); return contigs.get(rowIndex); } @Override public void setValueAt(Object aValue, int rowIndex, int columnIndex) { } @Override public void addTableModelListener(TableModelListener l) { } @Override public void removeTableModelListener(TableModelListener l) { } }; ctable.setModel(ctablemodel); JScrollPane sscrollpane = new JScrollPane(stable); JScrollPane cscrollpane = new JScrollPane(ctable); FlowLayout flowlayout = new FlowLayout(); JComponent c = new JComponent() { }; c.setLayout(flowlayout); if (selspec.length == 0) c.add(sscrollpane); c.add(cscrollpane); if (complist != null) { for (JComponent comp : complist) { c.add(comp); } } stable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { ctable.tableChanged(new TableModelEvent(ctablemodel)); } }); JOptionPane.showMessageDialog(this, c); int[] rr = stable.getSelectedRows(); if (rr.length > 1) { List slist = new ArrayList(); for (int r : rr) { int i = stable.convertRowIndexToModel(r); slist.add(specs.get(i)); } return slist; } else { int sr = stable.getSelectedRow(); String spec = selspec.length > 0 ? selspec[0] : (String) stable.getValueAt(sr, 0); if (spec != null) { List<Sequence> ctgs = geneset.speccontigMap.get(spec); rr = ctable.getSelectedRows(); contigs = new ArrayList<Sequence>(); for (int r : rr) { int i = ctable.convertRowIndexToModel(r); contigs.add(ctgs.get(i)); } } return contigs; } }