]> git.somenet.org - pub/jan/sbc.git/blob - src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupCreationPanel.java
Add wizard for creating delivery groups to GroupFrame
[pub/jan/sbc.git] / src / main / java / at / ac / tuwien / sbc / valesriegler / group / gui / GroupCreationPanel.java
1 package at.ac.tuwien.sbc.valesriegler.group.gui;
2
3 import javax.swing.*;
4 import javax.swing.border.TitledBorder;
5 import java.awt.*;
6 import java.awt.event.ActionEvent;
7 import java.awt.event.ActionListener;
8
9
10 public class GroupCreationPanel extends JPanel {
11
12     private boolean withAddress;
13
14     public GroupCreationPanel(final boolean withAddress) {
15         this.withAddress = withAddress;
16
17         final JPanel chooseGroupSizePanel = new JPanel();
18         JLabel creationLabel = new JLabel("How many members should the group have?");
19         JButton next = new JButton("Next");
20         SpinnerNumberModel model = new SpinnerNumberModel(1, 1, 4, 1);
21         final JSpinner spinner = new JSpinner(model);
22
23         // When 'next' is clicked the second, final panel of the Group Creation
24         // Wizard should be shown
25         next.addActionListener(new ActionListener() {
26             @Override
27             public void actionPerformed(ActionEvent e) {
28                 int numberMembers = (int) spinner.getValue();
29                 GroupCreationPanel.this.withAddress = withAddress;
30                 final GroupCreationDetailsPanel groupCreationDetailsPanel = new GroupCreationDetailsPanel(numberMembers, GroupCreationPanel.this.withAddress);
31                 GroupCreationHandler groupCreationHandler = new GroupCreationHandler(GroupCreationPanel.this, chooseGroupSizePanel,
32                         groupCreationDetailsPanel, GroupCreationPanel.this.withAddress);
33
34                 groupCreationDetailsPanel.setCreateAndCancelHandler(groupCreationHandler);
35                 groupCreationHandler.showGroupCreationDetailPanel();
36
37             }
38         });
39
40         GridLayout creationPanelLayout = new GridLayout(3, 1);
41         chooseGroupSizePanel.setLayout(creationPanelLayout);
42         final String title = withAddress ? "Create Delivery Groups" : "Create Normal Groups";
43         this.setBorder(new TitledBorder(title));
44
45         this.add(chooseGroupSizePanel);
46         chooseGroupSizePanel.add(creationLabel);
47         chooseGroupSizePanel.add(spinner);
48         chooseGroupSizePanel.add(next);
49
50     }
51 }