Changeset 12497


Ignore:
Timestamp:
2006-08-22T15:13:47+12:00 (18 years ago)
Author:
kjdon
Message:

tidied up a bit: style, command list generation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/cdm/download/ServerInfoDialog.java

    r12468 r12497  
    1010import org.greenstone.gatherer.cdm.Argument;
    1111import org.greenstone.gatherer.Configuration;
     12import org.greenstone.gatherer.DebugStream;
    1213import org.greenstone.gatherer.Dictionary;
     14import org.greenstone.gatherer.LocalGreenstone;
    1315import org.greenstone.gatherer.gui.*;
    1416import org.greenstone.gatherer.cdm.download.Download;
     
    1719public class ServerInfoDialog extends JDialog
    1820{   
     21    static private Dimension SIZE = new Dimension(500, 300);
    1922    private String url;
    2023    private String mode;
    2124    private JPanel info_list_pane;
    2225    private JScrollPane info_scroll_pane;
    23     private JDialog me;
     26    private JDialog info_dialog;
    2427    private Download download;
    2528    private String proxy_url;
    26 
     29   
    2730    public ServerInfoDialog(String url, String proxy_url, String mode, Download download) {
    2831    super();
     
    3134        this.download = download;
    3235        this.proxy_url = proxy_url;
     36    this.info_dialog = this;
     37   
     38    this.setSize(SIZE);
    3339
    34     this.setSize(300,400);
    35 
    36     JButton close_button = new GLIButton(Dictionary.get("Download.ServerInformation.close"),Dictionary.get("Download.ServerInformation.close_Tooltip"));
    37     close_button.setEnabled(true);
    38     close_button.setMnemonic(KeyEvent.VK_C);
    39  
    40     close_button.addActionListener(new CloseBtnListener());
    41 
     40    JButton close_button = new GLIButton(Dictionary.get("General.Close"),Dictionary.get("General.Close_Tooltip"));
     41    close_button.setEnabled(true);
     42    close_button.addActionListener(new ActionListener() {
     43        public void actionPerformed(ActionEvent event) {
     44            info_dialog.dispose();
     45        }
     46        });
     47   
    4248    JPanel button_pane = new JPanel();
    4349    button_pane.setLayout(new FlowLayout());
     
    6571    Container main_container = this.getContentPane();
    6672    main_container.add(main_pane);
    67     me = this;
     73   
     74    // Show
     75    Dimension screen_size = Configuration.screen_size;
     76    setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
     77    setVisible(true);
     78
    6879    }
    6980
    7081    private void getServerInfo()
    7182    {
    72         String command =""; 
    73         if (Utility.isWindows()) {
    74               command = "perl -S \"" + Configuration.gsdl_path + "bin" + File.separator + "script" + File.separator + "downloadfrom.pl "+"\"" + " -info -download_mode " + mode + " ";
    75     }
    76     else{
    77         command =Configuration.gsdl_path + "bin" + File.separator + "script" + File.separator + "downloadfrom.pl  -info -download_mode " + mode + " ";
     83    ArrayList commands = new ArrayList();
     84    if (Utility.isWindows()) {
     85        commands.add(Configuration.perl_path);
     86        commands.add("-S");
    7887    }
    79 
     88    commands.add(LocalGreenstone.getBinScriptDirectoryPath()+"downloadfrom.pl");
     89    commands.add("-info");
     90    commands.add("-download_mode");
     91    commands.add(mode);
     92   
    8093        ArrayList all_arg = download.getArguments(true,false);
    81     for(int i = 0; i < all_arg.size(); i++) {
     94    for (int i = 0; i < all_arg.size(); i++) {
    8295        Argument argument = (Argument) all_arg.get(i);
    8396       
    84         if(argument.isAssigned())
    85         {
    86                 command +="-" + argument.getName()+" ";
    87             if(argument.getType() != Argument.FLAG)
    88             {
    89                 command +=argument.getValue()+" ";
    90             }
     97        if(argument.isAssigned()) {
     98        commands.add("-" + argument.getName());
     99        if(argument.getType() != Argument.FLAG) {
     100            commands.add(argument.getValue());
    91101        }
    92      
     102        }   
    93103    }
    94 
    95      try {
    96           String [] env = null;
    97           Process prcs = null;
    98       Runtime rt = Runtime.getRuntime();
     104   
     105    String[] command = (String[]) commands.toArray(new String[0]);
     106    DebugStream.println("Getting server info: "+commands);
     107    try {
     108        String [] env = null;
     109        Process prcs = null;
     110        Runtime rt = Runtime.getRuntime();
    99111     
    100          if (Utility.isWindows()) {
     112        if (Utility.isWindows()) {
    101113                prcs = rt.exec(command);   
    102114        }
    103         else{
    104         //for lunix
     115        else {
     116        ArrayList env_list = new ArrayList();
    105117        if (proxy_url != null && !proxy_url.equals("")) {           
    106             env = new String[4];
    107118                    proxy_url = proxy_url.replaceAll("http://","");
    108             env[0] = "http_proxy=http://"+proxy_url;
    109             env[1] = "ftp_proxy=ftp://"+proxy_url;
    110             env[2] = "GSDLHOME="+Configuration.gsdl_path;
    111             env[3] = "GSDLOS="+System.getProperty("os.name");
    112             prcs = rt.exec(command,env);
    113         }
    114         else{       
    115             env = new String[2];
    116          
    117             env[0] = "GSDLHOME="+Configuration.gsdl_path;
    118             env[1] = "GSDLOS="+System.getProperty("os.name");
    119             prcs = rt.exec(command,env);
    120         }
     119            env_list.add("http_proxy=http://"+proxy_url);
     120            env_list.add("ftp_proxy=ftp://"+proxy_url);
     121        }
     122        env_list.add("GSDLHOME="+Configuration.gsdl_path);
     123        env_list.add("GSDLOS="+System.getProperty("os.name"));
     124        env = (String []) env_list.toArray(new String[0]);
     125        prcs = rt.exec(command,env);
     126       
    121127        }
    122128
    123      // System.out.println(command);
    124      
    125       InputStreamReader isr = new InputStreamReader(prcs.getErrorStream());
     129        InputStreamReader isr = new InputStreamReader(prcs.getErrorStream());
    126130        BufferedReader br = new BufferedReader(isr);
    127131        String line;
     
    133137        info_list_pane.add(a_label);
    134138        }
    135     }catch (Exception ioe) {
     139       
     140    } catch (Exception ioe) {
    136141     
    137         }
     142    }
    138143   
    139144    }
    140145
    141     private class CloseBtnListener implements ActionListener
    142     {
    143     public void actionPerformed(ActionEvent event)
    144     {
    145        me.dispose();
    146     }
    147     }
    148 
    149146}
Note: See TracChangeset for help on using the changeset viewer.