parent
637a9afa82
commit
5e176c426a
@ -67,9 +67,7 @@ public class OptimizationEditorPanel extends JPanel implements ItemListener {
|
||||
* Creates the GUI editor component
|
||||
*/
|
||||
private GenericObjectEditor genericObjectEditor = null;
|
||||
private boolean withComboBoxToolTips = true; // should tool tips for the combo box be created?
|
||||
private int tipMaxLen = 100; // maximum length of tool tip
|
||||
private HashMap<String, String> classNameMap;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -96,7 +94,7 @@ public class OptimizationEditorPanel extends JPanel implements ItemListener {
|
||||
System.gc();
|
||||
System.err.println("Could not create backup object: not enough memory (OptimizationEditorPanel backup of " + object + ")");
|
||||
}
|
||||
comboBoxModel = new DefaultComboBoxModel(new String[0]);
|
||||
comboBoxModel = new DefaultComboBoxModel(new Vector<Item>());
|
||||
objectChooser = new JComboBox(comboBoxModel);
|
||||
objectChooser.setEditable(false);
|
||||
propertySheetPanel = new PropertySheetPanel();
|
||||
@ -318,15 +316,16 @@ public class OptimizationEditorPanel extends JPanel implements ItemListener {
|
||||
classesLongNames = GenericObjectEditor.getClassesFromProperties(genericObjectEditor.getClassType().getName(), instances);
|
||||
LOGGER.finest("Selected type for OptimizationEditorPanel: " + genericObjectEditor.getClassType().getName());
|
||||
if (classesLongNames.size() > 1) {
|
||||
classNameMap = new HashMap<>();
|
||||
Vector<Item> classesList = new Vector<>();
|
||||
String[] toolTips = collectComboToolTips(instances, tipMaxLen);
|
||||
int i = 0;
|
||||
for (String className : classesLongNames) {
|
||||
classNameMap.put(StringTools.cutClassName(className), className);
|
||||
String displayName = StringTools.cutClassName(className);
|
||||
|
||||
classesList.add(new Item(className, displayName, toolTips[i++]));
|
||||
}
|
||||
Vector<String> classesList = new Vector<>(classesLongNames);
|
||||
objectChooser.setModel(new DefaultComboBoxModel(classesList));
|
||||
if (withComboBoxToolTips) {
|
||||
objectChooser.setRenderer(new ToolTipComboBoxRenderer(collectComboToolTips(instances, tipMaxLen)));
|
||||
}
|
||||
objectChooser.setRenderer(new ToolTipComboBoxRenderer());
|
||||
GridBagConstraints gbConstraints = new GridBagConstraints();
|
||||
gbConstraints.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbConstraints.gridx = 0;
|
||||
@ -342,7 +341,6 @@ public class OptimizationEditorPanel extends JPanel implements ItemListener {
|
||||
|
||||
for (int i = 0; i < tips.length; i++) {
|
||||
tips[i] = null;
|
||||
Class[] classParams = new Class[]{};
|
||||
|
||||
String tip = null;
|
||||
|
||||
@ -363,20 +361,16 @@ public class OptimizationEditorPanel extends JPanel implements ItemListener {
|
||||
}
|
||||
|
||||
public void updateChooser() {
|
||||
String objectName = /*
|
||||
* EVAHELP.cutClassName
|
||||
*/ (genericObjectEditor.getValue().getClass().getName());
|
||||
String objectName = genericObjectEditor.getValue().getClass().getName();
|
||||
boolean found = false;
|
||||
for (int i = 0; i < comboBoxModel.getSize(); i++) {
|
||||
if (objectName.equals(comboBoxModel.getElementAt(i))) {
|
||||
Item element = (Item)comboBoxModel.getElementAt(i);
|
||||
if (objectName.equals(element.getId())) {
|
||||
found = true;
|
||||
objectChooser.getModel().setSelectedItem(element);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
comboBoxModel.addElement(objectName);
|
||||
}
|
||||
objectChooser.getModel().setSelectedItem(objectName);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -398,7 +392,7 @@ public class OptimizationEditorPanel extends JPanel implements ItemListener {
|
||||
String className;
|
||||
|
||||
if ((e.getSource() == objectChooser) && (e.getStateChange() == ItemEvent.SELECTED)) {
|
||||
className = (String) objectChooser.getSelectedItem();
|
||||
className = ((Item)objectChooser.getSelectedItem()).getId();
|
||||
try {
|
||||
Object n = Class.forName(className).newInstance();
|
||||
genericObjectEditor.setValue(n);
|
||||
@ -423,30 +417,73 @@ public class OptimizationEditorPanel extends JPanel implements ItemListener {
|
||||
class ToolTipComboBoxRenderer extends BasicComboBoxRenderer {
|
||||
|
||||
private static final long serialVersionUID = -5781643352198561208L;
|
||||
String[] toolTips = null;
|
||||
|
||||
public ToolTipComboBoxRenderer(String[] tips) {
|
||||
public ToolTipComboBoxRenderer() {
|
||||
super();
|
||||
toolTips = tips;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getListCellRendererComponent(JList list, Object value,
|
||||
int index, boolean isSelected, boolean cellHasFocus) {
|
||||
|
||||
super.getListCellRendererComponent(list, value, index,
|
||||
isSelected, cellHasFocus);
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
Item item = (Item)value;
|
||||
setText(item.getDisplayName());
|
||||
|
||||
if (isSelected) {
|
||||
setBackground(list.getSelectionBackground());
|
||||
setForeground(list.getSelectionForeground());
|
||||
if ((toolTips != null) && (index >= 0)) {
|
||||
if (toolTips[index] != null) {
|
||||
list.setToolTipText(toolTips[index]);
|
||||
}
|
||||
}
|
||||
list.setToolTipText(item.getDescription());
|
||||
} else {
|
||||
setBackground(list.getBackground());
|
||||
setForeground(list.getForeground());
|
||||
}
|
||||
}
|
||||
|
||||
if (index == -1)
|
||||
{
|
||||
Item item = (Item)value;
|
||||
setText(item.getDisplayName());
|
||||
}
|
||||
|
||||
setFont(list.getFont());
|
||||
setText((value == null) ? "" : value.toString());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
class Item
|
||||
{
|
||||
private String id;
|
||||
private String displayName;
|
||||
private String description;
|
||||
|
||||
public Item(String id, String displayName, String description)
|
||||
{
|
||||
this.id = id;
|
||||
this.displayName = displayName;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user