1
22 package org.crosswire.bibledesktop.book.install;
23
24 import java.awt.GridBagConstraints;
25 import java.awt.GridBagLayout;
26 import java.awt.Insets;
27 import java.io.IOException;
28 import java.io.ObjectInputStream;
29
30 import javax.swing.JLabel;
31 import javax.swing.JPanel;
32 import javax.swing.JTextField;
33
34 import org.crosswire.bibledesktop.BDMsg;
35 import org.crosswire.jsword.book.install.Installer;
36 import org.crosswire.jsword.book.install.sword.AbstractSwordInstaller;
37
38
45 public class SwordSiteEditor extends JPanel implements SiteEditor {
46 public void initialize() {
47 host = new JTextField();
48 JLabel hostLabel = getLabelForText(BDMsg.gettext("Host:"), host);
51
52 catalogDir = new JTextField();
53 JLabel catalogDirLabel = getLabelForText(BDMsg.gettext("Catalog Directory:"), catalogDir);
56
57 packageDir = new JTextField();
58 JLabel packageDirLabel = getLabelForText(BDMsg.gettext("Zip Directory:"), packageDir);
61
62 proxyHost = new JTextField();
63 JLabel proxyHostLabel = getLabelForText(BDMsg.gettext("Proxy Host:"), proxyHost);
66
67 proxyPort = new JTextField();
68 JLabel proxyPortLabel = getLabelForText(BDMsg.gettext("Proxy Port:"), proxyPort);
71
72 setLayout(new GridBagLayout());
73 add(hostLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_END, GridBagConstraints.NONE, new Insets(2, 10, 2, 2), 0, 0));
74 add(host, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 10), 0, 0));
75 add(catalogDirLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_END, GridBagConstraints.NONE, new Insets(2, 10, 2, 2), 0, 0));
76 add(catalogDir, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 10), 0, 0));
77 add(packageDirLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_END, GridBagConstraints.NONE, new Insets(2, 10, 2, 2), 0, 0));
78 add(packageDir, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 10), 0, 0));
79 add(proxyHostLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_END, GridBagConstraints.NONE, new Insets(2, 10, 2, 2), 0, 0));
80 add(proxyHost, new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 10), 0, 0));
81 add(proxyPortLabel, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_END, GridBagConstraints.NONE, new Insets(2, 10, 2, 2), 0, 0));
82 add(proxyPort, new GridBagConstraints(1, 4, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 10), 0, 0));
83
84 reset();
85 }
86
87
90 public void save() {
91 if (installer == null) {
92 return;
93 }
94
95 installer.setHost(host.getText());
96 installer.setCatalogDirectory(catalogDir.getText());
97 installer.setPackageDirectory(packageDir.getText());
98 installer.setProxyHost(proxyHost.getText());
99 Integer pport = null;
100 try {
101 pport = Integer.valueOf(proxyPort.getText());
102 } catch (NumberFormatException e) {
103 pport = null; }
105 installer.setProxyPort(pport);
106 }
107
108
111 public void reset() {
112 if (installer == null) {
113 return;
114 }
115
116 host.setText(installer.getHost());
117 catalogDir.setText(installer.getCatalogDirectory());
118 packageDir.setText(installer.getPackageDirectory());
119 proxyHost.setText(installer.getProxyHost());
120 Integer port = installer.getProxyPort();
121 proxyPort.setText(port == null ? null : port.toString());
122 }
123
124
127 public void setEditable(boolean editable) {
128 if (host != null) {
129 host.setEditable(editable);
130 }
131
132 if (catalogDir != null) {
133 catalogDir.setEditable(editable);
134 }
135
136 if (packageDir != null) {
137 packageDir.setEditable(editable);
138 }
139
140 if (proxyHost != null) {
141 proxyHost.setEditable(editable);
142 }
143
144 if (proxyPort != null) {
145 proxyPort.setEditable(editable);
146 }
147 }
148
149
152 public Installer getInstaller() {
153 return installer;
154 }
155
156
159 public void setInstaller(Installer newInstaller) {
160 assert newInstaller == null || newInstaller instanceof AbstractSwordInstaller;
161 Installer old = installer;
162 installer = (AbstractSwordInstaller) newInstaller;
163 if (newInstaller == null) {
164 removeAll();
165 } else if (!newInstaller.equals(old)) {
166 removeAll();
167 initialize();
168 }
169 }
170
171 private JLabel getLabelForText(String title, JTextField field) {
172 JLabel label = new JLabel();
173 label.setText(title);
174 label.setLabelFor(field);
175 return label;
176 }
177
178
185 private void readObject(ObjectInputStream is) throws IOException, ClassNotFoundException {
186 installer = null;
187 is.defaultReadObject();
188 }
189
190 private transient AbstractSwordInstaller installer;
191 private JTextField host;
192 private JTextField catalogDir;
193 private JTextField packageDir;
194 private JTextField proxyHost;
195 private JTextField proxyPort;
196
197
200 private static final long serialVersionUID = 3834589894202175795L;
201
202 }
203