Unformatted text preview:

HotDrawSlide 2ComponentsHotDraw exampleDrawingFigureFigure (cont)EllipseFigureSlide 9Slide 10Slide 11Figure class hierarchyPolylineFigureFigure as an abstract classToolStateMachine editorTools and the State patternHandleHandlesHotDraw and MVCDrawingEditorSlide 22Domain KnowledgeSlide 24HotDraw SummaryBlack-box FrameworksHistory of HotDrawBlack-box Frameworks haveLife-cycleHard Facts of ReuseOrigin of FrameworksFramework is:FrameworksHotDrawA Framework for 2-D graphicsHotDrawOriginal done at Tektronix by Kent Beck and Ward CunninghamDrawing toolOscilloscope user interface prototyper Diagramming inspectorElectronic schematic editor.PERT chart editor.ComponentsDrawing -- a collection of figuresFigure -- a visible component of a drawingTool -- a user interface “mode”Handle -- a small box that controls an aspect of a figureDrawingEditor -- the whole systemHotDraw exampleDrawingDrawing keeps track of figures.Methods for managing figuresadd:, remove:, bringToFront:, sendToBack:displayOn:Methods for animating (default does nothing) step, waitFigureCan display itselfKnows its location on the screenCan move and change its sizeKnows the drawings and other figures that depend on it and notifies them when it changesCan create handles for itselfFigure (cont)Figure is a VisualComponent, but it keeps track of its own location.So, implement bounds and displayOn:.Figure provides containsPoint: containedBy:, center, right, bottom, etc.EllipseFigureA new Figure class must implement displayFigureOn:, which is called by displayOn:Both methods take a GraphicsContext as an argument.ElipseFigure>>displayOn: aGCself isOpaque ifTrue: [self displayFilledOn: aGraphicsContext].self lineWidth > 0 ifTrue: [self displayOutlineOn: aGraphicsContext]displayFilledOn: aGraphicsContext aGraphicsContext paint: self fillColor.aGraphicsContext displayWedgeBoundedBy: self boundsstartAngle: self startAnglesweepAngle: self sweepAngledisplayOutlineOn: aGraphicsContext aGraphicsContext lineWidth: self lineWidth.aGraphicsContext paint: self lineColor.aGraphicsContext displayArcBoundedBy: self boundsstartAngle: self startAnglesweepAngle: self sweepAngleFigure class hierarchyFigureEllipseFigureCachedFigureImageFigureCompositeFigurePolylineFigureTextFigureViewAdapterFigurePolylineFigureFigure made up of line segmentsBezierFigureLineFigureSplineFigureFigure as an abstract classConcrete methods• keep track of drawingAbstract methods• display• knows bounding boxTemplate methods• tell whether point is inside itToolTool has an icon (for pallette) and a cursor (for canvas).Tool acts like a part of the controller. The drawing controller delegates all operations to the current tool, so changing the current tool changes the behavior of the editor.Tool is a state for the controller, and has a set of states that it can be in.Tool is a state machine.StateMachine editorTools and the State patternOne Tool classAction defined with a Smalltalk blockData stored in a dictionary so subclasses are not neededState transitions stored in a dictionary so it is easy to change.Tool definitions stored in class methods of Tool.HandleA handle is a figure that looks like a little box. It is attached to a figure and does something to the figure when you press it.Each Figure has a "handles" method that creates a set of handles for it.HandlesTrackHandle -- executes block while trackingIndexedTrackHandleTentativePositionHandleHotDraw and MVCHotDraw hides most of MVCDrawingEditor, DrawingControllerDrawing is a View!HotDraw programmer needs to know about DrawingEditor and VisualComponent protocol, but not about controllers.DrawingEditorThe DrawingEditor knows the tools on the palette and the current tool.DrawingView gets Drawing from DrawingEditor.HotDraw and MVCHotDrawHotDrawGraphicsGraphicsMVCMVCValueModelValueModelDomain KnowledgeA framework describes how to build a particular kind of program.• HotDraw embodies a theory of interactive graphics• HotDraw contains knowledge of graphics tricksDomain KnowledgeDevelopers of framework have to understand application domain.Framework can hide lots of information from its users.Frameworks make programmers more specialized.HotDraw SummaryBuilding an application consists primarily of reusing existing classes as well as creating a few new classes .Framework reuses not only code, but also design and analysis.Black-box FrameworksReplacing reuse by inheritance with reuse by object composition makes it easier to make programs without defining new classes.Ultimate framework lets you plug objects together with visual language.History of HotDrawV1 Tools used the State pattern, there was a subclass of Tool for each kind of tool.V2 Tools became a table of Commands. Tools became event driven. Figures used a constraint system.V3 Figures became as much like VisualComponents as possible. Tools became state machines, constraints and commands were eliminated.Black-box Frameworks have• more kinds of objects• more artificial kinds of objects• more complex relationships between objects• more objectsNot-quite-ultimate framework forces you to debug more complex system.Life-cycleReusable code requires many iterations.Johnson's law of software engineeringIf it hasn't been tested, it doesn't work.Corollary: software that hasn't been reused is not reusable.Hard Facts of ReuseUsing reusable code is easy - writing reusable code is hard.Software must be tested for its reusableness.Fixing reusability bugs may require major changes.Good design requires domain knowledge.Origin of FrameworksFrameworks are a generalization of a subsystem or application.Abstract classes are generalizations of concrete subclasses.Frameworks evolve.Interfaces should minimize changes.Framework is often "refactored" as it evolves.Framework is:• reuse of design of subsystem or entire application• tells how to break problem into objects• consists of classes (usually abstract) and the way they interact• not just static interface, but invariants and abstract algorithms• reuse of collaborative modelFrameworks• made up of a set of interlocking design patterns• evolve over time, usually becoming more black-box• are hard to design, but give the big payoff of


View Full Document

UIUC CS 497 - HotDraw A Framework for 2-D graphics

Download HotDraw A Framework for 2-D graphics
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view HotDraw A Framework for 2-D graphics and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view HotDraw A Framework for 2-D graphics 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?