Index: /trunk/gsdl3/src/java/org/greenstone/server/ServerSettings.java
===================================================================
--- /trunk/gsdl3/src/java/org/greenstone/server/ServerSettings.java	(revision 13562)
+++ /trunk/gsdl3/src/java/org/greenstone/server/ServerSettings.java	(revision 13563)
@@ -14,57 +14,56 @@
 import org.greenstone.gsdl3.util.XMLConverter;
 
+import org.apache.log4j.*;
+
 public class ServerSettings extends JDialog
 
 {
-    static final private String DEFPORT = "8080";
-
-    //    static final private String WARN_LABEL = "Could not find a port number for tomcat. System gives a default port below:";
-
-    //    static final private String PORT_LABEL = "Tomcat start port number:";
-
-    //    static final private String RESTART_LABEL = "Restarting...";
-
-    static final private String ICON_IMG = "gatherer_small.gif";
-
-    //   static final private String AUTO_INFO = "Enter Digital library automatically";
-
-    // static final private String BUILD_PROPERTIES="build.properties";
-    // static final private String
-    // WEB_GLOBAL_PROPERTIES="web/WEB-INF/classes/global.properties";
-    static final private String CHALK_IMG = "chalk.gif";
-
-    JPanel content_panel, top_panel, textfield_panel, comb_panel, mid_panel,
-	down_panel;
-
-    JLabel warn_label, port_label, server_label, servlet_label, restart_label;
-
-    JButton start_button, conne_button, stop_button, save_button, exit_button;
-
+
+    static Logger logger = Logger.getLogger(org.greenstone.server.ServerControl.class.getName());
+    static final int DEFPORT = 8080;
     JCheckBox autoEnter;
-
     JComboBox servlet_combobox;
-
-    private JTextField portNumber_textfield = null;
-
-    // private MsgDialog msgDialog=null;
-
+    private JSpinner portNumber_spinner = null;
+    private JTextField program_path_field = null;
+    private JButton browse_button = null; 
+    private JRadioButton default_browser_button = null ;
+    private JRadioButton other_browser_button = null;
     private Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
 
-    static final private Dimension SIZE = new Dimension(370, 280);
-
-    private String portNum = null;
-
+    static final private Dimension SIZE = new Dimension(300, 350);
+    static final Color bg_color = Color.white; 
+    private int portNum = DEFPORT;
     private boolean autoStart = false;
-
     private String servletDefault = null;
+    private String browserPath = "";
+    private boolean useDefaultBrowser = true;
 
     private HashMap url_mappings = null;
-    protected boolean configure_required = false;
     private JDialog self;
-    public ServerSettings() {
+    private Server server;
+     
+    public ServerSettings(Server server) {
 	super((Frame)null, "", true);
 	this.self = this;
-	this.portNum = Server.build_properties.getProperty(StaticStrings.TOMCAT_PORT_PROPERTY);
-	String auto_start_str = Server.build_properties.getProperty(StaticStrings.AUTOSTART_PROPERTY);
+        this.server = server;
+
+        try{
+	    this.portNum = Integer.parseInt(server.build_properties.getProperty(StaticStrings.TOMCAT_PORT_PROPERTY));
+	}
+        catch(Exception e){
+	    logger.error(e);
+	} 
+
+        this.browserPath = server.build_properties.getProperty(StaticStrings.BROWSER_PATH);
+        
+        if (this.browserPath == null || this.browserPath.equals("")){
+	    useDefaultBrowser = true;
+            this.browserPath = "";
+	}
+	else{
+	    useDefaultBrowser = false;
+	}
+
+	String auto_start_str = server.build_properties.getProperty(StaticStrings.AUTOSTART_PROPERTY);
 	if ((auto_start_str.trim()).equals("true")) {
 	    this.autoStart = true;
@@ -73,39 +72,19 @@
 	}
 
-	this.servletDefault = Server.build_properties.getProperty(StaticStrings.DEFAULT_SERVLET_PROPERTY);
+	this.servletDefault = server.build_properties.getProperty(StaticStrings.DEFAULT_SERVLET_PROPERTY).replaceAll("/","");
 
 	setSize(SIZE);
-	setTitle(Server.dictionary.get("ServerSettings.Title"));
-	//setIconImage(Toolkit.getDefaultToolkit().getImage(Server.images_path + ICON_IMG));
+	setTitle(server.dictionary.get("ServerSettings.Title"));
+
 	setLocation((screen.width - SIZE.width) / 2,
 		    (screen.height - SIZE.height) / 2);
 	setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
 
-	content_panel = (JPanel) getContentPane();
-	top_panel = new JPanel();
-	textfield_panel = new JPanel();
-	mid_panel = new JPanel();
-	comb_panel = new JPanel();
-	down_panel = new JPanel();
-
-	//warn_label = new JLabel(WARN_LABEL);
-	//warn_label.setForeground(Color.red);
-
-	//	restart_label = new JLabel(Server.dictionary.get("ServerSettings.Restart"));
-	//	restart_label.setForeground(Color.red);
-	// restart_label.setVisible(false);
-
-	port_label = new JLabel(Server.dictionary.get("ServerSettings.Tomcat_Port"));
-
-	if (portNum != null) {
-	    //warn_label.setVisible(false);
-	    portNumber_textfield = new JTextField(portNum, 10);
-	} else {
-	    //warn_label.setVisible(true);
-	    portNumber_textfield = new JTextField(DEFPORT, 10);
-	}
-	portNumber_textfield.setHorizontalAlignment(JTextField.LEFT);
-
-	autoEnter = new JCheckBox(Server.dictionary.get("ServerSettings.Auto_Start"));
+	JLabel port_label = new JLabel(Server.dictionary.get("ServerSettings.Tomcat_Port"));
+
+	portNumber_spinner = new JSpinner(new SpinnerNumberModel(portNum,1,65535,1));
+	portNumber_spinner.setEditor(new JSpinner.NumberEditor(portNumber_spinner, "#####")); 
+
+	autoEnter = new JCheckBox(server.dictionary.get("ServerSettings.Auto_Start"));
 	
 	if (autoStart) {
@@ -114,11 +93,11 @@
 	    autoEnter.setSelected(false);
 	}
-	autoEnter.setBackground(Color.white);
-
-	servlet_label = new JLabel(Server.dictionary.get("ServerSettings.Servlet"));
+	autoEnter.setBackground(bg_color);
+
+	JLabel servlet_label = new JLabel(server.dictionary.get("ServerSettings.Servlet"));
 
 	servlet_combobox = new JComboBox();
 	servlet_combobox.setMaximumRowCount(5);
-	servlet_combobox.setBackground(Color.white);
+	servlet_combobox.setBackground(bg_color);
 
 	File web_xml = new File(GlobalProperties.getProperty(StaticStrings.GSDL3_HOME_PROPERTY) + File.separator + "WEB-INF" + File.separator + "web.xml");
@@ -126,5 +105,5 @@
 	Document web_config = converter.getDOM(web_xml);
 	if (web_config == null) {
-	    System.err.println("web.xml is null! "+web_xml.getAbsolutePath());
+	    logger.error("web.xml is null! "+web_xml.getAbsolutePath());
 	    return;
 	}
@@ -145,14 +124,13 @@
 	    }
 
-	    if (pattern.equals(servletDefault)) {
+	    if (name.equals(servletDefault)) {
 		servlet_combobox.setSelectedItem(name);
 	    }
-
-	}
-
-	save_button = new JButton(Server.dictionary.get("ServerSettings.OK"));
+	}
+
+	JButton save_button = new JButton(Server.dictionary.get("ServerSettings.OK"));
 	save_button.addActionListener(new SaveActionListener());
 
-	exit_button = new JButton(Server.dictionary.get("ServerSettings.Cancel"));
+	JButton exit_button = new JButton(Server.dictionary.get("ServerSettings.Cancel"));
 	exit_button.addActionListener(new ActionListener() {
 		public void actionPerformed(ActionEvent ev) {
@@ -161,94 +139,114 @@
 	    });
 
-	top_panel.setBorder(BorderFactory.createEmptyBorder(15, 10, 0, 0));
-	top_panel.setLayout(new BorderLayout());
-	//top_panel.add(warn_label, BorderLayout.CENTER);
-	// top_panel.add(restart_label,BorderLayout.CENTER);
-	top_panel.setBackground(Color.white);
-
-	textfield_panel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
-	textfield_panel.setLayout(new FlowLayout(FlowLayout.LEFT));
-	textfield_panel.add(port_label);
-	textfield_panel.add(portNumber_textfield);
-	textfield_panel.setBackground(Color.white);
-
-	comb_panel.setBorder(BorderFactory.createEmptyBorder(10, 0, 20, 0));
+        JPanel  port_panel = new JPanel();    
+        port_panel.setLayout(new FlowLayout(FlowLayout.LEFT));
+	port_panel.add(port_label);
+	port_panel.add(portNumber_spinner);
+	port_panel.setBackground(bg_color);
+
+        JPanel comb_panel = new JPanel();
 	comb_panel.setLayout(new FlowLayout(FlowLayout.LEFT));
 	comb_panel.add(servlet_label);
 	comb_panel.add(servlet_combobox);
-	comb_panel.setBackground(Color.white);
-
-	mid_panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 40, 0));
-	mid_panel.setLayout(new GridLayout(3, 1));
-	mid_panel.add(textfield_panel);
-	mid_panel.add(autoEnter);
+	comb_panel.setBackground(bg_color);
+
+        
+	JPanel  check_panel = new JPanel(); 
+       	check_panel.setLayout(new FlowLayout(FlowLayout.LEFT));
+        check_panel.add(autoEnter);
+        check_panel.setBackground(bg_color);
+
+	JPanel mid_panel = new JPanel();
+        mid_panel.setLayout(new GridLayout(3,1));
+	mid_panel.add(port_panel);
+	mid_panel.add(check_panel);
 	mid_panel.add(comb_panel);
