Browse Source

REPORT-10045 重构 UIListControlPane 和 JListControlPane => 调整代码,修复一个bug

final/10.0
plough 6 years ago
parent
commit
87af02ba02
  1. 4
      designer-base/src/main/java/com/fr/design/gui/controlpane/UIControlPane.java
  2. 92
      designer-base/src/main/java/com/fr/design/gui/controlpane/UIListControlPane.java
  3. 8
      designer-base/src/main/java/com/fr/design/gui/controlpane/shortcutfactory/ShortCutFactory.java
  4. 46
      designer-base/src/main/java/com/fr/design/gui/ilist/UINameEdList.java
  5. 68
      designer-base/src/test/java/com/fr/design/gui/ilist/JNameEdListTest.java
  6. 82
      designer-base/src/test/java/com/fr/design/gui/ilist/UINameEdListTest.java
  7. 4
      designer-chart/src/main/java/com/fr/van/chart/custom/component/VanChartShortCutFactory.java

4
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.gui.controlpane.shortcutfactory.NewShortCutFactory; 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;
@ -67,7 +67,7 @@ abstract class UIControlPane extends JControlPane {
@Override @Override
protected void initShortCutFactory() { protected void initShortCutFactory() {
this.shortCutFactory = NewShortCutFactory.newInstance(this); this.shortCutFactory = ShortCutFactory.newInstance(this);
} }
// 是否使用新样式 // 是否使用新样式

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

@ -96,7 +96,7 @@ public abstract class UIListControlPane extends UIControlPane implements ListCon
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大大降低效率
@ -305,60 +305,62 @@ public abstract class UIListControlPane extends UIControlPane implements ListCon
/* /*
* UINameEdList的鼠标事件 * UINameEdList的鼠标事件
*/ */
private MouseListener listMouseListener = new MouseAdapter() { private MouseListener getListMouseListener() {
@Override return new MouseAdapter() {
public void mouseReleased(MouseEvent evt) { @Override
nameableList.stopEditing(); public void mouseReleased(MouseEvent evt) {
if (evt.getClickCount() >= 2 nameableList.stopEditing();
&& SwingUtilities.isLeftMouseButton(evt) && evt.getX() > EDIT_RANGE) { if (evt.getClickCount() >= 2
editingIndex = nameableList.getSelectedIndex(); && SwingUtilities.isLeftMouseButton(evt) && evt.getX() > EDIT_RANGE) {
selectedName = nameableList.getNameAt(editingIndex); editingIndex = nameableList.getSelectedIndex();
nameableList.editItemAt(nameableList.getSelectedIndex()); selectedName = nameableList.getNameAt(editingIndex);
} else if (SwingUtilities.isLeftMouseButton(evt) && evt.getX() <= EDIT_RANGE) { nameableList.editItemAt(nameableList.getSelectedIndex());
editingIndex = nameableList.getSelectedIndex(); } else if (SwingUtilities.isLeftMouseButton(evt) && evt.getX() <= EDIT_RANGE) {
selectedName = nameableList.getNameAt(editingIndex); editingIndex = nameableList.getSelectedIndex();
popupEditDialog(evt.getPoint()); selectedName = nameableList.getNameAt(editingIndex);
} popupEditDialog(evt.getPoint());
}
// peter:处理右键的弹出菜单 // peter:处理右键的弹出菜单
if (!SwingUtilities.isRightMouseButton(evt)) { if (!SwingUtilities.isRightMouseButton(evt)) {
return; return;
} }
// peter: 注意,在checkButtonEnabled()方法里面,设置了所有的Action的Enabled. // peter: 注意,在checkButtonEnabled()方法里面,设置了所有的Action的Enabled.
checkButtonEnabled(); checkButtonEnabled();
// p:右键菜单. // p:右键菜单.
JPopupMenu popupMenu = new JPopupMenu(); JPopupMenu popupMenu = new JPopupMenu();
for (ShortCut4JControlPane sj : getShorts()) { for (ShortCut4JControlPane sj : getShorts()) {
sj.getShortCut().intoJPopupMenu(popupMenu); sj.getShortCut().intoJPopupMenu(popupMenu);
} }
// peter: 只有弹出菜单有子菜单的时候,才需要弹出来. // peter: 只有弹出菜单有子菜单的时候,才需要弹出来.
GUICoreUtils.showPopupMenu(popupMenu, nameableList, evt.getX() - 1, GUICoreUtils.showPopupMenu(popupMenu, nameableList, evt.getX() - 1,
evt.getY() - 1); evt.getY() - 1);
} }
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
JList list = (JList) e.getSource(); JList list = (JList) e.getSource();
if (list.locationToIndex(e.getPoint()) == -1 && !e.isShiftDown() if (list.locationToIndex(e.getPoint()) == -1 && !e.isShiftDown()
&& !isMenuShortcutKeyDown(e)) { && !isMenuShortcutKeyDown(e)) {
list.clearSelection(); list.clearSelection();
}
} }
}
private boolean isMenuShortcutKeyDown(InputEvent event) { private boolean isMenuShortcutKeyDown(InputEvent event) {
return (event.getModifiers() & Toolkit.getDefaultToolkit() return (event.getModifiers() & Toolkit.getDefaultToolkit()
.getMenuShortcutKeyMask()) != 0; .getMenuShortcutKeyMask()) != 0;
} }
@Override @Override
public void mouseMoved(MouseEvent e) { public void mouseMoved(MouseEvent e) {
} }
}; };
}
/** /**
* 检查按钮可用状态 Check button enabled. * 检查按钮可用状态 Check button enabled.

8
designer-base/src/main/java/com/fr/design/gui/controlpane/shortcutfactory/NewShortCutFactory.java → designer-base/src/main/java/com/fr/design/gui/controlpane/shortcutfactory/ShortCutFactory.java

@ -23,14 +23,14 @@ import java.awt.event.ActionEvent;
/** /**
* Created by plough on 2018/8/13. * Created by plough on 2018/8/13.
*/ */
public class NewShortCutFactory extends AbstractShortCutFactory { public class ShortCutFactory extends AbstractShortCutFactory {
protected NewShortCutFactory(ShortCutListenerProvider listenerProvider) { protected ShortCutFactory(ShortCutListenerProvider listenerProvider) {
super(listenerProvider); super(listenerProvider);
} }
public static NewShortCutFactory newInstance(ShortCutListenerProvider listenerProvider) { public static ShortCutFactory newInstance(ShortCutListenerProvider listenerProvider) {
return new NewShortCutFactory(listenerProvider); return new ShortCutFactory(listenerProvider);
} }
@Override @Override

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

@ -1,54 +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 JNameEdList { 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();
}
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) {
@ -71,11 +38,4 @@ public class UINameEdList extends JNameEdList {
return index; return index;
} }
} }
/**
* 主函数
*
* @param args 参数
*/
} }

