forked from fanruan/design
Starryi
3 years ago
27 changed files with 1019 additions and 165 deletions
@ -0,0 +1,140 @@ |
|||||||
|
package com.fr.design.gui.style; |
||||||
|
|
||||||
|
import com.fr.base.theme.FormTheme; |
||||||
|
import com.fr.base.theme.TemplateTheme; |
||||||
|
import com.fr.design.dialog.BasicPane; |
||||||
|
import com.fr.design.event.GlobalNameListener; |
||||||
|
import com.fr.design.event.GlobalNameObserver; |
||||||
|
import com.fr.design.event.UIObserver; |
||||||
|
import com.fr.design.event.UIObserverListener; |
||||||
|
import com.fr.design.file.HistoryTemplateListCache; |
||||||
|
import com.fr.design.gui.ibutton.UIButtonGroup; |
||||||
|
import com.fr.design.gui.ilable.UILabel; |
||||||
|
import com.fr.design.i18n.Toolkit; |
||||||
|
import com.fr.design.layout.FRGUIPaneFactory; |
||||||
|
import com.fr.design.layout.TableLayout; |
||||||
|
import com.fr.design.layout.TableLayoutHelper; |
||||||
|
import com.fr.design.mainframe.JTemplate; |
||||||
|
|
||||||
|
import javax.swing.BorderFactory; |
||||||
|
import javax.swing.JPanel; |
||||||
|
import java.awt.BorderLayout; |
||||||
|
import java.awt.Component; |
||||||
|
import java.awt.Dimension; |
||||||
|
import java.awt.event.ActionEvent; |
||||||
|
import java.awt.event.ActionListener; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Starryi |
||||||
|
* @version 1.0 |
||||||
|
* Created by Starryi on 2021/8/19 |
||||||
|
*/ |
||||||
|
public class FollowingThemePane extends BasicPane implements UIObserver { |
||||||
|
public static final int SETTING_LABEL_WIDTH = 60; |
||||||
|
|
||||||
|
public static final String[] FOLLOWING_THEME_STRING_ARRAYS = new String[]{ |
||||||
|
Toolkit.i18nText("Fine-Design_Style_Follow_Theme"), |
||||||
|
Toolkit.i18nText("Fine-Design_Style_Not_Follow_Theme"), |
||||||
|
}; |
||||||
|
|
||||||
|
private final UIButtonGroup<String> followingThemeButtonGroup; |
||||||
|
private final List<FollowingThemeActionChangeListener> changeListeners = new ArrayList<>(); |
||||||
|
private UIObserverListener uiObserverListener; |
||||||
|
|
||||||
|
private JPanel container; |
||||||
|
|
||||||
|
public FollowingThemePane(String name) { |
||||||
|
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||||
|
this.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); |
||||||
|
|
||||||
|
followingThemeButtonGroup = new UIButtonGroup<>(FOLLOWING_THEME_STRING_ARRAYS); |
||||||
|
followingThemeButtonGroup.setSelectedIndex(1); |
||||||
|
followingThemeButtonGroup.addActionListener(new ActionListener() { |
||||||
|
@Override |
||||||
|
public void actionPerformed(ActionEvent e) { |
||||||
|
for (FollowingThemeActionChangeListener changeListener : changeListeners) { |
||||||
|
changeListener.onFollowingTheme(isFollowingTheme()); |
||||||
|
} |
||||||
|
|
||||||
|
// 与主题相关的属性面板更新完毕后,再通知外层更新数据
|
||||||
|
if (uiObserverListener != null) { |
||||||
|
uiObserverListener.doChange(); |
||||||
|
} |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
UILabel followingThemeLabel = new UILabel(name); |
||||||
|
|
||||||
|
double p = TableLayout.PREFERRED; |
||||||
|
double f = TableLayout.FILL; |
||||||
|
JPanel followingThemePane = |
||||||
|
TableLayoutHelper.createGapTableLayoutPane( new Component[][]{new Component[] { followingThemeLabel, followingThemeButtonGroup}}, |
||||||
|
new double[] { p }, new double[] { SETTING_LABEL_WIDTH, f }, 10, 0); |
||||||
|
followingThemePane.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); |
||||||
|
followingThemePane.setVisible(false); |
||||||
|
|
||||||
|
add(followingThemePane, BorderLayout.NORTH); |
||||||
|
container = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||||
|
add(container, BorderLayout.CENTER); |
||||||
|
} |
||||||
|
|
||||||
|
public void addFollowThemePane(JPanel content, FollowingThemeActionChangeListener changeListener) { |
||||||
|
if (content != null) { |
||||||
|
container.add(content, BorderLayout.NORTH); |
||||||
|
changeListeners.add(changeListener); |
||||||
|
|
||||||
|
JPanel nextContainer = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||||
|
container.add(nextContainer, BorderLayout.CENTER); |
||||||
|
container = nextContainer; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String title4PopupWindow() { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void registerChangeListener(UIObserverListener uiObserverListener) { |
||||||
|
this.uiObserverListener = uiObserverListener; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean shouldResponseChangeListener() { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
public interface FollowingThemeActionChangeListener { |
||||||
|
void onFollowingTheme(boolean following); |
||||||
|
} |
||||||
|
|
||||||
|
public TemplateTheme getUsingTheme() { |
||||||
|
JTemplate<?, ?> template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
||||||
|
if (template != null) { |
||||||
|
TemplateTheme theme = template.getTemplateTheme(); |
||||||
|
if (theme instanceof FormTheme) { |
||||||
|
return theme; |
||||||
|
} |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public void supportFollowingTheme(boolean supporting) { |
||||||
|
getComponent(0).setVisible(supporting); |
||||||
|
if (!supporting) { |
||||||
|
setFollowingTheme(false); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void setFollowingTheme(boolean following) { |
||||||
|
followingThemeButtonGroup.setSelectedIndex(following ? 0 : 1); |
||||||
|
for (FollowingThemeActionChangeListener changeListener : changeListeners) { |
||||||
|
changeListener.onFollowingTheme(isFollowingTheme()); |
||||||
|
} |
||||||
|
} |
||||||
|
public boolean isFollowingTheme() { |
||||||
|
return followingThemeButtonGroup.getSelectedIndex() == 0; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,102 @@ |
|||||||
|
package com.fr.design.gui.style; |
||||||
|
|
||||||
|
import com.fr.design.ExtraDesignClassManager; |
||||||
|
import com.fr.design.event.UIObserverListener; |
||||||
|
import com.fr.design.fun.BackgroundQuickUIProvider; |
||||||
|
import com.fr.design.mainframe.backgroundpane.BackgroundQuickPane; |
||||||
|
import com.fr.design.mainframe.backgroundpane.ColorBackgroundQuickPane; |
||||||
|
import com.fr.design.mainframe.backgroundpane.GradientBackgroundQuickPane; |
||||||
|
import com.fr.design.mainframe.backgroundpane.ImageBackgroundQuickPane; |
||||||
|
import com.fr.design.mainframe.backgroundpane.NullBackgroundQuickPane; |
||||||
|
import com.fr.design.mainframe.backgroundpane.PatternBackgroundQuickPane; |
||||||
|
import com.fr.design.mainframe.backgroundpane.TextureBackgroundQuickPane; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Set; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Starryi |
||||||
|
* @version 1.0 |
||||||
|
* Created by Starryi on 2021/8/19 |
||||||
|
*/ |
||||||
|
public class ReportBackgroundSpecialPane extends BackgroundPane { |
||||||
|
public ReportBackgroundSpecialPane(){ |
||||||
|
super(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected BackgroundQuickPane[] supportKindsOfBackgroundUI() { |
||||||
|
NullBackgroundQuickPane nullBackgroundPane = new NullBackgroundQuickPane(); |
||||||
|
|
||||||
|
ColorBackgroundQuickPane colorBackgroundPane = new ColorBackgroundQuickPane(); |
||||||
|
colorBackgroundPane.registerChangeListener(new UIObserverListener() { |
||||||
|
@Override |
||||||
|
public void doChange() { |
||||||
|
fireStateChanged(); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
ImageBackgroundQuickPane imageBackgroundPane = new ImageBackgroundQuickPane(); |
||||||
|
imageBackgroundPane.registerChangeListener(new UIObserverListener() { |
||||||
|
@Override |
||||||
|
public void doChange() { |
||||||
|
fireStateChanged(); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
GradientBackgroundQuickPane gradientBackgroundPane = createGradientBackgroundQuickPane(); |
||||||
|
gradientBackgroundPane.registerChangeListener(new UIObserverListener() { |
||||||
|
@Override |
||||||
|
public void doChange() { |
||||||
|
fireStateChanged(); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
TextureBackgroundQuickPane textureBackgroundPane = new TextureBackgroundQuickPane(); |
||||||
|
textureBackgroundPane.registerChangeListener(new UIObserverListener() { |
||||||
|
@Override |
||||||
|
public void doChange() { |
||||||
|
fireStateChanged(); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
PatternBackgroundQuickPane patternBackgroundPane = new PatternBackgroundQuickPane(); |
||||||
|
patternBackgroundPane.registerChangeListener(new UIObserverListener() { |
||||||
|
@Override |
||||||
|
public void doChange() { |
||||||
|
fireStateChanged(); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
List<BackgroundQuickPane> kinds = new ArrayList<BackgroundQuickPane>(); |
||||||
|
|
||||||
|
kinds.add(nullBackgroundPane); |
||||||
|
kinds.add(colorBackgroundPane); |
||||||
|
kinds.add(imageBackgroundPane); |
||||||
|
kinds.add(gradientBackgroundPane); |
||||||
|
kinds.add(textureBackgroundPane); |
||||||
|
kinds.add(patternBackgroundPane); |
||||||
|
|
||||||
|
Set<BackgroundQuickUIProvider> providers = ExtraDesignClassManager.getInstance().getArray(BackgroundQuickUIProvider.MARK_STRING); |
||||||
|
for (BackgroundQuickUIProvider provider : providers) { |
||||||
|
BackgroundQuickPane newTypePane = provider.appearanceForBackground(); |
||||||
|
newTypePane.registerChangeListener(new UIObserverListener() { |
||||||
|
@Override |
||||||
|
public void doChange() { |
||||||
|
fireStateChanged(); |
||||||
|
} |
||||||
|
}); |
||||||
|
kinds.add(newTypePane); |
||||||
|
} |
||||||
|
|
||||||
|
return kinds.toArray(new BackgroundQuickPane[kinds.size()]); |
||||||
|
} |
||||||
|
|
||||||
|
protected GradientBackgroundQuickPane createGradientBackgroundQuickPane() { |
||||||
|
// 使用默认的150宽度构建渐变条
|
||||||
|
return new GradientBackgroundQuickPane(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,211 @@ |
|||||||
|
package com.fr.design.report; |
||||||
|
|
||||||
|
import com.fr.base.theme.ReportTheme; |
||||||
|
import com.fr.base.theme.TemplateTheme; |
||||||
|
import com.fr.base.theme.settings.ThemedComponentStyle; |
||||||
|
import com.fr.base.theme.settings.ThemedReportBodyStyle; |
||||||
|
import com.fr.design.designer.IntervalConstants; |
||||||
|
import com.fr.design.dialog.BasicPane; |
||||||
|
import com.fr.design.gui.frpane.AbstractAttrNoScrollPane; |
||||||
|
import com.fr.design.gui.frpane.AttributeChangeListener; |
||||||
|
import com.fr.design.gui.icheckbox.UICheckBox; |
||||||
|
import com.fr.design.gui.ilable.UILabel; |
||||||
|
import com.fr.design.gui.style.ReportBackgroundSpecialPane; |
||||||
|
import com.fr.design.gui.style.FollowingThemePane; |
||||||
|
import com.fr.design.i18n.Toolkit; |
||||||
|
import com.fr.design.layout.FRGUIPaneFactory; |
||||||
|
import com.fr.design.layout.TableLayout; |
||||||
|
import com.fr.design.layout.TableLayoutHelper; |
||||||
|
import com.fr.design.mainframe.theme.ui.BorderUtils; |
||||||
|
import com.fr.form.ui.PaddingMargin; |
||||||
|
import com.fr.general.Background; |
||||||
|
import com.fr.page.ReportSettingsProvider; |
||||||
|
import com.fr.report.stable.ReportSettings; |
||||||
|
|
||||||
|
import javax.swing.BorderFactory; |
||||||
|
import javax.swing.JPanel; |
||||||
|
import javax.swing.SwingConstants; |
||||||
|
import javax.swing.border.CompoundBorder; |
||||||
|
import java.awt.BorderLayout; |
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.Component; |
||||||
|
import java.awt.Dimension; |
||||||
|
import java.awt.Graphics; |
||||||
|
import java.awt.Graphics2D; |
||||||
|
import java.awt.Shape; |
||||||
|
import java.awt.geom.Rectangle2D; |
||||||
|
|
||||||
|
public class NewReportBackgroundPane extends BasicPane { |
||||||
|
private final UICheckBox isPrintBackgroundCheckBox; |
||||||
|
private final UICheckBox isExportBackgroundCheckBox; |
||||||
|
private final BackgroundProfilePane profilePane; |
||||||
|
|
||||||
|
public NewReportBackgroundPane() { |
||||||
|
setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||||
|
setBorder(BorderFactory.createEmptyBorder()); |
||||||
|
setPreferredSize(new Dimension(600, 570)); |
||||||
|
|
||||||
|
profilePane = new BackgroundProfilePane(); |
||||||
|
isPrintBackgroundCheckBox = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Print_Background")); |
||||||
|
isExportBackgroundCheckBox = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Export_Background")); |
||||||
|
|
||||||
|
add(profilePane, BorderLayout.CENTER); |
||||||
|
add(createBottomPane(), BorderLayout.SOUTH); |
||||||
|
} |
||||||
|
|
||||||
|
private JPanel createBottomPane() { |
||||||
|
JPanel container = new JPanel(); |
||||||
|
container.setPreferredSize(new Dimension(container.getPreferredSize().width, 30)); |
||||||
|
container.add(isExportBackgroundCheckBox); |
||||||
|
container.add(isPrintBackgroundCheckBox); |
||||||
|
return container; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String title4PopupWindow() { |
||||||
|
return Toolkit.i18nText("Fine-Design_Report_Background"); |
||||||
|
} |
||||||
|
|
||||||
|
public void populate(ReportSettingsProvider reportSettings) { |
||||||
|
this.profilePane.populateBean(reportSettings); |
||||||
|
this.isPrintBackgroundCheckBox.setSelected(reportSettings.isPrintBackground()); |
||||||
|
this.isExportBackgroundCheckBox.setSelected(reportSettings.isExportBackground()); |
||||||
|
} |
||||||
|
|
||||||
|
public void update(ReportSettingsProvider reportSettings) { |
||||||
|
this.profilePane.updateBean(reportSettings); |
||||||
|
reportSettings.setPrintBackground(this.isPrintBackgroundCheckBox.isSelected()); |
||||||
|
reportSettings.setExportBackground(this.isExportBackgroundCheckBox.isSelected()); |
||||||
|
} |
||||||
|
|
||||||
|
private static class BackgroundPreviewPane extends JPanel { |
||||||
|
private Background background = null; |
||||||
|
|
||||||
|
void refresh(Background background) { |
||||||
|
this.background = background; |
||||||
|
repaint(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void paint(Graphics g) { |
||||||
|
g.setColor(Color.WHITE); |
||||||
|
g.fillRect(0, 0, getWidth(), getHeight()); |
||||||
|
Graphics2D g2d = (Graphics2D) g; |
||||||
|
if (background != null) { |
||||||
|
Shape shape = new Rectangle2D.Double(0, 0, getWidth(), getHeight()); |
||||||
|
background.paint(g2d, shape); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private static class BackgroundProfilePane extends AbstractAttrNoScrollPane { |
||||||
|
public static final int SETTING_LABEL_WIDTH = 60; |
||||||
|
|
||||||
|
private BackgroundPreviewPane previewPane; |
||||||
|
private FollowingThemePane themePane; |
||||||
|
private ReportBackgroundSpecialPane backgroundPane; |
||||||
|
private JPanel backgroundLabeledPane; |
||||||
|
|
||||||
|
@Override |
||||||
|
protected JPanel createContentPane() { |
||||||
|
previewPane = new BackgroundPreviewPane(); |
||||||
|
themePane = new FollowingThemePane(Toolkit.i18nText("Fine-Design_Report_Background_Setting")); |
||||||
|
themePane.supportFollowingTheme(true); |
||||||
|
|
||||||
|
double p = TableLayout.PREFERRED; |
||||||
|
double f = TableLayout.FILL; |
||||||
|
|
||||||
|
JPanel uiLabelPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||||
|
uiLabelPane.add(new UILabel(Toolkit.i18nText("Fine-Design_Report_Background_Fill")), BorderLayout.NORTH); |
||||||
|
uiLabelPane.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); |
||||||
|
backgroundPane = new ReportBackgroundSpecialPane(); |
||||||
|
backgroundLabeledPane = TableLayoutHelper.createCommonTableLayoutPane( |
||||||
|
new Component[][]{ new Component[] { uiLabelPane, backgroundPane } }, |
||||||
|
new double[] { p }, new double[] { SETTING_LABEL_WIDTH, f}, IntervalConstants.INTERVAL_L1 |
||||||
|
); |
||||||
|
themePane.addFollowThemePane(backgroundLabeledPane, new FollowingThemePane.FollowingThemeActionChangeListener() { |
||||||
|
@Override |
||||||
|
public void onFollowingTheme(boolean following) { |
||||||
|
backgroundLabeledPane.setVisible(!following); |
||||||
|
|
||||||
|
if (following) { |
||||||
|
TemplateTheme theme = themePane.getUsingTheme(); |
||||||
|
if (theme instanceof ReportTheme) { |
||||||
|
ThemedReportBodyStyle style = ((ReportTheme) theme).getBodyStyle(); |
||||||
|
Background background = style.getBackground(); |
||||||
|
backgroundPane.populateBean(background); |
||||||
|
previewPane.refresh(background); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
JPanel contentContainer = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||||
|
contentContainer.setBorder(BorderFactory.createEmptyBorder()); |
||||||
|
contentContainer.setBorder(BorderFactory.createEmptyBorder()); |
||||||
|
contentContainer.setPreferredSize(new Dimension(600, 540)); |
||||||
|
contentContainer.add(createLeftPane(), BorderLayout.WEST); |
||||||
|
contentContainer.add(createRightPane(), BorderLayout.EAST); |
||||||
|
|
||||||
|
addAttributeChangeListener(new AttributeChangeListener() { |
||||||
|
@Override |
||||||
|
public void attributeChange() { |
||||||
|
valueChangeAction(); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
return contentContainer; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void initContentPane() { |
||||||
|
super.initContentPane(); |
||||||
|
leftContentPane.setBorder(BorderFactory.createEmptyBorder()); |
||||||
|
} |
||||||
|
|
||||||
|
private JPanel createLeftPane() { |
||||||
|
JPanel container = FRGUIPaneFactory.createLeftFlowZeroGapBorderPane(); |
||||||
|
container.setBorder(BorderFactory.createEmptyBorder()); |
||||||
|
JPanel titledPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||||
|
titledPane.setBorder(new CompoundBorder( |
||||||
|
BorderUtils.createTitleBorder("预览", 12), |
||||||
|
BorderFactory.createEmptyBorder(5, 5, 4, 5) |
||||||
|
)); |
||||||
|
titledPane.setPreferredSize(new Dimension(397, 502)); |
||||||
|
container.add(titledPane, BorderLayout.WEST); |
||||||
|
titledPane.add(previewPane, BorderLayout.WEST); |
||||||
|
previewPane.setPreferredSize(new Dimension(387, 480)); |
||||||
|
|
||||||
|
return container; |
||||||
|
} |
||||||
|
|
||||||
|
private JPanel createRightPane() { |
||||||
|
JPanel container = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||||
|
container.setBorder(BorderFactory.createEmptyBorder()); |
||||||
|
container.setPreferredSize(new Dimension(253, 502)); |
||||||
|
container.add(themePane, BorderLayout.NORTH); |
||||||
|
return container; |
||||||
|
} |
||||||
|
|
||||||
|
private void valueChangeAction() { |
||||||
|
previewPane.refresh(backgroundPane.update()); |
||||||
|
} |
||||||
|
|
||||||
|
public void populateBean(ReportSettingsProvider reportSettings) { |
||||||
|
if (reportSettings instanceof ReportSettings) { |
||||||
|
boolean followingTheme = ((ReportSettings) reportSettings).isBackgroundFollowingTheme(); |
||||||
|
themePane.setFollowingTheme(followingTheme); |
||||||
|
backgroundLabeledPane.setVisible(!followingTheme); |
||||||
|
} |
||||||
|
backgroundPane.populateBean(reportSettings.getBackground()); |
||||||
|
previewPane.refresh(reportSettings.getBackground()); |
||||||
|
} |
||||||
|
|
||||||
|
public void updateBean(ReportSettingsProvider reportSettings) { |
||||||
|
if (reportSettings instanceof ReportSettings) { |
||||||
|
((ReportSettings) reportSettings).setBackgroundFollowingTheme(themePane.isFollowingTheme()); |
||||||
|
} |
||||||
|
reportSettings.setBackground(backgroundPane.update()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue