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