Revision 10281
tags/Root_v10+Piloto/libraries/libUIComponent_praster/doc/contents.html | ||
---|---|---|
1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
|
2 |
<HTML> |
|
3 |
<HEAD> |
|
4 |
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=iso-8859-15"> |
|
5 |
<TITLE></TITLE> |
|
6 |
<META NAME="GENERATOR" CONTENT="OpenOffice.org 1.1.3 (Linux)"> |
|
7 |
<META NAME="CREATED" CONTENT="20060322;9174300"> |
|
8 |
<META NAME="CHANGED" CONTENT="20060322;10202100"> |
|
9 |
<STYLE> |
|
10 |
<!-- |
|
11 |
@page { size: 21cm 29.7cm; margin: 2cm } |
|
12 |
P { margin-bottom: 0.21cm } |
|
13 |
A:link { color: #000080; text-decoration: underline } |
|
14 |
A:visited { color: #800000; text-decoration: underline } |
|
15 |
--> |
|
16 |
</STYLE> |
|
17 |
</HEAD> |
|
18 |
<BODY LANG="en-US" LINK="#000080" VLINK="#800000" DIR="LTR"> |
|
19 |
<P STYLE="margin-bottom: 0cm"><FONT FACE="Monospace"><FONT SIZE=3 STYLE="font-size: 13pt"><B>PRESENT |
|
20 |
BEANS.</B></FONT></FONT></P> |
|
21 |
<P STYLE="margin-bottom: 0cm"><BR> |
|
22 |
</P> |
|
23 |
<P STYLE="margin-bottom: 0cm"><FONT FACE="Times, serif"><FONT SIZE=2><B>DefaultBean.java |
|
24 |
(extends JPanel (standard in Swing)):</B><SPAN STYLE="font-weight: medium"> |
|
25 |
Just a JPanel with addListener(BeanListener l), |
|
26 |
removeListener(BeanListener l), and callValueChange(Object value) |
|
27 |
methods for adding listeners, removing listeners, and firing |
|
28 |
BeanValueChange events.</SPAN></FONT></FONT></P> |
|
29 |
<P STYLE="margin-bottom: 0cm"><BR> |
|
30 |
</P> |
|
31 |
<P STYLE="margin-bottom: 0cm"><FONT FACE="Times, serif"><FONT SIZE=2><B>Pager.java |
|
32 |
(extends DefaultBean.java)</B>: this is an |
|
33 |
AcrobatReader-page-browser-like bean that allows you to easy browse a |
|
34 |
list of values. Each time you drag the slider, click a button or type |
|
35 |
a number an Integer value is produced and a BeanValueChanged event is |
|
36 |
fired returning an Object value. Catch this event and cast the value |
|
37 |
produced to a Integer (or even an int) and use it to move your list |
|
38 |
pointer to this position. An example of use can be found in |
|
39 |
<B>SamplePanel.java</B></FONT></FONT></P> |
|
40 |
<P STYLE="margin-bottom: 0cm"><BR> |
|
41 |
</P> |
|
42 |
<P STYLE="margin-bottom: 0cm"><BR> |
|
43 |
</P> |
|
44 |
<P STYLE="margin-bottom: 0cm"><FONT FACE="Monospace"><FONT SIZE=3 STYLE="font-size: 13pt"><B>PRESENT |
|
45 |
CONTROLS.</B></FONT></FONT></P> |
|
46 |
<P STYLE="margin-bottom: 0cm"><BR> |
|
47 |
</P> |
|
48 |
<P STYLE="margin-bottom: 0cm"><FONT FACE="Monospace"><FONT SIZE=2><B>package |
|
49 |
org.gvsig.gui.beans.controls</B></FONT></FONT></P> |
|
50 |
<P STYLE="margin-bottom: 0cm"><BR> |
|
51 |
</P> |
|
52 |
<P STYLE="margin-bottom: 0cm"><FONT FACE="Times, serif"><FONT SIZE=2><B>MultilineTooltip.java |
|
53 |
(extends JToolTip (standard in Swing)): </B><SPAN STYLE="font-weight: medium">Allows |
|
54 |
using more than one line length tooltips. It also automatically |
|
55 |
calculates the size of the screen rectangle used and the preferred |
|
56 |
sized up on the contained text. It does NOT format the text to fit |
|
57 |
within a given size. The user must provide the text as she/he wishes |
|
58 |
to show it. It means that new line characters must be placed in the |
|
59 |
string as well as it was a System.out.println statement.</SPAN></FONT></FONT></P> |
|
60 |
<P STYLE="margin-bottom: 0cm"><BR> |
|
61 |
</P> |
|
62 |
<P STYLE="margin-bottom: 0cm"><FONT FACE="Monospace"><FONT SIZE=2><B>package |
|
63 |
org.gvsig.gui.beans.controls.dnd</B></FONT></FONT></P> |
|
64 |
<P STYLE="margin-bottom: 0cm"><BR> |
|
65 |
</P> |
|
66 |
<P STYLE="margin-bottom: 0cm"><FONT FACE="Times, serif"><FONT SIZE=2><B>JDnDList |
|
67 |
(extends JList (standard in Swing)): </B><SPAN STYLE="font-weight: medium">A |
|
68 |
JList that allows drag'n'drop elements. It accepts changing position |
|
69 |
of one or more elements within the list, adding other from other |
|
70 |
JDnDList's, removing sets of selected items, and other features. In |
|
71 |
order to use this features you have to use a JDnDListModel as the |
|
72 |
list's model.</SPAN></FONT></FONT></P> |
|
73 |
<P STYLE="margin-bottom: 0cm"><BR> |
|
74 |
</P> |
|
75 |
<P STYLE="margin-bottom: 0cm"><FONT FACE="Times, serif"><FONT SIZE=2><B>JDnDListModel |
|
76 |
(extends AbstractListModel (standard in Swing)): </B><SPAN STYLE="font-weight: medium">List |
|
77 |
model to use in junction the JDnDList. Contains some useful tools.</SPAN></FONT></FONT></P> |
|
78 |
<P STYLE="margin-bottom: 0cm"><BR> |
|
79 |
</P> |
|
80 |
<P STYLE="margin-bottom: 0cm"><FONT FACE="Monospace"><FONT SIZE=2><B>package |
|
81 |
org.gvsig.gui.geans.listeners</B></FONT></FONT></P> |
|
82 |
<P STYLE="margin-bottom: 0cm"><BR> |
|
83 |
</P> |
|
84 |
<P STYLE="margin-bottom: 0cm"><FONT FACE="Times, serif"><FONT SIZE=2><B>BeanListener.java: |
|
85 |
</B><SPAN STYLE="font-weight: medium">Defines an object which listens |
|
86 |
for changes in the value produced by a bean. It is used, for example, |
|
87 |
in</SPAN><B> DefaultBean.java.</B></FONT></FONT></P> |
|
88 |
<P STYLE="margin-bottom: 0cm"><BR> |
|
89 |
</P> |
|
90 |
<P STYLE="margin-bottom: 0cm; font-weight: medium"><BR> |
|
91 |
</P> |
|
92 |
<P STYLE="margin-bottom: 0cm; font-weight: medium"><FONT FACE="Courier, monospace"><FONT SIZE=2>by |
|
93 |
Jaume Domínguez Faus (:S)</FONT></FONT></P> |
|
94 |
</BODY> |
|
95 |
</HTML> |
|
0 | 96 |
tags/Root_v10+Piloto/libraries/libUIComponent_praster/src/org/gvsig/gui/beans/dataInput/DataInputContainer.java | ||
---|---|---|
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 |
package org.gvsig.gui.beans.dataInput; |
|
20 |
|
|
21 |
import java.awt.FlowLayout; |
|
22 |
import java.awt.GridBagConstraints; |
|
23 |
import java.awt.event.FocusEvent; |
|
24 |
import java.awt.event.FocusListener; |
|
25 |
import java.awt.event.KeyEvent; |
|
26 |
import java.awt.event.KeyListener; |
|
27 |
|
|
28 |
import javax.swing.JLabel; |
|
29 |
import javax.swing.JPanel; |
|
30 |
import javax.swing.JTextField; |
|
31 |
|
|
32 |
import org.gvsig.gui.beans.BaseComponent; |
|
33 |
|
|
34 |
public class DataInputContainer extends BaseComponent implements FocusListener, KeyListener{ |
|
35 |
|
|
36 |
private int wComp = 150, hComp = 22; |
|
37 |
private int wLabel = 30, hLabel = 20; |
|
38 |
private int wText = wComp - wLabel - 5, hText = 20; |
|
39 |
|
|
40 |
private boolean decimal = false; |
|
41 |
private boolean caracter = false; |
|
42 |
|
|
43 |
private JPanel pInput = null; |
|
44 |
private JLabel lText = null; |
|
45 |
private JTextField jTextField = null; |
|
46 |
|
|
47 |
private String focusText = null; |
|
48 |
|
|
49 |
/** |
|
50 |
* This is the default constructor |
|
51 |
*/ |
|
52 |
public DataInputContainer(int widthLabel) { |
|
53 |
super(); |
|
54 |
if(widthLabel > 0){ |
|
55 |
wLabel = widthLabel; |
|
56 |
wText = wComp - wLabel - 5; |
|
57 |
} |
|
58 |
initialize(); |
|
59 |
} |
|
60 |
|
|
61 |
/** |
|
62 |
* This method initializes this |
|
63 |
* |
|
64 |
* @return void |
|
65 |
*/ |
|
66 |
private void initialize() { |
|
67 |
FlowLayout flowLayout = new FlowLayout(); |
|
68 |
flowLayout.setHgap(0); |
|
69 |
flowLayout.setVgap(0); |
|
70 |
flowLayout.setAlignment(java.awt.FlowLayout.RIGHT); |
|
71 |
this.setLayout(flowLayout); |
|
72 |
//this.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1)); |
|
73 |
this.add(getPInput(), null); |
|
74 |
this.getJTextField().addFocusListener(this); |
|
75 |
this.getJTextField().addKeyListener(this); |
|
76 |
setComponentSize(wComp, hComp); |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* This method initializes jPanel |
|
81 |
* |
|
82 |
* @return javax.swing.JPanel |
|
83 |
*/ |
|
84 |
private JPanel getPInput() { |
|
85 |
if (pInput == null) { |
|
86 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
|
87 |
gridBagConstraints1.gridy = 0; |
|
88 |
gridBagConstraints1.gridx = 1; |
|
89 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
|
90 |
gridBagConstraints.gridx = 0; |
|
91 |
gridBagConstraints.gridy = 0; |
|
92 |
FlowLayout flowLayout3 = new FlowLayout(); |
|
93 |
flowLayout3.setAlignment(java.awt.FlowLayout.RIGHT); |
|
94 |
flowLayout3.setVgap(0); |
|
95 |
flowLayout3.setHgap(0); |
|
96 |
pInput = new JPanel(); |
|
97 |
pInput.setLayout(flowLayout3); |
|
98 |
pInput.add(getLText(), null); |
|
99 |
pInput.add(getJTextField(), null); |
|
100 |
} |
|
101 |
return pInput; |
|
102 |
} |
|
103 |
|
|
104 |
private JLabel getLText(){ |
|
105 |
if (lText == null){ |
|
106 |
lText = new JLabel(); |
|
107 |
lText.setText("JLabel"); |
|
108 |
lText.setComponentOrientation(java.awt.ComponentOrientation.RIGHT_TO_LEFT); |
|
109 |
} |
|
110 |
return lText; |
|
111 |
} |
|
112 |
|
|
113 |
|
|
114 |
/** |
|
115 |
* Da nombre al campo de texto del componente. |
|
116 |
* @param text |
|
117 |
*/ |
|
118 |
public void setLabelText(String text){ |
|
119 |
this.lText.setText(text + ": "); |
|
120 |
} |
|
121 |
|
|
122 |
/** |
|
123 |
* This method initializes jTextField |
|
124 |
* |
|
125 |
* @return javax.swing.JTextField |
|
126 |
*/ |
|
127 |
public JTextField getJTextField() { |
|
128 |
if (jTextField == null) { |
|
129 |
jTextField = new JTextField(); |
|
130 |
jTextField.setBackground(java.awt.Color.white); |
|
131 |
} |
|
132 |
return jTextField; |
|
133 |
} |
|
134 |
|
|
135 |
/** |
|
136 |
* Ajusta el tama?o del componente. |
|
137 |
* @param w |
|
138 |
* @param h |
|
139 |
*/ |
|
140 |
public void setComponentSize(int w, int h){ |
|
141 |
wComp = w; |
|
142 |
int wPanel = (int)(wComp * 0.9); |
|
143 |
int hPanel = (int)(hComp * 0.95); |
|
144 |
wText = wPanel - wLabel - 5; |
|
145 |
this.setPreferredSize(new java.awt.Dimension(wComp, hComp)); |
|
146 |
this.getPInput().setPreferredSize(new java.awt.Dimension(wPanel, hPanel)); |
|
147 |
this.getJTextField().setPreferredSize(new java.awt.Dimension(wText, hText)); |
|
148 |
} |
|
149 |
|
|
150 |
/** |
|
151 |
* Modifica la altura del componente. |
|
152 |
* @param h |
|
153 |
*/ |
|
154 |
public void setComponentHeight(int h){ |
|
155 |
this.hComp = h; |
|
156 |
this.setPreferredSize(new java.awt.Dimension(wComp, hComp)); |
|
157 |
} |
|
158 |
|
|
159 |
/** |
|
160 |
* Devuelve el valor del campo de texto del componente. |
|
161 |
* @return |
|
162 |
*/ |
|
163 |
public String getTextValue(){ |
|
164 |
return this.jTextField.getText(); |
|
165 |
} |
|
166 |
|
|
167 |
/** |
|
168 |
* metodos para indicar y conocer el tipo de valor acepatado por el |
|
169 |
* campo de texto. |
|
170 |
* @param flag |
|
171 |
*/ |
|
172 |
public void setDecimal(boolean flag){ |
|
173 |
this.decimal = flag; |
|
174 |
} |
|
175 |
|
|
176 |
public void setCaracter(boolean flag){ |
|
177 |
this.caracter = flag; |
|
178 |
} |
|
179 |
|
|
180 |
public boolean isDecimal(){ |
|
181 |
return this.decimal; |
|
182 |
} |
|
183 |
|
|
184 |
public boolean isCaracter(){ |
|
185 |
return this.caracter; |
|
186 |
} |
|
187 |
|
|
188 |
/** |
|
189 |
* Modifica el tama?o de la etiqueta del componente. |
|
190 |
* @param w |
|
191 |
*/ |
|
192 |
public void setLabelSize(int w){ |
|
193 |
this.wLabel = w; |
|
194 |
} |
|
195 |
|
|
196 |
/** |
|
197 |
* Habilita o deshabilita el control |
|
198 |
* @param en |
|
199 |
*/ |
|
200 |
public void setControlEnabled(boolean en){ |
|
201 |
this.getJTextField().setEnabled(en); |
|
202 |
if (en) |
|
203 |
this.getJTextField().setBackground(java.awt.Color.white); |
|
204 |
else |
|
205 |
this.getJTextField().setBackground(getBackground()); |
|
206 |
} |
|
207 |
|
|
208 |
/** |
|
209 |
* Devuelve el valor del campo de texto. |
|
210 |
* @return |
|
211 |
*/ |
|
212 |
public String getValue(){ |
|
213 |
return this.getJTextField().getText(); |
|
214 |
} |
|
215 |
|
|
216 |
/** |
|
217 |
* Asigna el valor al campo de texto. |
|
218 |
* @return |
|
219 |
*/ |
|
220 |
public void setValue(String value){ |
|
221 |
this.getJTextField().setText(value); |
|
222 |
} |
|
223 |
|
|
224 |
|
|
225 |
/*********************************************************/ |
|
226 |
/*********************LISTENERS***************************/ |
|
227 |
/*********************************************************/ |
|
228 |
|
|
229 |
|
|
230 |
public void focusGained(FocusEvent e) { |
|
231 |
if (e.getSource() == this.getJTextField()){ |
|
232 |
if(!validateNumericFormat(this.getJTextField().getText())) |
|
233 |
this.getJTextField().setText(""); |
|
234 |
} |
|
235 |
|
|
236 |
} |
|
237 |
|
|
238 |
public void focusLost(FocusEvent e) { |
|
239 |
//if(e.getSource() == this.getJTextField()) |
|
240 |
//checkTextValue(); |
|
241 |
|
|
242 |
} |
|
243 |
|
|
244 |
|
|
245 |
|
|
246 |
public void keyPressed(KeyEvent e) { |
|
247 |
|
|
248 |
} |
|
249 |
|
|
250 |
|
|
251 |
public void keyReleased(KeyEvent e) { |
|
252 |
String cad = this.getJTextField().getText(); |
|
253 |
|
|
254 |
if (e.getSource()==this.getJTextField()){ |
|
255 |
if (e.getKeyCode() == 10){ |
|
256 |
if(!validateNumericFormat(cad)) |
|
257 |
this.getJTextField().setText(""); |
|
258 |
return; |
|
259 |
} |
|
260 |
if (!caracter){ |
|
261 |
if (checkTextField(e.getKeyCode())) |
|
262 |
focusText = cad; |
|
263 |
else |
|
264 |
this.getJTextField().setText(focusText); |
|
265 |
} |
|
266 |
} |
|
267 |
} |
|
268 |
|
|
269 |
public void keyTyped(KeyEvent e) { |
|
270 |
|
|
271 |
} |
|
272 |
|
|
273 |
|
|
274 |
/** |
|
275 |
* Checkea un textField para que contenga caracteres validos. Consideramos validos |
|
276 |
* los caracteres del 0 al 9, el punto, DEL, Supr, flechas y Enter teniendo en cuenta que el |
|
277 |
* c?digo ascii del teclado numerico es distinto. |
|
278 |
*/ |
|
279 |
public boolean checkTextField(int code){ |
|
280 |
|
|
281 |
//Si el caracter es erroneo pasamos de el y reponemos el texto que habia |
|
282 |
if( (code >= 0 && code <= 7) || |
|
283 |
code == 9 || |
|
284 |
(code >= 11 && code <= 36) || |
|
285 |
(code >= 41 && code <= 45) || |
|
286 |
code == 47 || |
|
287 |
(code >= 58 && code <= 95) || |
|
288 |
(code >= 106 && code <= 109) || |
|
289 |
(code >= 111 && code <= 126) || |
|
290 |
code >= 128){ |
|
291 |
return false; |
|
292 |
} |
|
293 |
|
|
294 |
return true; |
|
295 |
} |
|
296 |
|
|
297 |
/** |
|
298 |
* Validaci?n de que el par?metro tenga formato numerico |
|
299 |
* @param t Valor del campo |
|
300 |
* @return true si es valido y false si no lo es |
|
301 |
*/ |
|
302 |
private boolean validateNumericFormat(String field){ |
|
303 |
double d = 0D; |
|
304 |
try{ |
|
305 |
d = Double.valueOf(field).doubleValue(); |
|
306 |
}catch(NumberFormatException exc){ |
|
307 |
return false; |
|
308 |
} |
|
309 |
return true; |
|
310 |
} |
|
311 |
|
|
312 |
|
|
313 |
} |
|
0 | 314 |
tags/Root_v10+Piloto/libraries/libUIComponent_praster/src/org/gvsig/gui/beans/treelist/TreeListContainer.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2006 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 |
package org.gvsig.gui.beans.treelist; |
|
20 |
|
|
21 |
import java.awt.FlowLayout; |
|
22 |
import java.awt.GridBagConstraints; |
|
23 |
import java.awt.GridBagLayout; |
|
24 |
import java.util.ArrayList; |
|
25 |
import java.util.Hashtable; |
|
26 |
|
|
27 |
import javax.swing.DefaultListModel; |
|
28 |
import javax.swing.JList; |
|
29 |
import javax.swing.JPanel; |
|
30 |
import javax.swing.JScrollPane; |
|
31 |
import javax.swing.JTree; |
|
32 |
import javax.swing.ListSelectionModel; |
|
33 |
import javax.swing.tree.DefaultMutableTreeNode; |
|
34 |
import javax.swing.tree.DefaultTreeModel; |
|
35 |
|
|
36 |
import org.gvsig.gui.beans.BaseComponent; |
|
37 |
import org.gvsig.gui.beans.treelist.listeners.TreeListComponentListener; |
|
38 |
import org.gvsig.gui.beans.treelist.listeners.TreeListListener; |
|
39 |
import org.gvsig.i18n.Messages; |
|
40 |
|
|
41 |
/** |
|
42 |
* Componente consistente en un men? de arbol al que se le pueden a?adir entradas |
|
43 |
* y una lista de elementos debajo de este. |
|
44 |
* Haciendo doble click o arrastrando un elemento del men? a la lista este queda a?adido |
|
45 |
* en esta. Haciendo doble click en un elemento de la lista se elimina de esta y arrastrando |
|
46 |
* elementos dentro de la lista se varia su posici?n en ella. |
|
47 |
* Nacho Brodin (brodin_ign@gva.es) |
|
48 |
*/ |
|
49 |
|
|
50 |
public class TreeListContainer extends BaseComponent { |
|
51 |
|
|
52 |
private int wComp = 190; |
|
53 |
private int hComp = 360; |
|
54 |
private int hTree = (int)Math.floor(hComp * 0.68); |
|
55 |
private int hList = hComp - hTree; |
|
56 |
private Hashtable map; |
|
57 |
|
|
58 |
private JPanel pMain = null; |
|
59 |
private JScrollPane pTree = null; |
|
60 |
private JScrollPane pList = null; |
|
61 |
private JTree tree = null; |
|
62 |
private JList list = null; |
|
63 |
private DefaultMutableTreeNode raiz = null; |
|
64 |
private TreeListListener listener = null; |
|
65 |
private ArrayList listListeners = new ArrayList(); |
|
66 |
|
|
67 |
/** |
|
68 |
* This method initializes |
|
69 |
* |
|
70 |
*/ |
|
71 |
public TreeListContainer() { |
|
72 |
super(); |
|
73 |
listener = new TreeListListener(); |
|
74 |
initialize(); |
|
75 |
listener.setList(getList()); |
|
76 |
listener.setTree(getTree()); |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* This method initializes this |
|
81 |
* |
|
82 |
*/ |
|
83 |
private void initialize() { |
|
84 |
map = new Hashtable(); |
|
85 |
raiz = new DefaultMutableTreeNode(Messages.getText("filtros")); |
|
86 |
this.setPreferredSize(new java.awt.Dimension(wComp, hComp)); |
|
87 |
FlowLayout flowLayout = new FlowLayout(); |
|
88 |
flowLayout.setHgap(0); |
|
89 |
flowLayout.setVgap(0); |
|
90 |
this.setLayout(flowLayout); |
|
91 |
this.add(getPMain(), null); |
|
92 |
|
|
93 |
} |
|
94 |
|
|
95 |
/** |
|
96 |
* This method initializes jPanel |
|
97 |
* |
|
98 |
* @return javax.swing.JPanel |
|
99 |
*/ |
|
100 |
private JPanel getPMain() { |
|
101 |
if (pMain == null) { |
|
102 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
|
103 |
gridBagConstraints1.gridx = 0; |
|
104 |
gridBagConstraints1.gridy = 1; |
|
105 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
|
106 |
gridBagConstraints.gridx = 0; |
|
107 |
gridBagConstraints.gridy = 0; |
|
108 |
pMain = new JPanel(); |
|
109 |
pMain.setLayout(new GridBagLayout()); |
|
110 |
pMain.setPreferredSize(new java.awt.Dimension(wComp,hComp)); |
|
111 |
pMain.add(getPTree(), gridBagConstraints); |
|
112 |
pMain.add(getPList(), gridBagConstraints1); |
|
113 |
} |
|
114 |
return pMain; |
|
115 |
} |
|
116 |
|
|
117 |
/** |
|
118 |
* This method initializes jPanel |
|
119 |
* |
|
120 |
* @return javax.swing.JPanel |
|
121 |
*/ |
|
122 |
private JScrollPane getPTree() { |
|
123 |
if (pTree == null) { |
|
124 |
pTree = new JScrollPane(); |
|
125 |
pTree.setPreferredSize(new java.awt.Dimension(wComp, hTree)); |
|
126 |
pTree.setViewportBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED)); |
|
127 |
pTree.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); |
|
128 |
pTree.setViewportView(getTree()); |
|
129 |
} |
|
130 |
return pTree; |
|
131 |
} |
|
132 |
|
|
133 |
/** |
|
134 |
* This method initializes jPanel1 |
|
135 |
* |
|
136 |
* @return javax.swing.JPanel |
|
137 |
*/ |
|
138 |
private JScrollPane getPList() { |
|
139 |
if (pList == null) { |
|
140 |
pList = new JScrollPane(); |
|
141 |
pList.setPreferredSize(new java.awt.Dimension(wComp, hList)); |
|
142 |
pList.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED)); |
|
143 |
pList.setBackground(java.awt.Color.white); |
|
144 |
pList.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); |
|
145 |
pList.setViewportView(getList()); |
|
146 |
} |
|
147 |
return pList; |
|
148 |
} |
|
149 |
|
|
150 |
/** |
|
151 |
* This method initializes jTree |
|
152 |
* |
|
153 |
* @return javax.swing.JTree |
|
154 |
*/ |
|
155 |
public JTree getTree() { |
|
156 |
if (tree == null) { |
|
157 |
tree = new JTree(raiz); |
|
158 |
tree.addMouseListener(listener); |
|
159 |
tree.addMouseMotionListener(listener); |
|
160 |
} |
|
161 |
return tree; |
|
162 |
} |
|
163 |
|
|
164 |
/** |
|
165 |
* This method initializes jList |
|
166 |
* |
|
167 |
* @return javax.swing.JList |
|
168 |
*/ |
|
169 |
public JList getList() { |
|
170 |
if (list == null) { |
|
171 |
DefaultListModel m = new DefaultListModel(); |
|
172 |
list = new JList(m); |
|
173 |
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
|
174 |
list.addMouseListener(listener); |
|
175 |
list.addMouseMotionListener(listener); |
|
176 |
} |
|
177 |
return list; |
|
178 |
} |
|
179 |
|
|
180 |
|
|
181 |
public void setComponentSize(int w, int h){ |
|
182 |
wComp = w; |
|
183 |
hComp = h; |
|
184 |
hTree = (int)Math.floor(hComp * 0.68); |
|
185 |
hList = hComp - hTree; |
|
186 |
this.setPreferredSize(new java.awt.Dimension(wComp, hComp)); |
|
187 |
pMain.setPreferredSize(new java.awt.Dimension(wComp, hComp)); |
|
188 |
pTree.setPreferredSize(new java.awt.Dimension(wComp, hTree)); |
|
189 |
pList.setPreferredSize(new java.awt.Dimension(wComp, hList)); |
|
190 |
} |
|
191 |
|
|
192 |
//------------------------------------------- |
|
193 |
//M?TODOS DE ARBOL |
|
194 |
|
|
195 |
/** |
|
196 |
* A?ade una nueva categoria al arbol |
|
197 |
* @param name Etiqueta que aparece en el arbol. |
|
198 |
* @param pos Posici?n en el arbol de la nueva categoria |
|
199 |
*/ |
|
200 |
public void addClass(String name, int pos){ |
|
201 |
DefaultTreeModel model =(DefaultTreeModel)tree.getModel(); |
|
202 |
DefaultMutableTreeNode r = new DefaultMutableTreeNode( name ); |
|
203 |
model.insertNodeInto(r, raiz, pos); |
|
204 |
} |
|
205 |
|
|
206 |
/** |
|
207 |
* A?ade una entrada a una categoria |
|
208 |
* @param name Nombre de la entrada a a?adir |
|
209 |
* @param parentName Categoria a la que a?adimos |
|
210 |
* @param value Valor asociado a la entrada |
|
211 |
*/ |
|
212 |
public void addEntry(String name, String parentName, String value){ |
|
213 |
DefaultTreeModel model =(DefaultTreeModel)tree.getModel(); |
|
214 |
for(int i = 0; i < model.getChildCount(raiz); i++){ |
|
215 |
if(model.getChild(raiz, i).toString().equals(parentName)){ |
|
216 |
DefaultMutableTreeNode node = (DefaultMutableTreeNode)model.getChild(raiz, i); |
|
217 |
node.add(new DefaultMutableTreeNode(name)); |
|
218 |
if (value!=null) |
|
219 |
map.put(name,value); |
|
220 |
} |
|
221 |
} |
|
222 |
} |
|
223 |
|
|
224 |
/** |
|
225 |
* M?todo que comprueba si una entrada existe en la lista. |
|
226 |
* @param value Valor que se quiere comprobar si est? en la lista |
|
227 |
* @return true si el valor est? en la lista y false si no lo est? |
|
228 |
*/ |
|
229 |
public boolean isInList(String value){ |
|
230 |
DefaultListModel model = (DefaultListModel)getList().getModel(); |
|
231 |
for(int i = 0; i < model.getSize(); i++) |
|
232 |
if(((String)model.get(i)).equals(value)) |
|
233 |
return true; |
|
234 |
return false; |
|
235 |
} |
|
236 |
|
|
237 |
/** |
|
238 |
* A?ade un listener TreeListComponent |
|
239 |
* @param e |
|
240 |
*/ |
|
241 |
public void addTreeListListener(TreeListComponentListener e){ |
|
242 |
listListeners.add(e); |
|
243 |
listener.setListeners(listListeners); |
|
244 |
} |
|
245 |
|
|
246 |
/** |
|
247 |
* A?ade un elemento a la lista |
|
248 |
* @param element Elemento a a?adir |
|
249 |
*/ |
|
250 |
public void addElementInList(String element){ |
|
251 |
DefaultListModel model = (DefaultListModel)getList().getModel(); |
|
252 |
model.addElement(element); |
|
253 |
} |
|
254 |
|
|
255 |
/** |
|
256 |
* Elimina un elemento a la lista |
|
257 |
* @param element Elemento a eliminar |
|
258 |
*/ |
|
259 |
public void removeElementInList(String element){ |
|
260 |
DefaultListModel model = (DefaultListModel)getList().getModel(); |
|
261 |
model.removeElement(element); |
|
262 |
} |
|
263 |
|
|
264 |
/** |
|
265 |
* Elimina un elemento a la lista por indice |
|
266 |
* @param element Indice del elemento a eliminar |
|
267 |
*/ |
|
268 |
public void removeElementInList(int element){ |
|
269 |
DefaultListModel model = (DefaultListModel)getList().getModel(); |
|
270 |
model.remove(element); |
|
271 |
} |
|
272 |
|
|
273 |
public Hashtable getMap() { |
|
274 |
return map; |
|
275 |
} |
|
276 |
|
|
277 |
public void setMap(Hashtable map) { |
|
278 |
this.map = map; |
|
279 |
} |
|
280 |
} |
|
0 | 281 |
tags/Root_v10+Piloto/libraries/libUIComponent_praster/src/org/gvsig/gui/beans/treelist/event/TreeListEvent.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2006 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 |
package org.gvsig.gui.beans.treelist.event; |
|
20 |
|
|
21 |
|
|
22 |
/** |
|
23 |
* Event para el TreeListComponentListener |
|
24 |
* Nacho Brodin (brodin_ign@gva.es) |
|
25 |
*/ |
|
26 |
|
|
27 |
public class TreeListEvent{ |
|
28 |
|
|
29 |
private String elementAdded = null; |
|
30 |
private String elementRemoved = null; |
|
31 |
private String sourceElement = null; |
|
32 |
private String DestElement = null; |
|
33 |
private int positionSourceElement = -1; |
|
34 |
private int positionDestElement = -1; |
|
35 |
|
|
36 |
/** |
|
37 |
* Obtiene el elemento a?adido |
|
38 |
* @return Elemento a?adido |
|
39 |
*/ |
|
40 |
public String getElementAdded() { |
|
41 |
return elementAdded; |
|
42 |
} |
|
43 |
|
|
44 |
/** |
|
45 |
* Asigna el elemento a?adido |
|
46 |
* @param elementAdded |
|
47 |
*/ |
|
48 |
public void setElementAdded(String elementAdded) { |
|
49 |
this.elementAdded = elementAdded; |
|
50 |
} |
|
51 |
|
|
52 |
/** |
|
53 |
* Obtiene el elemento eliminado |
|
54 |
* @return Elemento eliminado |
|
55 |
*/ |
|
56 |
public String getElementRemoved() { |
|
57 |
return elementRemoved; |
|
58 |
} |
|
59 |
|
|
60 |
/** |
|
61 |
* Asigna el elemento eliminado |
|
62 |
* @param elementRemoved |
|
63 |
*/ |
|
64 |
public void setElementRemoved(String elementRemoved) { |
|
65 |
this.elementRemoved = elementRemoved; |
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* Obtiene el elemento de destino |
|
70 |
* @return Elemento de destino |
|
71 |
*/ |
|
72 |
public String getDestElement() { |
|
73 |
return DestElement; |
|
74 |
} |
|
75 |
|
|
76 |
/** |
|
77 |
* Asigna el elemento de destino |
|
78 |
* @param destElement |
|
79 |
*/ |
|
80 |
public void setDestElement(String destElement) { |
|
81 |
DestElement = destElement; |
|
82 |
} |
|
83 |
|
|
84 |
/** |
|
85 |
* Obtiene la posici?n del elemento de destino |
|
86 |
* @return Elemento de destino |
|
87 |
*/ |
|
88 |
public int getPositionDestElement() { |
|
89 |
return positionDestElement; |
|
90 |
} |
|
91 |
|
|
92 |
/** |
|
93 |
* Asigna la posici?n del elemento de destino |
|
94 |
* @param positionDestElement |
|
95 |
*/ |
|
96 |
public void setPositionDestElement(int positionDestElement) { |
|
97 |
this.positionDestElement = positionDestElement; |
|
98 |
} |
|
99 |
|
|
100 |
/** |
|
101 |
* Obtiene la posici?n del elemento de origen |
|
102 |
* @return Elemento de origen |
|
103 |
*/ |
|
104 |
public int getPositionSourceElement() { |
|
105 |
return positionSourceElement; |
|
106 |
} |
|
107 |
|
|
108 |
/** |
|
109 |
* Asigna la posici?n del elemento de origen |
|
110 |
* @param positionSourceElement |
|
111 |
*/ |
|
112 |
public void setPositionSourceElement(int positionSourceElement) { |
|
113 |
this.positionSourceElement = positionSourceElement; |
|
114 |
} |
|
115 |
|
|
116 |
/** |
|
117 |
* Obtiene el elemento de origen |
|
118 |
* @return Elemento de origen |
|
119 |
*/ |
|
120 |
public String getSourceElement() { |
|
121 |
return sourceElement; |
|
122 |
} |
|
123 |
|
|
124 |
/** |
|
125 |
* Asigna el elemento de origen |
|
126 |
* @param sourceElement |
|
127 |
*/ |
|
128 |
public void setSourceElement(String sourceElement) { |
|
129 |
this.sourceElement = sourceElement; |
|
130 |
} |
|
131 |
|
|
132 |
/** |
|
133 |
* Resetea los valores |
|
134 |
*/ |
|
135 |
public void resetValues(){ |
|
136 |
elementAdded = null; |
|
137 |
elementRemoved = null; |
|
138 |
sourceElement = null; |
|
139 |
DestElement = null; |
|
140 |
positionSourceElement = -1; |
|
141 |
positionDestElement = -1; |
|
142 |
} |
|
143 |
} |
|
0 | 144 |
tags/Root_v10+Piloto/libraries/libUIComponent_praster/src/org/gvsig/gui/beans/treelist/listeners/TreeListComponentListener.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2006 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 |
package org.gvsig.gui.beans.treelist.listeners; |
|
20 |
|
|
21 |
import java.awt.FlowLayout; |
|
22 |
import java.awt.GridBagConstraints; |
|
23 |
import java.awt.GridBagLayout; |
|
24 |
import java.awt.event.MouseEvent; |
|
25 |
import java.awt.event.MouseListener; |
|
26 |
import java.awt.event.MouseMotionListener; |
|
27 |
|
|
28 |
import javax.swing.DefaultListModel; |
|
29 |
import javax.swing.JList; |
|
30 |
import javax.swing.JPanel; |
|
31 |
import javax.swing.JScrollPane; |
|
32 |
import javax.swing.JTree; |
|
33 |
import javax.swing.ListSelectionModel; |
|
34 |
import javax.swing.event.ListSelectionEvent; |
|
35 |
import javax.swing.event.ListSelectionListener; |
|
36 |
import javax.swing.tree.DefaultMutableTreeNode; |
|
37 |
import javax.swing.tree.DefaultTreeModel; |
|
38 |
import javax.swing.tree.TreePath; |
|
39 |
|
|
40 |
import org.gvsig.gui.beans.treelist.event.TreeListEvent; |
|
41 |
import org.gvsig.i18n.Messages; |
|
42 |
|
|
43 |
/** |
|
44 |
* Interfaz que contiene los eventos del componente TreeList |
|
45 |
* Nacho Brodin (brodin_ign@gva.es) |
|
46 |
*/ |
|
47 |
|
|
48 |
public interface TreeListComponentListener{ |
|
49 |
/** |
|
50 |
* Este m?todo es ejecutado cuando se inserta un nuevo elemento en la lista |
|
51 |
* @param e TreeListEvent |
|
52 |
*/ |
|
53 |
public void elementAdded(TreeListEvent e); |
|
54 |
|
|
55 |
/** |
|
56 |
* Este m?todo es ejecutado cuando se elimina un elemento de la lista |
|
57 |
* @param e TreeListEvent |
|
58 |
*/ |
|
59 |
public void elementRemoved(TreeListEvent e); |
|
60 |
|
|
61 |
/** |
|
62 |
* Este m?todo es ejecutado cuando se mueve un elemento de la lista |
|
63 |
* @param e TreeListEvent |
|
64 |
*/ |
|
65 |
public void elementMoved(TreeListEvent e); |
|
66 |
} |
|
0 | 67 |
tags/Root_v10+Piloto/libraries/libUIComponent_praster/src/org/gvsig/gui/beans/treelist/listeners/TreeListListener.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2006 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 |
package org.gvsig.gui.beans.treelist.listeners; |
|
20 |
|
|
21 |
import java.awt.event.MouseEvent; |
|
22 |
import java.awt.event.MouseListener; |
|
23 |
import java.awt.event.MouseMotionListener; |
|
24 |
import java.util.ArrayList; |
|
25 |
|
|
26 |
import javax.swing.DefaultListModel; |
|
27 |
import javax.swing.JList; |
|
28 |
import javax.swing.JTree; |
|
29 |
import javax.swing.tree.DefaultMutableTreeNode; |
|
30 |
import javax.swing.tree.TreePath; |
|
31 |
|
|
32 |
import org.gvsig.gui.beans.treelist.event.TreeListEvent; |
|
33 |
|
|
34 |
/** |
|
35 |
* Esta clase contiene la l?gica que a?ade elementos desde el arbol a la lista, arrastrando o |
|
36 |
* haciendo doble click sobre el elemento en el arbol, elimina elementos de la lista haciendo |
|
37 |
* doble click sobre ellos o intercambia elementos arrastrando en la lista de una posici?n |
|
38 |
* a otra. |
|
39 |
* Nacho Brodin (brodin_ign@gva.es) |
|
40 |
*/ |
|
41 |
|
|
42 |
public class TreeListListener implements MouseListener, MouseMotionListener, TreeListComponentListener{ |
|
43 |
|
|
44 |
private JTree tree = null; |
|
45 |
private JList list = null; |
|
46 |
private DefaultMutableTreeNode raiz = null; |
|
47 |
private ArrayList listListeners = null; |
|
48 |
private TreeListEvent ev = new TreeListEvent(); |
|
49 |
|
|
50 |
|
|
51 |
/** |
|
52 |
* This method initializes |
|
53 |
* |
|
54 |
*/ |
|
55 |
public TreeListListener() { |
|
56 |
} |
|
57 |
|
|
58 |
/** |
|
59 |
* Asigna la lista |
|
60 |
* @param list |
|
61 |
*/ |
|
62 |
public void setList(JList list) { |
|
63 |
this.list = list; |
|
64 |
} |
|
65 |
|
|
66 |
/** |
|
67 |
* Asigna el arbol |
|
68 |
* @param tree |
|
69 |
*/ |
|
70 |
public void setTree(JTree tree) { |
|
71 |
this.tree = tree; |
|
72 |
} |
|
73 |
|
|
74 |
//------------------------------------------- |
|
75 |
//M?TODOS DEL LISTENER |
|
76 |
|
|
77 |
//A?ADIR A LA LISTA |
|
78 |
//Pinchar con doble click el elemento del arbol |
|
79 |
|
|
80 |
//Pichar lista -> obtiene draggLabel |
|
81 |
//Arrastrar -> draggActive |
|
82 |
//Released -> !draggActive. Si enterList y se ha arrastrado y se ha pichado un elemento de la lista -> a?ade elemento |
|
83 |
|
|
84 |
//ELIMINAR DE LA LISTA |
|
85 |
//Pinchar con doble click el elemento de la lista. |
|
86 |
|
|
87 |
//CAMBIAR EL ORDEN DE LOS ELEMENTOS DE LA LISTA |
|
88 |
//Pinchar lista -> Obtiene index del elem pinchado |
|
89 |
//Arrastrar -> draggElement a true |
|
90 |
//Soltar -> si hay elemento seleccionado estamos dentro de la lista y draggElement es true -> se intercambiar |
|
91 |
|
|
92 |
/** |
|
93 |
* Variable que contiene la etiqueta seleccionada y arrastrado hasta la lista |
|
94 |
*/ |
|
95 |
private String draggLabel = null; |
|
96 |
/** |
|
97 |
* Variable que est? a true si estamos arrastrando una etiqueta |
|
98 |
*/ |
|
99 |
private boolean draggActive = false; |
|
100 |
/** |
|
101 |
* Variable que est? a true si el rat?n ha entrado en la lista |
|
102 |
*/ |
|
103 |
private boolean enterInList = false; |
|
104 |
/** |
|
105 |
* Elemento seleccionado de la lista. -1 si no hay ninguno; |
|
106 |
*/ |
|
107 |
private int selectElement = -1; |
|
108 |
/** |
|
109 |
* Variable que est? a true si estamos arrastrando un elemento de la lista |
|
110 |
*/ |
|
111 |
private boolean draggElement = false; |
|
112 |
|
|
113 |
public void mouseClicked(MouseEvent e) { |
|
114 |
|
|
115 |
if(e.getSource() == list){ |
|
116 |
//Si es doble click y hay alg?n elemento seleccionado en la lista lo eliminamos |
|
117 |
if(e.getClickCount() == 2 && list.getSelectedIndex() != -1){ |
|
118 |
DefaultListModel model = (DefaultListModel)list.getModel(); |
|
119 |
|
|
120 |
//Lanzamos el evento de eliminar un elemento |
|
121 |
ev.resetValues(); |
|
122 |
ev.setElementRemoved((String)list.getSelectedValue()); |
|
123 |
elementRemoved(ev); |
|
124 |
|
|
125 |
model.remove(list.getSelectedIndex()); |
|
126 |
} |
|
127 |
} |
|
128 |
|
|
129 |
if(e.getSource() == tree){ |
|
130 |
//Si es doble click y hay alg?n elemento seleccionado en el arbol lo a?adimos |
|
131 |
if(e.getClickCount() == 2 && draggLabel != null){ |
|
132 |
DefaultListModel model = (DefaultListModel)list.getModel(); |
|
133 |
|
|
134 |
//Lanzamos el evento de a?adir un elemento |
|
135 |
ev.resetValues(); |
|
136 |
ev.setElementAdded(draggLabel); |
|
137 |
elementAdded(ev); |
|
138 |
|
|
139 |
model.addElement(draggLabel); |
|
140 |
draggLabel = null; |
|
141 |
} |
|
142 |
} |
|
143 |
} |
|
144 |
|
|
145 |
public void mouseEntered(MouseEvent e) { |
|
146 |
if(e.getSource() == list) |
|
147 |
enterInList = true; |
|
148 |
|
|
149 |
} |
|
150 |
|
|
151 |
public void mouseExited(MouseEvent e) { |
|
152 |
if(e.getSource() == list) |
|
153 |
enterInList = false; |
|
154 |
} |
|
155 |
|
|
156 |
|
|
157 |
|
|
158 |
public void mousePressed(MouseEvent e) { |
|
159 |
selectElement = -1; |
|
160 |
|
|
161 |
//Al pulsar sobre el Arbol se captura el elemento seleccionado |
|
162 |
if(e.getSource() == tree){ |
|
163 |
TreePath[] tp = tree.getSelectionPaths(); |
|
164 |
if(tp != null){ |
|
165 |
String val = tp[0].toString(); |
|
166 |
//Comprobamos que se haya pinchado sobre una rama |
|
167 |
String[] pathTree = val.split(", "); |
|
168 |
if(pathTree.length <= 2) |
|
169 |
draggLabel = null; |
|
170 |
else |
|
171 |
draggLabel = val.substring(val.lastIndexOf(", ") + 2, val.lastIndexOf("]")); |
|
172 |
} |
|
173 |
} |
|
174 |
|
|
175 |
//Al pulsar sobre la lista capturamos el elemento seleccionado |
|
176 |
if(e.getSource() == list){ |
|
177 |
selectElement = list.getSelectedIndex(); |
|
178 |
if(selectElement < 0) |
|
179 |
return; |
|
180 |
|
|
181 |
//Capturamos datos para el evento elementMoved |
|
182 |
ev.resetValues(); |
|
183 |
ev.setPositionSourceElement(selectElement); |
|
184 |
ev.setSourceElement((String)((DefaultListModel)list.getModel()).getElementAt(selectElement)); |
|
185 |
} |
|
186 |
} |
|
187 |
|
|
188 |
|
|
189 |
public void mouseReleased(MouseEvent e) { |
|
190 |
|
|
191 |
//Si se ha pinchado sobre un elemento del arbol y se ha arrastrado lo a?adimos |
|
192 |
if(enterInList){ |
|
193 |
if(draggLabel != null && draggActive == true){ |
|
194 |
DefaultListModel model = (DefaultListModel)list.getModel(); |
|
195 |
|
|
196 |
//Lanzamos el evento de a?adir un elemento |
|
197 |
ev.setElementAdded(draggLabel); |
|
198 |
elementAdded(ev); |
|
199 |
|
|
200 |
model.addElement(draggLabel); |
|
201 |
draggLabel = null; |
|
202 |
} |
|
203 |
} |
|
204 |
|
|
205 |
//Si se est? arrastrando un elemento de la lista se intercambia por el lugar donde se suelta |
|
206 |
if(draggElement && e.getSource() == list && selectElement != -1){ |
|
207 |
if(list.getSelectedIndex() != selectElement){ |
|
208 |
DefaultListModel model = (DefaultListModel)list.getModel(); |
|
209 |
int posDst = list.getSelectedIndex(); |
|
210 |
String elemOrig = (String)model.getElementAt(selectElement); |
|
211 |
|
|
212 |
ev.setPositionDestElement(posDst); |
|
213 |
ev.setDestElement((String)((DefaultListModel)list.getModel()).getElementAt(posDst)); |
|
214 |
|
|
215 |
model.remove(selectElement); |
|
216 |
model.insertElementAt(elemOrig, posDst); |
|
217 |
} |
|
218 |
} |
|
219 |
|
|
220 |
//Al levantar el click del rat?n desactivamos los arrastres |
|
221 |
draggActive = false; |
|
222 |
draggElement = false; |
|
223 |
selectElement = -1; |
|
224 |
|
|
225 |
} |
|
226 |
|
|
227 |
public void mouseDragged(MouseEvent e) { |
|
228 |
//Al arrastrar desde el arbor se pone draggActive a true se se ha pinchado antes en un elemento |
|
229 |
if(e.getSource() == tree){ |
|
230 |
if(draggLabel != null) |
|
231 |
draggActive = true; |
|
232 |
} |
|
233 |
|
|
234 |
if(e.getSource() == list){ |
|
235 |
if(selectElement != -1) |
|
236 |
draggElement = true; |
|
237 |
} |
|
238 |
} |
|
239 |
|
|
240 |
public void mouseMoved(MouseEvent e) { |
|
241 |
|
|
242 |
} |
|
243 |
|
|
244 |
/** |
|
245 |
* A?ade la lista de listeners |
|
246 |
* @param l |
|
247 |
*/ |
|
248 |
public void setListeners(ArrayList l){ |
|
249 |
this.listListeners = l; |
|
250 |
} |
|
251 |
|
|
252 |
/** |
|
253 |
* Ejecutamos el m?todo elementAdded de todos los listeners registrados |
|
254 |
* @param e TreeListEvent |
|
255 |
*/ |
|
256 |
public void elementAdded(TreeListEvent e) { |
|
257 |
if(listListeners == null || listListeners.size() == 0) |
|
258 |
return; |
|
259 |
for(int i = 0; i < listListeners.size(); i++) |
|
260 |
((TreeListComponentListener)listListeners.get(i)).elementAdded(e); |
|
261 |
} |
|
262 |
|
|
263 |
/** |
|
264 |
* Ejecutamos el m?todo elementRemoved de todos los listeners registrados |
|
265 |
* @param e TreeListEvent |
|
266 |
*/ |
|
267 |
public void elementRemoved(TreeListEvent e) { |
|
268 |
if(listListeners == null || listListeners.size() == 0) |
|
269 |
return; |
|
270 |
for(int i = 0; i < listListeners.size(); i++) |
|
271 |
((TreeListComponentListener)listListeners.get(i)).elementRemoved(e); |
|
272 |
} |
|
273 |
|
|
274 |
/** |
|
275 |
* Ejecutamos el m?todo elementMoved de todos los listeners registrados |
|
276 |
* @param e TreeListEvent |
|
277 |
*/ |
|
278 |
public void elementMoved(TreeListEvent e) { |
|
279 |
if(listListeners == null || listListeners.size() == 0) |
|
280 |
return; |
|
281 |
for(int i = 0; i < listListeners.size(); i++) |
|
282 |
((TreeListComponentListener)listListeners.get(i)).elementMoved(e); |
|
283 |
} |
|
284 |
|
|
285 |
} |
|
0 | 286 |
tags/Root_v10+Piloto/libraries/libUIComponent_praster/src/org/gvsig/gui/beans/BaseComponent.java | ||
---|---|---|
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 |
|
|
20 |
/** |
|
21 |
* |
|
22 |
*/ |
|
23 |
package org.gvsig.gui.beans; |
|
24 |
|
|
25 |
import javax.swing.JPanel; |
|
26 |
|
|
27 |
import org.gvsig.i18n.Messages; |
|
28 |
|
|
29 |
/** |
|
30 |
* Clase base para los componentes. |
|
31 |
* Registramos en ella de forma est?tica el directorio de los ficheros de traducci?n para la |
|
32 |
* libreria gvsig-i18n.jar |
|
33 |
* |
|
34 |
* @author Nacho Brodin (brodin_ign@gva.es) |
|
35 |
* |
|
36 |
*/ |
|
37 |
public abstract class BaseComponent extends JPanel{ |
|
38 |
|
|
39 |
static { |
|
40 |
Messages.addResourceFamily("org.gvsig.gui.beans.translations.text", BaseComponent.class.getClassLoader(), "org.gvsig.gui.beans"); |
|
41 |
} |
|
42 |
|
|
43 |
} |
|
0 | 44 |
tags/Root_v10+Piloto/libraries/libUIComponent_praster/src/org/gvsig/gui/beans/graphic/listeners/GraphicListener.java | ||
---|---|---|
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 |
package org.gvsig.gui.beans.graphic.listeners; |
|
20 |
|
|
21 |
import java.awt.event.ActionEvent; |
|
22 |
import java.awt.event.ActionListener; |
|
23 |
import java.awt.event.MouseEvent; |
|
24 |
import java.awt.event.MouseListener; |
|
25 |
import java.awt.event.MouseMotionListener; |
|
26 |
|
|
27 |
import javax.swing.JLabel; |
|
28 |
import javax.swing.event.TableModelEvent; |
|
29 |
|
|
30 |
import org.gvsig.gui.beans.graphic.GraphicContainer; |
|
31 |
import org.jfree.chart.ChartPanel; |
|
32 |
|
|
33 |
/** |
|
34 |
* |
|
35 |
* @author Nacho Brodin <brodin_ign@gva.es> |
|
36 |
* |
|
37 |
*/ |
|
38 |
public class GraphicListener implements MouseListener, ActionListener, MouseMotionListener{ |
|
39 |
|
|
40 |
private GraphicContainer graphicContainer = null; |
|
41 |
private boolean move = false; |
|
42 |
private JLabel left = null; |
|
43 |
private JLabel right = null; |
|
44 |
|
|
45 |
public GraphicListener(GraphicContainer graphicContainer){ |
|
46 |
this.graphicContainer = graphicContainer; |
|
47 |
} |
|
48 |
|
|
49 |
public void mouseDragged(MouseEvent e) { |
|
50 |
if(move){ |
|
51 |
if(e.getSource() == left) |
|
52 |
left.setLocation(left.getLocation().x + e.getX(), left.getLocation().y); |
|
53 |
|
|
54 |
if(e.getSource() == right) |
|
55 |
right.setLocation(right.getLocation().x + e.getX(), right.getLocation().y); |
|
56 |
} |
|
57 |
ChartPanel cp = graphicContainer.getPGraphic().getChart(); |
|
58 |
|
|
59 |
//System.out.println(cp.getScaleX()); |
|
60 |
|
|
61 |
} |
|
62 |
|
|
63 |
public void mousePressed(MouseEvent e) { |
|
64 |
move = true; |
|
65 |
} |
|
66 |
|
|
67 |
public void mouseReleased(MouseEvent e) { |
|
68 |
move = false; |
|
69 |
} |
|
70 |
|
|
71 |
public void setLabels(JLabel left, JLabel right){ |
|
72 |
this.left = left; |
|
73 |
this.right = right; |
|
74 |
} |
|
75 |
|
|
76 |
public void mouseMoved(MouseEvent e) { |
|
77 |
|
|
78 |
} |
|
79 |
|
|
80 |
private void initialize(){ |
|
81 |
|
|
82 |
} |
|
83 |
|
|
84 |
public void actionPerformed(ActionEvent e) { |
|
85 |
|
|
86 |
} |
|
87 |
|
|
88 |
public void tableChanged(TableModelEvent e) { |
|
89 |
|
|
90 |
} |
|
91 |
|
|
92 |
public void mouseClicked(MouseEvent e) { |
|
93 |
|
|
94 |
} |
|
95 |
|
|
96 |
public void mouseEntered(MouseEvent e) { |
|
97 |
|
|
98 |
} |
|
99 |
|
|
100 |
public void mouseExited(MouseEvent e) { |
|
101 |
|
|
102 |
} |
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
} |
|
0 | 107 |
Also available in: Unified diff