|
|
|
@ -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")); |
|
|
|
|