您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 信息化管理 > Swing Architecture Overview 架构概述
ArticleArticleArticleArticleAAAASwingSwingSwingSwingArchitectureArchitectureArchitectureArchitectureOverviewOverviewOverviewOverviewSSSSwingwingwingwing架构概述TheInsideStoryonJFCComponentDesignJFC组件设计探究ByByByByAmyAmyAmyAmyFowlerFowlerFowlerFowler作者:AmyAmyAmyAmyFowlerFowlerFowlerFowler中文翻译:AzureAzureAzureAzureMostSwingdevelopersknowbynowthatSwingcomponentshaveaseparablemodel-and-viewdesign.AndmanySwingusershaverunacrossarticlessayingthatSwingisbasedonsomethingcalledamodifiedMVC(model-view-controller)architecture.大多swing开发人员现在都知道swing的组件采用的是模型-与-视图分离的设计,也有大量的swing使用者撰文陈述swing是基于“改良的MVC(模型-视图-控制者)结构”。ButaccurateexplanationsofhowSwingcomponentsaredesigned,andhowtheirpartsallfittogether,havebeenhardtocomeby--untilnow.但是在此之前对于swing组件是怎么设计的,它们的各部分是如何组合到一块的都描述的不是很准确。Thesilenceendswiththepublicationofthisarticle,amajorwhitepaperonSwingcomponentdesign.ItprovidesacomprehensivetechnicaloverviewofSwing'smodifiedMVCstructureanddemystifiesmanyotherfacetsofSwingcomponentarchitectureaswell.直到这篇swing组件设计白皮书文章的发表之后才让事情真相大白。本文对swing的改良的MVC架构做了一个很全面的技术概述,同时也对很多关于swing组件架构的其它方面的技术也做了概述。ThisdocumentpresentsatechnicaloverviewoftheSwingcomponentarchitecture.Inparticular,itcoversthefollowingareasindetail:这篇文档对swing组件的架构做一个技术概论。详细来说,它具体包括以下几个领域:DesigngoalsRootsinMVCSeparablemodelarchitecturePluggablelook-and-feelarchitecture设计目标MVC的来源可分离模型架构可拔插感官架构DesignDesignDesignDesignGoalsGoalsGoalsGoals设计目标TheoverallgoalfortheSwingprojectwas:Swing项目的所有目标如下:TobuildasetofextensibleGUIcomponentstoenabledeveloperstomorerapidlydeveloppowerfulJavafrontendsforcommercialapplications.为java开发人员建立一套可扩展的GUI组件,以助其快速开发出强大的面向java的商用软件。Tothisend,theSwingteamestablishedasetofdesigngoalsearlyintheprojectthatdrovetheresultingarchitecture.TheseguidelinesmandatedthatSwingwould:为达到此目的,swing开发组在项目初期建立了一套设计目标来制定最终的架构。这些指导要求swing必须:1.BeimplementedentirelyinJavatopromotecross-platformconsistencyandeasiermaintenance.完全使用java来实现以保证跨平台性和易维护性。2.ProvideasingleAPIcapableofsupportingmultiplelook-and-feelssothatdevelopersandend-userswouldnotbelockedintoasinglelook-and-feel.提供可以支持多感官的单一的API,这样用户和开发人员将不会被绑定到单一的感官上面。3.Enablethepowerofmodel-drivenprogrammingwithoutrequiringitinthehighest-levelAPI.具有不需要在最上层使用API的模型驱动编程能力。4.AdheretoJavaBeansdesignprinciplestoensurethatcomponentsbehavewellinIDEsandbuildertools.遵循JavaBeans设计规范以保证组件能够获得集成开发工具的良好支持。5.ProvidecompatibilitywithAWTAPIswherethereisoverlapping,toleveragetheAWTknowledgebaseandeaseporting.让功能重叠的AWTAPIs可以兼容,使得AWT为基础知识能够轻松过渡。RootsRootsRootsRootsininininMVCMVCMVCMVCMVCMVCMVCMVC的来源Swingarchitectureisrootedinthemodel-view-controller(MVC)designthatdatesbacktoSmallTalk.MVCarchitecturecallsforavisualapplicationtobebrokenupintothreeseparateparts:Swing结构的来源要追溯到SmallTalk的模型-视图-控制者(MVC)设计。MVC架构要求可视化的应用程序分为三个独立的部分:Amodelthatrepresentsthedatafortheapplication.模型代表应用软件的数据。Theviewthatisthevisualrepresentationofthatdata.视图指数据的可视化展现。Acontrollerthattakesuserinputontheviewandtranslatesthattochangesinthemodel.控制者获得视图上用户的输入并把它送到模型里面做相应的改变。Earlyon,MVCwasalogicalchoiceforSwingbecauseitprovidedabasisformeetingthefirstthreeofourdesigngoalswithintheboundsofthelattertwo.早期,MVC对swing来说是一个合理的选择,因为它基本上能够满足在后来两者的约束下实现我们的前三个设计目标。ThefirstSwingprototypefollowedatraditionalMVCseparationinwhicheachcomponenthadaseparatemodelobjectanddelegateditslook-and-feelimplementationtoseparateviewandcontrollerobjects.在开始的时候,swing原型遵循了传统的MVC分离式架构,每个组件都有独立的模型对象,并且可以通过代理它的感官实现来分离视图和控制者对象。TheTheTheThedelegatedelegatedelegatedelegate代理Wequicklydiscoveredthatthissplitdidn'tworkwellinpracticaltermsbecausetheviewandcontrollerpartsofacomponentrequiredatightcoupling(forexample,itwasverydifficulttowriteagenericcontrollerthatdidn'tknowspecificsabouttheview).SowecollapsedthesetwoentitiesintoasingleUI(user-interface)object,asshowninthisdiagram:我们很快发现这样分割在实际应用中工作的不是很好,因为一个组件的视图和控制者部分需要紧密的耦合在一起(比如,一般很难写出一个不知道视图细节的控制者)。所以我们将这两个实体捏合成一个单一的UI(用户接口)对象,如图所示:(TheUIdelegateobjectshowninthispictureissometimescalledadelegateobject,orUIdelegate.TheUIdelegateusedinSwingisdescribedinmoredetailinthePluggablelook-and-feelsectionofthisarticle,underthesubheadingTheUIdelegate.)(图中的UI代理对象有时被称为代理对象,或者UI代理,swing中的UI代理在本文的可拔插感官部分有更详细的描述,副标题为“UI代理”)。Asthediagramillustrates,Swingarchitectureislooselybased--butnotstrictlybased--onthetraditionalMVCdesign.IntheworldofSwing,thisnewquasi-MVCdesignissometimesreferredtoaseparablemodelarchitecture.如图所示,swing架构基本上是基于传统的MVC架构设计-但不是很严格。在swing的世界里,这种类MVC架构设计有时归类于模型可分离架构。Swing'sseparablemodeldesigntreatsthemodelpartofacomponentasaseparateelement,justastheMVCdesigndoes.ButSwingcollapsestheviewandcontrollerpartsofeachcomponentintoasingleUI(user-interface)object.Swing的模型可分离设计和MVC架构设计一样把一个组件的模型部分当作一个单独的元件。但是swing把视图和控制者部分捏合到一块变成一个独立的UI(用户接口)对象。ToToToToMVCMVCMVCMVCorororornotnotnotnottotototoMVC?MVC?MVC?MVC?到底是还是不是MVCMVCMVCMVC架构?Onenoteworthypointisthatasanapplicationdeveloper,youshouldthinkofacomponent'sview/controllerresponsibilitiesasbeinghandledbythegenericcomponentclass(suchas.JButton,JTree,andsoon).Thecomponentclassthendelegatesthelook-and-feel-specificaspectsofthoserespo
本文标题:Swing Architecture Overview 架构概述
链接地址:https://www.777doc.com/doc-5985556 .html