Browse Source

Merge branch 'master' of Lucian.Chen/finekit into master

先合并进来,之后再把不行的移除掉
master
richie 5 years ago committed by Gogs
parent
commit
19ffaa02e9
  1. 38
      src/main/java/com/fanruan/api/cluster/ClusterBridgeKit.java
  2. 19
      src/main/java/com/fanruan/api/cluster/state/MachineKit.java
  3. 20
      src/main/java/com/fanruan/api/concurrent/ConcurrentKit.java
  4. 30
      src/main/java/com/fanruan/api/conf/impl/xml/XmlColConf.java
  5. 22
      src/main/java/com/fanruan/api/conf/impl/xml/XmlConf.java
  6. 30
      src/main/java/com/fanruan/api/conf/xml/XmlHolderKit.java
  7. 12
      src/main/java/com/fanruan/api/decision/CommonKit.java
  8. 16
      src/main/java/com/fanruan/api/decision/monitor/RuntimeMemScoreKit.java
  9. 10
      src/main/java/com/fanruan/api/decision/store/StateHubManager.java
  10. 30
      src/main/java/com/fanruan/api/design/DesignKit.java
  11. 22
      src/main/java/com/fanruan/api/design/ui/component/UIHeadGroup.java
  12. 44
      src/main/java/com/fanruan/api/design/ui/component/UIRadioButton.java
  13. 16
      src/main/java/com/fanruan/api/design/ui/component/target/TargetComponent.java
  14. 12
      src/main/java/com/fanruan/api/design/ui/table/BasePropertyTable.java
  15. 27
      src/main/java/com/fanruan/api/design/util/GUICoreKit.java
  16. 14
      src/main/java/com/fanruan/api/design/work/FormHyperlinkGroupPane.java
  17. 198
      src/main/java/com/fanruan/api/design/work/SelectImagePane.java
  18. 3
      src/main/java/com/fanruan/api/design/work/component/ParameterComboBox.java
  19. 18
      src/main/java/com/fanruan/api/image/general/ImageWithSuffix.java
  20. 9
      src/main/java/com/fanruan/api/report/cell/CellImage.java
  21. 22
      src/main/java/com/fanruan/api/report/cell/FloatElement.java
  22. 4
      src/main/java/com/fanruan/api/util/ArrayKit.java
  23. 18
      src/main/java/com/fanruan/api/util/AssistKit.java
  24. 16
      src/main/java/com/fanruan/api/util/FineCollectionKit.java
  25. 10
      src/main/java/com/fanruan/api/util/GeneralKit.java
  26. 39
      src/main/java/com/fanruan/api/util/HyperKit.java
  27. 72
      src/test/java/com/fanruan/api/cluster/ClusterBridgeKitTest.java
  28. 44
      src/test/java/com/fanruan/api/cluster/state/MachineKitTest.java
  29. 65
      src/test/java/com/fanruan/api/conf/xml/XmlHolderKitTest.java
  30. 59
      src/test/java/com/fanruan/api/decision/CommonKitTest.java
  31. 19
      src/test/java/com/fanruan/api/decision/monitor/RuntimeMemScoreKitTest.java
  32. 12
      src/test/java/com/fanruan/api/util/ArrayKitTest.java
  33. 17
      src/test/java/com/fanruan/api/util/AssistKitTest.java
  34. 19
      src/test/java/com/fanruan/api/util/FineCollectionKitTest.java
  35. 8
      src/test/java/com/fanruan/api/util/GeneralKitTest.java
  36. 62
      src/test/java/com/fanruan/api/util/HyperKitTest.java
  37. 2
      src/test/java/com/fanruan/api/util/IOKitTest.java

38
src/main/java/com/fanruan/api/cluster/ClusterBridgeKit.java

@ -0,0 +1,38 @@
package com.fanruan.api.cluster;
import com.fr.cluster.ClusterBridge;
import com.fr.cluster.core.ClusterNode;
import com.fr.cluster.core.ClusterView;
import com.fr.stable.Filter;
import java.util.List;
/**
* @author Lucian.Chen
* @version 10.0
* Created by Lucian.Chen on 2020/3/23
*/
public class ClusterBridgeKit {
public static ClusterNode getCurrentNode() {
return ClusterBridge.getView().getCurrent();
}
public static ClusterNode getNodeById(String var1) {
return ClusterBridge.getView().getNodeById(var1);
}
public static List<ClusterNode> listNodes() {
return ClusterBridge.getView().listNodes();
}
public static List<ClusterNode> listNodes(Filter<ClusterNode> var1) {
return ClusterBridge.getView().listNodes(var1);
}
public static boolean isClusterMode() {
return ClusterBridge.isClusterMode();
}
}

19
src/main/java/com/fanruan/api/cluster/state/MachineKit.java

@ -0,0 +1,19 @@
package com.fanruan.api.cluster.state;
import com.fr.cluster.engine.core.jchannel.MachineMarker;
/**
* @author Lucian.Chen
* @version 10.0
* Created by Lucian.Chen on 2020/3/23
*/
public class MachineKit {
public static String currentID() {
return MachineMarker.currentID();
}
public static String currentName() {
return MachineMarker.currentName();
}
}

20
src/main/java/com/fanruan/api/concurrent/ConcurrentKit.java

@ -0,0 +1,20 @@
package com.fanruan.api.concurrent;
import com.fr.concurrent.NamedThreadFactory;
/**
* @author Lucian.Chen
* @version 10.0
* Created by Lucian.Chen on 2020/3/27
*/
public class ConcurrentKit {
/**
* 创建命名的线程工厂
* @param prefix 线程池名称前缀
* @return 线程工厂
*/
public static NamedThreadFactory newNamedThreadFactory(String prefix) {
return new NamedThreadFactory(prefix);
}
}

