/**
* Copyright 1999-2009 The Pegadi Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pegadi.storysketch.cells;
import java.util.ArrayList;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.pegadi.storysketch.XMLUtil;
public class ConflictCell extends StorySketchCell {
public ConflictCell() {
this(new Conflict());
}
public ConflictCell(Object userObject) {
super(userObject);
}
public String getClassDescription() {
return "Konflikter";
}
public String toHTML() {
Conflict c = (Conflict) userObject;
StringBuffer html = new StringBuffer();
html.append("<html><body>");
if(c.getTopic().length() > 0) {
html.append("<b>").append(c.getTopic()).append("</b><br>");
}
else {
html.append("<b>Konflikt</b><br><i>Tips: </i>Dobbeltklikk paa konflikten for aa legge til informasjon.<br>");
}
html.append("<table width=\"100%\">");
if(c.getViewpoints()[0].length() > 0 ||
c.getViewpoints()[0].length() > 0) {
html.append("<tr>");
html.append("<td valign=\"top\" width=\"50%\" bgcolor=\"#D0FFD9\">").append(c.getViewpoints()[0]).append("</td>");
html.append("<td valign=\"top\" width=\"50%\" bgcolor=\"#FFD8CF\">").append(c.getViewpoints()[1]).append("</td>");
html.append("</tr>");
}
html.append("</table></body></html>");
return html.toString();
}
public Element getCellElement(Document doc) {
Element element = doc.createElement("conflictcell");
Conflict c = (Conflict) userObject;
Element conflict = doc.createElement("conflict");
Element topic = doc.createElement("topic");
topic.appendChild(doc.createTextNode(c.getTopic()));
conflict.appendChild(topic);
String[] viewpoints = c.getViewpoints();
for (String viewpoint : viewpoints) {
conflict.appendChild(XMLUtil.createParagraphElement("viewpoint", viewpoint, doc));
}
element.appendChild(conflict);
return element;
}
public void setCellElement(Element e) {
Conflict c = new Conflict();
Element conflict = (Element)e.getElementsByTagName("conflict").item(0);
c.setTopic(XMLUtil.extractValue(conflict,"topic"));
NodeList nl = conflict.getElementsByTagName("viewpoint");
ArrayList viewpoints = new ArrayList();
for(int i = 0; i < nl.getLength(); i++) {
Element vp = (Element) nl.item(i);
viewpoints.add(XMLUtil.getStringFromParagraphElement(vp));
}
c.setViewpoints((String[]) viewpoints.toArray(new String[viewpoints.size()]));
userObject = c;
}
}