Browse Source

Merge branch 'feature/10.0' of https://cloud.finedevelop.com/scm/~wim.zhai/Xdesign into feature/10.0

research/11.0
Wim.Zhai 5 years ago
parent
commit
09fb6f5b66
  1. 188
      designer-base/src/main/java/com/fr/design/mainframe/loghandler/DesignerLogHandler.java

188
designer-base/src/main/java/com/fr/design/mainframe/loghandler/DesignerLogHandler.java

@ -4,6 +4,7 @@ import com.fr.base.BaseUtils;
import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.imenu.UIMenuItem; import com.fr.design.gui.imenu.UIMenuItem;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.ui.util.UIUtil;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.general.log.Log4jConfig; import com.fr.general.log.Log4jConfig;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
@ -41,66 +42,66 @@ import java.util.Date;
import static com.fr.design.gui.syntax.ui.rtextarea.RTADefaultInputMap.DEFAULT_MODIFIER; import static com.fr.design.gui.syntax.ui.rtextarea.RTADefaultInputMap.DEFAULT_MODIFIER;
public class DesignerLogHandler { public class DesignerLogHandler {
private final SimpleDateFormat LOG_SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private final SimpleDateFormat LOG_SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private static final int GAP_X = -150; private static final int GAP_X = -150;
private static final int INFO_GAP_Y = -60; private static final int INFO_GAP_Y = -60;
private static final int ERRO_GAP_Y = -40; private static final int ERRO_GAP_Y = -40;
private static final int SERVER_GAP_Y = -20; private static final int SERVER_GAP_Y = -20;
public static DesignerLogHandler getInstance() { public static DesignerLogHandler getInstance() {
return HOLDER.singleton; return HOLDER.singleton;
} }
private static class HOLDER { private static class HOLDER {
private static DesignerLogHandler singleton = new DesignerLogHandler(); private static DesignerLogHandler singleton = new DesignerLogHandler();
} }
// 所有的面板 // 所有的面板
private LogHandlerBar caption; private LogHandlerBar caption;
private JCheckBoxMenuItem showInfo; private JCheckBoxMenuItem showInfo;
private JCheckBoxMenuItem showError; private JCheckBoxMenuItem showError;
private JCheckBoxMenuItem showServer; private JCheckBoxMenuItem showServer;
private LogHandlerArea logHandlerArea; private LogHandlerArea logHandlerArea;
public DesignerLogHandler() { public DesignerLogHandler() {
logHandlerArea = new LogHandlerArea(); logHandlerArea = new LogHandlerArea();
caption = new LogHandlerBar(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Log")); caption = new LogHandlerBar(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Log"));
caption.addClearListener(new ActionListener() { caption.addClearListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
logHandlerArea.jTextArea.setText(""); logHandlerArea.jTextArea.setText("");
caption.clearMessage(); caption.clearMessage();
} }
}); });
caption.addSelectedListener(new ActionListener() { caption.addSelectedListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
logHandlerArea.jTextArea.requestFocus(); logHandlerArea.jTextArea.requestFocus();
logHandlerArea.jTextArea.selectAll(); logHandlerArea.jTextArea.selectAll();
} }
}); });
ItemListener itemlistener = new ItemListener() { ItemListener itemlistener = new ItemListener() {
@Override @Override
public void itemStateChanged(ItemEvent e) { public void itemStateChanged(ItemEvent e) {
logHandlerArea.jTextArea.setText(""); logHandlerArea.jTextArea.setText("");
caption.clearMessage(); caption.clearMessage();
} }
@ -112,12 +113,12 @@ public class DesignerLogHandler {
showServer = new JCheckBoxMenuItem(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Log_Level_Error"), true); showServer = new JCheckBoxMenuItem(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Log_Level_Error"), true);
showServer.addItemListener(itemlistener); showServer.addItemListener(itemlistener);
caption.addSetListener(new ActionListener() { caption.addSetListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
JPopupMenu jPopupMenu = new JPopupMenu(); JPopupMenu jPopupMenu = new JPopupMenu();
int logLevelInt = Log4jConfig.getInstance().getRootLevel().toInt(); int logLevelInt = Log4jConfig.getInstance().getRootLevel().toInt();
if (logLevelInt <= DesignerLogger.INFO_INT) { if (logLevelInt <= DesignerLogger.INFO_INT) {
jPopupMenu.add(showInfo); jPopupMenu.add(showInfo);
@ -135,72 +136,73 @@ public class DesignerLogHandler {
} }
}); });
} }
public JComponent getLogHandlerArea() { public JComponent getLogHandlerArea() {
return logHandlerArea; return logHandlerArea;
} }
public JComponent getCaption() { public JComponent getCaption() {
return caption; return caption;
} }
public void printRemoteLog(String message, Level level, Date date) { public void printRemoteLog(String message, Level level, Date date) {
logHandlerArea.printStackTrace(message, level, date); logHandlerArea.printStackTrace(message, level, date);
} }
private class LogHandlerArea extends JPanel { private class LogHandlerArea extends JPanel {
private static final long serialVersionUID = 8215630927304621660L; private static final long serialVersionUID = 8215630927304621660L;
private JTextPane jTextArea; private JTextPane jTextArea;
private JPopupMenu popup; private JPopupMenu popup;
private UIMenuItem selectAll; private UIMenuItem selectAll;
private UIMenuItem copy; private UIMenuItem copy;
private UIMenuItem clear; private UIMenuItem clear;
private LogHandlerArea() { private LogHandlerArea() {
jTextArea = initLogJTextArea(); jTextArea = initLogJTextArea();
this.setLayout(FRGUIPaneFactory.createBorderLayout()); this.setLayout(FRGUIPaneFactory.createBorderLayout());
UIScrollPane js = new UIScrollPane(jTextArea); UIScrollPane js = new UIScrollPane(jTextArea);
this.add(js, BorderLayout.CENTER); this.add(js, BorderLayout.CENTER);
this.setPreferredSize(new Dimension(super.getPreferredSize().width, 150)); this.setPreferredSize(new Dimension(super.getPreferredSize().width, 150));
jTextArea.setEditable(false); jTextArea.setEditable(false);
jTextArea.setBackground(Color.WHITE); jTextArea.setBackground(Color.WHITE);
popup = new JPopupMenu(); popup = new JPopupMenu();
selectAll = new UIMenuItem(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Select_All")); selectAll = new UIMenuItem(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Select_All"));
selectAll.addActionListener(popupListener); selectAll.addActionListener(popupListener);
selectAll.setIcon(BaseUtils.readIcon("/com/fr/design/images/log/selectedall.png")); selectAll.setIcon(BaseUtils.readIcon("/com/fr/design/images/log/selectedall.png"));
popup.add(selectAll); popup.add(selectAll);
copy = new UIMenuItem(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Copy")); copy = new UIMenuItem(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Copy"));
copy.addActionListener(popupListener); copy.addActionListener(popupListener);
copy.setIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/copy.png")); copy.setIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/copy.png"));
popup.add(copy); popup.add(copy);
clear = new UIMenuItem(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Clear_All")); clear = new UIMenuItem(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Clear_All"));
clear.addActionListener(popupListener); clear.addActionListener(popupListener);
clear.setIcon(BaseUtils.readIcon("/com/fr/design/images/log/clear.png")); clear.setIcon(BaseUtils.readIcon("/com/fr/design/images/log/clear.png"));
popup.add(clear); popup.add(clear);
selectAll.setAccelerator(KeyStroke.getKeyStroke('A', DEFAULT_MODIFIER)); selectAll.setAccelerator(KeyStroke.getKeyStroke('A', DEFAULT_MODIFIER));
copy.setAccelerator(KeyStroke.getKeyStroke('C', DEFAULT_MODIFIER)); copy.setAccelerator(KeyStroke.getKeyStroke('C', DEFAULT_MODIFIER));
clear.setAccelerator(KeyStroke.getKeyStroke('L', DEFAULT_MODIFIER)); clear.setAccelerator(KeyStroke.getKeyStroke('L', DEFAULT_MODIFIER));
jTextArea.addMouseListener(new MouseAdapter() { jTextArea.addMouseListener(new MouseAdapter() {
// check for right click // check for right click
@Override
public void mousePressed(MouseEvent event) { public void mousePressed(MouseEvent event) {
if (event.getButton() == MouseEvent.BUTTON3) { if (event.getButton() == MouseEvent.BUTTON3) {
popup.show(jTextArea, event.getX(), event.getY()); popup.show(jTextArea, event.getX(), event.getY());
checkEnabled(); checkEnabled();
@ -208,9 +210,9 @@ public class DesignerLogHandler {
} }
}); });
} }
private JTextPane initLogJTextArea() { private JTextPane initLogJTextArea() {
final JTextPane resultPane = new JTextPane(); final JTextPane resultPane = new JTextPane();
InputMap inputMap = resultPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); InputMap inputMap = resultPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, DEFAULT_MODIFIER), DefaultEditorKit.copyAction); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, DEFAULT_MODIFIER), DefaultEditorKit.copyAction);
@ -218,18 +220,19 @@ public class DesignerLogHandler {
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_L, DEFAULT_MODIFIER), "clear"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_L, DEFAULT_MODIFIER), "clear");
ActionMap actionMap = resultPane.getActionMap(); ActionMap actionMap = resultPane.getActionMap();
actionMap.put("clear", new AbstractAction() { actionMap.put("clear", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
resultPane.setText(""); resultPane.setText("");
caption.clearMessage(); caption.clearMessage();
} }
}); });
return resultPane; return resultPane;
} }
public void printStackTrace(LoggingEvent event) { public void printStackTrace(LoggingEvent event) {
int intLevel = event.getLevel().toInt(); int intLevel = event.getLevel().toInt();
Date date = new Date(event.getTimeStamp()); Date date = new Date(event.getTimeStamp());
ThrowableInformation information = event.getThrowableInformation(); ThrowableInformation information = event.getThrowableInformation();
@ -241,9 +244,9 @@ public class DesignerLogHandler {
printMessage(event.getRenderedMessage(), intLevel, date, information == null ? null : information.getThrowable()); printMessage(event.getRenderedMessage(), intLevel, date, information == null ? null : information.getThrowable());
} }
} }
public void printStackTrace(String message, Level level, Date date) { public void printStackTrace(String message, Level level, Date date) {
int intLevel = level.toInt(); int intLevel = level.toInt();
if (intLevel == DesignerLogger.INFO_INT && showInfo.isSelected()) { if (intLevel == DesignerLogger.INFO_INT && showInfo.isSelected()) {
printMessage(message, intLevel, date); printMessage(message, intLevel, date);
@ -252,32 +255,36 @@ public class DesignerLogHandler {
} else if (intLevel == DesignerLogger.WARN_INT && showServer.isSelected()) { } else if (intLevel == DesignerLogger.WARN_INT && showServer.isSelected()) {
printMessage(message, intLevel, date); printMessage(message, intLevel, date);
} }
} }
private void printMessage(String message, int intLevel, Date date) { private void printMessage(String message, int intLevel, Date date) {
printMessage(message, intLevel, date, null); printMessage(message, intLevel, date, null);
} }
private void printMessage(String msg, int intLevel, Date date, Throwable e) { private void printMessage(final String msg, final int intLevel, final Date date, final Throwable e) {
UIUtil.invokeLaterIfNeeded(new Runnable() {
this.log(LOG_SIMPLE_DATE_FORMAT.format(date) + "\n", 0); @Override
String message = appendLocaleMark(msg, intLevel); public void run() {
this.log(message, intLevel); LogHandlerArea.this.log(LOG_SIMPLE_DATE_FORMAT.format(date) + "\n", 0);
setMessage(message, intLevel); String message = appendLocaleMark(msg, intLevel);
if (e == null) { LogHandlerArea.this.log(message, intLevel);
return; setMessage(message, intLevel);
} if (e == null) {
return;
StackTraceElement[] traceElements = e.getStackTrace(); }
for (int i = 0; i < traceElements.length; i++) {
this.log("\t" + "at " + traceElements[i].toString() + "\n", 0); StackTraceElement[] traceElements = e.getStackTrace();
} for (StackTraceElement traceElement : traceElements) {
LogHandlerArea.this.log("\t" + "at " + traceElement.toString() + "\n", 0);
}
}
});
} }
private void log(String str, int style) { private void log(String str, int style) {
SimpleAttributeSet attrSet = new SimpleAttributeSet(); SimpleAttributeSet attrSet = new SimpleAttributeSet();
if (style == DesignerLogger.ERROR_INT) { if (style == DesignerLogger.ERROR_INT) {
StyleConstants.setForeground(attrSet, new Color(247, 148, 29)); StyleConstants.setForeground(attrSet, new Color(247, 148, 29));
@ -299,9 +306,9 @@ public class DesignerLogHandler {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }
} }
private String appendLocaleMark(String str, int style) { private String appendLocaleMark(String str, int style) {
if (style == DesignerLogger.ERROR_INT) { if (style == DesignerLogger.ERROR_INT) {
str = com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Alert") + ":" + str + "\n"; str = com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Alert") + ":" + str + "\n";
} else if (style == DesignerLogger.WARN_INT) { } else if (style == DesignerLogger.WARN_INT) {
@ -311,9 +318,9 @@ public class DesignerLogHandler {
} }
return str; return str;
} }
private void setMessage(String message, int level) { private void setMessage(String message, int level) {
LogMessageBar.getInstance().setMessage(message); LogMessageBar.getInstance().setMessage(message);
if (level == DesignerLogger.INFO_INT && showInfo.isSelected()) { if (level == DesignerLogger.INFO_INT && showInfo.isSelected()) {
caption.infoAdd(); caption.infoAdd();
@ -323,31 +330,32 @@ public class DesignerLogHandler {
caption.serverAdd(); caption.serverAdd();
} }
} }
private void checkEnabled() { private void checkEnabled() {
this.selectAll.setEnabled(true); this.selectAll.setEnabled(true);
this.copy.setEnabled(true); this.copy.setEnabled(true);
this.clear.setEnabled(true); this.clear.setEnabled(true);
if (ComparatorUtils.equals(this.jTextArea.getText(), "")) { if (ComparatorUtils.equals(this.jTextArea.getText(), "")) {
this.selectAll.setEnabled(false); this.selectAll.setEnabled(false);
this.clear.setEnabled(false); this.clear.setEnabled(false);
} }
if (ComparatorUtils.equals(this.jTextArea.getSelectionStart(), this.jTextArea.getSelectionEnd())) { if (ComparatorUtils.equals(this.jTextArea.getSelectionStart(), this.jTextArea.getSelectionEnd())) {
this.copy.setEnabled(false); this.copy.setEnabled(false);
} }
if (this.jTextArea.getSelectionStart() == 0 && ComparatorUtils.equals(this.jTextArea.getSelectionEnd(), this.jTextArea.getText().length())) { if (this.jTextArea.getSelectionStart() == 0 && ComparatorUtils.equals(this.jTextArea.getSelectionEnd(), this.jTextArea.getText().length())) {
this.selectAll.setEnabled(false); this.selectAll.setEnabled(false);
} }
} }
ActionListener popupListener = new ActionListener() { ActionListener popupListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
if (ComparatorUtils.equals(evt.getActionCommand(), LogHandlerArea.this.selectAll.getText())) { if (ComparatorUtils.equals(evt.getActionCommand(), LogHandlerArea.this.selectAll.getText())) {
LogHandlerArea.this.jTextArea.selectAll(); LogHandlerArea.this.jTextArea.selectAll();
} else if (ComparatorUtils.equals(evt.getActionCommand(), LogHandlerArea.this.copy.getText())) { } else if (ComparatorUtils.equals(evt.getActionCommand(), LogHandlerArea.this.copy.getText())) {
@ -358,6 +366,6 @@ public class DesignerLogHandler {
} }
} }
}; };
} }
} }

Loading…
Cancel
Save