<HTML>
<HEAD><TITLE>A Case Study: Designing a Document Editor</TITLE>
<SCRIPT>
function setFocus() {
if ((navigator.appName != "Netscape") && (parseFloat(navigator.appVersion) == 2)) {
return;
} else {
self.focus();
}
}
</SCRIPT>
</HEAD>
<BODY BGCOLOR="#FFFFFF" onLoad="setFocus()";>
<A NAME="top"></A>
<A NAME="chapter_scenario"></A>
<P>This chapter presents a case study in the design of a
"What-You-See-Is-What-You-Get" (or "WYSIWYG") document editor called
<STRONG>Lexi</STRONG>.<A NAME="fn1"></A><A HREF="#footnote1"><SUP>1</SUP></A> We'll
see how design patterns capture solutions to design problems in
Lexi and applications like it. By the end of this chapter you will
have gained experience with eight patterns, learning them by
example.</P>
<A NAME="lexi-userint"></A>
<P><A HREF="#editor_Lexi">Figure 2.1</A> depicts Lexi's user interface. A
WYSIWYG representation of the document occupies the large rectangular
area in the center. The document can mix text and graphics freely in
a variety of formatting styles. Surrounding the document are the
usual pull-down menus and scroll bars, plus a collection of page icons
for jumping to a particular page in the document.</P>
<A NAME="editor_Lexi"></A>
<P ALIGN=CENTER><IMG SRC="Pictures/doc.gif"><BR><BR>
Figure 2.1: Lexi's user interface</P>
<A NAME="sec2-1"></A>
<H2><A HREF="#sec2-2"><IMG SRC="gifsb/down3.gif" BORDER=0 ALT="next: Document Structure"></A>
Design Problems</H2>
<A NAME="auto1000"></A>
<P>We will examine seven problems in Lexi's design:</P>
<OL>
<A NAME="auto1001"></A>
<LI><EM>Document structure.</EM>
The choice of internal representation for the document affects nearly
every aspect of Lexi's design. All editing, formatting, displaying,
and textual analysis will require traversing the representation. The
way we organize this information will impact the design of the rest of
the application.</LI>
<A NAME="auto1002"></A>
<P></P>
<A NAME="auto1003"></A>
<LI><EM>Formatting.</EM>
How does Lexi actually arrange text and graphics into lines and
columns? What objects are responsible for carrying out different
formatting policies? How do these policies interact with the
document's internal representation?</LI>
<A NAME="auto1004"></A>
<P></P>
<A NAME="auto1005"></A>
<LI><EM>Embellishing the user interface.</EM>
Lexi's user interface includes scroll bars, borders, and drop shadows
that embellish the WYSIWYG document interface. Such embellishments are
likely to change as Lexi's user interface evolves. Hence it's
important to be able to add and remove embellishments easily without
affecting the rest of the application.</LI>
<A NAME="auto1006"></A>
<P></P>
<A NAME="lexi-looknfeel"></A>
<A NAME="present-manage"></A>
<LI><EM>Supporting multiple look-and-feel standards.</EM>
Lexi should adapt easily to different look-and-feel standards
such as Motif and Presentation Manager (PM) without major modification.</LI>
<A NAME="auto1007"></A>
<P></P>
<A NAME="multiple-windows"></A>
<LI><EM>Supporting multiple window systems.</EM>
Different look-and-feel standards are usually implemented on different
window systems. Lexi's design should be as independent of the window
system as possible.</LI>
<A NAME="auto1008"></A>
<P></P>
<A NAME="auto1009"></A>
<LI><EM>User operations.</EM>
Users control Lexi through various user interfaces, including
buttons and pull-down menus. The functionality behind these
interfaces is scattered throughout the objects in the application.
The challenge here is to provide a uniform mechanism both for
accessing this scattered functionality and for undoing its effects.</LI>
<A NAME="auto1010"></A>
<P></P>
<A NAME="auto1011"></A>
<LI><EM>Spelling checking and hyphenation.</EM>
How does Lexi support analytical operations such as checking for
misspelled words and determining hyphenation points? How can we
minimize the number of classes we have to modify to add a new
analytical operation?</LI>
</OL>
<A NAME="auto1012"></A>
<P>We discuss these design problems in the sections that follow. Each
problem has an associated set of goals plus constraints on how we
achieve those goals. We explain the goals and constraints in detail
before proposing a specific solution. The problem and its solution
will illustrate one or more design patterns. The discussion for each
problem will culminate in a brief introduction to the relevant
patterns.</P>
<A NAME="sec2-2"></A>
<H2><A HREF="#sec2-3"><IMG SRC="gifsb/down3.gif" BORDER=0 ALT="next: Formatting"></A>
Document Structure</H2>
<A NAME="editor_sec_document_structure"></A>
<P>A document is ultimately just an arrangement of basic graphical
elements such as characters, lines, polygons, and other shapes. These
elements capture the total information content of the document. Yet an
author often views these elements not in graphical terms but in terms
of the document's physical structure—lines, columns, figures,
tables, and other substructures.<A NAME="fn2"></A><A HREF="#footnote2"><SUP>2</SUP></A>
In turn, these substructures have substructures of their
own, and so on.</P>
<A NAME="auto1013"></A>
<P>Lexi's user interface should let users manipulate these
substructures directly. For example, a user should be able to treat a
diagram as a unit rather than as a collection of individual graphical
primitives. The user should be able to refer to a table as a whole,
not as an unstructured mass of text and graphics. That helps make the
interface simple and intuitive. To give Lexi's implementation
similar qualities, we'll choose an internal representation that
matches the document's physical structure.</P>
<A NAME="auto1014"></A>
<P>In particular, the internal representation should support the
following:</P>
<UL>
<A NAME="auto1015"></A>
<LI>Maintaining the document's physical structure, that is, the
arrangement of text and graphics into lines, columns, tables, etc.</LI>
<A NAME="auto1016"></A>
<P></P>
<A NAME="auto1017"></A>
<LI>Generating and presenting the document visually.</LI>
<A NAME="auto1018"></A>
<P></P>
<A NAME="auto1019"></A>
<LI>Mapping positions on the display to elements in the internal
representation. This lets Lexi determine what the user is
referring to when he points to something in the visual representation.</LI>
</UL>
<A NAME="auto1020"></A>
<P>In addition to these goals are some constraints. First, we should
treat text and graphics uniformly. The application's interface lets
the user embed text within graphics freely and vice versa. We should
avoid treating graphics as a special case of text or text as a special
case of graphics; otherwise we'll end up with redundant formatting and
manipulation mechanisms. One set of mechanisms should suffice for
both text and graphics.</P>
<A NAME="auto1021"></A>
<P>Second, our implementation shouldn't have to distinguish between
single elements and groups of elements in the internal representation.
Lexi should be able to treat simple and complex elements
uniformly, thereby allowing arbitrarily complex documents. The tenth
element in line five of column two, for instance, could be a single
character or an intricate diagram with many subelements. As long as we
know this element can draw itself and specify its dimensions, its
complexity has no bearing on how and where it should appear on the
page.</P>
<A NAME="auto1022"></A>
<P>Opposing the second constraint, however, is the need to analyze the
text for such things as spelling errors and potential hyphenation
points. Often we don't care whether the element of a line is a simple
or complex object. But sometimes an analysis depends on the objects
being analyzed. It makes little sense, for example, to check the
spelling of a polygon or to hyphenate it. The internal
representation's design should take this and other pote
设计模式——可复用的OO软件
需积分: 0 113 浏览量
2007-10-20
12:56:46
上传
评论
收藏 4.22MB ZIP 举报
kittyjie
- 粉丝: 237
- 资源: 1615
最新资源
- 冯璐阳 42105650—祝福.docx
- 基于多种算法及改进算法实现的移动机器人路径规划matlab源码(含A星算法+PRM+RRT的改进等).zip
- 布里斯托尔纸细分市场、总体规模、先进性、市占率行业分析报告2024年.docx
- Obi绳子插件,好用的很 6.5.4版本
- openjfx-22.0.1-windows-x64-bin-sdk.zip
- 基于ros和stm32f1的小车代码(含串口通信)+项目说明.zip
- 人体姿态估计-基于Tensorflow实现的人体姿态估计算法-附项目源码-优质项目分享.zip
- java实现所有算法大全
- JDBC DAO模式 (复习)
- Proteus仿真AT89C51电子密码锁
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0