svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / beans / table / models / ModelLoader.java @ 40561
History | View | Annotate | Download (5.77 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program 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 this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.gui.beans.table.models; |
25 |
|
26 |
import java.awt.event.ActionListener; |
27 |
import java.util.ArrayList; |
28 |
|
29 |
import javax.swing.JTable; |
30 |
import javax.swing.table.DefaultTableModel; |
31 |
import javax.swing.table.TableColumn; |
32 |
/**
|
33 |
* Cargador de Modelos
|
34 |
*
|
35 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
36 |
*/
|
37 |
public class ModelLoader { |
38 |
private static DefaultTableModel tableModel = null; |
39 |
|
40 |
public JTable load(String model, String[] columnNames, ArrayList listeners) { |
41 |
if (model == null || model.equals("")) |
42 |
return null; |
43 |
|
44 |
ActionListener actionListener = null; |
45 |
if(listeners != null) { |
46 |
for (int i = 0; i < listeners.size(); i++) { |
47 |
if(listeners.get(i) instanceof ActionListener) |
48 |
actionListener = (ActionListener)listeners.get(i);
|
49 |
} |
50 |
} |
51 |
|
52 |
JTable table = null; |
53 |
|
54 |
if (model.equals("ListModel")) { |
55 |
tableModel = new ListModel(columnNames); |
56 |
table = new JTable(tableModel); |
57 |
} |
58 |
|
59 |
if (model.equals("TreeRadioButtonModel")) { |
60 |
tableModel = new TreeRadioButtonModel(columnNames);
|
61 |
table = new JTable(tableModel); |
62 |
TableColumn column = null; |
63 |
|
64 |
for (int i = 0; i < columnNames.length - 1; i++) { |
65 |
column = table.getColumnModel().getColumn(i); |
66 |
column.setCellRenderer(new TreeRadioButtonColumnRenderer());
|
67 |
column.setCellEditor(new TreeRadioButtonColumnEditor());
|
68 |
} |
69 |
} |
70 |
|
71 |
if (model.equals("ARGBBandSelectorModel")) { |
72 |
tableModel = new ARGBBandSelectorModel(columnNames);
|
73 |
table = new JTable(tableModel); |
74 |
TableColumn column = null; |
75 |
|
76 |
for (int i = 0; i < columnNames.length - 1; i++) { |
77 |
column = table.getColumnModel().getColumn(i); |
78 |
column.setMaxWidth(52);
|
79 |
column.setMinWidth(26);
|
80 |
column.setCellRenderer(new TreeRadioButtonColumnRenderer());
|
81 |
TreeRadioButtonColumnEditor trbce = new TreeRadioButtonColumnEditor();
|
82 |
trbce.setActionListener(actionListener); |
83 |
column.setCellEditor(trbce); |
84 |
} |
85 |
} |
86 |
|
87 |
if (model.equals("RadioButtonModel")) { |
88 |
tableModel = new RadioButtonModel(columnNames);
|
89 |
table = new JTable(tableModel); |
90 |
TableColumn column = null; |
91 |
|
92 |
for (int i = 0; i < columnNames.length - 1; i++) { |
93 |
column = table.getColumnModel().getColumn(i); |
94 |
column.setCellRenderer(new TreeRadioButtonColumnRenderer());
|
95 |
column.setCellEditor(new TreeRadioButtonColumnEditor());
|
96 |
} |
97 |
} |
98 |
|
99 |
if (model.equals("CheckBoxModel")) { |
100 |
tableModel = new CheckBoxModel(columnNames);
|
101 |
table = new JTable(tableModel); |
102 |
TableColumn column = null; |
103 |
|
104 |
column = table.getColumnModel().getColumn(0);
|
105 |
column.setCellRenderer(new CheckBoxColumnRenderer());
|
106 |
column.setCellEditor(new CheckBoxColumnEditor());
|
107 |
} |
108 |
|
109 |
if (model.equals("TableButtonModel")) { |
110 |
tableModel = new TableButtonModel(columnNames);
|
111 |
table = new JTable(tableModel); |
112 |
TableColumn column = null; |
113 |
|
114 |
column = table.getColumnModel().getColumn(0);
|
115 |
column.setCellRenderer(new TableColorButtonColumnRenderer(true)); |
116 |
column.setCellEditor(new TableColorButtonColumnEditor((DefaultTableModel) tableModel, table)); |
117 |
|
118 |
column = table.getColumnModel().getColumn(4);
|
119 |
column.setCellRenderer(new TableSelectorButtonColumnRenderer());
|
120 |
column.setCellEditor(new TableSelectorButtonColumnEditor());
|
121 |
} |
122 |
|
123 |
if (model.equals("TableColorModel")) { |
124 |
tableModel = new TableColorModel(columnNames);
|
125 |
table = new JTable(tableModel); |
126 |
TableColumn column = null; |
127 |
|
128 |
column = table.getColumnModel().getColumn(0);
|
129 |
column.setCellRenderer(new TableColorButtonColumnRenderer(true)); |
130 |
column.setCellEditor(new TableColorButtonColumnEditor((DefaultTableModel) tableModel, table)); |
131 |
|
132 |
column = table.getColumnModel().getColumn(5);
|
133 |
column.setCellRenderer(new TableSelectorButtonColumnRenderer());
|
134 |
column.setCellEditor(new TableSelectorButtonColumnEditor());
|
135 |
} |
136 |
|
137 |
if (model.equals("ROIsTableModel")) { |
138 |
tableModel = new ROIsTableModel(columnNames);
|
139 |
table = new JTable(tableModel); |
140 |
TableColumn column = null; |
141 |
|
142 |
column = table.getColumnModel().getColumn(4);
|
143 |
column.setCellRenderer(new TableColorButtonColumnRenderer(true)); |
144 |
column.setCellEditor(new TableColorButtonColumnEditor((DefaultTableModel) tableModel, table)); |
145 |
} |
146 |
if (model.equals("ProfilesTableModel")) { |
147 |
tableModel = new ProfilesTableModel(columnNames);
|
148 |
table = new JTable(tableModel); |
149 |
TableColumn column = null; |
150 |
|
151 |
column = table.getColumnModel().getColumn(1);
|
152 |
column.setCellRenderer(new TableColorButtonColumnRenderer(true)); |
153 |
column.setCellEditor(new TableColorButtonColumnEditor((DefaultTableModel) tableModel, table)); |
154 |
} |
155 |
|
156 |
if (model.equals("GCPModel")) { |
157 |
tableModel = new GCPModel(columnNames);
|
158 |
table = new JTable(tableModel); |
159 |
TableColumn column = null; |
160 |
|
161 |
column = table.getColumnModel().getColumn(0);
|
162 |
column.setCellRenderer(new CheckBoxColumnRenderer(actionListener));
|
163 |
column.setCellEditor(new CheckBoxColumnEditor());
|
164 |
} |
165 |
|
166 |
return table;
|
167 |
} |
168 |
|
169 |
/**
|
170 |
* Obtiene el modelo de la tabla
|
171 |
* @return DefaultTableModel
|
172 |
*/
|
173 |
public DefaultTableModel getTableModel() { |
174 |
return tableModel;
|
175 |
} |
176 |
} |