Bankviewer |
|
Home | Bankviewer | Weekend text editor | Weekend interpreter | Game "Aspen Forest" | CMS | Diary |
|
Class overview |
The main class of the application is the BankViewer class. Everything necessary for work is created in its constructor. First of all, this is the application window - an object of the JFrame class. To implement SDI, I use the BorderLayout() layout manager. In the central part, I place the JEditorPane. It will be used to display the bank statement as a table. In the upper part, I place the toolbar, in the lower part - the status bar. The main application window has a menu attached to it. The context menu is attached to the JEditorPane, and, as already mentioned, the toolbar is displayed. All three of these objects are created by methods of the Act class. Each menu item or toolbar button is an object of the Action class. All the necessary Actions are created by methods of the Act class. That is why this is probably the largest class in this program by the number of lines. But it is also probably the simplest class in this program, because all Actions are created in the same way, and the menu and toolbar are just a listing of the necessary Actions in the right order. However, there are some small nuances that are easy to understand by looking at the class text. The status bar is an object of the StatusBar class. Actually, the status bar is a JPanel in which three JTextFields are located in a row. The class has three methods for issuing a string message to the corresponding JTextField. The far right field is a little special: the message displayed in it will be visible for 5 seconds, and then it disappears. Of course, the status bar can be infinitely complicated and improved, but for this program such a status bar is quite enough. Swing provides the JTable class to display information in the form of a table. But there is another way: JEditorPane, to which the setPage(URL u) method was passed the URL of an HTML file in which the table was formed by the <table> ... </table> tags. I use the second option. So, the main thing in the program is to convert the original text file "key-value" into an HTML file. Then the HTML file is passed to display the same JeditorPane, which is located in the central part of the main application window. Everything else is the implementation of SDI and ensuring the usability of the program. The program opens files to display them in a table. Swing provides a ready-made window for specifying the file to be opened: this is the javax.swing.JFileChooser class. The Filer class is just a shell around it, allowing you to slightly customize the appearance and behavior. Filer requires an object of the LastFiles class to work. LastFiles, using the Proper class (a wrapper for the java.util.Properties class), stores and can read several special strings when the program is launched - these are the paths to the last opened files. It is very convenient to see them in the File menu and quickly specify the desired one instead of using the file open window. Filer, on the other hand, saves the path to a file in the LastFiles class object every time it successfully opens. If the file is not opened successfully, it deletes such a path from the saved list, if there is one, of course. LastFiles provides the put() and remove() methods for these actions. In addition, there is a getList() method, with the help of which Act forms a fragment of the File menu with a list of the last opened files from the list of paths. If the user has specified a file, then Filer will call the only public convert() method of the Convertor class in the open() method. This method converts the original file with data in the form of key-value pairs into an HTML file with the same data presented in the form of a table. Then this HTML file will be passed to JEditorPane, which will parse it and display it without any intervention from the programmer. What Java program does not allow the user to install Look & Fill? This program is no exception. In the "View" menu, the user can select any Look & Fill available in his system. The LaF class helps to work with this. The Finder class was created to implement the search in the displayed file. FinderFrame is a window for specifying the search string, which is a set of javax.swing components. The search algorithm is implemented in the Finder class. When creating FinderFrame, the problem of placing components arose, and the GBL class was created to solve it. GBL is a simplification of the GridBagLayout layout manager, adapted to the needs of the application. It is worth paying attention to the Proper class. This is a class that is a wrapper for the java.util.Properties class. The read() method reads a file with previously recorded data of an object of the java.util.Properties class. The save() method does the opposite: it writes everything that is placed in the object to a file. The class is needed so that the application can save some data between sessions. This saves the location and size of the main window, paths to several recently opened files, an indicator of whether to display the toolbar, the status bar, the last entered search string, and some other data. For ease of use, a pair of methods have been made: setProperty(name, value) and getProperty(name, def), where value can be a string or an integer. It is clear that the first method saves some value named name, and the second reads the value name, and if it was not written, then the value def will be returned. To write and restore the location and size of the application window, a pair of methods saveBounds() and setBounds() are used. The program has tested internationalization (i18n). The Loc class is used for this. All phrases that are intended for display are written in English using underscores instead of spaces. If the messages_ru.properties file contains a translation for such a phrase, it will be used for display. Otherwise, the underscores in the English phrase will be replaced with spaces, and the first letter will be made capital. And the resulting one will be used for display. For the purposes of this program, this is quite sufficient. |
|
Home | Bankviewer | Weekend text editor | Weekend interpreter | Game "Aspen Forest" | CMS | Diary |
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 |