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 603 by alloc, Thu Jan 10 16:25:51 2013 UTC vs.
Revision 604 by alloc, Sat Jan 12 22:48:33 2013 UTC

# Line 1 | Line 1
1   package net.oni2.aeinstaller.gui;
2  
3 + import java.io.File;
4   import java.util.ArrayList;
5   import java.util.List;
6   import java.util.ResourceBundle;
# Line 9 | Line 10 | import java.util.TreeSet;
10   import javax.swing.JButton;
11   import javax.swing.JComboBox;
12   import javax.swing.JComponent;
13 + import javax.swing.JFileChooser;
14   import javax.swing.JFrame;
15   import javax.swing.JLabel;
16   import javax.swing.JMenu;
# Line 21 | Line 23 | import javax.swing.SortOrder;
23   import javax.swing.SwingUtilities;
24   import javax.swing.event.ListSelectionEvent;
25   import javax.swing.event.ListSelectionListener;
26 + import javax.swing.filechooser.FileFilter;
27   import javax.swing.table.TableRowSorter;
28  
29 + import net.oni2.aeinstaller.backend.Paths;
30   import net.oni2.aeinstaller.backend.Settings;
31   import net.oni2.aeinstaller.backend.Settings.Platform;
32   import net.oni2.aeinstaller.backend.SizeFormatter;
# Line 31 | Line 35 | import net.oni2.aeinstaller.backend.depo
35   import net.oni2.aeinstaller.backend.mods.Mod;
36   import net.oni2.aeinstaller.backend.mods.ModManager;
37   import net.oni2.aeinstaller.backend.mods.Type;
38 + import net.oni2.aeinstaller.backend.mods.download.ModDownloader;
39 + import net.oni2.aeinstaller.backend.mods.download.ModDownloader.State;
40 + import net.oni2.aeinstaller.backend.mods.download.ModDownloaderListener;
41   import net.oni2.aeinstaller.backend.oni.InstallProgressListener;
42   import net.oni2.aeinstaller.backend.oni.Installer;
43   import net.oni2.aeinstaller.gui.about.AboutDialog;
# Line 221 | Line 228 | public class MainWin extends JFrame impl
228                  new AboutDialog().setVisible(true);
229          }
230  
231 +        private JFileChooser getConfigOpenSaveDialog(boolean save) {
232 +                JFileChooser fc = new JFileChooser();
233 +                fc.setCurrentDirectory(Paths.getEditionBasePath());
234 +                if (save)
235 +                        fc.setDialogType(JFileChooser.SAVE_DIALOG);
236 +                else
237 +                        fc.setDialogType(JFileChooser.OPEN_DIALOG);
238 +                fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
239 +                fc.setFileFilter(new FileFilter() {
240 +                        @Override
241 +                        public String getDescription() {
242 +                                return "XML files";
243 +                        }
244 +
245 +                        @Override
246 +                        public boolean accept(File arg0) {
247 +                                return (arg0.isDirectory())
248 +                                                || (arg0.getName().toLowerCase().endsWith(".xml"));
249 +                        }
250 +                });
251 +                fc.setMultiSelectionEnabled(false);
252 +                return fc;
253 +        }
254 +
255          @SuppressWarnings("unused")
256          private void loadConfig() {
257 <                // TODO method stub
258 <                JOptionPane.showMessageDialog(this, "loadConfig", "todo",
259 <                                JOptionPane.INFORMATION_MESSAGE);
257 >                JFileChooser fc = getConfigOpenSaveDialog(false);
258 >                int res = fc.showOpenDialog(this);
259 >                if (res == JFileChooser.APPROVE_OPTION) {
260 >                        if (fc.getSelectedFile().exists())
261 >                                model.reloadSelection(fc.getSelectedFile());
262 >                }
263          }
264  
265          @SuppressWarnings("unused")
266          private void saveConfig() {
267 <                // TODO method stub
268 <                JOptionPane.showMessageDialog(this, "saveConfig", "todo",
269 <                                JOptionPane.INFORMATION_MESSAGE);
267 >                JFileChooser fc = getConfigOpenSaveDialog(true);
268 >                int res = fc.showSaveDialog(this);
269 >                if (res == JFileChooser.APPROVE_OPTION) {
270 >                        File f = fc.getSelectedFile();
271 >                        if (!f.getName().endsWith(".xml"))
272 >                                f = new File(f.getParentFile(), f.getName() + ".xml");
273 >                        ModManager.getInstance().saveModSelection(f,
274 >                                        model.getSelectedMods());
275 >                }
276          }
277  
278          @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false)
# Line 256 | Line 296 | public class MainWin extends JFrame impl
296  
297          @SuppressWarnings("unused")
298          private void revertSelection() {
299 <                // TODO method stub
260 <                JOptionPane.showMessageDialog(this, "revertSelection", "todo",
261 <                                JOptionPane.INFORMATION_MESSAGE);
299 >                model.revertSelection();
300          }
301  
302          @DoInBackground(progressMessage = "mandatoryFiles.title", cancelable = false, indeterminateProgress = false)
303          private void checkMandatoryFiles(final BackgroundEvent evt) {
304 <                //TODO
267 <                System.out.println("Mandatory Tools:");
304 >                TreeSet<Mod> mand = new TreeSet<Mod>();
305                  for (Mod m : ModManager.getInstance().getMandatoryTools()) {
306 <                        System.out.format("  %05d %15s - Local: %b - Update: %b", m.getPackageNumber(), m.getName(), m.isLocalAvailable(), m.isNewerAvailable());
306 >                        if (m.isNewerAvailable()) {
307 >                                mand.add(m);
308 >                        }
309                  }
271                System.out.println();
272                
273                System.out.println("Mandatory Mods:");
310                  for (Mod m : ModManager.getInstance().getMandatoryMods()) {
311 <                        System.out.format("  %05d %15s - Local: %b - Update: %b", m.getPackageNumber(), m.getName(), m.isLocalAvailable(), m.isNewerAvailable());
311 >                        if (m.isNewerAvailable()) {
312 >                                mand.add(m);
313 >                        }
314 >                }
315 >                if (mand.size() > 0) {
316 >                        ModDownloader m = new ModDownloader(mand,
317 >                                        new ModDownloaderListener() {
318 >                                                @Override
319 >                                                public void updateStatus(ModDownloader source,
320 >                                                                State state, int filesDown, int filesTotal,
321 >                                                                int bytesDown, int bytesTotal) {
322 >                                                        evt.setProgressEnd(filesTotal);
323 >                                                        evt.setProgressValue(filesDown);
324 >                                                }
325 >                                        });
326 >                        while (!m.isFinished()) {
327 >                                try {
328 >                                        Thread.sleep(50);
329 >                                } catch (InterruptedException e) {
330 >                                        // TODO Auto-generated catch block
331 >                                        e.printStackTrace();
332 >                                }
333 >                        }
334                  }
335 +                evt.setProgressMessage(bundle.getString("mandatoryToolsInstall.title"));
336 +                Installer.installTools(ModManager.getInstance().getMandatoryTools());
337          }
338  
339          @DoInBackground(progressMessage = "installing.title", cancelable = false, indeterminateProgress = false)
# Line 286 | Line 346 | public class MainWin extends JFrame impl
346  
347                  System.out.println("Install mods:");
348                  for (Mod m : mods) {
349 <                        System.out
350 <                                        .println("  " + m.getPackageNumber() + ": " + m.getName());
349 >                        System.out.println("  " + m.getPackageNumberString() + ": "
350 >                                        + m.getName());
351                  }
352  
353                  Installer.install(mods, new InstallProgressListener() {

Diff Legend

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