UQ Students should read the Disclaimer & Warning

Note: This page dates from 2005, and is kept for historical purposes.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--

Copyright © 2004 Ned Martin
http://copyright.the-i.org/
























Magic.

































































-->
<title>COMP2801 – Assignment 3 – Software Modification</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
<!--
.centre {
    text-align: center;
}
tr {
    text-align: left;
}
table li {
    padding: 0;
    margin: 0;
}
table ul {
    list-style: none;
}
.green {
    color: #008000;
}
.dark-green {
    color: #006400;
}
.dark-gray {
    color: #A9A9A9;
}
.slate-gray {
    color: #708090;
}
.blue {
    color: #0000FF;
}
.red {
    color: #FF0000
}
.navy {
    color: #000080;
}
.midnight-blue {
    color: #191970;
}
.teal {
    color: #008080;
}
.brown {
    color: #A52A2A;
}
.Xnines {
    color: #999999;
}
.code-samples {
    background-color: #FFFFE0;
}
.code-samples p {
    padding: 0;
    margin: 0;
}
-->
</style>
</head>

<body>
<h1>COMP2801 &ndash; Assignment Three &ndash; Software Modification </h1>
<p>I achieved twenty-three out of a possible thirty-five marks. </p>
<p>&nbsp;</p>
<hr />
<p class="centre"><strong><img alt="UMLet Logo" width="155" height="114"
src="COMP2801-assignment-3-files/image001.png" /></strong></p> 
<h1 class="centre">Software Documentation Project</h1> 
<h2 class="centre">ASSIGNMENT 3</h2> 
<p class="centre"><strong>Project Team</strong></p>
<p class="centre">Stephen Gordon<br /> 
Stephen Jenks<br /> 
Ned Martin<br /> 
Lachlan Smith</p>
<p class="centre">Tuesday 8am Group A</p> 
<hr />
<h2>Table of Contents</h2> 
<div class="centre">
<table style="margin:auto"> 
    <tr> 
        <td> <ul> 
                <li><strong>1. Introduction</strong></li> 
                <li><strong>2. Code Changes</strong> 
                    <ul> 
                        <li><strong>2.1. </strong>Feature Selection</li> 
                        <li><strong>2.2. </strong>Feature Implementation</li> 
                    </ul> 
                </li> 
                <li><strong>3. Testing</strong></li> 
                <li><strong>4. Team Journals</strong> 
                    <ul> 
                        <li><strong>4.1. </strong>Stephen Gordon</li> 
                        <li><strong>4.2. </strong>Stephen Jenks</li> 
                        <li><strong>4.3. </strong>Ned Martin</li> 
                        <li><strong>4.4. </strong>Lachlan Smith</li> 
                    </ul> 
                </li> 
                <li><strong>5. Appendix A &ndash; Evidence of Code Changes</strong> 
                    <ul> 
                        <li><strong>5.1. </strong>PrintPage</li> 
                        <li><strong>5.2. </strong>TipContainer</li> 
                        <li><strong>5.3. </strong>TipGenerator</li> 
                        <li><strong>5.4. </strong>TestTipContainer</li> 
                        <li><strong>5.5. </strong>AllTests</li> 
                        <li><strong>5.6. </strong>Colour</li> 
                        <li><strong>5.7. </strong>UniversalListener (amendments)</li> 
                        <li><strong>5.8. </strong>Generator</li> 
                        <li><strong>5.9. </strong>DimensionCalculator</li> 
                        <li><strong>5.10. </strong>GenEPS and similar</li> 
                        <li><strong>5.11. </strong>TestColour</li> 
                    </ul> 
                </li> 
            </ul></td> 
        <td> <ul> 
                <li><strong>2</strong></li> 
                <li><strong>3</strong></li> 
                <li>3</li> 
                <li>4</li> 
                <li><strong>8</strong></li> 
                <li><strong>12</strong></li> 
                <li>12</li> 
                <li>14</li> 
                <li>17</li> 
                <li>23</li> 
                <li><strong>28</strong></li> 
                <li>28</li> 
                <li>30</li> 
                <li>32</li> 
                <li>35</li> 
                <li>36</li> 
                <li>37</li> 
                <li>41</li> 
                <li>43</li> 
                <li>43</li> 
                <li>44</li> 
                <li>46</li> 
            </ul></td> 
    </tr> 
</table>
</div>
<hr />
<h2>1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Introduction</h2> 
<p>Software products follow a set life cycle that generally follows the pattern
    of analysis, design, implementation, and maintenance; this pattern can be managed
    in many ways such as the waterfall model and the phased model, amongst others.
    The maintenance phase, however, is consistent throughout all models, in that
    it is an ongoing process that lasts until the software product’s life is terminated.</p> 
<p>The maintenance of a software product can include many different operations
    being performed on the code. Some possibilities are the removal of bugs that
    were previously undetected during testing, alterations to the programs functionality
    by extensions to current features or the inclusion of new features, the improvement
    of in-code documentation, or re-factoring of the code.  Re-factoring can be
    used to improve the internal structure of the code to allow the program to run
    more efficiently, to improve the usability of the code by loosening coupling
    between classes, or just to improve the codes’ general structure.</p> 
<p>In prior research done by this group on the UMLet program, several areas were
    identified as candidates for improvement and a list of these can be found in
    the previously tabled report.  Several of these improvements have now been implemented
    and it is the purpose of this document to give an account of these changes. 
    The changes made to the UMLet program include extra features, and re-factoring
    of the program’s internal code.  As well as the changes to be made, methods
    were determined for testing the implementations of the changes, and these will
    also be outlined in this document.</p> 
<p>The extra features are the inclusion of a tip of the day generator, that appears
    upon original execution of the program or from a request in the menu bar, the
    ability to print UML diagrams from the drawing canvas, colour control of the
    UML entities, and a right click function to update UML relations. Code re-factoring
    was used to improve the object-oriented nature of the program by implementing
    a common interface for the save mechanisms that generate different file types
    from UMLet drawings.</p> 
<hr />
<h2>2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Code Changes</h2> 
<h3>2.1. Feature Selection</h3> 
<p>During an earlier stage of this project, a list of desirable features that
    could be added to the existing UMLet code base was presented with the goal being
    to implement these at some time in the future. As part of this next stage this
    list was re-examined and while some of those features listed have indeed been
    implemented some others have not. In this section, the reasons behind these
    decisions will be discussed.</p> 
<h3>2.1.1 Code Documentation</h3> 
<p>One of the major issues noted during the original examination of the UMLet
    source code was that for the most part it contained little or no commenting
    whatsoever. A result of this was that often building an understanding of the
    code or implementing changes to it was made much more difficult than would otherwise
    have been necessary. Unfortunately, the UMLet code package was found to be far
    too large to be documented in the short time available. As a result, the group
    chose instead to devote time to the implementation of other features and changes.
    The goal of improving code documentation was however achieved through the fact
    that all changes were fully labelled and documented. Where possible all documentation
    of implemented features was undertaken using full JavaDoc syntax.  This can
    of course later be parsed to Hypertext Mark-up Language (HTML) if desired, resulting
    in readable and user friendly documentation for both current and future editors
    of the code.</p> 
<h3>2.1.2. Toolbar</h3> 
<p>Another suggestion made after the initial code examination was that it might
    prove useful to add a toolbar to the UMLet program. While it is indeed quite
    possible that this would still be beneficial it was decided that such a modification
    would provide too little benefit as compared to the amount of change required.
    As such further developments in the area of improving the UMLet user interface
    were directed elsewhere.</p> 
<h3>2.1.3. Extending save and open functionality</h3> 
<p>The original suggestion for changes in this area was to add additional capabilities
    by enabling the program to save to and open from additional file formats. This
    was to be done by allowing, for instance, loading from the Scalable Vector Graphics
    (SVG) format. Since this time it has however been decided that with the ability
    to save to no less than five different file formats, including UMLet’s own format,
    which it can also load from, the software is more than capable enough in this
    area. It was however noted that the inability of the program to print was a
    somewhat major deficiency and as such, the group went about implementing functionality
    in this area of output instead. This new direction was also chosen because of
    the level of additional interest it provided for the development team. None
    of the team members had until now used the Java language’s printing support
    at all and as such, this presented an opportunity to learn something new while
    also working towards obtaining the goals of the project.</p> 
<h3>2.1.4. Additional UML icons and improvement of the palette.</h3> 
<p>No additional UML objects were added to the palette as had originally been
    suggested. After some consideration, however, it was decided that it would be
    beneficial to provide the ability to change the colour of items placed on the
    drawing canvas. It was felt that such a change would be beneficial in allowing
    users to highlight specific items in a drawing rather than force the use of
    UMLet’s default colour scheme, which is a bland black and white. Other changes
    to the palette were felt unnecessary as UMLet provides most, if not all, required
    UML drawing entities as is. Even if other drawing entities were required, their
    addition is not really a major programming task.</p> 
<h3>2.1.5. Code Re-factoring</h3> 
<p>During the planning for this stage of the project, it was suggested that some
    re-factoring of the UMLet code base might prove beneficial to both the team
    currently developing upon it and those who might choose to do so in the future.
    After some discussion, it was decided that the <em>com.umlet.control.io</em> package
    was most in need of attention. This was the most obvious area for re-factoring
    as a large number of classes found in this package accomplish very similar tasks
    yet are presented as completely separate classes rather than being grouped in
    some manner to indicate similarity of purpose. As such, this area was re-factored
    to better convey its purpose and workings. Details of the implementation of
    these changes are provided later in this document.</p> 
<h3>2.1.6. Online Help</h3> 
<p>Another feature planned for the development stage of this project was the
    addition of some form of online help service, however basic. As originally suggested
    a ‘Tip of the Day’ system has been added to the program and once again, the
    implementation of this is detailed later in this document. Unfortunately, due
    to both time constraints and also to the somewhat limited nature of UMLet’s
    feature set no other help facility has yet been added. This is mostly attributed
    to the fact that most users would more than likely benefit more from a well
    written online manual than any help ‘feature’ added to the code base. This is
    an area which could however be re-examined by future development teams.</p> 
<h3>2.1.7. User Interface (UI) Enhancement</h3> 
<p>Yet one more extra feature added to the UMLet program is a right-click activated
    popup menu.  The menu contains options to change the UML relations wherever
    they exist, which is in both the drawing panel and in the palette panel. The
    contained options are to change the relation’s body into either a solid or a
    dotted line, or to change either end of the relation to indicate a dependency,
    an inheritance, an aggregation, or a composition.  Only one aspect of the relation
    can be changed at a time and any further changes will require a successive right
    click on the particular relation requiring change.  As each change is made the
    properties panel is updated to reflect the change made to the current relation.</p> 
<p>The purpose of adding this functionality is that the only method for altering
    the relations previously was a text-based entry in the property panel.  Since
    the UMLet program uses a GUI based look and feel, the addition of a right-click
    method for relation alterations does improve upon this theme. The added functionality
    does not entirely remove the need for the text-based method, however, as not
    all possible alterations to the relations are accessible from the popup menu,
    although this would just require extra programming, perhaps along the lines
    of a multi-tiered style menu. As with all other changes discussed in this section,
    implementation specifics are detailed later in this document.</p> 
<h3>2.2. Feature Implementation</h3> 
<h3>2.2.1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Tip of the Day</h3> 
<p>To facilitate the addition of some user help functionality, as described previously
    in this document, it was decided to add the capability to display a ‘tip’ each
    time the program started as well as further tips on demand if required. As an
    example of the reusable nature of Object-Orientated (OO) design the majority
    of the code for the addition of this feature is entirely self contained and
    is connected to the main program with only a minor number of changes to the
    existing code base. As such it would be quite a simple matter to simply copy
    the new classes across to any other Java project and use them to provide the
    same functionality without having to rewrite the ‘tip of the day’ code. To facilitate
    the addition of tips without requiring a recompilation of the UMLet code all
    such data was stored in a new line delimited text file. While this is quite
    a basic storage method, it has proven to be quite adequate for the job. These
    factors combined mean that adding this functionality to a new project will,
    in most cases, not even need a recompile of the <em>TipGenerator</em> and <em>TipContainer</em> classes
    let alone any editing of the actual code they contain.</p> 
<h3>2.2.2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Printing</h3> 
<p>Surprisingly, the addition of the ability to print from UMLet was relatively
    simply accomplished. After some research was completed, it was found that while
    the Java language was unable to provide full printing, control libraries were
    provided to allow for most common operations in this area. To provide this functionality
    a new <em>PrintPage</em> class was created. This new class was built to implement
    the <em>Printable</em> interface as provided by the <em>java.awt.print</em> package
    in the Java libraries. After examining the requirements of the interface and
    the manner in which other classes responsible for outputting the contents of
    the drawing canvas worked the class methods were then created. </p> 
<p>The following methods have been provided within the new <em>PrintPage</em> class:</p> 
<ul> 
    <li><em>public static PrintPage getInstance()</em></li> 
</ul> 
<p>This provides a way for a program, in this case UMLet, to access the class,
    which is singleton.</p> 
<ul> 
    <li><em>public void doPrint()</em></li> 
</ul> 
<p>The <em>doPrint()</em> method creates a <em>PrinterJob</em> which is set to
    call this class’s print method when required. It then proceeds to present the
    user with a dialog box to select printing options before then attempting to
    call the job’s <em>print(…)</em> method to perform actual printing of the document,
    if necessary. Any exceptions related to printing are also caught here. It is
    also worth noting that the provision of an actual dialog box for printing options
    is handled by the host operating system as such can and will vary between platforms.</p> 
<ul> 
    <li><em>public int print (Graphics graphics, PageFormat format, int page)</em></li> 
</ul> 
<p>The bulk of the actual work undertaken by the class is contained in this method.
    As specified by the <em>Printable</em> interface it requires a graphics object
    to draw upon, a <em>PageFormat </em>object with all the required settings for
    the page and an integer representing the number of the page. As the method is
    actually called by the <em>PrinterJob </em>set to print this <em>Printable </em>object
    all of these parameters can in fact be provided with no real intervention from
    the programmer if required. Once called the method simply translates all objects
    on the drawing canvas onto the actual <em>Graphics2D</em> object to be printed
    and, if successful, returns the PAGE_EXISTS constant so that the <em>PrinterJob</em> may
    proceed to send the page to the printer.</p> 
<p>This new class was very simply hooked into the menu structure of UMLet via
    the addition of a new menu item and an appropriate change to the <em>ActionListener</em> attached
    to it. While the simplicity of this might give the impression that the <em>PrintPage</em> class
    could be reused in any other project this is unfortunately not the case. This
    is due to the fact that the <em>print(…)</em> method makes use of an UMLet specific
    call to find out what entities are on the drawing panel to print. As such to
    re-use this particular section of code in another project it would be necessary
    to make some alterations to build the data to be printed into an appropriate
    format. This however remains an example of how easy it can be to build basic
    but useful functionality onto a program using only the Java standard libraries
    and some minor code production.</p> 
<h3>2.2.3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Re-factoring
        – com.umlet.control.io</h3> 
<p>As part of the overall re-working of the UMLet code base undertaken in this
    assignment it was decided that some re-factoring of the <em>com.umlet.control.io </em>package
    would be beneficial. The goal of this action was to make the code layout to
    better reflect its actual purpose to anyone intent on further modifying the
    code base in the future. </p> 
<p>To facilitate this, an interface ‘<em>Generator</em>’ was created to be implemented
    by the existing <em>GenEPS</em>, <em>GenPDF</em> and <em>GenSVG</em> classes
    and any further classes used for file output. This interface specifies that
    all classes implementing it must provide the following methods:</p> 
<ul> 
    <li><em>public void createAndOutputToFile(String filename)</em></li> 
    <li><em>public void createToStream(OutputStream ostream)</em></li> 
</ul> 
<p>These two methods provide all the outward facing functionality required for
    UMLet to be able to access and use a given class for file output. All other
    methods required by a given file output class to complete its task can be kept
    completely separate from the main UMLet code base. On further investigation
    of the package, it was also found that the <em>GenPDF</em> class was responsible
    for the output of both PDF and JPG files due to some shared code. To provide
    a more consistent design in this area it was undertaken to separate this functionality
    by creating a new <em>GenJPG</em> class and moving the shared methods to the
    new <em>DimensionCalculator </em>class, which are called statically as required
    by both <em>GenJPG</em> and <em>GenPDF</em>. As a result of the above changes,
    some minor changes were made to the section of the <em>Umlet</em> class where
    the above classes and their respective methods are called from.</p> 
<p>So in summary, as a result of this re-factoring the following classes were
    changed or created:</p> 
<ul> 
    <li><em>Umlet</em> (Changed)</li> 
    <li><em>GenEPS</em> (Changed)</li> 
    <li><em>GenSVG</em> (Changed)</li> 
    <li><em>GenPDF</em> (Changed)</li> 
    <li><em>GenJPG</em> (Created)</li> 
    <li><em>DimensionCalculator</em> (Created)</li> 
</ul> 
<p>The end product of this is a package layout that much better reflects the
    actual capabilities and functionality of the package and provides a slightly
    wider scope for future re-use of code.</p> 
<h3>2.2.4 User Interface (UI) Improvement</h3> 
<p>The <em>UniversalListener</em> class is used to handle mouse events occurring
    in any one of the panels or in the top menu bar during the runtime of the UMLet
    program.  The addition of a right-click menu for the altering of UML relations
    was entirely implemented in the one source file, <em>UniversalListener.java</em> in
    the <em>com.umlet.control</em> package. The only methods called from other classes
    in the additional code are the <em>decomposeStrings</em> method from the </p> 
<p><em>Constants</em> class, and the <em>setPropertyPanelToEntity</em> method
    of the <em>Umlet</em> class. Both the <em>Constants</em> class and the <em>Umlet</em> class
    were already being called from within the <em>UniversalListener</em> class,
    so no new dependencies were created and as such, the coupling of classes was
    not made any tighter by the new implementation.</p> 
<p>To implement the right-click popup menu two of the existing methods in the <em>UniversalListener </em>class
    needed to be extended, the <em>mousePressed</em> method and the <em>actionPerformed</em> method. 
    Also, a couple of new methods were added, the <em>alterArrow</em> method and
    the <em>getUMLSymbol</em> method.</p> 
<p>The first of the extended methods was <em>mousePressed</em>. This method is
    called whenever the mouse is clicked on one of UMLet’s components. The functionality
    added to draw the right-click popup menu is called upon when the mouse is pressed
    if the component pressed on is an instance of a UML relation, and if the mouse
    button pressed is the right hand button. The popup menu contains several menu
    items relating to the different possible types that a UML relation can be. Each
    of these menu items has an <em>ActionListener</em> associated with them, and
    whenever an <em>ActionListener</em> detects an action, it calls the <em>actionPerformed</em> method.</p> 
<p>The second method extended was the <em>actionPerformed</em> method. The <em>actionPerformed</em> method
    in the UMLet program only handles events sent from menu items so extending it
    to handle menu items from a popup menu was not a difficult task, as it merely
    needed to have the extra menu item identification added. Each of the new menu
    items added to the <em>actionPerformed</em> method calls upon the <em>alterArrow</em> method.</p> 
<h3>2.2.5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Colour
        Support</h3> 
<p>Java’s polymorphic nature has made it both easy, and hard, to add colour support
    to UMLet. The initial difficulty was in understanding exactly how UMLet worked,
    and a basic introduction to this will be necessary to explain how colour support
    was added.</p> 
<p>All the entities UMLet displays are instances of the aptly named <em>Entity</em> class,
    or more strictly, various subclasses of this. Each subclass is responsible for
    the unique attributes of that particular <em>Entity</em>, such as its unique
    shape and any particular quirks that entity may have, such as arrow heads if
    it is a relation between other entities. Each <em>Entity</em> has a stored state,
    which is a combination of its unique attributes, and several common attributes
    such as its location, width and height. The unique attributes for each <em>Entity</em> are
    stored as a <em>String</em>, which is displayed via an editable palette on the
    UMLet interface, and it is through this properties palette that users are able
    to make changes to that particular <em>Entity</em>’s properties.</p> 
<p>Each <em>Entity</em>’s class parses its state from the properties palette,
    generally from their <em>paint()</em> method, and reacts accordingly. One of
    the problems encountered was that part of the state of each <em>Entity</em> is
    actually drawn as text to that <em>Entity</em>, while other parts of an <em>Entity</em>’s
    state modify properties of the <em>Entity</em> and aren’t actually displayed.
    This is handled by a simple if/else within each <em>Entity</em>, where its state
    is parsed, and any state that doesn’t correspond to a hidden modifier is then
    output to the <em>Entity</em> as text.</p> 
<p>The first step in giving UMLet colour support was adding a hidden colour modifier
    to each <em>Entity</em>. The syntax used follows that used by UMLet’s existing
    property modifiers, “modifier=property”, which, in the case of colours, is “c1=r
    g b” and “c2=r g b”, where “c1” and “c2” are the foreground and background colours
    respectively, and “r”, “g” and “b” are integers between 0 and 255 representing
    red, green and blue. The problem with using this method is that colour support
    is not unique to each <em>Entity</em> type, and as such should be included within
    the <em>Entity</em> class, rather than duplicated within each of its subclasses,
    but the current method used within UMLet would mean that the modifiers would
    then be output to each <em>Entity</em> as text, rather than hidden. To counter
    this problem, a <em>paint()</em> method was added to the <em>Entity</em> class,
    and each subclass makes a call to <em>Entity</em>’s <em>paint()</em> method
    from within its <em>paint()</em> method, and its state is initially parsed within <em>Entity</em>’s <em>paint()</em> method,
    rather than its own.</p> 
<p>A new class, <em>Colour</em>, was introduced to handle the various functions
    related to providing colour support, and contains the following publicly useable
    methods:</p> 
<ul> 
    <li><em>public static Object[] parseActive(String palletteProperties)</em></li> 
</ul> 
<p>This method accepts a <em>String</em> representing the palette properties
    for the current <em>Entity</em>, and returns an array of <em>Object</em>s. The
    first element within the array is a <em>Vector</em> representation of the palette
    properties <em>String</em>, which returned to the <em>Entity</em> for further
    parsing, stripped of any hidden colour modifiers. The second and third <em>Object</em>s
    in the returned array are the foreground and background colours parsed out of
    the palette properties <em>String</em>.</p> 
<ul> 
    <li><em>public static Color decode(String colour)</em></li> 
</ul> 
<p>This method accepts a <em>String</em> and returns the colour represented by
    the <em>String</em>. It expects the <em>String</em> to be in the format “r g
    b” where “r”, “g” and “b” are <em>String</em> representations of integers from
    0 to 255, representing the amount of red, green and blue respectively. This
    method gracefully handles “invalid” input not in the expected format, returning
    the <em>Color</em> black if it is unable to parse the input <em>String</em> into
    valid red, green and blue components, or tending towards black if it is unable
    to parse only a portion of the input <em>String</em>. This method is used to
    generate the foreground colours.</p> 
<ul> 
    <li><em>public static Color decodeFill(String colour)</em></li> 
</ul> 
<p>This method is identical to the one above, except that it tends towards the
    Color white on invalid input. This method is used to generate the background
    colours.</p> 
<p>Two other slight modifications were made, one to support the existing feature
    where an <em>Entity</em>, when selected, assumes a different colour, and a new
    feature, where an <em>Entity</em> has a bolded border when selected, bringing
    UMLet inline with many other applications. The colour change on select is handled
    in <em>Entity</em>’s <em>paint()</em> method along with the colour parsing,
    simply providing a different colour if the <em>Entity</em> is currently selected
    by the use of a simple test. This was previously handled by an <em>onSelect()</em> method
    within <em>Entity</em>, which set a global variable to the suitable colour for
    use by the subclass’ <em>paint()</em> method whenever an <em>Entity</em> was
    selected, and then called <em>repaint()</em> to repaint that <em>Entity</em>.
    This method has been preserved, but now only calls <em>repaint()</em> to ensure
    an <em>Entity</em> is repainted when its selected status changes. The bolding
    is handled in each subclass of <em>Entity</em>, due to the unique drawing requirements
    of each type of <em>Entity</em>, and is also a simple test if the <em>Entity</em> is
    currently selected, changing the drawing attributes in that particular subclass’ <em>paint()</em> method
    if it is selected.</p> 
<hr />
<h2>3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Testing</h2> 
<h3>3.1.      Tip of the Day</h3> 
<h3>3.1.1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Goals</h3> 
<p>The ‘Tip of the Day’ feature that has been added to UMLet is intended to complete
    a very specific task and as such testing in this particular case proved relatively
    straight forward. The goals for the testing of these classes were:</p> 
<ol> 
    <li>Check a tip is displayed on program start.</li> 
    <li>Check that a tip is displayed when requested from the menu.</li> 
    <li>Check that tips are loaded correctly from the ‘tips.txt’ file.</li> 
    <li>Check that tip to be displayed is selected randomly from those in the aforementioned
        file.</li> 
</ol> 
<p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </strong><strong>Methodology</strong></p> 
<p>Despite the Graphical User Interface (GUI) nature of the actual tip of the
    day functionality, it was found to be possible to make use of a test script
    to test the new <em>TipContainer</em> class automatically. The test class created
    for this purpose is <em>TestTipContainer </em>in the new <em>com.umlet.testing</em> package.
    This class makes use of the JUnit test engine to automatically test the capabilities
    of the <em>TipContainer</em>. To do this the test script accesses the container
    in various states before and after adding new tips. This basic testing simply
    provides a way to eliminate fence post errors and the like, which are liable
    to result in a <em>NullPointerException</em> at run time if not handled correctly.</p> 
<p>All further testing of the class was undertaken manually by starting the program
    multiple times to check that a randomly selected tip was displayed each time,
    starting the program when no tips.txt file was present and accessing the menu
    option multiple times, once again to check random tips were being displayed
    each and every time.</p> 
<p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </strong><strong>Results</strong></p> 
<p>Due to the relatively simple nature of this feature, it proved quite possible
    to successfully test all of the added functionality with the simple testing
    outline above. As a result of this, several errors were located and removed
    including a minor error with tip selection in the original code.</p> 
<h3> 3.2.     
        Printing</h3> 
<h3>3.2.1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Goals</h3> 
<p>When testing the printing class it was felt that the group could ensure that
    all entities on the palette could be printed and that the newly added colour
    support would also be reflected in print outs.</p> 
<h3>3.2.2    Methodology</h3> 
<p>Due to the very nature of the added printing functionality, in that it is
    called by a GUI action and expects a drawing to be present for printing, it
    proved impossible to write an automated test script. As such all testing of
    this new feature was undertaken manually by creating drawings with each of the
    UML entities represented and then testing various variations with and without
    colour. While tests were sent all the way to the printer on several occasions,
    it proved beneficial to use the ‘print to file’ option of the host operating
    system to save to PostScript. These PostScript files were then examined for
    correctness using the GhostScript tool under the UNIX environment. Worth noting
    is that testing of printing functionality occurred on both the Windows and UNIX
    platforms but as no member of the team has direct access to a Macintosh, performance
    on this platform is as yet untested. As Java relies heavily on the host operating
    system to provide printing support this is a rather unfortunate but unavoidable
    omission in testing. Theoretically, if the functionality works correctly under
    the Java Virtual Machine (JVM) on one platform, as it does in this case, then
    it should also perform correctly on all other platforms, in reality however,
    this is not always the case.</p> 
