From 42c7e596747873afeb572be551dd991986beb51c Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Wed, 18 May 2022 09:38:49 -0500 Subject: Added front-end code information to the design document --- docs/design.org | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'docs/design.org') diff --git a/docs/design.org b/docs/design.org index be345f2..8bd27e6 100644 --- a/docs/design.org +++ b/docs/design.org @@ -1,14 +1,12 @@ #+TITLE: 7Units Design Document -#+SUBTITLE: For version 0.3.1 -#+DATE: 2021 August 26 +#+SUBTITLE: For version 0.4.0-alpha.1 +#+DATE: 2022 May 18 #+LaTeX_HEADER: \usepackage[a4paper, lmargin=25mm, rmargin=25mm, tmargin=25mm, bmargin=25mm]{geometry} #+LaTeX_HEADER: \usepackage{xurl} #+LaTeX: \newpage * Introduction 7Units is a program that can convert between units. This document details the internal design of 7Units, intended to be used by current and future developers. - - The frontend code is currently subject to change, so it is not included in the current version of this document. * Unit System Design Any code related to the backend unit system is stored in the ~sevenUnits.unit~ package. @@ -56,6 +54,31 @@ Dimension files are similar, only for dimensions instead of units and prefixes. #+LaTeX: \newpage +* Front-End Design + The front-end of 7Units is based on an MVP model. There are two major frontend classes, the *View* and the *Presenter*. +** The View + The ~View~ is the part of the frontend code that directly interacts with the user. It handles input and output, but does not do any processing. Processing is handled by the presenter and the backend code. + + The ~View~ is an interface, not a single class, so that I can easily create multiple views without having to rewrite any processing code. This allows me to easily prototype changes to the GUI without messing with existing code. + + In addition, I have decided to move some functions of the ~View~ into two subinterfaces, ~UnitConversionView~ and ~ExpressionConversionView~. This is because 7Units supports two kinds of unit conversion: unit conversion (select two compatible units, specify a value then convert) and expression conversion (enter two expressions and convert the first to a multiple of the second). Putting these functions into subinterfaces allows a ~View~ to do one type of conversion without forcing it to support the other. + + There are currently two implementations of the ~View~: + - TabbedView :: A Swing GUI implementation that uses tabs to separate the two types of conversion. The default GUI used by 7Units. + - ViewBot :: A simulated view that allows programs to set the output of its public methods (i.e. every getter in ~View~ has a setter in ~ViewBot~). Intended for testing, and is already used by ~PresenterTest~. + Both of these ~View~ implementations implement ~UnitConversionView~ and ~ExpressionConversionView~. +** The Presenter + The ~Presenter~ is an intermediary between the ~View~ and the backend code. It accepts the user's input and passes it to the backend, then accepts the backend's output and passes it to the frontend for user viewing. Its main functions do not have arguments or return values; instead it takes input from and provides output to the ~View~ via its public methods. +** Utility Classes + The frontend has many miscellaneous utility classes. Many of them are package-private. Here is a list of them, with a brief description of what they do and where they are used: + - DefaultPrefixRepetitionRule :: An enum containing the available rules determining when you can repeat prefixes. Used by the ~TabbedView~ for selecting the rule and by the ~Presenter~ for loading it from a file. + - DelegateListModel :: A ~javax.swing.ListModel~ implementation that delegates all of its methods to a ~List~. Implements ~List~ by also delegating to the underlying list. Used by the ~SearchBoxList~ to create an easily mutable ~ListModel~. + - FilterComparator :: A ~Comparator~ that sorts objects according to whether or not they match a filter. Used by the ~SearchBoxList~ for item sorting. + - GridBagBuilder :: A convenience class for generating ~GridBagConstraints~ objects for Swing's ~GridBagLayout~. Used by ~TabbedView~ for constructing the GUI. + - SearchBoxList :: A Swing component that combines a text field and a ~JList~ to create a searchable list. Used by the ~TabbedView~'s unit conversion mode. + - StandardDisplayRules :: A static utility class that allows you to generate display/rounding rules. Used by ~TabbedView~ for generating these rules and ~Presenter~ for loading them from a file. + - UnitConversionRecord :: A record-like object that contains the results of a unit or expression conversion. Used by ~UnitConversionView~ and ~ExpressionConversionView~ for accepting the results to be displayed. +#+LaTeX: \newpage * Utility Classes 7Units has a few general "utility" classes. They aren't directly related to units, but are used in the units system. ** ObjectProduct -- cgit v1.2.3