30
src/main/java/com/fanruan/api/conf/impl/xml/XmlColConf.java

@ -0,0 +1,30 @@
package com.fanruan.api.conf.impl.xml;
import java.util.Collection;
/**
* @author Lucian.Chen
* @version 10.0
* Created by Lucian.Chen on 2020/3/23
*/
public class XmlColConf<T extends Collection> extends com.fr.config.holder.impl.xml.XmlColConf<Collection> {
public XmlColConf(String s, Collection collection, Class aClass) {
super(s, collection, aClass);
}
public XmlColConf(Collection collection, Class aClass) {
super(collection, aClass);
}
public XmlColConf(Collection collection, Class aClass, boolean b) {
super(collection, aClass, b);
}
public XmlColConf(Collection collection, Class aClass, String s) {
super(collection, aClass, s);
}
public XmlColConf(Collection collection, Class aClass, String s, boolean b) {
super(collection, aClass, s, b);
}
}

22
src/main/java/com/fanruan/api/conf/impl/xml/XmlConf.java

@ -0,0 +1,22 @@
package com.fanruan.api.conf.impl.xml;
import com.fr.stable.xml.XMLable;
/**
* @author Lucian.Chen
* @version 10.0
* Created by Lucian.Chen on 2020/3/23
*/
public class XmlConf<T extends XMLable> extends com.fr.config.holder.impl.xml.XmlConf<XMLable> {
public XmlConf(String s, XMLable xmLable, Class aClass) {
super(s, xmLable, aClass);
}
public XmlConf(XMLable xmLable, Class aClass) {
super(xmLable, aClass);
}
public XmlConf(XMLable xmLable, Class aClass, String s) {
super(xmLable, aClass, s);
}
}

30
src/main/java/com/fanruan/api/conf/xml/XmlHolderKit.java

@ -1,9 +1,11 @@
package com.fanruan.api.conf.xml; package com.fanruan.api.conf.xml;
import com.fanruan.api.conf.impl.xml.XmlColConf;
import com.fanruan.api.conf.impl.xml.XmlConf;
import com.fr.config.holder.Conf; import com.fr.config.holder.Conf;
import com.fr.config.holder.impl.xml.XmlConf;
import com.fr.stable.xml.XMLable; import com.fr.stable.xml.XMLable;
import java.util.Collection;
/** /**
* @author richie * @author richie
* @version 10.0 * @version 10.0
@ -23,4 +25,30 @@ public class XmlHolderKit {
public static <T extends XMLable> Conf<T> obj(T t, Class<T> clazz, String xmlTag) { public static <T extends XMLable> Conf<T> obj(T t, Class<T> clazz, String xmlTag) {
return new XmlConf(t, clazz, xmlTag); return new XmlConf(t, clazz, xmlTag);
} }
/**
* 创建一个集合类型的xml配置
*
* @param t 初始值
* @param clazz 对象class类型
* @param <T> 类型
* @return 配置对象
*/
public static <T extends XMLable> XmlColConf<Collection<T>> collection(Collection<T> t, Class<T> clazz) {
return collection(t,clazz,true);
}
/**
* 创建一个集合类型的xml配置
*
* @param t 初始值
* @param clazz 对象class类型
* @param order 是否是有序的配置
* @param <T> 类型
* @return 配置对象
*/
public static <T extends XMLable> XmlColConf<Collection<T>> collection(Collection<T> t, Class<T> clazz, boolean order) {
return new XmlColConf<Collection<T>>(t, clazz, order);
}
} }

12
src/main/java/com/fanruan/api/decision/CommonKit.java

@ -7,6 +7,7 @@ import com.fr.base.ServerConfig;
import com.fr.decision.webservice.utils.DecisionServiceConstants; import com.fr.decision.webservice.utils.DecisionServiceConstants;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import java.awt.Image;
/** /**
* @author richie * @author richie
* @version 10.0 * @version 10.0
@ -51,4 +52,15 @@ public class CommonKit {
return StringKit.EMPTY; return StringKit.EMPTY;
} }
/**
* 将图片对象用指定的格式输出成base64编码表示的字符串
*
* @param im 图片对象
* @param format 要输出的格式
* @return 表示图片的base64编码的字符串
*/
public static String encode(Image im, String format) {
return Base64.encode(im, format);
}
} }

16
src/main/java/com/fanruan/api/decision/monitor/RuntimeMemScoreKit.java

@ -0,0 +1,16 @@
package com.fanruan.api.decision.monitor;
import com.fr.decision.system.monitor.gc.load.RuntimeMemScoreProvider;
/**
* @author Lucian.Chen
* @version 10.0
* Created by Lucian.Chen on 2020/3/23
*/
public class RuntimeMemScoreKit {
//分发得分
public static int getLoadScore() {
return RuntimeMemScoreProvider.getLoadScore();
}
}

10
src/main/java/com/fanruan/api/decision/store/StateHubManager.java

@ -0,0 +1,10 @@
package com.fanruan.api.decision.store;
/**
* @author Lucian.Chen
* @version 10.0
* Created by Lucian.Chen on 2020/3/23
*/
public class StateHubManager extends com.fr.store.StateHubManager {
}

30
src/main/java/com/fanruan/api/design/DesignKit.java

