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.io.IOException;
019:
020: /**
021: * Contains the suitability information for a single palette with several colour schemes.
022: *
023: * @author Cory Horner, Refractions Research Inc.
024: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/brewer/src/main/java/org/geotools/brewer/color/PaletteSuitability.java $
025: */
026: public class PaletteSuitability {
027: /** Suitability = GOOD */
028: public static final int QUALITY_GOOD = 3;
029:
030: /** Suitability = UNKNOWN */
031: public static final int QUALITY_UNKNOWN = 2;
032:
033: /** Suitability = DOUBTFUL */
034: public static final int QUALITY_DOUBTFUL = 1;
035:
036: /** Suitability = BAD */
037: public static final int QUALITY_BAD = 0;
038:
039: /** ViewerType = Suitable for the colorblind? */
040: public static final int VIEWER_COLORBLIND = 0;
041:
042: /** ViewerType = Suitable for photocopiers? */
043: public static final int VIEWER_PHOTOCOPY = 1;
044:
045: /** ViewerType = Suitable for overhead projectors (lcd)? */
046: public static final int VIEWER_PROJECTOR = 2;
047:
048: /** ViewerType = Suitable for LCD monitors? */
049: public static final int VIEWER_LCD = 3;
050:
051: /** ViewerType = Suitable for CRT monitors? */
052: public static final int VIEWER_CRT = 4;
053:
054: /** ViewerType = Suitable for colour printing? */
055: public static final int VIEWER_PRINT = 5;
056:
057: /**
058: * Contains the suitability data for this palette. First index is the
059: * number of colors - 2. Second index is the viewer type. Values are the
060: * suitability value.
061: *
062: * <p>
063: * Viewer Types: PaletteSuitability.COLORBLIND, PHOTOCOPY, PROJECTOR, LCD,
064: * CRT, or PRINT
065: * </p>
066: *
067: * <p>
068: * Suitability: PaletteSuitability.GOOD, UNKNOWN, DOUBTFUL, or BAD
069: * </p>
070: */
071: private int[][] paletteSuitability = new int[11][6];
072:
073: /**
074: * The maximum number of colors this palette can support (minimum is
075: * assumed to be 2).
076: */
077: private int maxColors = 0;
078:
079: public PaletteSuitability() {
080: }
081:
082: /**
083: * Indexed getter for property paletteSuitability. For this palette, this
084: * returns an array containing the integer values for all 6 suitabilities.
085: *
086: * @param numClasses
087: * The number of colors to determine the suitability for
088: *
089: * @return int array; index = PaletteSuitability.VIEWER_COLORBLIND,
090: * VIEWER_PHOTOCOPY, VIEWER_PROJECTOR, VIEWER_LCD, VIEWER_CRT, or
091: * VIEWER_PRINT; values = PaletteSuitability.QUALITY_GOOD,
092: * QUALITY_UNKNOWN, QUALITY_DOUBTFUL, or QUALITY_BAD.
093: */
094: public int[] getSuitability(int numClasses) {
095: return paletteSuitability[numClasses - 2];
096: }
097:
098: /**
099: * Indexed getter for the property paletteSuitability. For the selected
100: * palette and viewerType, this returns the integer value of the
101: *
102: * @param numClasses
103: * number of colours in this palette
104: * @param viewerType
105: * PaletteSuitability.VIEWER_COLORBLIND, VIEWER_PHOTOCOPY,
106: * VIEWER_PROJECTOR, VIEWER_LCD, VIEWER_CRT, or VIEWER_PRINT.
107: *
108: * @return PaletteSuitability.QUALITY_GOOD, QUALITY_UNKNOWN,
109: * QUALITY_DOUBTFUL, or QUALITY_BAD.
110: */
111: public int getSuitability(int numClasses, int viewerType) {
112: return paletteSuitability[numClasses - 2][viewerType];
113: }
114:
115: /**
116: *
117: *
118: * @param numClasses Index of the property.
119: * @param suitability New value of the property at<CODE>index</CODE>.
120: *
121: * @throws IOException
122: */
123: public void setSuitability(int numClasses, String[] suitability)
124: throws IOException {
125: //update max number of classes
126: if (numClasses > maxColors) {
127: maxColors = numClasses;
128: }
129:
130: //convert G,D,B,? --> int
131: if (suitability.length == 6) {
132: for (int i = 0; i < 6; i++) {
133: if (suitability[i].equals("G")) {
134: paletteSuitability[numClasses - 2][i] = QUALITY_GOOD;
135: } else if (suitability[i].equals("D")) {
136: paletteSuitability[numClasses - 2][i] = QUALITY_DOUBTFUL;
137: } else if (suitability[i].equals("B")) {
138: paletteSuitability[numClasses - 2][i] = QUALITY_BAD;
139: } else {
140: paletteSuitability[numClasses - 2][i] = QUALITY_UNKNOWN;
141: }
142: }
143: } else {
144: throw new IOException(
145: "wrong number of items in suitability list");
146: }
147: }
148:
149: public int getMaxColors() {
150: return maxColors;
151: }
152: }
|