Revision 20311 trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/properties/panels/GeneralPanel.java

View differences:

GeneralPanel.java
31 31
import javax.swing.BorderFactory;
32 32
import javax.swing.JButton;
33 33
import javax.swing.JCheckBox;
34
import javax.swing.JEditorPane;
34 35
import javax.swing.JFormattedTextField;
35 36
import javax.swing.JLabel;
36 37
import javax.swing.JPanel;
38
import javax.swing.JScrollPane;
37 39
import javax.swing.border.TitledBorder;
38 40
import javax.swing.text.DefaultFormatterFactory;
39 41
import javax.swing.text.NumberFormatter;
......
41 43
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
42 44
import org.gvsig.gui.beans.panelGroup.panels.AbstractPanel;
43 45
import org.gvsig.raster.Configuration;
46
import org.gvsig.raster.IProcessActions;
44 47
import org.gvsig.raster.RasterProcess;
48
import org.gvsig.raster.dataset.properties.DatasetStatistics;
45 49
import org.gvsig.raster.grid.GridTransparency;
46 50
import org.gvsig.raster.hierarchy.IRasterProperties;
47 51
import org.gvsig.raster.util.RasterToolsUtil;
......
57 61
 * @version 15/04/2008
58 62
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
59 63
 */
60
public class GeneralPanel extends AbstractPanel implements ActionListener, INoDataPanel {
64
public class GeneralPanel extends AbstractPanel implements ActionListener, INoDataPanel, IProcessActions {
61 65
	private static final long serialVersionUID = -4761218260868307869L;
62 66
	private FLayer              fLayer              = null;
63 67

  
......
79 83
	private JPanel              recalcStatsPanel    = null;
80 84
	private NoDataPanel         pNoDataPanel        = null;
81 85
	private GridTransparency    transparency        = null;
86
	
87
	private JScrollPane         jScrollPane         = null;
88
	private JEditorPane         jEditorPane         = null;
82 89

  
90
	private final String      bgColor0        = "\"#FEEDD6\""; // light salmon
91
	private final String      bgColor1        = "\"#EAEAEA\""; // light grey
92
	private final String      bgColor3        = "\"#FBFFE1\""; // light yellow
93
	private final String      bgColor4        = "\"#D6D6D6\""; // Gris
94

  
83 95
	/**
96
	 * Booleano que est? a true cuando la fila a dibujar es par y a false cuando
97
	 * es impar.
98
	 */
99
	private boolean           rowColor        = true;
100

  
101

  
102
	/**
84 103
	 * Constructor del GeneralPanel
85 104
	 */
86 105
	public GeneralPanel() {
......
134 153
		gridBagConstraints = new java.awt.GridBagConstraints();
135 154
		gridBagConstraints.gridx = 0;
136 155
		gridBagConstraints.gridy = 2;
137
		gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
156
		gridBagConstraints.weighty = 1.0;
157
		gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
138 158
		add(getRecalcStatsPanel(), gridBagConstraints);
139 159
		
140
		gridBagConstraints = new java.awt.GridBagConstraints();
141
		gridBagConstraints.gridx = 0;
142
		gridBagConstraints.gridy = 3;
143
		gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
144
		gridBagConstraints.weighty = 1.0;
145
		add(new JPanel(), gridBagConstraints);
146
		
147 160
		this.setPreferredSize(new Dimension(100, 80));
148 161
	}
149 162
	
......
241 254
	public JPanel getRecalcStatsPanel() {
242 255
		if (recalcStatsPanel == null) {
243 256
			recalcStatsPanel = new JPanel();
244
			recalcStatsPanel.setLayout(new BorderLayout());
245
			recalcStatsPanel.add(getCalcButton(), BorderLayout.CENTER);
257
			recalcStatsPanel.setLayout(new BorderLayout(5, 5));
258
			
259
			recalcStatsPanel.add(getJScrollPane(), BorderLayout.CENTER);
260
			recalcStatsPanel.add(getCalcButton(), BorderLayout.SOUTH);
246 261
		}
247 262
		return recalcStatsPanel;
248 263
	}
......
254 269
	public JButton getCalcButton() {
255 270
		if(calcButton == null) {
256 271
			calcButton = new JButton(RasterToolsUtil.getText(this, "recalc_stats"));
257
			calcButton.addActionListener(new ActionListener() {
258
				public void actionPerformed(ActionEvent e) {
259
					RasterProcess process = new StatisticsProcess();
260
					process.addParam("layer", fLayer);
261
					process.addParam("force", new Boolean(true));
262
					process.start();
263
				}
264
			});
272
			calcButton.addActionListener(this);
265 273
		}
266 274
		return calcButton;
267 275
	}
......
345 353
			getJTextFieldMinim().setBackground(enabled?Color.white: getBackground());
346 354
		}
347 355

  
356
		if (e.getSource() == getCalcButton()) {
357
			RasterProcess process = new StatisticsProcess();
358
			process.addParam("layer", fLayer);
359
			process.addParam("force", new Boolean(true));
360
			process.setActions(this);
361
			process.start();
362
		}
363
		
348 364
		if (e.getSource() == getJCheckBoxMaxim()) {
349 365
			boolean enabled = getJCheckBoxMaxim().isSelected();
350 366
			getJLabelMaxim().setEnabled(enabled);
......
353 369
		}
354 370
	}
