Revision 10962
trunk/libraries/libUIComponent/src-test/org/gvsig/gui/beans/incrementableTask/TestIncrementableTask.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import org.gvsig.gui.beans.incrementabletask.IIncrementable; |
4 | 4 |
import org.gvsig.gui.beans.incrementabletask.IncrementableTask; |
5 |
import org.gvsig.gui.beans.progresspanel.LogControl; |
|
5 | 6 |
|
6 | 7 |
public class TestIncrementableTask { |
7 |
class ClassProcess implements IIncrementable { |
|
8 |
class ClassProcess extends Thread implements IIncrementable {
|
|
8 | 9 |
int i = 0; |
10 |
long j = 0; |
|
11 |
LogControl log = new LogControl(); |
|
9 | 12 |
|
13 |
public ClassProcess() { |
|
14 |
this.start(); |
|
15 |
} |
|
16 |
|
|
17 |
public synchronized void run(){ |
|
18 |
for (j=0; j<=65535; j++) { |
|
19 |
for (long i=0; i<=65535; i++); |
|
20 |
log.replaceLastLine(j + ""); |
|
21 |
if ((j%1000)==0) { |
|
22 |
log.addLine(j + ""); |
|
23 |
} |
|
24 |
} |
|
25 |
} |
|
26 |
|
|
10 | 27 |
public String getLabel() { |
11 |
return "Etiqueta " + i;
|
|
28 |
return "Etiqueta " + j;
|
|
12 | 29 |
} |
13 | 30 |
|
14 | 31 |
public String getLog() { |
15 |
return "Mi log " + i;
|
|
32 |
return log.getText();
|
|
16 | 33 |
} |
17 | 34 |
|
18 | 35 |
public int getPercent() { |
19 |
i++; |
|
20 |
return i/10; |
|
36 |
return (int) ((j*100)/65535); |
|
21 | 37 |
} |
22 | 38 |
|
23 | 39 |
public String getTitle() { |
24 | 40 |
return "TestIncrementTask"; |
25 | 41 |
} |
42 |
|
|
43 |
public void canceled() { |
|
44 |
this.suspend(); |
|
45 |
} |
|
46 |
|
|
47 |
public void closed() { |
|
48 |
this.suspend(); |
|
49 |
} |
|
50 |
|
|
51 |
public void resumed() { |
|
52 |
this.resume(); |
|
53 |
} |
|
54 |
|
|
55 |
public void suspended() { |
|
56 |
this.suspend(); |
|
57 |
} |
|
26 | 58 |
} |
27 | 59 |
|
28 | 60 |
ClassProcess ncp = new ClassProcess(); |
trunk/libraries/libUIComponent/src-test/org/gvsig/gui/beans/progressPanel/TestProgressPanel.java | ||
---|---|---|
40 | 40 |
private volatile Thread blinker; |
41 | 41 |
|
42 | 42 |
public void showWindow() { |
43 |
frame.getButtonsPanel().getButton(ButtonsPanel.BUTTON_PAUSE).setVisible(false); |
|
43 | 44 |
frame.setTitle("Actualizando datos"); |
44 | 45 |
frame.showLog(false); |
45 | 46 |
frame.show(); |
... | ... | |
96 | 97 |
// Cerramos la ventana |
97 | 98 |
frame.hide(); |
98 | 99 |
frame = null; |
99 |
System.out.println("fin"); |
|
100 | 100 |
} |
101 | 101 |
|
102 | 102 |
public void actionPerformed(ActionEvent e) { |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/incrementabletask/IIncrementable.java | ||
---|---|---|
24 | 24 |
* @return int |
25 | 25 |
*/ |
26 | 26 |
public int getPercent(); |
27 |
} |
|
27 |
|
|
28 |
/** |
|
29 |
* Metodo que se ejecuta cuando se cancela el panel. |
|
30 |
* |
|
31 |
*/ |
|
32 |
public void canceled(); |
|
33 |
|
|
34 |
/** |
|
35 |
* Metodo que se ejecuta cuando se cierra el panel. |
|
36 |
* |
|
37 |
*/ |
|
38 |
public void closed(); |
|
39 |
|
|
40 |
|
|
41 |
/** |
|
42 |
* Metodo que se ejecuta cuando se suspende el panel. |
|
43 |
* |
|
44 |
*/ |
|
45 |
public void suspended(); |
|
46 |
|
|
47 |
/** |
|
48 |
* Metodo que se ejecuta cuando se reanuda el panel. |
|
49 |
* |
|
50 |
*/ |
|
51 |
public void resumed(); |
|
52 |
} |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/incrementabletask/IncrementableTask.java | ||
---|---|---|
8 | 8 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
9 | 9 |
import org.gvsig.gui.beans.progresspanel.ProgressPanel; |
10 | 10 |
|
11 |
public class IncrementableTask extends Thread implements ActionListener {
|
|
11 |
public class IncrementableTask implements Runnable, ActionListener {
|
|
12 | 12 |
IIncrementable iIncrementable; |
13 |
ProgressPanel progressPanel = null; |
|
14 |
|
|
13 |
private volatile ProgressPanel progressPanel = getProgressPanel(); |
|
14 |
private volatile Thread blinker; |
|
15 |
private boolean threadSuspended = false; |
|
16 |
|
|
15 | 17 |
public IncrementableTask(IIncrementable incrementable) { |
16 | 18 |
iIncrementable = incrementable; |
17 | 19 |
} |
20 |
|
|
21 |
public void start() { |
|
22 |
blinker = new Thread(this); |
|
23 |
blinker.start(); |
|
24 |
} |
|
25 |
|
|
26 |
public synchronized void stop() { |
|
27 |
blinker = null; |
|
28 |
notify(); |
|
29 |
} |
|
18 | 30 |
|
19 | 31 |
/** |
20 | 32 |
* Este thread va leyendo el porcentaje hasta que se completa el histograma. |
21 | 33 |
*/ |
22 | 34 |
public synchronized void run(){ |
23 |
while(true){ |
|
24 |
showWindow(); |
|
25 |
while (iIncrementable.getPercent() < 100){ |
|
35 |
Thread thisThread = Thread.currentThread(); |
|
36 |
while ((blinker == thisThread) && (iIncrementable.getPercent() < 100)) { |
|
37 |
try { |
|
38 |
Thread.sleep(100); |
|
26 | 39 |
getProgressPanel().setLabel(iIncrementable.getLabel()); |
27 | 40 |
getProgressPanel().setPercent(iIncrementable.getPercent()); |
28 | 41 |
getProgressPanel().setTitle(iIncrementable.getTitle()); |
29 | 42 |
getProgressPanel().setLog(iIncrementable.getLog()); |
30 |
try { |
|
31 |
sleep(100); |
|
32 |
} catch (InterruptedException e) { |
|
33 |
e.printStackTrace(); |
|
43 |
synchronized(this) { |
|
44 |
while (threadSuspended && blinker==thisThread) |
|
45 |
wait(500); |
|
34 | 46 |
} |
47 |
} catch (InterruptedException e) { |
|
35 | 48 |
} |
36 |
//Cerramos la ventana |
|
37 |
|
|
38 |
handleClose(); |
|
39 |
|
|
40 |
this.suspend(); |
|
41 | 49 |
} |
50 |
//Cerramos la ventana |
|
51 |
handleClose(); |
|
42 | 52 |
} |
43 | 53 |
|
44 | 54 |
private void handleClose() { |
45 | 55 |
getProgressPanel().setVisible(false); |
46 | 56 |
getProgressPanel().hide(); |
47 | 57 |
progressPanel = null; |
48 |
System.out.println("Cerrado"); |
|
58 |
if (iIncrementable.getPercent() == 100) |
|
59 |
iIncrementable.closed(); |
|
60 |
else |
|
61 |
iIncrementable.canceled(); |
|
49 | 62 |
} |
50 | 63 |
/** |
51 | 64 |
* Muestra la ventana de incremento con el porcentaje de la construcci?n del |
... | ... | |
56 | 69 |
getProgressPanel().showLog(false); |
57 | 70 |
getProgressPanel().show(); |
58 | 71 |
|
59 |
if(this.isAlive()) |
|
60 |
this.resume(); |
|
61 |
else |
|
62 |
this.start(); |
|
72 |
this.start(); |
|
63 | 73 |
} |
64 | 74 |
|
65 | 75 |
private ProgressPanel getProgressPanel() { |
... | ... | |
69 | 79 |
progressPanel.addWindowListener( new WindowAdapter() { |
70 | 80 |
public void windowClosing(WindowEvent e) |
71 | 81 |
{ |
72 |
handleClose();
|
|
82 |
blinker = null;
|
|
73 | 83 |
} |
74 | 84 |
}); |
75 | 85 |
} |
... | ... | |
78 | 88 |
|
79 | 89 |
public void actionPerformed(ActionEvent e) { |
80 | 90 |
if (e.getActionCommand().compareTo(ButtonsPanel.BUTTON_CANCEL + "") == 0) { |
81 |
handleClose();
|
|
91 |
blinker = null;
|
|
82 | 92 |
} |
93 |
if (e.getActionCommand().compareTo(ButtonsPanel.BUTTON_PAUSE + "") == 0) { |
|
94 |
iIncrementable.suspended(); |
|
95 |
threadSuspended = true; |
|
96 |
} |
|
97 |
if (e.getActionCommand().compareTo(ButtonsPanel.BUTTON_RESTART + "") == 0) { |
|
98 |
iIncrementable.resumed(); |
|
99 |
threadSuspended = false; |
|
100 |
} |
|
83 | 101 |
} |
84 | 102 |
} |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/graphic/listeners/GraphicListener.java | ||
---|---|---|
26 | 26 |
|
27 | 27 |
import javax.swing.JLabel; |
28 | 28 |
|
29 |
import org.gvsig.gui.beans.graphic.GraphicContainer; |
|
30 |
|
|
29 | 31 |
/** |
30 | 32 |
* |
31 | 33 |
* @author Nacho Brodin <brodin_ign@gva.es> |
32 | 34 |
* |
33 | 35 |
*/ |
34 | 36 |
public class GraphicListener implements MouseListener, ActionListener, MouseMotionListener{ |
37 |
|
|
38 |
private GraphicContainer graphicContainer = null; |
|
35 | 39 |
private boolean move = false; |
36 | 40 |
private JLabel left = null; |
37 | 41 |
private JLabel right = null; |
38 | 42 |
|
43 |
public GraphicListener(GraphicContainer graphicContainer){ |
|
44 |
this.graphicContainer = graphicContainer; |
|
45 |
} |
|
46 |
|
|
39 | 47 |
public void mouseDragged(MouseEvent e) { |
40 | 48 |
if(move){ |
41 | 49 |
if(e.getSource() == left) |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/graphic/GraphicContainer.java | ||
---|---|---|
53 | 53 |
private boolean showSlider = true; |
54 | 54 |
|
55 | 55 |
public GraphicContainer() { |
56 |
graphicListener = new GraphicListener(); |
|
56 |
graphicListener = new GraphicListener(this);
|
|
57 | 57 |
initialize(); |
58 | 58 |
} |
59 | 59 |
|
... | ... | |
61 | 61 |
this.showSlider = showSlider; |
62 | 62 |
if (!showSlider) |
63 | 63 |
HEIGHT_DOUBLESLIDER = 0; |
64 |
graphicListener = new GraphicListener(); |
|
64 |
graphicListener = new GraphicListener(this);
|
|
65 | 65 |
initialize(); |
66 | 66 |
} |
67 | 67 |
|
... | ... | |
215 | 215 |
return this.getPBoxes().getControlLeft().getTText(); |
216 | 216 |
} |
217 | 217 |
|
218 |
public void componentResized(ComponentEvent e) { |
|
219 |
this.setComponentSize(this.getWidth(), this.getHeight()); |
|
220 |
} |
|
221 |
|
|
218 | 222 |
public void componentHidden(ComponentEvent e) { |
219 | 223 |
// TODO Auto-generated method stub |
220 | 224 |
} |
221 | 225 |
|
222 | 226 |
public void componentMoved(ComponentEvent e) { |
223 |
// TODO Auto-generated method stub |
|
227 |
// TODO Auto-generated method stub
|
|
224 | 228 |
} |
225 | 229 |
|
226 |
public void componentResized(ComponentEvent e) { |
|
227 |
this.setComponentSize(this.getWidth(), this.getHeight()); |
|
228 |
} |
|
229 |
|
|
230 | 230 |
public void componentShown(ComponentEvent e) { |
231 | 231 |
// TODO Auto-generated method stub |
232 | 232 |
} |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/buttonspanel/ButtonsPanel.java | ||
---|---|---|
51 | 51 |
public static final int BUTTON_EXIT = 7; |
52 | 52 |
public static final int BUTTON_SEEDETAILS = 8; |
53 | 53 |
public static final int BUTTON_HIDEDETAILS = 9; |
54 |
public static final int BUTTON_PAUSE = 10; |
|
55 |
public static final int BUTTON_RESTART = 11; |
|
54 | 56 |
|
55 | 57 |
public static final int BUTTONS_ACCEPT = 1; |
56 | 58 |
public static final int BUTTONS_ACCEPTCANCEL = 2; |
... | ... | |
188 | 190 |
} |
189 | 191 |
|
190 | 192 |
/** |
193 |
* A?adir el boton Pausar. |
|
194 |
*/ |
|
195 |
public void addPause() { |
|
196 |
addButton(Messages.getText("pausar"), BUTTON_PAUSE); |
|
197 |
} |
|
198 |
|
|
199 |
/** |
|
200 |
* A?adir el boton Reanudar. |
|
201 |
*/ |
|
202 |
public void addRestart() { |
|
203 |
addButton(Messages.getText("reanudar"), BUTTON_RESTART); |
|
204 |
} |
|
205 |
|
|
206 |
/** |
|
191 | 207 |
* A?adimos un bot?n definido por el usuario. |
192 | 208 |
* |
193 | 209 |
* @param text Texto que contendr? el bot?n |
... | ... | |
206 | 222 |
|
207 | 223 |
add(button); |
208 | 224 |
} |
209 |
|
|
225 |
|
|
210 | 226 |
/** |
211 | 227 |
* Obtener un bot?n por su Entero |
212 | 228 |
* @param id N?mero del disparador del bot?n |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/translations/text.properties | ||
---|---|---|
30 | 30 |
cerrar=Cerrar |
31 | 31 |
salir=Salir |
32 | 32 |
verdetalles=Ver detalles |
33 |
ocultardetalles=Ocultar detalles |
|
33 |
ocultardetalles=Ocultar detalles |
|
34 |
pausar=Pausar |
|
35 |
reanudar=Reanudar |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/defaultbuttonspanel/DefaultButtonsPanel.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
27 | 27 |
/** |
28 |
* <code>DialogPanel</code> es un Panel que hereda de <code>JPanel</code> con
|
|
28 |
* <code>DefaultButtonsPanel</code> es un Panel que hereda de <code>JPanel</code> con
|
|
29 | 29 |
* el a?adido de poder definir una botonera por defecto. |
30 | 30 |
* |
31 | 31 |
* @version 15/03/2007 |
... | ... | |
37 | 37 |
JPanel content = null; |
38 | 38 |
|
39 | 39 |
/** |
40 |
* Crea el <code>DialogPanel</code> con los botones por defecto.
|
|
40 |
* Crea el <code>DefaultButtonsPanel</code> con los botones por defecto.
|
|
41 | 41 |
*/ |
42 | 42 |
public DefaultButtonsPanel() { |
43 | 43 |
super.setLayout(new java.awt.BorderLayout(5, 5)); |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/progresspanel/ProgressPanel.java | ||
---|---|---|
113 | 113 |
} |
114 | 114 |
|
115 | 115 |
public void showLog(boolean visible) { |
116 |
|
|
116 | 117 |
buttonsPanel.getButton(ButtonsPanel.BUTTON_SEEDETAILS).setVisible(!visible); |
117 | 118 |
buttonsPanel.getButton(ButtonsPanel.BUTTON_HIDEDETAILS).setVisible(visible); |
118 | 119 |
jScrollPane.setVisible(visible); |
119 | 120 |
|
120 |
int width = 400;
|
|
121 |
int width = (this.getWidth()<400?400:this.getWidth());
|
|
121 | 122 |
int height = (visible?300:120); |
122 | 123 |
|
124 |
this.setIgnoreRepaint(true); |
|
123 | 125 |
this.setSize(width, height); |
126 |
this.setResizable(visible); |
|
127 |
this.setIgnoreRepaint(false); |
|
124 | 128 |
this.show(); |
125 | 129 |
} |
130 |
|
|
131 |
public void showPause(boolean visible) { |
|
132 |
buttonsPanel.getButton(ButtonsPanel.BUTTON_RESTART).setVisible(!visible); |
|
133 |
buttonsPanel.getButton(ButtonsPanel.BUTTON_PAUSE).setVisible(visible); |
|
134 |
} |
|
126 | 135 |
|
127 | 136 |
/** |
128 | 137 |
* This method initializes ButtonsPanel |
... | ... | |
134 | 143 |
buttonsPanel = new ButtonsPanel(ButtonsPanel.BUTTONS_NONE); |
135 | 144 |
buttonsPanel.addSeeDetails(); |
136 | 145 |
buttonsPanel.addHideDetails(); |
146 |
buttonsPanel.addPause(); |
|
147 |
buttonsPanel.addRestart(); |
|
148 |
showPause(true); |
|
137 | 149 |
buttonsPanel.addCancel(); |
138 | 150 |
buttonsPanel.setLayout(new java.awt.FlowLayout(FlowLayout.CENTER)); |
139 | 151 |
buttonsPanel.addActionListener(new java.awt.event.ActionListener() { |
... | ... | |
144 | 156 |
if (e.getActionCommand().compareTo(ButtonsPanel.BUTTON_HIDEDETAILS + "") == 0) { |
145 | 157 |
showLog(false); |
146 | 158 |
} |
159 |
if (e.getActionCommand().compareTo(ButtonsPanel.BUTTON_PAUSE + "") == 0) { |
|
160 |
showPause(false); |
|
161 |
} |
|
162 |
if (e.getActionCommand().compareTo(ButtonsPanel.BUTTON_RESTART + "") == 0) { |
|
163 |
showPause(true); |
|
164 |
} |
|
147 | 165 |
} |
148 | 166 |
}); |
149 | 167 |
} |
... | ... | |
192 | 210 |
|
193 | 211 |
private void updateLog() { |
194 | 212 |
jTextPane.setText(text.getText()); |
213 |
jTextPane.setCaretPosition(jTextPane.getText().length()); |
|
195 | 214 |
} |
196 | 215 |
|
197 | 216 |
public void addLineLog(String line) { |
Also available in: Unified diff