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