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. 6
      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.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.itoolbar.UIToolBarUI;
import com.fr.design.gui.itoolbar.UIToolbar;
@ -67,7 +67,7 @@ abstract class UIControlPane extends JControlPane {
@Override
protected void initShortCutFactory() {
this.shortCutFactory = NewShortCutFactory.newInstance(this);
this.shortCutFactory = ShortCutFactory.newInstance(this);
}
// 是否使用新样式

6
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.addMouseListener(listMouseListener);
nameableList.addMouseListener(getListMouseListener());
nameableList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent evt) {
// richie:避免多次update和populate大大降低效率
@ -305,7 +305,8 @@ public abstract class UIListControlPane extends UIControlPane implements ListCon
/*
* UINameEdList的鼠标事件
*/
private MouseListener listMouseListener = new MouseAdapter() {
private MouseListener getListMouseListener() {
return new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent evt) {
nameableList.stopEditing();
@ -359,6 +360,7 @@ public abstract class UIListControlPane extends UIControlPane implements ListCon
}
};
}
/**
* 检查按钮可用状态 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.
*/
public class NewShortCutFactory extends AbstractShortCutFactory {
public class ShortCutFactory extends AbstractShortCutFactory {
protected NewShortCutFactory(ShortCutListenerProvider listenerProvider) {
protected ShortCutFactory(ShortCutListenerProvider listenerProvider) {
super(listenerProvider);
}
public static NewShortCutFactory newInstance(ShortCutListenerProvider listenerProvider) {
return new NewShortCutFactory(listenerProvider);
public static ShortCutFactory newInstance(ShortCutListenerProvider listenerProvider) {
return new ShortCutFactory(listenerProvider);
}
@Override

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

@ -1,54 +1,21 @@
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.stable.Nameable;
import com.fr.stable.StringUtils;
import com.fr.stable.core.PropertyChangeAdapter;
import javax.swing.*;
import javax.swing.event.CellEditorListener;
import javax.swing.event.ChangeEvent;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.ListModel;
import java.awt.Point;
/**
* Created by plough on 2017/7/23.
*/
public class UINameEdList extends JNameEdList {
// private static final int TEST_LIST_LENTH = 20;
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);
}
public UINameEdList(final Object[] listData) {
super(listData);
}
public UINameEdList(final Vector<?> listData) {
super(listData);
}
public UINameEdList() {
super();
}
public Object getType(int index) {
Nameable nameable = ((ListModelElement) getModel().getElementAt(index)).wrapper;
if (nameable != null && nameable instanceof NameObject) {
@ -71,11 +38,4 @@ public class UINameEdList extends JNameEdList {
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.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.menu.ShortCut;
/**
* Created by plough on 2018/8/13.
*/
public class VanChartShortCutFactory extends NewShortCutFactory {
public class VanChartShortCutFactory extends ShortCutFactory {
private VanChartShortCutFactory(ShortCutListenerProvider listenerProvider) {
super(listenerProvider);
}

Loading…
Cancel
Save