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.ui; |
17 | |
18 | import java.util.ArrayList; |
19 | import java.util.List; |
20 | import java.util.Locale; |
21 | |
22 | import javax.imageio.spi.ImageReaderSpi; |
23 | import javax.swing.table.AbstractTableModel; |
24 | |
25 | import net.sf.jomic.tools.ImageTools; |
26 | |
27 | /** |
28 | * TableModel to show supported image formats in SystemInfoFrame. |
29 | * |
30 | * @see SystemInfoFrame |
31 | * @author Thomas Aglassinger |
32 | */ |
33 | public class ImageFormatTableModel extends AbstractTableModel |
34 | { |
35 | private static final Class[] CLASSES = |
36 | new Class[]{String.class, String.class, String.class, String.class}; |
37 | private static final int COLUMN_DESCRIPTION = 3; |
38 | private static final int COLUMN_FORMAT = 0; |
39 | private static final int COLUMN_PROVIDER = 1; |
40 | private static final int COLUMN_VERSION = 2; |
41 | |
42 | private List formatList; |
43 | private ImageTools imageTools; |
44 | |
45 | /** |
46 | * Create a new empty ComicInfoModel. |
47 | */ |
48 | public ImageFormatTableModel() { |
49 | imageTools = ImageTools.instance(); |
50 | formatList = new ArrayList(imageTools.getImageProviderMap().keySet()); |
51 | } |
52 | |
53 | public Class getColumnClass(int column) { |
54 | assertColumnIsValid(column); |
55 | return CLASSES[column]; |
56 | } |
57 | |
58 | public int getColumnCount() { |
59 | return CLASSES.length; |
60 | } |
61 | |
62 | public String getColumnName(int column) { |
63 | assertColumnIsValid(column); |
64 | |
65 | String result = null; |
66 | |
67 | if (column == COLUMN_FORMAT) { |
68 | result = "Suffix"; |
69 | } else if (column == COLUMN_PROVIDER) { |
70 | result = "Provider"; |
71 | } else if (column == COLUMN_VERSION) { |
72 | result = "Version"; |
73 | } else if (column == COLUMN_DESCRIPTION) { |
74 | result = "Description"; |
75 | } else { |
76 | assert false : "column=" + column; |
77 | } |
78 | return result; |
79 | } |
80 | |
81 | public int getRowCount() { |
82 | return imageTools.getImageProviderMap().size(); |
83 | } |
84 | |
85 | public Object getValueAt(int row, int column) { |
86 | assertRowIsValid(row); |
87 | assertColumnIsValid(column); |
88 | |
89 | Object result = null; |
90 | String format = (String) formatList.get(row); |
91 | ImageReaderSpi provider = (ImageReaderSpi) imageTools.getImageProviderMap().get(format); |
92 | |
93 | if (column == COLUMN_FORMAT) { |
94 | result = format; |
95 | } else if (column == COLUMN_PROVIDER) { |
96 | result = provider.getVendorName(); |
97 | } else if (column == COLUMN_VERSION) { |
98 | result = provider.getVersion(); |
99 | } else if (column == COLUMN_DESCRIPTION) { |
100 | result = provider.getDescription(Locale.ENGLISH); |
101 | } else { |
102 | assert false : "column=" + column; |
103 | } |
104 | return result; |
105 | } |
106 | |
107 | /** |
108 | * Return <code>false</code> to prevent all cells to be editable. |
109 | */ |
110 | public boolean isCellEditable(int row, int column) { |
111 | assertColumnIsValid(column); |
112 | return false; |
113 | } |
114 | |
115 | private void assertColumnIsValid(int column) { |
116 | assert column < getColumnCount() : "column " + column + " must be less than " + getColumnCount(); |
117 | } |
118 | |
119 | private void assertRowIsValid(int row) { |
120 | assert row < getRowCount() : "row " + row + " must be less than " + getRowCount(); |
121 | } |
122 | } |