Browse Source

REPORT-27647 模板组件的安装下载-模板组件复用插件

ui 界面
1、 本地组件库界面
2、 小圆点设计
feature/big-screen
Harrison 5 years ago
parent
commit
ef24b120a9
  1. 20
      designer-base/src/main/java/com/fr/design/DesignerEnvManager.java
  2. 31
      designer-base/src/main/java/com/fr/design/fun/ComponentLibraryPaneProcessor.java
  3. 25
      designer-base/src/main/java/com/fr/design/fun/impl/AbstractComponentLibraryPaneProcessor.java
  4. 73
      designer-base/src/main/java/com/fr/design/gui/imenu/UIMenuItem.java
  5. 81
      designer-base/src/main/java/com/fr/design/gui/imenu/UIMenuItemUI.java
  6. 20
      designer-base/src/main/java/com/fr/design/mainframe/toolbar/ToolBarMenuDock.java
  7. 33
      designer-base/src/main/java/com/fr/design/menu/MenuDef.java
  8. 161
      designer-base/src/main/java/com/fr/design/menu/SnapChatMenuDef.java
  9. 31
      designer-base/src/main/java/com/fr/design/menu/SnapChatMenuItemUI.java
  10. 29
      designer-base/src/main/java/com/fr/design/menu/SnapChatMenuUI.java
  11. 74
      designer-base/src/main/java/com/fr/design/menu/SnapChatUpdateAction.java
  12. 33
      designer-base/src/main/java/com/fr/design/menu/SnapChatUtil.java
  13. 28
      designer-base/src/main/java/com/fr/design/notification/SnapChat.java
  14. 38
      designer-base/src/main/java/com/fr/design/notification/SnapChatAllTypes.java
  15. 88
      designer-base/src/main/java/com/fr/design/notification/SnapChatConfig.java
  16. 9
      designer-base/src/main/java/com/fr/design/notification/SnapChatKey.java
  17. 377
      designer-form/src/main/java/com/fr/design/mainframe/FormWidgetDetailPane.java
  18. 23
      designer-form/src/main/java/com/fr/design/mainframe/component/ComponentLibraryManager.java
  19. 68
      designer-form/src/main/java/com/fr/design/mainframe/component/pane/ComponentLibraryPaneCreator.java
  20. 412
      designer-form/src/main/java/com/fr/design/mainframe/component/pane/ComponentLibraryPaneProcessorImpl.java

20
designer-base/src/main/java/com/fr/design/DesignerEnvManager.java

@ -18,6 +18,7 @@ import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.i18n.Toolkit;
import com.fr.design.locale.impl.ProductImproveMark;
import com.fr.design.mainframe.vcs.VcsConfigManager;
import com.fr.design.notification.SnapChatConfig;
import com.fr.design.update.push.DesignerPushUpdateConfigManager;
import com.fr.design.style.color.ColorSelectConfigManager;
import com.fr.design.utils.DesignUtils;
@ -162,6 +163,11 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
*/
private AlphaFineConfigManager alphaFineConfigManager = AlphaFineConfigManager.getInstance();
/**
* 阅后即焚的配置项
*/
private SnapChatConfig snapChatConfig = SnapChatConfig.getInstance();
private DesignerPushUpdateConfigManager designerPushUpdateConfigManager = DesignerPushUpdateConfigManager.getInstance();
private VcsConfigManager vcsConfigManager = VcsConfigManager.getInstance();
@ -1562,12 +1568,18 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
readVcsAttr(reader);
} else if (DesignerPort.XML_TAG.equals(name)) {
readDesignerPort(reader);
}else if (name.equals(SnapChatConfig.XML_TAG)) {
readSnapChatConfig(reader);
} else {
readLayout(reader, name);
}
}
}
private void readSnapChatConfig(XMLableReader reader) {
reader.readXMLObject(this.snapChatConfig = SnapChatConfig.getInstance());
}
private void readAlphaFineAttr(XMLableReader reader) {
reader.readXMLObject(this.alphaFineConfigManager = AlphaFineConfigManager.getInstance());
}
@ -1783,9 +1795,17 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
writeDesignerPushUpdateAttr(writer);
writeVcsAttr(writer);
writeDesignerPort(writer);
writeSnapChatConfig(writer);
writer.end();
}
private void writeSnapChatConfig(XMLPrintWriter writer) {
if (this.snapChatConfig != null) {
this.snapChatConfig.writeXML(writer);
}
}
private void writeAlphaFineAttr(XMLPrintWriter writer) {
if (this.alphaFineConfigManager != null) {
this.alphaFineConfigManager.writeXML(writer);

31
designer-base/src/main/java/com/fr/design/fun/ComponentLibraryPaneProcessor.java

@ -0,0 +1,31 @@
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 = "ParameterExpandablePaneUIProvider";
int CURRENT_LEVEL = 1;
UIScrollPane createShowPanel(boolean isEdit);
JPanel createMenuNorthPane();
UIComboBox createMenuComBox();
void parentView(DockingView dockingView);
void parentPane(JPanel panel);
void complete();
}

25
designer-base/src/main/java/com/fr/design/fun/impl/AbstractComponentLibraryPaneProcessor.java

@ -0,0 +1,25 @@
package com.fr.design.fun.impl;
import com.fr.design.fun.ComponentLibraryPaneProcessor;
import com.fr.stable.fun.impl.AbstractProvider;
import com.fr.stable.fun.mark.API;
import com.fr.stable.fun.mark.Layer;
/**
* created by Harrison on 2020/03/16
**/
@API(level = ComponentLibraryPaneProcessor.CURRENT_LEVEL)
public abstract class AbstractComponentLibraryPaneProcessor extends AbstractProvider implements ComponentLibraryPaneProcessor {
@Override
public int currentAPILevel() {
return ComponentLibraryPaneProcessor.CURRENT_LEVEL;
}
@Override
public int layerIndex() {
return Layer.DEFAULT_LAYER_INDEX;
}
}

73
designer-base/src/main/java/com/fr/design/gui/imenu/UIMenuItem.java

@ -1,15 +1,11 @@
package com.fr.design.gui.imenu;
import java.awt.*;
import javax.swing.*;
import javax.swing.plaf.basic.BasicMenuItemUI;
import com.fr.design.constants.UIConstants;
import com.fr.stable.Constants;
import com.fr.stable.StringUtils;
import com.fr.design.utils.gui.GUIPaintUtils;
import sun.swing.SwingUtilities2;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JMenuItem;
public class UIMenuItem extends JMenuItem{
public UIMenuItem() {
@ -43,65 +39,4 @@ public class UIMenuItem extends JMenuItem{
return StringUtils.BLANK + super.getText();
}
private 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());
}
}
}
}

