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.
159 lines
6.0 KiB
159 lines
6.0 KiB
package com.fr.env.detect.ui; |
|
|
|
import com.fr.base.svg.IconUtils; |
|
import com.fr.design.RestartHelper; |
|
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.utils.ColorUtils; |
|
import com.fr.design.utils.DesignUtils; |
|
import com.fr.design.utils.gui.GUICoreUtils; |
|
import com.fr.env.detect.base.DetectorUtil; |
|
import com.fr.env.detect.bean.DetectorResult; |
|
import com.fr.env.detect.bean.ExceptionSolution; |
|
import com.fr.env.detect.bean.ExceptionTips; |
|
import com.fr.env.detect.bean.Message; |
|
import com.fr.exit.DesignerExiter; |
|
|
|
import javax.swing.BorderFactory; |
|
import javax.swing.JDialog; |
|
import javax.swing.JPanel; |
|
import javax.swing.JScrollPane; |
|
import javax.swing.ScrollPaneConstants; |
|
import java.awt.BorderLayout; |
|
import java.awt.Color; |
|
import java.awt.Dimension; |
|
import java.awt.FlowLayout; |
|
import java.awt.Font; |
|
import java.awt.Frame; |
|
import java.awt.event.ActionEvent; |
|
import java.awt.event.ActionListener; |
|
import java.util.List; |
|
|
|
/** |
|
* 未知错误框 |
|
* todo 其实这里可以将多个 error-dialog 抽象在一起的。 时间不够, 简单写写 |
|
* 见 {@link com.fr.design.dialog.ErrorDialog} |
|
* |
|
* created by Harrison on 2022/05/29 |
|
**/ |
|
public class DetectorErrorDialog extends JDialog implements ActionListener { |
|
|
|
public static final float FONT_BOLD_HEIGHT = 16f; |
|
private UIButton okButton; |
|
private UIButton restartButton; |
|
|
|
public DetectorErrorDialog(Frame parent, List<DetectorResult> results) { |
|
|
|
super(parent, true); |
|
|
|
// 可能是还没初始化 UI 的时候出现的问题,初始化一下 UI |
|
DesignUtils.initLookAndFeel(); |
|
|
|
JPanel northPane = FRGUIPaneFactory.createBorderLayout_L_Pane(); |
|
JPanel headerPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
headerPane.setLayout(new BorderLayout(15, 0)); |
|
|
|
UILabel iconLabel = new UILabel(IconUtils.readIcon("/com/fr/design/standard/reminder/reminder_warning_window.svg")); |
|
headerPane.add(iconLabel, BorderLayout.WEST); |
|
|
|
JPanel messagePane = FRGUIPaneFactory.createVerticalFlowLayout_S_Pane(true); |
|
{ |
|
UILabel boldHeader = new UILabel(Toolkit.i18nText("Fine-Design_Error_Start_Apology_Message")); |
|
Font font = boldHeader.getFont(); |
|
Font boldFont = font.deriveFont(FONT_BOLD_HEIGHT); |
|
boldHeader.setFont(boldFont); |
|
messagePane.add(boldHeader); |
|
|
|
UILabel description = new UILabel(Toolkit.i18nText("Fine-Design_Send_Report_To_Us")); |
|
messagePane.add(description); |
|
} |
|
headerPane.add(messagePane, BorderLayout.CENTER); |
|
|
|
northPane.add(headerPane); |
|
|
|
JPanel centerPane = FRGUIPaneFactory.createBorderLayout_L_Pane(); |
|
centerPane.setLayout(new BorderLayout(0, 5)); |
|
|
|
UILabel detailDesc = new UILabel(Toolkit.i18nText("Fine-Design_Problem_Detail_Message")); |
|
centerPane.add(detailDesc, BorderLayout.NORTH); |
|
|
|
JPanel detailPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
detailPanel.setBorder(BorderFactory.createEmptyBorder(0, 20, 10, 10)); |
|
detailPanel.setLayout(new BorderLayout(0, 8)); |
|
|
|
for (DetectorResult result : results) { |
|
JPanel detailItemPanel = FRGUIPaneFactory.createBorderLayout_L_Pane(); |
|
detailItemPanel.setLayout(new BorderLayout(0, 8)); |
|
ExceptionTips tips = result.getTips(); |
|
|
|
UILabel template = new UILabel(); |
|
template.setBackground(Color.white); |
|
|
|
if (tips != null) { |
|
Message tipsMsg = tips.getMessage(); |
|
detailItemPanel.add(DetectorUtil.convert2TextComponent(tipsMsg, template), BorderLayout.NORTH); |
|
} |
|
ExceptionSolution solution = result.getSolution(); |
|
if (solution != null) { |
|
Message solutionMsg = solution.getMessage(); |
|
detailItemPanel.add(DetectorUtil.convert2TextComponent(solutionMsg, template), BorderLayout.CENTER); |
|
} |
|
detailPanel.add(detailItemPanel, BorderLayout.CENTER); |
|
} |
|
|
|
JScrollPane detailPanelWrapper = new JScrollPane(detailPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); |
|
ColorUtils.syncBackground(detailPanelWrapper, Color.WHITE); |
|
centerPane.add(detailPanelWrapper, BorderLayout.CENTER); |
|
|
|
JPanel southPane = FRGUIPaneFactory.createBorderLayout_L_Pane(); |
|
JPanel controlPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
JPanel buttonPane = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 0)); |
|
okButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Ok")); |
|
okButton.addActionListener(new ActionListener() { |
|
@Override |
|
public void actionPerformed(ActionEvent e) { |
|
okEvent(); |
|
} |
|
}); |
|
buttonPane.add(okButton); |
|
restartButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Restart")); |
|
restartButton.addActionListener(new ActionListener() { |
|
@Override |
|
public void actionPerformed(ActionEvent e) { |
|
restartEvent(); |
|
} |
|
}); |
|
buttonPane.add(restartButton); |
|
controlPane.add(buttonPane, BorderLayout.EAST); |
|
southPane.add(controlPane); |
|
|
|
this.setTitle(Toolkit.i18nText("Fine-Design_Error_Start_Report")); |
|
this.setResizable(false); |
|
this.add(northPane, BorderLayout.NORTH); |
|
this.add(centerPane, BorderLayout.CENTER); |
|
this.add(southPane, BorderLayout.SOUTH); |
|
this.setSize(new Dimension(650, 500)); |
|
GUICoreUtils.centerWindow(this); |
|
|
|
} |
|
|
|
@Override |
|
public void actionPerformed(ActionEvent e) { |
|
dispose(); |
|
} |
|
|
|
protected void okEvent() { |
|
|
|
dispose(); |
|
DesignerExiter.getInstance().execute(); |
|
} |
|
|
|
protected void restartEvent() { |
|
|
|
dispose(); |
|
RestartHelper.restart(); |
|
} |
|
|
|
}
|
|
|