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