-	mid_panel.setBackground(Color.white);
-
-	down_panel.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 10));
+	mid_panel.setBackground(bg_color);
+	mid_panel.setBorder(BorderFactory.createEmptyBorder(5,10,5,10));
+
+
+	JPanel browser_panel = new JPanel();
+        browser_panel.setLayout(new GridLayout(4,1));
+        default_browser_button = new JRadioButton(Server.dictionary.get("ServerSettings.DefaultBrowser"));
+        other_browser_button = new JRadioButton(Server.dictionary.get("ServerSettings.OtherBrowser"));
+        other_browser_button.addActionListener(new BrowserSelectionListener());
+        default_browser_button.addActionListener(new BrowserSelectionListener());
+
+	ButtonGroup bg = new ButtonGroup();
+        bg.add(default_browser_button);
+        bg.add(other_browser_button);
+        default_browser_button.setBorder(BorderFactory.createEmptyBorder(5,10,5,0));
+        default_browser_button.setBackground(bg_color);     
+        other_browser_button.setBorder(BorderFactory.createEmptyBorder(5,10,5,0)); 
+        other_browser_button.setBackground(bg_color);
+        JPanel browse_program_panel = new JPanel();     
+        browse_program_panel.setLayout(new BorderLayout());
+        program_path_field = new JTextField(this.browserPath);
+        browse_button = new JButton(Server.dictionary.get("ServerSettings.Browse"));
+	browse_program_panel.add(program_path_field,BorderLayout.CENTER);
+        browse_program_panel.add(browse_button,BorderLayout.EAST);
+        browse_program_panel.setBorder(BorderFactory.createEmptyBorder(5,10,5,0));
+	browse_program_panel.setBackground(bg_color);
+        browser_panel.add(new JLabel(Server.dictionary.get("ServerSettings.ChooseBrowser")));
+        browser_panel.add(default_browser_button);
+	browser_panel.add(other_browser_button);
+        browser_panel.add(browse_program_panel);
+	browser_panel.setBorder(BorderFactory.createEmptyBorder(5,10,5,10));
+        browser_panel.setBackground(bg_color);
+	if (useDefaultBrowser){
+	    default_browser_button.setSelected(true);
+	    program_path_field.setEnabled(false);
+	    browse_button.setEnabled(false); 
+	}
+	else{
+	    other_browser_button.setSelected(true);
+	}
+        browse_button.addActionListener(new BrowseActionListener());       
+        
+        JPanel down_panel = new JPanel();
+	down_panel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
 	down_panel.add(save_button);
 	down_panel.add(exit_button);
