Browse Source

KERNEL-10650:改变并行计算设置面板风格,跟设计器风格保持一致

feature/x
Fly.Li 3 years ago
parent
commit
d419f39316
  1. 102
      designer-form/src/main/java/com/fr/design/widget/ui/designer/FormParallelSettingPane.java

102
designer-form/src/main/java/com/fr/design/widget/ui/designer/FormParallelSettingPane.java

@ -2,6 +2,7 @@ package com.fr.design.widget.ui.designer;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.dialog.BasicPane;
import com.fr.design.gui.icheckbox.UICheckBox;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.i18n.Toolkit;
@ -9,22 +10,16 @@ import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.form.main.parallel.FormParallelAttr;
import com.fr.form.main.parallel.ParallelAttrMark;
import com.fr.general.IOUtils;
import com.fr.report.core.config.FormParallelCalConfig;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
/**
* @author fly.li
@ -66,83 +61,69 @@ public class FormParallelSettingPane extends BasicBeanPane<FormParallelAttr> {
}
static class ParallelSettingPane extends BasicPane {
private static final String[] CHOOSEITEM = new String[] {
private static final String[] CHOOSE_ITEM = new String[] {
Toolkit.i18nText("Fine-Design_Report_I_Want_To_Set_Single"),
Toolkit.i18nText("Fine-Design_Form_Using_Server_Report_View_Settings")
};
protected static final int SINGLE_SET = 0;
protected static final int SERVER_SET = 1;
//提示文字标签
UIComboBox combox;
//并行设置范围的下拉框(服务器设置还是模板设置)
UIComboBox parallelSettingScope;
//并行计算开关
ParallelSwitchLabel parallelSwitchLabel;
UICheckBox parallelSwitch;
public ParallelSettingPane(){
this.setLayout(new BorderLayout());
JPanel comboxPane = new JPanel();
comboxPane.setLayout(new BorderLayout());
comboxPane.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));
UILabel belowSetLabel = new UILabel(Toolkit.i18nText("Fine-Designer_Setting_Mode"));
belowSetLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 20));
JPanel buttonPane = GUICoreUtils.createFlowPane(new Component[] {
belowSetLabel, getCombox()}, FlowLayout.LEFT, 0, 0);
this.add(buttonPane, BorderLayout.NORTH);
JPanel parallelSettingScopePane = GUICoreUtils.createFlowPane(new Component[] {
belowSetLabel, getParallelSettingScope()}, FlowLayout.LEFT, 0, 0);
this.add(parallelSettingScopePane, BorderLayout.NORTH);
this.add(getSwitchPane(Toolkit.i18nText("Fine-Designer_Enable_Form_Block_Parallel_Calculate")), BorderLayout.CENTER);
}
private UIComboBox getCombox() {
if (combox == null){
combox = new UIComboBox(CHOOSEITEM);
combox.setFont(new Font(null, 0, 11));
combox.addItemListener(new ItemListener() {
private UIComboBox getParallelSettingScope() {
if (parallelSettingScope == null){
parallelSettingScope = new UIComboBox(CHOOSE_ITEM);
parallelSettingScope.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
if (combox.getSelectedIndex() == SERVER_SET) {
if (isUsingServerSettings()) {
populateServerSettings();
parallelSwitch.setEnabled(false);
} else {
parallelSwitch.setEnabled(true);
}
}
}
});
}
return combox;
return parallelSettingScope;
}
private JPanel getSwitchPane(String tip){
JPanel innerPane = new JPanel();
innerPane.setLayout(new BorderLayout());
innerPane.setPreferredSize(new Dimension(500, 30));
innerPane.setBorder(BorderFactory.createEmptyBorder(5, 70, 5, 10));
JLabel label = new JLabel(tip);
label.setFont(new Font(null, 0, 12));
innerPane.add(label, BorderLayout.WEST);
innerPane.add(getSwitchLabel(), BorderLayout.EAST);
innerPane.setBorder(BorderFactory.createEmptyBorder(10, 70, 5, 10));
innerPane.add(getSwitchBox(tip));
return innerPane;
}
private JLabel getSwitchLabel(){
if (parallelSwitchLabel == null){
parallelSwitchLabel = new ParallelSwitchLabel();
combox.setSelectedIndex(SERVER_SET);
parallelSwitchLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (!isUsingServerSettings()){
parallelSwitchLabel.changeSwitchState();
}
}
});
private UICheckBox getSwitchBox(String tip){
if (parallelSwitch == null){
parallelSwitch = new UICheckBox(tip);
}
return parallelSwitchLabel;
return parallelSwitch;
}
private boolean isUsingServerSettings(){
return combox.getSelectedIndex() == SERVER_SET;
return parallelSettingScope.getSelectedIndex() == SERVER_SET;
}
public void populateBean(ParallelAttrMark parallelAttrMark){
combox.setSelectedIndex(parallelAttrMark.isUseServerSetting() ? SERVER_SET : SINGLE_SET);
parallelSettingScope.setSelectedIndex(parallelAttrMark.isUseServerSetting() ? SERVER_SET : SINGLE_SET);
if (parallelAttrMark.isUseServerSetting()){
populateServerSettings();
} else {
@ -151,15 +132,15 @@ public class FormParallelSettingPane extends BasicBeanPane<FormParallelAttr> {
}
private void populateServerSettings(){
parallelSwitchLabel.setSwitchState(FormParallelCalConfig.getInstance().isParallelCal());
parallelSwitch.setSelected(FormParallelCalConfig.getInstance().isParallelCal());
}
private void populateSingleTemplateSetting(ParallelAttrMark parallelAttrMark){
parallelSwitchLabel.setSwitchState(parallelAttrMark.isEnableParallel());
parallelSwitch.setSelected(parallelAttrMark.isEnableParallel());
}
public ParallelAttrMark updateBean(){
return new ParallelAttrMark(isUsingServerSettings(), parallelSwitchLabel.isParallel());
return new ParallelAttrMark(isUsingServerSettings(), parallelSwitch.isSelected());
}
@Override
@ -167,31 +148,4 @@ public class FormParallelSettingPane extends BasicBeanPane<FormParallelAttr> {
return "";
}
}
/**
* 一个并行开关Label
* */
private static class ParallelSwitchLabel extends JLabel{
boolean parallel;
private final static Icon openIcon = IOUtils.readIcon("com/fr/design/form/images/open.png");
private final static Icon closeIcon = IOUtils.readIcon("com/fr/design/form/images/close.png");
//设置计算状态,parallel状态和图标一起变化
public void setSwitchState(boolean parallel){
this.parallel = parallel;
if (parallel){
this.setIcon(openIcon);
}else {
this.setIcon(closeIcon);
}
}
public void changeSwitchState(){
parallel = !parallel;
setSwitchState(parallel);
}
public boolean isParallel() {
return parallel;
}
}
}

Loading…
Cancel
Save