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.
316 lines
12 KiB
316 lines
12 KiB
package com.fr.design.mainframe.theme; |
|
|
|
import com.fr.base.ScreenResolution; |
|
import com.fr.base.theme.FormTheme; |
|
import com.fr.base.theme.FormThemeConfig; |
|
import com.fr.base.theme.ReportTheme; |
|
import com.fr.base.theme.ReportThemeConfig; |
|
import com.fr.base.theme.TemplateTheme; |
|
import com.fr.base.theme.TemplateThemeConfig; |
|
import com.fr.design.ExtraDesignClassManager; |
|
import com.fr.design.dialog.BasicPane; |
|
import com.fr.design.event.ChangeEvent; |
|
import com.fr.design.event.ChangeListener; |
|
import com.fr.design.file.HistoryTemplateListCache; |
|
import com.fr.design.gui.frpane.UITabbedPane; |
|
import com.fr.design.gui.ibutton.UIButton; |
|
import com.fr.design.i18n.Toolkit; |
|
import com.fr.design.layout.FRGUIPaneFactory; |
|
import com.fr.design.mainframe.JTemplate; |
|
import com.fr.design.mainframe.theme.dialog.TemplateThemeDialog; |
|
import com.fr.design.mainframe.theme.provider.ThemeManageActionProvider; |
|
import com.fr.design.mainframe.theme.ui.BreadcrumbBar; |
|
import com.fr.stable.ArrayUtils; |
|
import com.fr.stable.unit.FU; |
|
import com.fr.third.javax.annotation.Nullable; |
|
import com.fr.workspace.WorkContext; |
|
|
|
import javax.swing.BorderFactory; |
|
import javax.swing.JPanel; |
|
import javax.swing.border.CompoundBorder; |
|
import javax.swing.border.LineBorder; |
|
import java.awt.BasicStroke; |
|
import java.awt.BorderLayout; |
|
import java.awt.CardLayout; |
|
import java.awt.Color; |
|
import java.awt.Component; |
|
import java.awt.Container; |
|
import java.awt.Graphics; |
|
import java.awt.Graphics2D; |
|
import java.awt.RenderingHints; |
|
import java.awt.Stroke; |
|
import java.awt.Window; |
|
import java.awt.event.ActionEvent; |
|
import java.awt.event.ActionListener; |
|
import java.util.ArrayList; |
|
import java.util.List; |
|
import java.util.Set; |
|
|
|
/** |
|
* @author Starryi |
|
* @version 1.0 |
|
* Created by Starryi on 2021/10/9 |
|
*/ |
|
public class TemplateThemeGridPagesPane extends JPanel { |
|
public static final String COMPLETE_BUTTON = "theme_button_complete"; |
|
private BreadcrumbBar breadcrumbBar; |
|
private JPanel contentPane; |
|
private CardLayout cardLayout; |
|
|
|
private TemplateThemeGridPagePane themeUsingPane; |
|
private TemplateThemeGridPagePane themeManagingPane; |
|
|
|
private PageChangeListener pageChangeListener; |
|
private TemplateThemeGridPagePane currentTemplateThemeGridPagePane; |
|
|
|
public TemplateThemeGridPagesPane() { |
|
initializePane(null); |
|
} |
|
|
|
public TemplateThemeGridPagesPane(@Nullable Window window) { |
|
initializePane(window); |
|
} |
|
|
|
private void initializePane(@Nullable Window window) { |
|
setLayout(new BorderLayout()); |
|
setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10)); |
|
|
|
breadcrumbBar = new BreadcrumbBar(); |
|
breadcrumbBar.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0)); |
|
add(breadcrumbBar, BorderLayout.NORTH); |
|
|
|
contentPane = new JPanel(); |
|
contentPane.setBorder(new CompoundBorder( |
|
new TopLineBorder(new Color(0xE0E0E1), 1), |
|
BorderFactory.createEmptyBorder(10, 0, 0, 0))); |
|
cardLayout = new CardLayout(); |
|
contentPane.setLayout(cardLayout); |
|
add(contentPane, BorderLayout.CENTER); |
|
|
|
|
|
themeUsingPane = new TemplateThemeUsingPane(window); |
|
contentPane.add(themeUsingPane, themeUsingPane.getTitle()); |
|
themeManagingPane = new TemplateThemeManagingPane(window); |
|
contentPane.add(themeManagingPane, themeManagingPane.getTitle()); |
|
|
|
showThemeUsingPane(); |
|
} |
|
|
|
public void showThemeUsingPane() { |
|
if (currentTemplateThemeGridPagePane != themeUsingPane) { |
|
cardLayout.show(contentPane, themeUsingPane.getTitle()); |
|
currentTemplateThemeGridPagePane = themeUsingPane; |
|
if (pageChangeListener != null) { |
|
pageChangeListener.onPageChangeListener(); |
|
} |
|
breadcrumbBar.clear(); |
|
breadcrumbBar.addCrumb(themeUsingPane.getTitle(), new BreadcrumbBar.BreadcrumbBackListener() { |
|
@Override |
|
public void onBreadcrumbBack(String text) { |
|
cardLayout.show(contentPane, themeUsingPane.getTitle()); |
|
currentTemplateThemeGridPagePane = themeUsingPane; |
|
if (pageChangeListener != null) { |
|
pageChangeListener.onPageChangeListener(); |
|
} |
|
} |
|
}); |
|
} |
|
} |
|
|
|
public void showThemeManagingPane() { |
|
if (currentTemplateThemeGridPagePane != themeManagingPane) { |
|
cardLayout.show(contentPane, themeManagingPane.getTitle()); |
|
currentTemplateThemeGridPagePane = themeManagingPane; |
|
if (pageChangeListener != null) { |
|
pageChangeListener.onPageChangeListener(); |
|
} |
|
breadcrumbBar.addCrumb(themeManagingPane.getTitle(), null); |
|
} |
|
} |
|
|
|
public UIButton[] createLeftButtons() { |
|
UIButton[] buttons = new UIButton[] {}; |
|
if (currentTemplateThemeGridPagePane != themeManagingPane && WorkContext.getCurrent().isRoot()) { |
|
buttons = ArrayUtils.addAll(buttons, createOpenThemeManagerButton()); |
|
} |
|
return buttons; |
|
} |
|
|
|
public UIButton[] createRightButtons() { |
|
UIButton[] buttons = new UIButton[] {}; |
|
buttons = ArrayUtils.addAll(buttons, createExtraButtons()); |
|
buttons = ArrayUtils.addAll(buttons, createCompleteButton()); |
|
return buttons; |
|
} |
|
|
|
private UIButton createOpenThemeManagerButton() { |
|
UIButton button = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Manager_Dialog_Title")); |
|
button.addActionListener(new ActionListener() { |
|
@Override |
|
public void actionPerformed(ActionEvent e) { |
|
showThemeManagingPane(); |
|
} |
|
}); |
|
return button; |
|
} |
|
|
|
private UIButton[] createExtraButtons() { |
|
List<UIButton> uiButtonList = new ArrayList<>(); |
|
|
|
Set<ThemeManageActionProvider> providers = ExtraDesignClassManager.getInstance().getArray(ThemeManageActionProvider.MARK_STRING); |
|
for (ThemeManageActionProvider provider : providers) { |
|
uiButtonList.add(provider.createButton(new ThemeManageActionProvider.ThemeManageActionContext() { |
|
|
|
@Override |
|
public TemplateThemeDialog getDialog() { |
|
Container container = getRootPane().getParent(); |
|
if (container instanceof TemplateThemeDialog) { |
|
return (TemplateThemeDialog) container; |
|
} |
|
return null; |
|
} |
|
|
|
@Override |
|
public TemplateThemeConfig<? extends TemplateTheme> getConfig() { |
|
return currentTemplateThemeGridPagePane.getConfig(); |
|
} |
|
})); |
|
} |
|
|
|
return uiButtonList.toArray(new UIButton[]{}); |
|
} |
|
|
|
private UIButton createCompleteButton() { |
|
UIButton button = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Manager_Dialog_Complete")); |
|
button.setName(COMPLETE_BUTTON); |
|
button.addActionListener(new ActionListener() { |
|
@Override |
|
public void actionPerformed(ActionEvent e) { |
|
Container container = getRootPane().getParent(); |
|
if (container instanceof TemplateThemeDialog) { |
|
((TemplateThemeDialog) container).exit(); |
|
} |
|
} |
|
}); |
|
return button; |
|
} |
|
|
|
public void setPageChangeListener(PageChangeListener changeListener) { |
|
this.pageChangeListener = changeListener; |
|
} |
|
|
|
public interface PageChangeListener { |
|
void onPageChangeListener(); |
|
} |
|
|
|
public static class TopLineBorder extends LineBorder { |
|
private final FU fu; |
|
|
|
private TopLineBorder(Color color, int thickness) { |
|
super(color, thickness); |
|
fu = FU.getInstance(thickness); |
|
} |
|
|
|
@Override |
|
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { |
|
Graphics2D g2d = (Graphics2D)g; |
|
|
|
Color oldColor = g2d.getColor(); |
|
Stroke oldStroke = g2d.getStroke(); |
|
|
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
|
|
|
g2d.setColor(getLineColor()); |
|
int thickness = Math.max(1, fu.toPixI(ScreenResolution.getScreenResolution())); |
|
g2d.setStroke(new BasicStroke(thickness)); |
|
g2d.drawLine(0, 0, width, thickness); |
|
|
|
g2d.setStroke(oldStroke); |
|
g2d.setColor(oldColor); |
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); |
|
} |
|
} |
|
|
|
public abstract static class TemplateThemeGridPagePane extends BasicPane { |
|
public abstract TemplateThemeConfig<? extends TemplateTheme> getConfig(); |
|
} |
|
|
|
public static class TemplateThemeUsingPane extends TemplateThemeGridPagePane { |
|
private final JTemplate<?,?> template; |
|
public final TemplateThemeGridPane<? extends TemplateTheme> themeListPane; |
|
|
|
public TemplateThemeUsingPane(@Nullable Window window) { |
|
super(); |
|
setLayout(new BorderLayout()); |
|
setBorder(new CompoundBorder( |
|
BorderFactory.createLineBorder(new Color(0xE0E0E1)), |
|
BorderFactory.createEmptyBorder(0, 10, 0, 10))); |
|
|
|
template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
|
TemplateThemeConfig<? extends TemplateTheme> config = template.getUsingTemplateThemeConfig(); |
|
themeListPane = new TemplateThemeGridPane<>(window, false, config, null); |
|
|
|
themeListPane.setSelectedChangeListener(new ChangeListener() { |
|
@Override |
|
public void fireChanged(ChangeEvent event) { |
|
TemplateTheme theme = themeListPane.getSelectedTheme(); |
|
if (theme != null) { |
|
template.setTemplateTheme(theme); |
|
themeListPane.repaint(); |
|
} |
|
} |
|
}); |
|
|
|
add(themeListPane, BorderLayout.CENTER); |
|
} |
|
|
|
@Override |
|
public TemplateThemeConfig<? extends TemplateTheme> getConfig() { |
|
return template.getUsingTemplateThemeConfig(); |
|
} |
|
|
|
@Override |
|
protected String title4PopupWindow() { |
|
return Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Using_Dialog_Title"); |
|
} |
|
} |
|
|
|
public static class TemplateThemeManagingPane extends TemplateThemeGridPagePane { |
|
private final UITabbedPane tabbedPane; |
|
|
|
public TemplateThemeManagingPane(@Nullable Window window) { |
|
setLayout(FRGUIPaneFactory.createBorderLayout()); |
|
|
|
tabbedPane = new UITabbedPane(); |
|
tabbedPane.setTabBorderColor(new Color(0xE0E0E1)); |
|
add(tabbedPane, BorderLayout.CENTER); |
|
|
|
TemplateThemeGridControlPane<FormTheme> formThemesManagerPane = TemplateThemeGridControlPane.createFormThemesManagerPane(window); |
|
TemplateThemeGridControlPane<ReportTheme> reportThemesManagerPane = TemplateThemeGridControlPane.createReportThemesManagerPane(window); |
|
|
|
tabbedPane.addTab(Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Manager_Dialog_Form_Tab"), formThemesManagerPane); |
|
tabbedPane.addTab(Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Manager_Dialog_Report_Tab"), reportThemesManagerPane); |
|
|
|
tabbedPane.setSelectedIndex(0); |
|
JTemplate<?,?> template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
|
TemplateThemeConfig<? extends TemplateTheme> config = template.getUsingTemplateThemeConfig(); |
|
if (config == reportThemesManagerPane.getConfig()) { |
|
tabbedPane.setSelectedIndex(1); |
|
} |
|
} |
|
|
|
@Override |
|
public TemplateThemeConfig<? extends TemplateTheme> getConfig() { |
|
if (tabbedPane.getSelectedIndex() == 0) { |
|
return FormThemeConfig.getInstance(); |
|
} else { |
|
return ReportThemeConfig.getInstance(); |
|
} |
|
} |
|
|
|
@Override |
|
protected String title4PopupWindow() { |
|
return Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Manager_Dialog_Title"); |
|
} |
|
} |
|
}
|
|
|