| 1 | package net.oni2.aeinstaller.gui.mandatorypackages;
 | 
|---|
| 2 | 
 | 
|---|
| 3 | import java.awt.Dimension;
 | 
|---|
| 4 | import java.awt.event.ActionEvent;
 | 
|---|
| 5 | import java.awt.event.KeyEvent;
 | 
|---|
| 6 | import java.text.SimpleDateFormat;
 | 
|---|
| 7 | import java.util.Date;
 | 
|---|
| 8 | import java.util.ResourceBundle;
 | 
|---|
| 9 | import java.util.TreeSet;
 | 
|---|
| 10 | 
 | 
|---|
| 11 | import javax.swing.AbstractAction;
 | 
|---|
| 12 | import javax.swing.DefaultListModel;
 | 
|---|
| 13 | import javax.swing.JComponent;
 | 
|---|
| 14 | import javax.swing.JDialog;
 | 
|---|
| 15 | import javax.swing.JLabel;
 | 
|---|
| 16 | import javax.swing.JList;
 | 
|---|
| 17 | import javax.swing.JSplitPane;
 | 
|---|
| 18 | import javax.swing.KeyStroke;
 | 
|---|
| 19 | import javax.swing.ListSelectionModel;
 | 
|---|
| 20 | import javax.swing.event.ListSelectionEvent;
 | 
|---|
| 21 | import javax.swing.event.ListSelectionListener;
 | 
|---|
| 22 | 
 | 
|---|
| 23 | import net.oni2.aeinstaller.backend.SizeFormatter;
 | 
|---|
| 24 | import net.oni2.aeinstaller.backend.mods.Mod;
 | 
|---|
| 25 | import net.oni2.aeinstaller.backend.mods.ModManager;
 | 
|---|
| 26 | import net.oni2.aeinstaller.backend.mods.Type;
 | 
|---|
| 27 | import net.oni2.aeinstaller.gui.HTMLLinkLabel;
 | 
|---|
| 28 | 
 | 
|---|
| 29 | import org.javabuilders.BuildResult;
 | 
|---|
| 30 | import org.javabuilders.swing.SwingJavaBuilder;
 | 
|---|
| 31 | 
 | 
|---|
| 32 | /**
 | 
|---|
| 33 |  * @author Christian Illy
 | 
|---|
| 34 |  */
 | 
|---|
| 35 | public class MandatoryPackagesDialog extends JDialog implements
 | 
