Browse Source

Merge pull request #366 in DESIGN/design from ~PLOUGH/10-design:release/10.0 to release/10.0

* commit '87af02ba02f9a86a1f44c8c86e47853049ec3c8b':
  REPORT-10045 重构 UIListControlPane 和 JListControlPane => 调整代码,修复一个bug
  REPORT-10045 重构 UIListControlPane 和 JListControlPane
  REPORT-10045 重构 UIListControlPane 和 JListControlPane(部分)
final/10.0
plough 6 years ago
parent
commit
cdba003737
  1. 212
      designer-base/src/main/java/com/fr/design/gui/controlpane/CommonShortCutHandlers.java
  2. 107
      designer-base/src/main/java/com/fr/design/gui/controlpane/JControlPane.java
  3. 112
      designer-base/src/main/java/com/fr/design/gui/controlpane/JControlUpdatePane.java
  4. 608
      designer-base/src/main/java/com/fr/design/gui/controlpane/JListControlPane.java
  5. 112
      designer-base/src/main/java/com/fr/design/gui/controlpane/ListControlPaneHelper.java
  6. 35
      designer-base/src/main/java/com/fr/design/gui/controlpane/ListControlPaneProvider.java
  7. 2
      designer-base/src/main/java/com/fr/design/gui/controlpane/ObjectJControlPane.java
  8. 6
      designer-base/src/main/java/com/fr/design/gui/controlpane/ObjectUIControlPane.java
  9. 15
      designer-base/src/main/java/com/fr/design/gui/controlpane/ShortCutListenerProvider.java
  10. 203
      designer-base/src/main/java/com/fr/design/gui/controlpane/UIControlPane.java
  11. 776
      designer-base/src/main/java/com/fr/design/gui/controlpane/UIListControlPane.java
  12. 179
      designer-base/src/main/java/com/fr/design/gui/controlpane/shortcutfactory/AbstractShortCutFactory.java
  13. 112
      designer-base/src/main/java/com/fr/design/gui/controlpane/shortcutfactory/OldShortCutFactory.java
  14. 171
      designer-base/src/main/java/com/fr/design/gui/controlpane/shortcutfactory/ShortCutFactory.java
  15. 61
      designer-base/src/main/java/com/fr/design/gui/ilist/JNameEdList.java
  16. 386
      designer-base/src/main/java/com/fr/design/gui/ilist/UINameEdList.java
  17. 5
      designer-base/src/main/java/com/fr/env/EnvListPane.java
  18. 18
      designer-chart/src/main/java/com/fr/van/chart/custom/component/VanChartHyperLinkPane.java
  19. 33
      designer-chart/src/main/java/com/fr/van/chart/custom/component/VanChartShortCutFactory.java
  20. 2
      designer-chart/src/main/java/com/fr/van/chart/designer/other/VanChartConditionListControlPane.java
  21. 6
      designer-chart/src/main/java/com/fr/van/chart/designer/style/background/AlertLineListControlPane.java
  22. 6
      designer-chart/src/main/java/com/fr/van/chart/designer/style/background/BackgroundListControlPane.java
  23. 6
      designer-chart/src/main/java/com/fr/van/chart/designer/style/series/VanChartStackedAndAxisListControlPane.java
  24. 6
      designer-realize/src/main/java/com/fr/design/report/share/ConfusionManagerPane.java

212
designer-base/src/main/java/com/fr/design/gui/controlpane/CommonShortCutHandlers.java

@ -0,0 +1,212 @@
package com.fr.design.gui.controlpane;
import com.fr.base.BaseUtils;
import com.fr.base.FRContext;
import com.fr.design.gui.ilist.JNameEdList;
import com.fr.design.gui.ilist.ListModelElement;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.general.ComparatorUtils;
import com.fr.stable.ArrayUtils;
import com.fr.stable.Nameable;
import javax.swing.DefaultListModel;
import javax.swing.SwingUtilities;
import java.awt.Component;
import java.util.Arrays;
import java.util.Comparator;
/**
* 存放一些通用的事件处理方法
* Created by plough on 2018/8/13.
*/
public class CommonShortCutHandlers {
ListControlPaneProvider listControlPane;
JNameEdList nameableList;
private CommonShortCutHandlers(ListControlPaneProvider listControlPane) {
this.listControlPane = listControlPane;
this.nameableList = listControlPane.getNameableList();
}
public static CommonShortCutHandlers newInstance(ListControlPaneProvider listControlPane) {
return new CommonShortCutHandlers(listControlPane);
}
public void onAddItem(NameableCreator creator) {
if (listControlPane.hasInvalid(true)) {
return;
}
Nameable nameable = creator.createNameable(listControlPane);
listControlPane.addNameable(nameable, listControlPane.getModel().getSize());
}
public void onRemoveItem() {
try {
nameableList.getCellEditor()
.stopCellEditing();
} catch (Exception ignored) {
}
if (GUICoreUtils.removeJListSelectedNodes(SwingUtilities
.getWindowAncestor((Component) listControlPane), nameableList)) {
listControlPane.checkButtonEnabled();
}
}
public void onCopyItem() {
// p:选中的值.
ListModelElement selectedValue = (ListModelElement) nameableList.getSelectedValue();
if (selectedValue == null) {
return;
}
listControlPane.getControlUpdatePane().update();
Nameable selectedNameable = selectedValue.wrapper;
// p: 用反射机制实现
try {
Nameable newNameable = (Nameable) BaseUtils.cloneObject(selectedNameable);
newNameable.setName(createUnrepeatedCopyName(selectedNameable.getName()));
listControlPane.addNameable(newNameable, listControlPane.getSelectedIndex() + 1);
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
}
}
public void onMoveUpItem() {
int selectedIndex = nameableList.getSelectedIndex();
if (selectedIndex == -1) {
return;
}
// 上移
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);
nameableList.setSelectedIndex(selectedIndex - 1);
nameableList.ensureIndexIsVisible(selectedIndex - 1);
}
}
public void onMoveDownItem() {
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);
}
}
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;
}
for (int i = 0; i < listModel.getSize(); i++) {
nameableArray[i] = ((ListModelElement) listModel.getElementAt(i)).wrapper;
}
// p:排序.
if (isAtoZ) {
Comparator<Nameable> nameableComparator = new Comparator<Nameable>() {
@Override
public int compare(Nameable o1, Nameable o2) {
return -ComparatorUtils.compare(o1.getName(), o2
.getName());
}
};
isAtoZ = !isAtoZ;
Arrays.sort(nameableArray, nameableComparator);
} else {
Comparator<Nameable> nameableComparator = new Comparator<Nameable>() {
@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]));
}
// p:需要选中以前的那个值.
if (selectedValue != null) {
nameableList.setSelectedValue(selectedValue, true);
}
listControlPane.checkButtonEnabled();
// p:需要repaint.
nameableList.repaint();
}
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++;
}
}
}

107
designer-base/src/main/java/com/fr/design/gui/controlpane/JControlPane.java