-	down_panel.setBackground(Color.white);
-
-	ImageIcon chalk_icon = new ImageIcon(Toolkit.getDefaultToolkit().getImage(Server.images_path + CHALK_IMG));
-	content_panel.setBorder(BorderFactory.createMatteBorder(0, 40, 0, 0,
-								chalk_icon));
-	content_panel.setLayout(new BorderLayout());
-
-	content_panel.add(top_panel, BorderLayout.NORTH);
-	content_panel.add(mid_panel, BorderLayout.CENTER);
-	content_panel.add(down_panel, BorderLayout.SOUTH);
-	content_panel.setBackground(Color.white);
+	down_panel.setBackground(bg_color);
+	down_panel.setBorder(BorderFactory.createEmptyBorder(5,10,5,10));
+
+        getContentPane().add(mid_panel, BorderLayout.NORTH);
+        getContentPane().add(browser_panel, BorderLayout.CENTER);
+	getContentPane().add(down_panel, BorderLayout.SOUTH);
+	getContentPane().setBackground(bg_color);
 	setVisible(true);
     }
 
-//     public boolean getAutoStatus() {
-
-// 	if (autoEnter.isSelected()) {
-// 	    return true;
-// 	} else {
-// 	    return false;
-// 	}
-//     }
-    public boolean isConfigureRequired() {
-	return configure_required;
-    }
-//     public String getValue(String file, String param) {
-// 	ScriptReadWrite scriptReadWrite = new ScriptReadWrite();
-// 	ArrayList fileLines = null;
-// 	fileLines = scriptReadWrite.readInFile(file);
-// 	String exValue = scriptReadWrite.existValue(fileLines, param);
-// 	return exValue;
-//     }
-
-//     public boolean getAutoStart() {
-// 	return autoStart;
-//     }
-
-//     public void setAutoStart(String g_properties, String auto_start) {
-// 	String autoStart_ex = getValue(g_properties, auto_start);
-// 	System.out.println("auto_start : "+autoStart_ex);
-// 	if ((autoStart_ex.trim()).equals("true")) {
-// 	    this.autoStart = true;
-// 	} else {
-// 	    this.autoStart = false;
-// 	}
-//     }
-
-//     public String getPortNum() {
-// 	return portNum;
-//     }
-
-//     public void setPortNum(String g_properties, String port) {
-// 	this.portNum = getValue(g_properties, port);
-//     }
-
-//     public String getServletDefault() {
-// 	return servletDefault;
-//     }
-
-//     public void setServletDefault(String g_properties, String servletDef) {
-// 	this.servletDefault = getValue(g_properties, servletDef);
-//     }
+    private class BrowseActionListener 
+ 	implements ActionListener {
+	
+	public void actionPerformed(ActionEvent ev) {
+	    JFileChooser chooser = new JFileChooser();
+           int returnVal = chooser.showOpenDialog(self);        
+	   
+	    if(returnVal == JFileChooser.APPROVE_OPTION) {
+                File program_path = chooser.getSelectedFile();
+		program_path_field.setText(program_path.getPath());
+	    } 
+	}
+
+     }
+
+    private class BrowserSelectionListener 
+ 	implements ActionListener {
+	
+	public void actionPerformed(ActionEvent ev) {
+	    if (default_browser_button.isSelected()){
+		program_path_field.setEnabled(false);
+                browse_button.setEnabled(false);
+	    }
+            else{
+		program_path_field.setEnabled(true);
+                browse_button.setEnabled(true);
+	    }
+	}
+
+     }
+    
 
     private class SaveActionListener
