Index: /gli/trunk/src/org/greenstone/gatherer/gui/FedoraLogin.java
===================================================================
--- /gli/trunk/src/org/greenstone/gatherer/gui/FedoraLogin.java	(revision 16336)
+++ /gli/trunk/src/org/greenstone/gatherer/gui/FedoraLogin.java	(revision 16337)
@@ -66,9 +66,13 @@
 
 import org.greenstone.gatherer.Gatherer;
+import org.greenstone.gatherer.Configuration;
 
 public class FedoraLogin extends JDialog 
 {
+    private static final int MAX_ITEMS = 5;
+
     private static final java.awt.Color LIGHT = new java.awt.Color(244, 244, 224);
     private static final java.awt.Color TRANSPARENT = new java.awt.Color(0,0,0,0);
+
     private JPanel m_infoPane;
     private JComboBox m_serverComboBox;
@@ -82,8 +86,4 @@
     private String m_lastPassword="";
 
-    private HashMap m_usernames;
-    private HashMap m_servers;
-    private HashMap m_protocols;
-
     private boolean login_requested = false;
 
@@ -93,20 +93,14 @@
 	this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
         
-        m_servers=new HashMap();
-        m_protocols=new HashMap();
-        m_protocols.put("http", "");
-        m_protocols.put("https", "");
-        m_usernames=new HashMap();
-
-        JLabel serverLabel=new JLabel("Fedora Server");
-		JLabel protocolLabel=new JLabel("Protocol");
+	JLabel serverLabel=new JLabel("Fedora Server");
+	JLabel protocolLabel=new JLabel("Protocol");
         JLabel usernameLabel=new JLabel("Username");
         JLabel passwordLabel=new JLabel("Password");
 
-        m_serverComboBox=new JComboBox();
+        m_serverComboBox=new JComboBox(new String[]{m_lastServer});
         m_serverComboBox.setEditable(true);
-		m_protocolComboBox=new JComboBox();
-		m_protocolComboBox.setEditable(true);
-        m_usernameComboBox=new JComboBox();
+	m_protocolComboBox=new JComboBox(new String[]{m_lastProtocol, "https"}); // http and https
+	m_protocolComboBox.setEditable(true);
+        m_usernameComboBox=new JComboBox(new String[]{m_lastUsername});
         m_usernameComboBox.setEditable(true);
         m_passwordField=new JPasswordField();
@@ -193,113 +187,67 @@
     }
 
-    // re-writes fedora-admin.properties with latest values for servers 
-    // and usernames
-
+
+    public void saveProperties(JComboBox control, String affectedProperty, String editedValue) {
+	//String editedValue = (String)control.getSelectedItem();
+	// Edited value is the value in the combobox editfield, it has not yet been added to the combobox
+	control.insertItemAt(editedValue, 0); 
+	
+	if(editedValue == null) {
+	    editedValue = (String)control.getItemAt(0); // else reuse the first default
+	} 
+	Configuration.setString(affectedProperty, true, editedValue);
+	
+	// Add the values in the combobox as well.
+	int value_count = 1;
+	for(int i = 0; value_count < MAX_ITEMS && i < control.getItemCount(); i++, value_count++) {
+	    String value = (String)control.getItemAt(i);
+	    if(value == null || value.equals(editedValue) || value.equals("")) { 
+		// skip duplicates of just-edited comboBox value and empty values
+		value_count--;
+	    } else { 
+		Configuration.setString(affectedProperty+value_count, true, value);
+	    } // else retain old value for this affectedProperty (e.g. general.gliserver_url)
+	}
+    }
+
+    private void setComboBoxValues() {
+        // All comboboxes are of the same size
+        Dimension newSize=new Dimension(m_serverComboBox.getPreferredSize().width+20, m_serverComboBox.getPreferredSize().height);
+	m_passwordField.setPreferredSize(newSize);
+      
+	setComboBoxValues(m_serverComboBox, "fedora.server", newSize);
+	setComboBoxValues(m_protocolComboBox, "fedora.protocol", newSize);
+	setComboBoxValues(m_usernameComboBox, "fedora.username", newSize);
+	newSize = null;
+    }
     