@ -1,6 +1,8 @@
package com.fr.design.gui.controlpane; package com.fr.design.gui.controlpane;
import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.BasicPane;
import com.fr.design.gui.controlpane.shortcutfactory.AbstractShortCutFactory;
import com.fr.design.gui.controlpane.shortcutfactory.OldShortCutFactory;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itoolbar.UIToolbar; import com.fr.design.gui.itoolbar.UIToolbar;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
@ -17,24 +19,32 @@ import java.awt.*;
* Date: 2016/5/17 * Date: 2016/5/17
* Time: 15:07 * Time: 15:07
*/ */
public abstract class JControlPane extends BasicPane implements UnrepeatedNameHelper { abstract class JControlPane extends BasicPane implements UnrepeatedNameHelper, ShortCutListenerProvider {
protected static final int SHORT_WIDTH = 30; //每加一个short Divider位置加30 private static final int SHORT_WIDTH = 30; //每加一个short Divider位置加30
protected JPanel controlUpdatePane; private static final String SELECT = "SELECT";
private static final String EDIT = "EDIT";
private ShortCut4JControlPane[] shorts; JPanel controlUpdatePane;
private NameableCreator[] creators;
ShortCut4JControlPane[] shorts;
NameableCreator[] creators;
private ToolBarDef toolbarDef; private ToolBarDef toolbarDef;
private UIToolbar toolBar; UIToolbar toolBar;
// peter:这是整体的一个cardLayout Pane // peter:这是整体的一个cardLayout Pane
protected CardLayout cardLayout; protected CardLayout cardLayout;
protected JPanel cardPane; protected JPanel cardPane;
protected AbstractShortCutFactory shortCutFactory;
public JControlPane() { JControlPane() {
this.initShortCutFactory();
this.initComponentPane(); this.initComponentPane();
} }
protected void initShortCutFactory() {
this.shortCutFactory = OldShortCutFactory.newInstance(this);
}
/** /**
* 生成添加按钮的NameableCreator * 生成添加按钮的NameableCreator
* *
@ -46,10 +56,6 @@ public abstract class JControlPane extends BasicPane implements UnrepeatedNameHe
return shorts; return shorts;
} }
public void setShorts(ShortCut4JControlPane[] shorts) {
this.shorts = shorts;
}
public void setCreators(NameableCreator[] creators) { public void setCreators(NameableCreator[] creators) {
this.creators = creators; this.creators = creators;
} }
@ -89,6 +95,18 @@ public abstract class JControlPane extends BasicPane implements UnrepeatedNameHe
protected void initComponentPane() { protected void initComponentPane() {
this.setLayout(FRGUIPaneFactory.createBorderLayout()); this.setLayout(FRGUIPaneFactory.createBorderLayout());
this.creators = this.createNameableCreators(); this.creators = this.createNameableCreators();
initCardPane();
// SplitPane
JSplitPane mainSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, getLeftPane(), cardPane);
mainSplitPane.setBorder(BorderFactory.createLineBorder(GUICoreUtils.getTitleLineBorderColor()));
mainSplitPane.setOneTouchExpandable(true);
this.add(mainSplitPane, BorderLayout.CENTER);
mainSplitPane.setDividerLocation(getLeftPreferredSize());
this.checkButtonEnabled();
}
protected void initCardPane() {
this.controlUpdatePane = createControlUpdatePane(); this.controlUpdatePane = createControlUpdatePane();
// p: edit card layout // p: edit card layout
@ -97,20 +115,29 @@ public abstract class JControlPane extends BasicPane implements UnrepeatedNameHe
cardPane.setLayout(this.cardLayout); cardPane.setLayout(this.cardLayout);
// p:选择的Label // p:选择的Label
UILabel selectLabel = new UILabel(); UILabel selectLabel = new UILabel();
cardPane.add(selectLabel, "SELECT"); cardPane.add(selectLabel, SELECT);
cardPane.add(controlUpdatePane, "EDIT"); cardPane.add(controlUpdatePane, EDIT);
// SplitPane }
JSplitPane mainSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, getLeftPane(), cardPane);
mainSplitPane.setBorder(BorderFactory.createLineBorder(GUICoreUtils.getTitleLineBorderColor()));
mainSplitPane.setOneTouchExpandable(true);
this.add(mainSplitPane, BorderLayout.CENTER); public void showEditPane() {
mainSplitPane.setDividerLocation(getLeftPreferredSize()); this.cardLayout.show(cardPane, EDIT);
this.checkButtonEnabled(); }
public void showSelectPane() {
this.cardLayout.show(cardPane, SELECT);
} }
protected abstract JPanel createControlUpdatePane(); 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() { protected JPanel getLeftPane() {
// LeftPane // LeftPane
JPanel leftPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); JPanel leftPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
@ -122,12 +149,8 @@ public abstract class JControlPane extends BasicPane implements UnrepeatedNameHe
return leftPane; return leftPane;
} }
toolbarDef = new ToolBarDef(); initToolBar();
for (ShortCut4JControlPane sj : shorts) {
toolbarDef.addShortCut(sj.getShortCut());
}
toolBar = ToolBarDef.createJToolBar();
toolbarDef.updateToolBar(toolBar);
leftPane.add(toolBar, BorderLayout.NORTH); leftPane.add(toolBar, BorderLayout.NORTH);
return leftPane; return leftPane;
} }
@ -143,30 +166,10 @@ public abstract class JControlPane extends BasicPane implements UnrepeatedNameHe
return shorts.length * SHORT_WIDTH; return shorts.length * SHORT_WIDTH;
} }
protected ShortCut4JControlPane[] createShortcuts() { protected ShortCut4JControlPane[] createShortcuts() {
return new ShortCut4JControlPane[]{ return shortCutFactory.createShortCuts();
addItemShortCut(),
removeItemShortCut(),
copyItemShortCut(),
moveUpItemShortCut(),
moveDownItemShortCut(),
sortItemShortCut()
};
} }
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 abstract Nameable[] update();
@ -179,18 +182,10 @@ public abstract class JControlPane extends BasicPane implements UnrepeatedNameHe
public void checkButtonEnabled() { public void checkButtonEnabled() {
} }
protected void doBeforeRemove() {
}
protected void doAfterRemove() {
}
public NameableCreator[] creators() { public NameableCreator[] creators() {
return creators == null ? new NameableCreator[0] : creators; return creators == null ? new NameableCreator[0] : creators;
} }
protected abstract boolean hasInvalid(boolean isAdd);
/** /**
* 刷新 NameableCreator * 刷新 NameableCreator
* *

112
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.getSelectedValue();
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();
}
}
}
}
}

608
designer-base/src/main/java/com/fr/design/gui/controlpane/JListControlPane.java

@ -1,22 +1,10 @@
package com.fr.design.gui.controlpane; 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.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.icontainer.UIScrollPane;
import com.fr.design.gui.ilist.JNameEdList; import com.fr.design.gui.ilist.JNameEdList;
import com.fr.design.gui.ilist.ListModelElement; import com.fr.design.gui.ilist.ListModelElement;
import com.fr.design.gui.ilist.ModNameActionListener; 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.design.utils.gui.GUICoreUtils;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.general.IOUtils; import com.fr.general.IOUtils;
@ -25,24 +13,30 @@ import com.fr.stable.ArrayUtils;
import com.fr.stable.Nameable; import com.fr.stable.Nameable;
import com.fr.stable.core.PropertyChangeAdapter; import com.fr.stable.core.PropertyChangeAdapter;
import javax.swing.*; import javax.swing.DefaultListCellRenderer;
import javax.swing.DefaultListModel;
import javax.swing.JList;
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.ListSelectionEvent;
import javax.swing.event.ListSelectionListener; import javax.swing.event.ListSelectionListener;
import java.awt.*; import java.awt.BorderLayout;
import java.awt.event.ActionEvent; import java.awt.Component;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
import java.util.Arrays;
import java.util.Comparator;
public abstract class JListControlPane extends JControlPane { public abstract class JListControlPane extends JControlPane implements ListControlPaneProvider {
public static final String LIST_NAME = "JControl_List"; private static final String LIST_NAME = "JControl_List";
protected JNameEdList nameableList; protected JNameEdList nameableList;
protected int editingIndex; protected int editingIndex;
protected String selectedName; protected String selectedName;
private boolean isNameRepeated = false; private boolean isNameRepeated = false;
private CommonShortCutHandlers commonHandlers;
private ListControlPaneHelper helper;
public JListControlPane() { public JListControlPane() {
this.initComponentPane(); this.initComponentPane();
@ -50,7 +44,21 @@ public abstract class JListControlPane extends JControlPane {
@Override @Override
protected JPanel createControlUpdatePane() { protected JPanel createControlUpdatePane() {
return new JControlUpdatePane(); return JControlUpdatePane.newInstance(this);
}
private ListControlPaneHelper getHelper() {
if (helper == null) {
helper = ListControlPaneHelper.newInstance(this);
}
return helper;
}
private CommonShortCutHandlers getCommonHandlers() {
if (commonHandlers == null) {
commonHandlers = CommonShortCutHandlers.newInstance(this);
}
return commonHandlers;
} }
/** /**
@ -68,7 +76,6 @@ public abstract class JListControlPane extends JControlPane {
nameableList.setName(LIST_NAME); nameableList.setName(LIST_NAME);
leftPane.add(new UIScrollPane(nameableList), BorderLayout.CENTER); leftPane.add(new UIScrollPane(nameableList), BorderLayout.CENTER);
nameableList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); nameableList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
nameableList.addMouseListener(listMouseListener); nameableList.addMouseListener(listMouseListener);
nameableList.addListSelectionListener(new ListSelectionListener() { nameableList.addListSelectionListener(new ListSelectionListener() {
@ -87,7 +94,7 @@ public abstract class JListControlPane extends JControlPane {
}); });
} }
public JNameEdList createJNameList() { protected JNameEdList createJNameList() {
JNameEdList nameEdList = new JNameEdList(new DefaultListModel()) { JNameEdList nameEdList = new JNameEdList(new DefaultListModel()) {
@Override @Override
protected void doAfterLostFocus() { protected void doAfterLostFocus() {
@ -98,69 +105,13 @@ public abstract class JListControlPane extends JControlPane {
return nameEdList; return nameEdList;
} }
public void updateControlUpdatePane() { private void updateControlUpdatePane() {
((JControlUpdatePane) controlUpdatePane).update(); ((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 @Override
public Nameable[] update() { public Nameable[] update() {
java.util.List<Nameable> res = new java.util.ArrayList<Nameable>(); return getHelper().update();
((JControlUpdatePane) this.controlUpdatePane).update();
DefaultListModel listModel = (DefaultListModel) this.nameableList.getModel();
for (int i = 0, len = listModel.getSize(); i < len; i++) {
res.add(((ListModelElement) listModel.getElementAt(i)).wrapper);
}
return res.toArray(new Nameable[res.size()]);
} }
@Override @Override
@ -186,7 +137,7 @@ public abstract class JListControlPane extends JControlPane {
* *
* @param l 名字改变时的监听 * @param l 名字改变时的监听
*/ */
public void addModNameActionListener(ModNameActionListener l) { protected void addModNameActionListener(ModNameActionListener l) {
this.nameableList.addModNameActionListener(l); this.nameableList.addModNameActionListener(l);
} }
@ -195,7 +146,7 @@ public abstract class JListControlPane extends JControlPane {
* *
* @param l 监听 * @param l 监听
*/ */
public void addEditingListener(PropertyChangeAdapter l) { protected void addEditingListener(PropertyChangeAdapter l) {
this.nameableList.addEditingListner(l); this.nameableList.addEditingListner(l);
} }
@ -236,9 +187,7 @@ public abstract class JListControlPane extends JControlPane {
* 获取选中的名字 * 获取选中的名字
*/ */
public String getSelectedName() { public String getSelectedName() {
ListModelElement el = (ListModelElement) this.nameableList.getSelectedValue(); return getHelper().getSelectedName();
return el == null ? null : el.wrapper.getName();
} }
protected boolean isNameRepeated(java.util.List[] list, String name) { protected boolean isNameRepeated(java.util.List[] list, String name) {
@ -268,15 +217,7 @@ public abstract class JListControlPane extends JControlPane {
* @param index 序号 * @param index 序号
*/ */
public void addNameable(Nameable nameable, int index) { public void addNameable(Nameable nameable, int index) {
JNameEdList nameEdList = JListControlPane.this.nameableList; getHelper().addNameable(nameable, index);
DefaultListModel model = (DefaultListModel) nameEdList.getModel();
ListModelElement el = new ListModelElement(nameable);
model.add(index, el);
nameableList.setSelectedIndex(index);
nameableList.ensureIndexIsVisible(index);
nameEdList.repaint();
} }
/** /**
@ -295,24 +236,10 @@ public abstract class JListControlPane extends JControlPane {
return false; return false;
} }
protected DefaultListModel getModel() { public DefaultListModel getModel() {
return (DefaultListModel) JListControlPane.this.nameableList.getModel(); return (DefaultListModel) JListControlPane.this.nameableList.getModel();
} }
private String createUnrepeatedCopyName(String suffix) {
DefaultListModel model = this.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;
}
/** /**
* 生成不重复的名字 * 生成不重复的名字
* *
@ -321,288 +248,42 @@ public abstract class JListControlPane extends JControlPane {
*/ */
@Override @Override
public String createUnrepeatedName(String prefix) { public String createUnrepeatedName(String prefix) {
DefaultListModel model = this.getModel(); return getCommonHandlers().createUnrepeatedName(prefix);
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++;
}
}
/**
* 增加项的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 @Override
public void actionPerformed(ActionEvent e) { public void onAddItem(NameableCreator creator) {
Nameable nameable = creator.createNameable(JListControlPane.this); getCommonHandlers().onAddItem(creator);
JListControlPane.this.addNameable(nameable, getModel().getSize());
}
}
/*
* 增加项的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("Fine-Design_Basic_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 @Override
public void actionPerformed(ActionEvent e) { public void onRemoveItem() {
if (hasInvalid(true)) { getCommonHandlers().onRemoveItem();
return;
}
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 @Override
public void actionPerformed(ActionEvent evt) { public void onCopyItem() {
try { getCommonHandlers().onCopyItem();
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 @Override
public void actionPerformed(ActionEvent evt) { public void onMoveUpItem() {
// p:选中的值. getCommonHandlers().onMoveUpItem();
ListModelElement selectedValue = (ListModelElement) nameableList.getSelectedValue();
if (selectedValue == null) {
return;
}
((JControlUpdatePane) controlUpdatePane).update();
Nameable selectedNameable = selectedValue.wrapper;
// 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);
}
}
}
/*
* 上移Item
*/
private class MoveUpItemAction extends UpdateAction {
public MoveUpItemAction() {
this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Utils_Move_Up"));
this.setMnemonic('U');
this.setSmallIcon(BaseUtils
.readIcon("/com/fr/design/images/control/up.png"));
} }
@Override @Override
public void actionPerformed(ActionEvent evt) { public void onMoveDownItem() {
int selectedIndex = nameableList.getSelectedIndex(); getCommonHandlers().onMoveDownItem();
if (selectedIndex == -1) {
return;
}
// 上移
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);
nameableList.setSelectedIndex(selectedIndex - 1);
nameableList.ensureIndexIsVisible(selectedIndex - 1);
}
}
}
/*
* 下移Item
*/
private class MoveDownItemAction extends UpdateAction {
public MoveDownItemAction() {
this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Utils_Move_Down"));
this.setMnemonic('D');
this.setSmallIcon(BaseUtils
.readIcon("/com/fr/design/images/control/down.png"));
}
@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);
}
}
}
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 @Override
public void actionPerformed(ActionEvent evt) { public void onSortItem(boolean isAtoZ) {
// p:选中的值. getCommonHandlers().onSortItem(isAtoZ);
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<Nameable> nameableComparator = new Comparator<Nameable>() {
@Override
public int compare(Nameable o1, Nameable o2) {
return -ComparatorUtils.compare(o1.getName(), o2
.getName());
}
};
isAtoZ = !isAtoZ;
Arrays.sort(nameableArray, nameableComparator);
} else {
Comparator<Nameable> nameableComparator = new Comparator<Nameable>() {
@Override @Override
public int compare(Nameable o1, Nameable o2) { public boolean isItemSelected() {
return ComparatorUtils.compare(o1.getName(), o2 return getModel().getSize() > 0 && nameableList.getSelectedIndex() != -1;
.getName());
}
};
isAtoZ = !isAtoZ;
Arrays.sort(nameableArray, nameableComparator);
}
for (int i = 0; i < nameableArray.length; i++) {
listModel.set(i, new ListModelElement(nameableArray[i]));
}
// p:需要选中以前的那个值.
if (selectedValue != null) {
nameableList.setSelectedValue(selectedValue, true);
}
checkButtonEnabled();
// p:需要repaint.
nameableList.repaint();
}
} }
/* /*
@ -649,16 +330,7 @@ public abstract class JListControlPane extends JControlPane {
*/ */
@Override @Override
public void checkButtonEnabled() { public void checkButtonEnabled() {
getHelper().checkButtonEnabled();
int selectedIndex = nameableList.getSelectedIndex();
if (selectedIndex == -1) {
this.cardLayout.show(cardPane, "SELECT");
} else {
this.cardLayout.show(cardPane, "EDIT");
}
for (ShortCut4JControlPane sj : getShorts()) {
sj.checkEnable();
}
} }
private class NameableListCellRenderer extends private class NameableListCellRenderer extends
@ -690,129 +362,13 @@ public abstract class JListControlPane extends JControlPane {
} }
} }
public class AbsoluteEnableShortCut extends ShortCut4JControlPane {
public AbsoluteEnableShortCut(ShortCut shortCut) {
this.shortCut = shortCut;
}
/**
* 检查是否可用
*/
@Override @Override
public void checkEnable() { public BasicBeanPane createPaneByCreators(NameableCreator creator) {
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) {
return Reflect.on(creator.getUpdatePane()).create().get(); 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(); return Reflect.on(creator.getUpdatePane()).create(string).get();
} }
@ -826,35 +382,9 @@ public abstract class JListControlPane extends JControlPane {
((JControlUpdatePane) this.controlUpdatePane).checkValid(); ((JControlUpdatePane) this.controlUpdatePane).checkValid();
} }
private int getInValidIndex() {
BasicBeanPane[] p = ((JControlUpdatePane) controlUpdatePane).updatePanes;
if (p != null) {
for (int i = 0; i < p.length; i++) {
if (p[i] != null) {
try {
p[i].checkValid();
} catch (Exception e) {
return i;
}
}
}
}
return -1;
}
@Override @Override
protected boolean hasInvalid(boolean isAdd) { public boolean hasInvalid(boolean isAdd) {
int idx = JListControlPane.this.getInValidIndex(); return getHelper().hasInvalid(isAdd);
if (isAdd || nameableList.getSelectedIndex() != idx) {
try {
checkValid();
} catch (Exception exp) {
JOptionPane.showMessageDialog(JListControlPane.this, exp.getMessage());
nameableList.setSelectedIndex(idx);
return true;
}
}
return false;
} }
/** /**
@ -862,16 +392,28 @@ public abstract class JListControlPane extends JControlPane {
* *
* @param index 选中项的序列号 * @param index 选中项的序列号
*/ */
@Override
public void setSelectedIndex(int index) { public void setSelectedIndex(int index) {
nameableList.setSelectedIndex(index); nameableList.setSelectedIndex(index);
} }
@Override
public int getSelectedIndex() {
return nameableList.getSelectedIndex();
}
/** @Override
* 用于在list面板中过滤某些下拉选项 public JNameEdList getNameableList() {
* @return true过滤掉这个creator return nameableList;
*/ }
protected boolean filterNameableCreator(NameableCreator creator) {
return !HyperlinkFilterHelper.whetherAddHyperlink4cell(creator.menuName()); @Override
public ListModelElement getSelectedValue() {
return (ListModelElement) this.nameableList.getSelectedValue();
}
@Override
public JControlUpdatePane getControlUpdatePane() {
return (JControlUpdatePane) controlUpdatePane;
} }
} }

