- Timestamp:
- 2003-05-27T15:58:15+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/gui/OptionsBox.java
r4293 r4367 47 47 */ 48 48 public class OptionsBox 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 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 125 // Update config 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 BorderFactory.createBevelBorder(BevelBorder.LOWERED),166 get("Proxy_Configuration")));167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 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 251 252 253 254 252 public void focusLost(FocusEvent event) { 253 actionPerformed(new ActionEvent(event.getSource(), event.getID(), "")); 254 } 255 255 256 257 258 259 260 261 256 private String get(String key) { 257 if(key.indexOf(".") == -1) { 258 key = "Options." + key; 259 } 260 return Gatherer.dictionary.get(key); 261 } 262 262 }
Note:
See TracChangeset
for help on using the changeset viewer.