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

Last change on this file since 928 was 892, checked in by alloc, 11 years ago

AEI2.16:

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