@ -1,14 +1,20 @@
package com.fanruan.api.design; package com.fanruan.api.design;
import com.fr.design.mainframe.WidgetPropertyPane;
import com.fr.base.TableData; import com.fr.base.TableData;
import com.fr.design.DesignModelAdapter;
import com.fr.design.data.datapane.preview.PreviewTablePane; import com.fr.design.data.datapane.preview.PreviewTablePane;
import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.gui.frpane.HyperlinkGroupPaneActionProvider;
import com.fr.design.i18n.Toolkit; import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.DesignerBean; import com.fr.design.mainframe.DesignerBean;
import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.DesignerFrame; import com.fr.design.mainframe.DesignerFrame;
import com.fr.design.mainframe.HyperlinkGroupPaneActionImpl;
import com.fr.design.mainframe.JTemplate; import com.fr.design.mainframe.JTemplate;
import javax.swing.JComponent;
public class DesignKit { public class DesignKit {
/** /**
* 直接预览数据集没有实际值及显示值 * 直接预览数据集没有实际值及显示值
@ -67,4 +73,28 @@ public class DesignKit {
public static DesignerBean getDesignerBean(String name) { public static DesignerBean getDesignerBean(String name) {
return DesignerContext.getDesignerBean(name); return DesignerContext.getDesignerBean(name);
} }
/**
* 超链接面板操作
* @return 操作对象
*/
public static HyperlinkGroupPaneActionProvider getHyperlinkGroupPaneAction() {
return HyperlinkGroupPaneActionImpl.getInstance();
}
/**
* 当前的设计模式 FormModel or WorkBookModel
* @return 设计器模式
*/
public static DesignModelAdapter<?, ?> getCurrentModelAdapter() {
return DesignModelAdapter.getCurrentModelAdapter();
}
/**
* 控件属性容器
*/
public static JComponent getWidgetComponent() {
return (JComponent) (WidgetPropertyPane.getInstance().getEditingFormDesigner().getSelectionModel().getSelection().getSelectedCreator()).getComponent(0);
}
} }

22
src/main/java/com/fanruan/api/design/ui/component/UIHeadGroup.java

@ -0,0 +1,22 @@
package com.fanruan.api.design.ui.component;
import javax.swing.Icon;
/**
* @author Lucian.Chen
* @version 10.0
* Created by Lucian.Chen on 2020/3/23
*/
public class UIHeadGroup extends com.fr.design.gui.ibutton.UIHeadGroup {
public UIHeadGroup(String[] strings) {
super(strings);
}
public UIHeadGroup(Icon[] icons) {
super(icons);
}
public UIHeadGroup(Icon[] icons, String[] strings) {
super(icons, strings);
}
}

44
src/main/java/com/fanruan/api/design/ui/component/UIRadioButton.java

@ -0,0 +1,44 @@
package com.fanruan.api.design.ui.component;
import javax.swing.Action;
import javax.swing.Icon;
/**
* @author Lucian.Chen
* @version 10.0
* Created by Lucian.Chen on 2020/3/20
*/
public class UIRadioButton extends com.fr.design.gui.ibutton.UIRadioButton {
public UIRadioButton() {
super();
}
public UIRadioButton(Icon icon) {
super(icon);
}
public UIRadioButton(Action action) {
super(action);
}
public UIRadioButton(Icon icon, boolean selected) {
super(icon, selected);
}
public UIRadioButton(String text) {
super(text);
}
public UIRadioButton(String text, boolean selected) {
super(text, selected);
}
public UIRadioButton(String text, Icon icon) {
super(text, icon);
}
public UIRadioButton(String text, Icon icon, boolean selected) {
super(text, icon, selected);
}
}

16
src/main/java/com/fanruan/api/design/ui/component/target/TargetComponent.java

@ -0,0 +1,16 @@
package com.fanruan.api.design.ui.component.target;
/**
* 模板设计界面
*/
public abstract class TargetComponent<T> extends com.fr.design.designer.TargetComponent<T> {
public TargetComponent(T t) {
super(t);
}
public TargetComponent() {
super();
}
}

12
src/main/java/com/fanruan/api/design/ui/table/BasePropertyTable.java

@ -0,0 +1,12 @@
package com.fanruan.api.design.ui.table;
/**
* @author Lucian.Chen
* @version 10.0
* Created by Lucian.Chen on 2020/3/23
*/
public abstract class BasePropertyTable extends com.fr.design.gui.itable.AbstractPropertyTable {
public BasePropertyTable() {
super();
}
}

27
src/main/java/com/fanruan/api/design/util/GUICoreKit.java

@ -121,6 +121,33 @@ public class GUICoreKit {
return FRGUIPaneFactory.createBorderLayout_S_Pane(); return FRGUIPaneFactory.createBorderLayout_S_Pane();
} }
/**
* 创建纵向内置boxlayout的面板
*
* @return JPanel对象
*/
public static JPanel createYAXISBoxInnerContainerPane() {
return FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane();
}
/**
* 创建一个边框布局
*
* @return BorderLayout对象
*/
public static LayoutManager createBorderLayout() {
return FRGUIPaneFactory.createBorderLayout();
}
/**
* 创建一个靠左空边框面板间隔中等
*
* @return JPanel对象
*/
public static JPanel createMediumHGapHighTopFlowInnerContainerPane() {
return FRGUIPaneFactory.createMediumHGapHighTopFlowInnerContainer_M_Pane();
}
/** /**
* 设置一个窗口居中 * 设置一个窗口居中
*/ */

14
src/main/java/com/fanruan/api/design/work/FormHyperlinkGroupPane.java

