【Flex CookBook】TEXT组件添加到一个定制的TreeItemRenderer

本文介绍如何在Flex中创建可自适应不同大小文本的TreeItemRenderer。通过覆盖measure()和updateDisplayList()方法,调整Text组件尺寸,确保树节点内容正确显示。同时讨论了如何处理组件的重新测量问题。

TEXT组件添加到一个定制的TreeItemRenderer

Tagged with

Components , MXML , Flex and other technologies , mx.controls.Text mx.controls.Tree TreeItemRenderer

问题摘要

如果每一个renderer的大小都一样,创建一个定制的TreeItemRenderer非常简单。如果每一个renderer的大小都有所不同的话那么情况就有点复杂了,一个很好的例子就是将TEXT控件添加到renderer里面去,如果你的text里的字符数量不一样的话,那么这个TREE控件显示就会不正常。

解决摘要

.本指南将会一步一步的指导你如何去实践这样的一个TreeItemRenderer

解释

我最近要完成一个显示图标和标签的TreeItemRenderer,在这个过程中发现,MacMartine的例子对我实现这样的一个功能非常有帮助,就在前不久我又不得不将这样一个工作扩展为TreeItemRenderer显示文本控件,要在标签上显示一段可变长度的文本,开始的时候还以为这很简单,但到后来我才意识到这是挺有挑战性的,我最初的策略是从头开始实现一个TreeItemRenderer,不去扩展现有的TreeItemRenderer。我这样做是因为我相信通过使用MXML我很快就能够完成这项工作,问题是我发现缺省的TreeItemRenderer实现通过一个MX内部属性isopening()和方法dispatchTreeEvent(),因此没有核心类的支持,我最好还是扩展现有的TreeItemRenderer

我返回到了我修改过的MacMartine的版本,应该修改现有的uD方法,并且实现一个m方法,在uD方法里,我只需要将Text控件放置在标签Label控件的下面,而m方法我需要使r变得更高来适应Text组件的高度变化,问题是Text组件的呈现方法非常复杂而且看起来不连贯普,如果设置宽度和高度属性的顺序不正确,组件了显示就不正确,通过几个小时的错误和纠正以后,我基本上实现了所需要的功能,下面就是我的步骤:

1).measure()方法里,我将Text组建的宽度设置为itemrenderer宽度,然后我去读取Text组件根据内容计算的measuredHeight属性,然后将它加到renderer的宽度属性

2)updateDisplayList方法中,在定位我所有的组件之后,我显示的将Text组件的measuredHeight属性设置好,看起来不是很必要,但是如果不这样做那么根本就不会获得显示。

,你的文本就被正确显示,TreeItemRenderer也能够正确的伸缩,如果你的renderer有不同的大小那么还有一件事情,就是设置Tree控件的variableRowHeight属性为true

另外,如果你的Tree组件也需要重新设置大小,为了使文本控件显示正确,还有一件事情,当显式的设置文本控件的宽和高属性的时候,组建并不会去调用measure()方法,因此组建的带笑傲就不能正确地显示,要纠正这一点我们必须将文本组件的explicitWidthexplicitHeight设置为NaN,因此监听TREE控件的ResizeEvents,当事件触发的时候,我们就显式地去完成这项工作,这样文本控件就能够正确地显示。

我的博客上附有这样的问题的一个完整例子。

screenshot.jpg

源文档

<http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&productId=2&postId=7764>

Adding mx.controls.Text component to a custom TreeItemRenderer

Tagged with

Components , MXML , Flex and other technologies , mx.controls.Text mx.controls.Tree TreeItemRenderer

Problem Summary

Creating a custom TreeItemRenderer is simple if every renderer will be the same size. It gets more complicated when the renderers need to be different sizes. A good example of this is adding the mx.controls.Text component to the TreeItemRenderer. If you have differing amounts of text in each item, it will not display properly.

Solution Summary

This cookbook entry will walk through the steps of implementing a TreeItemRenderer with a variable size Text component.

Explanation

I recently had to build a custom TreeItemRenderer which displayed an icon and a label. I found Mac Martine's example to be quite helpful in implementing it successfully. More recently I needed to extend this work to add a mx.controls.Text component to the renderer, to display a variable length description under the label. I initially believed that this would be a simple task, but it turns out to be quite a challenge.

My first strategy to accomplish this was to implement a new TreeItemRenderer from scratch without extending mx.controls.treeClasses.TreeItemRenderer. I wanted to do this because I believed I could very quickly lay it out in MXML. The problem is, that the default TreeItemRenderer implements the expand/collapse controls for the item and does so by accessing a property (isOpening) and method (dispatchTreeEvent) which are both scoped mx_internal. So without some extra gymnastics, I am better off extending the default TreeItemRenderer.

I reverted back to my modified implementation of Mac Martine's custom renderer. I had to modify the existing updateDisplayList() method override and implement the measure() method override. In updateDisplayList(), I basically just need to position the Text component under the existing Label component. In measure(), I need to make the renderer taller to accomodate the height of the additional Text component. The problem is that the Text component renderering code is complex and a seemingly inconsistent in how it behaves. If you don't set the width and height properties in just the right order, it won't render correctly. After several hours of trial and error, I was able to get it to behave properly. Here is basically what I did.

1) In measure(), I set the width property of the Text component to the width of the item renderer less the x position of the label. Then I read the measuredHeight property of the Text component which is calculated based on the length of the text/htmlText property of the component and the explicit width of the component, and I add that to the measuredHeight of my renderer.

