Revision 12504 trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/colortable/panels/ColorTTable.java

View differences:

ColorTTable.java
26 26
import org.gvsig.gui.beans.table.TableContainer;
27 27
import org.gvsig.gui.beans.table.exceptions.NotInitializeException;
28 28

  
29
import com.iver.andami.PluginServices;
29 30
/**
30 31
 *
31 32
 * @version 27/06/2007
......
33 34
 */
34 35
public class ColorTTable extends JPanel {
35 36
	private static final long serialVersionUID = -6971866166164473789L;
36
	private TableContainer table = null;
37
	private TableContainer tableContainer = null;
37 38

  
38 39
	public ColorTTable() {
39 40
		initialize();
40 41
	}
41 42

  
42 43
	private void initialize() {
43
		String[] columnNames = { "Bot?n", "columna2", "columna3", "columna 4", "col5" };
44
		int[] columnWidths = { 54, 114, 94, 114, 60 };
45
		table = new TableContainer(columnNames, columnWidths);
46
		table.setModel("TableButtonModel");
47
		table.initialize();
44
		setLayout(new BorderLayout());
45
		add(getTableContainer(), BorderLayout.CENTER);
46
	}
48 47

  
49
		Object[] row = { Color.GREEN, "texto 0", "texto 0", "texto 0", "125" };
50
		Object[] row1 = { Color.BLUE, "texto 1", "texto 1", "texto 1", "255" };
51
		Object[] row2 = { Color.RED, "texto 2", "texto 2", "texto 2", "80" };
48
	/**
49
	 * Borra todas las filas de la tabla.
50
	 */
51
	public void clearTable() {
52 52
		try {
53
			table.addRow(row);
54

  
55
			table.addRow(row1);
56
			table.addRow(row2);
53
			getTableContainer().removeAllRows();
57 54
		} catch (NotInitializeException e) {
58 55
			e.printStackTrace();
59 56
		}
57
	}
60 58

  
61
		setLayout(new BorderLayout());
62
		add(table, BorderLayout.CENTER);
59
	private String getColorString(Color c) {
60
		return c.getRed() + ", " + c.getGreen() + ", " + c.getBlue();
63 61
	}
62

  
63
	/**
64
	 * A?ade una fila a la tabla asignando el color por par?metro. Este
65
	 * color asignado ser? el que aparezca en el bot?n y en el texto RGB
66
	 * @param color
67
	 */
68
	public void addRowToTable(Color color, String name, Double fromRange, Double toRange, String alpha){
69
		try {
70
			getTableContainer().addRow(new Object[] { color, name, getColorString(color), fromRange, toRange, alpha });
71
		} catch (NotInitializeException e1) {
72
			return;
73
		}
74
	}
75

  
76
	public TableContainer getTableContainer() {
77
		if (tableContainer == null) {
78
			String[] columnNames = {PluginServices.getText(this, "selec"), PluginServices.getText(this, "clase"), "RGB", PluginServices.getText(this, "valor"), PluginServices.getText(this, "hasta"), PluginServices.getText(this, "alpha")};
79
			int[] columnWidths = {50, 90, 94, 95, 95, 65};
80
			tableContainer = new TableContainer(columnNames, columnWidths);
81
			tableContainer.setModel("TableColorModel");
82
			tableContainer.initialize();
83
		}
84
		return tableContainer;
85
	}
64 86
}

Also available in: Unified diff