Browse Source

release1.0

master
felix xia 5 years ago
parent
commit
de1a0e2dcc
  1. 13
      .gitee/ISSUE_TEMPLATE.zh-CN.md
  2. 15
      .gitee/PULL_REQUEST_TEMPLATE.zh-CN.md
  3. 22
      build.xml
  4. BIN
      document/digitroll.png
  5. 15
      document/使用手册.txt
  6. 18
      plugin-widget-digitroll.iml
  7. 52
      plugin-widget-digitroll10.iml
  8. 12
      plugin.xml
  9. 14
      pom.xml
  10. 319
      src/com/fr/plugin/widget/digitroll/DigitRollWidget.java
  11. 19
      src/com/fr/plugin/widget/digitroll/JavaScriptFileLoader.java
  12. 32
      src/com/fr/plugin/widget/digitroll/OptionProvider.java
  13. 20
      src/com/fr/plugin/widget/digitroll/Util.java
  14. 321
      src/com/fr/plugin/widget/digitroll/Widget.java
  15. 84
      src/com/fr/plugin/widget/digitroll/WidgetUI.java
  16. 28
      src/com/fr/plugin/widget/digitroll/editor/DigitRollAlign.java
  17. BIN
      src/com/fr/plugin/widget/digitroll/images/digitroll_display.png
  18. BIN
      src/com/fr/plugin/widget/digitroll/images/digitroll_icon.png
  19. 7
      src/com/fr/plugin/widget/digitroll/locale/digitroll.properties
  20. 7
      src/com/fr/plugin/widget/digitroll/locale/digitroll_zh_CN.properties
  21. 21
      src/com/fr/plugin/widget/digitroll/ui/DecimalPlacesEditor.java
  22. 23
      src/com/fr/plugin/widget/digitroll/ui/DigitRollDataSourceEditor.java
  23. 88
      src/com/fr/plugin/widget/digitroll/ui/DigitRollWidgetUI.java
  24. 12
      src/com/fr/plugin/widget/digitroll/web/countUp.js
  25. 41
      src/com/fr/plugin/widget/digitroll/web/widget.digitRoll.js

13
.gitee/ISSUE_TEMPLATE.zh-CN.md

@ -1,13 +0,0 @@
### 该问题是怎么引起的?
### 重现步骤
### 报错信息

15
.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md

@ -1,15 +0,0 @@
### 该Pull Request关联的Issue
### 修改描述
### 测试用例
### 修复效果的截屏

22
build.xml

@ -1,14 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="jar" name="plugin">
<!-- JDK路径,根据自己机器上实际位置修改-->
<property name="jdk.home" value="D:\devTools\Java\jdk1.8.0_151\"/>
<property name="jdk.home" value="D:/Java/jdk1.8.0_25"/>
<property name="libs" value="${basedir}/lib"/>
<property name="publicLibs" value=""/>
<!--<property name="pubLib1" value="../lib-core"/>-->
<!--<property name="pubLib2" value="../lib-design"/>-->
<property name="pubLib2" value="../lib-design/jetty"/>
<property name="pubLib3" value="../lib-others"/>
<property name="reportLibs" value="${basedir}/../webroot/WEB-INF/lib"/>
<property name="destLoc" value="."/>
<property name="classes" value="classes"/>
<xmlproperty file="${basedir}/plugin.xml"/>
@ -17,7 +14,7 @@
<!-- 插件版本-->
<property name="plugin-version" value="${current-version}"/>
<!-- 插件名字-->
<property name="plugin-name" value="widget-flipconvert"/>
<property name="plugin-name" value="widget-digitroll"/>
<property name="plugin-jar" value="fr-plugin-${plugin-name}-${plugin-version}.jar"/>
<target name="prepare">
@ -27,19 +24,10 @@
<delete dir="${destLoc}/${plugin.name}"/>
</target>
<path id="compile.classpath">
<fileset dir="${libs}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${publicLibs}">
<include name="**/*.jar"/>
</fileset>
<!--<fileset dir="${pubLib1}">
<include name="**/*.jar"/>
</fileset>-->
<fileset dir="${pubLib2}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${pubLib3}">
<fileset dir="${reportLibs}">
<include name="**/*.jar"/>
</fileset>
</path>
@ -125,5 +113,7 @@
</zip>
<xmlproperty file="${basedir}/plugin.xml"/>
<move file="${plugin-folder}.zip" todir="${destLoc}/${plugin.name}"/>
<delete dir="${plugin-folder}"/>
<delete file="${basedir}/${plugin-jar}"/>
</target>
</project>

BIN
document/digitroll.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

15
document/使用手册.txt

@ -0,0 +1,15 @@
数字滚动控件使用手册
数字滚动控件,用于决策报表中以滚动的方式显示数据源中的数字。
一、设置数据源
数据源有两种:1、通过公式生成随机数;2、从数据集读取数据。数据可以是整数,小数。
二、属性设置
1、持续时间:设置数据滚动动画的持续时间。
2、前/后缀:设置显示在数字前/后的字符。
3、文字大小:调整数字的大小。
3、文字颜色。
4、背景颜色。
5、分组:勾选分组后,10000显示为10,000
6、小数位数:设置小数点后显示的位数。

18
plugin-widget-digitroll.iml

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager">
<output url="file://$MODULE_DIR$/../project/out/production/plugin-widget-digitroll" />
<output-test url="file://$MODULE_DIR$/../project/out/test/plugin-widget-digitroll" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="lib" level="project" />
<orderEntry type="module" module-name="designer" />
<orderEntry type="module" module-name="designer_base" />
<orderEntry type="module" module-name="designer_chart" />
<orderEntry type="module" module-name="designer_form" />
</component>
</module>

