	@Override
	public void loadXml(String filepath) throws Exception {
		File f = new File(filepath);
		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
		DocumentBuilder db = null;
		Document doc = null;
		try {
			db = dbf.newDocumentBuilder();
		} catch (ParserConfigurationException e) {
			e.printStackTrace();
		}
		try {
			doc = db.parse(f);
		} catch (SAXException | IOException | NullPointerException e) {
			e.printStackTrace();
		}
		Element root = doc.getDocumentElement();

		Node firstChild = root.getFirstChild();
		String tag = firstChild.getNodeName();
		//here is the problem. I can't cast from Node to Element and Node
		//stores only an int value, not the name of the object I want to restore
		
		ShapeDrawer drawable = null;
		switch (tag) {
		case "scribble":
			drawable = new ScribbleDrawer();
	}
	
	
	
	//from the class to resore:
		@Override
	public void setValues(Element root) {
		NodeList nodelist = null;

		nodelist = root.getElementsByTagName("color");
		colorManager.setColor((nodelist.item(0).getTextContent()));
		this.color = colorManager.getCurrentColor();
		System.out.println(color.toString());
		
		nodelist = root.getElementsByTagName("pressx");
		pressx = Integer.parseInt(nodelist.item(0).getTextContent());
		System.out.println(pressx);

		nodelist = root.getElementsByTagName("pressy");
		pressy = Integer.parseInt(nodelist.item(0).getTextContent());
		System.out.println(pressy);
		
		nodelist = root.getElementsByTagName("lastx");
		lastx = Integer.parseInt(nodelist.item(0).getTextContent());

		nodelist = root.getElementsByTagName("lasty");
		lasty = Integer.parseInt(nodelist.item(0).getTextContent());
	}

	public void toDOM(Document doc, Element root) {
		System.out.println("ScribbleDrawer being saved");
		Element shapeBranch = doc.createElement("scribble");
		Attr attr1 = doc.createAttribute("hashcode");
		attr1.setValue(((Integer) this.hashCode()).toString());
		shapeBranch.setAttributeNode(attr1);
		root.appendChild(shapeBranch);
		Element eColor = doc.createElement("color");
		eColor.setTextContent(colorManager.namedColorToString(color));
		shapeBranch.appendChild(eColor);

		// creating tree branch
		Element press = doc.createElement("press");

		Attr attr2 = doc.createAttribute("pressx");
		attr2.setValue(((Integer) pressy).toString());
		press.setAttributeNode(attr2);

		Attr attr3 = doc.createAttribute("pressy");
		attr3.setValue(((Integer) pressy).toString());
		press.setAttributeNode(attr3);

		shapeBranch.appendChild(press);

		Element last = doc.createElement("last");

		Attr attr4 = doc.createAttribute("lastx");
		attr4.setValue(((Integer) lastx).toString());
		last.setAttributeNode(attr4);

		Attr attr5 = doc.createAttribute("lasty");
		attr5.setValue(((Integer) lasty).toString());
		last.setAttributeNode(attr5);

		shapeBranch.appendChild(last);
	}
}


