1 package ca.uhn.hl7v2.testpanel.ui.conf;
2
3 import java.awt.BorderLayout;
4 import java.awt.FlowLayout;
5 import java.awt.GridBagConstraints;
6 import java.awt.GridBagLayout;
7 import java.awt.Insets;
8 import java.awt.event.ActionEvent;
9 import java.awt.event.ActionListener;
10
11 import javax.swing.JButton;
12 import javax.swing.JDialog;
13 import javax.swing.JLabel;
14 import javax.swing.JPanel;
15 import javax.swing.JTextField;
16 import javax.swing.border.EmptyBorder;
17
18 import ca.uhn.hl7v2.testpanel.util.IOkCancelCallback;
19
20 public class ProfileGroupNameDialog extends JDialog {
21
22 private final JPanel mycontentPanel = new JPanel();
23 private JTextField myNameTextField;
24 private IOkCancelCallback<String> myCallback;
25
26
27
28
29 public static void main(String[] args) {
30 try {
31 ProfileGroupNameDialog dialog = new ProfileGroupNameDialog();
32 dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
33 dialog.setVisible(true);
34 } catch (Exception e) {
35 e.printStackTrace();
36 }
37 }
38
39
40
41
42 public ProfileGroupNameDialog() {
43 setResizable(false);
44 setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
45 setModalityType(ModalityType.APPLICATION_MODAL);
46 setModal(true);
47 setBounds(100, 100, 329, 117);
48 getContentPane().setLayout(new BorderLayout());
49 mycontentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
50 getContentPane().add(mycontentPanel, BorderLayout.CENTER);
51 GridBagLayout gbl_contentPanel = new GridBagLayout();
52 gbl_contentPanel.columnWidths = new int[] { 0, 0 };
53 gbl_contentPanel.rowHeights = new int[] { 0, 0, 0 };
54 gbl_contentPanel.columnWeights = new double[] { 1.0, Double.MIN_VALUE };
55 gbl_contentPanel.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
56 mycontentPanel.setLayout(gbl_contentPanel);
57 {
58 JLabel lblChooseAName = new JLabel("Choose a name for the Profile Group");
59 GridBagConstraints gbc_lblChooseAName = new GridBagConstraints();
60 gbc_lblChooseAName.anchor = GridBagConstraints.WEST;
61 gbc_lblChooseAName.insets = new Insets(0, 0, 5, 0);
62 gbc_lblChooseAName.gridx = 0;
63 gbc_lblChooseAName.gridy = 0;
64 mycontentPanel.add(lblChooseAName, gbc_lblChooseAName);
65 }
66 {
67 myNameTextField = new JTextField();
68 GridBagConstraints gbc_NameTextField = new GridBagConstraints();
69 gbc_NameTextField.fill = GridBagConstraints.HORIZONTAL;
70 gbc_NameTextField.gridx = 0;
71 gbc_NameTextField.gridy = 1;
72 mycontentPanel.add(myNameTextField, gbc_NameTextField);
73 myNameTextField.setColumns(10);
74 }
75 {
76 JPanel buttonPane = new JPanel();
77 buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
78 getContentPane().add(buttonPane, BorderLayout.SOUTH);
79 {
80 JButton okButton = new JButton("OK");
81 okButton.setActionCommand("OK");
82 okButton.addActionListener(new ActionListener() {
83 public void actionPerformed(ActionEvent theE) {
84 myCallback.ok(getName());
85 setVisible(false);
86 }
87 });
88 buttonPane.add(okButton);
89 getRootPane().setDefaultButton(okButton);
90 }
91 {
92 JButton cancelButton = new JButton("Cancel");
93 cancelButton.setActionCommand("Cancel");
94 cancelButton.addActionListener(new ActionListener() {;
95 public void actionPerformed(ActionEvent theE) {
96 myCallback.cancel(getName());
97 setVisible(false);
98 }
99 });
100 buttonPane.add(cancelButton);
101 }
102 }
103 }
104
105 public void setCallback(IOkCancelCallback<String> theCallback) {
106 myCallback = theCallback;
107 }
108
109 public void setName(String theName) {
110 myNameTextField.setText(theName);
111 }
112
113 public String getName() {
114 return myNameTextField.getText();
115 }
116
117 public void start() {
118 setVisible(true);
119 myNameTextField.grabFocus();
120 myNameTextField.setSelectionEnd(0);
121 myNameTextField.setSelectionEnd(myNameTextField.getText().length());
122 }
123
124 }