From: kruland2607 Date: Tue, 5 Jun 2012 18:13:20 +0000 (+0000) Subject: Fixed two bugs. When the data in the table was sorted, the incorrect row in the... X-Git-Tag: upstream/12.09^2~200 X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=0ddc81f7b8eb861b225463e38836cd3c8c4fa901;p=debian%2Fopenrocket Fixed two bugs. When the data in the table was sorted, the incorrect row in the model was being manipulated. Fixed the problem where the derived materials (based on component's mass value) were being placed in the materials list. git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@758 180e2498-e6e9-4542-8430-84ac67f01cd8 --- diff --git a/core/src/net/sf/openrocket/gui/preset/ComponentPresetEditor.java b/core/src/net/sf/openrocket/gui/preset/ComponentPresetEditor.java index 3c9f7878..c8d4a191 100644 --- a/core/src/net/sf/openrocket/gui/preset/ComponentPresetEditor.java +++ b/core/src/net/sf/openrocket/gui/preset/ComponentPresetEditor.java @@ -112,20 +112,21 @@ public class ComponentPresetEditor extends JPanel implements PresetResultListene table.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { JTable target = (JTable) e.getSource(); - if (target.getSelectedColumn() == 4) { + int selectedColumn = table.getColumnModel().getColumnIndexAtX( target.getSelectedColumn() ); + int selectedRow = table.getRowSorter().convertRowIndexToModel( target.getSelectedRow() ); + if (selectedColumn == 4) { if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(ComponentPresetEditor.this, "Do you want to delete this preset?", "Confirm Delete", JOptionPane.YES_OPTION, JOptionPane.QUESTION_MESSAGE)) { - model.removeRow(target.getSelectedRow()); + model.removeRow(selectedRow); } } else { if (e.getClickCount() == 2) { - int row = target.getSelectedRow(); editContext.setEditingSelected(true); new PresetEditorDialog(ComponentPresetEditor.this, - (ComponentPreset) model.getAssociatedObject(row), editContext.getMaterialsLoaded()).setVisible(true); + (ComponentPreset) model.getAssociatedObject(selectedRow), editContext.getMaterialsLoaded()).setVisible(true); } } } @@ -431,9 +432,6 @@ public class ComponentPresetEditor extends JPanel implements PresetResultListene for (int x = 0; x < model.getRowCount(); x++) { ComponentPreset preset = (ComponentPreset) model.getAssociatedObject(x); - if (!materials.contains(preset.get(ComponentPreset.MATERIAL))) { - materials.add(preset.get(ComponentPreset.MATERIAL)); - } presets.add(preset); }