1 | package geniusweb.panels;
|
---|
2 |
|
---|
3 | import static org.mockito.Mockito.mock;
|
---|
4 |
|
---|
5 | import java.awt.BorderLayout;
|
---|
6 | import java.util.Arrays;
|
---|
7 | import java.util.Collections;
|
---|
8 | import java.util.Map;
|
---|
9 |
|
---|
10 | import javax.swing.JFrame;
|
---|
11 | import javax.swing.JPanel;
|
---|
12 | import javax.swing.JSeparator;
|
---|
13 |
|
---|
14 | import org.junit.Test;
|
---|
15 |
|
---|
16 | import geniusweb.domaineditor.ProfileEditor;
|
---|
17 | import geniusweb.domaineditor.model.DiscreteValueSetModel;
|
---|
18 | import geniusweb.domaineditor.model.DomainModel;
|
---|
19 | import geniusweb.domaineditor.model.ValueSetModel;
|
---|
20 | import tudelft.utilities.logging.Reporter;
|
---|
21 | import tudelft.utilities.mvc.model.DefaultListModel;
|
---|
22 | import tudelft.utilities.mvc.model.DefaultMapModel;
|
---|
23 | import tudelft.utilities.mvc.model.DefaultSelectionModel;
|
---|
24 | import tudelft.utilities.mvc.model.MapModel;
|
---|
25 | import tudelft.utilities.mvc.model.SelectionModel;
|
---|
26 | import tudelft.utilities.mvc.model.StringModel;
|
---|
27 | import tudelft.utilities.mvc.panels.ComboBox;
|
---|
28 |
|
---|
29 | public class ComboBoxTest {
|
---|
30 | private Reporter log = mock(Reporter.class);
|
---|
31 |
|
---|
32 | @Test
|
---|
33 | public void GuiTest() throws InterruptedException {
|
---|
34 |
|
---|
35 | StringModel a = new StringModel("apples", log, ProfileEditor.TIME);
|
---|
36 | StringModel b = new StringModel("bears", log, ProfileEditor.TIME);
|
---|
37 | StringModel c = new StringModel("carrots", log, ProfileEditor.TIME);
|
---|
38 |
|
---|
39 | JFrame f = new JFrame();
|
---|
40 | JPanel panel = new JPanel(new BorderLayout());
|
---|
41 | f.getContentPane().add(panel);
|
---|
42 | DefaultListModel<StringModel> model = new DefaultListModel(
|
---|
43 | Arrays.asList(a, b, c), log, ProfileEditor.TIME);
|
---|
44 | DefaultSelectionModel<StringModel> selectionmodel1 = new DefaultSelectionModel(
|
---|
45 | model, log, true);
|
---|
46 | panel.add(new ComboBox<StringModel>(selectionmodel1),
|
---|
47 | BorderLayout.NORTH);
|
---|
48 | panel.add(new JSeparator(), BorderLayout.CENTER);
|
---|
49 | panel.add(new ComboBox<StringModel>(selectionmodel1),
|
---|
50 | BorderLayout.SOUTH);
|
---|
51 | f.pack();
|
---|
52 | f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
---|
53 | f.setVisible(true);
|
---|
54 | Thread.sleep(10000);
|
---|
55 | f.setVisible(false);
|
---|
56 | }
|
---|
57 |
|
---|
58 | @Test
|
---|
59 | public void testEqualsDeep() {
|
---|
60 |
|
---|
61 | StringModel redvalue = new StringModel("red", log, ProfileEditor.TIME);
|
---|
62 | StringModel greenvalue = new StringModel("green", log,
|
---|
63 | ProfileEditor.TIME);
|
---|
64 | DiscreteValueSetModel issue1values = new DiscreteValueSetModel(
|
---|
65 | Arrays.asList(redvalue, greenvalue), log);
|
---|
66 |
|
---|
67 | StringModel issue1 = new StringModel("issue", log, ProfileEditor.TIME);
|
---|
68 |
|
---|
69 | SelectionModel issue1valuessel = new DefaultSelectionModel(issue1values,
|
---|
70 | log, true);
|
---|
71 | Map<StringModel, SelectionModel> a = Collections.singletonMap(issue1,
|
---|
72 | issue1valuessel);
|
---|
73 | DefaultMapModel<StringModel, SelectionModel> issuevalues = new DefaultMapModel<StringModel, SelectionModel>(
|
---|
74 | a, log, ProfileEditor.TIME) {
|
---|
75 |
|
---|
76 | @Override
|
---|
77 | public String getColumnName(int n) {
|
---|
78 | return n == 0 ? "issue" : "value";
|
---|
79 | }
|
---|
80 |
|
---|
81 | @Override
|
---|
82 | public SelectionModel create(StringModel key) {
|
---|
83 | throw new UnsupportedOperationException();
|
---|
84 | }
|
---|
85 |
|
---|
86 | @Override
|
---|
87 | public int getMinimumSize() {
|
---|
88 | return 1;
|
---|
89 | }
|
---|
90 |
|
---|
91 | };
|
---|
92 |
|
---|
93 | MapModel<StringModel, ValueSetModel> issuevaluesmodel = new DefaultMapModel<StringModel, ValueSetModel>(
|
---|
94 | Collections.singletonMap(issue1, issue1values), log,
|
---|
95 | ProfileEditor.TIME) {
|
---|
96 |
|
---|
97 | @Override
|
---|
98 | public String getColumnName(int n) {
|
---|
99 | return n == 0 ? "issue" : "value";
|
---|
100 | }
|
---|
101 |
|
---|
102 | @Override
|
---|
103 | public int getMinimumSize() {
|
---|
104 | return 1;
|
---|
105 | }
|
---|
106 |
|
---|
107 | @Override
|
---|
108 | public ValueSetModel create(StringModel key) {
|
---|
109 | throw new UnsupportedOperationException();
|
---|
110 | }
|
---|
111 |
|
---|
112 | };
|
---|
113 | DomainModel domain = new DomainModel(
|
---|
114 | new StringModel("testdomain", log, ProfileEditor.TIME),
|
---|
115 | issuevaluesmodel, log);
|
---|
116 |
|
---|
117 | // TODO test equals functions in ComboBoxModel
|
---|
118 | }
|
---|
119 | }
|
---|