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

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