2) In updateDisplayList, after positioning all of my components, I explicitly set the height of the Text component to the measuredHeight property of the Text component. This seems like an odd thing to have to do, but if I don't do it, the text doesn't display at all.

If you do these things, your Text will display and your renderer will be sized properly. There is one other important thing to do if your renderers are going to be different sizes, which is to set the variableRowHeight property on the Tree to true.

Additionally, if your Tree component will need to be resizable, there is something else that needs to be done to get the Text component to resize correctly. When the width and height of a Text component are both explicitly set, the component doesn't call measure() anymore, so it won't resize. To fix this, we need to set the explicitWidth & explicitHeight on the Text component to NaN. So we add a listener to the parent Tree to listen for ResizeEvents, and when they occur, set the explicitHeight and explicitWidth to NaN. This will then cause Text component to resize properly.

My blog has links to the example application (with source).

screenshot.jpg

采用PyQt5框架与Python编程语言构建图书信息管理平台 本项目基于Python编程环境,结合PyQt5图形界面开发库,设计实现了一套完整的图书信息管理解决方案。该系统主要面向图书馆、书店等机构的日常运营需求,通过模块化设计实现了图书信息的标准化管理流程。 系统架构采用典型的三层设计模式,包含数据存储层、业务逻辑层和用户界面层。数据持久化方案支持SQLite轻量级数据库与MySQL企业级数据库的双重配置选项,通过统一的数据库操作接口实现数据存取隔离。在数据建模方面,设计了包含图书基本信息、读者档案、借阅记录等核心数据实体,各实体间通过主外键约束建立关联关系。 核心功能模块包含六大子系统: 1. 图书编目管理:支持国际标准书号、中国图书馆分类法等专业元数据的规范化著录,提供批量导入与单条录入两种数据采集方式 2. 库存动态监控:实时追踪在架数量、借出状态、预约队列等流通指标,设置库存预警阈值自动提醒补货 3. 读者服务管理:建立完整的读者信用评价体系,记录借阅历史与违规行为,实施差异化借阅权限管理 4. 流通业务处理:涵盖借书登记、归还处理、续借申请、逾期计算等标准业务流程,支持射频识别技术设备集成 5. 统计报表生成:按日/月/年周期自动生成流通统计、热门图书排行、读者活跃度等多维度分析图表 6. 系统维护配置:提供用户权限分级管理、数据备份恢复、操作日志审计等管理功能 在技术实现层面,界面设计遵循Material Design设计规范,采用QSS样式表实现视觉定制化。通过信号槽机制实现前后端数据双向绑定,运用多线程处理技术保障界面响应流畅度。数据验证机制包含前端格式校验与后端业务规则双重保障,关键操作均设有二次确认流程。 该系统适用于中小型图书管理场景,通过可扩展的插件架构支持功能模块的灵活组合。开发过程中特别注重代码的可维护性,采用面向对象编程范式实现高内聚低耦合的组件设计,为后续功能迭代奠定技术基础。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
《基于SSM架构的学籍数据管理平台技术解析》 在当代数字化教育背景下,数据管理平台已成为教育机构运营的核心支撑。本系统以SSM技术组合为基础架构,构建了一套完整的学籍信息处理体系,通过系统化的技术方案实现教育数据的规范化管理与智能分析。以下从架构设计、技术实现与功能模块三个维度展开说明。 一、系统架构设计 该平台采用分层式架构设计,充分体现模块化与可维护性特征。Spring框架作为核心容器,通过依赖注入机制实现组件解耦;SpringMVC架构负责前端请求的路由与响应处理;MyBatis数据层框架则封装了数据库交互过程,通过映射配置简化SQL操作。三层架构协同工作,形成高内聚低耦合的技术体系。 二、技术实现要点 1. Spring容器:基于控制反转原则管理业务对象生命周期,结合面向切面编程实现事务控制与日志管理 2. SpringMVC模块:采用模型-视图-控制器设计范式,规范Web层开发流程,支持RESTful接口设计 3. MyBatis组件:通过XML配置实现对象关系映射,提供动态SQL生成机制,显著减少冗余编码 三、核心功能模块 1. 学籍信息维护:实现学员基本资料的增删改查操作,涵盖学籍编号、个人信息、所属院系等关键字段 2. 学业成绩管理:支持课程分数录入与批量处理,提供多维度统计分析功能 3. 教学组织管理:建立班级体系与学员关联关系,实现分级数据管理 4. 权限控制机制:基于角色访问控制模型,划分管理员、教职工、学员三级操作权限 5. 系统审计功能:完整记录用户操作轨迹,构建安全追踪体系 四、系统开发方法论 在项目生命周期中,采用结构化开发流程。前期通过需求调研确定系统边界,中期完成数据库范式设计与接口规范制定,后期采用迭代开发模式配合自动化测试,确保系统交付质量。 五、技术演进展望 当前系统虽未集成智能算法,但为未来升级预留了扩展接口。可预见的技术演进方向包括:基于学习行为数据的智能预警、个性化学习路径推荐等深度应用场景。 综上所述,该平台通过SSM技术体系实现了教育管理数据的标准化处理,既展示了现代软件开发范式的实践价值,也为教育信息化建设提供了可复用的技术方案。这种系统化的问题解决思路,充分体现了软件工程方法在教育领域的应用潜力。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值