@ -0,0 +1,14 @@
package com.fanruan.api.design.work;
import com.fr.design.gui.frpane.HyperlinkGroupPaneActionProvider;
/**
* @author Lucian.Chen
* @version 10.0
* Created by Lucian.Chen on 2020/3/23
*/
public class FormHyperlinkGroupPane extends com.fr.design.gui.xpane.FormHyperlinkGroupPane {
protected FormHyperlinkGroupPane(HyperlinkGroupPaneActionProvider hyperlinkGroupPaneActionProvider) {
super(hyperlinkGroupPaneActionProvider);
}
}

198
src/main/java/com/fanruan/api/design/work/SelectImagePane.java

@ -0,0 +1,198 @@
package com.fanruan.api.design.work;
import com.fanruan.api.design.ui.component.UIButton;
import com.fanruan.api.design.ui.component.UIRadioButton;
import com.fanruan.api.design.util.GUICoreKit;
import com.fanruan.api.report.cell.CellImage;
import com.fr.base.Style;
import com.fr.design.dialog.BasicPane;
import com.fr.design.gui.frpane.ImgChooseWrapper;
import com.fr.design.style.background.image.ImageFileChooser;
import com.fr.design.style.background.image.ImagePreviewPane;
import com.fr.report.cell.Elem;
import com.fr.report.cell.painter.CellImagePainter;
import com.fr.stable.Constants;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
/**
* 这个类主要用于插入图片时的设置
*/
public class SelectImagePane extends BasicPane {
private ImagePreviewPane previewPane = null;
private ImageFileChooser imageFileChooser = null;
private UIRadioButton defaultRadioButton = null;
private UIRadioButton tiledRadioButton = null;
private UIRadioButton extendRadioButton = null;
private UIRadioButton adjustRadioButton = null;
private Style imageStyle = null;
private File imageFile;
public SelectImagePane() {
this.setLayout(GUICoreKit.createBorderLayout());
// preview pane
JPanel previewContainerPane = GUICoreKit.createBorderLayoutPane();
this.add(previewContainerPane, BorderLayout.CENTER);
JPanel previewOwnerPane = GUICoreKit.createBorderLayoutPane();
previewContainerPane.add(previewOwnerPane, BorderLayout.CENTER);
previewOwnerPane.setBorder(GUICoreKit.createTitledBorder(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Preview"), null));
previewPane = new ImagePreviewPane();
previewOwnerPane.add(new JScrollPane(previewPane));
JPanel selectFilePane = GUICoreKit.createBorderLayoutPane();
previewContainerPane.add(selectFilePane, BorderLayout.EAST);
selectFilePane.setBorder(BorderFactory
.createEmptyBorder(8, 2, 4, 0));
UIButton selectPictureButton = new UIButton(
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Image_Select_Picture"));
selectFilePane.add(selectPictureButton, BorderLayout.NORTH);
selectPictureButton.setMnemonic('S');
selectPictureButton.addActionListener(selectPictureActionListener);
JPanel layoutPane = GUICoreKit.createMediumHGapHighTopFlowInnerContainerPane();
selectFilePane.add(layoutPane, BorderLayout.CENTER);
//布局
defaultRadioButton = new UIRadioButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Default"));
tiledRadioButton = new UIRadioButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Image_Titled"));
extendRadioButton = new UIRadioButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Image_Extend"));
adjustRadioButton = new UIRadioButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Image_Adjust"));
defaultRadioButton.addActionListener(layoutActionListener);
tiledRadioButton.addActionListener(layoutActionListener);
extendRadioButton.addActionListener(layoutActionListener);
adjustRadioButton.addActionListener(layoutActionListener);
JPanel jp = new JPanel(new GridLayout(4, 1, 15, 15));
jp.add(defaultRadioButton);
jp.add(tiledRadioButton);
jp.add(extendRadioButton);
jp.add(adjustRadioButton);
layoutPane.add(jp);
ButtonGroup layoutBG = new ButtonGroup();
layoutBG.add(defaultRadioButton);
layoutBG.add(tiledRadioButton);
layoutBG.add(extendRadioButton);
layoutBG.add(adjustRadioButton);
defaultRadioButton.setSelected(true);
// init image file chooser.
imageFileChooser = new ImageFileChooser();
imageFileChooser.setMultiSelectionEnabled(false);
}
/**
* Select picture.
*/
ActionListener selectPictureActionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
int returnVal = imageFileChooser
.showOpenDialog(SelectImagePane.this);
if (returnVal != JFileChooser.CANCEL_OPTION) {
File selectedFile = imageFileChooser.getSelectedFile();
imageFile = selectedFile;
ImgChooseWrapper.getInstance(previewPane, imageFileChooser, imageStyle, null).dealWithImageFile(returnVal);
}
}
};
// 调整图片样式,只有水平和垂直对齐以及拉伸。相对于背景,平铺不予考虑。
private void changeImageStyle() {
previewPane.setImageStyle(this.imageStyle);
previewPane.repaint();
}
private void setImageStyle() {
if (tiledRadioButton.isSelected()) {
imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_TILED);
} else if (adjustRadioButton.isSelected()) {
imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_ADJUST);
} else if (extendRadioButton.isSelected()) {
imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_EXTEND);
} else {
imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_CENTER);
}
}
ActionListener layoutActionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
setImageStyle();
changeImageStyle();
}
};
@Override
protected String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Image");
}
public void populate(Elem cell) {
Style style = null;
if (cell != null) {
Object value = cell.getValue();
if (value instanceof Image) {
setImage((Image) value);
} else if (value instanceof CellImagePainter) {
setImage(((CellImagePainter) value).getImage());
}
style = cell.getStyle();
}
if (style == null) {
return;
}
if (style.getImageLayout() == Constants.IMAGE_TILED) {
tiledRadioButton.setSelected(true);
} else if (style.getImageLayout() == Constants.IMAGE_EXTEND) {
extendRadioButton.setSelected(true);
} else if (style.getImageLayout() == Constants.IMAGE_ADJUST) {
adjustRadioButton.setSelected(true);
} else {
style.deriveImageLayout(Constants.IMAGE_CENTER);
defaultRadioButton.setSelected(true);
}
this.imageStyle = style;
changeImageStyle();
}
public void setImage(Image image) {
previewPane.setImage(image);
}
public CellImage update() {
CellImage cellImage = new CellImage();
cellImage.setImage(previewPane.getImageWithSuffix());
cellImage.setStyle(this.imageStyle);
return cellImage;
}
public File getSelectedImage() {
return imageFile;
}
}

