File: ConfigureLO.java

package info (click to toggle)
jfractionlab 0.92-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 5,456 kB
  • sloc: java: 10,103; sh: 182; makefile: 17
file content (364 lines) | stat: -rw-r--r-- 9,501 bytes parent folder | download | duplicates (3)
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
/*
 * C:\Programme\LibreOffice3.4\URE\java
 * C:\Programme\LibreOffice3.4\Basis\program\classes
 * C:\Programme\LibreOffice3.4\program
 */

package jfractionlab.jflDialogs;

import org.debian.tablelayout.TableLayout;

import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import jfractionlab.ConfManager;
import jfractionlab.JFractionLab;
import jfractionlab.officeMachine.OfficeStarter;

public class ConfigureLO extends JDialog implements ActionListener{
	static final long serialVersionUID = JFractionLab.serialVersionUID;
	
	private JLabel lb_intro = new JLabel("");
	
	private JPanel pn_outer = new JPanel();
	private JLabel lb_outer = new JLabel("");
	private JPanel pn_inner = new JPanel();
	
	private JPanel pn_jurt = new JPanel();
	private JLabel lb_jurt = new JLabel("", JLabel.LEFT);
	private JTextField jtf_jurt = new JTextField();
	private JButton btn_jurt = new JButton();
	
	private JPanel pn_unoil = new JPanel();
	private JLabel lb_unoil = new JLabel("", JLabel.LEFT);
	private JTextField jtf_unoil = new JTextField();
	private JButton btn_unoil = new JButton();
	
	private JPanel pn_soffice = new JPanel();
	private JLabel lb_soffice = new JLabel("", JLabel.LEFT);
	private JTextField jtf_soffice = new JTextField();
	private JButton btn_soffice = new JButton();
	
	private JButton btn_OK = new JButton("");
	private JButton btn_Cancel = new JButton("");
	
	public ConfigureLO() {
		makeGUI();
	}

	/**
	 * 
	 *
	 */
	private void makeGUI(){
		setLocation(50, 50);
		setSize(600, 650);
//		setResizable(false);
		setTitle(lang.Messages.getString("configure_libreoffice"));
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		double sizes_main[][] = {{
			5,
			TableLayout.FILL,
			TableLayout.FILL,
			5
		},{
			5,					//rand
			0.2,				//info
			TableLayout.FILL,	//pn_outer
			5,					//abstand
			30,					//buttons
			5					//rand
		}}; //Spalten / Zeilen
		double sizes_outer[][] = {{
			5,
			TableLayout.FILL,
			5
		},{
			5,
			0.45,
			TableLayout.FILL,
			5
		}}; //Spalten / Zeilen
		double sizes_inner[][] = {{
			5,
			TableLayout.FILL,
			5
		},{
			5,
			TableLayout.FILL,
			TableLayout.FILL,
			TableLayout.FILL,
			5
		}}; //Spalten / Zeilen
		getRootPane().setDefaultButton(btn_OK);
		Container content = getContentPane();
		content.setLayout(new TableLayout(sizes_main));
		
		pn_outer.setLayout(new TableLayout(sizes_outer));
		pn_outer.setBorder(BorderFactory.createEtchedBorder());
		pn_inner.setLayout(new TableLayout(sizes_inner));
		
		/* pn_main
		 * 		pn_outer
		 * 			pn_inner
		 * 				pn_jurt
		 * 				pn_unoil
		 * 				pn_soffice
		 * 
		 * build_all_components from inner to outer
		 */
		
		//build pn_inner
		lb_jurt.setText("jurt.jar");
		makePanel(pn_jurt, lb_jurt, jtf_jurt, btn_jurt);
		pn_inner.add(pn_jurt, "1,1");
		
		lb_unoil.setText("unoil.jar");
		makePanel(pn_unoil, lb_unoil, jtf_unoil, btn_unoil);
		pn_inner.add(pn_unoil, "1,2");
		
		lb_soffice.setText("soffice / soffice.exe");
		makePanel(pn_soffice, lb_soffice, jtf_soffice, btn_soffice);
		pn_inner.add(pn_soffice, "1,3");
		
		//build pn_outer
		lb_outer.setText("<html><p align=center>"+
				lang.Messages.getString("find_lo_jars")+"<br><br>"+
				lang.Messages.getString("example_path")+"<br>"+
				"Linux   : /opt/libreoffice3.4/ure/share/java/<br>"+
				"Windows : C:\\Programme\\LibreOffice3.4\\URE\\java</p></html>"
		);
		pn_outer.add(lb_outer, "1,1");
		pn_outer.add(pn_inner, "1,2");
		
		//build main
		lb_intro.setText("<html><p align=center>"+
				lang.Messages.getString(
						"officepath_needs_to_be_configured")+"<br>"+
				lang.Messages.getString("jfl_needs_three_paths")+"</p></html>"
		);
		content.add(lb_intro, "1,1,2,1");
		content.add(pn_outer, "1,2,2,2");
		
		btn_Cancel.addActionListener(this);
		btn_Cancel.setText(lang.Messages.getString("cancel"));
		content.add(btn_Cancel, "1,4");
		
		btn_OK.addActionListener(this);
		btn_OK.setText(lang.Messages.getString("OK"));
		content.add(btn_OK, "2,4");
		setVisible(true);
	}//makeGUI
	
	
	private void makePanel(JPanel pn, JLabel lb, JTextField jtf, JButton btn){
		double sizes_pn[][] = {{
			5,
			0.9,
			TableLayout.FILL,
			5
		},{
			5,
			TableLayout.FILL,
			30,
			5
		}}; //Spalten / Zeilen
		pn.setLayout(new TableLayout(sizes_pn));
		pn.setBorder(BorderFactory.createEtchedBorder());
		
		pn.add(lb, "1,1,2,1");
		//JOptionPane.showMessageDialog(this, new ConfManager().alertConfigurations());
		
		String[] ar = new ConfManager().getUnoConfJars();
		if(jtf == jtf_jurt){
			String str = ar[0];
			if(str.length()>0) jtf.setText(str.substring(0,str.lastIndexOf(File.separator)));
		}else if (jtf == jtf_unoil){
			String str = ar[(JFractionLab.nbOfUnoConfJars-2)];
			if(str.length()>0) jtf.setText(str.substring(0,str.lastIndexOf(File.separator)));
		}else if(jtf == jtf_soffice){
			String str = ar[(JFractionLab.nbOfUnoConfJars-1)];
			if(str.length()>0) jtf.setText(str.substring(0,str.lastIndexOf(File.separator)));
		}
		pn.add(jtf, "1,2");
		btn.addActionListener(this);
		btn.setText(" ... ");
		pn.add(btn, "2,2");
	}
	