68
designer-base/src/test/java/com/fr/design/gui/ilist/JNameEdListTest.java

@ -1,68 +0,0 @@
package com.fr.design.gui.ilist;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.general.NameObject;
import com.fr.stable.Nameable;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Toolkit;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
/**
* Created by plough on 2018/8/13.
*/
public class JNameEdListTest {
private static final int TEST_LIST_LENTH = 20;
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;
}
}
}

82
designer-base/src/test/java/com/fr/design/gui/ilist/UINameEdListTest.java

@ -1,82 +0,0 @@
package com.fr.design.gui.ilist;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.general.NameObject;
import com.fr.stable.Nameable;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Toolkit;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
/**
* Created by plough on 2018/8/13.
*/
public class UINameEdListTest {
private static final int TEST_LIST_LENTH = 20;
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;
}
}
}

4
designer-chart/src/main/java/com/fr/van/chart/custom/component/VanChartShortCutFactory.java

@ -2,14 +2,14 @@ package com.fr.van.chart.custom.component;
import com.fr.design.gui.HyperlinkFilterHelper; import com.fr.design.gui.HyperlinkFilterHelper;
import com.fr.design.gui.controlpane.NameableCreator; import com.fr.design.gui.controlpane.NameableCreator;
import com.fr.design.gui.controlpane.shortcutfactory.NewShortCutFactory; import com.fr.design.gui.controlpane.shortcutfactory.ShortCutFactory;
import com.fr.design.gui.controlpane.ShortCutListenerProvider; import com.fr.design.gui.controlpane.ShortCutListenerProvider;
import com.fr.design.menu.ShortCut; import com.fr.design.menu.ShortCut;
/** /**
* Created by plough on 2018/8/13. * Created by plough on 2018/8/13.
*/ */
public class VanChartShortCutFactory extends NewShortCutFactory { public class VanChartShortCutFactory extends ShortCutFactory {
private VanChartShortCutFactory(ShortCutListenerProvider listenerProvider) { private VanChartShortCutFactory(ShortCutListenerProvider listenerProvider) {
super(listenerProvider); super(listenerProvider);
} }

Loading…
Cancel
Save