diff --git a/src/main/java/eva2/gui/Item.java b/src/main/java/eva2/gui/Item.java new file mode 100644 index 00000000..c077d4f8 --- /dev/null +++ b/src/main/java/eva2/gui/Item.java @@ -0,0 +1,34 @@ +package eva2.gui; + +public 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; + } +} diff --git a/src/main/java/eva2/gui/ObjectArrayEditor.java b/src/main/java/eva2/gui/ObjectArrayEditor.java deleted file mode 100644 index 4b836108..00000000 --- a/src/main/java/eva2/gui/ObjectArrayEditor.java +++ /dev/null @@ -1,110 +0,0 @@ -package eva2.gui; - -import eva2.problems.AbstractProblemDouble; - -import javax.swing.*; -import java.awt.*; - -/** - * Created by fabian on 16/12/15. - */ -public class ObjectArrayEditor extends JPanel { - private JList objectList; - private DefaultListModel listModel; - - public ObjectArrayEditor(Class type) { - listModel = new DefaultListModel<>(); - - setLayout(new GridBagLayout()); - GridBagConstraints c = new GridBagConstraints(); - c.gridwidth = 2; - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 1.0; - c.weighty = 0.0; - c.gridx = 0; - c.gridy = 0; - - TypeSelector typeSelector = new TypeSelector(); - typeSelector.updateClassType(type.getName()); - - setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); - add(typeSelector, c); - - JButton addButton = new JButton("Add"); - c.gridwidth = 1; - c.gridx = 2; - c.gridy = 0; - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 1.0; - c.weighty = 0.0; - add(addButton, c); - - JButton removeButton = new JButton("Remove"); - c.gridx = 2; - c.gridy = 1; - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 1.0; - c.weighty = 0.0; - add(removeButton, c); - - JButton button; - button = new JButton("Config"); - c.gridx = 2; - c.gridy = 2; - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 1.0; - c.weighty = 0.0; - - add(button, c); - - objectList = new JList<>(listModel); - objectList.setVisibleRowCount(10); - //objectList.setFixedCellHeight(15); - //objectList.setFixedCellWidth(100); - - c.gridwidth = 2; - c.gridheight = 5; - c.gridx = 0; - c.gridy = 1; - c.fill = GridBagConstraints.BOTH; - c.weightx = 1.0; - c.weighty = 1.0; - - JScrollPane scrollPane = new JScrollPane(objectList); - add(scrollPane, c); - - addButton.addActionListener(event -> { - String className = ((Item) typeSelector.getSelectedItem()).getId(); - try { - T n = (T) Class.forName(className).newInstance(); - listModel.addElement(n); - } catch (Exception ex) { - System.err.println("Exception in itemStateChanged " + ex.getMessage()); - System.err.println("Classpath is " + System.getProperty("java.class.path")); - ex.printStackTrace(); - - JOptionPane.showMessageDialog(this, - "Could not create an example of\n" - + className + "\n" - + "from the current classpath. Is the resource folder at the right place?\nIs the class abstract or the default constructor missing?", - "GenericObjectEditor", - JOptionPane.ERROR_MESSAGE); - } - }); - - removeButton.addActionListener(event -> { - if (!objectList.isSelectionEmpty()) { - listModel.remove(objectList.getSelectedIndex()); - } - }); - - } - - public static void main(String[] args) { - JFrame frame = new JFrame("ObjectArrayEditor"); - frame.add(new ObjectArrayEditor<>(AbstractProblemDouble.class), BorderLayout.CENTER); - frame.setVisible(true); - frame.pack(); - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - } -} diff --git a/src/main/java/eva2/gui/TitledSeparator.java b/src/main/java/eva2/gui/TitledSeparator.java new file mode 100644 index 00000000..75e521a7 --- /dev/null +++ b/src/main/java/eva2/gui/TitledSeparator.java @@ -0,0 +1,25 @@ +package eva2.gui; + +import javax.swing.*; +import java.awt.*; + +/** + * Created by halfdan on 17/12/15. + */ +public final class TitledSeparator extends JPanel { + public TitledSeparator(String title) { + setLayout(new GridBagLayout()); + + GridBagConstraints gbConstraints = new GridBagConstraints(); + gbConstraints.gridx = 0; + gbConstraints.gridy = 0; + + add(new JLabel("" + title), gbConstraints); + + gbConstraints.gridx = 1; + gbConstraints.gridy = 0; + gbConstraints.weightx = 1.0; + gbConstraints.fill = GridBagConstraints.HORIZONTAL; + add(new JSeparator(JSeparator.HORIZONTAL), gbConstraints); + } +} diff --git a/src/main/java/eva2/gui/TypeSelector.java b/src/main/java/eva2/gui/TypeSelector.java index dc2ffd59..d2f4a15b 100644 --- a/src/main/java/eva2/gui/TypeSelector.java +++ b/src/main/java/eva2/gui/TypeSelector.java @@ -112,35 +112,3 @@ class ToolTipComboBoxRenderer extends BasicComboBoxRenderer { } } -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; - } -}