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

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

AEI2.00:

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