Revision 12514 trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/colortable/ui/ColorTablePanel.java
ColorTablePanel.java | ||
---|---|---|
26 | 26 |
import java.io.File; |
27 | 27 |
import java.util.ArrayList; |
28 | 28 |
|
29 |
import javax.swing.JButton; |
|
29 | 30 |
import javax.swing.JCheckBox; |
30 | 31 |
import javax.swing.JLabel; |
31 | 32 |
import javax.swing.JPanel; |
32 | 33 |
import javax.swing.JScrollPane; |
33 | 34 |
import javax.swing.JSplitPane; |
34 | 35 |
import javax.swing.JTabbedPane; |
36 |
import javax.swing.JTable; |
|
35 | 37 |
import javax.swing.JTextField; |
36 | 38 |
import javax.swing.event.ListSelectionEvent; |
37 | 39 |
import javax.swing.event.ListSelectionListener; |
40 |
import javax.swing.event.TableModelEvent; |
|
41 |
import javax.swing.event.TableModelListener; |
|
38 | 42 |
|
39 | 43 |
import org.gvsig.gui.beans.buttonscolor.ButtonColor; |
40 | 44 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
... | ... | |
42 | 46 |
import org.gvsig.gui.beans.graphic.listview.ListViewComponent; |
43 | 47 |
import org.gvsig.gui.beans.graphic.listview.ListViewItem; |
44 | 48 |
import org.gvsig.gui.beans.imagenavigator.ImageNavigator; |
49 |
import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
|
50 |
import org.gvsig.gui.beans.table.models.TableColorModel; |
|
45 | 51 |
import org.gvsig.raster.datastruct.ColorItem; |
46 | 52 |
import org.gvsig.rastertools.colortable.ColorTableListener; |
47 | 53 |
import org.gvsig.rastertools.colortable.panels.ColorTInterpolated; |
... | ... | |
57 | 63 |
* @version 26/06/2007 |
58 | 64 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es) |
59 | 65 |
*/ |
60 |
public class ColorTablePanel extends DefaultButtonsPanel implements ListSelectionListener, ActionListener { |
|
66 |
public class ColorTablePanel extends DefaultButtonsPanel implements ListSelectionListener, ActionListener, TableModelListener {
|
|
61 | 67 |
private static final long serialVersionUID = 6028780107787443656L; |
62 | 68 |
|
63 | 69 |
private ImageNavigator imageNavigator = null; |
... | ... | |
69 | 75 |
private ListViewComponent listViewComponent = null; |
70 | 76 |
private JPanel jPNoData = null; |
71 | 77 |
JCheckBox interpolated = null; |
78 |
boolean active = false; |
|
72 | 79 |
|
73 | 80 |
private String palettesPath = System.getProperty("user.home") + |
74 | 81 |
File.separator + |
... | ... | |
158 | 165 |
private ColorTTable getColorTTable() { |
159 | 166 |
if (colorTTable == null) { |
160 | 167 |
colorTTable = new ColorTTable(); |
168 |
colorTTable.getTableContainer().getTable().getJTable().getModel().addTableModelListener(this); |
|
161 | 169 |
} |
162 | 170 |
return colorTTable; |
163 | 171 |
} |
... | ... | |
264 | 272 |
} |
265 | 273 |
|
266 | 274 |
public void valueChanged(ListSelectionEvent e) { |
267 |
// System.out.println(listViewComponent.getSelectedValue().getName());
|
|
275 |
active = false;
|
|
268 | 276 |
ArrayList colorItems = ((ColorTableIconPainter) listViewComponent.getSelectedValue().getIcon()).getColorItems(); |
269 | 277 |
getColorTTable().clearTable(); |
270 | 278 |
for (int i=0; i<colorItems.size(); i++) { |
... | ... | |
274 | 282 |
toRange = Double.valueOf(((ColorItem) colorItems.get(i + 1)).getValue()); |
275 | 283 |
getColorTTable().addRowToTable(c1.getColor(), c1.getNameClass(), Double.valueOf(c1.getValue()), toRange, c1.getColor().getAlpha() + ""); |
276 | 284 |
} |
285 |
active = true; |
|
277 | 286 |
} |
278 | 287 |
|
279 | 288 |
public void actionPerformed(ActionEvent e) { |
... | ... | |
284 | 293 |
getListViewComponent().repaint(); |
285 | 294 |
} |
286 | 295 |
} |
296 |
|
|
297 |
/** |
|
298 |
* Convierte la tabla en un array de objetos para poder crear con el el objeto Palette |
|
299 |
* @return |
|
300 |
* @throws NotInitializeException |
|
301 |
*/ |
|
302 |
public ArrayList getTablePalette() { |
|
303 |
ArrayList arrayList = new ArrayList(); |
|
304 |
JTable jTable = getColorTTable().getTableContainer().getTable().getJTable(); |
|
305 |
TableColorModel model = (TableColorModel) jTable.getModel(); |
|
306 |
for (int iRow = 0; iRow < jTable.getRowCount(); iRow++) { |
|
307 |
Color rgb = (Color) model.getValueAt(iRow, 0); |
|
308 |
ColorItem colorItem = new ColorItem(); |
|
309 |
colorItem.setColor(new Color( |
|
310 |
rgb.getRed(), |
|
311 |
rgb.getGreen(), |
|
312 |
rgb.getBlue(), |
|
313 |
Integer.valueOf((String) model.getValueAt(iRow, 5)).intValue())); |
|
314 |
|
|
315 |
colorItem.setValue(((Double) model.getValueAt(iRow, 3)).doubleValue()); |
|
316 |
// TODO: Hacer algo para conservar el valor de interpolacion |
|
317 |
colorItem.setNameClass((String) model.getValueAt(iRow, 1)); |
|
318 |
arrayList.add(colorItem); |
|
319 |
} |
|
320 |
|
|
321 |
return arrayList; |
|
322 |
} |
|
323 |
|
|
324 |
public void tableChanged(TableModelEvent e) { |
|
325 |
if (!active) |
|
326 |
return; |
|
327 |
System.out.println("a"); |
|
328 |
|
|
329 |
((ColorTableIconPainter) listViewComponent.getSelectedValue().getIcon()).setColorItems(getTablePalette(), interpolated.isSelected()); |
|
330 |
getListViewComponent().repaint(); |
|
331 |
} |
|
287 | 332 |
} |
Also available in: Unified diff