1 | package genius.gui.domainrepository;
|
---|
2 |
|
---|
3 | import java.awt.Frame;
|
---|
4 | import java.awt.event.ActionEvent;
|
---|
5 | import java.awt.event.ActionListener;
|
---|
6 |
|
---|
7 | import javax.swing.JButton;
|
---|
8 | import javax.swing.JDialog;
|
---|
9 | import javax.swing.JLabel;
|
---|
10 | import javax.swing.JOptionPane;
|
---|
11 | import javax.swing.JTextField;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * GUI used to createFrom a new domain.
|
---|
15 | *
|
---|
16 | * @author Mark Hendrikx
|
---|
17 | */
|
---|
18 | public class CreateNewDomain extends JDialog {
|
---|
19 |
|
---|
20 | private JButton okButton;
|
---|
21 | private JButton cancelButton;
|
---|
22 | private JLabel domainNameLabel;
|
---|
23 | private JTextField domainNameField;
|
---|
24 | private String result = null;
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Creates new form DomainCreationUI
|
---|
28 | */
|
---|
29 | public CreateNewDomain(Frame frame) {
|
---|
30 | super(frame, "Create domain", true);
|
---|
31 | this.setLocation(frame.getLocation().x + frame.getWidth() / 4,
|
---|
32 | frame.getLocation().y + frame.getHeight() / 4);
|
---|
33 | }
|
---|
34 |
|
---|
35 | public String getResult() {
|
---|
36 | setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
|
---|
37 | setResizable(false);
|
---|
38 |
|
---|
39 | domainNameLabel = new JLabel();
|
---|
40 | okButton = new JButton();
|
---|
41 | cancelButton = new JButton();
|
---|
42 | domainNameField = new JTextField();
|
---|
43 |
|
---|
44 | domainNameLabel.setText("Domain name");
|
---|
45 |
|
---|
46 | okButton.setText("Ok");
|
---|
47 | okButton.addActionListener(new ActionListener() {
|
---|
48 | @Override
|
---|
49 | public void actionPerformed(ActionEvent e) {
|
---|
50 | if (domainNameField.getText().equals("")) {
|
---|
51 | JOptionPane.showMessageDialog(null,
|
---|
52 | "The domain name may not be empty.",
|
---|
53 | "Parameter error", 0);
|
---|
54 | } else {
|
---|
55 | result = domainNameField.getText();
|
---|
56 | dispose();
|
---|
57 | }
|
---|
58 | }
|
---|
59 | });
|
---|
60 |
|
---|
61 | cancelButton.setText("Cancel");
|
---|
62 | cancelButton.addActionListener(new ActionListener() {
|
---|
63 | @Override
|
---|
64 | public void actionPerformed(ActionEvent e) {
|
---|
65 | dispose();
|
---|
66 | }
|
---|
67 | });
|
---|
68 |
|
---|
69 | javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
|
---|
70 | getContentPane());
|
---|
71 | getContentPane().setLayout(layout);
|
---|
72 | layout.setHorizontalGroup(layout
|
---|
73 | .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
---|
74 | .addGroup(layout.createSequentialGroup().addContainerGap()
|
---|
75 | .addGroup(layout
|
---|
76 | .createParallelGroup(
|
---|
77 | javax.swing.GroupLayout.Alignment.LEADING)
|
---|
78 | .addGroup(layout.createSequentialGroup()
|
---|
79 | .addComponent(domainNameLabel)
|
---|
80 | .addGap(74, 74, 74)
|
---|
81 | .addComponent(domainNameField))
|
---|
82 | .addGroup(layout.createSequentialGroup()
|
---|
83 | .addComponent(okButton,
|
---|
84 | javax.swing.GroupLayout.PREFERRED_SIZE,
|
---|
85 | 80,
|
---|
86 | javax.swing.GroupLayout.PREFERRED_SIZE)
|
---|
87 | .addPreferredGap(
|
---|
88 | javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
---|
89 | .addComponent(cancelButton,
|
---|
90 | javax.swing.GroupLayout.PREFERRED_SIZE,
|
---|
91 | 80,
|
---|
92 | javax.swing.GroupLayout.PREFERRED_SIZE)
|
---|
93 | .addGap(0, 133, Short.MAX_VALUE)))
|
---|
94 | .addContainerGap()));
|
---|
95 | layout.setVerticalGroup(layout
|
---|
96 | .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
---|
97 | .addGroup(layout.createSequentialGroup().addContainerGap()
|
---|
98 | .addGroup(layout
|
---|
99 | .createParallelGroup(
|
---|
100 | javax.swing.GroupLayout.Alignment.BASELINE)
|
---|
101 | .addComponent(domainNameLabel)
|
---|
102 | .addComponent(domainNameField,
|
---|
103 | javax.swing.GroupLayout.PREFERRED_SIZE,
|
---|
104 | javax.swing.GroupLayout.DEFAULT_SIZE,
|
---|
105 | javax.swing.GroupLayout.PREFERRED_SIZE))
|
---|
106 | .addPreferredGap(
|
---|
107 | javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
---|
108 | .addGroup(layout
|
---|
109 | .createParallelGroup(
|
---|
110 | javax.swing.GroupLayout.Alignment.BASELINE)
|
---|
111 | .addComponent(okButton)
|
---|
112 | .addComponent(cancelButton))
|
---|
113 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
|
---|
114 | Short.MAX_VALUE)));
|
---|
115 |
|
---|
116 | pack();
|
---|
117 | setVisible(true);
|
---|
118 | return result;
|
---|
119 | }
|
---|
120 | } |
---|