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

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

AEI2.08, AEIUpdater:

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