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

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

AEI2.08, AEIUpdater:

File size: 4.8 KB
Line 
1package net.oni2.aeinstaller.gui.toolmanager;
2
3import java.awt.event.ActionEvent;
4import java.awt.event.KeyEvent;
5import java.util.ResourceBundle;
6import java.util.TreeSet;
7
8import javax.swing.AbstractAction;
9import javax.swing.Icon;
10import javax.swing.ImageIcon;
11import javax.swing.JButton;
12import javax.swing.JComponent;
13import javax.swing.JDialog;
14import javax.swing.JOptionPane;
15import javax.swing.JScrollPane;
16import javax.swing.JSplitPane;
17import javax.swing.KeyStroke;
18
19import net.oni2.SettingsManager;
20import net.oni2.aeinstaller.backend.RuntimeOptions;
21import net.oni2.aeinstaller.backend.oni.management.tools.ToolsManager;
22import net.oni2.aeinstaller.backend.packages.Package;
23import net.oni2.aeinstaller.gui.downloadwindow.Downloader;
24import net.oni2.aeinstaller.gui.modtable.ModSelectionListener;
25import net.oni2.aeinstaller.gui.modtable.ModTable;
26import net.oni2.aeinstaller.gui.modtable.ModTable.ETableContentType;
27import net.oni2.aeinstaller.gui.packageinfobox.PackageInfoBox;
28import net.oni2.resourcebundle.UTF8ResourceBundleLoader;
29
30import org.javabuilders.BuildResult;
31import org.javabuilders.swing.SwingJavaBuilder;
32
33/**
34 * @author Christian Illy
35 */
36public class ToolManager extends JDialog implements ModSelectionListener {
37 private static final long serialVersionUID = 343221630538866384L;
38
39 private ResourceBundle bundle = UTF8ResourceBundleLoader
40 .getBundle("net.oni2.aeinstaller.localization."
41 + getClass().getSimpleName());
42 @SuppressWarnings("unused")
43 private BuildResult result = SwingJavaBuilder.build(this, bundle);
44
45 private JSplitPane contents;
46
47 private JScrollPane scrollTools;
48 private ModTable tblTools;
49
50 private PackageInfoBox pkgInfo;
51 private JButton btnInstall;
52
53 private Icon icoInstall = null;
54 private Icon icoUninstall = null;
55
56 private Package selectedPackage = null;
57
58 /**
59 * Open the dialog
60 */
61 public ToolManager() {
62 AbstractAction closeAction = new AbstractAction() {
63
64 private static final long serialVersionUID = 1L;
65
66 public void actionPerformed(ActionEvent arg0) {
67 dispose();
68 }
69 };
70 KeyStroke ksCtrlW = KeyStroke
71 .getKeyStroke('W', KeyEvent.CTRL_DOWN_MASK);
72 getRootPane()
73 .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
74 .put(ksCtrlW, "close");
75 getRootPane().getActionMap().put("close", closeAction);
76
77 contents.setDividerLocation(SettingsManager.getInstance().get(
78 "win_tools_divloc", 550));
79 contents.setResizeWeight(0.4);
80
81 tblTools = new ModTable(ETableContentType.TOOLS);
82 tblTools.reloadData();
83 scrollTools.setViewportView(tblTools);
84
85 tblTools.addModSelectionListener(this);
86
87 icoInstall = new ImageIcon(getClass().getResource(
88 SwingJavaBuilder.getConfig().getResource("img.install")));
89 icoUninstall = new ImageIcon(getClass().getResource(
90 SwingJavaBuilder.getConfig().getResource("img.uninstall")));
91
92 setSize(SettingsManager.getInstance().get("win_tools_width", 950),
93 SettingsManager.getInstance().get("win_tools_height", 600));
94 setLocationRelativeTo(null);
95 }
96
97 @SuppressWarnings("unused")
98 private void install() {
99 if (selectedPackage != null) {
100 if (selectedPackage.isInstalled()) {
101 TreeSet<Package> tools = new TreeSet<Package>();
102 tools.add(selectedPackage);
103 ToolsManager.installTools(tools, true);
104 } else {
105 if (!selectedPackage.isLocalAvailable()) {
106 if (RuntimeOptions.isOfflineMode()) {
107 JOptionPane.showMessageDialog(this,
108 bundle.getString("offlineMode.text"),
109 bundle.getString("offlineMode.title"),
110 JOptionPane.WARNING_MESSAGE);
111 return;
112 }
113
114 TreeSet<Package> toDownload = new TreeSet<Package>();
115 toDownload.add(selectedPackage);
116
117 Downloader dl = new Downloader(toDownload, null, false);
118 try {
119 dl.setVisible(true);
120 if (!dl.isFinished())
121 return;
122 } finally {
123 dl.dispose();
124 }
125 }
126
127 TreeSet<Package> tools = new TreeSet<Package>();
128 tools.add(selectedPackage);
129 ToolsManager.installTools(tools, false);
130 }
131 }
132 modSelectionChanged(tblTools, selectedPackage);
133 }
134
135 @Override
136 public void modSelectionChanged(ModTable source, Package mod) {
137 selectedPackage = mod;
138
139 pkgInfo.updateInfo(mod);
140 if (mod != null) {
141 btnInstall.setEnabled(true);
142 if (mod.isInstalled()) {
143 btnInstall.setText(bundle.getString("btnInstall.un.text"));
144 btnInstall.setToolTipText(bundle
145 .getString("btnInstall.un.tooltip"));
146 btnInstall.setIcon(icoUninstall);
147 } else {
148 btnInstall.setText(bundle.getString("btnInstall.text"));
149 btnInstall.setToolTipText(bundle
150 .getString("btnInstall.tooltip"));
151 btnInstall.setIcon(icoInstall);
152 }
153 }
154 }
155
156 @SuppressWarnings("unused")
157 private void closing() {
158 SettingsManager.getInstance().put("win_tools_divloc",
159 contents.getDividerLocation());
160 SettingsManager.getInstance().put("win_tools_width", getWidth());
161 SettingsManager.getInstance().put("win_tools_height", getHeight());
162 }
163}
Note: See TracBrowser for help on using the repository browser.