source: src/main/java/genius/gui/panels/SubsetSelectionPanelPlus.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: 2.4 KB
Line 
1package genius.gui.panels;
2
3import java.awt.BorderLayout;
4import java.awt.Dimension;
5import java.awt.event.ActionEvent;
6import java.awt.event.ActionListener;
7import java.util.Arrays;
8import java.util.List;
9
10import javax.swing.JButton;
11import javax.swing.JFrame;
12import javax.swing.JLabel;
13import javax.swing.JPanel;
14import javax.swing.JScrollPane;
15import javax.swing.ListCellRenderer;
16
17import genius.core.listener.Listener;
18
19/**
20 * {@link SubsetSelectionPanel} with additional border, indicator of number of
21 * selected items, and clear button
22 *
23 */
24@SuppressWarnings("serial")
25public class SubsetSelectionPanelPlus<ItemType> extends VflowPanelWithBorder {
26
27 private JLabel infolabel = new JLabel("0 selected");
28 private SubsetSelectionModel<ItemType> model;
29 private SubsetSelectionPanel<ItemType> listpanel;
30
31 public SubsetSelectionPanelPlus(final String title, final SubsetSelectionModel<ItemType> model) {
32
33 super(title);
34 this.model = model;
35 updateInfo();
36
37 JPanel panel = new JPanel(new BorderLayout());
38 panel.setMaximumSize(new Dimension(999999999, 30));
39 panel.add(infolabel, BorderLayout.WEST);
40 JButton clearButton = new JButton("Clear");
41 panel.add(clearButton, BorderLayout.EAST);
42
43 listpanel = new SubsetSelectionPanel<>(model);
44 add(new JScrollPane(listpanel));
45 add(panel);
46
47 model.addListener(new Listener<ItemType>() {
48 @Override
49 public void notifyChange(ItemType data) {
50 updateInfo();
51 }
52 });
53
54 clearButton.addActionListener(new ActionListener() {
55 @Override
56 public void actionPerformed(ActionEvent e) {
57 model.clear();
58 }
59 });
60
61 }
62
63 /**
64 * Set the cell renderer.
65 *
66 * @param renderer
67 * the renderer for list elements
68 *
69 */
70 public void setCellRenderer(ListCellRenderer<ItemType> renderer) {
71 listpanel.setCellRenderer(renderer);
72 }
73
74 private void updateInfo() {
75 // FIXME invokelater
76 infolabel.setText("" + model.getSelectedItems().size() + " selected");
77 }
78
79 /**
80 * simple stub to run this stand-alone (for testing).
81 *
82 * @param args
83 */
84 public static void main(String[] args) {
85 final JFrame gui = new JFrame();
86 gui.setLayout(new BorderLayout());
87 List<String> allItems = Arrays.asList("een", "twee", "drie", "vier");
88 SubsetSelectionModel<String> model = new SubsetSelectionModel<String>(allItems);
89 gui.getContentPane().add(new SubsetSelectionPanelPlus<String>("Paneel", model), BorderLayout.CENTER);
90 gui.pack();
91 gui.setVisible(true);
92
93 }
94
95}
Note: See TracBrowser for help on using the repository browser.