355 371

  
372
	/**
373
	 * Controla la alternatividad de colores en la tabla.
374
	 *
375
	 * @return Cadena con el color de la fila siguiente.
376
	 */
377
	private String getColor() {
378
		String color = (rowColor ? bgColor0 : bgColor1);
379
		rowColor = !rowColor;
380
		return color;
381
	}
382
	
383
	/**
384
	 * Obtiene una entrada de la tabla en formato HTML a partir de una propiedad,
385
	 * un valor y un color.
386
	 *
387
	 * @param prop
388
	 *          Nombre de la propiedad
389
	 * @param value
390
	 *          Valor
391
	 * @param color
392
	 *          Color
393
	 *
394
	 * @return Entrada HTML de la tabla
395
	 */
396
	private String setHTMLBasicProperty(String prop, String value) {
397
		String content = "<tr valign=\"top\">";
398
		if (prop != null)
399
			content += "<td bgcolor=" + bgColor4 + "align=\"right\" width=\"140\"><font face=\"Arial\" size=\"3\">" + prop + ":&nbsp;</font></td>";
400
		content += "<td bgcolor=" + getColor() + "align=\"left\"><font face=\"Arial\" size=\"3\">" + value + "</font></td>";
401
		content += "</tr>";
402

  
403
		return content;
404
	}
405

  
406
	/**
407
	 * Obtiene una cabecera de tabla en formato HTML a partir de un titulo.
408
	 *
409
	 * @param title
410
	 *          Nombre del titulo
411
	 * @param colspan
412
	 *          Numero de celdas que ocupara el titulo
413
	 *
414
	 * @return Entrada HTML del titulo
415
	 */
416
	private String setHTMLTitleTable(String title, int colspan) {
417
		return
418
			"<tr valign=\"middle\" >" +
419
			"<td bgcolor=" + bgColor3 + " align=\"center\" colspan=\"" + colspan + "\"><font face=\"Arial\" size=\"3\"><b> " + title + "</b></font></td>" +
420
			"</tr>";
421
	}
422

  
423
	/**
424
	 * Obtiene una cabecera de tabla en formato HTML a partir de un titulo.
425
	 *
426
	 * @param content
427
	 *          Codigo HTML de las filas que componen la tabla.
428
	 *
429
	 * @return Entrada HTML de la tabla completa
430
	 */
431
	private String setHTMLTable(String content) {
432
		return "<table cellpadding=\"0\" cellspacing=\"0\" align=\"center\" width=\"100%\">" + content + "</table>";
433
	}
