Revision 12488

View differences:

trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/colortable/ui/ColorTablePanel.java
21 21
import java.awt.BorderLayout;
22 22
import java.awt.Color;
23 23
import java.awt.Dimension;
24
import java.awt.event.ActionEvent;
25
import java.awt.event.ActionListener;
24 26
import java.io.File;
25 27
import java.util.ArrayList;
26 28

  
29
import javax.swing.JCheckBox;
27 30
import javax.swing.JLabel;
28 31
import javax.swing.JPanel;
29 32
import javax.swing.JScrollPane;
33
import javax.swing.JSplitPane;
30 34
import javax.swing.JTabbedPane;
31 35
import javax.swing.JTextField;
36
import javax.swing.event.ListSelectionEvent;
37
import javax.swing.event.ListSelectionListener;
32 38

  
33 39
import org.gvsig.gui.beans.buttonscolor.ButtonColor;
34 40
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
35 41
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel;
36 42
import org.gvsig.gui.beans.graphic.listview.ListViewComponent;
37 43
import org.gvsig.gui.beans.graphic.listview.ListViewItem;
38
import org.gvsig.gui.beans.graphic.listview.RampPainter;
39 44
import org.gvsig.gui.beans.imagenavigator.ImageNavigator;
40 45
import org.gvsig.rastertools.colortable.ColorTableListener;
41 46
import org.gvsig.rastertools.colortable.panels.ColorTInterpolated;
......
51 56
 * @version 26/06/2007
52 57
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
53 58
 */
