source: src/main/java/genius/gui/boaparties/BoaComponentPanel.java@ 345

Last change on this file since 345 was 1, checked in by Wouter Pasman, 6 years ago

Initial import : Genius 9.0.0

File size: 3.3 KB
RevLine 
[1]1package genius.gui.boaparties;
2
3import java.awt.BorderLayout;
4import java.awt.event.ActionEvent;
5import java.awt.event.ActionListener;
6import java.util.List;
7
8import javax.swing.JButton;
9import javax.swing.JComboBox;
10import javax.swing.JFrame;
11import javax.swing.JLabel;
12import javax.swing.JOptionPane;
13import javax.swing.JPanel;
14import javax.swing.JTextField;
15import javax.swing.event.TableModelEvent;
16import javax.swing.event.TableModelListener;
17
18import genius.core.boaframework.AcceptanceStrategy;
19import genius.core.boaframework.BOA;
20import genius.core.boaframework.BOAparameter;
21import genius.core.boaframework.BoaType;
22import genius.core.exceptions.InstantiateException;
23import genius.core.repository.boa.BoaRepItem;
24import genius.gui.renderer.RepItemListCellRenderer;
25
26/**
27 * Allows user to pick properties of a Boa Component. Contains a row with the
28 * component (combobox) and a row with the settings (shows values as text and a
29 * "Change" button)..
30 *
31 * @param T
32 * the type of the BOA components
33 */
34@SuppressWarnings("serial")
35public class BoaComponentPanel<T extends BOA> extends JPanel {
36
37 public BoaComponentPanel(final BoaComponentModel<T> model, String title) {
38 setLayout(new BorderLayout());
39 add(new JLabel(title), BorderLayout.NORTH);
40 JComboBox<BoaRepItem<T>> combo = new JComboBox<BoaRepItem<T>>(model.getComponentsListModel());
41 combo.setRenderer(new RepItemListCellRenderer());
42 add(combo, BorderLayout.CENTER);
43 add(new BoaSettingsArea(model.getParameters()), BorderLayout.SOUTH);
44 }
45
46 /**
47 * Simple test function
48 *
49 * @param args
50 * @throws InstantiateException
51 * @throws InterruptedException
52 */
53 public static void main(String[] args) throws InstantiateException, InterruptedException {
54 JFrame frame = new JFrame();
55 frame.setLayout(new BorderLayout());
56
57 BoaComponentModel<AcceptanceStrategy> model = new BoaComponentModel<>(BoaType.ACCEPTANCESTRATEGY);
58
59 frame.getContentPane().add(new BoaComponentPanel<AcceptanceStrategy>(model, "test boa component panel"),
60 BorderLayout.CENTER);
61 frame.pack();
62 frame.setVisible(true);
63 }
64
65}
66
67/**
68 * The lower part of the panel: the settings as text, plus a change button.
69 */
70@SuppressWarnings("serial")
71class BoaSettingsArea extends JPanel {
72 private JTextField text = new JTextField();
73 private JButton change = new JButton("Change");
74 private BoaParametersModel model;
75
76 public BoaSettingsArea(final BoaParametersModel model) {
77 this.model = model;
78 setLayout(new BorderLayout());
79 text.setEditable(false);
80
81 add(text, BorderLayout.CENTER);
82 add(change, BorderLayout.EAST);
83
84 // handle change button click
85 change.addActionListener(new ActionListener() {
86 @Override
87 public void actionPerformed(ActionEvent e) {
88 BoaParametersPanel parampanel = new BoaParametersPanel(model);
89 int result = JOptionPane.showConfirmDialog(BoaSettingsArea.this, parampanel, "enter parameters",
90 JOptionPane.OK_CANCEL_OPTION);
91 if (result == JOptionPane.OK_OPTION) {
92 System.out.println("result=" + model);
93 }
94 }
95
96 });
97
98 // update when parameters change
99 model.addTableModelListener(new TableModelListener() {
100 @Override
101 public void tableChanged(TableModelEvent e) {
102 update();
103 }
104 });
105
106 update();
107 }
108
109 private void update() {
110 List<BOAparameter> setting = model.getSetting();
111 text.setText(setting.toString());
112 change.setEnabled(!setting.isEmpty());
113 }
114
115}
Note: See TracBrowser for help on using the repository browser.