<h3>3.2.3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Results</h3> 
<p>The printing functionality proved to work correctly in all manual tests undertaken
    including those where use had been made of the newly added colours support.
    In these tests in was found that there are some problems with varying margins
    between printers. Unfortunately, as yet no fix has been found for this problem,
    but it does not prevent the user from printing out most, if not all, basic diagrams
    as it only becomes a problem as the size of the diagram grows towards that of
    a full page.</p> 
<h3>3.3.      Re-factoring</h3> 
<h3>3.3.1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Goals</h3> 
<p>After the re-factoring of the IO package all classes involved in the generation
    of files were expected to require testing. The list of classes changed and likely
    to require at least some testing as a result included:</p> 
<p>·&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <em>GenEPS</em></p> 
<p>·&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <em>GenJPG</em></p> 
<p>·&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <em>GenPDF</em></p> 
<p>·&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <em>GenSVG</em></p> 
<p>·&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <em>DimensionCalculator</em></p> 
<h3>3.3.2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Methodology</h3> 
<p>Of the classes in the package listed as requiring re-testing, only the new <em>DimensionCalculator</em> class
    cannot be tested directly but rather is called by <em>GenJPG </em>and <em>GenPDF</em>.
    Unfortunately, once again all the <em>Gen*</em> classes rely on an a full image
    being provided as input and the only output goes to a file rather than being
    a returned value which can be tested. As such, manual testing was once again
    undertaken for these classes. This involved drawing up a series of diagrams
    making use of all entities on the UMLet drawing palette and saving to each of
    the available output formats. Once this was complete each newly created file
    was opened in an appropriate editor and checked for correctness.</p> 
<h3>3.3.3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Results</h3> 
<p>All of the modified output classes were found to work correctly using the
    manual testing methods detailed above. Even with special attention given to
    the <em>GenJPG</em> and <em>GenPDF</em> classes where the largest changes were
    made, no problems were found and as such, the <em>com.umlet.control.io</em> package
    is considered to be of production quality.</p> 
<h3>3.4.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; User
        Interface (UI) Improvements</h3> 
<h3>3.4.1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Goals</h3> 
<p>Testing for the right-click popup menu was done manually to show several events
    being completed successfully upon request. These events and the order in which
    they were expected to occur are:</p> 
<ul> 
    <li>The popup menu is only to appear when a relation is right clicked on.</li> 
    <li>Once on-screen, the relation’s popup menu is to contain all the required
        selectable choices.</li> 
    <li>If a selection is made the relation is updated with the expected change.</li> 
    <li>The change made is reflected in the properties panel.</li> 
    <li>The change made is persistent after the relation is deselected.</li> 
</ul> 
<h3>3.4.2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Methodology</h3> 
<p>Testing of this new feature was not an extensive task and did not require
    the creation of a large test harness to help ensure that each new addition to
    the code maintained Umlet in a working state. This is because these new features
    work at runtime and require user interaction rather than methods returning variables
    for calculations of lists. Although there are classes provided with Java and
    third party programs that are able to test user interaction processes, the extra
    speed gained by using these compared to manual checking would not outweigh the
    time taken to implement them on this relatively small additional feature.</p> 
<p>To satisfy each of the points mentioned in the goals for testing this new
    feature to UMLet, testing occurred on each of the steps aforementioned in order
    by first checking that the program could be compiled, and then trying to use
    the feature up to the point of its implementation so far.</p> 
<p>Since the code for mouse listeners is from a standard Java library this was
    not tested. What was tested was that if a right-click was made, the conditional
    statement for separating a right click on a relation from other <em>mousePressed()</em> events
    was made, this was tested by simply inserting a call to print to the screen
    a particular indicating statement.  From this statement, it was also possible
    to tell if, when multiple relations were clicked on, that they were different
    relation instances.  This indicating statement was removed from the code when
    it was determined that the implemented code worked.</p> 
<h3>3.4.3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Results</h3> 
<p>As the steps for implementing the right-click popup menu were performed consecutively,
    there was an assurance that once one part of the implementation was deemed to
    be working correctly the next step of the implementation process could be attempted.
    This method follows the waterfall method with a slight twist by adding an iteration
    of the implementation and testing phase, this seemed the most logical method
    for such a minor change that had little effect on any other parts of the program.</p> 
<h3>3.5.      Colours</h3> 
<h3>3.5.1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Goals</h3> 
<p>The <em>Colour</em> class provides a specific functionality to Umlet, namely
    it allows a user to specify foreground and background colours for a selected <em>Entity</em>.
    Testing had to ensure that the class was able to accept and gracefully handle
    any input a user might give, producing logical results, and that all existing <em>Entity</em>’s
    still behaved as expected, except displayed the appropriate colours when expected.
    Specifically, the <em>Colour</em> class should accept any given <em>String</em> and
    return a valid <em>Color</em>. If the <em>String</em> is a valid representation
    of three integers in the ranges 0 to 255, then the <em>Color</em> returned should
    match that given by interpreting the <em>String</em> as a series of red, green
    and blue values. Furthermore, if the <em>String</em> is intended to represent
    a foreground colour, the <em>Color</em> produced should tend to black. That
    is, if invalid input is given, the <em>Color</em> output should be black, and
    if partially valid input is given, such as a <em>String</em> containing representing
    a single integer, the remaining values should tend to zero. Similarly, if the <em>String</em> is
    intended to represent a background colour, the <em>Color</em> output should
    tend towards white.</p> 
<h3>3.5.2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Methodology</h3> 
<p>A testing script <em>TestColour</em>, using the JUnit testing framework, was
    used to automate the testing of the <em>Colour</em> class. As external interaction
    with the <em>Colour</em> class is limited to a <em>String</em> input and three
    known outputs, the test script simply sends a series of randomly chosen but
    valid and randomly chosen but invalid <em>String</em> inputs and tests that
    the required outputs are returned and that they match the expected outputs for
    that <em>String</em> input. Despite sounding simple, this task was complicated
    by the robust design of the <em>Colour</em> class, as it will accept many partially
    valid <em>String</em> inputs and still return a valid output.</p> 
<p>In addition to the automated testing, manual testing was performed to test
    such aspects as the integration with the rest of Umlet and to ensure that <em>Entity</em>’s
    still behave as expected. Several instances of each type of <em>Entity</em> were
    created, set to various colours, and each of their properties changed. The workspace
    was saved to a file at various stages, and reloaded at a later date, and saved
    to each of the available output formats, including the newly added printing
    support.</p> 
<h3>3.5.3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Results</h3> 
<p>Automated testing showed that the <em>Colour</em> class is able to handle
    all possible input while still producing the expected output, and will not produce
    any unexpected behaviour under normal operating conditions.</p> 
<p>The manual testing demonstrated with a reasonable degree of certainty that
    the existing functionality has not been altered, and that <em>Entit</em>y’s
    behave as expected when coloured.</p> 
<hr />
<h2>4.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Journals </h2> 
<h3>4.1. Stephen Gordon</h3> 
<p>[Removed for privacy]</p>
<!-- Removed for privacy
<h3>4.1.1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Original Journal</h3> 
<p>Software design theory is integral to the accomplishment of any significant
    task in programming or software development. While without good design practices
    it is possible to write working code projects written in this way tend to get
    hard to manage quickly and the initial quick speed of development slows to a
    crawl. This results from both the added difficulty of finding specific sections
    of code as a poorly designed project grows and the continuous code re-writing
    and re-structuring process which is forced as features need to be added to the
    code base. Unfortunately what exactly defines 'good' programming practice is
    open to constant debate and revision, creating a somewhat moving target. Object-orientated
    languages, specifically those like C# and Java, tend to promote many of the
    key ideas that are often promoted as central to good programming design. For
    the most part this is a result of the aforementioned languages essentially forcing
    tasks such as allowing for code re-use and separating major program functionality.</p> 
<p>As the code for the project documented in this report was written in the object-orientated
    Java language it was quite a simple task to divide the documentation task between
    group members by assigning different class or object files to each group member.
    When it was necessary classes were documented in small groups to display clearly
    the intertwining nature of the code, in all other cases classes were documented
    individually. In all cases documentation consisted of a reasonably concise description
    of the class and its' purpose along with a UML diagram displaying appropriate
    additional information. For consistency reasons all UML diagrams were later
    completed using Visio.</p> 
<p>During the project resources consulted included the UMLet homepage, Apache
    Software Foundation (ASF) sites as well as the source code itself. The UMLet
    homepage proved next to useless as little or no documentation is provided aside
    from a mediocre Frequently Asked Questions (FAQ) file relating mostly to installation
    procedures. Various ASF sites were consulted on multiple occasions to obtain
    information relating to the various libraries UMLet relies on which are made
    by the foundation. Luckily these sites generally proved to be extremely useful
    with full and thorough documentation of all aspects of the various projects.
    The level of detail found in the documentation on the ASF sites was in many
    cases, well above that required for the purposes of this project. Obtaining
    information from the source code was unfortunately not as easily facilitated
    as for the most part there was little or no source code documentation of tangible
    value to be found in the UMLet project. This however simply forced team members
    to delve deeper in their search for a full understanding of the code and as
    such this process, while time consuming, was more than likely worthwhile. </p> 
<p>During the process of the project there were several mistakes made by the
    team which while not large enough to prevent the task from being completed were
    certainly less than helpful. An example of this is the way in which the groups'
    software package was chosen, there is little doubt that if any team member had
    investigated thoroughly and discovered the lack of a build file and source code
    commenting it would have been extremely unlikely that UMLet would have been
    chosen. It has also been noted that deadlines could and should have been used
    more effectively in the process of this project. While at times deadlines were
    set it is fair to say that no group member ever accomplished the given tasks
    in the set time frame. Upon completion of this document and commencement of
    the program enhancement stage it is more than likely that some group discussion
    and reflection will occur in relation to this issue. Hopefully this will result
    in a more rigid and forward thinking plan covering the entirety of the next
    project.</p> 
<p>At this stage of the course some additional knowledge has been acquired to
    add to that held previously although not as much as might have been liked. A
    large part of this additional knowledge gained was related to streamlining of
    the build process using ANT and was obtained during the generation of a build
    script for UMLet. Some useful knowledge has been obtained in the use of UML
    diagrams to illustrate program semantics however once again this has not really
    been picked up as well as might have been hoped.</p> 
<p>Despite some hiccups the team appears to have accomplished it's goals for
    this assignment, the classes we set out to document have indeed been documented
    and plans have been made for future projects based on this documentation. Overall
    the only goal not accomplished was that of having a full draft written with
    plenty of time to spare, unfortunately this however may in many ways simply
    be a side effect of working in a group which cannot meet as often as might be
    liked due to members' conflicting weekly schedules.</p> 
<p>While this course is providing good grounding for the kind of software design
    and understanding required to extend existing programs it is possible that better
    insights into the actual software design process might come from actually designing
    and creating software. This however is of course a much larger undertaking and
    as such could well be beyond the scope of a second year subject. All in all
    however this project has been a definite learning experience although whether
    it has been more beneficial to software development or project management knowledge
    is still undecided.</p> 
<h3>4.1.2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Updated Journal</h3> 
<p>After the completion of the investigative stage of the course assignment three
    perhaps presented the best practical application of skills learnt over the past
    year or so of Information Technology I have studied at the University of Queensland.
    Despite the obvious failings of a program as simple as UMLet there is still
    much to learn from developing upon a real program, as opposed to a something
    a course coordinator has knocked up to demonstrate how to use a linked list.
    It was with these thoughts that I approached this final assignment, from an
    initial glance at the assignment specifications it appeared that skills developed
    would include the ability to extend the source code of others and to test and
    re-use it appropriately.</p> 
<p>As the group began moving towards the actual commencement of work for the
    project there were once again problems with delegation. With assignment two
    still lingering in people’s memories everybody was keen to ensure an equal distribution
    of work. In the end the project was divided into four areas, coding, presentation
    preparation, report preparation and diagram creation. With this set out it proved
    reasonably easy for everyone to find a way in which they could contribute meaningfully
    to the finished product that you see before you, there were still some issues
    but they were much better handled this time around.</p> 
<p>The coding of new features into UMLet and the re-factoring of some areas proved
    most beneficial in that it provided a very immediate and gratifying result.
    This is of course compared to previous course where the source of joy and jubilation
    after a night’s hard coding was to see a string pulled from a binary tree rather
    than a null pointer exception. While some of the features added probably aren’t
    that beneficial to the end user the development of their inner workings has
    more than likely benefited the group members involved in some way.</p> 
<p>Unfortunately the same might not be said for testing, while this area was
    taught as part of the course very little of the covered material could be applied
    in any way shape or form to a program which relies extensively on actions in
    a Graphical User Interface (GUI). As a result most of the testing that was carried
    out was of a tedious manual type and as such rather useless as far as learning
    anything. It was however still an interesting insight into some of the problems
    facing developers working on graphical applications. </p> 
<p>In the closing stages of the project when deadlines were drawing near and
    both the presentation and report were not yet complete the group’s time management
    issues once again came to light. This time however there was to be no 4AM finish
    the morning the assignment was due (or maybe I speak to soon since as I write
    this there is still some finishing to do), instead the 4AM session was done
    a whole TWO DAYS early. This is an obvious improvement and as such should be
    applauded. Of course such a huge improvement left some group members feeling
    out of place and as such we let the chief widget drawer to do the UML diagrams
    on the last night, as he has become accustomed to.</p> 
<p>Somewhat impressively the group has once again managed to complete the assignment
    with no organized group meeting as such, apart from when three of us happened
    to be in the labs at the same time. This is obvious proof that e-mail is coming
    of age and as such Information Technology professionals like ourselves no longer
    have to converse with other humans in a vocal manner. This is a day I have long
    been waiting for.</p> 
<p>All around I was much more impressed with the level of contribution of every
    single member of the group in this assignment, while as already mentioned the
    report is not fully complete at this stage it is very close and as such it is
    worth noting that all submissions appear to be well thought out and organized.
    This is possibly a reflection of the added time group members gave themselves
    to get the work started slightly earlier and if so this is an extremely commendable
    thing. Even if this is simply some form of fluke it is a testament to the skill
    of those concerned. As such I will close this journal by stating that despite
    some earlier misgivings I end this subject quite pleased with the efforts of
    all my group members and feel I have probably learnt more in this subject from
    working with them than I have by studying the actual course material.</p> 
-->
<h3>4.2. Stephen Jenks</h3> 
<p>[Removed for privacy]</p>
<!-- Removed for privacy
<h3>4.2.1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Original Journal</h3> 
<p>The following information is a summary from the scraps of ideas within documents
    and my head that I have written or thought about software design over the past
    3 weeks.  Initially I have been creating my programs with the ad-hoc approach,
    but have found that over the course of this semester I am beginning to write
    my programs differently, I am recognizing the value of understanding patterns
    and I don’t think I could produce code without thinking about the design I will
    incorporate into the program.  I am not up to the stage of writing UML modeled
    diagrams on paper following the factory method and then implementing this into
    a large program, but I am trying to use a design while I am programming.</p> 
<p>The theory of software design has helped me in the understanding of large
    programs because it has allowed me to understand ways in which to divide the
    program into smaller pieces that are more easily understood.  These pieces when
    assembled follow general patterns that are widely known and therefore make a
    large program fit into a familiar structure, for someone who knows software
    design methods.  When the creation of a large software system is developed,
    it usually goes though a process of requirements analysis, design, implementation
    and then maintenance.  By understanding the theory of design I am more easily
    able to see from a model of a program how its different pieces interact.</p> 
<p>There have been two basic strategies that I have used for the purpose of understanding
    the code of our groups program.  The first has been simple inspection, I have
    grabbed a class and read it.  While reading the class any objects that the class
    is associated with, that do not belong to the standard java libraries, I search
    for in the rest of the programs class list and try to understand what they do. 
    The second strategy I used was to reverse engineer the java files using Rational
    Rose, from the diagram I obtained I was able to see associations between the
    classes, once again not concerning myself with standard java libraries.  Also
    Rational Rose’s ability to allow you to look at code through its interface while
    looking at how the classes combine was a much more efficient way of understanding
    the documentation, compare this with opening the files up with an editor and
    swapping between class files and trying to remember their connections to each
    other.</p> 
<p>Apart from using Rational Rose and various other Java Integrated Development
    Environments (IDEs), used for the purpose of perusing the code, no other resource
    was really used during this few weeks.  The Internet was not used at all for
    the purpose of gaining understanding of our groups program due to after initial
    searches when looking for information to help with the first assignment it was
    discovered there was very little helpful information.  Also for this part of
    the course the CVS has been used little by me.  This is mainly because the code
    has not been altered and therefore the java files that were taken out of the
    CVS three weeks ago are no different to any java files in the CVS now, no new
    versions have been created, also I haven’t used the CVS as a repository for
    my journal upkeep or any other files associated with the writing of this assignment. 
    The only other resource used was Microsoft Visio, this was used to help me with
    the drawing of UML elements.</p> 
<p>During the course of this project the team hasn’t made any fundamental mistakes
    in there understanding or execution of the task due to their understanding of
    the course work, as far as I can tell.  Our group has maintained enough contact
    to discuss any difficulties that any particular person may have had, but at
    each of these meetings little has needed to be discussed, as no one has really
    had any difficulties, most of this type of contact has be brief.  Perhaps this
    in itself could be considered a mistake as possibly more time spent as a group
    may have had the assignment completed sooner, but unless the assignment is not
    submitted before the due date then this isn’t really a mistake.</p> 
<p>Before this semester I did not know hat rational Rose existed, but I was aware
    of UML and had had some small experience in using that particular modeling language
    although I did not know it to the same degree as taught in this course.  I would
    like to say that I now understand everything that has been offered in the course
    since the start of the semester, but this unfortunately is not true.  I feel
    it is good to reflect upon what you have learnt as this probably helps a bit
    at exam time, one area I definitely know more about is the design mo0dels used
    in software projects.</p> 
<p>Our teams goals have been to document UMLet with the thought of providing
    ourselves with an understanding how the program works to be able to find an
    area were the program can be improved of extended, I feel we have achieved this. 
    Apart from the assignment specs to be completed, I think that the assignment
    is attempting to give us experience at looking at real world code and to show
    us some useful techniques employed by developers who are possibly outside of
    a learning institution (perhaps not), also by seeing real world code we may
    see some bad habits and poor excepted practice.  Over the course of this assignment
    there have been observed both good and poor techniques.</p> 
<p>So far I have learnt the basics of creating code, usually written in java
    but sometimes in other languages, they so far all seem to follow at least similar
    semantics if not syntax.  Object orientation has been an extension to this,
    and software design has always gone with this hand in hand.  This course has
    yet again furthered my understanding of software design by giving the commonly
    used design patterns and further understanding of UML to allow a simple way
    for representing the design of a program.  As for furthering my understanding
    of design, perhaps being able to determine user needs and requirements and creating
    a design from this analysis to discover give the user what they want, possibly
    before they even know they want it.</p> 
<h3>4.2.2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Updated Journal</h3> 
<p>During the time I have spent studying this course I have learnt a great deal
    about the types and uses of different design patterns used in program creation. 
    When the exact type of patterns were described during lectures I generally found
    that I understood the idea behind the particular pattern, however when looking
    at the code used by our group in the assignment, trying to determine the patterns
    used was quite a difficult task, even with the aid of Rational Rose to reverse
    engineer the code and create design documentation in UML.  This is probably
    due to lack of experience and also to the fact that not all the patterns possible
    could be contained in the code, and as such I was searching for something nonexistent.</p> 
<p>To alleviate this problem I feel that the possible inclusion into the course
    could be a </p> 
<p>well-designed piece of set code that is known to contain examples of the design
    patterns taught during this subject.  In this way students could be graded according
    to the various patterns they detect in the custom built program, also or alternatively
    the program could contain known design defects that could be good bases in allowing
    for refactorisation.  This would allow the students learning to be controlled
    so as to ensure that students at least have the required material to begin with,
    although the reality of real world situations is that nothing is guaranteed. 
    I am sure the debate against real world compared to a controlled learning environment
    is a constantly reassessed balancing act, that is weighted by the ability of
    us as students compared to us as future professionals.</p> 
<p>Testing was another major area to be learnt in this course and was apart from
    the theory implemented by a guide to the use of Junit.  Junit is probably a
    very useful tool, however because of UMLet3 being our groups choice of open
    source software, and the improvements that I made to the code being very user
    orientated at runtime, I must admit I didn’t touch Junit apart from during the
    one practical class.  This is a great pity because I missed out on something
    that was to be learnt, and this will possibly affect me at exam time, and also
    I would have liked some practice with the product for future use.  This once
    again could possibly been fixed by a preset piece of code specifically created
    for this subjects assignments.</p> 
<p>For this assignment the change to the source code that I made was the inclusion
    of a couple of methods and a few lines of code into existing methods, both of
    these inclusions types were for the implementation of a new function that the
    program could perform.  Due to the code I implemented being functional rather
    than design orientated the resources that I used were references to code implementations
    of a specific nature.  After reflection of this I feel that it would have been
    more along the lines of what this course was attempting to teach had I made
    a refactoring style change, and focused my learning on the design rather than
    the implementation of programming projects, although had the change been less
    of a user interaction type implementation I may have gotten a bit more of this
    course’s intentions by discovering and using testing methods other than visual
    inspection.</p> 
<p>This assignment was an extension to assignment two, so many of the ideas that
    the group had for this assignment was seeded during the second assignment and
    a lot of the work was in a sense determined then, so it is quite difficult to
    state how this assignment was approached compared to assignment two. Same people,
    same open source program and a joining of assignments through the tasks leads
    to very few changes, especially since in my opinion our group did a fair job
    in assignment two.</p> 
<p>I feel that our group has as its members very talented people and one of the
    problems with this was a difficulty of dividing the tasks, as all of the members
    in this group wish to contribute more to the assignments.  This did not change
    from assignment two to assignment three either, and as a group we found that
    we did not have the problem of any members of our group trying to take a free
    ride on the backs of other group members.</p> 
-->
<h3>4.3. Ned Martin</h3> 
<h3>4.3.1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Original Journal</h3> 
<p>Apparently, I’m supposed to have been keeping a “team learning journal”, but
    I haven’t been so I’m currently in the same situation as the proverbial. To
    rectify this situation, I have decided to paraphrase various parts of another
    journal I have been keeping, interspersed with my own (occasionally accurate)
    recollections, and attempt to formulate from this something that vaguely matches
    the description of what a team journal should be.</p> 
<p>First, a little about myself – I am Ned. Hear me roar. That done, I guess
    I may as well begin at the beginning, way back in July – Thursday, 15th July,
    to be precise.</p> 
<p><em>Thursday 15 July – Sign On</em></p> 
<p>I woke up at a horribly early hour, to sign on for my COMP2801. I’ve gone
    from having an all but perfect timetable, to a pretty average timetable, to
    a rather bad timetable with two eight o’clock starts and a five o’clock finish
    on Friday – due to tutoring. Hopefully it’s worth it, and everything works out
    ok. </p> 
<p><em>Monday 26 July – First Lecture</em></p> 
<p>The next COMP2801 thing of any import was the first lecture, which I attended
    quite too bright and early one Monday morning. I believe I’ve dutifully attended
    all lectures since, and found them instrumental in helping me understand UML,
    along with the tutorials. This has been particularly handy, as I don’t have
    any UML textbooks.</p> 
<p><em>Tuesday 27 July – Practical 1</em></p> 
<p>I woke up when my alarm went off, at six o’clock, and again eight minutes
    later. Eight o’clock starts aren’t my favorite things. Nevertheless, I managed
    to get to uni on time, and it wasn’t even that cold. I found the right room
    for my practical, and formed a group with the three people sitting nearest me
    – all of whom I happened to know, vaguely. I had been a little worried that
    I’d end up being automatically assigned a group of dumb people – less intellectually
    endowed people, I should say, or people who wouldn’t do any work, couldn’t speak
    English, were intolerable, had multiple open wounds, etc. I just wasn’t quite
    sure what people would go to an 8 AM practical, because, by my logic, no sane
    person would intentionally sign up for something that early. Fortunately, though,
    I think the group I’ve managed to get are reasonably intelligent, willing and
    able to try, well versed in basic English and other associated communication
    skills, including, but not limited to, the ability to write and talk in an understandable
    manner, and so on, and so forth. In other words, I’m hopeful that I’m in a good
    group.</p> 
<p>&nbsp;We then proceeded to “bond”, by attempting to survive a plane crash
    in snowy, sub-zero northern Canada, in a wooded area crisscrossed with creeks
    and roughly 20 miles from the nearest town. Luckily, we had some vital survival
    equipment, such as a lighter with no fluid, a ball of steel wool, and two dead
    pilots. We had to individually rank these (and several other) items in order
    of importance to our survival, and then do the same again but as a group. We
    then compared our results to that of an “expert”, who, I suspect, would accidentally
    kill himself (and several innocent bystanders) while trying to survive a trip
    to the local supermarket. Nevertheless, we bonded, and, apart from one member
    who took the whisky and headed towards town and certain death, and another member
    who didn’t place enough importance on the lighter and froze to death, and myself
    and another member who left the steel wool behind and not only froze to death
    but were also unable to signal for help due to the unreflective properties of
    Crisco shortening, we all survived. </p> 
<p><em>Tuesday 3 August – Practical 2</em></p> 
<p>Today, at the ungodly time of 8 AM, I learnt how to use ANT – which beats
    learning how to use make files. I also learnt that I should follow instructions
    exactly as given – as I had several problems and had to ask for help a few times,
    and each time it was because I’d failed to read the instructions properly, or
    had missed a step. So, I guess you could say today has been a productive day.</p> 
<p><em>Tuesday 10 August – Practical 3</em></p> 
<p>I had to tutor for another subject, and attend my eight o’clock group practical,
    so didn’t want to be late. I had also stayed up most of the night, as usual,
    so had to use my patent-pending psychological trick to wake up – setting the
    computer’s alarm to play something loud five minutes after my alarm, so when
    mine goes off, I have to get up to turn the computer’s one off before it goes
    off and wakes everyone else, who will then kill me. It was very cold – one of
    the coldest mornings so far, but I managed to attend my prac, and probably learnt
    something there, although I can’t remember what it was.</p> 
<p><em>Tuesday 17 August – Practical 4</em></p> 
<p>We had a group meeting during our prac, which went quite well. We managed
    to delegate tasks to ourselves in a way that seems to make everyone happy, without
    really meaning to, while telling lots of doubtful jokes and stuff. It seems
    Flash (Steve Gordon) is Mr. CVS, Stephen (Jenks) is Mr. PowerPoint Designer,
    and Lachlan (Smith) and I are your presenters – with Lachlan being more comfortable
    talking, and me being less comfortable talking, so I’m Mr. Click Things and
    he’s the inimitable Dr Voice. It’s all going good. </p> 