434

  
435
	
356 436
	/*
357 437
	 * (non-Javadoc)
358 438
	 * @see org.gvsig.gui.beans.panelGroup.panels.AbstractPanel#setReference(java.lang.Object)
......
392 472
			}
393 473
		}
394 474
		
475
		refreshHTMLStatistics();
395 476
		saveStatus();
396 477
		setValuesFromPanelToGridTransparency();
397 478
	}
479
	
480
	/**
481
	 * Refresca el HTML del cuadro de texto de las estadisticas de todas las capas
482
	 */
483
	private void refreshHTMLStatistics() {
484
		String html = "";
485
		DatasetStatistics statistics = ((FLyrRasterSE) fLayer).getDataSource().getStatistics();
486
		statistics.loadStatisticsFromRmf();
487
		if (statistics.isCalculated()) {
488
			double[] maxRGB = statistics.getMaxRGB();
489
			double[] max = statistics.getMax();
490
			double[] minRGB = statistics.getMinRGB();
491
			double[] min = statistics.getMin();
492
			double[] variance = statistics.getVariance();
493
			double[] mean = statistics.getMean();
494
			
495
			for (int i=0; i<max.length; i++) {
496
				html += setHTMLTitleTable(RasterToolsUtil.getText(this, "band") + " " + (i + 1), 2);
497
				html += setHTMLBasicProperty(RasterToolsUtil.getText(this, "minimo"), Double.valueOf(min[i]).toString());
498
				html += setHTMLBasicProperty(RasterToolsUtil.getText(this, "maximo"), Double.valueOf(max[i]).toString());
499
				html += setHTMLBasicProperty(RasterToolsUtil.getText(this, "minimoRGB"), Double.valueOf(minRGB[i]).toString());
500
				html += setHTMLBasicProperty(RasterToolsUtil.getText(this, "maximoRGB"), Double.valueOf(maxRGB[i]).toString());
501
				html += setHTMLBasicProperty(RasterToolsUtil.getText(this, "media"), Double.valueOf(mean[i]).toString());
502
				html += setHTMLBasicProperty(RasterToolsUtil.getText(this, "varianza"), Double.valueOf(variance[i]).toString());
503
			}
504
			html = setHTMLTable(html);
505
		} else {
506
			html += setHTMLTitleTable("Estadisticas no calculadas", 2);
507
			html = setHTMLTable(html);
508
		}
509
		getJEditorPane().setText(html);
510
		getJEditorPane().setCaretPosition(0);
511
	}
512
	
513
	/**
514
	 * This method initializes jScrollPane
515
	 *
516
	 * @return javax.swing.JScrollPane
517
	 */
518
	private JScrollPane getJScrollPane() {
519
		if (jScrollPane == null) {
520
			jScrollPane = new JScrollPane();
521
			jScrollPane.setViewportView(getJEditorPane());
522
		}
523
		return jScrollPane;
524
	}
525
	
526
	/**
527
	 * This method initializes jEditorPane
528
	 *
529
	 * @return javax.swing.JEditorPane
530
	 */
531
	private JEditorPane getJEditorPane() {
532
		if (jEditorPane == null) {
533
			jEditorPane = new JEditorPane();
534
			jEditorPane.setEditable(false);
535
			jEditorPane.setContentType("text/html");
536
		}
537
		return jEditorPane;
538
	}
398 539

  
399 540
	/*
400 541
	 * (non-Javadoc)
......
529 670
		RefreshValues(noDataPanel);
530 671
	}
531 672

  
673
	/*
674
	 * (non-Javadoc)
675
	 * @see org.gvsig.raster.IProcessActions#end(java.lang.Object)
676
	 */
677
	public void end(Object param) {
678
		refreshHTMLStatistics();
679
	}
680

  
532 681
	public void selected() {}
682
	public void interrupted() {}
533 683
}

Also available in: Unified diff