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

Last change on this file since 1028 was 1023, checked in by alloc, 10 years ago

AEI 2.23: More strings in localization

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