Browse Source

feat: REPORT-70565 设计器环境监测(jar包异常、finedb、杀毒软件)

1-优化 UI 部分的代码质量
2-抽象部分公共类
feature/x
Harrison 3 years ago
parent
commit
4f0fe26f5c
  1. 9
      designer-base/src/main/java/com/fr/design/components/notification/NotificationDialog.java
  2. 4
      designer-base/src/main/java/com/fr/design/components/notification/NotificationMessage.java
  3. 8
      designer-base/src/main/java/com/fr/design/components/table/TablePanel.java
  4. 39
      designer-base/src/main/java/com/fr/design/dialog/link/MessageWithLink.java
  5. 30
      designer-base/src/main/java/com/fr/design/utils/ColorUtils.java
  6. 49
      designer-base/src/main/java/com/fr/design/utils/DevUtil.java
  7. 73
      designer-base/src/main/java/com/fr/design/utils/DevUtils.java
  8. 2
      designer-base/src/main/java/com/fr/design/utils/LinkStrUtils.java

9
designer-base/src/main/java/com/fr/design/components/notification/NotificationDialog.java

@ -9,6 +9,8 @@ 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.layout.VerticalFlowLayout;
import com.fr.env.detect.base.ExceptionDetectorConfig;
import javax.swing.BorderFactory;
import javax.swing.Icon;
@ -22,7 +24,6 @@ import java.awt.Color;
import java.awt.Container;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
@ -149,8 +150,7 @@ public class NotificationDialog extends JDialog {
.collect(Collectors.toList());
// 竖向排列
JPanel messageSummaryPanel = new JPanel();
messageSummaryPanel.setLayout(new GridLayout(messageComponents.size(), 1));
JPanel messageSummaryPanel = FRGUIPaneFactory.createVerticalFlowLayout_Pane(true, VerticalFlowLayout.TOP, 0, 0);
messageComponents.forEach(messageSummaryPanel::add);
JPanel centerPanel = FRGUIPaneFactory.createBorderLayout_L_Pane();
@ -210,7 +210,8 @@ public class NotificationDialog extends JDialog {
notReminder.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// todo
// 配置处理
ExceptionDetectorConfig.getInstance().setOpen(false);
// 点击事件
destroy();
}

4
designer-base/src/main/java/com/fr/design/components/notification/NotificationMessage.java

@ -1,6 +1,6 @@
package com.fr.design.components.notification;
import com.fr.design.utils.LinkStrUtil;
import com.fr.design.utils.LinkStrUtils;
/**
* created by Harrison on 2022/05/24
@ -76,7 +76,7 @@ public interface NotificationMessage {
@Override
public String format() {
return LinkStrUtil.generateHtmlTag(text);
return LinkStrUtils.generateHtmlTag(text);
}
@Override

8
designer-base/src/main/java/com/fr/design/components/table/TablePanel.java

@ -2,6 +2,7 @@ package com.fr.design.components.table;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.utils.ColorUtils;
import com.fr.third.org.apache.commons.lang3.ArrayUtils;
import javax.swing.BorderFactory;
@ -152,6 +153,8 @@ public class TablePanel extends JPanel {
int x = row - 1;
int y = column - 1;
syncCellColor(row, component);
JPanel cellPanel = this.cellPanels[x][y];
if (ArrayUtils.getLength(cellPanel.getComponents()) == 1) {
cellPanel.remove(0);
@ -167,13 +170,14 @@ public class TablePanel extends JPanel {
}
private void syncHeaderColor(Component component) {
component.setBackground(DEFAULT_HEADER_COLOR);
ColorUtils.syncBackground(component, DEFAULT_HEADER_COLOR);
}
private void syncCellColor(int row, Component component) {
Color rowColor = getRowColorByRowNumber(row);
ColorUtils.syncBackground(component, rowColor);
component.setBackground(rowColor);
}

39
designer-base/src/main/java/com/fr/design/dialog/link/MessageWithLink.java

@ -1,18 +1,18 @@
package com.fr.design.dialog.link;
import com.fr.design.utils.LinkStrUtil;
import com.fr.design.utils.LinkStrUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils;
import javax.swing.JEditorPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.Font;
import java.net.URI;
import java.net.URL;
import static com.fr.design.utils.LinkStrUtil.LABEL;
import static com.fr.design.utils.LinkStrUtils.LABEL;
/**
* 用来构建JOptionPane带超链的消息提示
@ -22,6 +22,14 @@ import static com.fr.design.utils.LinkStrUtil.LABEL;
* Created by hades on 2020/10/23
*/
public class MessageWithLink extends JEditorPane {
public MessageWithLink(String htmlText) {
super("text/html", htmlText);
setEditable(false);
setBorder(null);
}
public MessageWithLink(String htmlText, Runnable action) {
@ -57,20 +65,31 @@ public class MessageWithLink extends JEditorPane {
public MessageWithLink(String frontMessage, String linkName, String link, String backMessage, Color backgroundColor, Font font, Color fontColor) {
super("text/html", "<html><body style=\"" + LinkStrUtil.generateStyle(backgroundColor, font, fontColor) + "\">" + frontMessage + "<a href=\"" + link + "\">" + linkName + "</a>" + backMessage + "</body></html>");
super("text/html", "<html><body style=\"" + LinkStrUtils.generateStyle(backgroundColor, font, fontColor) + "\">" + frontMessage + "<a href=\"" + link + "\">" + linkName + "</a>" + backMessage + "</body></html>");
initListener(link);
setEditable(false);
setBorder(null);
}
public void initListener() {
addHyperlinkListener(hyperlinkEvent -> {
try {
if (hyperlinkEvent.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
URL url = hyperlinkEvent.getURL();
Desktop.getDesktop().browse(url.toURI());
}
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
});
}
public void initListener(Runnable runnable) {
addHyperlinkListener(new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
runnable.run();
}
addHyperlinkListener(e -> {
if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
runnable.run();
}
});
}

30
designer-base/src/main/java/com/fr/design/utils/ColorUtils.java

@ -0,0 +1,30 @@
package com.fr.design.utils;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.util.Arrays;
/**
* created by Harrison on 2022/05/29
**/
public class ColorUtils {
/**
* 递归的同步颜色
*
* @param color 颜色
*/
public static void syncBackground(Component component, Color color) {
component.setBackground(color);
if (component instanceof Container) {
Container container = (Container) component;
Component[] components = container.getComponents();
if (components != null) {
Arrays.stream(components).forEach((e) -> syncBackground(e, color));
}
}
}
}

49
designer-base/src/main/java/com/fr/design/utils/DevUtil.java

@ -1,49 +0,0 @@
package com.fr.design.utils;
import com.fr.design.ui.util.UIUtil;
import com.fr.env.detect.ui.EnvDetectorDialog;
import javax.swing.JFrame;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Toolkit;
import java.util.function.Consumer;
/**
* 设计器的开发时工具
* 帮助进行 UI 页面的调试
*
* created by Harrison on 2022/05/23
**/
public class DevUtil {
public static void show(Consumer<Frame> consumer) {
DesignUtils.initLookAndFeel();
UIUtil.invokeLaterIfNeeded(() -> {
JFrame frame = new JFrame("dev-util");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
frame.setSize(dimension);
consumer.accept(frame);
frame.setVisible(true);
});
}
public static void main(String[] args) {
DevUtil.show(new Consumer<Frame>() {
@Override
public void accept(Frame frame) {
EnvDetectorDialog envDetectorDialog = new EnvDetectorDialog(frame);
envDetectorDialog.setVisible(true);
}
});
}
}

73
designer-base/src/main/java/com/fr/design/utils/DevUtils.java

@ -0,0 +1,73 @@
package com.fr.design.utils;
import com.fr.config.dao.DaoContext;
import com.fr.config.dao.impl.LocalClassHelperDao;
import com.fr.config.dao.impl.LocalEntityDao;
import com.fr.config.dao.impl.LocalXmlEntityDao;
import com.fr.design.ui.util.UIUtil;
import com.fr.env.detect.bean.DetectorResult;
import com.fr.env.detect.bean.DetectorType;
import com.fr.env.detect.bean.ExceptionLog;
import com.fr.env.detect.bean.ExceptionSolution;
import com.fr.env.detect.bean.ExceptionTips;
import com.fr.env.detect.ui.DetectorErrorDialog;
import com.fr.third.guava.collect.Lists;
import com.fr.transaction.Configurations;
import com.fr.transaction.LocalConfigurationHelper;
import javax.swing.JFrame;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Toolkit;
import java.util.function.Consumer;
/**
* 设计器的开发时工具
* 帮助进行 UI 页面的调试
* <p>
* created by Harrison on 2022/05/23
**/
public class DevUtils {
private static void prepare() {
DaoContext.setEntityDao(new LocalEntityDao());
DaoContext.setClassHelperDao(new LocalClassHelperDao());
DaoContext.setXmlEntityDao(new LocalXmlEntityDao());
Configurations.setHelper(new LocalConfigurationHelper());
}
public static void show(Consumer<Frame> consumer) {
DesignUtils.initLookAndFeel();
UIUtil.invokeLaterIfNeeded(() -> {
JFrame frame = new JFrame("dev-util");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
frame.setSize(dimension);
consumer.accept(frame);
frame.setVisible(true);
});
}
public static void main(String[] args) {
DevUtils.prepare();
DevUtils.show(new Consumer<Frame>() {
@Override
public void accept(Frame frame) {
DetectorErrorDialog dialog = new DetectorErrorDialog(frame, Lists.newArrayList(DetectorResult.exception(DetectorType.FINE_DB_PERMISSION,
ExceptionTips.create("test"),
ExceptionSolution.create("111<a href=\"\">test</a>222", "www.baidu.com", null),
ExceptionLog.create("log"))));
dialog.setVisible(true);
}
});
}
}

2
designer-base/src/main/java/com/fr/design/utils/LinkStrUtil.java → designer-base/src/main/java/com/fr/design/utils/LinkStrUtils.java

@ -9,7 +9,7 @@ import java.awt.Font;
/**
* created by Harrison on 2022/05/24
**/
public class LinkStrUtil {
public class LinkStrUtils {
public static final UILabel LABEL = new UILabel();
Loading…
Cancel
Save