001: /*
002: * uDig - User Friendly Desktop Internet GIS client
003: * http://udig.refractions.net
004: * (C) 2004, Refractions Research Inc.
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: */
017: package net.refractions.udig.ui.palette;
018:
019: import java.awt.Color;
020: import java.util.ArrayList;
021: import java.util.Arrays;
022: import java.util.Collections;
023: import java.util.EnumSet;
024: import java.util.List;
025:
026: /**
027: * A color schme from a palette.
028: *
029: * @author Jody Garnett, Refractions Research
030: * @since 0.6.0
031: * @deprecated
032: */
033: public class Scheme {
034:
035: /** List of Color aranged by length */
036: public final List<Color> colors;
037:
038: /** <code>good</code> field */
039: public final EnumSet<Friendly> good;
040:
041: /** <code>doubtful</code> field */
042: public final EnumSet<Friendly> doubtful;
043:
044: /**
045: * Construct <code>Scheme</code>.
046: *
047: * @param scheme
048: */
049: public Scheme(Color[] scheme) {
050: this (scheme, new Friendly[] { Friendly.CRT, Friendly.LCD },
051: new Friendly[] { Friendly.COLORBLIND,
052: Friendly.PROJECTOR });
053: }
054:
055: /**
056: * Construct <code>Scheme</code>.
057: *
058: * @param scheme
059: * @param good
060: */
061: public Scheme(Color[] scheme, Friendly good[]) {
062: this (scheme, good, new Friendly[0]);
063: }
064:
065: /**
066: * Construct <code>Scheme</code>.
067: *
068: * @param scheme
069: */
070: public Scheme(List<Color> scheme) {
071: this (scheme, EnumSet.of(Friendly.CRT, Friendly.LCD), EnumSet
072: .of(Friendly.COLORBLIND, Friendly.PROJECTOR));
073: }
074:
075: /**
076: * Construct <code>Scheme</code>.
077: *
078: * @param scheme
079: * @param good
080: * @param doubtful
081: */
082: public Scheme(List<Color> scheme, EnumSet<Friendly> good,
083: EnumSet<Friendly> doubtful) {
084: colors = scheme;
085: this .good = good;
086: this .doubtful = doubtful;
087: }
088:
089: /**
090: * Construct <code>Scheme</code>.
091: *
092: * @param scheme
093: * @param good
094: * @param doubtful
095: */
096: public Scheme(Color[] scheme, Friendly good[], Friendly doubtful[]) {
097: this (colors(scheme), friendly(good), friendly(doubtful));
098: }
099:
100: /**
101: * Construct <code>Scheme</code>.
102: *
103: * @param scheme
104: * @param good
105: * @param doubtful
106: */
107: public Scheme(int[][] scheme, int friendly[]) {
108: this (colors(scheme), good(friendly), doubtful(friendly));
109: }
110:
111: /*
112: * @see java.lang.Object#toString()
113: */
114: public String toString() {
115: StringBuffer buf = new StringBuffer();
116: buf.append("<Scheme"); //$NON-NLS-1$
117: if (colors.size() != 0) {
118: if (colors.size() == 1) {
119: buf.append(colors.get(0));
120: } else {
121: buf.append("("); //$NON-NLS-1$
122: buf.append(colors.size());
123: buf.append("("); //$NON-NLS-1$
124: buf.append(colors.get(0));
125: buf.append(".."); //$NON-NLS-1$
126: buf.append(colors.get(colors.size() - 1));
127: }
128: }
129: if (!good.isEmpty()) {
130: buf.append(" good="); //$NON-NLS-1$
131: buf.append(good);
132: }
133: if (!doubtful.isEmpty()) {
134: buf.append(" doubtful="); //$NON-NLS-1$
135: buf.append(doubtful);
136: }
137: buf.append(">"); //$NON-NLS-1$
138: return buf.toString();
139: }
140:
141: private static EnumSet<Friendly> friendly(Friendly good[]) {
142: if (good != null) {
143: return EnumSet.copyOf(Arrays.asList(good));
144: }
145: return (EnumSet<Friendly>) Collections.unmodifiableSet(EnumSet
146: .noneOf(Friendly.class));
147: }
148:
149: private static List<Color> colors(Color[] scheme) {
150: return Collections.unmodifiableList(Arrays.asList(scheme));
151: }
152:
153: /** One of GOOD, BAD, DOUBTFUL */
154: private static EnumSet<Friendly> good(int[] friendly) {
155: EnumSet<Friendly> set = EnumSet.noneOf(Friendly.class);
156: int i = 0;
157: for (Friendly f : Friendly.values()) {
158: if (friendly[i] == Palette.GOOD) {
159: set.add(f);
160: }
161: i++;
162: }
163: return set;
164: }
165:
166: /** One of GOOD, BAD, DOUBTFUL */
167: private static EnumSet<Friendly> doubtful(int[] friendly) {
168: EnumSet<Friendly> set = EnumSet.noneOf(Friendly.class);
169: int i = 0;
170: for (Friendly f : Friendly.values()) {
171: if (friendly[i] == Palette.DOUBTFUL) {
172: set.add(f);
173: }
174: i++;
175: }
176: return set;
177: }
178:
179: private static List<Color> colors(int[][] scheme) {
180: List<Color> list = new ArrayList<Color>();
181: int R = 0, G = 1, B = 2;
182: for (int rgb[] : scheme) {
183: list.add(new Color(rgb[R], rgb[G], rgb[B]));
184: }
185: return Collections.unmodifiableList(list);
186: }
187: }
|