Skip to content
Kevin Jia edited this page Jun 28, 2015 · 1 revision

Welcome to the SpreadSheet wiki!

The SpreadSheet Application Design Document


General information


Versions:


Date modified Version. No Author Modifications
04 May 2015 0.0.1 Zhenge Jia Initial version
08 May 2015 0.0.2 Zhenge Jia Enable expression to obtain cell element from cell index
13 May 2015 0.0.3 Zhenge Jia Implement a stable parse method for expression, add extra operators
14 May 2015 0.0.4 Zhenge Jia Implement and optimize automatic recalculation, set up like-c-function, enable cell to be in various formats
15 May 2015 0.0.5 Zhenge Jia Add skins, implement copy, cut, paste
16 May 2015 0.0.6 Zhenge Jia Enlarge amount of test cases, add accelerator key for menuItem
20 May 2015 0.0.7 Zhenge Jia Implement the useful feedback providing part and correct the precision of result in double
21 May 2015 0.0.8 Zhenge Jia Enable the multiple sheets function and finish all extensions requirements

Purpose of this document


  1. To provide an introduction for the Spreadsheet application.
  2. To summarize and explain ideas on various components on the application.
  3. To analysis the parse method for expression identification and execution.
  4. To explain the usage of ScriptEngine for compiling user-defined function.
  5. To serve as a summary of the experience and reflection on designing such application.

Introduction


This assignment aims to develop a simple Spreadsheet application. The application is designed to store data typed into cells, parse expressions and print out the calculation result. The application consists of GUI, expressions parsed into trees for calculation, user-defined functions executed by the API ScriptEngine, amendment on precision of result in double format and feedback about correction of syntax.

The Structure of Spreadsheet Application


The Spreadsheet Application is made up with four parts which are GUI, expressions parsing, user-defined function compiling and correction of precision on result and expression syntax. The following document will discuss these parts respectively.

About GUI


The jFrame provides users with an initial interface for following operations. It consist of three main parts, which are JMenuBar bar, JPanel toolarea with tools components and WorkSheetView worksheetview for table. The following will give out a brief introduction to these three main components.

1. The JMenuBar for menus


In the JMenuBar bar, it provides users with functions to export and load table data in xml formats, change skin of the app, edit user-defined function, do copy, cut and paste operations on selected cell and etc. The accelerator keys are added into several JMenuItems to improve the efficiency.

2. The JPanel for tools


In the JPanel toolarea, it enables users to enter data into cell and calculate expressions. The JButton calculate is the core part of the whole application. The function of it is implemented within the ActionPerformed method.

3. The WorkSheetView for table


In the WorkSheetView worksheetview, it provides users with a view and operations of cells.

About Expressions Parse


To analysis an expression, the Expression class is necessary to distinguish operators and numbers. Besides that, it place symbols into correct positions according to the order of operations. The SimpleTokenizer class is like a provider of data to parse method in the Expression class.

1. The Structure of Expressions


exp :: = term | term + exp | term - exp

term :: = ope | ope * term | ope / term

ope :: = val | val ^ ope | val % ope

val :: = num | (exp) | - exp

2. The Expression Class


In the Expression class, the parse method is to parse the input into an expression tree. The precedence of operators including bracket is considered into it so that there are four methods for the paring expression process. The plus and minus are in level 1, multiply and divide are in level 2, mod and power are in level 3 and the bracket is in level 4 with the basic number identification. As a result, it provides the expressions with a stable parsing process and satisfy the order of operations correctly.

3. The SimpleTokenizer And Tokenizer Classes


In the Tokenizer class, it is an abstract class which is used in SimpleTokenizer for extending. The SimpleTokenizer handle the input in format of String and give out the output contains all symbols with white spaces consumed. The method tokenizeParseShowEvaluate in Expression class utilizes the SimpleTokenizer to transfer the String input into Tokenizer format which is readable in expression parsing process.

About Function Compiling


As for user-defined functions, the API ScriptEngine is utilized to read input in String format and compile it in JavaScript grammar. ScriptEngine is the fundamental interface whose methods must be fully functional in every implementation of this specification. These methods provide basic scripting functionality. In the Spreadsheet, the functions in String written in FunctionEditor is splited with the sign of "\n". The function will be invoked when the input name is the same as that of function. As a result, users should provide the functions satisfying the rules of grammar in JavaScript.

About Correction


The implemention of basic functions of Spreadsheet application is not a hard task. However, there are several functions which would improve the usability of the whole application. The precision of result in double format and providing users with useful feedback on syntax are the two significant parts in the Spreadsheet.

1. The Arith Classes


This class is created for the precision of calculation on double format numbers. It import the java.math.BigDecimal to provide the result with correct precision. The API BigDecimal provides operations for arithmetic, scale manipulation, rounding, comparison, hashing, and format conversion. With applying methods in Arith class, the calculation result will be rounded to the value without the trouble like "1.99999.." such format.

2. The ParseException Classes


This class extends the Exception class and contains a feedback method. In this method, it divides the situations where the syntax of input has errors into six groups. Besides that, the method Thread.currentThread.stop() is utilized to stop the thread once the errors are detected. It is invoked in four parse methods contained in the Expression class. As a result, the errors would cause a interruption of thread and print out error message using JOptionPane.

The End


Through the design process on Assignment2, my understanding of relationship among GUI, methods has been improved. The expression parse part is helpful for the development of other software in the future. Hope for the next semester and I could obtain more improvement.

The UML Diagrame


The UML without GUI.


UML-ver02

The UML with GUI with several modification in it.


UML