Browse Source
* commit '486e03ae6a459202995890162afe832d932fb1dc': REPORT-27647 模板组件的安装下载-模板组件复用插件 调整暴露的接口,返回合适的接口 REPORT-27647 模板组件的安装下载-模板组件复用插件 调整暴露的接口,返回合适的接口 REPORT-27647 模板组件的安装下载-模板组件复用插件 图片需要先加载进去。 set 的时候就晚了 REPORT-27647 模板组件的安装下载-模板组件复用插件 处理下可能的 npe REPORT-27647 模板组件的安装下载-模板组件复用插件 修复部分监听上的问题 REPORT-27647 模板组件的安装下载-模板组件复用插件 删掉多余的设计 REPORT-27647 模板组件的安装下载-模板组件复用插件 1、抽出一个更通用的接口来添加面板 2、为共享加载器添加插件实现 REPORT-27647 模板组件的安装下载-模板组件复用插件 1、空字符串 2、判空 3、接口 xml REPORT-27647 模板组件的安装下载-模板组件复用插件 ui 界面 1、 本地组件库界面 2、 小圆点设计feature/big-screen
Harrison
5 years ago
25 changed files with 1108 additions and 110 deletions
@ -0,0 +1,57 @@
|
||||
package com.fr.design.fun; |
||||
|
||||
import com.fr.design.gui.icombobox.UIComboBox; |
||||
import com.fr.design.gui.icontainer.UIScrollPane; |
||||
import com.fr.design.mainframe.DockingView; |
||||
import com.fr.stable.fun.mark.Immutable; |
||||
|
||||
import javax.swing.JPanel; |
||||
|
||||
/** |
||||
* 组件库面板处理器 |
||||
* |
||||
* created by Harrison on 2020/03/16 |
||||
**/ |
||||
public interface ComponentLibraryPaneProcessor extends Immutable { |
||||
|
||||
String XML_TAG = "ComponentLibraryPaneProcessor"; |
||||
|
||||
int CURRENT_LEVEL = 1; |
||||
|
||||
/** |
||||
* 创建展示面板 |
||||
* |
||||
* @param isEdit 是否可以编辑 |
||||
* @return 展示面板 |
||||
*/ |
||||
UIScrollPane createShowPanel(boolean isEdit); |
||||
|
||||
/** |
||||
* 创建菜单的上部面板 |
||||
* |
||||
* @return 面板 |
||||
*/ |
||||
JPanel createMenuNorthPane(); |
||||
|
||||
/** |
||||
* 创建复选框 |
||||
* |
||||
* @return 复选框 |
||||
*/ |
||||
UIComboBox createMenuComBox(); |
||||
|
||||
void parentView(DockingView dockingView); |
||||
|
||||
/** |
||||
* 父面板 |
||||
* |
||||
* @param panel 面板 |
||||
*/ |
||||
void parentPane(JPanel panel); |
||||
|
||||
/** |
||||
* 创建完成 |
||||
*/ |
||||
void complete(); |
||||
|
||||
} |
@ -0,0 +1,50 @@
|
||||
package com.fr.design.fun; |
||||
|
||||
import com.fr.design.mainframe.PaneHolder; |
||||
import com.fr.design.mainframe.PropertyItemBean; |
||||
import com.fr.stable.fun.mark.Mutable; |
||||
import org.jetbrains.annotations.Nullable; |
||||
|
||||
/** |
||||
* created by Harrison on 2020/03/23 |
||||
**/ |
||||
public interface PropertyItemPaneProvider<T> extends Mutable { |
||||
|
||||
int CURRENT_LEVEL = 1; |
||||
|
||||
String XML_TAG = "PropertyItemPaneProvider"; |
||||
|
||||
int FIRST = 100; |
||||
|
||||
int LAST = -100; |
||||
|
||||
/** |
||||
* 独一无二的标志 |
||||
* |
||||
* @return 标志 |
||||
*/ |
||||
String key(); |
||||
|
||||
/** |
||||
* 配置属性 |
||||
* |
||||
* @return 熟悉 |
||||
*/ |
||||
PropertyItemBean getItem(); |
||||
|
||||
/** |
||||
* 面板持有者 |
||||
* |
||||
* @param clazz 类型 |
||||
* @return 持有者 |
||||
*/ |
||||
@Nullable |
||||
PaneHolder<T> getPaneHolder(Class<?> clazz); |
||||
|
||||
/** |
||||
* 想要替代的类型 |
||||
* |
||||
* @return 替代类型 |
||||
*/ |
||||
String replaceKey(); |
||||
} |
@ -0,0 +1,31 @@
|
||||
package com.fr.design.fun.impl; |
||||
|
||||
import com.fr.design.fun.PropertyItemPaneProvider; |
||||
import com.fr.design.mainframe.PaneHolder; |
||||
import com.fr.stable.fun.impl.AbstractProvider; |
||||
import com.fr.stable.fun.mark.API; |
||||
|
||||
/** |
||||
* created by Harrison on 2020/03/23 |
||||
**/ |
||||
@API(level = PropertyItemPaneProvider.CURRENT_LEVEL) |
||||
public abstract class AbstractPropertyItemPaneProvider<T> extends AbstractProvider implements PropertyItemPaneProvider<T> { |
||||
|
||||
@Override |
||||
public PaneHolder<T> getPaneHolder(Class<?> clazz) { |
||||
|
||||
if (sign().equals(clazz)) { |
||||
return getPathHolder0(); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
protected abstract PaneHolder<T> getPathHolder0(); |
||||
|
||||
protected abstract Class<T> sign(); |
||||
|
||||
@Override |
||||
public int currentAPILevel() { |
||||
return PropertyItemPaneProvider.CURRENT_LEVEL; |
||||
} |
||||
} |
@ -0,0 +1,81 @@
|
||||
package com.fr.design.gui.imenu; |
||||
|
||||
import com.fr.design.constants.UIConstants; |
||||
import com.fr.design.utils.gui.GUIPaintUtils; |
||||
import com.fr.stable.Constants; |
||||
import sun.swing.SwingUtilities2; |
||||
|
||||
import javax.swing.ButtonModel; |
||||
import javax.swing.JMenu; |
||||
import javax.swing.JMenuItem; |
||||
import javax.swing.UIManager; |
||||
import javax.swing.plaf.basic.BasicMenuItemUI; |
||||
import java.awt.Color; |
||||
import java.awt.FontMetrics; |
||||
import java.awt.Graphics; |
||||
import java.awt.Graphics2D; |
||||
import java.awt.Rectangle; |
||||
|
||||
/** |
||||
* created by Harrison on 2020/03/22 |
||||
**/ |
||||
public class UIMenuItemUI extends BasicMenuItemUI { |
||||
|
||||
@Override |
||||
protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) { |
||||
if (menuItem.getIcon() == null) { |
||||
super.paintBackground(g, menuItem, bgColor); |
||||
return; |
||||
} |
||||
ButtonModel model = menuItem.getModel(); |
||||
Color oldColor = g.getColor(); |
||||
int menuWidth = menuItem.getWidth(); |
||||
int menuHeight = menuItem.getHeight(); |
||||
|
||||
g.setColor(UIConstants.NORMAL_BACKGROUND); |
||||
g.fillRect(0, 0, menuWidth, menuHeight); |
||||
if (menuItem.isOpaque()) { |
||||
if (model.isArmed() || (menuItem instanceof JMenu && model.isSelected())) { |
||||
GUIPaintUtils.fillPaint((Graphics2D) g, 30, 0, menuWidth - 30, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, 7); |
||||
} else { |
||||
GUIPaintUtils.fillPaint((Graphics2D) g, 30, 0, menuWidth - 30, menuHeight, true, Constants.NULL, menuItem.getBackground(), 7); |
||||
} |
||||
g.setColor(oldColor); |
||||
} else if (model.isArmed() || (menuItem instanceof JMenu && |
||||
model.isSelected())) { |
||||
GUIPaintUtils.fillPaint((Graphics2D) g, 30, 0, menuWidth - 30, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, 7); |
||||
g.setColor(oldColor); |
||||
} |
||||
} |
||||
|
||||
protected void paintText(Graphics g, JMenuItem menuItem, Rectangle textRect, String text) { |
||||
ButtonModel model = menuItem.getModel(); |
||||
FontMetrics fm = SwingUtilities2.getFontMetrics(menuItem, g); |
||||
int mnemIndex = menuItem.getDisplayedMnemonicIndex(); |
||||
|
||||
if (!model.isEnabled()) { |
||||
// *** paint the text disabled
|
||||
if (UIManager.get("MenuItem.disabledForeground") instanceof Color) { |
||||
g.setColor(UIManager.getColor("MenuItem.disabledForeground")); |
||||
SwingUtilities2.drawStringUnderlineCharAt(menuItem, g, text, |
||||
-1, textRect.x, textRect.y + fm.getAscent()); |
||||
} else { |
||||
g.setColor(menuItem.getBackground().brighter()); |
||||
SwingUtilities2.drawStringUnderlineCharAt(menuItem, g, text, |
||||
-1, textRect.x, textRect.y + fm.getAscent()); |
||||
g.setColor(menuItem.getBackground().darker()); |
||||
SwingUtilities2.drawStringUnderlineCharAt(menuItem, g, text, |
||||
-1, textRect.x - 1, textRect.y + |
||||
fm.getAscent() - 1); |
||||
} |
||||
} else { |
||||
// *** paint the text normally
|
||||
if (model.isArmed() || (menuItem instanceof JMenu && model.isSelected())) { |
||||
g.setColor(Color.WHITE); // Uses protected field.
|
||||
} |
||||
SwingUtilities2.drawStringUnderlineCharAt(menuItem, g, text, |
||||
-1, textRect.x, textRect.y + fm.getAscent()); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,17 @@
|
||||
package com.fr.design.mainframe; |
||||
|
||||
import javax.swing.JPanel; |
||||
|
||||
/** |
||||
* created by Harrison on 2020/03/23 |
||||
**/ |
||||
public interface PaneHolder<T> { |
||||
|
||||
/** |
||||
* 得到 Pane |
||||
* |
||||
* @param arg 参数 |
||||
* @return 面板 |
||||
*/ |
||||
JPanel getInstance(T arg); |
||||
} |
@ -0,0 +1,78 @@
|
||||
package com.fr.design.mainframe; |
||||
|
||||
import java.awt.event.ActionListener; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* created by Harrison on 2020/03/23 |
||||
**/ |
||||
public class PropertyItemBean { |
||||
|
||||
private String name; |
||||
private String title; |
||||
private String btnIconName; |
||||
private String btnIconBaseDir; |
||||
private EastRegionContainerPane.PropertyMode[] visibleModes; |
||||
private EastRegionContainerPane.PropertyMode[] enableModes; |
||||
private List<ActionListener> buttonListeners; |
||||
|
||||
public PropertyItemBean() { |
||||
} |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
|
||||
public String getTitle() { |
||||
return title; |
||||
} |
||||
|
||||
public void setTitle(String title) { |
||||
this.title = title; |
||||
} |
||||
|
||||
public String getBtnIconName() { |
||||
return btnIconName; |
||||
} |
||||
|
||||
public void setBtnIconName(String btnIconName) { |
||||
this.btnIconName = btnIconName; |
||||
} |
||||
|
||||
public String getBtnIconBaseDir() { |
||||
|
||||
return btnIconBaseDir; |
||||
} |
||||
|
||||
public void setBtnIconBaseDir(String btnIconBaseDir) { |
||||
this.btnIconBaseDir = btnIconBaseDir; |
||||
} |
||||
|
||||
public EastRegionContainerPane.PropertyMode[] getVisibleModes() { |
||||
return visibleModes; |
||||
} |
||||
|
||||
public void setVisibleModes(EastRegionContainerPane.PropertyMode[] visibleModes) { |
||||
this.visibleModes = visibleModes; |
||||
} |
||||
|
||||
public EastRegionContainerPane.PropertyMode[] getEnableModes() { |
||||
return enableModes; |
||||
} |
||||
|
||||
public void setEnableModes(EastRegionContainerPane.PropertyMode[] enableModes) { |
||||
this.enableModes = enableModes; |
||||
} |
||||
|
||||
public List<ActionListener> getButtonListeners() { |
||||
return buttonListeners; |
||||
} |
||||
|
||||
public void setButtonListeners(List<ActionListener> buttonListeners) { |
||||
this.buttonListeners = buttonListeners; |
||||
} |
||||
} |
@ -0,0 +1,161 @@
|
||||
package com.fr.design.menu; |
||||
|
||||
import com.fr.design.gui.imenu.UIMenu; |
||||
import com.fr.design.gui.imenu.UIScrollMenu; |
||||
import com.fr.design.notification.SnapChat; |
||||
import com.fr.design.notification.SnapChatConfig; |
||||
import com.fr.design.notification.SnapChatKey; |
||||
|
||||
import javax.swing.JMenu; |
||||
import javax.swing.event.MenuEvent; |
||||
import javax.swing.event.MenuListener; |
||||
import java.awt.Color; |
||||
import java.awt.Graphics2D; |
||||
import java.awt.Image; |
||||
import java.awt.geom.Ellipse2D; |
||||
import java.awt.image.BufferedImage; |
||||
|
||||
/** |
||||
* created by Harrison on 2020/03/16 |
||||
**/ |
||||
public class SnapChatMenuDef extends MenuDef implements SnapChat { |
||||
|
||||
private SnapChatKey uniqueKey; |
||||
private SnapChatMenuUI menuUI = new SnapChatMenuUI(this); |
||||
|
||||
public SnapChatMenuDef(String name, SnapChatKey uniqueKey) { |
||||
super(name); |
||||
this.uniqueKey = uniqueKey; |
||||
} |
||||
|
||||
public SnapChatMenuDef(Boolean rePaint, SnapChatKey uniqueKey) { |
||||
super(rePaint); |
||||
this.uniqueKey = uniqueKey; |
||||
} |
||||
|
||||
public SnapChatMenuDef(String name, char mnemonic, SnapChatKey uniqueKey) { |
||||
super(name, mnemonic); |
||||
this.uniqueKey = uniqueKey; |
||||
} |
||||
|
||||
@Override |
||||
public boolean hasRead() { |
||||
|
||||
String calcKey = calcKey(); |
||||
return SnapChatConfig.getInstance().hasRead(calcKey); |
||||
} |
||||
|
||||
@Override |
||||
public void markRead() { |
||||
|
||||
String calcKey = calcKey(); |
||||
SnapChatConfig.getInstance().markRead(calcKey); |
||||
} |
||||
|
||||
@Override |
||||
public SnapChatKey key() { |
||||
|
||||
return this.uniqueKey; |
||||
} |
||||
|
||||
@Override |
||||
protected MenuListener createMenuListener() { |
||||
|
||||
return new SnapChatMenuListener(); |
||||
} |
||||
|
||||
private String calcKey() { |
||||
|
||||
return key().calc(); |
||||
} |
||||
|
||||
@Override |
||||
protected UIMenu createJMenu0() { |
||||
|
||||
UIMenu createdJMenu; |
||||
if (hasScrollSubMenu) { |
||||
createdJMenu = new SnapChatUIScrollMenu(this.getName()); |
||||
} else if (isHeadMenu){ |
||||
createdJMenu = new SnapChatUIHeadMenu(this.getName()); |
||||
} else { |
||||
createdJMenu = new SnapChatUIMenu(this.getName()); |
||||
} |
||||
return createdJMenu; |
||||
} |
||||
|
||||
private class SnapChatMenuListener implements MenuListener { |
||||
|
||||
@Override |
||||
public void menuSelected(MenuEvent e) { |
||||
|
||||
markRead(); |
||||
Object source = e.getSource(); |
||||
if (!(source instanceof JMenu)) { |
||||
return; |
||||
} |
||||
updateMenu(); |
||||
} |
||||
|
||||
@Override |
||||
public void menuDeselected(MenuEvent e) { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void menuCanceled(MenuEvent e) { |
||||
|
||||
} |
||||
} |
||||
|
||||
private class SnapChatUIScrollMenu extends UIScrollMenu { |
||||
|
||||
public SnapChatUIScrollMenu(String s) { |
||||
super(s); |
||||
} |
||||
|
||||
@Override |
||||
public void updateUI() { |
||||
setUI(menuUI); |
||||
} |
||||
} |
||||
|
||||
private class SnapChatUIMenu extends UIMenu { |
||||
|
||||
public SnapChatUIMenu(String name) { |
||||
|
||||
super(name); |
||||
} |
||||
|
||||
@Override |
||||
public void updateUI() { |
||||
|
||||
setUI(menuUI); |
||||
} |
||||
} |
||||
|
||||
private class SnapChatUIHeadMenu extends UIMenu { |
||||
|
||||
public SnapChatUIHeadMenu(String name) { |
||||
|
||||
super(name); |
||||
} |
||||
|
||||
@Override |
||||
public void updateUI() { |
||||
|
||||
setUI(menuUI); |
||||
} |
||||
} |
||||
|
||||
public static void main(String[] args) { |
||||
|
||||
BufferedImage image = new BufferedImage(16, 16, Image.SCALE_DEFAULT); |
||||
Graphics2D g2d = image.createGraphics(); |
||||
g2d.setColor(Color.green); |
||||
Ellipse2D.Double shape = |
||||
new Ellipse2D.Double(2, 2, 1, 1); |
||||
g2d.fill(shape); |
||||
g2d.draw(shape); |
||||
System.out.println(); |
||||
} |
||||
} |
@ -0,0 +1,31 @@
|
||||
package com.fr.design.menu; |
||||
|
||||
import com.fr.design.gui.imenu.UIMenuItemUI; |
||||
|
||||
import javax.swing.JMenuItem; |
||||
import java.awt.Graphics; |
||||
import java.awt.Rectangle; |
||||
|
||||
/** |
||||
* created by Harrison on 2020/03/22 |
||||
**/ |
||||
class SnapChatMenuItemUI extends UIMenuItemUI { |
||||
|
||||
private final SnapChatUpdateAction snapChatUpdateAction; |
||||
|
||||
public SnapChatMenuItemUI(SnapChatUpdateAction snapChatUpdateAction) { |
||||
|
||||
this.snapChatUpdateAction = snapChatUpdateAction; |
||||
} |
||||
|
||||
@Override |
||||
protected void paintText(Graphics g, JMenuItem menuItem, Rectangle textRect, String text) { |
||||
|
||||
super.paintText(g, menuItem, textRect, text); |
||||
|
||||
if (!snapChatUpdateAction.hasRead()) { |
||||
SnapChatUtil.paintSnapChat(g, textRect); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,29 @@
|
||||
package com.fr.design.menu; |
||||
|
||||
import com.fr.design.gui.imenu.UIMenuUI; |
||||
|
||||
import javax.swing.JMenuItem; |
||||
import java.awt.Graphics; |
||||
import java.awt.Rectangle; |
||||
|
||||
/** |
||||
* created by Harrison on 2020/03/22 |
||||
**/ |
||||
public class SnapChatMenuUI extends UIMenuUI { |
||||
|
||||
private SnapChatMenuDef menuDef; |
||||
|
||||
public SnapChatMenuUI(SnapChatMenuDef menuDef) { |
||||
this.menuDef = menuDef; |
||||
} |
||||
|
||||
@Override |
||||
protected void paintText(Graphics g, JMenuItem menuItem, Rectangle textRect, String text) { |
||||
|
||||
super.paintText(g, menuItem, textRect, text); |
||||
|
||||
if (!menuDef.hasRead()) { |
||||
SnapChatUtil.paintSnapChat(g, textRect); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,72 @@
|
||||
package com.fr.design.menu; |
||||
|
||||
import com.fr.design.actions.UpdateAction; |
||||
import com.fr.design.gui.imenu.UIMenuItem; |
||||
import com.fr.design.notification.SnapChat; |
||||
import com.fr.design.notification.SnapChatConfig; |
||||
import com.fr.design.notification.SnapChatKey; |
||||
|
||||
import java.awt.event.ActionEvent; |
||||
|
||||
/** |
||||
* created by Harrison on 2020/03/22 |
||||
**/ |
||||
public abstract class SnapChatUpdateAction extends UpdateAction implements SnapChat { |
||||
|
||||
private SnapChatKey uniqueKey; |
||||
|
||||
public SnapChatUpdateAction(SnapChatKey uniqueKey) { |
||||
this.uniqueKey = uniqueKey; |
||||
} |
||||
|
||||
@Override |
||||
public final void actionPerformed(ActionEvent e) { |
||||
|
||||
markRead(); |
||||
actionPerformed0(e); |
||||
} |
||||
|
||||
protected abstract void actionPerformed0(ActionEvent e); |
||||
|
||||
@Override |
||||
public boolean hasRead() { |
||||
|
||||
String calcKey = calcKey(); |
||||
return SnapChatConfig.getInstance().hasRead(calcKey); |
||||
} |
||||
|
||||
@Override |
||||
public void markRead() { |
||||
|
||||
String calcKey = calcKey(); |
||||
SnapChatConfig.getInstance().markRead(calcKey); |
||||
} |
||||
|
||||
@Override |
||||
public SnapChatKey key() { |
||||
|
||||
return this.uniqueKey; |
||||
} |
||||
|
||||
private String calcKey() { |
||||
|
||||
return key().calc(); |
||||
} |
||||
|
||||
@Override |
||||
public UIMenuItem createMenuItem() { |
||||
|
||||
Object object = this.getValue(UIMenuItem.class.getName()); |
||||
if (object == null && !(object instanceof UIMenuItem)) { |
||||
UIMenuItem menuItem = new UIMenuItem(this); |
||||
// 设置名字用作单元测
|
||||
menuItem.setName(getName()); |
||||
menuItem.setUI(new SnapChatMenuItemUI(this)); |
||||
object = menuItem; |
||||
|
||||
this.putValue(UIMenuItem.class.getName(), object); |
||||
} |
||||
return (UIMenuItem) object; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,33 @@
|
||||
package com.fr.design.menu; |
||||
|
||||
import java.awt.Color; |
||||
import java.awt.Graphics; |
||||
import java.awt.Graphics2D; |
||||
import java.awt.Rectangle; |
||||
import java.awt.geom.Ellipse2D; |
||||
|
||||
/** |
||||
* created by Harrison on 2020/03/22 |
||||
**/ |
||||
public class SnapChatUtil { |
||||
|
||||
public static void paintSnapChat(Graphics g, Rectangle textRect) { |
||||
|
||||
Color oldColor = g.getColor(); |
||||
|
||||
double x = textRect.getWidth(); |
||||
x += textRect.getX(); |
||||
x += 2; |
||||
|
||||
double y = textRect.getY(); |
||||
|
||||
Graphics2D g2d = (Graphics2D) g; |
||||
g2d.setColor(Color.red); |
||||
Ellipse2D.Double shape = |
||||
new Ellipse2D.Double(x, y, 4, 4); |
||||
g2d.fill(shape); |
||||
g2d.draw(shape); |
||||
|
||||
g2d.setColor(oldColor); |
||||
} |
||||
} |
@ -0,0 +1,28 @@
|
||||
package com.fr.design.notification; |
||||
|
||||
/** |
||||
* 阅后即焚的消息提醒 |
||||
* |
||||
* created by Harrison on 2020/03/16 |
||||
**/ |
||||
public interface SnapChat { |
||||
|
||||
/** |
||||
* 已读 |
||||
* |
||||
* @return 是否为已读 |
||||
*/ |
||||
boolean hasRead(); |
||||
|
||||
/** |
||||
* 标记为已读 |
||||
*/ |
||||
void markRead(); |
||||
|
||||
/** |
||||
* 独一无二的标志 |
||||
* |
||||
* @return 字符标志 |
||||
*/ |
||||
SnapChatKey key(); |
||||
} |
@ -0,0 +1,38 @@
|
||||
package com.fr.design.notification; |
||||
|
||||
import com.fr.stable.CommonUtils; |
||||
|
||||
/** |
||||
* created by Harrison on 2020/03/16 |
||||
**/ |
||||
public abstract class SnapChatAllTypes { |
||||
|
||||
public enum Menu implements SnapChatKey { |
||||
|
||||
/** |
||||
* 社区按钮 |
||||
*/ |
||||
BBS("BBS"); |
||||
|
||||
private static final String SIGN = "0001"; |
||||
|
||||
private String key; |
||||
|
||||
Menu(String key) { |
||||
this.key = key; |
||||
} |
||||
|
||||
public String getKey() { |
||||
return key; |
||||
} |
||||
|
||||
@Override |
||||
public String calc() { |
||||
|
||||
return CommonUtils.join( |
||||
new String[]{SIGN, getKey()}, "-" |
||||
); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,89 @@
|
||||
package com.fr.design.notification; |
||||
|
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.stable.xml.XMLPrintWriter; |
||||
import com.fr.stable.xml.XMLReadable; |
||||
import com.fr.stable.xml.XMLable; |
||||
import com.fr.stable.xml.XMLableReader; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* created by Harrison on 2020/03/16 |
||||
**/ |
||||
@SuppressWarnings("unchecked") |
||||
public class SnapChatConfig implements XMLable { |
||||
|
||||
public static final String XML_TAG = "SnapChatConfig"; |
||||
|
||||
/** |
||||
* 已经阅读过的属性 |
||||
*/ |
||||
private Map<String, Boolean> markReadMap = new HashMap<>(8); |
||||
|
||||
private static final SnapChatConfig INSTANCE = new SnapChatConfig(); |
||||
|
||||
public static SnapChatConfig getInstance() { |
||||
return INSTANCE; |
||||
} |
||||
|
||||
public Boolean hasRead(String key) { |
||||
|
||||
Map<String, Boolean> map = markReadMap; |
||||
Boolean val = map.get(key); |
||||
return val == null ? Boolean.FALSE : val; |
||||
} |
||||
|
||||
public void markRead(String key) { |
||||
|
||||
markReadMap.put(key, Boolean.TRUE); |
||||
} |
||||
|
||||
@Override |
||||
public void readXML(XMLableReader reader) { |
||||
|
||||
if (reader.isChildNode()) { |
||||
if ("item".equals(reader.getTagName())) { |
||||
String tmpVal = reader.getElementValue(); |
||||
Boolean markRead = Boolean.valueOf(tmpVal); |
||||
markReadMap.put(reader.getAttrAsString("key", StringUtils.EMPTY), markRead); |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void writeXML(XMLPrintWriter writer) { |
||||
|
||||
writer.startTAG(XML_TAG); |
||||
writeMarkReadMapXML(writer); |
||||
writer.end(); |
||||
} |
||||
|
||||
private void readMarkReadMapXML(XMLableReader reader) { |
||||
|
||||
reader.readXMLObject(new XMLReadable() { |
||||
@Override |
||||
public void readXML(XMLableReader reader) { |
||||
} |
||||
}); |
||||
} |
||||
|
||||
/** |
||||
* 写入map |
||||
*/ |
||||
private void writeMarkReadMapXML(XMLPrintWriter writer) { |
||||
|
||||
writer.startTAG("MarkReadMap"); |
||||
for (Map.Entry<String, Boolean> item : markReadMap.entrySet()) { |
||||
writer.startTAG("item").attr("key", item.getKey()).textNode(item.getValue().toString()).end(); |
||||
} |
||||
writer.end(); |
||||
} |
||||
|
||||
@Override |
||||
public Object clone() throws CloneNotSupportedException { |
||||
|
||||
return super.clone(); |
||||
} |
||||
} |
@ -0,0 +1,9 @@
|
||||
package com.fr.design.notification; |
||||
|
||||
/** |
||||
* created by Harrison on 2020/03/16 |
||||
**/ |
||||
public interface SnapChatKey { |
||||
|
||||
String calc(); |
||||
} |
Loading…
Reference in new issue