Compare commits

...

3 Commits
main ... 1.12.2

Author SHA1 Message Date
Andrew Lalis d7a15e9c8f Added latest jar. 2022-08-01 10:29:03 +02:00
Andrew Lalis 0ad1cef2d0 Removed lombok. 2022-08-01 10:27:01 +02:00
Andrew Lalis 67915ffdf1 Added 1.12.2 version with some changes. 2022-08-01 10:00:57 +02:00
13 changed files with 121 additions and 53 deletions

BIN
BlockBookBinder-1.2.0.jar Normal file

Binary file not shown.

View File

@ -42,14 +42,6 @@
</build> </build>
<dependencies> <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>
<!-- https://mvnrepository.com/artifact/com.1stleg/jnativehook --> <!-- https://mvnrepository.com/artifact/com.1stleg/jnativehook -->
<dependency> <dependency>
<groupId>com.1stleg</groupId> <groupId>com.1stleg</groupId>

View File

@ -1,6 +1,5 @@
package nl.andrewlalis.blockbookbinder.control.export; package nl.andrewlalis.blockbookbinder.control.export;
import lombok.Setter;
import nl.andrewlalis.blockbookbinder.model.Book; import nl.andrewlalis.blockbookbinder.model.Book;
import nl.andrewlalis.blockbookbinder.util.ApplicationProperties; import nl.andrewlalis.blockbookbinder.util.ApplicationProperties;
import nl.andrewlalis.blockbookbinder.view.export.ExportStatusPanel; import nl.andrewlalis.blockbookbinder.view.export.ExportStatusPanel;
@ -26,17 +25,14 @@ import java.util.logging.Logger;
* into one's clipboard and pasting the pages. * into one's clipboard and pasting the pages.
*/ */
public class BookExporter implements Runnable { public class BookExporter implements Runnable {
private final static int START_DELAY = 10; private final static int START_DELAY = 5;
private final static int CLIPBOARD_RETRY_DELAY_MS = 100; private final static int CLIPBOARD_RETRY_DELAY_MS = 100;
private final Book book; private final Book book;
private final boolean autoPaste; private final boolean autoPaste;
private final int autoPasteDelay; private final int autoPasteDelay;
@Setter
private volatile boolean running; private volatile boolean running;
@Setter
private volatile boolean nextPageRequested; private volatile boolean nextPageRequested;
private final ExporterKeyListener exporterKeyListener; private final ExporterKeyListener exporterKeyListener;
@ -48,8 +44,8 @@ public class BookExporter implements Runnable {
// Some sound clips to play as user feedback. // Some sound clips to play as user feedback.
private final Clip beepClip; private final Clip beepClip;
private final Clip beginningExportClip; // private final Clip beginningExportClip;
private final Clip finishClip; // private final Clip finishClip;
public BookExporter(ExportToBookDialog dialog, ExportStatusPanel exportStatusPanel, Book book, boolean autoPaste, int autoPasteDelay) { public BookExporter(ExportToBookDialog dialog, ExportStatusPanel exportStatusPanel, Book book, boolean autoPaste, int autoPasteDelay) {
this.dialog = dialog; this.dialog = dialog;
@ -58,8 +54,8 @@ public class BookExporter implements Runnable {
this.autoPaste = autoPaste; this.autoPaste = autoPaste;
this.autoPasteDelay = autoPasteDelay; this.autoPasteDelay = autoPasteDelay;
this.beepClip = this.loadAudioClip(ApplicationProperties.getProp("export_dialog.beep_sound")); this.beepClip = this.loadAudioClip(ApplicationProperties.getProp("export_dialog.beep_sound"));
this.beginningExportClip = this.loadAudioClip(ApplicationProperties.getProp("export_dialog.beginning_export")); // this.beginningExportClip = this.loadAudioClip(ApplicationProperties.getProp("export_dialog.beginning_export"));
this.finishClip = this.loadAudioClip(ApplicationProperties.getProp("export_dialog.finish_sound")); // this.finishClip = this.loadAudioClip(ApplicationProperties.getProp("export_dialog.finish_sound"));
this.clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); this.clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
this.exporterKeyListener = new ExporterKeyListener(this); this.exporterKeyListener = new ExporterKeyListener(this);
if (this.autoPaste) { // Only initialize the robot if we'll need it. if (this.autoPaste) { // Only initialize the robot if we'll need it.
@ -97,7 +93,7 @@ public class BookExporter implements Runnable {
this.initStatusPanel(); this.initStatusPanel();
this.updateStatusLabel("Exporting."); this.updateStatusLabel("Exporting.");
this.initNativeListener(); this.initNativeListener();
this.playAudioClip(this.beginningExportClip); // this.playAudioClip(this.beginningExportClip);
} }
this.exportPageToClipboard(nextPageToExport); this.exportPageToClipboard(nextPageToExport);
if (this.autoPaste) { if (this.autoPaste) {
@ -109,7 +105,7 @@ public class BookExporter implements Runnable {
this.updateStatusProgressBar(nextPageToExport); this.updateStatusProgressBar(nextPageToExport);
// If we've reached the end of the book, stop the exporter. // If we've reached the end of the book, stop the exporter.
if (nextPageToExport >= this.book.getPageCount()) { if (nextPageToExport >= this.book.getPageCount()) {
this.playAudioClip(this.finishClip); // this.playAudioClip(this.finishClip);
this.addStatusMessage("Export finished: " + this.book.getPageCount() + " pages exported."); this.addStatusMessage("Export finished: " + this.book.getPageCount() + " pages exported.");
if (!this.autoPaste) { if (!this.autoPaste) {
this.stopNativeListener(); this.stopNativeListener();
@ -125,6 +121,22 @@ public class BookExporter implements Runnable {
} }
} }
public boolean isRunning() {
return running;
}
public void setRunning(boolean running) {
this.running = running;
}
public boolean isNextPageRequested() {
return nextPageRequested;
}
public void setNextPageRequested(boolean nextPageRequested) {
this.nextPageRequested = nextPageRequested;
}
/** /**
* Loads the given page onto the system clipboard so either a user or this * Loads the given page onto the system clipboard so either a user or this
* program can paste it into a minecraft book. * program can paste it into a minecraft book.

View File

@ -1,7 +1,5 @@
package nl.andrewlalis.blockbookbinder.control.export; package nl.andrewlalis.blockbookbinder.control.export;
import lombok.Getter;
import lombok.Setter;
import nl.andrewlalis.blockbookbinder.model.Book; import nl.andrewlalis.blockbookbinder.model.Book;
import nl.andrewlalis.blockbookbinder.view.book.BookPreviewPanel; import nl.andrewlalis.blockbookbinder.view.book.BookPreviewPanel;
import nl.andrewlalis.blockbookbinder.view.export.ExportToBookDialog; import nl.andrewlalis.blockbookbinder.view.export.ExportToBookDialog;
@ -10,7 +8,6 @@ import javax.swing.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
public class ExportBookToMinecraftAction extends AbstractAction { public class ExportBookToMinecraftAction extends AbstractAction {
@Getter
private static final ExportBookToMinecraftAction instance = new ExportBookToMinecraftAction(); private static final ExportBookToMinecraftAction instance = new ExportBookToMinecraftAction();
public ExportBookToMinecraftAction() { public ExportBookToMinecraftAction() {
@ -18,7 +15,6 @@ public class ExportBookToMinecraftAction extends AbstractAction {
this.putValue(SHORT_DESCRIPTION, "Export the current book to Minecraft."); this.putValue(SHORT_DESCRIPTION, "Export the current book to Minecraft.");
} }
@Setter
private BookPreviewPanel bookPreviewPanel; private BookPreviewPanel bookPreviewPanel;
@Override @Override
@ -36,4 +32,12 @@ public class ExportBookToMinecraftAction extends AbstractAction {
ExportToBookDialog dialog = new ExportToBookDialog(SwingUtilities.getWindowAncestor(this.bookPreviewPanel), bookPreviewPanel.getBook()); ExportToBookDialog dialog = new ExportToBookDialog(SwingUtilities.getWindowAncestor(this.bookPreviewPanel), bookPreviewPanel.getBook());
dialog.setupAndShow(); dialog.setupAndShow();
} }
public void setBookPreviewPanel(BookPreviewPanel bookPreviewPanel) {
this.bookPreviewPanel = bookPreviewPanel;
}
public static ExportBookToMinecraftAction getInstance() {
return instance;
}
} }

View File

@ -1,17 +1,13 @@
package nl.andrewlalis.blockbookbinder.control.source; package nl.andrewlalis.blockbookbinder.control.source;
import lombok.Getter;
import lombok.Setter;
import nl.andrewlalis.blockbookbinder.view.SourceTextPanel; import nl.andrewlalis.blockbookbinder.view.SourceTextPanel;
import javax.swing.*; import javax.swing.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
public class CleanSourceAction extends AbstractAction { public class CleanSourceAction extends AbstractAction {
@Getter
private final static CleanSourceAction instance = new CleanSourceAction(); private final static CleanSourceAction instance = new CleanSourceAction();
@Setter
private SourceTextPanel sourceTextPanel; private SourceTextPanel sourceTextPanel;
public CleanSourceAction() { public CleanSourceAction() {
@ -46,4 +42,12 @@ public class CleanSourceAction extends AbstractAction {
} }
return sb.toString(); return sb.toString();
} }
public static CleanSourceAction getInstance() {
return instance;
}
public void setSourceTextPanel(SourceTextPanel sourceTextPanel) {
this.sourceTextPanel = sourceTextPanel;
}
} }

View File

@ -1,7 +1,5 @@
package nl.andrewlalis.blockbookbinder.control.source; package nl.andrewlalis.blockbookbinder.control.source;
import lombok.Getter;
import lombok.Setter;
import nl.andrewlalis.blockbookbinder.model.build.BookBuilder; import nl.andrewlalis.blockbookbinder.model.build.BookBuilder;
import nl.andrewlalis.blockbookbinder.view.SourceTextPanel; import nl.andrewlalis.blockbookbinder.view.SourceTextPanel;
import nl.andrewlalis.blockbookbinder.view.book.BookPreviewPanel; import nl.andrewlalis.blockbookbinder.view.book.BookPreviewPanel;
@ -10,12 +8,9 @@ import javax.swing.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
public class CompileFromSourceAction extends AbstractAction { public class CompileFromSourceAction extends AbstractAction {
@Getter
private static final CompileFromSourceAction instance = new CompileFromSourceAction(); private static final CompileFromSourceAction instance = new CompileFromSourceAction();
@Setter
private SourceTextPanel sourceTextPanel; private SourceTextPanel sourceTextPanel;
@Setter
private BookPreviewPanel bookPreviewPanel; private BookPreviewPanel bookPreviewPanel;
public CompileFromSourceAction() { public CompileFromSourceAction() {
@ -29,4 +24,16 @@ public class CompileFromSourceAction extends AbstractAction {
new BookBuilder().build(this.sourceTextPanel.getSourceText()) new BookBuilder().build(this.sourceTextPanel.getSourceText())
); );
} }
public static CompileFromSourceAction getInstance() {
return instance;
}
public void setSourceTextPanel(SourceTextPanel sourceTextPanel) {
this.sourceTextPanel = sourceTextPanel;
}
public void setBookPreviewPanel(BookPreviewPanel bookPreviewPanel) {
this.bookPreviewPanel = bookPreviewPanel;
}
} }

View File

@ -1,12 +1,9 @@
package nl.andrewlalis.blockbookbinder.control.source; package nl.andrewlalis.blockbookbinder.control.source;
import lombok.Getter;
import javax.swing.*; import javax.swing.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
public class ImportSourceAction extends AbstractAction { public class ImportSourceAction extends AbstractAction {
@Getter
private static final ImportSourceAction instance = new ImportSourceAction(); private static final ImportSourceAction instance = new ImportSourceAction();
public ImportSourceAction() { public ImportSourceAction() {
@ -18,4 +15,8 @@ public class ImportSourceAction extends AbstractAction {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
} }
public static ImportSourceAction getInstance() {
return instance;
}
} }

View File

@ -1,13 +1,11 @@
package nl.andrewlalis.blockbookbinder.model; package nl.andrewlalis.blockbookbinder.model;
import lombok.Getter;
import nl.andrewlalis.blockbookbinder.util.ApplicationProperties; import nl.andrewlalis.blockbookbinder.util.ApplicationProperties;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class Book { public class Book {
@Getter
private final List<BookPage> pages; private final List<BookPage> pages;
public Book() { public Book() {
@ -18,6 +16,10 @@ public class Book {
return this.pages.size(); return this.pages.size();
} }
public List<BookPage> getPages() {
return pages;
}
public void addPage(BookPage page) { public void addPage(BookPage page) {
this.pages.add(page); this.pages.add(page);
} }

View File

@ -1,15 +1,17 @@
package nl.andrewlalis.blockbookbinder.model; package nl.andrewlalis.blockbookbinder.model;
import lombok.Getter;
import nl.andrewlalis.blockbookbinder.util.ApplicationProperties; import nl.andrewlalis.blockbookbinder.util.ApplicationProperties;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class CharWidthMapper { public class CharWidthMapper {
@Getter
private static final CharWidthMapper instance = new CharWidthMapper(); private static final CharWidthMapper instance = new CharWidthMapper();
public static CharWidthMapper getInstance() {
return instance;
}
private final Map<Character, Integer> charWidthMap; private final Map<Character, Integer> charWidthMap;
public CharWidthMapper() { public CharWidthMapper() {

View File

@ -1,7 +1,5 @@
package nl.andrewlalis.blockbookbinder.util; package nl.andrewlalis.blockbookbinder.util;
import lombok.Getter;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -13,7 +11,6 @@ import java.util.Properties;
*/ */
public class ApplicationProperties { public class ApplicationProperties {
private static ApplicationProperties instance; private static ApplicationProperties instance;
@Getter
private final Properties properties; private final Properties properties;
private final Map<String, Integer> intPropCache; private final Map<String, Integer> intPropCache;
@ -30,6 +27,10 @@ public class ApplicationProperties {
return instance; return instance;
} }
public Properties getProperties() {
return properties;
}
/** /**
* Shortcut for getting a property. * Shortcut for getting a property.
* @param key The property's key. * @param key The property's key.

View File

@ -1,6 +1,5 @@
package nl.andrewlalis.blockbookbinder.view.book; package nl.andrewlalis.blockbookbinder.view.book;
import lombok.Getter;
import nl.andrewlalis.blockbookbinder.model.Book; import nl.andrewlalis.blockbookbinder.model.Book;
import nl.andrewlalis.blockbookbinder.model.BookPage; import nl.andrewlalis.blockbookbinder.model.BookPage;
import nl.andrewlalis.blockbookbinder.util.IconLoader; import nl.andrewlalis.blockbookbinder.util.IconLoader;
@ -15,7 +14,6 @@ import java.io.InputStream;
* A customized panel that's dedicated to showing a book's contents. * A customized panel that's dedicated to showing a book's contents.
*/ */
public class BookPreviewPanel extends JPanel { public class BookPreviewPanel extends JPanel {
@Getter
private Book book; private Book book;
private int currentPage = 0; private int currentPage = 0;
@ -27,6 +25,9 @@ public class BookPreviewPanel extends JPanel {
private final JButton firstPageButton; private final JButton firstPageButton;
private final JButton lastPageButton; private final JButton lastPageButton;
private final SpinnerNumberModel currentPageNumberModel;
private boolean ignoreCurrentPageChange = false;
public BookPreviewPanel() { public BookPreviewPanel() {
super(new BorderLayout()); super(new BorderLayout());
@ -51,10 +52,12 @@ public class BookPreviewPanel extends JPanel {
this.add(previewPageScrollPane, BorderLayout.CENTER); this.add(previewPageScrollPane, BorderLayout.CENTER);
JPanel previewButtonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); JPanel previewButtonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
currentPageNumberModel = new SpinnerNumberModel(0, 0, 0, 1);
this.firstPageButton = new JButton(); this.firstPageButton = new JButton();
this.firstPageButton.setIcon(IconLoader.load("images/page_first.png", 16, 16)); this.firstPageButton.setIcon(IconLoader.load("images/page_first.png", 16, 16));
this.firstPageButton.addActionListener(e -> { this.firstPageButton.addActionListener(e -> {
this.currentPage = 0; this.currentPage = 0;
updateCurrentPageModel();
displayCurrentPage(); displayCurrentPage();
}); });
@ -63,6 +66,7 @@ public class BookPreviewPanel extends JPanel {
this.previousPageButton.addActionListener(e -> { this.previousPageButton.addActionListener(e -> {
if (currentPage > 0) { if (currentPage > 0) {
currentPage--; currentPage--;
updateCurrentPageModel();
displayCurrentPage(); displayCurrentPage();
} }
}); });
@ -72,6 +76,7 @@ public class BookPreviewPanel extends JPanel {
this.nextPageButton.addActionListener(e -> { this.nextPageButton.addActionListener(e -> {
if (currentPage < book.getPageCount() - 1) { if (currentPage < book.getPageCount() - 1) {
currentPage++; currentPage++;
updateCurrentPageModel();
displayCurrentPage(); displayCurrentPage();
} }
}); });
@ -79,11 +84,21 @@ public class BookPreviewPanel extends JPanel {
this.lastPageButton.setIcon(IconLoader.load("images/page_last.png", 16, 16)); this.lastPageButton.setIcon(IconLoader.load("images/page_last.png", 16, 16));
this.lastPageButton.addActionListener(e -> { this.lastPageButton.addActionListener(e -> {
this.currentPage = Math.max(this.book.getPageCount() - 1, 0); this.currentPage = Math.max(this.book.getPageCount() - 1, 0);
updateCurrentPageModel();
displayCurrentPage(); displayCurrentPage();
}); });
JSpinner currentPageSpinner = new JSpinner(currentPageNumberModel);
currentPageSpinner.addChangeListener(e -> {
if (!ignoreCurrentPageChange) {
this.currentPage = (int) currentPageNumberModel.getValue() - 1;
displayCurrentPage();
}
});
previewButtonPanel.add(this.firstPageButton); previewButtonPanel.add(this.firstPageButton);
previewButtonPanel.add(this.previousPageButton); previewButtonPanel.add(this.previousPageButton);
previewButtonPanel.add(currentPageSpinner);
previewButtonPanel.add(this.nextPageButton); previewButtonPanel.add(this.nextPageButton);
previewButtonPanel.add(this.lastPageButton); previewButtonPanel.add(this.lastPageButton);
this.add(previewButtonPanel, BorderLayout.SOUTH); this.add(previewButtonPanel, BorderLayout.SOUTH);
@ -102,10 +117,31 @@ public class BookPreviewPanel extends JPanel {
public void setBook(Book book) { public void setBook(Book book) {
this.book = book; this.book = book;
ignoreCurrentPageChange = true;
if (book.getPageCount() == 0) {
currentPageNumberModel.setMinimum(0);
currentPageNumberModel.setMaximum(0);
currentPageNumberModel.setValue(0);
} else {
currentPageNumberModel.setMinimum(1);
currentPageNumberModel.setMaximum(book.getPageCount());
currentPageNumberModel.setValue(1);
}
ignoreCurrentPageChange = false;
this.currentPage = 0; this.currentPage = 0;
this.displayCurrentPage(); this.displayCurrentPage();
} }
public Book getBook() {
return book;
}
public void updateCurrentPageModel() {
ignoreCurrentPageChange = true;
currentPageNumberModel.setValue(currentPage + 1);
ignoreCurrentPageChange = false;
}
public void setCurrentPage(int page) { public void setCurrentPage(int page) {
this.currentPage = page; this.currentPage = page;
this.displayCurrentPage(); this.displayCurrentPage();

View File

@ -1,7 +1,5 @@
package nl.andrewlalis.blockbookbinder.view.export; package nl.andrewlalis.blockbookbinder.view.export;
import lombok.Getter;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
@ -10,11 +8,8 @@ import java.awt.*;
* job. * job.
*/ */
public class ExportStatusPanel extends JPanel { public class ExportStatusPanel extends JPanel {
@Getter
private final JLabel statusLabel; private final JLabel statusLabel;
@Getter
private final JTextArea outputTextArea; private final JTextArea outputTextArea;
@Getter
private final JProgressBar exportProgressBar; private final JProgressBar exportProgressBar;
public ExportStatusPanel() { public ExportStatusPanel() {
@ -35,4 +30,16 @@ public class ExportStatusPanel extends JPanel {
this.exportProgressBar = new JProgressBar(); this.exportProgressBar = new JProgressBar();
this.add(this.exportProgressBar, BorderLayout.SOUTH); this.add(this.exportProgressBar, BorderLayout.SOUTH);
} }
public JLabel getStatusLabel() {
return statusLabel;
}
public JTextArea getOutputTextArea() {
return outputTextArea;
}
public JProgressBar getExportProgressBar() {
return exportProgressBar;
}
} }

View File

@ -16,8 +16,8 @@ about_dialog.min_height=800
about_dialog.source=html/about.html about_dialog.source=html/about.html
# Settings for Minecraft book interaction. # Settings for Minecraft book interaction.
book.max_pages=100 book.max_pages=50
book.page_max_lines=14 book.page_max_lines=11
book.page_max_width=113 book.page_max_width=107
book.page_max_chars=255 book.page_max_chars=205
book.default_char_width=5 book.default_char_width=5