1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package davmail.ui;
20
21 import davmail.BundleMessage;
22 import davmail.ui.tray.DavGatewayTray;
23
24 import javax.swing.*;
25 import java.awt.*;
26
27
28
29
30 public class SelectCertificateDialog extends JDialog {
31 protected final JList<String> aliasListBox;
32 protected final String[] aliases;
33 protected String selectedAlias;
34
35
36
37
38
39
40 public String getSelectedAlias() {
41 return this.selectedAlias;
42 }
43
44
45
46
47
48
49 public SelectCertificateDialog(String[] aliases, String[] descriptions) {
50 setAlwaysOnTop(true);
51 this.aliases = aliases;
52
53 setTitle(BundleMessage.format("UI_CERTIFICATE_ALIAS_PROMPT"));
54 try {
55 setIconImages(DavGatewayTray.getFrameIcons());
56 } catch (NoSuchMethodError error) {
57 DavGatewayTray.debug(new BundleMessage("LOG_UNABLE_TO_SET_ICON_IMAGE"));
58 }
59
60 JPanel questionPanel = new JPanel();
61 questionPanel.setLayout(new BoxLayout(questionPanel, BoxLayout.Y_AXIS));
62 JLabel imageLabel = new JLabel();
63 imageLabel.setIcon(UIManager.getIcon("OptionPane.questionIcon"));
64 imageLabel.setText(BundleMessage.format("UI_CERTIFICATE_ALIAS_PROMPT"));
65 questionPanel.add(imageLabel);
66
67 aliasListBox = new JList<>(descriptions);
68 aliasListBox.setMaximumSize(aliasListBox.getPreferredSize());
69
70 JPanel aliasPanel = new JPanel();
71 aliasPanel.setLayout(new BoxLayout(aliasPanel, BoxLayout.Y_AXIS));
72 aliasPanel.add(aliasListBox);
73
74 add(questionPanel, BorderLayout.NORTH);
75 add(aliasPanel, BorderLayout.CENTER);
76 add(getButtonPanel(), BorderLayout.SOUTH);
77 setModal(true);
78
79 pack();
80
81 setLocation(getToolkit().getScreenSize().width / 2 -
82 getSize().width / 2,
83 getToolkit().getScreenSize().height / 2 -
84 getSize().height / 2);
85 setAlwaysOnTop(true);
86 setVisible(true);
87 }
88
89 protected JPanel getButtonPanel() {
90 JPanel buttonPanel = new JPanel();
91 JButton okButton = new JButton(BundleMessage.format("UI_BUTTON_OK"));
92 JButton cancelButton = new JButton(BundleMessage.format("UI_BUTTON_CANCEL"));
93 okButton.addActionListener(evt -> {
94 selectedAlias = aliases[aliasListBox.getSelectedIndex()];
95 setVisible(false);
96 });
97 cancelButton.addActionListener(evt -> {
98 selectedAlias = null;
99 setVisible(false);
100 });
101
102 buttonPanel.add(okButton);
103 buttonPanel.add(cancelButton);
104 return buttonPanel;
105 }
106
107 }