From 540097aed47e6201d8d005db0e251efede356ae0 Mon Sep 17 00:00:00 2001 From: Kevin Ruland Date: Tue, 5 Jun 2012 18:13:20 +0000 Subject: [PATCH] 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. --- .../openrocket/gui/preset/ComponentPresetEditor.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/core/src/net/sf/openrocket/gui/preset/ComponentPresetEditor.java b/core/src/net/sf/openrocket/gui/preset/ComponentPresetEditor.java index 3c9f78784..c8d4a191d 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); }