81
designer-base/src/main/java/com/fr/design/gui/imenu/UIMenuItemUI.java

@ -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());
}
}
}

20
designer-base/src/main/java/com/fr/design/mainframe/toolbar/ToolBarMenuDock.java

@ -12,7 +12,6 @@ import com.fr.design.actions.UpdateAction;
import com.fr.design.actions.community.BBSAction;
import com.fr.design.actions.community.BugAction;
import com.fr.design.actions.community.CenterAction;
import com.fr.design.actions.community.CusDemandAction;
import com.fr.design.actions.community.FacebookFansAction;
import com.fr.design.actions.community.NeedAction;
import com.fr.design.actions.community.QuestionAction;
@ -53,7 +52,9 @@ import com.fr.design.mainframe.ToolBarNewTemplatePane;
import com.fr.design.menu.MenuDef;
import com.fr.design.menu.SeparatorDef;
import com.fr.design.menu.ShortCut;
import com.fr.design.menu.SnapChatMenuDef;
import com.fr.design.menu.ToolBarDef;
import com.fr.design.notification.SnapChatAllTypes;
import com.fr.design.os.impl.SupportOSImpl;
import com.fr.design.remote.action.RemoteDesignAuthManagerAction;
import com.fr.design.update.actions.SoftwareUpdateAction;
@ -563,15 +564,24 @@ public abstract class ToolBarMenuDock {
* @return 社区菜单的子菜单
*/
public ShortCut[] createCommunityShortCuts() {
final java.util.List<ShortCut> shortCuts = new ArrayList<ShortCut>();
shortCuts.add(new BBSAction());
shortCuts.add(SeparatorDef.DEFAULT);
shortCuts.add(new VideoAction());
shortCuts.add(new TutorialAction());
shortCuts.add(new QuestionAction());
shortCuts.add(new TechSolutionAction());
shortCuts.add(SeparatorDef.DEFAULT);
shortCuts.add(new BugAction());
shortCuts.add(new NeedAction());
shortCuts.add(new CusDemandAction());
shortCuts.add(SeparatorDef.DEFAULT);
shortCuts.add(new CenterAction());
shortCuts.add(new SignAction());
LocaleCenter.buildAction(new LocaleAction() {
@ -594,7 +604,11 @@ public abstract class ToolBarMenuDock {
}
public MenuDef createCommunityMenuDef() {
MenuDef menuDef = new MenuDef(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Community"), 'C');
MenuDef menuDef = new SnapChatMenuDef(
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Community"),
'C',
SnapChatAllTypes.Menu.BBS);
ShortCut[] otherCommunityShortCuts = createCommunityShortCuts();
for (ShortCut shortCut : otherCommunityShortCuts) {
menuDef.addShortCut(shortCut);

33
designer-base/src/main/java/com/fr/design/menu/MenuDef.java

@ -38,8 +38,8 @@ public class MenuDef extends ShortCut {
protected UIMenu createdJMenu;
protected UIButton createdButton;
protected JPopupMenu popupMenu;
private boolean hasScrollSubMenu;
private boolean isHeadMenu;
protected boolean hasScrollSubMenu;
protected boolean isHeadMenu;
private String anchor;
@ -187,18 +187,13 @@ public class MenuDef extends ShortCut {
*/
public UIMenu createJMenu() {
if (createdJMenu == null) {
if (hasScrollSubMenu) {
createdJMenu = new UIScrollMenu(this.getName());
} else if (isHeadMenu){
createdJMenu = new UIHeadMenu(this.getName());
} else {
createdJMenu = new UIMenu(this.getName());
}
createdJMenu = createJMenu0();
createdJMenu.setMnemonic(this.getMnemonic());
if (this.iconPath != null) {
createdJMenu.setIcon(BaseUtils.readIcon(this.iconPath));
}
createdJMenu.addMenuListener(menuDefListener);
MenuListener menuListener = createMenuListener();
createdJMenu.addMenuListener(menuListener);
ContainerListener listener = getContainerListener();
if (listener != null) {
createdJMenu.getPopupMenu().addContainerListener(listener);
@ -208,6 +203,19 @@ public class MenuDef extends ShortCut {
return createdJMenu;
}
protected UIMenu createJMenu0() {
UIMenu createdJMenu;
if (hasScrollSubMenu) {
createdJMenu = new UIScrollMenu(this.getName());
} else if (isHeadMenu){
createdJMenu = new UIHeadMenu(this.getName());
} else {
createdJMenu = new UIMenu(this.getName());
}
return createdJMenu;
}
protected ContainerListener getContainerListener() {
return null;
}
@ -378,6 +386,11 @@ public class MenuDef extends ShortCut {
toolBar.add(this.createUIButton());
}
protected MenuListener createMenuListener() {
return menuDefListener;
}
private MenuListener menuDefListener = new MenuListener() {
@Override

161
designer-base/src/main/java/com/fr/design/menu/SnapChatMenuDef.java

@ -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();
}
}

31
designer-base/src/main/java/com/fr/design/menu/SnapChatMenuItemUI.java

@ -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);
}
}
}

29
designer-base/src/main/java/com/fr/design/menu/SnapChatMenuUI.java

@ -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);
}
}
}

74
designer-base/src/main/java/com/fr/design/menu/SnapChatUpdateAction.java

@ -0,0 +1,74 @@
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 class SnapChatUpdateAction extends UpdateAction implements SnapChat {
private SnapChatKey uniqueKey;
public SnapChatUpdateAction(SnapChatKey uniqueKey) {
this.uniqueKey = uniqueKey;
}
@Override
public void actionPerformed(ActionEvent e) {
markRead();
actionPerformed0(e);
}
protected 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;
}
}

33
designer-base/src/main/java/com/fr/design/menu/SnapChatUtil.java

@ -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);
}
}