	private void okAction(){
		boolean bl = true;
		String[] uno_jars = new String[JFractionLab.nbOfUnoConfJars];
		String malPath = "";
		
		String jurtPath= jtf_jurt.getText().trim();
		String unoilPath = jtf_unoil.getText().trim();
		String sofficePath = jtf_soffice.getText().trim();
		
		if(jurtPath.endsWith("jurt.jar")){
			jurtPath = jurtPath.substring(0, jurtPath.indexOf("jurt.jar"));
			jtf_jurt.setText(jurtPath);
		}
		if(unoilPath.endsWith("unoil.jar")){
			unoilPath = unoilPath.substring(0, unoilPath.indexOf("unoil.jar"));
			jtf_unoil.setText(unoilPath);
		}
		
		if(sofficePath.endsWith("soffice")){
			sofficePath = sofficePath.substring(0, sofficePath.indexOf("soffice"));
			jtf_soffice.setText(sofficePath);
		}
		if(sofficePath.endsWith("soffice.exe")){
			sofficePath = sofficePath.substring(0, sofficePath.indexOf("soffice.exe"));
			jtf_soffice.setText(sofficePath);
		}
		
		String str = createURIString(jurtPath, "java_uno.jar");
		if(new File(str).exists()){
			uno_jars[0] = str;
		}else{
			bl = false;
			malPath=jurtPath;
		}
		str = createURIString(jurtPath, "juh.jar");
		if(new File(str).exists()){
			uno_jars[1] = str;
		}else{
			bl = false;
			malPath=jurtPath;
		}
		str = createURIString(jurtPath, "jurt.jar");
		if(new File(str).exists()){
			uno_jars[2] = str;
		}else{
			bl = false;
			malPath=jurtPath;
		}
		str = createURIString(jurtPath, "ridl.jar");
		if(new File(str).exists()){
			uno_jars[3] = str;
		}else{
			bl = false;
			malPath=jurtPath;
		}
		str = createURIString(jurtPath, "unoloader.jar");
		if(new File(str).exists()){
			uno_jars[4] = str;
		}else{
			bl = false;
			malPath=jurtPath;
		}
		str = createURIString(unoilPath, "unoil.jar");
		if(new File(str).exists()){
			uno_jars[5] = str;
		}else{
			bl = false;
			malPath=unoilPath;
		}
		
		if (JFractionLab.os.contains("win")){	
			str = createURIString(sofficePath, "soffice.exe");
			if(new File(str).exists()){
				uno_jars[6] = str;
			}else{
				bl = false;
				malPath=sofficePath;
			}
		}else{
			str = createURIString(sofficePath, "soffice");
			if(new File(str).exists()){
				uno_jars[6] = str;
			}else{
				bl = false;
				malPath=sofficePath;
			}
		}
		if(!bl){
			JOptionPane.showMessageDialog(this,
					lang.Messages.getString("cant_find_jar")+" : "+
					malPath
			);
		}else{
			ConfManager cm = new ConfManager();
			cm.setUnoConfJars(uno_jars);
			for(int i = 0; i < uno_jars.length; i++){
				try {
					OfficeStarter.addToClassPath(new File(uno_jars[i]));
				} catch (IllegalArgumentException e) {
					e.printStackTrace();
				} catch (SecurityException e) {
					e.printStackTrace();
				} catch (IllegalAccessException e) {
					e.printStackTrace();
				} catch (InvocationTargetException e) {
					e.printStackTrace();
				} catch (NoSuchMethodException e) {
					e.printStackTrace();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			// conf auslesen
			//JOptionPane.showMessageDialog(this, cm.readConfigurations());
			close();
		}
	}

	private String createURIString(String path, String file){
		String str;
		if(path.substring(path.length()-1).equals(File.separator)){
			str = path+file;
		}else{
			str = path+File.separator+file;
		}
		return str;
	}

	public void actionPerformed(ActionEvent e){
		Object obj = e.getSource();
		if (obj == btn_OK){
			okAction();
		}else if(obj == btn_Cancel){
			close();
		}else if(obj == btn_jurt){
			jtf_jurt.setText(selectDir());
		}else if(obj == btn_unoil){
			jtf_unoil.setText(selectDir());
		}else if(obj == btn_soffice){
			jtf_soffice.setText(selectDir());
		}
	}//actionPerformed

	public String selectDir(){
		
		JFileChooser fc = new JFileChooser();
		//warum hat setLocale keine Wirkung?
		fc.setLocale(lang.Messages.getLocale());
		fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		int returnVal = fc.showOpenDialog(this);
		if (returnVal == JFileChooser.APPROVE_OPTION) {
			return fc.getSelectedFile().toString();
		}else{
			return "";
		}
	}
	
	private void close(){
		setVisible(false);
		dispose();
	}

	}//class InfoDialog