Browse Source

Merge remote-tracking branch 'origin/feature/10.0' into feature/10.0

research/11.0
Bryant 5 years ago
parent
commit
fa09775565
  1. 19
      designer-base/src/main/java/com/fr/design/gui/ispinner/UISpinner.java
  2. 28
      designer-base/src/main/java/com/fr/design/gui/ispinner/UnsignedIntUISpinner.java
  3. 107
      designer-base/src/main/java/com/fr/design/report/WatermarkPane.java
  4. 8
      designer-chart/src/main/java/com/fr/design/ChartTypeInterfaceManager.java
  5. 2
      designer-chart/src/main/java/com/fr/design/chart/ChartTypePane.java
  6. 12
      designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/ChartTypePane.java
  7. 2
      designer-chart/src/main/java/com/fr/extended/chart/ExtendedTypePane.java
  8. 7
      designer-chart/src/main/java/com/fr/van/chart/heatmap/designer/HeatMapIndependentVanChartInterface.java
  9. 644
      designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java
  10. 9
      designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/StartupMessageCollector.java

19
designer-base/src/main/java/com/fr/design/gui/ispinner/UISpinner.java

@ -39,6 +39,7 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver
private String spinnerName = StringUtils.EMPTY; private String spinnerName = StringUtils.EMPTY;
private UIObserverListener uiObserverListener; private UIObserverListener uiObserverListener;
private GlobalNameListener globalNameListener = null; private GlobalNameListener globalNameListener = null;
private boolean lessMinValue = false;
public UISpinner(double minValue, double maxValue, double dierta) { public UISpinner(double minValue, double maxValue, double dierta) {
@ -93,6 +94,18 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver
return textField; return textField;
} }
public UIButton getNextButton() {
return nextButton;
}
public boolean isLessMinValue() {
return lessMinValue;
}
public void resetLessMinValue() {
lessMinValue = false;
}
public void setValue(double value) { public void setValue(double value) {
setValue(value, true); setValue(value, true);
} }
@ -109,7 +122,8 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver
if (globalNameListener != null && shouldResponseNameListener()) { if (globalNameListener != null && shouldResponseNameListener()) {
globalNameListener.setGlobalName(spinnerName); globalNameListener.setGlobalName(spinnerName);
} }
value = value < minValue ? minValue : value; lessMinValue = value < minValue;
value = lessMinValue ? minValue : value;
value = value > maxValue ? maxValue : value; value = value > maxValue ? maxValue : value;
if (CommonUtils.equals(value, this.value)) { if (CommonUtils.equals(value, this.value)) {
return; return;
@ -131,7 +145,8 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver
if (globalNameListener != null && shouldResponseNameListener()) { if (globalNameListener != null && shouldResponseNameListener()) {
globalNameListener.setGlobalName(spinnerName); globalNameListener.setGlobalName(spinnerName);
} }
value = value < minValue ? minValue : value; lessMinValue = value < minValue;
value = lessMinValue ? minValue : value;
value = value > maxValue ? maxValue : value; value = value > maxValue ? maxValue : value;
if (CommonUtils.equals(value, this.value)) { if (CommonUtils.equals(value, this.value)) {

28
designer-base/src/main/java/com/fr/design/gui/ispinner/UnsignedIntUISpinner.java

@ -3,8 +3,6 @@ package com.fr.design.gui.ispinner;
import com.fr.design.gui.itextfield.UIIntNumberField; import com.fr.design.gui.itextfield.UIIntNumberField;
import com.fr.design.gui.itextfield.UINumberField; import com.fr.design.gui.itextfield.UINumberField;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
/** /**
* Created by IntelliJ IDEA. * Created by IntelliJ IDEA.
@ -31,7 +29,7 @@ public class UnsignedIntUISpinner extends UISpinner {
@Override @Override
protected UINumberField initNumberField() { protected UINumberField initNumberField() {
final UIIntNumberField numberField = new UIIntNumberField() { return new UIIntNumberField() {
public boolean shouldResponseChangeListener() { public boolean shouldResponseChangeListener() {
return false; return false;
} }
@ -44,29 +42,5 @@ public class UnsignedIntUISpinner extends UISpinner {
}; };
} }
}; };
numberField.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
}
/**
* 失去焦点后再做范围限制不然最小值为 100 输个 1 都不让....
* @param e
*/
@Override
public void focusLost(FocusEvent e) {
double value = numberField.getValue();
if (!isOverMaxOrMinValue(value)) {
return;
}
numberField.setValue(value < minValue ? minValue : maxValue);
}
private boolean isOverMaxOrMinValue(double value) {
return value < minValue || value > maxValue;
}
});
return numberField;
} }
} }

107
designer-base/src/main/java/com/fr/design/report/WatermarkPane.java