28
designer-base/src/main/java/com/fr/design/notification/SnapChat.java

@ -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();
}

38
designer-base/src/main/java/com/fr/design/notification/SnapChatAllTypes.java

@ -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()}, "-"
);
}
}
}

88
designer-base/src/main/java/com/fr/design/notification/SnapChatConfig.java

@ -0,0 +1,88 @@
package com.fr.design.notification;
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) {
String tagName = reader.getTagName();
if ("MarkReadMap".equals(tagName)) {
readMarkReadMapXML(reader);
}
}
@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) {
String tmpVal = reader.getElementValue();
Boolean markRead = Boolean.valueOf(tmpVal);
markReadMap.put(reader.getAttrAsString("key", ""), markRead);
}
});
}
/**
* 写入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 null;
}
}

9
designer-base/src/main/java/com/fr/design/notification/SnapChatKey.java

@ -0,0 +1,9 @@
package com.fr.design.notification;
/**
* created by Harrison on 2020/03/16
**/
public interface SnapChatKey {
String calc();
}

377
designer-form/src/main/java/com/fr/design/mainframe/FormWidgetDetailPane.java

@ -1,42 +1,19 @@
package com.fr.design.mainframe;
import com.fr.base.BaseUtils;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.fun.ComponentLibraryPaneProcessor;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.widget.FRWidgetFactory;
import com.fr.form.share.ShareLoader;
import com.fr.form.ui.SharableWidgetBindInfo;
import com.fr.general.CloudCenter;
import com.fr.log.FineLoggerFactory;
import com.fr.share.ShareConstants;
import com.fr.stable.ArrayUtils;
import com.fr.stable.StringUtils;
import com.fr.design.mainframe.component.pane.ComponentLibraryPaneCreator;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.manage.PluginFilter;
import com.fr.plugin.observer.PluginEvent;
import com.fr.plugin.observer.PluginEventListener;
import com.fr.plugin.observer.PluginListenerRegistration;
import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.Icon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingWorker;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
/**
* Created with IntelliJ IDEA.
@ -45,19 +22,6 @@ import java.net.URISyntaxException;
* Time: 下午8:18
*/
public class FormWidgetDetailPane extends FormDockView{
private static final int LOCAL_WIDGET_LABEL_WIDTH = 90;
private UIScrollPane downPane;
private JPanel reuWidgetPanel;
private UIComboBox comboBox;
private SharableWidgetBindInfo[] elCaseBindInfoList;
private UIButton deleteButton;
private JPanel editPanel;
private JPanel resetPanel;
private JPanel menutPanelNorthPane;
private SwingWorker sw;
//组件面板是否可以编辑
private boolean isEdit;
public static FormWidgetDetailPane getInstance() {
if (HOLDER.singleton == null) {
@ -68,6 +32,7 @@ public class FormWidgetDetailPane extends FormDockView{
private FormWidgetDetailPane(){
setLayout(FRGUIPaneFactory.createBorderLayout());
listenPluginComponentPane();
}
@ -93,346 +58,52 @@ public class FormWidgetDetailPane extends FormDockView{
/**
* 初始化
*/
@Override
public void refreshDockingView(){
FormDesigner designer = this.getEditingFormDesigner();
removeAll();
if(designer == null){
clearDockingView();
return;
}
reuWidgetPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
reuWidgetPanel.setBorder(null);
if (elCaseBindInfoList == null) {
if (sw != null) {
sw.cancel(true);
}
sw = new SwingWorker() {
@Override
protected Object doInBackground() throws Exception {
elCaseBindInfoList = ShareLoader.getLoader().getAllBindInfoList();
refreshDownPanel(false);
return null;
}
};
sw.execute();
}
initReuWidgetPanel();
initMenuPanel();
add(reuWidgetPanel, BorderLayout.CENTER);
}
/**
* 初始化组件共享和复用面板
*/
private void initReuWidgetPanel() {
elCaseBindInfoList = ShareLoader.getLoader().getAllBindInfoList();
downPane = new UIScrollPane(new ShareWidgetPane(elCaseBindInfoList, false));
downPane.setBorder(null);
reuWidgetPanel.add(downPane);
}
/**
* 初始化菜单栏面板
*/
private void initMenuPanel() {
JPanel menutPanel = new JPanel();
menutPanel.setLayout(FRGUIPaneFactory.createBorderLayout());
menutPanel.setBorder(BorderFactory.createEmptyBorder(3, 10, 10, 15));
menutPanelNorthPane = new JPanel(new BorderLayout());
UILabel localWidgetLabel = FRWidgetFactory.createLineWrapLabel(
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Local_Widget"),
LOCAL_WIDGET_LABEL_WIDTH);
menutPanelNorthPane.add(localWidgetLabel, BorderLayout.WEST);
menutPanelNorthPane.add(initEditButtonPane(), BorderLayout.EAST);
menutPanelNorthPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
menutPanel.add(menutPanelNorthPane, BorderLayout.NORTH);
comboBox = new UIComboBox(getFormCategories());
comboBox.setPreferredSize(new Dimension(240, comboBox.getPreferredSize().height));
initComboBoxSelectedListener();
menutPanel.add(comboBox, BorderLayout.CENTER);
reuWidgetPanel.add(menutPanel, BorderLayout.NORTH);
}
/**
* 创建菜单栏按钮面板
*/
private JPanel initEditButtonPane() {
editPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 0));
editPanel.add(createRefreshButton());
editPanel.add(createDownloadButton());
editPanel.add(createInstallButton());
editPanel.add(createDeleteButton());
return editPanel;
initComponentPane();
}
/**
* 创建取消删除面板
*/
private JPanel initResetButtonPane() {
resetPanel = new JPanel();
UIButton resetButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Reset"));
resetPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
resetButton.setBackground(Color.white);
resetButton.setForeground(new Color(0x333334));
resetButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
refreshDownPanel(false);
replaceButtonPanel(false);
reuWidgetPanel.remove(deleteButton);
}
});
deleteButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Remove_Item"));
deleteButton.setBackground(Color.white);
deleteButton.setForeground(new Color(0xeb1d1f));
deleteButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (ShareLoader.getLoader().removeModulesFromList()) {
refreshShareMoudule();
reuWidgetPanel.remove(deleteButton);
elCaseBindInfoList = ShareLoader.getLoader().getAllBindInfoList();
JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Share_Module_Removed_Successful"));
refreshDownPanel(false);
replaceButtonPanel(false);
refreshComboxData();
} else {
JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Share_Module_Removed_Failed"));
}
}
});
JPanel deletePane = new JPanel(new BorderLayout());
deletePane.add(deleteButton, BorderLayout.CENTER);
deletePane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
resetPanel.setLayout(FRGUIPaneFactory.createBorderLayout());
resetPanel.add(resetButton, BorderLayout.CENTER);
resetPanel.add(deletePane, BorderLayout.WEST);
refreshDownPanel(true);
return resetPanel;
}
private void initComboBoxSelectedListener() {
comboBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
ShareLoader.getLoader().resetRemovedModuleList();
int filterIndex = comboBox.getSelectedIndex();
if (filterIndex == 0) {
elCaseBindInfoList = ShareLoader.getLoader().getAllBindInfoList();
} else {
String filterName = comboBox.getSelectedItem().toString();
elCaseBindInfoList = ShareLoader.getLoader().getFilterBindInfoList(filterName);
}
refreshDownPanel(isEdit);
}
});
}
/**
* 创建工具条按钮
*/
private UIButton createToolButton(Icon icon, String toolTip, ActionListener actionListener) {
UIButton toolButton = new UIButton();
toolButton.setIcon(icon);
toolButton.setToolTipText(toolTip);
toolButton.set4ToolbarButton();
toolButton.addActionListener(actionListener);
return toolButton;
}
private void listenPluginComponentPane() {
/**
* 创建刷新按钮
*/
private UIButton createRefreshButton() {
return createToolButton(
BaseUtils.readIcon("/com/fr/design/form/images/refresh.png"),
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Refresh"),
new ActionListener() {
PluginFilter filter = new PluginFilter() {
@Override
public void actionPerformed(ActionEvent e) {
if (sw != null) {
sw.cancel(true);
}
sw = new SwingWorker() {
@Override
protected Object doInBackground() throws Exception {
ShareLoader.getLoader().refreshModule();
elCaseBindInfoList = ShareLoader.getLoader().getAllBindInfoList();
refreshComboxData();
refreshDownPanel(false);
return null;
public boolean accept(PluginContext context) {
return context.contain(ComponentLibraryPaneProcessor.XML_TAG);
}
};
sw.execute();
}
}
);
}
private void refreshComboxData() {
comboBox.setSelectedIndex(0);
comboBox.setModel(new DefaultComboBoxModel(getFormCategories()));
}
/**
* 创建下载模板的按钮
*/
private UIButton createDownloadButton() {
UIButton downloadButton = new UIButton();
downloadButton.setIcon(BaseUtils.readIcon("/com/fr/design/form/images/download icon.png"));
downloadButton.set4ToolbarButton();
downloadButton.setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Download_Template"));
downloadButton.addActionListener(new ActionListener() {
PluginListenerRegistration.getInstance().listenRunningChanged(new PluginEventListener() {
@Override
public void actionPerformed(ActionEvent e) {
String url = CloudCenter.getInstance().acquireUrlByKind("reuse.url");
if (StringUtils.isEmpty(url)) {
FineLoggerFactory.getLogger().info("The URL is empty!");
return;
}
try {
Desktop.getDesktop().browse(new URI(url));
} catch (IOException exp) {
JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Set_Default_Browser_Duplicate"));
FineLoggerFactory.getLogger().error(exp.getMessage(), exp);
} catch (URISyntaxException exp) {
FineLoggerFactory.getLogger().error(exp.getMessage(), exp);
} catch (Exception exp) {
FineLoggerFactory.getLogger().error(exp.getMessage(), exp);
FineLoggerFactory.getLogger().error("Can not open the browser for URL: " + url);
public void on(PluginEvent event) {
refreshDockingView();
}
}
});
return downloadButton;
}, filter);
}
/**
* 创建安装模板的按钮
*/
private UIButton createInstallButton() {
return createToolButton(
BaseUtils.readIcon("/com/fr/design/form/images/install icon.png"),
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Install_Template"),
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
fileChooser.setFileFilter(new FileNameExtensionFilter(".reu", "reu"));
int returnValue = fileChooser.showDialog(new UILabel(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Select"));
if (returnValue == JFileChooser.APPROVE_OPTION) {
final File chosenFile = fileChooser.getSelectedFile();
installFromDiskZipFile(chosenFile);
}
}
}
);
}
private void initComponentPane() {
/**
* 创建删除模板的按钮
*/
private UIButton createDeleteButton() {
return createToolButton(
BaseUtils.readIcon("/com/fr/design/form/images/delete icon.png"),
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Delete_Template"),
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
replaceButtonPanel(true);
}
}
);
}
private void replaceButtonPanel(boolean isEdit) {
this.isEdit = isEdit;
if (isEdit) {
menutPanelNorthPane.remove(editPanel);
menutPanelNorthPane.add(initResetButtonPane(), BorderLayout.EAST);
} else {
menutPanelNorthPane.remove(resetPanel);
menutPanelNorthPane.add(initEditButtonPane(), BorderLayout.EAST);
ShareLoader.getLoader().resetRemovedModuleList();
}
}
private void installFromDiskZipFile(File chosenFile) {
if (chosenFile != null && chosenFile.getName().endsWith(ShareConstants.SUFFIX_MODULE)) {
try {
if (ShareLoader.getLoader().installModuleFromDiskZipFile(chosenFile)) {
refreshShareMoudule();
elCaseBindInfoList = ShareLoader.getLoader().getAllBindInfoList();
refreshDownPanel(false);
refreshComboxData();
JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Share_Module_OK"));
} else {
JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Share_Module_Error"));
}
} catch (IOException e) {
JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Share_Module_Error"));
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
}
private void refreshShareMoudule() {
try {
ShareLoader.getLoader().refreshModule();
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
/**
* 获取报表块组件分类
*/
public String[] getFormCategories() {
return ArrayUtils.addAll(new String[] {com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_AllCategories")}, ShareLoader.getLoader().getModuleCategory());
}
public void refreshDownPanel(boolean isEdit) {
reuWidgetPanel.remove(downPane);
downPane = new UIScrollPane(new ShareWidgetPane(elCaseBindInfoList, isEdit));
downPane.setBorder(null);
reuWidgetPanel.add(downPane);
repaintContainer();
}
public void repaintContainer() {
validate();
repaint();
revalidate();
ComponentLibraryPaneCreator creator = ComponentLibraryPaneCreator.getNew();
JPanel componentLibraryPane = creator.create(this);
add(componentLibraryPane, BorderLayout.CENTER);
}
/**
* 清除数据
*/
public void clearDockingView() {
JScrollPane psp = new JScrollPane();
psp.setBorder(null);
this.add(psp, BorderLayout.CENTER);
}
/**
* 定位
* @return 位置

23
designer-form/src/main/java/com/fr/design/mainframe/component/ComponentLibraryManager.java

@ -0,0 +1,23 @@
package com.fr.design.mainframe.component;
import com.fr.design.ExtraDesignClassManager;
import com.fr.design.fun.ComponentLibraryPaneProcessor;
import com.fr.design.mainframe.component.pane.ComponentLibraryPaneProcessorImpl;
/**
* created by Harrison on 2020/03/16
**/
public class ComponentLibraryManager {
private static ComponentLibraryPaneProcessor DEFAULT = new ComponentLibraryPaneProcessorImpl();
public static ComponentLibraryPaneProcessor selectPaneProcessor() {
ComponentLibraryPaneProcessor right = ExtraDesignClassManager.getInstance().getSingle(ComponentLibraryPaneProcessor.XML_TAG);
if (right == null || DEFAULT.layerIndex() > right.layerIndex()) {
right = DEFAULT;
}
return right;
}
}

68
designer-form/src/main/java/com/fr/design/mainframe/component/pane/ComponentLibraryPaneCreator.java

@ -0,0 +1,68 @@
package com.fr.design.mainframe.component.pane;
import com.fr.design.fun.ComponentLibraryPaneProcessor;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.DockingView;
import com.fr.design.mainframe.component.ComponentLibraryManager;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import java.awt.BorderLayout;
/**
* created by Harrison on 2020/03/22
**/
public class ComponentLibraryPaneCreator {
private ComponentLibraryPaneProcessor processor;
public ComponentLibraryPaneCreator() {
processor = ComponentLibraryManager.selectPaneProcessor();
}
public static ComponentLibraryPaneCreator getNew() {
return new ComponentLibraryPaneCreator();
}
public JPanel create(DockingView dockingView) {
JPanel componentLibPanel = createComponentLibPanel();
processor.parentView(dockingView);
processor.parentPane(componentLibPanel);
JPanel menuPanel = createMenuPanel();
componentLibPanel.add(menuPanel, BorderLayout.NORTH);
UIScrollPane showPane = processor.createShowPanel(false);
componentLibPanel.add(showPane);
return componentLibPanel;
}
private JPanel createComponentLibPanel() {
JPanel reuWidgetPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
reuWidgetPanel.setBorder(null);
return reuWidgetPanel;
}
/**
* 初始化菜单栏面板
*/
private JPanel createMenuPanel() {
JPanel menuPanel = new JPanel();
menuPanel.setLayout(FRGUIPaneFactory.createBorderLayout());
menuPanel.setBorder(BorderFactory.createEmptyBorder(3, 10, 10, 15));
JPanel menuPanelNorthPane = processor.createMenuNorthPane();
menuPanel.add(menuPanelNorthPane, BorderLayout.NORTH);
UIComboBox menuPanelComboBox = processor.createMenuComBox();
menuPanel.add(menuPanelComboBox, BorderLayout.CENTER);
return menuPanel;
}
}

412
designer-form/src/main/java/com/fr/design/mainframe/component/pane/ComponentLibraryPaneProcessorImpl.java

@ -0,0 +1,412 @@
package com.fr.design.mainframe.component.pane;
import com.fr.base.BaseUtils;
import com.fr.design.fun.impl.AbstractComponentLibraryPaneProcessor;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.DockingView;
import com.fr.design.mainframe.ShareWidgetPane;
import com.fr.design.widget.FRWidgetFactory;
import com.fr.form.share.ShareLoader;
import com.fr.form.ui.SharableWidgetBindInfo;
import com.fr.general.CloudCenter;
import com.fr.log.FineLoggerFactory;
import com.fr.share.ShareConstants;
import com.fr.stable.ArrayUtils;
import com.fr.stable.StringUtils;
import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.Icon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingWorker;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
/**
* created by Harrison on 2020/03/16
**/
public class ComponentLibraryPaneProcessorImpl extends AbstractComponentLibraryPaneProcessor {
private static final int LOCAL_WIDGET_LABEL_WIDTH = 90;
private DockingView parentView;
private SwingWorker sw;
private JPanel componentLibPane;
private UIScrollPane showPane;
private UIComboBox menuPanelComboBox;
private JPanel menuPanelNorthPane;
private SharableWidgetBindInfo[] bindInfoArray;
private UIButton deleteButton;
private JPanel editPanel;
private JPanel resetPanel;
/**
* 组件面板是否可以编辑
*/
private boolean isEdit;
public ComponentLibraryPaneProcessorImpl() {
}
@Override
public void parentView(DockingView dockingView) {
parentView = dockingView;
if (bindInfoArray == null) {
if (sw != null) {
sw.cancel(true);
}
sw = new SwingWorker() {
@Override
protected Object doInBackground() throws Exception {
bindInfoArray = ShareLoader.getLoader().getAllBindInfoList();
refreshShowPanel(false);
return null;
}
};
sw.execute();
}
}
@Override
public void parentPane(JPanel panel) {
this.componentLibPane = panel;
}
@Override
public void complete() {
}
/**
* 初始化组件共享和复用面板
*/
@Override
public UIScrollPane createShowPanel(boolean isEdit) {
showPane = new UIScrollPane(
new ShareWidgetPane(bindInfoArray, isEdit)
);
showPane.setBorder(null);
return showPane;
}
@Override
public UIComboBox createMenuComBox() {
menuPanelComboBox = new UIComboBox(getFormCategories());
menuPanelComboBox.setPreferredSize(new Dimension(240, menuPanelComboBox.getPreferredSize().height));
addComboBoxListener();
return menuPanelComboBox;
}
private void addComboBoxListener() {
menuPanelComboBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
ShareLoader.getLoader().resetRemovedModuleList();
int filterIndex = menuPanelComboBox.getSelectedIndex();
if (filterIndex == 0) {
bindInfoArray = ShareLoader.getLoader().getAllBindInfoList();
} else {
String filterName = menuPanelComboBox.getSelectedItem().toString();
bindInfoArray = ShareLoader.getLoader().getFilterBindInfoList(filterName);
}
refreshShowPanel(isEdit);
}
});
}
@Override
public JPanel createMenuNorthPane() {
menuPanelNorthPane = new JPanel(new BorderLayout());
UILabel localWidgetLabel = FRWidgetFactory.createLineWrapLabel(
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Local_Widget"),
LOCAL_WIDGET_LABEL_WIDTH);
menuPanelNorthPane.add(localWidgetLabel, BorderLayout.WEST);
menuPanelNorthPane.add(initEditButtonPane(), BorderLayout.EAST);
menuPanelNorthPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
return menuPanelNorthPane;
}
/**
* 创建菜单栏按钮面板
*/
protected JPanel initEditButtonPane() {
editPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 0));
editPanel.add(createRefreshButton());
editPanel.add(createDownloadButton());
editPanel.add(createInstallButton());
editPanel.add(createDeleteButton());
return editPanel;
}
/**
* 创建取消删除面板
*/
protected JPanel initResetButtonPane() {
resetPanel = new JPanel();
UIButton resetButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Reset"));
resetPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
resetButton.setBackground(Color.white);
resetButton.setForeground(new Color(0x333334));
resetButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
refreshShowPanel(false);
replaceButtonPanel(false);
componentLibPane.remove(deleteButton);
}
});
deleteButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Remove_Item"));
deleteButton.setBackground(Color.white);
deleteButton.setForeground(new Color(0xeb1d1f));
deleteButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (ShareLoader.getLoader().removeModulesFromList()) {
refreshShareModule();
componentLibPane.remove(deleteButton);
bindInfoArray = ShareLoader.getLoader().getAllBindInfoList();
JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Share_Module_Removed_Successful"));
refreshShowPanel(false);
replaceButtonPanel(false);
refreshComboBoxData();
} else {
JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Share_Module_Removed_Failed"));
}
}
});
JPanel deletePane = new JPanel(new BorderLayout());
deletePane.add(deleteButton, BorderLayout.CENTER);
deletePane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
resetPanel.setLayout(FRGUIPaneFactory.createBorderLayout());
resetPanel.add(resetButton, BorderLayout.CENTER);
resetPanel.add(deletePane, BorderLayout.WEST);
refreshShowPanel(true);
return resetPanel;
}
/**
* 创建工具条按钮
*/
protected UIButton createToolButton(Icon icon, String toolTip, ActionListener actionListener) {
UIButton toolButton = new UIButton();
toolButton.setIcon(icon);
toolButton.setToolTipText(toolTip);
toolButton.set4ToolbarButton();
toolButton.addActionListener(actionListener);
return toolButton;
}
/**
* 创建刷新按钮
*/
protected UIButton createRefreshButton() {
return createToolButton(
BaseUtils.readIcon("/com/fr/design/form/images/refresh.png"),
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Refresh"),
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (sw != null) {
sw.cancel(true);
}
sw = new SwingWorker() {
@Override
protected Object doInBackground() throws Exception {
ShareLoader.getLoader().refreshModule();
bindInfoArray = ShareLoader.getLoader().getAllBindInfoList();
refreshComboBoxData();
refreshShowPanel(false);
return null;
}
};
sw.execute();
}
}
);
}
/**
* 创建下载模板的按钮
*/
protected UIButton createDownloadButton() {
UIButton downloadButton = new UIButton();
downloadButton.setIcon(BaseUtils.readIcon("/com/fr/design/form/images/download icon.png"));
downloadButton.set4ToolbarButton();
downloadButton.setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Download_Template"));
downloadButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String url = CloudCenter.getInstance().acquireUrlByKind("reuse.url");
if (StringUtils.isEmpty(url)) {
FineLoggerFactory.getLogger().info("The URL is empty!");
return;
}
try {
Desktop.getDesktop().browse(new URI(url));
} catch (IOException exp) {
JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Set_Default_Browser_Duplicate"));
FineLoggerFactory.getLogger().error(exp.getMessage(), exp);
} catch (URISyntaxException exp) {
FineLoggerFactory.getLogger().error(exp.getMessage(), exp);
} catch (Exception exp) {
FineLoggerFactory.getLogger().error(exp.getMessage(), exp);
FineLoggerFactory.getLogger().error("Can not open the browser for URL: " + url);
}
}
});
return downloadButton;
}
/**
* 创建安装模板的按钮
*/
protected UIButton createInstallButton() {
return createToolButton(
BaseUtils.readIcon("/com/fr/design/form/images/install icon.png"),
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Install_Template"),
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
fileChooser.setFileFilter(new FileNameExtensionFilter(".reu", "reu"));
int returnValue = fileChooser.showDialog(new UILabel(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Select"));
if (returnValue == JFileChooser.APPROVE_OPTION) {
final File chosenFile = fileChooser.getSelectedFile();
installFromDiskZipFile(chosenFile);
}
}
}
);
}
/**
* 创建删除模板的按钮
*/
protected UIButton createDeleteButton() {
return createToolButton(
BaseUtils.readIcon("/com/fr/design/form/images/delete icon.png"),
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Delete_Template"),
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
replaceButtonPanel(true);
}
}
);
}
/**
* 获取报表块组件分类
*/
protected String[] getFormCategories() {
return ArrayUtils.addAll(new String[]{com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_AllCategories")}, ShareLoader.getLoader().getModuleCategory());
}
protected void refreshShowPanel(boolean isEdit) {
componentLibPane.remove(showPane);
showPane = createShowPanel(isEdit);
componentLibPane.add(showPane);
repaint();
}
private void refreshComboBoxData() {
menuPanelComboBox.setSelectedIndex(0);
menuPanelComboBox.setModel(new DefaultComboBoxModel(getFormCategories()));
}
private void replaceButtonPanel(boolean isEdit) {
this.isEdit = isEdit;
if (isEdit) {
menuPanelNorthPane.remove(editPanel);
menuPanelNorthPane.add(initResetButtonPane(), BorderLayout.EAST);
} else {
menuPanelNorthPane.remove(resetPanel);
menuPanelNorthPane.add(initEditButtonPane(), BorderLayout.EAST);
ShareLoader.getLoader().resetRemovedModuleList();
}
}
private void installFromDiskZipFile(File chosenFile) {
if (chosenFile != null && chosenFile.getName().endsWith(ShareConstants.SUFFIX_MODULE)) {
try {
if (ShareLoader.getLoader().installModuleFromDiskZipFile(chosenFile)) {
refreshShareModule();
bindInfoArray = ShareLoader.getLoader().getAllBindInfoList();
refreshShowPanel(false);
refreshComboBoxData();
JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Share_Module_OK"));
} else {
JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Share_Module_Error"));
}
} catch (IOException e) {
JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Share_Module_Error"));
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
}
private void refreshShareModule() {
try {
ShareLoader.getLoader().refreshModule();
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
public void repaint() {
parentView.validate();
parentView.repaint();
parentView.revalidate();
}
}
Loading…
Cancel
Save