Revision 6804
trunk/libraries/libUI/src/org/gvsig/gui/beans/swing/GridBagLayoutPanel.java | ||
---|---|---|
43 | 43 |
* |
44 | 44 |
* $Id$ |
45 | 45 |
* $Log$ |
46 |
* Revision 1.7 2006-08-11 16:36:15 azabala |
|
46 |
* Revision 1.8 2006-08-22 07:38:58 jaume |
|
47 |
* added support for detecting changes keyboard and mouse changes over the componenets added via addComponent methods |
|
48 |
* |
|
49 |
* Revision 1.7 2006/08/11 16:36:15 azabala |
|
47 | 50 |
* *** empty log message *** |
48 | 51 |
* |
49 | 52 |
* Revision 1.6 2006/08/07 14:45:14 azabala |
... | ... | |
72 | 75 |
import java.awt.GridBagConstraints; |
73 | 76 |
import java.awt.GridBagLayout; |
74 | 77 |
import java.awt.Insets; |
78 |
import java.awt.event.KeyEvent; |
|
79 |
import java.awt.event.KeyListener; |
|
80 |
import java.awt.event.MouseEvent; |
|
81 |
import java.awt.event.MouseListener; |
|
75 | 82 |
|
76 | 83 |
import javax.swing.JComponent; |
77 | 84 |
import javax.swing.JLabel; |
... | ... | |
90 | 97 |
*/ |
91 | 98 |
public class GridBagLayoutPanel extends JPanel{ |
92 | 99 |
private GridBagLayout gridBag; |
93 |
|
|
100 |
private boolean changed; |
|
94 | 101 |
/** |
95 | 102 |
* The number of components already added to the layout manager. |
96 | 103 |
*/ |
97 | 104 |
protected int y; |
98 |
|
|
99 |
|
|
105 |
private MyValueChangeListener lst; |
|
106 |
|
|
107 |
|
|
100 | 108 |
public GridBagLayoutPanel() { |
101 | 109 |
setLayout(gridBag = new GridBagLayout()); |
110 |
lst = new MyValueChangeListener(); |
|
102 | 111 |
} |
103 | 112 |
|
104 | 113 |
/** |
... | ... | |
130 | 139 |
l.setBorder(new EmptyBorder(0,0,0,12)); |
131 | 140 |
addComponent(l,comp,fill); |
132 | 141 |
} |
133 |
|
|
134 |
|
|
142 |
|
|
143 |
|
|
135 | 144 |
public void addComponent(String label, Component comp, Insets insets) |
136 | 145 |
{ |
137 | 146 |
addComponent(label, comp, GridBagConstraints.BOTH, insets); |
138 | 147 |
} |
139 |
|
|
148 |
|
|
140 | 149 |
public void addComponent(String label, Component comp, int fill, Insets insets){ |
141 | 150 |
JLabel l = newLabel(label, comp); |
142 | 151 |
l.setBorder(new EmptyBorder(0,0,0,12)); |
... | ... | |
197 | 206 |
cons.weightx = 1.0f; |
198 | 207 |
gridBag.setConstraints(comp2,cons); |
199 | 208 |
add(comp2); |
209 |
comp1.addKeyListener(lst); |
|
210 |
comp1.addMouseListener(lst); |
|
211 |
comp2.addKeyListener(lst); |
|
212 |
comp2.addMouseListener(lst); |
|
200 | 213 |
} |
201 | 214 |
|
202 | 215 |
/** |
... | ... | |
251 | 264 |
cons.weightx = 1.0f; |
252 | 265 |
gridBag.setConstraints(comp3, cons); |
253 | 266 |
add(comp3); |
267 |
comp1.addKeyListener(lst); |
|
268 |
comp1.addMouseListener(lst); |
|
269 |
comp2.addKeyListener(lst); |
|
270 |
comp2.addMouseListener(lst); |
|
254 | 271 |
} |
255 | 272 |
|
256 | 273 |
/** |
... | ... | |
288 | 305 |
|
289 | 306 |
gridBag.setConstraints(comp,cons); |
290 | 307 |
add(comp); |
308 |
comp.addKeyListener(lst); |
|
309 |
comp.addMouseListener(lst); |
|
310 |
comp.addKeyListener(lst); |
|
311 |
comp.addMouseListener(lst); |
|
312 |
|
|
291 | 313 |
} |
292 |
|
|
314 |
|
|
293 | 315 |
/** |
294 | 316 |
* (azabala) |
295 | 317 |
* Adds a component which is going to fill many rows of the grid |
296 | 318 |
* (useful to add scrollpanes with list, etc.) |
297 |
*
|
|
319 |
* |
|
298 | 320 |
* */ |
299 | 321 |
public void addComponent(Component comp, Insets insets, int numRows){ |
300 | 322 |
GridBagConstraints cons = new GridBagConstraints(); |
... | ... | |
311 | 333 |
|
312 | 334 |
gridBag.setConstraints(comp,cons); |
313 | 335 |
add(comp); |
336 |
comp.addKeyListener(lst); |
|
337 |
comp.addMouseListener(lst); |
|
338 |
|
|
314 | 339 |
} |
315 |
|
|
316 |
|
|
340 |
|
|
341 |
|
|
317 | 342 |
///////ADDING SEPARATORS |
318 |
|
|
319 |
|
|
320 |
|
|
321 |
|
|
322 |
|
|
323 |
|
|
324 |
|
|
325 |
|
|
326 |
|
|
327 |
|
|
328 |
|
|
343 |
|
|
344 |
|
|
345 |
|
|
346 |
|
|
347 |
|
|
348 |
|
|
349 |
|
|
350 |
|
|
351 |
|
|
352 |
|
|
353 |
|
|
329 | 354 |
public void addComponent(Component comp, int fill){ |
330 | 355 |
addComponent(comp, fill, new Insets(1, 0, 1, 0)); |
331 | 356 |
} |
... | ... | |
349 | 374 |
|
350 | 375 |
gridBag.setConstraints(comp,cons); |
351 | 376 |
add(comp); |
377 |
comp.addKeyListener(lst); |
|
378 |
comp.addMouseListener(lst); |
|
352 | 379 |
} |
353 | 380 |
|
354 | 381 |
private void copyToolTips (Component c1, Component c2) { |
... | ... | |
401 | 428 |
} |
402 | 429 |
return retval; |
403 | 430 |
} |
431 |
|
|
432 |
public boolean hasChanged() { |
|
433 |
return changed; |
|
434 |
} |
|
435 |
|
|
436 |
private class MyValueChangeListener implements KeyListener, MouseListener { |
|
437 |
public void keyPressed(KeyEvent e) { changed = true; } |
|
438 |
public void keyReleased(KeyEvent e) { changed = true; } |
|
439 |
public void keyTyped(KeyEvent e) { changed = true; } |
|
440 |
public void mouseClicked(MouseEvent e) { changed = true; } |
|
441 |
public void mouseEntered(MouseEvent e) { changed = true; } |
|
442 |
public void mouseExited(MouseEvent e) { changed = true; } |
|
443 |
public void mousePressed(MouseEvent e) { changed = true; } |
|
444 |
public void mouseReleased(MouseEvent e) { changed = true; } |
|
445 |
} |
|
404 | 446 |
} |
Also available in: Unified diff