view src/MPipeline2/src/mpipeline/ltpdapreferences/MiscPrefGroup.java @ 52:daf4eab1a51e database-connection-manager tip

Fix. Default password should be [] not an empty string
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 07 Dec 2011 17:29:47 +0100
parents f0afece42f48
children
line wrap: on
line source

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mpipeline.ltpdapreferences;

import java.util.ArrayList;
import java.util.Iterator;
import mpipeline.utils.MXMLUtils;
import mpipeline.utils.Utils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 *
 * @author hewitson
 */
public class MiscPrefGroup extends LTPDAPrefGroup {

  public static final int MISC_UNITS_CHANGED = 1;
  public static final int MISC_DEFAULT_WINDOW_CHANGED = 2;

  private ArrayList<String> units = new ArrayList<String>();
  private String defaultWindow = "hanning";
  
  public MiscPrefGroup() {
  }

  public MiscPrefGroup(Node node, float version) {

    NamedNodeMap nmap = node.getAttributes();
    defaultWindow = MXMLUtils.getStringFromNode("defaultWindow", nmap, version, version);

    NodeList nl = node.getChildNodes();
    for (int ii = 0; ii < nl.getLength(); ii++) {
      Node n = nl.item(ii);
      Utils.dmsg(" reading child node: " + n.getNodeName());
      if (n.getNodeName().equals("Unit")) {
        NamedNodeMap wbnm = n.getAttributes();
        String path = MXMLUtils.getStringFromNode("name", wbnm, version, version);
        this.addUnit(path);
      }
    }
  }

  public void attachToDom(Document doc, Element tnode) {

    Element pnode = doc.createElement("Misc");

    pnode.setAttribute("defaultWindow", defaultWindow);

    Iterator it = units.iterator();
    while (it.hasNext()) {
      String path = (String) it.next();
      Element snode = doc.createElement("Unit");
      snode.setAttribute("name", path);
      pnode.appendChild(snode);
    }

    tnode.appendChild(pnode);

  }

  public void addUnit(String unit) {
    units.add(unit);
    this.setChanged();
    this.notifyObservers(MISC_UNITS_CHANGED);
  }

  public ArrayList<String> getUnits() {
    return units;
  }

  public String getDefaultWindow() {
    return defaultWindow;
  }

  public void setDefaultWindow(String window) {
    this.defaultWindow = window;
    setChanged();
    notifyObservers(MISC_DEFAULT_WINDOW_CHANGED);
  }

  public void setUnits(ArrayList<String> units) {
    this.units = units;
    setChanged();
    notifyObservers(MISC_UNITS_CHANGED);
  }

  public void display() {
    System.out.println("Default window: " + defaultWindow);
    System.out.println("Units: " + units);
  }

  public void removeUnitAtIndex(int idx) {
    this.units.remove(idx);
    this.setChanged();
    this.notifyObservers(MISC_UNITS_CHANGED);
  }
}