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 / TableControllerListener.java @ 1556
History | View | Annotate | Download (4.48 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 TableControllerListener 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 |
private PaginationBarPanel paginationBarPanel = null; |
46 |
public boolean enableNewLineListener = true; |
47 |
|
48 |
/**
|
49 |
* Constructor
|
50 |
* @param tableContainer
|
51 |
*/
|
52 |
public TableControllerListener(PagedTableImpl tableContainer){
|
53 |
this.pagedTable = tableContainer;
|
54 |
} |
55 |
|
56 |
public void setControlPanel(TableEntryControllerPanel control) { |
57 |
this.controlPanel = control;
|
58 |
} |
59 |
|
60 |
public void setMoveRowsPanel(MoveRowsPanel moveRowsPanel) { |
61 |
this.moveRowsPanel = moveRowsPanel;
|
62 |
} |
63 |
|
64 |
public void setPaginationBarPanel(PaginationBarPanel paginationBarPanel) { |
65 |
this.paginationBarPanel = paginationBarPanel;
|
66 |
} |
67 |
|
68 |
/**
|
69 |
* Captura y gestiona los eventos del control de la tabla para a?adir filas,
|
70 |
* eliminar filas y moverse por la tabla.
|
71 |
*/
|
72 |
public void actionPerformed(ActionEvent e) { |
73 |
if(!comboEventEnable)
|
74 |
return;
|
75 |
|
76 |
comboEventEnable = false;
|
77 |
|
78 |
/**
|
79 |
* Nueva entrada
|
80 |
*/
|
81 |
if (enableNewLineListener && e.getSource() == controlPanel.getBNew()) {
|
82 |
if (pagedTable.getTableModel() instanceof TableModel) |
83 |
pagedTable.addRow(((TableModel) pagedTable.getTableModel()).getNewLine());
|
84 |
} |
85 |
|
86 |
/**
|
87 |
* Eliminar todas las filas
|
88 |
*/
|
89 |
if (enableNewLineListener && e.getSource() == controlPanel.getBClear()) {
|
90 |
pagedTable.removeAllRows(); |
91 |
} |
92 |
|
93 |
/**
|
94 |
* Elimina una entrada concreta de la tabla
|
95 |
*/
|
96 |
if (enableNewLineListener && e.getSource() == controlPanel.getBDelPoint()) {
|
97 |
int[] listSelection = pagedTable.getSelectedRows(); |
98 |
for (int i = listSelection.length - 1; i >= 0; i--) |
99 |
pagedTable.delRow(listSelection[i]); |
100 |
} |
101 |
|
102 |
/**
|
103 |
* Subir un elemento
|
104 |
*/
|
105 |
if (e.getSource() == moveRowsPanel.getBUp()) {
|
106 |
int[] lista = pagedTable.getSelectedRows(); |
107 |
if (lista.length > 0) { |
108 |
for (int i = 0; i < lista.length; i++) |
109 |
pagedTable.swapRow(lista[i] - 1, lista[i]);
|
110 |
} |
111 |
} |
112 |
|
113 |
/**
|
114 |
* Bajar un elemento
|
115 |
*/
|
116 |
if (e.getSource() == moveRowsPanel.getBDown()) {
|
117 |
int[] lista = pagedTable.getSelectedRows(); |
118 |
if (lista.length > 0) { |
119 |
for (int i = lista.length - 1; i >= 0; i--) |
120 |
pagedTable.swapRow(lista[i], lista[i] + 1);
|
121 |
} |
122 |
} |
123 |
|
124 |
if (e.getSource() == controlPanel.getBFirst()) {
|
125 |
pagedTable.setSelectedRow(0);
|
126 |
} |
127 |
|
128 |
if (e.getSource() == controlPanel.getBLast()) {
|
129 |
pagedTable.setSelectedRow(-1); //With -1 selects the last |
130 |
} |
131 |
|
132 |
if (e.getSource() == controlPanel.getBNext()) {
|
133 |
pagedTable.increaseSelectedRows(); |
134 |
} |
135 |
|
136 |
if (e.getSource() == controlPanel.getBPrev()) {
|
137 |
pagedTable.decreaseSelectedRows(); |
138 |
} |
139 |
|
140 |
if (e.getSource() == controlPanel.getCPoint()) {
|
141 |
pagedTable.setSelectedRow(controlPanel.getCPoint().getSelectedIndex()); |
142 |
} |
143 |
|
144 |
comboEventEnable = true;
|
145 |
} |
146 |
|
147 |
/*
|
148 |
* (non-Javadoc)
|
149 |
* @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
|
150 |
*/
|
151 |
public void valueChanged(ListSelectionEvent e) { |
152 |
//pagedTable.setSelectedIndex(pagedTable.getSelectedTableRow());
|
153 |
} |
154 |
} |