112
designer-base/src/main/java/com/fr/design/gui/controlpane/ListControlPaneHelper.java

@ -0,0 +1,112 @@
package com.fr.design.gui.controlpane;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.gui.ilist.JNameEdList;
import com.fr.design.gui.ilist.ListModelElement;
import com.fr.stable.Nameable;
import com.fr.stable.StringUtils;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import java.awt.Component;
/**
* 存放一些公用的方法
* Created by plough on 2018/8/13.
*/
class ListControlPaneHelper {
private ListControlPaneProvider listControlPane;
private ListControlPaneHelper(ListControlPaneProvider listControlPane) {
this.listControlPane = listControlPane;
}
public static ListControlPaneHelper newInstance(ListControlPaneProvider listControlPane) {
return new ListControlPaneHelper(listControlPane);
}
public boolean hasInvalid(boolean isAdd) {
int idx = getInValidIndex();
if (isAdd || listControlPane.getSelectedIndex() != idx) {
try {
listControlPane.checkValid();
} catch (Exception exp) {
JOptionPane.showMessageDialog((Component) listControlPane, exp.getMessage());
listControlPane.setSelectedIndex(idx);
return true;
}
}
return false;
}
private int getInValidIndex() {
BasicBeanPane[] p = listControlPane.getControlUpdatePane().getUpdatePanes();
if (p != null) {
for (int i = 0; i < p.length; i++) {
if (p[i] != null) {
try {
p[i].checkValid();
} catch (Exception e) {
return i;
}
}
}
}
return -1;
}
public Nameable[] update() {
java.util.List<Nameable> res = new java.util.ArrayList<Nameable>();
listControlPane.getControlUpdatePane().update();
DefaultListModel listModel = listControlPane.getModel();
for (int i = 0, len = listModel.getSize(); i < len; i++) {
res.add(((ListModelElement) listModel.getElementAt(i)).wrapper);
}
return res.toArray(new Nameable[res.size()]);
}
/**
* 获取选中的名字
*/
public String getSelectedName() {
ListModelElement el = listControlPane.getSelectedValue();
return el == null ? StringUtils.EMPTY : el.wrapper.getName();
}
/**
* 添加 Nameable
*
* @param nameable 添加的Nameable
* @param index 序号
*/
public void addNameable(Nameable nameable, int index) {
JNameEdList nameableList = listControlPane.getNameableList();
DefaultListModel model = listControlPane.getModel();
ListModelElement el = new ListModelElement(nameable);
model.add(index, el);
nameableList.setSelectedIndex(index);
nameableList.ensureIndexIsVisible(index);
nameableList.repaint();
}
/**
* 检查按钮可用状态 Check button enabled.
*/
public void checkButtonEnabled() {
int selectedIndex = listControlPane.getSelectedIndex();
if (selectedIndex == -1) {
listControlPane.showSelectPane();
} else {
listControlPane.showEditPane();
}
for (ShortCut4JControlPane sj : listControlPane.getShorts()) {
sj.checkEnable();
}
}
}

