From ba2efd53f765edf8dadada46bb3b82691ea4dcad Mon Sep 17 00:00:00 2001 From: "yaoh.wu" Date: Mon, 3 Sep 2018 16:30:21 +0800 Subject: [PATCH 1/2] =?UTF-8?q?REPORT-11037=20=E6=9C=80=E8=BF=91=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E9=A2=9C=E8=89=B2=E5=8F=AA=E5=AD=98=E4=B8=8D=E9=80=8F?= =?UTF-8?q?=E6=98=8E=E9=A2=9C=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../style/color/ColorSelectConfigManager.java | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/style/color/ColorSelectConfigManager.java b/designer-base/src/main/java/com/fr/design/style/color/ColorSelectConfigManager.java index d4ca574db..aaea88ea9 100644 --- a/designer-base/src/main/java/com/fr/design/style/color/ColorSelectConfigManager.java +++ b/designer-base/src/main/java/com/fr/design/style/color/ColorSelectConfigManager.java @@ -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; @@ -18,9 +17,8 @@ import java.util.List; public class ColorSelectConfigManager implements XMLReadable { // 最近使用的颜色个数 - private int colorNums = 20; + private int colorNum = 20; - private boolean init = true; // 最近使用颜色 private List colors = new ArrayList(); 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.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); + } } } } From 688e96673df662477f51ce9a5f2bfd22c6ad9de5 Mon Sep 17 00:00:00 2001 From: "yaoh.wu" Date: Mon, 3 Sep 2018 17:11:55 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=97=A0JIRA=E4=BB=BB=E5=8A=A1=EF=BC=8C?= =?UTF-8?q?=E4=BD=BF=E5=8E=86=E5=8F=B2=E9=A2=9C=E8=89=B2=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E6=9C=80=E5=A4=A7=E5=80=BC=E7=94=9F=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../style/color/ColorSelectConfigManager.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/style/color/ColorSelectConfigManager.java b/designer-base/src/main/java/com/fr/design/style/color/ColorSelectConfigManager.java index aaea88ea9..14307ee53 100644 --- a/designer-base/src/main/java/com/fr/design/style/color/ColorSelectConfigManager.java +++ b/designer-base/src/main/java/com/fr/design/style/color/ColorSelectConfigManager.java @@ -16,7 +16,7 @@ import java.util.List; */ public class ColorSelectConfigManager implements XMLReadable { - // 最近使用的颜色个数 + // 最大存储的最近使用的颜色个数 private int colorNum = 20; // 最近使用颜色 @@ -51,7 +51,7 @@ public class ColorSelectConfigManager implements XMLReadable { } // 过滤重复的最近使用颜色 - // 最近使用的颜色需要放到最前面 + // 最近使用的颜色需要放到"最前面","最前面"是在面板部分做的,是 colors 的逆序,因此保证最新的放在 list 的最后, colors.remove(color); colors.add(color); @@ -78,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(); }