📄 flowingline.java
字号:
package com.mc.svg.shape.supershape;
import java.awt.Color;
import java.awt.Point;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import com.mc.svg.SVGMath;
import com.mc.svg.script.FlowingLineFunction;
import com.mc.svg.script.Function;
import com.mc.svg.script.Script;
import com.mc.svg.shape.basicshape.GPanel;
import com.mc.svg.shape.basicshape.Line;
public class FlowingLine extends GPanel {
private Point point1 = null;
private Point point2 = null;
private Color color = Color.WHITE;
private Color flowingColor = Color.BLACK;
private int lineWidth = 5;
private Script script = null;
private Function cyclopse = null;
private Function flowingline = null;
public FlowingLine(Document doc) {
super(doc);
}
public FlowingLine(Document doc,Script script) {
super(doc);
this.script = script;
}
public FlowingLine(Node node1, Node node2,Script script) {
super(node1.getDocument());
this.script = script;
point1 = new Point();
point1.x = node1.getX()+node1.getWidth()/2;
point1.y = node1.getY()+node1.getHeight()/2;
point2 = new Point();
point2.x = node2.getX()+node2.getWidth()/2;
point2.y = node2.getY()+node2.getHeight()/2;
cyclopse = script.findFunction("cyclopse");
flowingline = script.findFunction("flowinglinefunction");
if(cyclopse == null){
cyclopse = new Function("cyclopse");
cyclopse.addContent("setTimeout('cyclopse()', 1000);");
script.addFuntion(cyclopse);
Function start = script.findFunction("onload");
String dses = Function.functionDispose("cyclopse");
start.addContent(dses);
}
}
private void genFlowLine() {
if (point2.x - point1.x > 0) {
boolean tf = true;
Point oldpoint = point1;
for (int i = point1.x; i <= point2.x; i = i + 4) {
Point newpoint = new Point();
newpoint.x = i + 4;
newpoint.y = SVGMath.getY(point1, point2, i + 4);
if (tf == true) {
Line line = new Line(doc, oldpoint, newpoint);
line.setLineColor(color);
line.setLineWidth(lineWidth);
oldpoint = newpoint;
this.add(line);
tf = false;
} else {
Line line = new Line(doc, oldpoint, newpoint);
oldpoint = newpoint;
line.setLineWidth(lineWidth);
line.setLineColor(flowingColor);
this.add(line);
tf = true;
}
}
} else {
boolean tf = true;
Point oldpoint = point2;
for (int i = point2.x; i <= point1.x; i = i + 4) {
Point newpoint = new Point();
newpoint.x = i + 4;
newpoint.y = SVGMath.getY(point2, point1, i + 4);
if (tf == true) {
Line line = new Line(doc, oldpoint, newpoint);
line.setLineColor(color);
line.setLineWidth(lineWidth);
oldpoint = newpoint;
this.add(line);
tf = false;
} else {
Line line = new Line(doc, oldpoint, newpoint);
oldpoint = newpoint;
line.setLineWidth(lineWidth);
line.setLineColor(flowingColor);
this.add(line);
tf = true;
}
}
}
}
public void setLineFlowing(boolean tf){
if(tf == true){
String tmp = id+"tmp";
script.addSentence("var "+tmp+" = 20;");
if(flowingline == null){
flowingline = new FlowingLineFunction(color,flowingColor);
script.addFuntion(flowingline);
}
String[] params = {tmp,"'"+id+"'"};
String strDispose = Function.functionDispose("flowinglinefunction",params);
cyclopse.addContent("}",0);
cyclopse.addContent(tmp +" = 20;",0);
cyclopse.addContent(strDispose,0);
cyclopse.addContent("}else{",0);
cyclopse.addContent(tmp +" = 30;",0);
cyclopse.addContent(strDispose,0);
cyclopse.addContent("if("+tmp +"== 20){",0);
}
}
public Element getElement(){
genFlowLine();
return root;
}
public int getLineWidth() {
return lineWidth;
}
public void setLineWidth(int lineWidth) {
this.lineWidth = lineWidth;
}
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;
}
public Color getFlowingColor() {
return flowingColor;
}
public void setFlowingColor(Color flowingColor) {
this.flowingColor = flowingColor;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -