Weekend text editor

Java (11), Swing (Single document interface), BankViewer is used as an application template.

So, I created a bank statement viewer. You can create viewers for many other things using a similar approach. But these are just viewers. And if you try to create an editor, you will find that you have to solve many problems. Now I am not creating some unusual editor, I am not creating an editor better than others, I am not trying to compete with anyone. I am researching what problems need to be solved and looking for solutions.

This is a regular text editor that allows you to edit simple text files. It has kept all the features already available in BankViewer. But it not only opens existing files, but also creates new ones, saves edited text, makes sure of that you do not lose lose the result of editing, intelligently and sensibly manages the activity of the "Edit" menu items. It can not only search for text, but also replace one text with another. It allows you to set a convenient font size, use a monospace font if it is convenient in any situation.

Eclipse was used for development. The project is located here: https://github.com/weekend-game/weekendtexteditor/ (EN) and here: https://gitflic.ru/project/weekend-game/weekendtexteditor/ (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 WeekendTextEditor.jar file or, if the program doesn't start, double-click the WeekendTextEditor.bat file. If the program doesn't start, download and install Java 11 or later and repeat the steps above.

How to open a 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 WeekendTextEditor.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.

How to use the program

This text editor is based on the bank statement viewer and inherits its entire user interface ( see here ). Of course, the opened file is now displayed as a text file, not as a table. New features have been added.

The "File" menu now includes the following options: "Create," "Save," and "Save As." They work the same way as in all programs.

The "Edit" menu now includes the "Undo" and "Redo" options. The "Cut" and "Copy" text editing options are active if a text fragment is selected, while the "Paste" option is active only if a copy has been made.

A "Replace" option has been added. When selected, a dialog box appears where you can specify a search string, a replacement string, whether to select case, and specify the search direction. The "Find Next" button works the same as in the search window. The "Replace" button replaces the found string with the replacement string. The "Replace All" button will replace all instances of the search string with the replacement string.

The "View" menu now includes the following options: "Use monospaced font," "Enlarge font," "Decrease font," and "Default font size."

How the program is written

The main class of the application is the WeekendTextEditor class. It contains the static main() method for launching the program. Its constructor creates everything necessary for operation.

Since this text editor is based on a bank statement viewer, it uses the same objects for its operation. You can learn more about them here. But there are also some new features.

The same JEditorPane is used for editing text, but it is now separated into a separate Editor class, which implements many functions. This class contains methods for changing the font and its size, methods for supporting the "Undo" and "Redo" menu items, methods for selecting, copying, and pasting text, and some other functions.

The Replacer and ReplacerFrame classes are similar to Finder and FinderFrame, but are designed to perform not only searching but also replacing text.

You can learn more about the program's operation by downloading the project, opening it in Eclipse, reading the class code, making changes, running the program, and watching the results.

Results

Excellent practice! The editor can be improved endlessly. But you need to know when to stop.