|---|
| 36 |                 ListSelectionListener {
 | 
|---|
| 37 |         private static final long serialVersionUID = -5444213842599816301L;
 | 
|---|
| 38 | 
 | 
|---|
| 39 |         private ResourceBundle bundle = ResourceBundle
 | 
|---|
| 40 |                         .getBundle("net.oni2.aeinstaller.localization."
 | 
|---|
| 41 |                                         + getClass().getSimpleName());
 | 
|---|
| 42 |         @SuppressWarnings("unused")
 | 
|---|
| 43 |         private BuildResult result = SwingJavaBuilder.build(this, bundle);
 | 
|---|
| 44 | 
 | 
|---|
| 45 |         private JSplitPane contents;
 | 
|---|
| 46 | 
 | 
|---|
| 47 |         private JList lstTools;
 | 
|---|
| 48 | 
 | 
|---|
| 49 |         private JLabel lblTitleVal;
 | 
|---|
| 50 |         private JLabel lblCreatorVal;
 | 
|---|
| 51 |         private JLabel lblTypesVal;
 | 
|---|
| 52 |         private JLabel lblPlatformVal;
 | 
|---|
| 53 |         private JLabel lblPackageNumberVal;
 | 
|---|
| 54 |         private JLabel lblVersionNumberVal;
 | 
|---|
| 55 |         private JLabel lblLastChangeVal;
 | 
|---|
| 56 |         private HTMLLinkLabel lblDescriptionVal;
 | 
|---|
| 57 |         private JLabel lblDownloadSizeVal;
 | 
|---|
| 58 | 
 | 
|---|
| 59 |         private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
 | 
|---|
| 60 | 
 | 
|---|
| 61 |         /**
 | 
|---|
| 62 |          * Open the dialog
 | 
|---|
| 63 |          */
 | 
|---|
| 64 |         public MandatoryPackagesDialog() {
 | 
|---|
| 65 |                 setMinimumSize(new Dimension(getWidth() + 100, getHeight() + 100));
 | 
|---|
| 66 | 
 | 
|---|
| 67 |                 AbstractAction closeAction = new AbstractAction() {
 | 
|---|
| 68 | 
 | 
|---|
| 69 |                         private static final long serialVersionUID = 1L;
 | 
|---|
| 70 | 
 | 
|---|
| 71 |                         public void actionPerformed(ActionEvent arg0) {
 | 
|---|
| 72 |                                 dispose();
 | 
|---|
| 73 |                         }
 | 
|---|
| 74 |                 };
 | 
|---|
| 75 |                 KeyStroke ksCtrlW = KeyStroke
 | 
|---|
| 76 |                                 .getKeyStroke('W', KeyEvent.CTRL_DOWN_MASK);
 | 
|---|
| 77 |                 getRootPane()
 | 
|---|
| 78 |                                 .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
 | 
|---|
| 79 |                                 .put(ksCtrlW, "close");
 | 
|---|
| 80 |                 getRootPane().getActionMap().put("close", closeAction);
 | 
|---|
| 81 | 
 | 
|---|
| 82 |                 contents.setDividerLocation(200);
 | 
|---|
| 83 |                 contents.setResizeWeight(0.4);
 | 
|---|
| 84 | 
 | 
|---|
| 85 |                 lstTools.addListSelectionListener(this);
 | 
|---|
| 86 |                 lstTools.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
 | 
|---|
| 87 | 
 | 
|---|
| 88 |                 DefaultListModel dlm = new DefaultListModel();
 | 
|---|
| 89 |                 TreeSet<Mod> tools = ModManager.getInstance().getMandatoryTools();
 | 
|---|
| 90 |                 for (Mod m : tools)
 | 
|---|
| 91 |                         dlm.addElement(m);
 | 
|---|
| 92 |                 TreeSet<Mod> mods = ModManager.getInstance().getMandatoryMods();
 | 
|---|
| 93 |                 for (Mod m : mods)
 | 
|---|
| 94 |                         dlm.addElement(m);
 | 
|---|
| 95 |                 lstTools.setModel(dlm);
 | 
|---|
| 96 | 
 | 
|---|
| 97 |                 setLocationRelativeTo(null);
 | 
|---|
| 98 |         }
 | 
|---|
| 99 | 
 | 
|---|
| 100 |         @Override
 | 
|---|
| 101 |         public void valueChanged(ListSelectionEvent evt) {
 | 
|---|
| 102 |                 lblTitleVal.setText("");
 | 
|---|
| 103 |                 lblCreatorVal.setText("");
 | 
|---|
| 104 |                 lblDescriptionVal.setText("");
 | 
|---|
| 105 |                 lblTypesVal.setText("");
 | 
|---|
| 106 |                 lblPlatformVal.setText("");
 | 
|---|
| 107 |                 lblPackageNumberVal.setText("");
 | 
|---|
| 108 |                 lblVersionNumberVal.setText("");
 | 
|---|
| 109 |                 lblLastChangeVal.setText("");
 | 
|---|
| 110 |                 lblDownloadSizeVal.setText("");
 | 
|---|
| 111 | 
 | 
|---|
| 112 |                 if (lstTools.getSelectedValue() instanceof Mod) {
 | 
|---|
| 113 |                         Mod m = (Mod) lstTools.getSelectedValue();
 | 
|---|
| 114 |                         lblTitleVal.setText(m.getName());
 | 
|---|
| 115 |                         lblCreatorVal.setText(m.getCreator());
 | 
|---|
| 116 |                         lblDescriptionVal.setText(m.getDescription());
 | 
|---|
| 117 | 
 | 
|---|
| 118 |                         String types = "";
 | 
|---|
| 119 |                         for (Type t : m.getTypes()) {
 | 
|---|
| 120 |                                 if (types.length() > 0)
 | 
|---|
| 121 |                                         types += ", ";
 | 
|---|
| 122 |                                 types += t.getName();
 | 
|---|
| 123 |                         }
 | 
|---|
| 124 |                         lblTypesVal.setText(types);
 | 
|---|
| 125 |                         lblPlatformVal.setText(m.getPlatform().toString());
 | 
|---|
| 126 |                         lblPackageNumberVal.setText(m.getPackageNumberString());
 | 
|---|
| 127 |                         lblVersionNumberVal.setText(m.getVersion());
 | 
|---|
| 128 |                         if (m.getFile() != null)
 | 
|---|
| 129 |                                 lblLastChangeVal.setText(sdf.format(new Date(m.getFile()
 | 
|---|
| 130 |                                                 .getTimestamp() * 1000)));
 | 
|---|
| 131 |                         lblDownloadSizeVal.setText(SizeFormatter.format(m.getZipSize(), 3));
 | 
|---|
| 132 |                 }
 | 
|---|
| 133 |         }
 | 
|---|
| 134 | }
 | 
|---|