35
designer-base/src/main/java/com/fr/design/gui/controlpane/ListControlPaneProvider.java

@ -0,0 +1,35 @@
package com.fr.design.gui.controlpane;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.gui.ilist.JNameEdList;
import com.fr.design.gui.ilist.ListModelElement;
import com.fr.stable.Nameable;
import javax.swing.DefaultListModel;
/**
* Created by plough on 2018/8/13.
*/
public interface ListControlPaneProvider extends UnrepeatedNameHelper {
NameableCreator[] creators();
BasicBeanPane createPaneByCreators(NameableCreator creator);
BasicBeanPane createPaneByCreators(NameableCreator creator, String string);
DefaultListModel getModel();
boolean hasInvalid(boolean isAdd);
void addNameable(Nameable nameable, int index);
JNameEdList getNameableList();
int getSelectedIndex();
void setSelectedIndex(int idx);
ListModelElement getSelectedValue();
void checkButtonEnabled();
JControlUpdatePane getControlUpdatePane();
// BasicBeanPane[] getUpdatePanes();
/**
* 检查是否符合规范
* @throws Exception
*/
void checkValid() throws Exception;
void showSelectPane();
void showEditPane();
ShortCut4JControlPane[] getShorts();
}

2
designer-base/src/main/java/com/fr/design/gui/controlpane/ObjectJControlPane.java

