| 1 | 
 package net.oni2.aeinstaller.gui; | 
 
 
 
 
 
 | 2 | 
  | 
 
 
 
 
 
 | 3 | 
 import java.awt.Frame; | 
 
 
 
 
 
 | 4 | 
 import java.io.File; | 
 
 
 
 
 
 | 5 | 
 import java.util.ArrayList; | 
 
 
 
 
 
 | 6 | 
 import java.util.Comparator; | 
 
 
 
 
 
 | 7 | 
 import java.util.List; | 
 
 
 
 
 
 | 8 | 
 import java.util.ResourceBundle; | 
 
 
 
 
 
 | 9 | 
 import java.util.TreeMap; | 
 
 
 
 
 
 | 10 | 
  | 
 
 
 
 
 
 | 11 | 
 import javax.swing.JComboBox; | 
 
 
 
 
 
 | 12 | 
 import javax.swing.JFrame; | 
 
 
 
 
 
 | 13 | 
 import javax.swing.JOptionPane; | 
 
 
 
 
 
 | 14 | 
 import javax.swing.JTable; | 
 
 
 
 
 
 | 15 | 
 import javax.swing.ListSelectionModel; | 
 
 
 
 
 
 | 16 | 
 import javax.swing.RowSorter; | 
 
 
 
 
 
 | 17 | 
 import javax.swing.RowSorter.SortKey; | 
 
 
 
 
 
 | 18 | 
 import javax.swing.SortOrder; | 
 
 
 
 
 
 | 19 | 
 import javax.swing.SwingUtilities; | 
 
 
 
 
 
 | 20 | 
 import javax.swing.event.ListSelectionEvent; | 
 
 
 
 
 
 | 21 | 
 import javax.swing.event.ListSelectionListener; | 
 
 
 
 
 
 | 22 | 
 import javax.swing.table.TableRowSorter; | 
 
 
 
 
 
 | 23 | 
  | 
 
 
 
 
 
 | 24 | 
 import net.oni2.aeinstaller.backend.Settings; | 
 
 
 
 
 
 | 25 | 
 import net.oni2.aeinstaller.backend.StuffToRefactorLater; | 
 
 
 
 
 
 | 26 | 
 import net.oni2.aeinstaller.backend.depot.DepotCacheUpdateProgressListener; | 
 
 
 
 
 
 | 27 | 
 import net.oni2.aeinstaller.backend.depot.DepotConfig; | 
 
 
 
 
 
 | 28 | 
 import net.oni2.aeinstaller.backend.depot.DepotManager; | 
 
 
 
 
 
 | 29 | 
 import net.oni2.aeinstaller.backend.depot.model.NodeMod; | 
 
 
 
 
 
 | 30 | 
 import net.oni2.aeinstaller.backend.depot.model.TaxonomyTerm; | 
 
 
 
 
 
 | 31 | 
 import net.oni2.aeinstaller.gui.modtable.ModTableFilter; | 
 
 
 
 
 
 | 32 | 
 import net.oni2.aeinstaller.gui.modtable.ModTableModel; | 
 
 
 
 
 
 | 33 | 
 import net.oni2.aeinstaller.gui.settings.SettingsDialog; | 
 
 
 
 
 
 | 34 | 
  | 
 
 
 
 
 
 | 35 | 
 import org.javabuilders.BuildResult; | 
 
 
 
 
 
 | 36 | 
 import org.javabuilders.annotations.DoInBackground; | 
 
 
 
 
 
 | 37 | 
 import org.javabuilders.event.BackgroundEvent; | 
 
 
 
 
 
 | 38 | 
 import org.javabuilders.swing.SwingJavaBuilder; | 
 
 
 
 
 
 | 39 | 
  | 
 
 
 
 
 
 | 40 | 
 /** | 
 
 
 
 
 
 | 41 | 
  * @author Christian Illy | 
 
 
 
 
 
 | 42 | 
  */ | 
 
 
 
 
 
 | 43 | 
 public class MainWin extends JFrame implements ListSelectionListener { | 
 
 
 
 
 
 | 44 | 
         private static final long serialVersionUID = -4027395051382659650L; | 
 
 
 
 
 
 | 45 | 
  | 
 
 
 
 
 
 | 46 | 
         private ResourceBundle bundle = ResourceBundle.getBundle(getClass() | 
 
 
 
 
 
 | 47 | 
                         .getName()); | 
 
 
 
 
 
 | 48 | 
         @SuppressWarnings("unused") | 
 
 
 
 
 
 | 49 | 
         private BuildResult result = SwingJavaBuilder.build(this, bundle); | 
 
 
 
 
 
 | 50 | 
  | 
 
 
 
 
 
 | 51 | 
         private JComboBox cmbModTypes; | 
 
 
 
 
 
 | 52 | 
         private JTable tblMods; | 
 
 
 
 
 
 | 53 | 
         private ModTableModel model; | 
 
 
 
 
 
 | 54 | 
         private TableRowSorter<ModTableModel> sorter; | 
 
 
 
 
 
 | 55 | 
  | 
 
 
 
 
 
 | 56 | 
         /** | 
 
 
 
 
 
 | 57 | 
          * Constructor of main window. | 
 
 
 
 
 
 | 58 | 
          */ | 
 
 
 
 
 
 | 59 | 
         public MainWin() { | 
 
 
 
 
 
 | 60 | 
                 this.setTitle(bundle.getString("frame.title") + " - v" | 
 
 
 
 
 
 | 61 | 
                                 + bundle.getString("version")); | 
 
 
 
 
 
 | 62 | 
  | 
 
 
 
 
 
 | 63 | 
                 initTable(); | 
 
 
 
 
 
 | 64 | 
                 initModTypeBox(); | 
 
 
 
 
 
 | 65 | 
         } | 
 
 
 
 
 
 | 66 | 
  | 
 
 
 
 
 
 | 67 | 
         private void initModTypeBox() { | 
 
 
 
 
 
 | 68 | 
                 int vid = DepotManager.getInstance() | 
 
 
 
 
 
 | 69 | 
                                 .getVocabulary(DepotConfig.MODTYPE_VOCAB).getVid(); | 
 
 
 
 
 
 | 70 | 
                 TreeMap<String, TaxonomyTerm> terms = new TreeMap<String, TaxonomyTerm>(); | 
 
 
 
 
 
 | 71 | 
                 terms.put(" ", new TaxonomyTerm(-1, vid, "-All-")); | 
 
 
 
 
 
 | 72 | 
                 for (TaxonomyTerm t : DepotManager.getInstance() | 
 
 
 
 
 
 | 73 | 
                                 .getTaxonomyTermsByVocabulary(vid)) { | 
 
 
 
 
 
 | 74 | 
                         terms.put(t.getName(), t); | 
 
 
 
 
 
 | 75 | 
                 } | 
 
 
 
 
 
 | 76 | 
                 for (TaxonomyTerm t : terms.values()) { | 
 
 
 
 
 
 | 77 | 
                         cmbModTypes.addItem(t); | 
 
 
 
 
 
 | 78 | 
                 } | 
 
 
 
 
 
 | 79 | 
                 cmbModTypes.setSelectedIndex(0); | 
 
 
 
 
 
 | 80 | 
         } | 
 
 
 
 
 
 | 81 | 
  | 
 
 
 
 
 
 | 82 | 
         private void initTable() { | 
 
 
 
 
 
 | 83 | 
                 tblMods.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); | 
 
 
 
 
 
 | 84 | 
                 tblMods.getSelectionModel().addListSelectionListener(this); | 
 
 
 
 
 
 | 85 | 
  | 
 
 
 
 
 
 | 86 | 
                 model = new ModTableModel(); | 
 
 
 
 
 
 | 87 | 
  | 
 
 
 
 
 
 | 88 | 
                 tblMods.setModel(model); | 
 
 
 
 
 
 | 89 | 
  | 
 
 
 
 
 
 | 90 | 
                 sorter = new TableRowSorter<ModTableModel>(model); | 
 
 
 
 
 
 | 91 | 
                 tblMods.setRowSorter(sorter); | 
 
 
 
 
 
 | 92 | 
  | 
 
 
 
 
 
 | 93 | 
                 sorter.setRowFilter(new ModTableFilter(-1)); | 
 
 
 
 
 
 | 94 | 
  | 
 
 
 
 
 
 | 95 | 
                 sorter.setSortable(2, false); | 
 
 
 
 
 
 | 96 | 
                 sorter.setComparator(1, new Comparator<String>() { | 
 
 
 
 
 
 | 97 | 
  | 
 
 
 
 
 
 | 98 | 
                         @Override | 
 
 
 
 
 
 | 99 | 
                         public int compare(String o1, String o2) { | 
 
 
 
 
 
 | 100 | 
                                 int i1 = Integer.parseInt(o1); | 
 
 
 
 
 
 | 101 | 
                                 int i2 = Integer.parseInt(o2); | 
 
 
 
 
 
 | 102 | 
                                 return i1 - i2; | 
 
 
 
 
 
 | 103 | 
                         } | 
 
 
 
 
 
 | 104 | 
                 }); | 
 
 
 
 
 
 | 105 | 
  | 
 
 
 
 
 
 | 106 | 
                 List<RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>(); | 
 
 
 
 
 
 | 107 | 
                 sortKeys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING)); | 
 
 
 
 
 
 | 108 | 
                 sorter.setSortKeys(sortKeys); | 
 
 
 
 
 
 | 109 | 
  | 
 
 
 
 
 
 | 110 | 
                 for (int i = 0; i < model.getColumnCount(); i++) { | 
 
 
 
 
 
 | 111 | 
                         model.setColumnConstraints(i, tblMods.getColumnModel().getColumn(i)); | 
 
 
 
 
 
 | 112 | 
                 } | 
 
 
 
 
 
 | 113 | 
  | 
 
 
 
 
 
 | 114 | 
                 // for (int i = 3; i > 0; i--) { | 
 
 
 
 
 
 | 115 | 
                 // tblMods.getColumnModel().removeColumn(tblMods.getColumnModel().getColumn(i)); | 
 
 
 
 
 
 | 116 | 
                 // } | 
 
 
 
 
 
 | 117 | 
         } | 
 
 
 
 
 
 | 118 | 
  | 
 
 
 
 
 
 | 119 | 
         @SuppressWarnings("unused") | 
 
 
 
 
 
 | 120 | 
         private boolean closeFrames() { | 
 
 
 
 
 
 | 121 | 
                 System.gc(); | 
 
 
 
 
 
 | 122 | 
                 for (Frame f : Frame.getFrames()) { | 
 
 
 
 
 
 | 123 | 
                         if (f != this) | 
 
 
 
 
 
 | 124 | 
                                 f.dispose(); | 
 
 
 
 
 
 | 125 | 
                 } | 
 
 
 
 
 
 | 126 | 
                 return true; | 
 
 
 
 
 
 | 127 | 
         } | 
 
 
 
 
 
 | 128 | 
  | 
 
 
 
 
 
 | 129 | 
         private void exit() { | 
 
 
 
 
 
 | 130 | 
                 setVisible(false); | 
 
 
 
 
 
 | 131 | 
                 dispose(); | 
 
 
 
 
 
 | 132 | 
         } | 
 
 
 
 
 
 | 133 | 
  | 
 
 
 
 
 
 | 134 | 
         @SuppressWarnings("unused") | 
 
 
 
 
 
 | 135 | 
         private void saveLocalData() { | 
 
 
 
 
 
 | 136 | 
                 Settings.getInstance().serializeToFile(); | 
 
 
 
 
 
 | 137 | 
                 DepotManager.getInstance().saveToFile( | 
 
 
 
 
 
 | 138 | 
                                 new File(Settings.getDepotCacheFilename())); | 
 
 
 
 
 
 | 139 | 
         } | 
 
 
 
 
 
 | 140 | 
  | 
 
 
 
 
 
 | 141 | 
         @SuppressWarnings("unused") | 
 
 
 
 
 
 | 142 | 
         private boolean validatePath() { | 
 
 
 
 
 
 | 143 | 
                 if (!StuffToRefactorLater.verifyRunningDirectory()) { | 
 
 
 
 
 
 | 144 | 
                         JOptionPane.showMessageDialog(this, | 
 
 
 
 
 
 | 145 | 
                                         bundle.getString("invalidPath.text"), | 
 
 
 
 
 
 | 146 | 
                                         bundle.getString("invalidPath.title"), | 
 
 
 
 
 
 | 147 | 
                                         JOptionPane.ERROR_MESSAGE); | 
 
 
 
 
 
 | 148 | 
                         if (!Settings.getDebug()) { | 
 
 
 
 
 
 | 149 | 
                                 exit(); | 
 
 
 
 
 
 | 150 | 
                                 return false; | 
 
 
 
 
 
 | 151 | 
                         } | 
 
 
 
 
 
 | 152 | 
                 } | 
 
 
 
 
 
 | 153 | 
                 return true; | 
 
 
 
 
 
 | 154 | 
         } | 
 
 
 
 
 
 | 155 | 
  | 
 
 
 
 
 
 | 156 | 
         @DoInBackground(progressMessage = "updateDepot.title", cancelable = false, indeterminateProgress = false) | 
 
 
 
 
 
 | 157 | 
         private void execDepotUpdate(final BackgroundEvent evt) { | 
 
 
 
 
 
 | 158 | 
                 try { | 
 
 
 
 
 
 | 159 | 
                         DepotManager.getInstance().updateInformation(false, | 
 
 
 
 
 
 | 160 | 
                                         new DepotCacheUpdateProgressListener() { | 
 
 
 
 
 
 | 161 | 
  | 
 
 
 
 
 
 | 162 | 
                                                 @Override | 
 
 
 
 
 
 | 163 | 
                                                 public void cacheUpdateProgress(String stepName, | 
 
 
 
 
 
 | 164 | 
                                                                 int current, int total) { | 
 
 
 
 
 
 | 165 | 
                                                         evt.setProgressEnd(total); | 
 
 
 
 
 
 | 166 | 
                                                         evt.setProgressValue(current); | 
 
 
 
 
 
 | 167 | 
                                                         evt.setProgressMessage(stepName); | 
 
 
 
 
 
 | 168 | 
                                                 } | 
 
 
 
 
 
 | 169 | 
                                         }); | 
 
 
 
 
 
 | 170 | 
                         model.reloadData(); | 
 
 
 
 
 
 | 171 | 
                         DepotManager.getInstance().printStats(); | 
 
 
 
 
 
 | 172 | 
                 } catch (Exception e) { | 
 
 
 
 
 
 | 173 | 
                         e.printStackTrace(); | 
 
 
 
 
 
 | 174 | 
                 } | 
 
 
 
 
 
 | 175 | 
         } | 
 
 
 
 
 
 | 176 | 
  | 
 
 
 
 
 
 | 177 | 
         @SuppressWarnings("unused") | 
 
 
 
 
 
 | 178 | 
         private void checkUpdates() { | 
 
 
 
 
 
 | 179 | 
                 if (Settings.getInstance().get("notifyupdates", true)) { | 
 
 
 
 
 
 | 180 | 
                 } | 
 
 
 
 
 
 | 181 | 
         } | 
 
 
 
 
 
 | 182 | 
  | 
 
 
 
 
 
 | 183 | 
         @SuppressWarnings("unused") | 
 
 
 
 
 
 | 184 | 
         private void focus() { | 
 
 
 
 
 
 | 185 | 
                 SwingUtilities.invokeLater(new Runnable() { | 
 
 
 
 
 
 | 186 | 
  | 
 
 
 
 
 
 | 187 | 
                         @Override | 
 
 
 
 
 
 | 188 | 
                         public void run() { | 
 
 
 
 
 
 | 189 | 
                                 toFront(); | 
 
 
 
 
 
 | 190 | 
                                 repaint(); | 
 
 
 
 
 
 | 191 | 
                         } | 
 
 
 
 
 
 | 192 | 
                 }); | 
 
 
 
 
 
 | 193 | 
  | 
 
 
 
 
 
 | 194 | 
         } | 
 
 
 
 
 
 | 195 | 
  | 
 
 
 
 
 
 | 196 | 
         @SuppressWarnings("unused") | 
 
 
 
 
 
 | 197 | 
         private void showSettings() { | 
 
 
 
 
 
 | 198 | 
                 SettingsDialog.openWindow(); | 
 
 
 
 
 
 | 199 | 
         } | 
 
 
 
 
 
 | 200 | 
  | 
 
 
 
 
 
 | 201 | 
         @SuppressWarnings("unused") | 
 
 
 
 
 
 | 202 | 
         private void modTypeSelection() { | 
 
 
 
 
 
 | 203 | 
                 TaxonomyTerm t = (TaxonomyTerm) cmbModTypes.getSelectedItem(); | 
 
 
 
 
 
 | 204 | 
                 sorter.setRowFilter(new ModTableFilter(t.getTid())); | 
 
 
 
 
 
 | 205 | 
         } | 
 
 
 
 
 
 | 206 | 
  | 
 
 
 
 
 
 | 207 | 
         @SuppressWarnings("unused") | 
 
 
 
 
 
 | 208 | 
         private void sortAlpha() { | 
 
 
 
 
 
 | 209 | 
                 SortOrder order = SortOrder.ASCENDING; | 
 
 
 
 
 
 | 210 | 
                 for (SortKey sk : sorter.getSortKeys()) { | 
 
 
 
 
 
 | 211 | 
                         if (sk.getColumn() == 0) { | 
 
 
 
 
 
 | 212 | 
                                 if (sk.getSortOrder() == SortOrder.ASCENDING) | 
 
 
 
 
 
 | 213 | 
                                         order = SortOrder.DESCENDING; | 
 
 
 
 
 
 | 214 | 
                         } | 
 
 
 
 
 
 | 215 | 
                 } | 
 
 
 
 
 
 | 216 | 
                 List<RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>(); | 
 
 
 
 
 
 | 217 | 
                 sortKeys.add(new RowSorter.SortKey(0, order)); | 
 
 
 
 
 
 | 218 | 
                 sorter.setSortKeys(sortKeys); | 
 
 
 
 
 
 | 219 | 
         } | 
 
 
 
 
 
 | 220 | 
  | 
 
 
 
 
 
 | 221 | 
         @SuppressWarnings("unused") | 
 
 
 
 
 
 | 222 | 
         private void sortPackageNumber() { | 
 
 
 
 
 
 | 223 | 
                 SortOrder order = SortOrder.ASCENDING; | 
 
 
 
 
 
 | 224 | 
                 for (SortKey sk : sorter.getSortKeys()) { | 
 
 
 
 
 
 | 225 | 
                         if (sk.getColumn() == 1) { | 
 
 
 
 
 
 | 226 | 
                                 if (sk.getSortOrder() == SortOrder.ASCENDING) | 
 
 
 
 
 
 | 227 | 
                                         order = SortOrder.DESCENDING; | 
 
 
 
 
 
 | 228 | 
                         } | 
 
 
 
 
 
 | 229 | 
                 } | 
 
 
 
 
 
 | 230 | 
                 List<RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>(); | 
 
 
 
 
 
 | 231 | 
                 sortKeys.add(new RowSorter.SortKey(1, order)); | 
 
 
 
 
 
 | 232 | 
                 sorter.setSortKeys(sortKeys); | 
 
 
 
 
 
 | 233 | 
         } | 
 
 
 
 
 
 | 234 | 
  | 
 
 
 
 
 
 | 235 | 
         @Override | 
 
 
 
 
 
 | 236 | 
         public void valueChanged(ListSelectionEvent arg0) { | 
 
 
 
 
 
 | 237 | 
                 int viewRow = tblMods.getSelectedRow(); | 
 
 
 
 
 
 | 238 | 
                 if (viewRow < 0) | 
 
 
 
 
 
 | 239 | 
                         // TODO | 
 
 
 
 
 
 | 240 | 
                         return; | 
 
 
 
 
 
 | 241 | 
                 int modelRow = tblMods.convertRowIndexToModel(viewRow); | 
 
 
 
 
 
 | 242 | 
                 NodeMod mod = (NodeMod) model.getValueAt(modelRow, -1); | 
 
 
 
 
 
 | 243 | 
                 // TODO | 
 
 
 
 
 
 | 244 | 
         } | 
 
 
 
 
 
 | 245 | 
 } |