Browse Source
* commit '87af02ba02f9a86a1f44c8c86e47853049ec3c8b': REPORT-10045 重构 UIListControlPane 和 JListControlPane => 调整代码,修复一个bug REPORT-10045 重构 UIListControlPane 和 JListControlPane REPORT-10045 重构 UIListControlPane 和 JListControlPane(部分)final/10.0
plough
6 years ago
24 changed files with 1341 additions and 1976 deletions
@ -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++; |
||||
} |
||||
} |
||||
} |
@ -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(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -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(); |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
@ -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(); |
||||
} |
@ -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(); |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -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); |
||||
} |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
}); |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
@ -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); |
||||
} |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue