setSize(800, 600);
setLayout(new BorderLayout());
- add(mainPanel);
+ add(mainPanel, BorderLayout.CENTER);
}
@Override
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);
}
});
}
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);
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}.
/**
* 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<String, String> 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);
}
}
--- /dev/null
+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<String, String> 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;
+ }
+}