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

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

AEI2 0.97:

  • Finished toolmanager
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 lblSubmitterVal;
55 private JLabel lblCreatorVal;
56 private JLabel lblPlatformVal;
57 private JLabel lblPackageNumberVal;
58 private HTMLLinkLabel lblDescriptionVal;
59 private JLabel lblDownloadSizeVal;
60
61 private JButton btnInstall;
62
63 private Icon icoInstall = null;
64 private Icon icoUninstall = null;
65
66 /**
67 * Open the dialog
68 */
69 public ToolManager() {
70 setMinimumSize(new Dimension(getWidth() + 100, getHeight() + 100));
71
72 AbstractAction closeAction = new AbstractAction() {
73
74 private static final long serialVersionUID = 1L;
75
76 public void actionPerformed(ActionEvent arg0) {
77 dispose();
78 }
79 };
80 KeyStroke ksCtrlW = KeyStroke
81 .getKeyStroke('W', KeyEvent.CTRL_DOWN_MASK);
82 getRootPane()
83 .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
84 .put(ksCtrlW, "close");
85 getRootPane().getActionMap().put("close", closeAction);
86
87 contents.setDividerLocation(200);
88 contents.setResizeWeight(0.4);
89
90 lstTools.addListSelectionListener(this);
91 lstTools.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
92
93 DefaultListModel dlm = new DefaultListModel();
94 TreeMap<String, Mod> tools = ModManager.getInstance().getTools();
95 for (String name : tools.keySet())
96 dlm.addElement(tools.get(name));
97 lstTools.setModel(dlm);
98
99 icoInstall = new ImageIcon(getClass().getResource(
100 SwingJavaBuilder.getConfig().getResource("img.install")));
101 icoUninstall = new ImageIcon(getClass().getResource(
102 SwingJavaBuilder.getConfig().getResource("img.uninstall")));
103 }
104
105 @SuppressWarnings("unused")
106 private void install() {
107 Object o = lstTools.getSelectedValue();
108 if (o instanceof Mod) {
109 Mod theMod = (Mod) o;
110
111 if (theMod.isInstalled()) {
112 TreeSet<Mod> tools = new TreeSet<Mod>();
113 tools.add(theMod);
114 Installer.uninstallTools(tools);
115 } else {
116 if (!theMod.isLocalAvailable()) {
117 if (Settings.getInstance().isOfflineMode()) {
118 JOptionPane.showMessageDialog(this,
119 bundle.getString("offlineMode.text"),
120 bundle.getString("offlineMode.title"),
121 JOptionPane.WARNING_MESSAGE);
122 return;
123 }
124
125 TreeSet<Mod> toDownload = new TreeSet<Mod>();
126 toDownload.add(theMod);
127
128 Downloader dl = new Downloader(toDownload);
129 try {
130 dl.setVisible(true);
131 if (!dl.isFinished())
132 return;
133 } finally {
134 dl.dispose();
135 }
136 }
137
138 TreeSet<Mod> tools = new TreeSet<Mod>();
139 tools.add(theMod);
140 Installer.installTools(tools);
141 }
142 }
143 valueChanged(null);
144 }
145
146 @Override
147 public void valueChanged(ListSelectionEvent evt) {
148 lblTitleVal.setText("");
149 lblSubmitterVal.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 lblSubmitterVal.setText(m.getSubmitter());
162 lblCreatorVal.setText(m.getCreator());
163 lblDescriptionVal.setText(m.getDescription());
164 lblPlatformVal.setText(m.getPlatform().toString());
165 lblPackageNumberVal.setText(m.getPackageNumberString());
166 lblDownloadSizeVal.setText(SizeFormatter.format(m.getZipSize(), 3));
167 btnInstall.setEnabled(true);
168 if (m.isInstalled()) {
169 btnInstall.setText(bundle.getString("btnInstall.un.text"));
170 btnInstall.setToolTipText(bundle
171 .getString("btnInstall.un.tooltip"));
172 btnInstall.setIcon(icoUninstall);
173 } else {
174 btnInstall.setText(bundle.getString("btnInstall.text"));
175 btnInstall.setToolTipText(bundle
176 .getString("btnInstall.tooltip"));
177 }
178 }
179 }
180}
Note: See TracBrowser for help on using the repository browser.