root / trunk / libraries / libUIComponent / src / org / gvsig / gui / beans / controls / dnd / JDnDTableModel.java @ 13655
History | View | Annotate | Download (4.67 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 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 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
|
42 |
/* CVS MESSAGES:
|
43 |
*
|
44 |
* $Id: JDnDTableModel.java 13655 2007-09-12 16:28:55Z bsanchez $
|
45 |
* $Log$
|
46 |
* Revision 1.2 2007-09-12 16:28:23 bsanchez
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.1 2007/08/20 08:34:46 evercher
|
50 |
* He fusionado LibUI con LibUIComponents
|
51 |
*
|
52 |
* Revision 1.2 2006/09/27 13:34:57 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
* Revision 1.1 2006/09/21 16:35:12 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
*
|
59 |
*/
|
60 |
package org.gvsig.gui.beans.controls.dnd; |
61 |
|
62 |
import java.util.ArrayList; |
63 |
|
64 |
import javax.swing.table.AbstractTableModel; |
65 |
|
66 |
public class JDnDTableModel extends AbstractTableModel{ |
67 |
private static final long serialVersionUID = 7508610018581206163L; |
68 |
public static final short ONLY_ALLOW_MOVING_COLUMNS = JDnDTable.ONLY_ALLOW_MOVING_COLUMNS; |
69 |
public static final short ONLY_ALLOW_MOVING_ROWS = JDnDTable.ONLY_ALLOW_MOVING_ROWS; |
70 |
private static final short FREE_CELL_MOVING = JDnDTable.FREE_CELL_MOVING; |
71 |
|
72 |
private short mode = ONLY_ALLOW_MOVING_COLUMNS; |
73 |
|
74 |
private String[] colNames; |
75 |
private Object[][] values; |
76 |
|
77 |
public JDnDTableModel(Object[][] values, String[] colNames) { |
78 |
super();
|
79 |
this.colNames = colNames;
|
80 |
this.values = values;
|
81 |
} |
82 |
|
83 |
public int getColumnCount() { |
84 |
// TODO Auto-generated method stub
|
85 |
return colNames.length;
|
86 |
} |
87 |
|
88 |
public int getRowCount() { |
89 |
// TODO Auto-generated method stub
|
90 |
return values[0].length; |
91 |
} |
92 |
|
93 |
public Object getValueAt(int rowIndex, int columnIndex) { |
94 |
// TODO Auto-generated method stub
|
95 |
return values[rowIndex][columnIndex];
|
96 |
} |
97 |
|
98 |
public void itemsMoved(CellCoordinates newCellCoord, CellCoordinates[] coordinates) { |
99 |
// TODO Auto-generated method stub
|
100 |
System.out.println("Model itemsMoved"); |
101 |
|
102 |
|
103 |
switch (mode) {
|
104 |
case ONLY_ALLOW_MOVING_COLUMNS:
|
105 |
|
106 |
// last selected cell defines which column
|
107 |
int srcColumnIndex = coordinates[coordinates.length-1].i; |
108 |
int dstColumnIndex = newCellCoord.i;
|
109 |
System.out.println("movent columna "+ srcColumnIndex + " a columna "+dstColumnIndex); |
110 |
for (int i = 0; i < getRowCount(); i++) { |
111 |
CellCoordinates srcCoord = new CellCoordinates(i, srcColumnIndex);
|
112 |
CellCoordinates dstCoord = new CellCoordinates(i, dstColumnIndex);
|
113 |
swapCells(srcCoord, dstCoord); |
114 |
} |
115 |
swapColumnNames(dstColumnIndex, srcColumnIndex); |
116 |
break;
|
117 |
case ONLY_ALLOW_MOVING_ROWS:
|
118 |
// last selected cell defines which row
|
119 |
int rowIndex = coordinates[coordinates.length-1].i; |
120 |
coordinates = new CellCoordinates[getColumnCount()];
|
121 |
for (int i = 0; i < coordinates.length; i++) { |
122 |
coordinates[i].i = rowIndex; |
123 |
coordinates[i].j = i; |
124 |
} |
125 |
newCellCoord.j = 0;
|
126 |
break;
|
127 |
case FREE_CELL_MOVING:
|
128 |
// TODO implement it
|
129 |
break;
|
130 |
} |
131 |
this.fireTableDataChanged();
|
132 |
} |
133 |
|
134 |
private void swapColumnNames(int ind1, int ind2) { |
135 |
String aux = colNames[ind2];
|
136 |
colNames[ind2] = colNames[ind1]; |
137 |
colNames[ind1] = aux; |
138 |
} |
139 |
|
140 |
private void swapCells(CellCoordinates cell1, CellCoordinates cell2) { |
141 |
Object aux = values[cell1.i][cell1.j];
|
142 |
values[cell1.i][cell1.j] = values[cell2.i][cell2.j]; |
143 |
values[cell2.i][cell2.j] = aux; |
144 |
} |
145 |
|
146 |
public void insertItems(CellCoordinates cellCoord, ArrayList items) { |
147 |
// TODO Auto-generated method stub
|
148 |
System.out.println("Model inserItems"); |
149 |
} |
150 |
|
151 |
public void setSelectionMode(short mode) { |
152 |
this.mode = mode;
|
153 |
} |
154 |
|
155 |
} |