juhaoyu
8 years ago
27 changed files with 846 additions and 204 deletions
File diff suppressed because one or more lines are too long
@ -1,56 +1,192 @@
|
||||
package com.fr.design.style.color; |
||||
|
||||
import com.fr.file.XMLFileManager; |
||||
|
||||
|
||||
import com.fr.base.FRContext; |
||||
import com.fr.cluster.rpc.RPC; |
||||
import com.fr.file.BaseClusterHelper; |
||||
import com.fr.general.ComparatorUtils; |
||||
import com.fr.general.GeneralContext; |
||||
import com.fr.stable.EnvChangedListener; |
||||
import com.fr.stable.xml.XMLPrintWriter; |
||||
import com.fr.stable.xml.XMLTools; |
||||
import com.fr.stable.xml.XMLableReader; |
||||
import com.fr.general.FRLogger; |
||||
|
||||
import java.awt.Color; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.io.InputStream; |
||||
|
||||
/** |
||||
* 最近使用颜色 |
||||
* @author focus |
||||
* |
||||
* @author focus |
||||
*/ |
||||
public class ColorSelectConfigManager{ |
||||
|
||||
// 最近使用的颜色个数
|
||||
private int colorNums = 20; |
||||
// 最近使用颜色
|
||||
private List<Color> colors; |
||||
|
||||
private static ColorSelectConfigManager colorSelectConfigManager = null; |
||||
|
||||
public Color[] getColors() { |
||||
if(colors == null){ |
||||
colors = new ArrayList<Color>(); |
||||
} |
||||
return colors.toArray(new Color[colors.size()]); |
||||
} |
||||
|
||||
public int getColorNum() { |
||||
return colorNums; |
||||
} |
||||
public void setColorNum(int colorNums) { |
||||
this.colorNums = colorNums; |
||||
} |
||||
|
||||
public synchronized static ColorSelectConfigManager getInstance() { |
||||
if (colorSelectConfigManager == null) { |
||||
colorSelectConfigManager = new ColorSelectConfigManager(); |
||||
} |
||||
return colorSelectConfigManager; |
||||
} |
||||
|
||||
/** |
||||
* 添加颜色到最近使用队列中 |
||||
* |
||||
* @param color 颜色 |
||||
* |
||||
*/ |
||||
public void addToColorQueue(Color color){ |
||||
// 过滤重复的最近使用颜色
|
||||
// 因为有个后进先出的问题,最近使用的颜色需要放到最前面所以没用set
|
||||
if(colors.contains(color)){ |
||||
colors.remove(color); |
||||
} |
||||
colors.add(color); |
||||
} |
||||
} |
||||
public class ColorSelectConfigManager extends XMLFileManager implements ColorSelectConfigManagerProvider { |
||||
|
||||
// 最近使用的颜色个数
|
||||
private int colorNums = 20; |
||||
|
||||
private static ColorSelectConfigManagerProvider configManager = null; |
||||
private static ColorSelectConfigManager colorSelectConfigManager = null; |
||||
private boolean init = true; |
||||
// 最近使用颜色
|
||||
private List<Color> colors = new ArrayList<Color>(); |
||||
private static final String RECENT_COLOR_TAG = "RecentColors"; |
||||
private static final String COLOR_TAG = "Color"; |
||||
|
||||
static { |
||||
GeneralContext.addEnvChangedListener(new EnvChangedListener() { |
||||
public void envChanged() { |
||||
ColorSelectConfigManager.envChanged(); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
private static void envChanged() { |
||||
configManager = null; |
||||
} |
||||
|
||||
public Color[] getColors() { |
||||
|
||||
//初次打开软件时从xml文件中获取历史颜色信息
|
||||
if (init) { |
||||
ColorSelectConfigManagerProvider manager = ColorSelectConfigManager.getProviderInstance(); |
||||
this.colors = manager.getColorsFromFile(); |
||||
init = false; |
||||
} |
||||
if (colors == null) { |
||||
colors = new ArrayList<Color>(); |
||||
} |
||||
return colors.toArray(new Color[colors.size()]); |
||||
} |
||||
|
||||
public int getColorNum() { |
||||
return colorNums; |
||||
} |
||||
|
||||
public void setColorNum(int colorNums) { |
||||
this.colorNums = colorNums; |
||||
} |
||||
|
||||
public synchronized static ColorSelectConfigManager getInstance() { |
||||
if (colorSelectConfigManager == null) { |
||||
colorSelectConfigManager = new ColorSelectConfigManager(); |
||||
} |
||||
return colorSelectConfigManager; |
||||
} |
||||
|
||||
/** |
||||
* 添加颜色到最近使用队列中 |
||||
* |
||||
* @param color 颜色 |
||||
*/ |
||||
public void addToColorQueue(Color color) { |
||||
// 过滤重复的最近使用颜色
|
||||
// 因为有个后进先出的问题,最近使用的颜色需要放到最前面所以没用set
|
||||
if (colors.contains(color)) { |
||||
colors.remove(color); |
||||
} |
||||
colors.add(color); |
||||
|
||||
/*@author yaohwu*/ |
||||
//将历史颜色信息保存到xml文件中去
|
||||
ColorSelectConfigManagerProvider manager = ColorSelectConfigManager.getProviderInstance(); |
||||
if (colors != null && !colors.isEmpty()) { |
||||
manager.setColorsToFile(colors); |
||||
} |
||||
try { |
||||
FRContext.getCurrentEnv().writeResource(manager); |
||||
} catch (Exception e) { |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 读取配置文件流 |
||||
* |
||||
* @param input 流 |
||||
* @throws Exception 异常 |
||||
*/ |
||||
@Override |
||||
public void readFromInputStream(InputStream input) throws Exception { |
||||
ColorSelectConfigManager manager = new ColorSelectConfigManager(); |
||||
XMLTools.readInputStreamXML(manager, input); |
||||
configManager = manager; |
||||
FRContext.getCurrentEnv().writeResource(configManager); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 获取配置管理接口 |
||||
* |
||||
* @return 配置管理接口ConfigManagerProvider |
||||
*/ |
||||
public synchronized static ColorSelectConfigManagerProvider getProviderInstance() { |
||||
if (configManager == null) { |
||||
if (isClusterMember()) { |
||||
return configManager; |
||||
} |
||||
configManager.readXMLFile(); |
||||
} |
||||
return configManager; |
||||
} |
||||
|
||||
private synchronized static boolean isClusterMember() { |
||||
switch (BaseClusterHelper.getClusterState()) { |
||||
case LEADER: |
||||
configManager = new ColorSelectConfigManager(); |
||||
RPC.registerSkeleton(configManager); |
||||
return false; |
||||
case MEMBER: |
||||
String ip = BaseClusterHelper.getMainServiceIP(); |
||||
configManager = (ColorSelectConfigManagerProvider) RPC.getProxy(ColorSelectConfigManager.class, ip); |
||||
return true; |
||||
default: |
||||
configManager = new ColorSelectConfigManager(); |
||||
break; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
public boolean writeResource() throws Exception { |
||||
return FRContext.getCurrentEnv().writeResource(ColorSelectConfigManager.getProviderInstance()); |
||||
} |
||||
|
||||
public String fileName() { |
||||
return "recentcolors.xml"; |
||||
} |
||||
|
||||
public void readXML(XMLableReader reader) { |
||||
String name = reader.getTagName(); |
||||
if (reader.isChildNode()) { |
||||
if (ComparatorUtils.equals(COLOR_TAG, name)) { |
||||
Color color = null; |
||||
colors.add(reader.getAttrAsColor("colors", color)); |
||||
} |
||||
} |
||||
} |
||||
|
||||
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++) { |
||||
writer.startTAG(COLOR_TAG); |
||||
writer.attr("colors", colors.get(i).getRGB()); |
||||
writer.end(); |
||||
} |
||||
} |
||||
writer.end(); |
||||
} |
||||
|
||||
public List<Color> getColorsFromFile() { |
||||
return this.colors; |
||||
} |
||||
|
||||
public void setColorsToFile(List<Color> colors) { |
||||
this.colors = colors; |
||||
} |
||||
} |
||||
|
@ -0,0 +1,17 @@
|
||||
package com.fr.design.style.color; |
||||
|
||||
import com.fr.stable.file.RemoteXMLFileManagerProvider; |
||||
|
||||
import java.awt.Color; |
||||
import java.util.List; |
||||
|
||||
|
||||
/** |
||||
* Created by yaohwu on 2017/2/8. |
||||
*/ |
||||
public interface ColorSelectConfigManagerProvider extends RemoteXMLFileManagerProvider { |
||||
|
||||
List<Color> getColorsFromFile(); |
||||
|
||||
void setColorsToFile(List<Color> colors); |
||||
} |
@ -0,0 +1,32 @@
|
||||
package com.fr.design.designer.creator.cardlayout; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.design.designer.beans.actions.FormUndoableAction; |
||||
import com.fr.design.mainframe.FormDesigner; |
||||
|
||||
/** |
||||
* Created by zhouping on 2017/2/9. |
||||
*/ |
||||
public class TabMoveCustomAction extends FormUndoableAction { |
||||
private XCardSwitchButton xCardSwitchButton; |
||||
|
||||
public TabMoveCustomAction(FormDesigner t, XCardSwitchButton xCardSwitchButton) { |
||||
super(t); |
||||
this.setName(""); |
||||
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/control/refresh.png")); |
||||
this.xCardSwitchButton = xCardSwitchButton; |
||||
} |
||||
|
||||
@Override |
||||
public boolean executeActionReturnUndoRecordNeeded() { |
||||
return false; |
||||
} |
||||
|
||||
public XCardSwitchButton getxCardSwitchButton() { |
||||
return xCardSwitchButton; |
||||
} |
||||
|
||||
public void setxCardSwitchButton(XCardSwitchButton xCardSwitchButton) { |
||||
this.xCardSwitchButton = xCardSwitchButton; |
||||
} |
||||
} |
@ -0,0 +1,66 @@
|
||||
package com.fr.design.designer.creator.cardlayout; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.design.designer.beans.actions.FormUndoableAction; |
||||
import com.fr.design.mainframe.FormDesigner; |
||||
import com.fr.form.ui.CardSwitchButton; |
||||
import com.fr.form.ui.container.cardlayout.WTabFitLayout; |
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.Inter; |
||||
|
||||
/** |
||||
* Created by zhouping on 2017/2/9. |
||||
*/ |
||||
public class TabMoveEndAction extends FormUndoableAction { |
||||
private XCardSwitchButton xCardSwitchButton; |
||||
|
||||
public TabMoveEndAction(FormDesigner t, XCardSwitchButton xCardSwitchButton) { |
||||
super(t); |
||||
this.setName(Inter.getLocText("FR-Designer-Move_Tab_End")); |
||||
this.setSmallIcon(BaseUtils.readIcon("com/fr/design/images/control/rightright.png")); |
||||
this.xCardSwitchButton = xCardSwitchButton; |
||||
} |
||||
|
||||
@Override |
||||
public boolean executeActionReturnUndoRecordNeeded() { |
||||
XWCardTagLayout xwCardTagLayout = xCardSwitchButton.getTagLayout(); |
||||
XWCardLayout xwCardLayout = xCardSwitchButton.getCardLayout(); |
||||
CardSwitchButton currentButton = (CardSwitchButton) xCardSwitchButton.toData(); |
||||
try { |
||||
int currentIndex = currentButton.getIndex(); |
||||
int maxIndex = xwCardTagLayout.getComponentCount(); |
||||
XWTabFitLayout xCurrentTab = (XWTabFitLayout) xwCardLayout.getXCreator(currentIndex); |
||||
WTabFitLayout currentTab = (WTabFitLayout) xCurrentTab.toData(); |
||||
xwCardTagLayout.setSwitchingTab(true); |
||||
//修改当前tab往后所有tab的索引号
|
||||
for (int i = currentIndex + 1; i < maxIndex; i++) { |
||||
CardSwitchButton tempBtn = (CardSwitchButton) xwCardTagLayout.getXCreator(i).toData(); |
||||
tempBtn.setIndex(i - 1); |
||||
WTabFitLayout tempTab = (WTabFitLayout) xwCardLayout.getXCreator(i).toData(); |
||||
tempTab.setIndex(i - 1); |
||||
tempTab.setTabNameIndex(i - 1); |
||||
} |
||||
xwCardTagLayout.remove(xCardSwitchButton); |
||||
xwCardTagLayout.add(xCardSwitchButton); |
||||
xwCardLayout.remove(xCurrentTab); |
||||
xwCardLayout.add(xCurrentTab); |
||||
currentButton.setIndex(maxIndex - 1); |
||||
currentTab.setIndex(maxIndex - 1); |
||||
currentTab.setTabNameIndex(maxIndex - 1); |
||||
xwCardTagLayout.setSwitchingTab(false); |
||||
}catch (Exception e){ |
||||
xwCardTagLayout.setSwitchingTab(false); |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
return false; |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
public XCardSwitchButton getxCardSwitchButton() { |
||||
return xCardSwitchButton; |
||||
} |
||||
|
||||
public void setxCardSwitchButton(XCardSwitchButton xCardSwitchButton) { |
||||
this.xCardSwitchButton = xCardSwitchButton; |
||||
} |
||||
} |
@ -0,0 +1,65 @@
|
||||
package com.fr.design.designer.creator.cardlayout; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.design.designer.beans.actions.FormUndoableAction; |
||||
import com.fr.design.mainframe.FormDesigner; |
||||
import com.fr.form.ui.CardSwitchButton; |
||||
import com.fr.form.ui.container.cardlayout.WTabFitLayout; |
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.Inter; |
||||
|
||||
/** |
||||
* Created by zhouping on 2017/2/9. |
||||
*/ |
||||
public class TabMoveFirstAction extends FormUndoableAction { |
||||
private XCardSwitchButton xCardSwitchButton; |
||||
|
||||
public TabMoveFirstAction(FormDesigner t, XCardSwitchButton xCardSwitchButton) { |
||||
super(t); |
||||
this.setName(Inter.getLocText("FR-Designer-Move_Tab_First")); |
||||
this.setSmallIcon(BaseUtils.readIcon("com/fr/design/images/control/leftleft.png")); |
||||
this.xCardSwitchButton = xCardSwitchButton; |
||||
} |
||||
|
||||
@Override |
||||
public boolean executeActionReturnUndoRecordNeeded() { |
||||
XWCardTagLayout xwCardTagLayout = xCardSwitchButton.getTagLayout(); |
||||
XWCardLayout xwCardLayout = xCardSwitchButton.getCardLayout(); |
||||
CardSwitchButton currentButton = (CardSwitchButton) xCardSwitchButton.toData(); |
||||
try { |
||||
int currentIndex = currentButton.getIndex(); |
||||
XWTabFitLayout xCurrentTab = (XWTabFitLayout) xwCardLayout.getXCreator(currentIndex); |
||||
WTabFitLayout currentTab = (WTabFitLayout) xCurrentTab.toData(); |
||||
xwCardTagLayout.setSwitchingTab(true); |
||||
//修改当前tab往前所有tab的索引号
|
||||
for (int i = currentIndex - 1; i >= 0; i--) { |
||||
CardSwitchButton tempBtn = (CardSwitchButton) xwCardTagLayout.getXCreator(i).toData(); |
||||
tempBtn.setIndex(i + 1); |
||||
WTabFitLayout tempTab = (WTabFitLayout) xwCardLayout.getXCreator(i).toData(); |
||||
tempTab.setIndex(i + 1); |
||||
tempTab.setTabNameIndex(i + 1); |
||||
} |
||||
xwCardTagLayout.remove(xCardSwitchButton); |
||||
xwCardTagLayout.add(xCardSwitchButton, 0); |
||||
xwCardLayout.remove(xCurrentTab); |
||||
xwCardLayout.add(xCurrentTab, 0); |
||||
currentButton.setIndex(0); |
||||
currentTab.setIndex(0); |
||||
currentTab.setTabNameIndex(0); |
||||
xwCardTagLayout.setSwitchingTab(false); |
||||
}catch (Exception e){ |
||||
xwCardTagLayout.setSwitchingTab(false); |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
return false; |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
public XCardSwitchButton getxCardSwitchButton() { |
||||
return xCardSwitchButton; |
||||
} |
||||
|
||||
public void setxCardSwitchButton(XCardSwitchButton xCardSwitchButton) { |
||||
this.xCardSwitchButton = xCardSwitchButton; |
||||
} |
||||
} |
@ -0,0 +1,64 @@
|
||||
package com.fr.design.designer.creator.cardlayout; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.design.designer.beans.actions.FormUndoableAction; |
||||
import com.fr.design.mainframe.FormDesigner; |
||||
import com.fr.form.ui.CardSwitchButton; |
||||
import com.fr.form.ui.container.cardlayout.WTabFitLayout; |
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.Inter; |
||||
|
||||
/** |
||||
* Created by zhouping on 2017/2/9. |
||||
*/ |
||||
public class TabMoveNextAction extends FormUndoableAction { |
||||
private XCardSwitchButton xCardSwitchButton; |
||||
|
||||
public TabMoveNextAction(FormDesigner t, XCardSwitchButton xCardSwitchButton) { |
||||
super(t); |
||||
this.setName(Inter.getLocText("FR-Designer-Move_Tab_Next")); |
||||
this.setSmallIcon(BaseUtils.readIcon("com/fr/design/images/control/right.png")); |
||||
this.xCardSwitchButton = xCardSwitchButton; |
||||
} |
||||
|
||||
@Override |
||||
public boolean executeActionReturnUndoRecordNeeded() { |
||||
XWCardTagLayout xwCardTagLayout = xCardSwitchButton.getTagLayout(); |
||||
XWCardLayout xwCardLayout = xCardSwitchButton.getCardLayout(); |
||||
CardSwitchButton currentButton = (CardSwitchButton) xCardSwitchButton.toData(); |
||||
try { |
||||
int currentIndex = currentButton.getIndex(); |
||||
XWTabFitLayout xCurrentTab = (XWTabFitLayout) xwCardLayout.getXCreator(currentIndex); |
||||
WTabFitLayout currentTab = (WTabFitLayout) xCurrentTab.toData(); |
||||
xwCardTagLayout.setSwitchingTab(true); |
||||
//修改下一个tab的索引号
|
||||
CardSwitchButton nextBtn = (CardSwitchButton) xwCardTagLayout.getXCreator(currentIndex + 1).toData(); |
||||
nextBtn.setIndex(currentIndex); |
||||
WTabFitLayout nextTab = (WTabFitLayout) xwCardLayout.getXCreator(currentIndex + 1).toData(); |
||||
nextTab.setIndex(currentIndex); |
||||
nextTab.setTabNameIndex(currentIndex); |
||||
|
||||
xwCardTagLayout.remove(xCardSwitchButton); |
||||
xwCardTagLayout.add(xCardSwitchButton, currentIndex + 1); |
||||
xwCardLayout.remove(xCurrentTab); |
||||
xwCardLayout.add(xCurrentTab, currentIndex + 1); |
||||
currentButton.setIndex(currentIndex + 1); |
||||
currentTab.setIndex(currentIndex + 1); |
||||
currentTab.setTabNameIndex(currentIndex + 1); |
||||
xwCardTagLayout.setSwitchingTab(false); |
||||
}catch (Exception e){ |
||||
xwCardTagLayout.setSwitchingTab(false); |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
return false; |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
public XCardSwitchButton getxCardSwitchButton() { |
||||
return xCardSwitchButton; |
||||
} |
||||
|
||||
public void setxCardSwitchButton(XCardSwitchButton xCardSwitchButton) { |
||||
this.xCardSwitchButton = xCardSwitchButton; |
||||
} |
||||
} |
@ -0,0 +1,64 @@
|
||||
package com.fr.design.designer.creator.cardlayout; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.design.designer.beans.actions.FormUndoableAction; |
||||
import com.fr.design.mainframe.FormDesigner; |
||||
import com.fr.form.ui.CardSwitchButton; |
||||
import com.fr.form.ui.container.cardlayout.WTabFitLayout; |
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.Inter; |
||||
|
||||
/** |
||||
* Created by zhouping on 2017/2/9. |
||||
*/ |
||||
public class TabMovePrevAction extends FormUndoableAction { |
||||
private XCardSwitchButton xCardSwitchButton; |
||||
|
||||
public TabMovePrevAction(FormDesigner t, XCardSwitchButton xCardSwitchButton) { |
||||
super(t); |
||||
this.setName(Inter.getLocText("FR-Designer-Move_Tab_Prev")); |
||||
this.setSmallIcon(BaseUtils.readIcon("com/fr/design/images/control/left.png")); |
||||
this.xCardSwitchButton = xCardSwitchButton; |
||||
} |
||||
|
||||
@Override |
||||
public boolean executeActionReturnUndoRecordNeeded() { |
||||
XWCardTagLayout xwCardTagLayout = xCardSwitchButton.getTagLayout(); |
||||
XWCardLayout xwCardLayout = xCardSwitchButton.getCardLayout(); |
||||
CardSwitchButton currentButton = (CardSwitchButton) xCardSwitchButton.toData(); |
||||
try { |
||||
int currentIndex = currentButton.getIndex(); |
||||
XWTabFitLayout xCurrentTab = (XWTabFitLayout) xwCardLayout.getXCreator(currentIndex); |
||||
WTabFitLayout currentTab = (WTabFitLayout) xCurrentTab.toData(); |
||||
xwCardTagLayout.setSwitchingTab(true); |
||||
//修改上一个tab的索引号
|
||||
CardSwitchButton prevBtn = (CardSwitchButton) xwCardTagLayout.getXCreator(currentIndex - 1).toData(); |
||||
prevBtn.setIndex(currentIndex); |
||||
WTabFitLayout prevTab = (WTabFitLayout) xwCardLayout.getXCreator(currentIndex - 1).toData(); |
||||
prevTab.setIndex(currentIndex); |
||||
prevTab.setTabNameIndex(currentIndex); |
||||
|
||||
xwCardTagLayout.remove(xCardSwitchButton); |
||||
xwCardTagLayout.add(xCardSwitchButton, currentIndex - 1); |
||||
xwCardLayout.remove(xCurrentTab); |
||||
xwCardLayout.add(xCurrentTab, currentIndex - 1); |
||||
currentButton.setIndex(currentIndex - 1); |
||||
currentTab.setIndex(currentIndex - 1); |
||||
currentTab.setTabNameIndex(currentIndex - 1); |
||||
xwCardTagLayout.setSwitchingTab(false); |
||||
}catch (Exception e){ |
||||
xwCardTagLayout.setSwitchingTab(false); |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
return false; |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
public XCardSwitchButton getxCardSwitchButton() { |
||||
return xCardSwitchButton; |
||||
} |
||||
|
||||
public void setxCardSwitchButton(XCardSwitchButton xCardSwitchButton) { |
||||
this.xCardSwitchButton = xCardSwitchButton; |
||||
} |
||||
} |
Loading…
Reference in new issue