3
src/main/java/com/fanruan/api/design/work/component/ParameterComboBox.java

@ -1,6 +1,7 @@
package com.fanruan.api.design.work.component; package com.fanruan.api.design.work.component;
import com.fanruan.api.cal.ParameterKit; import com.fanruan.api.cal.ParameterKit;
import com.fanruan.api.design.DesignKit;
import com.fanruan.api.design.ui.component.UIComboBox; import com.fanruan.api.design.ui.component.UIComboBox;
import com.fanruan.api.util.AssistKit; import com.fanruan.api.util.AssistKit;
import com.fr.design.DesignModelAdapter; import com.fr.design.DesignModelAdapter;
@ -41,7 +42,7 @@ public class ParameterComboBox extends UIComboBox<ParameterProvider> {
public void updateParaItems() { public void updateParaItems() {
DesignModelAdapter<?, ?> designModel = DesignModelAdapter.getCurrentModelAdapter(); DesignModelAdapter<?, ?> designModel = DesignKit.getCurrentModelAdapter();
this.removeAllItems(); this.removeAllItems();
if (designModel != null) { if (designModel != null) {

18
src/main/java/com/fanruan/api/image/general/ImageWithSuffix.java

@ -0,0 +1,18 @@
package com.fanruan.api.image.general;
import java.awt.Image;
/**
* @author Lucian.Chen
* @version 10.0
* Created by Lucian.Chen on 2020/3/23
*/
public class ImageWithSuffix extends com.fr.general.ImageWithSuffix {
public ImageWithSuffix(Image image, String format) {
super(image, format);
}
public ImageWithSuffix(Image image) {
super(image);
}
}

9
src/main/java/com/fanruan/api/report/cell/CellImage.java

@ -0,0 +1,9 @@
package com.fanruan.api.report.cell;
/**
* @author Lucian.Chen
* @version 10.0
* Created by Lucian.Chen on 2020/3/23
*/
public class CellImage extends com.fr.report.cell.cellattr.CellImage {
}

22
src/main/java/com/fanruan/api/report/cell/FloatElement.java

@ -0,0 +1,22 @@
package com.fanruan.api.report.cell;
import com.fr.stable.unit.UNIT;
/**
* @author Lucian.Chen
* @version 10.0
* Created by Lucian.Chen on 2020/3/23
*/
public class FloatElement extends com.fr.report.cell.FloatElement {
public FloatElement() {
super();
}
public FloatElement(Object value) {
super(value);
}
public FloatElement(UNIT leftDistance, UNIT topDistance, UNIT width, UNIT height, Object value) {
super(leftDistance, topDistance, width, height, value);
}
}

4
src/main/java/com/fanruan/api/util/ArrayKit.java

@ -120,4 +120,8 @@ public class ArrayKit {
public static int getLength(Object array) { public static int getLength(Object array) {
return ArrayUtils.getLength(array); return ArrayUtils.getLength(array);
} }
public static <T> T[] insert(final int index, final T[] array, final T... values) {
return ArrayUtils.insert(index, array, values);
}
} }

18
src/main/java/com/fanruan/api/util/AssistKit.java

@ -23,6 +23,24 @@ public class AssistKit {
return AssistUtils.equals(parm1, parm2); return AssistUtils.equals(parm1, parm2);
} }
/**
* 判断 float 类型是否相等
* <p>
* 浮点数采用尾数+阶码的编码方式类似于科学计数法的有效数字+指数的表示方式
* 二进制无法精确表示大部分的十进制小数
* <p>
* 这里首先比较该数二进制是否相等若不相等则采用近视精度比较精度可自定义
*
* @param f1 单精度浮点
* @param f2 单精度浮点
* @param delta 判断精度
* @return 是否相等
* @see #equals(float, float)
*/
public static boolean equalsFloat(float f1, float f2, float delta) {
return AssistUtils.equalsFloat(f1, f2 ,delta);
}
/** /**
* 判断两个Object类型数据是否相等 * 判断两个Object类型数据是否相等
* @param parm1 第一个Object数据 * @param parm1 第一个Object数据

16
src/main/java/com/fanruan/api/util/FineCollectionKit.java

@ -0,0 +1,16 @@
package com.fanruan.api.util;
import com.fr.collections.FineCollections;
import com.fr.collections.api.FineCollectionClient;
/**
* @author Lucian.Chen
* @version 10.0
* Created by Lucian.Chen on 2020/3/23
*/
public class FineCollectionKit {
public static FineCollectionClient getClient() {
return FineCollections.getInstance().getClient();
}
}

10
src/main/java/com/fanruan/api/util/GeneralKit.java

@ -148,4 +148,14 @@ public class GeneralKit {
return (rgb & 0xff000000) | (gray << 16) | (gray << 8) | (gray); return (rgb & 0xff000000) | (gray << 16) | (gray << 8) | (gray);
} }
/**
* 寻找指定名字的class文件
*
* @param className 指定的类名
* @return class类
*/
public static Class<?> classForName(String className) throws ClassNotFoundException, NoClassDefFoundError {
return StableUtils.classForName(className);
}
} }

