gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.swing / org.gvsig.raster.swing.impl / src / main / java / org / gvsig / raster / swing / impl / pagedtable / TableListener.java @ 1506
History | View | Annotate | Download (4.27 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2012 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 2
|
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.raster.swing.impl.pagedtable; |
25 |
|
26 |
import java.awt.event.ActionEvent; |
27 |
import java.awt.event.ActionListener; |
28 |
|
29 |
import javax.swing.event.ListSelectionEvent; |
30 |
import javax.swing.event.ListSelectionListener; |
31 |
|
32 |
import org.gvsig.raster.swing.pagedtable.PagedTable; |
33 |
import org.gvsig.raster.swing.pagedtable.TableModel; |
34 |
|
35 |
|
36 |
|
37 |
/**
|
38 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
39 |
*/
|
40 |
public class TableListener implements ActionListener, ListSelectionListener { |
41 |
public static boolean comboEventEnable = true; |
42 |
private PagedTable pagedTable = null; |
43 |
private TableEntryControllerPanel controlPanel = null; |
44 |
private MoveRowsPanel moveRowsPanel = null; |
45 |
public boolean enableNewLineListener = true; |
46 |
|
47 |
/**
|
48 |
* Constructor
|
49 |
* @param tableContainer
|
50 |
*/
|
51 |
public TableListener(PagedTableImpl tableContainer){
|
52 |
this.pagedTable = tableContainer;
|
53 |
} |
54 |
|
55 |
public void setControlPanel(TableEntryControllerPanel control) { |
56 |
this.controlPanel = control;
|
57 |
} |
58 |
|
59 |
public void setMoveRowsPanel(MoveRowsPanel moveRowsPanel) { |
60 |
this.moveRowsPanel = moveRowsPanel;
|
61 |
} |
62 |
|
63 |
/**
|
64 |
* Captura y gestiona los eventos del control de la tabla para a?adir filas,
|
65 |
* eliminar filas y moverse por la tabla.
|
66 |
*/
|
67 |
public void actionPerformed(ActionEvent e) { |
68 |
if(!comboEventEnable)
|
69 |
return;
|
70 |
|
71 |
comboEventEnable = false;
|
72 |
|
73 |
/**
|
74 |
* Nueva entrada
|
75 |
*/
|
76 |
if (enableNewLineListener && e.getSource() == controlPanel.getBNew()) {
|
77 |
if (pagedTable.getTableModel() instanceof TableModel) |
78 |
pagedTable.addRow(((TableModel) pagedTable.getTableModel()).getNewLine());
|
79 |
} |
80 |
|
81 |
/**
|
82 |
* Eliminar todas las filas
|
83 |
*/
|
84 |
if (enableNewLineListener && e.getSource() == controlPanel.getBClear()) {
|
85 |
pagedTable.removeAllRows(); |
86 |
} |
87 |
|
88 |
/**
|
89 |
* Elimina una entrada concreta de la tabla
|
90 |
*/
|
91 |
if (enableNewLineListener && e.getSource() == controlPanel.getBDelPoint()) {
|
92 |
int[] listSelection = pagedTable.getSelectedRows(); |
93 |
for (int i = listSelection.length - 1; i >= 0; i--) |
94 |
pagedTable.delRow(listSelection[i]); |
95 |
} |
96 |
|
97 |
/**
|
98 |
* Subir un elemento
|
99 |
*/
|
100 |
if (e.getSource() == moveRowsPanel.getBUp()) {
|
101 |
int[] lista = pagedTable.getSelectedRows(); |
102 |
if (lista.length > 0) { |
103 |
for (int i = 0; i < lista.length; i++) |
104 |
pagedTable.swapRow(lista[i] - 1, lista[i]);
|
105 |
} |
106 |
} |
107 |
|
108 |
/**
|
109 |
* Bajar un elemento
|
110 |
*/
|
111 |
if (e.getSource() == moveRowsPanel.getBDown()) {
|
112 |
int[] lista = pagedTable.getSelectedRows(); |
113 |
if (lista.length > 0) { |
114 |
for (int i = lista.length - 1; i >= 0; i--) |
115 |
pagedTable.swapRow(lista[i], lista[i] + 1);
|
116 |
} |
117 |
} |
118 |
|
119 |
if (e.getSource() == controlPanel.getBFirst()) {
|
120 |
pagedTable.setSelectedRow(0);
|
121 |
} |
122 |
|
123 |
if (e.getSource() == controlPanel.getBLast()) {
|
124 |
pagedTable.setSelectedRow(-1); //With -1 selects the last |
125 |
} |
126 |
|
127 |
if (e.getSource() == controlPanel.getBNext()) {
|
128 |
pagedTable.increaseSelectedRows(); |
129 |
} |
130 |
|
131 |
if (e.getSource() == controlPanel.getBPrev()) {
|
132 |
pagedTable.decreaseSelectedRows(); |
133 |
} |
134 |
|
135 |
if (e.getSource() == controlPanel.getCPoint()) {
|
136 |
pagedTable.setSelectedRow(controlPanel.getCPoint().getSelectedIndex()); |
137 |
} |
138 |
|
139 |
comboEventEnable = true;
|
140 |
} |
141 |
|
142 |
/*
|
143 |
* (non-Javadoc)
|
144 |
* @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
|
145 |
*/
|
146 |
public void valueChanged(ListSelectionEvent e) { |
147 |
//pagedTable.setSelectedIndex(pagedTable.getSelectedTableRow());
|
148 |
} |
149 |
} |