惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threatpost
V
Vulnerabilities – Threatpost
TaoSecurity Blog
TaoSecurity Blog
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed
G
GRAHAM CLULEY
S
Securelist
P
Palo Alto Networks Blog
MongoDB | Blog
MongoDB | Blog
A
Arctic Wolf
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
WordPress大学
WordPress大学
Project Zero
Project Zero
T
Threat Research - Cisco Blogs
L
Lohrmann on Cybersecurity
C
Cyber Attacks, Cyber Crime and Cyber Security
F
Fortinet All Blogs
博客园 - 叶小钗
B
Blog RSS Feed
C
Cisco Blogs
Google DeepMind News
Google DeepMind News
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Apple Machine Learning Research
Apple Machine Learning Research
G
Google Developers Blog
K
Kaspersky official blog
D
Docker
Latest news
Latest news
Cisco Talos Blog
Cisco Talos Blog
T
Tor Project blog
Cyberwarzone
Cyberwarzone
Security Latest
Security Latest
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Spread Privacy
Spread Privacy
Microsoft Azure Blog
Microsoft Azure Blog
C
Check Point Blog
J
Java Code Geeks
Simon Willison's Weblog
Simon Willison's Weblog
T
Tenable Blog
Recent Announcements
Recent Announcements
T
Tailwind CSS Blog
H
Help Net Security
L
LINUX DO - 热门话题
T
The Exploit Database - CXSecurity.com
Jina AI
Jina AI
S
SegmentFault 最新的问题
MyScale Blog
MyScale Blog
NISL@THU
NISL@THU
美团技术团队
腾讯CDC

博客园 - 太白飞仙

.Net网络资源 CI创意的方法与技巧 可控人生核聚变 用c#备份和还原sql server 2000数据库 论文先睹:关于科学的生命哲学的思考 蚂蚁造山的思考 语言争霸VS魔兽争霸 :: IT世界VS魔兽世界 第九章 SQL Server的简单应用 [导入]类型MSN窗体行为的实现(.NET 2.0) - 太白飞仙 - 博客园 [导入]文章藏金阁 [导入]敏捷实验室的一次争论 [导入]Netron研究(四)----"移动和联通"之联通篇 [导入]Netron研究(一)----初识 [导入]Netron研究(三)----"移动和联通"之移动篇 [导入]Agile Framework的日志服务 [导入]Agile Framework工作流服务的设计思路 [导入]KISS原则 [导入]WWF工作流引擎的一个奇怪现象 - 太白飞仙 - 博客园 [导入]时刻提防过度设计
[导入]Netron研究(二)----"容器"登场
太白飞仙 · 2006-01-16 · via 博客园 - 太白飞仙

    在上一篇随笔中,写了一点对Netron的初步认识,简单分析了下Netron中的三个基本图形实体:ShapeBase,Connection,Connector.但是这个三个实体只是三个光棍司令.他们怎么显示在窗体上呢?OK.下面,Netron的下一个主角即将登场.
    Netron中,有一个继承自.net framework中的System.Windows.Forms.ScrollableControl控件GraphControl,他在Netron中充当一个"容器"的角色(之所以加上引号,是为了和我们框架使用的IOC容器区分下).Netron中的所有图形实体都在他里面进行显示,控制.我将其部分重要的域和方法拿出来说明一下.

    GraphControl中的关键域:

protected ShapeCollection shapes; protected ConnectionCollection connections;

    shapes域保存的是GraphControl中所有的ShapeBase对象.ShapeCollection是一个继承自System.Collections.CollectionBase的集合类,也就是对ShapeBase对象进行添加,删除,检索等操作,很简单,不细谈.connections类似,保存的是Conncetion对象集合.(这里有一个值得改进的地方,由于该版本的Netron是在.net1.1下开发的,没有利用到.net2.0泛型的优点,这样,当以后图形元素不断增加,这类Collection对象将会随之增多,但他们内部代码都是大同小异的,完全可以用一个泛型集合代替)

protected Entity hoveredEntity; protected Entity selectedEntity;

    hoveredEntity域保存的是鼠标悬浮到的图形实体对象,得到这个对象的目的是当鼠标移动到某个实体上的时候,改变该图形实体的外观(比如:将其周边线条变为红色).selectedEntity域保存的是一个被鼠标选中的唯一图形实体,以达到选中一个图形对象,然后进行相关操作的目的.

protected bool tracking = false;

    该域表示是否应该进行鼠标轨迹的追踪,在进行图形元素拖动的时候将会利用到这个域.

    GraphControl的构造器
    这个很简单,大概的看一下,以达到理解该"容器"的构造行为.

public GraphControl() { //double-buffering SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.DoubleBuffer, true); SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.ResizeRedraw, true); //init the collections shapes = new ShapeCollection(); connections = new ConnectionCollection(); //menu menu = new ContextMenu(); BuildMenu(); this.ContextMenu = menu; //init the randomizer rnd = new Random(); //init the proxy proxy = new Proxy(this); }

   

GraphControl中的关键方法

public ShapeBase AddShape(ShapeBase shape) public ShapeBase AddShape(ShapeTypes type, Point location)

    这两个重载方法提供向GraphControl添加基本图形对象(椭圆,矩形...)的功能.

public Connection AddConnection(Connection con) public Connection AddConnection(Point startPoint) public Connection AddConnection(Connector from, Connector to) public Connection AddConnection(Point from, Point to)

    这四个重载方法提供向GraphControl添加图形对象间连线对象的功能.

protected override void OnMouseDown(MouseEventArgs e) protected override void OnMouseUp(MouseEventArgs e) protected override void OnMouseMove(MouseEventArgs e)

    这三个重载方法对图形的选择,拖动起到了至关重要的作用.在以后的随笔中将深入其内部进行分析.
   
    OK.该"容器"的登场亮相到此结束,现在,你对Netron的大体实现原理是否已经有了一个宏观上的认识呢?继续学习研究吧.

----2005.12.22 23:31 星期四


文章来源:http://www.agilelabs.cn/blogs/woody/archive/2005/12/22/296.aspx