Bonjour,

Je bloque sur un problème depuis un moment, si quelqu'un pouvait m'aider ça serait top.

J'ai un utilitaire en ./bat qui fonctionne très bien.
Edigeo2SHP permettant de convertir des fichier Edigeo vers SHP.

J'ai voulu y ajouter une interface graphique ce qui rendrait la manipulation plus simple, j'ai donc integrer le .bat via la fonction
J'avais cependant une fenêtre DOS avec tout les logs qui sortait, j'ai donc ajouté les options qu'ils faillaient pour masquer ces fenêtres.

Du coup on appuie, le traitement s'effectue, puis on attend et quand c'est fini les boutons sont de nouveau actifs.
Il a donc fallu ajouter la barre de progression, et c'est là que vient le problème.

J'ai ajouté ma barre de progression:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
 
/* Barre de progression */
	progressbar = new JProgressBar(SwingConstants.HORIZONTAL);
	progressbar.setMinimum(1);
	progressbar.setMaximum(100);
	progressbar.setValue(0);
	progressbar.setSize(300,20);
	progressbar.setStringPainted(true);
Puis lors de ma récupération du readLine() de mon process, je met à jour ma barre de progression, dans le while:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
 
while ( (( ligne = br.readLine()) != null) && !ligne.isEmpty() ) {
        progressbar.setString(i+++":"+ligne);
     	progressbar.setValue(i%54);
     	progressbar.repaint();
}
Seul souci, c'est que la barre se met à jour qu'a la fin du traitement, donc il faudrait un thread, je me suis pencher sur la solution du SwingWorker avec:
http://docs.oracle.com/javase/tutori.../progress.html
qui propose un code source ici:
http://docs.oracle.com/javase/tutori...ssBarDemo.java

et là, aucun résultat..
ça peut paraitre long à lire, mais voici mon code en PJ:
EDIGEO2SHP.java
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
 
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.JProgressBar;
import javax.swing.SwingWorker;
 
public class EDIGEO2SHP extends JFrame implements ActionListener,PropertyChangeListener {
	private JButton parcourir;
	private JButton selectionner;
	private JButton convertir;
	private JTextField textParcour;
	private JTextField textSelection;
	private JProgressBar progressbar;
	private boolean traitement;
	private int i;
	private String ligne;
	private Task task;
 
	/**
         * 
         */
	private static final long serialVersionUID = 1L;
 
	public EDIGEO2SHP(){
		super();
		init();
	}
 
	class Task extends SwingWorker<Void, Void> implements Runnable {
 
		protected Void doInBackground() throws Exception {
			setProgress(0);
			while(traitement){
                setProgress(i);
			}
			return null;
		}
 
	}
 
	private void init(){
		setTitle("EDIGEO2SHP"); //On donne un titre à l'application
		setSize(700,300); //On donne une taille à notre fenêtre
		setLocationRelativeTo(null); //On centre la fenêtre sur l'écran
		setResizable(false); //On interdit la redimensionnement de la fenêtre
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //On dit à l'application de se fermer lors du clic sur la croix
		setContentPane(setContentPanel());
 
	}
 
	private JPanel setContentPanel(){
		JPanel panel = new JPanel();
		panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
		panel.setLayout(new BorderLayout(1,4));
 
		/* Boutons */
		setBouton(panel);
 
		/* retour du pannel */
		return panel;
	}
 
 
	private void setBouton(JPanel panel){
 
		/* PARCOURIR 
		 * Répertoire source à traiter
		 * */
		JPanel parcour = new JPanel();
		parcour.setBorder(BorderFactory.createEmptyBorder(7, 7, 7, 7));
		parcour.setLayout(new BorderLayout(1,2));
		//Titre
		JPanel sousParcour = new JPanel();
		sousParcour.add((new JLabel("Répertoire EDIGEO")));
		parcour.add(sousParcour,BorderLayout.WEST);
		//
		JPanel sousParcour2 = new JPanel();
		sousParcour2.setBorder(BorderFactory.createEmptyBorder(7, 7, 7, 7));
		sousParcour2.setLayout(new FlowLayout());
		//Texte de saisi
		textParcour = new JTextField();
		textParcour.setColumns(40);
		sousParcour2.add(textParcour);
		//Parcourir
		this.parcourir = new JButton("Parcourir");
		parcourir.addActionListener(this);
		sousParcour2.add(parcourir);
		parcour.add(sousParcour2,BorderLayout.SOUTH);
		panel.add(parcour,BorderLayout.NORTH);
 
		/* SELECTIONNER 
		 * Selection du fichier en sortie du traitement
		 * */
		JPanel selection = new JPanel();
		selection.setBorder(BorderFactory.createEmptyBorder(7, 7, 7, 7));
		selection.setLayout(new BorderLayout(1,2));
		//Titre
		JPanel sousSelection = new JPanel();
		sousSelection.add((new JLabel("Répertoire du fichier zip produit")));
		selection.add(sousSelection,BorderLayout.WEST);
		//
		JPanel sousSelection2 = new JPanel();
		sousSelection2.setBorder(BorderFactory.createEmptyBorder(7, 7, 7, 7));
		sousSelection2.setLayout(new FlowLayout());
		//Texte de saisi
		this.textSelection = new JTextField();
		textSelection.setColumns(40);
		sousSelection2.add(textSelection);
		//Parcourir
		this.selectionner = new JButton("Sélectionner");
		selectionner.addActionListener(this);
		sousSelection2.add(selectionner);
		selection.add(sousSelection2,BorderLayout.SOUTH);
		panel.add(selection,BorderLayout.CENTER);
 
		/* CONVERTIR 
		 * Action qui va lancer le traitement
		 * */
		JPanel conversion = new JPanel();
		conversion.setBorder(BorderFactory.createEmptyBorder(7, 7, 7, 7));
		this.convertir = new JButton("Convertir");
		convertir.addActionListener(this);
		conversion.add(convertir);
 
		/* Barre de progression */
		progressbar = new JProgressBar(SwingConstants.HORIZONTAL);
		progressbar.setMinimum(1);
		progressbar.setMaximum(100);
		progressbar.setValue(0);
		progressbar.setSize(300,20);
		progressbar.setStringPainted(true); 
		conversion.add(progressbar);
 
		panel.add(conversion,BorderLayout.SOUTH);
 
		traitement= false;
 
	}
 
	@Override
	public void actionPerformed(ActionEvent e) {
		Object source = e.getSource();
		if(source == parcourir){
			JFileChooser dialogue = new JFileChooser();
			dialogue.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
			if(dialogue.showOpenDialog(this)== JFileChooser.APPROVE_OPTION){
				String dossier = dialogue.getSelectedFile().getAbsolutePath();
				(new File(dossier)).isDirectory();
				textParcour.setText(dossier);
			}
		} else if(source == selectionner){
			JFileChooser dialogue = new JFileChooser();
			if(dialogue.showOpenDialog(this)== JFileChooser.APPROVE_OPTION){
				String fichier = dialogue.getSelectedFile().getAbsolutePath();
				textSelection.setText(fichier);
			}
		} else if(source == convertir){
			try {
				activation(false);
				executeProcess();
				/*test*/
		        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
				task = new Task();
				task.addPropertyChangeListener(this);
				task.execute();
				traitement= true;
				 /*test*/
			}catch (Exception error) {
				System.out.println("Erreur :"+error);
			}
 
	        System.out.println("activation interface");
			activation(true);
		}
 
	}
 
	public void activation(boolean act){
		parcourir.setEnabled(act);
		selectionner.setEnabled(act);
		convertir.setEnabled(act);
	}
 
	/*static public void Message ( String mes){
		JDialog box= new JDialog();
		box.add(new JLabel(mes));
		box.setResizable(false);
		box.setVisible(true);
		box.setSize(300,100); //On donne une taille à notre fenêtre
		box.setLocationRelativeTo(null); //On centre la fenêtre sur l'écran
	}	*/
 
	static public JDialog Message ( JLabel mes){
		JDialog box= new JDialog();
		box.add(mes);
		box.setResizable(false);
		box.setVisible(true);
		box.setSize(200,100); //On donne une taille à notre fenêtre
		box.setLocationRelativeTo(null); //On centre la fenêtre sur l'écran
		return box;
	}
 
	public static List<String> executeEdigeo2SHP(JTextField textParcour, JTextField textSelection){
		final List<String> listCommand = new ArrayList<String>();
		listCommand.add("cmd.exe");
		listCommand.add("/C");
		listCommand.add("Start");
		listCommand.add("/B");
		listCommand.add("/MIN");
		String path = (new File(".")).getAbsolutePath();
		listCommand.add(path.substring(0,path.length()-1)+"Edigeo2SHP.bat");
		listCommand.add("\""+textParcour.getText()+"\"");
		listCommand.add(textSelection.getText());
		listCommand.add("exit");
		return listCommand;
	}
 
	public void executeProcess( ) throws Exception {
 
 
		progressbar.setString("démarage du traitement");
		// Création de la ligne de commande
		final List<String> listCommand = executeEdigeo2SHP(textParcour, textSelection);
 
		// Création du processus ogr2ogr
		final ProcessBuilder edigeo2SHP = new ProcessBuilder(listCommand); 
		edigeo2SHP.redirectErrorStream(true);
		Process process = edigeo2SHP.start();
 
	    BufferedReader br = new BufferedReader(new InputStreamReader( process.getInputStream()));
	    ligne=""; 
        i = 0;
        while ( (( ligne = br.readLine()) != null) && !ligne.isEmpty() ) {
 
	    }
        process.waitFor();
		traitement= false;
	   // process.destroy();
	}
 
	@Override
	public void propertyChange(PropertyChangeEvent evt) {
		 //if ("progress" == evt.getPropertyName()) {
     		 progressbar.setString(i+":"+ligne);
     		 progressbar.setValue(i%54);
     		 progressbar.repaint();
		 //}
	}
	public static void main(String [] args){
		SwingUtilities.invokeLater(new Runnable(){
			public void run(){
				//On crée une nouvelle instance de notre interface
				EDIGEO2SHP fenetre = new EDIGEO2SHP();
				//On la rend visible
				fenetre.setVisible(true);
			}
		});
	}
 
 
 
 
}
Si quelqu'un pourrait m'aider, ça serait top.. Merci par avance..