Introduction

This next stage of the Gaga project is to build a graphical user interface for viewing SVG documents. A prototype is provided. It is extended from the version provided for assignment 1. The program uses a Model View Controller architecture with the display of the SVG image embedded into a window where it is easy to place control widgets. The Model is the SVG abstract parse tree, the View is created by a tree visitor that calculates how to insert text in the correct layout into a TextPanel.

The prototype has an effectively empty Controller. At present it has no actions that change the Model.

Tasks for assignment 2

Create Graphic User Interface controls in the control panel for Gaga to the following specification; and add a new graphic element.

  • Open a button control for a pop-up file chooser that shall enable the user to select the SVG input file. (see JFileChooser). If the user selects a new file at any time, the program will parse and display this new file. (The implementation changes include changing the handling of errors such as a non-SVG file or an empty document, to allow the user to continue and make another choice; and handling the changes to the Model properly.)
  • Zoom a slider to select the zoom magnification scale in a range 0.1 (graphics appear small) to 10.0 (large, zoomed in detail). Remove the Zoom In/Zoom Out button
  • Quit a Quit button
  • Reverse a button control to render the SVG tree in reverse order (hint: create a new visitor). The purpose is to help the user see if there are hidden objects in their picture.
  • new element Extend the SVG specification to include a new graphic element named square. A square has three attributes: cx, cy the coordinates of the centre of the square side the length of one side. Like other elements the square may have other attributes such as fill colour, strokewidth etc.

Display your own error messages in a popup. There should normally be no console output (apart from unavoidable Java system messages).

You must change the usage of Gaga to use no command line arguments (not even the document filename), and switch off reporting of the SVG tree structure. This should be done using a switch in the program source code, not by removing the reporting code altogether, which will remain useful for debugging.

Restrictions on your programming

You must create your own solution by programming the Java yourself, using the Swing components (JPanel, JTextArea, JButton etc. You are not permitted to use a GUI generator, designer tool, or helper system such as NetBeans (or any other).

If you use any program code examples from any source (apart from the course lecture and lab notes) you must acknowledge the source in comments in the code. This is important: see the notes on good practice to avoid plagiarism in programs.

Getting Start:

The Gaga GUI code is structured as a Model-View-Controller program that displays the buffer image from the Java2DRenderer, with an empty Controller. You will need to modify this structure so that the controls are generated before the input file is processed; you may need to extend the controller to handle the graphic elements; you will need to change the Model code, and make it handle and notify changes to any observers.

Implementing the square element requires adding a class to the package types, extending the Visitor interface, and adding a method to each visitor. (Read the program to see how this ease of making changes demonstrates good program design: these changes are relatively small and the modification work is well controlled).

A large part of the work in this assignment is finding the information you need in the Java API documentation and the Swing Tutorial. You are not expected to already know how to do all this programming, but you are expected to learn how to look it up. You will be expected to have an elementary idea of how Swing GUIs work, and to be able to look up the information you need, read and understand it and put it into action. Take some time to read the documentation for these features and think about it before you start writing code.

It is impossible to do this kind of programming in a single hit. You will need time to try out ideas, find and read the documentation and tutorials, debug (and this is very hard with GUIs) and tidy up.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.