From 969cda11f373907c85a0f07711a5dfc1b71198cb Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Tue, 28 Apr 2020 16:52:13 +0200 Subject: [PATCH] better UI for PropertiesPanel --- .../fanfix_swing/gui/PropertiesFrame.java | 29 ++++++++++++++----- .../fanfix_swing/gui/PropertiesPanel.java | 19 +++++++----- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/be/nikiroo/fanfix_swing/gui/PropertiesFrame.java b/src/be/nikiroo/fanfix_swing/gui/PropertiesFrame.java index 915c2550..b2215d85 100644 --- a/src/be/nikiroo/fanfix_swing/gui/PropertiesFrame.java +++ b/src/be/nikiroo/fanfix_swing/gui/PropertiesFrame.java @@ -1,10 +1,13 @@ package be.nikiroo.fanfix_swing.gui; import java.awt.BorderLayout; +import java.awt.Point; +import javax.swing.JDialog; import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; -import be.nikiroo.fanfix.Instance; import be.nikiroo.fanfix.bundles.StringIdGui; import be.nikiroo.fanfix.data.MetaData; import be.nikiroo.fanfix.data.Story; @@ -15,8 +18,9 @@ import be.nikiroo.fanfix.library.BasicLibrary; * * @author niki */ -public class PropertiesFrame extends JFrame { +public class PropertiesFrame extends JDialog { private static final long serialVersionUID = 1L; + private JPanel desc; /** * Create a new {@link PropertiesFrame}. @@ -27,14 +31,23 @@ public class PropertiesFrame extends JFrame { * the meta to describe */ public PropertiesFrame(BasicLibrary lib, MetaData meta) { - setTitle(Instance.getInstance().getTransGui().getString( - StringIdGui.TITLE_STORY, meta.getLuid(), meta.getTitle())); - - PropertiesPanel desc = new PropertiesPanel(lib, meta); - setSize(800, (int) desc.getPreferredSize().getHeight() - + 2 * desc.getBorderThickness()); + setTitle(MainFrame.trans(StringIdGui.TITLE_STORY, meta.getLuid(), + meta.getTitle())); + desc = new PropertiesPanel(lib, meta); setLayout(new BorderLayout()); add(desc, BorderLayout.NORTH); + + this.setSize(800, desc.getHeight() + 0); + } + + @Override + public void setVisible(boolean b) { + super.setVisible(b); + + int titleBarHeight = Math + .abs(getContentPane().getHeight() - getHeight()); + + this.setSize(800, desc.getHeight() + titleBarHeight); } } diff --git a/src/be/nikiroo/fanfix_swing/gui/PropertiesPanel.java b/src/be/nikiroo/fanfix_swing/gui/PropertiesPanel.java index 46da9a9b..8bc1e02c 100644 --- a/src/be/nikiroo/fanfix_swing/gui/PropertiesPanel.java +++ b/src/be/nikiroo/fanfix_swing/gui/PropertiesPanel.java @@ -18,6 +18,7 @@ import be.nikiroo.fanfix.library.BasicLibrary; import be.nikiroo.fanfix.reader.BasicReader; import be.nikiroo.fanfix_swing.gui.book.BookInfo; import be.nikiroo.fanfix_swing.gui.utils.CoverImager; +import be.nikiroo.utils.ui.UIUtils; /** * A panel displaying properties and other information of a {@link Story}. @@ -26,7 +27,9 @@ import be.nikiroo.fanfix_swing.gui.utils.CoverImager; */ public class PropertiesPanel extends JPanel { private static final long serialVersionUID = 1L; - private final int space = 10; + private final int space = 10; // empty space for visual correctness + private final int hscroll = 10; // we reserve space at the bottom for a + // potential HScroll /** * Create a new {@link PropertiesPanel}. @@ -52,7 +55,8 @@ public class PropertiesPanel extends JPanel { .setLayout(new BoxLayout(mainPanelValues, BoxLayout.Y_AXIS)); mainPanel.add(mainPanelKeys, BorderLayout.WEST); - mainPanel.add(mainPanelValues, BorderLayout.CENTER); + mainPanel.add(UIUtils.scroll(mainPanelValues, true, false), + BorderLayout.CENTER); Map desc = BasicReader.getMetaDesc(meta); @@ -79,11 +83,12 @@ public class PropertiesPanel extends JPanel { 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)); + mainPanelKeys.setBorder(BorderFactory.createEmptyBorder(space, space, + space + hscroll, space)); + mainPanelValues.setBorder(BorderFactory.createEmptyBorder(space, space, + space + hscroll, space)); + imgLabel.setBorder( + BorderFactory.createEmptyBorder(0, space, space + hscroll, 0)); // Add all add(imgLabel, BorderLayout.WEST); -- 2.27.0