| 1 | package net.oni2.aeinstaller.gui.toolmanager;
|
|---|
| 2 |
|
|---|
| 3 | import java.awt.Dimension;
|
|---|
| 4 | import java.awt.event.ActionEvent;
|
|---|
| 5 | import java.awt.event.KeyEvent;
|
|---|
| 6 | import java.util.ResourceBundle;
|
|---|
| 7 | import java.util.TreeMap;
|
|---|
| 8 |
|
|---|
| 9 | import javax.swing.AbstractAction;
|
|---|
| 10 | import javax.swing.DefaultListModel;
|
|---|
| 11 | import javax.swing.Icon;
|
|---|
| 12 | import javax.swing.ImageIcon;
|
|---|
| 13 | import javax.swing.JButton;
|
|---|
| 14 | import javax.swing.JComponent;
|
|---|
| 15 | import javax.swing.JDialog;
|
|---|
| 16 | import javax.swing.JLabel;
|
|---|
| 17 | import javax.swing.JList;
|
|---|
| 18 | import javax.swing.JOptionPane;
|
|---|
| 19 | import javax.swing.JSplitPane;
|
|---|
| 20 | import javax.swing.KeyStroke;
|
|---|
| 21 | import javax.swing.ListSelectionModel;
|
|---|
| 22 | import javax.swing.event.ListSelectionEvent;
|
|---|
| 23 | import javax.swing.event.ListSelectionListener;
|
|---|
| 24 |
|
|---|
| 25 | import net.oni2.aeinstaller.backend.SizeFormatter;
|
|---|
| 26 | import net.oni2.aeinstaller.backend.mods.Mod;
|
|---|
| 27 | import net.oni2.aeinstaller.backend.mods.ModManager;
|
|---|
| 28 | import net.oni2.aeinstaller.backend.oni.Installer;
|
|---|
| 29 | import net.oni2.aeinstaller.gui.HTMLLinkLabel;
|
|---|
| 30 |
|
|---|
| 31 | import org.javabuilders.BuildResult;
|
|---|
| 32 | import org.javabuilders.swing.SwingJavaBuilder;
|
|---|
| 33 |
|
|---|
| 34 | /**
|
|---|
| 35 | * @author Christian Illy
|
|---|
| 36 | */
|
|---|
| 37 | public class ToolManager extends JDialog implements ListSelectionListener {
|
|---|
| 38 | private static final long serialVersionUID = 343221630538866384L;
|
|---|
| 39 |
|
|---|
| 40 | private ResourceBundle bundle = ResourceBundle
|
|---|
| 41 | .getBundle("net.oni2.aeinstaller.localization."
|
|---|
| 42 | + getClass().getSimpleName());
|
|---|
| 43 | @SuppressWarnings("unused")
|
|---|
| 44 | private BuildResult result = SwingJavaBuilder.build(this, bundle);
|
|---|
| 45 |
|
|---|
| 46 | private JSplitPane contents;
|
|---|
| 47 |
|
|---|
| 48 | private JList lstTools;
|
|---|
| 49 |
|
|---|
| 50 | private JLabel lblSubmitterVal;
|
|---|
| 51 | private JLabel lblCreatorVal;
|
|---|
| 52 | private JLabel lblPlatformVal;
|
|---|
| 53 | private JLabel lblPackageNumberVal;
|
|---|
| 54 | private HTMLLinkLabel lblDescriptionVal;
|
|---|
| 55 | private JLabel lblDownloadSizeVal;
|
|---|
| 56 |
|
|---|
| 57 | private JButton btnInstall;
|
|---|
| 58 |
|
|---|
| 59 | private Icon icoInstall = null;
|
|---|
| 60 | private Icon icoUninstall = null;
|
|---|
| 61 |
|
|---|
| 62 | /**
|
|---|
| 63 | * Open the dialog
|
|---|
| 64 | */
|
|---|
| 65 | public ToolManager() {
|
|---|
| 66 | setMinimumSize(new Dimension(getWidth() + 100, getHeight() + 100));
|
|---|
| 67 |
|
|---|
| 68 | AbstractAction closeAction = new AbstractAction() {
|
|---|
| 69 |
|
|---|
| 70 | private static final long serialVersionUID = 1L;
|
|---|
| 71 |
|
|---|
| 72 | public void actionPerformed(ActionEvent arg0) {
|
|---|
| 73 | dispose();
|
|---|
| 74 | }
|
|---|
| 75 | };
|
|---|
| 76 | KeyStroke ksCtrlW = KeyStroke
|
|---|
| 77 | .getKeyStroke('W', KeyEvent.CTRL_DOWN_MASK);
|
|---|
| 78 | getRootPane()
|
|---|
| 79 | .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
|
|---|
| 80 | .put(ksCtrlW, "close");
|
|---|
| 81 | getRootPane().getActionMap().put("close", closeAction);
|
|---|
| 82 |
|
|---|
| 83 | contents.setDividerLocation(200);
|
|---|
| 84 | contents.setResizeWeight(0.4);
|
|---|
| 85 |
|
|---|
| 86 | lstTools.addListSelectionListener(this);
|
|---|
| 87 | lstTools.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
|---|
| 88 |
|
|---|
| 89 | DefaultListModel dlm = new DefaultListModel();
|
|---|
| 90 | TreeMap<String, Mod> tools = ModManager.getInstance().getTools();
|
|---|
| 91 | for (String name : tools.keySet())
|
|---|
| 92 | dlm.addElement(tools.get(name));
|
|---|
| 93 | lstTools.setModel(dlm);
|
|---|
| 94 |
|
|---|
| 95 | icoInstall = new ImageIcon(getClass().getResource(
|
|---|
| 96 | SwingJavaBuilder.getConfig().getResource("img.install")));
|
|---|
| 97 | icoUninstall = new ImageIcon(getClass().getResource(
|
|---|
| 98 | SwingJavaBuilder.getConfig().getResource("img.uninstall")));
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | @SuppressWarnings("unused")
|
|---|
| 102 | private void install() {
|
|---|
| 103 | // TODO: care for offline mode
|
|---|
| 104 | JOptionPane.showMessageDialog(this, "install", "todo",
|
|---|
| 105 | JOptionPane.INFORMATION_MESSAGE);
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | @SuppressWarnings("unused")
|
|---|
| 109 | private void installDone() {
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | @Override
|
|---|
| 113 | public void valueChanged(ListSelectionEvent evt) {
|
|---|
| 114 | lblSubmitterVal.setText("");
|
|---|
| 115 | lblCreatorVal.setText("");
|
|---|
| 116 | lblDescriptionVal.setText("");
|
|---|
| 117 | lblPlatformVal.setText("");
|
|---|
| 118 | lblPackageNumberVal.setText("");
|
|---|
| 119 | lblDownloadSizeVal.setText("");
|
|---|
| 120 | btnInstall.setEnabled(false);
|
|---|
| 121 | btnInstall.setIcon(icoInstall);
|
|---|
| 122 |
|
|---|
| 123 | if (lstTools.getSelectedValue() instanceof Mod) {
|
|---|
| 124 | Mod m = (Mod) lstTools.getSelectedValue();
|
|---|
| 125 | lblSubmitterVal.setText(m.getName());
|
|---|
| 126 | lblCreatorVal.setText(m.getCreator());
|
|---|
| 127 | lblDescriptionVal.setText(m.getDescription());
|
|---|
| 128 | lblPlatformVal.setText(m.getPlatform().toString());
|
|---|
| 129 | lblPackageNumberVal.setText(m.getPackageNumberString());
|
|---|
| 130 | lblDownloadSizeVal.setText(SizeFormatter.format(m.getZipSize(), 3));
|
|---|
| 131 | btnInstall.setEnabled(true);
|
|---|
| 132 | if (Installer.getInstalledTools().contains(m.getPackageNumber())) {
|
|---|
| 133 | btnInstall.setText(bundle.getString("btnInstall.un.text"));
|
|---|
| 134 | btnInstall.setToolTipText(bundle
|
|---|
| 135 | .getString("btnInstall.un.tooltip"));
|
|---|
| 136 | btnInstall.setIcon(icoUninstall);
|
|---|
| 137 | } else {
|
|---|
| 138 | btnInstall.setText(bundle.getString("btnInstall.text"));
|
|---|
| 139 | btnInstall.setToolTipText(bundle
|
|---|
| 140 | .getString("btnInstall.tooltip"));
|
|---|
| 141 | }
|
|---|
| 142 | }
|
|---|
| 143 | }
|
|---|
| 144 | }
|
|---|