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

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

AEI2 0.99c:

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