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

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

AEI2 0.99i:

  • Lots of refactorings for the GUI:
    • Global type for the mod info box (Main, Tools, Core)
    • Same table for Main, Tools, Core
File size: 4.2 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.aeinstaller.backend.Settings;
20import net.oni2.aeinstaller.backend.oni.Installer;
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;
27
28import org.javabuilders.BuildResult;
29import org.javabuilders.swing.SwingJavaBuilder;
30
31/**
32 * @author Christian Illy
33 */
34public class ToolManager extends JDialog implements ModSelectionListener {
35 private static final long serialVersionUID = 343221630538866384L;
36
37 private ResourceBundle bundle = ResourceBundle
38 .getBundle("net.oni2.aeinstaller.localization."
39 + getClass().getSimpleName());
40 @SuppressWarnings("unused")
41 private BuildResult result = SwingJavaBuilder.build(this, bundle);
42
43 private JSplitPane contents;
44
45 private JScrollPane scrollTools;
46 private ModTable tblTools;
47
48 private PackageInfoBox pkgInfo;
49 private JButton btnInstall;
50
51 private Icon icoInstall = null;
52 private Icon icoUninstall = null;
53
54 private Package selectedPackage = null;
55
56 /**
57 * Open the dialog
58 */
59 public ToolManager() {
60 AbstractAction closeAction = new AbstractAction() {
61
62 private static final long serialVersionUID = 1L;
63
64 public void actionPerformed(ActionEvent arg0) {
65 dispose();
66 }
67 };
68 KeyStroke ksCtrlW = KeyStroke
69 .getKeyStroke('W', KeyEvent.CTRL_DOWN_MASK);
70 getRootPane()
71 .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
72 .put(ksCtrlW, "close");
73 getRootPane().getActionMap().put("close", closeAction);
74
75 contents.setDividerLocation(550);
76 contents.setResizeWeight(0.4);
77
78 tblTools = new ModTable(ETableContentType.TOOLS);
79 tblTools.reloadData();
80 scrollTools.setViewportView(tblTools);
81
82 tblTools.addModSelectionListener(this);
83
84 icoInstall = new ImageIcon(getClass().getResource(
85 SwingJavaBuilder.getConfig().getResource("img.install")));
86 icoUninstall = new ImageIcon(getClass().getResource(
87 SwingJavaBuilder.getConfig().getResource("img.uninstall")));
88
89 setLocationRelativeTo(null);
90 }
91
92 @SuppressWarnings("unused")
93 private void install() {
94 if (selectedPackage != null) {
95 if (selectedPackage.isInstalled()) {
96 TreeSet<Package> tools = new TreeSet<Package>();
97 tools.add(selectedPackage);
98 Installer.uninstallTools(tools);
99 } else {
100 if (!selectedPackage.isLocalAvailable()) {
101 if (Settings.getInstance().isOfflineMode()) {
102 JOptionPane.showMessageDialog(this,
103 bundle.getString("offlineMode.text"),
104 bundle.getString("offlineMode.title"),
105 JOptionPane.WARNING_MESSAGE);
106 return;
107 }
108
109 TreeSet<Package> toDownload = new TreeSet<Package>();
110 toDownload.add(selectedPackage);
111
112 Downloader dl = new Downloader(toDownload, null);
113 try {
114 dl.setVisible(true);
115 if (!dl.isFinished())
116 return;
117 } finally {
118 dl.dispose();
119 }
120 }
121
122 TreeSet<Package> tools = new TreeSet<Package>();
123 tools.add(selectedPackage);
124 Installer.installTools(tools);
125 }
126 }
127 modSelectionChanged(tblTools, selectedPackage);
128 }
129
130 @Override
131 public void modSelectionChanged(ModTable source, Package mod) {
132 selectedPackage = mod;
133
134 pkgInfo.updateInfo(mod);
135 if (mod != null) {
136 btnInstall.setEnabled(true);
137 if (mod.isInstalled()) {
138 btnInstall.setText(bundle.getString("btnInstall.un.text"));
139 btnInstall.setToolTipText(bundle
140 .getString("btnInstall.un.tooltip"));
141 btnInstall.setIcon(icoUninstall);
142 } else {
143 btnInstall.setText(bundle.getString("btnInstall.text"));
144 btnInstall.setToolTipText(bundle
145 .getString("btnInstall.tooltip"));
146 btnInstall.setIcon(icoInstall);
147 }
148 }
149 }
150}
Note: See TracBrowser for help on using the repository browser.