better UI for PropertiesPanel
authorNiki Roo <niki@nikiroo.be>
Tue, 28 Apr 2020 14:52:13 +0000 (16:52 +0200)
committerNiki Roo <niki@nikiroo.be>
Tue, 28 Apr 2020 14:52:13 +0000 (16:52 +0200)
src/be/nikiroo/fanfix_swing/gui/PropertiesFrame.java
src/be/nikiroo/fanfix_swing/gui/PropertiesPanel.java

index 915c255067a5692f6c833946038cac04f38ab748..b2215d8584ff1302797d2635e6947ec134f200fc 100644 (file)
@@ -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);
        }
 }
index 46da9a9b59ab1d4c52bbe5a68b8396232968c568..8bc1e02cfcd9964924b57358fca6165c94be81e1 100644 (file)
@@ -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<String, String> 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);