From cb6841cdac370d32162b46b1d99ad45a62bb0148 Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Sat, 7 Nov 2020 00:26:27 +0100 Subject: [PATCH] reorganized view into some sub components. --- .../model/{BookContents.java => Book.java} | 8 +++- .../view/BookPreviewPanel.java | 30 ++++++++++++++ .../blockbookbinder/view/MainFrame.java | 39 ++----------------- .../blockbookbinder/view/SourceTextPanel.java | 28 +++++++++++++ 4 files changed, 68 insertions(+), 37 deletions(-) rename src/main/java/nl/andrewlalis/blockbookbinder/model/{BookContents.java => Book.java} (67%) create mode 100644 src/main/java/nl/andrewlalis/blockbookbinder/view/BookPreviewPanel.java create mode 100644 src/main/java/nl/andrewlalis/blockbookbinder/view/SourceTextPanel.java diff --git a/src/main/java/nl/andrewlalis/blockbookbinder/model/BookContents.java b/src/main/java/nl/andrewlalis/blockbookbinder/model/Book.java similarity index 67% rename from src/main/java/nl/andrewlalis/blockbookbinder/model/BookContents.java rename to src/main/java/nl/andrewlalis/blockbookbinder/model/Book.java index 3ef02a6..1c3ed61 100644 --- a/src/main/java/nl/andrewlalis/blockbookbinder/model/BookContents.java +++ b/src/main/java/nl/andrewlalis/blockbookbinder/model/Book.java @@ -5,11 +5,15 @@ import lombok.Getter; import java.util.ArrayList; import java.util.List; -public class BookContents { +public class Book { @Getter private final List pages; - public BookContents() { + public Book() { this.pages = new ArrayList<>(); } + + public int getPageCount() { + return this.pages.size(); + } } diff --git a/src/main/java/nl/andrewlalis/blockbookbinder/view/BookPreviewPanel.java b/src/main/java/nl/andrewlalis/blockbookbinder/view/BookPreviewPanel.java new file mode 100644 index 0000000..665621f --- /dev/null +++ b/src/main/java/nl/andrewlalis/blockbookbinder/view/BookPreviewPanel.java @@ -0,0 +1,30 @@ +package nl.andrewlalis.blockbookbinder.view; + +import nl.andrewlalis.blockbookbinder.model.Book; + +import javax.swing.*; +import javax.swing.border.EmptyBorder; +import java.awt.*; + +/** + * A customized panel that's dedicated to showing a book's contents. + */ +public class BookPreviewPanel extends JPanel { + private Book book; + + public BookPreviewPanel() { + super(new BorderLayout()); + + this.add(new JLabel("Book Preview"), BorderLayout.NORTH); + this.setBorder(new EmptyBorder(5, 5, 5, 5)); + + JTextArea previewPageTextArea = new JTextArea(); + JScrollPane previewPageScrollPane = new JScrollPane(previewPageTextArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + this.add(previewPageScrollPane, BorderLayout.CENTER); + + JPanel previewButtonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); + previewButtonPanel.add(new JButton("<")); + previewButtonPanel.add(new JButton(">")); + this.add(previewButtonPanel, BorderLayout.SOUTH); + } +} diff --git a/src/main/java/nl/andrewlalis/blockbookbinder/view/MainFrame.java b/src/main/java/nl/andrewlalis/blockbookbinder/view/MainFrame.java index 551ca21..16b7060 100644 --- a/src/main/java/nl/andrewlalis/blockbookbinder/view/MainFrame.java +++ b/src/main/java/nl/andrewlalis/blockbookbinder/view/MainFrame.java @@ -4,9 +4,7 @@ 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; /** @@ -58,45 +56,16 @@ public class MainFrame extends JFrame { JPanel mainPanel = new JPanel(new BorderLayout()); JPanel doublePanel = new JPanel(new GridLayout(1, 2)); + doublePanel.add(new BookPreviewPanel()); + doublePanel.add(new SourceTextPanel()); 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); +// 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); diff --git a/src/main/java/nl/andrewlalis/blockbookbinder/view/SourceTextPanel.java b/src/main/java/nl/andrewlalis/blockbookbinder/view/SourceTextPanel.java new file mode 100644 index 0000000..df006ae --- /dev/null +++ b/src/main/java/nl/andrewlalis/blockbookbinder/view/SourceTextPanel.java @@ -0,0 +1,28 @@ +package nl.andrewlalis.blockbookbinder.view; + +import javax.swing.*; +import javax.swing.border.EmptyBorder; +import java.awt.*; + +/** + * A panel dedicated to displaying an interacting with a raw source of text for + * a book. + */ +public class SourceTextPanel extends JPanel { + public SourceTextPanel() { + super(new BorderLayout()); + + this.add(new JLabel("Source Text"), BorderLayout.NORTH); + this.setBorder(new EmptyBorder(5, 5, 5, 5)); + + JTextArea mainTextArea = new JTextArea(); + JScrollPane scrollWrappedMainTextArea = new JScrollPane(mainTextArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + this.add(scrollWrappedMainTextArea, BorderLayout.CENTER); + + JPanel rightPanelButtonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + this.add(rightPanelButtonPanel, BorderLayout.SOUTH); + JButton importButton = new JButton("Import"); + importButton.setActionCommand("importSource"); + rightPanelButtonPanel.add(importButton); + } +}