📄 vmlreport.java
字号:
package com.xuntian.material.util;
import java.awt.Color;
import java.util.Iterator;
import java.util.Map;
public class VMLReport {
public static final int TYPE_LINE = 1;
public static final int TYPE_RECT = 2;
public static final int TYPE_OAVL = 3;
private static int OVAL_ROUND_ANGLE = 2360;// 1/10000
private Map<Integer, String> map = null;
private String[] nameArray;
private double[] valueArray;
private double valueSum = 0d;
private double valueMax = 0d;
private Color[] colors;
// report set
private int reportTop = 50;
private int reportLeft = 0;
// rect report set
private int rectReportHeight = 400;
private int rectReportWidth = 30;
private int rectReportDistence = 60;
private int rectRowDistence = 50;
// line report set
private int lineReportHeight = 400;
private int lineReportDistence = 60;
private int lineRowDistence = 50;
// oval report set
private int ovalReportSize = 400;
// report set
private int ovalReportTop = reportTop;
private int ovalReportLeft = reportLeft + 200;
public VMLReport(String[] name, double[] value) {
this.setNameArray(name);
this.setValueArray(value);
this.setColors();
}
public VMLReport(String[] name, double[] value, Color[] colors) {
this.setNameArray(name);
this.setValueArray(value);
this.setColors(colors);
}
public VMLReport(Map<Integer, String> map) {
this.setMap(map);
this.setColors();
}
public VMLReport(Map<Integer, String> map, Color[] colors) {
this.setMap(map);
this.setColors(colors);
}
public void setMap(Map<Integer, String> map) {
this.map = map;
int len = map.size();
String[] names = new String[len];
double[] values = new double[len];
Iterator<Integer> iterator = map.keySet().iterator();
Integer key;
for (int i = 0; iterator.hasNext(); i++) {
key = iterator.next();
names[i] = map.get(key);
values[i] = key.intValue();
}
this.setNameArray(names);
this.setValueArray(values);
}
public Map<Integer, String> getMap() {
return map;
}
public void setNameAndValue(String[] name, double[] value) {
this.setNameArray(name);
this.setValueArray(value);
}
private void setNameArray(String[] name) {
this.nameArray = name;
}
public String[] getNameArray() {
return nameArray;
}
private void setValueArray(double[] values) {
this.valueArray = values;
for (double value : values) {
valueSum += value;
if (value > this.valueMax) {
this.valueMax = value;
}
}
}
public double[] getValueArray() {
return valueArray;
}
public void setColors(Color[] colors) {
this.colors = colors;
}
public Color[] getColors() {
return colors;
}
public int getRectReportDistence() {
return rectReportDistence;
}
public int getReportLeft() {
return reportLeft;
}
public int getLineReportDistence() {
return lineReportDistence;
}
public int getOvalReportSize() {
return ovalReportSize;
}
public int getRectReportWidth() {
return rectReportWidth;
}
public int getRectReportHeight() {
return rectReportHeight;
}
public int getReportTop() {
return reportTop;
}
public int getLineReportHeight() {
return lineReportHeight;
}
public int getLineRowDistence() {
return lineRowDistence;
}
public int getRectRowDistence() {
return rectRowDistence;
}
public void setRectReportDistence(int rectReportDistence) {
this.rectReportDistence = rectReportDistence;
}
public void setReportLeft(int reportLeft) {
this.reportLeft = reportLeft;
}
public void setLineReportDistence(int lineReportDistence) {
this.lineReportDistence = lineReportDistence;
}
public void setOvalReportSize(int ovalReportSize) {
this.ovalReportSize = ovalReportSize;
}
public void setRectReportWidth(int rectReportWidth) {
this.rectReportWidth = rectReportWidth;
}
public void setRectReportHeight(int rectReportHeight) {
this.rectReportHeight = rectReportHeight;
}
public void setReportTop(int reportTop) {
this.reportTop = reportTop;
}
public void setLineReportHeight(int lineReportHeight) {
this.lineReportHeight = lineReportHeight;
}
public void setLineRowDistence(int lineRowDistence) {
this.lineRowDistence = lineRowDistence;
}
public void setRectRowDistence(int rectRowDistence) {
this.rectRowDistence = rectRowDistence;
}
public void setColors() {
int[] color = { 255, 128, 0 };
int l = color.length;
colors = new Color[l * l * l - 2];
for (int i = 0; i < l; i++) {
for (int j = 0; j < l; j++) {
for (int k = 0; k < l; k++) {
if (i + j + k != 0 && i + j + k != (l - 1) * 3) {
int no = i * l * l + j * l + k - 1;
colors[no] = new Color(color[i], color[j], color[k]);
}
}
}
}
}
public String getVMLReport(int type) {
StringBuffer results = new StringBuffer();
results.append("<html");
prepareAttribute(results, "xmlns:v", "urn:schemas-microsoft-com:vml");
prepareAttribute(results, "xmlns:o",
"urn:schemas-microsoft-com:office:office)");
results.append(">\n");
results.append("<head>\n");
results.append("<title>物资比价分析</title>\n");
results
.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=GBK\">\n");
results.append("<STYLE>\n");
results.append("v\\:* {BEHAVIOR: url(#default#VML)}\n");
results.append("o\\:* {BEHAVIOR: url(#default#VML)}\n");
results.append(".shape {BEHAVIOR: url(#default#VML)}\n");
results.append("</STYLE>\n");
results.append("</head>\n\n");
results.append("<body>\n");
if (this.nameArray != null && this.valueArray != null) {
results.append("<div");
results.append(" ID=\"group1\"");
results.append(" style=\"");
results.append("position: absolute;");
results.append(" top:").append(this.reportTop).append("px;");
results.append("left:").append(this.reportLeft).append("px;");
results.append("\"");
results.append(">\n");
switch (type) {
case TYPE_LINE:
prepareVMLReportLine(results);
break;
case TYPE_RECT:
prepareVMLReportRect(results);
break;
case TYPE_OAVL:
prepareVMLReportOval(results);
break;
}
results.append("</div>\n");
}
results.append("</body>\n");
results.append("</html>\n");
return results.toString();
}
public void prepareVMLReportLine(StringBuffer handler) {
int width = this.lineReportDistence * this.nameArray.length;
prepareRectRect(handler, 0, 50, width, this.lineReportHeight);
prepareLine(handler, 50, 0, 50, this.lineReportHeight, "#000000");
prepareLine(handler, 50, this.lineReportHeight, width + 50,
this.lineReportHeight, "#000000");
String str = String.valueOf((int) this.valueMax);
int temp = Integer.parseInt(str.substring(0, 1));
temp++;
for (int i = 1; i < str.length(); i++) {
temp *= 10;
}
int count = temp * this.lineRowDistence / this.lineReportHeight;
// 锟斤拷锟斤拷锟\uFFFD
for (int i = 0; i < this.lineReportHeight / this.lineRowDistence; i++) {
int height = this.lineReportHeight - (i + 1) * this.lineRowDistence;
prepareLine(handler, 50, height, width + 50, height, "#6699FF");
prepareLine(handler, 30, height, 50, height, "#000000");
prepareTextbox(handler, height + 5, 0, 45, 18, String.valueOf(count
* (i + 1)), "right");
}
// 锟斤拷锟斤拷
int[][] points = new int[valueArray.length][2];
for (int i = 0; i < nameArray.length; i++) {
points[i][0] = this.lineReportDistence * i + 50;
points[i][1] = (int) (this.lineReportHeight - valueArray[i]
* this.lineRowDistence / count);
}
preparePolyLine(handler, points);
for (int i = 0; i < nameArray.length; i++) {
int t = (int) (this.lineReportHeight - valueArray[i]
* this.lineRowDistence / count - 3);
int l = this.lineReportDistence * i + 47;
prepareLineOval(handler, t, l, 6, 6, this.colors[i
% this.colors.length]);
prepareTextbox(handler, t - 17, l - 2, 100, 18, String
.valueOf(valueArray[i]), "left");
int x = this.lineReportDistence * i + 50;
int y = this.lineReportHeight;
if (i != 0) {
prepareLine(handler, x, 0, x, y, "#ffffff");
}
prepareLine(handler, x, y, x, y + 20, "#000000");
t = this.lineReportHeight + 5;
l = this.lineReportDistence * i + 55;
int w = this.lineReportDistence - 10;
prepareTextbox(handler, t, l, w, 100, nameArray[i], "left");
}
}
private void preparePolyLine(StringBuffer handler, int[][] points) {
handler.append("<v:PolyLine");
{
prepareAttributeBegin(handler, "style");
prepareStyleAttribute(handler, "position", "absolute");
prepareAttributeEnd(handler);
}
prepareAttribute(handler, "filled", "false");
{
prepareAttributeBegin(handler, "Points");
for (int[] point : points) {
preparePoint(handler, point[0], point[1]);
}
prepareAttributeEnd(handler);
}
handler.append("/>\n");
}
private void prepareLineOval(StringBuffer handler, int top, int left,
int width, int height, Color color) {
handler.append("<v:oval");
{
prepareAttributeBegin(handler, "style");
prepareStyleAttribute(handler, "position", "absolute");
prepareStyleAttribute(handler, "top", top);
prepareStyleAttribute(handler, "left", left);
prepareStyleAttribute(handler, "width", width);
prepareStyleAttribute(handler, "height", height);
prepareAttributeEnd(handler);
}
{
prepareAttributeBegin(handler, "strokeColor");
prepareRGBString(handler, color);
prepareAttributeEnd(handler);
}
{
prepareAttributeBegin(handler, "fillcolor");
prepareRGBString(handler, color);
prepareAttributeEnd(handler);
}
handler.append("/>");
}
public void prepareVMLReportRect(StringBuffer handler) {
int width = this.rectReportWidth + this.rectReportDistence
* this.nameArray.length;
prepareRectRect(handler, 0, 50, width, this.rectReportHeight);
prepareLine(handler, 50, 0, 50, this.rectReportHeight, "#000000");
prepareLine(handler, 60, 0, 60, this.rectReportHeight - 10, "#000000");
prepareLine(handler, 50, this.rectReportHeight, width + 50,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -