1
2 package hoplugins.transfers.ui.component;
3
4 import hoplugins.Commons;
5
6 import hoplugins.commons.utils.PluginProperty;
7
8 import hoplugins.transfers.dao.TransferSettingDAO;
9
10 import java.awt.BorderLayout;
11 import java.awt.GridLayout;
12 import java.awt.event.ActionEvent;
13
14 import javax.swing.JCheckBox;
15 import javax.swing.JLabel;
16 import javax.swing.JOptionPane;
17 import javax.swing.JPanel;
18
19
20 /***
21 * A panel that allows the user to configure the plugin
22 *
23 * @author <a href=mailto:draghetto@users.sourceforge.net>Massimiliano Amato</a>
24 */
25 public class OptionPanel extends JPanel {
26
27
28 private JCheckBox automatic = new JCheckBox();
29
30
31
32 /***
33 * Constructs a new instance.
34 */
35 public OptionPanel() {
36 super();
37 automatic.setSelected(TransferSettingDAO.isAutomatic());
38 automatic.setOpaque(false);
39 jbInit();
40 }
41
42
43
44 /***
45 * Create a new Panel
46 *
47 * @param string Label text
48 * @param checkBox CheckBox
49 *
50 * @return a panel
51 */
52 private JPanel createPanel(String string, JCheckBox checkBox) {
53 final JPanel panel = new JPanel();
54 panel.setLayout(new BorderLayout());
55 panel.setOpaque(false);
56
57 final JPanel innerPanel = new JPanel();
58
59
60 innerPanel.add(checkBox);
61 innerPanel.add(new JLabel(string, JLabel.LEFT));
62 innerPanel.setOpaque(false);
63 panel.add(innerPanel, BorderLayout.WEST);
64 return panel;
65 }
66
67 /***
68 * Initialize listeners
69 */
70 private void initListeners() {
71 automatic.addActionListener(new java.awt.event.ActionListener() {
72 public void actionPerformed(ActionEvent e) {
73 TransferSettingDAO.setAutomatic(automatic.isSelected());
74
75 if (!automatic.isSelected()) {
76 JOptionPane.showMessageDialog(Commons.getModel().getGUI().getOwner4Dialog(),
77 new DisablePanel(),
78 PluginProperty.getString("Option.Title"),
79 JOptionPane.PLAIN_MESSAGE);
80 }
81 }
82 });
83 }
84
85 /***
86 * Initializes the state of this instance.
87 */
88 private void jbInit() {
89 initListeners();
90
91 final JPanel mainPanel = new JPanel();
92 mainPanel.setLayout(new GridLayout(1, 1));
93 mainPanel.setOpaque(false);
94 mainPanel.add(createPanel(PluginProperty.getString("Option.Auto"), automatic));
95
96 setLayout(new BorderLayout());
97 setOpaque(false);
98 add(mainPanel, BorderLayout.CENTER);
99 }
100 }