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