package com.sunking.tp.swing;
import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.util.Vector;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.event.MouseInputListener;
import com.sunking.tp.framework.AssoicatorLine;
import com.sunking.tp.framework.Desktop;
import com.sunking.tp.framework.JTPComponent;
import com.sunking.tp.framework.JTPMenuFactory;
import com.sunking.tp.tool.SelectionTool;
import com.sunking.tp.tool.Tool;
/**
*
* <p>Title: </p>
* <p>Description: 画图桌面</p>
* <p>Copyright: Copyright (c) 2007</p>
* <p>Company: </p>
* @author <a href="mailto:tommorowisbetter@hotmail.com">Better</a>
* @version 1.1
*/
public class JTPDesktopPane extends JPanel implements Desktop, java.io.Serializable {
private static final long serialVersionUID = -3000000000000000009L;
/**
*
*/
// BasicStroke stroke=new BasicStroke(1.0f,BasicStroke.CAP_BUTT,
// BasicStroke.JOIN_ROUND,140.0f,new float[]{1.0f},150.0f);
/**
*拖动框
*/
Rectangle dragRec = null;
/**
*当前选取的连线
*/
AssoicatorLine selectedLine = null;
/**
*所有连线
*/
AssoicatorLine assoicatorLines[] = null;
/**
*最大尺寸
*/
Dimension maxSize = new Dimension(0, 0);
/**
*当前工具
*/
Tool tool;
/**
*默认工具
*/
transient Tool defaultTool;
/**
*右键弹出菜单生成器
*/
transient JTPMenuFactory jtpMenuFactory;
/**
* 最后生成的btt
*/
JTPComponent lastBtt;
public static Color bg;
///////////////
// public void mouseDragged(MouseEvent e)
// {
// System.out.print("txxxxx");
// }
//
// public void mouseMoved(MouseEvent e)
// {
//
// }
////////////////
public JTPDesktopPane() {
this.setLayout(null);
//this.addMouseMotionListener(this);
setTool(getDefaultTool());
//setBackground(UIManager.getColor("Desktop.background"));
setBackground(Color.white);
bg=this.getBackground();
}
/**
*添加鼠标监听器
* @param l
*/
public void addMouseInputListener(MouseInputListener l) {
this.addMouseListener(l);
this.addMouseMotionListener(l);
}
/**
*移除鼠标监听器
* @param l
*/
public void removeMouseInputListener(MouseInputListener l) {
this.removeMouseListener(l);
this.removeMouseMotionListener(l);
}
/**
*取得某点上的组件
* @param p
* @return
*/
public JTPComponent getJTPComponent(Point p) {
for (int i = 0; i < getComponentCount(); i++) {
Component c = getComponent(i);
Point p1 = SwingUtilities.convertPoint(this, p, c);
if ( (c instanceof JTPComponent) && c.contains(p1)) {
return (JTPComponent) c;
}
}
return null;
}
/**
*取得某点上的组件,但排除传入的组件
* @param Point
* @param Compoent
* @return JTPComponent
*/
public JTPComponent getJTPComponentExcept(Point p,Component exceptC) {
for (int i = 0; i < getComponentCount(); i++) {
Component c = getComponent(i);
Point p1 = SwingUtilities.convertPoint(this, p, c);
if ( (c instanceof JTPComponent) && c.contains(p1) && !c.equals(exceptC)) {
return (JTPComponent) c;
}
}
return null;
}
/**
*如果进入了某个控件区域,鼠标指针换成相应的形状
* @param Point p
* @return boolean
*/
public Cursor getEnteredComponentCursor(Point p) {
for (int i = 0; i < getComponentCount(); i++) {
Component c = getComponent(i);
Point p1 = SwingUtilities.convertPoint(this, p, c);
if ( (c instanceof JTPComponent) && c.contains(p1)) {
int handleIndex = ( (JTPComponent) c).getHandle(p1);
if (((JTPComponent)c).isSelected() && handleIndex != -1){
return ( (JTPComponent) c).getAdjustCursor(handleIndex);
}
else{
return new Cursor(Cursor.HAND_CURSOR);
}
}
}
if (assoicatorLines != null && p != null) {
for (int i = 0; i < assoicatorLines.length; i++) {
if (assoicatorLines[i].contains(p)) {
return new Cursor(Cursor.HAND_CURSOR);
}
}
}
return Cursor.getDefaultCursor();
}
/**
*取得当前选取的组件
* @return
*/
public JTPComponent[] getSelectionJTPComponent() {
Vector vSelection = new Vector();
for (int i = 0; i < getComponentCount(); i++) {
Component c = getComponent(i);
if (c instanceof JTPComponent) {
JTPComponent tc = (JTPComponent) c;
if (tc.isSelected()) {
vSelection.add(tc);
}
}
}
JTPComponent tpc[] = new JTPComponent[vSelection.size()];
vSelection.copyInto(tpc);
return tpc;
}
/**
*添加选取的组件
* @param c
*/
public void addSelection(JTPComponent c) {
c.setSelect(true);
}
/**
*移除选取的组件
* @param c
*/
public void removeSelection(JTPComponent c) {
c.setSelect(false);
}
/**
*设置工具
* @param t
*/
public void setTool(Tool t) {
getDefaultTool().disabledTool();
if (tool != null) {
tool.disabledTool();
}
this.tool = t;
if (t != null) {
t.enabledTool();
} else {
getDefaultTool().enabledTool();
}
repaint();
}
/**
*取得当前工具
* @return
*/
public Tool getTool() {
if (tool != null) {
return tool;
}
return getDefaultTool();
}
/**
*取得默认工具
* @return
*/
public Tool getDefaultTool() {
if (defaultTool == null) {
defaultTool = new SelectionTool(this);
}
return defaultTool;
}
/**
*激发连接器更新
*/
public void fireAssoicatorChanged() {
assoicatorLines = getAssoicatorLines();
this.setPreferredSize(maxSize);
repaint();
if (getParent() != null) {
getParent().doLayout();
}
}
/**
*鼠标点击选取
* @param p
*/
public void mouseSelect(Point p) {
selectedLine = null;
JTPComponent tp = getJTPComponent(p);
if (tp != null) {
tp.setSelect(true);
} else {
if (assoicatorLines != null && p != null) {
for (int i = 0; i < assoicatorLines.length; i++) {
if (assoicatorLines[i].contains(p)) {
selectedLine = assoicatorLines[i];
}
}
}
}
repaint();
}
/**
*鼠标拉框选取
* @param rec
*/
public void mouseSelect(Rectangle rec) {
dragRec = rec;
if (dragRec == null) {
repaint();
return;
}
for (int i = 0; i < getComponentCount(); i++) {
Component c = getComponent(i);
if (c instanceof JTPComponent) {
if (c.getBounds().intersects(rec)) {
没有合适的资源?快使用搜索试试~ 我知道了~
一个用JAVA做的简单的画图程序
共153个文件
class:57个
java:46个
txvclassdiagram20:20个
需积分: 44 35 下载量 87 浏览量
2007-11-05
14:44:03
上传
评论 1
收藏 482KB RAR 举报
温馨提示
可以定义点,系统自动在点与点之间用直线连接。<br>可以通过鼠标的拖动操作调整直线的曲率(度),从而实现弧线的功能。<br>可以在任意位置放置补充说明的文字,并且可以调整文字的大小。<br>可以保存成通用的网页图片JPG格式。<br>
资源推荐
资源详情
资源评论
收起资源包目录
一个用JAVA做的简单的画图程序 (153个子文件)
Test.html.bak 133B
Test.html.bak 133B
JTPDesktopPane.class 9KB
AssoicatorLine.class 7KB
JTPButton.class 7KB
SelectionTool.class 6KB
AssociateTool.class 5KB
CreateTool.class 5KB
JTPUtil.class 5KB
SaveTool.class 5KB
ManualDrawing.class 4KB
ManualDrawing.class 4KB
AbstractTool.class 4KB
JTPDefaultMenuFactory.class 4KB
UndoRedoManager.class 4KB
MyProperties.class 4KB
UndoableEditFactory.class 3KB
JTPFileFilter.class 3KB
DeleteUndoableEdit.class 3KB
OpenTool.class 3KB
JTPResource.class 3KB
Arrow.class 3KB
JToolButton.class 3KB
JTPComponentSection.class 2KB
CreateUndoableEdit.class 2KB
PasteTool.class 2KB
ToolAction.class 2KB
JTPTextArea.class 2KB
ChangeAngleUndoableEdit.class 2KB
UndoRedoManager$RedoAction.class 2KB
UndoRedoManager$UndoLastAction.class 2KB
ChangeTextTool.class 2KB
DragUndoableEdit.class 2KB
ChangeImageUndoableEdit.class 2KB
ChangeTextUndoableEdit.class 2KB
JTPImage.class 2KB
ChangeImageTool.class 2KB
AssoicatorUndoableEdit.class 2KB
AdjustUndoableEdit.class 2KB
CopyTool.class 2KB
PasteUndoableEdit.class 2KB
Desktop.class 1KB
DeleteTool.class 1KB
UndoRedoManager$UndoableApdater.class 1KB
NewTool.class 1KB
JTPComponent.class 1KB
Assoicator.class 1KB
UndoableChangeEvent.class 1KB
Tool.class 952B
DrawingPoint.class 909B
SaveTool$2.class 895B
SaveTool$1.class 890B
ManualDrawing$1.class 806B
PolarCoordinate.class 799B
Config_Additonal.class 637B
UndoableChangeListener.class 274B
JTPMenuFactory.class 222B
LineRenderer.class 199B
Locator.class 182B
.classpath 229B
.classpath 229B
Test.html 156B
Test.html 156B
JTPDesktopPane.java 13KB
AssoicatorLine.java 11KB
JTPResource.java 10KB
JTPButton.java 8KB
SelectionTool.java 7KB
JTPFileFilter.java 7KB
UndoRedoManager.java 6KB
JTPUtil.java 6KB
UndoableEditFactory.java 6KB
ManualDrawing.java 6KB
CreateTool.java 6KB
AssociateTool.java 5KB
SaveTool.java 5KB
JTPDefaultMenuFactory.java 5KB
AbstractTool.java 4KB
Arrow.java 4KB
DeleteUndoableEdit.java 4KB
Desktop.java 3KB
JToolButton.java 3KB
JTPComponent.java 2KB
ToolAction.java 2KB
CreateUndoableEdit.java 2KB
OpenTool.java 2KB
Tool.java 2KB
DragUndoableEdit.java 2KB
JTPComponentSection.java 2KB
JTPTextArea.java 2KB
ChangeImageUndoableEdit.java 2KB
ChangeTextUndoableEdit.java 2KB
ChangeAngleUndoableEdit.java 2KB
PasteTool.java 2KB
ChangeImageTool.java 2KB
ChangeTextTool.java 2KB
AdjustUndoableEdit.java 2KB
Assoicator.java 2KB
PasteUndoableEdit.java 1KB
AssoicatorUndoableEdit.java 1KB
共 153 条
- 1
- 2
资源评论
litao1658
- 粉丝: 2
- 资源: 17
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功