Rename Item to TypeSelectorItem
This commit is contained in:
parent
ef6033c303
commit
a39acf3a22
@ -317,7 +317,7 @@ public class OptimizationEditorPanel extends JPanel implements ItemListener {
|
|||||||
public void updateChooser() {
|
public void updateChooser() {
|
||||||
String objectName = genericObjectEditor.getValue().getClass().getName();
|
String objectName = genericObjectEditor.getValue().getClass().getName();
|
||||||
for (int i = 0; i < typeSelector.getItemCount(); i++) {
|
for (int i = 0; i < typeSelector.getItemCount(); i++) {
|
||||||
Item element = typeSelector.getItemAt(i);
|
TypeSelectorItem element = typeSelector.getItemAt(i);
|
||||||
|
|
||||||
if (objectName.equals(element.getId())) {
|
if (objectName.equals(element.getId())) {
|
||||||
typeSelector.getModel().setSelectedItem(element);
|
typeSelector.getModel().setSelectedItem(element);
|
||||||
@ -345,7 +345,7 @@ public class OptimizationEditorPanel extends JPanel implements ItemListener {
|
|||||||
String className;
|
String className;
|
||||||
|
|
||||||
if ((e.getSource() == typeSelector) && (e.getStateChange() == ItemEvent.SELECTED)) {
|
if ((e.getSource() == typeSelector) && (e.getStateChange() == ItemEvent.SELECTED)) {
|
||||||
className = ((Item) typeSelector.getSelectedItem()).getId();
|
className = ((TypeSelectorItem) typeSelector.getSelectedItem()).getId();
|
||||||
try {
|
try {
|
||||||
Object n = Class.forName(className).newInstance();
|
Object n = Class.forName(className).newInstance();
|
||||||
genericObjectEditor.setValue(n);
|
genericObjectEditor.setValue(n);
|
||||||
|
@ -15,12 +15,12 @@ import java.util.logging.Logger;
|
|||||||
/**
|
/**
|
||||||
* Created by fabian on 16/12/15.
|
* Created by fabian on 16/12/15.
|
||||||
*/
|
*/
|
||||||
public class TypeSelector extends JComboBox<Item> {
|
public class TypeSelector extends JComboBox<TypeSelectorItem> {
|
||||||
private static final Logger LOGGER = Logger.getLogger(TypeSelector.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(TypeSelector.class.getName());
|
||||||
/**
|
/**
|
||||||
* The model containing the list of names to select from
|
* The model containing the list of names to select from
|
||||||
*/
|
*/
|
||||||
private DefaultComboBoxModel<Item> comboBoxModel;
|
private DefaultComboBoxModel<TypeSelectorItem> comboBoxModel;
|
||||||
|
|
||||||
public TypeSelector() {
|
public TypeSelector() {
|
||||||
|
|
||||||
@ -33,13 +33,13 @@ public class TypeSelector extends JComboBox<Item> {
|
|||||||
classesLongNames = GenericObjectEditor.getClassesFromProperties(classTypeName, instances);
|
classesLongNames = GenericObjectEditor.getClassesFromProperties(classTypeName, instances);
|
||||||
LOGGER.finest("Selected type for OptimizationEditorPanel: " + classTypeName);
|
LOGGER.finest("Selected type for OptimizationEditorPanel: " + classTypeName);
|
||||||
if (classesLongNames.size() > 1) {
|
if (classesLongNames.size() > 1) {
|
||||||
Vector<Item> classesList = new Vector<>();
|
Vector<TypeSelectorItem> classesList = new Vector<>();
|
||||||
String[] toolTips = collectComboToolTips(instances, 100);
|
String[] toolTips = collectComboToolTips(instances, 100);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (String className : classesLongNames) {
|
for (String className : classesLongNames) {
|
||||||
String displayName = StringTools.cutClassName(className);
|
String displayName = StringTools.cutClassName(className);
|
||||||
|
|
||||||
classesList.add(new Item(className, displayName, toolTips[i++]));
|
classesList.add(new TypeSelectorItem(className, displayName, toolTips[i++]));
|
||||||
}
|
}
|
||||||
comboBoxModel = new DefaultComboBoxModel<>(classesList);
|
comboBoxModel = new DefaultComboBoxModel<>(classesList);
|
||||||
this.setModel(comboBoxModel);
|
this.setModel(comboBoxModel);
|
||||||
@ -89,7 +89,7 @@ class ToolTipComboBoxRenderer extends BasicComboBoxRenderer {
|
|||||||
isSelected, cellHasFocus);
|
isSelected, cellHasFocus);
|
||||||
|
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
Item item = (Item)value;
|
TypeSelectorItem item = (TypeSelectorItem)value;
|
||||||
setText(item.getDisplayName());
|
setText(item.getDisplayName());
|
||||||
|
|
||||||
if (isSelected) {
|
if (isSelected) {
|
||||||
@ -103,7 +103,7 @@ class ToolTipComboBoxRenderer extends BasicComboBoxRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
Item item = (Item)value;
|
TypeSelectorItem item = (TypeSelectorItem)value;
|
||||||
setText(item.getDisplayName());
|
setText(item.getDisplayName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package eva2.gui;
|
package eva2.gui;
|
||||||
|
|
||||||
public class Item
|
public class TypeSelectorItem
|
||||||
{
|
{
|
||||||
private String id;
|
private String id;
|
||||||
private String displayName;
|
private String displayName;
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
public Item(String id, String displayName, String description)
|
public TypeSelectorItem(String id, String displayName, String description)
|
||||||
{
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.displayName = displayName;
|
this.displayName = displayName;
|
@ -78,7 +78,7 @@ public class ObjectArrayEditor<T> extends JPanel implements PropertyEditor {
|
|||||||
add(scrollPane, c);
|
add(scrollPane, c);
|
||||||
|
|
||||||
addButton.addActionListener(event -> {
|
addButton.addActionListener(event -> {
|
||||||
String className = ((Item) typeSelector.getSelectedItem()).getId();
|
String className = ((TypeSelectorItem) typeSelector.getSelectedItem()).getId();
|
||||||
try {
|
try {
|
||||||
T n = (T) Class.forName(className).newInstance();
|
T n = (T) Class.forName(className).newInstance();
|
||||||
listModel.addElement(n);
|
listModel.addElement(n);
|
||||||
|
40
src/test/java/eva2/gui/TypeSelectorItemTest.java
Normal file
40
src/test/java/eva2/gui/TypeSelectorItemTest.java
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package eva2.gui;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public class TypeSelectorItemTest {
|
||||||
|
TypeSelectorItem item;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
item = new TypeSelectorItem(
|
||||||
|
"eva2.problem.AbstractProblemDouble",
|
||||||
|
"AbstractProblemDouble",
|
||||||
|
"An abstract problem"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetId() throws Exception {
|
||||||
|
assertEquals("eva2.problem.AbstractProblemDouble", item.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetDescription() throws Exception {
|
||||||
|
assertEquals("An abstract problem", item.getDescription());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetDisplayName() throws Exception {
|
||||||
|
assertEquals("AbstractProblemDouble", item.getDisplayName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testToString() throws Exception {
|
||||||
|
// Should match the id
|
||||||
|
assertEquals("eva2.problem.AbstractProblemDouble", item.toString());
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user