📄 dsextenddesktop.java
字号:
package drawsmart.itsv.swing;
import drawsmart.itsv.basic.DSDesktopPane;
import java.awt.Cursor;
import java.awt.*;
import java.awt.geom.Line2D;
import drawsmart.itsv.framework.*;
import java.util.HashMap;
import drawsmart.itsv.framework.JDSSetupDataModelface;
/**
* <p>Title: 桌面绘图类</p>
* <p>Description: 继承绘图桌面基类,实现绘图方法</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author 崔江
* @version 2.0
*/
public class DSExtendDesktop
extends DSDesktopPane
implements JDSExtendDesktopface {
//
private DSDesktopEvent dsDesktopEvent;
//
//填充的颜色
private Color fillColor = new Color(255, 255, 255);
//组件边线的颜色
private Color frameColor = new Color(0, 0, 0);
//组件边线的宽度
private int frameWidth = 4;
//连接器的宽度
private int lineWidth = 2;
//是否是透明 0 不透明 1 透明
private boolean isClarity = true;
private Stroke s;
private int iComponentId=0;
public DSExtendDesktop(JDSXMLReadWriteface jDSXMLReadWriteface,
HashMap hashMap,
JDSSetupDataModelface jDSSetupDataModelface) {
super(jDSXMLReadWriteface, hashMap, jDSSetupDataModelface);
this.setPreferredSize(new Dimension(2000, 2000));
//setBackground(UIManager.getColor("Desktop.background"));
}
public void setMouseSyle(Cursor cursor) {
this.setCursor(cursor); //鼠标样式
}
/**
*根据连接源和连接目标定位线的位置
* @param line 两个圆心的连线
* @param c 两个物体的矩形
*/
private Point getPointShortToComponent(Line2D line, Rectangle c) {
int x1 = (int) c.getX();
int y1 = (int) c.getY();
int x2 = x1 + (int) c.getWidth();
int y2 = y1 + (int) c.getHeight();
if (line.intersectsLine(x1, y1, x2, y1)) { //top
return new Point(x1 + ( (int) c.getWidth()) / 2, y1);
}
else if (line.intersectsLine(x1, y2, x2, y2)) { //bottom
return new Point(x1 + ( (int) c.getWidth()) / 2, y2);
}
else if (line.intersectsLine(x2, y1, x2, y2)) { //right
return new Point(x2, y1 + ( (int) c.getHeight()) / 2);
}
else { //left
return new Point(x1, y1 + ( (int) c.getHeight()) / 2);
}
}
/**
* 刷新所有的组件
*/
public void fireComponentChanged(Graphics2D g2D) {
//设置连接器的线宽
s = new BasicStroke(lineWidth);
g2D.setStroke(s);
//刷新连接器
JDSLineface[] jDSLineface = this.getJDSAllLineface();
//设置颜色
//颜色为黑色
g2D.setColor(new Color(0, 0, 0));
for (int i = 0; i < jDSLineface.length; i++) {
//重新获取圆心
//获得连接源圆心
JDSComponentface jDSComponentfaceStart = jDSLineface[i].
getJDSComponentStart();
//获得截止源圆心
JDSComponentface jDSComponentfaceEnd = jDSLineface[i].getJDSComponentEnd();
if (jDSComponentfaceStart != null && jDSComponentfaceEnd != null) {
//获得圆心1
int x1 = jDSComponentfaceStart.getComponentX() +
(jDSComponentfaceStart.getComponentWidth() / 2);
int y1 = jDSComponentfaceStart.getComponentY() +
(jDSComponentfaceStart.getComponentHeight() / 2);
//获得圆心2
int x2 = jDSComponentfaceEnd.getComponentX() +
(jDSComponentfaceEnd.getComponentWidth() / 2);
int y2 = jDSComponentfaceEnd.getComponentY() +
(jDSComponentfaceEnd.getComponentHeight() / 2);
//先设置直线的位置
jDSLineface[i].setLine(x1, y1, x2, y2);
//System.out.println("x1="+x1+" y1="+y1+" x2="+x2+" y2="+y2);
//再确定应该连接在目标物体的那个边上
jDSLineface[i].setLine(getPointShortToComponent( (Line2D) jDSLineface[i],
jDSComponentfaceStart.getRectSize()),
getPointShortToComponent( (Line2D) jDSLineface[i],
jDSComponentfaceEnd.getRectSize()));
//刷新箭头
jDSLineface[i].drawLine(g2D);
//System.out.println("刷新直线");
}
//刷新直线
if (jDSLineface[i].getIsSelect() == true) {
s = new BasicStroke(lineWidth + 2);
g2D.setStroke(s);
}
else {
s = new BasicStroke(lineWidth);
g2D.setStroke(s);
}
g2D.draw( (Shape) jDSLineface[i]);
}
/***********************************************/
//设置组件的边框宽度
s = new BasicStroke(frameWidth);
g2D.setStroke(s);
JDSComponentface[] jDSComponents = getJDSAllComponent();
//System.out.println(jDSComponents.length);
//for(int i=0;i<jDSComponents.length;i++)
for (int i = jDSComponents.length - 1; i >= 0; i--) {
//设置文本
String str1 = jDSComponents[i].getTextInfo();
int x = jDSComponents[i].getComponentX();
int y = jDSComponents[i].getComponentY() - 10;
g2D.setFont(new Font("Dialog", 14, 14));
g2D.drawString(str1, x, y);
//设置边框颜色
g2D.setColor(jDSComponents[i].getFrameColor());
g2D.draw(jDSComponents[i].getShape());
if (isClarity) {
//设置填充颜色
g2D.setColor(jDSComponents[i].getFillColor());
g2D.fill(jDSComponents[i].getShape());
}
//颜色为黑色
g2D.setColor(new Color(0, 0, 0));
//显示选中组件的句柄
s = new BasicStroke(1);
g2D.setStroke(s);
if (jDSComponents[i].getIsSelect()) {
Rectangle[] rec = jDSComponents[i].getHandleRectangles();
for (int j = 0; j < rec.length; j++) {
g2D.drawRect(rec[j].x, rec[j].y, rec[j].width, rec[j].height);
}
}
s = new BasicStroke(frameWidth);
g2D.setStroke(s);
}
//显示选择框
s = new BasicStroke(1);
g2D.setStroke(s);
Rectangle rect = this.getSelectRect();
if (rect != null) {
//颜色
g2D.setColor(new Color(204, 204, 255));
g2D.drawRect(rect.x, rect.y, rect.width, rect.height);
}
}
/**
* 刷新所有的组件
*/
public void fireComponentChanged() {
}
/**
* 绘制组件及其选取状态\拉框选取时的框线,实现接口方法
* 刷新会自动调用
* @param g
*/
public void paintChildren(Graphics g) {
Graphics2D g2D = (Graphics2D) g;
//super.paintChildren(g);
//刷新组件
fireComponentChanged(g2D);
//super.paintChildren(g);
}
/**
* 设置填充色
* @param color
*/
public void setFillColor(Color color) {
fillColor = color;
}
/**
* 获得填充色
* @return
*/
public Color getFillColor() {
return fillColor;
}
/**
* 设置组件编框的颜色
* @param color
*/
public void setFrameColor(Color color) {
frameColor = color;
}
/**
* 获得组件编框的颜色
* @return
*/
public Color getFrameColor() {
return frameColor;
}
/**
* 设置组件边框的宽度
* @param width
*/
public void setFrameWidth(int width) {
frameWidth = width;
}
/**
* 获得组件边框的宽度
* @return
*/
public int getFrameWidth() {
return frameWidth;
}
/**
* 设置连接器的线宽度
* @param width
*/
public void setLineWidth(int width) {
lineWidth = width;
}
/**
* 获得连接器的线宽度
* @return
*/
public int getLineWidth() {
return lineWidth;
}
/**
* 设置组件是否透明
* @param bool
*/
public void setIsClarity(boolean bool) {
isClarity = bool;
}
/**
* 获得组件是否透明
* @return
*/
public boolean getIsClarity() {
return isClarity;
}
/**
* 获得该流程的序号
* @return int
*/
public int getComponentID()
{
return iComponentId;
}
/**
* 设置该流程的序号
* @param id int
*/
public void setComponentID(int id)
{
this.iComponentId=id;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -