source: AE/installer2/src/net/oni2/aeinstaller/gui/toolmanager/ToolManager.java@ 642

Last change on this file since 642 was 641, checked in by alloc, 12 years ago

AEI2 0.98:

  • Reduced number+size of HTTP queries
  • Removed "submitter" field
  • Added output of dependencies to be selected before continuing
File size: 5.2 KB
Line 
1package net.oni2.aeinstaller.gui.toolmanager;
2
3import java.awt.Dimension;
4import java.awt.event.ActionEvent;
5import java.awt.event.KeyEvent;
6import java.util.ResourceBundle;
7import java.util.TreeMap;
8import java.util.TreeSet;
9
10import javax.swing.AbstractAction;
11import javax.swing.DefaultListModel;
12import javax.swing.Icon;
13import javax.swing.ImageIcon;
14import javax.swing.JButton;
15import javax.swing.JComponent;
16import javax.swing.JDialog;
17import javax.swing.JLabel;
18import javax.swing.JList;
19import javax.swing.JOptionPane;
20import javax.swing.JSplitPane;
21import javax.swing.KeyStroke;
22import javax.swing.ListSelectionModel;
23import javax.swing.event.ListSelectionEvent;
24import javax.swing.event.ListSelectionListener;
25
26import net.oni2.aeinstaller.backend.Settings;
27import net.oni2.aeinstaller.backend.SizeFormatter;
28import net.oni2.aeinstaller.backend.mods.Mod;
29import net.oni2.aeinstaller.backend.mods.ModManager;
30import net.oni2.aeinstaller.backend.oni.Installer;
31import net.oni2.aeinstaller.gui.HTMLLinkLabel;
32import net.oni2.aeinstaller.gui.downloadwindow.Downloader;
33
34import org.javabuilders.BuildResult;
35import org.javabuilders.swing.SwingJavaBuilder;
36
37/**
38 * @author Christian Illy
39 */
40public 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}
Note: See TracBrowser for help on using the repository browser.