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