source: trunk/gli/src/org/greenstone/gatherer/gui/OptionsBox.java@ 4448

Last change on this file since 4448 was 4367, checked in by mdewsnip, 21 years ago

Fixed tabbing.

  • Property svn:keywords set to Author Date Id Revision
File size: 7.5 KB
Line 
1package org.greenstone.gatherer.gui;
2/**
3 *#########################################################################
4 *
5 * A component of the Gatherer application, part of the Greenstone digital
6 * library suite from the New Zealand Digital Library Project at the
7 * University of Waikato, New Zealand.
8 *
9 * <BR><BR>
10 *
11 * Author: John Thompson, Greenstone Digital Library, University of Waikato
12 *
13 * <BR><BR>
14 *
15 * Copyright (C) 1999 New Zealand Digital Library Project
16 *
17 * <BR><BR>
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * <BR><BR>
25 *
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
30 *
31 * <BR><BR>
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software
35 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36 *########################################################################
37 */
38import java.awt.*;
39import java.awt.event.*;
40import java.util.*;
41import javax.swing.*;
42import javax.swing.border.*;
43import org.greenstone.gatherer.Gatherer;
44/**
45 * @author John Thompson, Greenstone Digital Library, University of Waikato
46 * @version 2.3
47 */
48public class OptionsBox
49 extends JDialog
50 implements ActionListener, FocusListener {
51
52 private JButton cancel_button;
53 private JButton establish_connection;
54 private JButton ok_button;
55
56 private JCheckBox use_colours;
57 private JCheckBox use_proxy;
58
59 private JLabel proxy_host_label;
60 private JLabel proxy_port_label;
61
62 private JTabbedPane tab_pane;
63
64 private JTextField proxy_host;
65 private JTextField proxy_port;
66
67 private JPanel button_pane;
68 private JPanel connection_pane;
69 private JPanel content_pane;
70 private JPanel download_pane;
71 private JPanel general_pane;
72 private JPanel proxy_pane;
73 private JPanel proxy_host_pane;
74 private JPanel proxy_port_pane;
75
76 static final private Dimension SIZE = new Dimension(400,300);
77
78 public OptionsBox() {
79 super(Gatherer.g_man);
80
81 this.setModal(true);
82 this.setTitle(get("Title"));
83 this.setSize(SIZE);
84
85 content_pane = (JPanel) this.getContentPane();
86 content_pane.setLayout(new BorderLayout());
87 content_pane.setMinimumSize(this.getSize());
88 content_pane.setSize(this.getSize());
89 content_pane.setMaximumSize(this.getSize());
90
91 tab_pane = new JTabbedPane();
92
93 tab_pane.add(get("General"), buildGeneral());
94 if(!Gatherer.config.get("workflow.mirror", true)) {
95 tab_pane.add(get("Connection"), buildConnection());
96 tab_pane.add(get("Download"), buildDownload());
97 }
98
99 button_pane = new JPanel(new GridLayout(1,2));
100 button_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
101
102 cancel_button = new JButton(get("General.Cancel"));
103 cancel_button.addActionListener(this);
104
105 ok_button = new JButton(get("General.OK"));
106 ok_button.addActionListener(this);
107
108 // Add components.
109 content_pane.add(tab_pane, BorderLayout.CENTER);
110 button_pane.add(ok_button);
111 button_pane.add(cancel_button);
112 content_pane.add(button_pane, BorderLayout.SOUTH);
113
114 // Final dialog setup & positioning.
115 // Position the window.
116 Dimension screen_size = Gatherer.config.screen_size;
117 setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
118 show();
119 }
120
121 public void actionPerformed(ActionEvent event) {
122 Object esrc = event.getSource();
123 // OK - Save all settings.
124 if(esrc == ok_button) {
125 // Update config
126 this.dispose();
127 }
128 // Cancel - Ignore settings and close.
129 else if(esrc == cancel_button) {
130 this.dispose();
131 }
132 else if(esrc == use_proxy) {
133 Gatherer.config.set("general.use_proxy", true, use_proxy.isSelected());
134 proxy_host.setEnabled(use_proxy.isSelected());
135 proxy_port.setEnabled(use_proxy.isSelected());
136 establish_connection.setEnabled(use_proxy.isSelected());
137 }
138 else if(esrc == establish_connection) {
139 if(use_proxy.isSelected()) {
140 Gatherer.config.setString("general.proxy_host", true, proxy_host.getText());
141 Gatherer.config.setString("general.proxy_port", true, proxy_port.getText());
142 Gatherer.self.setProxy();
143 }
144 }
145 }
146
147 public JPanel buildGeneral() {
148 general_pane = new JPanel(new GridLayout(2,1));
149 JPanel color_pane = new JPanel();
150 use_colours = new JCheckBox(get("Use_Colours"));
151 // Connection
152 use_colours.addActionListener(this);
153 // Layout
154 color_pane.add(use_colours);
155
156 general_pane.add(color_pane);
157 return general_pane;
158 }
159
160 public JPanel buildConnection() {
161 connection_pane = new JPanel(new BorderLayout());
162
163 proxy_pane = new JPanel(new GridLayout(4,1));
164 proxy_pane.setBorder(BorderFactory.createTitledBorder(
165 BorderFactory.createBevelBorder(BevelBorder.LOWERED),
166 get("Proxy_Configuration")));
167
168 use_proxy = new JCheckBox(get("Use_Proxy"));
169 use_proxy.addActionListener(this);
170
171 establish_connection = new JButton(get("Establish_Connection"));
172 establish_connection.addActionListener(this);
173
174 proxy_host_pane = new JPanel(new BorderLayout());
175 proxy_host_label = new JLabel(get("Proxy_Host"));
176
177 proxy_port_pane = new JPanel(new BorderLayout());
178 proxy_port_label = new JLabel(get("Proxy_Port"));
179
180 if(Gatherer.config.get("general.use_proxy", true)) {
181 use_proxy.setSelected(true);
182
183 proxy_host = new JTextField(Gatherer.config.getString("general.proxy_host", true));
184 proxy_port = new JTextField(Gatherer.config.getString("general.proxy_port", true));
185 }
186 else {
187 use_proxy.setSelected(false);
188 proxy_host = new JTextField();
189 proxy_host.setEnabled(false);
190 proxy_port = new JTextField();
191 proxy_port.setEnabled(false);
192
193 establish_connection.setEnabled(false);
194 }
195
196 proxy_host.setColumns(40);
197
198 proxy_host.addActionListener(this);
199 proxy_host.addFocusListener(this);
200 proxy_port.addActionListener(this);
201 proxy_port.addFocusListener(this);
202
203 // Add lowest layer components
204 proxy_host_pane.add(proxy_host_label, BorderLayout.WEST);
205 proxy_host_pane.add(proxy_host, BorderLayout.CENTER);
206
207 proxy_port_pane.add(proxy_port_label, BorderLayout.WEST);
208 proxy_port_pane.add(proxy_port, BorderLayout.CENTER);
209
210 // Add components
211 proxy_pane.add(use_proxy);
212 proxy_pane.add(proxy_host_pane);
213 proxy_pane.add(proxy_port_pane);
214 proxy_pane.add(establish_connection);
215
216 // Add to higher layer.
217 connection_pane.add(proxy_pane, BorderLayout.CENTER);
218
219 return connection_pane;
220 }
221
222 public JPanel buildDownload() {
223 download_pane = new JPanel(new BorderLayout());
224 return download_pane;
225 }
226
227 public void destroy() {
228 cancel_button = null;
229 establish_connection = null;
230 ok_button = null;
231 use_colours = null;
232 use_proxy = null;
233 proxy_host_label = null;
234 proxy_port_label = null;
235 tab_pane = null;
236 proxy_host = null;
237 proxy_port = null;
238 button_pane = null;
239 connection_pane = null;
240 content_pane = null;
241 download_pane = null;
242 general_pane = null;
243 proxy_pane = null;
244 proxy_host_pane = null;
245 proxy_port_pane = null;
246 }
247
248 // We have to trap focus changes and change them into action events.
249 public void focusGained(FocusEvent e) {
250 }
251
252 public void focusLost(FocusEvent event) {
253 actionPerformed(new ActionEvent(event.getSource(), event.getID(), ""));
254 }
255
256 private String get(String key) {
257 if(key.indexOf(".") == -1) {
258 key = "Options." + key;
259 }
260 return Gatherer.dictionary.get(key);
261 }
262}
Note: See TracBrowser for help on using the repository browser.