svn-gvsig-desktop / tags / PilotoRaster_Build_5 / libraries / libUIComponent_praster / src / org / gvsig / gui / beans / table / models / ModelLoader.java @ 11401
History | View | Annotate | Download (3.39 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package org.gvsig.gui.beans.table.models; |
20 |
|
21 |
import javax.swing.JTable; |
22 |
import javax.swing.table.DefaultTableModel; |
23 |
import javax.swing.table.TableColumn; |
24 |
|
25 |
/**
|
26 |
* Cargador de Modelos
|
27 |
*
|
28 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
29 |
*
|
30 |
*/
|
31 |
public class ModelLoader{ |
32 |
|
33 |
private static DefaultTableModel tableModel = null; |
34 |
|
35 |
public JTable load(String model, String[] columnNames){ |
36 |
if(model == null || model.equals("")) |
37 |
return null; |
38 |
|
39 |
JTable table = null; |
40 |
|
41 |
if(model.equals("ListModel")){ |
42 |
tableModel = new ListModel(columnNames); |
43 |
table = new JTable(tableModel); |
44 |
} |
45 |
|
46 |
if(model.equals("TreeRadioButtonModel")){ |
47 |
tableModel = new TreeRadioButtonModel(columnNames);
|
48 |
table = new JTable(tableModel); |
49 |
TableColumn column = null; |
50 |
|
51 |
for (int i = 0; i < columnNames.length - 1; i++) { |
52 |
column = table.getColumnModel().getColumn(i); |
53 |
column.setCellRenderer(new TreeRadioButtonColumnRenderer());
|
54 |
column.setCellEditor(new TreeRadioButtonColumnEditor());
|
55 |
} |
56 |
} |
57 |
|
58 |
if(model.equals("RadioButtonModel")){ |
59 |
tableModel = new RadioButtonModel(columnNames);
|
60 |
table = new JTable(tableModel); |
61 |
TableColumn column = null; |
62 |
|
63 |
for (int i = 0; i < columnNames.length - 1; i++){ |
64 |
column = table.getColumnModel().getColumn(i); |
65 |
column.setCellRenderer(new TreeRadioButtonColumnRenderer());
|
66 |
column.setCellEditor(new TreeRadioButtonColumnEditor());
|
67 |
} |
68 |
} |
69 |
|
70 |
if(model.equals("CheckBoxModel")){ |
71 |
tableModel = new CheckBoxModel(columnNames);
|
72 |
table = new JTable(tableModel); |
73 |
TableColumn column = null; |
74 |
|
75 |
for (int i = 0; i < columnNames.length - 1; i++){ |
76 |
column = table.getColumnModel().getColumn(i); |
77 |
column.setCellRenderer(new CheckBoxColumnRenderer());
|
78 |
column.setCellEditor(new CheckBoxColumnEditor());
|
79 |
} |
80 |
} |
81 |
|
82 |
|
83 |
if(model.equals("TableButtonModel")){ |
84 |
tableModel = new TableButtonModel(columnNames);
|
85 |
table = new JTable(tableModel); |
86 |
TableColumn column = null; |
87 |
|
88 |
column = table.getColumnModel().getColumn(0);
|
89 |
column.setCellRenderer(new TableColorButtonColumnRenderer(true)); |
90 |
column.setCellEditor(new TableColorButtonColumnEditor((TableButtonModel)tableModel, table));
|
91 |
|
92 |
column = table.getColumnModel().getColumn(4);
|
93 |
column.setCellRenderer(new TableSelectorButtonColumnRenderer());
|
94 |
column.setCellEditor(new TableSelectorButtonColumnEditor());
|
95 |
} |
96 |
return table;
|
97 |
} |
98 |
|
99 |
/**
|
100 |
* Obtiene el modelo de la tabla
|
101 |
* @return DefaultTableModel
|
102 |
*/
|
103 |
public DefaultTableModel getTableModel(){ |
104 |
return tableModel;
|
105 |
} |
106 |
} |