@@ -257,18 +255,37 @@
 	public void actionPerformed(ActionEvent ev) {
 	    // save everything to build_properties if things have changed
-	    System.out.println("auto_start: " + autoStart);
-	    System.out.println("auto_selected: " + autoEnter.isSelected());
-	    boolean has_changed = false;
-	    if (!portNum.equals(portNumber_textfield.getText().trim())) {
+	     boolean has_changed = false;
+             boolean require_restart = false;
+	    if (portNum != ((Integer)portNumber_spinner.getValue()).intValue()) {
 		has_changed = true;
-		configure_required = true;
-		System.err.println("port changed");
+                require_restart = true; 
+                server.reconfigRequired();
+             	logger.info("port changed, new port is "+portNumber_spinner.getValue());
 	    }
 	    if (autoStart != autoEnter.isSelected()) {
+            	has_changed = true;
+	    }
+	    if (!servletDefault.equals(servlet_combobox.getSelectedItem())) {
+         	has_changed = true;
+                require_restart = true; 
+	    }
+            //changed to use other browser
+            if (useDefaultBrowser && other_browser_button.isSelected()){
+		browserPath = program_path_field.getText();
 		has_changed = true;
-	    }
-	    if (!servletDefault.equals(servlet_combobox.getSelectedItem())) {
+	    } 
+	    //the browser path has been changed 
+	    if ( !useDefaultBrowser && !browserPath.equals(program_path_field.getText())){
+		browserPath = program_path_field.getText();
+		 has_changed = true;
+	    }
+	    
+            //changed to use the default browser
+	    if ( default_browser_button.isSelected() && !useDefaultBrowser){
+		browserPath = "";
 		has_changed = true;
 	    }
+             
+
 	    if (has_changed) {
 		ArrayList oldFileLines = null;
@@ -278,5 +295,5 @@
 		oldFileLines = scriptReadWrite.readInFile(Server.build_properties_file);
 		
-		newFileLines = scriptReadWrite.queryReplace(oldFileLines, StaticStrings.TOMCAT_PORT_PROPERTY, portNumber_textfield.getText());
+		newFileLines = scriptReadWrite.queryReplace(oldFileLines, StaticStrings.TOMCAT_PORT_PROPERTY, portNum+"");
 		
 		String newAutoEnter = (new Boolean(autoEnter.isSelected())).toString();
@@ -285,12 +302,19 @@
 		String newServletDef = (String) servlet_combobox.getSelectedItem();
 		newFileLines = scriptReadWrite.queryReplace(newFileLines,StaticStrings.DEFAULT_SERVLET_PROPERTY, (String) url_mappings.get(newServletDef));
-		
+
+		String osName = System.getProperty("os.name");
+                if (osName.startsWith("Windows")){
+		    browserPath = browserPath.replaceAll("\\\\","/");
+		}
+                 newFileLines = scriptReadWrite.queryReplace(newFileLines,StaticStrings.BROWSER_PATH, browserPath);
+
 		scriptReadWrite.writeOutFile(Server.build_properties_file,
 					     newFileLines);
-		Server.reloadBuildProperties();
-		JOptionPane.showMessageDialog(null,"The new settings will be avaliable after the server restarted","Info", JOptionPane.INFORMATION_MESSAGE);
-	    } else {
-		JOptionPane.showMessageDialog(null,"No change has been made", "Info",JOptionPane.INFORMATION_MESSAGE);
-	    }
+		server.reloadBuildProperties();
+		if (require_restart){
+		    JOptionPane.showMessageDialog(null,server.dictionary.get("ServerSetting.SettingChanged"),"Info", JOptionPane.INFORMATION_MESSAGE);
+		}
+	    } 
+
 	    self.dispose();
 	}
