Index: /trunk/gsdl3/src/java/org/greenstone/server/ServerControl.java
===================================================================
--- /trunk/gsdl3/src/java/org/greenstone/server/ServerControl.java	(revision 13560)
+++ /trunk/gsdl3/src/java/org/greenstone/server/ServerControl.java	(revision 13561)
@@ -10,4 +10,5 @@
 import org.greenstone.gsdl3.util.GlobalProperties;
 
+import org.apache.log4j.*;
 /**
  * This class is to start or restart the library server
@@ -16,31 +17,25 @@
 public class ServerControl extends JFrame {
 
+    static Logger logger = Logger.getLogger(org.greenstone.server.ServerControl.class.getName());
+ 
     /** The dimension of the frame */
     static final private Dimension FRAME_SIZE = new Dimension(350, 250);
 
-    /** Ant command for managing Tomcat */
-    static final private String START_CMD = "start";
-    static final private String RESTART_CMD = "restart";
-    static final private String CONFIGURE_CMD = "configure";
-    static final private String STOP_CMD = "stop";
-    
-    /** images for the panel */
-    static final private String ICON_IMG = "gatherer_small.gif";
-    static final private String LOGO_IMG = "logogreenstone.gif";
-    static final private String CHALK_IMG = "chalk.gif";
-    
-    private boolean configure_required = false;
-    private boolean tomcat_running = false;
-
+    Color bg_color = Color.white;    
+    
     /** some components we need to refer to later */
-    private JPanel mid_panel;
-    private JLabel process_label;
-    private JTextArea info_label;
+    private JLabel info_label;
     private JButton enter_button;
-
-    public ServerControl() {
+    private JMenu fMenu;
+    private Server server;
+    private JFrame thisframe;
+    
+    public ServerControl(Server server) {
 	super(Server.dictionary.get("ServerControl.Frame_Title"));
+ 
+	this.server = server;
+        thisframe = this;
+
 	setSize(FRAME_SIZE);
-	setIconImage(Toolkit.getDefaultToolkit().getImage(Server.images_path + ICON_IMG));
 	setDefaultCloseOperation(EXIT_ON_CLOSE);
 	Dimension screen_size = Toolkit.getDefaultToolkit().getScreenSize();
@@ -48,70 +43,52 @@
 		    (screen_size.height - FRAME_SIZE.height) / 2);
 	setBackground(Color.white);
-
-	// do we automatically start the server/browser on launching?
-	String auto_start_str = Server.build_properties.getProperty(StaticStrings.AUTOSTART_PROPERTY);
-	boolean auto_start = false;
-	if (auto_start_str!= null && auto_start_str.equals("true")) {
-	    auto_start = true;
-	}
-	addWindowListener(new MyWindowAdapter());
-
-	JPanel content_panel = (JPanel) getContentPane();
-	JPanel title_panel = new JPanel();
-	mid_panel = new JPanel();
-	JPanel button_panel = new JPanel();
-
-	JLabel title_label = new JLabel(Server.dictionary.get("ServerControl.Title"), JLabel.CENTER);
-	title_label.setFont(new Font("Dialog", Font.BOLD, 18));
-
-	JLabel version_label = new JLabel(Server.dictionary.get("ServerControl.Version", new String [] {GlobalProperties.getProperty(StaticStrings.GSDL3_VERSION_PROPERTY)}), JLabel.CENTER);
+        addWindowListener(new MyAdapter()); 
+   
+        JPanel title_panel = new JPanel();
+	title_panel.setLayout(new BorderLayout());
+
+        JLabel title_label = new JLabel();
+        String title = Server.dictionary.get("ServerControl.Title");           
+        title_label.setText(stringToHTML(title)); 
+        title_label.setOpaque(false);	
+	title_label.setHorizontalAlignment(SwingConstants.CENTER);
+        title_label.setFont(new Font("SansSerif",Font.PLAIN,18));
+       
+
+        JLabel version_label = new JLabel();
+        String version = Server.dictionary.get("ServerControl.Version", new String [] {GlobalProperties.getProperty(StaticStrings.GSDL3_VERSION_PROPERTY)}).toLowerCase();
+         
+        version_label.setText(stringToHTML(version)); 
+        version_label.setOpaque(false);	
+	version_label.setHorizontalAlignment(SwingConstants.CENTER);
+        version_label.setFont(new Font("SansSerif",Font.PLAIN,14));
+        
+        title_panel.add(title_label,BorderLayout.CENTER);
+        title_panel.add(version_label,BorderLayout.SOUTH);
+	title_panel.setBackground(bg_color);	
+	title_panel.setBorder(BorderFactory.createEmptyBorder(5,10,5,10));
+
+   	info_label = new JLabel();
+        info_label.setOpaque(false);
+        info_label.setHorizontalAlignment(SwingConstants.LEFT);
+        info_label.setVerticalAlignment(SwingConstants.CENTER);
+        info_label.setFont(new Font("SansSerif",Font.PLAIN,14));
+	info_label.setBorder(BorderFactory.createEmptyBorder(5,10,5,10));	        
 		
-	title_panel.setBorder(BorderFactory.createEmptyBorder(20, 0, 0, 0));
-	title_panel.setLayout(new BorderLayout());
-	title_panel.add(title_label, BorderLayout.NORTH);
-	title_panel.add(version_label, BorderLayout.CENTER);
-	title_panel.setBackground(Color.white);
-
-	process_label = new JLabel(Server.dictionary.get("ServerControl.Starting"), JLabel.CENTER);
-	info_label = new JTextArea();
-	info_label.setEditable(false);
-	info_label.setLineWrap(true);
-	info_label.setWrapStyleWord(true);
-	mid_panel.setBorder(BorderFactory.createEmptyBorder(20, 0, 0, 0));
-	mid_panel.setLayout(new BorderLayout());
-	mid_panel.setBackground(Color.white);
-
-	if (auto_start) {
-	    // starting automatically, just show starting.... and set up the 
-	    // info and button to restart - will be added by windowListener
-	    
-	    mid_panel.add(process_label, BorderLayout.CENTER);
-	    enter_button = new JButton(Server.dictionary.get("ServerControl.Restart"));
-	    enter_button.setVisible(false);
-	    info_label.setText(Server.dictionary.get("ServerControl.Help_Restart"));
-	} else {
-	    info_label.setText(Server.dictionary.get("ServerControl.Help_Start"));
-	    mid_panel.add(info_label, BorderLayout.CENTER);
-	    enter_button = new JButton(Server.dictionary.get("ServerControl.Start"));
-	    enter_button.setVisible(true);
-	}
+        JPanel button_panel = new JPanel(new FlowLayout(FlowLayout.CENTER));
+	enter_button = new JButton();
+	enter_button.setEnabled(false);
 	enter_button.addActionListener(new EnterButtonListener());
-
-	ImageIcon logo_icon = new ImageIcon(Toolkit.getDefaultToolkit().getImage(Server.images_path + LOGO_IMG));
-	button_panel.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 10));
-	button_panel.add(enter_button);
-	button_panel.add(new JLabel(logo_icon));
-	button_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 GridLayout(3, 1));
-	content_panel.add(title_panel);
-	content_panel.add(mid_panel);
-	content_panel.add(button_panel);
-	content_panel.setBackground(Color.white);
-
-	setJMenuBar(createMenu());
+        enter_button.setText(Server.dictionary.get("ServerControl.EnterLibrary"));
+ 	button_panel.add(enter_button);
+	button_panel.setBackground(bg_color);	
+	button_panel.setBorder(BorderFactory.createEmptyBorder(5,10,5,10));
+
+	getContentPane().setLayout(new BorderLayout());
+	getContentPane().add(title_panel,BorderLayout.NORTH);
+	getContentPane().add(info_label,BorderLayout.CENTER);
+	getContentPane().add(button_panel,BorderLayout.SOUTH);
+	getContentPane().setBackground(bg_color);
+    	setJMenuBar(createMenu());
 	setVisible(true);
     }
