| 1 | package net.oni2.aeinstaller.gui; | 
 
 
 
 
 | 2 |  | 
 
 
 
 
 | 3 | import java.awt.Frame; | 
 
 
 
 
 | 4 | import java.util.ArrayList; | 
 
 
 
 
 | 5 | import java.util.Comparator; | 
 
 
 
 
 | 6 | import java.util.List; | 
 
 
 
 
 | 7 | import java.util.ResourceBundle; | 
 
 
 
 
 | 8 | import java.util.TreeMap; | 
 
 
 
 
 | 9 |  | 
 
 
 
 
 | 10 | import javax.swing.JComboBox; | 
 
 
 
 
 | 11 | import javax.swing.JComponent; | 
 
 
 
 
 | 12 | import javax.swing.JFrame; | 
 
 
 
 
 | 13 | import javax.swing.JLabel; | 
 
 
 
 
 | 14 | import javax.swing.JMenu; | 
 
 
 
 
 | 15 | import javax.swing.JOptionPane; | 
 
 
 
 
 | 16 | import javax.swing.JSplitPane; | 
 
 
 
 
 | 17 | import javax.swing.JTable; | 
 
 
 
 
 | 18 | import javax.swing.ListSelectionModel; | 
 
 
 
 
 | 19 | import javax.swing.RowSorter; | 
 
 
 
 
 | 20 | import javax.swing.SortOrder; | 
 
 
 
 
 | 21 | import javax.swing.SwingUtilities; | 
 
 
 
 
 | 22 | import javax.swing.event.ListSelectionEvent; | 
 
 
 
 
 | 23 | import javax.swing.event.ListSelectionListener; | 
 
 
 
 
 | 24 | import javax.swing.table.TableRowSorter; | 
 
 
 
 
 | 25 |  | 
 
 
 
 
 | 26 | import net.oni2.aeinstaller.backend.Settings; | 
 
 
 
 
 | 27 | import net.oni2.aeinstaller.backend.Settings.Platform; | 
 
 
 
 
 | 28 | import net.oni2.aeinstaller.backend.depot.DepotCacheUpdateProgressListener; | 
 
 
 
 
 | 29 | import net.oni2.aeinstaller.backend.depot.DepotConfig; | 
 
 
 
 
 | 30 | import net.oni2.aeinstaller.backend.depot.DepotManager; | 
 
 
 
 
 | 31 | import net.oni2.aeinstaller.backend.depot.model.NodeMod; | 
 
 
 
 
 | 32 | import net.oni2.aeinstaller.backend.depot.model.TaxonomyTerm; | 
 
 
 
 
 | 33 | import net.oni2.aeinstaller.backend.depot.model.TaxonomyVocabulary; | 
 
 
 
 
 | 34 | import net.oni2.aeinstaller.gui.about.AboutDialog; | 
 
 
 
 
 | 35 | import net.oni2.aeinstaller.gui.modtable.ModTableFilter; | 
 
 
 
 
 | 36 | import net.oni2.aeinstaller.gui.modtable.ModTableModel; | 
 
 
 
 
 | 37 | import net.oni2.aeinstaller.gui.settings.SettingsDialog; | 
 
 
 
 
 | 38 |  | 
 
 
 
 
 | 39 | import org.javabuilders.BuildResult; | 
 
 
 
 
 | 40 | import org.javabuilders.annotations.DoInBackground; | 
 
 
 
 
 | 41 | import org.javabuilders.event.BackgroundEvent; | 
 
 
 
 
 | 42 | import org.javabuilders.swing.SwingJavaBuilder; | 
 
 
 
 
 | 43 | import org.simplericity.macify.eawt.ApplicationEvent; | 
 
 
 
 
 | 44 | import org.simplericity.macify.eawt.ApplicationListener; | 
 
 
 
 
 | 45 |  | 
 
 
 
 
 | 46 | /** | 
 
 
 
 
 | 47 | * @author Christian Illy | 
 
 
 
 
 | 48 | */ | 
 
 
 
 
 | 49 | public class MainWin extends JFrame implements ApplicationListener { | 
 
 
 
 
 | 50 | private static final long serialVersionUID = -4027395051382659650L; | 
 
 
 
 
 | 51 |  | 
 
 
 
 
 | 52 | private ResourceBundle bundle = ResourceBundle.getBundle(getClass() | 
 
 
 
 
 | 53 | .getName()); | 
 
 
 
 
 | 54 | @SuppressWarnings("unused") | 
 
 
 
 
 | 55 | private BuildResult result = SwingJavaBuilder.build(this, bundle); | 
 
 
 
 
 | 56 |  | 
 
 
 
 
 | 57 | private JMenu mainMenu; | 
 
 
 
 
 | 58 |  | 
 
 
 
 
 | 59 | private JSplitPane contents; | 
 
 
 
 
 | 60 |  | 
 
 
 
 
 | 61 | private JComboBox cmbModTypes; | 
 
 
 
 
 | 62 | private JTable tblMods; | 
 
 
 
 
 | 63 | private ModTableModel model; | 
 
 
 
 
 | 64 | private TableRowSorter<ModTableModel> sorter; | 
 
 
 
 
 | 65 |  | 
 
 
 
 
 | 66 | private JLabel lblSubmitterVal; | 
 
 
 
 
 | 67 | private JLabel lblCreatorVal; | 
 
 
 
 
 | 68 | private JLabel lblFilesVal; | 
 
 
 
 
 | 69 | private JLabel lblIdVal; | 
 
 
 
 
 | 70 | private HTMLLinkLabel lblDescriptionVal; | 
 
 
 
 
 | 71 |  | 
 
 
 
 
 | 72 | /** | 
 
 
 
 
 | 73 | * Constructor of main window. | 
 
 
 
 
 | 74 | */ | 
 
 
 
 
 | 75 | public MainWin() { | 
 
 
 
 
 | 76 | this.setTitle(SwingJavaBuilder.getConfig().getResource("appname") | 
 
 
 
 
 | 77 | + " - v" | 
 
 
 
 
 | 78 | + SwingJavaBuilder.getConfig().getResource("appversion")); | 
 
 
 
 
 | 79 |  | 
 
 
 
 
 | 80 | contents.setDividerLocation(400); | 
 
 
 
 
 | 81 | initTable(); | 
 
 
 
 
 | 82 | initModTypeBox(); | 
 
 
 
 
 | 83 |  | 
 
 
 
 
 | 84 | if (Settings.getPlatform() == Platform.MACOS) { | 
 
 
 
 
 | 85 | mainMenu.setVisible(false); | 
 
 
 
 
 | 86 | } | 
 
 
 
 
 | 87 | } | 
 
 
 
 
 | 88 |  | 
 
 
 
 
 | 89 | private void initModTypeBox() { | 
 
 
 
 
 | 90 | cmbModTypes.removeAllItems(); | 
 
 
 
 
 | 91 |  | 
 
 
 
 
 | 92 | TaxonomyVocabulary tv = DepotManager.getInstance().getVocabulary( | 
 
 
 
 
 | 93 | DepotConfig.getVocabularyName_ModType()); | 
 
 
 
 
 | 94 | if (tv == null) | 
 
 
 
 
 | 95 | return; | 
 
 
 
 
 | 96 |  | 
 
 
 
 
 | 97 | int vid = tv.getVid(); | 
 
 
 
 
 | 98 | TreeMap<String, TaxonomyTerm> terms = new TreeMap<String, TaxonomyTerm>(); | 
 
 
 
 
 | 99 | terms.put(" ", new TaxonomyTerm(-1, vid, "-All-")); | 
 
 
 
 
 | 100 | for (TaxonomyTerm t : DepotManager.getInstance() | 
 
 
 
 
 | 101 | .getTaxonomyTermsByVocabulary(vid)) { | 
 
 
 
 
 | 102 | terms.put(t.getName(), t); | 
 
 
 
 
 | 103 | } | 
 
 
 
 
 | 104 | for (TaxonomyTerm t : terms.values()) { | 
 
 
 
 
 | 105 | cmbModTypes.addItem(t); | 
 
 
 
 
 | 106 | } | 
 
 
 
 
 | 107 | cmbModTypes.setSelectedIndex(0); | 
 
 
 
 
 | 108 | } | 
 
 
 
 
 | 109 |  | 
 
 
 
 
 | 110 | private void initTable() { | 
 
 
 
 
 | 111 | tblMods.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); | 
 
 
 
 
 | 112 | tblMods.getSelectionModel().addListSelectionListener( | 
 
 
 
 
 | 113 | new ListSelectionListener() { | 
 
 
 
 
 | 114 |  | 
 
 
 
 
 | 115 | @Override | 
 
 
 
 
 | 116 | public void valueChanged(ListSelectionEvent e) { | 
 
 
 
 
 | 117 | int viewRow = tblMods.getSelectedRow(); | 
 
 
 
 
 | 118 | if (viewRow < 0) { | 
 
 
 
 
 | 119 | modSelection(null); | 
 
 
 
 
 | 120 | } else { | 
 
 
 
 
 | 121 | int modelRow = tblMods | 
 
 
 
 
 | 122 | .convertRowIndexToModel(viewRow); | 
 
 
 
 
 | 123 | NodeMod mod = (NodeMod) model.getValueAt(modelRow, | 
 
 
 
 
 | 124 | -1); | 
 
 
 
 
 | 125 | modSelection(mod); | 
 
 
 
 
 | 126 | } | 
 
 
 
 
 | 127 | } | 
 
 
 
 
 | 128 | }); | 
 
 
 
 
 | 129 |  | 
 
 
 
 
 | 130 | // To get checkbox-cells with background of row | 
 
 
 
 
 | 131 | ((JComponent) tblMods.getDefaultRenderer(Boolean.class)) | 
 
 
 
 
 | 132 | .setOpaque(true); | 
 
 
 
 
 | 133 |  | 
 
 
 
 
 | 134 | model = new ModTableModel(); | 
 
 
 
 
 | 135 |  | 
 
 
 
 
 | 136 | tblMods.setModel(model); | 
 
 
 
 
 | 137 |  | 
 
 
 
 
 | 138 | sorter = new TableRowSorter<ModTableModel>(model); | 
 
 
 
 
 | 139 | tblMods.setRowSorter(sorter); | 
 
 
 
 
 | 140 |  | 
 
 
 
 
 | 141 | sorter.setRowFilter(new ModTableFilter(-1)); | 
 
 
 
 
 | 142 |  | 
 
 
 
 
 | 143 | sorter.setSortable(2, false); | 
 
 
 
 
 | 144 | sorter.setComparator(1, new Comparator<String>() { | 
 
 
 
 
 | 145 |  | 
 
 
 
 
 | 146 | @Override | 
 
 
 
 
 | 147 | public int compare(String o1, String o2) { | 
 
 
 
 
 | 148 | int i1 = Integer.parseInt(o1); | 
 
 
 
 
 | 149 | int i2 = Integer.parseInt(o2); | 
 
 
 
 
 | 150 | return i1 - i2; | 
 
 
 
 
 | 151 | } | 
 
 
 
 
 | 152 | }); | 
 
 
 
 
 | 153 |  | 
 
 
 
 
 | 154 | List<RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>(); | 
 
 
 
 
 | 155 | sortKeys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING)); | 
 
 
 
 
 | 156 | sorter.setSortKeys(sortKeys); | 
 
 
 
 
 | 157 |  | 
 
 
 
 
 | 158 | for (int i = 0; i < model.getColumnCount(); i++) { | 
 
 
 
 
 | 159 | model.setColumnConstraints(i, tblMods.getColumnModel().getColumn(i)); | 
 
 
 
 
 | 160 | } | 
 
 
 
 
 | 161 |  | 
 
 
 
 
 | 162 | // for (int i = 3; i > 0; i--) { | 
 
 
 
 
 | 163 | // tblMods.getColumnModel().removeColumn(tblMods.getColumnModel().getColumn(i)); | 
 
 
 
 
 | 164 | // } | 
 
 
 
 
 | 165 | } | 
 
 
 
 
 | 166 |  | 
 
 
 
 
 | 167 | private boolean askClose() { | 
 
 
 
 
 | 168 | int res = JOptionPane.showConfirmDialog(this, | 
 
 
 
 
 | 169 | bundle.getString("askClose.text"), | 
 
 
 
 
 | 170 | bundle.getString("askClose.title"), JOptionPane.YES_NO_OPTION, | 
 
 
 
 
 | 171 | JOptionPane.QUESTION_MESSAGE); | 
 
 
 
 
 | 172 | return res == JOptionPane.YES_OPTION; | 
 
 
 
 
 | 173 | } | 
 
 
 
 
 | 174 |  | 
 
 
 
 
 | 175 | private boolean closeFrames() { | 
 
 
 
 
 | 176 | System.gc(); | 
 
 
 
 
 | 177 | for (Frame f : Frame.getFrames()) { | 
 
 
 
 
 | 178 | if (f != this) | 
 
 
 
 
 | 179 | f.dispose(); | 
 
 
 
 
 | 180 | } | 
 
 
 
 
 | 181 | return true; | 
 
 
 
 
 | 182 | } | 
 
 
 
 
 | 183 |  | 
 
 
 
 
 | 184 | private void exit() { | 
 
 
 
 
 | 185 | setVisible(false); | 
 
 
 
 
 | 186 | dispose(); | 
 
 
 
 
 | 187 | } | 
 
 
 
 
 | 188 |  | 
 
 
 
 
 | 189 | private void saveLocalData() { | 
 
 
 
 
 | 190 | Settings.getInstance().serializeToFile(); | 
 
 
 
 
 | 191 | DepotManager.getInstance().saveToFile(Settings.getDepotCacheFilename()); | 
 
 
 
 
 | 192 | } | 
 
 
 
 
 | 193 |  | 
 
 
 
 
 | 194 | @DoInBackground(progressMessage = "updateDepot.title", cancelable = false, indeterminateProgress = false) | 
 
 
 
 
 | 195 | private void execDepotUpdate(final BackgroundEvent evt) { | 
 
 
 
 
 | 196 | try { | 
 
 
 
 
 | 197 | DepotManager.getInstance().updateInformation(false, | 
 
 
 
 
 | 198 | new DepotCacheUpdateProgressListener() { | 
 
 
 
 
 | 199 |  | 
 
 
 
 
 | 200 | @Override | 
 
 
 
 
 | 201 | public void cacheUpdateProgress(String stepName, | 
 
 
 
 
 | 202 | int current, int total) { | 
 
 
 
 
 | 203 | evt.setProgressEnd(total); | 
 
 
 
 
 | 204 | evt.setProgressValue(current); | 
 
 
 
 
 | 205 | evt.setProgressMessage(stepName); | 
 
 
 
 
 | 206 | } | 
 
 
 
 
 | 207 | }); | 
 
 
 
 
 | 208 | model.reloadData(); | 
 
 
 
 
 | 209 | initModTypeBox(); | 
 
 
 
 
 | 210 | tblMods.setVisible(true); | 
 
 
 
 
 | 211 | DepotManager.getInstance().printStats(); | 
 
 
 
 
 | 212 | } catch (Exception e) { | 
 
 
 
 
 | 213 | e.printStackTrace(); | 
 
 
 
 
 | 214 | } | 
 
 
 
 
 | 215 | } | 
 
 
 
 
 | 216 |  | 
 
 
 
 
 | 217 | @SuppressWarnings("unused") | 
 
 
 
 
 | 218 | private void checkUpdates() { | 
 
 
 
 
 | 219 | if (Settings.getInstance().get("notifyupdates", true)) { | 
 
 
 
 
 | 220 | } | 
 
 
 
 
 | 221 | } | 
 
 
 
 
 | 222 |  | 
 
 
 
 
 | 223 | @SuppressWarnings("unused") | 
 
 
 
 
 | 224 | private void focus() { | 
 
 
 
 
 | 225 | SwingUtilities.invokeLater(new Runnable() { | 
 
 
 
 
 | 226 |  | 
 
 
 
 
 | 227 | @Override | 
 
 
 
 
 | 228 | public void run() { | 
 
 
 
 
 | 229 | toFront(); | 
 
 
 
 
 | 230 | repaint(); | 
 
 
 
 
 | 231 | } | 
 
 
 
 
 | 232 | }); | 
 
 
 
 
 | 233 |  | 
 
 
 
 
 | 234 | } | 
 
 
 
 
 | 235 |  | 
 
 
 
 
 | 236 | private void showSettings() { | 
 
 
 
 
 | 237 | new SettingsDialog().setVisible(true); | 
 
 
 
 
 | 238 | } | 
 
 
 
 
 | 239 |  | 
 
 
 
 
 | 240 | private void showAbout() { | 
 
 
 
 
 | 241 | new AboutDialog().setVisible(true); | 
 
 
 
 
 | 242 | } | 
 
 
 
 
 | 243 |  | 
 
 
 
 
 | 244 | @SuppressWarnings("unused") | 
 
 
 
 
 | 245 | private void loadConfig() { | 
 
 
 
 
 | 246 | // TODO Auto-generated method stub | 
 
 
 
 
 | 247 | JOptionPane.showMessageDialog(this, "loadConfig", "todo", | 
 
 
 
 
 | 248 | JOptionPane.INFORMATION_MESSAGE); | 
 
 
 
 
 | 249 | } | 
 
 
 
 
 | 250 |  | 
 
 
 
 
 | 251 | @SuppressWarnings("unused") | 
 
 
 
 
 | 252 | private void saveConfig() { | 
 
 
 
 
 | 253 | // TODO Auto-generated method stub | 
 
 
 
 
 | 254 | JOptionPane.showMessageDialog(this, "saveConfig", "todo", | 
 
 
 
 
 | 255 | JOptionPane.INFORMATION_MESSAGE); | 
 
 
 
 
 | 256 | } | 
 
 
 
 
 | 257 |  | 
 
 
 
 
 | 258 | @SuppressWarnings("unused") | 
 
 
 
 
 | 259 | private void reglobalize() { | 
 
 
 
 
 | 260 | // TODO Auto-generated method stub | 
 
 
 
 
 | 261 | JOptionPane.showMessageDialog(this, "reglobalize", "todo", | 
 
 
 
 
 | 262 | JOptionPane.INFORMATION_MESSAGE); | 
 
 
 
 
 | 263 | } | 
 
 
 
 
 | 264 |  | 
 
 
 
 
 | 265 | @SuppressWarnings("unused") | 
 
 
 
 
 | 266 | private void revertSelection() { | 
 
 
 
 
 | 267 | // TODO Auto-generated method stub | 
 
 
 
 
 | 268 | JOptionPane.showMessageDialog(this, "revertSelection", "todo", | 
 
 
 
 
 | 269 | JOptionPane.INFORMATION_MESSAGE); | 
 
 
 
 
 | 270 | } | 
 
 
 
 
 | 271 |  | 
 
 
 
 
 | 272 | private void modSelection(NodeMod n) { | 
 
 
 
 
 | 273 | lblSubmitterVal.setText(""); | 
 
 
 
 
 | 274 | lblCreatorVal.setText(""); | 
 
 
 
 
 | 275 | lblIdVal.setText(""); | 
 
 
 
 
 | 276 | lblFilesVal.setText(""); | 
 
 
 
 
 | 277 | lblDescriptionVal.setText(""); | 
 
 
 
 
 | 278 | if (n != null) { | 
 
 
 
 
 | 279 | lblSubmitterVal.setText(n.getName()); | 
 
 
 
 
 | 280 | lblCreatorVal.setText(n.getFields().get("creator")); | 
 
 
 
 
 | 281 | lblIdVal.setText(Integer.toString(n.getNid())); | 
 
 
 
 
 | 282 | lblFilesVal.setText(Integer.toString(n.getUploads().size())); | 
 
 
 
 
 | 283 | if (n.getBody() != null) | 
 
 
 
 
 | 284 | lblDescriptionVal.setText(n.getBody().getSafe_value()); | 
 
 
 
 
 | 285 | } | 
 
 
 
 
 | 286 | // TODO | 
 
 
 
 
 | 287 | } | 
 
 
 
 
 | 288 |  | 
 
 
 
 
 | 289 | @SuppressWarnings("unused") | 
 
 
 
 
 | 290 | private void modTypeSelection() { | 
 
 
 
 
 | 291 | TaxonomyTerm t = (TaxonomyTerm) cmbModTypes.getSelectedItem(); | 
 
 
 
 
 | 292 | if (t != null) | 
 
 
 
 
 | 293 | sorter.setRowFilter(new ModTableFilter(t.getTid())); | 
 
 
 
 
 | 294 | else | 
 
 
 
 
 | 295 | sorter.setRowFilter(new ModTableFilter(-1)); | 
 
 
 
 
 | 296 | } | 
 
 
 
 
 | 297 |  | 
 
 
 
 
 | 298 | @Override | 
 
 
 
 
 | 299 | public void handleAbout(ApplicationEvent event) { | 
 
 
 
 
 | 300 | event.setHandled(true); | 
 
 
 
 
 | 301 | showAbout(); | 
 
 
 
 
 | 302 | } | 
 
 
 
 
 | 303 |  | 
 
 
 
 
 | 304 | @Override | 
 
 
 
 
 | 305 | public void handleOpenApplication(ApplicationEvent event) { | 
 
 
 
 
 | 306 | } | 
 
 
 
 
 | 307 |  | 
 
 
 
 
 | 308 | @Override | 
 
 
 
 
 | 309 | public void handleOpenFile(ApplicationEvent event) { | 
 
 
 
 
 | 310 | } | 
 
 
 
 
 | 311 |  | 
 
 
 
 
 | 312 | @Override | 
 
 
 
 
 | 313 | public void handlePreferences(ApplicationEvent event) { | 
 
 
 
 
 | 314 | showSettings(); | 
 
 
 
 
 | 315 | } | 
 
 
 
 
 | 316 |  | 
 
 
 
 
 | 317 | @Override | 
 
 
 
 
 | 318 | public void handlePrintFile(ApplicationEvent event) { | 
 
 
 
 
 | 319 | } | 
 
 
 
 
 | 320 |  | 
 
 
 
 
 | 321 | @Override | 
 
 
 
 
 | 322 | public void handleQuit(ApplicationEvent event) { | 
 
 
 
 
 | 323 | if (askClose()) { | 
 
 
 
 
 | 324 | event.setHandled(true); | 
 
 
 
 
 | 325 | closeFrames(); | 
 
 
 
 
 | 326 | saveLocalData(); | 
 
 
 
 
 | 327 | exit(); | 
 
 
 
 
 | 328 | } else { | 
 
 
 
 
 | 329 | event.setHandled(false); | 
 
 
 
 
 | 330 | } | 
 
 
 
 
 | 331 | } | 
 
 
 
 
 | 332 |  | 
 
 
 
 
 | 333 | @Override | 
 
 
 
 
 | 334 | public void handleReOpenApplication(ApplicationEvent event) { | 
 
 
 
 
 | 335 | } | 
 
 
 
 
 | 336 | } |