|
From: <dav...@us...> - 2012-03-07 14:01:46
|
Revision: 1312
http://cishell.svn.sourceforge.net/cishell/?rev=1312&view=rev
Author: david-coe
Date: 2012-03-07 14:01:35 +0000 (Wed, 07 Mar 2012)
Log Message:
-----------
You can optionally create a registry that will not recycle the colors.
Reviewed by Chin Hua.
Modified Paths:
--------------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/color/ColorRegistry.java
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/color/ColorRegistry.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/color/ColorRegistry.java 2012-03-06 22:05:17 UTC (rev 1311)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/color/ColorRegistry.java 2012-03-07 14:01:35 UTC (rev 1312)
@@ -21,9 +21,15 @@
private int currentIndex;
private ColorSchema colorSchema;
private Map<K, Color> registedColors;
+ private boolean recycleColor;
public ColorRegistry(ColorSchema colorSchema) {
+ this(colorSchema, true);
+ }
+
+ public ColorRegistry(ColorSchema colorSchema, boolean recycleColor) {
this.currentIndex = 0;
+ this.recycleColor = recycleColor;
this.colorSchema = colorSchema;
this.registedColors = new HashMap<K, Color>();
}
@@ -33,7 +39,7 @@
* @return Return the registered keys
*/
public Set<K> getKeySet() {
- return registedColors.keySet();
+ return this.registedColors.keySet();
}
/**
@@ -44,11 +50,10 @@
* color defined by the ColorSchema will be returned
*/
public Color getColorOf(K key) {
- if (registedColors.containsKey(key)) {
- return registedColors.get(key);
- } else {
- return reserveColorFor(key);
+ if (this.registedColors.containsKey(key)) {
+ return this.registedColors.get(key);
}
+ return reserveColorFor(key);
}
/**
@@ -56,14 +61,14 @@
* @return the default color.
*/
public Color getDefaultColor() {
- return colorSchema.getDefaultColor();
+ return this.colorSchema.getDefaultColor();
}
/**
* Clear all entry and reset to initial state.
*/
public void clear() {
- registedColors.clear();
+ this.registedColors.clear();
}
/*
@@ -71,22 +76,24 @@
*/
private Color reserveColorFor(K key) {
- Color color = colorSchema.get(getNextIndex());
- registedColors.put(key, color);
+ Color color = this.colorSchema.get(getNextIndex());
+ this.registedColors.put(key, color);
return color;
}
/*
- * Return next color index. This will reuse the color if it out of color
+ * Return next color index. This will recycle the color
+ * if the recycleColor is true
*/
private int getNextIndex() {
- int index = currentIndex;
+ int index = this.currentIndex;
- if (currentIndex < colorSchema.size() - 1) {
- currentIndex++;
+ if (this.currentIndex < this.colorSchema.size() - 1
+ || !this.recycleColor) {
+ this.currentIndex++;
} else {
- currentIndex = 0;
+ this.currentIndex = 0;
}
return index;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|