<p><em>Friday 20 August – Group Meeting</em></p> 
<p>We had a group meeting today. I almost forgot about it, and because my tutoring
    ran overtime, I was late. The meeting went for all of three minutes, during
    which time we unanimously decided to have another group meeting at a later date,
    due to lack of motivation and a dire lack of a lack of assignments in other
    subjects. </p> 
<p>I am so busy right now - it’s not good. I have an assignment due before 2
    PM Monday, this one due during my two-hour eight o’clock practical on Tuesday
    and another due on Friday. I also have a fourth assignment that I should be
    doing, but I haven’t even looked at it so don’t know when it’s due. Then, on
    top of that, there’s a few things relating to my tutoring that I have to do,
    several little things around here I need to do, paperwork and computer stuff,
    and I need to go shopping and do some washing.</p> 
<p><em>Tuesday 24 August – Practical 5</em></p> 
<p>I headed down to the labs, via the refectory where I bought a terrible pretending
    pizza thing that was so bad I had to throw it out. After three quarters of our
    group finished not preparing in the labs, we went up to the other lab and, after
    the fourth quarter arrived we presented our program – “UMLet”, a Java based
    UML drawing program, which I insist is pronounced as “omelet”. It was a ten-minute
    presentation, during which Lachlan spoke and I cleverly manipulated our PowerPoint
    slides and the actual program. This was followed by rapturous applause (or so
    I insist on remembering), and then Stephen (the Gordon one) took a break from
    losing sleep over Slashdot to demonstrate his immeasurable CVS skills – and
    that was that. The rest of the groups ran through their presentations ranging
    from one who had a simple script and read it out without any computer involvement
    to one who had a fully scripted presentation with all four participating. We
    were the only group who ran to time (or at least the only group who had a two-minute
    warning given), and successfully covered all points on the criteria sheet with
    a live demonstration of the program, so I’m hoping for marks. We might even
    get an excellence and innovation mark for Stephen’s installation and run script.</p> 
<p><em>Tuesday 31 August – Practical 6</em></p> 
<p>Today’s practical was supposed to teach us how to use Rational Rose, but after
    a quick perusal of that program, I’ve decided that “use” is not the appropriate
    word – performing even the most basic tasks requires immense effort, although
    perhaps it wouldn’t be so bad if I actually understood what I was trying to
    do – something I must aim for. I did, however, learn how to create complex-looking
    (and sometimes meaningful) UML diagrams from Java without expending too much
    effort – something that’s very useful considering that’s part of what I have
    to do for the next assignment. My only other exposure to UML had been through
    Visio, while attempting to draw ER diagrams for an INFS assignment, I came across
    some UML templates and had a bit of a play around, but I didn’t realize the
    full depth and breadth, and the rich variety of diagrammatical styles possible.
    Now I do. The tutorials on UML have been instrumental in aiding my understanding
    as well, as I’ve found some aspects of UML, particularly the way it’s only semi-formal
    and a lot of discretion is required to determine precisely how to model something,
    quite confusing. </p> 
<p><em>Tuesday 7 September – Practical 7</em></p> 
<p>I pretended the world was round and that today was just another day, and headed
    into university. I attended my prac, during which we planned how we are going
    to try to do our assignment, and after that, I repressed all thoughts of assignments
    for as long as possible. </p> 
<p><em>Tuesday 14 September – Practical 8</em></p> 
<p>Our original plan had us all completing our individual parts of assignment
    two by today, and beginning the group parts. What actually happened, though,
    was that I went to Sydney over the weekend and didn’t complete my part on time,
    and we realized that some aspects of the individual work we’d assigned ourselves
    is better done in a group environment. Basically, we each found that we had
    to read half of the java files assigned to other group members in order to be
    able to figure out what the code in our files did – so we’ve modified our schedule
    a little. It is now more realistic and goes something like “finish everything
    as fast as possible – definitely before the due date”.</p> 
<p><em>Wednesday 15 September</em></p> 
<p>So here am I, sitting down in the lab typing all this. Now that I’ve given
    what is, I hope, an accurate overview of my experiences with COMP2801 so far,
    I would like to reflect on what I’ve actually learnt so far, and how I’ve gone
    about it.</p> 
<p>UML – I had a vague idea about it, mostly garnered from using Visio to draw
    diagrams during a previous INFS course. I’ve now learnt quite a lot about UML,
    and can actually use Rational Rose – in a way.</p> 
<p>Teamwork – This is the third teamwork-based assessment I’ve done here at UQ,
    but the first where I’ve really learnt how to cooperate and trust others. I’ve
    had to, as I haven’t had enough time to check work others are doing to see if
    it matches my “standards”.</p> 
<p>Java – I don’t really think I’ve learnt anything I didn’t already know about
    Java and programming itself, everything has been straightforward code so far
    and I believe I’m becoming adept at spotting situations that could benefit from
    re-factoring. I have, however, had to struggle to understand and identify design
    patterns, as I don’t find their discovery intuitive.</p> 
<p>CVS – This course is the first time I’ve used CVS. I’d heard about it a lot
    from various open-source places, but never actually had to use it myself. I
    can’t say I’m overly impressed, it doesn’t seem to be much more than a glorified
    versioning archive to me – but it’s handy to know how to use it should I ever
    need to.</p> 
<p>ANT – Having only used make files before, ANT came as a nice surprise. It’s
    quite powerful, relatively easy to learn, and uses XML for that up-to-the-minute
    effect. I didn’t have much input into the ANT build file used by our team, but
    the ANT practical helped.</p> 
<h3>4.3.2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Updated Journal</h3> 
<p><em>Friday 17 September – Assignment Submitted</em></p> 
<p>I headed off to uni to complete our assignment. I am supposed to have gone
    to uni earlier, but, for some strange reason (possibly related to not getting
    to bed until early this morning), I felt quite sleepy when I woke up and didn’t
    want to go. Today is the day of the grand submission, and our document is a
    proud 42 pages, much of which was written at ridiculous hours of the night,
    so I corrected a few silly mistakes when proof reading – and we submitted it.
    It should definitely get us a pass, if not better.</p> 
<p><em>Tuesday 21 September – Sick</em></p> 
<p>I attended my eight o’clock prac, at great risk to my health. I’m feeling
    sick and terrible. We made up a list of a few things to consider for assignment
    three – re-factoring the code (an obvious and generic choice), adding print
    functionality, adding colours, documenting the code (another generic choice),
    and adding a tip of the day module (which Steve has already written). This doesn’t
    sound like much, and isn’t very exciting, but it should fulfil the assignment
    criteria. Adding colours, if that’s a plausible option, would involve quite
    a bit of object-orientated nastiness, as changes would cascade across stacks
    of classes. The print option should, hopefully, be plausible and shouldn’t be
    too hard to add on without modifying too much existing code. Steve has gone
    home for the holidays, and the rest of us have other assignments due sooner,
    so we’re giving them a higher priority.</p> 
<p><em>Friday 1 October – Woe</em></p> 
<p>I spent all night at uni last night, and have been working hard on three assignments
    for my three other subjects all week, all of which are due on the same day.
    COMP2801 isn’t receiving any attention at all right now, and won’t until these
    are submitted.</p> 
<p>Tuesday 5 October – Wherein I discover I can no longer afford to sleep</p> 
<p>I went to bed shortly after three o’clock, and I left for uni around a quarter
    to seven – that’s less than three hours sleep, and it isn’t enough, but I had
    to be at uni by eight o’clock for my group practical, during which we discussed
    our fairly limited progress so far. I then spent a normal day at uni, doing
    normal things. That is, I spent all day sitting in the computer labs programming
    for my other assignments. COMP2801 is still on the backburner.</p> 
<p><em>Wednesday 6 October – Assignment Two Returned</em></p> 
<p>I went to uni and worked on my COMS3200 assignment. It is turning into a nightmare.
    It is excessively complex for the marks given, and most of it isn’t anything
    to do with networking. I also went and got our marked assignment two for COMP2801
    back. We’ve got 18 out of 20. The average mark is 12.9 and the median 11.5.
    Only one other group, who happened to be from our practical, got a higher mark
    – at 19, so I think we’ve done quite well. I wasn’t sure what mark we’d get
    for this, as there were other groups talking about immensely long documents,
    and I wasn’t sure that we’d really completed what was expected, but now that
    we’ve got a good mark, I’d like to try to get a good mark for the next assignment
    and see if I can’t get a good overall result for this course.</p> 
<p><em>Sunday 10 October – All Night</em></p> 
<p>I have to finish COMS3200 and start and complete COMP3502 by tomorrow. COMP3502
    is due at 2 PM, and COMS3200 at 10 AM. COMP2502, also due tomorrow, is already
    completed. With this in mind, I headed into and spent the night working on them.
    Once these are submitted, for better or worse, I can at least stop worrying
    about them and get on with COMP2801, which I’ve been ignoring totally.</p> 
<p><em>Tuesday 12 October – Of which little is said</em></p> 
<p>I had to be at uni by eight o’clock at the wrong end of the day for my practical,
    so I was. The rest of the day followed along, as if by clockwork, one moment
    at a time and never two at once. By the end, it was over and ready to begin
    again.</p> 
<p><em>Wednesday 13 October – My day not off</em></p> 
<p>Today used to be my day off, back before I realised that uni is harder than
    before. Because I don’t have any lectures, I did sleep in, but still went to
    uni in the evening to do some work on our assignment. I had wanted to go see
    a movie tonight, but a few friends convinced me to wait until tomorrow, so I
    stayed at uni until late instead, trying to figure out where and how to add
    colour support to Umlet – not an easy task given its complex polymorphic structure.</p> 
<p><em>Thursday 14 October – Shaun of the Dead</em></p> 
<p>Another exciting day of fun, study and Java – but that is not all. Today,
    a few friends and I went to the movies. We saw “Shaun of the Dead”. The movie
    is a successful synthesis of British humour and American gore, managing to be
    both amusing and entertaining, but isn’t really related to COMP2801, so that’s
    all I’ll say about it. After the movie, I started on my time management reflection,
    which I have, ironically, left to the last minute, and that ended the uni-related
    portion of my day. It was actually quite interesting writing my time management
    reflection, as it gave me an opportunity to look back and consider my progress
    at uni so far – something I haven’t really done before.</p> 
