package com.fr.design.lock; import com.fr.design.file.TemplateTreePane; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ilable.UILabel; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.DesignerContext; import com.fr.design.utils.TemplateUtils; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.file.FileNodeFILE; import com.fr.file.filetree.FileNode; import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; import com.fr.stable.project.ProjectConstants; import com.fr.workspace.base.UserInfo; import java.awt.BorderLayout; import java.awt.Color; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import javax.swing.BorderFactory; import javax.swing.JDialog; import javax.swing.JPanel; import javax.swing.UIManager; /** * @author hades * @version 11.0 * Created by hades on 2021/12/2 */ public class LockInfoDialog extends JDialog { private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm"); public LockInfoDialog(UserInfo userInfo) { super(DesignerContext.getDesignerFrame()); JPanel panel = new JPanel(new BorderLayout()); panel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); UILabel iconLabel = new UILabel(UIManager.getIcon("OptionPane.warningIcon")); panel.add(iconLabel, BorderLayout.WEST); panel.add(createContentPane(userInfo), BorderLayout.CENTER); panel.add(createControlPane(), BorderLayout.SOUTH); this.getContentPane().add(panel); this.setTitle(Toolkit.i18nText("Fine-Design_Basic_Alert")); this.setSize(400, 180); this.setResizable(false); this.setModal(true); GUICoreUtils.centerWindow(this); this.setVisible(true); } private JPanel createContentPane(UserInfo userInfo) { JPanel contentPanel = new JPanel(new BorderLayout()); contentPanel.setBorder(BorderFactory.createEmptyBorder(15, 0, 0, 0)); contentPanel.add(new UILabel(Toolkit.i18nText("Fine-Design_Template_Lock_And_SaveAs_Tip")), BorderLayout.NORTH); JPanel detailInfoPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane(); detailInfoPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 0,0)); if (userInfo != null && StringUtils.isNotEmpty(userInfo.getUserName())) { detailInfoPane.add(createLabel(Toolkit.i18nText("Fine-Design_Template_Lock_Holder", userInfo.getUserName()))); } if (userInfo != null && StringUtils.isNotEmpty(userInfo.getIp())) { detailInfoPane.add(createLabel(Toolkit.i18nText("Fine-Design_Template_Lock_Holder_Ip", userInfo.getIp()) )); } detailInfoPane.add(createLabel(Toolkit.i18nText("Fine-Design_Template_Lock_Get_Time", FORMATTER.format(LocalDateTime.now())))); contentPanel.add(detailInfoPane, BorderLayout.CENTER); return contentPanel; } private UILabel createLabel(String text) { UILabel label = new UILabel(text); label.setForeground(Color.GRAY); label.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0)); return label; } private JPanel createControlPane() { JPanel controlPane = new JPanel(new FlowLayout(FlowLayout.RIGHT)); UIButton saveAsButton = new UIButton(Toolkit.i18nText("Fine_Design_Template_Lock_Save_As")); UIButton cancelButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Button_Cancel")); saveAsButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dispose(); FileNode node = TemplateTreePane.getInstance().getFileNode(); if (node == null) { return; } final String selectedFilePath = StableUtils.pathJoin(ProjectConstants.REPORTLETS_NAME, TemplateTreePane.getInstance().getFilePath()); TemplateUtils.createAndOpenTemplate(Toolkit.i18nText("Fine_Design_Template_Lock_Copy"), new FileNodeFILE(new FileNode(selectedFilePath, false)), true); } }); cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dispose(); } }); controlPane.add(saveAsButton); controlPane.add(cancelButton); return controlPane; } public static void show(UserInfo userInfo) { new LockInfoDialog(userInfo); } }