| 1 | package net.oni2.aeinstaller.gui.toolmanager;
|
|---|
| 2 |
|
|---|
| 3 | import java.awt.event.ActionEvent;
|
|---|
| 4 | import java.awt.event.KeyEvent;
|
|---|
| 5 | import java.util.ResourceBundle;
|
|---|
| 6 | import java.util.TreeSet;
|
|---|
| 7 |
|
|---|
| 8 | import javax.swing.AbstractAction;
|
|---|
| 9 | import javax.swing.Icon;
|
|---|
| 10 | import javax.swing.ImageIcon;
|
|---|
| 11 | import javax.swing.JButton;
|
|---|
| 12 | import javax.swing.JComponent;
|
|---|
| 13 | import javax.swing.JDialog;
|
|---|
| 14 | import javax.swing.JOptionPane;
|
|---|
| 15 | import javax.swing.JScrollPane;
|
|---|
| 16 | import javax.swing.JSplitPane;
|
|---|
| 17 | import javax.swing.KeyStroke;
|
|---|
| 18 |
|
|---|
| 19 | import net.oni2.SettingsManager;
|
|---|
| 20 | import net.oni2.aeinstaller.backend.oni.management.tools.ToolsManager;
|
|---|
| 21 | import net.oni2.aeinstaller.backend.packages.Package;
|
|---|
| 22 | import net.oni2.aeinstaller.gui.downloadwindow.Downloader;
|
|---|
| 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;
|
|---|
| 27 | import net.oni2.resourcebundle.UTF8ResourceBundleLoader;
|
|---|
| 28 |
|
|---|
| 29 | import org.javabuilders.BuildResult;
|
|---|
| 30 | import org.javabuilders.swing.SwingJavaBuilder;
|
|---|
| 31 |
|
|---|
| 32 | /**
|
|---|
| 33 | * @author Christian Illy
|
|---|
| 34 | */
|
|---|
| 35 | public class ToolManager extends JDialog implements ModSelectionListener {
|
|---|
| 36 | private static final long serialVersionUID = 343221630538866384L;
|
|---|
| 37 |
|
|---|
| 38 | private ResourceBundle bundle = UTF8ResourceBundleLoader
|
|---|
| 39 | .getBundle("net.oni2.aeinstaller.localization."
|
|---|
| 40 | + getClass().getSimpleName());
|
|---|
| 41 | @SuppressWarnings("unused")
|
|---|
| 42 | private BuildResult result = SwingJavaBuilder.build(this, bundle);
|
|---|
| 43 |
|
|---|
| 44 | private JSplitPane contents;
|
|---|
| 45 |
|
|---|
| 46 | private JScrollPane scrollTools;
|
|---|
| 47 | private ModTable tblTools;
|
|---|
| 48 |
|
|---|
| 49 | private PackageInfoBox pkgInfo;
|
|---|
| 50 | private JButton btnInstall;
|
|---|
| 51 |
|
|---|
| 52 | private Icon icoInstall = null;
|
|---|
| 53 | private Icon icoUninstall = null;
|
|---|
| 54 |
|
|---|
| 55 | private Package selectedPackage = null;
|
|---|
| 56 |
|
|---|
| 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 |
|
|---|
| 76 | contents.setDividerLocation(SettingsManager.getInstance().get(
|
|---|
| 77 | "win_tools_divloc", 550));
|
|---|
| 78 | contents.setResizeWeight(0.4);
|
|---|
| 79 |
|
|---|
| 80 | tblTools = new ModTable(ETableContentType.TOOLS);
|
|---|
| 81 | tblTools.reloadData();
|
|---|
| 82 | scrollTools.setViewportView(tblTools);
|
|---|
| 83 |
|
|---|
| 84 | tblTools.addModSelectionListener(this);
|
|---|
| 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")));
|
|---|
| 90 |
|
|---|
| 91 | setSize(SettingsManager.getInstance().get("win_tools_width", 950),
|
|---|
| 92 | SettingsManager.getInstance().get("win_tools_height", 600));
|
|---|
| 93 | setLocationRelativeTo(null);
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | @SuppressWarnings("unused")
|
|---|
| 97 | private void install() {
|
|---|
| 98 | if (selectedPackage != null) {
|
|---|
| 99 | if (selectedPackage.isInstalled()) {
|
|---|
| 100 | TreeSet<Package> tools = new TreeSet<Package>();
|
|---|
| 101 | tools.add(selectedPackage);
|
|---|
| 102 | ToolsManager.installTools(tools, true);
|
|---|
| 103 | } else {
|
|---|
| 104 | if (!selectedPackage.isLocalAvailable()) {
|
|---|
| 105 | if (SettingsManager.getInstance().isOfflineMode()) {
|
|---|
| 106 | JOptionPane.showMessageDialog(this,
|
|---|
| 107 | bundle.getString("offlineMode.text"),
|
|---|
| 108 | bundle.getString("offlineMode.title"),
|
|---|
| 109 | JOptionPane.WARNING_MESSAGE);
|
|---|
| 110 | return;
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | TreeSet<Package> toDownload = new TreeSet<Package>();
|
|---|
| 114 | toDownload.add(selectedPackage);
|
|---|
| 115 |
|
|---|
| 116 | Downloader dl = new Downloader(toDownload, null, false);
|
|---|
| 117 | try {
|
|---|
| 118 | dl.setVisible(true);
|
|---|
| 119 | if (!dl.isFinished())
|
|---|
| 120 | return;
|
|---|
| 121 | } finally {
|
|---|
| 122 | dl.dispose();
|
|---|
| 123 | }
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | TreeSet<Package> tools = new TreeSet<Package>();
|
|---|
| 127 | tools.add(selectedPackage);
|
|---|
| 128 | ToolsManager.installTools(tools, false);
|
|---|
| 129 | }
|
|---|
| 130 | }
|
|---|
| 131 | modSelectionChanged(tblTools, selectedPackage);
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | @Override
|
|---|
| 135 | public void modSelectionChanged(ModTable source, Package mod) {
|
|---|
| 136 | selectedPackage = mod;
|
|---|
| 137 |
|
|---|
| 138 | pkgInfo.updateInfo(mod);
|
|---|
| 139 | if (mod != null) {
|
|---|
| 140 | btnInstall.setEnabled(true);
|
|---|
| 141 | if (mod.isInstalled()) {
|
|---|
| 142 | btnInstall.setText(bundle.getString("btnInstall.un.text"));
|
|---|
| 143 | btnInstall.setToolTipText(bundle
|
|---|
| 144 | .getString("btnInstall.un.tooltip"));
|
|---|
| 145 | btnInstall.setIcon(icoUninstall);
|
|---|
| 146 | } else {
|
|---|
| 147 | btnInstall.setText(bundle.getString("btnInstall.text"));
|
|---|
| 148 | btnInstall.setToolTipText(bundle
|
|---|
| 149 | .getString("btnInstall.tooltip"));
|
|---|
| 150 | btnInstall.setIcon(icoInstall);
|
|---|
| 151 | }
|
|---|
| 152 | }
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | @SuppressWarnings("unused")
|
|---|
| 156 | private void closing() {
|
|---|
| 157 | SettingsManager.getInstance().put("win_tools_divloc",
|
|---|
| 158 | contents.getDividerLocation());
|
|---|
| 159 | SettingsManager.getInstance().put("win_tools_width", getWidth());
|
|---|
| 160 | SettingsManager.getInstance().put("win_tools_height", getHeight());
|
|---|
| 161 | }
|
|---|
| 162 | }
|
|---|