From 8aac396938ecc4593c9144e272d1131c263547d0 Mon Sep 17 00:00:00 2001 From: Fabian Becker Date: Sat, 5 Dec 2015 14:15:15 +0100 Subject: [PATCH] Correctly select selected object in object chooser fixes #42 --- src/eva2/gui/OptimizationEditorPanel.java | 27 +++++++++-------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/eva2/gui/OptimizationEditorPanel.java b/src/eva2/gui/OptimizationEditorPanel.java index 60f7f6cc..b2e462cd 100644 --- a/src/eva2/gui/OptimizationEditorPanel.java +++ b/src/eva2/gui/OptimizationEditorPanel.java @@ -22,7 +22,6 @@ import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.lang.reflect.Proxy; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Vector; import java.util.logging.Logger; @@ -80,19 +79,18 @@ public class OptimizationEditorPanel extends JPanel implements ItemListener { * */ public OptimizationEditorPanel(Object target, Object backup, PropertyChangeSupport support, GenericObjectEditor goe, boolean withCancel) { - Object object = target; backupObject = backup; propChangeSupport = support; genericObjectEditor = goe; try { - if (!(Proxy.isProxyClass(object.getClass()))) { - backupObject = copyObject(object); + if (!(Proxy.isProxyClass(target.getClass()))) { + backupObject = copyObject(target); } } catch (OutOfMemoryError err) { backupObject = null; System.gc(); - System.err.println("Could not create backup object: not enough memory (OptimizationEditorPanel backup of " + object + ")"); + System.err.println("Could not create backup object: not enough memory (OptimizationEditorPanel backup of " + target + ")"); } comboBoxModel = new DefaultComboBoxModel(new Vector()); objectChooser = new JComboBox(comboBoxModel); @@ -225,9 +223,9 @@ public class OptimizationEditorPanel extends JPanel implements ItemListener { * This method is duplicated from EvAModuleButtonPanelMaker. ToDo: Refactor * this. * - * @param iconSrc - * @param title - * @return + * @param iconSrc Source path of icon + * @param title Title of button + * @return A JButton with the title and icon */ private JButton makeIconButton(final String iconSrc, final String title) { JButton newButton; @@ -258,7 +256,6 @@ public class OptimizationEditorPanel extends JPanel implements ItemListener { try { SerializedObject so = new SerializedObject(source); result = so.getObject(); - so = null; } catch (Exception ex) { System.err.println("GenericObjectEditor: Problem making backup object"); System.err.println(source.getClass().getName()); @@ -324,7 +321,8 @@ public class OptimizationEditorPanel extends JPanel implements ItemListener { classesList.add(new Item(className, displayName, toolTips[i++])); } - objectChooser.setModel(new DefaultComboBoxModel(classesList)); + comboBoxModel = new DefaultComboBoxModel(classesList); + objectChooser.setModel(comboBoxModel); objectChooser.setRenderer(new ToolTipComboBoxRenderer()); GridBagConstraints gbConstraints = new GridBagConstraints(); gbConstraints.fill = GridBagConstraints.HORIZONTAL; @@ -362,13 +360,10 @@ public class OptimizationEditorPanel extends JPanel implements ItemListener { public void updateChooser() { String objectName = genericObjectEditor.getValue().getClass().getName(); - boolean found = false; for (int i = 0; i < comboBoxModel.getSize(); i++) { Item element = (Item)comboBoxModel.getElementAt(i); - System.out.println(objectName + " - " + element.getId()); if (objectName.equals(element.getId())) { - found = true; objectChooser.getModel().setSelectedItem(element); break; } @@ -431,8 +426,7 @@ class ToolTipComboBoxRenderer extends BasicComboBoxRenderer { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - if (value != null) - { + if (value != null) { Item item = (Item)value; setText(item.getDisplayName()); @@ -446,8 +440,7 @@ class ToolTipComboBoxRenderer extends BasicComboBoxRenderer { } } - if (index == -1) - { + if (index == -1) { Item item = (Item)value; setText(item.getDisplayName()); }