From 8d9e5fb5fb1eb7fd23c89f896a51adaa6479adfb Mon Sep 17 00:00:00 2001 From: plough Date: Tue, 8 Jan 2019 14:06:39 +0800 Subject: [PATCH 1/3] =?UTF-8?q?REPORT-14057=2010.0=E6=97=A5=E6=96=87?= =?UTF-8?q?=E5=9B=BD=E9=99=85=E5=8C=96=E9=97=AE=E9=A2=98=E5=A4=84=E7=90=86?= =?UTF-8?q?=3D>=E9=9D=A2=E6=9D=BF=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/report/WriteShortCutsPane.java | 108 ++++++++++-------- 1 file changed, 63 insertions(+), 45 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/design/report/WriteShortCutsPane.java b/designer-realize/src/main/java/com/fr/design/report/WriteShortCutsPane.java index d9b9741d6..c3105b211 100644 --- a/designer-realize/src/main/java/com/fr/design/report/WriteShortCutsPane.java +++ b/designer-realize/src/main/java/com/fr/design/report/WriteShortCutsPane.java @@ -8,14 +8,22 @@ import com.fr.design.gui.ilable.UILabel; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.general.ComparatorUtils; - -import javax.swing.*; +import javax.swing.BorderFactory; +import javax.swing.JPanel; +import javax.swing.SwingConstants; +import java.awt.BorderLayout; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.GridLayout; +import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class WriteShortCutsPane extends JPanel{ - + private static final int H_GAP = 60; + private static final int V_GAP = 20; + private String nextColString = "Tab"; private String nextRowString = "Enter"; private UILabel nextColHK; @@ -24,9 +32,8 @@ public class WriteShortCutsPane extends JPanel{ private UILabel preRow; public WriteShortCutsPane(){ - this.setLayout(null); - this.add(getFeatureNamePane()); - this.add(getHintsPane()); + this.setLayout(new BorderLayout()); + this.add(createContentPane(), BorderLayout.NORTH); if(!ServerPreferenceConfig.getInstance().isWriteShortCuts()){ nextColString = "Enter"; @@ -34,64 +41,75 @@ public class WriteShortCutsPane extends JPanel{ switchColRow(); } } + + private JPanel createContentPane() { + JPanel contentPane = new JPanel(); + contentPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10)); + + // 纵向布局,横向自适应 + contentPane.setLayout(new GridBagLayout()); + GridBagConstraints cons = new GridBagConstraints(); + cons.fill = GridBagConstraints.HORIZONTAL; + cons.weightx = 1; + cons.gridx = 0; + cons.insets = new Insets(20, 0, 0, 0); + + contentPane.add(getFeatureNamePane(), cons); + contentPane.add(getHintsPane(), cons); + + return contentPane; + } - //todo:布局不要用绝对定位 - public JPanel getFeatureNamePane(){ - JPanel panel1 = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); - panel1.setBounds(20, 20, 600, 140); - panel1.setLayout(null); - panel1.setBorder(BorderFactory.createTitledBorder(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Shortcut_Set"))); + private JPanel getFeatureNamePane(){ + JPanel featureNamePane = FRGUIPaneFactory.createTitledBorderPane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Shortcut_Set")); + UILabel name = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Feature_Name"), SwingConstants.CENTER); - name.setBounds(40, 30, 80, 50); UILabel nextCol = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Cursor_To_Next_Column"), SwingConstants.CENTER); - nextCol.setBounds(140, 30, 180, 50); UILabel nextRow = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Cursor_To_Next_Row"), SwingConstants.CENTER); - nextRow.setBounds(390, 30, 180, 50); UILabel shortName = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Current_Keys"), SwingConstants.CENTER); - shortName.setBounds(40, 80, 80, 50); nextColHK = new UILabel(nextColString, SwingConstants.CENTER); - nextColHK.setBounds(140, 80, 180, 50); UIButton switchbt = new UIButton(BaseUtils.readIcon("com/fr/design/images/buttonicon/switchShortCuts.png")); switchbt.addActionListener(getListener()); switchbt.setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Exchange_Key")); - switchbt.setBounds(337, 90, 36, 29); nextRowHK = new UILabel(nextRowString, SwingConstants.CENTER); - nextRowHK.setBounds(390, 80, 180, 50); - - panel1.add(name); - panel1.add(nextCol); - panel1.add(nextRow); - panel1.add(shortName); - panel1.add(nextColHK); - panel1.add(switchbt); - panel1.add(nextRowHK); + + JPanel centerPane = new JPanel(new GridLayout(2, 4, H_GAP, V_GAP)); + centerPane.add(name); + centerPane.add(nextCol); + centerPane.add(new JPanel()); + centerPane.add(nextRow); + centerPane.add(shortName); + centerPane.add(nextColHK); + centerPane.add(switchbt); + centerPane.add(nextRowHK); + + featureNamePane.add(centerPane); - return panel1; + return featureNamePane; } - public JPanel getHintsPane(){ - JPanel panel2 =FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); - panel2.setBounds(20, 170, 600, 150); - panel2.setLayout(null); - panel2.setBorder(BorderFactory.createTitledBorder(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"))); + private JPanel getHintsPane(){ + JPanel hintsPane = FRGUIPaneFactory.createTitledBorderPane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Tool_Tips")); + UILabel systemDefault = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_System_Default"), SwingConstants.CENTER); - systemDefault.setBounds(38, 30, 84, 50); UILabel preColText = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Cursor_To_Previous_Column"), SwingConstants.CENTER); - preColText.setBounds(140, 30, 190, 50); UILabel preRowText = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Cursor_To_Previous_Row"), SwingConstants.CENTER); - preRowText.setBounds(140, 80, 190, 50); preCol = new UILabel("Shift+" + nextColString, SwingConstants.CENTER); - preCol.setBounds(370, 30, 100, 50); preRow = new UILabel("Shift+" + nextRowString, SwingConstants.CENTER); - preRow.setBounds(370, 80, 100, 50); - - panel2.add(systemDefault); - panel2.add(preColText); - panel2.add(preRowText); - panel2.add(preCol); - panel2.add(preRow); + + JPanel centerPane = new JPanel(new GridLayout(2, 3, H_GAP, V_GAP)); + + centerPane.add(systemDefault); + centerPane.add(preColText); + centerPane.add(preCol); + + centerPane.add(new JPanel()); + centerPane.add(preRowText); + centerPane.add(preRow); + + hintsPane.add(centerPane); - return panel2; + return hintsPane; } public ActionListener getListener(){ From 36655594494ba82996959c2b16538c0b72f8ac98 Mon Sep 17 00:00:00 2001 From: plough Date: Tue, 8 Jan 2019 15:13:49 +0800 Subject: [PATCH 2/3] =?UTF-8?q?REPORT-14057=2010.0=E6=97=A5=E6=96=87?= =?UTF-8?q?=E5=9B=BD=E9=99=85=E5=8C=96=E9=97=AE=E9=A2=98=E5=A4=84=E7=90=86?= =?UTF-8?q?=3D>=E9=9D=A2=E6=9D=BF=E9=87=8D=E6=9E=84=EF=BC=9B=E9=97=AE?= =?UTF-8?q?=E9=A2=9814?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/report/WriteShortCutsPane.java | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/design/report/WriteShortCutsPane.java b/designer-realize/src/main/java/com/fr/design/report/WriteShortCutsPane.java index c3105b211..fa1948e9d 100644 --- a/designer-realize/src/main/java/com/fr/design/report/WriteShortCutsPane.java +++ b/designer-realize/src/main/java/com/fr/design/report/WriteShortCutsPane.java @@ -12,6 +12,7 @@ import javax.swing.BorderFactory; import javax.swing.JPanel; import javax.swing.SwingConstants; import java.awt.BorderLayout; +import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.GridLayout; @@ -21,8 +22,8 @@ import java.awt.event.ActionListener; public class WriteShortCutsPane extends JPanel{ - private static final int H_GAP = 60; private static final int V_GAP = 20; + private static final int MAX_LABEL_WIDTH = 100; private String nextColString = "Tab"; private String nextRowString = "Enter"; @@ -62,34 +63,49 @@ public class WriteShortCutsPane extends JPanel{ private JPanel getFeatureNamePane(){ JPanel featureNamePane = FRGUIPaneFactory.createTitledBorderPane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Shortcut_Set")); + featureNamePane.setLayout(new BorderLayout()); UILabel name = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Feature_Name"), SwingConstants.CENTER); UILabel nextCol = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Cursor_To_Next_Column"), SwingConstants.CENTER); UILabel nextRow = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Cursor_To_Next_Row"), SwingConstants.CENTER); UILabel shortName = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Current_Keys"), SwingConstants.CENTER); + shortName.setLineWrap(MAX_LABEL_WIDTH); nextColHK = new UILabel(nextColString, SwingConstants.CENTER); - UIButton switchbt = new UIButton(BaseUtils.readIcon("com/fr/design/images/buttonicon/switchShortCuts.png")); - switchbt.addActionListener(getListener()); - switchbt.setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Exchange_Key")); + JPanel switchBtnPane = getSwitchBtnPane(); nextRowHK = new UILabel(nextRowString, SwingConstants.CENTER); - JPanel centerPane = new JPanel(new GridLayout(2, 4, H_GAP, V_GAP)); + JPanel centerPane = new JPanel(new GridLayout(2, 4, 0, 0)); + centerPane.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0)); centerPane.add(name); centerPane.add(nextCol); centerPane.add(new JPanel()); centerPane.add(nextRow); centerPane.add(shortName); centerPane.add(nextColHK); - centerPane.add(switchbt); + centerPane.add(switchBtnPane); centerPane.add(nextRowHK); - featureNamePane.add(centerPane); + featureNamePane.add(centerPane, BorderLayout.CENTER); return featureNamePane; } - + + private JPanel getSwitchBtnPane() { + UIButton switchbt = new UIButton(BaseUtils.readIcon("com/fr/design/images/buttonicon/switchShortCuts.png")) { + public Dimension getPreferredSize() { + return new Dimension(40, 30); + } + }; + switchbt.addActionListener(getListener()); + switchbt.setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Exchange_Key")); + JPanel switchBtnPane = FRGUIPaneFactory.createCenterFlowInnerContainer_S_Pane(); + switchBtnPane.add(switchbt); + return switchBtnPane; + } + private JPanel getHintsPane(){ JPanel hintsPane = FRGUIPaneFactory.createTitledBorderPane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Tool_Tips")); + hintsPane.setLayout(new BorderLayout()); UILabel systemDefault = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_System_Default"), SwingConstants.CENTER); UILabel preColText = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Cursor_To_Previous_Column"), SwingConstants.CENTER); @@ -97,7 +113,8 @@ public class WriteShortCutsPane extends JPanel{ preCol = new UILabel("Shift+" + nextColString, SwingConstants.CENTER); preRow = new UILabel("Shift+" + nextRowString, SwingConstants.CENTER); - JPanel centerPane = new JPanel(new GridLayout(2, 3, H_GAP, V_GAP)); + JPanel centerPane = new JPanel(new GridLayout(2, 3, 0, V_GAP)); + centerPane.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 100)); centerPane.add(systemDefault); centerPane.add(preColText); @@ -107,7 +124,7 @@ public class WriteShortCutsPane extends JPanel{ centerPane.add(preRowText); centerPane.add(preRow); - hintsPane.add(centerPane); + hintsPane.add(centerPane, BorderLayout.CENTER); return hintsPane; } From e12025cf6c8beb15a9b4a0d55eb4567e04c38a5b Mon Sep 17 00:00:00 2001 From: plough Date: Thu, 10 Jan 2019 17:08:48 +0800 Subject: [PATCH 3/3] =?UTF-8?q?REPORT-14057=2010.0=E6=97=A5=E6=96=87?= =?UTF-8?q?=E5=9B=BD=E9=99=85=E5=8C=96=E9=97=AE=E9=A2=98=E5=A4=84=E7=90=86?= =?UTF-8?q?=3D>25=20tab=E6=A0=87=E9=A2=98=E6=98=BE=E7=A4=BA=E4=B8=8D?= =?UTF-8?q?=E5=85=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/gui/ibutton/UIButton.java | 65 ++++++++++++++++--- .../fr/design/gui/ibutton/UIHeadGroup.java | 17 +++-- 2 files changed, 69 insertions(+), 13 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/gui/ibutton/UIButton.java b/designer-base/src/main/java/com/fr/design/gui/ibutton/UIButton.java index 2af8c8f91..d70f06ea6 100644 --- a/designer-base/src/main/java/com/fr/design/gui/ibutton/UIButton.java +++ b/designer-base/src/main/java/com/fr/design/gui/ibutton/UIButton.java @@ -6,22 +6,35 @@ import com.fr.base.GraphHelper; import com.fr.design.constants.UIConstants; import com.fr.design.event.UIObserver; import com.fr.design.event.UIObserverListener; +import com.fr.design.utils.gui.GUICoreUtils; import com.fr.stable.Constants; import com.fr.stable.StringUtils; -import com.fr.design.utils.gui.GUICoreUtils; -import javax.swing.*; +import javax.swing.Action; +import javax.swing.Icon; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.ToolTipManager; import javax.swing.plaf.ButtonUI; -import java.awt.*; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Insets; +import java.awt.Shape; +import java.awt.Stroke; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.geom.RoundRectangle2D; public class UIButton extends JButton implements UIObserver { + private static final int TOOLTIP_INIT_DELAY = 300; // 延迟 0.3s 显示提示文字 public static final int OTHER_BORDER = 1; public static final int NORMAL_BORDER = 2; - private static final int HEIGH = 20; + private static final int HEIGHT = 20; + private boolean isExtraPainted = true; private boolean isRoundBorder = true; private int rectDirection = Constants.NULL; @@ -36,7 +49,7 @@ public class UIButton extends JButton implements UIObserver { private CellBorderStyle border = null; protected UIObserverListener uiObserverListener; - private static final int TOOLTIP_INIT_DELAY = 300; // 延迟 0.3s 显示提示文字 + private boolean fixedHeight = true; // 是否将按钮的高度固定为 HEIGHT public UIButton() { this(StringUtils.EMPTY); @@ -112,7 +125,7 @@ public class UIButton extends JButton implements UIObserver { public void set4ToolbarButton() { setNormalPainted(false); Dimension dim = getPreferredSize(); - dim.height = HEIGH; + dim.height = HEIGHT; setBackground(null); setOpaque(false); setSize(dim); @@ -170,7 +183,11 @@ public class UIButton extends JButton implements UIObserver { //@Override public Dimension getPreferredSize() { - return new Dimension(super.getPreferredSize().width, 20); + Dimension dim = super.getPreferredSize(); + if (isFixedHeight() || dim.height < HEIGHT) { + dim.height = HEIGHT; + } + return dim; } @@ -323,7 +340,39 @@ public class UIButton extends JButton implements UIObserver { this.isBorderPaintedOnlyWhenPressed = value; } - /** + /** + * 到达指定宽度后换行 + */ + public void setLineWrap(int width) { + insertPrefixToText(""); + } + + /** + * 自动换行 + */ + public void setLineWrap() { + insertPrefixToText(""); + } + + private void insertPrefixToText(String prefix) { + String text = this.getText(); + if (StringUtils.isEmpty(text)) { + return; + } + this.setText(prefix + text); + // 如果文本过长,且允许换行的话,需要放开按钮高度的限制 + this.setFixedHeight(false); + } + + private boolean isFixedHeight() { + return fixedHeight; + } + + private void setFixedHeight(boolean fixedHeight) { + this.fixedHeight = fixedHeight; + } + + /** * 主函数 * @param args 入口参数 */ diff --git a/designer-base/src/main/java/com/fr/design/gui/ibutton/UIHeadGroup.java b/designer-base/src/main/java/com/fr/design/gui/ibutton/UIHeadGroup.java index c1f5ed24e..c9771b766 100644 --- a/designer-base/src/main/java/com/fr/design/gui/ibutton/UIHeadGroup.java +++ b/designer-base/src/main/java/com/fr/design/gui/ibutton/UIHeadGroup.java @@ -4,8 +4,13 @@ import com.fr.base.BaseUtils; import com.fr.design.constants.UIConstants; import com.fr.design.utils.gui.GUICoreUtils; -import javax.swing.*; -import java.awt.*; +import javax.swing.Icon; +import javax.swing.JFrame; +import javax.swing.JPanel; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.GridLayout; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; @@ -13,6 +18,7 @@ import java.util.ArrayList; import java.util.List; public class UIHeadGroup extends JPanel { + private static final int MIN_HEIGHT = 25; protected List labelButtonList; private boolean isNeedLeftRightOutLine = true; protected int selectedIndex = -1; @@ -25,7 +31,6 @@ public class UIHeadGroup extends JPanel { labelButtonList = new ArrayList(textArray.length); this.setBackground(UIConstants.TREE_BACKGROUND); this.setLayout(new GridLayout(0, textArray.length, 0, 0)); -// this.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); for (int i = 0; i < textArray.length; i++) { final int index = i; String text = textArray[i]; @@ -50,7 +55,6 @@ public class UIHeadGroup extends JPanel { labelButtonList = new ArrayList(iconArray.length); this.setBackground(UIConstants.NORMAL_BACKGROUND); this.setLayout(new GridLayout(0, iconArray.length, 1, 0)); -// this.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); for (int i = 0; i < iconArray.length; i++) { final int index = i; Icon icon = iconArray[i]; @@ -99,7 +103,9 @@ public class UIHeadGroup extends JPanel { @Override public Dimension getPreferredSize() { Dimension dim = super.getPreferredSize(); - dim.height = 25; + if (dim.height < MIN_HEIGHT) { + dim.height = MIN_HEIGHT; + } return dim; } @@ -133,6 +139,7 @@ public class UIHeadGroup extends JPanel { labelButton.setRoundBorder(false); labelButton.setBorderPainted(false); labelButton.setPressedPainted(false); + labelButton.setLineWrap(); labelButtonList.add(labelButton); this.add(labelButton); }