[50] | 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.model.DiscreteValueSetModel;
|
---|
| 17 | import geniusweb.domaineditor.model.DomainModel;
|
---|
| 18 | import geniusweb.domaineditor.model.ValueSetModel;
|
---|
| 19 | import tudelft.utilities.logging.Reporter;
|
---|
| 20 | import tudelft.utilities.mvc.model.DefaultListModel;
|
---|
| 21 | import tudelft.utilities.mvc.model.DefaultMapModel;
|
---|
| 22 | import tudelft.utilities.mvc.model.DefaultSelectionModel;
|
---|
| 23 | import tudelft.utilities.mvc.model.MapModel;
|
---|
| 24 | import tudelft.utilities.mvc.model.SelectionModel;
|
---|
| 25 | import tudelft.utilities.mvc.model.StringModel;
|
---|
| 26 | import tudelft.utilities.mvc.panels.ComboBox;
|
---|
| 27 |
|
---|
| 28 | public class ComboBoxTest {
|
---|
| 29 | private Reporter log = mock(Reporter.class);
|
---|
| 30 |
|
---|
| 31 | @Test
|
---|
| 32 | public void GuiTest() throws InterruptedException {
|
---|
| 33 |
|
---|
| 34 | StringModel a = new StringModel("apples", log);
|
---|
| 35 | StringModel b = new StringModel("bears", log);
|
---|
| 36 | StringModel c = new StringModel("carrots", log);
|
---|
| 37 |
|
---|
| 38 | JFrame f = new JFrame();
|
---|
| 39 | JPanel panel = new JPanel(new BorderLayout());
|
---|
| 40 | f.getContentPane().add(panel);
|
---|
| 41 | DefaultListModel<StringModel> model = new DefaultListModel(
|
---|
| 42 | Arrays.asList(a, b, c), log) {
|
---|
| 43 |
|
---|
| 44 | };
|
---|
| 45 | DefaultSelectionModel<StringModel> selectionmodel1 = new DefaultSelectionModel(
|
---|
| 46 | model);
|
---|
| 47 | panel.add(new ComboBox<StringModel>(selectionmodel1),
|
---|
| 48 | BorderLayout.NORTH);
|
---|
| 49 | panel.add(new JSeparator(), BorderLayout.CENTER);
|
---|
| 50 | panel.add(new ComboBox<StringModel>(selectionmodel1),
|
---|
| 51 | BorderLayout.SOUTH);
|
---|
| 52 | f.pack();
|
---|
| 53 | f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
---|
| 54 | f.setVisible(true);
|
---|
| 55 | Thread.sleep(10000);
|
---|
| 56 | f.setVisible(false);
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | @Test
|
---|
| 60 | public void testEqualsDeep() {
|
---|
| 61 |
|
---|
| 62 | StringModel redvalue = new StringModel("red", log);
|
---|
| 63 | StringModel greenvalue = new StringModel("green", log);
|
---|
| 64 | DiscreteValueSetModel issue1values = new DiscreteValueSetModel(
|
---|
| 65 | Arrays.asList(redvalue, greenvalue), log);
|
---|
| 66 |
|
---|
| 67 | StringModel issue1 = new StringModel("issue", log);
|
---|
| 68 |
|
---|
| 69 | SelectionModel issue1valuessel = new DefaultSelectionModel(
|
---|
| 70 | issue1values);
|
---|
| 71 | Map<StringModel, SelectionModel> a = Collections.singletonMap(issue1,
|
---|
| 72 | issue1valuessel);
|
---|
| 73 | DefaultMapModel<StringModel, SelectionModel> issuevalues = new DefaultMapModel<StringModel, SelectionModel>(
|
---|
| 74 | a, log) {
|
---|
| 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 |
|
---|
| 96 | @Override
|
---|
| 97 | public String getColumnName(int n) {
|
---|
| 98 | return n == 0 ? "issue" : "value";
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | @Override
|
---|
| 102 | public int getMinimumSize() {
|
---|
| 103 | return 1;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | @Override
|
---|
| 107 | public ValueSetModel create(StringModel key) {
|
---|
| 108 | throw new UnsupportedOperationException();
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | };
|
---|
| 112 | DomainModel domain = new DomainModel(new StringModel("testdomain", log),
|
---|
| 113 | issuevaluesmodel, log);
|
---|
| 114 |
|
---|
| 115 | // TODO test equals functions in ComboBoxModel
|
---|
| 116 | }
|
---|
| 117 | }
|
---|