@ -23,6 +23,9 @@ import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener; import javax.swing.event.DocumentListener;
import javax.swing.JDialog;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color; import java.awt.Color;
@ -30,6 +33,13 @@ import java.awt.event.FocusEvent;
import java.awt.event.FocusListener; import java.awt.event.FocusListener;
import java.awt.event.ItemEvent; import java.awt.event.ItemEvent;
import java.awt.event.ItemListener; import java.awt.event.ItemListener;
import java.awt.event.MouseListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.FocusAdapter;
import java.awt.Dialog;
import java.awt.FlowLayout;
/** /**
* Created by plough on 2018/5/15. * Created by plough on 2018/5/15.
@ -49,6 +59,13 @@ public class WatermarkPane extends BasicPane {
private UISpinner verticalGapSpinner; private UISpinner verticalGapSpinner;
// 文字颜色 // 文字颜色
private NewColorSelectPane colorPane; private NewColorSelectPane colorPane;
//间距超过限制消息
private UILabel message;
//横向间距最小值
public static final int HORIZONTAL_GAP_MIX = 100;
//纵向间距最小值
public static final int VERTICAL_GAP_MIX = 50;
private static final Dimension SPINNER_DIMENSION = new Dimension(75, 20); private static final Dimension SPINNER_DIMENSION = new Dimension(75, 20);
@ -57,6 +74,7 @@ public class WatermarkPane extends BasicPane {
} }
private void initComponents() { private void initComponents() {
message = new UILabel();
this.setBorder(BorderFactory.createEmptyBorder(4, 4, -5, 4)); this.setBorder(BorderFactory.createEmptyBorder(4, 4, -5, 4));
this.setLayout(FRGUIPaneFactory.createBorderLayout()); this.setLayout(FRGUIPaneFactory.createBorderLayout());
@ -93,7 +111,7 @@ public class WatermarkPane extends BasicPane {
public WatermarkAttr update() { public WatermarkAttr update() {
WatermarkAttr watermark = new WatermarkAttr(); WatermarkAttr watermark = new WatermarkAttr();
watermark.setText(formulaPane.getUITextField().getText()); watermark.setText(formulaPane.getUITextField().getText());
watermark.setFontSize((int)fontSizeComboBox.getSelectedItem()); watermark.setFontSize((int) fontSizeComboBox.getSelectedItem());
watermark.setHorizontalGap((int) horizontalGapSpinner.getValue()); watermark.setHorizontalGap((int) horizontalGapSpinner.getValue());
watermark.setVerticalGap((int) verticalGapSpinner.getValue()); watermark.setVerticalGap((int) verticalGapSpinner.getValue());
watermark.setColor(colorPane.getColor()); watermark.setColor(colorPane.getColor());
@ -109,7 +127,7 @@ public class WatermarkPane extends BasicPane {
this.formulaPane = formulaPane; this.formulaPane = formulaPane;
} }
protected UIScrollPane initRightPane(){ protected UIScrollPane initRightPane() {
formulaPane = new TinyFormulaPane(); formulaPane = new TinyFormulaPane();
fontSizeComboBox = new UIComboBox(FRFontPane.FONT_SIZES); fontSizeComboBox = new UIComboBox(FRFontPane.FONT_SIZES);
fontSizeComboBox.setEditable(true); fontSizeComboBox.setEditable(true);
@ -117,7 +135,17 @@ public class WatermarkPane extends BasicPane {
verticalGapSpinner = new UnsignedIntUISpinner(50, Integer.MAX_VALUE, 1, 100); verticalGapSpinner = new UnsignedIntUISpinner(50, Integer.MAX_VALUE, 1, 100);
horizontalGapSpinner.setPreferredSize(SPINNER_DIMENSION); horizontalGapSpinner.setPreferredSize(SPINNER_DIMENSION);
verticalGapSpinner.setPreferredSize(SPINNER_DIMENSION); verticalGapSpinner.setPreferredSize(SPINNER_DIMENSION);
JPanel fontSizeTypePane = new JPanel(new BorderLayout(10,0)); message.setBorder(BorderFactory.createEmptyBorder(8, 5, 0, 0));
//失去焦点时要判断是否要弹出提示
horizontalGapSpinner.getTextField().addFocusListener(
createFocusListener4GapNumberField(horizontalGapSpinner, HORIZONTAL_GAP_MIX, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Horizontal_Gap_Over_Warning")));
verticalGapSpinner.getTextField().addFocusListener(createFocusListener4GapNumberField(verticalGapSpinner, VERTICAL_GAP_MIX, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Vertical_Gap_Over_Warning")));
//next 按钮 释放时也要判断是否要弹出提示
horizontalGapSpinner.getNextButton().addMouseListener(createMouseListener4GapNextButton(horizontalGapSpinner, HORIZONTAL_GAP_MIX, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Horizontal_Gap_Over_Warning")));
verticalGapSpinner.getNextButton().addMouseListener(createMouseListener4GapNextButton(verticalGapSpinner, VERTICAL_GAP_MIX, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Vertical_Gap_Over_Warning")));
JPanel fontSizeTypePane = new JPanel(new BorderLayout(10, 0));
fontSizeTypePane.add(fontSizeComboBox, BorderLayout.CENTER); fontSizeTypePane.add(fontSizeComboBox, BorderLayout.CENTER);
//水印间距面板 //水印间距面板
@ -144,18 +172,18 @@ public class WatermarkPane extends BasicPane {
JPanel rightContentPane = TableLayoutHelper.createCommonTableLayoutPane(new JComponent[][]{ JPanel rightContentPane = TableLayoutHelper.createCommonTableLayoutPane(new JComponent[][]{
{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Watermark_Text")), formulaPane}, {new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Watermark_Text")), formulaPane},
{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Font_Size")), fontSizeTypePane}, {new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Font_Size")), fontSizeTypePane},
{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Watermark_Gap")),watermarkGapPane }, {new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Watermark_Gap")), watermarkGapPane},
{null,watermarkGapTipsPane }, {null, watermarkGapTipsPane},
{colorLabelPane, colorPane}, {colorLabelPane, colorPane},
}, rowSize, columnSize, 10); }, rowSize, columnSize, 10);
rightContentPane.setBorder(BorderFactory.createEmptyBorder(15, 12, 10, 12)); rightContentPane.setBorder(BorderFactory.createEmptyBorder(15, 12, 10, 12));
UIScrollPane configPane = new UIScrollPane(rightContentPane); UIScrollPane configPane = new UIScrollPane(rightContentPane);
configPane.setBorder(GUICoreUtils.createTitledBorder(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Config"),null)); configPane.setBorder(GUICoreUtils.createTitledBorder(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Config"), null));
return configPane; return configPane;
} }
protected void populateFontSize(int fontSize){ protected void populateFontSize(int fontSize) {
this.fontSizeComboBox.setSelectedItem(fontSize); this.fontSizeComboBox.setSelectedItem(fontSize);
this.fontSizeComboBox.addItemListener(new ItemListener() { this.fontSizeComboBox.addItemListener(new ItemListener() {
@Override @Override
@ -165,7 +193,7 @@ public class WatermarkPane extends BasicPane {
}); });
} }
protected void populateWatermarkGap(WatermarkAttr watermark){ protected void populateWatermarkGap(WatermarkAttr watermark) {
this.horizontalGapSpinner.setValue(watermark.getHorizontalGap()); this.horizontalGapSpinner.setValue(watermark.getHorizontalGap());
this.horizontalGapSpinner.addUISpinnerFocusListenner(new FocusListener() { this.horizontalGapSpinner.addUISpinnerFocusListenner(new FocusListener() {
@ -195,7 +223,7 @@ public class WatermarkPane extends BasicPane {
}); });
} }
protected void paintPreviewPane(){ protected void paintPreviewPane() {
watermarkPreviewPane.repaint(update()); watermarkPreviewPane.repaint(update());
} }
@ -235,4 +263,65 @@ public class WatermarkPane extends BasicPane {
protected String title4PopupWindow() { protected String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_WaterMark"); return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_WaterMark");
} }
/**
* 创建水印间距文本段焦点监听器
*
* @return
*/
private FocusListener createFocusListener4GapNumberField(final UISpinner spinner, final int limitMinValue, final String messageStr) {
return new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
if (!spinner.isLessMinValue()) {
return;
}
spinner.resetLessMinValue();
createGapDialog(new StringBuilder(messageStr).append(limitMinValue).toString());
}
};
}
/**
* 创建水印间距微调器 NextButton 的鼠标释放监听器
*
* @param messageStr 提示消息
* @param limitMinValue 限制的最小值
* @return
*/
private MouseListener createMouseListener4GapNextButton(final UISpinner spinner, final int limitMinValue, final String messageStr) {
MouseAdapter mouseAdapter = new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
if (!spinner.isLessMinValue()) {
return;
}
spinner.resetLessMinValue();
createGapDialog(new StringBuilder(messageStr).append(limitMinValue).toString());
}
};
return mouseAdapter;
}
/**
* 创建超过水印间距限制的对话框
*
* @param messageStr 提示消息
*/
private void createGapDialog(String messageStr) {
JDialog dialog = new JDialog((Dialog) SwingUtilities.getWindowAncestor(WatermarkPane.this), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Joption_News"), true);
dialog.setSize(new Dimension(268, 118));
message.setText(messageStr);
JPanel upPane = new JPanel();
UILabel uiLabel = new UILabel(UIManager.getIcon("OptionPane.informationIcon"));
upPane.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10));
upPane.add(uiLabel);
upPane.add(message);
dialog.add(upPane);
dialog.setResizable(false);
dialog.setLocationRelativeTo(SwingUtilities.getWindowAncestor(WatermarkPane.this));
dialog.setVisible(true);
dialog.dispose();
}
} }

