From fe785e4afc103f4913fa5f51a0d7f30a9925e545 Mon Sep 17 00:00:00 2001 From: fr_shine Date: Wed, 9 Nov 2016 17:00:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E8=A1=A8=E5=88=87=E6=8D=A2button?= =?UTF-8?q?=E9=87=8D=E5=91=BD=E5=90=8D=E7=BB=93=E6=9D=9F=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chart/gui/ChartTypeButtonPane.java | 67 +++++++++++-------- 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypeButtonPane.java b/designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypeButtonPane.java index 8ee4e4667f..8d9ed81530 100644 --- a/designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypeButtonPane.java +++ b/designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypeButtonPane.java @@ -1,10 +1,10 @@ package com.fr.design.mainframe.chart.gui; import com.fr.base.BaseUtils; +import com.fr.chart.base.AttrChangeConfig; import com.fr.chart.chartattr.Chart; import com.fr.chart.chartattr.ChartCollection; import com.fr.chart.chartattr.SwitchState; -import com.fr.chart.base.AttrChangeConfig; import com.fr.design.beans.BasicBeanPane; import com.fr.design.dialog.DialogActionListener; import com.fr.design.dialog.UIDialog; @@ -53,19 +53,14 @@ public class ChartTypeButtonPane extends BasicBeanPane implemen private ChartTypePane parent = null; - //记录鼠标当前是否在操作添加按钮 - private boolean mouseOnChartTypeButtonPane = false; - //配置窗口属性 private UIMenuNameableCreator configCreator; - /** - * 鼠标事件是否在这个面板 - * @return 返回是否 - */ - public boolean isMouseOnChartTypeButtonPane() { - return this.mouseOnChartTypeButtonPane; - } + //处理 编辑一个button时,选中另一个button的问题. + //stopEditing不能直接relayout,否则click事件不响应了. + //所以:stopEditing--选中其他button则响应click之后relayout;普通失焦则直接relayout. + private boolean pressOtherButtonWhenEditing = false; + // private AWTEventListener awt = new AWTEventListener() { // public void eventDispatched(AWTEvent event) { @@ -122,7 +117,6 @@ public class ChartTypeButtonPane extends BasicBeanPane implemen private void initAddButton() { addButton.setPreferredSize(new Dimension(20, 20)); addButton.addActionListener(addListener); - addButton.addMouseListener(mouseListener); } private void initConfigButton() { @@ -133,7 +127,6 @@ public class ChartTypeButtonPane extends BasicBeanPane implemen ActionListener addListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - mouseOnChartTypeButtonPane = true; String name = getNewChartName(); ChartChangeButton button = new ChartChangeButton(name);// some set selected @@ -188,15 +181,6 @@ public class ChartTypeButtonPane extends BasicBeanPane implemen dialog.setVisible(true); } }; - - - MouseListener mouseListener = new MouseAdapter() { - @Override - public void mouseExited(MouseEvent e) { - super.mouseExited(e); - mouseOnChartTypeButtonPane = false; - } - }; private String getNewChartName() { int count = indexList.size() + 1; @@ -352,12 +336,19 @@ public class ChartTypeButtonPane extends BasicBeanPane implemen if (currentEditingEditor != null) { String newName = currentEditingEditor.getText(); int selectedIndex = editingCollection.getSelectedIndex(); + ChartChangeButton button = indexList.get(selectedIndex); + button.isMoveOn = false; if (!ComparatorUtils.equals(editingCollection.getChartName(selectedIndex), newName)) { editingCollection.setChartName(selectedIndex, newName); HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().fireTargetModified(); + button.changeChartName(newName); } buttonPane.remove(currentEditingEditor); currentEditingEditor = null; + + if(!pressOtherButtonWhenEditing) { + layoutPane(buttonPane); + } } } @@ -375,11 +366,25 @@ public class ChartTypeButtonPane extends BasicBeanPane implemen buttonName = name; this.setToolTipText(name); - nameField.addActionListener(new ActionListener() { + nameField.addActionListener(new ActionListener() {//enter @Override public void actionPerformed(ActionEvent e) { + pressOtherButtonWhenEditing = false; stopEditing(); - populateBean(editingCollection); + } + }); + + nameField.addFocusListener(new FocusListener() { + @Override + public void focusGained(FocusEvent e) { + + } + + @Override + public void focusLost(FocusEvent e) {//编辑状态lost才走这边 + if (currentEditingEditor != null ) { + stopEditing(); + } } }); } @@ -388,6 +393,11 @@ public class ChartTypeButtonPane extends BasicBeanPane implemen return buttonName; } + private void changeChartName(String name) { + this.setText(name); + buttonName = name; + } + public Dimension getPreferredSize() { return new Dimension(B_W, B_H); } @@ -467,17 +477,20 @@ public class ChartTypeButtonPane extends BasicBeanPane implemen @Override public void mouseClicked(MouseEvent e) { mouseClick(e); - mouseOnChartTypeButtonPane = true; + if(pressOtherButtonWhenEditing){ + relayoutPane(); + pressOtherButtonWhenEditing = false; + } } public void mouseEntered(MouseEvent e) { checkMoveOn(true); - mouseOnChartTypeButtonPane = true; + pressOtherButtonWhenEditing = currentEditingEditor != null; } public void mouseExited(MouseEvent e) { checkMoveOn(false); - mouseOnChartTypeButtonPane = false; + pressOtherButtonWhenEditing = false; } }; }