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