8
designer-chart/src/main/java/com/fr/design/ChartTypeInterfaceManager.java

@ -165,7 +165,7 @@ public class ChartTypeInterfaceManager implements ExtraChartDesignClassManagerPr
ChartWidgetOption[] child = new ChartWidgetOption[chartIDs.length]; ChartWidgetOption[] child = new ChartWidgetOption[chartIDs.length];
int index = 0; int index = 0;
for (String chartID : chartIDs) { for (String chartID : chartIDs) {
ChartProvider[] rowChart = ChartTypeManager.getInstance().getChartTypes(chartID); ChartProvider[] rowChart = ChartTypeManager.getInstance().getCharts(chartID);
if (ArrayUtils.isEmpty(rowChart) && !ChartTypeManager.innerChart(chartID)) { if (ArrayUtils.isEmpty(rowChart) && !ChartTypeManager.innerChart(chartID)) {
continue; continue;
} }
@ -364,7 +364,7 @@ public class ChartTypeInterfaceManager implements ExtraChartDesignClassManagerPr
try { try {
//兼容 图表类型选择界面会调到这边 //兼容 图表类型选择界面会调到这边
ChartProvider[] charts = ChartTypeManager.getInstanceWithCheck().getChartTypes(chartID); ChartProvider[] charts = ChartTypeManager.getInstanceWithCheck().getCharts(chartID);
result = new String[charts.length]; result = new String[charts.length];
for (int i = 0; i < charts.length; i++) { for (int i = 0; i < charts.length; i++) {
//Chart && AbstractChart //Chart && AbstractChart
@ -403,7 +403,7 @@ public class ChartTypeInterfaceManager implements ExtraChartDesignClassManagerPr
//兼容 //兼容
private String[] getCompatibleSubName(String chartID, ChartTypeUIProvider provider) { private String[] getCompatibleSubName(String chartID, ChartTypeUIProvider provider) {
ChartProvider[] chartProviders = ChartTypeManager.getInstanceWithCheck().getChartTypes(chartID); ChartProvider[] chartProviders = ChartTypeManager.getInstanceWithCheck().getCharts(chartID);
if (chartProviders.length == 1) { if (chartProviders.length == 1) {
return new String[]{getName(chartID)}; return new String[]{getName(chartID)};
@ -453,7 +453,7 @@ public class ChartTypeInterfaceManager implements ExtraChartDesignClassManagerPr
try { try {
ChartProvider chartProvider = ChartTypeManager.getInstanceWithCheck().getChartTypes(chartID)[0]; ChartProvider chartProvider = ChartTypeManager.getInstanceWithCheck().getCharts(chartID)[0];
if (chartProvider instanceof Chart) { if (chartProvider instanceof Chart) {
//AbstractExtendedChartUIProvider //AbstractExtendedChartUIProvider
result = ((Chart) chartProvider).getChartName(); result = ((Chart) chartProvider).getChartName();

2
designer-chart/src/main/java/com/fr/design/chart/ChartTypePane.java

@ -126,7 +126,7 @@ public class ChartTypePane extends ChartCommonWizardPane {
ChartProvider chart4Update = cc.getSelectedChartProvider(); ChartProvider chart4Update = cc.getSelectedChartProvider();
if (chart4Update == null) { if (chart4Update == null) {
String plotID = this.chartIDs[mainTypeList.getSelectedIndex()]; String plotID = this.chartIDs[mainTypeList.getSelectedIndex()];
ChartProvider chart = ChartTypeManager.getInstance().getChartTypes(plotID)[iconViewList.getSelectedIndex()]; ChartProvider chart = ChartTypeManager.getInstance().getCharts(plotID)[iconViewList.getSelectedIndex()];
try { try {
chart4Update = (ChartProvider) chart.clone(); chart4Update = (ChartProvider) chart.clone();
cc.addChart(chart4Update); cc.addChart(chart4Update);

12
designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/ChartTypePane.java

@ -19,15 +19,15 @@ import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import javax.swing.JPanel; import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
/** /**
* 图表 属性表, 类型选择 界面. * 图表 属性表, 类型选择 界面.
@ -124,7 +124,8 @@ public class ChartTypePane extends AbstractChartAttrPane{
String lastPlotID = chart.getID(); String lastPlotID = chart.getID();
try{ try{
ChartProvider newDefaultChart = (ChartProvider) ((AbstractChartTypePane) getSelectedPane()).getDefaultChart().clone(); AbstractChartTypePane selectedPane = (AbstractChartTypePane) getSelectedPane();
ChartProvider newDefaultChart =(ChartProvider) ChartTypeManager.getInstanceWithCheck().getCharts(selectedPane.getPlotID())[0].clone();
if (!ComparatorUtils.equals(chart.getClass(), newDefaultChart.getClass())) { if (!ComparatorUtils.equals(chart.getClass(), newDefaultChart.getClass())) {
//vanChart 和 chart 之间切换 //vanChart 和 chart 之间切换
//不同chart之间切换 //不同chart之间切换
@ -135,7 +136,6 @@ public class ChartTypePane extends AbstractChartAttrPane{
}catch (CloneNotSupportedException e){ }catch (CloneNotSupportedException e){
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }
//这一步会替换plot //这一步会替换plot
((AbstractChartTypePane)getSelectedPane()).updateBean(chart); ((AbstractChartTypePane)getSelectedPane()).updateBean(chart);

2
designer-chart/src/main/java/com/fr/extended/chart/ExtendedTypePane.java

@ -67,7 +67,7 @@ public class ExtendedTypePane<T extends AbstractChart> extends AbstractChartType
@Override @Override
public ChartProvider getDefaultChart() { public ChartProvider getDefaultChart() {
return ChartTypeManager.getInstance().getChartTypes(getPlotID())[0]; return ChartTypeManager.getInstance().getCharts(getPlotID())[0];
} }
@Override @Override

7
designer-chart/src/main/java/com/fr/van/chart/heatmap/designer/HeatMapIndependentVanChartInterface.java

@ -38,6 +38,13 @@ public class HeatMapIndependentVanChartInterface extends MapIndependentVanChartI
return Toolkit.i18nText("Fine-Design_Chart_New_HeatMap"); return Toolkit.i18nText("Fine-Design_Chart_New_HeatMap");
} }
@Override
public String[] getSubName() {
return new String[]{
Toolkit.i18nText("Fine-Design_Chart_New_HeatMap"),
};
}
@Override @Override
public String[] getDemoImagePath() { public String[] getDemoImagePath() {
return new String[]{ return new String[]{

644
designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java

@ -30,6 +30,7 @@ import com.fr.stable.xml.XMLTools;
import com.fr.stable.xml.XMLWriter; import com.fr.stable.xml.XMLWriter;
import com.fr.stable.xml.XMLableReader; import com.fr.stable.xml.XMLableReader;
import com.fr.third.javax.xml.stream.XMLStreamException; import com.fr.third.javax.xml.stream.XMLStreamException;
import com.sun.management.OperatingSystemMXBean;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -43,11 +44,14 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.lang.management.ManagementFactory;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -58,309 +62,339 @@ import java.util.concurrent.TimeUnit;
*/ */
public class InformationCollector implements XMLReadable, XMLWriter { public class InformationCollector implements XMLReadable, XMLWriter {
// 24小时上传一次 /**
private static final long DELTA = 24 * 3600 * 1000L; * 24小时上传一次
private static final long SEND_DELAY = 300 * 1000L; */
private static final String FILE_NAME = "fr.info"; private static final long DELTA = 24 * 3600 * 1000L;
private static final String XML_START_STOP_LIST = "StartStopList"; private static final long SEND_DELAY = 300 * 1000L;
private static final String XML_START_STOP = "StartStop"; private static final int BYTE_TO_MB = 1024 * 1024;
private static final String XML_LAST_TIME = "LastTime"; private static final String FILE_NAME = "fr.info";
private static final String ATTR_START = "start"; private static final String XML_START_STOP_LIST = "StartStopList";
private static final String ATTR_STOP = "stop"; private static final String XML_START_STOP = "StartStop";
private static final String XML_JAR = "JarInfo"; private static final String XML_LAST_TIME = "LastTime";
private static final String XML_VERSION = "Version"; private static final String ATTR_START = "start";
private static final String XML_USERNAME = "Username"; private static final String ATTR_STOP = "stop";
private static final String XML_UUID = "UUID"; private static final String XML_JAR = "JarInfo";
private static final String XML_KEY = "ActiveKey"; private static final String XML_VERSION = "Version";
private static final String XML_OS = "OS"; private static final String XML_USERNAME = "Username";
private static final String XML_UUID = "UUID";
private static InformationCollector collector; private static final String XML_KEY = "ActiveKey";
private static final String XML_OS = "OS";
//启动时间与关闭时间列表 private static final String XML_ARCH = "arch";
private List<StartStopTime> startStop = new ArrayList<StartStopTime>(); private static final String XML_AVAILABLE_PROCESSORS = "cpu";
//上一次的发送时间 private static final String XML_PHYSICAL_MEMORY = "systemMemory";
private String lastTime;
private StartStopTime current = new StartStopTime(); private static InformationCollector collector;
public static InformationCollector getInstance() { /**
if (collector == null) { * 启动时间与关闭时间列表
collector = new InformationCollector(); */
private List<StartStopTime> startStop = new ArrayList<StartStopTime>();
readEncodeXMLFile(collector, collector.getInfoFile());
} /**
* 上一次的发送时间
return collector; */
} private String lastTime;
private StartStopTime current = new StartStopTime();
private static void readEncodeXMLFile(XMLReadable xmlReadable, File xmlFile) {
if (xmlFile == null || !xmlFile.exists()) { public static InformationCollector getInstance() {
return; if (collector == null) {
} collector = new InformationCollector();
String charset = EncodeConstants.ENCODING_UTF_8;
try { readEncodeXMLFile(collector, collector.getInfoFile());
String decodeContent = getDecodeFileContent(xmlFile); }
InputStream xmlInputStream = new ByteArrayInputStream(decodeContent.getBytes(charset));
InputStreamReader inputStreamReader = new InputStreamReader(xmlInputStream, charset); return collector;
}
XMLableReader xmlReader = XMLableReader.createXMLableReader(inputStreamReader);
private static void readEncodeXMLFile(XMLReadable xmlReadable, File xmlFile) {
if (xmlReader != null) { if (xmlFile == null || !xmlFile.exists()) {
xmlReader.readXMLObject(xmlReadable); return;
} }
xmlInputStream.close(); String charset = EncodeConstants.ENCODING_UTF_8;
} catch (FileNotFoundException e) { try {
FineLoggerFactory.getLogger().error(e.getMessage(), e); String decodeContent = getDecodeFileContent(xmlFile);
} catch (IOException e) { InputStream xmlInputStream = new ByteArrayInputStream(decodeContent.getBytes(charset));
FineLoggerFactory.getLogger().error(e.getMessage(), e); InputStreamReader inputStreamReader = new InputStreamReader(xmlInputStream, charset);
} catch (XMLStreamException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); XMLableReader xmlReader = XMLableReader.createXMLableReader(inputStreamReader);
}
if (xmlReader != null) {
} xmlReader.readXMLObject(xmlReadable);
}
private static String getDecodeFileContent(File xmlFile) throws FileNotFoundException, UnsupportedEncodingException { xmlInputStream.close();
InputStream encodeInputStream = new FileInputStream(xmlFile); } catch (FileNotFoundException e) {
String encodeContent = IOUtils.inputStream2String(encodeInputStream); FineLoggerFactory.getLogger().error(e.getMessage(), e);
return DesUtils.getDecString(encodeContent); } catch (IOException e) {
} FineLoggerFactory.getLogger().error(e.getMessage(), e);
} catch (XMLStreamException e) {
private long getLastTimeMillis() { FineLoggerFactory.getLogger().error(e.getMessage(), e);
if (StringUtils.isEmpty(this.lastTime)) { }
return 0;
} }
try { private static String getDecodeFileContent(File xmlFile) throws FileNotFoundException, UnsupportedEncodingException {
return DateUtils.string2Date(this.lastTime, true).getTime(); InputStream encodeInputStream = new FileInputStream(xmlFile);
} catch (Exception e) { String encodeContent = IOUtils.inputStream2String(encodeInputStream);
return -1; return DesUtils.getDecString(encodeContent);
} }
} private long getLastTimeMillis() {
if (StringUtils.isEmpty(this.lastTime)) {
private JSONObject getJSONContentAsByte() { return 0;
JSONObject content = new JSONObject(); }
JSONArray startStopArray = new JSONArray(); try {
for (int i = 0; i < startStop.size(); i++) { return Objects.requireNonNull(DateUtils.string2Date(this.lastTime, true)).getTime();
JSONObject jo = new JSONObject(); } catch (Exception e) {
jo.put(ATTR_START, startStop.get(i).getStartDate()); return -1;
jo.put(ATTR_STOP, startStop.get(i).getStopDate()); }
startStopArray.put(jo);
DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); }
content.put(XML_START_STOP, startStopArray);
content.put(XML_UUID, envManager.getUUID()); private JSONObject getJSONContentAsByte() {
content.put(XML_JAR, GeneralUtils.readBuildNO()); JSONObject content = new JSONObject();
content.put(XML_VERSION, ProductConstants.RELEASE_VERSION);
content.put(XML_USERNAME, MarketConfig.getInstance().getBbsUsername()); JSONArray startStopArray = new JSONArray();
content.put(XML_KEY, envManager.getActivationKey()); for (StartStopTime startStopTime : startStop) {
content.put(XML_OS, System.getProperty("os.name")); JSONObject jo = new JSONObject();
} jo.put(ATTR_START, startStopTime.getStartDate());
return content; jo.put(ATTR_STOP, startStopTime.getStopDate());
} startStopArray.put(jo);
}
private void sendUserInfo() { DesignerEnvManager envManager = DesignerEnvManager.getEnvManager();
long currentTime = new Date().getTime(); content.put(XML_START_STOP, startStopArray);
long lastTime = getLastTimeMillis(); content.put(XML_UUID, envManager.getUUID());
content.put(XML_JAR, GeneralUtils.readBuildNO());
if (currentTime - lastTime <= DELTA) { content.put(XML_VERSION, ProductConstants.RELEASE_VERSION);
return; content.put(XML_USERNAME, MarketConfig.getInstance().getBbsUsername());
} content.put(XML_KEY, envManager.getActivationKey());
JSONObject content = getJSONContentAsByte(); content.put(XML_OS, System.getProperty("os.name"));
String url = CloudCenter.getInstance().acquireUrlByKind("user.info.v10"); content.put(XML_ARCH, System.getProperty("os.arch"));
boolean success = false; content.put(XML_AVAILABLE_PROCESSORS, Runtime.getRuntime().availableProcessors());
try { content.put(XML_PHYSICAL_MEMORY, getTotalPhysicalMemorySize());
HashMap<String, Object> para = new HashMap<>(); return content;
para.put("token", SiteCenterToken.generateToken()); }
para.put("content", content);
String res = HttpToolbox.post(url, para); /**
success = ComparatorUtils.equals(new JSONObject(res).get("status"), "success"); * 获取物理内存单位GB
} catch (Exception e) { *
FineLoggerFactory.getLogger().error(e.getMessage(), e); * @return 物理内存
} */
if (success) { private static long getTotalPhysicalMemorySize() {
this.reset(); OperatingSystemMXBean bean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
} return bean.getTotalPhysicalMemorySize() / BYTE_TO_MB;
} }
/**
* 收集开始使用时间发送信息 private void sendUserInfo() {
*/ long currentTime = System.currentTimeMillis();
public void collectStartTime() { long lastTime = getLastTimeMillis();
this.current.setStartDate(dateToString());
if (currentTime - lastTime <= DELTA) {
sendUserInfoInOtherThread(); return;
} }
JSONObject content = getJSONContentAsByte();
private void sendUserInfoInOtherThread() { String url = CloudCenter.getInstance().acquireUrlByKind("user.info.v10");
if (!DesignerEnvManager.getEnvManager().isJoinProductImprove() || !FRContext.isChineseEnv()) { boolean success = false;
return; try {
} HashMap<String, Object> para = new HashMap<>();
para.put("token", SiteCenterToken.generateToken());
ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("InformationCollector")); para.put("content", content);
service.schedule(new Runnable() { String res = HttpToolbox.post(url, para);
@Override success = ComparatorUtils.equals(new JSONObject(res).get("status"), "success");
public void run() { } catch (Exception e) {
sendUserInfo(); FineLoggerFactory.getLogger().error(e.getMessage(), e);
FocusPointMessageUploader.getInstance().sendToCloudCenter(); }
TemplateInfoCollector.getInstance().sendTemplateInfo(); if (success) {
ErrorInfoUploader.getInstance().sendErrorInfo(); this.reset();
} }
}, SEND_DELAY, TimeUnit.MILLISECONDS); }
}
/**
/** * 收集开始使用时间发送信息
* 收集结束使用时间 */
*/ public void collectStartTime() {
public void collectStopTime() { this.current.setStartDate(dateToString());
this.current.setStopDate(dateToString());
} sendUserInfoInOtherThread();
}
private String dateToString() {
DateFormat df = FRContext.getDefaultValues().getDateTimeFormat(); private void sendUserInfoInOtherThread() {
return df.format(new Date()); if (!DesignerEnvManager.getEnvManager().isJoinProductImprove() || !FRContext.isChineseEnv()) {
} return;
}
private void reset() {
this.startStop.clear(); ScheduledExecutorService service = Executors
this.lastTime = dateToString(); .newSingleThreadScheduledExecutor(new NamedThreadFactory("InformationCollector"));
} service.schedule(new Runnable() {
@Override
private File getInfoFile() { public void run() {
return new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), FILE_NAME)); sendUserInfo();
} FocusPointMessageUploader.getInstance().sendToCloudCenter();
TemplateInfoCollector.getInstance().sendTemplateInfo();
/** ErrorInfoUploader.getInstance().sendErrorInfo();
* 保存xml文件 }
*/ }, SEND_DELAY, TimeUnit.MILLISECONDS);
public void saveXMLFile() { service.shutdown();
File xmlFile = this.getInfoFile(); }
try {
ByteArrayOutputStream out = new ByteArrayOutputStream(); /**
XMLTools.writeOutputStreamXML(this, out); * 收集结束使用时间
out.flush(); */
out.close(); public void collectStopTime() {
String fileContent = new String(out.toByteArray(), EncodeConstants.ENCODING_UTF_8); this.current.setStopDate(dateToString());
String encodeCotent = DesUtils.getEncString(fileContent); }
writeEncodeContentToFile(encodeCotent, xmlFile);
} catch (Exception e) { private String dateToString() {
FineLoggerFactory.getLogger().error(e.getMessage(), e); DateFormat df = FRContext.getDefaultValues().getDateTimeFormat();
} return df.format(new Date());
} }
private void reset() {
/** this.startStop.clear();
* 将文件内容写到输出流中 this.lastTime = dateToString();
*/ }
private static void writeEncodeContentToFile(String fileContent, File file) {
try (FileOutputStream fos = new FileOutputStream(file); private File getInfoFile() {
OutputStreamWriter osw = new OutputStreamWriter(fos, EncodeConstants.ENCODING_UTF_8); return new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), FILE_NAME));
BufferedWriter bw = new BufferedWriter(osw)) { }
bw.write(fileContent);
} catch (Exception e) { /**
FineLoggerFactory.getLogger().error(e.getMessage(), e); * 保存xml文件
} */
} public void saveXMLFile() {
File xmlFile = this.getInfoFile();
@Override try {
public void writeXML(XMLPrintWriter writer) { ByteArrayOutputStream out = new ByteArrayOutputStream();
startStop.add(current); XMLTools.writeOutputStreamXML(this, out);
writer.startTAG("Info"); out.flush();
//启停信息 out.close();
writeStartStopList(writer); String fileContent = new String(out.toByteArray(), StandardCharsets.UTF_8);
//上一次更新的时间 String encodeCotent = DesUtils.getEncString(fileContent);
writeTag(XML_LAST_TIME, this.lastTime, writer); writeEncodeContentToFile(encodeCotent, xmlFile);
} catch (Exception e) {
writer.end(); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }
}
private void writeStartStopList(XMLPrintWriter writer) {
//启停
writer.startTAG(XML_START_STOP_LIST); /**
for (int i = 0; i < startStop.size(); i++) { * 将文件内容写到输出流中
startStop.get(i).writeXML(writer); */
} private static void writeEncodeContentToFile(String fileContent, File file) {
writer.end(); try (FileOutputStream fos = new FileOutputStream(file);
} OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
BufferedWriter bw = new BufferedWriter(osw)) {
private void writeTag(String tag, String content, XMLPrintWriter writer) { bw.write(fileContent);
if (StringUtils.isEmpty(content)) { } catch (Exception e) {
return; FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }
}
writer.startTAG(tag);
writer.textNode(content); @Override
writer.end(); public void writeXML(XMLPrintWriter writer) {
} startStop.add(current);
writer.startTAG("Info");
@Override //启停信息
public void readXML(XMLableReader reader) { writeStartStopList(writer);
if (reader.isChildNode()) { //上一次更新的时间
String name = reader.getTagName(); writeTag(XML_LAST_TIME, this.lastTime, writer);
if (XML_START_STOP_LIST.equals(name)) {
readStartStopList(reader); writer.end();
} else if (XML_LAST_TIME.equals(name)) { }
readLastTime(reader);
} private void writeStartStopList(XMLPrintWriter writer) {
} //启停
} writer.startTAG(XML_START_STOP_LIST);
for (StartStopTime startStopTime : startStop) {
private void readLastTime(XMLableReader reader) { startStopTime.writeXML(writer);
String tmpVal; }
if (StringUtils.isNotBlank(tmpVal = reader.getElementValue())) { writer.end();
this.lastTime = tmpVal; }
}
} private void writeTag(String tag, String content, XMLPrintWriter writer) {
if (StringUtils.isEmpty(content)) {
private void readStartStopList(XMLableReader reader) { return;
startStop.clear(); }
reader.readXMLObject(new XMLReadable() { writer.startTAG(tag);
public void readXML(XMLableReader reader) { writer.textNode(content);
if (XML_START_STOP.equals(reader.getTagName())) { writer.end();
StartStopTime startStopTime = new StartStopTime(); }
reader.readXMLObject(startStopTime);
startStop.add(startStopTime); @Override
} public void readXML(XMLableReader reader) {
} if (reader.isChildNode()) {
}); String name = reader.getTagName();
} if (XML_START_STOP_LIST.equals(name)) {
readStartStopList(reader);
private class StartStopTime implements XMLReadable, XMLWriter { } else if (XML_LAST_TIME.equals(name)) {
readLastTime(reader);
private String startDate; }
private String stopDate; }
}
public String getStartDate() {
return startDate; private void readLastTime(XMLableReader reader) {
} String tmpVal;
if (StringUtils.isNotBlank(tmpVal = reader.getElementValue())) {
public void setStartDate(String startDate) { this.lastTime = tmpVal;
this.startDate = startDate; }
} }
public String getStopDate() { private void readStartStopList(XMLableReader reader) {
return stopDate; startStop.clear();
}
reader.readXMLObject(new XMLReadable() {
public void setStopDate(String endDate) { @Override
this.stopDate = endDate; public void readXML(XMLableReader reader) {
} if (XML_START_STOP.equals(reader.getTagName())) {
StartStopTime startStopTime = new StartStopTime();
public void writeXML(XMLPrintWriter writer) { reader.readXMLObject(startStopTime);
writer.startTAG(XML_START_STOP); startStop.add(startStopTime);
if (StringUtils.isNotEmpty(startDate)) { }
writer.attr(ATTR_START, this.startDate); }
} });
if (StringUtils.isNotEmpty(stopDate)) { }
writer.attr(ATTR_STOP, this.stopDate);
} private class StartStopTime implements XMLReadable, XMLWriter {
writer.end();
} private String startDate;
private String stopDate;
public void readXML(XMLableReader reader) {
this.startDate = reader.getAttrAsString(ATTR_START, StringUtils.EMPTY); public String getStartDate() {
this.stopDate = reader.getAttrAsString(ATTR_STOP, StringUtils.EMPTY); return startDate;
} }
} public void setStartDate(String startDate) {
this.startDate = startDate;
}
public String getStopDate() {
return stopDate;
}
public void setStopDate(String endDate) {
this.stopDate = endDate;
}
@Override
public void writeXML(XMLPrintWriter writer) {
writer.startTAG(XML_START_STOP);
if (StringUtils.isNotEmpty(startDate)) {
writer.attr(ATTR_START, this.startDate);
}
if (StringUtils.isNotEmpty(stopDate)) {
writer.attr(ATTR_STOP, this.stopDate);
}
writer.end();
}
@Override
public void readXML(XMLableReader reader) {
this.startDate = reader.getAttrAsString(ATTR_START, StringUtils.EMPTY);
this.stopDate = reader.getAttrAsString(ATTR_STOP, StringUtils.EMPTY);
}
}
} }

9
designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/StartupMessageCollector.java

@ -8,6 +8,7 @@ import com.fr.event.EventDispatcher;
import com.fr.event.Listener; import com.fr.event.Listener;
import com.fr.general.CloudCenter; import com.fr.general.CloudCenter;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.general.GeneralUtils;
import com.fr.general.http.HttpToolbox; import com.fr.general.http.HttpToolbox;
import com.fr.json.JSONObject; import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
@ -30,14 +31,15 @@ public class StartupMessageCollector {
private static final String XML_STARTUP_TIME = "t"; private static final String XML_STARTUP_TIME = "t";
private static final String XML_STARTUP_LOG = "startupLog"; private static final String XML_STARTUP_LOG = "startupLog";
private static final String XML_STARTUP_Memory = "designerMemory"; private static final String XML_STARTUP_MEMORY = "designerMemory";
private static final String XML_STARTUP_COST = "cost"; private static final String XML_STARTUP_COST = "cost";
private static final String XML_UUID = "UUID"; private static final String XML_UUID = "UUID";
private static final String XML_BUILD_NO = "buildNO";
private static final String STARTUP_URL_KEY = "user.info.v10.startup"; private static final String STARTUP_URL_KEY = "user.info.v10.startup";
private static final String LOG_TYPE = "single"; private static final String LOG_TYPE = "single";
private static final int BYTE_TO_MB = 1024 * 1024; private static final int BYTE_TO_MB = 1024 * 1024;
public static final StartupMessageCollector INSTANCE = new StartupMessageCollector(); private static final StartupMessageCollector INSTANCE = new StartupMessageCollector();
private StartupMessageCollector() { private StartupMessageCollector() {
} }
@ -67,10 +69,11 @@ public class StartupMessageCollector {
} }
JSONObject json = JSONObject.create() JSONObject json = JSONObject.create()
.put(XML_UUID, DesignerEnvManager.getEnvManager().getUUID()) .put(XML_UUID, DesignerEnvManager.getEnvManager().getUUID())
.put(XML_BUILD_NO, GeneralUtils.readBuildNO())
.put(XML_STARTUP_TIME, FineRuntime.getAppStartTime() + FineRuntime.getStartingTime()) .put(XML_STARTUP_TIME, FineRuntime.getAppStartTime() + FineRuntime.getStartingTime())
.put(XML_STARTUP_COST, FineRuntime.getStartingTime()) .put(XML_STARTUP_COST, FineRuntime.getStartingTime())
.put(XML_STARTUP_LOG, profile) .put(XML_STARTUP_LOG, profile)
.put(XML_STARTUP_Memory, Runtime.getRuntime().totalMemory() / BYTE_TO_MB); .put(XML_STARTUP_MEMORY, Runtime.getRuntime().maxMemory() / BYTE_TO_MB);
sendInfo(json, url + LOG_TYPE); sendInfo(json, url + LOG_TYPE);
} }
}); });

Loading…
Cancel
Save