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

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

AEI2.11:

File size: 32.0 KB
RevLine 
[591]1package net.oni2.aeinstaller.gui;
2
[627]3import java.awt.BorderLayout;
[608]4import java.awt.Desktop;
[632]5import java.awt.GridLayout;
[807]6import java.awt.Toolkit;
7import java.awt.datatransfer.Clipboard;
8import java.awt.datatransfer.StringSelection;
[608]9import java.awt.event.ActionEvent;
[627]10import java.awt.event.ItemEvent;
11import java.awt.event.ItemListener;
[660]12import java.awt.event.KeyAdapter;
13import java.awt.event.KeyEvent;
[604]14import java.io.File;
[720]15import java.io.FileNotFoundException;
[806]16import java.io.IOException;
17import java.net.URI;
18import java.net.URISyntaxException;
[623]19import java.net.URL;
[634]20import java.util.Date;
[605]21import java.util.HashMap;
22import java.util.HashSet;
[591]23import java.util.ResourceBundle;
24import java.util.TreeMap;
[600]25import java.util.TreeSet;
[605]26import java.util.Vector;
[591]27
[623]28import javax.swing.AbstractAction;
29import javax.swing.ImageIcon;
[600]30import javax.swing.JButton;
[627]31import javax.swing.JCheckBox;
[591]32import javax.swing.JComboBox;
[604]33import javax.swing.JFileChooser;
[591]34import javax.swing.JFrame;
[592]35import javax.swing.JLabel;
[593]36import javax.swing.JMenu;
[608]37import javax.swing.JMenuItem;
[593]38import javax.swing.JOptionPane;
[627]39import javax.swing.JPanel;
[630]40import javax.swing.JRadioButton;
[658]41import javax.swing.JScrollPane;
[592]42import javax.swing.JSplitPane;
[660]43import javax.swing.JTextField;
[591]44import javax.swing.SwingUtilities;
[631]45import javax.swing.ToolTipManager;
[604]46import javax.swing.filechooser.FileFilter;
[591]47
[720]48import net.oni2.SettingsManager;
[623]49import net.oni2.aeinstaller.AEInstaller2;
[671]50import net.oni2.aeinstaller.backend.ImageResizer;
[604]51import net.oni2.aeinstaller.backend.Paths;
[852]52import net.oni2.aeinstaller.backend.RuntimeOptions;
[600]53import net.oni2.aeinstaller.backend.SizeFormatter;
[720]54import net.oni2.aeinstaller.backend.oni.OniLauncher;
[658]55import net.oni2.aeinstaller.backend.oni.OniSplit;
[749]56import net.oni2.aeinstaller.backend.oni.management.Initializer;
57import net.oni2.aeinstaller.backend.oni.management.InstallProgressListener;
58import net.oni2.aeinstaller.backend.oni.management.Installer;
[804]59import net.oni2.aeinstaller.backend.oni.management.tools.ToolInstallationList;
60import net.oni2.aeinstaller.backend.oni.management.tools.ToolsManager;
[648]61import net.oni2.aeinstaller.backend.packages.Package;
62import net.oni2.aeinstaller.backend.packages.PackageManager;
63import net.oni2.aeinstaller.backend.packages.Type;
[593]64import net.oni2.aeinstaller.gui.about.AboutDialog;
[648]65import net.oni2.aeinstaller.gui.corepackages.CorePackagesDialog;
[605]66import net.oni2.aeinstaller.gui.downloadwindow.Downloader;
[720]67import net.oni2.aeinstaller.gui.modtable.EApplyFilterTo;
[673]68import net.oni2.aeinstaller.gui.modtable.ModInstallSelectionListener;
[631]69import net.oni2.aeinstaller.gui.modtable.ModSelectionListener;
70import net.oni2.aeinstaller.gui.modtable.ModTable;
[658]71import net.oni2.aeinstaller.gui.modtable.ModTable.ETableContentType;
72import net.oni2.aeinstaller.gui.packageinfobox.PackageInfoBox;
[591]73import net.oni2.aeinstaller.gui.settings.SettingsDialog;
[625]74import net.oni2.aeinstaller.gui.toolmanager.ToolManager;
[749]75import net.oni2.moddepot.DepotManager;
[720]76import net.oni2.platformtools.PlatformInformation;
77import net.oni2.platformtools.PlatformInformation.Platform;
78import net.oni2.platformtools.applicationinvoker.ApplicationInvoker;
79import net.oni2.platformtools.applicationinvoker.ERuntimeNotInstalledException;
[840]80import net.oni2.resourcebundle.UTF8ResourceBundleLoader;
[591]81
82import org.javabuilders.BuildResult;
83import org.javabuilders.annotations.DoInBackground;
84import org.javabuilders.event.BackgroundEvent;
85import org.javabuilders.swing.SwingJavaBuilder;
[593]86import org.simplericity.macify.eawt.ApplicationEvent;
87import org.simplericity.macify.eawt.ApplicationListener;
[591]88
89/**
90 * @author Christian Illy
91 */
[600]92public class MainWin extends JFrame implements ApplicationListener,
[673]93 ModInstallSelectionListener, ModSelectionListener {
[591]94 private static final long serialVersionUID = -4027395051382659650L;
95
[840]96 private ResourceBundle bundle = UTF8ResourceBundleLoader
[629]97 .getBundle("net.oni2.aeinstaller.localization."
98 + getClass().getSimpleName());
[591]99 @SuppressWarnings("unused")
100 private BuildResult result = SwingJavaBuilder.build(this, bundle);
101
[593]102 private JMenu mainMenu;
[623]103 private JMenu toolsMenu;
[641]104 private Vector<JMenuItem> toolsMenuItems = new Vector<JMenuItem>();
[593]105
[592]106 private JSplitPane contents;
107
[591]108 private JComboBox cmbModTypes;
[630]109 private JRadioButton radAll;
110 private JRadioButton radOnline;
111 private JRadioButton radLocal;
[805]112 private JRadioButton radInstalled;
[817]113 private JButton btnShowHelp;
[660]114 private JTextField txtShowFilter;
115 private JComboBox cmbShowFilterTo;
[658]116 private JScrollPane scrollMods;
[631]117 private ModTable tblMods;
[673]118 private JLabel lblSelectedModsVal;
[600]119 private JLabel lblDownloadSizeVal;
[591]120
[658]121 private PackageInfoBox pkgInfo;
[660]122
[600]123 private JButton btnInstall;
124
[648]125 private TreeSet<Package> execCoreUpdates = new TreeSet<Package>();
126 private TreeSet<Package> execUpdates = null;
[621]127
[641]128 private enum EInstallState {
[621]129 DONE,
[641]130 READY,
131 ABORTED,
[621]132 OFFLINE,
[641]133 INCOMPATIBLE,
134 CHECKING
[621]135 };
136
[641]137 private EInstallState installState = EInstallState.DONE;
[648]138 private TreeSet<Package> installMods = null;
139 private TreeSet<Package> installDeps = null;
[621]140
[591]141 /**
142 * Constructor of main window.
143 */
144 public MainWin() {
[593]145 this.setTitle(SwingJavaBuilder.getConfig().getResource("appname")
146 + SwingJavaBuilder.getConfig().getResource("appversion"));
[591]147
[658]148 tblMods = new ModTable(ETableContentType.MODS);
149 tblMods.setVisible(false);
150 scrollMods.setViewportView(tblMods);
151
[720]152 contents.setDividerLocation(SettingsManager.getInstance().get(
[772]153 "win_main_divloc", 700));
[631]154 contents.setResizeWeight(0.4);
[593]155
[720]156 if (PlatformInformation.getPlatform() == Platform.MACOS) {
[593]157 mainMenu.setVisible(false);
[817]158 } else {
159 btnShowHelp.setVisible(false);
[593]160 }
[600]161
[631]162 ToolTipManager.sharedInstance().setInitialDelay(250);
163
[600]164 getRootPane().setDefaultButton(btnInstall);
[673]165 lblSelectedModsVal.setText("0");
[605]166 lblDownloadSizeVal.setText(SizeFormatter.format(0, 2));
[630]167 radAll.setSelected(true);
[631]168
[660]169 for (EApplyFilterTo f : EApplyFilterTo.values()) {
170 cmbShowFilterTo.addItem(f);
171 }
172 txtShowFilter.addKeyListener(new KeyAdapter() {
173 @Override
174 public void keyReleased(KeyEvent e) {
175 super.keyReleased(e);
176 updateTableFilter();
177 }
178 });
179
[631]180 tblMods.addModSelectionListener(this);
181 tblMods.addDownloadSizeListener(this);
[720]182
[772]183 setSize(SettingsManager.getInstance().get("win_main_width", 1050),
[720]184 SettingsManager.getInstance().get("win_main_height", 600));
[701]185 setLocationRelativeTo(null);
[591]186 }
187
188 private void initModTypeBox() {
[592]189 cmbModTypes.removeAllItems();
190
[600]191 TreeMap<String, Type> types = new TreeMap<String, Type>();
[648]192 for (Type t : PackageManager.getInstance().getTypesWithContent()) {
[600]193 types.put(t.getName(), t);
[591]194 }
[630]195 cmbModTypes.addItem("-All-");
[600]196 for (Type t : types.values()) {
[591]197 cmbModTypes.addItem(t);
198 }
199 cmbModTypes.setSelectedIndex(0);
200 }
201
202 private void exit() {
203 dispose();
[608]204 System.exit(0);
[591]205 }
206
207 private void saveLocalData() {
[720]208 SettingsManager.getInstance().put("win_main_divloc",
209 contents.getDividerLocation());
210 SettingsManager.getInstance().put("win_main_width", getWidth());
211 SettingsManager.getInstance().put("win_main_height", getHeight());
212 SettingsManager.getInstance().serializeToFile(
213 Paths.getSettingsFilename());
[591]214 }
215
216 @DoInBackground(progressMessage = "updateDepot.title", cancelable = false, indeterminateProgress = false)
217 private void execDepotUpdate(final BackgroundEvent evt) {
[857]218 boolean hasUpdated = false;
[852]219 if (!RuntimeOptions.isOfflineMode()
220 && !RuntimeOptions.isNoCacheUpdateMode()) {
[634]221 long start = new Date().getTime();
[858]222 hasUpdated = DepotManager.getInstance().updateInformation();
[634]223 System.out.println("Took: " + (new Date().getTime() - start)
224 + " msec");
[621]225 }
[633]226
[860]227 PackageManager.loadFromCacheFile(Paths.getPacManCacheFilename());
228
[857]229 if (hasUpdated || !Paths.getPacManCacheFilename().exists()) {
230 PackageManager.getInstance().init();
231 PackageManager.getInstance().saveToCacheFile(
232 Paths.getPacManCacheFilename());
[860]233 }
[631]234 tblMods.reloadData();
[621]235 initModTypeBox();
[600]236
[621]237 tblMods.setVisible(true);
238 }
239
240 @SuppressWarnings("unused")
241 private void checkUpdates(Object evtSource) {
242 if ((evtSource != this)
[720]243 || SettingsManager.getInstance().get("notifyupdates", true)) {
[852]244 if (RuntimeOptions.isOfflineMode()) {
[621]245 if (evtSource != this) {
[657]246 JOptionPane.showMessageDialog(
247 this,
248 SwingJavaBuilder.getConfig().getResource(
249 "offlineMode.text"),
250 SwingJavaBuilder.getConfig().getResource(
251 "offlineMode.title"),
[621]252 JOptionPane.WARNING_MESSAGE);
253 }
254 } else {
[657]255 TreeSet<Package> mods = PackageManager.getInstance()
256 .getUpdatableMods();
[648]257 TreeSet<Package> tools = PackageManager.getInstance()
[621]258 .getUpdatableTools();
[632]259 JPanel panPackages = new JPanel(new GridLayout(0, 1));
[648]260 execUpdates = new TreeSet<Package>();
[632]261 execUpdates.addAll(mods);
262 execUpdates.addAll(tools);
[672]263 final JLabel lblSize = new JLabel("<html>"
264 + String.format(
265 bundle.getString("updatesAvailableSize.text"),
266 SizeFormatter.format(0, 3)) + "</html>");
267 int size = 0;
[648]268 for (final Package m : mods) {
[621]269 size += m.getZipSize();
[672]270 JCheckBox check = new JCheckBox("Mod: " + m.getName()
[720]271 + " (" + SizeFormatter.format(m.getZipSize(), 1)
272 + ")");
[632]273 check.setSelected(true);
274 check.addItemListener(new ItemListener() {
275 @Override
276 public void itemStateChanged(ItemEvent e) {
277 if (e.getStateChange() == ItemEvent.SELECTED)
278 execUpdates.add(m);
279 else
280 execUpdates.remove(m);
[672]281 int s = 0;
282 for (Package p : execUpdates)
283 s += p.getZipSize();
284 lblSize.setText("<html>"
285 + String.format(
286 bundle.getString("updatesAvailableSize.text"),
287 SizeFormatter.format(s, 3))
288 + "</html>");
[632]289 }
290 });
291 panPackages.add(check);
[621]292 }
[648]293 for (final Package m : tools) {
[621]294 size += m.getZipSize();
[672]295 JCheckBox check = new JCheckBox("Tool: " + m.getName()
[720]296 + " (" + SizeFormatter.format(m.getZipSize(), 1)
297 + ")");
[632]298 check.setSelected(true);
[672]299 check.addItemListener(new ItemListener() {
300 @Override
301 public void itemStateChanged(ItemEvent e) {
302 if (e.getStateChange() == ItemEvent.SELECTED)
303 execUpdates.add(m);
304 else
305 execUpdates.remove(m);
306 int s = 0;
307 for (Package p : execUpdates)
308 s += p.getZipSize();
309 lblSize.setText("<html>"
310 + String.format(
311 bundle.getString("updatesAvailableSize.text"),
312 SizeFormatter.format(s, 3))
313 + "</html>");
314 }
315 });
[632]316 panPackages.add(check);
[621]317 }
[672]318 lblSize.setText("<html>"
319 + String.format(
320 bundle.getString("updatesAvailableSize.text"),
321 SizeFormatter.format(size, 3)) + "</html>");
[622]322 if (size > 0) {
[627]323 // Build info dialog content
[632]324 JPanel packages = new JPanel(new BorderLayout(0, 7));
325 JLabel lblIntro = new JLabel("<html>"
326 + bundle.getString("updatesAvailable.text")
327 + "</html>");
328 packages.add(lblIntro, BorderLayout.NORTH);
329 packages.add(panPackages, BorderLayout.CENTER);
330 packages.add(lblSize, BorderLayout.SOUTH);
[627]331
[632]332 JPanel pan = new JPanel(new BorderLayout(0, 25));
333 pan.add(packages, BorderLayout.CENTER);
[627]334 JCheckBox checkFutureUpdates = new JCheckBox(
335 bundle.getString("checkOnStartup.text"));
[720]336 checkFutureUpdates.setSelected(SettingsManager
337 .getInstance().get("notifyupdates", true));
[627]338 checkFutureUpdates.addItemListener(new ItemListener() {
339 @Override
340 public void itemStateChanged(ItemEvent evt) {
[720]341 SettingsManager.getInstance().put("notifyupdates",
[627]342 evt.getStateChange() == ItemEvent.SELECTED);
343 }
344 });
345 pan.add(checkFutureUpdates, BorderLayout.SOUTH);
346
347 // Show dialog
348 int res = JOptionPane.showConfirmDialog(this, pan,
[622]349 bundle.getString("updatesAvailable.title"),
350 JOptionPane.YES_NO_OPTION,
351 JOptionPane.QUESTION_MESSAGE);
[632]352 if (res == JOptionPane.NO_OPTION) {
353 execUpdates = null;
[622]354 }
[656]355 } else {
356 if (evtSource != this) {
357 JOptionPane.showMessageDialog(this,
358 bundle.getString("updatesNotAvailable.text"),
359 bundle.getString("updatesNotAvailable.title"),
360 JOptionPane.INFORMATION_MESSAGE);
361 }
[621]362 }
363 }
[591]364 }
365 }
366
[624]367 @SuppressWarnings("unused")
368 private void doUpdate() {
[632]369 if (execUpdates != null && execUpdates.size() > 0) {
[773]370 Downloader dl = new Downloader(execUpdates, null, false);
[624]371 try {
372 dl.setVisible(true);
373 if (dl.isFinished()) {
[804]374 ToolInstallationList til = ToolInstallationList
375 .getInstance();
[648]376 TreeSet<Package> tools = new TreeSet<Package>();
377 for (Package m : execUpdates)
[804]378 if (m.isTool() && til.isInstalled(m.getPackageNumber()))
[624]379 tools.add(m);
380 if (tools.size() > 0) {
[804]381 ToolsManager.installTools(tools, true);
[749]382 ToolsManager.installTools(tools, false);
[624]383 }
384 }
385 } finally {
386 dl.dispose();
387 }
[591]388 }
[621]389 execUpdates = null;
[591]390 }
391
392 @SuppressWarnings("unused")
[860]393 private void showNewPackages() {
394 PackageManager pm = PackageManager.getInstance();
395 if ((pm.getNewModsOnDepot().size() >= pm.getModsValidAndNotCore()
396 .size())
397 || (pm.getNewToolsOnDepot().size() >= pm.getTools().size()))
398 return;
399 if (SettingsManager.getInstance().get("notifynewpackages", true)) {
400 if (pm.getNewModsOnDepot().size() > 0
401 || pm.getNewToolsOnDepot().size() > 0) {
402 TreeSet<Package> mods = new TreeSet<Package>(pm
403 .getNewModsOnDepot().values());
404 TreeSet<Package> tools = new TreeSet<Package>(pm
405 .getNewToolsOnDepot().values());
406 StringBuffer modsString = new StringBuffer();
407 StringBuffer toolsString = new StringBuffer();
408 for (final Package m : mods) {
409 modsString.append("<li>" + m.getName() + "</li>");
410 }
411 for (final Package m : tools) {
412 toolsString.append("<li>" + m.getName() + "</li>");
413 }
414 // Build info dialog content
415 String message = "<html>"
416 + bundle.getString("newPackages.text") + "</html>";
417 if (modsString.length() > 0) {
418 modsString.insert(0, "Mods:<ul>");
419 modsString.append("</ul>");
420 message = message.replaceAll("%1", modsString.toString());
421 } else {
422 message = message.replaceAll("%1", "");
423 }
424 if (toolsString.length() > 0) {
425 toolsString.insert(0, "Tools:<ul>");
426 toolsString.append("</ul>");
427 message = message.replaceAll("%2", toolsString.toString());
428 } else {
429 message = message.replaceAll("%2", "");
430 }
431
432 JPanel pan = new JPanel(new BorderLayout(0, 25));
433 JLabel lblTxt = new JLabel(message);
434 pan.add(lblTxt, BorderLayout.CENTER);
435 JCheckBox checkFutureUpdates = new JCheckBox(
436 bundle.getString("checkNewPackagesOnStartup.text"));
437 checkFutureUpdates.setSelected(SettingsManager.getInstance()
438 .get("notifynewpackages", true));
439 checkFutureUpdates.addItemListener(new ItemListener() {
440 @Override
441 public void itemStateChanged(ItemEvent evt) {
442 SettingsManager.getInstance().put("notifynewpackages",
443 evt.getStateChange() == ItemEvent.SELECTED);
444 }
445 });
446 pan.add(checkFutureUpdates, BorderLayout.SOUTH);
447
448 JOptionPane.showMessageDialog(this, pan,
449 bundle.getString("newPackages.title"),
450 JOptionPane.INFORMATION_MESSAGE);
451 }
452 }
453 }
454
455 @SuppressWarnings("unused")
[591]456 private void focus() {
457 SwingUtilities.invokeLater(new Runnable() {
458
459 @Override
460 public void run() {
461 toFront();
462 repaint();
463 }
464 });
465
466 }
[646]467
[645]468 @SuppressWarnings("unused")
[648]469 private void showCorePackagesDialog() {
470 new CorePackagesDialog().setVisible(true);
[645]471 }
[591]472
473 private void showSettings() {
[593]474 new SettingsDialog().setVisible(true);
[591]475 }
476
[593]477 private void showAbout() {
478 new AboutDialog().setVisible(true);
479 }
[807]480
[806]481 @SuppressWarnings("unused")
482 private void showHelp() {
483 try {
484 Desktop.getDesktop().browse(new URI("http://wiki.oni2.net/AEI"));
485 } catch (IOException e) {
486 e.printStackTrace();
487 } catch (URISyntaxException e) {
488 e.printStackTrace();
489 }
490 }
[593]491
[604]492 private JFileChooser getConfigOpenSaveDialog(boolean save) {
493 JFileChooser fc = new JFileChooser();
494 fc.setCurrentDirectory(Paths.getEditionBasePath());
495 if (save)
496 fc.setDialogType(JFileChooser.SAVE_DIALOG);
497 else
498 fc.setDialogType(JFileChooser.OPEN_DIALOG);
499 fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
500 fc.setFileFilter(new FileFilter() {
501 @Override
502 public String getDescription() {
503 return "XML files";
504 }
505
506 @Override
507 public boolean accept(File arg0) {
508 return (arg0.isDirectory())
509 || (arg0.getName().toLowerCase().endsWith(".xml"));
510 }
511 });
512 fc.setMultiSelectionEnabled(false);
513 return fc;
514 }
515
[593]516 @SuppressWarnings("unused")
517 private void loadConfig() {
[604]518 JFileChooser fc = getConfigOpenSaveDialog(false);
519 int res = fc.showOpenDialog(this);
520 if (res == JFileChooser.APPROVE_OPTION) {
521 if (fc.getSelectedFile().exists())
[631]522 tblMods.reloadSelection(fc.getSelectedFile());
[604]523 }
[593]524 }
525
526 @SuppressWarnings("unused")
527 private void saveConfig() {
[604]528 JFileChooser fc = getConfigOpenSaveDialog(true);
529 int res = fc.showSaveDialog(this);
530 if (res == JFileChooser.APPROVE_OPTION) {
531 File f = fc.getSelectedFile();
532 if (!f.getName().endsWith(".xml"))
533 f = new File(f.getParentFile(), f.getName() + ".xml");
[648]534 PackageManager.getInstance().saveModSelection(f,
[631]535 tblMods.getSelectedMods());
[604]536 }
[593]537 }
538
[661]539 @SuppressWarnings("unused")
[807]540 private void copyConfig() {
541 StringBuffer b = new StringBuffer();
542 b.append("[code]");
543 for (Package p : PackageManager.getInstance().getInstalledMods())
544 b.append(String.format("%s %s%n", p.getPackageNumberString(),
545 p.getName()));
546 b.append("[/code]");
[810]547
[807]548 StringSelection selection = new StringSelection(b.toString());
[810]549 Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
550 clipboard.setContents(selection, selection);
[807]551 }
552
553 @SuppressWarnings("unused")
[661]554 private boolean reglobalizeVerify() {
555 int res = JOptionPane.showConfirmDialog(this,
556 bundle.getString("rebuildCore.text"),
557 bundle.getString("rebuildCore.title"),
558 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
559 return res == JOptionPane.YES_OPTION;
560 }
561
[600]562 @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false)
563 private void reglobalize(final BackgroundEvent evt) {
[749]564 Initializer.initializeEdition(new InstallProgressListener() {
[600]565 @Override
566 public void installProgressUpdate(int done, int total, String step) {
567 evt.setProgressEnd(total);
568 evt.setProgressValue(done);
569 evt.setProgressMessage(step);
570 }
571 });
572 }
[860]573
[859]574 @SuppressWarnings("unused")
575 private void refreshLocalMods() {
576 PackageManager.getInstance().updateLocalData();
577 }
[600]578
[593]579 @SuppressWarnings("unused")
[600]580 private void tools() {
[625]581 new ToolManager().setVisible(true);
[593]582 }
[596]583
[593]584 @SuppressWarnings("unused")
[623]585 private void refreshToolsMenu() {
586 for (JMenuItem i : toolsMenuItems) {
587 toolsMenu.remove(i);
588 }
589 toolsMenuItems.clear();
[672]590 for (final Package m : PackageManager.getInstance().getInstalledTools()) {
[640]591 File exe = m.getExeFile();
592 if (exe != null && exe.exists()) {
[623]593 JMenuItem item = new JMenuItem();
[671]594 ImageIcon ico = null;
[623]595 if (m.getIconFile() != null && m.getIconFile().exists()) {
596 ico = new ImageIcon(m.getIconFile().getPath());
597 } else {
[624]598 URL icon = AEInstaller2.class
599 .getResource("images/transparent.png");
[623]600 ico = new ImageIcon(icon);
601 }
[671]602 ico = ImageResizer.resizeImage(ico, 32, 32);
[623]603 item.setAction(new AbstractAction(m.getName(), ico) {
604 private static final long serialVersionUID = 1L;
605
606 @Override
[672]607 public void actionPerformed(ActionEvent evt) {
608 try {
[720]609 ApplicationInvoker.execute(m.getExeType(),
[773]610 m.getWorkingDir(), m.getExeFile(), null,
611 false);
[720]612 } catch (ERuntimeNotInstalledException e) {
613 JOptionPane.showMessageDialog(null,
614 bundle.getString("exeNotFound.text"),
615 bundle.getString("exeNotFound.title"),
616 JOptionPane.ERROR_MESSAGE);
617 e.printStackTrace();
618 } catch (FileNotFoundException e) {
619 if (e.getMessage().contains("JRE"))
[672]620 JOptionPane.showMessageDialog(null,
621 bundle.getString("jreNotFound.text"),
622 bundle.getString("jreNotFound.title"),
623 JOptionPane.ERROR_MESSAGE);
[720]624 if (e.getMessage().contains(".NET"))
[673]625 JOptionPane.showMessageDialog(
626 null,
[672]627 bundle.getString("dotNetNotFound.text"),
628 bundle.getString("dotNetNotFound.title"),
629 JOptionPane.ERROR_MESSAGE);
[720]630 if (e.getMessage().contains("Wine"))
631 JOptionPane.showMessageDialog(null,
632 bundle.getString("wineNotFound.text"),
633 bundle.getString("wineNotFound.title"),
634 JOptionPane.ERROR_MESSAGE);
635 e.printStackTrace();
[672]636 }
[623]637 }
638 });
639 toolsMenuItems.add(item);
640 toolsMenu.add(item);
641 }
642 }
643 }
644
[593]645 private void revertSelection() {
[631]646 tblMods.revertSelection();
[593]647 }
[658]648
[657]649 @SuppressWarnings("unused")
650 private void unSelectAll() {
651 tblMods.unSelectAll();
652 }
[593]653
[773]654 @SuppressWarnings("unused")
655 private void checkCorePackages() {
[852]656 if (!RuntimeOptions.isOfflineMode()) {
[804]657 TreeSet<Package> tools = new TreeSet<Package>();
[648]658 for (Package m : PackageManager.getInstance().getCoreTools()) {
[621]659 if (m.isNewerAvailable()) {
[648]660 execCoreUpdates.add(m);
[804]661 tools.add(m);
[840]662 } else if (!m.isInstalled())
663 tools.add(m);
[604]664 }
[648]665 for (Package m : PackageManager.getInstance().getCoreMods()) {
[621]666 if (m.isNewerAvailable()) {
[648]667 execCoreUpdates.add(m);
[621]668 }
[604]669 }
[648]670 if (execCoreUpdates.size() > 0) {
[773]671 Downloader dl = new Downloader(execCoreUpdates, null, true);
672 try {
673 dl.setVisible(true);
674 } finally {
675 dl.dispose();
[604]676 }
677 }
[804]678
679 ToolsManager.installTools(tools, true);
680 ToolsManager.installTools(tools, false);
[604]681 }
[804]682 ToolsManager.verifyToolsIntegrity();
683 if (ToolInstallationList.getInstance().getModifiedTools().size() > 0)
684 System.out.println("Locally modified tools: "
685 + ToolInstallationList.getInstance().getModifiedTools()
686 .toString());
[602]687 }
688
[641]689 @SuppressWarnings("unused")
[648]690 private void infoCorePackages() {
691 if (execCoreUpdates.size() > 0) {
[645]692 String packages = "";
[648]693 for (Package m : execCoreUpdates) {
[645]694 packages += String.format("\n - %s (%s)", m.getName(),
695 m.getVersion());
696 }
697 JOptionPane.showMessageDialog(this, String.format(
[648]698 bundle.getString("corePackagesUpdated.text"), packages),
699 bundle.getString("corePackagesUpdated.title"),
[645]700 JOptionPane.INFORMATION_MESSAGE);
701 }
702 }
703
704 @SuppressWarnings("unused")
[641]705 private void install() {
[648]706 TreeSet<Package> mods = new TreeSet<Package>();
707 mods.addAll(PackageManager.getInstance().getCoreMods());
[631]708 mods.addAll(tblMods.getSelectedMods());
[600]709
[648]710 installDeps = new TreeSet<Package>();
[646]711
[641]712 installState = EInstallState.CHECKING;
[605]713
[641]714 while (installState == EInstallState.CHECKING) {
[648]715 TreeSet<Package> toDownload = new TreeSet<Package>();
716 for (Package m : mods) {
[605]717 if (!m.isLocalAvailable())
718 toDownload.add(m);
719 }
[669]720
[852]721 if (toDownload.size() > 0 && RuntimeOptions.isOfflineMode()) {
[641]722 installState = EInstallState.OFFLINE;
[621]723 break;
724 }
[669]725
[605]726 if (toDownload.size() > 0) {
[773]727 Downloader dl = new Downloader(toDownload, installDeps, false);
[617]728 try {
729 dl.setVisible(true);
[641]730 if (!dl.isFinished()) {
731 installState = EInstallState.ABORTED;
[617]732 break;
[641]733 }
[617]734 } finally {
735 dl.dispose();
736 }
[605]737 }
[669]738
[657]739 HashMap<Package, HashSet<Package>> dependencies = PackageManager
740 .getInstance().checkDependencies(mods);
[605]741 if (dependencies.size() > 0) {
[648]742 for (HashSet<Package> hm : dependencies.values()) {
[646]743 installDeps.addAll(hm);
744 }
[647]745
[669]746 int size = 0;
747 String depsLocalString = "";
748 String depsDownloadString = "";
749 for (Package m : dependencies.keySet()) {
750 for (Package mDep : dependencies.get(m)) {
751 if (!mods.contains(mDep)) {
752 mods.add(mDep);
753 if (!mDep.isLocalAvailable()) {
754 size += mDep.getZipSize();
755 if (depsDownloadString.length() > 0)
756 depsDownloadString += "\n";
757 depsDownloadString += " - " + mDep.getName();
758 } else {
759 if (depsLocalString.length() > 0)
760 depsLocalString += "\n";
761 depsLocalString += " - " + mDep.getName();
[641]762 }
763 }
764 }
[669]765 }
[641]766
[669]767 if (depsLocalString.length() == 0)
768 depsLocalString = bundle
769 .getString("installDependencies.none");
770 if (depsDownloadString.length() == 0)
771 depsDownloadString = bundle
772 .getString("installDependencies.none");
773
[720]774 if (!SettingsManager.getInstance().get(
775 "notifyDepsAfterInstall", false)) {
[646]776 int res = JOptionPane.showConfirmDialog(this, String
777 .format(bundle
778 .getString("installDependencies.text"),
779 depsLocalString, depsDownloadString,
780 SizeFormatter.format(size, 3)), bundle
781 .getString("installDependencies.title"),
782 JOptionPane.YES_NO_OPTION,
783 JOptionPane.INFORMATION_MESSAGE);
[669]784
[646]785 if (res == JOptionPane.NO_OPTION) {
786 installState = EInstallState.ABORTED;
787 break;
788 }
[641]789 }
[605]790 } else {
[648]791 HashMap<Package, HashSet<Package>> incompatibilities = PackageManager
[645]792 .getInstance().checkIncompabitilites(mods);
[643]793 if (incompatibilities.size() > 0) {
[641]794 installState = EInstallState.INCOMPATIBLE;
[643]795
796 String incompatString = "";
[648]797 for (Package m : incompatibilities.keySet()) {
[643]798 if (incompatString.length() > 0)
799 incompatString += "\n";
800 incompatString += m.getName() + ": ";
801 String confMods = "";
[648]802 for (Package mConf : incompatibilities.get(m)) {
[643]803 if (confMods.length() > 0)
804 confMods += ", ";
805 confMods += mConf.getName();
806 }
807 incompatString += confMods;
808 }
809
810 JOptionPane.showMessageDialog(this, String.format(
811 bundle.getString("installIncompatibilities.text"),
812 incompatString), bundle
813 .getString("installIncompatibilities.title"),
814 JOptionPane.ERROR_MESSAGE);
[605]815 break;
816 } else {
[641]817 installState = EInstallState.READY;
[605]818 }
819 }
[600]820 }
[618]821
[641]822 if (installState == EInstallState.READY) {
[648]823 installMods = new TreeSet<Package>();
824 TreeSet<Package> actuallyTools = new TreeSet<Package>();
[623]825
[648]826 for (Package m : mods) {
[623]827 if (m.isTool())
828 actuallyTools.add(m);
829 else
[641]830 installMods.add(m);
[623]831 }
832
833 if (actuallyTools.size() > 0) {
[749]834 ToolsManager.installTools(actuallyTools, false);
[623]835 }
[641]836 }
837 }
838
839 @DoInBackground(progressMessage = "installing.title", cancelable = false, indeterminateProgress = false)
840 private void installExec(final BackgroundEvent evt) {
841 if (installState == EInstallState.READY) {
842 Installer.install(installMods, new InstallProgressListener() {
[605]843 @Override
844 public void installProgressUpdate(int done, int total,
845 String step) {
846 evt.setProgressEnd(total);
847 evt.setProgressValue(done);
848 evt.setProgressMessage(step);
849 }
850 });
[641]851 installState = EInstallState.DONE;
[605]852 }
[641]853 installMods = null;
[600]854 }
[618]855
[617]856 @SuppressWarnings("unused")
857 private void installDone() {
[641]858 switch (installState) {
[621]859 case DONE:
[641]860 revertSelection();
[646]861 if (installDeps.size() > 0
[720]862 && SettingsManager.getInstance().get(
863 "notifyDepsAfterInstall", false)) {
[646]864 String installedDeps = "";
[648]865 for (Package m : installDeps) {
[646]866 if (installedDeps.length() > 0)
867 installedDeps += "\n";
868 installedDeps += " - " + m.getName();
869 }
870 JOptionPane.showMessageDialog(this, String.format(
871 bundle.getString("installDoneDeps.text"),
872 installedDeps), bundle
873 .getString("installDone.title"),
874 JOptionPane.INFORMATION_MESSAGE);
875 } else {
876 JOptionPane.showMessageDialog(this,
877 bundle.getString("installDone.text"),
878 bundle.getString("installDone.title"),
879 JOptionPane.INFORMATION_MESSAGE);
880 }
[621]881 break;
882 case OFFLINE:
[657]883 JOptionPane.showMessageDialog(
884 this,
885 SwingJavaBuilder.getConfig().getResource(
886 "offlineMode.text"),
887 SwingJavaBuilder.getConfig().getResource(
888 "offlineMode.title"),
[621]889 JOptionPane.WARNING_MESSAGE);
890 break;
[641]891 default:
[621]892 break;
893 }
[646]894 installDeps = null;
[617]895 }
[600]896
[631]897 @Override
[648]898 public void modSelectionChanged(ModTable source, Package m) {
[658]899 pkgInfo.updateInfo(m);
[591]900 }
[807]901
[805]902 @SuppressWarnings("unused")
903 private void clearFilter() {
904 txtShowFilter.setText("");
905 updateTableFilter();
906 }
[591]907
[630]908 private void updateTableFilter() {
909 Object o = cmbModTypes.getSelectedItem();
910 Type t = null;
911 if (o instanceof Type)
912 t = (Type) o;
913 int downloadState = 0;
914 if (radOnline.isSelected())
915 downloadState = 1;
916 if (radLocal.isSelected())
917 downloadState = 2;
[805]918 if (radInstalled.isSelected())
919 downloadState = 3;
[660]920 tblMods.setFilter(t, downloadState, txtShowFilter.getText(),
921 (EApplyFilterTo) cmbShowFilterTo.getSelectedItem());
[630]922 }
923
[593]924 @Override
[673]925 public void modInstallSelectionChanged(int newSize, int newCount) {
926 lblSelectedModsVal.setText(String.valueOf(newCount));
[600]927 lblDownloadSizeVal.setText(SizeFormatter.format(newSize, 2));
928 }
929
[616]930 @SuppressWarnings("unused")
931 private void checkInitialize() {
[600]932 if (!Installer.isEditionInitialized()) {
[621]933 if (!OniSplit.isOniSplitInstalled()) {
934 JOptionPane.showMessageDialog(this,
935 bundle.getString("noOniSplit.text"),
936 bundle.getString("noOniSplit.title"),
937 JOptionPane.ERROR_MESSAGE);
[600]938 exit();
[621]939 } else {
940 int res = JOptionPane
941 .showConfirmDialog(this,
942 bundle.getString("askInitialize.text"),
943 bundle.getString("askInitialize.title"),
944 JOptionPane.YES_NO_OPTION,
945 JOptionPane.QUESTION_MESSAGE);
946 if (res == JOptionPane.NO_OPTION) {
947 saveLocalData();
948 exit();
949 }
[600]950 }
951 }
952 }
[606]953
[616]954 @DoInBackground(progressMessage = "initializingEdition.title", cancelable = false, indeterminateProgress = false)
955 private void initialize(final BackgroundEvent evt) {
956 if (!Installer.isEditionInitialized()) {
[749]957 Initializer.initializeEdition(new InstallProgressListener() {
[616]958 @Override
959 public void installProgressUpdate(int done, int total,
960 String step) {
961 evt.setProgressEnd(total);
962 evt.setProgressValue(done);
963 evt.setProgressMessage(step);
964 }
965 });
966 }
967 }
968
[720]969 private void oni(boolean windowed) {
[810]970 if (!Paths.getEditionGDF().isDirectory()) {
[720]971 JOptionPane.showMessageDialog(this,
[810]972 bundle.getString("notInstalled.text"),
973 bundle.getString("notInstalled.title"),
974 JOptionPane.WARNING_MESSAGE);
975 } else {
976 try {
977 OniLauncher.launch(windowed);
978 } catch (FileNotFoundException e) {
979 JOptionPane.showMessageDialog(this,
980 bundle.getString("oniExeNotFound.text"),
981 bundle.getString("oniExeNotFound.title"),
982 JOptionPane.ERROR_MESSAGE);
983 e.printStackTrace();
984 } catch (ERuntimeNotInstalledException e) {
985 JOptionPane.showMessageDialog(this,
986 bundle.getString("wineNotFound.text"),
987 bundle.getString("wineNotFound.title"),
988 JOptionPane.ERROR_MESSAGE);
989 e.printStackTrace();
990 }
[605]991 }
992 }
[600]993
[605]994 @SuppressWarnings("unused")
995 private void oniFull() {
[720]996 oni(false);
[605]997 }
998
999 @SuppressWarnings("unused")
1000 private void oniWin() {
[720]1001 oni(true);
[605]1002 }
1003
[608]1004 @SuppressWarnings("unused")
1005 private void openEditionFolder() {
1006 try {
1007 Desktop.getDesktop().open(Paths.getEditionBasePath());
[639]1008 } catch (Exception e) {
[608]1009 e.printStackTrace();
1010 }
1011 }
1012
[600]1013 @Override
[593]1014 public void handleAbout(ApplicationEvent event) {
1015 event.setHandled(true);
1016 showAbout();
1017 }
1018
1019 @Override
1020 public void handleOpenApplication(ApplicationEvent event) {
1021 }
1022
1023 @Override
1024 public void handleOpenFile(ApplicationEvent event) {
1025 }
1026
1027 @Override
1028 public void handlePreferences(ApplicationEvent event) {
1029 showSettings();
1030 }
1031
1032 @Override
1033 public void handlePrintFile(ApplicationEvent event) {
1034 }
1035
1036 @Override
1037 public void handleQuit(ApplicationEvent event) {
[605]1038 event.setHandled(true);
1039 saveLocalData();
1040 exit();
[593]1041 }
1042
1043 @Override
1044 public void handleReOpenApplication(ApplicationEvent event) {
1045 }
[600]1046
[592]1047}
Note: See TracBrowser for help on using the repository browser.