|
|
|
@ -5,8 +5,7 @@ import com.fr.stable.xml.XMLPrintWriter;
|
|
|
|
|
import com.fr.stable.xml.XMLReadable; |
|
|
|
|
import com.fr.stable.xml.XMLableReader; |
|
|
|
|
|
|
|
|
|
import java.awt.*; |
|
|
|
|
|
|
|
|
|
import java.awt.Color; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
@ -17,10 +16,9 @@ import java.util.List;
|
|
|
|
|
*/ |
|
|
|
|
public class ColorSelectConfigManager implements XMLReadable { |
|
|
|
|
|
|
|
|
|
// 最近使用的颜色个数
|
|
|
|
|
private int colorNums = 20; |
|
|
|
|
// 最大存储的最近使用的颜色个数
|
|
|
|
|
private int colorNum = 20; |
|
|
|
|
|
|
|
|
|
private boolean init = true; |
|
|
|
|
// 最近使用颜色
|
|
|
|
|
private List<Color> colors = new ArrayList<Color>(); |
|
|
|
|
private static final String RECENT_COLOR_TAG = "RecentColors"; |
|
|
|
@ -33,35 +31,30 @@ public class ColorSelectConfigManager implements XMLReadable {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public int getColorNum() { |
|
|
|
|
return colorNums; |
|
|
|
|
return colorNum; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setColorNum(int colorNums) { |
|
|
|
|
this.colorNums = colorNums; |
|
|
|
|
public void setColorNum(int colorNum) { |
|
|
|
|
this.colorNum = colorNum; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 添加颜色到最近使用队列中 |
|
|
|
|
* |
|
|
|
|
* @param color 颜色 |
|
|
|
|
*/ |
|
|
|
|
public void addToColorQueue(Color color) { |
|
|
|
|
if(color == null){ |
|
|
|
|
|
|
|
|
|
// 将透明度不为 0% 的 颜色去掉
|
|
|
|
|
if (color == null || color.getAlpha() != 0xff) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 过滤重复的最近使用颜色
|
|
|
|
|
// 因为有个后进先出的问题,最近使用的颜色需要放到最前面所以没用set
|
|
|
|
|
if (colors.contains(color)) { |
|
|
|
|
colors.remove(color); |
|
|
|
|
} |
|
|
|
|
// 最近使用的颜色需要放到"最前面","最前面"是在面板部分做的,是 colors 的逆序,因此保证最新的放在 list 的最后,
|
|
|
|
|
colors.remove(color); |
|
|
|
|
colors.add(color); |
|
|
|
|
|
|
|
|
|
/*@author yaohwu*/ |
|
|
|
|
//将历史颜色信息保存到xml文件中去
|
|
|
|
|
if (colors != null && !colors.isEmpty()) { |
|
|
|
|
this.setColorsToFile(colors); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void readXML(XMLableReader reader) { |
|
|
|
@ -71,8 +64,11 @@ public class ColorSelectConfigManager implements XMLReadable {
|
|
|
|
|
String tagName = reader.getTagName(); |
|
|
|
|
if (reader.isChildNode()) { |
|
|
|
|
if (ComparatorUtils.equals(COLOR_TAG, tagName)) { |
|
|
|
|
Color color = null; |
|
|
|
|
colors.add(reader.getAttrAsColor("colors", color)); |
|
|
|
|
Color color = reader.getAttrAsColor("colors", null); |
|
|
|
|
// 将透明度不为 0% 的 颜色去掉
|
|
|
|
|
if (color != null && color.getAlpha() == 0xff) { |
|
|
|
|
colors.add(color); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -82,11 +78,18 @@ public class ColorSelectConfigManager implements XMLReadable {
|
|
|
|
|
public void writeXML(XMLPrintWriter writer) { |
|
|
|
|
writer.startTAG(RECENT_COLOR_TAG); |
|
|
|
|
if (this.colors != null && !this.colors.isEmpty()) { |
|
|
|
|
for (int i = 0; i < this.colors.size(); i++) { |
|
|
|
|
// 只应该存储 max 个,其他颜色存了也没用
|
|
|
|
|
// 从 colors 的尾部开始计算,从尾往头数 max 个,但是存储的时候还是要从头往尾
|
|
|
|
|
int size = colors.size(); |
|
|
|
|
|
|
|
|
|
int beginIndex = size > colorNum ? size - colorNum : 0; |
|
|
|
|
|
|
|
|
|
for (int i = beginIndex; i < this.colors.size(); i++) { |
|
|
|
|
writer.startTAG(COLOR_TAG); |
|
|
|
|
writer.attr("colors", colors.get(i).getRGB()); |
|
|
|
|
writer.end(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
writer.end(); |
|
|
|
|
} |
|
|
|
|