1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package p3j.gui.dialogs;
17
18 import java.awt.BorderLayout;
19 import java.awt.Frame;
20 import java.awt.event.ActionEvent;
21 import java.awt.event.ActionListener;
22 import java.util.ArrayList;
23 import java.util.List;
24
25 import javax.swing.BoxLayout;
26 import javax.swing.ButtonGroup;
27 import javax.swing.JButton;
28 import javax.swing.JDialog;
29 import javax.swing.JPanel;
30 import javax.swing.JRadioButton;
31
32 import p3j.database.DatabaseType;
33 import p3j.gui.panels.PropertiesShowPanelFactory;
34 import p3j.misc.gui.GUI;
35
36
37
38
39
40
41
42
43
44 public class DatabaseTypeSelectionDialog extends JDialog {
45
46
47 private static final long serialVersionUID = -6739792487369234085L;
48
49 private static final int DIALOG_WIDTH = 500;
50
51 private static final int DIALOG_HEIGHT = 200;
52
53 private final JPanel contentPanel = new JPanel(GUI.getStdBorderLayout());
54
55 private DatabaseType dbType = DatabaseType.HSQLDB;
56
57 public DatabaseTypeSelectionDialog(Frame owner, DatabaseType currentDBType) {
58 super(owner, "Select Database Type", true);
59 setSize(DIALOG_WIDTH, DIALOG_HEIGHT);
60 GUI.centerOnScreen(this);
61
62 dbType = currentDBType;
63
64 JButton next = new JButton("Next");
65 next.addActionListener(new ActionListener() {
66 @Override
67 public void actionPerformed(ActionEvent e) {
68 setVisible(false);
69 }
70 });
71
72 JButton cancel = new JButton("Cancel");
73 cancel.addActionListener(new ActionListener() {
74 @Override
75 public void actionPerformed(ActionEvent e) {
76 dbType = null;
77 setVisible(false);
78 }
79 });
80
81 List<JButton> buttons = new ArrayList<JButton>();
82 buttons.add(cancel);
83 buttons.add(next);
84
85 PropertiesShowPanelFactory pspf = new PropertiesShowPanelFactory(0,
86 buttons, 1);
87
88 JPanel radioButtonPanel = createRadioButtons();
89
90 contentPanel.add(radioButtonPanel, BorderLayout.CENTER);
91 contentPanel.add(pspf.constructPanel(), BorderLayout.SOUTH);
92 this.getContentPane().add(contentPanel);
93 }
94
95
96
97
98
99
100 private JPanel createRadioButtons() {
101 JPanel radioButtonPanel = new JPanel();
102 BoxLayout layout = new BoxLayout(radioButtonPanel, BoxLayout.Y_AXIS);
103 radioButtonPanel.setLayout(layout);
104 ButtonGroup dbTypesRadioButtons = new ButtonGroup();
105 for (final DatabaseType type : DatabaseType.values()) {
106 JRadioButton radioButton = new JRadioButton(type.toString(),
107 type == dbType);
108 radioButton.addActionListener(new ActionListener() {
109 @Override
110 public void actionPerformed(ActionEvent e) {
111 dbType = type;
112 }
113 });
114 dbTypesRadioButtons.add(radioButton);
115 radioButtonPanel.add(radioButton);
116 }
117
118 JPanel resultPanel = new JPanel(GUI.getStdBorderLayout());
119 resultPanel.add(radioButtonPanel, BorderLayout.CENTER);
120 resultPanel.add(new JPanel(), BorderLayout.NORTH);
121 resultPanel.add(new JPanel(), BorderLayout.WEST);
122 return resultPanel;
123 }
124
125 public DatabaseType getDBType() {
126 return dbType;
127 }
128
129 }