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

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

AEI2 0.99e:

  • Added forced offline mode (argument -offline)
  • Fixed bug when displaying dependencies during installation
  • Switched from term "mandatory" to "core" for always-install packages
File size: 5.7 KB
RevLine 
[625]1package net.oni2.aeinstaller.gui.toolmanager;
2
[626]3import java.awt.Dimension;
4import java.awt.event.ActionEvent;
5import java.awt.event.KeyEvent;
[646]6import java.text.SimpleDateFormat;
7import java.util.Date;
[626]8import java.util.ResourceBundle;
9import java.util.TreeMap;
[640]10import java.util.TreeSet;
[626]11
12import javax.swing.AbstractAction;
13import javax.swing.DefaultListModel;
[637]14import javax.swing.Icon;
15import javax.swing.ImageIcon;
[626]16import javax.swing.JButton;
17import javax.swing.JComponent;
[625]18import javax.swing.JDialog;
[626]19import javax.swing.JLabel;
20import javax.swing.JList;
21import javax.swing.JOptionPane;
[637]22import javax.swing.JSplitPane;
[626]23import javax.swing.KeyStroke;
24import javax.swing.ListSelectionModel;
25import javax.swing.event.ListSelectionEvent;
26import javax.swing.event.ListSelectionListener;
[625]27
[640]28import net.oni2.aeinstaller.backend.Settings;
[626]29import net.oni2.aeinstaller.backend.SizeFormatter;
[648]30import net.oni2.aeinstaller.backend.packages.Package;
31import net.oni2.aeinstaller.backend.packages.PackageManager;
[626]32import net.oni2.aeinstaller.backend.oni.Installer;
33import net.oni2.aeinstaller.gui.HTMLLinkLabel;
[640]34import net.oni2.aeinstaller.gui.downloadwindow.Downloader;
[626]35
36import org.javabuilders.BuildResult;
37import org.javabuilders.swing.SwingJavaBuilder;
38
[625]39/**
40 * @author Christian Illy
41 */
[626]42public class ToolManager extends JDialog implements ListSelectionListener {
[625]43 private static final long serialVersionUID = 343221630538866384L;
44
[629]45 private ResourceBundle bundle = ResourceBundle
46 .getBundle("net.oni2.aeinstaller.localization."
47 + getClass().getSimpleName());
[626]48 @SuppressWarnings("unused")
49 private BuildResult result = SwingJavaBuilder.build(this, bundle);
50
[637]51 private JSplitPane contents;
[640]52
[626]53 private JList lstTools;
54
[640]55 private JLabel lblTitleVal;
[626]56 private JLabel lblCreatorVal;
57 private JLabel lblPlatformVal;
58 private JLabel lblPackageNumberVal;
[646]59 private JLabel lblVersionNumberVal;
60 private JLabel lblLastChangeVal;
[626]61 private HTMLLinkLabel lblDescriptionVal;
62 private JLabel lblDownloadSizeVal;
63
64 private JButton btnInstall;
65
[637]66 private Icon icoInstall = null;
67 private Icon icoUninstall = null;
68
[646]69 private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
70
[626]71 /**
72 * Open the dialog
73 */
74 public ToolManager() {
75 setMinimumSize(new Dimension(getWidth() + 100, getHeight() + 100));
76
77 AbstractAction closeAction = new AbstractAction() {
78
79 private static final long serialVersionUID = 1L;
80
81 public void actionPerformed(ActionEvent arg0) {
82 dispose();
83 }
84 };
85 KeyStroke ksCtrlW = KeyStroke
86 .getKeyStroke('W', KeyEvent.CTRL_DOWN_MASK);
87 getRootPane()
88 .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
89 .put(ksCtrlW, "close");
90 getRootPane().getActionMap().put("close", closeAction);
91
[637]92 contents.setDividerLocation(200);
93 contents.setResizeWeight(0.4);
94
[626]95 lstTools.addListSelectionListener(this);
96 lstTools.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
97
98 DefaultListModel dlm = new DefaultListModel();
[648]99 TreeMap<String, Package> tools = PackageManager.getInstance().getTools();
[626]100 for (String name : tools.keySet())
101 dlm.addElement(tools.get(name));
[637]102 lstTools.setModel(dlm);
103
104 icoInstall = new ImageIcon(getClass().getResource(
105 SwingJavaBuilder.getConfig().getResource("img.install")));
106 icoUninstall = new ImageIcon(getClass().getResource(
107 SwingJavaBuilder.getConfig().getResource("img.uninstall")));
[646]108
[641]109 setLocationRelativeTo(null);
[626]110 }
111
112 @SuppressWarnings("unused")
113 private void install() {
[640]114 Object o = lstTools.getSelectedValue();
[648]115 if (o instanceof Package) {
116 Package theMod = (Package) o;
[626]117
[640]118 if (theMod.isInstalled()) {
[648]119 TreeSet<Package> tools = new TreeSet<Package>();
[640]120 tools.add(theMod);
121 Installer.uninstallTools(tools);
122 } else {
123 if (!theMod.isLocalAvailable()) {
124 if (Settings.getInstance().isOfflineMode()) {
125 JOptionPane.showMessageDialog(this,
126 bundle.getString("offlineMode.text"),
127 bundle.getString("offlineMode.title"),
128 JOptionPane.WARNING_MESSAGE);
129 return;
130 }
131
[648]132 TreeSet<Package> toDownload = new TreeSet<Package>();
[640]133 toDownload.add(theMod);
134
[646]135 Downloader dl = new Downloader(toDownload, null);
[640]136 try {
137 dl.setVisible(true);
138 if (!dl.isFinished())
139 return;
140 } finally {
141 dl.dispose();
142 }
143 }
144
[648]145 TreeSet<Package> tools = new TreeSet<Package>();
[640]146 tools.add(theMod);
147 Installer.installTools(tools);
148 }
149 }
150 valueChanged(null);
[626]151 }
152
153 @Override
154 public void valueChanged(ListSelectionEvent evt) {
[640]155 lblTitleVal.setText("");
[626]156 lblCreatorVal.setText("");
157 lblDescriptionVal.setText("");
158 lblPlatformVal.setText("");
159 lblPackageNumberVal.setText("");
[646]160 lblVersionNumberVal.setText("");
161 lblLastChangeVal.setText("");
[626]162 lblDownloadSizeVal.setText("");
163 btnInstall.setEnabled(false);
[637]164 btnInstall.setIcon(icoInstall);
[626]165
[648]166 if (lstTools.getSelectedValue() instanceof Package) {
167 Package m = (Package) lstTools.getSelectedValue();
[640]168 lblTitleVal.setText(m.getName());
[626]169 lblCreatorVal.setText(m.getCreator());
170 lblDescriptionVal.setText(m.getDescription());
171 lblPlatformVal.setText(m.getPlatform().toString());
172 lblPackageNumberVal.setText(m.getPackageNumberString());
[646]173 lblVersionNumberVal.setText(m.getVersion());
174 if (m.getFile() != null)
175 lblLastChangeVal.setText(sdf.format(new Date(m.getFile()
176 .getTimestamp() * 1000)));
[626]177 lblDownloadSizeVal.setText(SizeFormatter.format(m.getZipSize(), 3));
178 btnInstall.setEnabled(true);
[640]179 if (m.isInstalled()) {
[626]180 btnInstall.setText(bundle.getString("btnInstall.un.text"));
181 btnInstall.setToolTipText(bundle
182 .getString("btnInstall.un.tooltip"));
[637]183 btnInstall.setIcon(icoUninstall);
[626]184 } else {
185 btnInstall.setText(bundle.getString("btnInstall.text"));
186 btnInstall.setToolTipText(bundle
187 .getString("btnInstall.tooltip"));
188 }
189 }
190 }
[625]191}
Note: See TracBrowser for help on using the repository browser.