1 | // Jomic - a viewer for comic book archives. |
2 | // Copyright (C) 2004-2011 Thomas Aglassinger |
3 | // |
4 | // This program is free software: you can redistribute it and/or modify |
5 | // it under the terms of the GNU General Public License as published by |
6 | // the Free Software Foundation, either version 3 of the License, or |
7 | // (at your option) any later version. |
8 | // |
9 | // This program is distributed in the hope that it will be useful, |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | // GNU General Public License for more details. |
13 | // |
14 | // You should have received a copy of the GNU General Public License |
15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | package net.sf.jomic.comic; |
17 | |
18 | import java.awt.BorderLayout; |
19 | import java.awt.Dimension; |
20 | |
21 | import javax.swing.JPanel; |
22 | import javax.swing.JScrollPane; |
23 | import javax.swing.JTable; |
24 | import javax.swing.ListSelectionModel; |
25 | import javax.swing.table.TableColumn; |
26 | |
27 | import net.sf.jomic.common.Settings; |
28 | import net.sf.jomic.tools.UiTools; |
29 | |
30 | /** |
31 | * Panel to show information about a comic. |
32 | * |
33 | * @author Thomas Aglassinger |
34 | */ |
35 | public class ComicInfoPanel extends JPanel |
36 | { |
37 | private Settings settings; |
38 | private JTable table; |
39 | private ComicInfoTableModel tableModel; |
40 | |
41 | |
42 | /** |
43 | * Create new empty ComicInfoPanel. |
44 | */ |
45 | public ComicInfoPanel() { |
46 | // TODO: Change fixed size to somthing dynamic. |
47 | Dimension preferredSize = new Dimension(600, 80); |
48 | |
49 | tableModel = new ComicInfoTableModel(); |
50 | table = new JTable(tableModel); |
51 | table.setPreferredScrollableViewportSize(preferredSize); |
52 | |
53 | TableColumn errorColumn = table.getColumnModel().getColumn(ComicInfoTableModel.COLUMN_ERROR); |
54 | |
55 | errorColumn.setCellRenderer(new ComicImageErrorRenderer()); |
56 | setLayout(new BorderLayout()); |
57 | add(new JScrollPane(table), BorderLayout.CENTER); |
58 | settings = Settings.instance(); |
59 | } |
60 | |
61 | public void setComicModel(ComicModel newComicModel) { |
62 | table.setModel(new ComicInfoTableModel(newComicModel)); |
63 | table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
64 | UiTools.instance().initColumnWidths(table); |
65 | } |
66 | |
67 | /** |
68 | * Depending on <code>Settings.getShowToolbar()</code>, either get the preferred size of the |
69 | * super class, or a (0, 0). |
70 | */ |
71 | public Dimension getPreferredSize() { |
72 | Dimension result; |
73 | |
74 | if (settings.getShowInfo()) { |
75 | result = super.getPreferredSize(); |
76 | } else { |
77 | result = new Dimension(0, 0); |
78 | } |
79 | return result; |
80 | } |
81 | |
82 | /** |
83 | * Get the table that lists the images. |
84 | * |
85 | * @see ComicInfoTableModel |
86 | */ |
87 | public JTable getTable() { |
88 | return table; |
89 | } |
90 | |
91 | public void dispose() { |
92 | // Do nothing for now. |
93 | } |
94 | } |