From f8932e2f28a2fd4ecb89d2e2e1405e2de221ed22 Mon Sep 17 00:00:00 2001 From: hzzz Date: Wed, 31 May 2017 13:47:22 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-2811=20=E8=AE=BE=E8=AE=A1=E5=99=A8?= =?UTF-8?q?=E8=A1=A8=E5=8D=95=EF=BC=8C=E7=82=B9=E5=87=BB=E6=8E=A7=E4=BB=B6?= =?UTF-8?q?=E4=B8=8B=E6=96=B9=E7=9A=84=E5=B1=95=E5=BC=80=E6=8C=89=E9=92=AE?= =?UTF-8?q?=EF=BC=8C=E8=AE=BE=E8=AE=A1=E5=99=A8=E6=9C=80=E5=B0=8F=E5=8C=96?= =?UTF-8?q?=E5=90=8E=EF=BC=8C=E6=8E=A7=E4=BB=B6=E7=95=8C=E9=9D=A2=E8=BF=98?= =?UTF-8?q?=E5=9C=A8=E6=A1=8C=E9=9D=A2=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/mainframe/FormParaWidgetPane.java | 185 ++++++------------ 1 file changed, 60 insertions(+), 125 deletions(-) diff --git a/designer_form/src/com/fr/design/mainframe/FormParaWidgetPane.java b/designer_form/src/com/fr/design/mainframe/FormParaWidgetPane.java index 6187bbd48..a29dced2b 100644 --- a/designer_form/src/com/fr/design/mainframe/FormParaWidgetPane.java +++ b/designer_form/src/com/fr/design/mainframe/FormParaWidgetPane.java @@ -30,8 +30,8 @@ public class FormParaWidgetPane extends JPanel { private static FormParaWidgetPane THIS; private List predifinedwidgeList = new ArrayList(); - private JWindow chartTypeWindow; - private JWindow widgetTypeWindow; + private JPopupMenu chartTypePopupMenu; + private JPopupMenu widgetTypePopupMenu; private WidgetOption[] widgetOptions = null; private WidgetOption[] chartOptions = null; private WidgetOption[] layoutOptions = null; @@ -89,6 +89,56 @@ public class FormParaWidgetPane extends JPanel { initFormParaComponent(); } + private void initWidgetTypePopUp() { + if (widgetTypePopupMenu == null) { + JPanel widgetPane = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); + loadPredefinedWidget(); + int rowNum = calculateWidgetWindowRowNum(); + JPanel westPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + for (WidgetOption o : loadWidgetOptions()) { + westPanel.add(new ToolBarButton(o)); + } + int x = commonWidgetNum * (widgetButtonWidth + smallGAP) - smallGAP; + westPanel.setPreferredSize(new Dimension(x, (int) (rowNum * westPanel.getPreferredSize().getHeight()))); + JPanel eastPane = new JPanel(new FlowLayout(FlowLayout.LEFT)); + for (WidgetOption no : predifinedwidgeList) { + eastPane.add(new ToolBarButton(no)); + } + int maxWidth = preWidgetShowMaxNum * (widgetButtonWidth + smallGAP) - smallGAP; + int width = predifinedwidgeList.size() >= preWidgetShowMaxNum ? maxWidth : (int) eastPane.getPreferredSize().getWidth(); + eastPane.setPreferredSize(new Dimension(width, (int) (rowNum * eastPane.getPreferredSize().getHeight()))); + + UIScrollPane eastScrollPane = new UIScrollPane(eastPane); + eastScrollPane.setBorder(null); + int maxHeight = preWidgetShowMaxRow * (widgetButtonHeight + smallGAP) - smallGAP; + int height = predifinedwidgeList.size() >= preWidgetShowMaxNum * preWidgetShowMaxRow ? maxHeight : (int) eastPane.getPreferredSize().getHeight(); + width = predifinedwidgeList.size() >= preWidgetShowMaxNum * preWidgetShowMaxRow ? (int) eastPane.getPreferredSize().getWidth() + smallGAP + jsparatorWidth : (int) eastPane.getPreferredSize().getWidth(); + eastScrollPane.setPreferredSize(new Dimension(width, height)); + + widgetPane.add(westPanel); + widgetPane.add(createJSeparator(height)); + widgetPane.add(eastScrollPane); + + widgetTypePopupMenu = new JPopupMenu(); + widgetTypePopupMenu.add(widgetPane); + } + } + + private void initChartTypePopUp() { + if (chartTypePopupMenu == null){ + JPanel componentsPara = new JPanel(new FlowLayout(FlowLayout.LEFT)); + WidgetOption[] chartOptions = loadChartOptions(); + for (WidgetOption chartOption : chartOptions) { + componentsPara.add(new ToolBarButton(chartOption)); + } + int x = COMMON_CHAR_NUM * (widgetButtonWidth + smallGAP); + int y = (int) Math.ceil(chartOptions.length / ((double) COMMON_CHAR_NUM)) * (widgetButtonHeight + smallGAP); + componentsPara.setPreferredSize(new Dimension(x, y)); + chartTypePopupMenu = new JPopupMenu(); + chartTypePopupMenu.add(componentsPara); + } + } + private void initFormParaComponent() { this.removeAll(); @@ -200,18 +250,10 @@ public class FormParaWidgetPane extends JPanel { chartPopUpButton.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { - JPanel componentsPara = new JPanel(new FlowLayout(FlowLayout.LEFT)); - WidgetOption[] chartOptions = loadChartOptions(); - for (WidgetOption chartOption : chartOptions) { - componentsPara.add(new ToolBarButton(chartOption)); - } - int x = COMMON_CHAR_NUM * (widgetButtonWidth + smallGAP); - int y = (int) Math.ceil(chartOptions.length / ((double) COMMON_CHAR_NUM)) * (widgetButtonHeight + smallGAP); - componentsPara.setPreferredSize(new Dimension(x, y)); - chartTypeWindow = new PopUpWindow(componentsPara, Inter.getLocText("FR-Designer-Form-ToolBar_Chart")); - chartTypeWindow.setLocation((int) jSeparatorLayout.getLocationOnScreen().getX() + 1, (int) jSeparatorLayout.getLocationOnScreen().getY()); - chartTypeWindow.setSize(chartTypeWindow.getPreferredSize()); - chartTypeWindow.setVisible(true); + initChartTypePopUp(); + chartTypePopupMenu.show(FormParaWidgetPane.this, + (int) jSeparatorLayout.getLocation().getX() + 5, + (int) jSeparatorLayout.getLocation().getY() - 4); } }); labelPane.add(chartPopUpButton, BorderLayout.EAST); @@ -228,40 +270,10 @@ public class FormParaWidgetPane extends JPanel { chartPopUpButton.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { - JPanel widgetPane = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); - loadPredefinedWidget(); - int rowNum = calculateWidgetWindowRowNum(); - JPanel westPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - for (WidgetOption o : loadWidgetOptions()) { - westPanel.add(new ToolBarButton(o)); - } - int x = commonWidgetNum * (widgetButtonWidth + smallGAP); - westPanel.setPreferredSize(new Dimension(x, (int) (rowNum * westPanel.getPreferredSize().getHeight()))); - JPanel eastPane = new JPanel(new FlowLayout(FlowLayout.LEFT)); - for (WidgetOption no : predifinedwidgeList) { - eastPane.add(new ToolBarButton(no)); - } - int maxWidth = preWidgetShowMaxNum * (widgetButtonWidth + smallGAP); - int width = predifinedwidgeList.size() >= preWidgetShowMaxNum ? maxWidth : (int) eastPane.getPreferredSize().getWidth(); - eastPane.setPreferredSize(new Dimension(width, (int) (rowNum * eastPane.getPreferredSize().getHeight()))); - - UIScrollPane eastScrollPane = new UIScrollPane(eastPane); - eastScrollPane.setBorder(null); - int maxHeight = preWidgetShowMaxRow * (widgetButtonHeight + smallGAP); - int height = predifinedwidgeList.size() >= preWidgetShowMaxNum * preWidgetShowMaxRow ? maxHeight : (int) eastPane.getPreferredSize().getHeight(); - width = predifinedwidgeList.size() >= preWidgetShowMaxNum * preWidgetShowMaxRow ? (int) eastPane.getPreferredSize().getWidth() + smallGAP + jsparatorWidth : (int) eastPane.getPreferredSize().getWidth(); - eastScrollPane.setPreferredSize(new Dimension(width, height)); - - widgetPane.add(westPanel); - widgetPane.add(createJSeparator(height)); - widgetPane.add(eastScrollPane); - - widgetTypeWindow = new PopUpWindow(widgetPane, Inter.getLocText("FR-Designer-Form-ToolBar_Widget")); - widgetTypeWindow.setSize(widgetTypeWindow.getPreferredSize()); - if (jSeparatorChart != null) { - widgetTypeWindow.setLocation((int) jSeparatorChart.getLocationOnScreen().getX() + 1, (int) jSeparatorChart.getLocationOnScreen().getY()); - } - widgetTypeWindow.setVisible(true); + initWidgetTypePopUp(); + widgetTypePopupMenu.show(FormParaWidgetPane.this, + (int) jSeparatorChart.getLocation().getX() + 5, + (int) jSeparatorChart.getLocation().getY() - 4); } }); @@ -354,83 +366,6 @@ public class FormParaWidgetPane extends JPanel { } } - - private class PopUpWindow extends JWindow { - private JPanel northPane; - private String typeName; - private int LineWidth = 5; - private int BarWidth = 10; - - public PopUpWindow(JPanel northPane, String typeName) { - super(); - this.northPane = northPane; - this.typeName = typeName; - this.getContentPane().add(initComponents()); - this.doLayout(); - Toolkit.getDefaultToolkit().addAWTEventListener(awt, AWTEvent.MOUSE_EVENT_MASK); - } - - private AWTEventListener awt = new AWTEventListener() { - public void eventDispatched(AWTEvent event) { - if (event instanceof MouseEvent) { - MouseEvent mv = (MouseEvent) event; - if (mv.getClickCount() > 0) { - Point point = new Point((int) (mv.getLocationOnScreen().getX()), (int) mv.getLocationOnScreen().getY()); - // 直接contains在mac下,点击内部也会消失 - Dimension d = PopUpWindow.this.getSize(); - Point p = PopUpWindow.this.getLocation(); - Rectangle rect = new Rectangle(p, d); - if (!rect.contains(point)) { - PopUpWindow.this.setVisible(false); - } - } - } - } - }; - - - protected JPanel initComponents() { - JPanel rootPane = new EditorChoosePane(); - JPanel contentPane = new JPanel(); - contentPane.setLayout(new BorderLayout(17, 0)); - contentPane.add(northPane, BorderLayout.CENTER); - JPanel labelPane = new JPanel(new BorderLayout()); - labelPane.add(new UILabel(typeName, UILabel.CENTER), BorderLayout.CENTER); - JButton popUpButton = createPopDownButton(); - popUpButton.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - PopUpWindow.this.setVisible(false); - } - }); - labelPane.add(popUpButton, BorderLayout.EAST); - contentPane.add(labelPane, BorderLayout.SOUTH); - rootPane.add(contentPane, BorderLayout.CENTER); - return rootPane; - - } - - - } - - private class EditorChoosePane extends JPanel { - public EditorChoosePane() { - super(); - ((FlowLayout) this.getLayout()).setVgap(1); - } - - @Override - public void paintComponent(Graphics g) { - Rectangle r = this.getBounds(); - g.setColor(UIConstants.NORMAL_BACKGROUND); - g.fillRoundRect(r.x, r.y, r.width, r.height, 0, 0); - g.setColor(UIConstants.LINE_COLOR); - g.drawLine(r.x, r.y, r.x, r.y + r.height); - g.drawLine(r.x, r.y + r.height - 1, r.x + r.width - 1, r.y + r.height - 1); - g.drawLine(r.x + r.width - 1, r.y, r.x + r.width - 1, r.y + r.height - 1); - } - } - private WidgetOption[] loadWidgetOptions() { if (widgetOptions == null) { widgetOptions = (WidgetOption[]) ArrayUtils.addAll(WidgetOption.getFormWidgetIntance(), ExtraDesignClassManager.getInstance().getFormWidgetOptions());