39
src/main/java/com/fanruan/api/util/HyperKit.java

@ -0,0 +1,39 @@
package com.fanruan.api.util;
import com.fr.js.HyperlinkUtils;
import com.fr.js.NameJavaScriptGroup;
import com.fr.json.JSONArray;
import com.fr.json.JSONException;
import com.fr.stable.web.Repository;
/**
* @author Lucian.Chen
* @version 10.0
* Created by Lucian.Chen on 2020/3/23
*/
public class HyperKit {
/**
* 写超链的内容
*
* @param g 超级链接的集合
* @param repo
* @return JSONArray转化的字符串
* @throws JSONException JSON异常 J
*/
public static String writeJSLinkContent(NameJavaScriptGroup g, Repository repo) throws JSONException {
return HyperlinkUtils.writeJSLinkContent(g, repo);
}
/**
* 把超链转化成json
*
* @param g 超链
* @param repo
* @return json对象
* @throws JSONException JSON异常
*/
public static JSONArray createJSLink(NameJavaScriptGroup g, Repository repo) throws JSONException {
return HyperlinkUtils.createJSLink(g, repo);
}
}

72
src/test/java/com/fanruan/api/cluster/ClusterBridgeKitTest.java

@ -0,0 +1,72 @@
package com.fanruan.api.cluster;
import com.fr.cluster.ClusterBridge;
import com.fr.cluster.core.ClusterNode;
import com.fr.cluster.core.ClusterView;
import com.fr.stable.Filter;
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import java.util.ArrayList;
import java.util.List;
/**
* @author Lucian.Chen
* @version 10.0
* Created by Lucian.Chen on 2020/3/24
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(ClusterBridge.class)
public class ClusterBridgeKitTest {
@Test
public void testGetView() {
ClusterView view = EasyMock.mock(ClusterView.class);
PowerMock.mockStatic(ClusterBridge.class);
EasyMock.expect(ClusterBridge.getView()).andReturn(view).anyTimes();
Filter filter = EasyMock.createMock(Filter.class);
ClusterNode node1 = EasyMock.mock(ClusterNode.class);
ClusterNode node2 = EasyMock.mock(ClusterNode.class);
ClusterNode node3 = EasyMock.mock(ClusterNode.class);
List<ClusterNode> list1 = new ArrayList<>();
List<ClusterNode> list2 = new ArrayList<>();
list1.add(node1);
list1.add(node2);
list2.add(node3);
EasyMock.expect(view.getCurrent()).andReturn(node1).once();
EasyMock.expect(view.getNodeById("1")).andReturn(node2).once();
EasyMock.expect(view.listNodes()).andReturn(list1).once();
EasyMock.expect(view.listNodes(filter)).andReturn(list2).once();
EasyMock.replay(view, filter, node1, node2, node3);
PowerMock.replay(ClusterBridge.class);
Assert.assertEquals(ClusterBridgeKit.getCurrentNode(), node1);
Assert.assertEquals(ClusterBridgeKit.getNodeById("1"), node2);
Assert.assertEquals(ClusterBridgeKit.listNodes(), list1);
Assert.assertEquals(ClusterBridgeKit.listNodes(filter), list2);
EasyMock.verify(view, filter, node1, node2, node3);
PowerMock.verify(ClusterBridge.class);
}
@Test
public void testIsClusterMode() {
PowerMock.mockStatic(ClusterBridge.class);
EasyMock.expect(ClusterBridge.isClusterMode()).andReturn(true).once();
EasyMock.expect(ClusterBridge.isClusterMode()).andReturn(false).once();
PowerMock.replay(ClusterBridge.class);
Assert.assertTrue(ClusterBridgeKit.isClusterMode());
Assert.assertFalse(ClusterBridgeKit.isClusterMode());
PowerMock.verify(ClusterBridge.class);
}
}

44
src/test/java/com/fanruan/api/cluster/state/MachineKitTest.java

@ -0,0 +1,44 @@
package com.fanruan.api.cluster.state;
import com.fr.cluster.engine.core.jchannel.MachineMarker;
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
import org.powermock.modules.junit4.PowerMockRunner;
/**
* @author Lucian.Chen
* @version 10.0
* Created by Lucian.Chen on 2020/3/24
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(MachineMarker.class)
@SuppressStaticInitializationFor("com.fr.cluster.engine.core.jchannel.MachineMarker")
public class MachineKitTest {
@Test
public void testCurrentID() {
PowerMock.mockStatic(MachineMarker.class);
EasyMock.expect(MachineMarker.currentID()).andReturn("1").anyTimes();
PowerMock.replay(MachineMarker.class);
Assert.assertEquals(MachineKit.currentID(), "1");
PowerMock.verify(MachineMarker.class);
}
@Test
public void testCurrentName() {
PowerMock.mockStatic(MachineMarker.class);
EasyMock.expect(MachineMarker.currentName()).andReturn("1").anyTimes();
PowerMock.replay(MachineMarker.class);
Assert.assertEquals(MachineKit.currentName(), "1");
PowerMock.verify(MachineMarker.class);
}
}

65
src/test/java/com/fanruan/api/conf/xml/XmlHolderKitTest.java

@ -0,0 +1,65 @@
package com.fanruan.api.conf.xml;
import java.util.ArrayList;
import java.util.List;
import com.fanruan.api.conf.impl.xml.XmlColConf;
import com.fanruan.api.conf.impl.xml.XmlConf;
import com.fr.stable.xml.XMLable;
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
/**
* @author Lucian.Chen
* @version 10.0
* Created by Lucian.Chen on 2020/3/24
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({XmlHolderKit.class})
public class XmlHolderKitTest {
@Test
public void testOjb() throws Exception {
XMLable xmlable = EasyMock.createMock(XMLable.class);
XmlConf xmlConf = EasyMock.createMock(XmlConf.class);
PowerMock.expectNew(XmlConf.class, xmlable, XMLable.class, "A").andReturn(xmlConf);
EasyMock.replay(xmlable, xmlConf);
PowerMock.replay(XmlConf.class);
Assert.assertEquals(XmlHolderKit.obj(xmlable, XMLable.class, "A"), xmlConf);
EasyMock.verify(xmlable, xmlConf);
PowerMock.verify(XmlConf.class);
}
@Test
public void testCollection() throws Exception {
XmlColConf xmlColConf1 = EasyMock.createMock(XmlColConf.class);
XmlColConf xmlColConf2 = EasyMock.createMock(XmlColConf.class);
List<XMLable> list = new ArrayList<>();
PowerMock.expectNew(XmlColConf.class, list, XMLable.class, true).andReturn(xmlColConf1).times(2);
PowerMock.expectNew(XmlColConf.class, list, XMLable.class, false).andReturn(xmlColConf2).once();
EasyMock.replay(xmlColConf1, xmlColConf2);
PowerMock.replay(XmlColConf.class);
Assert.assertEquals(XmlHolderKit.collection(list, XMLable.class), xmlColConf1);
Assert.assertEquals(XmlHolderKit.collection(list, XMLable.class, true), xmlColConf1);
Assert.assertEquals(XmlHolderKit.collection(list, XMLable.class, false), xmlColConf2);
EasyMock.verify(xmlColConf1, xmlColConf2);
PowerMock.verify(XmlColConf.class);
}
}

59
src/test/java/com/fanruan/api/decision/CommonKitTest.java

@ -0,0 +1,59 @@
package com.fanruan.api.decision;
import com.fr.base.Base64;
import com.fr.base.ServerConfig;
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.UnsupportedEncodingException;
/**
* @author Lucian.Chen
* @version 10.0
* Created by Lucian.Chen on 2020/3/24
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(ServerConfig.class)
public class CommonKitTest {
@Test
public void testIsDefaultPassword() {
Assert.assertTrue(CommonKit.isDefaultPasswordHolderString("********"));
}
@Test
public void testFetchDefaultPassword() {
Assert.assertEquals(CommonKit.fetchDefaultPasswordHolderString(), "********");
}
@Test
public void testGetBase64DecodeStr() throws UnsupportedEncodingException {
ServerConfig serverConfig = EasyMock.createMock(ServerConfig.class);
PowerMock.mockStatic(ServerConfig.class);
EasyMock.expect(ServerConfig.getInstance()).andReturn(serverConfig).anyTimes();
EasyMock.expect(serverConfig.getServerCharset()).andReturn("utf-8").anyTimes();
EasyMock.replay(serverConfig);
PowerMock.replay(ServerConfig.class);
String result = new String(Base64.decode("a"), "utf-8");
Assert.assertEquals(CommonKit.getBase64DecodeStr("a"), result);
Assert.assertEquals(CommonKit.getBase64DecodeStr(""), "");
EasyMock.verify(serverConfig);
PowerMock.verify(ServerConfig.class);
}
@Test
public void testEncode() {
Image im = new BufferedImage(1, 1, 1);
String result = Base64.encode(im, "");
Assert.assertEquals(result, CommonKit.encode(im, ""));
}
}

19
src/test/java/com/fanruan/api/decision/monitor/RuntimeMemScoreKitTest.java

@ -0,0 +1,19 @@
package com.fanruan.api.decision.monitor;
import com.fr.decision.system.monitor.gc.load.RuntimeMemScoreProvider;
import org.junit.Assert;
import org.junit.Test;
/**
* @author Lucian.Chen
* @version 10.0
* Created by Lucian.Chen on 2020/3/24
*/
public class RuntimeMemScoreKitTest {
@Test
public void testGetLoadScore() {
Assert.assertEquals(RuntimeMemScoreProvider.getLoadScore(), RuntimeMemScoreKit.getLoadScore());
}
}

