From fab281b2b2e0d4ffb822773e0d64c197adb24a80 Mon Sep 17 00:00:00 2001 From: plough Date: Mon, 13 Aug 2018 16:54:07 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-10045=20=E9=87=8D=E6=9E=84=20UIListContr?= =?UTF-8?q?olPane=20=E5=92=8C=20JListControlPane=EF=BC=88=E9=83=A8?= =?UTF-8?q?=E5=88=86=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/gui/controlpane/JControlPane.java | 77 +- .../gui/controlpane/JControlUpdatePane.java | 112 +++ .../gui/controlpane/JListControlPane.java | 554 ++++---------- .../controlpane/ListControlPaneHandlers.java | 71 ++ .../controlpane/ListControlPaneProvider.java | 14 + .../gui/controlpane/ObjectJControlPane.java | 2 +- .../gui/controlpane/ObjectUIControlPane.java | 2 +- .../controlpane/ShortCutListenerProvider.java | 15 + .../design/gui/controlpane/UIControlPane.java | 188 +---- .../gui/controlpane/UIListControlPane.java | 686 ++++-------------- .../AbstractShortCutFactory.java | 179 +++++ .../shortcutfactory/NewShortCutFactory.java | 172 +++++ .../shortcutfactory/OldShortCutFactory.java | 112 +++ .../src/main/java/com/fr/env/EnvListPane.java | 5 - .../component/VanChartHyperLinkPane.java | 18 +- .../component/VanChartShortCutFactory.java | 33 + .../VanChartConditionListControlPane.java | 2 +- .../background/AlertLineListControlPane.java | 6 +- .../background/BackgroundListControlPane.java | 6 +- ...VanChartStackedAndAxisListControlPane.java | 6 +- .../report/share/ConfusionManagerPane.java | 6 +- 21 files changed, 1061 insertions(+), 1205 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/gui/controlpane/JControlUpdatePane.java create mode 100644 designer-base/src/main/java/com/fr/design/gui/controlpane/ListControlPaneHandlers.java create mode 100644 designer-base/src/main/java/com/fr/design/gui/controlpane/ListControlPaneProvider.java create mode 100644 designer-base/src/main/java/com/fr/design/gui/controlpane/ShortCutListenerProvider.java create mode 100644 designer-base/src/main/java/com/fr/design/gui/controlpane/shortcutfactory/AbstractShortCutFactory.java create mode 100644 designer-base/src/main/java/com/fr/design/gui/controlpane/shortcutfactory/NewShortCutFactory.java create mode 100644 designer-base/src/main/java/com/fr/design/gui/controlpane/shortcutfactory/OldShortCutFactory.java create mode 100644 designer-chart/src/main/java/com/fr/van/chart/custom/component/VanChartShortCutFactory.java diff --git a/designer-base/src/main/java/com/fr/design/gui/controlpane/JControlPane.java b/designer-base/src/main/java/com/fr/design/gui/controlpane/JControlPane.java index 55201d639..172810f0e 100644 --- a/designer-base/src/main/java/com/fr/design/gui/controlpane/JControlPane.java +++ b/designer-base/src/main/java/com/fr/design/gui/controlpane/JControlPane.java @@ -17,24 +17,30 @@ import java.awt.*; * Date: 2016/5/17 * Time: 15:07 */ -public abstract class JControlPane extends BasicPane implements UnrepeatedNameHelper { - protected static final int SHORT_WIDTH = 30; //每加一个short Divider位置加30 - protected JPanel controlUpdatePane; +abstract class JControlPane extends BasicPane implements UnrepeatedNameHelper, ShortCutListenerProvider { + private static final int SHORT_WIDTH = 30; //每加一个short Divider位置加30 + JPanel controlUpdatePane; - private ShortCut4JControlPane[] shorts; - private NameableCreator[] creators; + ShortCut4JControlPane[] shorts; + NameableCreator[] creators; private ToolBarDef toolbarDef; - private UIToolbar toolBar; + UIToolbar toolBar; // peter:这是整体的一个cardLayout Pane protected CardLayout cardLayout; protected JPanel cardPane; + protected AbstractShortCutFactory shortCutFactory; - public JControlPane() { + JControlPane() { + this.initShortCutFactory(); this.initComponentPane(); } + protected void initShortCutFactory() { + this.shortCutFactory = OldShortCutFactory.newInstance(this); + } + /** * 生成添加按钮的NameableCreator * @@ -42,14 +48,10 @@ public abstract class JControlPane extends BasicPane implements UnrepeatedNameHe */ public abstract NameableCreator[] createNameableCreators(); - public ShortCut4JControlPane[] getShorts() { + ShortCut4JControlPane[] getShorts() { return shorts; } - public void setShorts(ShortCut4JControlPane[] shorts) { - this.shorts = shorts; - } - public void setCreators(NameableCreator[] creators) { this.creators = creators; } @@ -111,6 +113,15 @@ public abstract class JControlPane extends BasicPane implements UnrepeatedNameHe protected abstract JPanel createControlUpdatePane(); + protected void initToolBar() { + toolbarDef = new ToolBarDef(); + for (ShortCut4JControlPane sj : shorts) { + toolbarDef.addShortCut(sj.getShortCut()); + } + toolBar = ToolBarDef.createJToolBar(); + toolbarDef.updateToolBar(toolBar); + } + protected JPanel getLeftPane() { // LeftPane JPanel leftPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); @@ -122,12 +133,8 @@ public abstract class JControlPane extends BasicPane implements UnrepeatedNameHe return leftPane; } - toolbarDef = new ToolBarDef(); - for (ShortCut4JControlPane sj : shorts) { - toolbarDef.addShortCut(sj.getShortCut()); - } - toolBar = ToolBarDef.createJToolBar(); - toolbarDef.updateToolBar(toolBar); + initToolBar(); + leftPane.add(toolBar, BorderLayout.NORTH); return leftPane; } @@ -143,30 +150,10 @@ public abstract class JControlPane extends BasicPane implements UnrepeatedNameHe return shorts.length * SHORT_WIDTH; } - protected ShortCut4JControlPane[] createShortcuts() { - return new ShortCut4JControlPane[]{ - addItemShortCut(), - removeItemShortCut(), - copyItemShortCut(), - moveUpItemShortCut(), - moveDownItemShortCut(), - sortItemShortCut() - }; + return shortCutFactory.createShortCuts(); } - protected abstract ShortCut4JControlPane addItemShortCut(); - - protected abstract ShortCut4JControlPane removeItemShortCut(); - - protected abstract ShortCut4JControlPane copyItemShortCut(); - - protected abstract ShortCut4JControlPane moveUpItemShortCut(); - - protected abstract ShortCut4JControlPane moveDownItemShortCut(); - - protected abstract ShortCut4JControlPane sortItemShortCut(); - public abstract Nameable[] update(); @@ -179,10 +166,10 @@ public abstract class JControlPane extends BasicPane implements UnrepeatedNameHe public void checkButtonEnabled() { } - protected void doBeforeRemove() { + void doBeforeRemove() { } - protected void doAfterRemove() { + void doAfterRemove() { } public NameableCreator[] creators() { @@ -192,10 +179,10 @@ public abstract class JControlPane extends BasicPane implements UnrepeatedNameHe protected abstract boolean hasInvalid(boolean isAdd); /** - * 刷新 NameableCreator - * - * @param creators 生成器 - */ + * 刷新 NameableCreator + * + * @param creators 生成器 + */ public void refreshNameableCreator(NameableCreator[] creators) { this.creators = creators; shorts = this.createShortcuts(); diff --git a/designer-base/src/main/java/com/fr/design/gui/controlpane/JControlUpdatePane.java b/designer-base/src/main/java/com/fr/design/gui/controlpane/JControlUpdatePane.java new file mode 100644 index 000000000..177b2517d --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/gui/controlpane/JControlUpdatePane.java @@ -0,0 +1,112 @@ +package com.fr.design.gui.controlpane; + +import com.fr.design.beans.BasicBeanPane; +import com.fr.design.data.tabledata.tabledatapane.GlobalMultiTDTableDataPane; +import com.fr.design.data.tabledata.tabledatapane.GlobalTreeTableDataPane; +import com.fr.design.data.tabledata.tabledatapane.MultiTDTableDataPane; +import com.fr.design.data.tabledata.tabledatapane.TreeTableDataPane; +import com.fr.design.gui.ilist.ListModelElement; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.general.ComparatorUtils; + +import javax.swing.JPanel; +import java.awt.CardLayout; + +/** + * Created by plough on 2018/8/13. + */ +class JControlUpdatePane extends JPanel { + private ListControlPaneProvider listControlPane; + private CardLayout card; + private JPanel cardPane; + private BasicBeanPane[] updatePanes; + + private ListModelElement elEditing; + + private JControlUpdatePane(ListControlPaneProvider listControlPane) { + this.listControlPane = listControlPane; + initUpdatePane(); + } + + public static JControlUpdatePane newInstance(ListControlPaneProvider listControlPane) { + return new JControlUpdatePane(listControlPane); + } + + private void initUpdatePane() { + NameableCreator[] creators = listControlPane.creators(); + if (creators == null) { + return; + } + card = new CardLayout(); + cardPane = FRGUIPaneFactory.createCardLayout_S_Pane(); + cardPane.setLayout(card); + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + this.add(cardPane); + int len = creators.length; + updatePanes = new BasicBeanPane[len]; + } + + public BasicBeanPane[] getUpdatePanes() { + return updatePanes; + } + + public void populate() { + ListModelElement el = listControlPane.getSelectedElement(); + if (el == null) { + return; + } + + elEditing = el; + NameableCreator[] creators = listControlPane.creators(); + + for (int i = 0, len = updatePanes.length; i < len; i++) { + Object ob2Populate = creators[i].acceptObject2Populate(el.wrapper); + if (ob2Populate != null) { + if (updatePanes[i] == null) { + if (isMulti(creators[i].getUpdatePane()) || isTree(creators[i].getUpdatePane())) { + updatePanes[i] = listControlPane.createPaneByCreators(creators[i], el.wrapper.getName()); + } else { + updatePanes[i] = listControlPane.createPaneByCreators(creators[i]); + } + cardPane.add(updatePanes[i], String.valueOf(i)); + } + card.show(cardPane, String.valueOf(i)); + updatePanes[i].populateBean(ob2Populate); + break; + } + } + } + + + public boolean isMulti(Class _class) { + return ComparatorUtils.equals(_class, GlobalMultiTDTableDataPane.class) || ComparatorUtils.equals(_class, MultiTDTableDataPane.class); + } + + public boolean isTree(Class _class) { + return ComparatorUtils.equals(_class, GlobalTreeTableDataPane.class) || ComparatorUtils.equals(_class, TreeTableDataPane.class); + } + + public void update() { + NameableCreator[] creators = listControlPane.creators(); + for (int i = 0; i < updatePanes.length; i++) { + BasicBeanPane pane = updatePanes[i]; + + if (pane != null && pane.isVisible()) { + Object bean = pane.updateBean(); + if (i < creators.length) { + creators[i].saveUpdatedBean(elEditing, bean); + } + } + } + } + + public void checkValid() throws Exception { + if (updatePanes != null) { + for (int i = 0; i < updatePanes.length; i++) { + if (updatePanes[i] != null) { + updatePanes[i].checkValid(); + } + } + } + } +} \ No newline at end of file diff --git a/designer-base/src/main/java/com/fr/design/gui/controlpane/JListControlPane.java b/designer-base/src/main/java/com/fr/design/gui/controlpane/JListControlPane.java index efaf27a76..57f4ec1ab 100644 --- a/designer-base/src/main/java/com/fr/design/gui/controlpane/JListControlPane.java +++ b/designer-base/src/main/java/com/fr/design/gui/controlpane/JListControlPane.java @@ -2,21 +2,11 @@ package com.fr.design.gui.controlpane; import com.fr.base.BaseUtils; import com.fr.base.FRContext; -import com.fr.design.actions.UpdateAction; import com.fr.design.beans.BasicBeanPane; -import com.fr.design.data.tabledata.tabledatapane.GlobalMultiTDTableDataPane; -import com.fr.design.data.tabledata.tabledatapane.GlobalTreeTableDataPane; -import com.fr.design.data.tabledata.tabledatapane.MultiTDTableDataPane; -import com.fr.design.data.tabledata.tabledatapane.TreeTableDataPane; -import com.fr.design.gui.HyperlinkFilterHelper; import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.ilist.JNameEdList; import com.fr.design.gui.ilist.ListModelElement; import com.fr.design.gui.ilist.ModNameActionListener; -import com.fr.design.layout.FRGUIPaneFactory; -import com.fr.design.menu.LineSeparator; -import com.fr.design.menu.MenuDef; -import com.fr.design.menu.ShortCut; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.general.ComparatorUtils; import com.fr.general.IOUtils; @@ -25,19 +15,26 @@ import com.fr.stable.ArrayUtils; import com.fr.stable.Nameable; import com.fr.stable.core.PropertyChangeAdapter; -import javax.swing.*; +import javax.swing.DefaultListCellRenderer; +import javax.swing.DefaultListModel; +import javax.swing.JList; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JPopupMenu; +import javax.swing.ListSelectionModel; +import javax.swing.SwingUtilities; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; -import java.awt.*; -import java.awt.event.ActionEvent; +import java.awt.BorderLayout; +import java.awt.Component; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.util.Arrays; import java.util.Comparator; -public abstract class JListControlPane extends JControlPane { - public static final String LIST_NAME = "JControl_List"; +public abstract class JListControlPane extends JControlPane implements ListControlPaneProvider { + private static final String LIST_NAME = "JControl_List"; protected JNameEdList nameableList; protected int editingIndex; @@ -50,7 +47,7 @@ public abstract class JListControlPane extends JControlPane { @Override protected JPanel createControlUpdatePane() { - return new JControlUpdatePane(); + return JControlUpdatePane.newInstance(this); } /** @@ -87,7 +84,7 @@ public abstract class JListControlPane extends JControlPane { }); } - public JNameEdList createJNameList() { + protected JNameEdList createJNameList() { JNameEdList nameEdList = new JNameEdList(new DefaultListModel()) { @Override protected void doAfterLostFocus() { @@ -98,59 +95,10 @@ public abstract class JListControlPane extends JControlPane { return nameEdList; } - public void updateControlUpdatePane() { + private void updateControlUpdatePane() { ((JControlUpdatePane) controlUpdatePane).update(); } - protected void doWhenPopulate(BasicBeanPane beanPane) { - - } - - protected void doBeforePopulate(ListModelElement el, Object obj) { - - } - - @Override - protected ShortCut4JControlPane addItemShortCut() { - ShortCut addItemShortCut; - NameableCreator[] creators = creators(); - if (creators.length == 1) { - addItemShortCut = new AddItemUpdateAction(creators); - } else { - addItemShortCut = new AddItemMenuDef(creators); - } - return new AbsoluteEnableShortCut(addItemShortCut); - } - - @Override - protected ShortCut4JControlPane removeItemShortCut() { - return new NormalEnableShortCut(new RemoveItemAction()); - } - - @Override - protected ShortCut4JControlPane copyItemShortCut() { - return new NormalEnableShortCut(new CopyItemAction()); - } - - @Override - protected ShortCut4JControlPane moveUpItemShortCut() { - return new NormalEnableShortCut(new MoveUpItemAction()); - } - - @Override - protected ShortCut4JControlPane moveDownItemShortCut() { - return new NormalEnableShortCut(new MoveDownItemAction()); - } - - @Override - protected ShortCut4JControlPane sortItemShortCut() { - return new NormalEnableShortCut(new SortItemAction()); - } - - public void setNameListEditable(boolean editable) { - this.nameableList.setEditable(editable); - } - @Override public Nameable[] update() { java.util.List res = new java.util.ArrayList(); @@ -186,7 +134,7 @@ public abstract class JListControlPane extends JControlPane { * * @param l 名字改变时的监听 */ - public void addModNameActionListener(ModNameActionListener l) { + protected void addModNameActionListener(ModNameActionListener l) { this.nameableList.addModNameActionListener(l); } @@ -195,7 +143,7 @@ public abstract class JListControlPane extends JControlPane { * * @param l 监听 */ - public void addEditingListener(PropertyChangeAdapter l) { + protected void addEditingListener(PropertyChangeAdapter l) { this.nameableList.addEditingListner(l); } @@ -267,7 +215,7 @@ public abstract class JListControlPane extends JControlPane { * @param nameable 添加的Nameable * @param index 序号 */ - public void addNameable(Nameable nameable, int index) { + private void addNameable(Nameable nameable, int index) { JNameEdList nameEdList = JListControlPane.this.nameableList; DefaultListModel model = (DefaultListModel) nameEdList.getModel(); @@ -347,262 +295,152 @@ public abstract class JListControlPane extends JControlPane { } } - /** - * 增加项的UpdateAction - */ - protected class AddItemUpdateAction extends UpdateAction { - final NameableCreator creator; - - public AddItemUpdateAction(NameableCreator[] creators) { - this.creator = creators[0]; - this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Action_Add")); - this.setMnemonic('A'); - this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/buttonicon/add.png")); - } - - @Override - public void actionPerformed(ActionEvent e) { - Nameable nameable = creator.createNameable(JListControlPane.this); - - JListControlPane.this.addNameable(nameable, getModel().getSize()); + @Override + public void onAddItem(NameableCreator creator) { + if (hasInvalid(true)) { + return; } - } - - /* - * 增加项的MenuDef - */ - protected class AddItemMenuDef extends MenuDef { - public AddItemMenuDef(NameableCreator[] creators) { - this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Action_Add")); - this.setMnemonic('A'); - this.setIconPath("/com/fr/design/images/control/addPopup.png"); - wrapActionListener(creators); - } - - private void wrapActionListener(NameableCreator[] creators) { - for (final NameableCreator creator : creators) { - if (filterNameableCreator(creator)) { - continue; - } - boolean isTrue = ComparatorUtils.equals(creator.menuName(), com.fr.design.i18n.Toolkit.i18nText("Datasource-Stored_Procedure")) || - ComparatorUtils.equals(creator.menuName(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_DS_Relation_TableData")) || ComparatorUtils.equals(creator.menuName(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_DS_Multi_Dimensional_Database")); - if (isTrue) { - this.addShortCut(new LineSeparator()); - } - this.addShortCut(new UpdateAction() { - { - this.setName(creator.menuName()); - Icon icon = creator.menuIcon(); - if (icon != null) { - this.setSmallIcon(icon); - } - } - - @Override - public void actionPerformed(ActionEvent e) { - if (hasInvalid(true)) { - return; - } - - Nameable nameable = creator.createNameable(JListControlPane.this); - JListControlPane.this.addNameable(nameable, getModel().getSize()); - } - }); - } - } + Nameable nameable = creator.createNameable(JListControlPane.this); + JListControlPane.this.addNameable(nameable, getModel().getSize()); } - /* - * 移除item - */ - private class RemoveItemAction extends UpdateAction { - public RemoveItemAction() { - this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Action_Remove")); - this.setMnemonic('R'); - this.setSmallIcon(BaseUtils - .readIcon("/com/fr/base/images/cell/control/remove.png")); - } - - @Override - public void actionPerformed(ActionEvent evt) { - try { - JListControlPane.this.nameableList.getCellEditor() - .stopCellEditing(); - } catch (Exception ignored) { - } - // bug:在选中一个NameObject并删除,会遗留下Name. - doBeforeRemove(); - if (GUICoreUtils.removeJListSelectedNodes(SwingUtilities - .getWindowAncestor(JListControlPane.this), nameableList)) { - checkButtonEnabled(); - doAfterRemove(); - } + @Override + public void onRemoveItem() { + try { + JListControlPane.this.nameableList.getCellEditor() + .stopCellEditing(); + } catch (Exception ignored) { + } + // bug:在选中一个NameObject并删除,会遗留下Name. + doBeforeRemove(); + if (GUICoreUtils.removeJListSelectedNodes(SwingUtilities + .getWindowAncestor(JListControlPane.this), nameableList)) { + checkButtonEnabled(); + doAfterRemove(); } } - /* - * CopyItem - */ - private class CopyItemAction extends UpdateAction { - public CopyItemAction() { - this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Action_Copy")); - this.setMnemonic('C'); - this.setSmallIcon(BaseUtils - .readIcon("/com/fr/design/images/m_edit/copy.png")); + @Override + public void onCopyItem() { + // p:选中的值. + ListModelElement selectedValue = (ListModelElement) nameableList.getSelectedValue(); + if (selectedValue == null) { + return; } - @Override - public void actionPerformed(ActionEvent evt) { - // p:选中的值. - ListModelElement selectedValue = (ListModelElement) nameableList.getSelectedValue(); - if (selectedValue == null) { - return; - } - - ((JControlUpdatePane) controlUpdatePane).update(); + ((JControlUpdatePane) controlUpdatePane).update(); - Nameable selectedNameable = selectedValue.wrapper; + Nameable selectedNameable = selectedValue.wrapper; - // p: 用反射机制实现 - try { - Nameable newNameable = (Nameable) BaseUtils.cloneObject(selectedNameable); - newNameable.setName(createUnrepeatedCopyName(selectedNameable.getName())); + // p: 用反射机制实现 + try { + Nameable newNameable = (Nameable) BaseUtils.cloneObject(selectedNameable); + newNameable.setName(createUnrepeatedCopyName(selectedNameable.getName())); - JListControlPane.this.addNameable(newNameable, nameableList.getSelectedIndex() + 1); - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage(), e); - } + JListControlPane.this.addNameable(newNameable, nameableList.getSelectedIndex() + 1); + } catch (Exception e) { + FRContext.getLogger().error(e.getMessage(), e); } } - /* - * 上移Item - */ - private class MoveUpItemAction extends UpdateAction { - public MoveUpItemAction() { - this.setName(com.fr.design.i18n.Toolkit.i18nText("Utils-Move_Up")); - this.setMnemonic('U'); - this.setSmallIcon(BaseUtils - .readIcon("/com/fr/design/images/control/up.png")); + @Override + public void onMoveUpItem() { + int selectedIndex = nameableList.getSelectedIndex(); + if (selectedIndex == -1) { + return; } - @Override - public void actionPerformed(ActionEvent evt) { - int selectedIndex = nameableList.getSelectedIndex(); - if (selectedIndex == -1) { - return; - } - - // 上移 - if (selectedIndex > 0) { - DefaultListModel listModel = (DefaultListModel) nameableList - .getModel(); + // 上移 + if (selectedIndex > 0) { + DefaultListModel listModel = (DefaultListModel) nameableList + .getModel(); - Object selecteObj1 = listModel.get(selectedIndex - 1); - listModel.set(selectedIndex - 1, listModel.get(selectedIndex)); - listModel.set(selectedIndex, selecteObj1); + Object selecteObj1 = listModel.get(selectedIndex - 1); + listModel.set(selectedIndex - 1, listModel.get(selectedIndex)); + listModel.set(selectedIndex, selecteObj1); - nameableList.setSelectedIndex(selectedIndex - 1); - nameableList.ensureIndexIsVisible(selectedIndex - 1); - } + nameableList.setSelectedIndex(selectedIndex - 1); + nameableList.ensureIndexIsVisible(selectedIndex - 1); } } - /* - * 下移Item - */ - private class MoveDownItemAction extends UpdateAction { - public MoveDownItemAction() { - this.setName(com.fr.design.i18n.Toolkit.i18nText("Utils-Move_Down")); - this.setMnemonic('D'); - this.setSmallIcon(BaseUtils - .readIcon("/com/fr/design/images/control/down.png")); + @Override + public void onMoveDownItem() { + int selectedIndex = nameableList.getSelectedIndex(); + if (selectedIndex == -1) { + return; } - @Override - public void actionPerformed(ActionEvent evt) { - int selectedIndex = nameableList.getSelectedIndex(); - if (selectedIndex == -1) { - return; - } - - if (selectedIndex < nameableList.getModel().getSize() - 1) { - DefaultListModel listModel = (DefaultListModel) nameableList - .getModel(); + if (selectedIndex < nameableList.getModel().getSize() - 1) { + DefaultListModel listModel = (DefaultListModel) nameableList + .getModel(); - Object selecteObj1 = listModel.get(selectedIndex + 1); - listModel.set(selectedIndex + 1, listModel.get(selectedIndex)); - listModel.set(selectedIndex, selecteObj1); + Object selecteObj1 = listModel.get(selectedIndex + 1); + listModel.set(selectedIndex + 1, listModel.get(selectedIndex)); + listModel.set(selectedIndex, selecteObj1); - nameableList.setSelectedIndex(selectedIndex + 1); - nameableList.ensureIndexIsVisible(selectedIndex + 1); - } + nameableList.setSelectedIndex(selectedIndex + 1); + nameableList.ensureIndexIsVisible(selectedIndex + 1); } } - private class SortItemAction extends UpdateAction { - private boolean isAtoZ = false; - - public SortItemAction() { - this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Action_Sort")); - this.setMnemonic('S'); - this.setSmallIcon(BaseUtils - .readIcon("/com/fr/design/images/control/sortAsc.png")); + @Override + public void onSortItem(boolean isAtoZ) { + // p:选中的值. + Object selectedValue = nameableList.getSelectedValue(); + + DefaultListModel listModel = (DefaultListModel) nameableList + .getModel(); + Nameable[] nameableArray = new Nameable[listModel.getSize()]; + if (nameableArray.length <= 0) { + return; } - @Override - public void actionPerformed(ActionEvent evt) { - // p:选中的值. - Object selectedValue = nameableList.getSelectedValue(); - - DefaultListModel listModel = (DefaultListModel) nameableList - .getModel(); - Nameable[] nameableArray = new Nameable[listModel.getSize()]; - if (nameableArray.length <= 0) { - return; - } + for (int i = 0; i < listModel.getSize(); i++) { + nameableArray[i] = ((ListModelElement) listModel.getElementAt(i)).wrapper; + } - for (int i = 0; i < listModel.getSize(); i++) { - nameableArray[i] = ((ListModelElement) listModel.getElementAt(i)).wrapper; - } + // p:排序. + if (isAtoZ) { + Comparator nameableComparator = new Comparator() { + @Override + public int compare(Nameable o1, Nameable o2) { + return -ComparatorUtils.compare(o1.getName(), o2 + .getName()); + } + }; + isAtoZ = !isAtoZ; + Arrays.sort(nameableArray, nameableComparator); + } else { + Comparator nameableComparator = new Comparator() { + @Override + public int compare(Nameable o1, Nameable o2) { + return ComparatorUtils.compare(o1.getName(), o2 + .getName()); + } + }; + isAtoZ = !isAtoZ; + Arrays.sort(nameableArray, nameableComparator); + } - // p:排序. - if (isAtoZ) { - Comparator nameableComparator = new Comparator() { - @Override - public int compare(Nameable o1, Nameable o2) { - return -ComparatorUtils.compare(o1.getName(), o2 - .getName()); - } - }; - isAtoZ = !isAtoZ; - Arrays.sort(nameableArray, nameableComparator); - } else { - Comparator nameableComparator = new Comparator() { - @Override - public int compare(Nameable o1, Nameable o2) { - return ComparatorUtils.compare(o1.getName(), o2 - .getName()); - } - }; - isAtoZ = !isAtoZ; - Arrays.sort(nameableArray, nameableComparator); - } + for (int i = 0; i < nameableArray.length; i++) { + listModel.set(i, new ListModelElement(nameableArray[i])); + } - for (int i = 0; i < nameableArray.length; i++) { - listModel.set(i, new ListModelElement(nameableArray[i])); - } + // p:需要选中以前的那个值. + if (selectedValue != null) { + nameableList.setSelectedValue(selectedValue, true); + } - // p:需要选中以前的那个值. - if (selectedValue != null) { - nameableList.setSelectedValue(selectedValue, true); - } + checkButtonEnabled(); + // p:需要repaint. + nameableList.repaint(); + } - checkButtonEnabled(); - // p:需要repaint. - nameableList.repaint(); - } + @Override + public boolean isItemSelected() { + return getModel().getSize() > 0 && nameableList.getSelectedIndex() != -1; } /* @@ -690,129 +528,13 @@ public abstract class JListControlPane extends JControlPane { } } - public class AbsoluteEnableShortCut extends ShortCut4JControlPane { - public AbsoluteEnableShortCut(ShortCut shortCut) { - this.shortCut = shortCut; - } - - /** - * 检查是否可用 - */ - @Override - public void checkEnable() { - this.shortCut.setEnabled(true); - } - } - - public class NormalEnableShortCut extends ShortCut4JControlPane { - public NormalEnableShortCut(ShortCut shortCut) { - this.shortCut = shortCut; - } - - /** - * 检查是否可用 - */ - @Override - public void checkEnable() { - this.shortCut.setEnabled(getModel() - .getSize() > 0 - && JListControlPane.this.nameableList.getSelectedIndex() != -1); - } - } - - - private class JControlUpdatePane extends JPanel { - private CardLayout card; - private JPanel cardPane; - private BasicBeanPane[] updatePanes; - - private ListModelElement elEditing; - - public JControlUpdatePane() { - initUpdatePane(); - } - - private void initUpdatePane() { - NameableCreator[] creators = creators(); - if (creators == null) { - return; - } - card = new CardLayout(); - cardPane = FRGUIPaneFactory.createCardLayout_S_Pane(); - cardPane.setLayout(card); - this.setLayout(FRGUIPaneFactory.createBorderLayout()); - this.add(cardPane); - int len = creators.length; - updatePanes = new BasicBeanPane[len]; - } - - public void populate() { - ListModelElement el = (ListModelElement) JListControlPane.this.nameableList.getSelectedValue(); - if (el == null) { - return; - } - - elEditing = el; - NameableCreator[] creators = creators(); - - for (int i = 0, len = updatePanes.length; i < len; i++) { - Object ob2Populate = creators[i].acceptObject2Populate(el.wrapper); - if (ob2Populate != null) { - if (updatePanes[i] == null) { - if (isMulti(creators[i].getUpdatePane()) || isTree(creators[i].getUpdatePane())) { - updatePanes[i] = createPaneByCreators(creators[i], el.wrapper.getName()); - } else { - updatePanes[i] = createPaneByCreators(creators[i]); - } - cardPane.add(updatePanes[i], String.valueOf(i)); - } - card.show(cardPane, String.valueOf(i)); - doBeforePopulate(el, ob2Populate); - updatePanes[i].populateBean(ob2Populate); - doWhenPopulate(updatePanes[i]); - break; - } - } - } - - public boolean isMulti(Class _class) { - return ComparatorUtils.equals(_class, GlobalMultiTDTableDataPane.class) || ComparatorUtils.equals(_class, MultiTDTableDataPane.class); - } - - public boolean isTree(Class _class) { - return ComparatorUtils.equals(_class, GlobalTreeTableDataPane.class) || ComparatorUtils.equals(_class, TreeTableDataPane.class); - } - - public void update() { - NameableCreator[] creators = creators(); - for (int i = 0; i < updatePanes.length; i++) { - BasicBeanPane pane = updatePanes[i]; - - if (pane != null && pane.isVisible()) { - Object bean = pane.updateBean(); - if (i < creators.length) { - creators[i].saveUpdatedBean(elEditing, bean); - } - } - } - } - - public void checkValid() throws Exception { - if (updatePanes != null) { - for (int i = 0; i < updatePanes.length; i++) { - if (updatePanes[i] != null) { - updatePanes[i].checkValid(); - } - } - } - } - } - - protected BasicBeanPane createPaneByCreators(NameableCreator creator) { + @Override + public BasicBeanPane createPaneByCreators(NameableCreator creator) { return Reflect.on(creator.getUpdatePane()).create().get(); } - private BasicBeanPane createPaneByCreators(NameableCreator creator, String string) { + @Override + public BasicBeanPane createPaneByCreators(NameableCreator creator, String string) { return Reflect.on(creator.getUpdatePane()).create(string).get(); } @@ -827,7 +549,7 @@ public abstract class JListControlPane extends JControlPane { } private int getInValidIndex() { - BasicBeanPane[] p = ((JControlUpdatePane) controlUpdatePane).updatePanes; + BasicBeanPane[] p = ((JControlUpdatePane) controlUpdatePane).getUpdatePanes(); if (p != null) { for (int i = 0; i < p.length; i++) { if (p[i] != null) { @@ -866,12 +588,8 @@ public abstract class JListControlPane extends JControlPane { nameableList.setSelectedIndex(index); } - - /** - * 用于在list面板中,过滤某些下拉选项 - * @return true:过滤掉这个creator - */ - protected boolean filterNameableCreator(NameableCreator creator) { - return !HyperlinkFilterHelper.whetherAddHyperlink4cell(creator.menuName()); + @Override + public ListModelElement getSelectedElement() { + return (ListModelElement) JListControlPane.this.nameableList.getSelectedValue(); } } diff --git a/designer-base/src/main/java/com/fr/design/gui/controlpane/ListControlPaneHandlers.java b/designer-base/src/main/java/com/fr/design/gui/controlpane/ListControlPaneHandlers.java new file mode 100644 index 000000000..868f97e0b --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/gui/controlpane/ListControlPaneHandlers.java @@ -0,0 +1,71 @@ +package com.fr.design.gui.controlpane; + +import com.fr.design.gui.ilist.ListModelElement; +import com.fr.general.ComparatorUtils; +import com.fr.stable.ArrayUtils; +import com.fr.stable.Nameable; + +import javax.swing.DefaultListModel; + +/** + * Created by plough on 2018/8/13. + */ +public class ListControlPaneHandlers { + ListControlPaneProvider listControlPane; + + private ListControlPaneHandlers(ListControlPaneProvider listControlPane) { + this.listControlPane = listControlPane; + } + + public ListControlPaneHandlers newInstance(ListControlPaneProvider listControlPane) { + return new ListControlPaneHandlers(listControlPane); + } + + + private String createUnrepeatedCopyName(String suffix) { + DefaultListModel model = listControlPane.getModel(); + String[] names = new String[model.getSize()]; + for (int i = 0; i < model.size(); i++) { + names[i] = ((ListModelElement) model.get(i)).wrapper.getName(); + } + String lastName = "CopyOf" + suffix; + while (ArrayUtils.contains(names, lastName)) { + lastName = "CopyOf" + lastName; + } + return lastName; + } + + + /** + * 生成不重复的名字 + * + * @param prefix 名字前缀 + * @return 名字 + */ + public String createUnrepeatedName(String prefix) { + DefaultListModel model = listControlPane.getModel(); + Nameable[] all = new Nameable[model.getSize()]; + for (int i = 0; i < model.size(); i++) { + all[i] = ((ListModelElement) model.get(i)).wrapper; + } + // richer:生成的名字从1开始. kunsnat: 添加属性从0开始. + int count = all.length + 1; + while (true) { + String name_test = prefix + count; + boolean repeated = false; + for (int i = 0, len = model.size(); i < len; i++) { + Nameable nameable = all[i]; + if (ComparatorUtils.equals(nameable.getName(), name_test)) { + repeated = true; + break; + } + } + + if (!repeated) { + return name_test; + } + + count++; + } + } +} diff --git a/designer-base/src/main/java/com/fr/design/gui/controlpane/ListControlPaneProvider.java b/designer-base/src/main/java/com/fr/design/gui/controlpane/ListControlPaneProvider.java new file mode 100644 index 000000000..43dcd7260 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/gui/controlpane/ListControlPaneProvider.java @@ -0,0 +1,14 @@ +package com.fr.design.gui.controlpane; + +import com.fr.design.beans.BasicBeanPane; +import com.fr.design.gui.ilist.ListModelElement; + +/** + * Created by plough on 2018/8/13. + */ +public interface ListControlPaneProvider { + NameableCreator[] creators(); + ListModelElement getSelectedElement(); + BasicBeanPane createPaneByCreators(NameableCreator creator); + BasicBeanPane createPaneByCreators(NameableCreator creator, String string); +} diff --git a/designer-base/src/main/java/com/fr/design/gui/controlpane/ObjectJControlPane.java b/designer-base/src/main/java/com/fr/design/gui/controlpane/ObjectJControlPane.java index 2fd680a9c..5fc72214c 100644 --- a/designer-base/src/main/java/com/fr/design/gui/controlpane/ObjectJControlPane.java +++ b/designer-base/src/main/java/com/fr/design/gui/controlpane/ObjectJControlPane.java @@ -22,7 +22,7 @@ public abstract class ObjectJControlPane extends JListControlPane { } @Override - protected BasicBeanPane createPaneByCreators(NameableCreator creator) { + public BasicBeanPane createPaneByCreators(NameableCreator creator) { try { return Reflect.on(creator.getUpdatePane()).create(object).get(); } catch (Exception e) { diff --git a/designer-base/src/main/java/com/fr/design/gui/controlpane/ObjectUIControlPane.java b/designer-base/src/main/java/com/fr/design/gui/controlpane/ObjectUIControlPane.java index 3b2a1b071..4cfad0c57 100644 --- a/designer-base/src/main/java/com/fr/design/gui/controlpane/ObjectUIControlPane.java +++ b/designer-base/src/main/java/com/fr/design/gui/controlpane/ObjectUIControlPane.java @@ -20,7 +20,7 @@ public abstract class ObjectUIControlPane extends UIListControlPane { } @Override - protected BasicBeanPane createPaneByCreators(NameableCreator creator) { + public BasicBeanPane createPaneByCreators(NameableCreator creator) { try { if (object == null) { return super.createPaneByCreators(creator); diff --git a/designer-base/src/main/java/com/fr/design/gui/controlpane/ShortCutListenerProvider.java b/designer-base/src/main/java/com/fr/design/gui/controlpane/ShortCutListenerProvider.java new file mode 100644 index 000000000..5ee93bd47 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/gui/controlpane/ShortCutListenerProvider.java @@ -0,0 +1,15 @@ +package com.fr.design.gui.controlpane; + +/** + * Created by plough on 2018/8/12. + */ +public interface ShortCutListenerProvider { + void onAddItem(NameableCreator creator); + void onRemoveItem(); + void onCopyItem(); + void onMoveUpItem(); + void onMoveDownItem(); + void onSortItem(boolean isAtoZ); + boolean isItemSelected(); + NameableCreator[] creators(); +} \ No newline at end of file diff --git a/designer-base/src/main/java/com/fr/design/gui/controlpane/UIControlPane.java b/designer-base/src/main/java/com/fr/design/gui/controlpane/UIControlPane.java index d0a4c12c5..546aceb55 100644 --- a/designer-base/src/main/java/com/fr/design/gui/controlpane/UIControlPane.java +++ b/designer-base/src/main/java/com/fr/design/gui/controlpane/UIControlPane.java @@ -2,7 +2,6 @@ package com.fr.design.gui.controlpane; import com.fr.base.chart.BasePlot; import com.fr.design.constants.UIConstants; -import com.fr.design.dialog.BasicPane; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itoolbar.UIToolBarUI; import com.fr.design.gui.itoolbar.UIToolbar; @@ -11,10 +10,8 @@ import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.mainframe.DesignerContext; import com.fr.design.menu.ShortCut; -import com.fr.design.menu.ToolBarDef; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.stable.ArrayUtils; -import com.fr.stable.Nameable; import com.fr.stable.StringUtils; import javax.swing.BorderFactory; @@ -49,85 +46,30 @@ import java.awt.event.WindowEvent; /** * Created by plough on 2017/7/21. */ -public abstract class UIControlPane extends BasicPane implements UnrepeatedNameHelper { - protected static final int SHORT_WIDTH = 30; //每加一个short Divider位置加30 - protected JPanel controlUpdatePane; - private ShortCut4JControlPane[] shorts; - private NameableCreator[] creators; - private ToolBarDef toolbarDef; - private UIToolbar toolBar; +abstract class UIControlPane extends JControlPane { private UIToolbar topToolBar; protected Window popupEditDialog; - // peter:这是整体的一个cardLayout Pane - protected CardLayout cardLayout; - protected JPanel cardPane; protected BasePlot plot; private static final int TOP_TOOLBAR_HEIGHT = 20; private static final int TOP_TOOLBAR_WIDTH = 156; // 可能因为用了tablelayout,要比其他地方多一个像素,看起来才正常 private static final int TOP_TOOLBAR_WIDTH_SHORT = 76; - public UIControlPane() { - this.initComponentPane(); + UIControlPane() { + super(); } - public UIControlPane(BasePlot plot) { + UIControlPane(BasePlot plot) { + super(); this.plot = plot; - this.initComponentPane(); } - /** - * 生成添加按钮的NameableCreator - * - * @return 按钮的NameableCreator - */ - public abstract NameableCreator[] createNameableCreators(); - - public ShortCut4JControlPane[] getShorts() { - return shorts; - } - - public void setShorts(ShortCut4JControlPane[] shorts) { - this.shorts = shorts; - } - - public void setCreators(NameableCreator[] creators) { - this.creators = creators; - } - - public ToolBarDef getToolbarDef() { - return toolbarDef; - } - - public void setToolbarDef(ToolBarDef toolbarDef) { - this.toolbarDef = toolbarDef; - } - - public UIToolbar getToolBar() { - return toolBar; - } - - public void setToolBar(UIToolbar toolBar) { - this.toolBar = toolBar; - } - - public CardLayout getCardLayout() { - return cardLayout; - } - - public void setCardLayout(CardLayout cardLayout) { - this.cardLayout = cardLayout; - } - - public JPanel getCardPane() { - return cardPane; - } + public abstract void saveSettings(); - public void setCardPane(JPanel cardPane) { - this.cardPane = cardPane; + @Override + protected void initShortCutFactory() { + this.shortCutFactory = NewShortCutFactory.newInstance(this); } - public abstract void saveSettings(); - // 是否使用新样式 protected boolean isNewStyle() { return true; @@ -169,11 +111,22 @@ public abstract class UIControlPane extends BasicPane implements UnrepeatedNameH this.checkButtonEnabled(); } - protected void getPopupEditDialog(JPanel cardPane) { + private void getPopupEditDialog(JPanel cardPane) { popupEditDialog = new PopupEditDialog(cardPane); } - protected abstract JPanel createControlUpdatePane(); + @Override + protected void initToolBar() { + super.initToolBar(); + toolBar.setUI(new UIToolBarUI() { + @Override + public void paint(Graphics g, JComponent c) { + Graphics2D g2 = (Graphics2D) g; + g2.setColor(Color.WHITE); + g2.fillRect(0, 0, c.getWidth(), c.getHeight()); + } + }); + } protected JPanel getLeftPane() { // LeftPane @@ -188,20 +141,8 @@ public abstract class UIControlPane extends BasicPane implements UnrepeatedNameH return leftPane; } - toolbarDef = new ToolBarDef(); - for (ShortCut4JControlPane sj : shorts) { - toolbarDef.addShortCut(sj.getShortCut()); - } - toolBar = ToolBarDef.createJToolBar(); - toolBar.setUI(new UIToolBarUI() { - @Override - public void paint(Graphics g, JComponent c) { - Graphics2D g2 = (Graphics2D) g; - g2.setColor(Color.WHITE); - g2.fillRect(0, 0, c.getWidth(), c.getHeight()); - } - }); - toolbarDef.updateToolBar(toolBar); + initToolBar(); + // 封装一层,加边框 JPanel toolBarPane = new JPanel(new BorderLayout()); toolBarPane.add(toolBar, BorderLayout.CENTER); @@ -220,7 +161,7 @@ public abstract class UIControlPane extends BasicPane implements UnrepeatedNameH }); topToolBar.setBorder(null); topToolBar.setLayout(new BorderLayout()); - ShortCut addItem = addItemShortCut().getShortCut(); + ShortCut addItem = shortCutFactory.addItemShortCut().getShortCut(); addItem.intoJToolBar(topToolBar); JPanel leftTopPane = getLeftTopPane(topToolBar); @@ -249,85 +190,22 @@ public abstract class UIControlPane extends BasicPane implements UnrepeatedNameH return "add item "; } - /** - * 初始化左边面板 - */ - protected void initLeftPane(JPanel leftPane) { - - } - - protected int getLeftPreferredSize() { - return shorts.length * SHORT_WIDTH; - } - - protected ShortCut4JControlPane[] createShortcuts() { - return new ShortCut4JControlPane[]{ - copyItemShortCut(), - moveUpItemShortCut(), - moveDownItemShortCut(), - sortItemShortCut(), - removeItemShortCut() - }; - } - - protected abstract ShortCut4JControlPane addItemShortCut(); - - protected abstract ShortCut4JControlPane removeItemShortCut(); - - protected abstract ShortCut4JControlPane copyItemShortCut(); - - protected abstract ShortCut4JControlPane moveUpItemShortCut(); - - protected abstract ShortCut4JControlPane moveDownItemShortCut(); - - protected abstract ShortCut4JControlPane sortItemShortCut(); - - public abstract Nameable[] update(); - - - public void populate(Nameable[] nameableArray) { +// return AbstractShortCutFactory.getInstance(this).createNewShortCuts(); + return shortCutFactory.createShortCuts(); } - /** - * 检查按钮可用状态 Check button enabled. - */ - public void checkButtonEnabled() { - } - - protected void doBeforeRemove() { - } - - protected void doAfterRemove() { - } - - public NameableCreator[] creators() { - return creators == null ? new NameableCreator[0] : creators; - } - - protected abstract boolean hasInvalid(boolean isAdd); - /** * 刷新 NameableCreator * * @param creators 生成器 */ public void refreshNameableCreator(NameableCreator[] creators) { - this.creators = creators; - shorts = this.createShortcuts(); - toolbarDef.clearShortCuts(); - for (ShortCut4JControlPane sj : shorts) { - toolbarDef.addShortCut(sj.getShortCut()); - } - - toolbarDef.updateToolBar(toolBar); - toolBar.validate(); - toolBar.repaint(); - + super.refreshNameableCreator(creators); // 顶部按钮 topToolBar.removeAll(); - ShortCut addItem = addItemShortCut().getShortCut(); + ShortCut addItem = shortCutFactory.addItemShortCut().getShortCut(); addItem.intoJToolBar(topToolBar); topToolBar.validate(); this.controlUpdatePane = createControlUpdatePane();//REPORT-4841 刷新一下编辑面板 @@ -337,13 +215,13 @@ public abstract class UIControlPane extends BasicPane implements UnrepeatedNameH } // 点击"编辑"按钮,弹出面板 - protected class PopupEditDialog extends JDialog { + class PopupEditDialog extends JDialog { private JComponent editPane; private PopupToolPane popupToolPane; private static final int WIDTH = 570; private static final int HEIGHT = 490; - public PopupEditDialog(JComponent pane) { + PopupEditDialog(JComponent pane) { super(DesignerContext.getDesignerFrame()); setUndecorated(true); pane.setBorder(BorderFactory.createEmptyBorder(20, 10, 10, 10)); @@ -475,11 +353,11 @@ public abstract class UIControlPane extends BasicPane implements UnrepeatedNameH } }; - public PopupToolPane(JDialog parentDialog) { + PopupToolPane(JDialog parentDialog) { this(StringUtils.EMPTY, parentDialog); } - public PopupToolPane(String title, JDialog parentDialog) { + PopupToolPane(String title, JDialog parentDialog) { super(); this.parentDialog = parentDialog; originColor = UIConstants.DIALOG_TITLEBAR_BACKGROUND; diff --git a/designer-base/src/main/java/com/fr/design/gui/controlpane/UIListControlPane.java b/designer-base/src/main/java/com/fr/design/gui/controlpane/UIListControlPane.java index 1c938b362..9de012bbf 100644 --- a/designer-base/src/main/java/com/fr/design/gui/controlpane/UIListControlPane.java +++ b/designer-base/src/main/java/com/fr/design/gui/controlpane/UIListControlPane.java @@ -3,39 +3,37 @@ package com.fr.design.gui.controlpane; import com.fr.base.BaseUtils; import com.fr.base.FRContext; import com.fr.base.chart.BasePlot; -import com.fr.design.actions.UpdateAction; -import com.fr.design.actions.core.ActionFactory; import com.fr.design.beans.BasicBeanPane; import com.fr.design.constants.UIConstants; -import com.fr.design.data.tabledata.tabledatapane.GlobalMultiTDTableDataPane; -import com.fr.design.data.tabledata.tabledatapane.GlobalTreeTableDataPane; -import com.fr.design.data.tabledata.tabledatapane.MultiTDTableDataPane; -import com.fr.design.data.tabledata.tabledatapane.TreeTableDataPane; -import com.fr.design.gui.HyperlinkFilterHelper; -import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.ilist.ListModelElement; import com.fr.design.gui.ilist.UINameEdList; -import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.DesignerContext; -import com.fr.design.menu.LineSeparator; -import com.fr.design.menu.MenuDef; -import com.fr.design.menu.ShortCut; -import com.fr.design.menu.ToolBarDef; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.general.ComparatorUtils; - import com.fr.stable.ArrayUtils; import com.fr.stable.Nameable; -import com.fr.stable.StringUtils; -import javax.swing.*; +import javax.swing.DefaultListModel; +import javax.swing.JList; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JPopupMenu; +import javax.swing.ListSelectionModel; +import javax.swing.SwingUtilities; import javax.swing.event.ListDataEvent; import javax.swing.event.ListDataListener; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; -import java.awt.*; -import java.awt.event.*; +import java.awt.BorderLayout; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Toolkit; +import java.awt.Window; +import java.awt.event.InputEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.Arrays; @@ -45,7 +43,7 @@ import java.util.Comparator; * Created by plough on 2017/7/19. */ -public abstract class UIListControlPane extends UIControlPane { +public abstract class UIListControlPane extends UIControlPane implements ListControlPaneProvider { public static final String LIST_NAME = "UIControl_List"; private static final int EDIT_RANGE = 25; // 编辑按钮的x坐标范围 @@ -66,7 +64,7 @@ public abstract class UIListControlPane extends UIControlPane { @Override protected JPanel createControlUpdatePane() { - return new JControlUpdatePane(); + return JControlUpdatePane.newInstance(this); } /** @@ -141,55 +139,6 @@ public abstract class UIListControlPane extends UIControlPane { ((JControlUpdatePane) controlUpdatePane).update(); } - protected void doWhenPopulate(BasicBeanPane beanPane) { - - } - - protected void doBeforePopulate(ListModelElement el, Object obj) { - - } - - @Override - protected ShortCut4JControlPane addItemShortCut() { - ShortCut addItemShortCut; - NameableCreator[] creators = creators(); - if (creators.length == 1) { - addItemShortCut = new AddItemUpdateAction(creators); - } else { - addItemShortCut = getAddItemMenuDef(creators); - } - return new AbsoluteEnableShortCut(addItemShortCut); - } - - protected AddItemMenuDef getAddItemMenuDef (NameableCreator[] creators) { - return new AddItemMenuDef(creators); - } - - @Override - protected ShortCut4JControlPane removeItemShortCut() { - return new NormalEnableShortCut(new RemoveItemAction()); - } - - @Override - protected ShortCut4JControlPane copyItemShortCut() { - return new NormalEnableShortCut(new CopyItemAction()); - } - - @Override - protected ShortCut4JControlPane moveUpItemShortCut() { - return new NormalEnableShortCut(new MoveUpItemAction()); - } - - @Override - protected ShortCut4JControlPane moveDownItemShortCut() { - return new NormalEnableShortCut(new MoveDownItemAction()); - } - - @Override - protected ShortCut4JControlPane sortItemShortCut() { - return new NormalEnableShortCut(new SortItemAction()); - } - public void setNameListEditable(boolean editable) { this.nameableList.setEditable(editable); } @@ -259,22 +208,6 @@ public abstract class UIListControlPane extends UIControlPane { popupEditDialog(); } - /** - * 是否重命名 - * - * @return 是则true - */ - public boolean isContainsRename() { - String rename = com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Please_Rename") + "!"; - String[] names = this.nameableList.getAllNames(); - for (int i = names.length - 1; i >= 0; i--) { - if (ComparatorUtils.equals(names[i], rename)) { - return true; - } - } - return false; - } - protected DefaultListModel getModel() { return (DefaultListModel) UIListControlPane.this.nameableList.getModel(); } @@ -377,320 +310,148 @@ public abstract class UIListControlPane extends UIControlPane { return resultPos; } - /** - * 增加项的UpdateAction - */ - protected class AddItemUpdateAction extends UpdateAction { - final NameableCreator creator; - - public AddItemUpdateAction(NameableCreator[] creators) { - this.creator = creators[0]; - this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Action_Add")); - this.setMnemonic('A'); - this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/buttonicon/add.png")); - } - - /** - * Gets component on toolbar. - * - * @return the created components on toolbar. - */ - @Override - public JComponent createToolBarComponent() { - Object object = this.getValue(UIButton.class.getName()); - if (!(object instanceof AbstractButton)) { - // 直接使用默认UI - UIButton button = new UIButton(); - // 添加一个名字作为自动化测试用 - button.setName(getName()); - - //设置属性. - Integer mnemonicInteger = (Integer) this.getValue(Action.MNEMONIC_KEY); - if (mnemonicInteger != null) { - button.setMnemonic((char) mnemonicInteger.intValue()); - } - - button.setIcon((Icon) this.getValue(Action.SMALL_ICON)); - button.addActionListener(this); - - button.registerKeyboardAction(this, this.getAccelerator(), JComponent.WHEN_IN_FOCUSED_WINDOW); - - this.putValue(UIButton.class.getName(), button); - button.setText(StringUtils.EMPTY); - button.setEnabled(this.isEnabled()); - - //peter:产生tooltip - button.setToolTipText(ActionFactory.createButtonToolTipText(this)); - object = button; - } - - return (JComponent) object; - } - - @Override - public void actionPerformed(ActionEvent e) { - Nameable nameable = creator.createNameable(UIListControlPane.this); - - UIListControlPane.this.addNameable(nameable, getModel().getSize()); - } + @Override + public void onAddItem(NameableCreator creator) { + Nameable nameable = creator.createNameable(this); + this.addNameable(nameable, getModel().getSize()); } - /* - * 增加项的MenuDef - */ - protected class AddItemMenuDef extends MenuDef { - public AddItemMenuDef(NameableCreator[] creators) { - super(true); - this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Action_Add")); - this.setMnemonic('A'); - this.setIconPath("/com/fr/design/images/control/addPopup.png"); - wrapActionListener(creators); + @Override + public void onRemoveItem() { + try { + this.nameableList.getCellEditor().stopCellEditing(); + } catch (Exception ignored) { + // do nothing + } + // bug:在选中一个NameObject并删除,会遗留下Name. + doBeforeRemove(); + if (GUICoreUtils.removeJListSelectedNodes(SwingUtilities + .getWindowAncestor(this), nameableList)) { + checkButtonEnabled(); + doAfterRemove(); } + } - /** - * 生成UIButton - * @return 菜单按钮 - */ - public UIButton createUIButton() { - createdButton = super.createUIButton(); - // 此按钮单独抽出,不应使用工具栏外观 - if (!createdButton.isOpaque()) { - createdButton.setOpaque(true); - createdButton.setNormalPainted(true); - createdButton.setBorderPaintedOnlyWhenPressed(false); - } - return createdButton; + @Override + public void onCopyItem() { + // p:选中的值. + ListModelElement selectedValue = (ListModelElement) nameableList.getSelectedValue(); + if (selectedValue == null) { + return; } - private void wrapActionListener(NameableCreator[] creators) { - for (final NameableCreator creator : creators) { - if (!whetherAdd(creator.menuName())) { - continue; - } - boolean isTrue = ComparatorUtils.equals(creator.menuName(), com.fr.design.i18n.Toolkit.i18nText("Datasource-Stored_Procedure")) || - ComparatorUtils.equals(creator.menuName(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_DS_Relation_TableData")) || ComparatorUtils.equals(creator.menuName(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_DS_Multi_Dimensional_Database")); - if (isTrue) { - this.addShortCut(new LineSeparator()); - } - this.addShortCut(new UpdateAction() { - { - this.setName(creator.menuName()); - Icon icon = creator.menuIcon(); - if (icon != null) { - this.setSmallIcon(icon); - } - } - - @Override - public void actionPerformed(ActionEvent e) { - if (hasInvalid(true)) { - return; - } - - Nameable nameable = creator.createNameable(UIListControlPane.this); - - UIListControlPane.this.addNameable(nameable, getModel().getSize()); - } - }); - } - } + ((JControlUpdatePane) controlUpdatePane).update(); - protected boolean whetherAdd(String itemName){ - return HyperlinkFilterHelper.whetherAddHyperlink4cell(itemName); - } - } + Nameable selectedNameable = selectedValue.wrapper; - /* - * 移除item - */ - private class RemoveItemAction extends UpdateAction { - public RemoveItemAction() { - this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Action_Remove")); - this.setMnemonic('R'); - this.setSmallIcon(BaseUtils - .readIcon("/com/fr/base/images/cell/control/remove.png")); - } + // p: 用反射机制实现 + try { + Nameable newNameable = (Nameable) BaseUtils.cloneObject(selectedNameable); + newNameable.setName(createUnrepeatedCopyName(selectedNameable.getName())); - @Override - public void actionPerformed(ActionEvent evt) { - try { - UIListControlPane.this.nameableList.getCellEditor() - .stopCellEditing(); - } catch (Exception ignored) { - // do nothing - } - // bug:在选中一个NameObject并删除,会遗留下Name. - doBeforeRemove(); - if (GUICoreUtils.removeJListSelectedNodes(SwingUtilities - .getWindowAncestor(UIListControlPane.this), nameableList)) { - checkButtonEnabled(); - doAfterRemove(); - } + UIListControlPane.this.addNameable(newNameable, nameableList.getSelectedIndex() + 1); + } catch (Exception e) { + FRContext.getLogger().error(e.getMessage(), e); } } - /* - * CopyItem - */ - private class CopyItemAction extends UpdateAction { - public CopyItemAction() { - this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Action_Copy")); - this.setMnemonic('C'); - this.setSmallIcon(BaseUtils - .readIcon("/com/fr/design/images/m_edit/copy.png")); + @Override + public void onMoveUpItem() { + int selectedIndex = nameableList.getSelectedIndex(); + if (selectedIndex == -1) { + return; } - @Override - public void actionPerformed(ActionEvent evt) { - // p:选中的值. - ListModelElement selectedValue = (ListModelElement) nameableList.getSelectedValue(); - if (selectedValue == null) { - return; - } - - ((JControlUpdatePane) controlUpdatePane).update(); - - Nameable selectedNameable = selectedValue.wrapper; + // 上移 + if (selectedIndex > 0) { + DefaultListModel listModel = (DefaultListModel) nameableList + .getModel(); - // p: 用反射机制实现 - try { - Nameable newNameable = (Nameable) BaseUtils.cloneObject(selectedNameable); - newNameable.setName(createUnrepeatedCopyName(selectedNameable.getName())); + Object selecteObj1 = listModel.get(selectedIndex - 1); + listModel.set(selectedIndex - 1, listModel.get(selectedIndex)); + listModel.set(selectedIndex, selecteObj1); - UIListControlPane.this.addNameable(newNameable, nameableList.getSelectedIndex() + 1); - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage(), e); - } + nameableList.setSelectedIndex(selectedIndex - 1); + nameableList.ensureIndexIsVisible(selectedIndex - 1); } } - /* - * 上移Item - */ - private class MoveUpItemAction extends UpdateAction { - public MoveUpItemAction() { - this.setName(com.fr.design.i18n.Toolkit.i18nText("Utils-Move_Up")); - this.setMnemonic('U'); - this.setSmallIcon(BaseUtils - .readIcon("/com/fr/design/images/control/up.png")); + @Override + public void onMoveDownItem() { + int selectedIndex = nameableList.getSelectedIndex(); + if (selectedIndex == -1) { + return; } - @Override - public void actionPerformed(ActionEvent evt) { - int selectedIndex = nameableList.getSelectedIndex(); - if (selectedIndex == -1) { - return; - } - - // 上移 - if (selectedIndex > 0) { - DefaultListModel listModel = (DefaultListModel) nameableList - .getModel(); + if (selectedIndex < nameableList.getModel().getSize() - 1) { + DefaultListModel listModel = (DefaultListModel) nameableList + .getModel(); - Object selecteObj1 = listModel.get(selectedIndex - 1); - listModel.set(selectedIndex - 1, listModel.get(selectedIndex)); - listModel.set(selectedIndex, selecteObj1); + Object selecteObj1 = listModel.get(selectedIndex + 1); + listModel.set(selectedIndex + 1, listModel.get(selectedIndex)); + listModel.set(selectedIndex, selecteObj1); - nameableList.setSelectedIndex(selectedIndex - 1); - nameableList.ensureIndexIsVisible(selectedIndex - 1); - } + nameableList.setSelectedIndex(selectedIndex + 1); + nameableList.ensureIndexIsVisible(selectedIndex + 1); } } - /* - * 下移Item - */ - private class MoveDownItemAction extends UpdateAction { - public MoveDownItemAction() { - this.setName(com.fr.design.i18n.Toolkit.i18nText("Utils-Move_Down")); - this.setMnemonic('D'); - this.setSmallIcon(BaseUtils - .readIcon("/com/fr/design/images/control/down.png")); + @Override + public void onSortItem(boolean isAtoZ) { + // p:选中的值. + Object selectedValue = nameableList.getSelectedValue(); + + DefaultListModel listModel = (DefaultListModel) nameableList + .getModel(); + Nameable[] nameableArray = new Nameable[listModel.getSize()]; + if (nameableArray.length <= 0) { + return; } - @Override - public void actionPerformed(ActionEvent evt) { - int selectedIndex = nameableList.getSelectedIndex(); - if (selectedIndex == -1) { - return; - } - - if (selectedIndex < nameableList.getModel().getSize() - 1) { - DefaultListModel listModel = (DefaultListModel) nameableList - .getModel(); - - Object selecteObj1 = listModel.get(selectedIndex + 1); - listModel.set(selectedIndex + 1, listModel.get(selectedIndex)); - listModel.set(selectedIndex, selecteObj1); - - nameableList.setSelectedIndex(selectedIndex + 1); - nameableList.ensureIndexIsVisible(selectedIndex + 1); - } + for (int i = 0; i < listModel.getSize(); i++) { + nameableArray[i] = ((ListModelElement) listModel.getElementAt(i)).wrapper; } - } - - private class SortItemAction extends UpdateAction { - private boolean isAtoZ = false; - public SortItemAction() { - this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Action_Sort")); - this.setMnemonic('S'); - this.setSmallIcon(BaseUtils - .readIcon("/com/fr/design/images/control/sortAsc.png")); + // p:排序. + if (isAtoZ) { + Comparator nameableComparator = new Comparator() { + @Override + public int compare(Nameable o1, Nameable o2) { + return -ComparatorUtils.compare(o1.getName(), o2 + .getName()); + } + }; + isAtoZ = !isAtoZ; + Arrays.sort(nameableArray, nameableComparator); + } else { + Comparator nameableComparator = new Comparator() { + @Override + public int compare(Nameable o1, Nameable o2) { + return ComparatorUtils.compare(o1.getName(), o2 + .getName()); + } + }; + isAtoZ = !isAtoZ; + Arrays.sort(nameableArray, nameableComparator); } - @Override - public void actionPerformed(ActionEvent evt) { - // p:选中的值. - Object selectedValue = nameableList.getSelectedValue(); - - DefaultListModel listModel = (DefaultListModel) nameableList - .getModel(); - Nameable[] nameableArray = new Nameable[listModel.getSize()]; - if (nameableArray.length <= 0) { - return; - } - - for (int i = 0; i < listModel.getSize(); i++) { - nameableArray[i] = ((ListModelElement) listModel.getElementAt(i)).wrapper; - } - - // p:排序. - if (isAtoZ) { - Comparator nameableComparator = new Comparator() { - @Override - public int compare(Nameable o1, Nameable o2) { - return -ComparatorUtils.compare(o1.getName(), o2 - .getName()); - } - }; - isAtoZ = !isAtoZ; - Arrays.sort(nameableArray, nameableComparator); - } else { - Comparator nameableComparator = new Comparator() { - @Override - public int compare(Nameable o1, Nameable o2) { - return ComparatorUtils.compare(o1.getName(), o2 - .getName()); - } - }; - isAtoZ = !isAtoZ; - Arrays.sort(nameableArray, nameableComparator); - } + for (int i = 0; i < nameableArray.length; i++) { + listModel.set(i, new ListModelElement(nameableArray[i])); + } - for (int i = 0; i < nameableArray.length; i++) { - listModel.set(i, new ListModelElement(nameableArray[i])); - } + // p:需要选中以前的那个值. + if (selectedValue != null) { + nameableList.setSelectedValue(selectedValue, true); + } - // p:需要选中以前的那个值. - if (selectedValue != null) { - nameableList.setSelectedValue(selectedValue, true); - } + checkButtonEnabled(); + // p:需要repaint. + nameableList.repaint(); + } - checkButtonEnabled(); - // p:需要repaint. - nameableList.repaint(); - } + @Override + public boolean isItemSelected() { + return getModel().getSize() > 0 && nameableList.getSelectedIndex() != -1; } /* @@ -768,179 +529,7 @@ public abstract class UIListControlPane extends UIControlPane { } } - - public class AbsoluteEnableShortCut extends ShortCut4JControlPane { - public AbsoluteEnableShortCut(ShortCut shortCut) { - this.shortCut = shortCut; - } - - /** - * 检查是否可用 - */ - @Override - public void checkEnable() { - this.shortCut.setEnabled(true); - } - } - - public class NormalEnableShortCut extends ShortCut4JControlPane { - public NormalEnableShortCut(ShortCut shortCut) { - this.shortCut = shortCut; - } - - /** - * 检查是否可用 - */ - @Override - public void checkEnable() { - this.shortCut.setEnabled(getModel() - .getSize() > 0 - && UIListControlPane.this.nameableList.getSelectedIndex() != -1); - } - } - - public class SortEnableShortCut extends ShortCut4JControlPane { - public SortEnableShortCut(ShortCut shortCut) { - this.shortCut = shortCut; - } - - /** - * 检查是否可用 - */ - @Override - public void checkEnable() { - this.shortCut.setEnabled(getModel().getSize() > 1); - } - - } - - public class MoveUpEnableShortCut extends ShortCut4JControlPane { - public MoveUpEnableShortCut(ShortCut shortCut) { - this.shortCut = shortCut; - } - - /** - * 检查是否可用 - */ - @Override - public void checkEnable() { - this.shortCut.setEnabled(getModel().getSize() > 1 - && UIListControlPane.this.nameableList.getSelectedIndex() > 0); - } - - } - - public class MoveDownEnableShortCut extends ShortCut4JControlPane { - public MoveDownEnableShortCut(ShortCut shortCut) { - this.shortCut = shortCut; - } - - /** - * 检查是否可用 - */ - @Override - public void checkEnable() { - this.shortCut.setEnabled(getModel().getSize() > 1 - && UIListControlPane.this.nameableList.getSelectedIndex() < UIListControlPane.this.nameableList.getModel().getSize() - 1); - } - - } - - - protected Object getob2Populate (Object ob2Populate) { - return ob2Populate; - } - - private class JControlUpdatePane extends JPanel { - private CardLayout card; - private JPanel cardPane; - private BasicBeanPane[] updatePanes; - - private ListModelElement elEditing; - - public JControlUpdatePane() { - initUpdatePane(); - } - - private void initUpdatePane() { - NameableCreator[] creators = creators(); - if (creators == null) { - return; - } - card = new CardLayout(); - cardPane = FRGUIPaneFactory.createCardLayout_S_Pane(); - cardPane.setLayout(card); - this.setLayout(FRGUIPaneFactory.createBorderLayout()); - this.add(cardPane); - int len = creators.length; - updatePanes = new BasicBeanPane[len]; - } - - public void populate() { - ListModelElement el = (ListModelElement) UIListControlPane.this.nameableList.getSelectedValue(); - if (el == null) { - return; - } - - elEditing = el; - NameableCreator[] creators = creators(); - - for (int i = 0, len = updatePanes.length; i < len; i++) { - Object ob2Populate = creators[i].acceptObject2Populate(el.wrapper); - ob2Populate = getob2Populate(ob2Populate); - if (ob2Populate != null) { - if (updatePanes[i] == null) { - if (isMulti(creators[i].getUpdatePane()) || isTree(creators[i].getUpdatePane())) { - updatePanes[i] = createPaneByCreators(creators[i], el.wrapper.getName()); - } else { - updatePanes[i] = createPaneByCreators(creators[i]); - } - cardPane.add(updatePanes[i], String.valueOf(i)); - } - card.show(cardPane, String.valueOf(i)); - doBeforePopulate(el, ob2Populate); - updatePanes[i].populateBean(ob2Populate); - doWhenPopulate(updatePanes[i]); - break; - } - } - } - - - public boolean isMulti(Class _class) { - return ComparatorUtils.equals(_class, GlobalMultiTDTableDataPane.class) || ComparatorUtils.equals(_class, MultiTDTableDataPane.class); - } - - public boolean isTree(Class _class) { - return ComparatorUtils.equals(_class, GlobalTreeTableDataPane.class) || ComparatorUtils.equals(_class, TreeTableDataPane.class); - } - - public void update() { - NameableCreator[] creators = creators(); - for (int i = 0; i < updatePanes.length; i++) { - BasicBeanPane pane = updatePanes[i]; - - if (pane != null && pane.isVisible()) { - Object bean = pane.updateBean(); - if (i < creators.length) { - creators[i].saveUpdatedBean(elEditing, bean); - } - } - } - } - - public void checkValid() throws Exception { - if (updatePanes != null) { - for (int i = 0; i < updatePanes.length; i++) { - if (updatePanes[i] != null) { - updatePanes[i].checkValid(); - } - } - } - } - } - - protected BasicBeanPane createPaneByCreators(NameableCreator creator) { + public BasicBeanPane createPaneByCreators(NameableCreator creator) { try { return creator.getUpdatePane().newInstance(); } catch (InstantiationException e) { @@ -950,7 +539,7 @@ public abstract class UIListControlPane extends UIControlPane { } } - protected BasicBeanPane createPaneByCreators(NameableCreator creator, String string) { + public BasicBeanPane createPaneByCreators(NameableCreator creator, String string) { Constructor constructor = null; try { constructor = creator.getUpdatePane().getDeclaredConstructor(new Class[]{String.class}); @@ -965,21 +554,6 @@ public abstract class UIListControlPane extends UIControlPane { } catch (InvocationTargetException e) { throw new RuntimeException(e); } - - } - - // 选项添加个数有限制等情况下 要求能控制快捷按钮的状态 - protected void setToolbarDefEnable(int shortCutIndex, int itemIndex, boolean enabled) { - ToolBarDef toolbarDef = getToolbarDef(); - if (toolbarDef.getShortCutCount() > shortCutIndex) { - ShortCut sc = toolbarDef.getShortCut(shortCutIndex); - if (sc instanceof AddItemMenuDef) { - AddItemMenuDef am = (AddItemMenuDef) sc; - if (am.getShortCutCount() > itemIndex) { - am.getShortCut(itemIndex).setEnabled(enabled); - } - } - } } /** @@ -993,7 +567,7 @@ public abstract class UIListControlPane extends UIControlPane { } private int getInValidIndex() { - BasicBeanPane[] p = ((JControlUpdatePane) controlUpdatePane).updatePanes; + BasicBeanPane[] p = ((JControlUpdatePane) controlUpdatePane).getUpdatePanes(); if (p != null) { for (int i = 0; i < p.length; i++) { if (p[i] != null) { @@ -1031,4 +605,8 @@ public abstract class UIListControlPane extends UIControlPane { nameableList.setSelectedIndex(index); } + @Override + public ListModelElement getSelectedElement() { + return (ListModelElement) this.nameableList.getSelectedValue(); + } } diff --git a/designer-base/src/main/java/com/fr/design/gui/controlpane/shortcutfactory/AbstractShortCutFactory.java b/designer-base/src/main/java/com/fr/design/gui/controlpane/shortcutfactory/AbstractShortCutFactory.java new file mode 100644 index 000000000..ff1c34fd6 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/gui/controlpane/shortcutfactory/AbstractShortCutFactory.java @@ -0,0 +1,179 @@ +package com.fr.design.gui.controlpane.shortcutfactory; + +import com.fr.base.BaseUtils; +import com.fr.design.actions.UpdateAction; +import com.fr.design.gui.controlpane.NameableCreator; +import com.fr.design.gui.controlpane.ShortCut4JControlPane; +import com.fr.design.gui.controlpane.ShortCutListenerProvider; +import com.fr.design.menu.ShortCut; +import com.fr.general.Inter; + +import java.awt.event.ActionEvent; + +/** + * 生成 ShortCut 的抽象工厂 + * Created by plough on 2018/8/2. + */ +public abstract class AbstractShortCutFactory { + protected ShortCutListenerProvider listener; + + AbstractShortCutFactory(ShortCutListenerProvider listener) { + setListener(listener); + } + + /** + * 生成一组默认的 ShortCut + */ + abstract public ShortCut4JControlPane[] createShortCuts(); + + abstract public ShortCut createAddItemUpdateAction(NameableCreator[] creator); + + abstract public ShortCut createAddItemMenuDef(NameableCreator[] creator); + + public ShortCut4JControlPane addItemShortCut() { + ShortCut addItemShortCut; + NameableCreator[] creators = listener.creators(); + if (creators.length == 1) { + addItemShortCut = createAddItemUpdateAction(creators); + } else { + addItemShortCut = createAddItemMenuDef(creators); + } + return new AbsoluteEnableShortCut(addItemShortCut); + } + + public ShortCut4JControlPane removeItemShortCut() { + return new NormalEnableShortCut(new RemoveItemAction()); + } + + public ShortCut4JControlPane copyItemShortCut() { + return new NormalEnableShortCut(new CopyItemAction()); + } + + public ShortCut4JControlPane moveUpItemShortCut() { + return new NormalEnableShortCut(new MoveUpItemAction()); + } + + public ShortCut4JControlPane moveDownItemShortCut() { + return new NormalEnableShortCut(new MoveDownItemAction()); + } + + public ShortCut4JControlPane sortItemShortCut() { + return new NormalEnableShortCut(new SortItemAction()); + } + + public void setListener(ShortCutListenerProvider listener) { + this.listener = listener; + } + + private class AbsoluteEnableShortCut extends ShortCut4JControlPane { + AbsoluteEnableShortCut(ShortCut shortCut) { + this.shortCut = shortCut; + } + + /** + * 检查是否可用 + */ + @Override + public void checkEnable() { + this.shortCut.setEnabled(true); + } + } + + private class NormalEnableShortCut extends ShortCut4JControlPane { + NormalEnableShortCut(ShortCut shortCut) { + this.shortCut = shortCut; + } + + /** + * 检查是否可用 + */ + @Override + public void checkEnable() { + this.shortCut.setEnabled(listener.isItemSelected()); + } + } + + /* + * 移除item + */ + private class RemoveItemAction extends UpdateAction { + RemoveItemAction() { + this.setName(Inter.getLocText("FR-Action_Remove")); + this.setMnemonic('R'); + this.setSmallIcon(BaseUtils + .readIcon("/com/fr/base/images/cell/control/remove.png")); + } + + @Override + public void actionPerformed(ActionEvent evt) { + listener.onRemoveItem(); + } + } + + /* + * CopyItem + */ + private class CopyItemAction extends UpdateAction { + CopyItemAction() { + this.setName(Inter.getLocText("FR-Action_Copy")); + this.setMnemonic('C'); + this.setSmallIcon(BaseUtils + .readIcon("/com/fr/design/images/m_edit/copy.png")); + } + + @Override + public void actionPerformed(ActionEvent evt) { + listener.onCopyItem(); + } + } + + /* + * 上移Item + */ + private class MoveUpItemAction extends UpdateAction { + MoveUpItemAction() { + this.setName(Inter.getLocText("Utils-Move_Up")); + this.setMnemonic('U'); + this.setSmallIcon(BaseUtils + .readIcon("/com/fr/design/images/control/up.png")); + } + + @Override + public void actionPerformed(ActionEvent evt) { + listener.onMoveUpItem(); + } + } + + /* + * 下移Item + */ + private class MoveDownItemAction extends UpdateAction { + MoveDownItemAction() { + this.setName(Inter.getLocText("Utils-Move_Down")); + this.setMnemonic('D'); + this.setSmallIcon(BaseUtils + .readIcon("/com/fr/design/images/control/down.png")); + } + + @Override + public void actionPerformed(ActionEvent evt) { + listener.onMoveDownItem(); + } + } + + private class SortItemAction extends UpdateAction { + private boolean isAtoZ = false; + + SortItemAction() { + this.setName(Inter.getLocText("FR-Action_Sort")); + this.setMnemonic('S'); + this.setSmallIcon(BaseUtils + .readIcon("/com/fr/design/images/control/sortAsc.png")); + } + + @Override + public void actionPerformed(ActionEvent evt) { + listener.onSortItem(isAtoZ); + } + } +} diff --git a/designer-base/src/main/java/com/fr/design/gui/controlpane/shortcutfactory/NewShortCutFactory.java b/designer-base/src/main/java/com/fr/design/gui/controlpane/shortcutfactory/NewShortCutFactory.java new file mode 100644 index 000000000..f7fa96f0c --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/gui/controlpane/shortcutfactory/NewShortCutFactory.java @@ -0,0 +1,172 @@ +package com.fr.design.gui.controlpane.shortcutfactory; + +import com.fr.base.BaseUtils; +import com.fr.design.actions.UpdateAction; +import com.fr.design.actions.core.ActionFactory; +import com.fr.design.gui.HyperlinkFilterHelper; +import com.fr.design.gui.controlpane.AbstractShortCutFactory; +import com.fr.design.gui.controlpane.NameableCreator; +import com.fr.design.gui.controlpane.ShortCut4JControlPane; +import com.fr.design.gui.controlpane.ShortCutListenerProvider; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.menu.LineSeparator; +import com.fr.design.menu.MenuDef; +import com.fr.design.menu.ShortCut; +import com.fr.general.ComparatorUtils; +import com.fr.stable.StringUtils; + +import javax.swing.AbstractButton; +import javax.swing.Action; +import javax.swing.Icon; +import javax.swing.JComponent; +import java.awt.event.ActionEvent; + +/** + * Created by plough on 2018/8/13. + */ +public class NewShortCutFactory extends AbstractShortCutFactory { + + protected NewShortCutFactory(ShortCutListenerProvider listenerProvider) { + super(listenerProvider); + } + + public static NewShortCutFactory newInstance(ShortCutListenerProvider listenerProvider) { + return new NewShortCutFactory(listenerProvider); + } + + @Override + public ShortCut4JControlPane[] createShortCuts() { + return new ShortCut4JControlPane[]{ + copyItemShortCut(), + moveUpItemShortCut(), + moveDownItemShortCut(), + sortItemShortCut(), + removeItemShortCut() + }; + } + + @Override + public ShortCut createAddItemUpdateAction(NameableCreator[] creators) { + return new AddItemUpdateAction(creators); + } + + @Override + public ShortCut createAddItemMenuDef(NameableCreator[] creators) { + return new AddItemMenuDef(creators); + } + + /** + * 增加项的UpdateAction + */ + protected class AddItemUpdateAction extends UpdateAction { + final NameableCreator creator; + + public AddItemUpdateAction(NameableCreator[] creators) { + this.creator = creators[0]; + this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Action_Add")); + this.setMnemonic('A'); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/buttonicon/add.png")); + } + + /** + * Gets component on toolbar. + * + * @return the created components on toolbar. + */ + @Override + public JComponent createToolBarComponent() { + Object object = this.getValue(UIButton.class.getName()); + if (!(object instanceof AbstractButton)) { + // 直接使用默认UI + UIButton button = new UIButton(); + // 添加一个名字作为自动化测试用 + button.setName(getName()); + + //设置属性. + Integer mnemonicInteger = (Integer) this.getValue(Action.MNEMONIC_KEY); + if (mnemonicInteger != null) { + button.setMnemonic((char) mnemonicInteger.intValue()); + } + + button.setIcon((Icon) this.getValue(Action.SMALL_ICON)); + button.addActionListener(this); + + button.registerKeyboardAction(this, this.getAccelerator(), JComponent.WHEN_IN_FOCUSED_WINDOW); + + this.putValue(UIButton.class.getName(), button); + button.setText(StringUtils.EMPTY); + button.setEnabled(this.isEnabled()); + + //peter:产生tooltip + button.setToolTipText(ActionFactory.createButtonToolTipText(this)); + object = button; + } + + return (JComponent) object; + } + + @Override + public void actionPerformed(ActionEvent e) { + listener.onAddItem(creator); + } + } + + /* + * 增加项的MenuDef + */ + protected class AddItemMenuDef extends MenuDef { + public AddItemMenuDef(NameableCreator[] creators) { + super(true); + this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Action_Add")); + this.setMnemonic('A'); + this.setIconPath("/com/fr/design/images/control/addPopup.png"); + wrapActionListener(creators); + } + + /** + * 生成UIButton + * @return 菜单按钮 + */ + public UIButton createUIButton() { + createdButton = super.createUIButton(); + // 此按钮单独抽出,不应使用工具栏外观 + if (!createdButton.isOpaque()) { + createdButton.setOpaque(true); + createdButton.setNormalPainted(true); + createdButton.setBorderPaintedOnlyWhenPressed(false); + } + return createdButton; + } + + private void wrapActionListener(NameableCreator[] creators) { + for (final NameableCreator creator : creators) { + if (!whetherAdd(creator.menuName())) { + continue; + } + boolean isTrue = ComparatorUtils.equals(creator.menuName(), com.fr.design.i18n.Toolkit.i18nText("Datasource-Stored_Procedure")) || + ComparatorUtils.equals(creator.menuName(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_DS_Relation_TableData")) || ComparatorUtils.equals(creator.menuName(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_DS_Multi_Dimensional_Database")); + if (isTrue) { + this.addShortCut(new LineSeparator()); + } + this.addShortCut(new UpdateAction() { + { + this.setName(creator.menuName()); + Icon icon = creator.menuIcon(); + if (icon != null) { + this.setSmallIcon(icon); + } + } + + @Override + public void actionPerformed(ActionEvent e) { + listener.onAddItem(creator); + } + }); + } + } + + protected boolean whetherAdd(String itemName){ + return HyperlinkFilterHelper.whetherAddHyperlink4cell(itemName); + } + } +} diff --git a/designer-base/src/main/java/com/fr/design/gui/controlpane/shortcutfactory/OldShortCutFactory.java b/designer-base/src/main/java/com/fr/design/gui/controlpane/shortcutfactory/OldShortCutFactory.java new file mode 100644 index 000000000..a608ebb3e --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/gui/controlpane/shortcutfactory/OldShortCutFactory.java @@ -0,0 +1,112 @@ +package com.fr.design.gui.controlpane.shortcutfactory; + +import com.fr.base.BaseUtils; +import com.fr.design.actions.UpdateAction; +import com.fr.design.gui.HyperlinkFilterHelper; +import com.fr.design.gui.controlpane.NameableCreator; +import com.fr.design.gui.controlpane.ShortCut4JControlPane; +import com.fr.design.gui.controlpane.ShortCutListenerProvider; +import com.fr.design.menu.LineSeparator; +import com.fr.design.menu.MenuDef; +import com.fr.design.menu.ShortCut; +import com.fr.general.ComparatorUtils; +import com.fr.general.Inter; + +import javax.swing.Icon; +import java.awt.event.ActionEvent; + +/** + * Created by plough on 2018/8/13. + */ +public class OldShortCutFactory extends AbstractShortCutFactory { + + private OldShortCutFactory(ShortCutListenerProvider listenerProvider) { + super(listenerProvider); + } + + public static OldShortCutFactory newInstance(ShortCutListenerProvider listenerProvider) { + return new OldShortCutFactory(listenerProvider); + } + + @Override + public ShortCut4JControlPane[] createShortCuts() { + return new ShortCut4JControlPane[]{ + addItemShortCut(), + removeItemShortCut(), + copyItemShortCut(), + moveUpItemShortCut(), + moveDownItemShortCut(), + sortItemShortCut() + }; + } + + @Override + public ShortCut createAddItemUpdateAction(NameableCreator[] creators) { + return new AddItemUpdateAction(creators); + } + + @Override + public ShortCut createAddItemMenuDef(NameableCreator[] creators) { + return new AddItemMenuDef(creators); + } + + + /** + * 增加项的UpdateAction + */ + protected class AddItemUpdateAction extends UpdateAction { + final NameableCreator creator; + + public AddItemUpdateAction(NameableCreator[] creators) { + this.creator = creators[0]; + this.setName(Inter.getLocText("FR-Action_Add")); + this.setMnemonic('A'); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/buttonicon/add.png")); + } + + @Override + public void actionPerformed(ActionEvent e) { + listener.onAddItem(creator); + } + } + + /* + * 增加项的MenuDef + */ + private class AddItemMenuDef extends MenuDef { + AddItemMenuDef(NameableCreator[] creators) { + this.setName(Inter.getLocText("FR-Action_Add")); + this.setMnemonic('A'); + this.setIconPath("/com/fr/design/images/control/addPopup.png"); + wrapActionListener(creators); + } + + private void wrapActionListener(NameableCreator[] creators) { + for (final NameableCreator creator : creators) { + if (!HyperlinkFilterHelper.whetherAddHyperlink4cell(creator.menuName())) { + continue; + } + boolean isTrue = ComparatorUtils.equals(creator.menuName(), Inter.getLocText("Datasource-Stored_Procedure")) || + ComparatorUtils.equals(creator.menuName(), Inter.getLocText("DS-Relation_TableData")) || ComparatorUtils.equals(creator.menuName(), Inter.getLocText("DS-Multi_Dimensional_Database")); + if (isTrue) { + this.addShortCut(new LineSeparator()); + } + this.addShortCut(new UpdateAction() { + { + this.setName(creator.menuName()); + Icon icon = creator.menuIcon(); + if (icon != null) { + this.setSmallIcon(icon); + } + } + + @Override + public void actionPerformed(ActionEvent e) { + listener.onAddItem(creator); + } + }); + } + } + } + +} diff --git a/designer-base/src/main/java/com/fr/env/EnvListPane.java b/designer-base/src/main/java/com/fr/env/EnvListPane.java index 6bff9638f..59eaea4e6 100644 --- a/designer-base/src/main/java/com/fr/env/EnvListPane.java +++ b/designer-base/src/main/java/com/fr/env/EnvListPane.java @@ -103,9 +103,4 @@ public class EnvListPane extends JListControlPane { } return this.getSelectedName(); } - - @Override - protected boolean filterNameableCreator(NameableCreator creator) { - return false; - } } diff --git a/designer-chart/src/main/java/com/fr/van/chart/custom/component/VanChartHyperLinkPane.java b/designer-chart/src/main/java/com/fr/van/chart/custom/component/VanChartHyperLinkPane.java index b6aae5da7..dc2b4a705 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/custom/component/VanChartHyperLinkPane.java +++ b/designer-chart/src/main/java/com/fr/van/chart/custom/component/VanChartHyperLinkPane.java @@ -74,7 +74,7 @@ public class VanChartHyperLinkPane extends VanChartUIListControlPane { } - protected BasicBeanPane createPaneByCreators(NameableCreator creator) { + public BasicBeanPane createPaneByCreators(NameableCreator creator) { Constructor constructor = null; try { constructor = creator.getUpdatePane().getConstructor(HashMap.class, boolean.class); @@ -111,8 +111,8 @@ public class VanChartHyperLinkPane extends VanChartUIListControlPane { } @Override - protected AddItemMenuDef getAddItemMenuDef (NameableCreator[] creators) { - return new AddVanChartItemMenuDef(creators); + protected void initShortCutFactory() { + this.shortCutFactory = VanChartShortCutFactory.newInstance(this); } public void populate(NameJavaScriptGroup nameHyperlink_array) { @@ -272,18 +272,6 @@ public class VanChartHyperLinkPane extends VanChartUIListControlPane { return null; } - protected class AddVanChartItemMenuDef extends AddItemMenuDef { - - public AddVanChartItemMenuDef(NameableCreator[] creators) { - super(creators); - } - - @Override - protected boolean whetherAdd(String itemName) { - return HyperlinkFilterHelper.whetherAddHyperlink4Chart(itemName); - } - } - //邮箱 public static class VanChartEmailPane extends ChartEmailPane { @Override diff --git a/designer-chart/src/main/java/com/fr/van/chart/custom/component/VanChartShortCutFactory.java b/designer-chart/src/main/java/com/fr/van/chart/custom/component/VanChartShortCutFactory.java new file mode 100644 index 000000000..565c4cbcf --- /dev/null +++ b/designer-chart/src/main/java/com/fr/van/chart/custom/component/VanChartShortCutFactory.java @@ -0,0 +1,33 @@ +package com.fr.van.chart.custom.component; + +import com.fr.design.gui.HyperlinkFilterHelper; +import com.fr.design.gui.controlpane.NameableCreator; +import com.fr.design.gui.controlpane.NewShortCutFactory; +import com.fr.design.gui.controlpane.ShortCutListenerProvider; +import com.fr.design.menu.ShortCut; + +/** + * Created by plough on 2018/8/13. + */ +public class VanChartShortCutFactory extends NewShortCutFactory { + private VanChartShortCutFactory(ShortCutListenerProvider listenerProvider) { + super(listenerProvider); + } + + @Override + public ShortCut createAddItemMenuDef(NameableCreator[] creators) { + return new AddVanChartItemMenuDef(creators); + } + + private class AddVanChartItemMenuDef extends AddItemMenuDef { + + AddVanChartItemMenuDef(NameableCreator[] creators) { + super(creators); + } + + @Override + protected boolean whetherAdd(String itemName) { + return HyperlinkFilterHelper.whetherAddHyperlink4Chart(itemName); + } + } +} diff --git a/designer-chart/src/main/java/com/fr/van/chart/designer/other/VanChartConditionListControlPane.java b/designer-chart/src/main/java/com/fr/van/chart/designer/other/VanChartConditionListControlPane.java index 617ce56a2..65b836047 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/designer/other/VanChartConditionListControlPane.java +++ b/designer-chart/src/main/java/com/fr/van/chart/designer/other/VanChartConditionListControlPane.java @@ -41,7 +41,7 @@ public class VanChartConditionListControlPane extends VanChartUIListControlPane } - protected BasicBeanPane createPaneByCreators(NameableCreator creator) { + public BasicBeanPane createPaneByCreators(NameableCreator creator) { Constructor constructor = null; try { constructor = creator.getUpdatePane().getConstructor(Plot.class); diff --git a/designer-chart/src/main/java/com/fr/van/chart/designer/style/background/AlertLineListControlPane.java b/designer-chart/src/main/java/com/fr/van/chart/designer/style/background/AlertLineListControlPane.java index 428d20a13..8bade1b88 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/designer/style/background/AlertLineListControlPane.java +++ b/designer-chart/src/main/java/com/fr/van/chart/designer/style/background/AlertLineListControlPane.java @@ -40,9 +40,9 @@ public class AlertLineListControlPane extends VanChartUIListControlPane { protected ShortCut4JControlPane[] createShortcuts() { return new ShortCut4JControlPane[]{ - moveUpItemShortCut(), - moveDownItemShortCut(), - removeItemShortCut() + shortCutFactory.moveUpItemShortCut(), + shortCutFactory.moveDownItemShortCut(), + shortCutFactory.removeItemShortCut() }; } diff --git a/designer-chart/src/main/java/com/fr/van/chart/designer/style/background/BackgroundListControlPane.java b/designer-chart/src/main/java/com/fr/van/chart/designer/style/background/BackgroundListControlPane.java index 95e6a48a4..061cf54a1 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/designer/style/background/BackgroundListControlPane.java +++ b/designer-chart/src/main/java/com/fr/van/chart/designer/style/background/BackgroundListControlPane.java @@ -42,9 +42,9 @@ public class BackgroundListControlPane extends VanChartUIListControlPane { protected ShortCut4JControlPane[] createShortcuts() { return new ShortCut4JControlPane[]{ - moveUpItemShortCut(), - moveDownItemShortCut(), - removeItemShortCut() + shortCutFactory.moveUpItemShortCut(), + shortCutFactory.moveDownItemShortCut(), + shortCutFactory.removeItemShortCut() }; } diff --git a/designer-chart/src/main/java/com/fr/van/chart/designer/style/series/VanChartStackedAndAxisListControlPane.java b/designer-chart/src/main/java/com/fr/van/chart/designer/style/series/VanChartStackedAndAxisListControlPane.java index 70cdcc399..3d2b2964f 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/designer/style/series/VanChartStackedAndAxisListControlPane.java +++ b/designer-chart/src/main/java/com/fr/van/chart/designer/style/series/VanChartStackedAndAxisListControlPane.java @@ -40,9 +40,9 @@ public class VanChartStackedAndAxisListControlPane extends VanChartUIListControl protected ShortCut4JControlPane[] createShortcuts() { return new ShortCut4JControlPane[]{ - moveUpItemShortCut(), - moveDownItemShortCut(), - removeItemShortCut() + shortCutFactory.moveUpItemShortCut(), + shortCutFactory.moveDownItemShortCut(), + shortCutFactory.removeItemShortCut() }; } diff --git a/designer-realize/src/main/java/com/fr/design/report/share/ConfusionManagerPane.java b/designer-realize/src/main/java/com/fr/design/report/share/ConfusionManagerPane.java index 6546465f2..aa0a4e4ca 100644 --- a/designer-realize/src/main/java/com/fr/design/report/share/ConfusionManagerPane.java +++ b/designer-realize/src/main/java/com/fr/design/report/share/ConfusionManagerPane.java @@ -77,7 +77,11 @@ public class ConfusionManagerPane extends JListControlPane { @Override protected ShortCut4JControlPane[] createShortcuts() { - return new ShortCut4JControlPane[] { moveUpItemShortCut(), moveDownItemShortCut(), sortItemShortCut() }; + return new ShortCut4JControlPane[] { + shortCutFactory.moveUpItemShortCut(), + shortCutFactory.moveDownItemShortCut(), + shortCutFactory.sortItemShortCut() + }; } }