Revision 38371

View differences:

branches/v2_0_0_prep/libraries/libUIComponent/src/org/gvsig/gui/DefaultColorTables.java
1
package org.gvsig.gui;
2

  
3
import java.awt.Color;
4
import java.awt.Graphics2D;
5
import java.awt.Rectangle;
6
import java.util.ArrayList;
7
import java.util.Iterator;
8
import java.util.List;
9

  
10
public class DefaultColorTables implements IColorTables {
11

  
12
	private class DefaultColorTablePaint implements IColorTablePaint {
13

  
14
		private class ColorItem {
15
			Color color = null;
16
			double value =0;
17
			
18
			ColorItem(double value, Color color) {
19
				this.color = color;
20
				this.value = value;
21
			}
22
			
23
			Color getColor() {
24
				return color;
25
			}
26
			
27
			double getValue() {
28
				return value;
29
			}
30
		}
31
		
32
		List<ColorItem> colorItems = null;
33
		
34
		DefaultColorTablePaint() {
35
			this.colorItems = new ArrayList<DefaultColorTables.DefaultColorTablePaint.ColorItem>();
36
			int n = 256;
37
			for( int i=0; i<n; i++) {
38
	                Color color = Color.getHSBColor((float) i / (float) n, 0.85f, 1.0f);
39
	                this.colorItems.add( new ColorItem(i,color));
40
	        }
41

  
42
		}
43
		
44
		public void setInterpolated(boolean value) {
45
			// This method is not supported, ignore it
46
		}
47

  
48
		public Color[] getColors() {
49
			Color[] colors = new Color[colorItems.size()];
50
			for (int i = 0; i < colors.length; i++) {
51
				colors[i] = ((ColorItem) colorItems.get(i)).getColor();
52
			}
53
			return colors;	
54
		}
55

  
56
		public void paint(Graphics2D g, boolean isSelected, Rectangle bounds) {
57
			Rectangle area = bounds;
58
			area.y=0;
59
			area.x=0;
60
			int x1 = area.x;
61
			int x2 = area.x + area.width - 1;
62

  
63
			if( this.colorItems.size() > 0 ) {
64
				double min = colorItems.get(0).getValue();
65
                double max = colorItems.get(colorItems.size() - 1).getValue();
66
                for (int i = area.x; i < (area.x + area.width - 1); i++) {
67
					double pos = min + (((max - min) * (i - area.x)) / (area.width - 2));
68
					g.setColor(this.colorItems.get((int) pos).getColor());
69
					g.drawLine(i, area.y, i, area.y + area.height);
70
				}
71
			} else {
72
				g.setColor(new Color(224, 224, 224));
73
				g.fillRect(x1, area.y, x2 - x1, area.height - 1);
74
			}
75
			if (isSelected) {
76
				g.setColor(Color.black);
77
			} else {
78
				g.setColor(new Color(96, 96, 96));
79
			}
80
			g.drawRect(x1, area.y, x2 - x1, area.height - 1);
81
		}
82

  
83
		public String getTableName() {
84
			return "Default colot table";
85
		}
86
		
87
	}
88
	
89
	private List<IColorTablePaint> colorTables = null;
90
	
91
	public DefaultColorTables() {
92
		this.colorTables = new ArrayList<IColorTables.IColorTablePaint>();
93
		this.colorTables.add(new DefaultColorTablePaint());
94
	}
95
	
96
	public void load(String palettesPath, boolean interpolateValues) {
97
		// DefaultColorTables don't support load of color tables.
98
	}
99

  
100
	public IColorTablePaint get(int i) {
101
		return this.colorTables.get(i);
102
	}
103

  
104
	public int size() {
105
		return this.colorTables.size();
106
	}
107

  
108
	public Iterator iterator() {
109
		return this.colorTables.iterator();
110
	}
111
	
112
}
branches/v2_0_0_prep/libraries/libUIComponent/src/org/gvsig/gui/IColorTables.java
1
package org.gvsig.gui;
2

  
3
import java.awt.Color;
4
import java.awt.Graphics2D;
5
import java.awt.Rectangle;
6
import java.util.Iterator;
7

  
8

  
9
public interface IColorTables {
10

  
11
	public abstract void load(String palettesPath, boolean interpolateValues);
12

  
13
	public abstract IColorTablePaint get(int i);
14

  
15
	public abstract int size();
16

  
17
	public abstract Iterator iterator();
18

  
19
	public interface IColorTablePaint {
20

  
21
		/**
22
		 * Defines if the values are interpolated between them or not.
23
		 *
24
		 * @param value
25
		 */
26
		public abstract void setInterpolated(boolean value);
27

  
28
		public abstract Color[] getColors();
29

  
30
		/**
31
		 * Method to paint the color table
32
		 *
33
		 * @param g
34
		 * @param isSelected
35
		 */
36
		public abstract void paint(Graphics2D g, boolean isSelected,
37
				Rectangle bounds);
38

  
39
		public abstract String getTableName();
40

  
41
	}
42
}
43

  
branches/v2_0_0_prep/libraries/libUIComponent/src/org/gvsig/gui/IColorTablesFactory.java
1
package org.gvsig.gui;
2

  
3
public interface IColorTablesFactory {
4
	public IColorTables createColorTables();
5
}
branches/v2_0_0_prep/libraries/libUIComponent/src/org/gvsig/gui/DefaultColorTablesFactory.java
1
package org.gvsig.gui;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5

  
6
public class DefaultColorTablesFactory implements ColorTablesFactory {
7
	private List<ColorTablePainter> colorTables;
8

  
9
	public DefaultColorTablesFactory() {
10
		this.colorTables = new ArrayList<ColorTablePainter>();
11
		this.colorTables.add(new DefaultColorTablePainter());
12
	}
13
	
14
	public List<ColorTablePainter> createColorTables() {
15
		return this.colorTables;
16
	}
17

  
18
}
0 19

  
branches/v2_0_0_prep/libraries/libUIComponent/src/org/gvsig/gui/ColorTablePainter.java
1
package org.gvsig.gui;
2

  
3
import java.awt.Color;
4
import java.awt.Graphics2D;
5

  
6

  
7
public interface ColorTablePainter {
8

  
9
	public Color[] getColors();
10

  
11
	/**
12
	 * Method to paint the color table
13
	 *
14
	 * @param g
15
	 * @param isSelected
16
	 */
17
	public void paint(Graphics2D g, boolean isSelected);
18

  
19
	public String getTableName();
20
}
21

  
0 22

  
branches/v2_0_0_prep/libraries/libUIComponent/src/org/gvsig/gui/DefaultColorTablePainter.java
1
package org.gvsig.gui;
2

  
3
import java.awt.Color;
4
import java.awt.Graphics2D;
5
import java.awt.Rectangle;
6
import java.util.ArrayList;
7
import java.util.List;
8

  
9
public class DefaultColorTablePainter implements ColorTablePainter {
10
	private class ColorItem {
11
		Color color = null;
12
		double value =0;
13
		
14
		ColorItem(double value, Color color) {
15
			this.color = color;
16
			this.value = value;
17
		}
18
		
19
		Color getColor() {
20
			return color;
21
		}
22
		
23
		double getValue() {
24
			return value;
25
		}
26
	}
27
	
28
	List<ColorItem> colorItems = null;
29
	
30
	DefaultColorTablePainter() {
31
		this.colorItems = new ArrayList<ColorItem>();
32
		int n = 256;
33
		for( int i=0; i<n; i++) {
34
                Color color = Color.getHSBColor((float) i / (float) n, 0.85f, 1.0f);
35
                this.colorItems.add( new ColorItem(i,color));
36
        }
37

  
38
	}
39
	
40
	public Color[] getColors() {
41
		Color[] colors = new Color[colorItems.size()];
42
		for (int i = 0; i < colors.length; i++) {
43
			colors[i] = ((ColorItem) colorItems.get(i)).getColor();
44
		}
45
		return colors;	
46
	}
47

  
48
	public String getTableName() {
49
		return "Default colot table";
50
	}
51

  
52
	public void paint(Graphics2D g, boolean isSelected) {
53
		Rectangle area = g.getClipBounds();
54
		area.y=0;
55
		area.x=0;
56
		int x1 = area.x;
57
		int x2 = area.x + area.width - 1;
58

  
59
		if( this.colorItems.size() > 0 ) {
60
			double min = colorItems.get(0).getValue();
61
            double max = colorItems.get(colorItems.size() - 1).getValue();
62
            for (int i = area.x; i < (area.x + area.width - 1); i++) {
63
				double pos = min + (((max - min) * (i - area.x)) / (area.width - 2));
64
				g.setColor(this.colorItems.get((int) pos).getColor());
65
				g.drawLine(i, area.y, i, area.y + 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
		}
76
		g.drawRect(x1, area.y, x2 - x1, area.height - 1);
77
	}
78

  
79
}
0 80

  
branches/v2_0_0_prep/libraries/libUIComponent/src/org/gvsig/gui/ColorTablesFactory.java
1
package org.gvsig.gui;
2

  
3
import java.util.List;
4

  
5
public interface ColorTablesFactory {
6
	public List<ColorTablePainter> createColorTables();
7
}
0 8

  
branches/v2_0_0_prep/libraries/org.gvsig.symbology/org.gvsig.symbology.swing/org.gvsig.symbology.swing.api/src/main/java/org/gvsig/app/gui/styling/JComboBoxColorScheme.java
57 57
import javax.swing.JList;
58 58
import javax.swing.ListCellRenderer;
59 59

  
60
import org.gvsig.gui.IColorTables;
61
import org.gvsig.gui.IColorTables.IColorTablePaint;
60
import org.gvsig.gui.ColorTablePainter;
62 61
import org.gvsig.i18n.Messages;
63 62
import org.gvsig.symbology.swing.SymbologySwingLocator;
64 63

  
......
80 79
	File.separator +
81 80
	"ColorSchemes";
82 81
//	private boolean interpolated = false;
83
	private List<IColorTablePaint> colorTables = new ArrayList<IColorTablePaint>();
82
	private List<ColorTablePainter> colorTables = new ArrayList<ColorTablePainter>();
84 83

  
85 84
	private ActionListener innerActionUpdateTooltip = new ActionListener() {
86 85
		public void actionPerformed(ActionEvent e) {
87
			IColorTablePaint colorTable = (IColorTablePaint)getSelectedItem();
86
			ColorTablePainter colorTable = (ColorTablePainter)getSelectedItem();
88 87
			if (colorTable != null) {
89 88
				setToolTipText(colorTable.getTableName());
90 89
			} else {
......
103 102
//		interpolated = interpolateValues;
104 103
		setPreferredSize(new Dimension(150, 20));
105 104
		
106
		IColorTables colorTables = SymbologySwingLocator.getSwingManager().createColorTables();
105
		List<ColorTablePainter> colorTables = SymbologySwingLocator.getSwingManager().createColorTables();
107 106
		if(colorTables != null){
108
			colorTables.load(palettesPath, interpolateValues);
109 107
			for (int i=0; i<colorTables.size(); i++) {
110
				IColorTablePaint colorTable = colorTables.get(i);
108
				ColorTablePainter colorTable = colorTables.get(i);
111 109
//				ArrayList array = new ArrayList();
112 110
//				array.add(colorTable.getTableName());
113 111
//				array.add(colorTable);
......
117 115
			addActionListener(innerActionUpdateTooltip);
118 116
			setRenderer(new ListCellRenderer() {
119 117
				public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
120
					IColorTablePaint colorTable = (IColorTablePaint) value;
118
					ColorTablePainter colorTable = (ColorTablePainter) value;
121 119
					ColorSchemeItemPainter paintItem = new ColorSchemeItemPainter(colorTable.getTableName(), colorTable, isSelected);
122 120
					paintItem.setPreferredSize(getPreferredSize());
123 121
					return paintItem;
......
132 130
	 * @return
133 131
	 */
134 132
	public Color[] getSelectedColors() {
135
		IColorTablePaint colorTable = (IColorTablePaint) getSelectedItem();
133
		ColorTablePainter colorTable = (ColorTablePainter) getSelectedItem();
136 134
		if (colorTable == null) {
137 135
			return null;
138 136
		}
......
147 145
			return;
148 146
		} else {
149 147
			for (int i = 0; i < getItemCount(); i++) {
150
				colorTables.add((IColorTablePaint) getItemAt(i));
148
				colorTables.add((ColorTablePainter) getItemAt(i));
151 149
			}
152 150

  
153 151
			for (int i = 0; i < colorTables.size(); i++) {
154
				IColorTablePaint colorTable = colorTables.get(i);
152
				ColorTablePainter colorTable = colorTables.get(i);
155 153
				Color[] myColors = colorTable.getColors();
156 154

  
157 155
				boolean isEqual = true;
......
179 177
	private class ColorSchemeItemPainter extends JComponent {
180 178
		private static final long serialVersionUID = -6448740563809113949L;
181 179
		private boolean isSelected = false;
182
		private IColorTablePaint colorTablePaint = null;
180
		private ColorTablePainter colorTablePaint = null;
183 181
		/**
184 182
		 * Constructor method
185 183
		 *
......
187 185
		 * @param colorTablePaint
188 186
		 * @param isSelected
189 187
		 */
190
		public ColorSchemeItemPainter(String name, IColorTablePaint colorTablePaint, boolean isSelected) {
188
		public ColorSchemeItemPainter(String name, ColorTablePainter colorTablePaint, boolean isSelected) {
191 189
			super();
192 190
			this.colorTablePaint = colorTablePaint;
193 191
			this.isSelected = isSelected;
......
210 208
				g2.setColor(Color.black);
211 209
			}
212 210

  
213
			colorTablePaint.paint(g2, isSelected, getBounds());
211
			colorTablePaint.paint(g2, isSelected);
214 212
		}
215 213
	}
216 214
	
branches/v2_0_0_prep/libraries/org.gvsig.symbology/org.gvsig.symbology.swing/org.gvsig.symbology.swing.api/src/main/java/org/gvsig/symbology/swing/SymbologySwingManager.java
21 21
 */
22 22
package org.gvsig.symbology.swing;
23 23

  
24
import org.gvsig.gui.IColorTables;
25
import org.gvsig.gui.IColorTablesFactory;
24
import java.util.List;
25

  
26
import org.gvsig.gui.ColorTablePainter;
27
import org.gvsig.gui.ColorTablesFactory;
26 28
import org.gvsig.symbology.SymbologyManager;
27 29

  
28 30
/**
......
73 75
     */
74 76
    public SymbologyWindowManager getWindowManager();
75 77
    
76
    public void setColorTablesFactory(IColorTablesFactory factory);
78
    public void setColorTablesFactory(ColorTablesFactory factory);
77 79
    
78
    public IColorTablesFactory getColorTablesFactory();
80
    public ColorTablesFactory getColorTablesFactory();
79 81
    
80
    public IColorTables createColorTables();
82
    public List<ColorTablePainter> createColorTables();
81 83
}
branches/v2_0_0_prep/libraries/org.gvsig.symbology/org.gvsig.symbology.swing/org.gvsig.symbology.swing.impl/src/main/java/org/gvsig/symbology/swing/impl/DefaultSymbologySwingManager.java
21 21
 */
22 22
package org.gvsig.symbology.swing.impl;
23 23

  
24
import java.util.List;
25

  
24 26
import org.gvsig.app.gui.styling.SymbolEditor;
25
import org.gvsig.gui.DefaultColorTables;
26
import org.gvsig.gui.IColorTables;
27
import org.gvsig.gui.IColorTablesFactory;
27
import org.gvsig.gui.ColorTablePainter;
28
import org.gvsig.gui.ColorTablesFactory;
29
import org.gvsig.gui.DefaultColorTablesFactory;
28 30
import org.gvsig.symbology.SymbologyLocator;
29 31
import org.gvsig.symbology.SymbologyManager;
30 32
import org.gvsig.symbology.swing.SymbologySwingManager;
......
42 44
    private SymbologyManager manager;
43 45
    // private I18nManager i18nmanager = null;
44 46
    private SymbologyWindowManager windowManager;
45
    private IColorTablesFactory colorTablesFactory;
47
    private ColorTablesFactory colorTablesFactory;
46 48

  
47 49
    public DefaultSymbologySwingManager() {
48 50
        this.manager = SymbologyLocator.getSymbologyManager();
49 51
        // this.i18nmanager = ToolsLocator.getI18nManager();
50 52
        this.windowManager = new DefaultSymbologyWindowManager();
53
        colorTablesFactory = new DefaultColorTablesFactory();
51 54
    }
52 55

  
53 56
    public SymbologyManager getManager() {
......
74 77
		SymbolEditor.addSymbolEditorPanel(abstractTypeSymbolEditorPanelClass, shapeType);
75 78
	}
76 79

  
77
	public void setColorTablesFactory(IColorTablesFactory factory) {
80
	public void setColorTablesFactory(ColorTablesFactory factory) {
78 81
		colorTablesFactory = factory;
79 82
	}
80 83

  
81
	public IColorTables createColorTables() {
84
	public List<ColorTablePainter> createColorTables() {
82 85
		if (colorTablesFactory != null){
83 86
		    return colorTablesFactory.createColorTables();
84 87
		}
85
		return new DefaultColorTables();
88
		return null;
86 89
	}
87 90
	
88
	public IColorTablesFactory getColorTablesFactory() {
91
	public ColorTablesFactory getColorTablesFactory() {
89 92
		return this.colorTablesFactory;
90 93
	}
91 94
}
branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/app/imp/DefaultAppgvSIGManager.java
71 71
import org.gvsig.fmap.mapcontext.MapContextLocator;
72 72
import org.gvsig.fmap.mapcontext.MapContextManager;
73 73
import org.gvsig.fmap.mapcontext.layers.FLayer;
74
import org.gvsig.gui.IColorTablesFactory;
74
import org.gvsig.gui.ColorTablesFactory;
75 75
import org.gvsig.symbology.swing.SymbologySwingLocator;
76 76
import org.gvsig.tools.ToolsLocator;
77 77
import org.gvsig.tools.dataTypes.DataTypesManager;
......
359 359
		return manager;
360 360
	}
361 361

  
362
	public IColorTablesFactory getColorTablesFactory() {
362
	public ColorTablesFactory getColorTablesFactory() {
363 363
		return SymbologySwingLocator.getSwingManager().getColorTablesFactory();
364 364
	}
365 365

  
366
	public void registerColorTablesFactory(IColorTablesFactory factory) {
366
	public void registerColorTablesFactory(ColorTablesFactory factory) {
367 367
		SymbologySwingLocator.getSwingManager().setColorTablesFactory(factory);
368 368
		
369 369
	}
branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/app/ApplicationManager.java
52 52
import org.gvsig.fmap.geom.GeometryManager;
53 53
import org.gvsig.fmap.mapcontext.MapContextManager;
54 54
import org.gvsig.fmap.mapcontext.layers.FLayer;
55
import org.gvsig.gui.IColorTablesFactory;
55
import org.gvsig.gui.ColorTablesFactory;
56 56
import org.gvsig.tools.dataTypes.DataTypesManager;
57 57
import org.gvsig.tools.dispose.DisposableManager;
58 58
import org.gvsig.tools.dynobject.DynObjectManager;
......
287 287
			throws Exception;
288 288
	
289 289
	
290
	public IColorTablesFactory getColorTablesFactory();
290
	public ColorTablesFactory getColorTablesFactory();
291 291
	
292
	public void registerColorTablesFactory(IColorTablesFactory factory);
292
	public void registerColorTablesFactory(ColorTablesFactory factory);
293 293

  
294 294
	public String getLocaleLanguage();
295 295

  

Also available in: Unified diff