12
src/test/java/com/fanruan/api/util/ArrayKitTest.java

@ -149,4 +149,16 @@ public class ArrayKitTest extends Prepare {
Assert.assertEquals(ArrayKit.getLength(null),0); Assert.assertEquals(ArrayKit.getLength(null),0);
Assert.assertEquals(ArrayKit.getLength(b),2); Assert.assertEquals(ArrayKit.getLength(b),2);
} }
@Test
public void testInsert() {
Integer[] array1 = new Integer[] {0, 1, 2};
Integer[] result1 = new Integer[] {0, 7, 8, 1, 2};
String[] array2 = new String[] {"1", "2"};
String[] result2 = new String[] {"3", "1", "2"};
Assert.assertEquals(ArrayKit.insert(1, array1, 7, 8), result1);
Assert.assertEquals(ArrayKit.insert(0, array2, "3"), result2);
}
} }

17
src/test/java/com/fanruan/api/util/AssistKitTest.java

@ -1,6 +1,7 @@
package com.fanruan.api.util; package com.fanruan.api.util;
import com.fr.event.Null; import com.fr.event.Null;
import com.fr.stable.AssistUtils;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -65,4 +66,20 @@ public class AssistKitTest {
Assert.assertEquals(Arrays.hashCode(a), AssistKit.hashCode(s)); Assert.assertEquals(Arrays.hashCode(a), AssistKit.hashCode(s));
Assert.assertEquals(0, AssistKit.hashCode(null)); Assert.assertEquals(0, AssistKit.hashCode(null));
} }
@Test
public void testEqualsFloat() {
float f1 = 0.6f;
float f2 = 0.6f;
float f3 = 0.6001f;
float f4 = 0.601f;
float f5 = 0.602f;
float delta = 0.001f;
Assert.assertTrue(AssistKit.equalsFloat(f1, f2, delta));
Assert.assertTrue(AssistKit.equalsFloat(f1, f3, delta));
Assert.assertTrue(AssistKit.equalsFloat(f1, f4, delta));
Assert.assertFalse(AssistKit.equalsFloat(f1, f5, delta));
}
} }

