1 |
alfonx |
244 |
/******************************************************************************* |
2 |
|
|
* Copyright (c) 2009 Martin O. J. Schmitz. |
3 |
|
|
* |
4 |
|
|
* This file is part of the SCHMITZM library - a collection of utility |
5 |
alfonx |
256 |
* classes based on Java 1.6, focusing (not only) on Java Swing |
6 |
alfonx |
244 |
* and the Geotools library. |
7 |
|
|
* |
8 |
|
|
* The SCHMITZM project is hosted at: |
9 |
|
|
* http://wald.intevation.org/projects/schmitzm/ |
10 |
|
|
* |
11 |
|
|
* This program is free software; you can redistribute it and/or |
12 |
|
|
* modify it under the terms of the GNU Lesser General Public License |
13 |
|
|
* as published by the Free Software Foundation; either version 3 |
14 |
|
|
* of the License, or (at your option) any later version. |
15 |
|
|
* |
16 |
|
|
* This program is distributed in the hope that it will be useful, |
17 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 |
|
|
* GNU General Public License for more details. |
20 |
|
|
* |
21 |
|
|
* You should have received a copy of the GNU Lesser General Public License (license.txt) |
22 |
|
|
* along with this program; if not, write to the Free Software |
23 |
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
24 |
|
|
* or try this link: http://www.gnu.org/licenses/lgpl.html |
25 |
|
|
* |
26 |
|
|
* Contributors: |
27 |
|
|
* Martin O. J. Schmitz - initial API and implementation |
28 |
|
|
* Stefan A. Krüger - additional utility classes |
29 |
|
|
******************************************************************************/ |
30 |
alfonx |
139 |
package skrueger.geotools.labelsearch; |
31 |
|
|
|
32 |
|
|
import java.util.List; |
33 |
|
|
|
34 |
|
|
import javax.swing.table.TableModel; |
35 |
|
|
|
36 |
|
|
import schmitzm.swing.table.AbstractTableModel; |
37 |
|
|
|
38 |
|
|
/** |
39 |
|
|
* A {@link TableModel} which presents a {@link List} of {@link SearchResult}s. |
40 |
|
|
* by the time of writing, {@link SearchResult}'s only concrete class is |
41 |
|
|
* {@link SearchResultFeature}, but others might follow that reference to a Map or a DpEntry.<br/> |
42 |
|
|
* The three columns of this {@link TableModel} are: result number, full name, |
43 |
|
|
* name of layer containing the result |
44 |
|
|
* |
45 |
|
|
* @author Stefan A. Krueger |
46 |
|
|
* |
47 |
|
|
*/ |
48 |
|
|
public class SearchResultTableModel extends AbstractTableModel implements |
49 |
|
|
TableModel { |
50 |
|
|
|
51 |
|
|
private final List<SearchResult> searchResultsList; |
52 |
|
|
|
53 |
|
|
public SearchResultTableModel(List<SearchResult> searchResultsList) { |
54 |
|
|
this.searchResultsList = searchResultsList; |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
@Override |
58 |
|
|
/* |
59 |
|
|
* The three columns of this {@link TableModel} are: full |
60 |
|
|
* name, name of layer containing the result |
61 |
|
|
*/ |
62 |
|
|
public int getColumnCount() { |
63 |
|
|
return 2; |
64 |
|
|
} |
65 |
|
|
|
66 |
|
|
@Override |
67 |
|
|
public int getRowCount() { |
68 |
|
|
return searchResultsList.size(); |
69 |
|
|
} |
70 |
|
|
|
71 |
|
|
@Override |
72 |
|
|
public Object getValueAt(int row, int column) { |
73 |
|
|
// if (column == 0) { |
74 |
|
|
// return row + 1; |
75 |
|
|
// } else |
76 |
|
|
if (column == 0) { |
77 |
|
|
return searchResultsList.get(row).getTitle(); |
78 |
|
|
|
79 |
|
|
} else if (column == 1) { |
80 |
|
|
return searchResultsList.get(row).getInTitle(); |
81 |
|
|
|
82 |
|
|
} else return null; |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
@Override |
86 |
|
|
public String[] createColumnNames() { |
87 |
|
|
return new String[] {LabelSearch.R("SearchMapDialog.Results.Column.Name"), LabelSearch.R("SearchMapDialog.Results.Column.Layer")}; |
88 |
|
|
} |
89 |
|
|
|
90 |
|
|
} |