| Bank statement viewer |
|
|
| Home | Bank statement viewer | Simple library | Text editor | Editor library | CMS | Programming language interpreter | Game "Aspen Forest" | Seeds keeper | Blog |
|
|
|
Java (11), Swing (Single document interface) My friend gets bank statements as text files, with data shown as key-value pairs. He puts these files into a system, but sometimes there are issues. The payment date might be strange, the wrong code might be used, or a required field might be missing. Checking the file in a text editor is hard. It would be much better if he could open the file in a program and see the statement as a clear table, with each payment on a separate row. This would easily show all payments, who they're from, who they're to, and all the details. This is exactly what this program does. But it also allows you to understand how to create a menu, toolbar, status bar, context menu, file open dialog, file table display, search, drag & drop, and L&F using a bit of Java and Swing, and put it all together as an SDI. Eclipse was used for development. The project is located here: https://github.com/weekend-game/bankviewer/ (EN) and here: https://gitflic.ru/project/weekend-game/bankviewer/ (RU). |
| How to run the program |
|
Download the repository to your computer. Everything you need for the program is located in the app folder. Navigate to the app folder and run the program by double-clicking the BankViewer.jar file or, if the program doesn't start, double-click the BankViewer.bat file. If the program doesn't start, download and install Java 11 or later and repeat the steps above. |
| How to open the project in Eclipse |
In Eclipse, select "Import..." from the "File" menu. In the window that opens, select "Existing projects into workspace." Navigate to the folder with the downloaded repository and click "Finish." The project will open in Eclipse. In the Package Explorer (on the left side of the screen), double-click the BankViewer.java file. The file will open for editing (in the center of the screen). Run the program by pressing Ctrl+F11 or using your preferred method for running programs in Eclipse. The project includes a separate program called TestGenerator. It is located in the game.weekend.bankviewer.util package. The program allows you to specify the file name and number of bank statement lines, and it will generate a test file for you. The files BankStatement1.txt, BankStatement2.txt and BankStatement3.txt were generated using TestGenerator. |
| How to use the program |
|
The program uses a single document interface. This means that upon launch, you'll see the familiar menu, toolbar, empty space in the center of the window for displaying the document, and a status bar at the very bottom. There are three ways to open a bank statement for viewing. The first method is to select "File" - "Open..." from the menu or use the button on the toolbar. This will open a dialog box where you can select a bank statement file, for example, the BankStatement1.txt file available in the repository. The second method is to use the Drag and Drop feature, specifically dragging the bank statement file to the center of the application window. The third method is good for previously opened files. Paths to recently opened files are displayed in the "File" menu. Simply select the desired file, and it will be displayed. To find text on a bank statement, press Ctrl+F, button with the image of binoculars on the toolbar, or select "Find..." from the Edit menu. In the dialog box that opens, enter your search string, select case sensitivity, specify the search direction, and click "Find Next." You can continue searching from the open search window using the toolbar buttons or keyboard shortcuts (Ctrl+G or Ctrl+Shift+G). Some operations can be performed by right-clicking to open the context menu. The application's appearance can be customized using the View menu. First, you can choose your preferred design style. Second, you can hide the toolbar and status bar. You can view your bank statement using only keyboard shortcuts and menu items, but the toolbar and status bar take up space. Third, you can select the interface language: Russian or English. All settings, even the search string, are saved between sessions. |
| How the program is written |
|
The main class of the application is the BankViewer class. It contains the static main() method for launching the program. Its constructor creates everything necessary for operation. The program's main point In the BankViewer() constructor, I create a pane object of the JEditorPane() class. JEditorPane is a ready-made class provided by Swing. This object can display HTML. But I don't have any HTML file. I have a bank statement file as a list of key-value pairs. Therefore, I need to convert the source file into an HTML file containing a table and pass it to the pane for display. The Filer class, which is designed for working with files, has method open(File file). In this method, I call Convertor.convert(file.getPath(), tempFile), where file.getPath() is the path to the source file, and tempFile is the name of the temporary file in which the HTML table will be generated. This method, based on the rule that all pairs between the "СекцияДокумент" and "КонецДокумента" keys are payment order fields, will generate an ArrayList of payment orders. It just so happens that different payment orders in the statement contain different lists of fields. But the table needs to display all the fields found in the payment orders. Therefore, I need to define many existing fields and only then write the HTML code for the HTML table to tempFile. Then, when tempFile is ready, I call viewer.showFile(tempFile), which does pane.setPage(name_of_the_generated_html_file), i.e., tells the pane object to display the file. Which is exactly what the pane does. That's all. The source file, containing key-value pairs, is displayed on the screen as a table. Everything else is just the SDI implementation and a service for ease of use. Yes, of course, the Convector class isn't all that simple; it's over 350 lines long. But that's the main thing that solves this program's problem. That's why I took the time to write extensive comments in the class's code. More about Convector Creating an HTML file (Convertor.convert(String srcFileName, File dstFile)) consists of three steps:
Now let's take a closer look. 1. Loading the source file as an array of documents (loadSource(srcFileName)) I read pairs from the source file and create a Substance class object that contains all the document's key-value pairs. A document is anything that begins with the key "СекцияДокумент" and ends with "КонецДокумента". Everything in between is captured in Substance. Since there are many documents in the extract, I create an array of these documents (ArrayList <Substance> documents). 2. Создание массива полей, которые встречаются во всех документах (getFields(documents)) I declare: ArrayList fields = new ArrayList(); This will be the list of fields that appear in all documents. From the list of documents, I select the document with the largest number of fields. This document becomes the basis for further work. I copy all its keys to fields. Then I look through all the other documents and add all the other keys that are not present to fields. So, at this stage, I have a list of all documents and a list of all possible fields. 3. Creating the HTML file (createHTML(dstFile, documents, fields)) I write the tags needed to create the table to dstFile. I then loop through all the documents and populate the HTML table. Since key/value pairs can be located in different positions in different documents, and some pairs may be missing, I use fields to determine where in the table to write the next value. You can learn more about how the program works by downloading the project, opening it in Eclipse, reading the class code, making changes, running the program, and observing the results. |
| Results |
|
The program turned out to be surprisingly simple and useful. |
| It would be nice... |
|
It would be nice to be able to change the font size of the displayed bank statement. Make voice control. |
|
|
| Home | Bank statement viewer | Simple library | Text editor | Editor library | CMS | Programming language interpreter | Game "Aspen Forest" | Seeds keeper | Blog |
|
See my projects at https://github.com/weekend-game (EN) or https://gitflic.ru/user/weekend-game (RU). Please write to me at weekend_game@mail.ru |