source: AE/installer2/src/net/oni2/aeinstaller/gui/MainWin.java@ 658

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

AEI2 0.99i:

  • Lots of refactorings for the GUI:
    • Global type for the mod info box (Main, Tools, Core)
    • Same table for Main, Tools, Core
File size: 25.2 KB
Line 
1package net.oni2.aeinstaller.gui;
2
3import java.awt.BorderLayout;
4import java.awt.Desktop;
5import java.awt.GridLayout;
6import java.awt.event.ActionEvent;
7import java.awt.event.ItemEvent;
8import java.awt.event.ItemListener;
9import java.io.File;
10import java.net.URL;
11import java.util.Date;
12import java.util.HashMap;
13import java.util.HashSet;
14import java.util.ResourceBundle;
15import java.util.TreeMap;
16import java.util.TreeSet;
17import java.util.Vector;
18
19import javax.swing.AbstractAction;
20import javax.swing.Icon;
21import javax.swing.ImageIcon;
22import javax.swing.JButton;
23import javax.swing.JCheckBox;
24import javax.swing.JComboBox;
25import javax.swing.JFileChooser;
26import javax.swing.JFrame;
27import javax.swing.JLabel;
28import javax.swing.JMenu;
29import javax.swing.JMenuItem;
30import javax.swing.JOptionPane;
31import javax.swing.JPanel;
32import javax.swing.JRadioButton;
33import javax.swing.JScrollPane;
34import javax.swing.JSplitPane;
35import javax.swing.SwingUtilities;
36import javax.swing.ToolTipManager;
37import javax.swing.filechooser.FileFilter;
38
39import net.oni2.aeinstaller.AEInstaller2;
40import net.oni2.aeinstaller.backend.AppExecution;
41import net.oni2.aeinstaller.backend.Paths;
42import net.oni2.aeinstaller.backend.Settings;
43import net.oni2.aeinstaller.backend.Settings.Platform;
44import net.oni2.aeinstaller.backend.SizeFormatter;
45import net.oni2.aeinstaller.backend.depot.DepotManager;
46import net.oni2.aeinstaller.backend.oni.InstallProgressListener;
47import net.oni2.aeinstaller.backend.oni.Installer;
48import net.oni2.aeinstaller.backend.oni.OniSplit;
49import net.oni2.aeinstaller.backend.packages.Package;
50import net.oni2.aeinstaller.backend.packages.PackageManager;
51import net.oni2.aeinstaller.backend.packages.Type;
52import net.oni2.aeinstaller.backend.packages.download.ModDownloader;
53import net.oni2.aeinstaller.backend.packages.download.ModDownloader.State;
54import net.oni2.aeinstaller.backend.packages.download.ModDownloaderListener;
55import net.oni2.aeinstaller.gui.about.AboutDialog;
56import net.oni2.aeinstaller.gui.corepackages.CorePackagesDialog;
57import net.oni2.aeinstaller.gui.downloadwindow.Downloader;
58import net.oni2.aeinstaller.gui.modtable.DownloadSizeListener;
59import net.oni2.aeinstaller.gui.modtable.ModSelectionListener;
60import net.oni2.aeinstaller.gui.modtable.ModTable;
61import net.oni2.aeinstaller.gui.modtable.ModTable.ETableContentType;
62import net.oni2.aeinstaller.gui.packageinfobox.PackageInfoBox;
63import net.oni2.aeinstaller.gui.settings.SettingsDialog;
64import net.oni2.aeinstaller.gui.toolmanager.ToolManager;
65
66import org.javabuilders.BuildResult;
67import org.javabuilders.annotations.DoInBackground;
68import org.javabuilders.event.BackgroundEvent;
69import org.javabuilders.swing.SwingJavaBuilder;
70import org.simplericity.macify.eawt.ApplicationEvent;
71import org.simplericity.macify.eawt.ApplicationListener;
72
73/**
74 * @author Christian Illy
75 */
76public class MainWin extends JFrame implements ApplicationListener,
77 DownloadSizeListener, ModSelectionListener {
78 private static final long serialVersionUID = -4027395051382659650L;
79
80 private ResourceBundle bundle = ResourceBundle
81 .getBundle("net.oni2.aeinstaller.localization."
82 + getClass().getSimpleName());
83 @SuppressWarnings("unused")
84 private BuildResult result = SwingJavaBuilder.build(this, bundle);
85
86 private JMenu mainMenu;
87 private JMenu toolsMenu;
88 private Vector<JMenuItem> toolsMenuItems = new Vector<JMenuItem>();
89
90 private JSplitPane contents;
91
92 private JComboBox cmbModTypes;
93 private JRadioButton radAll;
94 private JRadioButton radOnline;
95 private JRadioButton radLocal;
96 private JScrollPane scrollMods;
97 private ModTable tblMods;
98 private JLabel lblDownloadSizeVal;
99
100 private PackageInfoBox pkgInfo;
101
102 private JButton btnInstall;
103
104 private TreeSet<Package> execCoreUpdates = new TreeSet<Package>();
105 private TreeSet<Package> execUpdates = null;
106
107 private enum EInstallState {
108 DONE,
109 READY,
110 ABORTED,
111 OFFLINE,
112 INCOMPATIBLE,
113 CHECKING
114 };
115
116 private EInstallState installState = EInstallState.DONE;
117 private TreeSet<Package> installMods = null;
118 private TreeSet<Package> installDeps = null;
119
120 /**
121 * Constructor of main window.
122 */
123 public MainWin() {
124 this.setTitle(SwingJavaBuilder.getConfig().getResource("appname")
125 + " - v"
126 + SwingJavaBuilder.getConfig().getResource("appversion"));
127
128 tblMods = new ModTable(ETableContentType.MODS);
129 tblMods.setVisible(false);
130 scrollMods.setViewportView(tblMods);
131
132 contents.setDividerLocation(550);
133 contents.setResizeWeight(0.4);
134
135 if (Settings.getPlatform() == Platform.MACOS) {
136 mainMenu.setVisible(false);
137 }
138
139 ToolTipManager.sharedInstance().setInitialDelay(250);
140
141 getRootPane().setDefaultButton(btnInstall);
142 lblDownloadSizeVal.setText(SizeFormatter.format(0, 2));
143 radAll.setSelected(true);
144
145 tblMods.addModSelectionListener(this);
146 tblMods.addDownloadSizeListener(this);
147 }
148
149 private void initModTypeBox() {
150 cmbModTypes.removeAllItems();
151
152 TreeMap<String, Type> types = new TreeMap<String, Type>();
153 for (Type t : PackageManager.getInstance().getTypesWithContent()) {
154 types.put(t.getName(), t);
155 }
156 cmbModTypes.addItem("-All-");
157 for (Type t : types.values()) {
158 cmbModTypes.addItem(t);
159 }
160 cmbModTypes.setSelectedIndex(0);
161 }
162
163 private void exit() {
164 dispose();
165 System.exit(0);
166 }
167
168 private void saveLocalData() {
169 Settings.getInstance().serializeToFile();
170 }
171
172 @DoInBackground(progressMessage = "updateDepot.title", cancelable = false, indeterminateProgress = false)
173 private void execDepotUpdate(final BackgroundEvent evt) {
174 if (!Settings.getInstance().isOfflineMode()
175 && !Settings.getInstance().isNoCacheUpdateMode()) {
176 long start = new Date().getTime();
177
178 try {
179 DepotManager.getInstance().updateInformation(false);
180 } catch (Exception e) {
181 e.printStackTrace();
182 }
183
184 System.out.println("Took: " + (new Date().getTime() - start)
185 + " msec");
186 }
187
188 PackageManager.getInstance().init();
189 tblMods.reloadData();
190 initModTypeBox();
191
192 tblMods.setVisible(true);
193 }
194
195 @SuppressWarnings("unused")
196 private void checkUpdates(Object evtSource) {
197 if ((evtSource != this)
198 || Settings.getInstance().get("notifyupdates", true)) {
199 if (Settings.getInstance().isOfflineMode()) {
200 if (evtSource != this) {
201 JOptionPane.showMessageDialog(
202 this,
203 SwingJavaBuilder.getConfig().getResource(
204 "offlineMode.text"),
205 SwingJavaBuilder.getConfig().getResource(
206 "offlineMode.title"),
207 JOptionPane.WARNING_MESSAGE);
208 }
209 } else {
210 TreeSet<Package> mods = PackageManager.getInstance()
211 .getUpdatableMods();
212 TreeSet<Package> tools = PackageManager.getInstance()
213 .getUpdatableTools();
214 int size = 0;
215 JPanel panPackages = new JPanel(new GridLayout(0, 1));
216 execUpdates = new TreeSet<Package>();
217 execUpdates.addAll(mods);
218 execUpdates.addAll(tools);
219 for (final Package m : mods) {
220 size += m.getZipSize();
221 JCheckBox check = new JCheckBox("Mod: " + m.getName());
222 check.setSelected(true);
223 check.addItemListener(new ItemListener() {
224 @Override
225 public void itemStateChanged(ItemEvent e) {
226 if (e.getStateChange() == ItemEvent.SELECTED)
227 execUpdates.add(m);
228 else
229 execUpdates.remove(m);
230 }
231 });
232 panPackages.add(check);
233 }
234 for (final Package m : tools) {
235 size += m.getZipSize();
236 JCheckBox check = new JCheckBox("Tool: " + m.getName());
237 check.setSelected(true);
238 panPackages.add(check);
239 }
240 if (size > 0) {
241 // Build info dialog content
242 JPanel packages = new JPanel(new BorderLayout(0, 7));
243 JLabel lblIntro = new JLabel("<html>"
244 + bundle.getString("updatesAvailable.text")
245 + "</html>");
246 JLabel lblSize = new JLabel("<html>"
247 + String.format(bundle
248 .getString("updatesAvailableSize.text"),
249 SizeFormatter.format(size, 3)) + "</html>");
250 packages.add(lblIntro, BorderLayout.NORTH);
251 packages.add(panPackages, BorderLayout.CENTER);
252 packages.add(lblSize, BorderLayout.SOUTH);
253
254 JPanel pan = new JPanel(new BorderLayout(0, 25));
255 pan.add(packages, BorderLayout.CENTER);
256 JCheckBox checkFutureUpdates = new JCheckBox(
257 bundle.getString("checkOnStartup.text"));
258 checkFutureUpdates.setSelected(Settings.getInstance().get(
259 "notifyupdates", true));
260 checkFutureUpdates.addItemListener(new ItemListener() {
261 @Override
262 public void itemStateChanged(ItemEvent evt) {
263 Settings.getInstance().put("notifyupdates",
264 evt.getStateChange() == ItemEvent.SELECTED);
265 }
266 });
267 pan.add(checkFutureUpdates, BorderLayout.SOUTH);
268
269 // Show dialog
270 int res = JOptionPane.showConfirmDialog(this, pan,
271 bundle.getString("updatesAvailable.title"),
272 JOptionPane.YES_NO_OPTION,
273 JOptionPane.QUESTION_MESSAGE);
274 if (res == JOptionPane.NO_OPTION) {
275 execUpdates = null;
276 }
277 } else {
278 if (evtSource != this) {
279 JOptionPane.showMessageDialog(this,
280 bundle.getString("updatesNotAvailable.text"),
281 bundle.getString("updatesNotAvailable.title"),
282 JOptionPane.INFORMATION_MESSAGE);
283 }
284 }
285 }
286 }
287 }
288
289 @SuppressWarnings("unused")
290 private void doUpdate() {
291 if (execUpdates != null && execUpdates.size() > 0) {
292 Downloader dl = new Downloader(execUpdates, null);
293 try {
294 dl.setVisible(true);
295 if (dl.isFinished()) {
296 TreeSet<Integer> installed = Installer.getInstalledTools();
297 TreeSet<Package> tools = new TreeSet<Package>();
298 for (Package m : execUpdates)
299 if (m.isTool()
300 && installed.contains(m.getPackageNumber()))
301 tools.add(m);
302 if (tools.size() > 0) {
303 Installer.installTools(tools);
304 }
305 }
306 } finally {
307 dl.dispose();
308 }
309 }
310 execUpdates = null;
311 }
312
313 @SuppressWarnings("unused")
314 private void focus() {
315 SwingUtilities.invokeLater(new Runnable() {
316
317 @Override
318 public void run() {
319 toFront();
320 repaint();
321 }
322 });
323
324 }
325
326 @SuppressWarnings("unused")
327 private void showCorePackagesDialog() {
328 new CorePackagesDialog().setVisible(true);
329 }
330
331 private void showSettings() {
332 new SettingsDialog().setVisible(true);
333 }
334
335 private void showAbout() {
336 new AboutDialog().setVisible(true);
337 }
338
339 private JFileChooser getConfigOpenSaveDialog(boolean save) {
340 JFileChooser fc = new JFileChooser();
341 fc.setCurrentDirectory(Paths.getEditionBasePath());
342 if (save)
343 fc.setDialogType(JFileChooser.SAVE_DIALOG);
344 else
345 fc.setDialogType(JFileChooser.OPEN_DIALOG);
346 fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
347 fc.setFileFilter(new FileFilter() {
348 @Override
349 public String getDescription() {
350 return "XML files";
351 }
352
353 @Override
354 public boolean accept(File arg0) {
355 return (arg0.isDirectory())
356 || (arg0.getName().toLowerCase().endsWith(".xml"));
357 }
358 });
359 fc.setMultiSelectionEnabled(false);
360 return fc;
361 }
362
363 @SuppressWarnings("unused")
364 private void loadConfig() {
365 JFileChooser fc = getConfigOpenSaveDialog(false);
366 int res = fc.showOpenDialog(this);
367 if (res == JFileChooser.APPROVE_OPTION) {
368 if (fc.getSelectedFile().exists())
369 tblMods.reloadSelection(fc.getSelectedFile());
370 }
371 }
372
373 @SuppressWarnings("unused")
374 private void saveConfig() {
375 JFileChooser fc = getConfigOpenSaveDialog(true);
376 int res = fc.showSaveDialog(this);
377 if (res == JFileChooser.APPROVE_OPTION) {
378 File f = fc.getSelectedFile();
379 if (!f.getName().endsWith(".xml"))
380 f = new File(f.getParentFile(), f.getName() + ".xml");
381 PackageManager.getInstance().saveModSelection(f,
382 tblMods.getSelectedMods());
383 }
384 }
385
386 @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false)
387 private void reglobalize(final BackgroundEvent evt) {
388 Installer.initializeEdition(new InstallProgressListener() {
389 @Override
390 public void installProgressUpdate(int done, int total, String step) {
391 evt.setProgressEnd(total);
392 evt.setProgressValue(done);
393 evt.setProgressMessage(step);
394 }
395 });
396 }
397
398 @SuppressWarnings("unused")
399 private void tools() {
400 new ToolManager().setVisible(true);
401 }
402
403 @SuppressWarnings("unused")
404 private void refreshToolsMenu() {
405 for (JMenuItem i : toolsMenuItems) {
406 toolsMenu.remove(i);
407 }
408 toolsMenuItems.clear();
409 for (Package m : PackageManager.getInstance().getInstalledTools()) {
410 File exe = m.getExeFile();
411 if (exe != null && exe.exists()) {
412 JMenuItem item = new JMenuItem();
413 final Vector<String> params = new Vector<String>();
414 if (exe.getName().toLowerCase().endsWith(".jar")) {
415 File jre = null;
416 if (Settings.getPlatform() == Platform.WIN)
417 jre = new File(System.getProperties().getProperty(
418 "java.home"), "bin/javaw.exe");
419 else
420 jre = new File(System.getProperties().getProperty(
421 "java.home"), "bin/java");
422 params.add(jre.getPath());
423 params.add("-jar");
424 }
425 params.add(exe.getPath());
426 final File wd = m.getWorkingDir();
427 Icon ico = null;
428 if (m.getIconFile() != null && m.getIconFile().exists()) {
429 ico = new ImageIcon(m.getIconFile().getPath());
430 } else {
431 URL icon = AEInstaller2.class
432 .getResource("images/transparent.png");
433 ico = new ImageIcon(icon);
434 }
435 item.setAction(new AbstractAction(m.getName(), ico) {
436 private static final long serialVersionUID = 1L;
437
438 @Override
439 public void actionPerformed(ActionEvent e) {
440 AppExecution.execute(params, wd);
441 }
442 });
443 toolsMenuItems.add(item);
444 toolsMenu.add(item);
445 }
446 }
447 }
448
449 private void revertSelection() {
450 tblMods.revertSelection();
451 }
452
453 @SuppressWarnings("unused")
454 private void unSelectAll() {
455 tblMods.unSelectAll();
456 }
457
458 @DoInBackground(progressMessage = "checkCorePackages.title", cancelable = false, indeterminateProgress = false)
459 private void checkCorePackages(final BackgroundEvent evt) {
460 if (!Settings.getInstance().isOfflineMode()) {
461 for (Package m : PackageManager.getInstance().getCoreTools()) {
462 if (m.isNewerAvailable()) {
463 execCoreUpdates.add(m);
464 }
465 }
466 for (Package m : PackageManager.getInstance().getCoreMods()) {
467 if (m.isNewerAvailable()) {
468 execCoreUpdates.add(m);
469 }
470 }
471 if (execCoreUpdates.size() > 0) {
472 ModDownloader m = new ModDownloader(execCoreUpdates,
473 new ModDownloaderListener() {
474 @Override
475 public void updateStatus(ModDownloader source,
476 Package currentDownload, State state,
477 int filesDown, int filesTotal,
478 int bytesDown, int bytesTotal,
479 int duration, int remaining, int speed) {
480 evt.setProgressEnd(filesTotal);
481 evt.setProgressValue(filesDown);
482 }
483 });
484 while (!m.isFinished()) {
485 try {
486 Thread.sleep(10);
487 } catch (InterruptedException e) {
488 e.printStackTrace();
489 }
490 }
491 }
492 evt.setProgressMessage(bundle.getString("coreToolsInstall.title"));
493 Installer.installTools(PackageManager.getInstance().getCoreTools());
494 }
495 }
496
497 @SuppressWarnings("unused")
498 private void infoCorePackages() {
499 if (execCoreUpdates.size() > 0) {
500 String packages = "";
501 for (Package m : execCoreUpdates) {
502 packages += String.format("\n - %s (%s)", m.getName(),
503 m.getVersion());
504 }
505 JOptionPane.showMessageDialog(this, String.format(
506 bundle.getString("corePackagesUpdated.text"), packages),
507 bundle.getString("corePackagesUpdated.title"),
508 JOptionPane.INFORMATION_MESSAGE);
509 }
510 }
511
512 @SuppressWarnings("unused")
513 private void install() {
514 TreeSet<Package> mods = new TreeSet<Package>();
515 mods.addAll(PackageManager.getInstance().getCoreMods());
516 mods.addAll(tblMods.getSelectedMods());
517
518 installDeps = new TreeSet<Package>();
519
520 installState = EInstallState.CHECKING;
521
522 while (installState == EInstallState.CHECKING) {
523 TreeSet<Package> toDownload = new TreeSet<Package>();
524 for (Package m : mods) {
525 if (!m.isLocalAvailable())
526 toDownload.add(m);
527 }
528 if (toDownload.size() > 0 && Settings.getInstance().isOfflineMode()) {
529 installState = EInstallState.OFFLINE;
530 break;
531 }
532 if (toDownload.size() > 0) {
533 Downloader dl = new Downloader(toDownload, installDeps);
534 try {
535 dl.setVisible(true);
536 if (!dl.isFinished()) {
537 installState = EInstallState.ABORTED;
538 break;
539 }
540 } finally {
541 dl.dispose();
542 }
543 }
544 HashMap<Package, HashSet<Package>> dependencies = PackageManager
545 .getInstance().checkDependencies(mods);
546 if (dependencies.size() > 0) {
547 for (HashSet<Package> hm : dependencies.values()) {
548 installDeps.addAll(hm);
549 }
550
551 if (!Settings.getInstance()
552 .get("notifyDepsAfterInstall", false)) {
553 int size = 0;
554 String depsLocalString = "";
555 String depsDownloadString = "";
556 for (Package m : dependencies.keySet()) {
557 for (Package mDep : dependencies.get(m)) {
558 if (!mods.contains(mDep)) {
559 mods.add(mDep);
560 if (!mDep.isLocalAvailable()) {
561 size += mDep.getZipSize();
562 if (depsDownloadString.length() > 0)
563 depsDownloadString += "\n";
564 depsDownloadString += " - "
565 + mDep.getName();
566 } else {
567 if (depsLocalString.length() > 0)
568 depsLocalString += "\n";
569 depsLocalString += " - " + mDep.getName();
570 }
571 }
572 }
573 }
574 if (depsLocalString.length() == 0)
575 depsLocalString = bundle
576 .getString("installDependencies.none");
577 if (depsDownloadString.length() == 0)
578 depsDownloadString = bundle
579 .getString("installDependencies.none");
580
581 int res = JOptionPane.showConfirmDialog(this, String
582 .format(bundle
583 .getString("installDependencies.text"),
584 depsLocalString, depsDownloadString,
585 SizeFormatter.format(size, 3)), bundle
586 .getString("installDependencies.title"),
587 JOptionPane.YES_NO_OPTION,
588 JOptionPane.INFORMATION_MESSAGE);
589 if (res == JOptionPane.NO_OPTION) {
590 installState = EInstallState.ABORTED;
591 break;
592 }
593 }
594 } else {
595 HashMap<Package, HashSet<Package>> incompatibilities = PackageManager
596 .getInstance().checkIncompabitilites(mods);
597 if (incompatibilities.size() > 0) {
598 installState = EInstallState.INCOMPATIBLE;
599
600 String incompatString = "";
601 for (Package m : incompatibilities.keySet()) {
602 if (incompatString.length() > 0)
603 incompatString += "\n";
604 incompatString += m.getName() + ": ";
605 String confMods = "";
606 for (Package mConf : incompatibilities.get(m)) {
607 if (confMods.length() > 0)
608 confMods += ", ";
609 confMods += mConf.getName();
610 }
611 incompatString += confMods;
612 }
613
614 JOptionPane.showMessageDialog(this, String.format(
615 bundle.getString("installIncompatibilities.text"),
616 incompatString), bundle
617 .getString("installIncompatibilities.title"),
618 JOptionPane.ERROR_MESSAGE);
619 break;
620 } else {
621 installState = EInstallState.READY;
622 }
623 }
624 }
625
626 if (installState == EInstallState.READY) {
627 installMods = new TreeSet<Package>();
628 TreeSet<Package> actuallyTools = new TreeSet<Package>();
629
630 for (Package m : mods) {
631 if (m.isTool())
632 actuallyTools.add(m);
633 else
634 installMods.add(m);
635 }
636
637 if (actuallyTools.size() > 0) {
638 Installer.installTools(actuallyTools);
639 }
640 }
641
642 }
643
644 @DoInBackground(progressMessage = "installing.title", cancelable = false, indeterminateProgress = false)
645 private void installExec(final BackgroundEvent evt) {
646 if (installState == EInstallState.READY) {
647 Installer.install(installMods, new InstallProgressListener() {
648 @Override
649 public void installProgressUpdate(int done, int total,
650 String step) {
651 evt.setProgressEnd(total);
652 evt.setProgressValue(done);
653 evt.setProgressMessage(step);
654 }
655 });
656 installState = EInstallState.DONE;
657 }
658 installMods = null;
659 }
660
661 @SuppressWarnings("unused")
662 private void installDone() {
663 PackageManager.getInstance().updateInstalledMods();
664 switch (installState) {
665 case DONE:
666 revertSelection();
667 if (installDeps.size() > 0
668 && Settings.getInstance().get("notifyDepsAfterInstall",
669 false)) {
670 String installedDeps = "";
671 for (Package m : installDeps) {
672 if (installedDeps.length() > 0)
673 installedDeps += "\n";
674 installedDeps += " - " + m.getName();
675 }
676 JOptionPane.showMessageDialog(this, String.format(
677 bundle.getString("installDoneDeps.text"),
678 installedDeps), bundle
679 .getString("installDone.title"),
680 JOptionPane.INFORMATION_MESSAGE);
681 } else {
682 JOptionPane.showMessageDialog(this,
683 bundle.getString("installDone.text"),
684 bundle.getString("installDone.title"),
685 JOptionPane.INFORMATION_MESSAGE);
686 }
687 break;
688 case OFFLINE:
689 JOptionPane.showMessageDialog(
690 this,
691 SwingJavaBuilder.getConfig().getResource(
692 "offlineMode.text"),
693 SwingJavaBuilder.getConfig().getResource(
694 "offlineMode.title"),
695 JOptionPane.WARNING_MESSAGE);
696 break;
697 default:
698 break;
699 }
700 installDeps = null;
701 }
702
703 @Override
704 public void modSelectionChanged(ModTable source, Package m) {
705 pkgInfo.updateInfo(m);
706 }
707
708 private void updateTableFilter() {
709 Object o = cmbModTypes.getSelectedItem();
710 Type t = null;
711 if (o instanceof Type)
712 t = (Type) o;
713 int downloadState = 0;
714 if (radOnline.isSelected())
715 downloadState = 1;
716 if (radLocal.isSelected())
717 downloadState = 2;
718 tblMods.setFilter(t, downloadState);
719 }
720
721 @SuppressWarnings("unused")
722 private void modTypeSelection() {
723 updateTableFilter();
724 }
725
726 @SuppressWarnings("unused")
727 private void showTypeSelection() {
728 updateTableFilter();
729 }
730
731 @Override
732 public void downloadSizeChanged(int newSize) {
733 lblDownloadSizeVal.setText(SizeFormatter.format(newSize, 2));
734 }
735
736 @SuppressWarnings("unused")
737 private void checkInitialize() {
738 if (!Installer.isEditionInitialized()) {
739 if (!OniSplit.isOniSplitInstalled()) {
740 JOptionPane.showMessageDialog(this,
741 bundle.getString("noOniSplit.text"),
742 bundle.getString("noOniSplit.title"),
743 JOptionPane.ERROR_MESSAGE);
744 exit();
745 } else {
746 int res = JOptionPane
747 .showConfirmDialog(this,
748 bundle.getString("askInitialize.text"),
749 bundle.getString("askInitialize.title"),
750 JOptionPane.YES_NO_OPTION,
751 JOptionPane.QUESTION_MESSAGE);
752 if (res == JOptionPane.NO_OPTION) {
753 saveLocalData();
754 exit();
755 }
756 }
757 }
758 }
759
760 @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false)
761 private void initialize(final BackgroundEvent evt) {
762 if (!Installer.isEditionInitialized()) {
763 Installer.initializeEdition(new InstallProgressListener() {
764 @Override
765 public void installProgressUpdate(int done, int total,
766 String step) {
767 evt.setProgressEnd(total);
768 evt.setProgressValue(done);
769 evt.setProgressMessage(step);
770 }
771 });
772 }
773 }
774
775 private Vector<String> getBasicOniLaunchParams() {
776 Vector<String> params = new Vector<String>();
777 File exe = null;
778 switch (Settings.getPlatform()) {
779 case WIN:
780 exe = new File(Paths.getEditionBasePath(), "Oni.exe");
781 if (exe.exists())
782 params.add(exe.getPath());
783 break;
784 case MACOS:
785 exe = new File(Paths.getEditionBasePath(),
786 "Oni.app/Contents/MacOS/Oni");
787 if (exe.exists())
788 params.add(exe.getPath());
789 break;
790 case LINUX:
791 String wine = Settings.getWinePath();
792 exe = new File(Paths.getEditionBasePath(), "Oni.exe");
793 if (exe.exists()) {
794 if (wine != null) {
795 params.add(wine);
796 params.add(exe.getPath());
797 }
798 }
799 break;
800 default:
801 }
802 if (params.size() > 0) {
803 params.add("-debugfiles");
804 }
805 return params;
806 }
807
808 @SuppressWarnings("unused")
809 private void oniFull() {
810 Vector<String> params = getBasicOniLaunchParams();
811 if (params.size() > 0) {
812 AppExecution.execute(params, Paths.getEditionBasePath());
813 }
814 }
815
816 @SuppressWarnings("unused")
817 private void oniWin() {
818 Vector<String> params = getBasicOniLaunchParams();
819 if (params.size() > 0) {
820 params.add("-noswitch");
821 AppExecution.execute(params, Paths.getEditionBasePath());
822 }
823 }
824
825 @SuppressWarnings("unused")
826 private void openEditionFolder() {
827 try {
828 Desktop.getDesktop().open(Paths.getEditionBasePath());
829 } catch (Exception e) {
830 e.printStackTrace();
831 }
832 }
833
834 @Override
835 public void handleAbout(ApplicationEvent event) {
836 event.setHandled(true);
837 showAbout();
838 }
839
840 @Override
841 public void handleOpenApplication(ApplicationEvent event) {
842 }
843
844 @Override
845 public void handleOpenFile(ApplicationEvent event) {
846 }
847
848 @Override
849 public void handlePreferences(ApplicationEvent event) {
850 showSettings();
851 }
852
853 @Override
854 public void handlePrintFile(ApplicationEvent event) {
855 }
856
857 @Override
858 public void handleQuit(ApplicationEvent event) {
859 event.setHandled(true);
860 saveLocalData();
861 exit();
862 }
863
864 @Override
865 public void handleReOpenApplication(ApplicationEvent event) {
866 }
867
868}
Note: See TracBrowser for help on using the repository browser.