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

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

AEI2.07:

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