1
22 package org.crosswire.bibledesktop.book.install;
23
24 import java.awt.BorderLayout;
25 import java.awt.Component;
26 import java.awt.Container;
27 import java.awt.GridLayout;
28 import java.awt.event.ItemEvent;
29 import java.awt.event.ItemListener;
30 import java.io.IOException;
31 import java.io.ObjectInputStream;
32
33 import javax.swing.JButton;
34 import javax.swing.JCheckBox;
35 import javax.swing.JDialog;
36 import javax.swing.JFrame;
37 import javax.swing.JLabel;
38 import javax.swing.JPanel;
39 import javax.swing.SwingUtilities;
40
41 import org.crosswire.bibledesktop.BDMsg;
42 import org.crosswire.common.swing.ActionFactory;
43 import org.crosswire.common.swing.GuiUtil;
44 import org.crosswire.jsword.util.WebWarning;
45
46
55 public class InternetWarning extends JPanel {
56
59 public InternetWarning() {
60 actions = new ActionFactory(this);
61
62 ItemListener changer = new ItemListener() {
63 public void itemStateChanged(ItemEvent ev) {
64 fireStateChange();
65 }
66 };
67
68 setLayout(new GridLayout(2, 1, 5, 5));
69
70 add(new JLabel(WebWarning.instance().getWarning()));
71
72 showWarning = new JCheckBox(WebWarning.instance().getShownWarningLabel());
73 showWarning.setSelected(true);
74 showWarning.addItemListener(changer);
75
76 add(showWarning);
77 GuiUtil.applyDefaultOrientation(this);
78 }
79
80
83 public static int showDialog(Component parent, String title) {
84 final InternetWarning webWarning = new InternetWarning();
85
86 JPanel buttons = new JPanel();
87 JButton yesButton = new JButton(webWarning.actions.addAction("Yes", BDMsg.gettext("Yes")));
89 JButton noButton = new JButton(webWarning.actions.addAction("No", BDMsg.gettext("No")));
91 buttons.add(yesButton);
92 buttons.add(noButton);
93
94 Component root = SwingUtilities.getRoot(parent);
95
96 JDialog dialog = (root instanceof JFrame) ? new JDialog((JFrame) root, title, true) : new JDialog((JDialog) root, title, true);
97
98 webWarning.dialog = dialog;
99 webWarning.choice = InternetWarning.DENIED;
100
101 dialog.getRootPane().setDefaultButton(yesButton);
102
103 Container content = dialog.getContentPane();
104 content.setLayout(new BorderLayout());
105 content.add(webWarning, BorderLayout.NORTH);
106 content.add(buttons, BorderLayout.SOUTH);
107 dialog.pack();
108 GuiUtil.centerOnScreen(dialog);
109 GuiUtil.applyDefaultOrientation(dialog);
110 dialog.setVisible(true);
111
112 dialog.dispose();
113
114 return webWarning.choice;
115 }
116
117 public void doYes() {
118 dialog.setVisible(false);
119 choice = InternetWarning.GRANTED;
120 }
121
122 public void doNo() {
123 dialog.setVisible(false);
124 choice = InternetWarning.DENIED;
125 }
126
127
130 protected void fireStateChange() {
131 WebWarning.instance().setShown(showWarning.isSelected());
132 }
133
134
141 private void readObject(ObjectInputStream is) throws IOException, ClassNotFoundException {
142 actions = new ActionFactory(this);
143 is.defaultReadObject();
144 }
145
146
149 public static final int GRANTED = 0;
150
151
154 public static final int DENIED = 1;
155
156
160 private transient ActionFactory actions;
161
162
165 protected int choice;
166
167
170 protected JDialog dialog;
171
172
175 protected JCheckBox showWarning;
176
177
180 private static final long serialVersionUID = 3978992071925250097L;
181 }
182