52
plugin-widget-digitroll10.iml

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6">
<output url="file://$MODULE_DIR$/../webroot/WEB-INF/plugins/plugin-com.fr.plugin.widget.digitroll.v10-1.0/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
<excludeFolder url="file://$MODULE_DIR$/webroot/WEB-INF/classes" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: com.fr.third:fine-third:10.0-RELEASE-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: com.fr.activator:fine-activator:10.0-RELEASE-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: com.fr.core:fine-core:10.0-RELEASE-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-all:4.1.17" level="project" />
<orderEntry type="library" name="Maven: com.fr.webui:fine-webui:10.0-RELEASE-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: com.fr.datasource:fine-datasource:10.0-RELEASE-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: com.fr.decision:fine-decision:10.0-RELEASE-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: com.fr.decision:fine-decision-report:10.0-RELEASE-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: com.fr.schedule:fine-schedule:10.0-RELEASE-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: com.fr.schedule:fine-schedule-report:10.0-RELEASE-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: com.fr.intelligence:fine-swift:10.0-RELEASE-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: com.fineio:fineio:2.0-RELEASE-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: com.fr.third.server:servlet-api:3.0" level="project" />
<orderEntry type="library" name="Maven: com.fr.intelligence:fine-accumulator:10.0-RELEASE-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: com.fr.report:fine-report-engine:10.0-RELEASE-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: com.fr.report:fine-report-designer:10.0-RELEASE-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: io.socket:socket.io-client:0.7.0" level="project" />
<orderEntry type="library" name="Maven: io.socket:engine.io-client:0.7.0" level="project" />
<orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp-ws:3.0.1" level="project" />
<orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:3.0.1" level="project" />
<orderEntry type="library" name="Maven: com.squareup.okio:okio:1.6.0" level="project" />
<orderEntry type="library" name="Maven: org.json:json:20090211" level="project" />
<orderEntry type="library" name="Maven: org.aspectj:aspectjrt:1.6.9" level="project" />
<orderEntry type="library" name="Maven: org.swingexplorer:swexpl:2.0" level="project" />
<orderEntry type="library" name="Maven: org.swingexplorer:swag:1.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat:tomcat-catalina:8.5.32" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat:tomcat-servlet-api:8.5.32" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat:tomcat-jsp-api:8.5.32" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat:tomcat-el-api:8.5.32" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat:tomcat-juli:8.5.32" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat:tomcat-annotations-api:8.5.32" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat:tomcat-api:8.5.32" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat:tomcat-jni:8.5.32" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat:tomcat-coyote:8.5.32" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat:tomcat-util:8.5.32" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat:tomcat-util-scan:8.5.32" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat:tomcat-jaspic-api:8.5.32" level="project" />
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:5.1.44" level="project" />
</component>
</module>

12
plugin.xml

@ -1,15 +1,15 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<plugin>
<id>com.fr.plugin.widget.digitroll</id>
<name><![CDATA[超酷数字滚动器]]></name>
<id>com.fr.plugin.widget.digitroll.v10</id>
<name><![CDATA[数字滚动器]]></name>
<active>yes</active>
<version>1.0</version>
<env-version>8.0</env-version>
<jartime>2017-8-05</jartime>
<env-version>10.0</env-version>
<jartime>2019-12-01</jartime>
<vendor>Felix</vendor>
<description><![CDATA[在表单中实现数字滚动效果的插件。该插件可以实现根据后台数据库的变化而滚动数字。]]></description>
<change-notes><![CDATA[
<p>[2018-07-13]Felix:首发</p>
<p>[2019-12-30]Felix:首发</p>
]]></change-notes>
<extra-core>
<LocaleFinder class="com.fr.plugin.widget.digitroll.LocaleFinder"/>
@ -23,7 +23,7 @@
<FormWidgetOptionProvider class="com.fr.plugin.widget.digitroll.OptionProvider"/>
</extra-designer>
<!--<function-recorder class="com.fr.plugin.widget.digitroll.FlipWidget"/>-->
<function-recorder class="com.fr.plugin.widget.digitroll.OptionProvider"/>
</plugin>

14
pom.xml

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.fr.plugin</groupId>
<artifactId>starter</artifactId>
<version>10.0</version>
</parent>
<packaging>jar</packaging>
<artifactId>plugin-widget-digitroll10</artifactId>
</project>

319
src/com/fr/plugin/widget/digitroll/DigitRollWidget.java

