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

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

AEI2 0.99d:

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