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: /**
019: * This class doubles as a filter and an identifier for colour palettes.
020: *
021: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/brewer/src/main/java/org/geotools/brewer/color/PaletteType.java $
022: */
023: public class PaletteType {
024: /** name of the type, if null this will match any name */
025: String name;
026:
027: /** is the palette appropriate for numerical ranges? */
028: boolean suitableRanged;
029:
030: /** is the palette appropriate for categorical data (unique values)? */
031: boolean suitableUnique;
032:
033: /** interal flag for marking the type as UNKNOWN */
034: boolean isEmpty = false;
035:
036: /**
037: * Creates an identifier for palettes
038: *
039: * @param name simple identifier
040: * @param suitableRanged
041: * @param suitableUnique
042: */
043: public PaletteType(boolean suitableRanged, boolean suitableUnique,
044: String name) {
045: this .name = name;
046: this .suitableRanged = suitableRanged;
047: this .suitableUnique = suitableUnique;
048: }
049:
050: /**
051: *
052: * @param suitableRanged true, false, or null (for don't care)
053: * @param suitableUnique
054: */
055: public PaletteType(boolean suitableRanged, boolean suitableUnique) {
056: this .name = null;
057: this .suitableRanged = suitableRanged;
058: this .suitableUnique = suitableUnique;
059: }
060:
061: public PaletteType() {
062: this .name = null;
063: this .isEmpty = true;
064: }
065:
066: public String getName() {
067: return name;
068: }
069:
070: /**
071: * Deterines if this PaletteType instance is suitable ranged.
072: *
073: * @return a boolean, true if the paletteType is sutableRanged.
074: */
075: public boolean isSuitableRanged() {
076: return suitableRanged;
077: }
078:
079: public boolean isSuitableUnique() {
080: return suitableUnique;
081: }
082:
083: public boolean isMatch(PaletteType filter) {
084: if (filter.equals(ColorBrewer.ALL)) {
085: return true; //wildcard
086: }
087:
088: if (filter.isEmpty) {
089: return true; //wildcard (everything is null)
090: }
091:
092: if (filter.getName() == null) { //generic filter
093:
094: if (isEmpty) {
095: return false; //we know nothing about this item, so we assume it doesn't match
096: }
097: } else { //specific filter (exact name match + conditions)
098:
099: if (!filter.getName().equals(name)) {
100: return false;
101: }
102: }
103:
104: if (filter.isSuitableRanged() != suitableRanged) {
105: return false;
106: }
107:
108: if (filter.isSuitableUnique() != suitableUnique) {
109: return false;
110: }
111:
112: return true;
113: }
114:
115: public boolean equals(Object arg0) {
116: if (!(arg0 instanceof PaletteType)) {
117: return false;
118: }
119:
120: PaletteType arg = (PaletteType) arg0;
121:
122: if (name == null) {
123: if (arg.getName() != null) {
124: return false;
125: }
126: } else {
127: if (arg.getName() == null) {
128: return false;
129: }
130:
131: if (!arg.getName().equals(name)) {
132: return false;
133: }
134: }
135:
136: if (arg.isSuitableRanged() != suitableRanged) {
137: return false;
138: }
139:
140: if (arg.isSuitableUnique() != suitableUnique) {
141: return false;
142: }
143:
144: return true;
145: }
146: }
|