54
public class ColorTablePanel extends DefaultButtonsPanel {
59
public class ColorTablePanel extends DefaultButtonsPanel implements ListSelectionListener, ActionListener {
55 60
	private static final long  serialVersionUID   = 6028780107787443656L;
56 61

  
57 62
	private ImageNavigator     imageNavigator     = null;
......
62 67
	private ColorTInterpolated colorTInterpolated = null;
63 68
	private ListViewComponent  listViewComponent  = null;
64 69
	private JPanel             jPNoData           = null;
70
	JCheckBox                  interpolated       = null;
65 71

  
72
	private String palettesPath = System.getProperty("user.home") +
73
		File.separator +
74
		"gvSIG" + // PluginServices.getArguments()[0] +
75
		File.separator + "palettes.xml";
76

  
66 77
	/**
67 78
	 * Construir un nuevo ColorTablePanel
68 79
	 */
......
80 91
	private void initialize() {
81 92
		setLayout(new BorderLayout(8, 8));
82 93

  
83
		add(getJTabbedPane(), BorderLayout.CENTER);
84
		add(getPPreview(), BorderLayout.EAST);
85
		add(getJPNoData(), BorderLayout.SOUTH);
86
		ArrayList items = PalettePersistence.getPaletteList(
87
				System.getProperty("user.home") +
88
				File.separator +
89
				"gvSIG" + //PluginServices.getArguments()[0] +
90
				File.separator + "palettes.xml");
94
		JPanel panelLeft = new JPanel();
95
		panelLeft.setLayout(new BorderLayout(8, 8));
96
		panelLeft.add(getJTabbedPane(), BorderLayout.CENTER);
97
		panelLeft.add(getJPNoData(), BorderLayout.SOUTH);
91 98

  
99
		JSplitPane jSplitPane1 = new JSplitPane();
100
		jSplitPane1.setLeftComponent(panelLeft);
101
		jSplitPane1.setRightComponent(getPPreview());
102
		jSplitPane1.setResizeWeight(1.0);
103
		jSplitPane1.setContinuousLayout(true);
104
		jSplitPane1.setBorder(null);
105

  
106
		add(jSplitPane1, BorderLayout.CENTER);
107

  
108
		ArrayList items = PalettePersistence.getPaletteList(palettesPath);
109

  
92 110
		for (int i = 0; i < items.size(); i++) {
93
			ListViewItem item = new ListViewItem(new RampPainter(), (String) items.get(i));
111
			ArrayList paletteItems = new ArrayList();
112
			Boolean interpolate = PalettePersistence.loadPalette(palettesPath, (String) items.get(i), paletteItems);
113

  
114
			ListViewItem item = new ListViewItem(new ColorTableIconPainter((String) items.get(i), paletteItems, interpolate), (String) items.get(i));
94 115
			getListViewComponent().addItem(item);
95 116
		}
96 117

  
......
105 126
			jPNoData.add(buttonColor, null);
106 127
			jPNoData.add(new JLabel("Value:"), null);
107 128
			jPNoData.add(getValueNoData(), null);
129

  
130
			interpolated = new JCheckBox("Interpolado");
131
			interpolated.setSelected(true);
132
			interpolated.addActionListener(this);
133
			jPNoData.add(interpolated, null);
108 134
		}
109 135
		return jPNoData;
110 136
	}
......
188 214

  
189 215
			JScrollPane jScrollPane = new JScrollPane();
190 216
			jScrollPane.setViewportView(getListViewComponent());
217
			jScrollPane.setAutoscrolls(true);
191 218

  
192 219
			jsubpanel4.add(jScrollPane, BorderLayout.CENTER);
193 220
			jsubpanel3.add(jsubpanel4, BorderLayout.CENTER);
......
230 257
	public ListViewComponent getListViewComponent() {
231 258
		if (listViewComponent == null) {
232 259
			listViewComponent = new ListViewComponent();
260
			listViewComponent.addListSelectionListener(this);
233 261
		}
234 262
		return listViewComponent;
235 263
	}
264

  
265
	public void valueChanged(ListSelectionEvent e) {
266
		System.out.println(listViewComponent.getSelectedValue().getName());
267
//		PalettePersistence.loadPalette(palettesPath, listViewComponent.getSelectedValue().getName());
268
	}
269

  
270
	public void actionPerformed(ActionEvent e) {
271
		if (e.getSource() == interpolated) {
272
			for (int i = 0; i < getListViewComponent().getItems().size(); i++) {
273
				((ColorTableIconPainter) ((ListViewItem) getListViewComponent().getItems().get(i)).getIcon()).setInterpolated(interpolated.isSelected());
274
			}
275
			getListViewComponent().repaint();
276
		}
277
	}
236 278
}
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/colortable/ui/ColorTableIconPainter.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.rastertools.colortable.ui;
20

  
21
import java.awt.Color;
22
import java.awt.Graphics2D;
23
import java.awt.Rectangle;
24
import java.awt.Shape;
25
import java.util.ArrayList;
26

  
27
import org.gvsig.gui.beans.graphic.listview.IIconPaint;
28
import org.gvsig.raster.datastruct.ColorItem;
29
import org.gvsig.raster.datastruct.ColorTable;
30
/**
31
 *
32
 * @version 29/06/2007
33
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
34
 */
35
public class ColorTableIconPainter implements IIconPaint {
36
	private ColorTable colorTable;
37
	private ArrayList colorItems;
38

  
39
	public ColorTableIconPainter(String name, ArrayList colorItems, Boolean interpolate) {
40
		colorTable = new ColorTable();
41
		this.colorItems = colorItems;
42
		colorTable.setName(name);
43
		colorTable.createPaletteFromColorItems(colorItems);
44
		setInterpolated(true);
45
	}
46

  
47
	public void setInterpolated(boolean value) {
48
		colorTable.setInterpolated(value);
49
	}
50

  
51
	public void paint(Graphics2D g, boolean isSelected) {
52
		Shape clip = g.getClip();
53
		Rectangle area = clip.getBounds();
54

  
55
		int x1 = area.x;
56
		int x2 = area.x + area.width - 1;
57
		if (colorItems.size()>=1) {
58
			double min = ((ColorItem) colorItems.get(0)).getValue();
59
			double max = ((ColorItem) colorItems.get(colorItems.size()-1)).getValue();
60
			for (int i = area.x; i < (area.x + area.width); i++) {
61
				double pos = min + (((max - min) * (i - area.x)) / (area.width - 2));
62

  
63
				byte[] col3 = colorTable.getRGBByBand(pos);
64
				g.setColor(new Color(col3[0] & 0xff, col3[1] & 0xff, col3[2] & 0xff));
65
				g.drawLine(i, area.y, i, area.height);
66
			}
67
		} else {
68
			g.setColor(new Color(224, 224, 224));
69
			g.fillRect(x1, area.y, x2 - x1, area.height - 1);
70
		}
71
		if (isSelected)
72
			g.setColor(Color.black);
73
		else
74
			g.setColor(new Color(96, 96, 96));
75
		g.drawRect(x1, area.y, x2 - x1, area.height - 1);
76
	}
77
}
0 78

  
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/colortable/panels/PalettePersistence.java
18 18
 */
