Move objectChooser to sub panel and prefix with Type label.

This commit is contained in:
Fabian Becker 2015-12-15 09:37:55 +01:00
parent 29d53e94dc
commit 97fcc1c3d0

View File

@ -59,6 +59,10 @@ public class OptimizationEditorPanel extends JPanel implements ItemListener {
* cancel button * cancel button
*/ */
private JButton cancelButton; private JButton cancelButton;
/**
*
*/
private JPanel typeSelectionPanel;
/** /**
* Creates the GUI editor component * Creates the GUI editor component
*/ */
@ -72,6 +76,30 @@ public class OptimizationEditorPanel extends JPanel implements ItemListener {
this(target, backup, support, goe, false); this(target, backup, support, goe, false);
} }
private void buildTypeSelectionPanel() {
comboBoxModel = new DefaultComboBoxModel<>(new Vector<>());
objectChooser = new JComboBox<>(comboBoxModel);
objectChooser.setEditable(false);
GridBagConstraints gbConstraints = new GridBagConstraints();
typeSelectionPanel = new JPanel(new GridBagLayout());
gbConstraints.gridx = 0;
gbConstraints.gridy = 0;
JLabel typeLabel = new JLabel("Type:");
typeLabel.setLabelFor(objectChooser);
typeLabel.setDisplayedMnemonic('t');
typeSelectionPanel.add(typeLabel, gbConstraints);
gbConstraints.gridx = 1;
gbConstraints.gridy = 0;
gbConstraints.weightx = 1.0;
gbConstraints.fill = GridBagConstraints.HORIZONTAL;
typeSelectionPanel.add(objectChooser, gbConstraints);
}
/** /**
* *
*/ */
@ -90,9 +118,8 @@ public class OptimizationEditorPanel extends JPanel implements ItemListener {
LOGGER.severe("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<>()); buildTypeSelectionPanel();
objectChooser = new JComboBox<>(comboBoxModel);
objectChooser.setEditable(false);
propertySheetPanel = new PropertySheetPanel(); propertySheetPanel = new PropertySheetPanel();
propertySheetPanel.addPropertyChangeListener(event -> propChangeSupport.firePropertyChange("", backupObject, genericObjectEditor.getValue())); propertySheetPanel.addPropertyChangeListener(event -> propChangeSupport.firePropertyChange("", backupObject, genericObjectEditor.getValue()));
openButton = makeIconButton("images/Open16.gif", "Open"); openButton = makeIconButton("images/Open16.gif", "Open");
@ -154,6 +181,7 @@ public class OptimizationEditorPanel extends JPanel implements ItemListener {
((JDialog) container).dispose(); ((JDialog) container).dispose();
}); });
// 10px padding
setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
setLayout(new GridBagLayout()); setLayout(new GridBagLayout());
@ -162,14 +190,11 @@ public class OptimizationEditorPanel extends JPanel implements ItemListener {
gbConstraints.fill = GridBagConstraints.HORIZONTAL; gbConstraints.fill = GridBagConstraints.HORIZONTAL;
gbConstraints.gridx = 0; gbConstraints.gridx = 0;
gbConstraints.gridy = 0; gbConstraints.gridy = 0;
add(objectChooser, gbConstraints); add(typeSelectionPanel, 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 = 2; gbConstraints.gridy = 1;
gbConstraints.gridheight = GridBagConstraints.RELATIVE; gbConstraints.gridheight = GridBagConstraints.RELATIVE;
gbConstraints.fill = GridBagConstraints.BOTH; gbConstraints.fill = GridBagConstraints.BOTH;
add(propertySheetPanel, gbConstraints); add(propertySheetPanel, gbConstraints);
@ -190,7 +215,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 = 3; gbConstraints.gridy = 2;
gbConstraints.anchor = GridBagConstraints.LINE_START; gbConstraints.anchor = GridBagConstraints.LINE_START;
gbConstraints.fill = GridBagConstraints.HORIZONTAL; gbConstraints.fill = GridBagConstraints.HORIZONTAL;
add(buttonBar, gbConstraints); add(buttonBar, gbConstraints);
@ -308,17 +333,9 @@ public class OptimizationEditorPanel extends JPanel implements ItemListener {
comboBoxModel = new DefaultComboBoxModel<>(classesList); comboBoxModel = new DefaultComboBoxModel<>(classesList);
objectChooser.setModel(comboBoxModel); objectChooser.setModel(comboBoxModel);
objectChooser.setRenderer(new ToolTipComboBoxRenderer()); objectChooser.setRenderer(new ToolTipComboBoxRenderer());
/* typeSelectionPanel.setVisible(true);
GridBagConstraints gbConstraints = new GridBagConstraints();
gbConstraints.fill = GridBagConstraints.HORIZONTAL;
gbConstraints.gridx = 0;
gbConstraints.gridy = 1;
add(objectChooser, gbConstraints);
*/
objectChooser.setVisible(true);
} else { } else {
objectChooser.setVisible(false); typeSelectionPanel.setVisible(false);
//remove(objectChooser);
} }
} }
@ -349,7 +366,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 < comboBoxModel.getSize(); i++) { for (int i = 0; i < comboBoxModel.getSize(); i++) {
Item element = (Item)comboBoxModel.getElementAt(i); Item element = comboBoxModel.getElementAt(i);
if (objectName.equals(element.getId())) { if (objectName.equals(element.getId())) {
objectChooser.getModel().setSelectedItem(element); objectChooser.getModel().setSelectedItem(element);