From: Niki Roo Date: Fri, 22 Mar 2019 18:18:18 +0000 (+0100) Subject: gui: code cleanup for properties X-Git-Tag: fanfix-2.0.0~10 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=5beb7cdca74ad803e6863af8e73dcd97106eef44;p=fanfix.git gui: code cleanup for properties --- diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java index df8707c..045bb46 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java @@ -84,7 +84,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper { setSize(800, 600); setLayout(new BorderLayout()); - add(mainPanel); + add(mainPanel, BorderLayout.CENTER); } @Override @@ -738,8 +738,9 @@ class GuiReaderFrame extends JFrame implements FrameHelper { mainPanel.outOfUi(null, new Runnable() { @Override public void run() { - new GuiReaderPropertiesFrame(reader, selectedBook - .getInfo()).setVisible(true); + new GuiReaderPropertiesFrame(reader.getLibrary(), + selectedBook.getInfo().getMeta()) + .setVisible(true); } }); } @@ -763,8 +764,8 @@ class GuiReaderFrame extends JFrame implements FrameHelper { if (selectedBook != null) { if (selectedBook.getInfo().getMeta() == null) { mainPanel.removeBookPanes(); - mainPanel.addBookPane(selectedBook.getInfo().getMainInfo(), - mainPanel.getCurrentType()); + mainPanel.addBookPane(selectedBook.getInfo() + .getMainInfo(), mainPanel.getCurrentType()); mainPanel.refreshBooks(); } else { mainPanel.openBook(selectedBook); diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderPropertiesFrame.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderPropertiesFrame.java index 1841771..deddc3c 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderPropertiesFrame.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderPropertiesFrame.java @@ -1,22 +1,12 @@ package be.nikiroo.fanfix.reader.ui; import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Font; -import java.util.Map; -import javax.swing.BorderFactory; -import javax.swing.BoxLayout; -import javax.swing.ImageIcon; import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JTextArea; import be.nikiroo.fanfix.data.MetaData; import be.nikiroo.fanfix.data.Story; -import be.nikiroo.fanfix.reader.BasicReader; -import be.nikiroo.fanfix.reader.Reader; +import be.nikiroo.fanfix.library.BasicLibrary; /** * A frame displaying properties and other information of a {@link Story}. @@ -29,71 +19,20 @@ public class GuiReaderPropertiesFrame extends JFrame { /** * Create a new {@link GuiReaderPropertiesFrame}. * - * @param reader - * the linked reader + * @param ib + * the library to use for the cover image * @param meta * the meta to describe */ - public GuiReaderPropertiesFrame(Reader reader, GuiReaderBookInfo info) { - MetaData meta = info.getMeta(); - - // Borders - int top = 20; - int space = 10; - - // Image - ImageIcon img = GuiReaderCoverImager.generateCoverIcon( - reader.getLibrary(), info); - - // frame + public GuiReaderPropertiesFrame(BasicLibrary lib, MetaData meta) { setTitle(meta.getLuid() + ": " + meta.getTitle()); - setSize(800, img.getIconHeight() + 2 * top); - setLayout(new BorderLayout()); - - // Main panel - JPanel mainPanel = new JPanel(new BorderLayout()); - JPanel mainPanelKeys = new JPanel(); - mainPanelKeys.setLayout(new BoxLayout(mainPanelKeys, BoxLayout.Y_AXIS)); - JPanel mainPanelValues = new JPanel(); - mainPanelValues.setLayout(new BoxLayout(mainPanelValues, - BoxLayout.Y_AXIS)); - - mainPanel.add(mainPanelKeys, BorderLayout.WEST); - mainPanel.add(mainPanelValues, BorderLayout.CENTER); + GuiReaderPropertiesPane desc = new GuiReaderPropertiesPane(lib, meta); + setSize(800, + (int) desc.getPreferredSize().getHeight() + 2 + * desc.getBorderThickness()); - Map desc = BasicReader.getMetaDesc(meta); - - Color trans = new Color(0, 0, 0, 1); - for (String key : desc.keySet()) { - JTextArea jKey = new JTextArea(key); - jKey.setFont(new Font(jKey.getFont().getFontName(), Font.BOLD, jKey - .getFont().getSize())); - jKey.setEditable(false); - jKey.setLineWrap(false); - jKey.setBackground(trans); - mainPanelKeys.add(jKey); - - JTextArea jValue = new JTextArea(desc.get(key)); - jValue.setEditable(false); - jValue.setLineWrap(false); - jValue.setBackground(trans); - mainPanelValues.add(jValue); - } - - // Image - JLabel imgLabel = new JLabel(img); - imgLabel.setVerticalAlignment(JLabel.TOP); - - // Borders - mainPanelKeys.setBorder(BorderFactory.createEmptyBorder(top, space, 0, - 0)); - mainPanelValues.setBorder(BorderFactory.createEmptyBorder(top, space, - 0, 0)); - imgLabel.setBorder(BorderFactory.createEmptyBorder(0, space, 0, 0)); - - // Add all - add(imgLabel, BorderLayout.WEST); - add(mainPanel, BorderLayout.CENTER); + setLayout(new BorderLayout()); + add(desc, BorderLayout.NORTH); } } diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderPropertiesPane.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderPropertiesPane.java new file mode 100644 index 0000000..2c9c7e7 --- /dev/null +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderPropertiesPane.java @@ -0,0 +1,99 @@ +package be.nikiroo.fanfix.reader.ui; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Font; +import java.util.Map; + +import javax.swing.BorderFactory; +import javax.swing.BoxLayout; +import javax.swing.ImageIcon; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextArea; + +import be.nikiroo.fanfix.data.MetaData; +import be.nikiroo.fanfix.data.Story; +import be.nikiroo.fanfix.library.BasicLibrary; +import be.nikiroo.fanfix.reader.BasicReader; + +/** + * A panel displaying properties and other information of a {@link Story}. + * + * @author niki + */ +public class GuiReaderPropertiesPane extends JPanel { + private static final long serialVersionUID = 1L; + private final int space = 10; + + /** + * Create a new {@link GuiReaderPropertiesPane}. + * + * @param lib + * the library to use for the cover image + * @param meta + * the meta to describe + */ + public GuiReaderPropertiesPane(BasicLibrary lib, MetaData meta) { + // Image + ImageIcon img = GuiReaderCoverImager.generateCoverIcon(lib, meta); + + setLayout(new BorderLayout()); + + // Main panel + JPanel mainPanel = new JPanel(new BorderLayout()); + JPanel mainPanelKeys = new JPanel(); + mainPanelKeys.setLayout(new BoxLayout(mainPanelKeys, BoxLayout.Y_AXIS)); + JPanel mainPanelValues = new JPanel(); + mainPanelValues.setLayout(new BoxLayout(mainPanelValues, + BoxLayout.Y_AXIS)); + + mainPanel.add(mainPanelKeys, BorderLayout.WEST); + mainPanel.add(mainPanelValues, BorderLayout.CENTER); + + Map desc = BasicReader.getMetaDesc(meta); + + Color trans = new Color(0, 0, 0, 1); + Color base = mainPanelValues.getBackground(); + for (String key : desc.keySet()) { + JTextArea jKey = new JTextArea(key); + jKey.setFont(new Font(jKey.getFont().getFontName(), Font.BOLD, jKey + .getFont().getSize())); + jKey.setEditable(false); + jKey.setLineWrap(false); + jKey.setBackground(trans); + mainPanelKeys.add(jKey); + + final JTextArea jValue = new JTextArea(desc.get(key)); + jValue.setEditable(false); + jValue.setLineWrap(false); + jValue.setBackground(base); + mainPanelValues.add(jValue); + } + + // Image + JLabel imgLabel = new JLabel(img); + imgLabel.setVerticalAlignment(JLabel.TOP); + + // Borders + mainPanelKeys.setBorder(BorderFactory.createEmptyBorder(space, space, + space, space)); + mainPanelValues.setBorder(BorderFactory.createEmptyBorder(space, space, + space, space)); + imgLabel.setBorder(BorderFactory.createEmptyBorder(0, space, space, 0)); + + // Add all + add(imgLabel, BorderLayout.WEST); + add(mainPanel, BorderLayout.CENTER); + } + + /** + * The invisible border size (multiply by 2 if you need the total width or + * the total height). + * + * @return the invisible border thickness + */ + public int getBorderThickness() { + return space; + } +}