source: AE/installer2/src/net/oni2/aeinstaller/gui/modtable/ModTableModel.java@ 613

Last change on this file since 613 was 608, checked in by alloc, 12 years ago

AEI2:

  • Added BSL handling to installation
  • Updated config-terms for dependencies/incompatibilities
  • Fixed mod counts for types
  • Open Edition folder through menu
  • Open folder of already downloaded mod through context menu
  • (Semi?)Fixed launching Oni on MacOS
  • Settings: Added checkbox for update notification
File size: 4.4 KB
RevLine 
[591]1package net.oni2.aeinstaller.gui.modtable;
2
[604]3import java.io.File;
[600]4import java.util.HashSet;
[591]5import java.util.ResourceBundle;
[600]6import java.util.TreeSet;
[591]7import java.util.Vector;
8
9import javax.swing.table.AbstractTableModel;
10import javax.swing.table.TableColumn;
11
[600]12import net.oni2.aeinstaller.backend.mods.Mod;
13import net.oni2.aeinstaller.backend.mods.ModManager;
[591]14
15/**
16 * @author Christian Illy
17 */
18public class ModTableModel extends AbstractTableModel {
19
20 private static final long serialVersionUID = -8278155705802697354L;
21
22 private ResourceBundle bundle = ResourceBundle.getBundle(getClass()
23 .getName());
24
[600]25 private Vector<Mod> items = new Vector<Mod>();
26 private Vector<Boolean> install = new Vector<Boolean>();
[591]27
[600]28 private HashSet<DownloadSizeListener> listeners = new HashSet<DownloadSizeListener>();
29
[591]30 /**
31 * Create a new model
32 */
33 public ModTableModel() {
34 reloadData();
35 }
36
37 @Override
38 public Object getValueAt(int row, int col) {
[600]39 Mod mod = items.get(row);
[591]40 switch (col) {
41 case -1:
[600]42 return mod;
[591]43 case 0:
[606]44 return install.get(row);
45 case 1:
[600]46 return mod.getName();
[606]47 case 2:
[604]48 return mod.getPackageNumberString();
[591]49 }
50 return null;
51 }
52
53 @Override
54 public String getColumnName(int col) {
55 switch (col) {
56 case 0:
[606]57 return bundle.getString("mod.install");
58 case 1:
[591]59 return bundle.getString("mod.name");
[606]60 case 2:
[591]61 return bundle.getString("mod.package_number");
62 }
63 return null;
64 }
65
66 @Override
67 public int getRowCount() {
68 return items.size();
69 }
70
71 @Override
72 public int getColumnCount() {
[606]73 return 3;
[591]74 }
75
76 @Override
77 public Class<?> getColumnClass(int col) {
78 switch (col) {
79 case 0:
[606]80 return Boolean.class;
[591]81 case 1:
[604]82 return String.class;
[591]83 case 2:
84 return String.class;
85 }
86 return null;
87 }
88
89 /**
90 * Set the constraints on the columns size for the given column
91 *
92 * @param colNum
93 * Column number
94 * @param col
95 * Column object
96 */
97 public void setColumnConstraints(int colNum, TableColumn col) {
98 int w;
99 switch (colNum) {
100 case 0:
[606]101 w = 50;
[591]102 col.setPreferredWidth(w);
103 col.setMinWidth(w);
104 col.setMaxWidth(w);
105 break;
[606]106 case 1:
107 col.setPreferredWidth(150);
108 break;
[591]109 case 2:
[606]110 w = 55;
[591]111 col.setPreferredWidth(w);
112 col.setMinWidth(w);
113 col.setMaxWidth(w);
114 break;
115 }
116 }
117
118 /**
119 * Reload the nodes data after an update to the cache
120 */
121 public void reloadData() {
[600]122 items.clear();
[608]123 items.addAll(ModManager.getInstance().getModsValidAndNotMandatory());
[604]124 revertSelection();
125 }
126
127 /**
128 * Revert the selection to the mods that are currently installed
129 */
130 public void revertSelection() {
[600]131 install.clear();
[593]132 for (int i = 0; i < items.size(); i++) {
[604]133 install.add(i, ModManager.getInstance()
134 .isModInstalled(items.get(i)));
[593]135 }
[604]136 fireTableDataChanged();
[591]137 }
138
139 /**
[604]140 * Reload the selection after a config was loaded
141 *
142 * @param config
143 * Config to load
144 */
145 public void reloadSelection(File config) {
146 Vector<Integer> selected = ModManager.getInstance().loadModSelection(
147 config);
148 install.clear();
149 for (int i = 0; i < items.size(); i++) {
150 install.add(i, selected.contains(items.get(i).getPackageNumber()));
151 }
152 fireTableDataChanged();
153 }
154
155 /**
[591]156 * Get the items vector
157 *
158 * @return Items
159 */
[600]160 public Vector<Mod> getItems() {
[591]161 return items;
162 }
163
[600]164 /**
165 * @return Mods selected for installation
166 */
167 public TreeSet<Mod> getSelectedMods() {
168 TreeSet<Mod> res = new TreeSet<Mod>();
169 for (int i = 0; i < items.size(); i++) {
170 if (install.get(i))
171 res.add(items.get(i));
172 }
173 return res;
174 }
175
[593]176 @Override
177 public boolean isCellEditable(int rowIndex, int columnIndex) {
[606]178 return columnIndex == 0;
[593]179 }
180
181 @Override
182 public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
183 super.setValueAt(aValue, rowIndex, columnIndex);
[606]184 if (columnIndex == 0) {
[593]185 install.set(rowIndex, (Boolean) aValue);
[600]186
187 int size = 0;
188 for (int i = 0; i < items.size(); i++) {
189 if (install.get(i)) {
190 Mod m = items.get(i);
[605]191 if (!m.isLocalAvailable())
[600]192 size += m.getZipSize();
193 }
194 }
195 for (DownloadSizeListener dsl : listeners)
196 dsl.downloadSizeChanged(size);
[593]197 }
198 }
199
[600]200 /**
201 * @param lis
202 * Listener to receive download size changed events
203 */
204 public void addDownloadSizeListener(DownloadSizeListener lis) {
205 listeners.add(lis);
206 }
207
208 /**
209 * @param lis
210 * Listener to no longer receive download size changed events
211 */
212 public void removeDownloadSizeListener(DownloadSizeListener lis) {
213 listeners.remove(lis);
214 }
215
[591]216}
Note: See TracBrowser for help on using the repository browser.