Changeset 18710

Show
Ignore:
Timestamp:
18.03.2009 19:03:27 (10 years ago)
Author:
ak19
Message:

Moved some things from BaseServerSettings? to the specific subclasses as appropriate, and added definitions for overloadable methods.

Location:
greenstone3/trunk/src/java/org/greenstone/server
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • greenstone3/trunk/src/java/org/greenstone/server/BaseServerSettings.java

    r18696 r18710  
    1313 
    1414public abstract class BaseServerSettings extends JDialog 
    15  
    1615{ 
    17  
    1816    static Logger logger = Logger.getLogger(BaseServerSettings.class.getName()); 
    1917    static final int DEFPORT = 8080; 
    2018 
    2119    JCheckBox autoEnter; 
    22     JComboBox servlet_combobox; 
    2320 
    2421    protected JSpinner portNumber_spinner = null; 
     
    3431    protected int portNum = DEFPORT; 
    3532    protected boolean autoStart = false; 
    36     protected String servletDefault = null; 
    3733    protected String browserPath = ""; 
    3834    protected boolean useDefaultBrowser = true; 
    3935 
    40     protected HashMap url_mappings = null; 
    4136    protected JDialog self; 
    4237    protected BaseServer server; 
     
    4439    public BaseServerSettings(BaseServer server)  
    4540    { 
    46     super((Frame)null, "", true); 
     41    super(server.getServerControl(), "", true); 
    4742    this.self = this; 
    4843        this.server = server; 
     
    8277 
    8378    portNumber_spinner = new JSpinner(new SpinnerNumberModel(portNum,1,65535,1)); 
    84     portNumber_spinner.setEditor(new JSpinner.NumberEditor(portNumber_spinner, "#####"));  
     79    portNumber_spinner.setEditor(new JSpinner.NumberEditor(portNumber_spinner, "#####")); 
    8580 
    8681    autoEnter = new JCheckBox(server.dictionary.get("ServerSettings.Auto_Start")); 
     
    186181 
    187182 
     183    protected String onSave() { return ""; } 
     184    protected void save(ScriptReadWrite scriptReadWrite, ArrayList newFileLines) {} 
    188185    protected abstract JPanel createServletPanel(); 
    189186 
     
    238235                has_changed = true; 
    239236        } 
    240         if(servletDefault != null && servlet_combobox != null) { 
    241         if (!servletDefault.equals(servlet_combobox.getSelectedItem())) { 
    242             has_changed = true; 
    243             require_restart = true;  
    244         } 
    245         } 
     237 
     238        // call subclass' onSave method 
     239        String result = onSave(); 
     240        if(result.indexOf("changed") != -1) { 
     241        has_changed = true; 
     242        } 
     243        if(result.indexOf("restart") != -1) { 
     244        require_restart = true; 
     245        } 
     246 
    246247            //changed to use other browser 
    247248            if (useDefaultBrowser && other_browser_button.isSelected()){ 
     
    274275        newFileLines = scriptReadWrite.queryReplace(newFileLines, BaseServer.Property.AUTOSTART, newAutoEnter); 
    275276         
    276         String newServletDef = (String) servlet_combobox.getSelectedItem(); 
    277         newFileLines = scriptReadWrite.queryReplace(newFileLines,BaseServer.Property.DEFAULT_SERVLET, (String) url_mappings.get(newServletDef)); 
    278  
     277        // call the subclass' save() method to save custom elements 
     278        save(scriptReadWrite, newFileLines); 
     279         
    279280        String osName = System.getProperty("os.name"); 
    280281                if (osName.startsWith("Windows")){ 
  • greenstone3/trunk/src/java/org/greenstone/server/Server2Settings.java

    r18693 r18710  
    11package org.greenstone.server; 
    22 
     3import java.awt.BorderLayout; 
     4import java.awt.event.*; 
    35import javax.swing.*; 
    4 import java.awt.BorderLayout; 
     6import javax.swing.event.*; 
    57 
    68import org.greenstone.server.BaseServerSettings; 
    79 
    8 public class Server2Settings extends BaseServerSettings 
     10public class Server2Settings extends BaseServerSettings implements ChangeListener, ActionListener 
    911{ 
     12    protected JComboBox prefix_combobox; 
     13 
    1014    public Server2Settings(BaseServer server)  
    1115    { 
     
    1519    protected JPanel createServletPanel() 
    1620    { 
     21    portNumber_spinner.addChangeListener(this); 
     22 
    1723    JLabel prefix_label = new JLabel(server.dictionary.get(BaseServer.Property.SERVER_SETTINGS+".URL")); 
    1824 
    19     JComboBox prefix_combobox = new JComboBox(); 
     25    prefix_combobox = new JComboBox(); 
    2026    prefix_combobox.setEditable(true); 
    2127    prefix_combobox.addItem(server.getBrowserURL()); 
     28    prefix_combobox.addActionListener(this); 
    2229 
    2330    JPanel comb_panel = new JPanel(); 
     
    2734    return comb_panel; 
    2835    } 
    29      
     36 
     37    public String onSave()  
     38    { 
     39    return ""; 
     40    } 
     41 
     42    public void stateChanged(ChangeEvent e) { 
     43    int portNumber = ((Integer)portNumber_spinner.getValue()).intValue(); 
     44    String url = (String)prefix_combobox.getSelectedItem(); 
     45 
     46    String pre = ""; 
     47    if(url.indexOf("http://") != -1) { 
     48        pre = "http://"; 
     49        url = url.substring(7); 
     50    } 
     51 
     52    String[] parts = url.split("/"); 
     53    String prefix = parts[0]; 
     54 
     55    int colon = prefix.indexOf(':'); 
     56    if(colon != -1) { 
     57        prefix = prefix.substring(0, colon); 
     58    }  
     59     
     60    url = pre + prefix + ":" + portNumber; 
     61    for(int i = 1; i < parts.length; i++) { 
     62        url = url + "/" + parts[i]; 
     63    } 
     64 
     65    prefix_combobox.setSelectedItem(url);    
     66    } 
     67 
     68    public void actionPerformed(ActionEvent e) { 
     69        System.err.println("*** Port number changed in url box!"); 
     70    String url = (String)prefix_combobox.getSelectedItem(); 
     71    int portNumber = 80; 
     72 
     73    String oldUrl = url; 
     74    if(url.indexOf("http://") != -1) { 
     75        url = url.substring(7); 
     76    } 
     77    int colon = url.indexOf(':'); 
     78    int slash = url.indexOf('/'); 
     79    if(slash == -1) { 
     80        slash = url.length(); 
     81    } 
     82    if(colon != -1) { 
     83        url = url.substring(colon+1, slash); 
     84        try {  
     85        portNumber_spinner.setValue(Integer.decode(url)); 
     86        } catch(NumberFormatException nfe) { // couldn't parse port number 
     87        // not an integer, leave portnumber at 80 
     88        String oldNum = Integer.toString((Integer)portNumber_spinner.getValue()); 
     89        oldUrl = oldUrl.replace(oldNum, "80"); 
     90        portNumber_spinner.setValue(80); 
     91        } 
     92    } else { // no port number 
     93        oldUrl = oldUrl.replace(url, url+":80"); 
     94        portNumber_spinner.setValue(80); 
     95    } 
     96    } 
     97 
    3098}