19
src/test/java/com/fanruan/api/util/FineCollectionKitTest.java

@ -0,0 +1,19 @@
package com.fanruan.api.util;
import com.fr.collections.FineCollections;
import org.junit.Assert;
import org.junit.Test;
/**
* @author Lucian.Chen
* @version 10.0
* Created by Lucian.Chen on 2020/3/24
*/
public class FineCollectionKitTest {
@Test
public void testGetClient() {
Assert.assertEquals(FineCollections.getInstance().getClient(), FineCollectionKit.getClient());
}
}

8
src/test/java/com/fanruan/api/util/GeneralKitTest.java

@ -2,6 +2,8 @@ package com.fanruan.api.util;
import com.fanruan.api.Prepare; import com.fanruan.api.Prepare;
import com.fr.general.GeneralUtils; import com.fr.general.GeneralUtils;
import com.fr.license.utils.JsonUtil;
import com.fr.stable.StableUtils;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -73,4 +75,10 @@ public class GeneralKitTest extends Prepare {
Assert.assertEquals(GeneralKit.pathJoin(strArray), "abc/def"); Assert.assertEquals(GeneralKit.pathJoin(strArray), "abc/def");
} }
@Test
public void testClassForName() throws ClassNotFoundException {
String className = "com.fanruan.api.util.GeneralKitTest";
Assert.assertEquals(GeneralKit.classForName(className), StableUtils.classForName(className));
}
} }

62
src/test/java/com/fanruan/api/util/HyperKitTest.java

@ -0,0 +1,62 @@
package com.fanruan.api.util;
import com.fanruan.api.json.JSONKit;
import com.fr.js.HyperlinkUtils;
import com.fr.js.NameJavaScriptGroup;
import com.fr.json.JSONArray;
import com.fr.stable.web.Repository;
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
/**
* @author Lucian.Chen
* @version 10.0
* Created by Lucian.Chen on 2020/3/24
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({HyperlinkUtils.class})
public class HyperKitTest {
@Test
public void testWriteJS() {
NameJavaScriptGroup g = EasyMock.createMock(NameJavaScriptGroup.class);
Repository repo = EasyMock.createMock(Repository.class);
PowerMock.mockStatic(HyperlinkUtils.class);
EasyMock.expect(HyperlinkUtils.writeJSLinkContent(g, repo)).andReturn("A").once();
EasyMock.expect(HyperlinkUtils.writeJSLinkContent(g, repo)).andReturn("B").once();
EasyMock.replay(g, repo);
PowerMock.replay(HyperlinkUtils.class);
Assert.assertEquals(HyperKit.writeJSLinkContent(g, repo), "A");
Assert.assertEquals(HyperKit.writeJSLinkContent(g, repo), "B");
EasyMock.verify(g, repo);
PowerMock.verify(HyperlinkUtils.class);
}
@Test
public void testCreateJSLink() {
JSONArray array1 = JSONKit.createJSONArray("[]");
JSONArray array2 = JSONKit.createJSONArray("[{\"1\":\"a\"}, {\"1\":\"b\"}]");
NameJavaScriptGroup g = EasyMock.createMock(NameJavaScriptGroup.class);
Repository repo = EasyMock.createMock(Repository.class);
PowerMock.mockStatic(HyperlinkUtils.class);
EasyMock.expect(HyperlinkUtils.createJSLink(g, repo)).andReturn(array1).once();
EasyMock.expect(HyperlinkUtils.createJSLink(g, repo)).andReturn(array2).once();
EasyMock.replay(g, repo);
PowerMock.replay(HyperlinkUtils.class);
Assert.assertEquals(HyperKit.createJSLink(g, repo), array1);
Assert.assertEquals(HyperKit.createJSLink(g, repo), array2);
EasyMock.verify(g, repo);
PowerMock.verify(HyperlinkUtils.class);
}
}

2
src/test/java/com/fanruan/api/util/IOKitTest.java

@ -30,7 +30,7 @@ public class IOKitTest extends Prepare {
@Test @Test
public void readIcon() { public void readIcon() {
Assert.assertEquals((IOKit.readIcon("/com/fanruan/api/util/close.png")).getIconHeight(),(new ImageIcon(IOUtils.readImageWithCache("/com/fanruan/api/util/close.png")).getIconHeight())); Assert.assertEquals((IOKit.readIcon("/com/fanruan/api/util/close.png")).getIconHeight(), IOUtils.readIcon("/com/fanruan/api/util/close.png").getIconHeight());
} }
@Test @Test

Loading…
Cancel
Save