<p><em>Saturday 16 October – Another Normal Day</em></p> 
<p>Another particularly normal and uneventful day, during which I present myself
    at uni in order to fully add colour to Umlet, fail to do so, and so on. I also
    read perhaps the funniest geek joke ever – two strings walk into a bar. The
    first string says to the bartender, “Bartender, I’ll have a beer. u.5n$x5t?*&amp;4ru!2[sACCErJ”.
    The second string says, “Pardon my friend, he isn’t NULL terminated”. After
    a day of largely unsuccessful programming, that really is quite hilarious.</p> 
<p><em>Sunday 17 October – Rain &amp; Little Else</em></p> 
<p>I slept in for a while and then caught a train into uni where I did some coding
    for our team project, talked to a few friends, and then headed home again, after
    buying a falafel roll from the kebab place down the Ville. It’s now raining
    and a bit cool, and I still haven’t got colour support fully working, but I’m
    getting there. I understand what I need to do now, which is probably a good
    start, I just have to figure out some way of doing it that doesn’t involve editing
    every single subclass of Entity (as I currently have) – something the perfectionist
    in me refuses to accept.</p> 
<p><em>Tuesday 19 October – Uni</em></p> 
<p>After four hours sleep, or something woeful like that, I had to get up and
    go to uni for my practical, during which my group cleverly divided the remaining
    tasks. Once again we’ve managed to delegate everything in what seems to be a
    logical way which everyone agrees on, without any problems.</p> 
<p><em>Sunday 24 October – Gauls &amp; Arguments</em></p> 
<p>Today has been another really hot day. I spent the morning in bed asleep,
    and the evening at uni. I met up with Flashpix (Steve Gordon, so called from
    his last name) and Insomnix (Lachlan, the man who never sleeps), two indomitable
    Gauls still holding out against the house drawing, team project and sprinkler-mapping
    invaders that have overtaken all the other labs. We did much great teamwork,
    which can be summarised roughly as “Hey yeah, so we better do stuff, but Coles
    shuts soon and I haven’t had breakfast yet so I’ll see you later ok? Yeah, I’ll
    do some work tonight and we can compare tomorrow. Cool, see you then”. There
    was also something I was supposed to do tonight, so that we can compare it tomorrow,
    but I can’t remember what it is so I shan’t be doing it.</p> 
<p><em>Monday 25 October – University is as University Does</em></p> 
<p>I spent the morning attending lectures and tutoring, and the evening with Lachlan preparing
    for our presentation tomorrow. Lachlan is against “letting slides do the talking”,
    so our slides are just a method of displaying some UML diagrams to backup Lachlan’s
    talk, which is up to several pages of notes now, and will hopefully be impressive.</p> 
<p><em>Tuesday 26 October – Presentation Woes</em></p> 
<p>After a little less than four hours sleep, I got up and headed into uni so
    I’d be there by half past seven, to finish preparing for our presentation. Not
    surprisingly, I didn’t feel fantastic, and I don’t think Lachlan had had anymore
    sleep than I. </p> 
<p>Our group presented third. The first group had a comprehensive and highly
    detailed slideshow – there was probably too much information on it, as they
    didn’t cover it all. The second and fourth groups had what I’d call average,
    but good, presentations, although the second group was too pre-planned and choreographed,
    as they were in the first presentation. Our presentation went terribly, I felt.
    Despite Lachlan and I having done a reasonable amount of preparation yesterday,
    coupled with both our lack of sleep, it simply wasn’t enough. I don’t know what
    our presentation looked like from the observer’s perspective, but I was very
    aware that we didn’t cover much of what I’d hoped to cover, and what we did
    was confused, leaving me waiting for planned cues that never came. I am, however,
    very impressed with Lachlan’s ability to make up stuff on the spot, something
    I don’t think I could do. All I can do is hope, vainly I fear, that Doug is
    also impressed.</p> 
<p><em>Wednesday 27 October</em></p> 
<p>With our assignment’s due date rapidly approaching, the time has again come
    for me to stop being slack and write this. Unlike last time, I have actually
    been keeping something of a journal as I go, but it’s been pretty factual, with
    little in the way of reflection, so I plan to have a quick retrospective look
    back at the course, and see what I think.</p> 
<p>Overall, I think I’ve been fortunate to have a good group, who are all able
    to work well together, and capable of working on their own but still meeting
    group goals. I think we’ve done fairly well, although our marks for this assignment
    will show whether this is so. We have approached this assignment in exactly
    the same way we approached the first – which seemed like a good idea given that
    we got good marks for it. One thing that didn’t work out though, was the presentation,
    but that’s the problem with on the spot things like that – there’s always the
    chance that it won’t work out as planned when the time comes. The assignment,
    on the other hand, is something we can attempt, look at, and redo if necessary
    – and I think, or hope, we’ve met all the assignment goals. I am hoping for
    a reasonable mark given the effort we’ve expended in getting this far, but it’s
    hard to tell exactly what we should be doing, and whether we’ve done enough
    – I guess we won’t know until we get our marks, but I do feel that we’ve done
    a good job. In retrospect, we should have prepared a much more detailed slideshow,
    and rehearsed it more thoroughly, but other than that, I think we’ve done well
    and there’s nothing I’d change.</p> 
<p>I’ve used the computer labs heavily, but haven’t really used any of the information
    we’ve been taught in lectures, because most of my work has been with Java code,
    with the other team members handling the other aspects of our assignments, so
    I’ve mainly used online Java help pages and the Java documentation. In fact,
    that is also perhaps the only thing I’ve thought of that could be changed to
    improve this course. The current structure allows perhaps too great a disparity
    between various teams and team members – something that’s probably realistic
    from a real-world perspective, but probably not the best from a learning perspective.
    I feel that, had we all been given the same carefully pre-picked software to
    work on, and the assignments been structured in such a way that a broader contribution
    would be required from each team member, we would all learn a lot more. Looking
    back, I can say that so far I have learnt more about Java from this course than
    I have about software design, team work, UML, or any of the other aspects I
    should have been learning – because I felt I would be able to contribute more
    to our group in this way. While this has allowed us, as a group, to delegate
    tasks to members more able to complete them, it has also meant that individual
    members haven’t been developing a wide a range of skills as the course requires.
    A change like this might also reduce the severity of the exam at the end of
    the course, something else I’d like to see.</p> 
<p>Despite the above, I’d say this has been a good course, and my advice to any
    future students undertaking a similar project would be to ensure they’ve got
    a good, working group and don’t leave anything to the last minute like I always
    do.</p> 
<h3>4.4. Lachlan Smith</h3> 
<p>[Removed for privacy]</p>
<!-- Removed for privacy
<h3>4.4.1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Original Journal</h3> 
<p><em>Tuesday 10am:</em></p> 
<p>The weekly prac.  This is the first time we discussed the assignment as a
    group.</p> 
<p>Ned has summarized the information from the assignment spec, and has set out
    a draft table of contents.  As this assignment is a team effort, the need to
    have a &quot;top down&quot; style of development is important; having an abstract
    view of how the final document will be structured, allows us to efficiently
    divide tasks evenly among the four team members.</p> 
<p>Stephen G has identified the various UMLet classes.  Each group member will
    take a roughly even number of the classes and document it in the manner required
    by the assignment spec.</p> 
<p>We will collaborate via the email, and the plan is to have all of the classes
    specified by next Tuesday's prac, so that we can then concentrate on consolidating
    all of our endeavors into one document and making sure it is presented neatly,
    as well as finishing off the lower priority tasks such as the plan.</p> 
<p>Each team member will keep an individual journal, and these will be consolidated
    into one team journal once the rest of the assignment is complete.</p> 
<p>I have come to realize that there are many different ways to illustrate a
    Java class in UML.  Whether or not to specify things like return types, parameter
    types, visibility.  I asked Doug whether there was a particular UML 'style guide'
    I could adhere to; his advice was, rather than to stick to a particular style
    guide (there is apparently no real authoritative style guide for UML - it is
    envisioned as being a very flexible language), simply to choose one that meets
    our needs, and be consistent.</p> 
<p><em>Wednesday 10:45am:</em></p> 
<p>Came into GPS room 109 to actually start using Rational Rose.  I went through
    the Rose prac to reacquaint myself with how to reverse engineer Java classes.</p> 
<p>I had made the decision in yesterday's prac to do the reverse engineering
    in Rose, but to do the actual diagrams in Visio.  I have an idea of the style
    I would like the finished UML diagrams to be in, and I'm not a fan of the Rose
    UML style.  I pointed out to the team members that Rose cannot save to any other
    format than Rose, and the diagrams would have to be pasted into the assignment
    document in raster format, rather than the more aesthetically pleasing vector
    format.</p> 
<p>Therefore, the approach I have taken is to reverse engineer in Rose, and then
    to take Visio's diagram and redraw it manually in Visio.</p> 
<p>When reverse engineering in Rose, one other important 'style' aspect came
    to my attention - whether or not to draw the 'dependency' (ie. dotted line)
    arrow to classes referred to by the class that are not within UMLet, but part
    of the standard Java distribution.  For example, the Selector class refers to
    several classes in the <em>java.awt</em>, <em>java.util</em> and <em>javax.swing</em> packages.</p> 
<p>I have chosen to put these dependencies in, and draw a border around classes
    belonging to the same package, whilst foreign classes and packages go outside
    this border.</p> 
<p>I realise that the other team members may have a different approach, for example,
    they might not draw the dependencies as I have, or they might do aggregation,
    operation descriptors, etc, slightly differently, keeping in mind that there
    is no real standard way to do things.  It is important for us to be consistent,
    or we risk losing marks for poor presentation or quality, etc.</p> 
<p>So, rather than to risk this, to take everyone's work and draw it up in Visio,
    making sure every diagram sticks to the same conventions.</p> 
<p>The style I have chosen is primarily based upon the Braude textbook, but with
    visibility and return types for operations.</p> 
<p>Furthermore, Rose only finds the dependencies that occur within the return
    or parameter types for the operations, and not any classes referred to within
    the methods.  I have chosen to illustrate those classes as dependencies as well,
    this is a little extra work, but I feel it is more descriptive whilst not introducing
    too much in the way of clutter.</p> 
<p><em>Thursday 11:29am</em></p> 
<p>Came down into GPS 109 to write the journal and make a little more progress
    in diagramming and reverse engineering my share of classes.  I did <em>Selector</em> and <em>SelectorFrame</em> yesterday,
    and I am up to the &quot;Umlet&quot; class.  Hmm - the Umlet class, in an application
    called UMLet.  I can tell without looking that this class is gunna be huge.</p> 
<p><em>Thursday 6:00pm</em></p> 
<p>The Umlet class is indeed huge.  I am beginning to suspect that my UML diagram
    style is going to create too much work.  I am thinking of simplifying it somewhat.</p> 
<p>One problem I have encountered is looking at classes and trying to determine
    from which package they are.  I've seen Eclipse used as an IDE, and it appears
    to be good at things like telling you what package a certain class is from just
    by pointing at it.  This would sure beat the circuitous method I currently use
    to get this information, but I'm not sure if I want to learn a new IDE this
    far into the task.</p> 
<p><em>Friday 10:00am</em></p> 
<p>Today I took a break from the Umlet class (as yet unfinished) and started
    on the next one in the list - <em>UniversalListener</em>.  This is also a big
    class - both in terms of the list of attributes and operations, and the number
    of classes upon which it depends.</p> 
<p>I intend to take the diagram to the tutorial this afternoon to get some advice
    on how I should diagram monstrosities like Umlet and <em>UniversalListener</em>. 
    It is far too much work to comb the code, inside each method, looking for classes
    and trying to find out</p> 
<p>One idea I have is, instead of drawing a border around co-packaged classes
    and to draw the dependency arrow to each one, I simply put the 'package' icon
    on my diagram, label it with the name of the package, eg. &quot;<em>java.awt</em>&quot;,
    and draw the dependency arrow to it.</p> 
<p>But then, there is the case of packages that contain both loose dependencies
    and rigid dependencies such as aggregations.</p> 
<p>Stephen G has taken two of my classes off my hands, so that he may document
    the entire &quot;io&quot; package.  No objection here.</p> 
<p><em>Friday 3:00pm</em></p> 
<p>I decided not to get the advice from the tutorial, as I am going to be studying
    for another course all weekend and I can get advice from Doug in the practical
    on Tuesday morning.  Any spare time I get will be divided between this and yet
    another course in which I have pending assessment due.</p> 
<p><em>Tuesday 10:00am</em></p> 
<p>I spent some of the prac today redrawing some of the UML diagrams, and discussing
    with Doug the Tutor whether I was on the right track with my diagrams, what
    needed to be changed, what might be more effective, etc.  He seemed fairly positive
    and didn't make any suggestions for change.</p> 
<p>The ironic thing is, the way I am doing the diagrams now is quick and easy,
    but deciding to do them this way involved a lot of trial and error - realising
    that too much detail is bad, therefore simplifying without reducing the amount
    of useful information.</p> 
<p>Furthermore I have pretty much volunteered to do all the UML diagrams for
    this assignment, in order that they are all consistent, looking great, et cetera. 
    As my method is &quot;quick and easy&quot; I expect this will not take a huge
    amount of time.  I figured that I would compile everyone's best ideas from their
    respective UML diagrams into one style that I could apply consistently.</p> 
<p>As an example of an &quot;idea&quot;, I had been drawing each class in its
    own diagram.  For the bigger classes, this was a space-saving exercise, as having
    too much clutter would reduce the effectiveness of the diagram. But I was following
    the one class per diagram rule steadfastly, even for the small classes.</p> 
<p>Stephen J, on the other hand, drew a lot of smaller classes that inherited
    from the Command class in the same diagram, with dependency arrows pointing
    to Command, so that the importance of Command is made more obvious.</p> 
<p>My idea of leaving out the private methods and attributes, except where they
    help illustrate some design pattern or expound upon something said in the description
    of the class, also appears to have survived.</p> 
<p>My focus for the next four days is getting all the classes diagrammed in Visio,
    and documenting the classes I was given, whilst allowing time for another course's
    assignment due the same day as this one.</p> 
<p><em>Wednesday 2:52pm</em></p> 
<p>Came in to uni to do some more of this assignment.  The only real reason I
    am coming in is to use Visio, and it appears this is available free to us on
    the MSDNAA scheme, so I hope to take advantage of this and do more of it at
    home.</p> 
<p>Jervina (from another group studying UMLet) asked me about an aspect of the <em>UniversalListener</em> class,
    which happens to be one of the classes I am documenting.  I found that discussing
    it helped me to understand the code a bit more.  The code in question is difficult
    to understand as it is riddled with things like:</p> 
<p>   if (RESIZE_DIRECTION == 12) { ... }</p> 
<p>The method that sets RESIZE_DIRECTION is in another class, so one must do
    a lot of backtracking to work out what &quot;12&quot; means.  The ensuing backtracking
    revealed that &quot;12&quot; means 'top right', because 12 = binary 1100, where
    the first bit indicates 'top', the second bit is 'right', the third 'bottom',
    and the fourth 'left'.</p> 
<p>This is truly a missed opportunity for object orientation, and gives me some
    ideas for re-factoring UMLet in assignment three.</p> 
<p><em>Thursday 9:23pm</em></p> 
<p>Today, I have been working on a UML diagram containing Command and the eleven
    other classes that extend it.  I have also been doing diagrams for all the other
    classes that we chose to cover for this assignment.  These are almost done. 
    The class diagrams I will be completing later tonight.</p> 
<h3>4.4.2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Updated Journal</h3> 
<p><em>Wednesday 20th October</em></p> 
<p>For this assignment, we employed a similar approach to the last one: to divide
    up the labours (roughly) evenly amongst the team, and synchronise via the e-mail. 
    I have been in charge of the in-class presentation of the team effort, as well
    as my continuing role of identifying and diagramming software patterns.  This
    means that I am not personally adding any features to the code, but waiting
    for other team members to start making their changes first, during which time
    I have been getting assessment for other courses out of the way.</p> 
<p>Doug offered some interesting feedback on my diagramming effort in the second
    assignment.  From this, it is clear that I could do better in identifying patterns
    in the software, rather than simply transliterating the class and package structure
    of the software into UML.  For instance, he identified a (somewhat obvious)
    missed opportunity for an aggregation (solid diamond) connection between two
    classes, where I had just drawn a plain (dotted line) connection - the one-to-many
    relationship between the two classes was an important design consideration which
    I had not identified.</p> 
<p>Now that I understand a bit more about software patterns, I find myself revisiting
    the material I contributed toward the previous assignment, and reason about
    what I could have done better.  Certainly, if I'd had the time again, I'd have
    approached the design pattern identification as a 'top down' task, rather than
    at the level of individual classes, which seemed like a perfectly logical approach
    at the time.</p> 
<p>With other assignments almost out of the way, I plan to spend the last week
    or so entirely on this one.  This effort has been mostly successful, but the
    weekend, in which I had planned to finish my only other outstanding item, was
    unproductive, as has been the week so far.</p> 
<p>However, I feel that there is still ample time to get the presentation in
    tip top shape for Tuesday's prac.</p> 
<p><em>Sunday 24th October</em></p> 
<p>The weekend has been less productive toward COMP2801 than I would have hoped. 
    Having handed in the task for the other course on Friday, I came to discover
    that it would not compile under the tutor's JDK, so I had to make time-consuming
    revisions to the code and submit it again, late.</p> 
<p>In between the first submission and making the aforementioned discovery, I
    did some reasoning about how the presentation would be done.  We plan to do
    a similar format to last time, where I do the speaking, and Ned takes verbal
    cues to do certain things on the computer, such as demonstrating the application,
    and changing slides.  This allows Stephen G and Stephen J to focus their efforts
    on making their changes and additions to UMLet.</p> 
<p><em>Monday 25th October</em></p> 
<p>Ned and I have spent some time finalising the presentation.  There will be
    a handful of UML slides, which I will use to demonstrate certain key design
    patterns in UMLet.  The remainder of the time, I will either refer to the source
    code, or to the application itself.  I intend to give Ned a rough outline of
    my speech, as he has asked me what to expect in terms of verbal cues.</p> 
<p>This approach is risky, but I feel that the strength of our previous demonstration
    was our willingness to leave the safe confines of the slide show and actually
    demonstrate our application, and we are sticking to that formula this time around.</p> 
<p>I am not a great fan of using a large number of slides, or slides with a great
    deal of content.  Certain other teams built hugely complex slides with many
    diagrams and entire paragraphs of text for the first assignment, flicking through
    these slides at a million miles an hour to get through the presentation in the
    allotted ten minutes.  This may be a justifiable practice in course lectures,
    where students are likely to study the printed slides later; in the case of
    this presentation, the audience will most likely never see the slides again.</p> 
<p>I also don't favour the idea of reading the speech from a sheet.  As much
    as this may allow better synchronisation between speaker(s) and demonstrator(s),
    the speaker tends to deliver the words with a noticeably artificial cadence,
    as though the words were someone else's.  They also don't make much eye contact.</p> 
<p><em>Tuesday 26th October</em></p> 
<p>Today was the presentation prac.  My prediction of the other groups' slide-heavy
    presentations held true.  I hope our presentation didn't seem less informative
    due to the format we chose.  Having said that, the standard of the other groups'
    presentations was quite high, and we had some tough acts to follow.</p> 
<p>The synchronisation between Ned and I was not rehearsed, and we fumbled a
    bit, but once again, we were the only group to leave PowerPoint and actually
    visit the application in question.  Speaking without notes puts me out of my
    comfort zone, but I think we did okay; perhaps the fact that we couldn't yet
    demonstrate our refactoring or testing efforts was a weak point.</p> 
<p>My focus from here on out is to finish up the identification of design pattern
    changes in our updated code, applying the lessons I have learned in preparing
    for this presentation.</p> 
-->
<hr />
<h2>5.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Appendix A – Evidence
        of Code Changes</h2> 
<h3>5.1. PrintPage.java</h3> 
<p class="centre"><em><img alt="UML Diagram" width="466"
height="179" src="COMP2801-assignment-3-files/image002.png" /></em></p> 
<p class="centre"><strong>Figure 5.1.1.</strong>  Shows the new class <em>PrintPage</em> and
    its relationship with the existing <em>UniversalListener</em> class.</p> 
<div class="code-samples">
<p><strong><span class="green">package </span></strong>com<span class="dark-green">.</span>umlet<span class="dark-green">.</span>control;</p> 
<p><strong><span class="green">import </span></strong>java<span class="dark-green">.</span>awt<span class="dark-green">.*</span>;</p> 
<p><strong><span class="green">import </span></strong>java<span class="dark-green">.</span>awt<span class="dark-green">.</span>geom<span class="dark-green">.*</span>;</p> 
<p><strong><span class="green">import </span></strong>java<span class="dark-green">.</span>awt<span class="dark-green">.</span>print<span class="dark-green">.*</span>;</p> 
<p><strong><span class="green">import </span></strong>java<span class="dark-green">.</span>util<span class="dark-green">.*</span>;</p> 
<p><strong><span class="green">import </span></strong>com<span class="dark-green">.</span>umlet<span class="dark-green">.</span>element<span class="dark-green">.</span>base<span class="dark-green">.*</span>;</p> 
<p><em><span class="slate-gray">/**</span></em></p> 
<p><em><span class="slate-gray">  Provides Umlet with the ability to print the
            current drawing pane.</span></em></p> 
<p><em><span class="slate-gray">  </span></em><strong><em><span class="dark-gray">@author </span></em></strong><em><span class="slate-gray">Stephen
            Gordon &lt;a href=&quot;mailto:stephen.a.gordon@gmail.com&quot;&gt;stephen.a.gordon@gmail.com&lt;/a&gt;</span></em></p> 
<p><em><span class="slate-gray">*/</span></em></p> 
<p><strong><span class="blue">public </span></strong><span class="red">class </span>PrintPage <span class="brown">implements </span>Printable <span class="dark-green">{</span></p> 
<p><span class="dark-green">    </span><strong><span class="blue">private </span></strong><span class="brown">static </span>PrintPage
    _instance;</p> 
<p>    <em><span class="slate-gray">/**</span></em></p> 
<p><em><span class="slate-gray">      Returns an instance of the class.</span></em></p> 
<p><em><span class="slate-gray">    */</span></em></p> 
<p><em><span class="slate-gray">    </span></em><strong><span class="blue">public </span></strong><span class="brown">static </span>PrintPage <strong><span class="midnight-blue">getInstance</span></strong><span class="dark-green">()
        {</span></p> 
<p><span class="dark-green">      </span><strong><span class="blue">if</span></strong><span class="dark-green">(</span>_instance
    == <strong>null</strong><span class="dark-green">) {</span></p> 
<p><span class="dark-green">        </span>_instance = <strong><span class="dark-cyan">new </span></strong><strong><span class="midnight-blue">PrintPage</span></strong><span class="dark-green">()</span>;</p> 
<p>      <span class="dark-green">}</span></p> 
<p><span class="dark-green">      </span><span class="navy">return </span>_instance;</p> 
<p>    <span class="dark-green">}</span></p> 
<p><span class="dark-green">    </span><em><span class="slate-gray">/**</span></em></p> 
<p><em><span class="slate-gray">      When UMLet wishes to print this method
            is called and directs</span></em></p> 
<p><em><span class="slate-gray">      all further print related activitie.</span></em></p> 
<p><em><span class="slate-gray">    */</span></em></p> 
<p><em><span class="slate-gray">    </span></em><strong><span class="blue">public </span></strong><span class="red">void </span><strong><span class="midnight-blue">doPrint</span></strong><span class="dark-green">()
        {</span></p> 
<p><span class="dark-green">       </span>PrinterJob job = PrinterJob<span class="dark-green">.</span><strong><span class="midnight-blue">getPrinterJob </span></strong><span class="dark-green">()</span>;</p> 
<p>       job<span class="dark-green">.</span><strong><span class="midnight-blue">setPrintable</span></strong><span class="dark-green">(</span><strong>this</strong><span class="dark-green">)</span>;</p> 
<p>       <strong><span class="blue">if </span></strong><span class="dark-green">(</span>job<span class="dark-green">.</span><strong><span class="midnight-blue">printDialog</span></strong><span class="dark-green">())
        {</span></p> 
<p><span class="dark-green">          </span><strong><span class="teal">try </span></strong><span class="dark-green">{</span></p> 
<p><span class="dark-green">              </span>job<span class="dark-green">.</span><strong><span class="midnight-blue">print</span></strong><span class="dark-green">()</span>;</p> 
<p>          <span class="dark-green">} </span><strong><span class="teal">catch </span></strong><span class="dark-green">(</span>Exception
    PrintException<span class="dark-green">) {</span></p> 
<p><span class="dark-green">             </span>PrintException<span class="dark-green">.</span><strong><span class="midnight-blue">printStackTrace</span></strong><span class="dark-green">()</span>;</p> 
<p>          <span class="dark-green">}</span></p> 
<p><span class="dark-green">       }</span></p> 
<p><span class="dark-green">    }</span></p> 
<p><span class="dark-green">    </span><em><span class="slate-gray">/**</span></em></p> 
<p><em><span class="slate-gray">      Does the actual job of sending a page to
            print.</span></em></p> 
<p><em><span class="slate-gray">      </span></em><strong><em><span class="dark-gray">@param </span></em></strong><em><span class="slate-gray">Graphics
            the graphics object to print.</span></em></p> 
<p><em><span class="slate-gray">      </span></em><strong><em><span class="dark-gray">@param </span></em></strong><em><span class="slate-gray">PageFormat
            the page format sturcture which is used to</span></em></p> 
<p><em><span class="slate-gray">      set various printing options.</span></em></p> 
<p><em><span class="slate-gray">      </span></em><strong><em><span class="dark-gray">@param </span></em></strong><em><span class="slate-gray">page
            The number of the page.</span></em></p> 
<p><em><span class="slate-gray">      </span></em><strong><em><span class="dark-gray">@return </span></em></strong><em><span class="slate-gray">int
            PAGE_EXISTS or NO_SUCH_PAGE</span></em></p> 
<p><em><span class="slate-gray">    */</span></em></p> 
<p><em><span class="slate-gray">    </span></em><strong><span class="blue">public </span></strong><strong><span class="red">int </span></strong><strong><span class="midnight-blue">print </span></strong><span class="dark-green">(</span>Graphics
    graphics<span class="dark-green">, </span>PageFormat format<span class="dark-green">, </span><strong><span class="red">int </span></strong>page<span class="dark-green">)
    {</span></p> 
<p><span class="dark-green">        </span>Graphics2D graphics2D;</p> 
<p>        <strong><span class="blue">if </span></strong><span class="dark-green">(</span>page
    == <span class="dark-blue">0</span><span class="dark-green">) {</span></p> 
<p><span class="dark-green">            </span>graphics2D <strong><span class="midnight-blue">= </span></strong><span class="dark-green">(</span>Graphics2D<span class="dark-green">)</span>graphics;</p> 
<p>            graphics2D<span class="dark-green">.</span><strong><span class="midnight-blue">setColor</span></strong><span class="dark-green">(</span>Color<span class="dark-green">.</span>black<span class="dark-green">)</span>;</p> 
<p>            graphics2D<span class="dark-green">.</span><strong><span class="midnight-blue">translate</span></strong><span class="dark-green">(</span>format<span class="dark-green">.</span><strong><span class="midnight-blue">getImageableX</span></strong><span class="dark-green">(),</span></p> 
<p><span class="dark-green">                                 </span>format<span class="dark-green">.</span><strong><span class="midnight-blue">getImageableY</span></strong><span class="dark-green">())</span>;</p> 
<p>            Vector v=Selector<span class="dark-green">.</span><strong><span class="midnight-blue">getInstance</span></strong><span class="dark-green">().</span><strong><span class="midnight-blue">getAllEntitiesOnPanel</span></strong><span class="dark-green">()</span>;</p> 
<p>            <strong><span class="blue">for </span></strong><span class="dark-green">(</span><strong><span class="red">int </span></strong>i=<span class="dark-blue">0</span>;
    i<span class="dark-green">&lt;</span>v<span class="dark-green">.</span><strong><span class="midnight-blue">size</span></strong><span class="dark-green">()</span>;
    i<span class="dark-green">++) {</span></p> 
<p><span class="dark-green">                </span>Entity e<strong><span class="midnight-blue">=</span></strong><span class="dark-green">(</span>Entity<span class="dark-green">)</span>v<span class="dark-green">.</span><strong><span class="midnight-blue">elementAt</span></strong><span class="dark-green">(</span>i<span class="dark-green">)</span>;</p> 
<p>                graphics2D<span class="dark-green">.</span><strong><span class="midnight-blue">translate</span></strong><span class="dark-green">(</span>e<span class="dark-green">.</span><strong><span class="midnight-blue">getX</span></strong><span class="dark-green">(), </span>e<span class="dark-green">.</span><strong><span class="midnight-blue">getY</span></strong><span class="dark-green">())</span>;</p> 
<p>                e<span class="dark-green">.</span><strong><span class="midnight-blue">paint</span></strong><span class="dark-green">(</span>graphics2D<span class="dark-green">)</span>;</p> 
<p>                graphics2D<span class="dark-green">.</span><strong><span class="midnight-blue">translate</span></strong><span class="dark-green">(-</span>e<span class="dark-green">.</span><strong><span class="midnight-blue">getX</span></strong><span class="dark-green">(),
        -</span>e<span class="dark-green">.</span><strong><span class="midnight-blue">getY</span></strong><span class="dark-green">())</span>;</p> 
<p>            <span class="dark-green">}</span></p> 
<p><span class="dark-green">            </span><span class="navy">return </span><span class="dark-green">(</span>PAGE_EXISTS<span class="dark-green">)</span>;</p> 
<p>        <span class="dark-green">} </span><strong><span class="blue">else </span></strong><span class="dark-green">{</span></p> 
<p><span class="dark-green">            </span><span class="navy">return </span><span class="dark-green">(</span>NO_SUCH_PAGE<span class="dark-green">)</span>;</p> 
<p>        <span class="dark-green">}</span></p> 
<p><span class="dark-green">    }</span></p> 
<p><span class="dark-green">}</span></p> 
</div>
<h3>5.2. TipContainer.java</h3> 
<p><em>Note: because this class is considered to be aggregated by TipGenerator,
        both classes are diagrammed together in Section 5.3.</em></p> 
<div class="code-samples">
<p><strong><span class="green">package </span></strong>com<span class="dark-green">.</span>umlet<span class="dark-green">.</span>control;</p> 
<p><em><span class="slate-gray">/**</span></em></p> 
<p><em><span class="slate-gray">  Stores a collection of 'tips' for display to
            the user.</span></em></p> 
<p><em><span class="slate-gray">  </span></em><strong><em><span class="dark-gray">@author </span></em></strong><em><span class="slate-gray">Stephen
            Gordon &lt;a href=&quot;mailto:stephen.a.gordon@gmail.com&quot;&gt;stephen.a.gordon@gmail.com&lt;/a&gt;</span></em></p> 
<p><em><span class="slate-gray">*/</span></em></p> 
<p><strong><span class="blue">public </span></strong><span class="red">class </span>TipContainer <span class="dark-green">{</span></p> 
<p><span class="dark-green">    </span><em><span class="slate-gray">/** The TipContainer
            currently uses a string array as it's</span></em></p> 
<p><em><span class="slate-gray">        storage method. */</span></em></p> 
<p><em><span class="slate-gray">    </span></em><strong><span class="blue">private </span></strong>String <span class="dark-green">[] </span>_tips;</p> 
<p>    <em><span class="slate-gray">/**</span></em></p> 
<p><em><span class="slate-gray">      Default constructor simply initialises
            the storage structure.</span></em></p> 
<p><em><span class="slate-gray">    */</span></em></p> 
<p><em><span class="slate-gray">    </span></em><strong><span class="blue">public </span></strong><strong><span class="midnight-blue">TipContainer</span></strong><span class="dark-green">()
        {</span></p> 
<p><span class="dark-green">        </span>_tips = <strong><span class="dark-cyan">new </span></strong>String<span class="dark-green">[</span><span class="dark-blue">0</span><span class="dark-green">]</span>;</p> 
<p>    <span class="dark-green">}</span></p> 
<p><span class="dark-green">    </span><em><span class="slate-gray">/**</span></em></p> 
<p><em><span class="slate-gray">      Adds a new tip to the container. As the
            current implementation</span></em></p> 
<p><em><span class="slate-gray">      uses an array this operation is actually
            quite intensive.</span></em></p> 
<p><em><span class="slate-gray">      </span></em><strong><em><span class="dark-gray">@param </span></em></strong><em><span class="slate-gray">String
            newTip The string which will be displayed to the</span></em></p> 
<p><em><span class="slate-gray">      user as a 'tip'.</span></em></p> 
<p><em><span class="slate-gray">      </span></em><strong><em><span class="dark-gray">@return </span></em></strong><em><span class="slate-gray">int
            Returns the index of the newly added tip in the</span></em></p> 
<p><em><span class="slate-gray">      structure.</span></em></p> 
<p><em><span class="slate-gray">    */</span></em></p> 
<p><em><span class="slate-gray">    </span></em><strong><span class="blue">public </span></strong><strong><span class="red">int </span></strong><strong><span class="midnight-blue">add</span></strong><span class="dark-green">(</span>String
    newTip<span class="dark-green">) {</span></p> 
<p><span class="dark-green">        </span>String <span class="dark-green">[] </span>temporary
    = <strong><span class="dark-cyan">new </span></strong>String<span class="dark-green">[</span>_tips<span class="dark-green">.</span>length <span class="dark-green">+ </span><span class="dark-blue">1</span><span class="dark-green">]</span>;</p> 
<p>        <strong><span class="blue">for</span></strong><span class="dark-green">(</span><strong><span class="red">int </span></strong>count
    = <span class="dark-blue">0</span>; count <span class="dark-green">&lt; </span>_tips<span class="dark-green">.</span>length;
    count<span class="dark-green">++) {</span></p> 
<p><span class="dark-green">            </span>temporary<span class="dark-green">[</span>count<span class="dark-green">] </span>=
    _tips<span class="dark-green">[</span>count<span class="dark-green">]</span>;</p> 
<p>        <span class="dark-green">}</span></p> 
<p><span class="dark-green">        </span>temporary<span class="dark-green">[</span>temporary<span class="dark-green">.</span>length <span class="dark-green">- </span><span class="dark-blue">1</span><span class="dark-green">] </span>=
    newTip;</p> 
<p>        _tips = temporary;</p> 
<p>        <span class="navy">return </span>temporary<span class="dark-green">.</span>length;</p> 
<p>    <span class="dark-green">}</span></p> 
<p><span class="dark-green">    </span><em><span class="slate-gray">/**</span></em></p> 
<p><em><span class="slate-gray">      Returns the tip with the given index.</span></em></p> 
<p><em><span class="slate-gray">      </span></em><strong><em><span class="dark-gray">@param </span></em></strong><em><span class="slate-gray">int
            n The index of the tip to get.</span></em></p> 
<p><em><span class="slate-gray">      </span></em><strong><em><span class="dark-gray">@return </span></em></strong><em><span class="slate-gray">String
            Returns the string representation of a tip.</span></em></p> 
<p><em><span class="slate-gray">    */</span></em></p> 
<p><em><span class="slate-gray">    </span></em><strong><span class="blue">public </span></strong>String <strong><span class="midnight-blue">getTip</span></strong><span class="dark-green">(</span><strong><span class="red">int </span></strong>n<span class="dark-green">)
        {</span></p> 
<p><span class="dark-green">        </span><span class="navy">return </span>_tips<span class="dark-green">[</span>n<span class="dark-green">]</span>;</p> 
<p>    <span class="dark-green">}</span></p> 
<p><span class="dark-green">    </span><em><span class="slate-gray">/**</span></em></p> 
<p><em><span class="slate-gray">      Gets the number of tips in the container.</span></em></p> 
<p><em><span class="slate-gray">      </span></em><strong><em><span class="dark-gray">@return </span></em></strong><em><span class="slate-gray">int
            Returns the number of tips in the container.</span></em></p> 
<p><em><span class="slate-gray">    */</span></em></p> 
<p><em><span class="slate-gray">    </span></em><strong><span class="blue">public </span></strong><strong><span class="red">int </span></strong><strong><span class="midnight-blue">getLength</span></strong><span class="dark-green">()
        {</span></p> 
<p><span class="dark-green">        </span><span class="navy">return </span>_tips<span class="dark-green">.</span>length;</p> 
<p>    <span class="dark-green">}</span></p> 
<p><span class="dark-green">}</span></p> 
</div>
<h3>5.3. TipGenerator.java</h3> 
<p class="centre"><img alt="UML Diagram" width="406"
height="319" src="COMP2801-assignment-3-files/image003.png" /></p> 
<p class="centre"><strong>Figure 5.3.1.</strong>  Shows the new classes, TipGenerator
    and TipContainer, and their relationship to each other and the rest of UMLet.</p> 
<p class="centre"><img alt="UML Diagram" width="554"
height="372" src="COMP2801-assignment-3-files/image004.png" /></p> 
<p class="centre"><strong>Figure 5.3.2.</strong>  Shows the call to <em>TipGenerator.getInstance.show()</em> appended <em>Umlet.init()</em>,
    the method which initialises the UMLet application.</p> 
<p class="centre"><img alt="UML Diagram" width="553"
height="356" src="COMP2801-assignment-3-files/image005.png" /></p> 
<p class="centre"><strong>Figure 5.3.3.  </strong>Shows the call to <em>TipGenerator.getInstance.show()</em> added
    to the <em>UniversalListener.actionEvent()</em> method, the action handler for
    menu selections in UMLet.</p> 
<div class="code-samples">
<p><strong><span class="green">package </span></strong>com<span class="dark-green">.</span>umlet<span class="dark-green">.</span>control;</p> 
<p><strong><span class="green">import </span></strong>javax<span class="dark-green">.</span>swing<span class="dark-green">.*</span>;</p> 
<p><strong><span class="green">import </span></strong>java<span class="dark-green">.</span>io<span class="dark-green">.*</span>;</p> 
<p><em><span class="slate-gray">/**</span></em></p> 
<p><em><span class="slate-gray">  Facilitates the generation and display of 'tips'
            for program usage.</span></em></p> 
<p><em><span class="slate-gray">  </span></em><strong><em><span class="dark-gray">@author </span></em></strong><em><span class="slate-gray">Stephen
            Gordon &lt;a href=&quot;mailto:stephen.a.gordon@gmail.com&quot;&gt;stephen.a.gordon@gmail.com&lt;/a&gt;</span></em></p> 
<p><em><span class="slate-gray">  </span></em><strong><em><span class="dark-gray">@version </span></em></strong><em><span class="slate-gray">1</span></em></p> 
<p><em><span class="slate-gray">*/</span></em></p> 
<p><strong><span class="blue">public </span></strong><span class="red">class </span>TipGenerator <span class="dark-green">{</span></p> 
<p><span class="dark-green">    </span><strong><span class="blue">private </span></strong>TipContainer
    _tipContainer;</p> 
<p>    <strong><span class="blue">private </span></strong><span class="brown">static </span>TipGenerator
    _instance;</p> 
<p>    <em><span class="slate-gray">/**</span></em></p> 
<p><em><span class="slate-gray">      Provides a way for other classes to get
            an instance of the</span></em></p> 
<p><em><span class="slate-gray">      TipGenerator.</span></em></p> 
<p><em><span class="slate-gray">      </span></em><strong><em><span class="dark-gray">@return </span></em></strong><em><span class="slate-gray">TipGenerator
            Returns a new TipGenerator.</span></em></p> 
<p><em><span class="slate-gray">    */</span></em></p> 
<p><em><span class="slate-gray">    </span></em><strong><span class="blue">public </span></strong><span class="brown">static </span>TipGenerator <strong><span class="midnight-blue">getInstance</span></strong><span class="dark-green">() </span><span class="brown">throws </span>IOException <span class="dark-green">{</span></p> 
<p><span class="dark-green">      </span><strong><span class="blue">if</span></strong><span class="dark-green">(</span>_instance
    == <strong>null</strong><span class="dark-green">) {</span></p> 
<p><span class="dark-green">        </span>_instance = <strong><span class="dark-cyan">new </span></strong><strong><span class="midnight-blue">TipGenerator</span></strong><span class="dark-green">(</span><span class="fuchsia">&quot;tips.txt&quot;</span><span class="dark-green">)</span>;</p> 
<p>      <span class="dark-green">}</span></p> 
<p><span class="dark-green">      </span><span class="navy">return </span>_instance;</p> 
<p>    <span class="dark-green">}</span></p> 
<p><span class="dark-green">    </span><em><span class="slate-gray">/**</span></em></p> 
<p><em><span class="slate-gray">      TipGenerator constructor, allows loading
            of tips from file and</span></em></p> 
<p><em><span class="slate-gray">      populates the TipContainer.</span></em></p> 
<p><em><span class="slate-gray">      </span></em><strong><em><span class="dark-gray">@param </span></em></strong><em><span class="slate-gray">fileanem
            String representing the file to load tips from.</span></em></p> 
<p><em><span class="slate-gray">      </span></em><strong><em><span class="dark-gray">@throws </span></em></strong><em><span class="slate-gray">IOException</span></em></p> 
<p><em><span class="slate-gray">    */</span></em></p> 
<p><em><span class="slate-gray">    </span></em><strong><span class="blue">public </span></strong><strong><span class="midnight-blue">TipGenerator</span></strong><span class="dark-green">(</span>String
    filename<span class="dark-green">) </span><span class="brown">throws </span>IOException <span class="dark-green">{</span></p> 
<p><span class="dark-green">        </span><strong><span class="teal">try </span></strong><span class="dark-green">{</span></p> 
<p><span class="dark-green">            </span>BufferedReader br = <strong><span class="dark-cyan">new </span></strong><strong><span class="midnight-blue">BufferedReader</span></strong><span class="dark-green">(</span></p> 
<p><span class="dark-green">                                    </span><strong><span class="dark-cyan">New </span></strong><strong><span class="midnight-blue">FileReader</span></strong><span class="dark-green">(</span>filename<span class="dark-green">)</span></p> 
<p><span class="dark-green">                               )</span>;</p> 
<p>            String inputData = <strong>null</strong>;</p> 
<p>            _tipContainer = <strong><span class="dark-cyan">new </span></strong><strong><span class="midnight-blue">TipContainer</span></strong><span class="dark-green">()</span>;</p> 
<p>            <strong><span class="blue">do </span></strong><span class="dark-green">{</span></p> 
<p><span class="dark-green">                </span>inputData = br<span class="dark-green">.</span><strong><span class="midnight-blue">readLine</span></strong><span class="dark-green">()</span>;</p> 
<p>                <strong><span class="blue">if</span></strong><span class="dark-green">(</span>inputData <span class="dark-green">!</span>= <strong>null</strong><span class="dark-green">)
        {</span></p> 
<p><span class="dark-green">                     </span>_tipContainer<span class="dark-green">.</span><strong><span class="midnight-blue">add</span></strong><span class="dark-green">(</span>inputData<span class="dark-green">)</span>;</p> 
<p>                <span class="dark-green">}</span></p> 
<p><span class="dark-green">            } </span><strong><span class="blue">while</span></strong><span class="dark-green">(</span>inputData <span class="dark-green">!</span>= <strong>null</strong><span class="dark-green">)</span>;</p> 
<p>        <span class="dark-green">} </span><strong><span class="teal">catch</span></strong><span class="dark-green">(</span>IOException
    e<span class="dark-green">) {</span></p> 
<p><span class="dark-green">            </span>System<span class="dark-green">.</span>err<span class="dark-green">.</span><strong><span class="midnight-blue">println</span></strong><span class="dark-green">(</span><span class="fuchsia">&quot;ERR:
        Unable to open tips file.&quot;</span><span class="dark-green">)</span>;</p> 
<p>        <span class="dark-green">}</span></p> 
<p><span class="dark-green">    }</span></p> 
<p><span class="dark-green">    </span><em><span class="slate-gray">/**</span></em></p> 
<p><em><span class="slate-gray">      Displays a dialog box with a randomly chosen
            tip.</span></em></p> 
<p><em><span class="slate-gray">      </span></em><strong><em><span class="dark-gray">@return </span></em></strong><em><span class="slate-gray">void</span></em></p> 
<p><em><span class="slate-gray">    */</span></em></p> 
<p><em><span class="slate-gray">    </span></em><strong><span class="blue">public </span></strong><span class="red">void </span><strong><span class="midnight-blue">show</span></strong><span class="dark-green">()
        {</span></p> 
<p><span class="dark-green">        </span><strong><span class="blue">if</span></strong><span class="dark-green">(</span>_tipContainer<span class="dark-green">.</span><strong><span class="midnight-blue">getLength</span></strong><span class="dark-green">() &gt; </span><span class="dark-blue">0</span><span class="dark-green">)
        {</span></p> 
<p><span class="dark-green">            </span>JOptionPane<span class="dark-green">.</span><strong><span class="midnight-blue">showMessageDialog</span></strong><span class="dark-green">(</span><strong>null</strong><span class="dark-green">,</span></p> 
<p><span class="dark-green">                </span>_tipContainer<span class="dark-green">.</span><strong><span class="midnight-blue">getTip</span></strong><span class="dark-green">((</span><strong><span class="red">int</span></strong><span class="dark-green">)(</span>Math<span class="dark-green">.</span><strong><span class="midnight-blue">random</span></strong><span class="dark-green">()
        *</span></p> 
<p><span class="dark-green">                (</span>_tipContainer<span class="dark-green">.</span><strong><span class="midnight-blue">getLength</span></strong><span class="dark-green">()
        - </span><span class="dark-blue">1</span><span class="dark-green">))))</span>;</p> 
<p>        <span class="dark-green">} </span><strong><span class="blue">else </span></strong><span class="dark-green">{</span></p> 
<p><span class="dark-green">            </span>System<span class="dark-green">.</span>err<span class="dark-green">.</span><strong><span class="midnight-blue">println</span></strong><span class="dark-green">(</span><span class="fuchsia">&quot;ERR:
        No tips found.&quot;</span><span class="dark-green">)</span>;</p> 
<p>        <span class="dark-green">}</span></p> 
<p><span class="dark-green">    }</span></p> 
<p><span class="dark-green">}</span></p> 
</div>
<h3>5.4. TestTipContainer.java</h3> 
<div class="code-samples">
<p><strong><span class="green">package </span></strong>com<span class="dark-green">.</span>umlet<span class="dark-green">.</span>testing;</p> 
<p><strong><span class="green">import </span></strong>junit<span class="dark-green">.</span>framework<span class="dark-green">.*</span>;</p> 
<p><strong><span class="green">import </span></strong>com<span class="dark-green">.</span>umlet<span class="dark-green">.</span>control<span class="dark-green">.</span>TipContainer;</p> 
<p><em><span class="slate-gray">/**</span></em></p> 
<p><em><span class="slate-gray">  Provides a way to test the basic functionality
            of the TipContainer</span></em></p> 
<p><em><span class="slate-gray">  which is used for 'tip of the day' functionality.</span></em></p> 
<p><em><span class="slate-gray">*/</span></em></p> 
<p><strong><span class="blue">public </span></strong><span class="red">class </span>TestTipContainer <span class="brown">extends </span>TestCase <span class="dark-green">{</span></p> 
<p><span class="dark-green">    </span><em><span class="slate-gray">/**</span></em></p> 
<p><em><span class="slate-gray">      Simple constructor, simply feeds straight
            through to the parent</span></em></p> 
<p><em><span class="slate-gray">      class which is part of the JUnit framework.</span></em></p> 
<p><em><span class="slate-gray">      </span></em><strong><em><span class="dark-gray">@param </span></em></strong><em><span class="slate-gray">name
            String</span></em></p> 
<p><em><span class="slate-gray">    */</span></em></p> 
<p><em><span class="slate-gray">    </span></em><strong><span class="blue">public </span></strong><strong><span class="midnight-blue">TestTipContainer</span></strong><span class="dark-green">(</span>String
    name<span class="dark-green">) {</span></p> 
<p><span class="dark-green">        </span><strong>super</strong><span class="dark-green">(</span>name<span class="dark-green">)</span>;</p> 
<p>    <span class="dark-green">}</span></p> 
<p><span class="dark-green">    </span><em><span class="slate-gray">/**</span></em></p> 
<p><em><span class="slate-gray">      Test TipContainer creation.</span></em></p> 
<p><em><span class="slate-gray">      </span></em><strong><em><span class="dark-gray">@return </span></em></strong><em><span class="slate-gray">void</span></em></p> 
<p><em><span class="slate-gray">    */</span></em></p> 
<p><em><span class="slate-gray">    </span></em><strong><span class="blue">public </span></strong><span class="red">void </span><strong><span class="midnight-blue">testContainerCreate</span></strong><span class="dark-green">()
        {</span></p> 
<p><span class="dark-green">        </span>TipContainer tmpTip = <strong><span class="dark-cyan">new </span></strong><strong><span class="midnight-blue">TipContainer</span></strong><span class="dark-green">()</span>;</p> 
<p>        <strong><span class="midnight-blue">assertEquals</span></strong><span class="dark-green">(</span>tmpTip<span class="dark-green">.</span><strong><span class="midnight-blue">getLength</span></strong><span class="dark-green">(), </span><span class="dark-blue">0</span><span class="dark-green">)</span>;</p> 
<p>    <span class="dark-green">}</span></p> 
<p><span class="dark-green">    </span><em><span class="slate-gray">/**</span></em></p> 
<p><em><span class="slate-gray">      Test adding an item to the tipContainer.</span></em></p> 
<p><em><span class="slate-gray">    */</span></em></p> 
<p><em><span class="slate-gray">    </span></em><strong><span class="blue">public </span></strong><span class="red">void </span><strong><span class="midnight-blue">testContainerAdd</span></strong><span class="dark-green">()
        {</span></p> 
<p><span class="dark-green">        </span>TipContainer tmpTip = <strong><span class="dark-cyan">new </span></strong><strong><span class="midnight-blue">TipContainer</span></strong><span class="dark-green">()</span>;</p> 
<p>        tmpTip<span class="dark-green">.</span><strong><span class="midnight-blue">add</span></strong><span class="dark-green">(</span><span class="fuchsia">&quot;test&quot;</span><span class="dark-green">)</span>;</p> 
<p>        <strong><span class="midnight-blue">assertEquals</span></strong><span class="dark-green">(</span>tmpTip<span class="dark-green">.</span><strong><span class="midnight-blue">getLength</span></strong><span class="dark-green">(), </span><span class="dark-blue">1</span><span class="dark-green">)</span>;</p> 
<p>        <strong><span class="midnight-blue">assertEquals</span></strong><span class="dark-green">(</span>tmpTip<span class="dark-green">.</span><strong><span class="midnight-blue">getTip</span></strong><span class="dark-green">(</span><span class="dark-blue">0</span><span class="dark-green">), </span><span class="fuchsia">&quot;test&quot;</span><span class="dark-green">)</span>;</p> 
<p>    <span class="dark-green">}</span></p> 
<p><span class="dark-green">    </span><em><span class="slate-gray">/**</span></em></p> 
<p><em><span class="slate-gray">      Test accessing an item which does/should
            not exist.</span></em></p> 
<p><em><span class="slate-gray">    */</span></em></p> 
<p><em><span class="slate-gray">    </span></em><strong><span class="blue">public </span></strong><span class="red">void </span><strong><span class="midnight-blue">testNonexistantIndex</span></strong><span class="dark-green">()
        {</span></p> 
<p><span class="dark-green">        </span>TipContainer tmpTip = <strong><span class="dark-cyan">new </span></strong><strong><span class="midnight-blue">TipContainer</span></strong><span class="dark-green">()</span>;</p> 
<p>        <strong><span class="teal">try </span></strong><span class="dark-green">{</span></p> 
<p><span class="dark-green">            </span>String heh = tmpTip<span class="dark-green">.</span><strong><span class="midnight-blue">getTip</span></strong><span class="dark-green">(</span><span class="dark-blue">0</span><span class="dark-green">)</span>;</p> 
<p>            <strong><span class="midnight-blue">fail</span></strong><span class="dark-green">(</span><span class="fuchsia">&quot;Should
        throw ArrayIndexOutOfBoundsException.&quot;</span><span class="dark-green">)</span>;</p> 
<p>        <span class="dark-green">} </span><strong><span class="teal">catch</span></strong><span class="dark-green">(</span>ArrayIndexOutOfBoundsException
    e<span class="dark-green">) {</span></p> 
<p><span class="dark-green">        }</span></p> 
<p><span class="dark-green">    }</span></p> 
<p><span class="dark-green">}</span></p> 
<h3>5.5. AllTests.java</h3> 
<p>package com<span class="dark-green">.</span>umlet<span class="dark-green">.</span>testing<span class="dark-green">;</span></p> 
<p>import junit<span class="dark-green">.</span>framework<span class="dark-green">.*;</span></p> 
<p><strong><span class="blue">public </span></strong><span class="red">class </span>AllTests <span class="dark-green">{</span></p> 
<p><span class="dark-green">    </span><strong><span class="blue">public </span></strong><span class="brown">static </span><span class="red">void </span><strong><span class="midnight-blue">main</span></strong><span class="dark-green">(</span>String <span class="dark-green">[] </span>args<span class="dark-green">)
        {</span></p> 
<p><span class="dark-green">        </span>junit<span class="dark-green">.</span>textui<span class="dark-green">.</span>TestRunner<span class="dark-green">.</span><strong><span class="midnight-blue">run</span></strong><span class="dark-green">(</span><strong><span class="midnight-blue">testRun</span></strong><span class="dark-green">());</span></p> 
<p><span class="dark-green">    }</span></p> 
<p><span class="dark-green">    </span><strong><span class="blue">public </span></strong><span class="brown">static </span>TestSuite <strong><span class="midnight-blue">testRun</span></strong><span class="dark-green">()
        {</span></p> 
<p><span class="dark-green">        </span>TestSuite theSuite <span class="dark-green">= </span><strong><span class="dark-cyan">new </span></strong><strong><span class="midnight-blue">TestSuite</span></strong><span class="dark-green">();</span></p> 
<p><span class="dark-green">        </span>theSuite<span class="dark-green">.</span><strong><span class="midnight-blue">addTestSuite</span></strong><span class="dark-green">(</span>TestTipContainer<span class="dark-green">.</span><span class="red">class</span><span class="dark-green">);</span></p> 
<p><span class="dark-green">        </span>theSuite<span class="dark-green">.</span><strong><span class="midnight-blue">addTestSuite</span></strong><span class="dark-green">(</span>TestColour<span class="dark-green">.</span><span class="red">class</span><span class="dark-green">);</span></p> 
<p><span class="dark-green">        </span><span class="navy">return </span>theSuite<span class="dark-green">;</span></p> 
<p><span class="dark-green">    }</span></p> 
<p><span class="dark-green">}</span></p> 
</div>
<h3>5.6. Colour.java</h3> 
<p class="centre"><img alt="UML Diagram" width="426"
height="364" src="COMP2801-assignment-3-files/image006.png" /></p> 
<p class="centre"><strong>Figure 5.6.1.  </strong>Shows the relationship between
    the new Colour class and the existing Entity class.</p> 
<p class="centre"><img alt="UML Diagram" width="550"
height="398" src="COMP2801-assignment-3-files/image007.png" /></p> 
<p class="centre"><strong>Figure 5.6.2.</strong>  Shows the paint method added
    to the Entity class, which calls the Colour class to parse the information the
    user typed into the textual palette.</p> 
<div class="code-samples">
<p><strong><span class="green">package </span></strong>com<span class="dark-green">.</span>umlet<span class="dark-green">.</span>element<span class="dark-green">.</span>base; </p> 
<p><strong><span class="green">import </span></strong>java<span class="dark-green">.</span>awt<span class="dark-green">.*</span>;</p> 
<p><strong><span class="green">import </span></strong>java<span class="dark-green">.</span>util<span class="dark-green">.*</span>;</p> 
<p><strong><span class="green">import </span></strong>com<span class="dark-green">.</span>umlet<span class="dark-green">.</span>control<span class="dark-green">.*</span>; <em><span class="slate-gray">//
            Constants</span></em></p> 
<p><em><span class="slate-gray">/**</span></em></p> 
<p><em><span class="slate-gray"> * Provides decode and decodeFill methods to
            decode a string</span></em></p> 
<p><em><span class="slate-gray"> * and create a colour from that string.</span></em></p> 
<p><em><span class="slate-gray"> *</span></em></p> 
<p><em><span class="slate-gray"> * </span></em><strong><em><span class="dark-gray">@author  </span></em></strong><em><span class="slate-gray">Ned
            Martin</span></em></p> 
<p><em><span class="slate-gray"> * </span></em><strong><em><span class="dark-gray">@version </span></em></strong><em><span class="slate-gray">19-OCT-2004</span></em></p> 
<p><em><span class="slate-gray"> */</span></em></p> 
<p><strong><span class="blue">public </span></strong><span class="red">class </span>Colour</p> 
<p><span class="dark-green">{</span></p> 
<p><span class="dark-green">      </span><em><span class="slate-gray">/**</span></em></p> 
<p><em><span class="slate-gray">       * Decodes a given string and returns a
            colour, defaulting to</span></em></p> 
<p><em><span class="slate-gray">       * black.</span></em></p> 
<p><em><span class="slate-gray">       *</span></em></p> 
<p><em><span class="slate-gray">       * </span></em><strong><em><span class="dark-gray">@param   </span></em></strong><em><span class="slate-gray">String
            to decode.</span></em></p> 
<p><em><span class="slate-gray">       * </span></em><strong><em><span class="dark-gray">@return  </span></em></strong><em><span class="slate-gray">Color
            representation of input.</span></em></p> 
<p><em><span class="slate-gray">       */</span></em></p> 
<p><em><span class="slate-gray">      </span></em><strong><span class="blue">public </span></strong><span class="brown">static </span>Color
    decode</p> 
<p>      <span class="dark-green">(</span></p> 
<p><span class="dark-green">            </span>String      colour</p> 
<p>      <span class="dark-green">)</span></p> 
<p><span class="dark-green">      {</span></p> 
<p><span class="dark-green">            </span><em><span class="slate-gray">//
            split string into r, g, b</span></em></p> 
<p><em><span class="slate-gray">            </span></em><strong><span class="red">int</span></strong><span class="dark-green">[] </span>rgb
    = <strong><span class="midnight-blue">integerize</span></strong><span class="dark-green">(</span>colour<span class="dark-green">, </span><span class="dark-blue">0</span><span class="dark-green">)</span>;</p> 
<p>            <span class="navy">return </span><strong><span class="dark-cyan">new </span></strong><strong><span class="midnight-blue">Color</span></strong><span class="dark-green">(</span>rgb<span class="dark-green">[</span><span class="dark-blue">0</span><span class="dark-green">], </span>rgb<span class="dark-green">[</span><span class="dark-blue">1</span><span class="dark-green">], </span>rgb<span class="dark-green">[</span><span class="dark-blue">2</span><span class="dark-green">])</span>;</p> 
<p>      <span class="dark-green">} </span><em><span class="slate-gray">// end
            decode</span></em></p> 
<p><em><span class="slate-gray">      /**</span></em></p> 
<p><em><span class="slate-gray">       * Parses the palette attributes of an
            Entity and returns an</span></em></p> 
<p><em><span class="slate-gray">       * array containing the attributes minus
            any colour</span></em></p> 
<p><em><span class="slate-gray">       * information, and the foreground and
            background colours.</span></em></p> 
<p><em><span class="slate-gray">       *</span></em></p> 
<p><em><span class="slate-gray">       * </span></em><strong><em><span class="dark-gray">@param   </span></em></strong><em><span class="slate-gray">String
            pallette attributes.</span></em></p> 
<p><em><span class="slate-gray">       * </span></em><strong><em><span class="dark-gray">@return  </span></em></strong><em><span class="slate-gray">Object[]
            containing the palette attributes minus</span></em></p> 
<p><em><span class="slate-gray">       *          any colour information as a
            vector, and the</span></em></p> 
<p><em><span class="slate-gray">       *          foreground and background colours
            as Color.</span></em></p> 
<p><em><span class="slate-gray">       */</span></em></p> 
<p><em><span class="slate-gray">      </span></em><strong><span class="blue">public </span></strong><span class="brown">static </span>Object<span class="dark-green">[] </span>parseActive</p> 
<p>      <span class="dark-green">(</span></p> 
<p><span class="dark-green">            </span>String      palletteProperties</p> 
<p>      <span class="dark-green">)</span></p> 
<p><span class="dark-green">      {</span></p> 
<p><span class="dark-green">            </span>Vector input = Constants<span class="dark-green">.</span><strong><span class="midnight-blue">decomposeStrings</span></strong><span class="dark-green">(</span>palletteProperties<span class="dark-green">, </span><span class="fuchsia">&quot;&quot;</span><span class="dark-green">)</span>;</p> 
<p>            String            borderColour = <span class="fuchsia">&quot;&quot;</span><span class="dark-green">,</span></p> 
<p><span class="dark-green">                        </span>borderLine = <span class="fuchsia">&quot;&quot;</span><span class="dark-green">,</span></p> 
<p><span class="dark-green">                        </span>fillColour = <span class="fuchsia">&quot;&quot;</span><span class="dark-green">,</span></p> 
<p><span class="dark-green">                        </span>fillLine = <span class="fuchsia">&quot;&quot;</span>;</p> 
<p>            Object<span class="dark-green">[]    </span>output = <strong><span class="dark-cyan">new </span></strong>Object<span class="dark-green">[</span><span class="dark-blue">3</span><span class="dark-green">]</span>;</p> 
<p>            <strong><span class="blue">for </span></strong><span class="dark-green">(</span><strong><span class="red">int </span></strong>ii
    = <span class="dark-blue">0</span>; ii <span class="dark-green">&lt; </span>input<span class="dark-green">.</span><strong><span class="midnight-blue">size</span></strong><span class="dark-green">()</span>;
    ii<span class="dark-green">++)</span></p> 
<p><span class="dark-green">            {</span></p> 
<p><span class="dark-green">                  </span>String s <strong><span class="midnight-blue">= </span></strong><span class="dark-green">(</span>String<span class="dark-green">)</span>input<span class="dark-green">.</span><strong><span class="midnight-blue">elementAt</span></strong><span class="dark-green">(</span>ii<span class="dark-green">)</span>;</p> 
<p>                  <strong><span class="blue">if </span></strong><span class="dark-green">(</span>s<span class="dark-green">.</span><strong><span class="midnight-blue">startsWith</span></strong><span class="dark-green">(</span><span class="fuchsia">&quot;c1=&quot;</span><span class="dark-green">) </span>&amp; s<span class="dark-green">.</span><strong><span class="midnight-blue">length</span></strong><span class="dark-green">() &gt; </span><span class="dark-blue">3</span><span class="dark-green">)</span></p> 
<p><span class="dark-green">                  {</span></p> 
<p><span class="dark-green">                        </span><em><span class="slate-gray">//
            we have a foreground colour attribute</span></em></p> 
<p><em><span class="slate-gray">                        </span></em>borderColour
    = s<span class="dark-green">.</span><strong><span class="midnight-blue">substring</span></strong><span class="dark-green">(</span><span class="dark-blue">3</span><span class="dark-green">, </span>s<span class="dark-green">.</span><strong><span class="midnight-blue">length</span></strong><span class="dark-green">())</span>;</p> 
<p>                        borderLine = s;</p> 
<p>                  <span class="dark-green">}</span></p> 
<p><span class="dark-green">                  </span><strong><span class="blue">if </span></strong><span class="dark-green">(</span>s<span class="dark-green">.</span><strong><span class="midnight-blue">startsWith</span></strong><span class="dark-green">(</span><span class="fuchsia">&quot;c2=&quot;</span><span class="dark-green">) </span>&amp; s<span class="dark-green">.</span><strong><span class="midnight-blue">length</span></strong><span class="dark-green">() &gt; </span><span class="dark-blue">3</span><span class="dark-green">)</span></p> 
<p><span class="dark-green">                  {</span></p> 
<p><span class="dark-green">                        </span><em><span class="slate-gray">//
            we have a background colour attribute</span></em></p> 
<p><em><span class="slate-gray">                        </span></em>fillColour
    = s<span class="dark-green">.</span><strong><span class="midnight-blue">substring</span></strong><span class="dark-green">(</span><span class="dark-blue">3</span><span class="dark-green">, </span>s<span class="dark-green">.</span><strong><span class="midnight-blue">length</span></strong><span class="dark-green">())</span>;</p> 
<p>                        fillLine = s;</p> 
<p>                  <span class="dark-green">}</span></p> 
<p><span class="dark-green">            }</span></p> 
<p><span class="dark-green">            </span><em><span class="slate-gray">//
            remove the colour attributes</span></em></p> 
<p><em><span class="slate-gray">            </span></em>input<span class="dark-green">.</span><strong><span class="midnight-blue">remove</span></strong><span class="dark-green">(</span>borderLine<span class="dark-green">)</span>;</p> 
<p>            input<span class="dark-green">.</span><strong><span class="midnight-blue">remove</span></strong><span class="dark-green">(</span>fillLine<span class="dark-green">)</span>;</p> 
<p>            <em><span class="slate-gray">// we have a custom foreground colour</span></em></p> 
<p><em><span class="slate-gray">            </span></em><strong><span class="blue">if </span></strong><span class="dark-green">(</span>borderColour <span class="dark-green">!</span>= <strong>null </strong>&amp;&amp; borderColour<span class="dark-green">.</span><strong><span class="midnight-blue">length</span></strong><span class="dark-green">() &gt; </span><span class="dark-blue">0</span><span class="dark-green">)</span></p> 
<p><span class="dark-green">            {</span></p> 
<p><span class="dark-green">                  </span>output<span class="dark-green">[</span><span class="dark-blue">2</span><span class="dark-green">] </span>= <strong><span class="midnight-blue">decode</span></strong><span class="dark-green">(</span>borderColour<span class="dark-green">)</span>;</p> 
<p>            <span class="dark-green">}</span></p> 
<p><span class="dark-green">            </span><em><span class="slate-gray">//
            otherwise we don't have a custom foreground colour</span></em></p> 
<p><em><span class="slate-gray">            </span></em><strong><span class="blue">else</span></strong></p> 
<p><strong><span class="blue">            </span></strong><span class="dark-green">{</span></p> 
<p><span class="dark-green">                  </span><em><span class="slate-gray">//
            set to the default background colour</span></em></p> 
<p><em><span class="slate-gray">                  </span></em>output<span class="dark-green">[</span><span class="dark-blue">2</span><span class="dark-green">] </span>= <strong><span class="midnight-blue">decode</span></strong><span class="dark-green">(</span><span class="fuchsia">&quot;&quot;</span><span class="dark-green">)</span>;</p> 
<p>            <span class="dark-green">}</span></p> 
<p><span class="dark-green">            </span><em><span class="slate-gray">//
            we have a custom background colour</span></em></p> 
<p><em><span class="slate-gray">            </span></em><strong><span class="blue">if </span></strong><span class="dark-green">(</span>fillColour <span class="dark-green">!</span>= <strong>null </strong>&amp;&amp; fillColour<span class="dark-green">.</span><strong><span class="midnight-blue">length</span></strong><span class="dark-green">() &gt; </span><span class="dark-blue">0</span><span class="dark-green">)</span></p> 
<p><span class="dark-green">            {</span></p> 
<p><span class="dark-green">                  </span>output<span class="dark-green">[</span><span class="dark-blue">1</span><span class="dark-green">] </span>= <strong><span class="midnight-blue">decodeFill</span></strong><span class="dark-green">(</span>fillColour<span class="dark-green">)</span>;</p> 
<p>            <span class="dark-green">}</span></p> 
<p><span class="dark-green">            </span><em><span class="slate-gray">//
            otherwise we don't have a custom background colour</span></em></p> 
<p><em><span class="slate-gray">            </span></em><strong><span class="blue">else</span></strong></p> 
<p><strong><span class="blue">            </span></strong><span class="dark-green">{</span></p> 
<p><span class="dark-green">                  </span><em><span class="slate-gray">//
            set to the default foreground colour</span></em></p> 
<p><em><span class="slate-gray">                  </span></em>output<span class="dark-green">[</span><span class="dark-blue">1</span><span class="dark-green">] </span>= <strong><span class="midnight-blue">decodeFill</span></strong><span class="dark-green">(</span><span class="fuchsia">&quot;&quot;</span><span class="dark-green">)</span>;</p> 
<p>            <span class="dark-green">}</span></p> 
<p><span class="dark-green">            </span>output<span class="dark-green">[</span><span class="dark-blue">0</span><span class="dark-green">] </span>=
    input;</p> 
<p>            <span class="navy">return </span>output;</p> 
<p>      <span class="dark-green">} </span><em><span class="slate-gray">// end
            parseActive</span></em></p> 
<p><em><span class="slate-gray">      /**</span></em></p> 
<p><em><span class="slate-gray">       * Decodes a given string and returns a
            colour, defaulting to</span></em></p> 
<p><em><span class="slate-gray">       * white.</span></em></p> 
<p><em><span class="slate-gray">       *</span></em></p> 
<p><em><span class="slate-gray">       * </span></em><strong><em><span class="dark-gray">@param   </span></em></strong><em><span class="slate-gray">String
            to decode.</span></em></p> 
<p><em><span class="slate-gray">       * </span></em><strong><em><span class="dark-gray">@return  </span></em></strong><em><span class="slate-gray">Color
            representation of input.</span></em></p> 
<p><em><span class="slate-gray">       */</span></em></p> 
<p><em><span class="slate-gray">      </span></em><strong><span class="blue">public </span></strong><span class="brown">static </span>Color
    decodeFill</p> 
<p>      <span class="dark-green">(</span></p> 
<p><span class="dark-green">            </span>String      colour</p> 
<p>      <span class="dark-green">)</span></p> 
<p><span class="dark-green">      {</span></p> 
<p><span class="dark-green">            </span><em><span class="slate-gray">//
            split string into r, g, b</span></em></p> 
<p><em><span class="slate-gray">            </span></em><strong><span class="red">int</span></strong><span class="dark-green">[] </span>rgb
    = <strong><span class="midnight-blue">integerize</span></strong><span class="dark-green">(</span>colour<span class="dark-green">, </span><span class="dark-blue">255</span><span class="dark-green">)</span>;</p> 
<p>            <span class="navy">return </span><strong><span class="dark-cyan">new </span></strong><strong><span class="midnight-blue">Color</span></strong><span class="dark-green">(</span>rgb<span class="dark-green">[</span><span class="dark-blue">0</span><span class="dark-green">], </span>rgb<span class="dark-green">[</span><span class="dark-blue">1</span><span class="dark-green">], </span>rgb<span class="dark-green">[</span><span class="dark-blue">2</span><span class="dark-green">])</span>;</p> 
<p>      <span class="dark-green">} </span><em><span class="slate-gray">// end
            decodeFill</span></em></p> 
<p><em><span class="slate-gray">      /**</span></em></p> 
<p><em><span class="slate-gray">       * Splits a string into an array of three
            integers less than</span></em></p> 
<p><em><span class="slate-gray">       * 255.</span></em></p> 
<p><em><span class="slate-gray">       *</span></em></p> 
<p><em><span class="slate-gray">       * </span></em><strong><em><span class="dark-gray">@param   </span></em></strong><em><span class="slate-gray">String
            to split.</span></em></p> 
<p><em><span class="slate-gray">       * </span></em><strong><em><span class="dark-gray">@return  </span></em></strong><em><span class="slate-gray">int[]
            of integers.</span></em></p> 
<p><em><span class="slate-gray">       */</span></em></p> 
<p><em><span class="slate-gray">      </span></em><strong><span class="blue">private </span></strong><span class="brown">static </span><strong><span class="red">int</span></strong><span class="dark-green">[] </span>integerize</p> 
<p>      <span class="dark-green">(</span></p> 
<p><span class="dark-green">            </span>String      input<span class="dark-green">,</span></p> 
<p><span class="dark-green">            </span><strong><span class="red">int   </span></strong>baseColour</p> 
<p>      <span class="dark-green">)</span></p> 
<p><span class="dark-green">      {</span></p> 
<p><span class="dark-green">            </span><strong><span class="red">int   </span></strong>bufferPosition
    = <span class="dark-blue">0</span>;</p> 
<p>            <strong><span class="red">int</span></strong><span class="dark-green">[] </span>output
    = <strong><span class="dark-cyan">new </span></strong><strong><span class="red">int</span></strong><span class="dark-green">[</span><span class="dark-blue">3</span><span class="dark-green">]</span>;</p> 
<p>            <strong><span class="blue">for </span></strong><span class="dark-green">(</span><strong><span class="red">int </span></strong>ii
    = <span class="dark-blue">0</span>; ii <span class="dark-green">&lt; </span><span class="dark-blue">3</span>;
    ii<span class="dark-green">++)</span></p> 
<p><span class="dark-green">            {</span></p> 
<p><span class="dark-green">                  </span>String      temp = <span class="fuchsia">&quot;&quot;</span>;</p> 
<p>                  <strong><span class="red">int   </span></strong>out = baseColour;</p> 
<p>                  <em><span class="slate-gray">// skip any leading white space.</span></em></p> 
<p><em><span class="slate-gray">                  </span></em><strong><span class="blue">while </span></strong><span class="dark-green">(</span>bufferPosition <span class="dark-green">&lt; </span>input<span class="dark-green">.</span><strong><span class="midnight-blue">length</span></strong><span class="dark-green">() </span>&amp;&amp;</p> 
<p>                        <span class="dark-green">(</span>input<span class="dark-green">.</span><strong><span class="midnight-blue">charAt</span></strong><span class="dark-green">(</span>bufferPosition<span class="dark-green">) </span>== <span class="fuchsia">'
        ' </span><span class="dark-green">||</span></p> 
<p><span class="dark-green">                        </span>input<span class="dark-green">.</span><strong><span class="midnight-blue">charAt</span></strong><span class="dark-green">(</span>bufferPosition<span class="dark-green">) </span>== <span class="fuchsia">''</span><span class="dark-green">))</span></p> 
<p><span class="dark-green">                  {</span></p> 
<p><span class="dark-green">                        </span><em><span class="slate-gray">//
            advance the buffer position.</span></em></p> 
<p><em><span class="slate-gray">                        </span></em>bufferPosition<span class="dark-green">++</span>;</p> 
<p>                  <span class="dark-green">}</span></p> 
<p><span class="dark-green">                  </span><em><span class="slate-gray">//
            build a string of consecutive integers.</span></em></p> 
<p><em><span class="slate-gray">                  </span></em><strong><span class="blue">while </span></strong><span class="dark-green">(</span>bufferPosition <span class="dark-green">&lt; </span>input<span class="dark-green">.</span><strong><span class="midnight-blue">length</span></strong><span class="dark-green">() </span>&amp;&amp;</p> 
<p>                        Character<span class="dark-green">.</span><strong><span class="midnight-blue">isDigit</span></strong><span class="dark-green">(</span>input<span class="dark-green">.</span><strong><span class="midnight-blue">charAt</span></strong><span class="dark-green">(</span>bufferPosition<span class="dark-green">)))</span></p> 
<p><span class="dark-green">                  {</span></p> 
<p><span class="dark-green">                        </span><em><span class="slate-gray">//
            concatenate current character to the previous one.</span></em></p> 
<p><em><span class="slate-gray">                        </span></em>temp <span class="dark-green">+</span>=
    input<span class="dark-green">.</span><strong><span class="midnight-blue">charAt</span></strong><span class="dark-green">(</span>bufferPosition<span class="dark-green">)</span>;</p> 
<p>                        <em><span class="slate-gray">// advance the buffer
            position.</span></em></p> 
<p><em><span class="slate-gray">                        </span></em>bufferPosition<span class="dark-green">++</span>;</p> 
<p>                  <span class="dark-green">}</span></p> 
<p><span class="dark-green">                  </span><strong><span class="teal">try</span></strong></p> 
<p><strong><span class="teal">                  </span></strong><span class="dark-green">{</span></p> 
<p><span class="dark-green">                        </span>out = Integer<span class="dark-green">.</span><strong><span class="midnight-blue">parseInt</span></strong><span class="dark-green">(</span>temp<span class="dark-green">)</span>;</p> 
<p>                  <span class="dark-green">}</span></p> 
<p><span class="dark-green">                  </span><em><span class="slate-gray">//
            error parsing integer</span></em></p> 
<p><em><span class="slate-gray">                  </span></em><strong><span class="teal">catch </span></strong><span class="dark-green">(</span>Exception
    e<span class="dark-green">)</span></p> 
<p><span class="dark-green">                  {</span></p> 
<p><span class="dark-green">                        </span><em><span class="slate-gray">//
            integer was out of bounds</span></em></p> 
<p><em><span class="slate-gray">                  </span></em><span class="dark-green">}</span></p> 
<p><span class="dark-green">                  </span><em><span class="slate-gray">//
            ensure the output is not greater than 255</span></em></p> 
<p><em><span class="slate-gray">                  </span></em>output<span class="dark-green">[</span>ii<span class="dark-green">] </span><strong><span class="midnight-blue">= </span></strong><span class="dark-green">(</span>out <span class="dark-green">&lt;</span>= <span class="dark-blue">255</span><span class="dark-green">)?</span>out:baseColour;</p> 
<p>            <span class="dark-green">}</span></p> 
<p><span class="dark-green">            </span><em><span class="slate-gray">//
            return the integer value of the concatenated</span></em></p> 
<p><em><span class="slate-gray">            // characters.</span></em></p> 
<p><em><span class="slate-gray">            </span></em><span class="navy">return </span>output;</p> 
<p>      <span class="dark-green">} </span><em><span class="slate-gray">// end
            nextDouble</span></em></p> 
<p><span class="dark-green">} </span><em><span class="slate-gray">// end Colour</span></em></p> 
</div>
<h3>5.7. UniversalListener.java (extract)</h3> 
<div class="code-samples">
<p><strong><span class="blue">public </span></strong><span class="red">void </span><strong><span class="midnight-blue">actionPerformed</span></strong><span class="dark-green">(</span>ActionEvent
    e<span class="dark-green">) {</span></p> 
<p><span class="dark-green">    </span>JMenuItem b<strong><span class="midnight-blue">=</span></strong><span class="dark-green">(</span>JMenuItem<span class="dark-green">)</span>e<span class="dark-green">.</span><strong><span class="midnight-blue">getSource</span></strong><span class="dark-green">()</span>;</p> 
<p>    <strong><span class="blue">if </span></strong><span class="dark-green">(</span>b<span class="dark-green">.</span><strong><span class="midnight-blue">getText</span></strong><span class="dark-green">()</span>==<span class="fuchsia">&quot;Delete&quot;</span><span class="dark-green">)
        {</span></p> 
<p><span class="dark-green">        </span>Vector v=Selector<span class="dark-green">.</span><strong><span class="midnight-blue">getInstance</span></strong><span class="dark-green">().</span><strong><span class="midnight-blue">getSelectedEntitiesOnPanel</span></strong><span class="dark-green">()</span>;</p> 
<p>        <strong><span class="blue">if </span></strong><span class="dark-green">(</span>v<span class="dark-green">.</span><strong><span class="midnight-blue">size</span></strong><span class="dark-green">()&gt;</span><span class="dark-blue">0</span><span class="dark-green">)
        {</span></p> 
<p><span class="dark-green">          </span>Controller<span class="dark-green">.</span><strong><span class="midnight-blue">getInstance</span></strong><span class="dark-green">().</span><strong><span class="midnight-blue">executeCommand</span></strong><span class="dark-green">(</span><strong><span class="dark-cyan">new </span></strong><strong><span class="midnight-blue">RemoveElement</span></strong><span class="dark-green">(</span>v<span class="dark-green">))</span>;</p> 
<p>        <span class="dark-green">}</span></p> 
<p><span class="dark-green">    } </span><strong><span class="blue">else if </span></strong><span class="dark-green">(</span>b<span class="dark-green">.</span><strong><span class="midnight-blue">getText</span></strong><span class="dark-green">()</span>==<span class="fuchsia">&quot;Undo&quot;</span><span class="dark-green">)
        {</span></p> 
<p><span class="dark-green">      </span>Selector<span class="dark-green">.</span><strong><span class="midnight-blue">getInstance</span></strong><span class="dark-green">().</span><strong><span class="midnight-blue">deselectAll</span></strong><span class="dark-green">()</span>;</p> 
<p>      Controller<span class="dark-green">.</span><strong><span class="midnight-blue">getInstance</span></strong><span class="dark-green">().</span><strong><span class="midnight-blue">undo</span></strong><span class="dark-green">()</span>;</p> 
<p>    <span class="dark-green">} </span><strong><span class="blue">else if </span></strong><span class="dark-green">(</span>b<span class="dark-green">.</span><strong><span class="midnight-blue">getText</span></strong><span class="dark-green">()</span>==<span class="fuchsia">&quot;Redo&quot;</span><span class="dark-green">)
        {</span></p> 
<p><span class="dark-green">      </span>Controller<span class="dark-green">.</span><strong><span class="midnight-blue">getInstance</span></strong><span class="dark-green">().</span><strong><span class="midnight-blue">redo</span></strong><span class="dark-green">()</span>;</p> 
<p>    <span class="dark-green">} </span><strong><span class="blue">else if </span></strong><span class="dark-green">(</span>b<span class="dark-green">.</span><strong><span class="midnight-blue">getText</span></strong><span class="dark-green">()</span>==<span class="fuchsia">&quot;Open&quot;</span><span class="dark-green">)
        {</span></p> 
<p><span class="dark-green">      </span>Umlet<span class="dark-green">.</span><strong><span class="midnight-blue">getInstance</span></strong><span class="dark-green">().</span><strong><span class="midnight-blue">doOpen</span></strong><span class="dark-green">()</span>;</p> 
<p>    <span class="dark-green">} </span><strong><span class="blue">else if </span></strong><span class="dark-green">(</span>b<span class="dark-green">.</span><strong><span class="midnight-blue">getText</span></strong><span class="dark-green">()</span>==<span class="fuchsia">&quot;Save&quot;</span><span class="dark-green">)
        {</span></p> 
<p><span class="dark-green">      </span>Umlet<span class="dark-green">.</span><strong><span class="midnight-blue">getInstance</span></strong><span class="dark-green">().</span><strong><span class="midnight-blue">doSave</span></strong><span class="dark-green">()</span>;</p> 
<p>    <span class="dark-green">} </span><strong><span class="blue">else if </span></strong><span class="dark-green">(</span>b<span class="dark-green">.</span><strong><span class="midnight-blue">getText</span></strong><span class="dark-green">()</span>==<span class="fuchsia">&quot;Save
        as..&quot;</span><span class="dark-green">) {</span></p> 
<p><span class="dark-green">      </span>Umlet<span class="dark-green">.</span><strong><span class="midnight-blue">getInstance</span></strong><span class="dark-green">().</span><strong><span class="midnight-blue">doSaveAs</span></strong><span class="dark-green">()</span>;</p> 
<p>    <span class="dark-green">} </span><strong><span class="blue">else if </span></strong><span class="dark-green">(</span>b<span class="dark-green">.</span><strong><span class="midnight-blue">getText</span></strong><span class="dark-green">()</span>==<span class="fuchsia">&quot;New&quot;</span><span class="dark-green">)
        {</span></p> 
<p><span class="dark-green">       </span>Umlet<span class="dark-green">.</span><strong><span class="midnight-blue">getInstance</span></strong><span class="dark-green">().</span><strong><span class="midnight-blue">doNew</span></strong><span class="dark-green">()</span>;</p> 
<p>    <span class="dark-green">} </span><strong><span class="blue">else if </span></strong><span class="dark-green">(</span>b<span class="dark-green">.</span><strong><span class="midnight-blue">getText</span></strong><span class="dark-green">()</span>==<span class="fuchsia">&quot;Save
        as JPG..&quot;</span><span class="dark-green">) {</span></p> 
<p><span class="dark-green">      </span>Umlet<span class="dark-green">.</span><strong><span class="midnight-blue">getInstance</span></strong><span class="dark-green">().</span><strong><span class="midnight-blue">doSaveAsJPG</span></strong><span class="dark-green">()</span>;</p> 
<p>    <span class="dark-green">} </span><strong><span class="blue">else if </span></strong><span class="dark-green">(</span>b<span class="dark-green">.</span><strong><span class="midnight-blue">getText</span></strong><span class="dark-green">()</span>==<span class="fuchsia">&quot;Save
        as SVG..&quot;</span><span class="dark-green">) {        </span></p> 
<p><span class="dark-green">      </span>Umlet<span class="dark-green">.</span><strong><span class="midnight-blue">getInstance</span></strong><span class="dark-green">().</span><strong><span class="midnight-blue">doSaveAsSvg</span></strong><span class="dark-green">()</span>;</p> 
<p>    <span class="dark-green">} </span><strong><span class="blue">else if </span></strong><span class="dark-green">(</span>b<span class="dark-green">.</span><strong><span class="midnight-blue">getText</span></strong><span class="dark-green">()</span>==<span class="fuchsia">&quot;Save
        as EPS..&quot;</span><span class="dark-green">) { </span><em><span class="slate-gray">//LME</span></em></p> 
<p><em><span class="slate-gray">      </span></em>Umlet<span class="dark-green">.</span><strong><span class="midnight-blue">getInstance</span></strong><span class="dark-green">().</span><strong><span class="midnight-blue">doSaveAsEps</span></strong><span class="dark-green">()</span>;   </p> 
<p>    <span class="dark-green">} </span><strong><span class="blue">else if </span></strong><span class="dark-green">(</span>b<span class="dark-green">.</span><strong><span class="midnight-blue">getText</span></strong><span class="dark-green">()</span>==<span class="fuchsia">&quot;Save
        as PDF..&quot;</span><span class="dark-green">) {</span></p> 
<p><span class="dark-green">      </span>Umlet<span class="dark-green">.</span><strong><span class="midnight-blue">getInstance</span></strong><span class="dark-green">().</span><strong><span class="midnight-blue">doSaveAsPdf</span></strong><span class="dark-green">()</span>;</p> 
<p>    <span class="dark-green">} </span><strong><span class="blue">else if </span></strong><span class="dark-green">(</span>b<span class="dark-green">.</span><strong><span class="midnight-blue">getText</span></strong><span class="dark-green">()</span>==<span class="fuchsia">&quot;Tip
        of the day&quot;</span><span class="dark-green">) {</span></p> 
<p><span class="dark-green">      </span><strong><span class="teal">try </span></strong><span class="dark-green">{</span></p> 
<p><span class="dark-green">        </span>TipGenerator<span class="dark-green">.</span><strong><span class="midnight-blue">getInstance</span></strong><span class="dark-green">().</span><strong><span class="midnight-blue">show</span></strong><span class="dark-green">()</span>; <em><span class="slate-gray">//
            ADDED BY STEPHEN GORDON</span></em></p> 
<p><em><span class="slate-gray">      </span></em><span class="dark-green">} </span><strong><span class="teal">catch</span></strong><span class="dark-green">(</span>Exception
    ex<span class="dark-green">) {</span></p> 
<p><span class="dark-green">        </span>System<span class="dark-green">.</span>err<span class="dark-green">.</span><strong><span class="midnight-blue">println</span></strong><span class="dark-green">(</span><span class="fuchsia">&quot;ERR:
        Unable to display tip.&quot;</span><span class="dark-green">)</span>;</p> 
<p>      <span class="dark-green">}</span></p> 
<p><span class="dark-green">    } </span><strong><span class="blue">else if</span></strong><span class="dark-green">(</span>b<span class="dark-green">.</span><strong><span class="midnight-blue">getText</span></strong><span class="dark-green">()</span>==<span class="fuchsia">&quot;Print...&quot;</span><span class="dark-green">)
        {</span></p> 
<p><span class="dark-green">       </span>PrintPage<span class="dark-green">.</span><strong><span class="midnight-blue">getInstance</span></strong><span class="dark-green">().</span><strong><span class="midnight-blue">doPrint</span></strong><span class="dark-green">()</span>;</p> 
<p>    <span class="dark-green">}</span></p> 
<p><span class="dark-green">    </span><em><span class="slate-gray">//rightclick
            menu actionevents</span></em></p> 
<p><em><span class="slate-gray">     </span></em><strong><span class="blue">else
            if </span></strong><span class="dark-green">(</span>b<span class="dark-green">.</span><strong><span class="midnight-blue">getText</span></strong><span class="dark-green">()</span>==<span class="fuchsia">&quot;Solid
            Line      &quot;</span><span class="dark-green">) {</span></p> 
<p><span class="dark-green">      </span><strong><span class="midnight-blue">alterArrow</span></strong><span class="dark-green">(</span><span class="dark-blue">1</span><span class="dark-green">)</span>;</p> 
<p>    <span class="dark-green">}</span><strong><span class="blue">else if </span></strong><span class="dark-green">(</span>b<span class="dark-green">.</span><strong><span class="midnight-blue">getText</span></strong><span class="dark-green">()</span>==<span class="fuchsia">&quot;Dotted
        Line     &quot;</span><span class="dark-green">) {</span></p> 
<p><span class="dark-green">      </span><strong><span class="midnight-blue">alterArrow</span></strong><span class="dark-green">(</span><span class="dark-blue">2</span><span class="dark-green">)</span>;</p> 
<p>    <span class="dark-green">}</span><strong><span class="blue">else if </span></strong><span class="dark-green">(</span>b<span class="dark-green">.</span><strong><span class="midnight-blue">getText</span></strong><span class="dark-green">()</span>==<span class="fuchsia">&quot;Dependence  &lt;   &quot;</span><span class="dark-green">)
        {</span></p> 
<p><span class="dark-green">      </span><strong><span class="midnight-blue">alterArrow</span></strong><span class="dark-green">(</span><span class="dark-blue">3</span><span class="dark-green">)</span>;</p> 
<p>    <span class="dark-green">}</span><strong><span class="blue">else if </span></strong><span class="dark-green">(</span>b<span class="dark-green">.</span><strong><span class="midnight-blue">getText</span></strong><span class="dark-green">()</span>==<span class="fuchsia">&quot;Dependence  &gt;   &quot;</span><span class="dark-green">)
        {</span></p> 
<p><span class="dark-green">      </span><strong><span class="midnight-blue">alterArrow</span></strong><span class="dark-green">(</span><span class="dark-blue">4</span><span class="dark-green">)</span>;</p> 
<p>    <span class="dark-green">}</span><strong><span class="blue">else if </span></strong><span class="dark-green">(</span>b<span class="dark-green">.</span><strong><span class="midnight-blue">getText</span></strong><span class="dark-green">()</span>==<span class="fuchsia">&quot;Inheritance &lt;&lt;  &quot;</span><span class="dark-green">)
        {</span></p> 
<p><span class="dark-green">      </span><strong><span class="midnight-blue">alterArrow</span></strong><span class="dark-green">(</span><span class="dark-blue">5</span><span class="dark-green">)</span>;</p> 
<p>    <span class="dark-green">}</span><strong><span class="blue">else if </span></strong><span class="dark-green">(</span>b<span class="dark-green">.</span><strong><span class="midnight-blue">getText</span></strong><span class="dark-green">()</span>==<span class="fuchsia">&quot;Inheritance &gt;&gt;  &quot;</span><span class="dark-green">)
        {</span></p> 
<p><span class="dark-green">      </span><strong><span class="midnight-blue">alterArrow</span></strong><span class="dark-green">(</span><span class="dark-blue">6</span><span class="dark-green">)</span>;</p> 
<p>    <span class="dark-green">}</span><strong><span class="blue">else if </span></strong><span class="dark-green">(</span>b<span class="dark-green">.</span><strong><span class="midnight-blue">getText</span></strong><span class="dark-green">()</span>==<span class="fuchsia">&quot;Aggregation &lt;&lt;&lt; &quot;</span><span class="dark-green">)
        {</span></p> 
<p><span class="dark-green">      </span><strong><span class="midnight-blue">alterArrow</span></strong><span class="dark-green">(</span><span class="dark-blue">7</span><span class="dark-green">)</span>;</p> 
<p>    <span class="dark-green">}</span><strong><span class="blue">else if </span></strong><span class="dark-green">(</span>b<span class="dark-green">.</span><strong><span class="midnight-blue">getText</span></strong><span class="dark-green">()</span>==<span class="fuchsia">&quot;Aggregation &gt;&gt;&gt; &quot;</span><span class="dark-green">)
        {</span></p> 
<p><span class="dark-green">      </span><strong><span class="midnight-blue">alterArrow</span></strong><span class="dark-green">(</span><span class="dark-blue">8</span><span class="dark-green">)</span>;</p> 
<p>    <span class="dark-green">}</span><strong><span class="blue">else if </span></strong><span class="dark-green">(</span>b<span class="dark-green">.</span><strong><span class="midnight-blue">getText</span></strong><span class="dark-green">()</span>==<span class="fuchsia">&quot;Composition &lt;&lt;&lt;&lt;&quot;</span><span class="dark-green">)
        {</span></p> 
<p><span class="dark-green">      </span><strong><span class="midnight-blue">alterArrow</span></strong><span class="dark-green">(</span><span class="dark-blue">9</span><span class="dark-green">)</span>;</p> 
<p>    <span class="dark-green">}</span><strong><span class="blue">else if </span></strong><span class="dark-green">(</span>b<span class="dark-green">.</span><strong><span class="midnight-blue">getText</span></strong><span class="dark-green">()</span>==<span class="fuchsia">&quot;Composition &gt;&gt;&gt;&gt;&quot;</span><span class="dark-green">)
        {</span></p> 
<p><span class="dark-green">      </span><strong><span class="midnight-blue">alterArrow</span></strong><span class="dark-green">(</span><span class="dark-blue">10</span><span class="dark-green">)</span>;</p> 
<p>    <span class="dark-green">}</span></p> 
<p><span class="dark-green">  }</span></p> 
<p><span class="dark-green">  </span><em><span class="slate-gray">// the method
            for changing an arrow with a right click</span></em></p> 
<p><em><span class="slate-gray">  // it alters the drawing palette and then updates
            the properties palette</span></em></p> 
<p><em><span class="slate-gray">  </span></em><strong><span class="blue">public </span></strong><span class="red">void </span><strong><span class="midnight-blue">alterArrow</span></strong><span class="dark-green">(</span><strong><span class="red">int </span></strong>umlSelected<span class="dark-green">){</span></p> 
<p><span class="dark-green">      </span>Relation tmp <strong><span class="midnight-blue">= </span></strong><span class="dark-green">(</span>Relation<span class="dark-green">)</span>rc;</p> 
<p>      Vector atts = Constants<span class="dark-green">.</span><strong><span class="midnight-blue">decomposeStrings</span></strong><span class="dark-green">(</span>tmp<span class="dark-green">.</span><strong><span class="midnight-blue">getPanelAttributes</span></strong><span class="dark-green">(), </span><span class="fuchsia">&quot;&quot;</span><span class="dark-green">)</span>;</p> 
<p>      <strong><span class="blue">for</span></strong><span class="dark-green">(</span><strong><span class="red">int </span></strong>ii
    = <span class="dark-blue">0</span>; ii <span class="dark-green">&lt; </span>atts<span class="dark-green">.</span><strong><span class="midnight-blue">size</span></strong><span class="dark-green">()</span>;
    ii<span class="dark-green">++){</span></p> 
<p><span class="dark-green">         </span>String s = atts<span class="dark-green">.</span><strong><span class="midnight-blue">elementAt</span></strong><span class="dark-green">(</span>ii<span class="dark-green">).</span><strong><span class="midnight-blue">toString</span></strong><span class="dark-green">()</span>;</p> 
<p>         <strong><span class="blue">if</span></strong><span class="dark-green">(</span>s<span class="dark-green">.</span><strong><span class="midnight-blue">startsWith</span></strong><span class="dark-green">(</span><span class="fuchsia">&quot;lt=&quot;</span><span class="dark-green">)){</span></p> 
<p><span class="dark-green">            </span>atts<span class="dark-green">.</span><strong><span class="midnight-blue">setElementAt</span></strong><span class="dark-green">(</span><strong><span class="midnight-blue">getUMLSmbol</span></strong><span class="dark-green">(</span>s<span class="dark-green">, </span>umlSelected<span class="dark-green">), </span>ii<span class="dark-green">)</span>;</p> 
<p>         <span class="dark-green">}</span></p> 
<p><span class="dark-green">      }</span></p> 
<p><span class="dark-green">      </span>String concat = <span class="fuchsia">&quot;&quot;</span>;</p> 
<p>      <strong><span class="blue">for</span></strong><span class="dark-green">(</span><strong><span class="red">int </span></strong>ii
    = <span class="dark-blue">0</span>; ii <span class="dark-green">&lt; </span>atts<span class="dark-green">.</span><strong><span class="midnight-blue">size</span></strong><span class="dark-green">()</span>;
    ii<span class="dark-green">++){</span></p> 
<p><span class="dark-green">         </span>String s = atts<span class="dark-green">.</span><strong><span class="midnight-blue">elementAt</span></strong><span class="dark-green">(</span>ii<span class="dark-green">).</span><strong><span class="midnight-blue">toString</span></strong><span class="dark-green">()</span>;</p> 
<p>          concat = concat <span class="dark-green">+ </span>s<span class="dark-green">+ </span><span class="fuchsia">&quot;&quot;</span>;</p> 
<p>      <span class="dark-green">}</span></p> 
<p><span class="dark-green">      </span>tmp<span class="dark-green">.</span><strong><span class="midnight-blue">setState</span></strong><span class="dark-green">(</span>concat<span class="dark-green">)</span>;</p> 
<p>      Umlet<span class="dark-green">.</span><strong><span class="midnight-blue">getInstance</span></strong><span class="dark-green">().</span><strong><span class="midnight-blue">setPropertyPanelToEntity</span></strong><span class="dark-green">(</span>tmp<span class="dark-green">)</span>;</p> 
<p>  <span class="dark-green">}</span></p> 
</div>
<h3>5.8. Generator.java</h3> 
<div class="code-samples">
<p><strong><span class="green">package </span></strong>com<span class="dark-green">.</span>umlet<span class="dark-green">.</span>control<span class="dark-green">.</span>io;</p> 
<p><strong><span class="green">import </span></strong>java<span class="dark-green">.</span>awt<span class="dark-green">.*</span>;</p> 
<p><strong><span class="green">import </span></strong>java<span class="dark-green">.</span>io<span class="dark-green">.*</span>;</p> 
<p><em><span class="slate-gray">/**</span></em></p> 
<p><em><span class="slate-gray">  The Generator interface provides a common front
            for all classes used to create</span></em></p> 
<p><em><span class="slate-gray">  file output from UMLet.</span></em></p> 
<p><em><span class="slate-gray">  </span></em><strong><em><span class="dark-gray">@author </span></em></strong><em><span class="slate-gray">Stephen
            Gordon &lt;a href=&quot;mailto:stephen.a.gordon@gmail.com&quot;&gt;stephen.a.gordon@gmail.com&lt;/a&gt;</span></em></p> 
<p><em><span class="slate-gray">*/</span></em></p> 
<p><strong><span class="blue">public </span></strong><span class="red">interface </span>Generator <span class="dark-green">{</span></p> 
<p><span class="dark-green">    </span><strong><span class="blue">public </span></strong><span class="red">void </span><strong><span class="midnight-blue">createAndOutputToFile</span></strong><span class="dark-green">(</span>String
    filename<span class="dark-green">)</span>;</p> 
<p>    <strong><span class="blue">public </span></strong><span class="red">void </span><strong><span class="midnight-blue">createToStream</span></strong><span class="dark-green">(</span>OutputStream
    ostream<span class="dark-green">)</span>;</p> 
<p><span class="dark-green">}</span></p> 
</div>
<h3>5.9. DimensionCalculator.java</h3> 
<div class="code-samples">
<p><strong><span class="green">package </span></strong>com<span class="dark-green">.</span>umlet<span class="dark-green">.</span>control<span class="dark-green">.</span>io;</p> 
<p><strong><span class="green">import </span></strong>java<span class="dark-green">.</span>awt<span class="dark-green">.*</span>;</p> 
<p><strong><span class="green">import </span></strong>java<span class="dark-green">.</span>util<span class="dark-green">.*</span>;</p> 
<p><strong><span class="green">import </span></strong>org<span class="dark-green">.</span>apache<span class="dark-green">.</span>batik<span class="dark-green">.</span>dom<span class="dark-green">.*</span>;</p> 
<p><strong><span class="green">import </span></strong>com<span class="dark-green">.</span>umlet<span class="dark-green">.</span>control<span class="dark-green">.*</span>;</p> 
<p><strong><span class="green">import </span></strong>com<span class="dark-green">.</span>umlet<span class="dark-green">.</span>element<span class="dark-green">.</span>base<span class="dark-green">.</span>Entity;</p> 
<p><strong><span class="blue">public </span></strong><span class="red">class </span>DimensionCalculator <span class="dark-green">{</span></p> 
<p><span class="dark-green">    </span><strong><span class="blue">public </span></strong><span class="brown">static </span>Dimension <strong><span class="midnight-blue">calculateCanvas</span></strong><span class="dark-green">()
        {</span></p> 
<p><span class="dark-green">        </span><strong><span class="red">int </span></strong>maxx=<span class="dark-blue">50</span>;</p> 
<p>        <strong><span class="red">int </span></strong>minx=<span class="dark-blue">0</span>;</p> 
<p>        <strong><span class="red">int </span></strong>maxy=<span class="dark-blue">50</span>;</p> 
<p>        <strong><span class="red">int </span></strong>miny=<span class="dark-blue">0</span>;</p> 
<p>        Vector v=Selector<span class="dark-green">.</span><strong><span class="midnight-blue">getInstance</span></strong><span class="dark-green">().</span><strong><span class="midnight-blue">getAllEntitiesOnPanel</span></strong><span class="dark-green">()</span>;</p> 
<p>        <strong><span class="blue">for </span></strong><span class="dark-green">(</span><strong><span class="red">int </span></strong>i=<span class="dark-blue">0</span>;
    i<span class="dark-green">&lt;</span>v<span class="dark-green">.</span><strong><span class="midnight-blue">size</span></strong><span class="dark-green">()</span>;
    i<span class="dark-green">++) {</span></p> 
<p><span class="dark-green">            </span>Entity e <strong><span class="midnight-blue">=</span></strong><span class="dark-green">(</span>Entity<span class="dark-green">)</span>v<span class="dark-green">.</span><strong><span class="midnight-blue">elementAt</span></strong><span class="dark-green">(</span>i<span class="dark-green">)</span>;</p> 
<p>            maxx=Math<span class="dark-green">.</span><strong><span class="midnight-blue">max</span></strong><span class="dark-green">(</span>maxx<span class="dark-green">,</span>e<span class="dark-green">.</span><strong><span class="midnight-blue">getX</span></strong><span class="dark-green">()+</span>e<span class="dark-green">.</span><strong><span class="midnight-blue">getWidth</span></strong><span class="dark-green">()+</span><span class="dark-blue">20</span><span class="dark-green">)</span>;</p> 
<p>            maxy=Math<span class="dark-green">.</span><strong><span class="midnight-blue">max</span></strong><span class="dark-green">(</span>maxy<span class="dark-green">,</span>e<span class="dark-green">.</span><strong><span class="midnight-blue">getY</span></strong><span class="dark-green">()+</span>e<span class="dark-green">.</span><strong><span class="midnight-blue">getHeight</span></strong><span class="dark-green">()+</span><span class="dark-blue">20</span><span class="dark-green">)</span>;</p> 
<p>            minx=Math<span class="dark-green">.</span><strong><span class="midnight-blue">min</span></strong><span class="dark-green">(</span>minx<span class="dark-green">,</span>e<span class="dark-green">.</span><strong><span class="midnight-blue">getX</span></strong><span class="dark-green">()-</span><span class="dark-blue">20</span><span class="dark-green">)</span>;</p> 
<p>            miny=Math<span class="dark-green">.</span><strong><span class="midnight-blue">min</span></strong><span class="dark-green">(</span>miny<span class="dark-green">,</span>e<span class="dark-green">.</span><strong><span class="midnight-blue">getY</span></strong><span class="dark-green">()-</span><span class="dark-blue">20</span><span class="dark-green">)</span>;</p> 
<p>        <span class="dark-green">}</span></p> 
<p><span class="dark-green">        </span><span class="navy">return </span><strong><span class="dark-cyan">new </span></strong><strong><span class="midnight-blue">Dimension</span></strong><span class="dark-green">(</span>maxx<span class="dark-green">-</span>minx<span class="dark-green">,</span>maxy<span class="dark-green">-</span>miny<span class="dark-green">)</span>;</p> 
<p>    <span class="dark-green">}</span></p> 
<p><span class="dark-green">    </span><strong><span class="blue">public </span></strong><span class="brown">static </span>Dimension <strong><span class="midnight-blue">calculateTranslate</span></strong><span class="dark-green">()
        {</span></p> 
<p><span class="dark-green">        </span><strong><span class="red">int </span></strong>maxx=<span class="dark-blue">50</span>;</p> 
<p>        <strong><span class="red">int </span></strong>minx=<span class="dark-blue">0</span>;</p> 
<p>        <strong><span class="red">int </span></strong>maxy=<span class="dark-blue">50</span>;</p> 
<p>        <strong><span class="red">int </span></strong>miny=<span class="dark-blue">0</span>;</p> 
<p>        Vector v=Selector<span class="dark-green">.</span><strong><span class="midnight-blue">getInstance</span></strong><span class="dark-green">().</span><strong><span class="midnight-blue">getAllEntitiesOnPanel</span></strong><span class="dark-green">()</span>;</p> 
<p>        <strong><span class="blue">for </span></strong><span class="dark-green">(</span><strong><span class="red">int </span></strong>i=<span class="dark-blue">0</span>;
    i<span class="dark-green">&lt;</span>v<span class="dark-green">.</span><strong><span class="midnight-blue">size</span></strong><span class="dark-green">()</span>;
    i<span class="dark-green">++) {</span></p> 
<p><span class="dark-green">            </span>Entity e <strong><span class="midnight-blue">=</span></strong><span class="dark-green">(</span>Entity<span class="dark-green">)</span>v<span class="dark-green">.</span><strong><span class="midnight-blue">elementAt</span></strong><span class="dark-green">(</span>i<span class="dark-green">)</span>;</p> 
<p>            maxx=Math<span class="dark-green">.</span><strong><span class="midnight-blue">max</span></strong><span class="dark-green">(</span>maxx<span class="dark-green">,</span>e<span class="dark-green">.</span><strong><span class="midnight-blue">getX</span></strong><span class="dark-green">()+</span>e<span class="dark-green">.</span><strong><span class="midnight-blue">getWidth</span></strong><span class="dark-green">()+</span><span class="dark-blue">20</span><span class="dark-green">)</span>;</p> 
<p>            maxy=Math<span class="dark-green">.</span><strong><span class="midnight-blue">max</span></strong><span class="dark-green">(</span>maxy<span class="dark-green">,</span>e<span class="dark-green">.</span><strong><span class="midnight-blue">getY</span></strong><span class="dark-green">()+</span>e<span class="dark-green">.</span><strong><span class="midnight-blue">getHeight</span></strong><span class="dark-green">()+</span><span class="dark-blue">20</span><span class="dark-green">)</span>;</p> 
<p>            minx=Math<span class="dark-green">.</span><strong><span class="midnight-blue">min</span></strong><span class="dark-green">(</span>minx<span class="dark-green">,</span>e<span class="dark-green">.</span><strong><span class="midnight-blue">getX</span></strong><span class="dark-green">()-</span><span class="dark-blue">20</span><span class="dark-green">)</span>;</p> 
<p>            miny=Math<span class="dark-green">.</span><strong><span class="midnight-blue">min</span></strong><span class="dark-green">(</span>miny<span class="dark-green">,</span>e<span class="dark-green">.</span><strong><span class="midnight-blue">getY</span></strong><span class="dark-green">()-</span><span class="dark-blue">20</span><span class="dark-green">)</span>;</p> 
<p>        <span class="dark-green">}</span></p> 
<p><span class="dark-green">        </span><span class="navy">return </span><strong><span class="dark-cyan">new </span></strong><strong><span class="midnight-blue">Dimension</span></strong><span class="dark-green">(</span>minx<span class="dark-green">,</span>miny<span class="dark-green">)</span>;</p> 
<p>    <span class="dark-green">}</span></p> 
<p><span class="dark-green">}</span></p> 
</div>
<h3>5.10. GenEPS.java (Similar changes to GenJPG, GenPDF, GenSVG)</h3> 
<div class="code-samples">
<p><em><span class="slate-gray">/*</span></em></p> 
<p><em><span class="slate-gray"> * Created on 18.02.2004</span></em></p> 
<p><em><span class="slate-gray"> *</span></em></p> 
<p><em><span class="slate-gray"> * To change the template for this generated
            file go to</span></em></p> 
<p><em><span class="slate-gray"> * Window&amp;gt;Preferences&amp;gt;Java&amp;gt;Code
            Generation&amp;gt;Code and Comments</span></em></p> 
<p><em><span class="slate-gray"> */</span></em></p> 
<p><strong><span class="green">package </span></strong>com<span class="dark-green">.</span>umlet<span class="dark-green">.</span>control<span class="dark-green">.</span>io;</p> 
<p><strong><span class="green">import </span></strong>java<span class="dark-green">.</span>awt<span class="dark-green">.*</span>;</p> 
<p><strong><span class="green">import </span></strong>java<span class="dark-green">.</span>io<span class="dark-green">.*</span>;</p> 
<p><strong><span class="green">import </span></strong>java<span class="dark-green">.</span>util<span class="dark-green">.*</span>;</p> 
<p><strong><span class="green">import </span></strong>org<span class="dark-green">.</span>jibble<span class="dark-green">.</span>epsgraphics<span class="dark-green">.*</span>;</p> 
<p><strong><span class="green">import </span></strong>com<span class="dark-green">.</span>umlet<span class="dark-green">.</span>control<span class="dark-green">.*</span>;</p> 
<p><strong><span class="green">import </span></strong>com<span class="dark-green">.</span>umlet<span class="dark-green">.</span>element<span class="dark-green">.</span>base<span class="dark-green">.</span>Entity;</p> 
<p><em><span class="slate-gray">/**</span></em></p> 
<p><em><span class="slate-gray">  Generate EPS files from the UMLet drawing panel.
            If colour support</span></em></p> 
<p><em><span class="slate-gray">  is in use this will also be saved correctly.</span></em></p> 
<p><em><span class="slate-gray">  </span></em><strong><em><span class="dark-gray">@author </span></em></strong><em><span class="slate-gray">Stephen
            Gordon &lt;a href=&quot;mailto:stephen.a.gordon@gmail.com&quot;&gt;stephen.a.gordon@gmail.com&lt;/a&gt;</span></em></p> 
<p><em><span class="slate-gray">*/</span></em></p> 
<p><strong><span class="blue">public </span></strong><span class="red">class </span>GenEps <span class="brown">implements </span>Generator <span class="dark-green">{</span></p> 
<p><span class="dark-green">    </span><em><span class="slate-gray">/**</span></em></p> 
<p><em><span class="slate-gray">      Paints all entities on the panel to a provided
            Graphics2D object.</span></em></p> 
<p><em><span class="slate-gray">      </span></em><strong><em><span class="dark-gray">@param </span></em></strong><em><span class="slate-gray">Graphics2D
            g2d The object to paint the entities on.</span></em></p> 
<p><em><span class="slate-gray">      </span></em><strong><em><span class="dark-gray">@return </span></em></strong><em><span class="slate-gray">void</span></em></p> 
<p><em><span class="slate-gray">    */</span></em></p> 
<p><em><span class="slate-gray">    </span></em><strong><span class="blue">private </span></strong><span class="red">void </span><strong><span class="midnight-blue">paint</span></strong><span class="dark-green">(</span>Graphics2D
    g2d<span class="dark-green">) {</span></p> 
<p><span class="dark-green">        </span>Vector v=Selector<span class="dark-green">.</span><strong><span class="midnight-blue">getInstance</span></strong><span class="dark-green">().</span><strong><span class="midnight-blue">getAllEntitiesOnPanel</span></strong><span class="dark-green">()</span>;</p> 
<p>        <strong><span class="blue">for </span></strong><span class="dark-green">(</span><strong><span class="red">int </span></strong>i=<span class="dark-blue">0</span>;
    i<span class="dark-green">&lt;</span>v<span class="dark-green">.</span><strong><span class="midnight-blue">size</span></strong><span class="dark-green">()</span>;
    i<span class="dark-green">++) {</span></p> 
<p><span class="dark-green">            </span>Entity e<strong><span class="midnight-blue">=</span></strong><span class="dark-green">(</span>Entity<span class="dark-green">)</span>v<span class="dark-green">.</span><strong><span class="midnight-blue">elementAt</span></strong><span class="dark-green">(</span>i<span class="dark-green">)</span>;</p> 
<p>            g2d<span class="dark-green">.</span><strong><span class="midnight-blue">translate</span></strong><span class="dark-green">(</span>e<span class="dark-green">.</span><strong><span class="midnight-blue">getX</span></strong><span class="dark-green">(), </span>e<span class="dark-green">.</span><strong><span class="midnight-blue">getY</span></strong><span class="dark-green">())</span>;</p> 
<p>            e<span class="dark-green">.</span><strong><span class="midnight-blue">paint</span></strong><span class="dark-green">(</span>g2d<span class="dark-green">)</span>;</p> 
<p>            g2d<span class="dark-green">.</span><strong><span class="midnight-blue">translate</span></strong><span class="dark-green">(-</span>e<span class="dark-green">.</span><strong><span class="midnight-blue">getX</span></strong><span class="dark-green">(),
        -</span>e<span class="dark-green">.</span><strong><span class="midnight-blue">getY</span></strong><span class="dark-green">())</span>;</p> 
<p>        <span class="dark-green">}</span></p> 
<p><span class="dark-green">    }</span></p> 
<p><span class="dark-green">    </span><em><span class="slate-gray">/**</span></em></p> 
<p><em><span class="slate-gray">      Create an EPS image and output to a file.</span></em></p> 
<p><em><span class="slate-gray">      </span></em><strong><em><span class="dark-gray">@param </span></em></strong><em><span class="slate-gray">String
            filename The name of the file to save to.</span></em></p> 
<p><em><span class="slate-gray">      </span></em><strong><em><span class="dark-gray">@return </span></em></strong><em><span class="slate-gray">void</span></em></p> 
<p><em><span class="slate-gray">    */</span></em></p> 
<p><em><span class="slate-gray">    </span></em><strong><span class="blue">public </span></strong><span class="red">void </span><strong><span class="midnight-blue">createAndOutputToFile</span></strong><span class="dark-green">(</span>String
    filename<span class="dark-green">) {</span></p> 
<p><span class="dark-green">        </span><strong><span class="teal">try </span></strong><span class="dark-green">{</span></p> 
<p><span class="dark-green">            </span>OutputStream ostream = <strong><span class="dark-cyan">new </span></strong><strong><span class="midnight-blue">FileOutputStream</span></strong><span class="dark-green">(</span>filename<span class="dark-green">)</span>;</p> 
<p>            <strong><span class="midnight-blue">createToStream</span></strong><span class="dark-green">(</span>ostream<span class="dark-green">)</span>;</p> 
<p>        <span class="dark-green">} </span><strong><span class="teal">catch </span></strong><span class="dark-green">(</span>Exception
    e<span class="dark-green">) {</span></p> 
<p><span class="dark-green">            </span>System<span class="dark-green">.</span>out<span class="dark-green">.</span><strong><span class="midnight-blue">println</span></strong><span class="dark-green">(</span><span class="fuchsia">&quot;IO
        Exception.&quot;</span><span class="dark-green">)</span>;</p> 
<p>        <span class="dark-green">}</span></p> 
<p><span class="dark-green">    }</span></p> 
<p><span class="dark-green">    </span><em><span class="slate-gray">/**</span></em></p> 
<p><em><span class="slate-gray">      Create an EPS image and output it to a
            stream.</span></em></p> 
<p><em><span class="slate-gray">      </span></em><strong><em><span class="dark-gray">@param </span></em></strong><em><span class="slate-gray">OutputStream
            ostream The stream to output data to.</span></em></p> 
<p><em><span class="slate-gray">      </span></em><strong><em><span class="dark-gray">@return </span></em></strong><em><span class="slate-gray">void</span></em></p> 
<p><em><span class="slate-gray">    */</span></em></p> 
<p><em><span class="slate-gray">    </span></em><strong><span class="blue">public </span></strong><span class="red">void </span><strong><span class="midnight-blue">createToStream</span></strong><span class="dark-green">(</span>OutputStream
    outputStream<span class="dark-green">) { </span><em><span class="slate-gray">//create
    and write stream to file</span></em></p> 
<p><em><span class="slate-gray">        </span></em><strong><span class="teal">try </span></strong><span class="dark-green">{</span></p> 
<p><span class="dark-green">            </span>PrintWriter bw = <strong><span class="dark-cyan">new </span></strong><strong><span class="midnight-blue">PrintWriter</span></strong><span class="dark-green">(</span>outputStream<span class="dark-green">)</span>;</p> 
<p>            EpsGraphics2D g = <strong><span class="dark-cyan">new </span></strong><strong><span class="midnight-blue">EpsGraphics2D</span></strong><span class="dark-green">(</span><span class="fuchsia">&quot;umlet_diagram&quot;</span><span class="dark-green">)</span>;</p> 
<p>            <strong><span class="midnight-blue">paint</span></strong><span class="dark-green">(</span>g<span class="dark-green">)</span>;</p> 
<p>            bw<span class="dark-green">.</span><strong><span class="midnight-blue">print</span></strong><span class="dark-green">(</span>g<span class="dark-green">.</span><strong><span class="midnight-blue">toString</span></strong><span class="dark-green">())</span>;</p> 
<p>            bw<span class="dark-green">.</span><strong><span class="midnight-blue">flush</span></strong><span class="dark-green">()</span>;</p> 
<p>            bw<span class="dark-green">.</span><strong><span class="midnight-blue">close</span></strong><span class="dark-green">()</span>;</p> 
<p>        <span class="dark-green">} </span><strong><span class="teal">catch </span></strong><span class="dark-green">(</span>Exception
    fnfe<span class="dark-green">) {</span></p> 
<p><span class="dark-green">            </span>System<span class="dark-green">.</span>out<span class="dark-green">.</span><strong><span class="midnight-blue">println</span></strong><span class="dark-green">(</span><span class="fuchsia">&quot;UMLet:
        Error: Exception in GenEps.createToStream: &quot;</span><span class="dark-green">+</span>fnfe<span class="dark-green">)</span>;</p> 
<p>        <span class="dark-green">}</span></p> 
<p><span class="dark-green">    }</span></p> 
<p><span class="dark-green">}</span></p> 
</div>
<h3>5.11 TestColour.java</h3> 
<div class="code-samples">
<p>package com<span class="dark-green">.</span>umlet<span class="dark-green">.</span>testing<span class="dark-green">;</span></p> 
<p>import junit<span class="dark-green">.</span>framework<span class="dark-green">.*;</span></p> 
<p>import java<span class="dark-green">.</span>awt<span class="dark-green">.*;</span></p> 
<p>import java<span class="dark-green">.</span>util<span class="dark-green">.*;</span></p> 
<p>import com<span class="dark-green">.</span>umlet<span class="dark-green">.</span>element<span class="dark-green">.</span><strong>base</strong><span class="dark-green">.</span>Colour<span class="dark-green">;</span></p> 
<p><span class="Xnines">/**</span></p> 
<p><span class="Xnines"> * Tests the Colour class by passing various input to
        the </span></p> 
<p><span class="Xnines"> * three public functions within the Colour class, and
        testing that</span></p> 
<p><span class="Xnines"> * the returned values are the expected values for those
        input.</span></p> 
<p><span class="Xnines"> *</span></p> 
<p><span class="Xnines"> * @author  Ned Martin, s4052992 at the </span><span class="Xnines">University</span><span
 class="Xnines"> of </span><span
  class="Xnines">Queensland</span></p> 
<p><span class="Xnines"> *          www.nedmartin.org/uni/</span></p> 
<p><span class="Xnines"> * @copyright     Copyright (c) 2004 Ned Martin</span></p> 
<p><span class="Xnines"> * @version 2004-10-28-SUBMIT</span></p> 
<p><span class="Xnines"> */</span></p> 
<p><strong><span class="blue">public </span></strong><span class="red">class </span>TestColour
    extends TestCase</p> 
<p><span class="dark-green">{</span></p> 
<p><span class="dark-green">      </span><span class="Xnines">/**</span></p> 
<p><span class="Xnines">       * Simple constructor, simply feeds straight through
        to the</span></p> 
<p><span class="Xnines">       * parent class which is part of the JUnit framework.</span></p> 
<p><span class="Xnines">       *</span></p> 
<p><span class="Xnines">       * @param   String name.</span></p> 
<p><span class="Xnines">       */</span></p> 
<p><span class="green">      </span><strong><span class="blue">public </span></strong><strong><span class="midnight-blue">TestColour</span></strong><span class="dark-green">(</span>String
    name<span class="dark-green">)</span></p> 
<p><span class="dark-green">      {</span></p> 
<p><span class="dark-green">            </span><strong><span class="midnight-blue">super</span></strong><span class="dark-green">(</span>name<span class="dark-green">);</span></p> 
<p><span class="dark-green">      } </span><span class="green">// end TestColour</span></p> 
<p><span class="Xnines">      /**</span></p> 
<p><span class="Xnines">       * Tests the Colour.parseActive() method by passing
        it a series</span></p> 
<p><span class="Xnines">       * of different values and comparing the returned
        values.</span></p> 
<p><span class="Xnines">       *</span></p> 
<p><span class="Xnines">       * Various random valid and invalid strings are
        passed to</span></p> 
<p><span class="Xnines">       * Colour.parseActive() and the two Color's returned
        are tested</span></p> 
<p><span class="Xnines">       * to ensure that they match the expected return
        values.</span></p> 
<p><span class="Xnines">       *</span></p> 
<p><span class="Xnines">       * Note that should the random string generator
        generate a</span></p> 
<p><span class="Xnines">       * valid String in the format c1=number or c2=number,
        then this</span></p> 
<p><span class="Xnines">       * test will fail, but the likelihood of this occuring
        is very</span></p> 
<p><span class="Xnines">       * slight.</span></p> 
<p><span class="Xnines">       */</span></p> 
<p><span class="green">      </span><strong><span class="blue">public </span></strong><span class="red">void </span><strong><span class="midnight-blue">testParseActive</span></strong><span class="dark-green">()</span></p> 
<p><span class="dark-green">      {</span></p> 
<p><span class="dark-green">            </span><span class="Xnines">// test with
        random string</span></p> 
<p><span class="green">            </span>String randomString <span class="dark-green">= </span><strong><span class="midnight-blue">makeRandom</span></strong><span class="dark-green">();</span></p> 
<p><span class="dark-green">            </span>Object<span class="dark-green">[] </span>returned <span class="dark-green">= </span>Colour<span class="dark-green">.</span><strong><span class="midnight-blue">parseActive</span></strong><span class="dark-green">(</span>randomString<span class="dark-green">);</span></p> 
<p><span class="dark-green">      </span><span class="Xnines">      // test that
        Vector holding string still holds string</span></p> 
<p><span class="green">            </span><strong><span class="midnight-blue">assertEquals</span></strong><span class="dark-green">((</span>String<span class="dark-green">)((</span>Vector<span class="dark-green">)</span>returned<span class="dark-green">[</span><span class="dark-blue">0</span><span class="dark-green">]).</span><strong><span class="midnight-blue">elementAt</span></strong><span class="dark-green">(</span><span class="dark-blue">0</span><span class="dark-green">),</span></p> 
<p><span class="dark-green">                         </span>randomString<span class="dark-green">);</span></p> 
<p><span class="dark-green">            </span><span class="Xnines">// test that
        fill colour c2 equals the right Color</span></p> 
<p><span class="green">            </span><strong><span class="midnight-blue">assertEquals</span></strong><span class="dark-green">(</span>returned<span class="dark-green">[</span><span class="dark-blue">1</span><span class="dark-green">], </span>Color<span class="dark-green">.</span>white<span class="dark-green">);</span></p> 
<p><span class="dark-green">            </span><span class="Xnines">// test that
        border colour c1 equals the right Color</span></p> 
<p><span class="green">            </span><strong><span class="midnight-blue">assertEquals</span></strong><span class="dark-green">(</span>returned<span class="dark-green">[</span><span class="dark-blue">2</span><span class="dark-green">], </span>Color<span class="dark-green">.</span>black<span class="dark-green">);</span></p> 
<p><span class="dark-green">            </span>String      validString<span class="dark-green">;</span></p> 
<p><span class="dark-green">            </span>Color validColor<span class="dark-green">;</span></p> 
<p><span class="dark-green">            </span>Object<span class="dark-green">[] </span><span class="red">object</span><span class="dark-green">;</span></p> 
<p><span class="Xnines">            // get a valid colour set</span></p> 
<p><span class="green">            </span><span class="red">object </span><span class="dark-green">= </span><strong><span class="midnight-blue">validColourString</span></strong><span class="dark-green">();</span></p> 
<p><span class="dark-green">            </span>validString <span class="dark-green">=
        (</span>String<span class="dark-green">)</span><span class="red">object</span><span class="dark-green">[</span><span class="dark-blue">0</span><span class="dark-green">];</span></p> 
<p><span class="dark-green">            </span>validColor <span class="dark-green">=
        (</span>Color<span class="dark-green">)</span><span class="red">object</span><span class="dark-green">[</span><span class="dark-blue">1</span><span class="dark-green">];</span></p> 
<p><span class="Xnines">            // reset returned</span></p> 
<p><span class="green">            </span>returned <span class="dark-green">= </span><strong><span class="dark-cyan">new </span></strong>Object<span class="dark-green">[</span><span class="dark-blue">3</span><span class="dark-green">];</span></p> 
<p><span class="dark-green">            </span><span class="Xnines">// test with
        a valid c1 string</span></p> 
<p><span class="green">            </span>returned <span class="dark-green">= </span>Colour<span class="dark-green">.</span><strong><span class="midnight-blue">parseActive</span></strong><span class="dark-green">(</span><span class="fuchsia">&quot;c1=&quot; </span><span class="dark-green">+ </span>validString<span class="dark-green">);</span></p> 
<p><span class="dark-green">            </span><span class="Xnines">// ensure
        the Vector returned is empty</span></p> 
<p><span class="green">            </span><strong><span class="midnight-blue">assertEquals</span></strong><span class="dark-green">(((</span>Vector<span class="dark-green">)</span>returned<span class="dark-green">[</span><span class="dark-blue">0</span><span class="dark-green">]).</span><strong><span class="midnight-blue">size</span></strong><span class="dark-green">(), </span><span class="dark-blue">0</span><span class="dark-green">);</span></p> 
<p><span class="dark-green">            </span><span class="Xnines">// ensure
        the Color's returned are correct</span></p> 
<p><span class="green">            </span><strong><span class="midnight-blue">assertEquals</span></strong><span class="dark-green">(</span>returned<span class="dark-green">[</span><span class="dark-blue">1</span><span class="dark-green">], </span>Color<span class="dark-green">.</span>white<span class="dark-green">);</span></p> 
<p><span class="dark-green">            </span><strong><span class="midnight-blue">assertEquals</span></strong><span class="dark-green">(</span>returned<span class="dark-green">[</span><span class="dark-blue">2</span><span class="dark-green">], </span>validColor<span class="dark-green">);</span></p> 
<p><span class="Xnines">            // reset returned</span></p> 
<p><span class="green">            </span>returned <span class="dark-green">= </span><strong><span class="dark-cyan">new </span></strong>Object<span class="dark-green">[</span><span class="dark-blue">3</span><span class="dark-green">];</span></p> 
<p><span class="dark-green">            </span><span class="Xnines">// test with
        a valid c2 string</span></p> 
<p><span class="green">            </span>returned <span class="dark-green">= </span>Colour<span class="dark-green">.</span><strong><span class="midnight-blue">parseActive</span></strong><span class="dark-green">(</span><span class="fuchsia">&quot;c2=&quot; </span><span class="dark-green">+ </span>validString<span class="dark-green">);</span></p> 
<p><span class="dark-green">            </span><span class="Xnines">// ensure
        the Vector returned is empty</span></p> 
<p><span class="green">            </span><strong><span class="midnight-blue">assertEquals</span></strong><span class="dark-green">(((</span>Vector<span class="dark-green">)</span>returned<span class="dark-green">[</span><span class="dark-blue">0</span><span class="dark-green">]).</span><strong><span class="midnight-blue">size</span></strong><span class="dark-green">(), </span><span class="dark-blue">0</span><span class="dark-green">);</span></p> 
<p><span class="dark-green">            </span><span class="Xnines">// ensure
        the Color's returned are correct</span></p> 
<p><span class="green">            </span><strong><span class="midnight-blue">assertEquals</span></strong><span class="dark-green">(</span>returned<span class="dark-green">[</span><span class="dark-blue">1</span><span class="dark-green">], </span>validColor<span class="dark-green">);</span></p> 
<p><span class="dark-green">            </span><strong><span class="midnight-blue">assertEquals</span></strong><span class="dark-green">(</span>returned<span class="dark-green">[</span><span class="dark-blue">2</span><span class="dark-green">], </span>Color<span class="dark-green">.</span>black<span class="dark-green">);</span></p> 
<p><span class="dark-green">            </span><span class="Xnines">// reset
        returned</span></p> 
<p><span class="green">            </span>returned <span class="dark-green">= </span><strong><span class="dark-cyan">new </span></strong>Object<span class="dark-green">[</span><span class="dark-blue">3</span><span class="dark-green">];</span></p> 
<p><span class="dark-green">            </span><span class="Xnines">// test with
        a valid c1 and c2 string</span></p> 
<p><span class="green">            </span>String      c <span class="dark-green">= </span><span class="fuchsia">&quot;c1=&quot; </span><span class="dark-green">+ </span>validString <span class="dark-green">+ </span><span class="fuchsia">&quot;&quot; </span><span class="dark-green">+ </span><span class="fuchsia">&quot;c2=&quot; </span><span class="dark-green">+ </span>validString<span class="dark-green">;</span></p> 
<p><span class="dark-green">            </span>returned <span class="dark-green">= </span>Colour<span class="dark-green">.</span><strong><span class="midnight-blue">parseActive</span></strong><span class="dark-green">(</span>c<span class="dark-green">);</span></p> 
<p><span class="dark-green">            </span><span class="Xnines">// ensure
        the Vector returned is empty</span></p> 
<p><span class="green">            </span><strong><span class="midnight-blue">assertEquals</span></strong><span class="dark-green">(((</span>Vector<span class="dark-green">)</span>returned<span class="dark-green">[</span><span class="dark-blue">0</span><span class="dark-green">]).</span><strong><span class="midnight-blue">size</span></strong><span class="dark-green">(), </span><span class="dark-blue">0</span><span class="dark-green">);</span></p> 
<p><span class="dark-green">            </span><span class="Xnines">// ensure
        the Color's returned are correct</span></p> 
<p><span class="green">            </span><strong><span class="midnight-blue">assertEquals</span></strong><span class="dark-green">(</span>returned<span class="dark-green">[</span><span class="dark-blue">1</span><span class="dark-green">], </span>validColor<span class="dark-green">);</span></p> 
<p><span class="dark-green">            </span><strong><span class="midnight-blue">assertEquals</span></strong><span class="dark-green">(</span>returned<span class="dark-green">[</span><span class="dark-blue">2</span><span class="dark-green">], </span>validColor<span class="dark-green">);</span></p> 
<p><span class="dark-green">            </span><span class="Xnines">// reset
        returned</span></p> 
<p><span class="green">            </span>returned <span class="dark-green">= </span><strong><span class="dark-cyan">new </span></strong>Object<span class="dark-green">[</span><span class="dark-blue">3</span><span class="dark-green">];</span></p> 
<p><span class="dark-green">      </span><span class="Xnines">      // test with
        a valid c2 and c1 string</span></p> 
<p><span class="green">            </span>c <span class="dark-green">= </span><span class="fuchsia">&quot;c2=&quot; </span><span class="dark-green">+ </span>validString <span class="dark-green">+ </span><span class="fuchsia">&quot;&quot; </span><span class="dark-green">+ </span><span class="fuchsia">&quot;c1=&quot; </span><span class="dark-green">+ </span>validString<span class="dark-green">;</span></p> 
<p><span class="dark-green">            </span>returned <span class="dark-green">= </span>Colour<span class="dark-green">.</span><strong><span class="midnight-blue">parseActive</span></strong><span class="dark-green">(</span>c<span class="dark-green">);</span></p> 
<p><span class="dark-green">            </span><span class="Xnines">// ensure
        the Vector returned is empty</span></p> 
<p><span class="green">            </span><strong><span class="midnight-blue">assertEquals</span></strong><span class="dark-green">(((</span>Vector<span class="dark-green">)</span>returned<span class="dark-green">[</span><span class="dark-blue">0</span><span class="dark-green">]).</span><strong><span class="midnight-blue">size</span></strong><span class="dark-green">(), </span><span class="dark-blue">0</span><span class="dark-green">);</span></p> 
<p><span class="dark-green">            </span><span class="Xnines">// ensure
        the Color's returned are correct</span></p> 
<p><span class="green">            </span><strong><span class="midnight-blue">assertEquals</span></strong><span class="dark-green">(</span>returned<span class="dark-green">[</span><span class="dark-blue">1</span><span class="dark-green">], </span>validColor<span class="dark-green">);</span></p> 
<p><span class="dark-green">            </span><strong><span class="midnight-blue">assertEquals</span></strong><span class="dark-green">(</span>returned<span class="dark-green">[</span><span class="dark-blue">2</span><span class="dark-green">], </span>validColor<span class="dark-green">);</span></p> 
<p><span class="dark-green">            </span><span class="Xnines">// test with
        a randomly padded valid c1 and c2 string</span></p> 
<p><span class="green">            </span>c <span class="dark-green">= </span>randomString <span class="dark-green">+ </span><span class="fuchsia">&quot;=&quot; </span><span class="dark-green">+ </span>validString <span class="dark-green">+ </span><span class="fuchsia">&quot;&quot; </span><span class="dark-green">+ </span>randomString <span class="dark-green">+ </span><span class="fuchsia">&quot;&quot; </span><span class="dark-green">+ </span><span class="fuchsia">&quot;c2=&quot; </span><span class="dark-green">+ </span>validString <span class="dark-green">+ </span><span class="fuchsia">&quot;&quot; </span><span class="dark-green">+ </span>randomString<span class="dark-green">;</span></p> 
<p><span class="dark-green">            </span>returned <span class="dark-green">= </span>Colour<span class="dark-green">.</span><strong><span class="midnight-blue">parseActive</span></strong><span class="dark-green">(</span>c<span class="dark-green">);</span></p> 
<p><span class="dark-green">      </span><span class="Xnines">      // ensure
        the Vector returned contains 3 elements</span></p> 
<p><span class="green">            </span><strong><span class="midnight-blue">assertEquals</span></strong><span class="dark-green">(((</span>Vector<span class="dark-green">)</span>returned<span class="dark-green">[</span><span class="dark-blue">0</span><span class="dark-green">]).</span><strong><span class="midnight-blue">size</span></strong><span class="dark-green">(), </span><span class="dark-blue">3</span><span class="dark-green">);</span></p> 
<p><span class="dark-green">            </span><strong><span class="midnight-blue">assertEquals</span></strong><span class="dark-green">(</span>returned<span class="dark-green">[</span><span class="dark-blue">1</span><span class="dark-green">], </span>validColor<span class="dark-green">);</span></p> 
<p><span class="dark-green">            </span><strong><span class="midnight-blue">assertEquals</span></strong><span class="dark-green">(</span>returned<span class="dark-green">[</span><span class="dark-blue">2</span><span class="dark-green">], </span>validColor<span class="dark-green">);</span></p> 
<p><span class="dark-green">      } </span><span class="Xnines">// end testParseActive</span></p> 
<p><span class="Xnines">      /**</span></p> 
<p><span class="Xnines">       * Tests that Colour.decode() returns the expected
        Color when</span></p> 
<p><span class="Xnines">       * given both valid and invalid String input. The
        Color</span></p> 
<p><span class="Xnines">       * returned should be black if the input is invalid.</span></p> 
<p><span class="Xnines">       */</span></p> 
<p><span class="green">      </span><strong><span class="blue">public </span></strong><span class="red">void </span><strong><span class="midnight-blue">testDecode</span></strong><span class="dark-green">()</span></p> 
<p><span class="dark-green">      {</span></p> 
<p><span class="dark-green">            </span><span class="Xnines">// test with
        a random string</span></p> 
<p><span class="green">            </span>String randomString <span class="dark-green">= </span><strong><span class="midnight-blue">makeRandom</span></strong><span class="dark-green">();</span></p> 
<p><span class="dark-green">            </span>Color colour <span class="dark-green">= </span>Colour<span class="dark-green">.</span><strong><span class="midnight-blue">decode</span></strong><span class="dark-green">(</span>randomString<span class="dark-green">);</span></p> 
<p><span class="dark-green">      </span><span class="Xnines">      // if the
        first char of the random string is a digit then</span></p> 
<p><span class="Xnines">            // a non-black colour should be parsed, otherwise
        it is</span></p> 
<p><span class="Xnines">            // black.</span></p> 
<p><span class="green">            </span><strong><span class="blue">if </span></strong><span class="dark-green">(</span>Character<span class="dark-green">.</span><strong><span class="midnight-blue">isDigit</span></strong><span class="dark-green">(</span>randomString<span class="dark-green">.</span><strong><span class="midnight-blue">charAt</span></strong><span class="dark-green">(</span><span class="dark-blue">0</span><span class="dark-green">)))</span></p> 
<p><span class="dark-green">            {</span></p> 
<p><span class="dark-green">                  </span><strong><span class="midnight-blue">assertNotSame</span></strong><span class="dark-green">(</span>colour<span class="dark-green">, </span>Color<span class="dark-green">.</span>black<span class="dark-green">);</span></p> 
<p><span class="dark-green">            }</span></p> 
<p><span class="dark-green">            </span><strong><span class="blue">else</span></strong></p> 
<p><strong><span class="blue">            </span></strong><span class="dark-green">{</span></p> 
<p><span class="dark-green">                  </span><strong><span class="midnight-blue">assertEquals</span></strong><span class="dark-green">(</span>colour<span class="dark-green">, </span>Color<span class="dark-green">.</span>black<span class="dark-green">);</span></p> 
<p><span class="dark-green">            }</span></p> 
<p><span class="dark-green">      </span><span class="Xnines">      // test with
        a valid colour string</span></p> 
<p><span class="Xnines">            // get a valid colour set</span></p> 
<p><span class="green">            </span>Object<span class="dark-green">[]    </span><span class="red">object </span><span class="dark-green">= </span><strong><span class="midnight-blue">validColourString</span></strong><span class="dark-green">();</span></p> 
<p><span class="dark-green">            </span>String            validString <span class="dark-green">=
        (</span>String<span class="dark-green">)</span><span class="red">object</span><span class="dark-green">[</span><span class="dark-blue">0</span><span class="dark-green">];</span></p> 
<p><span class="dark-green">            </span>Color       validColor <span class="dark-green">=
        (</span>Color<span class="dark-green">)</span><span class="red">object</span><span class="dark-green">[</span><span class="dark-blue">1</span><span class="dark-green">];</span></p> 
<p><span class="dark-green">            </span>colour <span class="dark-green">= </span>Colour<span class="dark-green">.</span><strong><span class="midnight-blue">decode</span></strong><span class="dark-green">(</span>validString<span class="dark-green">);</span></p> 
<p><span class="dark-green">            </span><strong><span class="midnight-blue">assertEquals</span></strong><span class="dark-green">(</span>colour<span class="dark-green">, </span>validColor<span class="dark-green">);</span></p> 
<p><span class="dark-green">      } </span><span class="Xnines">// end testDecode</span></p> 
<p><span class="Xnines">      /**</span></p> 
<p><span class="Xnines">       * Tests that Colour.decodeFill() returns the expected
        Color</span></p> 
<p><span class="Xnines">       * when given</span></p> 
<p><span class="Xnines">       * both valid and invalid String input. The Color
        returned</span></p> 
<p><span class="Xnines">       * should be white if the input is invalid.</span></p> 
<p><span class="Xnines">       */</span></p> 
<p><span class="green">      </span><strong><span class="blue">public </span></strong><span class="red">void </span><strong><span class="midnight-blue">testDecodeFill</span></strong><span class="dark-green">()</span></p> 
<p><span class="dark-green">      {</span></p> 
<p><span class="dark-green">      </span><span class="Xnines">      // test with
        a random string</span></p> 
<p><span class="green">            </span>String randomString <span class="dark-green">= </span><strong><span class="midnight-blue">makeRandom</span></strong><span class="dark-green">();</span></p> 
<p><span class="dark-green">            </span>Color colour <span class="dark-green">= </span>Colour<span class="dark-green">.</span><strong><span class="midnight-blue">decodeFill</span></strong><span class="dark-green">(</span>randomString<span class="dark-green">);</span></p> 
<p><span class="Xnines">            // if the first char of the random string
        is a digit then</span></p> 
<p><span class="Xnines">            // a non-black colour should be parsed, otherwise
        it is</span></p> 
<p><span class="Xnines">            // black.</span></p> 
<p><span class="green">            </span><strong><span class="blue">if </span></strong><span class="dark-green">(</span>Character<span class="dark-green">.</span><strong><span class="midnight-blue">isDigit</span></strong><span class="dark-green">(</span>randomString<span class="dark-green">.</span><strong><span class="midnight-blue">charAt</span></strong><span class="dark-green">(</span><span class="dark-blue">0</span><span class="dark-green">)))</span></p> 
<p><span class="dark-green">            {</span></p> 
<p><span class="dark-green">                  </span><strong><span class="midnight-blue">assertNotSame</span></strong><span class="dark-green">(</span>colour<span class="dark-green">, </span>Color<span class="dark-green">.</span>white<span class="dark-green">);</span></p> 
<p><span class="dark-green">            }</span></p> 
<p><span class="dark-green">            </span><strong><span class="blue">else</span></strong></p> 
<p><strong><span class="blue">            </span></strong><span class="dark-green">{</span></p> 
<p><span class="dark-green">                  </span><strong><span class="midnight-blue">assertEquals</span></strong><span class="dark-green">(</span>colour<span class="dark-green">, </span>Color<span class="dark-green">.</span>white<span class="dark-green">);</span></p> 
<p><span class="dark-green">            }</span></p> 
<p><span class="dark-green">      </span><span class="Xnines">      // test with
        a valid colour string</span></p> 
<p><span class="Xnines">            // get a valid colour set</span></p> 
<p><span class="green">            </span>Object<span class="dark-green">[]    </span><span class="red">object </span><span class="dark-green">= </span><strong><span class="midnight-blue">validColourString</span></strong><span class="dark-green">();</span></p> 
<p><span class="dark-green">            </span>String            validString <span class="dark-green">=
        (</span>String<span class="dark-green">)</span><span class="red">object</span><span class="dark-green">[</span><span class="dark-blue">0</span><span class="dark-green">];</span></p> 
<p><span class="dark-green">            </span>Color       validColor <span class="dark-green">=
        (</span>Color<span class="dark-green">)</span><span class="red">object</span><span class="dark-green">[</span><span class="dark-blue">1</span><span class="dark-green">];</span></p> 
<p><span class="dark-green">            </span>colour <span class="dark-green">= </span>Colour<span class="dark-green">.</span><strong><span class="midnight-blue">decodeFill</span></strong><span class="dark-green">(</span>validString<span class="dark-green">);</span></p> 
<p><span class="dark-green">            </span><strong><span class="midnight-blue">assertEquals</span></strong><span class="dark-green">(</span>colour<span class="dark-green">, </span>validColor<span class="dark-green">);</span></p> 
<p><span class="dark-green">      } </span><span class="Xnines">// end testDecodeFill</span></p> 
<p><span class="Xnines">      /**</span></p> 
<p><span class="Xnines">       * Returns a pseudo-random String of a pseudo-random
        length,</span></p> 
<p><span class="Xnines">       * where the length is between 1 and 80 inclusive,
        containing</span></p> 
<p><span class="Xnines">       * only characters within the standard ASCII range
        (ASCII 32 to</span></p> 
<p><span class="Xnines">       * 126 inclusive). It is still  possible for a
        valid string to</span></p> 
<p><span class="Xnines">       * be generated, but it is infrequent.</span></p> 
<p><span class="Xnines">       *</span></p> 
<p><span class="Xnines">       * @return  String pseudo-randomnly generated</span></p> 
<p><span class="Xnines">       */</span></p> 
<p><span class="green">      </span><strong><span class="blue">private </span></strong>String <strong><span class="midnight-blue">makeRandom</span></strong><span class="dark-green">()</span></p> 
<p><span class="dark-green">      {</span></p> 
<p><span class="dark-green">            </span>Random randomizer <span class="dark-green">= </span><strong><span class="dark-cyan">new </span></strong><strong><span class="midnight-blue">Random</span></strong><span class="dark-green">();</span></p> 
<p><span class="dark-green">            </span>String returned <span class="dark-green">= </span><span class="fuchsia">&quot;&quot;</span><span class="dark-green">;</span></p> 
<p><span class="dark-green">            </span><strong><span class="blue">for </span></strong><span class="dark-green">(</span><strong><span class="red">int </span></strong>ii <span class="dark-green">= </span><span class="dark-blue">0</span><span class="dark-green">; </span>ii <span class="dark-green">&lt; </span>randomizer<span class="dark-green">.</span><strong><span class="midnight-blue">nextInt</span></strong><span class="dark-green">(</span><span class="dark-blue">80</span><span class="dark-green">)
        + </span><span class="dark-blue">1</span><span class="dark-green">; </span>ii<span class="dark-green">++)</span></p> 
<p><span class="dark-green">            {</span></p> 
<p><span class="dark-green">                  </span><span class="Xnines">//
        add an ASCII value from 32 to 126 inclusive</span></p> 
<p><span class="green">                  </span>returned <span class="dark-green">+= </span><strong><span class="dark-cyan">new </span></strong><strong><span class="midnight-blue">Character</span></strong><span class="dark-green">((</span><strong><span class="red">char</span></strong><span class="dark-green">)(</span>randomizer<span class="dark-green">.</span><strong><span class="midnight-blue">nextInt</span></strong><span class="dark-green">(</span><span class="dark-blue">95</span><span class="dark-green">)
        + </span><span class="dark-blue">32</span><span class="dark-green">)).</span><strong><span class="midnight-blue">toString</span></strong><span class="dark-green">();</span></p> 
<p><span class="dark-green">            }</span></p> 
<p><span class="dark-green">            </span><span class="navy">return </span>returned<span class="dark-green">;</span></p> 
<p><span class="dark-green">      } </span><span class="Xnines">// end makeRandom</span></p> 
<p><span class="green">      </span><span class="Xnines">/**</span></p> 
<p><span class="Xnines">       * Returns an Object array containing a valid String
        and the</span></p> 
<p><span class="Xnines">       * Color that valid String should create.</span></p> 
<p><span class="Xnines">       *</span></p> 
<p><span class="Xnines">       * @return  Object[] containing two elements, a
        valid String</span></p> 
<p><span class="Xnines">       *          and the Color produced by that valid
        String.</span></p> 
<p><span class="Xnines">       */</span></p> 
<p><span class="green">      </span><strong><span class="blue">private </span></strong>Object<span class="dark-green">[] </span><strong><span class="midnight-blue">validColourString</span></strong><span class="dark-green">()</span></p> 
<p><span class="dark-green">      {</span></p> 
<p><span class="dark-green">            </span>Random randomizer <span class="dark-green">= </span><strong><span class="dark-cyan">new </span></strong><strong><span class="midnight-blue">Random</span></strong><span class="dark-green">();</span></p> 
<p><span class="dark-green">            </span>Object<span class="dark-green">[] </span>returned <span class="dark-green">= </span><strong><span class="dark-cyan">new </span></strong>Object<span class="dark-green">[</span><span class="dark-blue">2</span><span class="dark-green">];</span></p> 
<p><span class="dark-green">            </span><strong><span class="red">int   </span></strong>r <span class="dark-green">= </span>randomizer<span class="dark-green">.</span><strong><span class="midnight-blue">nextInt</span></strong><span class="dark-green">(</span><span class="dark-blue">256</span><span class="dark-green">),</span></p> 
<p><span class="dark-green">                  </span>g <span class="dark-green">= </span>randomizer<span class="dark-green">.</span><strong><span class="midnight-blue">nextInt</span></strong><span class="dark-green">(</span><span class="dark-blue">256</span><span class="dark-green">),</span></p> 
<p><span class="dark-green">                  </span>b <span class="dark-green">= </span>randomizer<span class="dark-green">.</span><strong><span class="midnight-blue">nextInt</span></strong><span class="dark-green">(</span><span class="dark-blue">256</span><span class="dark-green">);</span></p> 
<p><span class="dark-green">            </span>returned<span class="dark-green">[</span><span class="dark-blue">0</span><span class="dark-green">]
        = </span>r <span class="dark-green">+ </span><span class="fuchsia">&quot; &quot; </span><span class="dark-green">+ </span>g <span class="dark-green">+ </span><span class="fuchsia">&quot; &quot; </span><span class="dark-green">+ </span>b<span class="dark-green">;</span></p> 
<p><span class="dark-green">            </span>returned<span class="dark-green">[</span><span class="dark-blue">1</span><span class="dark-green">]
        = </span><strong><span class="dark-cyan">new </span></strong><strong><span class="midnight-blue">Color</span></strong><span class="dark-green">(</span>r<span class="dark-green">, </span>g<span class="dark-green">, </span>b<span class="dark-green">);</span></p> 
<p><span class="dark-green">            </span><span class="navy">return </span>returned<span class="dark-green">;</span></p> 
<p><span class="dark-green">      } </span><span class="Xnines">// end validColourString</span></p> 
<p><span class="dark-green">} </span><span class="Xnines">// end TestColour</span></p> 
</div>
<p>29-Dec-2004</p>
</body>
</html>