source: src/main/java/genius/gui/panels/SubsetSelectionPanel.java@ 346

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

Initial import : Genius 9.0.0

File size: 1.7 KB
Line 
1package genius.gui.panels;
2
3import java.awt.BorderLayout;
4import java.util.Arrays;
5import java.util.List;
6
7import javax.swing.JFrame;
8import javax.swing.JList;
9import javax.swing.JPanel;
10import javax.swing.JScrollPane;
11import javax.swing.ListCellRenderer;
12
13/**
14 * A GUI to select a subset from a list of items. Just a bare list view. You
15 * probably want to wrap this into a {@link JScrollPane}.
16 */
17@SuppressWarnings("serial")
18public class SubsetSelectionPanel<ItemType> extends JPanel {
19 private SubsetSelectionModel<ItemType> model;
20 private JList<ItemType> list = new JList<ItemType>();
21
22 public SubsetSelectionPanel(SubsetSelectionModel<ItemType> model) {
23 this.model = model;
24 initPanel();
25 }
26
27 /**
28 * Set basic panel contents: buttons, list area
29 */
30 private void initPanel() {
31 setLayout(new BorderLayout());
32 list.setModel(new ListModelAdapter<>(model));
33 list.setSelectionModel(new SelectionModelAdapter<ItemType>(model));
34 add(list, BorderLayout.CENTER);
35
36 }
37
38 /**
39 * Set the cell renderer for the list items.
40 *
41 * @param renderer
42 * the cell renderer for the list items.
43 */
44 public void setCellRenderer(ListCellRenderer<ItemType> renderer) {
45 list.setCellRenderer(renderer);
46 }
47
48 /**
49 * simple stub to run this stand-alone (for testing).
50 *
51 * @param args
52 */
53 public static void main(String[] args) {
54 final JFrame gui = new JFrame();
55 gui.setLayout(new BorderLayout());
56 List<String> allItems = Arrays.asList("een", "twee", "drie", "vier");
57 SubsetSelectionModel<String> model = new SubsetSelectionModel<String>(allItems);
58 gui.getContentPane().add(new SubsetSelectionPanel<String>(model), BorderLayout.CENTER);
59 gui.pack();
60 gui.setVisible(true);
61
62 }
63}
Note: See TracBrowser for help on using the repository browser.