@@ -119,24 +96,36 @@
     protected JMenuBar createMenu() {
 	JMenuBar menuBar = new JMenuBar();
-	JMenu fMenu = new JMenu(Server.dictionary.get("ServerControl.Menu.File"));
+         fMenu = new JMenu(Server.dictionary.get("ServerControl.Menu.File"));
 	JMenuItem iConf = new JMenuItem(Server.dictionary.get("ServerControl.Menu.Settings"));
 	iConf.setBackground(Color.white);
 	iConf.addActionListener(new ActionListener() {
 		public void actionPerformed(ActionEvent ae) {
-		    ServerSettings serverSetting = new ServerSettings();
-		    configure_required = serverSetting.isConfigureRequired();
+		    ServerSettings serverSetting = new ServerSettings(server);
 		}
 	    });
-
+	
 	JMenuItem iExit = new JMenuItem(Server.dictionary.get("ServerControl.Menu.Exit"));
 	iExit.setBackground(Color.white);
 	iExit.addActionListener(new ActionListener() {
 		public void actionPerformed(ActionEvent ae) {
-		    stopServer();
-		    System.exit(0);
+		    Thread runInThread = new Thread(new Runnable(){
+			    public void run(){
+				server.stop();
+			    
+			    }
+			},"stop server");
+		    try{
+                        runInThread.start(); 
+		
+		    }
+		    catch(Exception e){
+			logger.error(e);
+		    }    
+		    thisframe.dispose();
 		}
 	    });
 	fMenu.add(iConf);
 	fMenu.add(iExit);
+	fMenu.setEnabled(false);
 	menuBar.add(fMenu);
 	menuBar.setBorder(new BevelBorder(BevelBorder.RAISED));
@@ -144,71 +133,108 @@
     }
 
