diff --git a/designer-base/src/main/java/com/fr/design/gui/controlpane/UIControlPane.java b/designer-base/src/main/java/com/fr/design/gui/controlpane/UIControlPane.java index 23583f2278..ff9e48e5db 100644 --- a/designer-base/src/main/java/com/fr/design/gui/controlpane/UIControlPane.java +++ b/designer-base/src/main/java/com/fr/design/gui/controlpane/UIControlPane.java @@ -2,7 +2,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); } // 是否使用新样式 diff --git a/designer-base/src/main/java/com/fr/design/gui/controlpane/UIListControlPane.java b/designer-base/src/main/java/com/fr/design/gui/controlpane/UIListControlPane.java index 6d8942bba8..de2a42fa80 100644 --- a/designer-base/src/main/java/com/fr/design/gui/controlpane/UIListControlPane.java +++ b/designer-base/src/main/java/com/fr/design/gui/controlpane/UIListControlPane.java @@ -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,60 +305,62 @@ public abstract class UIListControlPane extends UIControlPane implements ListCon /* * UINameEdList的鼠标事件 */ - private MouseListener listMouseListener = new MouseAdapter() { - @Override - public void mouseReleased(MouseEvent evt) { - nameableList.stopEditing(); - if (evt.getClickCount() >= 2 - && SwingUtilities.isLeftMouseButton(evt) && evt.getX() > EDIT_RANGE) { - editingIndex = nameableList.getSelectedIndex(); - selectedName = nameableList.getNameAt(editingIndex); - nameableList.editItemAt(nameableList.getSelectedIndex()); - } else if (SwingUtilities.isLeftMouseButton(evt) && evt.getX() <= EDIT_RANGE) { - editingIndex = nameableList.getSelectedIndex(); - selectedName = nameableList.getNameAt(editingIndex); - popupEditDialog(evt.getPoint()); - } + private MouseListener getListMouseListener() { + return new MouseAdapter() { + @Override + public void mouseReleased(MouseEvent evt) { + nameableList.stopEditing(); + if (evt.getClickCount() >= 2 + && SwingUtilities.isLeftMouseButton(evt) && evt.getX() > EDIT_RANGE) { + editingIndex = nameableList.getSelectedIndex(); + selectedName = nameableList.getNameAt(editingIndex); + nameableList.editItemAt(nameableList.getSelectedIndex()); + } else if (SwingUtilities.isLeftMouseButton(evt) && evt.getX() <= EDIT_RANGE) { + editingIndex = nameableList.getSelectedIndex(); + selectedName = nameableList.getNameAt(editingIndex); + popupEditDialog(evt.getPoint()); + } - // peter:处理右键的弹出菜单 - if (!SwingUtilities.isRightMouseButton(evt)) { - return; - } + // peter:处理右键的弹出菜单 + if (!SwingUtilities.isRightMouseButton(evt)) { + return; + } - // peter: 注意,在checkButtonEnabled()方法里面,设置了所有的Action的Enabled. - checkButtonEnabled(); + // peter: 注意,在checkButtonEnabled()方法里面,设置了所有的Action的Enabled. + checkButtonEnabled(); - // p:右键菜单. - JPopupMenu popupMenu = new JPopupMenu(); + // p:右键菜单. + JPopupMenu popupMenu = new JPopupMenu(); - for (ShortCut4JControlPane sj : getShorts()) { - sj.getShortCut().intoJPopupMenu(popupMenu); - } + for (ShortCut4JControlPane sj : getShorts()) { + sj.getShortCut().intoJPopupMenu(popupMenu); + } - // peter: 只有弹出菜单有子菜单的时候,才需要弹出来. - GUICoreUtils.showPopupMenu(popupMenu, nameableList, evt.getX() - 1, - evt.getY() - 1); - } + // peter: 只有弹出菜单有子菜单的时候,才需要弹出来. + GUICoreUtils.showPopupMenu(popupMenu, nameableList, evt.getX() - 1, + evt.getY() - 1); + } - @Override - public void mouseClicked(MouseEvent e) { - JList list = (JList) e.getSource(); - if (list.locationToIndex(e.getPoint()) == -1 && !e.isShiftDown() - && !isMenuShortcutKeyDown(e)) { - list.clearSelection(); + @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; - } + private boolean isMenuShortcutKeyDown(InputEvent event) { + return (event.getModifiers() & Toolkit.getDefaultToolkit() + .getMenuShortcutKeyMask()) != 0; + } - @Override - public void mouseMoved(MouseEvent e) { + @Override + public void mouseMoved(MouseEvent e) { - } - }; + } + }; + } /** * 检查按钮可用状态 Check button enabled. diff --git a/designer-base/src/main/java/com/fr/design/gui/controlpane/shortcutfactory/NewShortCutFactory.java b/designer-base/src/main/java/com/fr/design/gui/controlpane/shortcutfactory/ShortCutFactory.java similarity index 95% rename from designer-base/src/main/java/com/fr/design/gui/controlpane/shortcutfactory/NewShortCutFactory.java rename to designer-base/src/main/java/com/fr/design/gui/controlpane/shortcutfactory/ShortCutFactory.java index 5975dbc0c5..b561c28bac 100644 --- a/designer-base/src/main/java/com/fr/design/gui/controlpane/shortcutfactory/NewShortCutFactory.java +++ b/designer-base/src/main/java/com/fr/design/gui/controlpane/shortcutfactory/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 diff --git a/designer-base/src/main/java/com/fr/design/gui/ilist/UINameEdList.java b/designer-base/src/main/java/com/fr/design/gui/ilist/UINameEdList.java index f014096930..131adbed7a 100644 --- a/designer-base/src/main/java/com/fr/design/gui/ilist/UINameEdList.java +++ b/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 ll = new ArrayList(); - 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 参数 - */ - } \ No newline at end of file diff --git a/designer-base/src/test/java/com/fr/design/gui/ilist/JNameEdListTest.java b/designer-base/src/test/java/com/fr/design/gui/ilist/JNameEdListTest.java deleted file mode 100644 index ba611a66b9..0000000000 --- a/designer-base/src/test/java/com/fr/design/gui/ilist/JNameEdListTest.java +++ /dev/null @@ -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; - } - } -} diff --git a/designer-base/src/test/java/com/fr/design/gui/ilist/UINameEdListTest.java b/designer-base/src/test/java/com/fr/design/gui/ilist/UINameEdListTest.java deleted file mode 100644 index b2d0c8da42..0000000000 --- a/designer-base/src/test/java/com/fr/design/gui/ilist/UINameEdListTest.java +++ /dev/null @@ -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; - } - } -} diff --git a/designer-chart/src/main/java/com/fr/van/chart/custom/component/VanChartShortCutFactory.java b/designer-chart/src/main/java/com/fr/van/chart/custom/component/VanChartShortCutFactory.java index 753d98d483..9690654553 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/custom/component/VanChartShortCutFactory.java +++ b/designer-chart/src/main/java/com/fr/van/chart/custom/component/VanChartShortCutFactory.java @@ -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); }