package com.fr.startup.ui; import com.fr.base.svg.IconUtils; import com.fr.design.DesignerEnvManager; import com.fr.design.components.loading.LoadingPane; import com.fr.design.dialog.UIExpandDialog; import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.ilable.UILabel; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.VerticalFlowLayout; import com.fr.design.ui.util.UIUtil; import com.fr.design.utils.ColorUtils; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.general.GeneralUtils; import com.fr.log.FineLoggerFactory; import com.fr.stable.ProductConstants; import com.fr.stable.collections.CollectionUtils; import org.jetbrains.annotations.NotNull; import javax.swing.BorderFactory; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JLayeredPane; import javax.swing.JPanel; import javax.swing.JSeparator; import javax.swing.ScrollPaneConstants; import javax.swing.SwingConstants; import javax.swing.SwingWorker; import javax.swing.border.EmptyBorder; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GridLayout; import java.awt.LayoutManager; import java.awt.RenderingHints; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.List; import java.util.Map; /** * 启动页 * 见设计文档 *
* created by Harrison on 2022/07/06
**/
public class StartupPageWindow extends JFrame {
private static final int CONTENT_LAYER = 0;
private static final int TRANSPARENT_LAYER = 1;
private static final Color HOVER_COLOR = new Color(65, 155, 249);
private static final Color SEP_COLOR = new Color(224, 224, 225);
private static final int GROUP_WIDTH = 600;
private static final int RECENT_FILE_LIMIT = 6;
private static final int RECENT_FILE_SCROLL = RECENT_FILE_LIMIT + 1;
private static final int WORKSPACE_PANEL_WIDTH = 180;
private static final int TITLE_FONT_SIZE = 24;
private static final int ITEM_VERTICAL_GAP = 5;
private static final Dimension SCREEN_SIZE = new Dimension(1600, 820);
private StartupPageWorkspacePanel workspacePanel;
private JPanel recentOpenPanel;
private JPanel contentPane;
private JPanel body;
private LoadingPane loadingPane = new LoadingPane();
private JLayeredPane layeredPane = new JLayeredPane() {
@Override
public void doLayout() {
for (Component comp : getComponents()) {
comp.setBounds(0, 0, getWidth(), getHeight());
}
}
};
public StartupPageWindow(StartupPageModel pageModel) {
patchUIAction(pageModel);
setLayout(new BorderLayout());
this.body = FRGUIPaneFactory.createBorderLayout_S_Pane();
// Header
UILabel label = new UILabel(Toolkit.i18nText("Fine-Design_Startup_Page_Select_Workspace"));
Font font = label.getFont();
Font titleFont = font.deriveFont(font.getStyle(), TITLE_FONT_SIZE);
label.setFont(titleFont);
JPanel headerPanel = new JPanel();
LayoutManager centerFlowLayout = FRGUIPaneFactory.createCenterFlowLayout();
headerPanel.setLayout(centerFlowLayout);
headerPanel.add(label);
this.body.add(headerPanel, BorderLayout.NORTH);
// Workspace-description
this.workspacePanel = generateWorkspacePanel(pageModel);
this.body.add(workspacePanel, BorderLayout.CENTER);
workspacePanel.setSelectWorkspaceRunnable(new Runnable() {
@Override
public void run() {
JPanel newPanel = generateRecentOpenPanel(pageModel);
body.remove(recentOpenPanel);
recentOpenPanel = newPanel;
body.add(recentOpenPanel, BorderLayout.SOUTH);
validate();
repaint();
}
});
this.recentOpenPanel = generateRecentOpenPanel(pageModel);
this.body.add(recentOpenPanel, BorderLayout.SOUTH);
this.contentPane = new JPanel();
this.contentPane.setLayout(getCenterLayout(body));
this.contentPane.add(this.body, BorderLayout.CENTER);
this.contentPane.setPreferredSize(this.body.getPreferredSize());
this.layeredPane.setName("layered-pane");
this.layeredPane.add(this.contentPane, CONTENT_LAYER);
this.layeredPane.add(this.loadingPane, TRANSPARENT_LAYER);
this.layeredPane.moveToFront(this.contentPane);
add(this.layeredPane, BorderLayout.CENTER);
// Workspace-detail
setSize(SCREEN_SIZE);
setDefaultTitle();
repaint();
validate();
revalidate();
GUICoreUtils.centerWindow(this);
}
private void setDefaultTitle() {
StringBuilder sb = new StringBuilder();
sb.append(ProductConstants.APP_NAME);
sb.append(" ");
sb.append(GeneralUtils.getVersion());
sb.append(" ");
sb.append(ProductConstants.BRANCH);
sb.append(" ");
sb.append(Toolkit.i18nText("Fine-Design_Startup_Page_Title"));
setTitle(sb.toString());
}
private void patchUIAction(StartupPageModel pageModel) {
Runnable selectAndOpenLastTemplateRunnable = pageModel.getOpenLastTemplateRunnable();
pageModel.setOpenLastTemplateRunnable(() -> {
enterWorkspace(selectAndOpenLastTemplateRunnable);
});
Runnable createNewTemplateRunnable = pageModel.getCreateNewTemplateRunnable();
pageModel.setCreateNewTemplateRunnable(() -> {
enterWorkspace(createNewTemplateRunnable);
});
Runnable openEmptyTemplateRunnable = pageModel.getOpenEmptyTemplateRunnable();
pageModel.setOpenEmptyTemplateRunnable(() -> {
enterWorkspace(openEmptyTemplateRunnable);
});
}
private void enterWorkspace(Runnable action) {
loadingPane.start();
layeredPane.moveToFront(loadingPane);
SwingWorker