@ -22,7 +22,7 @@ public abstract class ObjectJControlPane extends JListControlPane {
} }
@Override @Override
protected BasicBeanPane createPaneByCreators(NameableCreator creator) { public BasicBeanPane createPaneByCreators(NameableCreator creator) {
try { try {
return Reflect.on(creator.getUpdatePane()).create(object).get(); return Reflect.on(creator.getUpdatePane()).create(object).get();
} catch (Exception e) { } catch (Exception e) {

6
designer-base/src/main/java/com/fr/design/gui/controlpane/ObjectUIControlPane.java

@ -10,17 +10,13 @@ import com.fr.design.beans.BasicBeanPane;
public abstract class ObjectUIControlPane extends UIListControlPane { public abstract class ObjectUIControlPane extends UIListControlPane {
private Object object; private Object object;
public ObjectUIControlPane() {
this(null);
}
public ObjectUIControlPane(Object object) { public ObjectUIControlPane(Object object) {
super(); super();
this.object = object; this.object = object;
} }
@Override @Override
protected BasicBeanPane createPaneByCreators(NameableCreator creator) { public BasicBeanPane createPaneByCreators(NameableCreator creator) {
try { try {
if (object == null) { if (object == null) {
return super.createPaneByCreators(creator); return super.createPaneByCreators(creator);

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

203
designer-base/src/main/java/com/fr/design/gui/controlpane/UIControlPane.java

@ -2,7 +2,7 @@ package com.fr.design.gui.controlpane;
import com.fr.base.chart.BasePlot; import com.fr.base.chart.BasePlot;
import com.fr.design.constants.UIConstants; import com.fr.design.constants.UIConstants;
import com.fr.design.dialog.BasicPane; import com.fr.design.gui.controlpane.shortcutfactory.ShortCutFactory;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itoolbar.UIToolBarUI; import com.fr.design.gui.itoolbar.UIToolBarUI;
import com.fr.design.gui.itoolbar.UIToolbar; import com.fr.design.gui.itoolbar.UIToolbar;
@ -11,10 +11,8 @@ import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper; import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerContext;
import com.fr.design.menu.ShortCut; import com.fr.design.menu.ShortCut;
import com.fr.design.menu.ToolBarDef;
import com.fr.design.utils.gui.GUICoreUtils; import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.stable.ArrayUtils; import com.fr.stable.ArrayUtils;
import com.fr.stable.Nameable;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
@ -25,7 +23,6 @@ import javax.swing.JPanel;
import javax.swing.JSplitPane; import javax.swing.JSplitPane;
import javax.swing.border.EmptyBorder; import javax.swing.border.EmptyBorder;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color; import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Cursor; import java.awt.Cursor;
@ -49,85 +46,30 @@ import java.awt.event.WindowEvent;
/** /**
* Created by plough on 2017/7/21. * Created by plough on 2017/7/21.
*/ */
public abstract class UIControlPane extends BasicPane implements UnrepeatedNameHelper { abstract class UIControlPane extends JControlPane {
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;
private UIToolbar topToolBar; private UIToolbar topToolBar;
protected Window popupEditDialog; protected Window popupEditDialog;
// peter:这是整体的一个cardLayout Pane
protected CardLayout cardLayout;
protected JPanel cardPane;
protected BasePlot plot; protected BasePlot plot;
private static final int TOP_TOOLBAR_HEIGHT = 20; private static final int TOP_TOOLBAR_HEIGHT = 20;
private static final int TOP_TOOLBAR_WIDTH = 156; // 可能因为用了tablelayout,要比其他地方多一个像素,看起来才正常 private static final int TOP_TOOLBAR_WIDTH = 156; // 可能因为用了tablelayout,要比其他地方多一个像素,看起来才正常
private static final int TOP_TOOLBAR_WIDTH_SHORT = 76; private static final int TOP_TOOLBAR_WIDTH_SHORT = 76;
public UIControlPane() { UIControlPane() {
this.initComponentPane(); super();
} }
public UIControlPane(BasePlot plot) { UIControlPane(BasePlot plot) {
super();
this.plot = plot; 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) { public abstract void saveSettings();
this.cardLayout = cardLayout;
}
public JPanel getCardPane() {
return cardPane;
}
public void setCardPane(JPanel cardPane) { @Override
this.cardPane = cardPane; protected void initShortCutFactory() {
this.shortCutFactory = ShortCutFactory.newInstance(this);
} }
public abstract void saveSettings();
// 是否使用新样式 // 是否使用新样式
protected boolean isNewStyle() { protected boolean isNewStyle() {
return true; return true;
@ -136,16 +78,9 @@ public abstract class UIControlPane extends BasicPane implements UnrepeatedNameH
protected void initComponentPane() { protected void initComponentPane() {
this.setLayout(FRGUIPaneFactory.createBorderLayout()); this.setLayout(FRGUIPaneFactory.createBorderLayout());
this.creators = this.createNameableCreators(); this.creators = this.createNameableCreators();
this.controlUpdatePane = createControlUpdatePane();
initCardPane();
// p: edit card layout
this.cardLayout = new CardLayout();
cardPane = FRGUIPaneFactory.createCardLayout_S_Pane();
cardPane.setLayout(this.cardLayout);
// p:选择的Label
UILabel selectLabel = new UILabel();
cardPane.add(selectLabel, "SELECT");
cardPane.add(controlUpdatePane, "EDIT");
if (isNewStyle()) { if (isNewStyle()) {
getPopupEditDialog(cardPane); getPopupEditDialog(cardPane);
this.add(getLeftPane(), BorderLayout.CENTER); this.add(getLeftPane(), BorderLayout.CENTER);
@ -169,11 +104,22 @@ public abstract class UIControlPane extends BasicPane implements UnrepeatedNameH
this.checkButtonEnabled(); this.checkButtonEnabled();
} }
protected void getPopupEditDialog(JPanel cardPane) { private void getPopupEditDialog(JPanel cardPane) {
popupEditDialog = new PopupEditDialog(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() { protected JPanel getLeftPane() {
// LeftPane // LeftPane
@ -188,20 +134,8 @@ public abstract class UIControlPane extends BasicPane implements UnrepeatedNameH
return leftPane; return leftPane;
} }
toolbarDef = new ToolBarDef(); initToolBar();
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);
// 封装一层,加边框 // 封装一层,加边框
JPanel toolBarPane = new JPanel(new BorderLayout()); JPanel toolBarPane = new JPanel(new BorderLayout());
toolBarPane.add(toolBar, BorderLayout.CENTER); toolBarPane.add(toolBar, BorderLayout.CENTER);
@ -220,7 +154,7 @@ public abstract class UIControlPane extends BasicPane implements UnrepeatedNameH
}); });
topToolBar.setBorder(null); topToolBar.setBorder(null);
topToolBar.setLayout(new BorderLayout()); topToolBar.setLayout(new BorderLayout());
ShortCut addItem = addItemShortCut().getShortCut(); ShortCut addItem = shortCutFactory.addItemShortCut().getShortCut();
addItem.intoJToolBar(topToolBar); addItem.intoJToolBar(topToolBar);
JPanel leftTopPane = getLeftTopPane(topToolBar); JPanel leftTopPane = getLeftTopPane(topToolBar);
@ -249,85 +183,22 @@ public abstract class UIControlPane extends BasicPane implements UnrepeatedNameH
return "add item "; return "add item ";
} }
/**
* 初始化左边面板
*/
protected void initLeftPane(JPanel leftPane) {
}
protected int getLeftPreferredSize() {
return shorts.length * SHORT_WIDTH;
}
protected ShortCut4JControlPane[] createShortcuts() { protected ShortCut4JControlPane[] createShortcuts() {
return new ShortCut4JControlPane[]{ // return AbstractShortCutFactory.getInstance(this).createNewShortCuts();
copyItemShortCut(), return shortCutFactory.createShortCuts();
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) {
} }
/**
* 检查按钮可用状态 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 * 刷新 NameableCreator
* *
* @param creators 生成器 * @param creators 生成器
*/ */
public void refreshNameableCreator(NameableCreator[] creators) { public void refreshNameableCreator(NameableCreator[] creators) {
this.creators = creators; super.refreshNameableCreator(creators);
shorts = this.createShortcuts();
toolbarDef.clearShortCuts();
for (ShortCut4JControlPane sj : shorts) {
toolbarDef.addShortCut(sj.getShortCut());
}
toolbarDef.updateToolBar(toolBar);
toolBar.validate();
toolBar.repaint();
// 顶部按钮 // 顶部按钮
topToolBar.removeAll(); topToolBar.removeAll();
ShortCut addItem = addItemShortCut().getShortCut(); ShortCut addItem = shortCutFactory.addItemShortCut().getShortCut();
addItem.intoJToolBar(topToolBar); addItem.intoJToolBar(topToolBar);
topToolBar.validate(); topToolBar.validate();
this.controlUpdatePane = createControlUpdatePane();//REPORT-4841 刷新一下编辑面板 this.controlUpdatePane = createControlUpdatePane();//REPORT-4841 刷新一下编辑面板
@ -337,13 +208,13 @@ public abstract class UIControlPane extends BasicPane implements UnrepeatedNameH
} }
// 点击"编辑"按钮,弹出面板 // 点击"编辑"按钮,弹出面板
protected class PopupEditDialog extends JDialog { class PopupEditDialog extends JDialog {
private JComponent editPane; private JComponent editPane;
private PopupToolPane popupToolPane; private PopupToolPane popupToolPane;
private static final int WIDTH = 570; private static final int WIDTH = 570;
private static final int HEIGHT = 490; private static final int HEIGHT = 490;
public PopupEditDialog(JComponent pane) { PopupEditDialog(JComponent pane) {
super(DesignerContext.getDesignerFrame()); super(DesignerContext.getDesignerFrame());
setUndecorated(true); setUndecorated(true);
pane.setBorder(BorderFactory.createEmptyBorder(20, 10, 10, 10)); pane.setBorder(BorderFactory.createEmptyBorder(20, 10, 10, 10));
@ -475,11 +346,11 @@ public abstract class UIControlPane extends BasicPane implements UnrepeatedNameH
} }
}; };
public PopupToolPane(JDialog parentDialog) { PopupToolPane(JDialog parentDialog) {
this(StringUtils.EMPTY, parentDialog); this(StringUtils.EMPTY, parentDialog);
} }
public PopupToolPane(String title, JDialog parentDialog) { PopupToolPane(String title, JDialog parentDialog) {
super(); super();
this.parentDialog = parentDialog; this.parentDialog = parentDialog;
originColor = UIConstants.DIALOG_TITLEBAR_BACKGROUND; originColor = UIConstants.DIALOG_TITLEBAR_BACKGROUND;

776
designer-base/src/main/java/com/fr/design/gui/controlpane/UIListControlPane.java

@ -1,72 +1,81 @@
package com.fr.design.gui.controlpane; 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.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.beans.BasicBeanPane;
import com.fr.design.constants.UIConstants; 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.icontainer.UIScrollPane;
import com.fr.design.gui.ilist.JNameEdList;
import com.fr.design.gui.ilist.ListModelElement; import com.fr.design.gui.ilist.ListModelElement;
import com.fr.design.gui.ilist.UINameEdList; import com.fr.design.gui.ilist.UINameEdList;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.DesignerContext; 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.design.utils.gui.GUICoreUtils;
import com.fr.general.ComparatorUtils;
import com.fr.stable.ArrayUtils; import com.fr.stable.ArrayUtils;
import com.fr.stable.Nameable; import com.fr.stable.Nameable;
import com.fr.stable.StringUtils;
import javax.swing.*; import javax.swing.DefaultListModel;
import javax.swing.JList;
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.ListDataEvent;
import javax.swing.event.ListDataListener; import javax.swing.event.ListDataListener;
import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener; import javax.swing.event.ListSelectionListener;
import java.awt.*; import java.awt.BorderLayout;
import java.awt.event.*; 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.Constructor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Comparator;
/** /**
* Created by plough on 2017/7/19. * 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 String LIST_NAME = "UIControl_List";
private static final int EDIT_RANGE = 25; // 编辑按钮的x坐标范围 private static final int EDIT_RANGE = 25; // 编辑按钮的x坐标范围
protected UINameEdList nameableList; protected UINameEdList nameableList;
protected int editingIndex; private int editingIndex;
protected String selectedName; protected String selectedName;
private boolean isNameRepeated = false;
protected boolean isPopulating = false; protected boolean isPopulating = false;
private CommonShortCutHandlers commonHandlers;
private ListControlPaneHelper helper;
public UIListControlPane() { public UIListControlPane() {
this.initComponentPane(); super();
} }
public UIListControlPane(BasePlot plot) { public UIListControlPane(BasePlot plot) {
super(plot); super(plot);
} }
private ListControlPaneHelper getHelper() {
if (helper == null) {
helper = ListControlPaneHelper.newInstance(this);
}
return helper;
}
private CommonShortCutHandlers getCommonHandlers() {
if (commonHandlers == null) {
commonHandlers = CommonShortCutHandlers.newInstance(this);
}
return commonHandlers;
}
@Override @Override
protected JPanel createControlUpdatePane() { protected JPanel createControlUpdatePane() {
return new JControlUpdatePane(); return JControlUpdatePane.newInstance(this);
} }
/** /**
@ -87,7 +96,7 @@ public abstract class UIListControlPane extends UIControlPane {
nameableList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); nameableList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
nameableList.addMouseListener(listMouseListener); nameableList.addMouseListener(getListMouseListener());
nameableList.addListSelectionListener(new ListSelectionListener() { nameableList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent evt) { public void valueChanged(ListSelectionEvent evt) {
// richie:避免多次update和populate大大降低效率 // richie:避免多次update和populate大大降低效率
@ -122,7 +131,7 @@ public abstract class UIListControlPane extends UIControlPane {
} }
} }
public UINameEdList createJNameList() { private UINameEdList createJNameList() {
UINameEdList nameEdList = new UINameEdList(new DefaultListModel()) { UINameEdList nameEdList = new UINameEdList(new DefaultListModel()) {
@Override @Override
protected void doAfterLostFocus() { protected void doAfterLostFocus() {
@ -137,73 +146,17 @@ public abstract class UIListControlPane extends UIControlPane {
return nameEdList; return nameEdList;
} }
public void updateControlUpdatePane() { private void updateControlUpdatePane() {
((JControlUpdatePane) controlUpdatePane).update(); ((JControlUpdatePane) controlUpdatePane).update();
} }
protected void doWhenPopulate(BasicBeanPane beanPane) { protected void setNameListEditable(boolean editable) {
}
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); this.nameableList.setEditable(editable);
} }
@Override @Override
public Nameable[] update() { public Nameable[] update() {
java.util.List<Nameable> res = new java.util.ArrayList<Nameable>(); return getHelper().update();
((JControlUpdatePane) this.controlUpdatePane).update();
DefaultListModel listModel = (DefaultListModel) this.nameableList.getModel();
for (int i = 0, len = listModel.getSize(); i < len; i++) {
res.add(((ListModelElement) listModel.getElementAt(i)).wrapper);
}
return res.toArray(new Nameable[res.size()]);
} }
@Override @Override
@ -235,9 +188,7 @@ public abstract class UIListControlPane extends UIControlPane {
* 获取选中的名字 * 获取选中的名字
*/ */
public String getSelectedName() { public String getSelectedName() {
ListModelElement el = (ListModelElement) this.nameableList.getSelectedValue(); return getHelper().getSelectedName();
return el == null ? null : el.wrapper.getName();
} }
/** /**
@ -247,86 +198,14 @@ public abstract class UIListControlPane extends UIControlPane {
* @param index 序号 * @param index 序号
*/ */
public void addNameable(Nameable nameable, int index) { public void addNameable(Nameable nameable, int index) {
UINameEdList nameEdList = UIListControlPane.this.nameableList; getHelper().addNameable(nameable, index);
DefaultListModel model = (DefaultListModel) nameEdList.getModel();
ListModelElement el = new ListModelElement(nameable);
model.add(index, el);
nameableList.setSelectedIndex(index);
nameableList.ensureIndexIsVisible(index);
nameEdList.repaint();
popupEditDialog(); popupEditDialog();
} }
/** public DefaultListModel getModel() {
* 是否重命名
*
* @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(); return (DefaultListModel) UIListControlPane.this.nameableList.getModel();
} }
private String createUnrepeatedCopyName(String suffix) {
DefaultListModel model = this.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 名字
*/
@Override
public String createUnrepeatedName(String prefix) {
DefaultListModel model = this.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++;
}
}
private void popupEditDialog() { private void popupEditDialog() {
popupEditDialog(null); popupEditDialog(null);
} }
@ -378,325 +257,56 @@ public abstract class UIListControlPane extends UIControlPane {
} }
/** /**
* 增加项的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. * @param prefix 名字前缀
* @return 名字
*/ */
@Override @Override
public JComponent createToolBarComponent() { public String createUnrepeatedName(String prefix) {
Object object = this.getValue(UIButton.class.getName()); return getCommonHandlers().createUnrepeatedName(prefix);
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 @Override
public void actionPerformed(ActionEvent e) { public void onAddItem(NameableCreator creator) {
Nameable nameable = creator.createNameable(UIListControlPane.this); getCommonHandlers().onAddItem(creator);
UIListControlPane.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);
}
/**
* 生成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("Fine-Design_Basic_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 @Override
public void actionPerformed(ActionEvent e) { public void onRemoveItem() {
if (hasInvalid(true)) { getCommonHandlers().onRemoveItem();
return;
}
Nameable nameable = creator.createNameable(UIListControlPane.this);
UIListControlPane.this.addNameable(nameable, getModel().getSize());
}
});
}
}
protected boolean whetherAdd(String itemName){
return HyperlinkFilterHelper.whetherAddHyperlink4cell(itemName);
}
}
/*
* 移除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 @Override
public void actionPerformed(ActionEvent evt) { public void onCopyItem() {
try { getCommonHandlers().onCopyItem();
UIListControlPane.this.nameableList.getCellEditor()
.stopCellEditing();
} catch (Exception ignored) {
// do nothing
}
// bug:在选中一个NameObject并删除,会遗留下Name.
doBeforeRemove();
if (GUICoreUtils.removeJListSelectedNodes(SwingUtilities
.getWindowAncestor(UIListControlPane.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 @Override
public void actionPerformed(ActionEvent evt) { public void onMoveUpItem() {
// p:选中的值. getCommonHandlers().onMoveUpItem();
ListModelElement selectedValue = (ListModelElement) nameableList.getSelectedValue();
if (selectedValue == null) {
return;
}
((JControlUpdatePane) controlUpdatePane).update();
Nameable selectedNameable = selectedValue.wrapper;
// p: 用反射机制实现
try {
Nameable newNameable = (Nameable) BaseUtils.cloneObject(selectedNameable);
newNameable.setName(createUnrepeatedCopyName(selectedNameable.getName()));
UIListControlPane.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("Fine-Design_Basic_Utils_Move_Up"));
this.setMnemonic('U');
this.setSmallIcon(BaseUtils
.readIcon("/com/fr/design/images/control/up.png"));
} }
@Override @Override
public void actionPerformed(ActionEvent evt) { public void onMoveDownItem() {
int selectedIndex = nameableList.getSelectedIndex(); getCommonHandlers().onMoveDownItem();
if (selectedIndex == -1) {
return;
}
// 上移
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);
nameableList.setSelectedIndex(selectedIndex - 1);
nameableList.ensureIndexIsVisible(selectedIndex - 1);
}
}
}
/*
* 下移Item
*/
private class MoveDownItemAction extends UpdateAction {
public MoveDownItemAction() {
this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Utils_Move_Down"));
this.setMnemonic('D');
this.setSmallIcon(BaseUtils
.readIcon("/com/fr/design/images/control/down.png"));
} }
@Override @Override
public void actionPerformed(ActionEvent evt) { public void onSortItem(boolean isAtoZ) {
int selectedIndex = nameableList.getSelectedIndex(); getCommonHandlers().onSortItem(isAtoZ);
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);
}
}
}
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 @Override
public void actionPerformed(ActionEvent evt) { public boolean isItemSelected() {
// p:选中的值. return getModel().getSize() > 0 && nameableList.getSelectedIndex() != -1;
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<Nameable> nameableComparator = new Comparator<Nameable>() {
@Override
public int compare(Nameable o1, Nameable o2) {
return -ComparatorUtils.compare(o1.getName(), o2
.getName());
}
};
isAtoZ = !isAtoZ;
Arrays.sort(nameableArray, nameableComparator);
} else {
Comparator<Nameable> nameableComparator = new Comparator<Nameable>() {
@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]));
}
// p:需要选中以前的那个值.
if (selectedValue != null) {
nameableList.setSelectedValue(selectedValue, true);
}
checkButtonEnabled();
// p:需要repaint.
nameableList.repaint();
}
} }
/* /*
* UINameEdList的鼠标事件 * UINameEdList的鼠标事件
*/ */
private MouseListener listMouseListener = new MouseAdapter() { private MouseListener getListMouseListener() {
return new MouseAdapter() {
@Override @Override
public void mouseReleased(MouseEvent evt) { public void mouseReleased(MouseEvent evt) {
nameableList.stopEditing(); nameableList.stopEditing();
@ -750,197 +360,17 @@ public abstract class UIListControlPane extends UIControlPane {
} }
}; };
}
/** /**
* 检查按钮可用状态 Check button enabled. * 检查按钮可用状态 Check button enabled.
*/ */
@Override @Override
public void checkButtonEnabled() { public void checkButtonEnabled() {
getHelper().checkButtonEnabled();
int selectedIndex = nameableList.getSelectedIndex();
if (selectedIndex == -1) {
this.cardLayout.show(cardPane, "SELECT");
} else {
this.cardLayout.show(cardPane, "EDIT");
}
for (ShortCut4JControlPane sj : getShorts()) {
sj.checkEnable();
}
}
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 { try {
return creator.getUpdatePane().newInstance(); return creator.getUpdatePane().newInstance();
} catch (InstantiationException e) { } catch (InstantiationException e) {
@ -950,7 +380,7 @@ public abstract class UIListControlPane extends UIControlPane {
} }
} }
protected BasicBeanPane createPaneByCreators(NameableCreator creator, String string) { public BasicBeanPane createPaneByCreators(NameableCreator creator, String string) {
Constructor constructor = null; Constructor constructor = null;
try { try {
constructor = creator.getUpdatePane().getDeclaredConstructor(new Class[]{String.class}); constructor = creator.getUpdatePane().getDeclaredConstructor(new Class[]{String.class});
@ -965,21 +395,6 @@ public abstract class UIListControlPane extends UIControlPane {
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
throw new RuntimeException(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);
}
}
}
} }
/** /**
@ -992,35 +407,9 @@ public abstract class UIListControlPane extends UIControlPane {
((JControlUpdatePane) this.controlUpdatePane).checkValid(); ((JControlUpdatePane) this.controlUpdatePane).checkValid();
} }
private int getInValidIndex() {
BasicBeanPane[] p = ((JControlUpdatePane) controlUpdatePane).updatePanes;
if (p != null) {
for (int i = 0; i < p.length; i++) {
if (p[i] != null) {
try {
p[i].checkValid();
} catch (Exception e) {
return i;
}
}
}
}
return -1;
}
@Override @Override
protected boolean hasInvalid(boolean isAdd) { public boolean hasInvalid(boolean isAdd) {
int idx = UIListControlPane.this.getInValidIndex(); return getHelper().hasInvalid(isAdd);
if (isAdd || nameableList.getSelectedIndex() != idx) {
try {
checkValid();
} catch (Exception exp) {
JOptionPane.showMessageDialog(UIListControlPane.this, exp.getMessage());
nameableList.setSelectedIndex(idx);
return true;
}
}
return false;
} }
/** /**
* 设置选中项 * 设置选中项
@ -1031,4 +420,23 @@ public abstract class UIListControlPane extends UIControlPane {
nameableList.setSelectedIndex(index); nameableList.setSelectedIndex(index);
} }
@Override
public int getSelectedIndex() {
return nameableList.getSelectedIndex();
}
@Override
public ListModelElement getSelectedValue() {
return (ListModelElement) this.nameableList.getSelectedValue();
}
@Override
public JControlUpdatePane getControlUpdatePane() {
return (JControlUpdatePane) controlUpdatePane;
}
@Override
public JNameEdList getNameableList() {
return nameableList;
}
} }

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

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

171
designer-base/src/main/java/com/fr/design/gui/controlpane/shortcutfactory/ShortCutFactory.java

@ -0,0 +1,171 @@
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.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 ShortCutFactory extends AbstractShortCutFactory {
protected ShortCutFactory(ShortCutListenerProvider listenerProvider) {
super(listenerProvider);
}
public static ShortCutFactory newInstance(ShortCutListenerProvider listenerProvider) {
return new ShortCutFactory(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);
}
}
}

61
designer-base/src/main/java/com/fr/design/gui/ilist/JNameEdList.java

@ -22,7 +22,6 @@ import java.util.ArrayList;
import java.util.Vector; import java.util.Vector;
public class JNameEdList extends UIList implements CellEditorListener { public class JNameEdList extends UIList implements CellEditorListener {
private static final int TEST_LIST_LENTH = 20;
private static final int ICON_WIDTH = 20; private static final int ICON_WIDTH = 20;
private boolean editable = true; private boolean editable = true;
@ -232,7 +231,7 @@ public class JNameEdList extends UIList implements CellEditorListener {
} }
Rectangle rect = this.getCellBounds(index, index); Rectangle rect = this.getCellBounds(index, index);
// alex:所有的JNameEdList都有Icon,空出前面20 * 20的位置就是放的Icon // alex:所有的JNameEdList都有Icon,空出前面20 * 20的位置就是放的Icon
rect.setRect(createRect(rect, ICON_WIDTH)); rect.setRect(createRect(rect, getIconWidth()));
editorComp.setBounds(rect); editorComp.setBounds(rect);
add(editorComp); add(editorComp);
@ -247,6 +246,10 @@ public class JNameEdList extends UIList implements CellEditorListener {
return true; return true;
} }
public int getIconWidth() {
return ICON_WIDTH;
}
public Rectangle createRect(Rectangle rect, int iconWidth) { public Rectangle createRect(Rectangle rect, int iconWidth) {
return new Rectangle(rect.x + iconWidth, rect.y, rect.width - iconWidth, rect.height); return new Rectangle(rect.x + iconWidth, rect.y, rect.width - iconWidth, rect.height);
} }
@ -301,9 +304,14 @@ public class JNameEdList extends UIList implements CellEditorListener {
String name = StringUtils.isBlank(value.toString()) ? oldName : value.toString(); String name = StringUtils.isBlank(value.toString()) ? oldName : value.toString();
setNameAt(name, editingIndex); setNameAt(name, editingIndex);
removeComp(); removeComp();
doAfterStopEditing();
} }
} }
protected void doAfterStopEditing() {
// default: do nothing
}
public String[] getAllNames() { public String[] getAllNames() {
int length = this.getModel().getSize(); int length = this.getModel().getSize();
String[] names = new String[length]; String[] names = new String[length];
@ -335,53 +343,4 @@ public class JNameEdList extends UIList implements CellEditorListener {
editorComp = null; editorComp = null;
repaint(cellRect); repaint(cellRect);
} }
/**
* 主函数
*
* @param args 参数
*/
public static void main(String... args) {
JFrame f = new JFrame();
JPanel c = (JPanel) f.getContentPane();
c.setLayout(new BorderLayout());
ListModelElement[] data = new ListModelElement[TEST_LIST_LENTH];
for (int i = 0; i < TEST_LIST_LENTH; i++) {
data[i] = new ListModelElement(new NameObject(i + 1 + "", i));
}
final JNameEdList list = new JNameEdList(data);
list.setEditable(true);
list.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent evt) {
list.stopEditing();
if (evt.getClickCount() >= 2
&& SwingUtilities.isLeftMouseButton(evt)) {
list.editItemAt(list.getSelectedIndex());
}
}
})
;
list.setCellEditor(new DefaultListCellEditor(new UITextField()));
list.setCellRenderer(new NameableListCellRenderer());
c.add(list, BorderLayout.CENTER);
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
f.setSize(400, 600);
f.setVisible(true);
}
private static class NameableListCellRenderer extends DefaultListCellRenderer {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value instanceof Nameable) {
Nameable wrappee = (Nameable) value;
this.setText(wrappee.getName());
}
return this;
}
}
} }

386
designer-base/src/main/java/com/fr/design/gui/ilist/UINameEdList.java

@ -1,163 +1,21 @@
package com.fr.design.gui.ilist; package com.fr.design.gui.ilist;
import com.fr.base.Utils;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.general.NameObject; import com.fr.general.NameObject;
import com.fr.stable.Nameable; import com.fr.stable.Nameable;
import com.fr.stable.StringUtils;
import com.fr.stable.core.PropertyChangeAdapter;
import javax.swing.*; import javax.swing.ListModel;
import javax.swing.event.CellEditorListener; import java.awt.Point;
import javax.swing.event.ChangeEvent;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.Vector;
/** /**
* Created by plough on 2017/7/23. * Created by plough on 2017/7/23.
*/ */
public class UINameEdList extends UIList implements CellEditorListener { public class UINameEdList extends JNameEdList {
private static final int TEST_LIST_LENTH = 20;
private static final int BUTTON_WIDTH = 25; private static final int BUTTON_WIDTH = 25;
private boolean editable = true;
// kunsnat: 是否强制ListName是数字 (int型)
private boolean isNameShouldNumber = false;
transient protected ListCellEditor cellEditor;
transient protected Component editorComp;
transient protected int editingIndex;
private PropertyChangeAdapter editingListner;
private java.util.List<ModNameActionListener> ll = new ArrayList<ModNameActionListener>();
public UINameEdList(ListModel dataModel) { protected UINameEdList(ListModel dataModel) {
super(dataModel); super(dataModel);
} }
public UINameEdList(final Object[] listData) {
super(listData);
}
public UINameEdList(final Vector<?> listData) {
super(listData);
}
public UINameEdList() {
super();
}
/*
* Sets是否可编辑
*/
public void setEditable(boolean editable) {
this.editable = editable;
}
/**
* 是否可编辑
*
* @return 是则返回true
*/
public boolean isEditable() {
return this.editable;
}
public void setNameShouldNumber(boolean isNameShouldNumber) {
this.isNameShouldNumber = isNameShouldNumber;
}
/**
* 是否强制ListName是数字 (int型)
*
* @return 是则返回true
*/
public boolean isNameShouldNumber() {
return isNameShouldNumber;
}
/**
* 添加名字改变时的listener
*
* @param l 监听器
*/
public void addModNameActionListener(ModNameActionListener l) {
ll.add(l);
}
/**
* 编辑时的监听器
*
* @param l 监听器
*/
public void addEditingListner(PropertyChangeAdapter l) {
this.editingListner = l;
}
/**
* 移除某名字改变时的listener
*
* @param l 监听器
*/
public void removeModNameActionListener(ModNameActionListener l) {
ll.remove(l);
}
public ListCellEditor getCellEditor() {
if (cellEditor == null) {
UITextField editField = new UITextField();
if (editingListner != null) {
editField.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
editingListner.propertyChange();
}
@Override
public void focusGained(FocusEvent e) {
// TODO Auto-generated method stub
}
});
}
cellEditor = new DefaultListCellEditor(editField) {
public boolean stopCellEditing() {
boolean isTrue = super.stopCellEditing();
stopEditing();
return isTrue;
}
};
cellEditor.addCellEditorListener(this);
}
return cellEditor;
}
protected void doAfterLostFocus() {
}
public void setCellEditor(ListCellEditor editor) {
this.cellEditor = editor;
}
/*
* 取得index节点的名字
*/
public String getNameAt(int index) {
Nameable nameable = ((ListModelElement) getModel().getElementAt(index)).wrapper;
if (nameable != null) {
return nameable.getName();
}
return null;
}
public Object getType(int index) { public Object getType(int index) {
Nameable nameable = ((ListModelElement) getModel().getElementAt(index)).wrapper; Nameable nameable = ((ListModelElement) getModel().getElementAt(index)).wrapper;
if (nameable != null && nameable instanceof NameObject) { if (nameable != null && nameable instanceof NameObject) {
@ -166,177 +24,8 @@ public class UINameEdList extends UIList implements CellEditorListener {
return null; return null;
} }
/* public int getIconWidth() {
* 设置index节点的名字 return BUTTON_WIDTH;
*/
// b:edit改变name的时候怎么办?
public void setNameAt(String name, int index) {
Nameable nameable = ((ListModelElement) getModel().getElementAt(index)).wrapper;
if (nameable != null) {
String oldName = nameable.getName();
if (isNameShouldNumber()) {
// kunsnat: 限制只能是数字(int型)
Number number = Utils.string2Number(name);
if (number == null) {
nameable.setName(oldName);
} else {
int newName = number.intValue();
nameable.setName(String.valueOf(newName));
}
} else {
nameable.setName(name);
}
for (int i = 0, len = ll.size(); i < len; i++) {
ll.get(i).nameModed(index, oldName, name);
}
}
}
/*
* 编辑第index个item
*/
private String oldName;
/**
* 编辑第index项
*
* @param index 序号
* @return 成功返回true
*/
public boolean editItemAt(int index) {
// 如果不可编辑,返回
if (!this.editable) {
return false;
}
if (cellEditor != null && !cellEditor.stopCellEditing()) {
return false;
}
if (index < 0 || index >= this.getModel().getSize()) {
return false;
}
ListCellEditor editor = getCellEditor();
Object value = editor.getCellEditorValue();
if (!StringUtils.isBlank(value.toString())) {
oldName = value.toString();
}
editorComp = prepareEditor(editor, index);
if (editorComp == null) {
return false;
}
Rectangle rect = this.getCellBounds(index, index);
// alex:所有的UINameEdList都有Icon,空出前面20 * 20的位置就是放的Icon
rect.setRect(createRect(rect, BUTTON_WIDTH));
editorComp.setBounds(rect);
add(editorComp);
editorComp.validate();
editorComp.requestFocus();
if (editorComp instanceof UITextField) {
((UITextField) editorComp).selectAll();
}
setEditingIndex(index);
return true;
}
public Rectangle createRect(Rectangle rect, int iconWidth) {
return new Rectangle(rect.x + iconWidth, rect.y, rect.width - iconWidth, rect.height);
}
public String getEditingName() {
return (String) getCellEditor().getCellEditorValue();
}
/*
* 根据ListCellEditor取得编辑器的Component
*/
private Component prepareEditor(ListCellEditor cellEditor, int index) {
String name = getNameAt(index);
boolean isSelected = this.isSelectedIndex(index);
Component comp = cellEditor.getListCellEditorComponent(this, name, isSelected, index);
return comp;
}
/*
* 记录正在编辑的index
*/
private void setEditingIndex(int idx) {
editingIndex = idx;
}
/**
* 编辑取消
*
* @param e 事件
*/
public void editingCanceled(ChangeEvent e) {
removeComp();
}
/**
* 编辑结束
*
* @param e 事件
*/
public void editingStopped(ChangeEvent e) {
doAfterLostFocus();
stopEditing();
}
/**
* 停止编辑事件
*/
public void stopEditing() {
ListCellEditor editor = getCellEditor();
if (editor != null && editorComp != null) {
Object value = editor.getCellEditorValue();
String name = StringUtils.isBlank(value.toString()) ? oldName : value.toString();
setNameAt(name, editingIndex);
removeComp();
doAfterStopEditing();
}
}
protected void doAfterStopEditing() {
// default: do nothing
}
public String[] getAllNames() {
int length = this.getModel().getSize();
String[] names = new String[length];
for (int i = 0; i < length; i++) {
names[i] = getNameAt(i);
}
return names;
}
public Object[] getAllTypes() {
int length = this.getModel().getSize();
Object[] types = new Object[length];
for (int i = 0; i < length; i++) {
types[i] = getType(i);
}
return types;
}
/*
* 移除编辑器的Component
*/
private void removeComp() {
if (editorComp != null) {
remove(editorComp);
}
Rectangle cellRect = this.getCellBounds(editingIndex, editingIndex);
setEditingIndex(-1);
editorComp = null;
repaint(cellRect);
} }
@Override @Override
@ -349,67 +38,4 @@ public class UINameEdList extends UIList implements CellEditorListener {
return index; return index;
} }
} }
/**
* 主函数
*
* @param args 参数
*/
public static void main(String... args) {
JFrame f = new JFrame();
JPanel c = (JPanel) f.getContentPane();
c.setLayout(new BorderLayout());
ListModelElement[] data = new ListModelElement[TEST_LIST_LENTH];
for (int i = 0; i < TEST_LIST_LENTH; i++) {
data[i] = new ListModelElement(new NameObject(i + 1 + "", i));
}
final UINameEdList list = new UINameEdList(data);
list.setEditable(true);
list.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent evt) {
list.stopEditing();
if (evt.getClickCount() >= 2
&& SwingUtilities.isLeftMouseButton(evt)) {
list.editItemAt(list.getSelectedIndex());
}
}
@Override
public void mouseClicked(MouseEvent e) {
JList list = (JList) e.getSource();
if (list.locationToIndex(e.getPoint()) == -1 && !e.isShiftDown()
&& !isMenuShortcutKeyDown(e)) {
list.clearSelection();
}
}
private boolean isMenuShortcutKeyDown(InputEvent event) {
return (event.getModifiers() & Toolkit.getDefaultToolkit()
.getMenuShortcutKeyMask()) != 0;
}
})
;
list.setCellEditor(new DefaultListCellEditor(new UITextField()));
list.setCellRenderer(new NameableListCellRenderer());
c.add(list, BorderLayout.CENTER);
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
f.setSize(400, 600);
f.setVisible(true);
}
private static class NameableListCellRenderer extends DefaultListCellRenderer {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value instanceof Nameable) {
Nameable wrappee = (Nameable) value;
this.setText(wrappee.getName());
}
return this;
}
}
} }

5
designer-base/src/main/java/com/fr/env/EnvListPane.java vendored

@ -103,9 +103,4 @@ public class EnvListPane extends JListControlPane {
} }
return this.getSelectedName(); return this.getSelectedName();
} }
@Override
protected boolean filterNameableCreator(NameableCreator creator) {
return false;
}
} }

18
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<? extends BasicBeanPane> constructor = null; Constructor<? extends BasicBeanPane> constructor = null;
try { try {
constructor = creator.getUpdatePane().getConstructor(HashMap.class, boolean.class); constructor = creator.getUpdatePane().getConstructor(HashMap.class, boolean.class);
@ -111,8 +111,8 @@ public class VanChartHyperLinkPane extends VanChartUIListControlPane {
} }
@Override @Override
protected AddItemMenuDef getAddItemMenuDef (NameableCreator[] creators) { protected void initShortCutFactory() {
return new AddVanChartItemMenuDef(creators); this.shortCutFactory = VanChartShortCutFactory.newInstance(this);
} }
public void populate(NameJavaScriptGroup nameHyperlink_array) { public void populate(NameJavaScriptGroup nameHyperlink_array) {
@ -272,18 +272,6 @@ public class VanChartHyperLinkPane extends VanChartUIListControlPane {
return null; 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 { public static class VanChartEmailPane extends ChartEmailPane {
@Override @Override

33
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.shortcutfactory.ShortCutFactory;
import com.fr.design.gui.controlpane.ShortCutListenerProvider;
import com.fr.design.menu.ShortCut;
/**
* Created by plough on 2018/8/13.
*/
public class VanChartShortCutFactory extends ShortCutFactory {
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);
}
}
}

2
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<? extends BasicBeanPane> constructor = null; Constructor<? extends BasicBeanPane> constructor = null;
try { try {
constructor = creator.getUpdatePane().getConstructor(Plot.class); constructor = creator.getUpdatePane().getConstructor(Plot.class);

6
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() { protected ShortCut4JControlPane[] createShortcuts() {
return new ShortCut4JControlPane[]{ return new ShortCut4JControlPane[]{
moveUpItemShortCut(), shortCutFactory.moveUpItemShortCut(),
moveDownItemShortCut(), shortCutFactory.moveDownItemShortCut(),
removeItemShortCut() shortCutFactory.removeItemShortCut()
}; };
} }

6
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() { protected ShortCut4JControlPane[] createShortcuts() {
return new ShortCut4JControlPane[]{ return new ShortCut4JControlPane[]{
moveUpItemShortCut(), shortCutFactory.moveUpItemShortCut(),
moveDownItemShortCut(), shortCutFactory.moveDownItemShortCut(),
removeItemShortCut() shortCutFactory.removeItemShortCut()
}; };
} }

6
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() { protected ShortCut4JControlPane[] createShortcuts() {
return new ShortCut4JControlPane[]{ return new ShortCut4JControlPane[]{
moveUpItemShortCut(), shortCutFactory.moveUpItemShortCut(),
moveDownItemShortCut(), shortCutFactory.moveDownItemShortCut(),
removeItemShortCut() shortCutFactory.removeItemShortCut()
}; };
} }

6
designer-realize/src/main/java/com/fr/design/report/share/ConfusionManagerPane.java

@ -77,7 +77,11 @@ public class ConfusionManagerPane extends JListControlPane {
@Override @Override
protected ShortCut4JControlPane[] createShortcuts() { protected ShortCut4JControlPane[] createShortcuts() {
return new ShortCut4JControlPane[] { moveUpItemShortCut(), moveDownItemShortCut(), sortItemShortCut() }; return new ShortCut4JControlPane[] {
shortCutFactory.moveUpItemShortCut(),
shortCutFactory.moveDownItemShortCut(),
shortCutFactory.sortItemShortCut()
};
} }
} }

Loading…
Cancel
Save