1 /* AdvancedProxySettingsDialog.java -- Display the dialog for modifying proxy settings.
2 Copyright (C) 2010 Red Hat
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */
18 
19 package net.sourceforge.jnlp.controlpanel;
20 
21 import java.awt.Container;
22 import java.awt.Dimension;
23 import java.awt.Frame;
24 import java.awt.GridBagConstraints;
25 import java.awt.GridBagLayout;
26 import java.awt.Toolkit;
27 import java.awt.event.WindowAdapter;
28 import java.awt.event.WindowEvent;
29 
30 import javax.swing.JDialog;
31 
32 import net.sourceforge.jnlp.config.DeploymentConfiguration;
33 import net.sourceforge.jnlp.runtime.Translator;
34 import net.sourceforge.jnlp.util.ImageResources;
35 import net.sourceforge.jnlp.util.ScreenFinder;
36 
37 /**
38  * This dialog provides a means for user to edit more of the proxy settings.
39  *
40  * @author Andrew Su <asu@redhat.com, andrew.su@utoronto.ca>
41  *
42  */
43 public class AdvancedProxySettingsDialog extends JDialog {
44 
45     private boolean initialized = false;
46     private static final String dialogTitle = Translator.R("APSDialogTitle");
47     private final DeploymentConfiguration config; // Configuration file which contains all the settings.
48 
49     AdvancedProxySettingsPane topPanel;
50 
51     /**
52      * Creates a new instance of the proxy settings dialog.
53      *
54      * @param config
55      *            Loaded DeploymentConfiguration file.
56      */
AdvancedProxySettingsDialog(DeploymentConfiguration config)57     public AdvancedProxySettingsDialog(DeploymentConfiguration config) {
58         super((Frame) null, dialogTitle, true); // Don't need a parent.
59         setIconImages(ImageResources.INSTANCE.getApplicationImages());
60 
61         this.config = config;
62 
63         /* Prepare for adding components to dialog box */
64         Container contentPane = getContentPane();
65         contentPane.setLayout(new GridBagLayout());
66         setMinimumSize(new Dimension(456, 404));
67         setPreferredSize(new Dimension(456, 404));
68 
69         GridBagConstraints c = new GridBagConstraints();
70         c.fill = GridBagConstraints.BOTH;
71         c.weightx = 1;
72         c.weighty = 1;
73         c.gridx = 0;
74         c.gridy = 0;
75         topPanel = new AdvancedProxySettingsPane(this, this.config);
76         contentPane.add(topPanel, c);
77 
78         pack();
79 
80         /* Set focus to default button when first activated */
81         WindowAdapter adapter = new WindowAdapter() {
82             private boolean gotFocus = false;
83 
84             public void windowGainedFocus(WindowEvent we) {
85                 // Once window gets focus, set initial focus
86                 if (!gotFocus) {
87                     topPanel.focusOnDefaultButton();
88                     gotFocus = true;
89                 }
90             }
91         };
92         addWindowFocusListener(adapter);
93 
94         initialized = true;
95     }
96 
97     /**
98      * Check whether the dialog has finished being created.
99      *
100      * @return True if dialog is ready to be displayed.
101      */
isInitialized()102     public boolean isInitialized() {
103         return initialized;
104     }
105 
106     /**
107      * Center the dialog box.
108      */
centerDialog()109     private void centerDialog() {
110         ScreenFinder.centerWindowsToCurrentScreen(this);
111     }
112 
113     /**
114      * Display the Proxy Settings Dialog.
115      *
116      * @param config
117      *            A loaded DeploymentConfiguration file.
118      */
showAdvancedProxySettingsDialog(final DeploymentConfiguration config)119     public static void showAdvancedProxySettingsDialog(final DeploymentConfiguration config) {
120         AdvancedProxySettingsDialog psd = new AdvancedProxySettingsDialog(config);
121         psd.setResizable(false);
122         psd.centerDialog();
123         psd.setVisible(true);
124         psd.dispose();
125     }
126 }
127