diff --git a/designer-base/src/main/java/com/fr/design/report/fit/FormFitConfigPane.java b/designer-base/src/main/java/com/fr/design/report/fit/FormFitConfigPane.java index 08b70cb772..d88a3a16eb 100644 --- a/designer-base/src/main/java/com/fr/design/report/fit/FormFitConfigPane.java +++ b/designer-base/src/main/java/com/fr/design/report/fit/FormFitConfigPane.java @@ -1,17 +1,35 @@ package com.fr.design.report.fit; +import com.fr.base.svg.SVGLoader; +import com.fr.design.gui.ibutton.UIRadioButton; import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.imenu.UIPopupMenu; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.report.fit.menupane.FitRadioGroup; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.general.ComparatorUtils; import com.fr.report.fit.ReportFitAttr; - import javax.swing.JPanel; +import javax.swing.JPopupMenu; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; +import java.awt.Dimension; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.Image; +import java.awt.Rectangle; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; public class FormFitConfigPane extends ReportFitConfigPane { + private static final int ICON_OFFSET_X = 25; + private static final int ICON_OFFSET_Y = 3; + private static final int ICON_SIZE = 16; + private static final Image HOVER_IMAGE = SVGLoader.load("/com/fr/design/icon/icon_ec_default_fit.svg"); private static final int DEFAULT_ITEM = 0; + private static final int CUSTOM_ITEM = 1; public FormFitConfigPane(FitAttrModel fitAttrModel) { @@ -33,6 +51,92 @@ public class FormFitConfigPane extends ReportFitConfigPane { return jPanel; } + protected void initRadioGroup(FitRadioGroup fitRadioGroup, String name, String[] options, Component[] components) { + components[0] = new UILabel(name); + for (int i = 0; i < options.length; i++) { + if (options[i] != null) { + UIRadioButton fontFitRadio = ComparatorUtils.equals(options[i], Toolkit.i18nText("Fine-Designer_Fit-Default")) ? new UIRadioButtonWithIcon(options[i]) : new UIRadioButton(options[i]); + fitRadioGroup.add(fontFitRadio); + components[i + 1] = fontFitRadio; + } else { + components[i + 1] = null; + } + } + fitRadioGroup.addActionListener(getPreviewActionListener()); + } + + private class UIRadioButtonWithIcon extends UIRadioButton { + private final JPopupMenu popupMenu; + private NewFitPreviewPane ecFitPreviewPane; + + public UIRadioButtonWithIcon(String text) { + super(text); + popupMenu = this.createPopupMenu(); + initMouseListener(); + } + + private JPopupMenu createPopupMenu() { + UIPopupMenu uiPopupMenu = new UIPopupMenu() { + @Override + protected void paintBorder(Graphics g) { + + } + }; + uiPopupMenu.setLayout(new BorderLayout(0, 0)); + uiPopupMenu.setOpaque(false); + uiPopupMenu.add(ecFitPreviewPane = new NewFitPreviewPane(FitType.HORIZONTAL_FIT), BorderLayout.CENTER); + ecFitPreviewPane.setPreferredSize(new Dimension(300, 204)); + return uiPopupMenu; + } + + private void initMouseListener() { + this.addMouseListener(new MouseAdapter() { + @Override + public void mouseExited(MouseEvent e) { + super.mouseExited(e); + hidePreviewPane(); + } + }); + int defaultTextWidth = calculateStartX(); + this.addMouseMotionListener(new MouseAdapter() { + @Override + public void mouseMoved(MouseEvent e) { + super.mouseMoved(e); + if (new Rectangle(ICON_OFFSET_X + defaultTextWidth, ICON_OFFSET_Y, ICON_SIZE, ICON_SIZE).contains(e.getPoint())) { + showPreviewPane(e); + } else { + hidePreviewPane(); + } + + } + }); + } + + public void showPreviewPane(MouseEvent e) { + popupMenu.setVisible(true); + ecFitPreviewPane.refreshPreview(fontRadioGroup.isFontFit()); + GUICoreUtils.showPopupMenu(popupMenu, this, e.getX() + 10, e.getY() + 10); + } + + public void hidePreviewPane() { + if (popupMenu != null && popupMenu.isVisible()) { + popupMenu.setVisible(false); + } + } + + + @Override + public void paint(Graphics g) { + super.paint(g); + g.drawImage(HOVER_IMAGE, calculateStartX() + ICON_OFFSET_X, ICON_OFFSET_Y, null); + } + + private int calculateStartX() { + FontMetrics metrics = this.getFontMetrics(this.getFont()); + return metrics.stringWidth(this.getText()); + } + } + private JPanel createTipPane() { JPanel jPanel = FRGUIPaneFactory.createVerticalFlowLayout_S_Pane(true); UILabel label1 = new UILabel(Toolkit.i18nText("Fine-Design_Form_PC_FIT_Config_Tip1")); diff --git a/designer-base/src/main/java/com/fr/design/report/fit/NewFitPreviewPane.java b/designer-base/src/main/java/com/fr/design/report/fit/NewFitPreviewPane.java index 8b0710de3f..2bc69cedc7 100644 --- a/designer-base/src/main/java/com/fr/design/report/fit/NewFitPreviewPane.java +++ b/designer-base/src/main/java/com/fr/design/report/fit/NewFitPreviewPane.java @@ -16,8 +16,16 @@ public class NewFitPreviewPane extends JPanel { private FitType fitType = FitType.DOUBLE_FIT; private static final Color DEFAULT_PAINT_COLOR = Color.decode("#419BF9"); private static final int FIT_FONT_SIZE = 15; - private static final int NO_FIT_FONT_SIZE = 9; - private static final Dimension NO_FIT_CONTAINER_DIMENSION = new Dimension(200, 136); + private static final int NO_FIT_FONT_SIZE = 10; + private static final Dimension NO_FIT_CONTAINER_DIMENSION = new Dimension(230, 80); + + public NewFitPreviewPane(){ + + } + + public NewFitPreviewPane(FitType fitType){ + this.fitType = fitType; + } @Override public void paint(Graphics g) { diff --git a/designer-base/src/main/java/com/fr/design/report/fit/ReportFitConfigPane.java b/designer-base/src/main/java/com/fr/design/report/fit/ReportFitConfigPane.java index 399e7fef93..158089602f 100644 --- a/designer-base/src/main/java/com/fr/design/report/fit/ReportFitConfigPane.java +++ b/designer-base/src/main/java/com/fr/design/report/fit/ReportFitConfigPane.java @@ -93,7 +93,7 @@ public class ReportFitConfigPane extends JPanel { fitRadioGroup.addActionListener(getPreviewActionListener()); } - private ActionListener getPreviewActionListener() { + protected ActionListener getPreviewActionListener() { return new ActionListener() { @Override public void actionPerformed(ActionEvent e) { diff --git a/designer-base/src/main/resources/com/fr/design/icon/icon_ec_default_fit.svg b/designer-base/src/main/resources/com/fr/design/icon/icon_ec_default_fit.svg new file mode 100644 index 0000000000..4deb67b0dd --- /dev/null +++ b/designer-base/src/main/resources/com/fr/design/icon/icon_ec_default_fit.svg @@ -0,0 +1,3 @@ + + +