19 19
package org.gvsig.rastertools.colortable.panels;
20 20

  
21
import java.awt.Color;
21 22
import java.io.File;
22 23
import java.io.FileInputStream;
23 24
import java.io.FileNotFoundException;
24 25
import java.io.IOException;
25 26
import java.util.ArrayList;
26 27

  
28
import org.gvsig.raster.datastruct.ColorItem;
27 29
import org.kxml2.io.KXmlParser;
28 30
import org.xmlpull.v1.XmlPullParserException;
29 31
/**
......
82 84
	 *
83 85
	 *  @param palettesPath Camino al fichero de paletas predefinidas.
84 86
	 *  @param paletteName Nombre de paleta a cargar desde el fichero xml.
85
	 *
86
	 *//*
87
	public void loadPalette(String palettesPath, String paletteName){
87
	 */
88
	public static Boolean loadPalette(String palettesPath, String paletteName, ArrayList items) {
88 89

  
90
		items.clear();
91

  
89 92
		File palettesFile = new File(palettesPath);
90
		if(!palettesFile.exists())
91
			return;
93
		if (!palettesFile.exists())
94
			return null;
92 95

  
93 96
		try {
94 97
			KXmlParser parser = new KXmlParser();
......
103 106
			parser.require(KXmlParser.END_TAG, null, "palette_list");
104 107
			tag = parser.nextTag();
105 108

  
106
			while (tag == KXmlParser.START_TAG){
109
			while (tag == KXmlParser.START_TAG) {
107 110
				parser.require(KXmlParser.START_TAG, null, "palette");
108
				if(parser.getAttributeCount()==2)
109
					if (parser.getAttributeValue(0).equals(paletteName)){
111
				if (parser.getAttributeCount() == 2) {
112
					if (parser.getAttributeValue(0).equals(paletteName)) {
110 113
						boolean interpolate = Boolean.valueOf(parser.getAttributeValue(1)).booleanValue();
111 114
						tag = parser.nextTag();
112 115
						parser.require(KXmlParser.START_TAG, null, "table");
113 116
						tag = parser.nextTag();
114
						try {
115
							panel.getPTable().removeAllRows();
116
						} catch (NotInitializeException e1) {
117
							e1.printStackTrace();
118
						}
119 117

  
120 118
						ArrayList rows = new ArrayList();
121 119

  
122
						while(tag == KXmlParser.START_TAG){
120
						while (tag == KXmlParser.START_TAG) {
123 121
							parser.require(KXmlParser.START_TAG, null, "entry");
124
							if (parser.getAttributeCount()==3){
122
							if (parser.getAttributeCount() == 3) {
125 123

  
126
								String rgb = parser.getAttributeValue(1).substring(parser.getAttributeValue(1).indexOf(",")+1,
127
										parser.getAttributeValue(1).length());
124
								String rgb = parser.getAttributeValue(1).substring(parser.getAttributeValue(1).indexOf(",") + 1, parser.getAttributeValue(1).length());
128 125

  
129
								int a = Integer.valueOf(parser.getAttributeValue(1).substring(0,parser.getAttributeValue(1).indexOf(","))).intValue();
130
								int r= Integer.valueOf(rgb.substring(0,rgb.indexOf(","))).intValue();
131
								int g=Integer.valueOf(rgb.substring(rgb.indexOf(",")+1,rgb.lastIndexOf(","))).intValue();
132
								int b=Integer.valueOf(rgb.substring(rgb.lastIndexOf(",")+1,rgb.length())).intValue();
126
								int a = Integer.valueOf(parser.getAttributeValue(1).substring(0, parser.getAttributeValue(1).indexOf(","))).intValue();
127
								int r = Integer.valueOf(rgb.substring(0, rgb.indexOf(","))).intValue();
128
								int g = Integer.valueOf(rgb.substring(rgb.indexOf(",") + 1, rgb.lastIndexOf(","))).intValue();
129
								int b = Integer.valueOf(rgb.substring(rgb.lastIndexOf(",") + 1, rgb.length())).intValue();
133 130

  
134
								//No a?ado filas a la tabla hasta que no se ha leido correctamente la paleta completa:
135
								Object row[] = {new Color(r,g,b), parser.getAttributeValue(0), parser.getAttributeValue(2), String.valueOf(a)};
131
								// No a?ado filas a la tabla hasta que no se ha leido
132
								// correctamente la paleta completa:
133
								Object row[] = { new Color(r, g, b), parser.getAttributeValue(0), parser.getAttributeValue(2), String.valueOf(a) };
136 134
								rows.add(row);
137 135
							}
138 136
							tag = parser.nextTag();
......
142 140
						parser.require(KXmlParser.END_TAG, null, "table");
143 141

  
144 142
						// Rellenar la tabla con las entradas leidas:
145
						for (int i=0;i<rows.size();i++)
146
							panel.addRowToTable((Color)((Object[])rows.get(i))[0], (String)((Object[])rows.get(i))[1],
147
									(String)((Object[])rows.get(i))[2], (String)((Object[])rows.get(i))[3]);
148
						panel.getCbInterpolar().setSelected(interpolate);
143
						for (int i = 0; i < rows.size(); i++) {
144
							ColorItem colorItem = new ColorItem();
145
							Color color = (Color) ((Object[]) rows.get(i))[0];
146
							colorItem.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), Integer.parseInt((String) ((Object[]) rows.get(i))[3])));
147
							colorItem.setValue(Double.parseDouble((String) ((Object[]) rows.get(i))[2]));
148
							items.add(colorItem);
149
						}
149 150
						fileInputStream.close();
150
						return;
151
						return Boolean.valueOf(interpolate);
152
					}
151 153
				}
152 154
				parser.skipSubTree();
153 155
				parser.require(KXmlParser.END_TAG, null, "palette");
......
155 157
			}
156 158

  
157 159
			parser.require(KXmlParser.END_TAG, null, "palettes");
158
			panel.deleteAllRows();
160
			// panel.deleteAllRows();
159 161
			fileInputStream.close();
160
			return;
162
			return null;
161 163

  
162
		}catch (FileNotFoundException fnfEx) {
164
		} catch (FileNotFoundException fnfEx) {
163 165
			fnfEx.printStackTrace();
164
		}catch (XmlPullParserException xmlEx) {
166
		} catch (XmlPullParserException xmlEx) {
165 167
			System.out.println("El fichero de paletas predeterminadas no tiene la estructura correcta:\n	" + xmlEx.getMessage());
166
		}catch (IOException e) {
168
		} catch (IOException e) {
167 169
		}
168
	}	*/
170
		return null;
171
	}
169 172
}
trunk/extensions/extRasterTools-SE/src/org/gvsig/fmap/raster/legend/ColorTableLegend.java
20 20

  
21 21
import java.awt.Color;
22 22

  
23
import org.gvsig.raster.datastruct.ColorItem;
23 24
import org.gvsig.raster.datastruct.ColorTable;
24 25

  
25 26
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
......
32 33

  
33 34
/**
34 35
 * Leyenda para tablas de color aplicadas a un raster.
35
 * 
36
 *
36 37
 * @version 27/06/2007
37 38
 * @author Nacho Brodin (nachobrodin@gmail.com)
38 39
 *
......
41 42

  
42 43
	ISymbol[] symbols = null;
43 44
	String[] desc = null;
44
	
45

  
45 46
	/**
46 47
	 * Crea una leyenda de tipo ColorTableLegend a partir de un objeto ColorTable
47 48
	 * @param colorTable
......
50 51
	public static ColorTableLegend createLegend(ColorTable colorTable) {
51 52
		SimpleLineSymbol line = new SimpleLineSymbol();
52 53
		line.setLineColor(Color.BLACK);
53
		ISymbol[] symbol = new ISymbol[colorTable.getColorTable().length];
54
		String[] desc = new String[colorTable.getColorTable().length];
55
		
56
		for (int i = 0; i < colorTable.getColorTable().length; i++) {
54
		ISymbol[] symbol = new ISymbol[colorTable.getColorItems().size()];
55
		String[] desc = new String[colorTable.getColorItems().size()];
56

  
57
		for (int i = 0; i < colorTable.getColorItems().size(); i++) {
57 58
			SimpleFillSymbol s = new SimpleFillSymbol();
58 59
			s.setOutline(line);
59
			byte[][] color = colorTable.getColorTableByBand();
60
			s.setFillColor(new Color(color[i][0] & 0xff, color[i][1] & 0xff, color[i][2] & 0xff));
61
			if(colorTable.getIntRange() != null)
62
				if(i < colorTable.getColorTable().length - 1)
63
					desc[i] = "[" + colorTable.getIntRange()[i] + " , " + colorTable.getIntRange()[i + 1] + "[ " + colorTable.getNameClass()[i];
64
				else
65
					desc[i] = "[" + colorTable.getIntRange()[i] + "] " + colorTable.getNameClass()[i];
66
			if(colorTable.getDoubleRange() != null)
67
				if(i < colorTable.getColorTable().length - 1)
68
					desc[i] = "[" + colorTable.getDoubleRange()[i] + " , " + colorTable.getDoubleRange()[i + 1] + "[ " + colorTable.getNameClass()[i];
69
				else
70
					desc[i] = "[" + colorTable.getDoubleRange()[i] + "] " + colorTable.getNameClass()[i];
71
				
60
			s.setFillColor(((ColorItem) colorTable.getColorItems().get(i)).getColor());
61
			if (i < (colorTable.getColorItems().size() - 1))
62
				desc[i] = "[" + ((ColorItem) colorTable.getColorItems().get(i)).getValue() + " , " + ((ColorItem) colorTable.getColorItems().get(i + 1)).getValue() + "[ " + ((ColorItem) colorTable.getColorItems().get(i)).getNameClass();
63
			else
64
				desc[i] = "[" + ((ColorItem) colorTable.getColorItems().get(i)).getValue() + "] " + ((ColorItem) colorTable.getColorItems().get(i)).getNameClass();
72 65
			symbol[i] = s;
73 66
		}
74
		
67

  
75 68
		return new ColorTableLegend(symbol, desc);
76 69
	}
77
	
70

  
78 71
	/**
79 72
	 * Leyenda para tablas de color raster.
80 73
	 * @param s Lista de simbolos
......
84 77
		symbols = s;
85 78
		desc = d;
86 79
	}
87
	
80

  
88 81
	/*
89 82
	 * (non-Javadoc)
90 83
	 * @see com.iver.cit.gvsig.fmap.rendering.IClassifiedLegend#getDescriptions()
......
136 129
	public XMLEntity getXMLEntity() {
137 130
		return null;
138 131
	}
139
	
132

  
140 133
}

Also available in: Unified diff