-    public void saveProperties() {
-        try {
-            Properties props=new Properties();
-            props.setProperty("lastServer", m_lastServer);
-			props.setProperty("lastProtocol", m_lastProtocol);
-            props.setProperty("lastUsername", m_lastUsername);
-            Iterator iter;
-            int i;
-            iter=m_servers.keySet().iterator();
-            i=0;
-            while (iter.hasNext()) {
-                String name=(String) iter.next();
-                props.setProperty("server" + i, name);
-                i++;
-            }
-			iter=m_protocols.keySet().iterator();
-			i=0;
-			while (iter.hasNext()) {
-				String name=(String) iter.next();
-				props.setProperty("protocol" + i, name);
-				i++;
-			}
-            iter=m_usernames.keySet().iterator();
-            i=0;
-            while (iter.hasNext()) {
-                String name=(String) iter.next();
-                props.setProperty("username" + i, name);
-                i++;
-            }
-            props.store(new FileOutputStream(new File(Gatherer.getGLIUserDirectoryPath(), "fedora-admin.properties")), "Fedora Administrator saved settings");
-        } catch (Exception e) {
-            System.err.println("Warning: Error writing properties: " 
-                    + e.getClass().getName() + ": " + e.getMessage());
-        }
-    }
-    
-
-    private void setComboBoxValues() {
-        // get values from prop file, or use localhost:8080/fedoraAdmin if none
-        try {
-            Properties props=new Properties();
-            props.load(new FileInputStream(new File(Gatherer.getGLIUserDirectoryPath(), "fedora-admin.properties")));
-            Enumeration names=props.propertyNames();
-            while (names.hasMoreElements()) {
-                String prop=(String) names.nextElement();
-                if (prop.equals("lastServer")) {
-                    m_lastServer=props.getProperty(prop);
-				} else if (prop.equals("lastProtocol")) {
-					m_lastProtocol=props.getProperty(prop);
-                } else if (prop.equals("lastUsername")) {
-                    m_lastUsername=props.getProperty(prop);
-                } else if (prop.startsWith("server")) {
-                    m_servers.put(props.getProperty(prop), "");
-				} else if (prop.startsWith("protocol")) {
-					m_protocols.put(props.getProperty(prop), "");
-                } else if (prop.startsWith("username")) {
-                    m_usernames.put(props.getProperty(prop), "");
-                }
-            }
-        } catch (Exception e) {
-            // no problem if props file doesn't exist...we have defaults
-        }
-        // finally, populate them
-        m_serverComboBox.addItem(m_lastServer);
-        Iterator sIter=m_servers.keySet().iterator();
-        while (sIter.hasNext()) {
-            String a=(String) sIter.next();
-            if (!a.equals(m_lastServer)) {
-                m_serverComboBox.addItem(a);
-            }
-        }
-        m_servers.put(m_lastServer, "");
-        
-		m_protocolComboBox.addItem(m_lastProtocol);
-		Iterator protocolIter=m_protocols.keySet().iterator();
-		while (protocolIter.hasNext()) {
-			String a=(String) protocolIter.next();
-			if (!a.equals(m_lastProtocol)) {
-				m_protocolComboBox.addItem(a);
-			}
-		}
-		m_protocols.put(m_lastProtocol, "");
-
-        m_usernameComboBox.addItem(m_lastUsername);
-        Iterator uIter=m_usernames.keySet().iterator();
-        while (uIter.hasNext()) {
-            String a=(String) uIter.next();
-            if (!a.equals(m_lastUsername)) {
-                m_usernameComboBox.addItem(a);
-            }
-        }
-        m_usernames.put(m_lastUsername, "");
-
-        // make all entry widgets same size
-        Dimension newSize=new Dimension(
-                m_serverComboBox.getPreferredSize().width+20,
-                m_serverComboBox.getPreferredSize().height);
-        m_serverComboBox.setPreferredSize(newSize);
-		m_protocolComboBox.setPreferredSize(newSize);
-        m_usernameComboBox.setPreferredSize(newSize);
-        m_passwordField.setPreferredSize(newSize);
+    private void setComboBoxValues(JComboBox control, String affectedProperty, Dimension newSize) {
+	// get values from Configuration file, if none, it will go back to using defaultvalues
+	// put them into the combobox
+	
+	String value = Configuration.getString(affectedProperty, true);
+	boolean finished = value.equals("");
+	if(!finished) {
+	    control.removeAllItems(); // remove defaults, since config file now contains init values
+	    control.addItem(value);
+	} // else value and combobox already contains the defaults
+	   	    
+	
+	for(int i = 1; !finished; i++) {
+	    value = Configuration.getString(affectedProperty+i, true);
+	    if(value.equals("")) {
+		finished = true;
+	    }
+	    else { // value is not empty
+		control.addItem(value);
+	    }
+	}
+	
+	// setting the size of the dropdown control
+	control.setPreferredSize(newSize);
     }
 
     public void addLabelValueRows(JLabel[] labels, JComponent[] values,
-            GridBagLayout gridBag, Container container) {
+				  GridBagLayout gridBag, Container container) {
         GridBagConstraints c=new GridBagConstraints();
         c.insets=new Insets(0, 6, 6, 6);
@@ -311,5 +259,5 @@
             gridBag.setConstraints(labels[i], c);
             container.add(labels[i]);
-
+	    
             c.gridwidth=GridBagConstraints.REMAINDER;     //end row
             if (!(values[i] instanceof JComboBox)) {
@@ -322,5 +270,5 @@
             container.add(values[i]);
         }
-
+	
     }
 
@@ -368,7 +316,7 @@
             dataChanged();
         }
-
+	
         public void dataChanged() {
-        	if (m_passField.getPassword().length == 0) { 
+	    if (m_passField.getPassword().length == 0) { 
                 m_loginButton.setEnabled(false);
             } else {
@@ -431,11 +379,15 @@
 
                     // all looks ok...just save stuff and exit now
-                    m_lastServer=host + ":" + port;
+		    m_lastServer=host + ":" + port;
                     m_lastProtocol=protocol;
                     m_lastUsername=username;
 		    m_lastPassword=pass;
 
-                    m_loginDialog.saveProperties();
-
+		    m_loginDialog.saveProperties(m_serverComboBox, "fedora.server", m_lastServer);
+		    m_loginDialog.saveProperties(m_protocolComboBox, "fedora.protocol", m_lastProtocol);
+		    m_loginDialog.saveProperties(m_usernameComboBox, "fedora.username", m_lastUsername);
+		   
+		    // now save these values to the Configuration file
+		    Configuration.save();                   
 
 		    login_requested = true;
@@ -450,5 +402,4 @@
 
 		    e.printStackTrace();
-		    
 
                 }
