| CMS |
|
|
| Home | Bank statement viewer | Simple library | Text editor | Editor library | CMS | Blog |
|
|
|
Java (11), Swing, SimpleLibrary New project ideas emerge, and every project needs to have its own page on the website. However, adding just one new project requires making changes to all the website's pages. Then, you have to spend a long time checking what you've created. Sure, it's possible, but why? I created my own CMS (content management system) to manage my website. Problem solved! Of course, I could use a ready-made one, but which one? And how long will it take me to master it? Would I be able to create the website exactly as I envisioned, or just something like it? I think Java is the best CMS in the world :-) But this CMS also allowed me to practice working with Java files and creating a Swing user interface, specifically working with text fields, radio buttons, comboboxes, list editing, and bilingual support. Eclipse was used for development. The project is located here: https://github.com/weekend-game/cms/ (EN) and here: https://gitflic.ru/project/weekend-game/cms/ (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 CMS.jar file or, if the program doesn't start, double-click the CMS.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 WeekendCMS.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 |
|
The program helps you create HTML website pages in a specific style - the style of my website. If you need something different, you'll need to modify the program. To better understand the explanations below, launch the program and open the website you created with it. We see that the website consists of two types of pages: the home page and project pages like this one. All project pages are essentially the same. |
| Homepage (index.htm) |
|
The project name is displayed in large font in the center. In this case, it's my profile name - Weekend Game. If you run the program, you'll see that the window that appears contains several fields. The "Project Name" field controls what's displayed in the center of the home page. At the top of the page is a link to the website for projects and a prompt to send emails to my address. It's written in English. The bottom section contains similar information, but in Russian. The CMS uses the "Website for projects in English", "Website for projects in Russian" and "Email" fields to specify all of these attributes. We can see that above and below the profile name are menu bars with links to the pages of each project (repository). The top section contains links to the English pages, and the bottom section contains links to the Russian pages. |
| Project (repository) pages |
|
The project (repository) page list is defined in the CMS under the "List of pages" section. These are the project pages. Each page has a "Language" setting (EN or RU). This setting determines whether the page link will be located at the top or bottom of the homepage. Links will be generated in the order they appear in the page list. You can change the order using the "Shift up" and "Shift down" buttons located to the right of the list. The "Name" field defines the page title in natural language, and the "File name" field defines the page file name. When generating pages, not only the homepage is generated but also pages for each row in the page list. Each project page will contain a title in large font, taken from the "Name" field. There will also be a menu with links to all pages in English or Russian, depending on the page attribute. The page will have two menu bars: one at the top and one at the bottom. At the very bottom, you will see suggestions for visiting project sites and email addresses. The page content will be taken from a file with the same name, extracted from the folder specified in the "Folder where text files are located" field. For example, to generate the page cms.htm, you must not only specify it in the page list but also place the CMS description in a file with the same name (cms.htm) and place it in the folder specified in the "Folder where text files are located" field. If such a file is not found, the page cms.htm will still be created, but with only a header and footer. |
| Website generation |
|
To generate website pages, click the "Generate pages" button. All generated HTML files will be saved in the folder specified in the "Folder for generated pages" field. My CMS does not generate a stylesheet. You should create one manually and place it in a convenient location. You should also take care of the placement of image files yourself. Important! Do not manually edit the generated HTML files located in the pages folder, as they will be overwritten the next time they are generated. |
| How the program is written |
|
The CMS class is the main class of the application. It contains a static main() method for launching the program. Its constructor creates everything necessary for operation. First, the Proper.read() method is called. Proper is a class that allows the application to save data between sessions. It saves the location and size of the main window, the preferred interface language, all information from input fields, and page list data. The read() method reads a file with previously saved data. The save() method does the opposite: it writes everything stored in the object to the file. The setProperty(name, value) method saves the value named "name." The getProperty(name, def) method reads the value named "name." If it hasn't been written, the value "def" is returned. The saveBounds() and setBounds() methods are used to save and restore the location and size of the application window. The interface language is then set using the static Loc.setLanguage() method. The Loc class is responsible for internationalization (I18n). After the language is set, the Loc.get() method will return strings in the specified language, provided, of course, that the messages_xx.properties localization file exists, where xx is the language character. A SiteDescriptor class object is created - an object for storing all generated site information. The siteDescriptor.readData() method is immediately called on the created object. This is where the information is read. The application window is created - an object of the JFrame class. The makeJFrame() method is immediately called, in which the user interface components are placed within the application window. The GBL class is used to place them. GBL is a simplified version of the GridBagLayout layout manager, adapted to the needs of the application. There are not many user interface components, but their creation and configuration require a significant amount of text. To simplify matters, everything related to editing the list of pages is separated into a separate class: ListEditor. The ListEditor object creates a page list editor panel, which can be retrieved using the getPanel() method and placed anywhere. Naturally, I'm placing it on the only screen of my application. Next, I initialize the Mes class, which is designed to display various messages using dialog boxes. Mes's methods are static, which creates a certain coupling between the classes in my program. However, I treat it like System.out in Java. Then I call the readFromSiteDescriptor() method, which populates the UI components with the data previously read from SiteDescriptor(). The main work is done in the "Generate Pages" button listener. The DoIt() method of the Generator class is called. This method generates site pages based on the available data. 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 |
|
Creating even this small CMS has significantly simplified my website management. |
| It would be nice... |
|
The blog is growing rapidly. I need to archive old posts. I need to create a filter in the blog that will allow me to filter posts by specific projects. |
|
|
| Home | Bank statement viewer | Simple library | Text editor | Editor library | CMS | 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 |