Compare commits
3 Commits
Author | SHA1 | Date |
---|---|---|
Andrew Lalis | d7a15e9c8f | |
Andrew Lalis | 0ad1cef2d0 | |
Andrew Lalis | 67915ffdf1 |
Binary file not shown.
8
pom.xml
8
pom.xml
|
@ -42,14 +42,6 @@
|
|||
</build>
|
||||
|
||||
<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 -->
|
||||
<dependency>
|
||||
<groupId>com.1stleg</groupId>
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package nl.andrewlalis.blockbookbinder.control.export;
|
||||
|
||||
import lombok.Setter;
|
||||
import nl.andrewlalis.blockbookbinder.model.Book;
|
||||
import nl.andrewlalis.blockbookbinder.util.ApplicationProperties;
|
||||
import nl.andrewlalis.blockbookbinder.view.export.ExportStatusPanel;
|
||||
|
@ -26,17 +25,14 @@ import java.util.logging.Logger;
|
|||
* into one's clipboard and pasting the pages.
|
||||
*/
|
||||
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 Book book;
|
||||
private final boolean autoPaste;
|
||||
private final int autoPasteDelay;
|
||||
|
||||
@Setter
|
||||
private volatile boolean running;
|
||||
|
||||
@Setter
|
||||
private volatile boolean nextPageRequested;
|
||||
|
||||
private final ExporterKeyListener exporterKeyListener;
|
||||
|
@ -48,8 +44,8 @@ public class BookExporter implements Runnable {
|
|||
|
||||
// Some sound clips to play as user feedback.
|
||||
private final Clip beepClip;
|
||||
private final Clip beginningExportClip;
|
||||
private final Clip finishClip;
|
||||
// private final Clip beginningExportClip;
|
||||
// private final Clip finishClip;
|
||||
|
||||
public BookExporter(ExportToBookDialog dialog, ExportStatusPanel exportStatusPanel, Book book, boolean autoPaste, int autoPasteDelay) {
|
||||
this.dialog = dialog;
|
||||
|
@ -58,8 +54,8 @@ public class BookExporter implements Runnable {
|
|||
this.autoPaste = autoPaste;
|
||||
this.autoPasteDelay = autoPasteDelay;
|
||||
this.beepClip = this.loadAudioClip(ApplicationProperties.getProp("export_dialog.beep_sound"));
|
||||
this.beginningExportClip = this.loadAudioClip(ApplicationProperties.getProp("export_dialog.beginning_export"));
|
||||
this.finishClip = this.loadAudioClip(ApplicationProperties.getProp("export_dialog.finish_sound"));
|
||||
// this.beginningExportClip = this.loadAudioClip(ApplicationProperties.getProp("export_dialog.beginning_export"));
|
||||
// this.finishClip = this.loadAudioClip(ApplicationProperties.getProp("export_dialog.finish_sound"));
|
||||
this.clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
this.exporterKeyListener = new ExporterKeyListener(this);
|
||||
if (this.autoPaste) { // Only initialize the robot if we'll need it.
|
||||
|
@ -97,7 +93,7 @@ public class BookExporter implements Runnable {
|
|||
this.initStatusPanel();
|
||||
this.updateStatusLabel("Exporting.");
|
||||
this.initNativeListener();
|
||||
this.playAudioClip(this.beginningExportClip);
|
||||
// this.playAudioClip(this.beginningExportClip);
|
||||
}
|
||||
this.exportPageToClipboard(nextPageToExport);
|
||||
if (this.autoPaste) {
|
||||
|
@ -109,7 +105,7 @@ public class BookExporter implements Runnable {
|
|||
this.updateStatusProgressBar(nextPageToExport);
|
||||
// If we've reached the end of the book, stop the exporter.
|
||||
if (nextPageToExport >= this.book.getPageCount()) {
|
||||
this.playAudioClip(this.finishClip);
|
||||
// this.playAudioClip(this.finishClip);
|
||||
this.addStatusMessage("Export finished: " + this.book.getPageCount() + " pages exported.");
|
||||
if (!this.autoPaste) {
|
||||
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
|
||||
* program can paste it into a minecraft book.
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package nl.andrewlalis.blockbookbinder.control.export;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import nl.andrewlalis.blockbookbinder.model.Book;
|
||||
import nl.andrewlalis.blockbookbinder.view.book.BookPreviewPanel;
|
||||
import nl.andrewlalis.blockbookbinder.view.export.ExportToBookDialog;
|
||||
|
@ -10,7 +8,6 @@ import javax.swing.*;
|
|||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class ExportBookToMinecraftAction extends AbstractAction {
|
||||
@Getter
|
||||
private static final ExportBookToMinecraftAction instance = new ExportBookToMinecraftAction();
|
||||
|
||||
public ExportBookToMinecraftAction() {
|
||||
|
@ -18,7 +15,6 @@ public class ExportBookToMinecraftAction extends AbstractAction {
|
|||
this.putValue(SHORT_DESCRIPTION, "Export the current book to Minecraft.");
|
||||
}
|
||||
|
||||
@Setter
|
||||
private BookPreviewPanel bookPreviewPanel;
|
||||
|
||||
@Override
|
||||
|
@ -36,4 +32,12 @@ public class ExportBookToMinecraftAction extends AbstractAction {
|
|||
ExportToBookDialog dialog = new ExportToBookDialog(SwingUtilities.getWindowAncestor(this.bookPreviewPanel), bookPreviewPanel.getBook());
|
||||
dialog.setupAndShow();
|
||||
}
|
||||
|
||||
public void setBookPreviewPanel(BookPreviewPanel bookPreviewPanel) {
|
||||
this.bookPreviewPanel = bookPreviewPanel;
|
||||
}
|
||||
|
||||
public static ExportBookToMinecraftAction getInstance() {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,13 @@
|
|||
package nl.andrewlalis.blockbookbinder.control.source;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import nl.andrewlalis.blockbookbinder.view.SourceTextPanel;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class CleanSourceAction extends AbstractAction {
|
||||
@Getter
|
||||
private final static CleanSourceAction instance = new CleanSourceAction();
|
||||
|
||||
@Setter
|
||||
private SourceTextPanel sourceTextPanel;
|
||||
|
||||
public CleanSourceAction() {
|
||||
|
@ -46,4 +42,12 @@ public class CleanSourceAction extends AbstractAction {
|
|||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static CleanSourceAction getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void setSourceTextPanel(SourceTextPanel sourceTextPanel) {
|
||||
this.sourceTextPanel = sourceTextPanel;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package nl.andrewlalis.blockbookbinder.control.source;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import nl.andrewlalis.blockbookbinder.model.build.BookBuilder;
|
||||
import nl.andrewlalis.blockbookbinder.view.SourceTextPanel;
|
||||
import nl.andrewlalis.blockbookbinder.view.book.BookPreviewPanel;
|
||||
|
@ -10,12 +8,9 @@ import javax.swing.*;
|
|||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class CompileFromSourceAction extends AbstractAction {
|
||||
@Getter
|
||||
private static final CompileFromSourceAction instance = new CompileFromSourceAction();
|
||||
|
||||
@Setter
|
||||
private SourceTextPanel sourceTextPanel;
|
||||
@Setter
|
||||
private BookPreviewPanel bookPreviewPanel;
|
||||
|
||||
public CompileFromSourceAction() {
|
||||
|
@ -29,4 +24,16 @@ public class CompileFromSourceAction extends AbstractAction {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
package nl.andrewlalis.blockbookbinder.control.source;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class ImportSourceAction extends AbstractAction {
|
||||
@Getter
|
||||
private static final ImportSourceAction instance = new ImportSourceAction();
|
||||
|
||||
public ImportSourceAction() {
|
||||
|
@ -18,4 +15,8 @@ public class ImportSourceAction extends AbstractAction {
|
|||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
}
|
||||
|
||||
public static ImportSourceAction getInstance() {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
package nl.andrewlalis.blockbookbinder.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import nl.andrewlalis.blockbookbinder.util.ApplicationProperties;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Book {
|
||||
@Getter
|
||||
private final List<BookPage> pages;
|
||||
|
||||
public Book() {
|
||||
|
@ -18,6 +16,10 @@ public class Book {
|
|||
return this.pages.size();
|
||||
}
|
||||
|
||||
public List<BookPage> getPages() {
|
||||
return pages;
|
||||
}
|
||||
|
||||
public void addPage(BookPage page) {
|
||||
this.pages.add(page);
|
||||
}
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
package nl.andrewlalis.blockbookbinder.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import nl.andrewlalis.blockbookbinder.util.ApplicationProperties;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class CharWidthMapper {
|
||||
@Getter
|
||||
private static final CharWidthMapper instance = new CharWidthMapper();
|
||||
|
||||
public static CharWidthMapper getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private final Map<Character, Integer> charWidthMap;
|
||||
|
||||
public CharWidthMapper() {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package nl.andrewlalis.blockbookbinder.util;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -13,7 +11,6 @@ import java.util.Properties;
|
|||
*/
|
||||
public class ApplicationProperties {
|
||||
private static ApplicationProperties instance;
|
||||
@Getter
|
||||
private final Properties properties;
|
||||
|
||||
private final Map<String, Integer> intPropCache;
|
||||
|
@ -30,6 +27,10 @@ public class ApplicationProperties {
|
|||
return instance;
|
||||
}
|
||||
|
||||
public Properties getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut for getting a property.
|
||||
* @param key The property's key.
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package nl.andrewlalis.blockbookbinder.view.book;
|
||||
|
||||
import lombok.Getter;
|
||||
import nl.andrewlalis.blockbookbinder.model.Book;
|
||||
import nl.andrewlalis.blockbookbinder.model.BookPage;
|
||||
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.
|
||||
*/
|
||||
public class BookPreviewPanel extends JPanel {
|
||||
@Getter
|
||||
private Book book;
|
||||
private int currentPage = 0;
|
||||
|
||||
|
@ -27,6 +25,9 @@ public class BookPreviewPanel extends JPanel {
|
|||
private final JButton firstPageButton;
|
||||
private final JButton lastPageButton;
|
||||
|
||||
private final SpinnerNumberModel currentPageNumberModel;
|
||||
private boolean ignoreCurrentPageChange = false;
|
||||
|
||||
public BookPreviewPanel() {
|
||||
super(new BorderLayout());
|
||||
|
||||
|
@ -51,10 +52,12 @@ public class BookPreviewPanel extends JPanel {
|
|||
this.add(previewPageScrollPane, BorderLayout.CENTER);
|
||||
|
||||
JPanel previewButtonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
|
||||
currentPageNumberModel = new SpinnerNumberModel(0, 0, 0, 1);
|
||||
this.firstPageButton = new JButton();
|
||||
this.firstPageButton.setIcon(IconLoader.load("images/page_first.png", 16, 16));
|
||||
this.firstPageButton.addActionListener(e -> {
|
||||
this.currentPage = 0;
|
||||
updateCurrentPageModel();
|
||||
displayCurrentPage();
|
||||
});
|
||||
|
||||
|
@ -63,6 +66,7 @@ public class BookPreviewPanel extends JPanel {
|
|||
this.previousPageButton.addActionListener(e -> {
|
||||
if (currentPage > 0) {
|
||||
currentPage--;
|
||||
updateCurrentPageModel();
|
||||
displayCurrentPage();
|
||||
}
|
||||
});
|
||||
|
@ -72,6 +76,7 @@ public class BookPreviewPanel extends JPanel {
|
|||
this.nextPageButton.addActionListener(e -> {
|
||||
if (currentPage < book.getPageCount() - 1) {
|
||||
currentPage++;
|
||||
updateCurrentPageModel();
|
||||
displayCurrentPage();
|
||||
}
|
||||
});
|
||||
|
@ -79,11 +84,21 @@ public class BookPreviewPanel extends JPanel {
|
|||
this.lastPageButton.setIcon(IconLoader.load("images/page_last.png", 16, 16));
|
||||
this.lastPageButton.addActionListener(e -> {
|
||||
this.currentPage = Math.max(this.book.getPageCount() - 1, 0);
|
||||
updateCurrentPageModel();
|
||||
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.previousPageButton);
|
||||
previewButtonPanel.add(currentPageSpinner);
|
||||
previewButtonPanel.add(this.nextPageButton);
|
||||
previewButtonPanel.add(this.lastPageButton);
|
||||
this.add(previewButtonPanel, BorderLayout.SOUTH);
|
||||
|
@ -102,10 +117,31 @@ public class BookPreviewPanel extends JPanel {
|
|||
|
||||
public void setBook(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.displayCurrentPage();
|
||||
}
|
||||
|
||||
public Book getBook() {
|
||||
return book;
|
||||
}
|
||||
|
||||
public void updateCurrentPageModel() {
|
||||
ignoreCurrentPageChange = true;
|
||||
currentPageNumberModel.setValue(currentPage + 1);
|
||||
ignoreCurrentPageChange = false;
|
||||
}
|
||||
|
||||
public void setCurrentPage(int page) {
|
||||
this.currentPage = page;
|
||||
this.displayCurrentPage();
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package nl.andrewlalis.blockbookbinder.view.export;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
|
@ -10,11 +8,8 @@ import java.awt.*;
|
|||
* job.
|
||||
*/
|
||||
public class ExportStatusPanel extends JPanel {
|
||||
@Getter
|
||||
private final JLabel statusLabel;
|
||||
@Getter
|
||||
private final JTextArea outputTextArea;
|
||||
@Getter
|
||||
private final JProgressBar exportProgressBar;
|
||||
|
||||
public ExportStatusPanel() {
|
||||
|
@ -35,4 +30,16 @@ public class ExportStatusPanel extends JPanel {
|
|||
this.exportProgressBar = new JProgressBar();
|
||||
this.add(this.exportProgressBar, BorderLayout.SOUTH);
|
||||
}
|
||||
|
||||
public JLabel getStatusLabel() {
|
||||
return statusLabel;
|
||||
}
|
||||
|
||||
public JTextArea getOutputTextArea() {
|
||||
return outputTextArea;
|
||||
}
|
||||
|
||||
public JProgressBar getExportProgressBar() {
|
||||
return exportProgressBar;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,8 +16,8 @@ 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
|
||||
book.page_max_width=113
|
||||
book.page_max_chars=255
|
||||
book.max_pages=50
|
||||
book.page_max_lines=11
|
||||
book.page_max_width=107
|
||||
book.page_max_chars=205
|
||||
book.default_char_width=5
|
||||
|
|
Loading…
Reference in New Issue