You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
173 lines
6.5 KiB
173 lines
6.5 KiB
package com.fr.design.report.fit; |
|
|
|
import com.fr.design.gui.ibutton.UIRadioButton; |
|
import com.fr.design.gui.ilable.UILabel; |
|
import com.fr.design.i18n.DesignSizeI18nManager; |
|
import com.fr.design.layout.FRGUIPaneFactory; |
|
import com.fr.design.layout.TableLayoutHelper; |
|
import com.fr.design.report.fit.menupane.FitRadioGroup; |
|
import com.fr.design.report.fit.menupane.FontRadioGroup; |
|
import com.fr.general.ComparatorUtils; |
|
import com.fr.report.fit.ReportFitAttr; |
|
|
|
import javax.swing.BorderFactory; |
|
import javax.swing.JPanel; |
|
import java.awt.BorderLayout; |
|
import java.awt.Component; |
|
import java.awt.Dimension; |
|
import java.awt.FlowLayout; |
|
import java.awt.event.ActionEvent; |
|
import java.awt.event.ActionListener; |
|
|
|
import static com.fr.design.i18n.Toolkit.i18nText; |
|
|
|
public class ReportFitConfigPane extends JPanel { |
|
public FontRadioGroup fontRadioGroup; |
|
public FitRadioGroup ecConfigRadioGroup; |
|
protected NewFitPreviewPane previewJPanel; |
|
protected FitAttrModel fitAttrModel; |
|
protected boolean globalConfig; |
|
|
|
|
|
public ReportFitConfigPane(FitAttrModel fitAttrModel, boolean globalConfig) { |
|
this.fitAttrModel = fitAttrModel; |
|
this.globalConfig = globalConfig; |
|
initComponent(); |
|
} |
|
|
|
private void initComponent() { |
|
JPanel contentJPanel = FRGUIPaneFactory.createVerticalFlowLayout_Pane(false, FlowLayout.LEFT, 0, 0); |
|
this.add(contentJPanel); |
|
fontRadioGroup = new FontRadioGroup(); |
|
ecConfigRadioGroup = new FitRadioGroup(); |
|
contentJPanel.add(initAttrJPanel()); |
|
contentJPanel.add(initPreviewJPanel()); |
|
} |
|
|
|
private JPanel initAttrJPanel() { |
|
JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
Component[] fontComponents = new Component[3]; |
|
initRadioGroup(fontRadioGroup, i18nText("Fine-Designer_Fit-Font"), new String[]{i18nText("Fine-Designer_Fit"), i18nText("Fine-Designer_Fit-No")}, fontComponents); |
|
jPanel.add(createSubAttrPane(fontComponents), BorderLayout.NORTH); |
|
jPanel.add(initECConfigPane(), BorderLayout.CENTER); |
|
return jPanel; |
|
} |
|
|
|
protected JPanel initECConfigPane() { |
|
JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
Component[] ecComponents = new Component[fitAttrModel.getFitTypeNames().length + 1]; |
|
initRadioGroup(ecConfigRadioGroup, fitAttrModel.getFitName(), fitAttrModel.getFitTypeNames(), ecComponents); |
|
jPanel.add(createSubAttrPane(ecComponents), BorderLayout.CENTER); |
|
return jPanel; |
|
} |
|
|
|
|
|
protected JPanel createSubAttrPane(Component[] components) { |
|
double[] rowSize = new double[]{20}; |
|
double[] columnSize = new double[components.length]; |
|
for (int i = 0; i < columnSize.length; i++) { |
|
if (i == 0) { |
|
columnSize[i] = DesignSizeI18nManager.getInstance().i18nDimension("com.fr.design.report.fit.firstColumn").getWidth(); |
|
} else { |
|
columnSize[i] = DesignSizeI18nManager.getInstance().i18nDimension("com.fr.design.report.fit.column").getWidth(); |
|
} |
|
} |
|
|
|
JPanel attrJPanel = TableLayoutHelper.createTableLayoutPane(new Component[][]{components}, rowSize, columnSize); |
|
attrJPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 10, 0)); |
|
return attrJPanel; |
|
} |
|
|
|
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 = new UIRadioButton(options[i]); |
|
fitRadioGroup.add(fontFitRadio); |
|
components[i + 1] = fontFitRadio; |
|
} else { |
|
components[i + 1] = null; |
|
} |
|
} |
|
fitRadioGroup.addActionListener(getPreviewActionListener()); |
|
} |
|
|
|
protected ActionListener getPreviewActionListener() { |
|
return new ActionListener() { |
|
@Override |
|
public void actionPerformed(ActionEvent e) { |
|
refreshPreviewJPanel(); |
|
} |
|
}; |
|
} |
|
|
|
public void refreshPreviewJPanel(FitType fitType) { |
|
previewJPanel.refreshPreview(fontRadioGroup.isFontFit(), fitType); |
|
} |
|
|
|
protected void refreshPreviewJPanel() { |
|
previewJPanel.refreshPreview(fontRadioGroup.isFontFit(), FitType.parse(updateBean())); |
|
} |
|
|
|
private JPanel initPreviewJPanel() { |
|
JPanel wrapperPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
previewJPanel = new NewFitPreviewPane(); |
|
wrapperPane.add(previewJPanel, BorderLayout.CENTER); |
|
int leftIndent = globalConfig ? (int) DesignSizeI18nManager.getInstance().i18nDimension("com.fr.design.report.fit.firstColumn").getWidth() : 0; |
|
int height = (int) DesignSizeI18nManager.getInstance().i18nDimension("com.fr.design.report.fit.topMargin").getHeight(); |
|
wrapperPane.setBorder(BorderFactory.createEmptyBorder(0, leftIndent, 0, 0)); |
|
wrapperPane.setPreferredSize(new Dimension(300 + leftIndent, height)); |
|
return wrapperPane; |
|
} |
|
|
|
|
|
public void populateBean(ReportFitAttr ob) { |
|
fontRadioGroup.selectIndexButton(ob.isFitFont() ? 0 : 1); |
|
populateECConfigRadioGroup(ob.fitStateInPC()); |
|
refreshPreviewJPanel(); |
|
} |
|
|
|
protected void populateECConfigRadioGroup(int fitStateInPC){ |
|
ecConfigRadioGroup.selectIndexButton(getOptionIndex(fitStateInPC)); |
|
} |
|
|
|
|
|
protected void updateECConfigRadioGroup(ReportFitAttr reportFitAttr){ |
|
reportFitAttr.setFitStateInPC(getStateInPC(ecConfigRadioGroup.getSelectRadioIndex())); |
|
} |
|
|
|
public ReportFitAttr updateBean() { |
|
ReportFitAttr reportFitAttr = new ReportFitAttr(); |
|
reportFitAttr.setFitFont(fontRadioGroup.isFontFit()); |
|
updateECConfigRadioGroup(reportFitAttr); |
|
return reportFitAttr; |
|
} |
|
|
|
|
|
protected int getStateInPC(int index) { |
|
FitType[] fitTypes = fitAttrModel.getFitTypes(); |
|
if (index > fitTypes.length - 1) { |
|
return index; |
|
} |
|
return fitTypes[index].getState(); |
|
} |
|
|
|
protected int getOptionIndex(int state) { |
|
FitType[] fitTypes = fitAttrModel.getFitTypes(); |
|
for (int i = 0; i < fitTypes.length; i++) { |
|
if (ComparatorUtils.equals(state, fitTypes[i].getState())) { |
|
return i; |
|
} |
|
} |
|
return 0; |
|
} |
|
|
|
|
|
public void setEnabled(boolean enabled) { |
|
super.setEnabled(enabled); |
|
fontRadioGroup.setEnabled(enabled); |
|
ecConfigRadioGroup.setEnabled(enabled); |
|
} |
|
|
|
}
|
|
|