Several improvements to the main editor panel (padding, etc.)

This commit is contained in:
Fabian Becker 2015-12-13 15:15:38 +01:00
parent cc09ce9381
commit 850664c313
5 changed files with 64 additions and 74 deletions

View File

@ -734,6 +734,7 @@ public class MainFrame extends JFrame implements OptimizationStateListener {
if (false && (newModuleAdapter instanceof AbstractModuleAdapter)) { if (false && (newModuleAdapter instanceof AbstractModuleAdapter)) {
JComponent tree = null; JComponent tree = null;
tree = getEvATreeView(frameMaker.getOptimizationParametersPanel(), "OptimizationParameters", ((AbstractModuleAdapter) newModuleAdapter).getOptimizationParameters()); tree = getEvATreeView(frameMaker.getOptimizationParametersPanel(), "OptimizationParameters", ((AbstractModuleAdapter) newModuleAdapter).getOptimizationParameters());
gbConstraints.gridx = 0; gbConstraints.gridx = 0;
gbConstraints.gridy = 0; gbConstraints.gridy = 0;
gbConstraints.fill = GridBagConstraints.BOTH; gbConstraints.fill = GridBagConstraints.BOTH;

View File

@ -13,12 +13,9 @@ import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.plaf.basic.BasicComboBoxRenderer; import javax.swing.plaf.basic.BasicComboBoxRenderer;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.ItemEvent; import java.awt.event.ItemEvent;
import java.awt.event.ItemListener; import java.awt.event.ItemListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport; import java.beans.PropertyChangeSupport;
import java.lang.reflect.Proxy; import java.lang.reflect.Proxy;
import java.util.ArrayList; import java.util.ArrayList;
@ -37,7 +34,7 @@ public class OptimizationEditorPanel extends JPanel implements ItemListener {
/** /**
* The chooser component * The chooser component
*/ */
private JComboBox objectChooser; private JComboBox<Item> objectChooser;
/** /**
* The component that performs classifier customization * The component that performs classifier customization
*/ */
@ -45,7 +42,7 @@ public class OptimizationEditorPanel extends JPanel implements ItemListener {
/** /**
* The model containing the list of names to select from * The model containing the list of names to select from
*/ */
private DefaultComboBoxModel comboBoxModel; private DefaultComboBoxModel<Item> comboBoxModel;
/** /**
* Open object from disk * Open object from disk
*/ */
@ -90,102 +87,89 @@ public class OptimizationEditorPanel extends JPanel implements ItemListener {
} catch (OutOfMemoryError err) { } catch (OutOfMemoryError err) {
backupObject = null; backupObject = null;
System.gc(); System.gc();
System.err.println("Could not create backup object: not enough memory (OptimizationEditorPanel backup of " + target + ")"); LOGGER.severe("Could not create backup object: not enough memory (OptimizationEditorPanel backup of " + target + ")");
} }
comboBoxModel = new DefaultComboBoxModel(new Vector<Item>());
objectChooser = new JComboBox(comboBoxModel); comboBoxModel = new DefaultComboBoxModel<>(new Vector<>());
objectChooser = new JComboBox<>(comboBoxModel);
objectChooser.setEditable(false); objectChooser.setEditable(false);
propertySheetPanel = new PropertySheetPanel(); propertySheetPanel = new PropertySheetPanel();
propertySheetPanel.addPropertyChangeListener( propertySheetPanel.addPropertyChangeListener(event -> propChangeSupport.firePropertyChange("", backupObject, genericObjectEditor.getValue()));
new PropertyChangeListener() {
@Override
public void propertyChange(final PropertyChangeEvent event) {
propChangeSupport.firePropertyChange("", backupObject, genericObjectEditor.getValue());
}
});
openButton = makeIconButton("images/Open16.gif", "Open"); openButton = makeIconButton("images/Open16.gif", "Open");
openButton.setToolTipText("Load a configured object"); openButton.setToolTipText("Load a configured object");
openButton.setEnabled(true); openButton.setEnabled(true);
openButton.addActionListener(new ActionListener() { openButton.addActionListener(event -> {
@Override FileFilter filter = new FileNameExtensionFilter("YAML file", "yml", "yaml");
public void actionPerformed(final ActionEvent event) { Object object = FileTools.openObject(openButton, genericObjectEditor.getClassType(), filter);
FileFilter filter = new FileNameExtensionFilter("YAML file", "yml", "yaml"); if (object != null) {
Object object = FileTools.openObject(openButton, genericObjectEditor.getClassType(), filter); // setValue takes care of: Making sure obj is of right type,
if (object != null) { // and firing property change.
// setValue takes care of: Making sure obj is of right type, genericObjectEditor.setValue(object);
// and firing property change. // Need a second setValue to get property values filled in OK.
genericObjectEditor.setValue(object); // Not sure why.
// Need a second setValue to get property values filled in OK. genericObjectEditor.setValue(object); // <- Hannes ?!?!?
// Not sure why.
genericObjectEditor.setValue(object); // <- Hannes ?!?!?
}
} }
}); });
saveButton = makeIconButton("images/Save16.gif", "Save"); saveButton = makeIconButton("images/Save16.gif", "Save");
saveButton.setToolTipText("Save the current configured object"); saveButton.setToolTipText("Save the current configured object");
saveButton.setEnabled(true); saveButton.setEnabled(true);
saveButton.addActionListener(new ActionListener() { saveButton.addActionListener(event -> {
@Override FileFilter filter = new FileNameExtensionFilter("YAML file", "yml", "yaml");
public void actionPerformed(final ActionEvent event) { FileTools.saveObjectWithFileChooser(saveButton, BeanSerializer.serializeObject(genericObjectEditor.getValue()), filter);
FileFilter filter = new FileNameExtensionFilter("YAML file", "yml", "yaml");
FileTools.saveObjectWithFileChooser(saveButton, BeanSerializer.serializeObject(genericObjectEditor.getValue()), filter);
}
}); });
okayButton = new JButton("OK"); okayButton = new JButton("OK");
okayButton.setEnabled(true); okayButton.setEnabled(true);
okayButton.addActionListener(new ActionListener() { okayButton.addActionListener(event -> {
@Override updateClassType();
public void actionPerformed(final ActionEvent event) { updateChildPropertySheet();
//backupObject = copyObject(genericObjectEditor.getValue());
updateClassType(); /*
updateChildPropertySheet(); * ToDo: This is really ugly. Find a way to make this better.
*/
/* Container container = OptimizationEditorPanel.this.getParent();
* ToDo: This is really ugly. Find a way to make this better. while (!(container instanceof JDialog)) {
*/ container = container.getParent();
Container container = OptimizationEditorPanel.this.getParent();
while (!(container instanceof JDialog)) {
container = container.getParent();
}
((JDialog) container).dispose();
} }
((JDialog) container).dispose();
}); });
cancelButton = new JButton("Cancel"); cancelButton = new JButton("Cancel");
cancelButton.setEnabled(true); cancelButton.setEnabled(true);
cancelButton.addActionListener(new ActionListener() { cancelButton.addActionListener(event -> {
@Override if (backupObject != null) {
public void actionPerformed(final ActionEvent event) { genericObjectEditor.setValue(copyObject(backupObject));
if (backupObject != null) { updateClassType();
genericObjectEditor.setValue(copyObject(backupObject)); updateChooser();
updateClassType(); updateChildPropertySheet();
updateChooser();
updateChildPropertySheet();
}
/*
* ToDo: This is really ugly. Find a way to make this better.
*/
Container container = OptimizationEditorPanel.this.getParent();
while (!(container instanceof JDialog)) {
container = container.getParent();
}
((JDialog) container).dispose();
} }
/*
* ToDo: This is really ugly. Find a way to make this better.
*/
Container container = OptimizationEditorPanel.this.getParent();
while (!(container instanceof JDialog)) {
container = container.getParent();
}
((JDialog) container).dispose();
}); });
setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
setLayout(new GridBagLayout()); setLayout(new GridBagLayout());
GridBagConstraints gbConstraints = new GridBagConstraints(); GridBagConstraints gbConstraints = new GridBagConstraints();
gbConstraints.fill = GridBagConstraints.HORIZONTAL; gbConstraints.fill = GridBagConstraints.HORIZONTAL;
gbConstraints.gridx = 0; gbConstraints.gridx = 0;
gbConstraints.gridy = 0; gbConstraints.gridy = 0;
add(objectChooser, gbConstraints); add(objectChooser, gbConstraints);
gbConstraints.gridy = 1;
add(new JSeparator(JSeparator.HORIZONTAL), gbConstraints);
gbConstraints.weightx = 1.0; gbConstraints.weightx = 1.0;
gbConstraints.weighty = 1.0; gbConstraints.weighty = 1.0;
gbConstraints.gridy = 1; gbConstraints.gridy = 2;
gbConstraints.gridheight = GridBagConstraints.RELATIVE; gbConstraints.gridheight = GridBagConstraints.RELATIVE;
gbConstraints.fill = GridBagConstraints.BOTH; gbConstraints.fill = GridBagConstraints.BOTH;
add(propertySheetPanel, gbConstraints); add(propertySheetPanel, gbConstraints);
@ -206,7 +190,7 @@ public class OptimizationEditorPanel extends JPanel implements ItemListener {
gbConstraints.weightx = 0.0; gbConstraints.weightx = 0.0;
gbConstraints.weighty = 0.0; gbConstraints.weighty = 0.0;
gbConstraints.gridy = 2; gbConstraints.gridy = 3;
gbConstraints.anchor = GridBagConstraints.LINE_START; gbConstraints.anchor = GridBagConstraints.LINE_START;
gbConstraints.fill = GridBagConstraints.HORIZONTAL; gbConstraints.fill = GridBagConstraints.HORIZONTAL;
add(buttonBar, gbConstraints); add(buttonBar, gbConstraints);
@ -321,16 +305,20 @@ public class OptimizationEditorPanel extends JPanel implements ItemListener {
classesList.add(new Item(className, displayName, toolTips[i++])); classesList.add(new Item(className, displayName, toolTips[i++]));
} }
comboBoxModel = new DefaultComboBoxModel(classesList); comboBoxModel = new DefaultComboBoxModel<>(classesList);
objectChooser.setModel(comboBoxModel); objectChooser.setModel(comboBoxModel);
objectChooser.setRenderer(new ToolTipComboBoxRenderer()); objectChooser.setRenderer(new ToolTipComboBoxRenderer());
/*
GridBagConstraints gbConstraints = new GridBagConstraints(); GridBagConstraints gbConstraints = new GridBagConstraints();
gbConstraints.fill = GridBagConstraints.HORIZONTAL; gbConstraints.fill = GridBagConstraints.HORIZONTAL;
gbConstraints.gridx = 0; gbConstraints.gridx = 0;
gbConstraints.gridy = 0; gbConstraints.gridy = 1;
add(objectChooser, gbConstraints); add(objectChooser, gbConstraints);
*/
objectChooser.setVisible(true);
} else { } else {
remove(objectChooser); objectChooser.setVisible(false);
//remove(objectChooser);
} }
} }

