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.Comparator;
23  
24  /**
25   * <code>MutableTableModelRows</code> is implementation of
26   * <code>TableModelRows</code> which acts as mutable
27   * <code>TabmeRowModel</code> in the same time. User can set this model to
28   * <code>JTable</code> and then add or remove rows directly from this model.
29   *
30   * @author <a href="mailto:igor.kriznar@cosylab.com">Igor Kriznar</a>
31   * @version $Id: MutableTableModelRows.java,v 1.5 2008-04-22 12:28:40 jbobnar Exp $
32   *
33   * @since May 4, 2004.
34   */
35  public class MutableTableModelRows extends TableModelRows
36  {
37  	private static final long serialVersionUID = 1L;
38  	private TableRowModelSupport support;
39  	private Comparator comparator;
40  
41  	/**
42  	 * Creates new instance.
43  	 */
44  	public MutableTableModelRows()
45  	{
46  		super(new TableRowModelSupport());
47  		support = (TableRowModelSupport)getRowModel();
48  	}
49  
50  	/**
51  	 * Inserts row at the specified index.
52  	 *
53  	 * @param index the index where to insert
54  	 * @param row the row to be added
55  	 */
56  	public synchronized void addRow(int index, TableRow row)
57  	{
58  		support.addRow(index, row);
59  	}
60  
61  	/**
62  	 * Adds row to the end of the row list.
63  	 *
64  	 * @param row the row to be added
65  	 */
66  	public synchronized void addRow(TableRow row)
67  	{
68  		support.addRow(row);
69  	}
70  
71  	/**
72  	 * Returns row at given index,
73  	 *
74  	 * @param index the index of  the row
75  	 *
76  	 * @return the row at the specified index
77  	 */
78  	public synchronized TableRow getRow(int index)
79  	{
80  		return support.getRow(index);
81  	}
82  
83  	/**
84  	 * Removes all rows from this model.
85  	 */
86  	public synchronized void removeAllRows()
87  	{
88  		support.removeAllRows();
89  	}
90  
91  	/**
92  	 * Removes row from this model.
93  	 *
94  	 * @param index rowindex to be roemoved
95  	 *
96  	 * @return the removed row
97  	 */
98  	public synchronized TableRow removeRow(int index)
99  	{
100 		return support.removeRow(index);
101 	}
102 
103 	/**
104 	 * Removes row from this model.
105 	 *
106 	 * @param row the row to be removed
107 	 */
108 	public synchronized void removeRow(TableRow row)
109 	{
110 		support.removeRow(row);
111 	}
112 
113 	/**
114 	 * Sets the number of columns this model presents.
115 	 *
116 	 * @param count the number of columns
117 	 */
118 	public void setColumnCount(int count)
119 	{
120 		support.setColumnCount(count);
121 	}
122 
123 	/**
124 	 * Sets column names.
125 	 *
126 	 * @param names the column names
127 	 */
128 	public void setColumnNames(String[] names)
129 	{
130 		support.setColumnNames(names);
131 	}
132 
133 	/**
134 	 * @return the comparator
135 	 */
136 	public Comparator getComparator() {
137 		return comparator;
138 	}
139 
140 	/**
141 	 * @param comparator the comparator to set
142 	 */
143 	public void setComparator(Comparator comparator) {
144 		this.comparator = comparator;
145 		support.setComparator(comparator);
146 	}
147 }
148 
149 /* __oOo__ */