[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 |
|
---|
[720] | 19 | import net.oni2.SettingsManager;
|
---|
[804] | 20 | import net.oni2.aeinstaller.backend.oni.management.tools.ToolsManager;
|
---|
[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;
|
---|
[840] | 27 | import net.oni2.resourcebundle.UTF8ResourceBundleLoader;
|
---|
[626] | 28 |
|
---|
| 29 | import org.javabuilders.BuildResult;
|
---|
| 30 | import org.javabuilders.swing.SwingJavaBuilder;
|
---|
| 31 |
|
---|
[625] | 32 | /**
|
---|
| 33 | * @author Christian Illy
|
---|
| 34 | */
|
---|
[658] | 35 | public class ToolManager extends JDialog implements ModSelectionListener {
|
---|
[625] | 36 | private static final long serialVersionUID = 343221630538866384L;
|
---|
| 37 |
|
---|
[840] | 38 | private ResourceBundle bundle = UTF8ResourceBundleLoader
|
---|
[629] | 39 | .getBundle("net.oni2.aeinstaller.localization."
|
---|
| 40 | + getClass().getSimpleName());
|
---|
[626] | 41 | @SuppressWarnings("unused")
|
---|
| 42 | private BuildResult result = SwingJavaBuilder.build(this, bundle);
|
---|
| 43 |
|
---|
[637] | 44 | private JSplitPane contents;
|
---|
[640] | 45 |
|
---|
[658] | 46 | private JScrollPane scrollTools;
|
---|
| 47 | private ModTable tblTools;
|
---|
[626] | 48 |
|
---|
[658] | 49 | private PackageInfoBox pkgInfo;
|
---|
[626] | 50 | private JButton btnInstall;
|
---|
| 51 |
|
---|
[637] | 52 | private Icon icoInstall = null;
|
---|
| 53 | private Icon icoUninstall = null;
|
---|
| 54 |
|
---|
[658] | 55 | private Package selectedPackage = null;
|
---|
[646] | 56 |
|
---|
[626] | 57 | /**
|
---|
| 58 | * Open the dialog
|
---|
| 59 | */
|
---|
| 60 | public ToolManager() {
|
---|
| 61 | AbstractAction closeAction = new AbstractAction() {
|
---|
| 62 |
|
---|
| 63 | private static final long serialVersionUID = 1L;
|
---|
| 64 |
|
---|
| 65 | public void actionPerformed(ActionEvent arg0) {
|
---|
| 66 | dispose();
|
---|
| 67 | }
|
---|
| 68 | };
|
---|
| 69 | KeyStroke ksCtrlW = KeyStroke
|
---|
| 70 | .getKeyStroke('W', KeyEvent.CTRL_DOWN_MASK);
|
---|
| 71 | getRootPane()
|
---|
| 72 | .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
|
---|
| 73 | .put(ksCtrlW, "close");
|
---|
| 74 | getRootPane().getActionMap().put("close", closeAction);
|
---|
| 75 |
|
---|
[840] | 76 | contents.setDividerLocation(SettingsManager.getInstance().get(
|
---|
| 77 | "win_tools_divloc", 550));
|
---|
[637] | 78 | contents.setResizeWeight(0.4);
|
---|
| 79 |
|
---|
[658] | 80 | tblTools = new ModTable(ETableContentType.TOOLS);
|
---|
| 81 | tblTools.reloadData();
|
---|
| 82 | scrollTools.setViewportView(tblTools);
|
---|
[626] | 83 |
|
---|
[658] | 84 | tblTools.addModSelectionListener(this);
|
---|
[637] | 85 |
|
---|
| 86 | icoInstall = new ImageIcon(getClass().getResource(
|
---|
| 87 | SwingJavaBuilder.getConfig().getResource("img.install")));
|
---|
| 88 | icoUninstall = new ImageIcon(getClass().getResource(
|
---|
| 89 | SwingJavaBuilder.getConfig().getResource("img.uninstall")));
|
---|
[646] | 90 |
|
---|
[840] | 91 | setSize(SettingsManager.getInstance().get("win_tools_width", 950),
|
---|
| 92 | SettingsManager.getInstance().get("win_tools_height", 600));
|
---|
[641] | 93 | setLocationRelativeTo(null);
|
---|
[626] | 94 | }
|
---|
| 95 |
|
---|
| 96 | @SuppressWarnings("unused")
|
---|
| 97 | private void install() {
|
---|
[658] | 98 | if (selectedPackage != null) {
|
---|
| 99 | if (selectedPackage.isInstalled()) {
|
---|
[648] | 100 | TreeSet<Package> tools = new TreeSet<Package>();
|
---|
[658] | 101 | tools.add(selectedPackage);
|
---|
[749] | 102 | ToolsManager.installTools(tools, true);
|
---|
[640] | 103 | } else {
|
---|
[658] | 104 | if (!selectedPackage.isLocalAvailable()) {
|
---|
[720] | 105 | if (SettingsManager.getInstance().isOfflineMode()) {
|
---|
[640] | 106 | JOptionPane.showMessageDialog(this,
|
---|
| 107 | bundle.getString("offlineMode.text"),
|
---|
| 108 | bundle.getString("offlineMode.title"),
|
---|
| 109 | JOptionPane.WARNING_MESSAGE);
|
---|
| 110 | return;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
[648] | 113 | TreeSet<Package> toDownload = new TreeSet<Package>();
|
---|
[658] | 114 | toDownload.add(selectedPackage);
|
---|
[640] | 115 |
|
---|
[773] | 116 | Downloader dl = new Downloader(toDownload, null, false);
|
---|
[640] | 117 | try {
|
---|
| 118 | dl.setVisible(true);
|
---|
| 119 | if (!dl.isFinished())
|
---|
| 120 | return;
|
---|
| 121 | } finally {
|
---|
| 122 | dl.dispose();
|
---|
| 123 | }
|
---|
| 124 | }
|
---|
| 125 |
|
---|
[648] | 126 | TreeSet<Package> tools = new TreeSet<Package>();
|
---|
[658] | 127 | tools.add(selectedPackage);
|
---|
[749] | 128 | ToolsManager.installTools(tools, false);
|
---|
[640] | 129 | }
|
---|
| 130 | }
|
---|
[658] | 131 | modSelectionChanged(tblTools, selectedPackage);
|
---|
[626] | 132 | }
|
---|
| 133 |
|
---|
| 134 | @Override
|
---|
[658] | 135 | public void modSelectionChanged(ModTable source, Package mod) {
|
---|
| 136 | selectedPackage = mod;
|
---|
[626] | 137 |
|
---|
[658] | 138 | pkgInfo.updateInfo(mod);
|
---|
| 139 | if (mod != null) {
|
---|
[626] | 140 | btnInstall.setEnabled(true);
|
---|
[658] | 141 | if (mod.isInstalled()) {
|
---|
[626] | 142 | btnInstall.setText(bundle.getString("btnInstall.un.text"));
|
---|
| 143 | btnInstall.setToolTipText(bundle
|
---|
| 144 | .getString("btnInstall.un.tooltip"));
|
---|
[637] | 145 | btnInstall.setIcon(icoUninstall);
|
---|
[626] | 146 | } else {
|
---|
| 147 | btnInstall.setText(bundle.getString("btnInstall.text"));
|
---|
| 148 | btnInstall.setToolTipText(bundle
|
---|
| 149 | .getString("btnInstall.tooltip"));
|
---|
[658] | 150 | btnInstall.setIcon(icoInstall);
|
---|
[626] | 151 | }
|
---|
| 152 | }
|
---|
| 153 | }
|
---|
[840] | 154 |
|
---|
[701] | 155 | @SuppressWarnings("unused")
|
---|
| 156 | private void closing() {
|
---|
[840] | 157 | SettingsManager.getInstance().put("win_tools_divloc",
|
---|
| 158 | contents.getDividerLocation());
|
---|
[720] | 159 | SettingsManager.getInstance().put("win_tools_width", getWidth());
|
---|
| 160 | SettingsManager.getInstance().put("win_tools_height", getHeight());
|
---|
[701] | 161 | }
|
---|
[625] | 162 | }
|
---|