ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/java/installer2/src/net/oni2/aeinstaller/gui/MainWin.java
(Generate patch)

Comparing AE/installer2/src/net/oni2/aeinstaller/gui/MainWin.java (file contents):
Revision 596 by alloc, Wed Jan 2 17:00:16 2013 UTC vs.
Revision 600 by alloc, Wed Jan 9 23:12:01 2013 UTC

# Line 1 | Line 1
1   package net.oni2.aeinstaller.gui;
2  
3 import java.awt.Frame;
3   import java.util.ArrayList;
5 import java.util.Comparator;
4   import java.util.List;
5   import java.util.ResourceBundle;
6   import java.util.TreeMap;
7 + import java.util.TreeSet;
8  
9 + import javax.swing.JButton;
10   import javax.swing.JComboBox;
11   import javax.swing.JComponent;
12   import javax.swing.JFrame;
# Line 25 | Line 25 | import javax.swing.table.TableRowSorter;
25  
26   import net.oni2.aeinstaller.backend.Settings;
27   import net.oni2.aeinstaller.backend.Settings.Platform;
28 + import net.oni2.aeinstaller.backend.SizeFormatter;
29   import net.oni2.aeinstaller.backend.depot.DepotCacheUpdateProgressListener;
29 import net.oni2.aeinstaller.backend.depot.DepotConfig;
30   import net.oni2.aeinstaller.backend.depot.DepotManager;
31 < import net.oni2.aeinstaller.backend.depot.model.NodeMod;
32 < import net.oni2.aeinstaller.backend.depot.model.TaxonomyTerm;
33 < import net.oni2.aeinstaller.backend.depot.model.TaxonomyVocabulary;
31 > import net.oni2.aeinstaller.backend.mods.Mod;
32 > import net.oni2.aeinstaller.backend.mods.ModManager;
33 > import net.oni2.aeinstaller.backend.mods.Type;
34 > import net.oni2.aeinstaller.backend.oni.InstallProgressListener;
35 > import net.oni2.aeinstaller.backend.oni.Installer;
36   import net.oni2.aeinstaller.gui.about.AboutDialog;
37 + import net.oni2.aeinstaller.gui.modtable.DownloadSizeListener;
38   import net.oni2.aeinstaller.gui.modtable.ModTableFilter;
39   import net.oni2.aeinstaller.gui.modtable.ModTableModel;
40   import net.oni2.aeinstaller.gui.settings.SettingsDialog;
# Line 46 | Line 49 | import org.simplericity.macify.eawt.Appl
49   /**
50   * @author Christian Illy
51   */
52 < public class MainWin extends JFrame implements ApplicationListener {
52 > public class MainWin extends JFrame implements ApplicationListener,
53 >                DownloadSizeListener {
54          private static final long serialVersionUID = -4027395051382659650L;
55  
56          private ResourceBundle bundle = ResourceBundle.getBundle(getClass()
# Line 62 | Line 66 | public class MainWin extends JFrame impl
66          private JTable tblMods;
67          private ModTableModel model;
68          private TableRowSorter<ModTableModel> sorter;
69 +        private JLabel lblDownloadSizeVal;
70  
71          private JLabel lblSubmitterVal;
72          private JLabel lblCreatorVal;
73          private JLabel lblFilesVal;
69        private JLabel lblIdVal;
74          private HTMLLinkLabel lblDescriptionVal;
75  
76 +        private JButton btnInstall;
77 +
78          /**
79           * Constructor of main window.
80           */
# Line 78 | Line 84 | public class MainWin extends JFrame impl
84                                  + SwingJavaBuilder.getConfig().getResource("appversion"));
85  
86                  contents.setDividerLocation(400);
81                initTable();
82                initModTypeBox();
87  
88                  if (Settings.getPlatform() == Platform.MACOS) {
89                          mainMenu.setVisible(false);
90                  }
91 +
92 +                getRootPane().setDefaultButton(btnInstall);
93          }
94  
95          private void initModTypeBox() {
96                  cmbModTypes.removeAllItems();
97  
98 <                TaxonomyVocabulary tv = DepotManager.getInstance().getVocabulary(
99 <                                DepotConfig.getVocabularyName_ModType());
100 <                if (tv == null)
95 <                        return;
96 <
97 <                int vid = tv.getVid();
98 <                TreeMap<String, TaxonomyTerm> terms = new TreeMap<String, TaxonomyTerm>();
99 <                terms.put(" ", new TaxonomyTerm(-1, vid, "-All-"));
100 <                for (TaxonomyTerm t : DepotManager.getInstance()
101 <                                .getTaxonomyTermsByVocabulary(vid)) {
102 <                        terms.put(t.getName(), t);
98 >                TreeMap<String, Type> types = new TreeMap<String, Type>();
99 >                for (Type t : ModManager.getInstance().getTypesWithContent()) {
100 >                        types.put(t.getName(), t);
101                  }
102 <                for (TaxonomyTerm t : terms.values()) {
102 >                for (Type t : types.values()) {
103                          cmbModTypes.addItem(t);
104                  }
105                  cmbModTypes.setSelectedIndex(0);
# Line 120 | Line 118 | public class MainWin extends JFrame impl
118                                                  } else {
119                                                          int modelRow = tblMods
120                                                                          .convertRowIndexToModel(viewRow);
121 <                                                        NodeMod mod = (NodeMod) model.getValueAt(modelRow,
124 <                                                                        -1);
121 >                                                        Mod mod = (Mod) model.getValueAt(modelRow, -1);
122                                                          modSelection(mod);
123                                                  }
124                                          }
# Line 132 | Line 129 | public class MainWin extends JFrame impl
129                                  .setOpaque(true);
130  
131                  model = new ModTableModel();
132 +                model.addDownloadSizeListener(this);
133  
134                  tblMods.setModel(model);
135  
136                  sorter = new TableRowSorter<ModTableModel>(model);
137                  tblMods.setRowSorter(sorter);
138  
139 <                sorter.setRowFilter(new ModTableFilter(-1));
139 >                sorter.setRowFilter(new ModTableFilter(null));
140  
141                  sorter.setSortable(2, false);
144                sorter.setComparator(1, new Comparator<String>() {
145
146                        @Override
147                        public int compare(String o1, String o2) {
148                                int i1 = Integer.parseInt(o1);
149                                int i2 = Integer.parseInt(o2);
150                                return i1 - i2;
151                        }
152                });
142  
143                  List<RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>();
144                  sortKeys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING));
# Line 172 | Line 161 | public class MainWin extends JFrame impl
161                  return res == JOptionPane.YES_OPTION;
162          }
163  
175        private boolean closeFrames() {
176                System.gc();
177                for (Frame f : Frame.getFrames()) {
178                        if (f != this)
179                                f.dispose();
180                }
181                return true;
182        }
183
164          private void exit() {
165                  setVisible(false);
166                  dispose();
# Line 205 | Line 185 | public class MainWin extends JFrame impl
185                                                          evt.setProgressMessage(stepName);
186                                                  }
187                                          });
188 <                        model.reloadData();
188 >                        ModManager.getInstance().init();
189 >                        initTable();
190                          initModTypeBox();
191 +
192                          tblMods.setVisible(true);
193                          DepotManager.getInstance().printStats();
194                  } catch (Exception e) {
# Line 243 | Line 225 | public class MainWin extends JFrame impl
225  
226          @SuppressWarnings("unused")
227          private void loadConfig() {
228 <                // TODO Auto-generated method stub
228 >                // TODO method stub
229                  JOptionPane.showMessageDialog(this, "loadConfig", "todo",
230                                  JOptionPane.INFORMATION_MESSAGE);
231          }
232  
233          @SuppressWarnings("unused")
234          private void saveConfig() {
235 <                // TODO Auto-generated method stub
235 >                // TODO method stub
236                  JOptionPane.showMessageDialog(this, "saveConfig", "todo",
237                                  JOptionPane.INFORMATION_MESSAGE);
238          }
239  
240 +        @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false)
241 +        private void reglobalize(final BackgroundEvent evt) {
242 +                Installer.initializeEdition(new InstallProgressListener() {
243 +                        @Override
244 +                        public void installProgressUpdate(int done, int total, String step) {
245 +                                evt.setProgressEnd(total);
246 +                                evt.setProgressValue(done);
247 +                                evt.setProgressMessage(step);
248 +                        }
249 +                });
250 +        }
251 +
252          @SuppressWarnings("unused")
253 <        private void reglobalize() {
254 <                // TODO Auto-generated method stub
255 <                JOptionPane.showMessageDialog(this, "reglobalize", "todo",
253 >        private void tools() {
254 >                // TODO method stub
255 >                JOptionPane.showMessageDialog(this, "tools", "todo",
256                                  JOptionPane.INFORMATION_MESSAGE);
257          }
258  
259          @SuppressWarnings("unused")
260          private void revertSelection() {
261 <                // TODO Auto-generated method stub
261 >                // TODO method stub
262                  JOptionPane.showMessageDialog(this, "revertSelection", "todo",
263                                  JOptionPane.INFORMATION_MESSAGE);
264          }
265  
266 <        private void modSelection(NodeMod n) {
266 >        @DoInBackground(progressMessage = "installing.title", cancelable = false, indeterminateProgress = false)
267 >        private void install(final BackgroundEvent evt) {
268 >                TreeSet<Mod> mods = new TreeSet<Mod>();
269 >                mods.addAll(ModManager.getInstance().getDefaultMods());
270 >                mods.addAll(model.getSelectedMods());
271 >
272 >                System.out.println("Install mods:");
273 >                for (Mod m : mods) {
274 >                        System.out
275 >                                        .println("  " + m.getPackageNumber() + ": " + m.getName());
276 >                }
277 >
278 >                Installer.install(mods, new InstallProgressListener() {
279 >                        @Override
280 >                        public void installProgressUpdate(int done, int total, String step) {
281 >                                evt.setProgressEnd(total);
282 >                                evt.setProgressValue(done);
283 >                                evt.setProgressMessage(step);
284 >                        }
285 >                });
286 >
287 >                // TODO method stub
288 >                JOptionPane.showMessageDialog(this, "install", "todo",
289 >                                JOptionPane.INFORMATION_MESSAGE);
290 >        }
291 >
292 >        private void modSelection(Mod m) {
293                  lblSubmitterVal.setText("");
294                  lblCreatorVal.setText("");
275                lblIdVal.setText("");
295                  lblFilesVal.setText("");
296                  lblDescriptionVal.setText("");
297 <                if (n != null) {
298 <                        lblSubmitterVal.setText(n.getName());
299 <                        lblCreatorVal.setText(n.getFields().get("creator"));
300 <                        lblIdVal.setText(Integer.toString(n.getNid()));
301 <                        lblFilesVal.setText(Integer.toString(n.getUploads().size()));
302 <                        if (n.getBody() != null)
303 <                                lblDescriptionVal.setText(n.getBody().getSafe_value());
297 >                if (m != null) {
298 >                        lblSubmitterVal.setText(m.getName());
299 >                        lblCreatorVal.setText(m.getCreator());
300 >                        if (m.getNode() != null) {
301 >                                lblFilesVal.setText(Integer.toString(m.getNode().getUploads()
302 >                                                .size()));
303 >                        }
304 >                        lblDescriptionVal.setText(m.getDescription());
305                  }
306                  // TODO
307          }
308  
309          @SuppressWarnings("unused")
310          private void modTypeSelection() {
311 <                TaxonomyTerm t = (TaxonomyTerm) cmbModTypes.getSelectedItem();
311 >                Type t = (Type) cmbModTypes.getSelectedItem();
312                  if (t != null)
313 <                        sorter.setRowFilter(new ModTableFilter(t.getTid()));
313 >                        sorter.setRowFilter(new ModTableFilter(t));
314                  else
315 <                        sorter.setRowFilter(new ModTableFilter(-1));
315 >                        sorter.setRowFilter(new ModTableFilter(null));
316 >        }
317 >
318 >        @Override
319 >        public void downloadSizeChanged(int newSize) {
320 >                lblDownloadSizeVal.setText(SizeFormatter.format(newSize, 2));
321 >        }
322 >
323 >        @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false)
324 >        private void initialize(final BackgroundEvent evt) {
325 >                if (!Installer.isEditionInitialized()) {
326 >                        int res = JOptionPane.showConfirmDialog(this,
327 >                                        bundle.getString("askInitialize.text"),
328 >                                        bundle.getString("askInitialize.title"),
329 >                                        JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
330 >                        if (res == JOptionPane.NO_OPTION) {
331 >                                exit();
332 >                        } else {
333 >                                Installer.initializeEdition(new InstallProgressListener() {
334 >                                        @Override
335 >                                        public void installProgressUpdate(int done, int total,
336 >                                                        String step) {
337 >                                                evt.setProgressEnd(total);
338 >                                                evt.setProgressValue(done);
339 >                                                evt.setProgressMessage(step);
340 >                                        }
341 >                                });
342 >                        }
343 >                }
344          }
345  
346          @Override
# Line 322 | Line 370 | public class MainWin extends JFrame impl
370          public void handleQuit(ApplicationEvent event) {
371                  if (askClose()) {
372                          event.setHandled(true);
325                        closeFrames();
373                          saveLocalData();
374                          exit();
375                  } else {
# Line 333 | Line 380 | public class MainWin extends JFrame impl
380          @Override
381          public void handleReOpenApplication(ApplicationEvent event) {
382          }
383 +
384   }

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)