diff --git a/src/main/java/nl/andrewlalis/blockbookbinder/view/MainFrame.java b/src/main/java/nl/andrewlalis/blockbookbinder/view/MainFrame.java index 0004f58..9c5bbfb 100644 --- a/src/main/java/nl/andrewlalis/blockbookbinder/view/MainFrame.java +++ b/src/main/java/nl/andrewlalis/blockbookbinder/view/MainFrame.java @@ -3,6 +3,7 @@ package nl.andrewlalis.blockbookbinder.view; import nl.andrewlalis.blockbookbinder.control.ImportAction; import nl.andrewlalis.blockbookbinder.model.Book; import nl.andrewlalis.blockbookbinder.util.ApplicationProperties; +import nl.andrewlalis.blockbookbinder.view.about.AboutDialog; import nl.andrewlalis.blockbookbinder.view.export.ExportToBookDialog; import javax.swing.*; @@ -13,7 +14,6 @@ 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")); @@ -26,7 +26,6 @@ public class MainFrame extends JFrame { this.setIconImage(new ImageIcon(iconUrl).getImage()); } - this.initActions(); this.setContentPane(this.buildContentPane()); this.setJMenuBar(this.buildMenuBar()); @@ -35,19 +34,21 @@ public class MainFrame extends JFrame { 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)); + JMenuItem exitItem = new JMenuItem("Exit"); + exitItem.addActionListener(e -> this.dispose()); + fileMenu.add(exitItem); menuBar.add(fileMenu); JMenu helpMenu = new JMenu("Help"); JMenuItem aboutItem = new JMenuItem("About"); + aboutItem.addActionListener(e -> { + AboutDialog dialog = new AboutDialog(this); + dialog.setupAndShow(); + }); helpMenu.add(aboutItem); menuBar.add(helpMenu); diff --git a/src/main/java/nl/andrewlalis/blockbookbinder/view/SourceTextPanel.java b/src/main/java/nl/andrewlalis/blockbookbinder/view/SourceTextPanel.java index ab84f95..0815a65 100644 --- a/src/main/java/nl/andrewlalis/blockbookbinder/view/SourceTextPanel.java +++ b/src/main/java/nl/andrewlalis/blockbookbinder/view/SourceTextPanel.java @@ -6,10 +6,6 @@ import nl.andrewlalis.blockbookbinder.control.ConvertToBookActionListener; import javax.swing.*; import javax.swing.border.EmptyBorder; import java.awt.*; -import java.io.IOException; -import java.net.URISyntaxException; -import java.nio.file.Files; -import java.nio.file.Path; /** * A panel dedicated to displaying an interacting with a raw source of text for @@ -32,9 +28,6 @@ public class SourceTextPanel extends JPanel { JPanel rightPanelButtonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); this.add(rightPanelButtonPanel, BorderLayout.SOUTH); - JButton importButton = new JButton("Import"); - importButton.setActionCommand("importSource"); - rightPanelButtonPanel.add(importButton); JButton convertButton = new JButton("Convert to Book"); convertButton.addActionListener(new ConvertToBookActionListener(this, bookPreviewPanel)); diff --git a/src/main/java/nl/andrewlalis/blockbookbinder/view/about/AboutDialog.java b/src/main/java/nl/andrewlalis/blockbookbinder/view/about/AboutDialog.java new file mode 100644 index 0000000..f42523e --- /dev/null +++ b/src/main/java/nl/andrewlalis/blockbookbinder/view/about/AboutDialog.java @@ -0,0 +1,64 @@ +package nl.andrewlalis.blockbookbinder.view.about; + +import nl.andrewlalis.blockbookbinder.util.ApplicationProperties; + +import javax.swing.*; +import javax.swing.event.HyperlinkEvent; +import java.awt.*; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.stream.Collectors; + +/** + * Simple dialog whose main purpose is rendering an HTML document. + */ +public class AboutDialog extends JDialog { + public AboutDialog(Frame owner) { + super(owner, "About", true); + } + + public void setupAndShow() { + this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); + this.setPreferredSize(new Dimension( + ApplicationProperties.getIntProp("about_dialog.min_width"), + ApplicationProperties.getIntProp("about_dialog.min_height") + )); + JTextPane textPane = new JTextPane(); + textPane.setEditable(false); + textPane.setContentType("text/html"); + textPane.setText(this.getAboutHtml()); + textPane.addHyperlinkListener(e -> { + try { + if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { + Desktop.getDesktop().browse(e.getURL().toURI()); + } + } catch (URISyntaxException | IOException uriSyntaxException) { + uriSyntaxException.printStackTrace(); + } + }); + JScrollPane scrollPane = new JScrollPane( + textPane, + JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, + JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED + ); + this.setContentPane(scrollPane); + this.pack(); + this.setLocationRelativeTo(this.getOwner()); + this.setVisible(true); + } + + private String getAboutHtml() { + InputStream is = this.getClass().getClassLoader().getResourceAsStream( + ApplicationProperties.getProp("about_dialog.source") + ); + if (is == null) { + return ""; + } + return new BufferedReader(new InputStreamReader(is)).lines() + .parallel().collect(Collectors.joining("\n")); + } +} diff --git a/src/main/java/nl/andrewlalis/blockbookbinder/view/export/ExportToBookDialog.java b/src/main/java/nl/andrewlalis/blockbookbinder/view/export/ExportToBookDialog.java index 998ddd8..a613b31 100644 --- a/src/main/java/nl/andrewlalis/blockbookbinder/view/export/ExportToBookDialog.java +++ b/src/main/java/nl/andrewlalis/blockbookbinder/view/export/ExportToBookDialog.java @@ -44,7 +44,7 @@ public class ExportToBookDialog extends JDialog { ApplicationProperties.getIntProp("export_dialog.min_height") )); this.pack(); - this.setLocationRelativeTo(null); + this.setLocationRelativeTo(this.getOwner()); this.setVisible(true); } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f68ff1b..31ed87a 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -8,6 +8,10 @@ export_dialog.min_height=300 export_dialog.beep_sound=sound/andrew_beep.wav export_dialog.beginning_export=sound/beginning_export.wav +about_dialog.min_width=600 +about_dialog.min_height=800 +about_dialog.source=html/about.html + # Settings for Minecraft book interaction. book.max_pages=100 book.page_max_lines=14 diff --git a/src/main/resources/html/about.html b/src/main/resources/html/about.html new file mode 100644 index 0000000..6b99895 --- /dev/null +++ b/src/main/resources/html/about.html @@ -0,0 +1,48 @@ + + +
+ ++ 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. +
+ ++ 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. +
+ ++ 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: +
+ ++ After setting any options that you want to, go ahead and press Start, and navigate back to your Minecraft window. You should hear ten beep sounds before exporting begins. If you selected auto-paste, you must make sure your mouse is hovering over the next page button in your written book before the ten seconds are up. +
+ ++ Once those first ten seconds pass, the first page will be loaded into your clipboard, and if auto-paste is enabled, automatically pasted into the book in your game. If auto-paste is not enabled, you'll need to manually paste each page, and then turn to the next page. You can see your progress in the popup, along with any important status updates as exporting progresses. +
+ ++ When all pages have been exported, you'll be prompted with a little popup, after which the export popup closes and you have the option to export again, or simply close the application if you're done. +
+ ++ This program was written by Andrew Lalis. The source code is available on GitHub here. It is copyrighted with the MIT license, which means you can do whatever you want with it, so long as you keep the included copyright notice in any copies or modifications of the program. +
+ + + \ No newline at end of file