001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2005-2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.brewer.color;
017:
018: import java.awt.Color;
019:
020: /**
021: * A generic palette containing colours.
022: * @author Cory Horner, Refractions Research Inc.
023: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/brewer/src/main/java/org/geotools/brewer/color/ColorPalette.java $
024: */
025: public class ColorPalette {
026: private Color[] colors = new Color[0]; //15
027:
028: /**
029: * Longer description of the palette
030: */
031: private String description;
032:
033: /**
034: * Very short name describing the palette
035: */
036: private String name;
037: private int numColors = 0;
038:
039: /**
040: * Returns the number of colours contained in the palette.
041: * @return int
042: */
043: public int getCount() {
044: return numColors;
045: }
046:
047: /**
048: * Getter for property name.
049: *
050: * @return Value of property name.
051: */
052: public String getName() {
053: return this .name;
054: }
055:
056: /**
057: * Setter for property name.
058: *
059: * @param name New value of property name.
060: */
061: public void setName(String name) {
062: this .name = name;
063: }
064:
065: /**
066: * Getter for property description.
067: *
068: * @return Value of property description.
069: */
070: public String getDescription() {
071: return this .description;
072: }
073:
074: /**
075: * Setter for property description.
076: *
077: * @param description New value of property description.
078: */
079: public void setDescription(String description) {
080: this .description = description;
081: }
082:
083: public void setColors(Color[] colors) {
084: this .colors = colors;
085:
086: int count = 0;
087:
088: for (int i = 0; i < colors.length; i++)
089: if (colors[i] != null) {
090: count++;
091: }
092:
093: this .numColors = count;
094: }
095:
096: public Color[] getColors(int length) {
097: if (length < 2) {
098: length = 2; //if they ask for 1 colour, give them 2 instead of crashing
099: }
100:
101: //int[] lookup = sampler.getSampleScheme(length);
102: Color[] result = new Color[length];
103:
104: for (int i = 0; i < length; i++) {
105: result[i] = colors[i];
106: }
107:
108: return result;
109: }
110:
111: /**
112: * Returns all colours
113: *
114: * @return complete colour array
115: */
116: public Color[] getColors() {
117: return colors;
118: }
119: }
|