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

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

AEI2 0.99c:

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