diff --git a/README.md b/README.md index 06d8d49..289aa9e 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,11 @@ This application was developed in order to make the production of written books ## Using Block Book Binder -To get started, look for the [**Releases**](https://github.com/andrewlalis/BlockBookBinder/releases) section on this page, and find the latest release. Download the executable JAR file and you're ready to go. Simply paste some plain text into the _Source_ panel on the right-hand side, and press the button _Convert to Book_ to process that text into a series of pages which will appear on the left-hand side. +To get started, look for the [**Releases**](https://github.com/andrewlalis/BlockBookBinder/releases) section on this page, and find the latest release. Download the executable JAR file, and make sure you have Java version 17 or higher installed to run it. -Once you're happy with how the pages are formatted, you can click the _Export_ button to begin exporting pages to your clipboard. Once you give an affirmative response to the confirmation popup that appears, the first page will be loaded into your clipboard. You can then use `CTRL + V` to paste the page into your book. Each time you do, the program will take about a second to load the next page into your clipboard, so that you can paste it without even having to leave your game. +Start the program, and you'll be greeted with a window that has **Book Preview** and **Source Text** panels. Enter the text you'd like to work with into the **Source Text** panel. In the top menu under **Book**, you'll find a **Clean Source** button, which will remove extra whitespace from the text to make it more friendly for Minecraft's cramped style. You'll also find **Compile from Source**, which will compile your source text into a book in the **Book Preview** panel. + +Once you're happy with how the pages are formatted, you can click the **Export to Minecraft** button to begin exporting pages to your clipboard. ## Demo Video on YouTube https://youtu.be/Mu7Hv1na7Sw diff --git a/pom.xml b/pom.xml index d195e81..1f9694e 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ nl.andrewlalis BlockBookBinder - 1.3.0-SNAPSHOT + 1.3.0 17 diff --git a/src/main/java/nl/andrewlalis/blockbookbinder/control/source/ImportSourceAction.java b/src/main/java/nl/andrewlalis/blockbookbinder/control/source/ImportSourceAction.java index 4ec167c..0b7c607 100644 --- a/src/main/java/nl/andrewlalis/blockbookbinder/control/source/ImportSourceAction.java +++ b/src/main/java/nl/andrewlalis/blockbookbinder/control/source/ImportSourceAction.java @@ -1,14 +1,27 @@ package nl.andrewlalis.blockbookbinder.control.source; import lombok.Getter; +import lombok.Setter; +import nl.andrewlalis.blockbookbinder.BlockBookBinder; +import nl.andrewlalis.blockbookbinder.view.SourceTextPanel; import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import java.awt.*; import java.awt.event.ActionEvent; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.prefs.Preferences; public class ImportSourceAction extends AbstractAction { @Getter private static final ImportSourceAction instance = new ImportSourceAction(); + @Setter + private SourceTextPanel sourceTextPanel; + public ImportSourceAction() { super("Import Source"); this.putValue(SHORT_DESCRIPTION, "Import source text from a file."); @@ -16,6 +29,24 @@ public class ImportSourceAction extends AbstractAction { @Override public void actionPerformed(ActionEvent e) { - + Preferences prefs = Preferences.userNodeForPackage(BlockBookBinder.class); + String dir = prefs.get("source-import-dir", "."); + JFileChooser fileChooser = new JFileChooser(dir); + fileChooser.setFileFilter(new FileNameExtensionFilter("Text files", ".txt")); + fileChooser.setAcceptAllFileFilterUsed(true); + fileChooser.setMultiSelectionEnabled(false); + final Component parent = SwingUtilities.getWindowAncestor((Component) e.getSource()); + int result = fileChooser.showOpenDialog(parent); + if (result == JFileChooser.APPROVE_OPTION) { + File file = fileChooser.getSelectedFile(); + try { + Path filePath = file.toPath(); + sourceTextPanel.setSourceText(Files.readString(filePath)); + prefs.put("source-import-dir", filePath.getParent().toAbsolutePath().toString()); + } catch (IOException exc) { + exc.printStackTrace(); + JOptionPane.showMessageDialog(parent, "Failed to read file:\n" + exc.getMessage(), "Read Failed", JOptionPane.ERROR_MESSAGE); + } + } } } diff --git a/src/main/java/nl/andrewlalis/blockbookbinder/view/MainFrame.java b/src/main/java/nl/andrewlalis/blockbookbinder/view/MainFrame.java index 3f9ba56..e54682e 100644 --- a/src/main/java/nl/andrewlalis/blockbookbinder/view/MainFrame.java +++ b/src/main/java/nl/andrewlalis/blockbookbinder/view/MainFrame.java @@ -44,14 +44,13 @@ public class MainFrame extends JFrame { BookPreviewPanel bookPreviewPanel = new BookPreviewPanel(); doublePanel.add(bookPreviewPanel); CompileFromSourceAction.getInstance().setBookPreviewPanel(bookPreviewPanel); - CompileFromSourceAction.getInstance().setBookPreviewPanel(bookPreviewPanel); ExportBookToMinecraftAction.getInstance().setBookPreviewPanel(bookPreviewPanel); SourceTextPanel sourceTextPanel = new SourceTextPanel(); doublePanel.add(sourceTextPanel); CompileFromSourceAction.getInstance().setSourceTextPanel(sourceTextPanel); - CompileFromSourceAction.getInstance().setSourceTextPanel(sourceTextPanel); CleanSourceAction.getInstance().setSourceTextPanel(sourceTextPanel); + ImportSourceAction.getInstance().setSourceTextPanel(sourceTextPanel); mainPanel.add(doublePanel, BorderLayout.CENTER); @@ -70,7 +69,6 @@ public class MainFrame extends JFrame { JMenu bookMenu = new JMenu("Book"); bookMenu.add(CompileFromSourceAction.getInstance()); - bookMenu.add(CompileFromSourceAction.getInstance()); bookMenu.add(CleanSourceAction.getInstance()); bookMenu.add(ExportBookToMinecraftAction.getInstance()); menuBar.add(bookMenu); diff --git a/src/main/resources/html/about.html b/src/main/resources/html/about.html index 6b99895..e0ec3be 100644 --- a/src/main/resources/html/about.html +++ b/src/main/resources/html/about.html @@ -9,15 +9,15 @@

About BlockBookBinder

- The BlockBookBinder is a simple application that gives you the power to write books faster than ever before! All you need to do is copy and paste some text into the Source panel on the right-hand side of the application, and click Convert to Book. Your text will be transformed so that it can fit onto written books in Minecraft, and you can preview the book in the Book Preview panel on the left-hand side of the application, using the navigation buttons below. + The BlockBookBinder is a simple application that gives you the power to write books faster than ever before! All you need to do is copy and paste some text into the Source panel on the right-hand side of the application, and click Compile from Source. Your text will be transformed so that it can fit onto written books in Minecraft, and you can preview the book in the Book Preview panel on the left-hand side of the application, using the navigation buttons below.

- Note that your text might benefit from the Clean functionality, where extra new-line and other unnecessary whitespace characters are removed so that the text can be better compressed into Minecraft's limited format. + Note that your text might benefit from the Clean Source functionality, where extra new-line and other unnecessary whitespace characters are removed so that the text can be better compressed into Minecraft's limited format.

- Once you've prepared a book and you want to actually copy it into Minecraft, click on Export to Book. This will open up a popup with a few different buttons: + Once you've prepared a book and you want to actually copy it into Minecraft, click on Export to Minecraft. This will open up a popup with a few different buttons: