Revision 40287 branches/v2_0_0_prep/extensions/extWFS2/src/org/gvsig/wfs/gui/panels/WFSOptionsPanel.java

View differences:

WFSOptionsPanel.java
1 1
package org.gvsig.wfs.gui.panels;
2 2

  
3
import java.awt.Dimension;
3 4
import java.awt.Rectangle;
4
import java.text.NumberFormat;
5
import java.util.Iterator;
5 6
import java.util.List;
6 7
import java.util.Vector;
7 8

  
8 9
import javax.swing.BorderFactory;
9 10
import javax.swing.JCheckBox;
10
import javax.swing.JFormattedTextField;
11
import javax.swing.JComboBox;
11 12
import javax.swing.JLabel;
13
import javax.swing.JOptionPane;
12 14
import javax.swing.JPanel;
13 15
import javax.swing.JPasswordField;
16
import javax.swing.JSpinner;
14 17
import javax.swing.JTextField;
18
import javax.swing.SpinnerModel;
19
import javax.swing.SpinnerNumberModel;
15 20
import javax.swing.border.TitledBorder;
16 21

  
17 22
import org.cresques.cts.IProjection;
18 23

  
19 24
import org.gvsig.andami.PluginServices;
25
import org.gvsig.app.ApplicationLocator;
20 26
import org.gvsig.fmap.crs.CRSFactory;
21 27
import org.gvsig.gui.beans.panelGroup.IPanelGroup;
22
import org.gvsig.utils.StringUtilities;
28
import org.gvsig.i18n.Messages;
23 29
import org.gvsig.wfs.gui.panels.model.WFSSelectedFeature;
24 30

  
25 31

  
......
118 124
 */
119 125
public class WFSOptionsPanel extends AbstractWFSPanel {
120 126
	private static final long serialVersionUID = -769956995699452173L;
127
	
128
	public static final int DEFAULT_TIMEOUT_MILLISECONDS = 20000;
121 129

  
122 130
	private JPanel credentialsPanel = null;
123 131
	private JLabel usernameLabel = null;
......
126 134
	private JPasswordField passwordText = null;
127 135
	private JPanel connectionParamsPanel = null;
128 136
	private JLabel timeoutLabel = null;
129
	private JFormattedTextField bufferText = null;
137
	
138
	private JSpinner maxFeaturesSpinner = null;
139
	
130 140
	private JLabel bufferLabel = null;
131
	private JFormattedTextField timeOutText = null;
141
	private JComboBox timeoutCombo = null;
132 142
	private JPanel formatPanel = null;
133 143
	private JLabel srsLabel = null;
134
	private JTextField srsText = null;
135
	private JLabel jLabelMiliSeconds = null;
144
	// private JTextField srsText = null;
145
	private JComboBox srsCombo = null;
146
	// private JLabel jLabelMiliSeconds = null;
136 147
	private JPanel bufferPanel = null;
137 148
	private JPanel timeOutPanel = null;
138 149
	private JPanel northPanel = null;
......
206 217
			bufferPanel = new JPanel();
207 218
			bufferLabel = new JLabel();
208 219
			bufferLabel.setText(PluginServices.getText(this, "max_features"));
220
			bufferLabel.setPreferredSize(new Dimension(90, 20));
209 221
			bufferPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
210 222
			bufferPanel.add(bufferLabel);
211
			bufferPanel.add(getBufferText());
223
			bufferPanel.add(getMaxFeatSpinner());
212 224

  
213 225
			timeOutPanel = new JPanel();
214 226
			timeoutLabel = new JLabel();
215 227
			timeoutLabel.setText(PluginServices.getText(this, "timeout"));
228
			timeoutLabel.setPreferredSize(new Dimension(90, 20));
216 229
			timeOutPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
217 230
			timeOutPanel.add(timeoutLabel);
218
			timeOutPanel.add(getTimeOutText());
219
			timeOutPanel.add(getJLabelMiliSeconds());
231
			timeOutPanel.add(getTimeoutCombo());
232
			// timeOutPanel.add(getJLabelMiliSeconds());
220 233

  
221 234
			connectionParamsPanel = new JPanel();
222 235
			connectionParamsPanel.setLayout(new java.awt.GridBagLayout());
......
238 251
		return connectionParamsPanel;
239 252
	}
240 253

  
241
	/**
242
	 * This method initializes jTextField
243
	 *
244
	 * @return javax.swing.JTextField
245
	 */