@ -0,0 +1,319 @@
package com.fr.plugin.widget.digitroll;
import com.fr.base.Formula;
import com.fr.base.ParameterMapNameSpace;
import com.fr.form.data.DataBinding;
import com.fr.form.ui.DataControl;
import com.fr.form.ui.DirectWriteEditor;
import com.fr.form.ui.Widget;
import com.fr.form.ui.WidgetValue;
import com.fr.form.ui.concept.data.ValueInitializer;
import com.fr.json.JSONArray;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
import com.fr.script.Calculator;
import com.fr.stable.ArrayUtils;
import com.fr.stable.CodeUtils;
import com.fr.stable.core.NodeVisitor;
import com.fr.stable.script.CalculatorProvider;
import com.fr.stable.web.Repository;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLableReader;
import com.fr.web.core.TemplateSessionIDInfo;
import com.fr.web.utils.WebUtils;
import javax.servlet.http.HttpServletRequest;
import java.awt.*;
public class DigitRollWidget extends DirectWriteEditor implements DataControl {
public static final String XTYPE = "digitroll";
public static final String DURATION = "duration";
public static final String FONT_SIZE = "fontSize";
public static final String FONT_COLOR = "fontColor";
public static final String BACKGROUND_COLOR = "backgroundColor";
public static final String PREFIX = "prefix";
public static final String SUFFIX = "suffix";
public static final String GROUP = "group";
public static final String DECIMAL_PALACES = "decimalPlaces";
public static final String DECIMAL = "decimal";
private ValueInitializer widgetValue;
private int duration;
private int fontSize;
private Object fontColor;
private Object backgroundColor;
private String prefix;
private String suffix;
private boolean group;
private int decimalPlaces;
public DigitRollWidget() {
widgetValue = new WidgetValue();
duration = 0;
fontSize = 70;
fontColor = new Color(204, 204, 204);
backgroundColor = new Color(51, 51, 51);
prefix = "";
suffix = "";
setGroup(true);
setDecimalPlaces(0);
}
public boolean isGroup() {
return group;
}
public void setGroup(boolean group) {
this.group = group;
}
public int getDecimalPlaces() {
return decimalPlaces;
}
public void setDecimalPlaces(int decimalPlaces) {
this.decimalPlaces = decimalPlaces;
}
public int getDuration() {
return this.duration;
}
public void setDuration(int duration) {
this.duration = duration;
}
public ValueInitializer getWidgetValue() {
return this.widgetValue;
}
public void setWidgetValue(ValueInitializer widgetValue) {
this.widgetValue = widgetValue;
}
public int getFontSize() {
return fontSize;
}
public void setFontSize(int fontSize) {
this.fontSize = fontSize;
}
public Object getFontColor() {
return fontColor;
}
public void setFontColor(Object fontColor) {
this.fontColor = fontColor;
}
public Object getBackgroundColor() {
return backgroundColor;
}
public void setBackgroundColor(Object backgroundColor) {
this.backgroundColor = backgroundColor;
}
public String getPrefix() {
return prefix;
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
public String getSuffix() {
return suffix;
}
public void setSuffix(String suffix) {
this.suffix = suffix;
}
@Override
public String getXType() {//控件类型,参考其他的案例,返回的是文本框
return XTYPE;
}
@Override
public int[] getValueType() {
return new int[]{TYPE_FORMULA, TYPE_DATABINDING};
}
@Override
public String[] dependence(CalculatorProvider calculatorProvider) {
return super.dependence(calculatorProvider);
}
@Override
public String getDataBindDefaultValue(CalculatorProvider calculatorProvider) {
return null;
}
/**
* 读取插件的值
*/
private int dataSetCursor = 0;
private double getWidgetValue(Calculator calculator) throws Exception {
double value = 0;
if (this.widgetValue.getValue() == null) {
value = 0;
} else if (this.widgetValue.getValue() instanceof Formula) {
Object v = calculator.eval((Formula) this.widgetValue.getValue());
value = Util.valueChangeToDouble(v);
} else if (this.widgetValue.getValue() instanceof DataBinding) {
calculator.setAttribute(Widget.NAME, this.getWidgetName().toUpperCase());
calculator.setAttribute(ValueInitializer.RETURN_ARRAY, true);
calculator.setAttribute(ValueInitializer.VALUE_REPEAT, true);
Object r = getWidgetValue().executeResult(calculator);
if (r instanceof Object[]) {
Object[] ra = (Object[]) r;
dataSetCursor %= ra.length;
Object val = ra[dataSetCursor++];
return Util.valueChangeToDouble(val);
} else {
return (Util.valueChangeToDouble(r));
}
}
return value;
}
@Override
public void createValueResult(CalculatorProvider calculatorProvider, JSONObject jsonObject) {
Object result = null;
try {
if (widgetValue.getValue() instanceof Formula) {
result = calculatorProvider.eval((Formula) widgetValue.getValue());
} else if (widgetValue.getValue() instanceof DataBinding) {
calculatorProvider.setAttribute(Widget.NAME, this.getWidgetName().toUpperCase());
calculatorProvider.setAttribute(ValueInitializer.RETURN_ARRAY, true);
calculatorProvider.setAttribute(ValueInitializer.VALUE_REPEAT, true);
result = getWidgetValue().executeResult(calculatorProvider);
}
jsonObject.put(this.widgetName.toUpperCase(), result == null ? 0 : result);
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
@Override
public String getFormatText() {
return "";
}
@Override
public JSONObject createJSONConfig(Repository repository,
Calculator calculator,
NodeVisitor visitor) throws JSONException {
JSONObject jsonConfig = super.createJSONConfig(repository, calculator, visitor);
Object value = jsonConfig.get("value");
if (value != null) {
Double v = 0d;
try {
JSONArray jsonArray = (JSONArray) value;
v = jsonArray.getDouble(0);
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
jsonConfig.put("value", v);
}
jsonConfig.put(DURATION, this.value2Config(this.duration, calculator));
jsonConfig.put(PREFIX, getPrefix());
jsonConfig.put(SUFFIX, getSuffix());
jsonConfig.put(FONT_COLOR, Util.colorValueToHexString(((Color) getFontColor()).getRGB()));
jsonConfig.put(BACKGROUND_COLOR, Util.colorValueToHexString(((Color) getBackgroundColor()).getRGB()));
jsonConfig.put(FONT_SIZE, getFontSize());
jsonConfig.put(GROUP, isGroup());
//jsonConfig.put(DECIMAL, (getDecimalPlaces() <= 0 ? false : true));
jsonConfig.put(DECIMAL_PALACES, getDecimalPlaces());
String[] dependence = this.dependence(calculator);
if (!ArrayUtils.isEmpty(dependence)) {
jsonConfig.put("dependence", dependence);
}
return jsonConfig;
}
@Override
public JSONArray createJSONData(TemplateSessionIDInfo sessionIDInfor,
Calculator calculator, HttpServletRequest request) throws Exception {
JSONArray jsonArray;
jsonArray = super.createJSONData(sessionIDInfor, calculator, request);
ParameterMapNameSpace parameterMapNameSpace = ParameterMapNameSpace.create(sessionIDInfor.getParameterMap4Execute());
DependenceNameSpace dependenceNameSpace = new DependenceNameSpace(CodeUtils.cjkDecode(WebUtils.getHTTPRequestParameter(request, "dependence")));
calculator.pushNameSpace(parameterMapNameSpace);
calculator.pushNameSpace(dependenceNameSpace);
JSONObject jsonObject = new JSONObject();
jsonObject.put("value", this.getWidgetValue(calculator));
jsonArray.put(jsonObject);
calculator.removeNameSpace(parameterMapNameSpace);
calculator.removeNameSpace(dependenceNameSpace);
return jsonArray;
}
@Override
public String[] supportedEvents() {
return new String[0];
}
@Override
public void readXML(XMLableReader reader) {
super.readXML(reader);
if (reader.isChildNode()) {
String tagName = reader.getTagName();
if (tagName.equals("DigitRollAttr")) {
String s = null;
if ((s = reader.getAttrAsString(DURATION, null)) != null) {
this.setDuration(Integer.parseInt(s));
}
if ((s = reader.getAttrAsString(FONT_SIZE, null)) != null) {
setFontSize(Integer.parseInt(s));
}
int color;
if ((color = reader.getAttrAsInt(FONT_COLOR, -1)) != -1) {
setFontColor(new Color(color));
}
if ((color = reader.getAttrAsInt(BACKGROUND_COLOR, -1)) != -1) {
setBackgroundColor(new Color(color));
}
setPrefix(reader.getAttrAsString(PREFIX, ""));
setSuffix(reader.getAttrAsString(SUFFIX, ""));
setDecimalPlaces(reader.getAttrAsInt(DECIMAL_PALACES, 0));
setGroup(reader.getAttrAsBoolean(GROUP, true));
} else if ("widgetValue".equals(tagName)) {
this.widgetValue = new WidgetValue();
reader.readXMLObject(this.widgetValue);
}
}
}
@Override
public void writeXML(XMLPrintWriter writer) {
super.writeXML(writer);
writer.startTAG("DigitRollAttr");
if (this.duration != 0) {
writer.attr(DURATION, this.getDuration());
}
writer.attr(FONT_SIZE, getFontSize());
writer.attr(FONT_COLOR, ((Color) getFontColor()).getRGB());
writer.attr(BACKGROUND_COLOR, ((Color) getBackgroundColor()).getRGB());
writer.attr(PREFIX, getPrefix());
writer.attr(SUFFIX, getSuffix());
writer.attr(GROUP, isGroup());
writer.attr(DECIMAL_PALACES, getDecimalPlaces());
writer.end();
if (this.widgetValue != null) {
this.widgetValue.writeXML(writer);
}
}
}

19
src/com/fr/plugin/widget/digitroll/JavaScriptFileLoader.java

@ -1,15 +1,30 @@
package com.fr.plugin.widget.digitroll;
import com.fr.general.Inter;
import com.fr.plugin.PluginLicense;
import com.fr.plugin.PluginLicenseManager;
import com.fr.stable.fun.Authorize;
import com.fr.stable.fun.impl.AbstractJavaScriptFileHandler;
import javax.swing.*;
@Authorize(
callSignKey = Constants.PLUGIN_ID
)
public class JavaScriptFileLoader extends AbstractJavaScriptFileHandler {
private PluginLicense license = PluginLicenseManager.getInstance().getPluginLicenseByID(Constants.PLUGIN_ID);
@Override
public String[] pathsForFiles() {
return new String[]{
"/com/fr/plugin/widget/digitroll/web/widget.digitRoll.js"};
if (license.isAvailable()) {
return new String[]{
"/com/fr/plugin/widget/digitroll/web/widget.digitRoll.js"};
} else {
JOptionPane.showMessageDialog(null
, Inter.getLocText("Plugin-DigitRoll_License_Expired")
, Inter.getLocText("Plugin-DigitRoll_License_Title")
, JOptionPane.PLAIN_MESSAGE);
return null;
}
}
}

32
src/com/fr/plugin/widget/digitroll/OptionProvider.java

@ -1,39 +1,23 @@
package com.fr.plugin.widget.digitroll;
import com.fr.design.fun.impl.AbstractFormWidgetOptionProvider;
import com.fr.form.ui.Widget;
import com.fr.general.Inter;
import com.fr.plugin.ExtraClassManager;
import com.fr.stable.fun.FunctionHelper;
import com.fr.stable.fun.FunctionProcessor;
import com.fr.stable.fun.impl.AbstractFunctionProcessor;
import com.fr.plugin.transform.ExecuteFunctionRecord;
import com.fr.plugin.transform.FunctionRecorder;
import com.fr.plugin.widget.digitroll.ui.DigitRollWidgetUI;
@FunctionRecorder
public class OptionProvider extends AbstractFormWidgetOptionProvider {
private static FunctionProcessor ONEFUNCTION = new AbstractFunctionProcessor() {
public int getId() {
return FunctionHelper.generateFunctionID(Constants.PLUGIN_ID);
}
public String toString() {
return Inter.getLocText("Plugin-DigitRoll_Widget");
}
};
@ExecuteFunctionRecord
@Override
public Class<? extends Widget> classForWidget() {
FunctionProcessor processor = ExtraClassManager.getInstance().getFunctionProcessor();
if (processor != null) {
processor.recordFunction(ONEFUNCTION);
}
return Widget.class;
public Class<? extends DigitRollWidget> classForWidget() {
return DigitRollWidget.class;
}
@Override
public Class<?> appearanceForWidget() {
//界面类
return WidgetUI.class;
return DigitRollWidgetUI.class;
}
@Override

20
src/com/fr/plugin/widget/digitroll/Util.java

@ -1,6 +1,7 @@
package com.fr.plugin.widget.digitroll;
import com.fr.base.FRContext;
import com.fr.log.FineLoggerFactory;
import java.math.BigDecimal;
@ -30,4 +31,23 @@ public class Util {
return value;
}
public static double valueChangeToDouble(Object o) {
double value = 0;
if (o instanceof Integer) {
value = ((Integer) o).doubleValue();
} else if (o instanceof BigDecimal) {
value = ((BigDecimal) o).doubleValue();
} else if (o instanceof Double) {
value = ((Double) o).doubleValue();
} else if (o instanceof String) {
try {
value = Double.parseDouble(o.toString());
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage());
}
}
return value;
}
}

321
src/com/fr/plugin/widget/digitroll/Widget.java

@ -1,321 +0,0 @@
package com.fr.plugin.widget.digitroll;
import com.fr.base.FRContext;
import com.fr.base.Formula;
import com.fr.base.ParameterMapNameSpace;
import com.fr.form.data.DataBinding;
import com.fr.form.ui.DataControl;
import com.fr.form.ui.DirectWriteEditor;
import com.fr.form.ui.WidgetValue;
import com.fr.general.Inter;
import com.fr.general.ModuleContext;
import com.fr.json.JSONArray;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
import com.fr.plugin.PluginLicense;
import com.fr.plugin.PluginLicenseManager;
import com.fr.script.Calculator;
import com.fr.stable.ArrayUtils;
import com.fr.stable.CodeUtils;
import com.fr.stable.core.NodeVisitor;
import com.fr.stable.script.CalculatorProvider;
import com.fr.stable.web.Repository;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLableReader;
import com.fr.web.core.SessionIDInfor;
import com.fr.web.utils.WebUtils;
import javax.servlet.http.HttpServletRequest;
import java.awt.*;
public class Widget extends DirectWriteEditor implements DataControl {
public static final int TYPE_YEAR_NONE = 8;
public static final String ALIGN = "align";
public static final String DURATION = "duration";
public static final String FONT_SIZE = "fontSize";
public static final String FONT_COLOR = "fontColor";
public static final String BACKGROUND_COLOR = "backgroundColor";
public static final String PREFIX = "prefix";
public static final String SUFFIX = "suffix";
public static final String CSS = "css";
private WidgetValue widgetValue = new WidgetValue();
private String align = new String();
private int duration = 0;
private int fontSize = 70;
private Object fontColor = new Color(204, 204, 204);
private Object backgroundColor = new Color(51, 51, 51);
private String prefix;
private String suffix;
public Widget() {
}
public String getAlign() {
return this.align;
}
public void setAlign(String align) {
this.align = align;
}
public int getDuration() {
return this.duration;
}
public void setDuration(int duration) {
this.duration = duration;
}
public WidgetValue getWidgetValue() {
return this.widgetValue;
}
public void setWidgetValue(WidgetValue widgetValue) {
this.widgetValue = widgetValue;
}
public int getFontSize() {
return fontSize;
}
public void setFontSize(int fontSize) {
this.fontSize = fontSize;
}
public Object getFontColor() {
return fontColor;
}
public void setFontColor(Object fontColor) {
this.fontColor = fontColor;
}
public Object getBackgroundColor() {
return backgroundColor;
}
public void setBackgroundColor(Object backgroundColor) {
this.backgroundColor = backgroundColor;
}
public String getPrefix() {
return prefix;
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
public String getSuffix() {
return suffix;
}
public void setSuffix(String suffix) {
this.suffix = suffix;
}
@Override
public String getXType() {//控件类型,参考其他的案例,返回的是文本框
return "digitroll";
}
@Override
// 数据源类型:空置,公式,字段
public int[] getValueType() {
return new int[]{TYPE_YEAR_NONE, TYPE_FORMULA, TYPE_DATABINDING};
}
@Override
public String[] dependence(CalculatorProvider calculatorProvider) {
return super.dependence(calculatorProvider);
}
private int getWidgetValueFM(Calculator calculator) throws Exception {
int value = 0;
if (this.widgetValue.getValue() == null) {
value = 0;
} else if (this.widgetValue.getValue() instanceof Formula) {
Object v = calculator.eval((Formula) this.widgetValue.getValue());
value = Util.valueChangeToInt(v);
} else if (this.widgetValue.getValue() instanceof DataBinding) {
value = this.getWidgetValueByBinding(calculator);
}
return value;
}
private int getWidgetValueByBinding(Calculator calculator) {
int value = 0;
WidgetValue.WidgetValueInfo valueInfo = new WidgetValue.WidgetValueInfo(this.getWidgetName());
Object result = this.getWidgetValue().createAttrResult(valueInfo, calculator, new JSONObject());
value = Util.valueChangeToInt(result);
return value;
}
@Override
public void createValueResult(DataControl dataControl, Calculator calculator,
JSONObject jsonObject, JSONObject jsonObject1) {
if (this.getWidgetValue() != null) {
WidgetValue.WidgetValueInfo valueInfo = new WidgetValue.WidgetValueInfo(this.getWidgetName());
Object result = this.getWidgetValue().createAttrResult(valueInfo, calculator, jsonObject1);
try {
jsonObject.put(this.widgetName.toUpperCase(), result == null ? "" : result);
} catch (JSONException e) {
FRContext.getLogger().error(e.getMessage(), e);
}
}
}
@Override
public String getFormatText() {
return "";
}
@Override
public JSONObject createJSONConfig(Repository repository,
Calculator calculator,
NodeVisitor visitor) throws JSONException {
// 许可证
PluginLicense pluginLicense = PluginLicenseManager.getInstance().getPluginLicenseByID(Constants.PLUGIN_ID);
if (pluginLicense.isAvailable()) {
JSONObject jsonConfig = super.createJSONConfig(repository, calculator, visitor);
try {
Object value = jsonConfig.get("value");
int v = Util.valueChangeToInt(value);
if (value == null) {
jsonConfig.remove("value");
} else if (value instanceof String) {
jsonConfig.put("value", (new JSONObject()).put("digitroll", v));
} else {
jsonConfig.put("value", v);
}
} catch (Exception e) {
e.printStackTrace();
}
if (this.align != null) {
jsonConfig.put(ALIGN, this.value2Config(this.align, calculator));
}
jsonConfig.put(DURATION, this.value2Config(this.duration, calculator));
jsonConfig.put(PREFIX, getPrefix());
jsonConfig.put(SUFFIX, getSuffix());
jsonConfig.put(CSS, buildCss());
String[] dependence = this.dependence(calculator);
if (!ArrayUtils.isEmpty(dependence)) {
jsonConfig.put("dependence", dependence);
}
return jsonConfig;
} else {
return licenseErr();
}
}
private String buildCss() {
StringBuilder css = new StringBuilder();
String fontClr = Util.colorValueToHexString(((Color) getFontColor()).getRGB());
String bgClr = Util.colorValueToHexString(((Color) getBackgroundColor()).getRGB());
css.append("color:" + fontClr + ';');
css.append("font-size:" + getFontSize() + ';');
css.append("background:" + bgClr + ";");
css.append("position:absolute;");
css.append("left:0px;");
css.append("top:0px;");
return css.toString();
}
@Override
public JSONArray createJSONData(SessionIDInfor sessionIDInfor,
Calculator calculator, HttpServletRequest request) throws Exception {
PluginLicense pluginLicense = PluginLicenseManager.getInstance().getPluginLicenseByID(Constants.PLUGIN_ID);
JSONArray errorMsg;
if (pluginLicense.isAvailable()) {
errorMsg = super.createJSONData(sessionIDInfor, calculator, request);
ParameterMapNameSpace parameterMapNameSpace = ParameterMapNameSpace.create(sessionIDInfor.getParameterMap4Execute());
DependenceNameSpace dependenceNameSpace = new DependenceNameSpace(CodeUtils.cjkDecode(WebUtils.getHTTPRequestParameter(request, "dependence")));
calculator.pushNameSpace(parameterMapNameSpace);
calculator.pushNameSpace(dependenceNameSpace);
JSONObject jsonObject = new JSONObject();
jsonObject.put("value", this.getWidgetValueFM(calculator));
errorMsg.put(jsonObject);
calculator.removeNameSpace(parameterMapNameSpace);
calculator.removeNameSpace(dependenceNameSpace);
return errorMsg;
} else {
errorMsg = new JSONArray();
errorMsg.put(licenseErr());
return errorMsg;
}
}
private JSONObject licenseErr() throws JSONException {
return (new JSONObject()).put("text", Inter.getLocText("Plugin-Flip_License_Expired"))
.put("value", Inter.getLocText("Plugin-Flip_License_Expired"));
}
private boolean isDesign() {
return ModuleContext.isModuleStarted("com.fr.design.module.DesignerModule");
}
@Override
public String[] supportedEvents() {
return new String[0];
}
@Override
public void readXML(XMLableReader reader) {
super.readXML(reader);
if (reader.isChildNode()) {
String tagName = reader.getTagName();
if (tagName.equals("DigitRollAttr")) {
String s = null;
if ((s = reader.getAttrAsString(ALIGN, null)) != null) {
this.setAlign(s);
}
if ((s = reader.getAttrAsString(DURATION, null)) != null) {
this.setDuration(Integer.parseInt(s));
}
if ((s = reader.getAttrAsString(FONT_SIZE, null)) != null) {
setFontSize(Integer.parseInt(s));
}
int color;
if ((color = reader.getAttrAsInt(FONT_COLOR, -1)) != -1) {
setFontColor(new Color(color));
}
if ((color = reader.getAttrAsInt(BACKGROUND_COLOR, -1)) != -1) {
setBackgroundColor(new Color(color));
}
} else if ("widgetValue".equals(tagName)) {
this.widgetValue = new WidgetValue();
reader.readXMLObject(this.widgetValue);
}
}
}
@Override
public void writeXML(XMLPrintWriter writer) {
super.writeXML(writer);
writer.startTAG("DigitRollAttr");
if (this.align != null) {
writer.attr(ALIGN, this.getAlign().toString());
}
if (this.duration != 0) {
writer.attr(DURATION, this.getDuration());
}
writer.attr(FONT_SIZE, getFontSize());
writer.attr(FONT_COLOR, ((Color) getFontColor()).getRGB());
writer.attr(BACKGROUND_COLOR, ((Color) getBackgroundColor()).getRGB());
writer.end();
if (this.widgetValue != null) {
this.widgetValue.writeXML(writer);
}
}
}

84
src/com/fr/plugin/widget/digitroll/WidgetUI.java

@ -1,84 +0,0 @@
package com.fr.plugin.widget.digitroll;
import com.fr.design.designer.creator.CRPropertyDescriptor;
import com.fr.design.designer.creator.XWidgetCreator;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.widget.editors.ColorEditor;
import com.fr.form.ui.Widget;
import com.fr.general.IOUtils;
import com.fr.general.Inter;
import com.fr.plugin.widget.digitroll.editor.DigitRollAlign;
import com.fr.plugin.widget.digitroll.editor.DigitRollDataSourceEditor;
import com.fr.stable.ArrayUtils;
import javax.swing.*;
import java.awt.*;
import java.beans.IntrospectionException;
public class WidgetUI extends XWidgetCreator {
private UITextField textField;
public WidgetUI(Widget widget, Dimension dimension) {
super(widget, dimension);
}
@Override
protected JComponent initEditor() {
//界面,就是在拖动到主面板上的时候,添加了一个LABLE控件,然后显示图标,并居中对齐
if (this.editor == null) {
this.editor = FRGUIPaneFactory.createBorderLayout_S_Pane();
UILabel label = new UILabel();
label.setIcon(IOUtils.readIcon("/com/fr/plugin/widget/digitroll/images/digitroll_display.png"));
label.setHorizontalAlignment(0);
label.setVerticalAlignment(0);
this.editor.add(label, "Center");
this.textField = new UITextField(5);
this.textField.setOpaque(false);
this.editor.add(this.textField, "South");
this.editor.setBackground(Color.WHITE);
}
return this.editor;
}
public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException {
return ArrayUtils.addAll(super.supportedDescriptor()
, new CRPropertyDescriptor[]{
(new CRPropertyDescriptor("widgetValue", this.data.getClass()))
.setI18NName(Inter.getLocText("Plugin-DigitRoll_DataSource"))
.setEditorClass(DigitRollDataSourceEditor.class)
.putKeyValue("category", "Advanced"),
(new CRPropertyDescriptor("align", this.data.getClass()))
.setI18NName(Inter.getLocText("Plugin-DigitRoll_AlignType"))
.setEditorClass(DigitRollAlign.class)
.putKeyValue("category", "Advanced"),
(new CRPropertyDescriptor("duration", this.data.getClass()))
.setI18NName(Inter.getLocText("Plugin-DigitRoll_Duration"))
.putKeyValue("category", "Advanced"),
(new CRPropertyDescriptor("prefix", this.data.getClass()))
.setI18NName(Inter.getLocText("Plugin-DigitRoll_Prefix"))
.putKeyValue("category", "Advanced"),
(new CRPropertyDescriptor("suffix", this.data.getClass()))
.setI18NName(Inter.getLocText("Plugin-DigitRoll_Suffix"))
.putKeyValue("category", "Advanced"),
(new CRPropertyDescriptor("fontSize", this.data.getClass()))
.setI18NName(Inter.getLocText("Plugin-DigitRoll_FontSize"))
.putKeyValue("category", "Advanced"),
(new CRPropertyDescriptor("fontColor", this.data.getClass()))
.setI18NName(Inter.getLocText("Plugin-DigitRoll_ColorFont"))
.setEditorClass(ColorEditor.class)
.putKeyValue("category", "Advanced"),
(new CRPropertyDescriptor("backgroundColor", this.data.getClass()))
.setI18NName(Inter.getLocText("Plugin-DigitRoll_ColorBackground"))
.setEditorClass(ColorEditor.class)
.putKeyValue("category", "Advanced")
}
);
}
public String getIconPath() {
return "com/fr/plugin/widget/digitroll/images/digitroll_icon.png";
}
}

28
src/com/fr/plugin/widget/digitroll/editor/DigitRollAlign.java

@ -1,28 +0,0 @@
package com.fr.plugin.widget.digitroll.editor;
import com.fr.design.mainframe.widget.editors.ComboEditor;
import com.fr.general.Inter;
import javax.swing.*;
import java.util.Vector;
public class DigitRollAlign extends ComboEditor {
public DigitRollAlign() {
}
public ComboBoxModel model() {
Vector<String> vector = new Vector();
vector.add(Inter.getLocText("Plugin-DigitRoll_AlignLeft"));
vector.add(Inter.getLocText("Plugin-DigitRoll_AlignCenter"));
vector.add(Inter.getLocText("Plugin-DigitRoll_AlignRight"));
return new DefaultComboBoxModel(vector);
}
/*public void setValue(Object o) {
this.comboBox.setSelectedItem(o);
}*/
/*public Object getValue() {
return this.comboBox.getSelectedItem();
}*/
}

BIN
src/com/fr/plugin/widget/digitroll/images/digitroll_display.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 9.4 KiB

BIN
src/com/fr/plugin/widget/digitroll/images/digitroll_icon.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 744 B

After

Width:  |  Height:  |  Size: 3.2 KiB

7
src/com/fr/plugin/widget/digitroll/local/digitroll.properties → src/com/fr/plugin/widget/digitroll/locale/digitroll.properties

@ -1,14 +1,17 @@
Plugin-DigitRoll_Widget=DigitRoll
Plugin-DigitRoll_Advanced=Advanced
Plugin-DigitRoll_License_Expired=Expired
Plugin-DigitRoll_License_Title=License
Plugin-DigitRoll_DataSource=DataSource
Plugin-DigitRoll_AlignType=AlignType
Plugin-DigitRoll_Duration=Duration
Plugin-DigitRoll_Prefix=Prefix
Plugin-DigitRoll_Suffix=Suffix
Plugin-DigitRoll_None=NoneValue
Plugin-DigitRoll_Formula=Formula
Plugin-DigitRoll_AlignLeft=Left
Plugin-DigitRoll_AlignCenter=Center
Plugin-DigitRoll_AlignRight=Right
Plugin-DigitRoll_FontSize = FontSize
Plugin-DigitRoll_ColorFont=FontColor
Plugin-DigitRoll_ColorBackground=BackgroundColor
Plugin-DigitRoll_Group=Use Grouping
Plugin-DigitRoll_DecimalPlaces=Decimal Places

7
src/com/fr/plugin/widget/digitroll/local/digitroll_zh_CN.properties → src/com/fr/plugin/widget/digitroll/locale/digitroll_zh_CN.properties

@ -1,14 +1,17 @@
Plugin-DigitRoll_Widget=\u6EDA\u52A8\u6570\u5B57
Plugin-DigitRoll_Advanced=\u9AD8\u7EA7
Plugin-DigitRoll_License_Expired=\u8BB8\u53EF\u8BC1\u5DF2\u8FC7\u671F
Plugin-DigitRoll_License_Title=\u8BB8\u53EF\u8BC1
Plugin-DigitRoll_DataSource=\u6570\u636E\u6E90
Plugin-DigitRoll_AlignType=\u5BF9\u9F50\u65B9\u5F0F
Plugin-DigitRoll_Duration=\u6301\u7EED\u65F6\u95F4\uFF08\u79D2\uFF09
Plugin-DigitRoll_Prefix=\u524D\u7F00
Plugin-DigitRoll_Suffix=\u540E\u7F00
Plugin-DigitRoll_None=\u7A7A\u503C
Plugin-DigitRoll_Formula=\u516C\u5F0F
Plugin-DigitRoll_AlignLeft=\u5DE6\u5BF9\u9F50
Plugin-DigitRoll_AlignCenter=\u5C45\u4E2D\u5BF9\u9F50
Plugin-DigitRoll_AlignRight=\u53F3\u5BF9\u9F50
Plugin-DigitRoll_FontSize = \u6587\u5B57\u5927\u5C0F
Plugin-DigitRoll_ColorFont=\u6587\u5B57\u989C\u8272
Plugin-DigitRoll_ColorBackground=\u80CC\u666F\u989C\u8272
Plugin-DigitRoll_Group=\u5206\u7EC4
Plugin-DigitRoll_DecimalPlaces=\u5C0F\u6570\u4F4D\u6570

21
src/com/fr/plugin/widget/digitroll/ui/DecimalPlacesEditor.java

@ -0,0 +1,21 @@
package com.fr.plugin.widget.digitroll.ui;
import com.fr.design.mainframe.widget.editors.ComboEditor;
import javax.swing.*;
import java.util.Vector;
public class DecimalPlacesEditor extends ComboEditor {
public DecimalPlacesEditor() {
}
@Override
public ComboBoxModel model() {
Vector<Integer> vector = new Vector<Integer>();
for (int i = 0; i < 11; i++) {
vector.add(i);
}
return new DefaultComboBoxModel(vector);
}
}

23
src/com/fr/plugin/widget/digitroll/editor/DigitRollDataSourceEditor.java → src/com/fr/plugin/widget/digitroll/ui/DigitRollDataSourceEditor.java

@ -1,10 +1,9 @@
package com.fr.plugin.widget.digitroll.editor;
package com.fr.plugin.widget.digitroll.ui;
import com.fr.design.Exception.ValidationException;
import com.fr.design.editor.ValueEditorPane;
import com.fr.design.editor.editor.Editor;
import com.fr.design.editor.editor.FormulaEditor;
import com.fr.design.editor.editor.NoneEditor;
import com.fr.design.mainframe.widget.editors.AbstractPropertyEditor;
import com.fr.design.mainframe.widget.editors.DataBindingEditor;
import com.fr.design.mainframe.widget.editors.ServerDataBindingEditor;
@ -20,7 +19,7 @@ import java.beans.PropertyChangeListener;
public class DigitRollDataSourceEditor extends AbstractPropertyEditor {
private DataControl widget;
private ValueEditorPane wep;
private ValueEditorPane pane;
public DigitRollDataSourceEditor(Object o) {
this.widget = (DataControl) o;
@ -37,8 +36,8 @@ public class DigitRollDataSourceEditor extends AbstractPropertyEditor {
});
}
this.wep = new ValueEditorPane(editors);
this.wep.addPropertyChangeListener("value", new PropertyChangeListener() {
this.pane = new ValueEditorPane(editors);
this.pane.addPropertyChangeListener("value", new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
DigitRollDataSourceEditor.this.firePropertyChanged();
}
@ -58,12 +57,10 @@ public class DigitRollDataSourceEditor extends AbstractPropertyEditor {
public static Editor createWidgetValueEditorByType(int type, boolean onlyServer) {
switch (type) {
case 2:
case DataControl.TYPE_DATABINDING:
return (Editor) (onlyServer ? new ServerDataBindingEditor() : new DataBindingEditor());
case 3:
return new FormulaEditor(Inter.getLocText("Parameter-Formula"));
case 8:
return new NoneEditor((String) null, Inter.getLocText("Plugin-DigitRoll_None"));
case DataControl.TYPE_FORMULA:
return new FormulaEditor(Inter.getLocText("Plugin-DigitRoll_Formula"));
default:
return null;
}
@ -73,16 +70,16 @@ public class DigitRollDataSourceEditor extends AbstractPropertyEditor {
}
public Component getCustomEditor() {
return this.wep;
return this.pane;
}
public Object getValue() {
return new WidgetValue(this.wep.update());
return new WidgetValue(this.pane.update());
}
public void setValue(Object value) {
if (value != null) {
this.wep.populate(((WidgetValue) value).getValue());
this.pane.populate(((WidgetValue) value).getValue());
}
}
}

88
src/com/fr/plugin/widget/digitroll/ui/DigitRollWidgetUI.java

@ -0,0 +1,88 @@
package com.fr.plugin.widget.digitroll.ui;
import com.fr.design.designer.creator.CRPropertyDescriptor;
import com.fr.design.designer.creator.XWidgetCreator;
import com.fr.design.editor.editor.SpinnerIntegerEditor;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.widget.editors.BooleanEditor;
import com.fr.design.mainframe.widget.editors.ColorEditor;
import com.fr.form.ui.Widget;
import com.fr.general.IOUtils;
import com.fr.general.Inter;
import com.fr.stable.ArrayUtils;
import javax.swing.*;
import java.awt.*;
import java.beans.IntrospectionException;
import static com.fr.plugin.widget.digitroll.DigitRollWidget.*;
public class DigitRollWidgetUI extends XWidgetCreator {
private UITextField textField;
public DigitRollWidgetUI(Widget widget, Dimension dimension) {
super(widget, dimension);
}
@Override
protected JComponent initEditor() {
if (this.editor == null) {
this.editor = FRGUIPaneFactory.createBorderLayout_S_Pane();
UILabel label = new UILabel();
label.setIcon(IOUtils.readIcon("/com/fr/plugin/widget/digitroll/images/digitroll_display.png"));
label.setHorizontalAlignment(0);
label.setVerticalAlignment(0);
this.editor.add(label, "Center");
this.textField = new UITextField(5);
this.textField.setOpaque(false);
this.editor.add(this.textField, "South");
this.editor.setBackground(Color.WHITE);
}
return this.editor;
}
public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException {
String advanced = Inter.getLocText("Plugin-DigitRoll_Advanced");
return ArrayUtils.addAll(super.supportedDescriptor(),
(new CRPropertyDescriptor("widgetValue", this.data.getClass()))
.setI18NName(Inter.getLocText("Plugin-DigitRoll_DataSource"))
.setEditorClass(DigitRollDataSourceEditor.class)
.putKeyValue("category", advanced),
(new CRPropertyDescriptor(DURATION, this.data.getClass()))
.setI18NName(Inter.getLocText("Plugin-DigitRoll_Duration"))
.putKeyValue("category", advanced),
(new CRPropertyDescriptor(PREFIX, this.data.getClass()))
.setI18NName(Inter.getLocText("Plugin-DigitRoll_Prefix"))
.putKeyValue("category", advanced),
(new CRPropertyDescriptor(SUFFIX, this.data.getClass()))
.setI18NName(Inter.getLocText("Plugin-DigitRoll_Suffix"))
.putKeyValue("category", advanced),
(new CRPropertyDescriptor(FONT_SIZE, this.data.getClass()))
.setI18NName(Inter.getLocText("Plugin-DigitRoll_FontSize"))
.putKeyValue("category", advanced),
(new CRPropertyDescriptor(FONT_COLOR, this.data.getClass()))
.setI18NName(Inter.getLocText("Plugin-DigitRoll_ColorFont"))
.setEditorClass(ColorEditor.class)
.putKeyValue("category", advanced),
(new CRPropertyDescriptor(BACKGROUND_COLOR, this.data.getClass()))
.setI18NName(Inter.getLocText("Plugin-DigitRoll_ColorBackground"))
.setEditorClass(ColorEditor.class)
.putKeyValue("category", advanced),
(new CRPropertyDescriptor(GROUP, this.data.getClass()))
.setI18NName(Inter.getLocText("Plugin-DigitRoll_Group"))
.setEditorClass(BooleanEditor.class)
.putKeyValue("category", advanced),
(new CRPropertyDescriptor(DECIMAL_PALACES, this.data.getClass()))
.setI18NName(Inter.getLocText("Plugin-DigitRoll_DecimalPlaces"))
.setEditorClass(DecimalPlacesEditor.class)
.putKeyValue("category", advanced)
);
}
public String getIconPath() {
return "com/fr/plugin/widget/digitroll/images/digitroll_icon.png";
}
}

12
src/com/fr/plugin/widget/digitroll/web/countUp.js

@ -3,6 +3,13 @@
countUp.js
by @inorganik
The MIT License (MIT)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// target = id of html element or var of previously selected html element where counting occurs
@ -239,7 +246,10 @@ var CountUp = function (target, startVal, endVal, decimals, duration, options) {
return;
}
self.error = '';
if (newEndVal === self.frameVal) return;
if (newEndVal === self.frameVal) {
if (self.callback) self.callback();
return;
}
cancelAnimationFrame(self.rAF);
self.paused = false;
delete self.startTime;

41
src/com/fr/plugin/widget/digitroll/web/widget.digitRoll.js

@ -13,11 +13,38 @@
FR.$defaultImport('/com/fr/plugin/widget/digitroll/web/countUp.js', 'js');
var o = this.options;
var element = this.element;
var widget = '<div id="' + o.widgetName + '" style=' + o.css + '></div>';
var widgetId = $(widget).appendTo(element);
o.options.prefix = o.prefix;
o.options.suffix = o.suffix;
var digitRoll = new CountUp(widgetId, 0, o.value, 0/*o.decimals*/, o.duration, o.options);
var widget = element[0];
var $widget = $('<span></span>');
var widgetId = $widget.appendTo(element);
$widget.css({
'position': 'absolute',
'left': '50%',
'top': '50%',
'-webkit-transform': 'translate(-50%, -50%)',
'-moz-transform': 'translate(-50%, -50%)',
'-ms-transform': 'translate(-50%, -50%)',
'-o-transform': 'translate(-50%, -50%)',
'transform': 'translate(-50%, -50%)'
});
this.element.css({
'font-size': o.fontSize + 'px',
'background-color': o.backgroundColor,
'color': o.fontColor,
'text-align': "center"
});
var options = {
useEasing: true, // 过渡动画效果,默认ture
useGrouping: o.group, // 千分位效果,例:1000->1,000。默认true
separator: ',', // 使用千分位时分割符号
decimal: '.', // 小数位分割符号
prefix: o.prefix, // 前置符号
suffix: o.suffix // 后置符号,可汉字
};
//debugger;
var digitRoll = new CountUp(widgetId[0], o.value, o.value, o.decimalPlaces, o.duration, options);
var callback = function () {
$.ajax({
@ -31,7 +58,7 @@
}
});
};
if (!digitRoll.error) {
if (!digitRoll.error) {
digitRoll.start(callback);
} else {
console.error(digitRoll.error);
@ -39,5 +66,5 @@
}
});
$.shortcut("digitRoll", FR.DigitRoll);
$.shortcut("digitroll", FR.DigitRoll);
})(jQuery);
Loading…
Cancel
Save