From 1a47a1fc774e22c6ddb6b4f7693a9f7472d3b873 Mon Sep 17 00:00:00 2001 From: plough Date: Tue, 25 Jul 2017 14:28:35 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-3163=20=E5=90=88=E4=BD=9C=E5=BC=80?= =?UTF-8?q?=E5=8F=919.0=E8=AE=BE=E8=AE=A1=E5=99=A8=3D>=E6=96=B0=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E9=9D=A2=E6=9D=BF=3D=E3=80=8B=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=BA=8C=E6=AC=A1=E5=BC=B9=E7=AA=97=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/gui/controlpane/UIControlPane.java | 67 +++++++++---------- .../gui/controlpane/UIListControlPane.java | 10 +-- .../UINameableListCellRenderer.java | 2 +- .../mainframe/EastRegionContainerPane.java | 39 +++++++++-- 4 files changed, 69 insertions(+), 49 deletions(-) diff --git a/designer_base/src/com/fr/design/gui/controlpane/UIControlPane.java b/designer_base/src/com/fr/design/gui/controlpane/UIControlPane.java index 632889bba8..b11dafba40 100644 --- a/designer_base/src/com/fr/design/gui/controlpane/UIControlPane.java +++ b/designer_base/src/com/fr/design/gui/controlpane/UIControlPane.java @@ -6,16 +6,15 @@ import com.fr.design.gui.itoolbar.UIToolbar; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; -import com.fr.design.mainframe.EastRegionContainerPane; +import com.fr.design.mainframe.DesignerContext; import com.fr.design.menu.ShortCut; import com.fr.design.menu.ToolBarDef; -import com.fr.design.utils.gui.GUICoreUtils; -import com.fr.general.Inter; import com.fr.stable.ArrayUtils; import com.fr.stable.Nameable; import javax.swing.*; import java.awt.*; +import java.awt.event.*; /** * Created by plough on 2017/7/21. @@ -29,7 +28,7 @@ public abstract class UIControlPane extends BasicPane implements UnrepeatedNameH private ToolBarDef toolbarDef; private UIToolbar toolBar; - protected PopupEditPane popupEditPane; + protected PopupEditDialog popupEditDialog; // peter:这是整体的一个cardLayout Pane protected CardLayout cardLayout; @@ -103,7 +102,7 @@ public abstract class UIControlPane extends BasicPane implements UnrepeatedNameH UILabel selectLabel = new UILabel(); cardPane.add(selectLabel, "SELECT"); cardPane.add(controlUpdatePane, "EDIT"); - popupEditPane = new PopupEditPane(cardPane); + popupEditDialog = new PopupEditDialog(cardPane); // SplitPane // JSplitPane mainSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, getLeftPane(), cardPane); // mainSplitPane.setBorder(BorderFactory.createLineBorder(GUICoreUtils.getTitleLineBorderColor())); @@ -185,7 +184,6 @@ public abstract class UIControlPane extends BasicPane implements UnrepeatedNameH protected ShortCut4JControlPane[] createShortcuts() { return new ShortCut4JControlPane[]{ -// addItemShortCut(), copyItemShortCut(), moveUpItemShortCut(), moveDownItemShortCut(), @@ -250,44 +248,39 @@ public abstract class UIControlPane extends BasicPane implements UnrepeatedNameH } // 点击"编辑"按钮,弹出面板 - protected class PopupEditPane extends JPopupMenu { - private JComponent contentPane; + protected class PopupEditDialog extends JDialog { + private JComponent editPane; private static final int WIDTH = 460; private static final int HEIGHT = 500; - // private PopupToolPane popupToolPane; -// private int fixedHeight; - - PopupEditPane(JComponent pane) { - contentPane = pane; - this.setLayout(new BorderLayout()); - this.add(contentPane, BorderLayout.CENTER); - this.setOpaque(false); - contentPane.setPreferredSize(new Dimension(WIDTH, HEIGHT)); -// fixedHeight = getPreferredSize().height - contentPane.getPreferredSize().height; -// updateSize(); - } - -// private void updateSize() { -// int newHeight = fixedHeight + contentPane.getPreferredSize().height; -// this.setPreferredSize(new Dimension(CONTAINER_WIDTH - TAB_WIDTH, newHeight)); -// } - public JComponent getContentPane() { - return contentPane; + PopupEditDialog(JComponent pane) { + super(DesignerContext.getDesignerFrame()); + setUndecorated(true); + this.editPane = pane; + this.getContentPane().add(editPane, BorderLayout.CENTER); + setSize(WIDTH, HEIGHT); + this.setVisible(false); + initListener(); } - public void replaceContentPane(JComponent pane) { -// remove(pane); - this.remove(this.contentPane); - this.add(this.contentPane = pane); -// updateSize(); - refreshContainer(); + private void hideDialog() { + // 检查是否有子弹窗,如果有,则不隐藏 + for (Window window : getOwnedWindows()) { + if (window.isVisible()) { + return; + } + } + setVisible(false); } - private void refreshContainer() { - validate(); - repaint(); - revalidate(); + private void initListener() { + addWindowFocusListener(new WindowAdapter() { + @Override + public void windowLostFocus(WindowEvent e) { + super.windowLostFocus(e); + hideDialog(); + } + }); } } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/gui/controlpane/UIListControlPane.java b/designer_base/src/com/fr/design/gui/controlpane/UIListControlPane.java index 893bd9581b..76be4f96db 100644 --- a/designer_base/src/com/fr/design/gui/controlpane/UIListControlPane.java +++ b/designer_base/src/com/fr/design/gui/controlpane/UIListControlPane.java @@ -26,10 +26,8 @@ import com.fr.general.Inter; import com.fr.stable.ArrayUtils; import com.fr.stable.Nameable; import com.fr.stable.core.PropertyChangeAdapter; -import sun.swing.DefaultLookup; import javax.swing.*; -import javax.swing.border.Border; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import java.awt.*; @@ -359,11 +357,13 @@ public abstract class UIListControlPane extends UIControlPane { } private void popupEditPane(Point mousePos) { - if (editingIndex < 0 || !nameableList.getCellBounds(editingIndex, editingIndex).contains(mousePos)) { + Rectangle currentCellBounds = nameableList.getCellBounds(editingIndex, editingIndex); + if (editingIndex < 0 || !currentCellBounds.contains(mousePos)) { return; } - GUICoreUtils.showPopupMenu(popupEditPane, this, - - popupEditPane.getPreferredSize().width, editingIndex * EDIT_RANGE); + Point listPos = nameableList.getLocationOnScreen(); + popupEditDialog.setLocation(listPos.x - popupEditDialog.getSize().width, listPos.y + editingIndex * EDIT_RANGE); + popupEditDialog.setVisible(true); } /** diff --git a/designer_base/src/com/fr/design/gui/controlpane/UINameableListCellRenderer.java b/designer_base/src/com/fr/design/gui/controlpane/UINameableListCellRenderer.java index e56b038074..70801736ac 100644 --- a/designer_base/src/com/fr/design/gui/controlpane/UINameableListCellRenderer.java +++ b/designer_base/src/com/fr/design/gui/controlpane/UINameableListCellRenderer.java @@ -54,7 +54,7 @@ public class UINameableListCellRenderer extends // editButton.addActionListener(new ActionListener() { // @Override // public void actionPerformed(ActionEvent e) { -// popupEditPane(); +// popupEditDialog(); // } // }); label = new UILabel(); diff --git a/designer_base/src/com/fr/design/mainframe/EastRegionContainerPane.java b/designer_base/src/com/fr/design/mainframe/EastRegionContainerPane.java index a0a3b8828d..7f96747d50 100644 --- a/designer_base/src/com/fr/design/mainframe/EastRegionContainerPane.java +++ b/designer_base/src/com/fr/design/mainframe/EastRegionContainerPane.java @@ -27,6 +27,7 @@ public class EastRegionContainerPane extends UIEastResizableContainer { private CardLayout propertyCard; private JPanel leftPane; private JPanel rightPane; + private FixedPopupPane currentPopupPane; private static final int CONTAINER_WIDTH = 260; private static final int TAB_WIDTH = 40; private static final int CONTENT_WIDTH = CONTAINER_WIDTH - TAB_WIDTH; @@ -381,6 +382,12 @@ public class EastRegionContainerPane extends UIEastResizableContainer { return 0; } + private void hideCurrentPopupPane() { + if (currentPopupPane != null && currentPopupPane.isVisible()) { + currentPopupPane.setVisible(false); + } + } + class PropertyItem { @@ -473,7 +480,7 @@ public class EastRegionContainerPane extends UIEastResizableContainer { propertyPanel.remove(this.contentPane); propertyPanel.add(this.contentPane = pane); if (popupDialog != null && isPoppedOut) { - popupDialog.replaceContentPane(contentPane); + popupDialog.replaceContentPane(this); } if (popupPane != null && !isRightPaneVisible()) { popupPane.replaceContentPane(contentPane); @@ -488,6 +495,7 @@ public class EastRegionContainerPane extends UIEastResizableContainer { public void onResize() { if (isRightPaneVisible()) { + hideCurrentPopupPane(); replaceContentPane(contentPane); } else if(popupPane != null) { popupPane.replaceContentPane(contentPane); @@ -540,7 +548,13 @@ public class EastRegionContainerPane extends UIEastResizableContainer { if (popupPane == null) { popupPane = new FixedPopupPane(this); } - GUICoreUtils.showPopupMenu(popupPane, button, -popupPane.getPreferredSize().width, 0); + if (popupPane.isVisible()) { + popupPane.setVisible(false); + } else { + hideCurrentPopupPane(); + currentPopupPane = popupPane; + GUICoreUtils.showPopupMenu(popupPane, button, -popupPane.getPreferredSize().width, 0); + } } // 弹出对话框 @@ -553,7 +567,8 @@ public class EastRegionContainerPane extends UIEastResizableContainer { if (popupDialog == null) { popupDialog = new PopupDialog(this); } else { - popupDialog.replaceContentPane(contentPane); + popupDialog.replaceContentPane(this); + popupDialog.adjustLocation(); popupDialog.setVisible(true); } // initContentPane(); @@ -588,6 +603,9 @@ public class EastRegionContainerPane extends UIEastResizableContainer { updateSize(); } + public void menuSelectionChanged(boolean isIncluded) { + } + private void updateSize() { int newHeight = fixedHeight + contentPane.getPreferredSize().height; this.setPreferredSize(new Dimension(CONTAINER_WIDTH - TAB_WIDTH, newHeight)); @@ -795,10 +813,12 @@ public class EastRegionContainerPane extends UIEastResizableContainer { private Point mouseDownCompCoords; private int minHeight; // 对话框最小高度 private JComponent contentPane; + private PropertyItem propertyItem; public PopupDialog(PropertyItem propertyItem) { super(DesignerContext.getDesignerFrame()); container = getContentPane(); setUndecorated(true); + this.propertyItem = propertyItem; PopupToolPane popupToolPane = new PopupToolPane(propertyItem, PopupToolPane.UP_BUTTON); popupToolPane.setParentDialog(this); contentPane = propertyItem.getContentPane(); @@ -807,13 +827,20 @@ public class EastRegionContainerPane extends UIEastResizableContainer { minHeight = container.getPreferredSize().height; setSize(CONTENT_WIDTH, minHeight); // validate(); - Point btnCoords = propertyItem.getButton().getLocationOnScreen(); - this.setLocation(btnCoords.x - CONTENT_WIDTH, btnCoords.y); + adjustLocation(); initListener(); this.setVisible(true); } - public void replaceContentPane(JComponent contentPane) { + + public void adjustLocation() { + Point btnCoords = propertyItem.getButton().getLocationOnScreen(); + this.setLocation(btnCoords.x - CONTENT_WIDTH, btnCoords.y); + } + + public void replaceContentPane(PropertyItem propertyItem) { + this.propertyItem = propertyItem; + JComponent contentPane = propertyItem.getContentPane(); container.remove(this.contentPane); container.add(this.contentPane = contentPane); // pack();