diff --git a/plugin.xml b/plugin.xml index dc950d1..bd55e5b 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,6 +1,7 @@ - com.fr.plugin.present.demo + com.fr.plugin.present.star + com.fr.plugin.present yes 1.0 diff --git a/pom.xml b/pom.xml index b08bff7..58e6931 100644 --- a/pom.xml +++ b/pom.xml @@ -13,6 +13,6 @@ demo-show-present - ${project.basedir}/../webroot/WEB-INF/plugins/plugin-com.fr.plugin.function.fib-1.0/classes + ${project.basedir}/../webroot/WEB-INF/plugins/plugin-com.fr.plugin.present.star-1.0/classes \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..bba91ef --- /dev/null +++ b/readme.md @@ -0,0 +1,11 @@ +# 扩展形态示例 + +可以将数值转化为用于评分展示的红星。 + +模板设置如下 + +![tpl](screenshots/1.png) + +预览效果如图所示 + +![show](screenshots/2.png) \ No newline at end of file diff --git a/screenshots/1.png b/screenshots/1.png new file mode 100644 index 0000000..f972a51 Binary files /dev/null and b/screenshots/1.png differ diff --git a/screenshots/2.png b/screenshots/2.png new file mode 100644 index 0000000..6e8e0c7 Binary files /dev/null and b/screenshots/2.png differ diff --git a/src/main/java/com/fr/plugin/present/PresentKindBridge.java b/src/main/java/com/fr/plugin/present/PresentKindBridge.java index 909af95..07319c2 100644 --- a/src/main/java/com/fr/plugin/present/PresentKindBridge.java +++ b/src/main/java/com/fr/plugin/present/PresentKindBridge.java @@ -4,7 +4,7 @@ import com.fr.base.present.Present; import com.fr.design.beans.FurtherBasicBeanPane; import com.fr.design.fun.impl.AbstractPresentKindProvider; import com.fr.plugin.present.fun.StarPresent; -import com.fr.plugin.present.ui.MyPresentPane; +import com.fr.plugin.present.ui.StarPresentPane; /** * @author richie @@ -15,7 +15,7 @@ public class PresentKindBridge extends AbstractPresentKindProvider { @Override public FurtherBasicBeanPane appearanceForPresent() { - return new MyPresentPane(); + return new StarPresentPane(); } @Override diff --git a/src/main/java/com/fr/plugin/present/fun/StarPainter.java b/src/main/java/com/fr/plugin/present/fun/StarPainter.java new file mode 100644 index 0000000..2f6d695 --- /dev/null +++ b/src/main/java/com/fr/plugin/present/fun/StarPainter.java @@ -0,0 +1,43 @@ +package com.fr.plugin.present.fun; + +import com.fr.base.AbstractPainter; +import com.fr.base.Style; +import com.fr.general.IOUtils; +import com.fr.report.cell.cellattr.core.CellUtils; +import com.fr.stable.html.Tag; +import com.fr.stable.web.Repository; +import com.fr.web.BaseHTMLWriterUtils; + +import java.awt.*; +import java.awt.image.BufferedImage; + +public class StarPainter extends AbstractPainter { + + private static final BufferedImage image = IOUtils.readImage("/com/fr/plugin/present/images/star.png"); + + private int count; + private int hGap = 4; + + public StarPainter(int count) { + this.count = count; + } + + @Override + public void paint(Graphics g, int width, int height, int resolution, Style style) { + Graphics2D g2d = (Graphics2D) g; + int imageWidth = image.getWidth(); + int imageHeight = image.getHeight(); + int y = (height - imageHeight) / 2; + for (int i = 0; i < count; i++) { + g2d.drawImage(image, (imageWidth + hGap) * i, y, imageWidth, imageHeight, null); + } + } + + @Override + public void paintTag(Repository repo, int width, int height, Style style, Tag tag) { + tag.cls("imageCellElement"); + tag.sub(BaseHTMLWriterUtils.createImageTag4RepoWithCheckVml( + CellUtils.value2Image(this, repo.getResolution(), style, width, height), new Dimension(width, height), repo + )); + } +} diff --git a/src/main/java/com/fr/plugin/present/fun/StarPresent.java b/src/main/java/com/fr/plugin/present/fun/StarPresent.java index 7d1094b..e673d1d 100644 --- a/src/main/java/com/fr/plugin/present/fun/StarPresent.java +++ b/src/main/java/com/fr/plugin/present/fun/StarPresent.java @@ -1,11 +1,18 @@ package com.fr.plugin.present.fun; +import com.fr.base.BaseFormula; import com.fr.base.present.AbstractPresent; +import com.fr.general.GeneralUtils; import com.fr.intelli.record.Focus; import com.fr.intelli.record.Original; +import com.fr.log.FineLoggerFactory; import com.fr.record.analyzer.EnableMetrics; import com.fr.script.Calculator; +import com.fr.stable.AssistUtils; import com.fr.stable.ColumnRow; +import com.fr.stable.StableUtils; +import com.fr.stable.StringUtils; +import com.fr.stable.UtilEvalError; import com.fr.stable.xml.XMLPrintWriter; import com.fr.stable.xml.XMLableReader; @@ -17,19 +24,67 @@ import com.fr.stable.xml.XMLableReader; @EnableMetrics public class StarPresent extends AbstractPresent { + private String condition; + + public String getCondition() { + return condition; + } + + public void setCondition(String condition) { + this.condition = condition; + } + @Override - @Focus(id = "com.fr.plugin.present.demo", text = "", source = Original.PLUGIN) + @Focus(id = "com.fr.plugin.present.star", text = "", source = Original.PLUGIN) public Object present(Object value, Calculator calculator, ColumnRow cr) { - return "aaa"; + Object result = null; + if (StableUtils.canBeFormula(condition)) { + try { + result = calculator.evalValue(BaseFormula.createFormulaBuilder().build(condition)); + } catch (UtilEvalError e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + } else { + result = condition; + } + Number num = GeneralUtils.objectToNumber(result, true); + if (num == null) { + return value; + } + return new StarPainter(num.intValue()); } @Override public void readXML(XMLableReader reader) { - + if (reader.isChildNode()) { + String tag = reader.getTagName(); + if ("Condition".equals(tag)) { + condition = reader.getElementValue(); + } + } } @Override public void writeXML(XMLPrintWriter writer) { + if (StringUtils.isNotEmpty(condition)) { + writer.startTAG("Condition").textNode(condition).end(); + } + } + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + @Override + public boolean equals(Object o) { + return o instanceof StarPresent + && super.equals(o) + && AssistUtils.equals(((StarPresent) o).condition, condition); + } + + @Override + public int hashCode() { + return AssistUtils.hashCode(condition); } } \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/present/ui/MyPresentPane.java b/src/main/java/com/fr/plugin/present/ui/MyPresentPane.java deleted file mode 100644 index e7035ad..0000000 --- a/src/main/java/com/fr/plugin/present/ui/MyPresentPane.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.fr.plugin.present.ui; - -import com.fr.design.beans.FurtherBasicBeanPane; -import com.fr.design.gui.itextfield.UITextField; -import com.fr.plugin.present.fun.StarPresent; - -import java.awt.*; - -/** - * @author richie - * @date 2015-05-24 - * @since 8.0 - */ -public class MyPresentPane extends FurtherBasicBeanPane{ - private UITextField textField; - - public MyPresentPane() { - initComponents(); - } - - private void initComponents() { - setLayout(new BorderLayout()); - textField = new UITextField(); - add(textField, BorderLayout.NORTH); - } - - - @Override - public boolean accept(Object ob) { - return ob instanceof StarPresent; - } - - @Override - public String title4PopupWindow() { - return "我的形态"; - } - - @Override - public void reset() { - - } - - @Override - public void populateBean(StarPresent ob) { - - } - - @Override - public StarPresent updateBean() { - return new StarPresent(); - } -} \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/present/ui/StarPresentPane.java b/src/main/java/com/fr/plugin/present/ui/StarPresentPane.java new file mode 100644 index 0000000..fc63405 --- /dev/null +++ b/src/main/java/com/fr/plugin/present/ui/StarPresentPane.java @@ -0,0 +1,73 @@ +package com.fr.plugin.present.ui; + +import com.fr.design.beans.FurtherBasicBeanPane; +import com.fr.design.editor.ValueEditorPane; +import com.fr.design.editor.ValueEditorPaneFactory; +import com.fr.design.editor.editor.Editor; +import com.fr.design.editor.editor.FormulaEditor; +import com.fr.design.editor.editor.IntegerEditor; +import com.fr.design.formula.TinyFormulaPane; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itextfield.UITextField; +import com.fr.design.i18n.Toolkit; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.plugin.present.fun.StarPresent; + +import java.awt.*; + +/** + * @author richie + * @date 2015-05-24 + * @since 8.0 + */ +public class StarPresentPane extends FurtherBasicBeanPane { + + private TinyFormulaPane formulaPane; + + public StarPresentPane() { + initComponents(); + } + + private void initComponents() { + setLayout(new BorderLayout()); + formulaPane = new TinyFormulaPane(); + add(GUICoreUtils.createBorderLayoutPane( + new UILabel(Toolkit.i18nText("Plugin-Present_Value") + ":"), + BorderLayout.WEST, + formulaPane, + BorderLayout.CENTER + ), BorderLayout.NORTH); + + } + + + @Override + public boolean accept(Object ob) { + return ob instanceof StarPresent; + } + + @Override + public String title4PopupWindow() { + return Toolkit.i18nText("Plugin-Present_Star"); + } + + @Override + public void reset() { + + } + + @Override + public void populateBean(StarPresent ob) { + if (ob == null) { + return; + } + formulaPane.populateBean(ob.getCondition()); + } + + @Override + public StarPresent updateBean() { + StarPresent starPresent = new StarPresent(); + starPresent.setCondition(formulaPane.updateBean()); + return starPresent; + } +} \ No newline at end of file diff --git a/src/main/resources/com/fr/plugin/present/images/star.png b/src/main/resources/com/fr/plugin/present/images/star.png new file mode 100644 index 0000000..42860e3 Binary files /dev/null and b/src/main/resources/com/fr/plugin/present/images/star.png differ diff --git a/src/main/resources/com/fr/plugin/present/locale/present.properties b/src/main/resources/com/fr/plugin/present/locale/present.properties index e69de29..1a7d4d4 100644 --- a/src/main/resources/com/fr/plugin/present/locale/present.properties +++ b/src/main/resources/com/fr/plugin/present/locale/present.properties @@ -0,0 +1,2 @@ +Plugin-Present_Star=Star +Plugin-Present_Value=Value \ No newline at end of file diff --git a/src/main/resources/com/fr/plugin/present/locale/present_zh_CN.properties b/src/main/resources/com/fr/plugin/present/locale/present_zh_CN.properties index e69de29..9cf985f 100644 --- a/src/main/resources/com/fr/plugin/present/locale/present_zh_CN.properties +++ b/src/main/resources/com/fr/plugin/present/locale/present_zh_CN.properties @@ -0,0 +1,2 @@ +Plugin-Present_Star=\u8BC4\u5206\u5F62\u6001 +Plugin-Present_Value=\u8BC4\u5206\u503C \ No newline at end of file