1 / 55

Abstract Widgets

Abstract Widgets. Dealing with more complex models. Abstract Widgets. Most widgets limited in terms of the complexity of the model they can handle Need to consider how we might use widgets where the model is external to the widget

mleggett
Download Presentation

Abstract Widgets

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Abstract Widgets Dealing with more complex models

  2. Abstract Widgets • Most widgets limited in terms of the complexity of the model they can handle • Need to consider how we might use widgets where the model is external to the widget • Abstract widgets handle this arrangement by supported common models • Tree widget handles hierarchy • Table widget handles tabular structured data

  3. Widgets Windowing System Graphics View EssentialGeometry Model Controller Input

  4. PropertySettings ModelChangeEvents Widgets Windowing System WIDGET Graphics View EssentialGeometry Model Controller Input Abstraction of the Model View Controller Arrangement

  5. Widgets PropertySettings Windowing System WIDGET Graphics View ABSTRACT MODEL INTERFACE EssentialGeometry Model Controller Input

  6. Abstract Widgets • Separates the model from the widget through a well know abstract model interface • Model is implemented externally needs to respond to the abstract interface • This allows widgets to be used to control deeper more complex systems • Filestores • Databases

  7. PropertySettings Windowing System WIDGET Graphics View ABSTRACT MODEL INTERFACE EssentialGeometry TranslatorObject Controller Input Model

  8. Translator Object • Translates between the abstract model interface and the means of driving existing APIs for the model • The translator class • accepts the model in its constructor • implements all of the widget abstract model methods, • passing them on to the appropriate model methods. • Translator is not another model • It will need to hide complexity of the underlying system but should seek to be “as thin as possible”

  9. Tree Widgets • Tree are one of the classic abstract model widgets • Provide an interactive interface onto hierarchical structures • Browsing through the structure • Amending nodes in the structure • Model is external to the widget • Networks systems • File stores • Interactive elements separated from the underlying model through an abstracted interface

  10. Hierarchy reflects file store Nodes are Directories Files Each Node has Label Icon Open Close Box Changed Icon File store

  11. Hierarchy reflects user structuring Nodes are Folders URLS of each site Each Node has Label Icon Open Close Box Favourites

  12. Hierarchy reflects software structure Nodes are Package names Files defining classes Each Node has Label Icon Open Close Box Software Packages

  13. Hierarchy reflects user structuring Nodes are Folders of mailboxes Mailboxes containing email Each Node has Label Icon Open Close Box Mail Boxes

  14. Similarities • All represent a tree as an indented outline using the same layout. • Every node of the tree has a textual name and one or two icons. Containers have two icons, one for open and one for closed. • They all use little plus/minus boxes to open/close the container • Clicking on the name allows the user to change the name of any of the nodes

  15. Differences • Containers have variable numbers of children arranged in varying depths in the tree. • Every node has a different name. • There are different icons for different applications and for different items within those applications. • Some use faint gray lines to indicate which nodes are siblings but some do not. • The may use a different type and size of font.

  16. Abstract Widget Structure • Similarities handled by the widget • Differences managed by either the model or properties • Properties focus on appearance • Font face, size and style • boolean to display sibling lines • number of pixels to indent at each level • External models handle content differences.

  17. Abstract Widget Interface • Interface provides all of the information the widget needs to know about the tree • Two main components to the interface • The model itself that our widget will manipulate to interact with the structure • The second is the notification mechanism for the widget to learn about external model changes.

  18. TreeNode public interface TreeNode { int numberOfChildren(); // how many children nodes are there. Zero for leaf nodes TreeNode getChild(int childIdx); // get one of this node’s children Image getIcon(); // gets the primary icon for this node Image getOpenIcon(); // if this is a container this returns the icon for when it is open String getName() // gets the name of this node void setName(String name); // changes the name of this node }

  19. TreeNode Interface -- Browse the Model • Provides all the information to move through hierarchical structure allowing the widget to display it. • Can recursive tour through the tree and present it as needed. • Does not make the widget aware of changes to the underlying model so other elements of the interface are needed

  20. Notification of Model Change • Changes can occur at any point in the tree • We can locate any node in the tree with a path • each container provides access to its children by an index • Sequence of indices that leads from the root of the tree to the desired node. • Treewidget implements this to allow model to notify view of changes public class TreeWidget extends Widget { public void nodeChanged (List<int> pathToChangedNode){ . . . } public void nodeToInsert (List<int> insertLocation) { . . . } public void nodeToDelete (List<int> deleteLocation) { . . . } }

  21. Model Change through the view • Provide methods that let the widget alter the model public interface TreeRoot { public TreeNode root; public void addListenerWidget(TreeWidget widget); public void removeListenerWidget(TreeWidget widget); public void deleteNode(List<int> deleteLocation); public void moveNode(List<int> fromLocation, List<int> toLocation); public void changeName(List<int> nodeToChange, String newName); }

  22. File browsing • The entire file system is obviously too large to copy into the tree widget model. The abstract interface technique provides us the advantage of pre-built widgets on a signification model. • Access to file system through an API and to provide tree browser will need three translator classes. • a FileRoot class that implements TreeRoot. • This class can have a constructor that accepts a path name for the root folder. • a TreeFolder class and a TreeFile class to interface to folders and files respectively that implement TreeNode interface • A TreeFolder would find out the number of files and folders that it contains and report them as children. • Using the file system API the TreeFolder class will create TreeFolder or TreeFile classes for the folders and files that it contains.

  23. Cone Trees

  24. Hyberbolic Trees

  25. Treeviz Maps • Exploits size associated with each node to drive layout • Need to amend the abstract model with a getSize() method in the treenode interface

  26. Degree of Interest Trees • Exploits a degree of interest per node to drvie presentation to users

  27. Microsoft File Table

  28. Eclipse Error Log

  29. Email List

  30. Email List Music Player List

  31. Similarities to be handled by Widget • A fixed set of columns each with a title and/or possibly an icon. • An arbitrary number of rows that will probably require scrolling. • Every cell of the table has a string and/or an icon for its content. If the icon and string occur together the icon is first. • Rows can be sorted based on any of the column contents. • Rows can be selected and that selection used elsewhere. Selecting a song in will play that song. Selecting a message will display the contents of the message. • It is possible to hide or show and resize the width of columns.

  32. Differences to be handled by model and properties • The number of columns is fixed but there are varying numbers of columns between applications. • Columns have different names, icons and widths. • The contents of rows and cells are all different. • There are differences in font and background colour.

  33. Table Widget • The key is the communication between the widget and the model • to retrieve and change model information • to be notified of changes to the model. • In most cases the table is used primarily for viewing of information rather than editing it. • BUT, selected rows can be deleted and frequently cell string contents can be edited and changed. • More complex manipulations of the table model are generally handled by other widgets and then notifications forwarded to the widget.

  34. Abstract Model public interface TableModel { public void addTableListener(TableListener listener); public void removeTableListener(TableListener listener); public int nRows(); // returns the number of rows public TableColumn [] getColumns(); // returns descriptors for all of the columns public String getCellString(int rowIndex, int columnID); public void setCellString(int rowIndex, int columnID,String newCellValue); public Image getCellIcon(int rowIndex, int columnID); public void selectRow(int rowIndex); // notifies the model when a row is selected public void deleteRow(int rowIndex); } public enum ColumnJustify{LEFT, CENTER, RIGHT} public interface TableColumn { public int columnID(); public ColumnJustify justification(); public String getColumnName(); public void setColumnName(String newName); public Image getColumnIcon(); public int getColumnWidth(); public void setColumnWidth(int widthInPixels); public boolean isReadOnly(); }

  35. Table Listener Interface public interface TableListener { public void cellToChange(int rowIndex, int columnID, String newCellValue); public void rowChanged(int rowIndex); public void rowsToDelete(int firstRowIndex, int nRowsToDelete); public void rowsInserted(int firstRowIndex, int nRowsInserted); public void columnDescChanged(int columnID); publis void tableChanged(); } Provides Notification at Different Levels of Scope (Table, Row, Cell, Labels)

  36. Table Properties • Our Table widget also needs properties. • header font, cell font, background colour, • Also alternating line background colour to highlight rows with slightly different colours. • May also need column properties balance between the properties for columns and things placed in the model • Alignment could be a property but is placed in model as columns are already defined • Deciding between properties and model elements based on how often you see changes occurring and by whom

  37. Drawing Widget • More complex model than regularly structured tree and table • Want to explore how we may have a model to support some form of shared drawing interface • Placement of entities within some form of canvas will be vital • But what else

  38. Similarities • The model is fundamentally a list of objects to be drawn on a surface. • There is a menu of objects that can be selected and placed in the drawing area. • Creating new objects uses the same event sequence and interactive behaviour. • click to place an item, • down-drag-up to create two control points, • placement of multiple control points. • Selection works by clicking on objects, shift-clicking to select multiple objects and rubberband rectangles to select a group of objects. • Objects can be dragged around the draw area. • Object are manipulated by dragging control points and those control points are displayed in a similar way. • Deleting objects is the same.

  39. Obvious Differences • Set of objects to be created is very different as is their appearance on the menu • How each object is drawn and how it relates to its control points is differen • The Geometry for selection objects differs

  40. Drawing Model • Drawing model is simple BUT the model is strongly linked with the presentation. • Objects in the drawing model differ in the way that they draw themselves and in the way that they handle their geometry. • This fuzzy relationship between the model and the presentation • The model for a drawing is simply a sequence of drawing objects that can be pained in order and a list of possible classes for drawing objects.

  41. public interface DrawingModel { public void addDrawingListener( DrawingListener listener); public void removeDrawingListener(DrawingListener listener); public int nDrawingObjects(); public DrawingObject getDrawingObject(int index); public void deleteDrawingObject(int index); public void addDrawingObject(DrawingObject newObject); public int nDrawingClasses(); public DrawingClass getDrawingClass(int index); } pubic interface DrawingObject { public void redraw(Graphics g); public boolean isSelected(Point mousePoint); public Rectangle getBounds(); public int nControlPoints(); public Point getControlPoint(int index); public void setControlPoint(int index, Point newPoint); public void addControlPoint(Point newPoint); public void move(int dX, int dY); } public enum InputSyntax{SINGLEPOINT, DRAGPOINT, MULTIPOINT} public interface DrawingClass { public Image getIcon(); public String getName(); public DrawingObject createNew(); public InputSyntax getSyntax(); }

  42. The DrawingModel itself consists of only three parts: • the registration of listeners • the list of drawing objects with means for deleting and adding them • a list of object classes that can be created. • A DrawingObject needs a means for drawing itself to a Graphics object (redraw), support for selection(isSelected and getBounds) and mechanisms for manipulating control points. • The DrawingClass contains the necessary information to create the menu and to create new objects.

  43. Widget tasks • 6 basic tasks that a widget must perform in either object creation mode (when one of the object classes is selected in the menu) or selection mode (when the pointer is selected in the menu) • Redraw the drawing from the model. • Create new objects on the drawing surface • Select objects • Drag objects around • Drag control points • Delete objects

  44. Redrawing public class DrawingWidget { private DrawingModel myModel; private int[] selectedObjects; . . . . public void redraw(Graphics g) { for (int i=0;i<myModel.nDrawingObjects();i++) { myModel.getDrawingObject(i).redraw(g); } for (int i=0;i<selectedObjects.length; i++) { DrawingObject so=myModel.getDrawingObject(i); for (int cp=0;cp<so.nControlPoints();cp++) { Point p=so.getControlPoint(cp); draw control point at point p } } } }

  45. Creating new Drawing Objects • nDrawingClasses() and getDrawingClass() methods give us the information that we need to build the menu of objects that we are offering to the user. • For each DrawingClass the getIcon() and getName() methods give us the information that we need to fill the menu. • Enumaration InputSyntax informs how the item is to be drawn • Single Click • Two Point Drag • Multi-point input

More Related