📄 dsrectanglespace.java
字号:
package drawsmart.itsv.basic;
import java.awt.geom.*;
import java.awt.*;
import drawsmart.itsv.framework.JDSLineface;
import drawsmart.itsv.framework.JDSComponentface;
import java.util.ArrayList;
/**
* <p>Title: 矩形基类</p>
* <p>Description: 实现矩形接口的基本方法</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author 崔江
* @version 2.0
*/
public abstract class DSRectangleSpace extends Rectangle2D.Double implements JDSComponentface
{
//存放已经添加的连接器
private ArrayList arrayLine=new ArrayList();
//选择的状态
private boolean isSelect=false;
private String strinfo="";
private Color fillColor=new Color(255,255,255);
private Color frameColor=new Color(0,0,0);
private String sID="";
public DSRectangleSpace()
{
}
/**
* 重绘矩形,实现接口方法
* @param g
*/
public void drawRect(Graphics g)
{
Graphics2D g2D = (Graphics2D) g;
double x = this.getX();
double y = this.getY();
double width=this.getWidth();
double height=this.getHeight();
//绘制矩形
g2D.drawRect((int)x,(int)y,(int)width,(int)height);
}
/** 取得这个组件的所有连接器 */
public JDSLineface[] getJDSLineface()
{
JDSLineface[] jDSLineface=(JDSLineface[])arrayLine.toArray(new JDSLineface[0]);
return jDSLineface;
}
/** 取得某点上的句柄序号,没有句柄时返回-1
*
* @param point */
public int getHandle(Point point)
{
Rectangle[] rec = getHandleRectangles();
for (int i = 0; i < rec.length; i++) {
if (rec[i].contains(point))
return i;
}
return -1;
}
/** 拖动句柄改变组件大小
*
* @param index 句柄的序号
* @param x2 拖动横轴移动的距离
* @param y2 拖动纵轴移动的距离 */
public void moveHandle(int index, Rectangle rec, int mx, int my) {
int x = rec.x, y = rec.y, w = rec.width, h = rec.height;
switch (index) {
case 0:
x += mx;
y += my;
w -= mx;
h -= my;
break;
case 1:
y += my;
h -= my;
break;
case 2:
y += my;
w += mx;
h -= my;
break;
case 3:
x += mx;
w -= mx;
break;
case 4:
w += mx;
break;
case 5:
x += mx;
w -= mx;
h += my;
break;
case 6:
h += my;
break;
case 7:
w += mx;
h += my;
break;
default:
break;
}
if (w < 0) {
x += w;
w = -w;
}
if (h < 0) {
y += h;
h = -h;
}
setFrame(x, y, w, h);
}
/** 添加一个连接直线
*
* @param tpc 连接的目标
* @param associateType 连接器的类型
* 直线、箭头(箭头的样式) */
public void addAssociator(JDSLineface tpc, int associateType) {
}
/** 添加一个连接直线
*
* @param tpc 连接的目标
* @param associateType 连接器的类型
* 直线、箭头(箭头的样式) */
public void addAssociator(JDSLineface jDSLineface) {
//判断是否重复
boolean bool=true;
for(int i=0;i<arrayLine.size();i++)
{
JDSLineface jDSLinefaces=(JDSLineface)arrayLine.get(i);
if(jDSLinefaces.getJDSComponentEnd()==jDSLineface.getJDSComponentEnd() && jDSLinefaces.getJDSComponentStart()==jDSLineface.getJDSComponentStart())
{
bool=false;
break;
}
}
//如果不重复
if (bool==true)
arrayLine.add(jDSLineface);
}
/** 删除一个连接器
*
* @param tpc 连接的目标 */
public void removeAssociator(JDSLineface tpc) {
}
/** 删除全部连接器
*
* @param tpc 连接的目标 */
public void removeAssociatorAll() {
arrayLine.clear();
}
/**
* 获得该组件的范围
* @return
*/
public Rectangle getRectSize()
{
return this.getBounds();
}
/**
* 获得坐标
* @return
*/
public int getComponentX()
{
return (int)getX();
}
/**
* 获得坐标
* @return
*/
public int getComponentY()
{
return (int)getY();
}
/**
* 获得高度
* @return
*/
public int getComponentHeight()
{
return (int)getHeight();
}
/**
* 获得宽度
* @return
*/
public int getComponentWidth()
{
return (int)getWidth();
}
/**
* 设置新的位置
*/
public void setPlaceComponent(Point p1,Point p2)
{
//x轴移动的距离
int x2x1=(int)p2.getX()-(int)p1.getX();
//y轴移动的距离
int y2y1=(int)p2.getY()-(int)p1.getY();
int x=(int)getX()+x2x1;
int y=(int)getY()+y2y1;
this.setFrame(x,y,this.getWidth(),this.getHeight());
}
/**
* 设置新的位置
* @param x int
* @param y int
*/
public void setPlaceComponent(int x,int y)
{
int x1=(int)getX()+x;
int y1=(int)getY()+y;
this.setFrame(x1,y1,this.getWidth(),this.getHeight());
}
/**
* 设置是否选中
* @param bool
*/
public void setIsSelect(boolean bool)
{
isSelect=bool;
}
/**
* 返回改组件的选中状态
* @return
*/
public boolean getIsSelect()
{
return isSelect;
}
/**
* 获得所有的句柄
* @return
*/
public Rectangle[] getHandleRectangles() {
int x = (int)getX();
int y = (int)getY();
int w = (int) getWidth();
int h = (int) getHeight();
return new Rectangle[] {
new Rectangle(x, y, HANDLE_SIZE, HANDLE_SIZE), //SW_RESIZE_CURSOR 4
//只有Y轴的变化
new Rectangle(x + w / 2, y, HANDLE_SIZE,
HANDLE_SIZE), //SE_RESIZE_CURSOR 5
new Rectangle(x + w - HANDLE_SIZE, y, HANDLE_SIZE, HANDLE_SIZE), //NW_RESIZE_CURSOR 6
//只有X轴的变化
new Rectangle(x, y + h / 2 - HANDLE_SIZE, HANDLE_SIZE, HANDLE_SIZE), //NE_RESIZE_CURSOR 7
//只有X轴的变化
new Rectangle(x + w - HANDLE_SIZE, y + h / 2 - HANDLE_SIZE, HANDLE_SIZE,
HANDLE_SIZE), //NE_RESIZE_CURSOR 7
new Rectangle(x, y + h - HANDLE_SIZE, HANDLE_SIZE, HANDLE_SIZE), //NE_RESIZE_CURSOR 7
//只有Y轴的变化
new Rectangle(x + w / 2, y + h - HANDLE_SIZE, HANDLE_SIZE, HANDLE_SIZE), //N_RESIZE_CURSOR 8
new Rectangle(x + w - HANDLE_SIZE, y + h - HANDLE_SIZE,
HANDLE_SIZE, HANDLE_SIZE), // S_RESIZE_CURSOR 9
};
}
/**
* 设置组件
* @param x
* @param y
* @param w
* @param h
*/
public void setCompinentRectangle(int x,int y,int w,int h)
{
this.setRect(x,y,w,h);
}
/**
* 文本说明
* @param str1 String
*/
public void setTextInfo(String str1)
{
strinfo=str1;
}
/**
* 文本说明
* @param str1 String
*/
public String getTextInfo()
{
if(strinfo==null) return "";
else
return strinfo;
}
/**
* 设置填充颜色
* @param color Color
*/
public void setFillColor(Color color) {
this.fillColor = color;
}
/**
* 获得填充颜色
* @param color Color
*/
public Color getFillColor() {
return fillColor;
}
/**
* 设置边框颜色
* @param color Color
*/
public void setFrameColor(Color color) {
this.frameColor = color;
}
/**
* 获得边框颜色
* @return Color
*/
public Color getFrameColor() {
return frameColor;
}
/**
* 设置该组件的ID
* @param sID String
*/
public void setComponentID(String sID)
{
this.sID=sID;
}
/**
* 获得该组件的ID
* @return String
*/
public String getComponentID()
{
return sID;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -