svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / beans / table / MoveRowsPanel.java @ 40561
History | View | Annotate | Download (4.25 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 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 3
|
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.gui.beans.table; |
25 |
|
26 |
import java.awt.Dimension; |
27 |
import java.net.URL; |
28 |
|
29 |
import javax.swing.ImageIcon; |
30 |
import javax.swing.JButton; |
31 |
import javax.swing.JPanel; |
32 |
|
33 |
import org.gvsig.gui.beans.Messages; |
34 |
import org.gvsig.gui.beans.table.listeners.TableListener; |
35 |
import org.gvsig.gui.util.StatusComponent; |
36 |
|
37 |
public class MoveRowsPanel extends JPanel { |
38 |
private static final long serialVersionUID = -4496318143555472677L; |
39 |
|
40 |
private int HEIGHT_BUTTONS = 19; // 16 estaria bien |
41 |
private JButton bUp = null; |
42 |
private JButton bDown = null; |
43 |
private int selected = -1; |
44 |
private int cont = 0; |
45 |
private String pathToImages = "images/"; // "/com/iver/cit/gvsig/gui/panels/images/"; |
46 |
|
47 |
/**
|
48 |
* Objeto para controlar el estado de los componentes visuales
|
49 |
*/
|
50 |
private StatusComponent statusComponent = null; |
51 |
|
52 |
/**
|
53 |
* This is the default constructor
|
54 |
*/
|
55 |
public MoveRowsPanel(TableListener tableListener) {
|
56 |
initialize(tableListener); |
57 |
} |
58 |
|
59 |
private void initialize(TableListener tableListener) { |
60 |
statusComponent = new StatusComponent(this); |
61 |
|
62 |
setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 1, 0)); |
63 |
add(getBUp()); |
64 |
add(getBDown()); |
65 |
|
66 |
getBUp().addActionListener(tableListener); |
67 |
getBDown().addActionListener(tableListener); |
68 |
} |
69 |
|
70 |
public void setSelectedIndex(int i, int cont) { |
71 |
selected = i; |
72 |
this.cont = cont;
|
73 |
checkArrows(); |
74 |
} |
75 |
|
76 |
/**
|
77 |
* Comprueba la posici?n del combo para ver si tiene que
|
78 |
* habilitar o deshabilitar las flechas de delante y detr?s.
|
79 |
*/
|
80 |
private void checkArrows(){ |
81 |
if (!statusComponent.isEnabled())
|
82 |
return;
|
83 |
|
84 |
if (selected == -1) { |
85 |
getBUp().setEnabled(false);
|
86 |
getBDown().setEnabled(false);
|
87 |
return;
|
88 |
} |
89 |
|
90 |
if (selected == 0) { |
91 |
getBUp().setEnabled(false);
|
92 |
} else {
|
93 |
getBUp().setEnabled(true);
|
94 |
} |
95 |
|
96 |
if (selected == (cont - 1)) { |
97 |
getBDown().setEnabled(false);
|
98 |
} else {
|
99 |
getBDown().setEnabled(true);
|
100 |
} |
101 |
} |
102 |
|
103 |
/**
|
104 |
* This method initializes bUp
|
105 |
* @return javax.swing.JButton
|
106 |
*/
|
107 |
public JButton getBUp() { |
108 |
if (bUp == null) { |
109 |
bUp = new JButton(""); |
110 |
bUp.setEnabled(true);
|
111 |
bUp.setPreferredSize(new Dimension(22, HEIGHT_BUTTONS)); |
112 |
URL url = getClass().getResource(pathToImages + "up-16x16.png"); |
113 |
if(url != null) |
114 |
bUp.setIcon(new ImageIcon(url)); |
115 |
bUp.setActionCommand("");
|
116 |
bUp.setToolTipText(Messages.getText("subir"));
|
117 |
} |
118 |
return bUp;
|
119 |
} |
120 |
|
121 |
|
122 |
/**
|
123 |
* This method initializes bDown
|
124 |
* @return javax.swing.JButton
|
125 |
*/
|
126 |
public JButton getBDown() { |
127 |
if (bDown == null) { |
128 |
bDown = new JButton(""); |
129 |
bDown.setEnabled(true);
|
130 |
bDown.setPreferredSize(new Dimension(22, HEIGHT_BUTTONS)); |
131 |
URL url = getClass().getResource(pathToImages + "down-16x16.png"); |
132 |
if(url != null) |
133 |
bDown.setIcon(new ImageIcon(url)); |
134 |
bDown.setActionCommand("");
|
135 |
bDown.setToolTipText(Messages.getText("bajar"));
|
136 |
} |
137 |
return bDown;
|
138 |
} |
139 |
|
140 |
/**
|
141 |
* Esta funci?n deshabilita todos los controles y guarda sus valores
|
142 |
* de habilitado o deshabilitado para que cuando se ejecute restoreControlsValue
|
143 |
* se vuelvan a quedar como estaba
|
144 |
*/
|
145 |
public void disableAllControls(){ |
146 |
statusComponent.setEnabled(false);
|
147 |
} |
148 |
|
149 |
/**
|
150 |
* Esta funci?n deja los controles como estaban al ejecutar la funci?n
|
151 |
* disableAllControls
|
152 |
*/
|
153 |
public void restoreControlsValue(){ |
154 |
statusComponent.setEnabled(true);
|
155 |
} |
156 |
} |