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

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

AEI2 0.94:

  • Added context menu item to open Depot page of mod in table
  • Added last-change column to table
File size: 4.3 KB
Line 
1package net.oni2.aeinstaller.gui.toolmanager;
2
3import java.awt.Dimension;
4import java.awt.event.ActionEvent;
5import java.awt.event.KeyEvent;
6import java.util.ResourceBundle;
7import java.util.TreeMap;
8
9import javax.swing.AbstractAction;
10import javax.swing.DefaultListModel;
11import javax.swing.Icon;
12import javax.swing.ImageIcon;
13import javax.swing.JButton;
14import javax.swing.JComponent;
15import javax.swing.JDialog;
16import javax.swing.JLabel;
17import javax.swing.JList;
18import javax.swing.JOptionPane;
19import javax.swing.JSplitPane;
20import javax.swing.KeyStroke;
21import javax.swing.ListSelectionModel;
22import javax.swing.event.ListSelectionEvent;
23import javax.swing.event.ListSelectionListener;
24
25import net.oni2.aeinstaller.backend.SizeFormatter;
26import net.oni2.aeinstaller.backend.mods.Mod;
27import net.oni2.aeinstaller.backend.mods.ModManager;
28import net.oni2.aeinstaller.backend.oni.Installer;
29import net.oni2.aeinstaller.gui.HTMLLinkLabel;
30
31import org.javabuilders.BuildResult;
32import org.javabuilders.swing.SwingJavaBuilder;
33
34/**
35 * @author Christian Illy
36 */
37public class ToolManager extends JDialog implements ListSelectionListener {
38 private static final long serialVersionUID = 343221630538866384L;
39
40 private ResourceBundle bundle = ResourceBundle
41 .getBundle("net.oni2.aeinstaller.localization."
42 + getClass().getSimpleName());
43 @SuppressWarnings("unused")
44 private BuildResult result = SwingJavaBuilder.build(this, bundle);
45
46 private JSplitPane contents;
47
48 private JList lstTools;
49
50 private JLabel lblSubmitterVal;
51 private JLabel lblCreatorVal;
52 private JLabel lblPlatformVal;
53 private JLabel lblPackageNumberVal;
54 private HTMLLinkLabel lblDescriptionVal;
55 private JLabel lblDownloadSizeVal;
56
57 private JButton btnInstall;
58
59 private Icon icoInstall = null;
60 private Icon icoUninstall = null;
61
62 /**
63 * Open the dialog
64 */
65 public ToolManager() {
66 setMinimumSize(new Dimension(getWidth() + 100, getHeight() + 100));
67
68 AbstractAction closeAction = new AbstractAction() {
69
70 private static final long serialVersionUID = 1L;
71
72 public void actionPerformed(ActionEvent arg0) {
73 dispose();
74 }
75 };
76 KeyStroke ksCtrlW = KeyStroke
77 .getKeyStroke('W', KeyEvent.CTRL_DOWN_MASK);
78 getRootPane()
79 .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
80 .put(ksCtrlW, "close");
81 getRootPane().getActionMap().put("close", closeAction);
82
83 contents.setDividerLocation(200);
84 contents.setResizeWeight(0.4);
85
86 lstTools.addListSelectionListener(this);
87 lstTools.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
88
89 DefaultListModel dlm = new DefaultListModel();
90 TreeMap<String, Mod> tools = ModManager.getInstance().getTools();
91 for (String name : tools.keySet())
92 dlm.addElement(tools.get(name));
93 lstTools.setModel(dlm);
94
95 icoInstall = new ImageIcon(getClass().getResource(
96 SwingJavaBuilder.getConfig().getResource("img.install")));
97 icoUninstall = new ImageIcon(getClass().getResource(
98 SwingJavaBuilder.getConfig().getResource("img.uninstall")));
99 }
100
101 @SuppressWarnings("unused")
102 private void install() {
103 // TODO: care for offline mode
104 JOptionPane.showMessageDialog(this, "install", "todo",
105 JOptionPane.INFORMATION_MESSAGE);
106 }
107
108 @SuppressWarnings("unused")
109 private void installDone() {
110 }
111
112 @Override
113 public void valueChanged(ListSelectionEvent evt) {
114 lblSubmitterVal.setText("");
115 lblCreatorVal.setText("");
116 lblDescriptionVal.setText("");
117 lblPlatformVal.setText("");
118 lblPackageNumberVal.setText("");
119 lblDownloadSizeVal.setText("");
120 btnInstall.setEnabled(false);
121 btnInstall.setIcon(icoInstall);
122
123 if (lstTools.getSelectedValue() instanceof Mod) {
124 Mod m = (Mod) lstTools.getSelectedValue();
125 lblSubmitterVal.setText(m.getName());
126 lblCreatorVal.setText(m.getCreator());
127 lblDescriptionVal.setText(m.getDescription());
128 lblPlatformVal.setText(m.getPlatform().toString());
129 lblPackageNumberVal.setText(m.getPackageNumberString());
130 lblDownloadSizeVal.setText(SizeFormatter.format(m.getZipSize(), 3));
131 btnInstall.setEnabled(true);
132 if (Installer.getInstalledTools().contains(m.getPackageNumber())) {
133 btnInstall.setText(bundle.getString("btnInstall.un.text"));
134 btnInstall.setToolTipText(bundle
135 .getString("btnInstall.un.tooltip"));
136 btnInstall.setIcon(icoUninstall);
137 } else {
138 btnInstall.setText(bundle.getString("btnInstall.text"));
139 btnInstall.setToolTipText(bundle
140 .getString("btnInstall.tooltip"));
141 }
142 }
143 }
144}
Note: See TracBrowser for help on using the repository browser.