[625] | 1 | package net.oni2.aeinstaller.gui.toolmanager;
|
---|
| 2 |
|
---|
[626] | 3 | import java.awt.Dimension;
|
---|
| 4 | import java.awt.event.ActionEvent;
|
---|
| 5 | import java.awt.event.KeyEvent;
|
---|
[646] | 6 | import java.text.SimpleDateFormat;
|
---|
| 7 | import java.util.Date;
|
---|
[626] | 8 | import java.util.ResourceBundle;
|
---|
| 9 | import java.util.TreeMap;
|
---|
[640] | 10 | import java.util.TreeSet;
|
---|
[626] | 11 |
|
---|
| 12 | import javax.swing.AbstractAction;
|
---|
| 13 | import javax.swing.DefaultListModel;
|
---|
[637] | 14 | import javax.swing.Icon;
|
---|
| 15 | import javax.swing.ImageIcon;
|
---|
[626] | 16 | import javax.swing.JButton;
|
---|
| 17 | import javax.swing.JComponent;
|
---|
[625] | 18 | import javax.swing.JDialog;
|
---|
[626] | 19 | import javax.swing.JLabel;
|
---|
| 20 | import javax.swing.JList;
|
---|
| 21 | import javax.swing.JOptionPane;
|
---|
[637] | 22 | import javax.swing.JSplitPane;
|
---|
[626] | 23 | import javax.swing.KeyStroke;
|
---|
| 24 | import javax.swing.ListSelectionModel;
|
---|
| 25 | import javax.swing.event.ListSelectionEvent;
|
---|
| 26 | import javax.swing.event.ListSelectionListener;
|
---|
[625] | 27 |
|
---|
[640] | 28 | import net.oni2.aeinstaller.backend.Settings;
|
---|
[626] | 29 | import net.oni2.aeinstaller.backend.SizeFormatter;
|
---|
[648] | 30 | import net.oni2.aeinstaller.backend.packages.Package;
|
---|
| 31 | import net.oni2.aeinstaller.backend.packages.PackageManager;
|
---|
[626] | 32 | import net.oni2.aeinstaller.backend.oni.Installer;
|
---|
| 33 | import net.oni2.aeinstaller.gui.HTMLLinkLabel;
|
---|
[640] | 34 | import net.oni2.aeinstaller.gui.downloadwindow.Downloader;
|
---|
[626] | 35 |
|
---|
| 36 | import org.javabuilders.BuildResult;
|
---|
| 37 | import org.javabuilders.swing.SwingJavaBuilder;
|
---|
| 38 |
|
---|
[625] | 39 | /**
|
---|
| 40 | * @author Christian Illy
|
---|
| 41 | */
|
---|
[626] | 42 | public class ToolManager extends JDialog implements ListSelectionListener {
|
---|
[625] | 43 | private static final long serialVersionUID = 343221630538866384L;
|
---|
| 44 |
|
---|
[629] | 45 | private ResourceBundle bundle = ResourceBundle
|
---|
| 46 | .getBundle("net.oni2.aeinstaller.localization."
|
---|
| 47 | + getClass().getSimpleName());
|
---|
[626] | 48 | @SuppressWarnings("unused")
|
---|
| 49 | private BuildResult result = SwingJavaBuilder.build(this, bundle);
|
---|
| 50 |
|
---|
[637] | 51 | private JSplitPane contents;
|
---|
[640] | 52 |
|
---|
[626] | 53 | private JList lstTools;
|
---|
| 54 |
|
---|
[640] | 55 | private JLabel lblTitleVal;
|
---|
[626] | 56 | private JLabel lblCreatorVal;
|
---|
| 57 | private JLabel lblPlatformVal;
|
---|
| 58 | private JLabel lblPackageNumberVal;
|
---|
[646] | 59 | private JLabel lblVersionNumberVal;
|
---|
| 60 | private JLabel lblLastChangeVal;
|
---|
[626] | 61 | private HTMLLinkLabel lblDescriptionVal;
|
---|
| 62 | private JLabel lblDownloadSizeVal;
|
---|
| 63 |
|
---|
| 64 | private JButton btnInstall;
|
---|
| 65 |
|
---|
[637] | 66 | private Icon icoInstall = null;
|
---|
| 67 | private Icon icoUninstall = null;
|
---|
| 68 |
|
---|
[646] | 69 | private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
---|
| 70 |
|
---|
[626] | 71 | /**
|
---|
| 72 | * Open the dialog
|
---|
| 73 | */
|
---|
| 74 | public ToolManager() {
|
---|
| 75 | setMinimumSize(new Dimension(getWidth() + 100, getHeight() + 100));
|
---|
| 76 |
|
---|
| 77 | AbstractAction closeAction = new AbstractAction() {
|
---|
| 78 |
|
---|
| 79 | private static final long serialVersionUID = 1L;
|
---|
| 80 |
|
---|
| 81 | public void actionPerformed(ActionEvent arg0) {
|
---|
| 82 | dispose();
|
---|
| 83 | }
|
---|
| 84 | };
|
---|
| 85 | KeyStroke ksCtrlW = KeyStroke
|
---|
| 86 | .getKeyStroke('W', KeyEvent.CTRL_DOWN_MASK);
|
---|
| 87 | getRootPane()
|
---|
| 88 | .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
|
---|
| 89 | .put(ksCtrlW, "close");
|
---|
| 90 | getRootPane().getActionMap().put("close", closeAction);
|
---|
| 91 |
|
---|
[637] | 92 | contents.setDividerLocation(200);
|
---|
| 93 | contents.setResizeWeight(0.4);
|
---|
| 94 |
|
---|
[626] | 95 | lstTools.addListSelectionListener(this);
|
---|
| 96 | lstTools.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
---|
| 97 |
|
---|
| 98 | DefaultListModel dlm = new DefaultListModel();
|
---|
[648] | 99 | TreeMap<String, Package> tools = PackageManager.getInstance().getTools();
|
---|
[626] | 100 | for (String name : tools.keySet())
|
---|
| 101 | dlm.addElement(tools.get(name));
|
---|
[637] | 102 | lstTools.setModel(dlm);
|
---|
| 103 |
|
---|
| 104 | icoInstall = new ImageIcon(getClass().getResource(
|
---|
| 105 | SwingJavaBuilder.getConfig().getResource("img.install")));
|
---|
| 106 | icoUninstall = new ImageIcon(getClass().getResource(
|
---|
| 107 | SwingJavaBuilder.getConfig().getResource("img.uninstall")));
|
---|
[646] | 108 |
|
---|
[641] | 109 | setLocationRelativeTo(null);
|
---|
[626] | 110 | }
|
---|
| 111 |
|
---|
| 112 | @SuppressWarnings("unused")
|
---|
| 113 | private void install() {
|
---|
[640] | 114 | Object o = lstTools.getSelectedValue();
|
---|
[648] | 115 | if (o instanceof Package) {
|
---|
| 116 | Package theMod = (Package) o;
|
---|
[626] | 117 |
|
---|
[640] | 118 | if (theMod.isInstalled()) {
|
---|
[648] | 119 | TreeSet<Package> tools = new TreeSet<Package>();
|
---|
[640] | 120 | tools.add(theMod);
|
---|
| 121 | Installer.uninstallTools(tools);
|
---|
| 122 | } else {
|
---|
| 123 | if (!theMod.isLocalAvailable()) {
|
---|
| 124 | if (Settings.getInstance().isOfflineMode()) {
|
---|
| 125 | JOptionPane.showMessageDialog(this,
|
---|
| 126 | bundle.getString("offlineMode.text"),
|
---|
| 127 | bundle.getString("offlineMode.title"),
|
---|
| 128 | JOptionPane.WARNING_MESSAGE);
|
---|
| 129 | return;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
[648] | 132 | TreeSet<Package> toDownload = new TreeSet<Package>();
|
---|
[640] | 133 | toDownload.add(theMod);
|
---|
| 134 |
|
---|
[646] | 135 | Downloader dl = new Downloader(toDownload, null);
|
---|
[640] | 136 | try {
|
---|
| 137 | dl.setVisible(true);
|
---|
| 138 | if (!dl.isFinished())
|
---|
| 139 | return;
|
---|
| 140 | } finally {
|
---|
| 141 | dl.dispose();
|
---|
| 142 | }
|
---|
| 143 | }
|
---|
| 144 |
|
---|
[648] | 145 | TreeSet<Package> tools = new TreeSet<Package>();
|
---|
[640] | 146 | tools.add(theMod);
|
---|
| 147 | Installer.installTools(tools);
|
---|
| 148 | }
|
---|
| 149 | }
|
---|
| 150 | valueChanged(null);
|
---|
[626] | 151 | }
|
---|
| 152 |
|
---|
| 153 | @Override
|
---|
| 154 | public void valueChanged(ListSelectionEvent evt) {
|
---|
[640] | 155 | lblTitleVal.setText("");
|
---|
[626] | 156 | lblCreatorVal.setText("");
|
---|
| 157 | lblDescriptionVal.setText("");
|
---|
| 158 | lblPlatformVal.setText("");
|
---|
| 159 | lblPackageNumberVal.setText("");
|
---|
[646] | 160 | lblVersionNumberVal.setText("");
|
---|
| 161 | lblLastChangeVal.setText("");
|
---|
[626] | 162 | lblDownloadSizeVal.setText("");
|
---|
| 163 | btnInstall.setEnabled(false);
|
---|
[637] | 164 | btnInstall.setIcon(icoInstall);
|
---|
[626] | 165 |
|
---|
[648] | 166 | if (lstTools.getSelectedValue() instanceof Package) {
|
---|
| 167 | Package m = (Package) lstTools.getSelectedValue();
|
---|
[640] | 168 | lblTitleVal.setText(m.getName());
|
---|
[626] | 169 | lblCreatorVal.setText(m.getCreator());
|
---|
| 170 | lblDescriptionVal.setText(m.getDescription());
|
---|
| 171 | lblPlatformVal.setText(m.getPlatform().toString());
|
---|
| 172 | lblPackageNumberVal.setText(m.getPackageNumberString());
|
---|
[646] | 173 | lblVersionNumberVal.setText(m.getVersion());
|
---|
| 174 | if (m.getFile() != null)
|
---|
| 175 | lblLastChangeVal.setText(sdf.format(new Date(m.getFile()
|
---|
| 176 | .getTimestamp() * 1000)));
|
---|
[626] | 177 | lblDownloadSizeVal.setText(SizeFormatter.format(m.getZipSize(), 3));
|
---|
| 178 | btnInstall.setEnabled(true);
|
---|
[640] | 179 | if (m.isInstalled()) {
|
---|
[626] | 180 | btnInstall.setText(bundle.getString("btnInstall.un.text"));
|
---|
| 181 | btnInstall.setToolTipText(bundle
|
---|
| 182 | .getString("btnInstall.un.tooltip"));
|
---|
[637] | 183 | btnInstall.setIcon(icoUninstall);
|
---|
[626] | 184 | } else {
|
---|
| 185 | btnInstall.setText(bundle.getString("btnInstall.text"));
|
---|
| 186 | btnInstall.setToolTipText(bundle
|
---|
| 187 | .getString("btnInstall.tooltip"));
|
---|
| 188 | }
|
---|
| 189 | }
|
---|
| 190 | }
|
---|
[625] | 191 | }
|
---|