View Javadoc

1   /*
2    * Copyright (c) 2003-2008 by Cosylab d. d.
3    *
4    * This file is part of CosyBeans-Common.
5    *
6    * CosyBeans-Common is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU General Public License as published by
8    * the Free Software Foundation, either version 3 of the License, or
9    * (at your option) any later version.
10   *
11   * CosyBeans-Common is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   *
16   * You should have received a copy of the GNU General Public License
17   * along with CosyBeans-Common.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  
20  package com.cosylab.gui.components.table;
21  
22  import java.util.Vector;
23  
24  import javax.swing.JTable;
25  import javax.swing.ListSelectionModel;
26  import javax.swing.table.TableColumnModel;
27  import javax.swing.table.TableModel;
28  
29  
30  /**
31   * <code>QueueTable</code> uses <code>QueueTableModelInterceptor</code> update
32   * table  in ferformance and thread safe way. User can use this table exactely
33   * the same way as <code>JTable</code>, all the event intercetion is done
34   * automagically inside this implementation.
35   *
36   * @author <a href="mailto:igor.kriznar@cosylab.com">Igor Kriznar</a>
37   * @version $Id: QueueTable.java,v 1.6 2008-04-22 12:28:40 jbobnar Exp $
38   *
39   * @since May 3, 2004.
40   */
41  public class QueueTable extends JTable
42  {
43  	private static final long serialVersionUID = 1L;
44  	private TableModel model;
45  	private QueueTableModelInterceptor interceptor;
46  
47  	/**
48  	 * Constructs a new QueueTable object.
49  	 * @see JTable#JTable()
50  	 */
51  	public QueueTable()
52  	{
53  		super();
54  	}
55  
56  	/**
57  	 * Constructs a new QueueTable object with the given number of rows and columns.
58  	 * 
59  	 * @param numRows number of rows
60  	 * @param numColumns number of columns
61  	 * @see JTable#JTable(int, int)
62  	 */
63  	public QueueTable(int numRows, int numColumns)
64  	{
65  		super(numRows, numColumns);
66  	}
67  
68  	/**
69  	 * Constructs a new QueueTable with the given TableModel.
70  	 * 
71  	 * @param dm table model
72  	 * @see JTable#JTable(TableModel)
73  	 */
74  	public QueueTable(TableModel dm)
75  	{
76  		super(dm);
77  	}
78  
79  	/**
80  	 * Constructs a new QueueTable with initial values and column names.
81  	 * 
82  	 * @param rowData initial data
83  	 * @param columnNames column names
84  	 * @see JTable#JTable(Object[][], Object[])
85  	 */
86  	public QueueTable(Object[][] rowData, Object[] columnNames)
87  	{
88  		super(rowData, columnNames);
89  	}
90  
91  	/**
92  	 * Constructs a new QueueTable with initial values and column names.
93  	 * 
94  	 * @param rowData initial data
95  	 * @param columnNames column names
96  	 * @see JTable#JTable(Vector, Vector)
97  	 */
98  	public QueueTable(Vector rowData, Vector columnNames)
99  	{
100 		super(rowData, columnNames);
101 	}
102 
103 	/**
104 	 * Constructs a new QueueTable using the given models.
105 	 * 
106 	 * @param dm table model
107 	 * @param cm column model
108 	 * @see JTable#JTable(TableModel, TableColumnModel)
109 	 */
110 	public QueueTable(TableModel dm, TableColumnModel cm)
111 	{
112 		super(dm, cm);
113 	}
114 
115 	/**
116 	 * Constructs a new QueueTable using the given models.
117 	 * 
118 	 * @param dm table model
119 	 * @param cm column model
120 	 * @param sm selection model
121 	 * @see JTable#JTable(TableModel, TableColumnModel, ListSelectionModel)
122 	 */
123 	public QueueTable(TableModel dm, TableColumnModel cm, ListSelectionModel sm)
124 	{
125 		super(dm, cm, sm);
126 	}
127 
128 	/* (non-Javadoc)
129 	 * @see javax.swing.JTable#setModel(javax.swing.table.TableModel)
130 	 */
131 	public void setModel(TableModel dataModel)
132 	{
133 		model = dataModel;
134 
135 		if (model == null) {
136 			super.setModel(null);
137 		} else {
138 			//super.setModel(model);
139 			QueueTableModelInterceptor i=new QueueTableModelInterceptor(model);
140 			if (interceptor!=null) {
141 				i.setRelaxationTime(interceptor.getRelaxationTime());
142 				interceptor.destroy();
143 			}
144 			super.setModel(interceptor=i);
145 		}
146 	}
147 	
148 	/* (non-Javadoc)
149 	 * @see javax.swing.JTable#getModel()
150 	 */
151 	public TableModel getModel() {
152 		return model;
153 	}
154 
155 	/**
156 	 * Returns minimum time betwean two table updates interceptor will wait.
157 	 * @return minimum time betwean two table updates 
158 	 */
159 	public int getRelaxationTime() {
160 		return interceptor.getRelaxationTime();
161 	}
162 
163 	/**
164 	 * Sets minimum time betwean two table updates interceptor will wait.
165 	 * @param relaxationTime
166 	 */
167 	public void setRelaxationTime(int relaxationTime) {
168 		interceptor.setRelaxationTime(relaxationTime);
169 	}
170 }
171 
172 /* __oOo__ */