-    protected void stopServer() {
-	RunAnt runAnt = new RunAnt();
-	runAnt.setAntCmd(STOP_CMD);
-	runAnt.run();
-    }
-    
-    protected void restartServer() {
-	RunAnt runAnt = new RunAnt();
-	// stop it if already running
-	if (tomcat_running) {
-	    runAnt.setAntCmd(STOP_CMD);
-	    runAnt.run();
-	}	    
-	// reconfigure if necessary
-	if (configure_required) {
-	    runAnt.setAntCmd(CONFIGURE_CMD);
-	    runAnt.run();
-	    GlobalProperties.reload(); // properties file may have changed, so reload it
-	    configure_required = false;
-	}
-	// start it up
-	runAnt.setAntCmd(START_CMD);
-	runAnt.run();
-	tomcat_running = true;
-    }
-	
-    protected void launchBrowser() {
-	setState(Frame.ICONIFIED); // make the server frame iconified
-	String url = GlobalProperties.getGSDL3WebAddress()+ Server.build_properties.getProperty(StaticStrings.DEFAULT_SERVLET_PROPERTY);
-	BrowserLauncher launcher = new BrowserLauncher(url);
-	launcher.start();
-    }
-    
-    private class MyWindowAdapter
-	extends WindowAdapter {
-	public void windowClosing(WindowEvent e) {
-	    /** When the frame is closed, the library server is terminated */
-	    stopServer();
-	    tomcat_running = false;
-	}
-	
-	public void windowOpened(WindowEvent e) {
-	    // if auto start is true, we start the server and launch a browser
-	    String auto_start = Server.build_properties.getProperty(StaticStrings.AUTOSTART_PROPERTY);
-	    if (auto_start != null && auto_start.equals("true")) {
-		restartServer();
-		launchBrowser();
-		// have to reset the panel to restart
-		mid_panel.remove(process_label);
-		mid_panel.add(info_label, BorderLayout.CENTER );
-		enter_button.setVisible(true);
-	    } 
-	}
-    }
-
+    public void updateControl(){
+      	switch (server.getServerState()){
+	case Server.SERVER_STARTED:
+	    {
+		info_label.setText(stringToHTML(Server.dictionary.get("ServerControl.Help_EnterLibrary")));
+		enter_button.setEnabled(true);
+		fMenu.setEnabled(true);
+                break;
+	    }
+	case Server.SERVER_START_FAILED:
+	    {
+		enter_button.setText(stringToHTML(Server.dictionary.get("ServerControl.StartServer")));
+		enter_button.setEnabled(true);
+		fMenu.setEnabled(true);
+		break;	
+	    }
+	case Server.BROWSER_LAUNCHED:
+	    {
+		info_label.setText(stringToHTML(Server.dictionary.get("ServerControl.Help_RestartLibrary")));
+		enter_button.setText(stringToHTML(Server.dictionary.get("ServerControl.RestartLibrary")));
+		thisframe.setState(Frame.ICONIFIED);
+		enter_button.setEnabled(true);
+                fMenu.setEnabled(true);
+		break;
+	    }
+	case Server.BROWSER_LAUNCH_FAILED:
+	    {
+		enter_button.setText(stringToHTML(Server.dictionary.get("ServerControl.EnterLibrary")));
+		enter_button.setEnabled(true);
+		fMenu.setEnabled(true);
+                 break;	
+	    }
+        default:{
+	    enter_button.setEnabled(false);
+	    fMenu.setEnabled(false);
+	}
+	}
+    }
+           
+   
+    public void displayMessage(String message){
+	info_label.setText(stringToHTML("<br>"+message));           
+    }
+    
+    private class MyAdapter extends WindowAdapter{   
+	public void windowClosing(WindowEvent env){
+            Thread runInThread = new Thread(new Runnable(){
+			    public void run(){
+				server.stop();
+				
+			    }
+		},"stop server");
+	    try{
+		runInThread.start(); 
+	    }
+	    catch(Exception e){
+		logger.error(e);
+	    }  
+	    thisframe.dispose();
+	}
+    } 
+
+    private String stringToHTML(String s){
+	return "<html><body>"+s+"</body></html>";	
+    }
+    
     private class EnterButtonListener
 	implements ActionListener {
-
+	
 	public void actionPerformed(ActionEvent ev) {
-	    boolean tomcat_was_running = tomcat_running;
-	    restartServer();
-	    launchBrowser();
-	    if (!tomcat_was_running) {
-		// reset the panel to restart
-		info_label.setText(Server.dictionary.get("ServerControl.Help_Restart"));
-		enter_button.setText(Server.dictionary.get("ServerControl.Restart"));
-	    }
+	    switch (server.getServerState()){
+	    case Server.SERVER_STARTED: case Server.BROWSER_LAUNCH_FAILED:
+		{
+		 Thread runInThread = new Thread(new Runnable(){
+			    public void run(){
+			    server.launchBrowser();
+			    }
+			},"launch browser");
+		    
+		    runInThread.start(); 
+                   break;     
+		}
+	    case Server.SERVER_START_FAILED:
+		{
+		    Thread runInThread = new Thread(new Runnable(){
+			    public void run(){
+				server.start();
+			    }
+			},"start server");
+		    runInThread.start();
+		    break;
+		}  	
+	    case Server.BROWSER_LAUNCHED:
+		{
+		    Thread runInThread = new Thread(new Runnable(){
+			    public void run(){
+				server.restart();
+				  
+			    }
+			},"restart server");
+		    runInThread.start();
+		}  
+	    }   
+	  
 	}
     }
