Harrison
5 years ago
20 changed files with 1229 additions and 445 deletions
@ -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(); |
||||
|
||||
} |
@ -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; |
||||
} |
||||
} |
@ -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,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,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; |
||||
} |
||||
|
||||
} |
@ -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,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; |
||||
} |
||||
} |
@ -0,0 +1,9 @@
|
||||
package com.fr.design.notification; |
||||
|
||||
/** |
||||
* created by Harrison on 2020/03/16 |
||||
**/ |
||||
public interface SnapChatKey { |
||||
|
||||
String calc(); |
||||
} |
@ -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; |
||||
} |
||||
} |
@ -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; |
||||
} |
||||
} |
@ -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…
Reference in new issue