svn-gvsig-desktop / tags / v1_0_2_Build_904 / libraries / libUI / src / org / gvsig / gui / beans / controls / dnd / JDnDTableModel.java @ 10724
History | View | Annotate | Download (4.67 KB)
1 | 7451 | jaume | /* 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$
|
||
45 | * $Log$
|
||
46 | 9037 | ppiqueras | * Revision 1.2.2.3 2006-11-28 09:46:36 ppiqueras
|
47 | * Actualizaci?n desde HEAD a v10 de libUI fruto de cambio de dependencia de libUI con el proyecto _fwAndami. (cambiado PluginServices.getText(..., ...) por Messages.getText(...)
|
||
48 | 7451 | jaume | *
|
49 | 8767 | jjdelcerro | * Revision 1.2 2006/09/27 13:34:57 jaume
|
50 | * *** empty log message ***
|
||
51 | *
|
||
52 | 7625 | jaume | * Revision 1.1 2006/09/21 16:35:12 jaume
|
53 | * *** empty log message ***
|
||
54 | 7451 | jaume | *
|
55 | 7625 | jaume | *
|
56 | 7451 | jaume | */
|
57 | package org.gvsig.gui.beans.controls.dnd; |
||
58 | |||
59 | import java.util.ArrayList; |
||
60 | |||
61 | import javax.swing.table.AbstractTableModel; |
||
62 | |||
63 | public class JDnDTableModel extends AbstractTableModel{ |
||
64 | |||
65 | public static final short ONLY_ALLOW_MOVING_COLUMNS = JDnDTable.ONLY_ALLOW_MOVING_COLUMNS; |
||
66 | public static final short ONLY_ALLOW_MOVING_ROWS = JDnDTable.ONLY_ALLOW_MOVING_ROWS; |
||
67 | private static final short FREE_CELL_MOVING = JDnDTable.FREE_CELL_MOVING; |
||
68 | |||
69 | private short mode = ONLY_ALLOW_MOVING_COLUMNS; |
||
70 | |||
71 | private String[] colNames; |
||
72 | private Object[][] values; |
||
73 | |||
74 | public JDnDTableModel(Object[][] values, String[] colNames) { |
||
75 | super();
|
||
76 | this.colNames = colNames;
|
||
77 | this.values = values;
|
||
78 | } |
||
79 | |||
80 | public int getColumnCount() { |
||
81 | // TODO Auto-generated method stub
|
||
82 | return colNames.length;
|
||
83 | } |
||
84 | |||
85 | public int getRowCount() { |
||
86 | // TODO Auto-generated method stub
|
||
87 | return values[0].length; |
||
88 | } |
||
89 | |||
90 | public Object getValueAt(int rowIndex, int columnIndex) { |
||
91 | // TODO Auto-generated method stub
|
||
92 | return values[rowIndex][columnIndex];
|
||
93 | } |
||
94 | |||
95 | public void itemsMoved(CellCoordinates newCellCoord, CellCoordinates[] coordinates) { |
||
96 | // TODO Auto-generated method stub
|
||
97 | System.out.println("Model itemsMoved"); |
||
98 | |||
99 | |||
100 | switch (mode) {
|
||
101 | case ONLY_ALLOW_MOVING_COLUMNS:
|
||
102 | |||
103 | // last selected cell defines which column
|
||
104 | int srcColumnIndex = coordinates[coordinates.length-1].i; |
||
105 | int dstColumnIndex = newCellCoord.i;
|
||
106 | System.out.println("movent columna "+ srcColumnIndex + " a columna "+dstColumnIndex); |
||
107 | for (int i = 0; i < getRowCount(); i++) { |
||
108 | CellCoordinates srcCoord = new CellCoordinates(i, srcColumnIndex);
|
||
109 | CellCoordinates dstCoord = new CellCoordinates(i, dstColumnIndex);
|
||
110 | swapCells(srcCoord, dstCoord); |
||
111 | } |
||
112 | swapColumnNames(dstColumnIndex, srcColumnIndex); |
||
113 | break;
|
||
114 | case ONLY_ALLOW_MOVING_ROWS:
|
||
115 | // last selected cell defines which row
|
||
116 | int rowIndex = coordinates[coordinates.length-1].i; |
||
117 | coordinates = new CellCoordinates[getColumnCount()];
|
||
118 | for (int i = 0; i < coordinates.length; i++) { |
||
119 | coordinates[i].i = rowIndex; |
||
120 | coordinates[i].j = i; |
||
121 | } |
||
122 | newCellCoord.j = 0;
|
||
123 | break;
|
||
124 | case FREE_CELL_MOVING:
|
||
125 | // TODO implement it
|
||
126 | break;
|
||
127 | } |
||
128 | 7625 | jaume | this.fireTableDataChanged();
|
129 | 7451 | jaume | } |
130 | |||
131 | private void swapColumnNames(int ind1, int ind2) { |
||
132 | String aux = colNames[ind2];
|
||
133 | colNames[ind2] = colNames[ind1]; |
||
134 | colNames[ind1] = aux; |
||
135 | } |
||
136 | |||
137 | private void swapCells(CellCoordinates cell1, CellCoordinates cell2) { |
||
138 | Object aux = values[cell1.i][cell1.j];
|
||
139 | values[cell1.i][cell1.j] = values[cell2.i][cell2.j]; |
||
140 | values[cell2.i][cell2.j] = aux; |
||
141 | } |
||
142 | |||
143 | public void insertItems(CellCoordinates cellCoord, ArrayList items) { |
||
144 | // TODO Auto-generated method stub
|
||
145 | System.out.println("Model inserItems"); |
||
146 | } |
||
147 | |||
148 | public void setSelectionMode(short mode) { |
||
149 | this.mode = mode;
|
||
150 | } |
||
151 | |||
152 | } |