246
	private JFormattedTextField getBufferText() {
247
		if (bufferText == null) {
248
			bufferText = new JFormattedTextField(NumberFormat.getIntegerInstance());
249
			bufferText.setValue(new Integer(1000));
250
			bufferText.setBounds(new Rectangle(100, 25, 70, 20));
251
			bufferText.setToolTipText(PluginServices.getText(bufferText, "set_Max_Number_Of_Features_Will_Be_Loaded"));
252
			bufferText.addKeyListener(new java.awt.event.KeyAdapter() {
253
				public void keyTyped(java.awt.event.KeyEvent e) {
254
					IPanelGroup panelGroup = getPanelGroup();
255

  
256
					if (panelGroup == null)
257
						return;
258

  
259
					((WFSParamsPanel)panelGroup).setApplicable(true);
260
				}
261
			});
262
		}
263

  
264
		return bufferText;
254
	private JSpinner getMaxFeatSpinner() {
255
	    
256
	    if (maxFeaturesSpinner == null) {
257
	        SpinnerModel model = new SpinnerNumberModel(10000, 1, 1000000, 1);
258
	        maxFeaturesSpinner = new JSpinner(model);
259
	        // maxFeaturesSpinner.setBounds(new Rectangle(100, 25, 100, 20));
260
	    }
261
	    return maxFeaturesSpinner;
265 262
	}
266 263

  
267 264
	/**
......
269 266
	 *
270 267
	 * @return javax.swing.JTextField
271 268
	 */
272
	private JFormattedTextField getTimeOutText() {
273
		if (timeOutText == null) {
274
			timeOutText = new JFormattedTextField(NumberFormat.getIntegerInstance());
275
			timeOutText.setValue(new Integer(10000));
276
			timeOutText.setBounds(new Rectangle(100, 50, 70, 20));
277
			timeOutText.setToolTipText(PluginServices.getText(timeOutText, "set_TimeOut_Explanation"));
278
			timeOutText.addKeyListener(new java.awt.event.KeyAdapter() {
279
				public void keyTyped(java.awt.event.KeyEvent e) {
280
					IPanelGroup panelGroup = getPanelGroup();
281

  
282
					if (panelGroup == null)
283
						return;
284

  
285
					((WFSParamsPanel)panelGroup).setApplicable(true);
286
				}
287
			});
269
	private JComboBox getTimeoutCombo() {
270
		if (timeoutCombo == null) {
271
		    timeoutCombo = new JComboBox();
272
		    timeoutCombo.setEditable(false);
273
            timeoutCombo.addItem("5 sec");
274
            timeoutCombo.addItem("20 sec");
275
            timeoutCombo.addItem("2 min");
276
            timeoutCombo.addItem("10 min");
277
            // timeoutCombo.setBounds(new Rectangle(100, 50, 100, 20));
278
            timeoutCombo.setToolTipText(PluginServices.getText(timeoutCombo, "set_TimeOut_Explanation"));
288 279
		}
289

  
290
		return timeOutText;
280
		return timeoutCombo;
291 281
	}
292 282

  
293 283
	/**
......
323 313
	 */
324 314
	public int getBuffer(){
325 315
		try {
326
			String buffer = StringUtilities.replace(getBufferText().getText(),".","");
327
			buffer = StringUtilities.replace(buffer,",","");
328
			return Integer.parseInt(buffer);
329
		} catch (NumberFormatException e) {
316
		    Object val = getMaxFeatSpinner().getValue();
317
			return Integer.parseInt(val.toString());
318
		} catch (Exception e) {
330 319
			return 10000;
331 320
		}
332 321
	}
333 322
	
334 323
	public void setBuffer(int buffer){
335
	    getBufferText().setText(String.valueOf(buffer));
324
	    try {
325
	        getMaxFeatSpinner().setValue(buffer);
326
	    } catch (Exception exc) {
327
	        ApplicationLocator.getManager().messageDialog(
328
	            Messages.getText("_Unable_to_show_max_featcount"),
329
	            Messages.getText("error"),
330
	            JOptionPane.ERROR_MESSAGE);
331
	    }
336 332
	}
337 333

  
338 334
	/**
......
340 336
	 *
341 337
	 * @return the timeout used during the loading process
342 338
	 */
343
	public int getTimeout(){
344
		try {
345
			String timeOut = StringUtilities.replace(getTimeOutText().getText(),".","");
346
			timeOut = StringUtilities.replace(timeOut,",","");
347
			return Integer.parseInt(timeOut);
348
		} catch (NumberFormatException e) {
349
			return 10000;
350
		}
339
	public int getTimeout() {
340
	    
341
        String tou = this.getTimeoutCombo().getSelectedItem().toString();
342
		return toMilliseconds(tou);
343
		
351 344
	}
352 345
	
353 346
	public void setTimeOut(int timeOut){
354
	      getTimeOutText().setText(String.valueOf(timeOut));	       
347
	    int cnt = this.getTimeoutCombo().getItemCount();
348
	    for (int i=0; i<cnt; i++) {
349
	        String aux = this.getTimeoutCombo().getItemAt(i).toString();
350
	        if (timeOut == toMilliseconds(aux)) {
351
	            this.getTimeoutCombo().setSelectedIndex(i);
352
	            return;
353
	        }
354
	    }
355
	    this.getTimeoutCombo().setSelectedIndex(1);
355 356
	}
357
	
358
	
359
	private int toMilliseconds(String txt) {
360
	    
361
	    try {
362
	        String[] tt = txt.split(" ");
363
	        int aux = Integer.parseInt(tt[0]);
364
	        if (tt[1].compareToIgnoreCase("min") == 0) {
365
	            aux = aux * 60;
366
	        }
367
	        return aux * 1000;
368
	    } catch (Exception ex) {
369
	        logger.info("Did not parse item. Timeout = " + DEFAULT_TIMEOUT_MILLISECONDS);
370
	        return DEFAULT_TIMEOUT_MILLISECONDS; 
371
	    }
372
	}
356 373

  
357 374
	/**
358 375
	 * Gets the reference system of the layer.
......
360 377
	 * @return the reference system of the layer
361 378
	 */
362 379
	public String getSRS(){
363
		return getSrsText().getText();
380
	    Object sel = getSrsCombo().getSelectedItem();
381
	    if (sel == null) {
382
	        String msg = Messages.getText("error")
383
	            + " (" + Messages.getText("srs") + ")";
384
	        ApplicationLocator.getManager().message(
385
	            msg,
386
	            JOptionPane.ERROR_MESSAGE);
387
	        return "";
388
	    } else {
389
	        return sel.toString();
390
	    }
364 391
	}
365 392
	
366 393
	public void setSRS(String srs){
367
	    getSrsText().setText(srs);
394
	    getSrsCombo().setSelectedItem(srs);
368 395
	}
369 396

  
370 397
	/**
......
378 405
			formatPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
379 406
			formatPanel.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "srs"), TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
380 407
			formatPanel.add(getSRSLabel());
381
			formatPanel.add(getSrsText());
408
			formatPanel.add(getSrsCombo());
382 409
		}
383 410
		return formatPanel;
384 411
	}
......
393 420
			srsLabel = new JLabel();
394 421
			srsLabel.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
395 422
			srsLabel.setText(PluginServices.getText(this, "srs"));
396
			srsLabel.setVerticalAlignment(javax.swing.SwingConstants.TOP);
397
			srsLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
398
			srsLabel.setBounds(new java.awt.Rectangle(10, 25, 85, 16));
423
			srsLabel.setPreferredSize(new Dimension(90, 20));
399 424
		}
400 425

  
401 426
		return srsLabel;
......
406 431
	 *
407 432
	 * @return javax.swing.JTextField
408 433
	 */
409
	private JTextField getSrsText() {
410
		if (srsText == null) {
411
			srsText = new JTextField();
412
			srsText.setBounds(new java.awt.Rectangle(98, 25, 100, 20));
413
			srsText.setEnabled(false);
414
			srsText.setEditable(false);
415
			srsText.setToolTipText(PluginServices.getText(srsText, "select_Feature_Reference_System"));
434
	private JComboBox getSrsCombo() {
435
		if (srsCombo == null) {
436
		    srsCombo = new JComboBox();
437
		    // srsCombo.setBounds(new java.awt.Rectangle(110, 25, 100, 20));
438
		    srsCombo.setEnabled(true);
439
		    srsCombo.setEditable(false);
440
		    srsCombo.setToolTipText(
441
		        PluginServices.getText(srsCombo, "select_Feature_Reference_System"));
416 442
		}
417
		return srsText;
443
		return srsCombo;
418 444
	}
419 445

  
420 446
	/**
......
424 450
	 */
425 451
	public void refresh(WFSSelectedFeature layer) {
426 452
		Vector srs = layer.getSrs();
427

  
428
		if (srs.size() > 0) {
429
		    String pref = getAxisOrderPreferredCrs(srs);
430
			getSrsText().setText(pref);
453
		Iterator iter = srs.iterator();
454
		JComboBox bx = this.getSrsCombo();
455
		bx.removeAllItems();
456
		while (iter.hasNext()) {
457
		    bx.addItem(iter.next());
431 458
		}
432 459
	}
433 460

  
......
436 463
	 *
437 464
	 * @return javax.swing.JLabel
438 465
	 */
466
	/*
439 467
	public JLabel getJLabelMiliSeconds() {
440 468
		if (jLabelMiliSeconds == null) {
441 469
			jLabelMiliSeconds = new JLabel();
......
445 473

  
446 474
		return jLabelMiliSeconds;
447 475
	}
476
	*/
448 477
	
449 478
	private JPanel getCachePanel() {
450 479
		if (cachePanel == null) {
......
456 485
		return formatPanel;
457 486
	}
458 487
	
459
	public JLabel getEnableCacheCheckBox() {
488
	public JCheckBox getEnableCacheCheckBox() {
460 489
		if (enableCacheCheckBox == null) {
461 490
			enableCacheCheckBox = new JCheckBox();
462 491
			enableCacheCheckBox.setText(PluginServices.getText(null, "enable_cache"));
463 492
			enableCacheCheckBox.setBounds(new Rectangle(175, 50, 40, 16));
464 493
		}
465 494

  
466
		return jLabelMiliSeconds;
495
		return enableCacheCheckBox;
467 496
	}
468 497

  
469 498
	/*
......
513 542
     * 
514 543
     * @param crs_list
515 544
     * @return
545
     * @deprecated
516 546
     */
517 547
    public static String getAxisOrderPreferredCrs(List crs_list) {
518 548
        

Also available in: Unified diff