View File

@ -228,6 +228,8 @@ public final class PropertySheetPanel extends JPanel implements PropertyChangeLi
gbConstraints.fill = GridBagConstraints.HORIZONTAL; gbConstraints.fill = GridBagConstraints.HORIZONTAL;
gbConstraints.anchor = GridBagConstraints.PAGE_START; gbConstraints.anchor = GridBagConstraints.PAGE_START;
add(infoPanel, gbConstraints); add(infoPanel, gbConstraints);
gbConstraints.gridy = 1;
add(new JSeparator(JSeparator.HORIZONTAL), gbConstraints);
} }
} }
@ -307,7 +309,7 @@ public final class PropertySheetPanel extends JPanel implements PropertyChangeLi
JScrollPane scrollableTable = new JScrollPane(propertyTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); JScrollPane scrollableTable = new JScrollPane(propertyTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
gbConstraints.gridx = 0; gbConstraints.gridx = 0;
gbConstraints.gridy = 1; gbConstraints.gridy = 2;
gbConstraints.weightx = 1.0; gbConstraints.weightx = 1.0;
gbConstraints.weighty = 1.0; gbConstraints.weighty = 1.0;
gbConstraints.fill = GridBagConstraints.BOTH; gbConstraints.fill = GridBagConstraints.BOTH;

View File

@ -82,7 +82,6 @@ public class TabbedFrameMaker implements Serializable, PanelMaker, InterfaceNoti
/** /**
* @return The toolbar with control buttons * @return The toolbar with control buttons
* @deprecated
*/ */
public JExtToolBar getToolBar() { public JExtToolBar getToolBar() {
return extToolBar; return extToolBar;

View File

@ -20,7 +20,7 @@ import java.util.logging.Logger;
*/ */
@Description("Terminate if a given number of optima has been found. Works for problems implementing InterfaceMultimodalProblemKnown, e.g. FM0.") @Description("Terminate if a given number of optima has been found. Works for problems implementing InterfaceMultimodalProblemKnown, e.g. FM0.")
public class KnownOptimaFoundTerminator implements InterfaceTerminator, Serializable { public class KnownOptimaFoundTerminator implements InterfaceTerminator, Serializable {
private Logger LOGGER = Logger.getLogger(KnownOptimaFoundTerminator.class.getName()); private static final Logger LOGGER = Logger.getLogger(KnownOptimaFoundTerminator.class.getName());
private InterfaceMultimodalProblemKnown mProblem = null; private InterfaceMultimodalProblemKnown mProblem = null;
private int reqOptima = 1; private int reqOptima = 1;
private String msg = ""; private String msg = "";