01: ///The contents of this file are subject to the Mozilla Public License Version 1.1
02: //(the "License"); you may not use this file except in compliance with the
03: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
04: //
05: //Software distributed under the License is distributed on an "AS IS" basis,
06: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
07: //for the specific language governing rights and
08: //limitations under the License.
09: //
10: //The Original Code is "The Columba Project"
11: //
12: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14: //
15: //All Rights Reserved.
16: package org.columba.mail.gui.config.filter;
17:
18: import javax.swing.JTable;
19: import javax.swing.ListSelectionModel;
20: import javax.swing.table.DefaultTableCellRenderer;
21: import javax.swing.table.TableColumn;
22:
23: import org.columba.core.filter.FilterList;
24: import org.columba.core.filter.IFilterList;
25:
26: class FilterListTable extends JTable {
27: public FilterListTable(IFilterList filterList, ConfigFrame frame) {
28: super (new FilterListDataModel(filterList));
29: setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
30: setShowGrid(false);
31: setIntercellSpacing(new java.awt.Dimension(0, 0));
32:
33: TableColumn tc = getColumnModel().getColumn(1);
34: tc.setMaxWidth(80);
35: tc.setMinWidth(80);
36:
37: DefaultTableCellRenderer renderer = (DefaultTableCellRenderer) tableHeader
38: .getDefaultRenderer();
39: renderer.setHorizontalAlignment(DefaultTableCellRenderer.LEFT);
40: }
41:
42: public void update() {
43: ((FilterListDataModel) getModel()).fireTableDataChanged();
44: }
45:
46: /**
47: * The specified row has been updated and should be repainted.
48: * @param row the row that has been updated.
49: */
50: public void update(int row) {
51: ((FilterListDataModel) getModel()).fireTableRowsUpdated(row,
52: row);
53: }
54:
55: /**
56: * Sets the specified row indicies to be selected in the table.
57: * Note that this clears all previous selections.
58: * @param selectedRows an array of integers containing the indices of
59: * all rows that are to be selected.
60: */
61: public void setRowSelection(int[] selectedRows) {
62: ListSelectionModel model = getSelectionModel();
63: model.setValueIsAdjusting(true);
64: model.clearSelection();
65:
66: for (int i = 0; i < selectedRows.length; i++) {
67: model
68: .addSelectionInterval(selectedRows[i],
69: selectedRows[i]);
70: }
71:
72: model.setValueIsAdjusting(false);
73: }
74: }
|