Ignore:
Timestamp:
2017-08-14T22:23:04+12:00 (7 years ago)
Author:
ak19
Message:

All the changes that were required to set up multiple proxy servers, one for HTTP, one for HTTPS, one for FTP. Still need to test on Windows

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/src/org/greenstone/gatherer/gui/Preferences.java

    r31861 r31880  
    5656    extends ModalDialog
    5757{
     58    static final public String HTTP = "HTTP";
     59    static final public String HTTPS = "HTTPS";
     60    static final public String FTP = "FTP";
     61   
    5862    static final public String CONNECTION_PREFS = "connection";
    5963    static final public String GENERAL_PREFS = "general";
     
    8690    private JRadioButton expert_mode_radio_button;
    8791    private JRadioButton librarian_mode_radio_button;
    88     private JSpinner proxy_port_field;
     92    private JSpinner http_proxy_port_field;
     93    private JSpinner https_proxy_port_field;
     94    private JSpinner ftp_proxy_port_field;
    8995    private JTabbedPane tab_pane;
    9096    private JTextArea mode_description_textarea;
     
    9399    private JTextField library_path_field;
    94100    private JTextField program_field;
    95     private JTextField proxy_host_field;
     101    private JTextField http_proxy_host_field;
     102    private JTextField https_proxy_host_field;
     103    private JTextField ftp_proxy_host_field;
    96104    private JTextField collect_dir_field;
    97105
     
    337345    use_proxy_checkbox.setPreferredSize(ROW_SIZE);
    338346   
    339         JPanel proxy_host_pane = new JPanel();
    340         proxy_host_pane.setComponentOrientation(Dictionary.getOrientation());
    341     proxy_host_pane.setPreferredSize(ROW_SIZE);
    342        
    343     JLabel proxy_host_label = new JLabel(Dictionary.get("Preferences.Connection.Proxy_Host"));
    344         proxy_host_label.setComponentOrientation(Dictionary.getOrientation());
    345     proxy_host_label.setPreferredSize(LABEL_SIZE);
    346    
    347     proxy_host_field = new JTextField(Configuration.getString("general.proxy_host", true));
    348     proxy_host_field.setEnabled(currently_enabled);
    349     proxy_host_field.setToolTipText(Dictionary.get("Preferences.Connection.Proxy_Host_Tooltip"));
    350     proxy_host_field.setComponentOrientation(Dictionary.getOrientation());
    351        
    352     JPanel proxy_port_pane = new JPanel();
    353         proxy_port_pane.setComponentOrientation(Dictionary.getOrientation());
    354     proxy_port_pane.setPreferredSize(ROW_SIZE);
    355        
    356     JLabel proxy_port_label = new JLabel(Dictionary.get("Preferences.Connection.Proxy_Port"));
    357     proxy_port_label.setPreferredSize(LABEL_SIZE);
    358         proxy_port_label.setComponentOrientation(Dictionary.getOrientation());
    359    
    360     String port_value = Configuration.getString("general.proxy_port", true);
    361     if(port_value.length() > 0) {
    362        proxy_port_field = new JSpinner(new SpinnerNumberModel((new Integer(port_value)).intValue(), 0, 65535, 1));
    363     }
    364     else {
    365        proxy_port_field = new JSpinner(new SpinnerNumberModel(0, 0, 65535, 1));
    366     }
    367     proxy_port_field.setEnabled(currently_enabled);
    368     proxy_port_field.setToolTipText(Dictionary.get("Preferences.Connection.Proxy_Port_Tooltip"));
    369347   
    370348    // Connection
     
    405383    collect_dir_pane.add(chdir_button, BorderLayout.LINE_END);
    406384
    407     proxy_host_pane.setLayout(new BorderLayout());
    408     proxy_host_pane.add(proxy_host_label, BorderLayout.LINE_START);
    409     proxy_host_pane.add(proxy_host_field, BorderLayout.CENTER);
    410 
    411     proxy_port_pane.setLayout(new BorderLayout());
    412     proxy_port_pane.add(proxy_port_label, BorderLayout.LINE_START);
    413     proxy_port_pane.add(proxy_port_field, BorderLayout.CENTER);
    414385
    415386    connection_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    416     connection_pane.setLayout(new GridLayout(9,1,0,2));
     387    connection_pane.setLayout(new GridLayout(10,1,0,2));
    417388    connection_pane.add(program_pane);
    418389    connection_pane.add(library_path_pane);
     
    428399    connection_pane.add(no_check_certificate_checkbox);
    429400    connection_pane.add(use_proxy_checkbox);
    430     connection_pane.add(proxy_host_pane);
    431     connection_pane.add(proxy_port_pane);
     401   
     402    // set up the proxy host and port fields for each of http, https and ftp   
     403        setupProxyHostPane(HTTP, connection_pane, currently_enabled, http_proxy_host_field, http_proxy_port_field);
     404    setupProxyHostPane(HTTPS, connection_pane, currently_enabled, https_proxy_host_field, https_proxy_port_field);
     405    setupProxyHostPane(FTP, connection_pane, currently_enabled, ftp_proxy_host_field, ftp_proxy_port_field);
    432406
    433407    return connection_pane;
     
    570544    return general_pane;
    571545    }
     546
     547    private void setupProxyHostPane(String protocol, JPanel connection_pane, boolean isEnabled,
     548                    JTextField proxy_host_field, JSpinner proxy_port_field)
     549    {
     550    final Dimension WIDER_LABEL_SIZE = new Dimension(180, 25);
     551    final Dimension NARROWER_LABEL_SIZE = new Dimension(60, 25);
     552    final Dimension WIDER_ROW_SIZE = new Dimension(480, 25);
     553    final Dimension NARROWER_ROW_SIZE = new Dimension(120, 25);
     554   
     555    JPanel proxy_host_pane = new JPanel();
     556        proxy_host_pane.setComponentOrientation(Dictionary.getOrientation());
     557    proxy_host_pane.setPreferredSize(WIDER_ROW_SIZE);
     558       
     559    JLabel proxy_host_label = new JLabel(Dictionary.get("Preferences.Connection."+protocol+"_Proxy_Host"));
     560        proxy_host_label.setComponentOrientation(Dictionary.getOrientation());
     561    proxy_host_label.setPreferredSize(WIDER_LABEL_SIZE);
     562   
     563    proxy_host_field = new JTextField(Configuration.getString("general."+protocol+"_proxy_host", true));
     564    proxy_host_field.setEnabled(isEnabled);
     565    proxy_host_field.setToolTipText(Dictionary.get("Preferences.Connection."+protocol+"_Proxy_Host_Tooltip"));
     566    proxy_host_field.setComponentOrientation(Dictionary.getOrientation());
     567       
     568    JPanel proxy_port_pane = new JPanel();
     569        proxy_port_pane.setComponentOrientation(Dictionary.getOrientation());
     570    proxy_port_pane.setPreferredSize(NARROWER_ROW_SIZE);
     571       
     572    JLabel proxy_port_label = new JLabel(Dictionary.get("Preferences.Connection.Proxy_Port"));
     573    proxy_port_label.setPreferredSize(NARROWER_LABEL_SIZE);
     574        proxy_port_label.setComponentOrientation(Dictionary.getOrientation());
     575   
     576    String port_value = Configuration.getString("general."+protocol+"_proxy_port", true);
     577    if(port_value.length() > 0) {
     578       proxy_port_field = new JSpinner(new SpinnerNumberModel((new Integer(port_value)).intValue(), 0, 65535, 1));
     579    }
     580    else {
     581       proxy_port_field = new JSpinner(new SpinnerNumberModel(0, 0, 65535, 1));
     582    }
     583    proxy_port_field.setEnabled(isEnabled);
     584    proxy_port_field.setToolTipText(Dictionary.get("Preferences.Connection."+protocol+"_Proxy_Port_Tooltip"));
     585
     586
     587    // Since the actual object member vars were null when this method is called
     588    // need to ensure they are assigned the correct value now, else those refs will remain null
     589    if(protocol.equals(HTTP)) {
     590        http_proxy_host_field = proxy_host_field;
     591        http_proxy_port_field = proxy_port_field;
     592    } else if (protocol.equals(HTTPS)) {
     593        https_proxy_host_field = proxy_host_field;
     594        https_proxy_port_field = proxy_port_field;
     595    } else if(protocol.equals(FTP)) {
     596        ftp_proxy_host_field = proxy_host_field;
     597        ftp_proxy_port_field = proxy_port_field;
     598    }
     599   
     600    proxy_host_pane.setLayout(new BorderLayout());
     601    proxy_host_pane.add(proxy_host_label, BorderLayout.LINE_START);
     602    proxy_host_pane.add(proxy_host_field, BorderLayout.CENTER);
     603
     604    proxy_port_pane.setLayout(new BorderLayout());
     605    proxy_port_pane.add(proxy_port_label, BorderLayout.LINE_START);
     606    proxy_port_pane.add(proxy_port_field, BorderLayout.CENTER);
     607
     608    //connection_pane.add(proxy_host_pane);
     609    //connection_pane.add(proxy_port_pane);
     610
     611    JPanel proxy_panel = new JPanel();
     612    proxy_panel.setLayout(new BorderLayout()); 
     613    proxy_panel.add(proxy_host_pane, BorderLayout.WEST);
     614    proxy_panel.add(proxy_port_pane, BorderLayout.CENTER);
     615
     616    connection_pane.add(proxy_panel);
     617    }
     618   
    572619
    573620    /** Generate the controls for altering the detail mode.
     
    786833        this.close = close;
    787834    }
     835
     836    private void setProxyHostForProtocol(String protocol,
     837                         JTextField proxy_host_field,
     838                         JSpinner proxy_port_field)
     839    {       
     840        Configuration.setString("general."+protocol+"_proxy_host", true, proxy_host_field.getText());
     841        Configuration.setString("general."+protocol+"_proxy_port", true, proxy_port_field.getValue() + "");
     842    }
     843   
    788844    public void actionPerformed(ActionEvent event)
    789845    {
     
    876932       
    877933        Configuration.set("general.use_proxy", true, use_proxy_checkbox.isSelected());
    878         Configuration.setString("general.proxy_host", true, proxy_host_field.getText());
    879         Configuration.setString("general.proxy_port", true, proxy_port_field.getValue() + "");
     934        setProxyHostForProtocol(HTTP, http_proxy_host_field, http_proxy_port_field);
     935        setProxyHostForProtocol(HTTPS, https_proxy_host_field, https_proxy_port_field);
     936        setProxyHostForProtocol(FTP, ftp_proxy_host_field, ftp_proxy_port_field);
    880937        Gatherer.setProxy();
    881938
     
    9751032
    9761033        // If proxy is on but proxy details are incomplete, then can't continue
    977         if (use_proxy_checkbox.isSelected() && proxy_host_field.getText().equals("")) {
     1034        if (use_proxy_checkbox.isSelected()
     1035        && http_proxy_host_field.getText().equals("")
     1036        && https_proxy_host_field.getText().equals("")
     1037        && ftp_proxy_host_field.getText().equals("")) {
    9781038        JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("Preferences.Connection.Proxy_Host_Missing"),
    9791039                          Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
     
    11441204        Configuration.set("general.use_proxy", true, enabled);
    11451205        // Fortunately this is already driven by the event thread.
    1146         proxy_host_field.setEnabled(enabled);
    1147         proxy_port_field.setEnabled(enabled);
     1206        http_proxy_host_field.setEnabled(enabled);
     1207        http_proxy_port_field.setEnabled(enabled);
     1208        https_proxy_host_field.setEnabled(enabled);
     1209        https_proxy_port_field.setEnabled(enabled);
     1210        ftp_proxy_host_field.setEnabled(enabled);
     1211        ftp_proxy_port_field.setEnabled(enabled);
    11481212    }
    11491213    }
Note: See TracChangeset for help on using the changeset viewer.