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

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

AEI2 0.99i:

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