Revision 12821

View differences:

trunk/extensions/extRasterTools-SE/src-test-ui/org/gvsig/rastertools/colortableJaume/TestColorTablePanel.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 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.colortableJaume;
20

  
21
import java.awt.Component;
22
import java.io.File;
23
import java.util.ArrayList;
24

  
25
import javax.swing.JComboBox;
26
import javax.swing.JFrame;
27
import javax.swing.JList;
28
import javax.swing.ListCellRenderer;
29

  
30
import org.gvsig.gui.beans.listview.ListViewItem;
31
import org.gvsig.raster.datastruct.ColorTable;
32
import org.gvsig.rastertools.colortable.panels.PalettePersistence;
33
import org.gvsig.rastertools.colortable.ui.ColorTableIconPainter;
34
/**
35
 *
36
 * @version 17/04/2007
37
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
38
 */
39
public class TestColorTablePanel {
40
	private JFrame      frame        = new JFrame();
41
	private JComboBox   jComboBox    = null;
42

  
43
	private String palettesPath = System.getProperty("user.home") +
44
	File.separator +
45
	"gvSIG"; // PluginServices.getArguments()[0];
46

  
47
	public TestColorTablePanel() {
48
		super();
49
		initialize();
50
	}
51

  
52
	public static void main(String[] args){
53
		new TestColorTablePanel();
54
	}
55

  
56
	private void initialize() {
57
		jComboBox = new JComboBox();
58

  
59
		ArrayList fileList = PalettePersistence.getPaletteFileList(palettesPath);
60

  
61
		for (int i = 0; i < fileList.size(); i++) {
62
			ArrayList paletteItems = new ArrayList();
63
			String paletteName = PalettePersistence.loadPalette(palettesPath, (String) fileList.get(i), paletteItems);
64

  
65
			if (paletteItems.size() <= 0)
66
				continue;
67

  
68
			ColorTable colorTable = new ColorTable();
69
			colorTable.setName(paletteName);
70
			colorTable.createPaletteFromColorItems(paletteItems, true);
71
			colorTable.setInterpolated(true);
72

  
73
			ListViewItem item = new ListViewItem(new ColorTableIconPainter(colorTable), paletteName);
74
			item.setTag(fileList.get(i));
75
			jComboBox.addItem(item);
76
		}
77

  
78

  
79
		frame.setContentPane(jComboBox);
80
		frame.setSize(new java.awt.Dimension(400, 60));
81
		frame.setResizable(true);
82
		frame.setTitle("Tablas de color");
83
		frame.setVisible(true);
84
		frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
85

  
86
		jComboBox.setRenderer(new ListCellRenderer() {
87
			public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
88
				PaintItem paintItem = new PaintItem((ListViewItem) value, isSelected);
89
				return paintItem;
90
			}
91
		});
92
	}
93
}
0 94

  
trunk/extensions/extRasterTools-SE/src-test-ui/org/gvsig/rastertools/colortableJaume/PaintItem.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.colortableJaume;
20

  
21
import java.awt.Color;
22
import java.awt.Dimension;
23
import java.awt.FontMetrics;
24
import java.awt.GradientPaint;
25
import java.awt.Graphics;
26
import java.awt.Graphics2D;
27
import java.awt.Rectangle;
28

  
29
import javax.swing.JComponent;
30

  
31
import org.gvsig.gui.beans.listview.ListViewItem;
32
/**
33
 *
34
 * @version 17/04/2007
35
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
36
 */
37
public class PaintItem extends JComponent {
38
	private static final long serialVersionUID = -6448740563809113949L;
39
	private ListViewItem listViewItem = null;
40
	private boolean isSelected = false;
41

  
42
	public PaintItem(ListViewItem value, boolean isSelected) {
43
		listViewItem = value;
44
		this.isSelected = isSelected;
45

  
46
		setSize(getWidth(), 19);
47
		setPreferredSize(new Dimension(getWidth(), 19));
48
	}
49

  
50
	public void paintComponent(Graphics g) {
51
		Graphics2D g2 = (Graphics2D) g;
52
		if (isSelected) {
53
			Color color1 = new Color(89, 153, 229);
54
			Color color2 = new Color(31, 92, 207);
55
			g2.setPaint(new GradientPaint(0, 1, color1, 0, getHeight() - 1, color2, false));
56
			g2.fillRect(0, 1, getWidth(), getHeight() - 1);
57
			g2.setColor(new Color(61, 123, 218));
58
			g2.drawLine(0, 0, getWidth(), 0);
59
			g2.setColor(Color.white);
60
		} else {
61
			g2.setColor(Color.white);
62
			g2.fillRect(0, 0, getWidth(), getHeight());
63
			g2.setColor(Color.black);
64
		}
65

  
66
		Rectangle bounds = getBounds();
67

  
68
		FontMetrics fm = g2.getFontMetrics();
69
		int upper = (bounds.height + fm.getHeight()) / 2 - fm.getDescent();
70

  
71
		g2.setClip(bounds.x, 0, bounds.width, bounds.height);
72
		g2.drawString(listViewItem.getName(), bounds.width - 146, upper);
73

  
74
		g2.setClip(bounds.x, 0, bounds.width - 150, bounds.height);
75

  
76
		listViewItem.getIcon().paint((Graphics2D) g2, isSelected);
77
	}
78
}
0 79

  
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/colortable/ui/ColorTableIconPainter.java
21 21
import java.awt.Color;
22 22
import java.awt.Graphics2D;
23 23
import java.awt.Rectangle;
24
import java.awt.Shape;
25 24
import java.util.ArrayList;
26 25

  
27 26
import org.gvsig.gui.beans.listview.IIconPaint;
......
57 56
	}
58 57

  
59 58
	public void paint(Graphics2D g, boolean isSelected) {
60
		Shape clip = g.getClip();
61
		Rectangle area = clip.getBounds();
59
		Rectangle area = g.getClipBounds();
62 60

  
63 61
		int x1 = area.x;
64 62
		int x2 = area.x + area.width - 1;
63

  
65 64
		if (colorTable.getColorItems().size()>=1) {
66 65
			double min = ((ColorItem) colorTable.getColorItems().get(0)).getValue();
67 66
			double max = ((ColorItem) colorTable.getColorItems().get(colorTable.getColorItems().size()-1)).getValue();
......
70 69

  
71 70
				byte[] col3 = colorTable.getRGBByBand(pos);
72 71
				g.setColor(new Color(col3[0] & 0xff, col3[1] & 0xff, col3[2] & 0xff));
73
				g.drawLine(i, area.y, i, area.height);
72
				g.drawLine(i, area.y, i, area.y + area.height);
74 73
			}
75 74
		} else {
76 75
			g.setColor(new Color(224, 224, 224));

Also available in: Unified diff