Changeset 631 for AE/installer2/src/net/oni2/aeinstaller/gui
- Timestamp:
- Jan 18, 2013, 4:45:11 PM (12 years ago)
- Location:
- AE/installer2/src/net/oni2/aeinstaller/gui
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
AE/installer2/src/net/oni2/aeinstaller/gui/MainWin.java
r630 r631 4 4 import java.awt.Desktop; 5 5 import java.awt.event.ActionEvent; 6 import java.awt.event.ActionListener;7 6 import java.awt.event.ItemEvent; 8 7 import java.awt.event.ItemListener; 9 import java.awt.event.MouseAdapter;10 import java.awt.event.MouseEvent;11 8 import java.io.File; 12 9 import java.io.IOException; 13 10 import java.net.URL; 14 import java.util.ArrayList;15 11 import java.util.HashMap; 16 12 import java.util.HashSet; 17 import java.util.List;18 13 import java.util.ResourceBundle; 19 14 import java.util.TreeMap; … … 27 22 import javax.swing.JCheckBox; 28 23 import javax.swing.JComboBox; 29 import javax.swing.JComponent;30 24 import javax.swing.JFileChooser; 31 25 import javax.swing.JFrame; … … 35 29 import javax.swing.JOptionPane; 36 30 import javax.swing.JPanel; 37 import javax.swing.JPopupMenu;38 31 import javax.swing.JRadioButton; 39 32 import javax.swing.JSplitPane; 40 import javax.swing.JTable;41 import javax.swing.ListSelectionModel;42 import javax.swing.RowSorter;43 import javax.swing.SortOrder;44 33 import javax.swing.SwingUtilities; 45 import javax.swing.event.ListSelectionEvent; 46 import javax.swing.event.ListSelectionListener; 34 import javax.swing.ToolTipManager; 47 35 import javax.swing.filechooser.FileFilter; 48 import javax.swing.table.TableRowSorter;49 36 50 37 import net.oni2.aeinstaller.AEInstaller2; … … 68 55 import net.oni2.aeinstaller.gui.downloadwindow.Downloader; 69 56 import net.oni2.aeinstaller.gui.modtable.DownloadSizeListener; 70 import net.oni2.aeinstaller.gui.modtable.Mod TableFilter;71 import net.oni2.aeinstaller.gui.modtable.ModTable Model;57 import net.oni2.aeinstaller.gui.modtable.ModSelectionListener; 58 import net.oni2.aeinstaller.gui.modtable.ModTable; 72 59 import net.oni2.aeinstaller.gui.settings.SettingsDialog; 73 60 import net.oni2.aeinstaller.gui.toolmanager.ToolManager; … … 84 71 */ 85 72 public class MainWin extends JFrame implements ApplicationListener, 86 DownloadSizeListener {73 DownloadSizeListener, ModSelectionListener { 87 74 private static final long serialVersionUID = -4027395051382659650L; 88 75 … … 103 90 private JRadioButton radOnline; 104 91 private JRadioButton radLocal; 105 private JTable tblMods; 106 private ModTableModel model; 107 private TableRowSorter<ModTableModel> sorter; 92 private ModTable tblMods; 108 93 private JLabel lblDownloadSizeVal; 109 94 … … 136 121 137 122 contents.setDividerLocation(400); 123 contents.setResizeWeight(0.4); 138 124 139 125 if (Settings.getPlatform() == Platform.MACOS) { 140 126 mainMenu.setVisible(false); 141 127 } 128 129 ToolTipManager.sharedInstance().setInitialDelay(250); 142 130 143 131 getRootPane().setDefaultButton(btnInstall); 144 132 lblDownloadSizeVal.setText(SizeFormatter.format(0, 2)); 145 133 radAll.setSelected(true); 134 135 tblMods.addModSelectionListener(this); 136 tblMods.addDownloadSizeListener(this); 146 137 } 147 138 … … 158 149 } 159 150 cmbModTypes.setSelectedIndex(0); 160 }161 162 private void initTable() {163 tblMods.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);164 tblMods.getSelectionModel().addListSelectionListener(165 new ListSelectionListener() {166 @Override167 public void valueChanged(ListSelectionEvent e) {168 int viewRow = tblMods.getSelectedRow();169 if (viewRow < 0) {170 modSelection(null);171 } else {172 int modelRow = tblMods173 .convertRowIndexToModel(viewRow);174 Mod mod = (Mod) model.getValueAt(modelRow, -1);175 modSelection(mod);176 }177 }178 });179 tblMods.addMouseListener(new MouseAdapter() {180 private void common(MouseEvent e) {181 int r = tblMods.rowAtPoint(e.getPoint());182 if (r >= 0 && r < tblMods.getRowCount())183 tblMods.setRowSelectionInterval(r, r);184 else185 tblMods.clearSelection();186 187 int rowindex = tblMods.getSelectedRow();188 if (rowindex >= 0) {189 if (e.isPopupTrigger()190 && e.getComponent() instanceof JTable) {191 int modelRow = tblMods.convertRowIndexToModel(rowindex);192 final Mod mod = (Mod) model.getValueAt(modelRow, -1);193 194 if (mod.isLocalAvailable()) {195 JPopupMenu popup = new JPopupMenu();196 JMenuItem openModFolder = new JMenuItem(bundle197 .getString("openModFolder.text"));198 openModFolder199 .addActionListener(new ActionListener() {200 @Override201 public void actionPerformed(202 ActionEvent arg0) {203 try {204 Desktop.getDesktop().open(205 mod.getLocalPath());206 } catch (IOException e) {207 e.printStackTrace();208 }209 }210 });211 popup.add(openModFolder);212 popup.show(e.getComponent(), e.getX(), e.getY());213 }214 }215 }216 }217 218 @Override219 public void mousePressed(MouseEvent e) {220 common(e);221 }222 223 @Override224 public void mouseReleased(MouseEvent e) {225 common(e);226 }227 });228 // To get checkbox-cells with background of row229 ((JComponent) tblMods.getDefaultRenderer(Boolean.class))230 .setOpaque(true);231 232 model = new ModTableModel();233 model.addDownloadSizeListener(this);234 235 tblMods.setModel(model);236 237 sorter = new TableRowSorter<ModTableModel>(model);238 tblMods.setRowSorter(sorter);239 240 sorter.setRowFilter(new ModTableFilter(null, 0));241 242 List<RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>();243 sortKeys.add(new RowSorter.SortKey(1, SortOrder.ASCENDING));244 sorter.setSortKeys(sortKeys);245 246 for (int i = 0; i < model.getColumnCount(); i++) {247 model.setColumnConstraints(i, tblMods.getColumnModel().getColumn(i));248 }249 151 } 250 152 … … 279 181 } 280 182 ModManager.getInstance().init(); 281 initTable();183 tblMods.reloadData(); 282 184 initModTypeBox(); 283 185 … … 430 332 if (res == JFileChooser.APPROVE_OPTION) { 431 333 if (fc.getSelectedFile().exists()) 432 model.reloadSelection(fc.getSelectedFile());334 tblMods.reloadSelection(fc.getSelectedFile()); 433 335 } 434 336 } … … 443 345 f = new File(f.getParentFile(), f.getName() + ".xml"); 444 346 ModManager.getInstance().saveModSelection(f, 445 model.getSelectedMods());347 tblMods.getSelectedMods()); 446 348 } 447 349 } … … 500 402 @SuppressWarnings("unused") 501 403 private void revertSelection() { 502 model.revertSelection();404 tblMods.revertSelection(); 503 405 } 504 406 … … 548 450 TreeSet<Mod> mods = new TreeSet<Mod>(); 549 451 mods.addAll(ModManager.getInstance().getMandatoryMods()); 550 mods.addAll( model.getSelectedMods());452 mods.addAll(tblMods.getSelectedMods()); 551 453 552 454 boolean instReady = false; … … 644 546 } 645 547 646 private void modSelection(Mod m) { 548 @Override 549 public void modSelectionChanged(ModTable source, Mod m) { 647 550 lblSubmitterVal.setText(""); 648 551 lblCreatorVal.setText(""); … … 678 581 if (radLocal.isSelected()) 679 582 downloadState = 2; 680 sorter.setRowFilter(new ModTableFilter(t, downloadState));583 tblMods.setFilter(t, downloadState); 681 584 } 682 585 -
AE/installer2/src/net/oni2/aeinstaller/gui/MainWin.yml
r630 r631 56 56 - ButtonGroup: [radAll,radOnline,radLocal] 57 57 - JScrollPane(name=scrollMods, vScrollBar=always, hScrollBar=never): 58 JTable(name=tblMods, visible=false)58 ModTable(name=tblMods, visible=false) 59 59 - JButton(name=btnRevertSelection, icon=img.undo16, text=btnRevertSelection.text, toolTipText=btnRevertSelection.tooltip, onAction=[revertSelection]) 60 60 - JButton(name=btnInstall, icon=img.install, text=btnInstall.text, toolTipText=btnInstall.tooltip, onAction=[install,installDone]) -
AE/installer2/src/net/oni2/aeinstaller/gui/modtable/ModTableModel.java
r630 r631 21 21 22 22 private ResourceBundle bundle = ResourceBundle 23 .getBundle("net.oni2.aeinstaller.localization." 24 + getClass().getSimpleName()); 23 .getBundle("net.oni2.aeinstaller.localization.ModTable"); 25 24 26 25 private Vector<Mod> items = new Vector<Mod>(); … … 33 32 */ 34 33 public ModTableModel() { 35 reloadData();36 34 } 37 35 … … 50 48 case 3: 51 49 return mod.getCreator(); 50 case 4: 51 String res = ""; 52 res += (install.get(row) ? "I" : "_"); 53 res += (mod.isLocalAvailable() && mod.isNewerAvailable() ? "U" 54 : "_"); 55 res += (mod.isLocalAvailable() ? "D" : "_"); 56 return res; 52 57 } 53 58 return null; … … 65 70 case 3: 66 71 return bundle.getString("mod.creator"); 72 case 4: 73 return bundle.getString("mod.state"); 67 74 } 68 75 return null; … … 76 83 @Override 77 84 public int getColumnCount() { 78 return 4;85 return 5; 79 86 } 80 87 … … 89 96 return String.class; 90 97 case 3: 98 return String.class; 99 case 4: 91 100 return String.class; 92 101 } … … 123 132 col.setPreferredWidth(90); 124 133 break; 134 case 4: 135 w = 55; 136 col.setPreferredWidth(w); 137 col.setMinWidth(w); 138 col.setMaxWidth(w); 139 break; 125 140 } 126 141 } … … 141 156 install.clear(); 142 157 for (int i = 0; i < items.size(); i++) { 143 install.add(i, ModManager.getInstance() 144 .isModInstalled(items.get(i))); 158 install.add(i, items.get(i).isInstalled()); 145 159 } 146 160 fireTableDataChanged();
Note:
See TracChangeset
for help on using the changeset viewer.