Revision 17453
org.gvsig.raster/tags/org.gvsig.raster-2.2.203/org.gvsig.raster.algorithm/src/main/java/org/gvsig/raster/algorithm/BasicAPISwingPanel.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
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 |
*/ |
|
22 |
package org.gvsig.raster.algorithm; |
|
23 |
|
|
24 |
import java.util.EventListener; |
|
25 |
|
|
26 |
import javax.swing.JComponent; |
|
27 |
|
|
28 |
/** |
|
29 |
* Interface for panels which build an algorithm using the parameters selected |
|
30 |
* by the user |
|
31 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
32 |
*/ |
|
33 |
public interface BasicAPISwingPanel { |
|
34 |
|
|
35 |
/** |
|
36 |
* Gets the main component |
|
37 |
* @return |
|
38 |
*/ |
|
39 |
public JComponent getComponent(); |
|
40 |
|
|
41 |
/** |
|
42 |
* Gets the process loaded with the data selected in the interface |
|
43 |
* @return |
|
44 |
*/ |
|
45 |
public Object getResult() throws Exception; |
|
46 |
|
|
47 |
/** |
|
48 |
* Initialization actions. |
|
49 |
*/ |
|
50 |
public void initialize(); |
|
51 |
|
|
52 |
/** |
|
53 |
* Gets the component ID using the object of this component. This is useful |
|
54 |
* to know what button has been pressed in a panel. The IDs should be defined |
|
55 |
* in the component API. |
|
56 |
* @param obj |
|
57 |
* @return |
|
58 |
*/ |
|
59 |
public int getComponentIDByObject(Object obj); |
|
60 |
|
|
61 |
/** |
|
62 |
* Adds a listener to the components of a panel. The EventListener could be |
|
63 |
* any listener. |
|
64 |
* @param listener |
|
65 |
*/ |
|
66 |
public void addListener(EventListener listener); |
|
67 |
} |
|
0 | 68 |
org.gvsig.raster/tags/org.gvsig.raster-2.2.203/org.gvsig.raster.algorithm/src/main/java/org/gvsig/raster/algorithm/gui/IIncrementable.java | ||
---|---|---|
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.raster.algorithm.gui; |
|
25 |
|
|
26 |
|
|
27 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
28 |
* |
|
29 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
30 |
* of the Valencian Government (CIT) |
|
31 |
* |
|
32 |
* This program is free software; you can redistribute it and/or |
|
33 |
* modify it under the terms of the GNU General Public License |
|
34 |
* as published by the Free Software Foundation; either version 2 |
|
35 |
* of the License, or (at your option) any later version. |
|
36 |
* |
|
37 |
* This program is distributed in the hope that it will be useful, |
|
38 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
39 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
40 |
* GNU General Public License for more details. |
|
41 |
* |
|
42 |
* You should have received a copy of the GNU General Public License |
|
43 |
* along with this program; if not, write to the Free Software |
|
44 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
45 |
* MA 02110-1301, USA. |
|
46 |
* |
|
47 |
*/ |
|
48 |
|
|
49 |
/** |
|
50 |
* |
|
51 |
* |
|
52 |
* @version 20/08/2008 |
|
53 |
* |
|
54 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es) |
|
55 |
*/ |
|
56 |
public interface IIncrementable { |
|
57 |
/** |
|
58 |
* Devuelve el titulo de la ventana IncrementableTask |
|
59 |
* @return String |
|
60 |
*/ |
|
61 |
public String getTitle(); |
|
62 |
|
|
63 |
/** |
|
64 |
* Devuelve el contenido del log de la ventana IncrementableTask |
|
65 |
* @return String |
|
66 |
*/ |
|
67 |
public String getLog(); |
|
68 |
|
|
69 |
/** |
|
70 |
* Devuelve la etiqueta de la ventana IncrementableTask |
|
71 |
* @return String |
|
72 |
*/ |
|
73 |
public String getLabel(); |
|
74 |
|
|
75 |
/** |
|
76 |
* Devuelve el porcentaje de 0 a 100 de la ventana IncrementableTask |
|
77 |
* @return int |
|
78 |
*/ |
|
79 |
public int getPercent(); |
|
80 |
|
|
81 |
/** |
|
82 |
* <p>Determines if this process can be canceled.</p> |
|
83 |
* |
|
84 |
* @return <code>true</code> if this process can be canceled, otherwise <code>false</code> |
|
85 |
*/ |
|
86 |
public boolean isCancelable(); |
|
87 |
|
|
88 |
/** |
|
89 |
* <p>Determines if this process can be paused.</p> |
|
90 |
* |
|
91 |
* @return <code>true</code> if this process can be paused, otherwise <code>false</code> |
|
92 |
*/ |
|
93 |
public boolean isPausable(); |
|
94 |
} |
|
0 | 95 |
org.gvsig.raster/tags/org.gvsig.raster-2.2.203/org.gvsig.raster.algorithm/src/main/java/org/gvsig/raster/algorithm/gui/LogControl.java | ||
---|---|---|
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.raster.algorithm.gui; |
|
25 |
|
|
26 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
27 |
* |
|
28 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
29 |
* of the Valencian Government (CIT) |
|
30 |
* |
|
31 |
* This program is free software; you can redistribute it and/or |
|
32 |
* modify it under the terms of the GNU General Public License |
|
33 |
* as published by the Free Software Foundation; either version 2 |
|
34 |
* of the License, or (at your option) any later version. |
|
35 |
* |
|
36 |
* This program is distributed in the hope that it will be useful, |
|
37 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
38 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
39 |
* GNU General Public License for more details. |
|
40 |
* |
|
41 |
* You should have received a copy of the GNU General Public License |
|
42 |
* along with this program; if not, write to the Free Software |
|
43 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
44 |
* MA 02110-1301, USA. |
|
45 |
* |
|
46 |
*/ |
|
47 |
|
|
48 |
/** |
|
49 |
* <code>LogControl</code>. Objeto para un control b?sico de un log. Para a?adir |
|
50 |
* y reemplazar la ?ltima l?nea a?adida. |
|
51 |
* |
|
52 |
* @version 27/03/2007 |
|
53 |
* @author BorSanZa - Borja Sanchez Zamorano (borja.sanchez@iver.es) |
|
54 |
*/ |
|
55 |
public class LogControl { |
|
56 |
String text = ""; |
|
57 |
|
|
58 |
/** |
|
59 |
* A?ade una l?nea al log. |
|
60 |
* @param line |
|
61 |
*/ |
|
62 |
public void addLine(String line) { |
|
63 |
if (text.length() > 0) |
|
64 |
text += "\n"; |
|
65 |
text += line; |
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* Reemplaza la ?ltima l?nea a?adida al log. |
|
70 |
* @param line |
|
71 |
*/ |
|
72 |
public void replaceLastLine(String line) { |
|
73 |
int index = text.lastIndexOf("\n"); |
|
74 |
if (index < 0) |
|
75 |
index = 0; |
|
76 |
text = text.substring(0, index); |
|
77 |
addLine(line); |
|
78 |
} |
|
79 |
|
|
80 |
/** |
|
81 |
* Establece el texto completo del log. |
|
82 |
* @param value |
|
83 |
*/ |
|
84 |
public void setText(String value) { |
|
85 |
text = value; |
|
86 |
} |
|
87 |
|
|
88 |
/** |
|
89 |
* Devuelve el contenido del log. |
|
90 |
* @return String |
|
91 |
*/ |
|
92 |
public String getText() { |
|
93 |
return text; |
|
94 |
} |
|
95 |
} |
|
0 | 96 |
org.gvsig.raster/tags/org.gvsig.raster-2.2.203/org.gvsig.raster.algorithm/src/main/java/org/gvsig/raster/algorithm/gui/ProgressPanel.java | ||
---|---|---|
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.raster.algorithm.gui; |
|
25 |
|
|
26 |
import java.awt.Dialog; |
|
27 |
import java.awt.Dimension; |
|
28 |
import java.awt.Frame; |
|
29 |
import java.awt.GraphicsConfiguration; |
|
30 |
import java.awt.HeadlessException; |
|
31 |
import java.awt.Toolkit; |
|
32 |
|
|
33 |
import javax.swing.JDialog; |
|
34 |
import javax.swing.JLabel; |
|
35 |
import javax.swing.JPanel; |
|
36 |
import javax.swing.JProgressBar; |
|
37 |
import javax.swing.JScrollPane; |
|
38 |
import javax.swing.JTextPane; |
|
39 |
|
|
40 |
import org.gvsig.i18n.Messages; |
|
41 |
import org.gvsig.raster.swing.RasterSwingLocator; |
|
42 |
import org.gvsig.raster.swing.basepanel.ButtonsPanelEvent; |
|
43 |
import org.gvsig.raster.swing.basepanel.ButtonsPanelListener; |
|
44 |
import org.gvsig.raster.swing.basepanel.IButtonsPanel; |
|
45 |
|
|
46 |
|
|
47 |
/** |
|
48 |
* <code>ProgressPanel</code>. Muestra una ventana de di�logo para representar |
|
49 |
* una barra de progreso con su ventana de registro. |
|
50 |
* |
|
51 |
* @version 15/07/2008 |
|
52 |
* |
|
53 |
* @author BorSanZa - Borja Sanchez Zamorano (borja.sanchez@iver.es) |
|
54 |
*/ |
|
55 |
public class ProgressPanel extends JDialog { |
|
56 |
private static final long serialVersionUID = 4321011219898234352L; |
|
57 |
|
|
58 |
private JPanel jPanel = null; |
|
59 |
private JLabel jLabel = null; |
|
60 |
private JLabel jLabel1 = null; |
|
61 |
private JPanel jPanel1 = null; |
|
62 |
private JPanel njp = null; |
|
63 |
private IButtonsPanel defaultButtonsPanel = null; |
|
64 |
private JProgressBar jProgressBar = null; |
|
65 |
private JScrollPane jScrollPane = null; |
|
66 |
private JTextPane jTextPane = null; |
|
67 |
private LogControl text = new LogControl(); |
|
68 |
private long startTime = System.currentTimeMillis(); |
|
69 |
private boolean showPause = true; |
|
70 |
|
|
71 |
/** |
|
72 |
* Constructor |
|
73 |
*/ |
|
74 |
public ProgressPanel() { |
|
75 |
super(); |
|
76 |
initialize(); |
|
77 |
} |
|
78 |
|
|
79 |
public ProgressPanel(boolean showPause) { |
|
80 |
super(); |
|
81 |
this.showPause = showPause; |
|
82 |
initialize(); |
|
83 |
} |
|
84 |
|
|
85 |
/** |
|
86 |
* @see JDialog#JDialog(Dialog, boolean) |
|
87 |
*/ |
|
88 |
public ProgressPanel(Dialog owner, boolean modal) throws HeadlessException { |
|
89 |
super(owner, modal); |
|
90 |
initialize(); |
|
91 |
} |
|
92 |
|
|
93 |
/** |
|
94 |
* @see JDialog#JDialog(Dialog, String, boolean, GraphicsConfiguration) |
|
95 |
*/ |
|
96 |
public ProgressPanel(Dialog owner, String title, boolean modal, GraphicsConfiguration gc) throws HeadlessException { |
|
97 |
super(owner, title, modal, gc); |
|
98 |
initialize(); |
|
99 |
} |
|
100 |
|
|
101 |
/** |
|
102 |
* @see JDialog#JDialog(Dialog, String, boolean) |
|
103 |
*/ |
|
104 |
public ProgressPanel(Dialog owner, String title, boolean modal) |
|
105 |
throws HeadlessException { |
|
106 |
super(owner, title, modal); |
|
107 |
initialize(); |
|
108 |
} |
|
109 |
|
|
110 |
/** |
|
111 |
* @see JDialog#JDialog(Dialog, String) |
|
112 |
*/ |
|
113 |
public ProgressPanel(Dialog owner, String title) throws HeadlessException { |
|
114 |
super(owner, title); |
|
115 |
initialize(); |
|
116 |
} |
|
117 |
|
|
118 |
/** |
|
119 |
* @see JDialog#JDialog(Dialog) |
|
120 |
*/ |
|
121 |
public ProgressPanel(Dialog owner) throws HeadlessException { |
|
122 |
super(owner); |
|
123 |
initialize(); |
|
124 |
} |
|
125 |
|
|
126 |
/** |
|
127 |
* @see JDialog#JDialog(Frame, boolean) |
|
128 |
*/ |
|
129 |
public ProgressPanel(Frame owner, boolean modal) throws HeadlessException { |
|
130 |
super(owner, modal); |
|
131 |
initialize(); |
|
132 |
} |
|
133 |
|
|
134 |
/** |
|
135 |
* @see JDialog#JDialog(Frame, String, boolean, GraphicsConfiguration) |
|
136 |
*/ |
|
137 |
public ProgressPanel(Frame owner, String title, boolean modal, GraphicsConfiguration gc) { |
|
138 |
super(owner, title, modal, gc); |
|
139 |
initialize(); |
|
140 |
} |
|
141 |
|
|
142 |
/** |
|
143 |
* @see JDialog#JDialog(Frame, String, boolean) |
|
144 |
*/ |
|
145 |
public ProgressPanel(Frame owner, String title, boolean modal) |
|
146 |
throws HeadlessException { |
|
147 |
super(owner, title, modal); |
|
148 |
initialize(); |
|
149 |
} |
|
150 |
|
|
151 |
/** |
|
152 |
* @see JDialog#JDialog(Frame, String) |
|
153 |
*/ |
|
154 |
public ProgressPanel(Frame owner, String title) throws HeadlessException { |
|
155 |
super(owner, title); |
|
156 |
initialize(); |
|
157 |
} |
|
158 |
|
|
159 |
/** |
|
160 |
* @see JDialog#JDialog(Frame) |
|
161 |
*/ |
|
162 |
public ProgressPanel(Frame owner) throws HeadlessException { |
|
163 |
super(owner); |
|
164 |
initialize(); |
|
165 |
} |
|
166 |
|
|
167 |
/** |
|
168 |
* This method initializes this |
|
169 |
*/ |
|
170 |
private void initialize() { |
|
171 |
njp = new JPanel(); |
|
172 |
njp.setLayout(new java.awt.BorderLayout(5, 5)); |
|
173 |
njp.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 15, 5, 15)); |
|
174 |
this.setContentPane(njp); |
|
175 |
this.setResizable(false); |
|
176 |
njp.add(getJPanel(), java.awt.BorderLayout.NORTH); |
|
177 |
njp.add(getJPanel1(), java.awt.BorderLayout.CENTER); |
|
178 |
njp.add(getButtonsPanel().getComponent(), java.awt.BorderLayout.SOUTH); |
|
179 |
showLog(false); |
|
180 |
setPercent(0); |
|
181 |
Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); |
|
182 |
this.setLocation( |
|
183 |
(int) (d.getWidth() - this.getWidth()) >> 1, |
|
184 |
(int) (d.getHeight() - this.getHeight()) >> 1); |
|
185 |
this.setVisible(true); |
|
186 |
} |
|
187 |
|
|
188 |
/** |
|
189 |
* This method initializes jPanel |
|
190 |
* |
|
191 |
* @return javax.swing.JPanel |
|
192 |
*/ |
|
193 |
private JPanel getJPanel() { |
|
194 |
if (jPanel == null) { |
|
195 |
jLabel1 = new JLabel(); |
|
196 |
jLabel = new JLabel(); |
|
197 |
jLabel.setText(Messages.getText("espere") + "..."); |
|
198 |
jPanel = new JPanel(); |
|
199 |
jPanel.setLayout(new java.awt.BorderLayout(5, 5)); |
|
200 |
jPanel.add(jLabel, java.awt.BorderLayout.WEST); |
|
201 |
jPanel.add(jLabel1, java.awt.BorderLayout.EAST); |
|
202 |
} |
|
203 |
return jPanel; |
|
204 |
} |
|
205 |
|
|
206 |
/** |
|
207 |
* This method initializes jPanel1 |
|
208 |
* |
|
209 |
* @return javax.swing.JPanel |
|
210 |
*/ |
|
211 |
private JPanel getJPanel1() { |
|
212 |
if (jPanel1 == null) { |
|
213 |
jPanel1 = new JPanel(); |
|
214 |
jPanel1.setLayout(new java.awt.BorderLayout(5, 5)); |
|
215 |
jPanel1.add(getJProgressBar(), java.awt.BorderLayout.NORTH); |
|
216 |
jPanel1.add(getJScrollPane(), java.awt.BorderLayout.CENTER); |
|
217 |
} |
|
218 |
return jPanel1; |
|
219 |
} |
|
220 |
|
|
221 |
public void addButtonPressedListener(ButtonsPanelListener listener) { |
|
222 |
getDefaultButtonsPanel().addButtonPressedListener(listener); |
|
223 |
} |
|
224 |
|
|
225 |
public void removeButtonPressedListener(ButtonsPanelListener listener) { |
|
226 |
getDefaultButtonsPanel().removeButtonPressedListener(listener); |
|
227 |
} |
|
228 |
|
|
229 |
public void showLog(boolean visible) { |
|
230 |
getButtonsPanel().getButton(IButtonsPanel.BUTTON_SEEDETAILS).setVisible(!visible); |
|
231 |
getButtonsPanel().getButton(IButtonsPanel.BUTTON_HIDEDETAILS).setVisible(visible); |
|
232 |
jScrollPane.setVisible(visible); |
|
233 |
|
|
234 |
this.setIgnoreRepaint(true); |
|
235 |
|
|
236 |
if (visible) |
|
237 |
this.setSize(this.getWidth(), 300); |
|
238 |
else |
|
239 |
this.pack(); |
|
240 |
|
|
241 |
this.setIgnoreRepaint(false); |
|
242 |
if (this.isVisible()) |
|
243 |
this.setVisible(true); |
|
244 |
} |
|
245 |
|
|
246 |
public void showPause(boolean visible) { |
|
247 |
if (showPause) { |
|
248 |
getButtonsPanel().getButton(IButtonsPanel.BUTTON_RESTART).setVisible(!visible); |
|
249 |
getButtonsPanel().getButton(IButtonsPanel.BUTTON_PAUSE).setVisible(visible); |
|
250 |
} else { |
|
251 |
getButtonsPanel().getButton(IButtonsPanel.BUTTON_RESTART).setVisible(false); |
|
252 |
getButtonsPanel().getButton(IButtonsPanel.BUTTON_PAUSE).setVisible(false); |
|
253 |
} |
|
254 |
} |
|
255 |
|
|
256 |
/** |
|
257 |
* @return Buttons panel |
|
258 |
* @see DefaultButtonsPanel#getButtonsPanel() |
|
259 |
*/ |
|
260 |
public IButtonsPanel getButtonsPanel() { |
|
261 |
return getDefaultButtonsPanel(); |
|
262 |
} |
|
263 |
|
|
264 |
/** |
|
265 |
* This method initializes DefaultButtonsPanel |
|
266 |
* |
|
267 |
* @return DefaultButtonsPanel |
|
268 |
*/ |
|
269 |
public IButtonsPanel getDefaultButtonsPanel() { |
|
270 |
if (defaultButtonsPanel == null) { |
|
271 |
defaultButtonsPanel = RasterSwingLocator.getSwingManager().createButtonsPanel(IButtonsPanel.BUTTONS_NONE, getJPanel1()); |
|
272 |
getButtonsPanel().addSeeDetails(); |
|
273 |
getButtonsPanel().addHideDetails(); |
|
274 |
getButtonsPanel().addPause(); |
|
275 |
getButtonsPanel().addRestart(); |
|
276 |
showPause(true); |
|
277 |
getButtonsPanel().addCancel(); |
|
278 |
//getButtonsPanel().setLayout(new java.awt.FlowLayout(FlowLayout.CENTER)); |
|
279 |
getButtonsPanel().addButtonPressedListener(new ButtonsPanelListener() { |
|
280 |
public void actionButtonPressed(ButtonsPanelEvent e) { |
|
281 |
switch (e.getButton()) { |
|
282 |
case IButtonsPanel.BUTTON_SEEDETAILS: |
|
283 |
showLog(true); |
|
284 |
break; |
|
285 |
case IButtonsPanel.BUTTON_HIDEDETAILS: |
|
286 |
showLog(false); |
|
287 |
break; |
|
288 |
case IButtonsPanel.BUTTON_PAUSE: |
|
289 |
showPause(false); |
|
290 |
break; |
|
291 |
case IButtonsPanel.BUTTON_RESTART: |
|
292 |
showPause(true); |
|
293 |
break; |
|
294 |
} |
|
295 |
} |
|
296 |
}); |
|
297 |
} |
|
298 |
return defaultButtonsPanel; |
|
299 |
} |
|
300 |
|
|
301 |
/** |
|
302 |
* This method initializes jProgressBar |
|
303 |
* |
|
304 |
* @return javax.swing.JProgressBar |
|
305 |
*/ |
|
306 |
private JProgressBar getJProgressBar() { |
|
307 |
if (jProgressBar == null) { |
|
308 |
jProgressBar = new JProgressBar(); |
|
309 |
jProgressBar.setValue(50); |
|
310 |
jProgressBar.setPreferredSize(new Dimension(450, 18)); |
|
311 |
} |
|
312 |
return jProgressBar; |
|
313 |
} |
|
314 |
|
|
315 |
/** |
|
316 |
* This method initializes jScrollPane |
|
317 |
* |
|
318 |
* @return javax.swing.JScrollPane |
|
319 |
*/ |
|
320 |
private JScrollPane getJScrollPane() { |
|
321 |
if (jScrollPane == null) { |
|
322 |
jScrollPane = new JScrollPane(); |
|
323 |
jScrollPane.setViewportView(getJTextPane()); |
|
324 |
jScrollPane.setVisible(false); |
|
325 |
} |
|
326 |
return jScrollPane; |
|
327 |
} |
|
328 |
|
|
329 |
/** |
|
330 |
* This method initializes jTextPane |
|
331 |
* |
|
332 |
* @return javax.swing.JTextPane |
|
333 |
*/ |
|
334 |
private JTextPane getJTextPane() { |
|
335 |
if (jTextPane == null) { |
|
336 |
jTextPane = new JTextPane(); |
|
337 |
jTextPane.setEditable(false); |
|
338 |
} |
|
339 |
return jTextPane; |
|
340 |
} |
|
341 |
|
|
342 |
private void updateLog() { |
|
343 |
jTextPane.setText(text.getText()); |
|
344 |
jTextPane.setCaretPosition(jTextPane.getText().length()); |
|
345 |
} |
|
346 |
|
|
347 |
public void addLineLog(String line) { |
|
348 |
text.addLine(line); |
|
349 |
updateLog(); |
|
350 |
} |
|
351 |
|
|
352 |
public void replaceLastLineLog(String line) { |
|
353 |
text.replaceLastLine(line); |
|
354 |
updateLog(); |
|
355 |
} |
|
356 |
|
|
357 |
public void setLog(String value) { |
|
358 |
long time = (System.currentTimeMillis() - startTime) / 1000; |
|
359 |
text.setText(value + "\n" + Messages.getText("tiempo_transcurrido") + ": " + time + "s"); |
|
360 |
updateLog(); |
|
361 |
} |
|
362 |
|
|
363 |
public int getPercent() { |
|
364 |
return jProgressBar.getValue(); |
|
365 |
} |
|
366 |
|
|
367 |
public void setPercent(int value) { |
|
368 |
if ((value == 0) && (!jProgressBar.isIndeterminate())) { |
|
369 |
jProgressBar.setIndeterminate(true); |
|
370 |
jLabel1.setVisible(false); |
|
371 |
} |
|
372 |
if ((value != 0) && (jProgressBar.isIndeterminate())) { |
|
373 |
jProgressBar.setIndeterminate(false); |
|
374 |
jLabel1.setVisible(true); |
|
375 |
} |
|
376 |
jProgressBar.setValue(value); |
|
377 |
jLabel1.setText(value + "%"); |
|
378 |
} |
|
379 |
|
|
380 |
public void setLabel(String value) { |
|
381 |
jLabel.setText(value); |
|
382 |
} |
|
383 |
|
|
384 |
/** |
|
385 |
* <p>Sets whether this panel will show a normal progress bar |
|
386 |
* or an indeterminate one.</p> |
|
387 |
* |
|
388 |
* @see JProgressBar#setIndeterminate(boolean) |
|
389 |
* @param indeterminate |
|
390 |
*/ |
|
391 |
public void setIndeterminate(boolean indeterminate) { |
|
392 |
getJProgressBar().setIndeterminate(indeterminate); |
|
393 |
} |
|
394 |
|
|
395 |
/** |
|
396 |
* <p>Gets whether this panel will show a normal progress bar |
|
397 |
* or an indeterminate one.</p> |
|
398 |
* |
|
399 |
* @see JProgressBar#setIndeterminate(boolean) |
|
400 |
* @param indeterminate |
|
401 |
* @return whether this panel will show a normal progress bar or an indeterminate one |
|
402 |
*/ |
|
403 |
public boolean getIndeterminate() { |
|
404 |
return getJProgressBar().isIndeterminate(); |
|
405 |
} |
|
406 |
} |
|
0 | 407 |
org.gvsig.raster/tags/org.gvsig.raster-2.2.203/org.gvsig.raster.algorithm/src/main/java/org/gvsig/raster/algorithm/gui/Cancel.java | ||
---|---|---|
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.raster.algorithm.gui; |
|
25 |
|
|
26 |
public class Cancel implements Cancellable { |
|
27 |
private boolean cancel = false; |
|
28 |
|
|
29 |
/** |
|
30 |
* Crea un nuevo CancelDraw. |
|
31 |
*/ |
|
32 |
public Cancel() { |
|
33 |
} |
|
34 |
|
|
35 |
/** |
|
36 |
* Insertar si se debe cancelar el dibujado. |
|
37 |
* |
|
38 |
* @param b |
|
39 |
* true si se debe cancelar el dibujado. |
|
40 |
*/ |
|
41 |
public void setCanceled(boolean b) { |
|
42 |
cancel = b; |
|
43 |
} |
|
44 |
|
|
45 |
/** |
|
46 |
* @see com.iver.utiles.swing.threads.Cancellable#isCanceled() |
|
47 |
*/ |
|
48 |
public boolean isCanceled() { |
|
49 |
return cancel; |
|
50 |
} |
|
51 |
|
|
52 |
} |
|
0 | 53 |
org.gvsig.raster/tags/org.gvsig.raster-2.2.203/org.gvsig.raster.algorithm/src/main/java/org/gvsig/raster/algorithm/gui/Cancellable.java | ||
---|---|---|
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.raster.algorithm.gui; |
|
25 |
|
|
26 |
|
|
27 |
/** |
|
28 |
* <p><code>Cancellable</code> interface is designed for adding support to notify that a task must be cancelled.</p> |
|
29 |
* |
|
30 |
* <p>This is useful if a process is hung up, blocking, or simply if user wants cancel it, for instance, a |
|
31 |
* drawing process of a heavy layer.</p> |
|
32 |
* |
|
33 |
* <p>The classes which implement this interface are force to share the canceling information, in order to be |
|
34 |
* notified about the current status of it. This implies a synchronous canceling process, that could be implemented by |
|
35 |
* another object.</p> |
|
36 |
*/ |
|
37 |
public interface Cancellable { |
|
38 |
/** |
|
39 |
* <p>Determines if the related task must be canceled.</p> |
|
40 |
* |
|
41 |
* @return <code>true</code> if task must been canceled; otherwise <code>false</code> |
|
42 |
* |
|
43 |
* @see #setCanceled(boolean) |
|
44 |
*/ |
|
45 |
boolean isCanceled(); |
|
46 |
|
|
47 |
/** |
|
48 |
* <p>Sets if the related task must be canceled.</p> |
|
49 |
* |
|
50 |
* @param canceled <code>true</code> if the task must be canceled; otherwise <code>false</code> |
|
51 |
* |
|
52 |
* @see #isCanceled() |
|
53 |
*/ |
|
54 |
void setCanceled(boolean canceled); |
|
55 |
} |
|
0 | 56 |
org.gvsig.raster/tags/org.gvsig.raster-2.2.203/org.gvsig.raster.algorithm/src/main/java/org/gvsig/raster/algorithm/gui/IncrementableEvent.java | ||
---|---|---|
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.raster.algorithm.gui; |
|
25 |
|
|
26 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
27 |
* |
|
28 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
29 |
* of the Valencian Government (CIT) |
|
30 |
* |
|
31 |
* This program is free software; you can redistribute it and/or |
|
32 |
* modify it under the terms of the GNU General Public License |
|
33 |
* as published by the Free Software Foundation; either version 2 |
|
34 |
* of the License, or (at your option) any later version. |
|
35 |
* |
|
36 |
* This program is distributed in the hope that it will be useful, |
|
37 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
38 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
39 |
* GNU General Public License for more details. |
|
40 |
* |
|
41 |
* You should have received a copy of the GNU General Public License |
|
42 |
* along with this program; if not, write to the Free Software |
|
43 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
44 |
* MA 02110-1301, USA. |
|
45 |
* |
|
46 |
*/ |
|
47 |
|
|
48 |
import java.util.EventObject; |
|
49 |
/** |
|
50 |
* Se utiliza para poder definir que acci?n esta ocurriendo en un momento dado |
|
51 |
* en la ventana IncrementableTask |
|
52 |
* |
|
53 |
* @version 23/04/2007 |
|
54 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es) |
|
55 |
*/ |
|
56 |
public class IncrementableEvent extends EventObject { |
|
57 |
private static final long serialVersionUID = 75795297813891036L; |
|
58 |
|
|
59 |
/** |
|
60 |
* Definir si la acci?n que esta ocurriendo es la de resumir. |
|
61 |
*/ |
|
62 |
public static final int RESUMED = 1; |
|
63 |
|
|
64 |
/** |
|
65 |
* Definir si la acci?n que esta ocurriendo es la de suspender |
|
66 |
*/ |
|
67 |
public static final int SUSPENDED = 2; |
|
68 |
|
|
69 |
/** |
|
70 |
* Definir si la acci?n que esta ocurriendo es la de cancelar. |
|
71 |
*/ |
|
72 |
public static final int CANCELED = 3; |
|
73 |
|
|
74 |
/** |
|
75 |
* Constructor de IncrementableEvent |
|
76 |
* @param source |
|
77 |
*/ |
|
78 |
public IncrementableEvent(Object source) { |
|
79 |
super(source); |
|
80 |
} |
|
81 |
} |
|
0 | 82 |
org.gvsig.raster/tags/org.gvsig.raster-2.2.203/org.gvsig.raster.algorithm/src/main/java/org/gvsig/raster/algorithm/gui/IncrementableTask.java | ||
---|---|---|
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.raster.algorithm.gui; |
|
25 |
|
|
26 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
27 |
* |
|
28 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
29 |
* of the Valencian Government (CIT) |
|
30 |
* |
|
31 |
* This program is free software; you can redistribute it and/or |
|
32 |
* modify it under the terms of the GNU General Public License |
|
33 |
* as published by the Free Software Foundation; either version 2 |
|
34 |
* of the License, or (at your option) any later version. |
|
35 |
* |
|
36 |
* This program is distributed in the hope that it will be useful, |
|
37 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
38 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
39 |
* GNU General Public License for more details. |
|
40 |
* |
|
41 |
* You should have received a copy of the GNU General Public License |
|
42 |
* along with this program; if not, write to the Free Software |
|
43 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
44 |
* MA 02110-1301, USA. |
|
45 |
* |
|
46 |
*/ |
|
47 |
|
|
48 |
import java.awt.event.WindowAdapter; |
|
49 |
import java.awt.event.WindowEvent; |
|
50 |
import java.util.ArrayList; |
|
51 |
import java.util.Iterator; |
|
52 |
|
|
53 |
import javax.swing.JDialog; |
|
54 |
import javax.swing.JOptionPane; |
|
55 |
|
|
56 |
import org.gvsig.i18n.Messages; |
|
57 |
import org.gvsig.raster.swing.basepanel.ButtonsPanelEvent; |
|
58 |
import org.gvsig.raster.swing.basepanel.ButtonsPanelListener; |
|
59 |
import org.gvsig.raster.swing.basepanel.IButtonsPanel; |
|
60 |
import org.slf4j.Logger; |
|
61 |
import org.slf4j.LoggerFactory; |
|
62 |
|
|
63 |
/** |
|
64 |
* <code>IncrementableTask</code>. Es un dialogo que contiene un ProgressPanel. |
|
65 |
* Se ejecuta bajo un Thread y va consultando a un objeto de tipo IIncrementable |
|
66 |
* para modificar sus valores. |
|
67 |
* |
|
68 |
* @version 20/08/2008 |
|
69 |
* |
|
70 |
* @author BorSanZa - Borja S�nchez Zamorano (borja.sanchez@iver.es) |
|
71 |
*/ |
|
72 |
public class IncrementableTask implements Runnable, ButtonsPanelListener { |
|
73 |
|
|
74 |
private static final Logger LOG = LoggerFactory |
|
75 |
.getLogger(IncrementableTask.class); |
|
76 |
|
|
77 |
IIncrementable iIncrementable = null; |
|
78 |
private volatile ProgressPanel progressPanel = null; |
|
79 |
private volatile Thread blinker = null; |
|
80 |
private boolean threadSuspended = false; |
|
81 |
private boolean ended = false; |
|
82 |
private boolean askOnCancel = true; |
|
83 |
private ArrayList<IncrementableListener> actionCommandListeners = new ArrayList<IncrementableListener>(); |
|
84 |
private boolean bDoCallListeners = true; |
|
85 |
|
|
86 |
/** |
|
87 |
* Constructor del IncrementableTask. |
|
88 |
* @param incrementable |
|
89 |
* @param dialog |
|
90 |
*/ |
|
91 |
public IncrementableTask(IIncrementable incrementable, ProgressPanel dialog) { |
|
92 |
iIncrementable = incrementable; |
|
93 |
progressPanel = dialog; |
|
94 |
configureProgressPanel(); |
|
95 |
} |
|
96 |
|
|
97 |
/** |
|
98 |
* Constructor del IncrementableTask. |
|
99 |
* @param incrementable |
|
100 |
*/ |
|
101 |
public IncrementableTask(IIncrementable incrementable) { |
|
102 |
iIncrementable = incrementable; |
|
103 |
configureProgressPanel(); |
|
104 |
} |
|
105 |
|
|
106 |
/** |
|
107 |
* Inicio del thread para que la ventana vaya consultando por si sola al |
|
108 |
* iIncrementable |
|
109 |
*/ |
|
110 |
public void start() { |
|
111 |
blinker = new Thread(this); |
|
112 |
blinker.start(); |
|
113 |
} |
|
114 |
|
|
115 |
/** |
|
116 |
* Detiene el proceso de consulta de la ventana. |
|
117 |
*/ |
|
118 |
public void stop() { |
|
119 |
ended = true; |
|
120 |
} |
|
121 |
|
|
122 |
/** |
|
123 |
* Este thread va leyendo el porcentaje hasta que se completa el histograma. |
|
124 |
*/ |
|
125 |
public synchronized void run() { |
|
126 |
// while (!ended && (iIncrementable.getPercent() <= 100)) { |
|
127 |
while (! ended) { |
|
128 |
try { |
|
129 |
getProgressPanel().setLabel(iIncrementable.getLabel()); |
|
130 |
getProgressPanel().setPercent(iIncrementable.getPercent()); |
|
131 |
getProgressPanel().setTitle(iIncrementable.getTitle()); |
|
132 |
getProgressPanel().setLog(iIncrementable.getLog()); |
|
133 |
Thread.sleep(100); |
|
134 |
synchronized (this) { |
|
135 |
while (threadSuspended && !ended) |
|
136 |
wait(500); |
|
137 |
} |
|
138 |
} catch (InterruptedException e) { |
|
139 |
} |
|
140 |
} |
|
141 |
|
|
142 |
// Forces to refresh the log with the last changes |
|
143 |
getProgressPanel().setLog(iIncrementable.getLog()); |
|
144 |
} |
|
145 |
|
|
146 |
/** |
|
147 |
* Termina el proceso de lectura de porcentajes y logs de la ventana y |
|
148 |
* cierra esta. |
|
149 |
*/ |
|
150 |
public void processFinalize() { |
|
151 |
stop(); |
|
152 |
while (isAlive()); |
|
153 |
hide(); |
|
154 |
} |
|
155 |
|
|
156 |
/** |
|
157 |
* Ocultar la ventana y parar el proceso |
|
158 |
*/ |
|
159 |
private void hide() { |
|
160 |
hideWindow(); |
|
161 |
progressPanel = null; |
|
162 |
blinker = null; |
|
163 |
} |
|
164 |
|
|
165 |
/** |
|
166 |
* Ocultar la ventana |
|
167 |
*/ |
|
168 |
public void hideWindow() { |
|
169 |
// getProgressPanel().dispose(); |
|
170 |
getProgressPanel().setVisible(false); |
|
171 |
} |
|
172 |
|
|
173 |
/** |
|
174 |
* Devuelve un booleano indicando si esta activa la ventana. |
|
175 |
* @return boolean |
|
176 |
*/ |
|
177 |
public boolean isAlive() { |
|
178 |
if (blinker == null) |
|
179 |
return false; |
|
180 |
return blinker.isAlive(); |
|
181 |
} |
|
182 |
|
|
183 |
/** |
|
184 |
* Muestra la ventana de incremento con el porcentaje de la construcci�n del |
|
185 |
* histograma. |
|
186 |
*/ |
|
187 |
public void showWindow() { |
|
188 |
getProgressPanel().setTitle(iIncrementable.getTitle()); |
|
189 |
getProgressPanel().showLog(false); |
|
190 |
getProgressPanel().setVisible(true); |
|
191 |
} |
|
192 |
|
|
193 |
/** |
|
194 |
* Devuelve el componente ProgressPanel de la ventana incrementable. |
|
195 |
* @return ProgressPanel |
|
196 |
*/ |
|
197 |
public ProgressPanel getProgressPanel() { |
|
198 |
if (progressPanel == null) { |
|
199 |
progressPanel = new ProgressPanel(false); |
|
200 |
} |
|
201 |
return progressPanel; |
|
202 |
} |
|
203 |
|
|
204 |
protected void configureProgressPanel() { |
|
205 |
getProgressPanel().setAlwaysOnTop(true); |
|
206 |
getProgressPanel().addButtonPressedListener(this); |
|
207 |
|
|
208 |
// Must ask if user wants to cancel the process, avoid closing the dialog |
|
209 |
getProgressPanel().setDefaultCloseOperation( JDialog.DO_NOTHING_ON_CLOSE ); |
|
210 |
getProgressPanel().addWindowListener(new WindowAdapter() { |
|
211 |
public void windowClosing(WindowEvent e) { |
|
212 |
// Simulates an event like the produced pressing the cancel button of the associated progress panel |
|
213 |
actionButtonPressed(new ButtonsPanelEvent(getProgressPanel(), IButtonsPanel.BUTTON_CANCEL)); |
|
214 |
} |
|
215 |
}); |
|
216 |
} |
|
217 |
|
|
218 |
private void callActionCommandListeners(int actions) { |
|
219 |
if (!bDoCallListeners) |
|
220 |
return; |
|
221 |
Iterator<IncrementableListener> acIterator = actionCommandListeners.iterator(); |
|
222 |
while (acIterator.hasNext()) { |
|
223 |
IncrementableListener listener = (IncrementableListener) acIterator.next(); |
|
224 |
switch (actions) { |
|
225 |
case IncrementableEvent.RESUMED: |
|
226 |
listener.actionResumed(new IncrementableEvent(this)); |
|
227 |
break; |
|
228 |
case IncrementableEvent.SUSPENDED: |
|
229 |
listener.actionSuspended(new IncrementableEvent(this)); |
|
230 |
break; |
|
231 |
case IncrementableEvent.CANCELED: |
|
232 |
listener.actionCanceled(new IncrementableEvent(this)); |
|
233 |
break; |
|
234 |
} |
|
235 |
} |
|
236 |
} |
|
237 |
|
|
238 |
/** |
|
239 |
* A�adir el manejador de eventos para atender las peticiones de start, |
|
240 |
* stop... |
|
241 |
* |
|
242 |
* @param listener |
|
243 |
*/ |
|
244 |
public void addIncrementableListener(IncrementableListener listener) { |
|
245 |
if (!actionCommandListeners.contains(listener)) |
|
246 |
actionCommandListeners.add(listener); |
|
247 |
} |
|
248 |
|
|
249 |
/** |
|
250 |
* Borrar un manejador de eventos. |
|
251 |
* @param listener |
|
252 |
*/ |
|
253 |
public void removeIncrementableListener(IncrementableListener listener) { |
|
254 |
actionCommandListeners.remove(listener); |
|
255 |
} |
|
256 |
|
|
257 |
/** |
|
258 |
* Definir si queremos que confirme al usuario si realmente desea cancelar el |
|
259 |
* proceso |
|
260 |
* |
|
261 |
* @param value |
|
262 |
*/ |
|
263 |
public void setAskCancel(boolean value) { |
|
264 |
askOnCancel = value; |
|
265 |
} |
|
266 |
|
|
267 |
/** |
|
268 |
* Metodo para gestionar todos los eventos del objeto. |
|
269 |
*/ |
|
270 |
public void actionButtonPressed(ButtonsPanelEvent e) { |
|
271 |
switch (e.getButton()) { |
|
272 |
case IButtonsPanel.BUTTON_CANCEL: |
|
273 |
boolean cancelled = true; |
|
274 |
if (askOnCancel) { |
|
275 |
if (! iIncrementable.isCancelable()) { |
|
276 |
JOptionPane.showMessageDialog(null, Messages.getText("The_process_cant_be_cancelled"), Messages.getText("Information"), JOptionPane.INFORMATION_MESSAGE); |
|
277 |
return; |
|
278 |
} |
|
279 |
|
|
280 |
/* Pauses the process */ |
|
281 |
if (iIncrementable.isPausable()) { |
|
282 |
try { |
|
283 |
callActionCommandListeners(IncrementableEvent.SUSPENDED); |
|
284 |
} |
|
285 |
catch (Exception iex) { |
|
286 |
LOG.error("", iex); |
|
287 |
JOptionPane.showMessageDialog(null, Messages.getText("Failed_pausing_the_process"), Messages.getText("Error"), JOptionPane.ERROR_MESSAGE); |
|
288 |
} |
|
289 |
} |
|
290 |
|
|
291 |
/* Asks user to cancel or not the process */ |
|
292 |
cancelled = false; |
|
293 |
String string1 = Messages.getText("Yes"); |
|
294 |
String string2 = Messages.getText("No"); |
|
295 |
Object[] options = { string1, string2 }; |
|
296 |
int answer = JOptionPane.showOptionDialog(getProgressPanel(), Messages |
|
297 |
.getText("msg_cancel_incrementable"), Messages |
|
298 |
.getText("title_cancel_incrementable"), |
|
299 |
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, |
|
300 |
options, string1); |
|
301 |
if (answer == JOptionPane.YES_OPTION) { |
|
302 |
cancelled = true; |
|
303 |
|
|
304 |
/* Continues the process */ |
|
305 |
try { |
|
306 |
if (iIncrementable.isPausable()) |
|
307 |
callActionCommandListeners(IncrementableEvent.RESUMED); |
|
308 |
} catch (Exception e2) { |
|
309 |
LOG.error("", e2); |
|
310 |
Messages.getText("Failed_resuming_the_process"); |
|
311 |
} |
|
312 |
} |
|
313 |
else { |
|
314 |
/* Continues the process */ |
|
315 |
try { |
|
316 |
if (iIncrementable.isPausable()) |
|
317 |
callActionCommandListeners(IncrementableEvent.RESUMED); |
|
318 |
} catch (Exception e2) { |
|
319 |
LOG.error("", e2); |
|
320 |
Messages.getText("Failed_resuming_the_process"); |
|
321 |
} |
|
322 |
} |
|
323 |
} |
|
324 |
if (cancelled) { |
|
325 |
// ended = true; |
|
326 |
// Will wait the process to finish and notify this to stop |
|
327 |
callActionCommandListeners(IncrementableEvent.CANCELED); |
|
328 |
} |
|
329 |
break; |
|
330 |
case IButtonsPanel.BUTTON_PAUSE: |
|
331 |
threadSuspended = true; |
|
332 |
|
|
333 |
/* Pauses the associated process */ |
|
334 |
try { |
|
335 |
if (! iIncrementable.isPausable()) { |
|
336 |
JOptionPane.showMessageDialog(null, Messages.getText("The_process_cant_be_paused"), Messages.getText("Information"), JOptionPane.INFORMATION_MESSAGE); |
|
337 |
} |
|
338 |
else { |
|
339 |
callActionCommandListeners(IncrementableEvent.SUSPENDED); |
|
340 |
} |
|
341 |
} |
|
342 |
catch (Exception iex) { |
|
343 |
LOG.error("", iex); |
|
344 |
JOptionPane.showMessageDialog(null, Messages.getText("Failed_pausing_the_process"), Messages.getText("Error"), JOptionPane.ERROR_MESSAGE); |
|
345 |
} |
|
346 |
|
|
347 |
break; |
|
348 |
case IButtonsPanel.BUTTON_RESTART: |
|
349 |
threadSuspended = false; |
|
350 |
|
|
351 |
/* Resumes the associated process */ |
|
352 |
callActionCommandListeners(IncrementableEvent.RESUMED); |
|
353 |
break; |
|
354 |
} |
|
355 |
} |
|
356 |
|
|
357 |
/** |
|
358 |
* @return Buttons panel |
|
359 |
* @see ProgressPanel#getButtonsPanel() |
|
360 |
*/ |
|
361 |
public IButtonsPanel getButtonsPanel() { |
|
362 |
return getProgressPanel().getButtonsPanel(); |
|
363 |
} |
|
364 |
} |
|
0 | 365 |
org.gvsig.raster/tags/org.gvsig.raster-2.2.203/org.gvsig.raster.algorithm/src/main/java/org/gvsig/raster/algorithm/gui/IncrementableListener.java | ||
---|---|---|
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.raster.algorithm.gui; |
|
25 |
|
|
26 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
27 |
* |
|
28 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
29 |
* of the Valencian Government (CIT) |
|
30 |
* |
|
31 |
* This program is free software; you can redistribute it and/or |
|
32 |
* modify it under the terms of the GNU General Public License |
|
33 |
* as published by the Free Software Foundation; either version 2 |
|
34 |
* of the License, or (at your option) any later version. |
|
35 |
* |
|
36 |
* This program is distributed in the hope that it will be useful, |
|
37 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
38 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
39 |
* GNU General Public License for more details. |
|
40 |
* |
|
41 |
* You should have received a copy of the GNU General Public License |
|
42 |
* along with this program; if not, write to the Free Software |
|
43 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
44 |
* MA 02110-1301, USA. |
|
45 |
* |
|
46 |
*/ |
|
47 |
|
|
48 |
import java.util.EventListener; |
|
49 |
|
|
50 |
/** |
|
51 |
* Interfaz para la ventana IncrementableTask, aqui se define los |
|
52 |
* comportamientos de los botones de la ventana. |
|
53 |
* |
|
54 |
* @version 23/04/2007 |
|
55 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es) |
|
56 |
*/ |
|
57 |
public interface IncrementableListener extends EventListener { |
|
58 |
/** |
|
59 |
* Invocado cuando se aprieta el boton Resumir de la ventana |
|
60 |
* @param e |
|
61 |
*/ |
|
62 |
public void actionResumed(IncrementableEvent e); |
|
63 |
|
|
64 |
/** |
|
65 |
* Invocado cuando se aprieta el boton Suspender de la ventana |
|
66 |
* @param e |
|
67 |
*/ |
|
68 |
public void actionSuspended(IncrementableEvent e); |
|
69 |
|
|
70 |
/** |
|
71 |
* Invocado cuando se aprieta el boton Cancelar de la ventana |
|
72 |
* @param e |
|
73 |
*/ |
|
74 |
public void actionCanceled(IncrementableEvent e); |
|
75 |
} |
|
0 | 76 |
org.gvsig.raster/tags/org.gvsig.raster-2.2.203/org.gvsig.raster.algorithm/src/main/java/org/gvsig/raster/algorithm/RasterBaseAlgorithmLibrary.java | ||
---|---|---|
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.algorithm; |
|
25 |
|
|
26 |
import java.util.List; |
|
27 |
|
|
28 |
import org.gvsig.i18n.Messages; |
|
29 |
import org.gvsig.tools.ToolsLocator; |
|
30 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
|
31 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
|
32 |
import org.gvsig.tools.library.AbstractLibrary; |
|
33 |
import org.gvsig.tools.library.LibraryException; |
|
34 |
|
|
35 |
/** |
|
36 |
* Initialization of RasterBaseAlgorithmLibrary library. |
|
37 |
* |
|
38 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a> |
|
39 |
*/ |
|
40 |
public class RasterBaseAlgorithmLibrary extends AbstractLibrary { |
|
41 |
public static final String REGISTER_PROCESS_LABEL = "DataProcess"; |
|
42 |
public static final String REGISTER_INPUT_PARAMETERS_LABEL = "DataProcessInputParameters"; |
|
43 |
public static final String REGISTER_OUTPUT_PARAMETERS_LABEL = "DataProcessOutputParameters"; |
|
44 |
|
|
45 |
/** |
|
46 |
* Registers a raster process |
|
47 |
*/ |
|
48 |
public static void register(String processLabel, Class<?> process) { |
|
49 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
|
50 |
ExtensionPoint point = extensionPoints.add(REGISTER_PROCESS_LABEL); |
|
51 |
point.append(processLabel, "", process); |
|
52 |
} |
|
53 |
|
|
54 |
/** |
|
55 |
* Gets the process name |
|
56 |
* @param process |
|
57 |
* @return |
|
58 |
*/ |
|
59 |
@SuppressWarnings("unchecked") |
|
60 |
public static String getProcessName(Class<?> process) { |
|
61 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
|
62 |
ExtensionPoint point = extensionPoints.add(REGISTER_PROCESS_LABEL); |
|
63 |
List<String> it = point.getNames(); |
|
64 |
for (int i = 0; i < it.size(); i++) { |
|
65 |
Class<?> value = point.get(it.get(i)).getExtension(); |
|
66 |
if(value == process) |
|
67 |
return it.get(i); |
|
68 |
} |
|
69 |
return null; |
|
70 |
} |
|
71 |
|
|
72 |
/** |
|
73 |
* Registers input parameters of a raster process |
|
74 |
* @deprecated Uses ProcessParamsManagement register |
|
75 |
*/ |
|
76 |
public static String registerInputParameter(String parameterLabel, Class<?> parameterClass) { |
|
77 |
return registerParameter(parameterLabel, parameterClass, REGISTER_INPUT_PARAMETERS_LABEL); |
|
78 |
} |
|
79 |
|
|
80 |
/** |
|
81 |
* Registers output parameters of a raster process |
|
82 |
* @deprecated Uses ProcessParamsManagement register |
|
83 |
*/ |
|
84 |
public static String registerOutputParameter(String parameterLabel, Class<?> parameterClass) { |
|
85 |
return registerParameter(parameterLabel, parameterClass, REGISTER_OUTPUT_PARAMETERS_LABEL); |
|
86 |
} |
|
87 |
|
|
88 |
/** |
|
89 |
* Registers a raster process |
|
90 |
* @deprecated Uses ProcessParamsManagement register |
|
91 |
*/ |
|
92 |
private static String registerParameter(String parameterLabel, Class<?> parameterClass, String type) { |
|
93 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
|
94 |
ExtensionPoint point = extensionPoints.add(type); |
|
95 |
int i = 0; |
|
96 |
|
|
97 |
//Si no hay un par?metro registrado con ese nombre se registra |
|
98 |
if(point.get(parameterLabel) == null) { |
|
99 |
point.append(parameterLabel, "", parameterClass); |
|
100 |
return parameterLabel; |
|
101 |
} else { |
|
102 |
//Si hay un par?metro registrado con ese nombre pero los tipos son iguales no se hace nada |
|
103 |
if(point.get(parameterLabel).getExtension() == parameterClass) |
Also available in: Unified diff