[625] | 1 | package net.oni2.aeinstaller.gui.toolmanager;
|
---|
| 2 |
|
---|
[626] | 3 | import java.awt.event.ActionEvent;
|
---|
| 4 | import java.awt.event.KeyEvent;
|
---|
| 5 | import java.util.ResourceBundle;
|
---|
[640] | 6 | import java.util.TreeSet;
|
---|
[626] | 7 |
|
---|
| 8 | import javax.swing.AbstractAction;
|
---|
[637] | 9 | import javax.swing.Icon;
|
---|
| 10 | import javax.swing.ImageIcon;
|
---|
[626] | 11 | import javax.swing.JButton;
|
---|
| 12 | import javax.swing.JComponent;
|
---|
[625] | 13 | import javax.swing.JDialog;
|
---|
[626] | 14 | import javax.swing.JOptionPane;
|
---|
[658] | 15 | import javax.swing.JScrollPane;
|
---|
[637] | 16 | import javax.swing.JSplitPane;
|
---|
[626] | 17 | import javax.swing.KeyStroke;
|
---|
[625] | 18 |
|
---|
[640] | 19 | import net.oni2.aeinstaller.backend.Settings;
|
---|
[658] | 20 | import net.oni2.aeinstaller.backend.oni.Installer;
|
---|
[648] | 21 | import net.oni2.aeinstaller.backend.packages.Package;
|
---|
[640] | 22 | import net.oni2.aeinstaller.gui.downloadwindow.Downloader;
|
---|
[658] | 23 | import net.oni2.aeinstaller.gui.modtable.ModSelectionListener;
|
---|
| 24 | import net.oni2.aeinstaller.gui.modtable.ModTable;
|
---|
| 25 | import net.oni2.aeinstaller.gui.modtable.ModTable.ETableContentType;
|
---|
| 26 | import net.oni2.aeinstaller.gui.packageinfobox.PackageInfoBox;
|
---|
[626] | 27 |
|
---|
| 28 | import org.javabuilders.BuildResult;
|
---|
| 29 | import org.javabuilders.swing.SwingJavaBuilder;
|
---|
| 30 |
|
---|
[625] | 31 | /**
|
---|
| 32 | * @author Christian Illy
|
---|
| 33 | */
|
---|
[658] | 34 | public class ToolManager extends JDialog implements ModSelectionListener {
|
---|
[625] | 35 | private static final long serialVersionUID = 343221630538866384L;
|
---|
| 36 |
|
---|
[629] | 37 | private ResourceBundle bundle = ResourceBundle
|
---|
| 38 | .getBundle("net.oni2.aeinstaller.localization."
|
---|
| 39 | + getClass().getSimpleName());
|
---|
[626] | 40 | @SuppressWarnings("unused")
|
---|
| 41 | private BuildResult result = SwingJavaBuilder.build(this, bundle);
|
---|
| 42 |
|
---|
[637] | 43 | private JSplitPane contents;
|
---|
[640] | 44 |
|
---|
[658] | 45 | private JScrollPane scrollTools;
|
---|
| 46 | private ModTable tblTools;
|
---|
[626] | 47 |
|
---|
[658] | 48 | private PackageInfoBox pkgInfo;
|
---|
[626] | 49 | private JButton btnInstall;
|
---|
| 50 |
|
---|
[637] | 51 | private Icon icoInstall = null;
|
---|
| 52 | private Icon icoUninstall = null;
|
---|
| 53 |
|
---|
[658] | 54 | private Package selectedPackage = null;
|
---|
[646] | 55 |
|
---|
[626] | 56 | /**
|
---|
| 57 | * Open the dialog
|
---|
| 58 | */
|
---|
| 59 | public ToolManager() {
|
---|
| 60 | AbstractAction closeAction = new AbstractAction() {
|
---|
| 61 |
|
---|
| 62 | private static final long serialVersionUID = 1L;
|
---|
| 63 |
|
---|
| 64 | public void actionPerformed(ActionEvent arg0) {
|
---|
| 65 | dispose();
|
---|
| 66 | }
|
---|
| 67 | };
|
---|
| 68 | KeyStroke ksCtrlW = KeyStroke
|
---|
| 69 | .getKeyStroke('W', KeyEvent.CTRL_DOWN_MASK);
|
---|
| 70 | getRootPane()
|
---|
| 71 | .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
|
---|
| 72 | .put(ksCtrlW, "close");
|
---|
| 73 | getRootPane().getActionMap().put("close", closeAction);
|
---|
| 74 |
|
---|
[658] | 75 | contents.setDividerLocation(550);
|
---|
[637] | 76 | contents.setResizeWeight(0.4);
|
---|
| 77 |
|
---|
[658] | 78 | tblTools = new ModTable(ETableContentType.TOOLS);
|
---|
| 79 | tblTools.reloadData();
|
---|
| 80 | scrollTools.setViewportView(tblTools);
|
---|
[626] | 81 |
|
---|
[658] | 82 | tblTools.addModSelectionListener(this);
|
---|
[637] | 83 |
|
---|
| 84 | icoInstall = new ImageIcon(getClass().getResource(
|
---|
| 85 | SwingJavaBuilder.getConfig().getResource("img.install")));
|
---|
| 86 | icoUninstall = new ImageIcon(getClass().getResource(
|
---|
| 87 | SwingJavaBuilder.getConfig().getResource("img.uninstall")));
|
---|
[646] | 88 |
|
---|
[641] | 89 | setLocationRelativeTo(null);
|
---|
[626] | 90 | }
|
---|
| 91 |
|
---|
| 92 | @SuppressWarnings("unused")
|
---|
| 93 | private void install() {
|
---|
[658] | 94 | if (selectedPackage != null) {
|
---|
| 95 | if (selectedPackage.isInstalled()) {
|
---|
[648] | 96 | TreeSet<Package> tools = new TreeSet<Package>();
|
---|
[658] | 97 | tools.add(selectedPackage);
|
---|
[699] | 98 | Installer.installTools(tools, true);
|
---|
[640] | 99 | } else {
|
---|
[658] | 100 | if (!selectedPackage.isLocalAvailable()) {
|
---|
[640] | 101 | if (Settings.getInstance().isOfflineMode()) {
|
---|
| 102 | JOptionPane.showMessageDialog(this,
|
---|
| 103 | bundle.getString("offlineMode.text"),
|
---|
| 104 | bundle.getString("offlineMode.title"),
|
---|
| 105 | JOptionPane.WARNING_MESSAGE);
|
---|
| 106 | return;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
[648] | 109 | TreeSet<Package> toDownload = new TreeSet<Package>();
|
---|
[658] | 110 | toDownload.add(selectedPackage);
|
---|
[640] | 111 |
|
---|
[646] | 112 | Downloader dl = new Downloader(toDownload, null);
|
---|
[640] | 113 | try {
|
---|
| 114 | dl.setVisible(true);
|
---|
| 115 | if (!dl.isFinished())
|
---|
| 116 | return;
|
---|
| 117 | } finally {
|
---|
| 118 | dl.dispose();
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
| 121 |
|
---|
[648] | 122 | TreeSet<Package> tools = new TreeSet<Package>();
|
---|
[658] | 123 | tools.add(selectedPackage);
|
---|
[699] | 124 | Installer.installTools(tools, false);
|
---|
[640] | 125 | }
|
---|
| 126 | }
|
---|
[658] | 127 | modSelectionChanged(tblTools, selectedPackage);
|
---|
[626] | 128 | }
|
---|
| 129 |
|
---|
| 130 | @Override
|
---|
[658] | 131 | public void modSelectionChanged(ModTable source, Package mod) {
|
---|
| 132 | selectedPackage = mod;
|
---|
[626] | 133 |
|
---|
[658] | 134 | pkgInfo.updateInfo(mod);
|
---|
| 135 | if (mod != null) {
|
---|
[626] | 136 | btnInstall.setEnabled(true);
|
---|
[658] | 137 | if (mod.isInstalled()) {
|
---|
[626] | 138 | btnInstall.setText(bundle.getString("btnInstall.un.text"));
|
---|
| 139 | btnInstall.setToolTipText(bundle
|
---|
| 140 | .getString("btnInstall.un.tooltip"));
|
---|
[637] | 141 | btnInstall.setIcon(icoUninstall);
|
---|
[626] | 142 | } else {
|
---|
| 143 | btnInstall.setText(bundle.getString("btnInstall.text"));
|
---|
| 144 | btnInstall.setToolTipText(bundle
|
---|
| 145 | .getString("btnInstall.tooltip"));
|
---|
[658] | 146 | btnInstall.setIcon(icoInstall);
|
---|
[626] | 147 | }
|
---|
| 148 | }
|
---|
| 149 | }
|
---|
[625] | 150 | }
|
---|