From ac6cf87132a2f1442a89d65583755dd99c2562bf Mon Sep 17 00:00:00 2001 From: "Hugh.C" Date: Thu, 26 Sep 2019 18:45:40 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-21689=20=20=E6=B0=B4=E5=8D=B0=E5=AF=86?= =?UTF-8?q?=E5=BA=A6=E5=A2=9E=E5=8A=A0=E6=9C=80=E5=B0=8F=E5=80=BC=E9=99=90?= =?UTF-8?q?=E5=88=B6=E3=80=81=E6=A0=B9=E6=8D=AE=E4=BA=A4=E4=BA=92=E6=8F=90?= =?UTF-8?q?=E4=BE=9B=E7=9A=84=E5=86=85=E5=AE=B9=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/gui/ispinner/UISpinner.java | 4 + .../gui/ispinner/UnsignedIntUISpinner.java | 28 +---- .../com/fr/design/report/WatermarkPane.java | 108 ++++++++++++++++-- 3 files changed, 104 insertions(+), 36 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/gui/ispinner/UISpinner.java b/designer-base/src/main/java/com/fr/design/gui/ispinner/UISpinner.java index 66a9a75755..825dddb4ec 100644 --- a/designer-base/src/main/java/com/fr/design/gui/ispinner/UISpinner.java +++ b/designer-base/src/main/java/com/fr/design/gui/ispinner/UISpinner.java @@ -93,6 +93,10 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver return textField; } + public UIButton getNextButton() { + return nextButton; + } + public void setValue(double value) { setValue(value, true); } diff --git a/designer-base/src/main/java/com/fr/design/gui/ispinner/UnsignedIntUISpinner.java b/designer-base/src/main/java/com/fr/design/gui/ispinner/UnsignedIntUISpinner.java index 1515477a3d..42a40cd79e 100644 --- a/designer-base/src/main/java/com/fr/design/gui/ispinner/UnsignedIntUISpinner.java +++ b/designer-base/src/main/java/com/fr/design/gui/ispinner/UnsignedIntUISpinner.java @@ -3,8 +3,6 @@ package com.fr.design.gui.ispinner; import com.fr.design.gui.itextfield.UIIntNumberField; import com.fr.design.gui.itextfield.UINumberField; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; /** * Created by IntelliJ IDEA. @@ -31,7 +29,7 @@ public class UnsignedIntUISpinner extends UISpinner { @Override protected UINumberField initNumberField() { - final UIIntNumberField numberField = new UIIntNumberField() { + return new UIIntNumberField() { public boolean shouldResponseChangeListener() { return false; } @@ -44,29 +42,5 @@ public class UnsignedIntUISpinner extends UISpinner { }; } }; - numberField.addFocusListener(new FocusListener() { - @Override - public void focusGained(FocusEvent e) { - - } - - /** - * 失去焦点后再做范围限制、不然最小值为 100 时,输个 1 都不让.... - * @param e - */ - @Override - public void focusLost(FocusEvent e) { - double value = numberField.getValue(); - if (!isOverMaxOrMinValue(value)) { - return; - } - numberField.setValue(value < minValue ? minValue : maxValue); - } - - private boolean isOverMaxOrMinValue(double value) { - return value < minValue || value > maxValue; - } - }); - return numberField; } } \ No newline at end of file diff --git a/designer-base/src/main/java/com/fr/design/report/WatermarkPane.java b/designer-base/src/main/java/com/fr/design/report/WatermarkPane.java index a7f78e1170..178479de8e 100644 --- a/designer-base/src/main/java/com/fr/design/report/WatermarkPane.java +++ b/designer-base/src/main/java/com/fr/design/report/WatermarkPane.java @@ -23,6 +23,9 @@ import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; +import javax.swing.JDialog; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; import java.awt.Dimension; import java.awt.BorderLayout; import java.awt.Color; @@ -30,6 +33,12 @@ import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; +import java.awt.event.MouseListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.Dialog; +import java.awt.FlowLayout; + /** * Created by plough on 2018/5/15. @@ -49,6 +58,13 @@ public class WatermarkPane extends BasicPane { private UISpinner verticalGapSpinner; // 文字颜色 private NewColorSelectPane colorPane; + //间距超过限制消息 + private UILabel message; + + //横向间距最小值 + public static final int HORIZONTAL_GAP_MIX = 100; + //纵向间距最小值 + public static final int VERTICAL_GAP_MIX = 50; private static final Dimension SPINNER_DIMENSION = new Dimension(75, 20); @@ -57,6 +73,7 @@ public class WatermarkPane extends BasicPane { } private void initComponents() { + message = new UILabel(); this.setBorder(BorderFactory.createEmptyBorder(4, 4, -5, 4)); this.setLayout(FRGUIPaneFactory.createBorderLayout()); @@ -93,7 +110,7 @@ public class WatermarkPane extends BasicPane { public WatermarkAttr update() { WatermarkAttr watermark = new WatermarkAttr(); watermark.setText(formulaPane.getUITextField().getText()); - watermark.setFontSize((int)fontSizeComboBox.getSelectedItem()); + watermark.setFontSize((int) fontSizeComboBox.getSelectedItem()); watermark.setHorizontalGap((int) horizontalGapSpinner.getValue()); watermark.setVerticalGap((int) verticalGapSpinner.getValue()); watermark.setColor(colorPane.getColor()); @@ -109,7 +126,7 @@ public class WatermarkPane extends BasicPane { this.formulaPane = formulaPane; } - protected UIScrollPane initRightPane(){ + protected UIScrollPane initRightPane() { formulaPane = new TinyFormulaPane(); fontSizeComboBox = new UIComboBox(FRFontPane.FONT_SIZES); fontSizeComboBox.setEditable(true); @@ -117,7 +134,17 @@ public class WatermarkPane extends BasicPane { verticalGapSpinner = new UnsignedIntUISpinner(50, Integer.MAX_VALUE, 1, 100); horizontalGapSpinner.setPreferredSize(SPINNER_DIMENSION); verticalGapSpinner.setPreferredSize(SPINNER_DIMENSION); - JPanel fontSizeTypePane = new JPanel(new BorderLayout(10,0)); + message.setBorder(BorderFactory.createEmptyBorder(8, 5, 0, 0)); + //失去焦点时要判断是否要弹出提示 + horizontalGapSpinner.getTextField().addFocusListener( + createFocusListener4GapNumberField(horizontalGapSpinner, HORIZONTAL_GAP_MIX, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Horizontal_Gap_Over_Warning"))); + verticalGapSpinner.getTextField().addFocusListener(createFocusListener4GapNumberField(verticalGapSpinner, VERTICAL_GAP_MIX, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Vertical_Gap_Over_Warning"))); + + //next 按钮 释放时也要判断是否要弹出提示 + horizontalGapSpinner.getNextButton().addMouseListener(createMouseListener4GapNextButton(horizontalGapSpinner, HORIZONTAL_GAP_MIX, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Horizontal_Gap_Over_Warning"))); + verticalGapSpinner.getNextButton().addMouseListener(createMouseListener4GapNextButton(verticalGapSpinner, VERTICAL_GAP_MIX, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Vertical_Gap_Over_Warning"))); + + JPanel fontSizeTypePane = new JPanel(new BorderLayout(10, 0)); fontSizeTypePane.add(fontSizeComboBox, BorderLayout.CENTER); //水印间距面板 @@ -144,18 +171,18 @@ public class WatermarkPane extends BasicPane { JPanel rightContentPane = TableLayoutHelper.createCommonTableLayoutPane(new JComponent[][]{ {new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Watermark_Text")), formulaPane}, {new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Font_Size")), fontSizeTypePane}, - {new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Watermark_Gap")),watermarkGapPane }, - {null,watermarkGapTipsPane }, + {new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Watermark_Gap")), watermarkGapPane}, + {null, watermarkGapTipsPane}, {colorLabelPane, colorPane}, }, rowSize, columnSize, 10); rightContentPane.setBorder(BorderFactory.createEmptyBorder(15, 12, 10, 12)); UIScrollPane configPane = new UIScrollPane(rightContentPane); - configPane.setBorder(GUICoreUtils.createTitledBorder(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Config"),null)); + configPane.setBorder(GUICoreUtils.createTitledBorder(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Config"), null)); return configPane; } - protected void populateFontSize(int fontSize){ + protected void populateFontSize(int fontSize) { this.fontSizeComboBox.setSelectedItem(fontSize); this.fontSizeComboBox.addItemListener(new ItemListener() { @Override @@ -165,7 +192,7 @@ public class WatermarkPane extends BasicPane { }); } - protected void populateWatermarkGap(WatermarkAttr watermark){ + protected void populateWatermarkGap(WatermarkAttr watermark) { this.horizontalGapSpinner.setValue(watermark.getHorizontalGap()); this.horizontalGapSpinner.addUISpinnerFocusListenner(new FocusListener() { @@ -195,7 +222,7 @@ public class WatermarkPane extends BasicPane { }); } - protected void paintPreviewPane(){ + protected void paintPreviewPane() { watermarkPreviewPane.repaint(update()); } @@ -235,4 +262,67 @@ public class WatermarkPane extends BasicPane { protected String title4PopupWindow() { return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_WaterMark"); } + + /** + * 创建水印间距文本段焦点监听器 + * + * @return + */ + private FocusListener createFocusListener4GapNumberField(final UISpinner spinner, final int limitMinValue, final String messageStr) { + return new FocusListener() { + @Override + public void focusGained(FocusEvent e) { + } + + @Override + public void focusLost(FocusEvent e) { + if (spinner.getValue() >= limitMinValue) { + return; + } + createGapDialog(new StringBuilder(messageStr).append(limitMinValue).toString()); + } + }; + } + + /** + * 创建水印间距微调器 NextButton 的鼠标释放监听器 + * + * @param messageStr 提示消息 + * @param limitMinValue 限制的最小值 + * @return + */ + private MouseListener createMouseListener4GapNextButton(final UISpinner spinner, final int limitMinValue, final String messageStr) { + MouseAdapter mouseAdapter = new MouseAdapter() { + @Override + public void mousePressed(MouseEvent e) { + if (spinner.getValue() >= limitMinValue) { + return; + } + createGapDialog(new StringBuilder(messageStr).append(limitMinValue).toString()); + } + }; + return mouseAdapter; + } + + /** + * 创建超过水印间距限制的对话框 + * + * @param messageStr 提示消息 + */ + private void createGapDialog(String messageStr) { + JDialog dialog = new JDialog((Dialog) SwingUtilities.getWindowAncestor(WatermarkPane.this), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Joption_News"), true); + dialog.setSize(new Dimension(268, 118)); + message.setText(messageStr); + JPanel upPane = new JPanel(); + UILabel uiLabel = new UILabel(UIManager.getIcon("OptionPane.informationIcon")); + upPane.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10)); + upPane.add(uiLabel); + upPane.add(message); + dialog.add(upPane); + dialog.setResizable(false); + dialog.setLocationRelativeTo(SwingUtilities.getWindowAncestor(WatermarkPane.this)); + dialog.setVisible(true); + dialog.dispose(); + } + }