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