Added starting application.
This commit is contained in:
parent
c36a5126cb
commit
238c6b44db
|
@ -9,3 +9,7 @@ buildNumber.properties
|
||||||
.mvn/timing.properties
|
.mvn/timing.properties
|
||||||
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
|
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
|
||||||
.mvn/wrapper/maven-wrapper.jar
|
.mvn/wrapper/maven-wrapper.jar
|
||||||
|
|
||||||
|
# IntelliJ Configuration Files
|
||||||
|
.idea/
|
||||||
|
*.iml
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>nl.andrewlalis</groupId>
|
||||||
|
<artifactId>BlockBookBinder</artifactId>
|
||||||
|
<version>0.0.1</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>12</maven.compiler.source>
|
||||||
|
<maven.compiler.target>12</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.14</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,17 @@
|
||||||
|
package nl.andrewlalis.blockbookbinder;
|
||||||
|
|
||||||
|
import nl.andrewlalis.blockbookbinder.view.MainFrame;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The main class for the application.
|
||||||
|
*/
|
||||||
|
public class BlockBookBinder {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
var mainFrame = new MainFrame();
|
||||||
|
mainFrame.setupAndShow();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package nl.andrewlalis.blockbookbinder.control;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
|
||||||
|
public class ImportAction extends AbstractAction {
|
||||||
|
public ImportAction(String name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImportAction(String name, Icon icon) {
|
||||||
|
super(name, icon);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
System.out.println("Import!");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package nl.andrewlalis.blockbookbinder.model;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class BookContents {
|
||||||
|
@Getter
|
||||||
|
private final List<BookPage> pages;
|
||||||
|
|
||||||
|
public BookContents() {
|
||||||
|
this.pages = new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package nl.andrewlalis.blockbookbinder.model;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
public class BookPage {
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
public BookPage() {
|
||||||
|
this.content = "";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
package nl.andrewlalis.blockbookbinder.util;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Singleton class which handles the properties defined in an external
|
||||||
|
* properties file.
|
||||||
|
*/
|
||||||
|
public class ApplicationProperties {
|
||||||
|
private static ApplicationProperties instance;
|
||||||
|
@Getter
|
||||||
|
private final Properties properties;
|
||||||
|
|
||||||
|
public static ApplicationProperties getInstance() {
|
||||||
|
if (instance == null) {
|
||||||
|
try {
|
||||||
|
instance = new ApplicationProperties();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println("Could not load properties!");
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shortcut for getting a property.
|
||||||
|
* @param key The property's key.
|
||||||
|
* @return The value for that property.
|
||||||
|
*/
|
||||||
|
public static String getProp(String key) {
|
||||||
|
return getInstance().getProperties().getProperty(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ApplicationProperties() throws IOException {
|
||||||
|
this.properties = new Properties();
|
||||||
|
this.properties.load(this.getClass().getClassLoader().getResourceAsStream("application.properties"));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,106 @@
|
||||||
|
package nl.andrewlalis.blockbookbinder.view;
|
||||||
|
|
||||||
|
import nl.andrewlalis.blockbookbinder.control.ImportAction;
|
||||||
|
import nl.andrewlalis.blockbookbinder.util.ApplicationProperties;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.border.EmptyBorder;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.datatransfer.StringSelection;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The main window of the application.
|
||||||
|
*/
|
||||||
|
public class MainFrame extends JFrame {
|
||||||
|
private Action importAction;
|
||||||
|
|
||||||
|
public void setupAndShow() {
|
||||||
|
final int width = Integer.parseInt(ApplicationProperties.getProp("frame.default_width"));
|
||||||
|
final int height = Integer.parseInt(ApplicationProperties.getProp("frame.default_height"));
|
||||||
|
this.setPreferredSize(new Dimension(width, height));
|
||||||
|
this.setTitle(ApplicationProperties.getProp("frame.title"));
|
||||||
|
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||||
|
final URL iconUrl = this.getClass().getClassLoader().getResource("images/book_and_quill.png");
|
||||||
|
if (iconUrl != null) {
|
||||||
|
this.setIconImage(new ImageIcon(iconUrl).getImage());
|
||||||
|
}
|
||||||
|
|
||||||
|
this.initActions();
|
||||||
|
this.setContentPane(this.buildContentPane());
|
||||||
|
this.setJMenuBar(this.buildMenuBar());
|
||||||
|
|
||||||
|
this.pack();
|
||||||
|
this.setLocationRelativeTo(null);
|
||||||
|
this.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initActions() {
|
||||||
|
this.importAction = new ImportAction("Import");
|
||||||
|
}
|
||||||
|
|
||||||
|
private JMenuBar buildMenuBar() {
|
||||||
|
JMenuBar menuBar = new JMenuBar();
|
||||||
|
|
||||||
|
JMenu fileMenu = new JMenu("File");
|
||||||
|
fileMenu.add(new JMenuItem(this.importAction));
|
||||||
|
menuBar.add(fileMenu);
|
||||||
|
|
||||||
|
JMenu helpMenu = new JMenu("Help");
|
||||||
|
JMenuItem aboutItem = new JMenuItem("About");
|
||||||
|
helpMenu.add(aboutItem);
|
||||||
|
menuBar.add(helpMenu);
|
||||||
|
|
||||||
|
return menuBar;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Container buildContentPane() {
|
||||||
|
JPanel mainPanel = new JPanel(new BorderLayout());
|
||||||
|
|
||||||
|
JPanel doublePanel = new JPanel(new GridLayout(1, 2));
|
||||||
|
mainPanel.add(doublePanel, BorderLayout.CENTER);
|
||||||
|
final Insets innerPanelInsets = new Insets(5, 5, 5, 5);
|
||||||
|
|
||||||
|
|
||||||
|
JPanel leftPanel = new JPanel(new BorderLayout());
|
||||||
|
doublePanel.add(leftPanel);
|
||||||
|
leftPanel.add(new JLabel("Book Preview"), BorderLayout.NORTH);
|
||||||
|
leftPanel.setBorder(new EmptyBorder(innerPanelInsets));
|
||||||
|
|
||||||
|
JTextArea previewPageTextArea = new JTextArea();
|
||||||
|
JScrollPane previewPageScrollPane = new JScrollPane(previewPageTextArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||||
|
leftPanel.add(previewPageScrollPane, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
JPanel previewButtonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
|
||||||
|
previewButtonPanel.add(new JButton("<"));
|
||||||
|
previewButtonPanel.add(new JButton(">"));
|
||||||
|
leftPanel.add(previewButtonPanel, BorderLayout.SOUTH);
|
||||||
|
|
||||||
|
|
||||||
|
JPanel rightPanel = new JPanel(new BorderLayout());
|
||||||
|
doublePanel.add(rightPanel);
|
||||||
|
rightPanel.add(new JLabel("Source Text"), BorderLayout.NORTH);
|
||||||
|
rightPanel.setBorder(new EmptyBorder(innerPanelInsets));
|
||||||
|
|
||||||
|
JTextArea mainTextArea = new JTextArea();
|
||||||
|
JScrollPane scrollWrappedMainTextArea = new JScrollPane(mainTextArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||||
|
rightPanel.add(scrollWrappedMainTextArea, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
JPanel rightPanelButtonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||||
|
rightPanel.add(rightPanelButtonPanel, BorderLayout.SOUTH);
|
||||||
|
rightPanelButtonPanel.add(new JButton(this.importAction));
|
||||||
|
|
||||||
|
|
||||||
|
JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||||
|
JButton exportButton = new JButton("Export to Book");
|
||||||
|
exportButton.addActionListener(e -> {
|
||||||
|
System.out.println("Starting export.");
|
||||||
|
final String fullText = mainTextArea.getText().trim();
|
||||||
|
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(fullText.substring(0, 200)), null);
|
||||||
|
});
|
||||||
|
bottomPanel.add(exportButton);
|
||||||
|
mainPanel.add(bottomPanel, BorderLayout.SOUTH);
|
||||||
|
|
||||||
|
return mainPanel;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
# Settings for the application's GUI.
|
||||||
|
frame.title=Block Book Binder
|
||||||
|
frame.default_width=800
|
||||||
|
frame.default_height=600
|
||||||
|
|
||||||
|
# Settings for Minecraft book interaction.
|
||||||
|
book.max_pages=100
|
||||||
|
book.page_max_lines=14
|
||||||
|
book.page_max_width=113
|
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 424 B |
Loading…
Reference in New Issue