use of org.apache.pivot.xml.TextNode in project pivot by apache.
the class XMLViewer method updateProperties.
public void updateProperties() {
Node node = (Node) treeView.getSelectedNode();
if (node == null) {
// no selection, but it's ok
} else if (node instanceof TextNode) {
TextNode textNode = (TextNode) node;
textArea.setText(textNode.getText());
propertiesCardPane.setSelectedIndex(1);
} else if (node instanceof Element) {
Element element = (Element) node;
// Populate the namespaces table
ArrayList<HashMap<String, String>> namespacesTableData = new ArrayList<>();
String defaultNamespaceURI = element.getDefaultNamespaceURI();
if (defaultNamespaceURI != null) {
HashMap<String, String> row = new HashMap<>();
row.put("prefix", "(default)");
row.put("uri", defaultNamespaceURI);
namespacesTableData.add(row);
}
Element.NamespaceDictionary namespaceDictionary = element.getNamespaces();
for (String prefix : namespaceDictionary) {
HashMap<String, String> row = new HashMap<>();
row.put("prefix", prefix);
row.put("uri", namespaceDictionary.get(prefix));
namespacesTableData.add(row);
}
namespacesTableView.setTableData(namespacesTableData);
// Populate the attributes table
ArrayList<HashMap<String, String>> attributesTableData = new ArrayList<>();
for (Element.Attribute attribute : element.getAttributes()) {
HashMap<String, String> row = new HashMap<>();
String attributeName = attribute.getName();
row.put("name", attributeName);
row.put("value", element.getElementDictionary().get(attributeName));
attributesTableData.add(row);
}
attributesTableView.setTableData(attributesTableData);
propertiesCardPane.setSelectedIndex(0);
} else {
throw new IllegalStateException();
}
}
use of org.apache.pivot.xml.TextNode in project pivot by apache.
the class XMLSerializerTest method equalsTest.
@Test
public void equalsTest() throws IOException, SerializationException {
XMLSerializer xmlSerializer = new XMLSerializer();
XMLSerializerListener xmlSerializerListener = new XMLSerializerListener() {
@Override
public void beginElement(XMLSerializer xmlSerializerArgument, Element element) {
System.out.println("Begin element: " + element);
}
@Override
public void endElement(XMLSerializer xmlSerializerArgument) {
System.out.println("End element");
}
@Override
public void readTextNode(XMLSerializer xmlSerializerArgument, TextNode textNode) {
System.out.println("Read text node: " + textNode);
}
};
xmlSerializer.getXMLSerializerListeners().add(xmlSerializerListener);
Element root1 = xmlSerializer.readObject(getClass().getResourceAsStream("sample.xml"));
assertNotNull(root1);
xmlSerializer.getXMLSerializerListeners().remove(xmlSerializerListener);
Element root2 = xmlSerializer.readObject(getClass().getResourceAsStream("sample.xml"));
assertNotNull(root2);
}
use of org.apache.pivot.xml.TextNode in project pivot by apache.
the class RSSItemRenderer method render.
@Override
public void render(Object item, int index, ListView listView, boolean selected, Button.State state, boolean highlighted, boolean disabled) {
if (item != null) {
Element itemElement = (Element) item;
String title = XML.getText(itemElement, "title");
titleLabel.setText(title);
String categories = "Categories:";
List<Element> categoryElements = itemElement.getElements("category");
for (int i = 0, n = categoryElements.getLength(); i < n; i++) {
Element categoryElement = categoryElements.get(i);
TextNode categoryTextNode = (TextNode) categoryElement.get(0);
String category = categoryTextNode.getText();
if (i > 0) {
categories += ", ";
}
categories += category;
}
categoriesLabel.setText(categories);
String submitter = XML.getText(itemElement, "dz:submitter/dz:username");
submitterLabel.setText("Submitter: " + submitter);
}
Font font = listView.getStyles().getFont(Style.font);
Font largeFont = font.deriveFont(Font.BOLD, 14);
titleLabel.getStyles().put(Style.font, largeFont);
categoriesLabel.getStyles().put(Style.font, font);
submitterLabel.getStyles().put(Style.font, font);
Color color;
if (listView.isEnabled() && !disabled) {
if (selected) {
if (listView.isFocused()) {
color = listView.getStyles().getColor(Style.selectionColor);
} else {
color = listView.getStyles().getColor(Style.inactiveSelectionColor);
}
} else {
color = listView.getStyles().getColor(Style.color);
}
} else {
color = listView.getStyles().getColor(Style.disabledColor);
}
titleLabel.getStyles().put(Style.color, color);
categoriesLabel.getStyles().put(Style.color, color);
submitterLabel.getStyles().put(Style.color, color);
}
use of org.apache.pivot.xml.TextNode in project pivot by apache.
the class NodeRenderer method toString.
@Override
public String toString(Object node) {
String string;
if (node instanceof Element) {
Element element = (Element) node;
string = element.getName();
} else if (node instanceof TextNode) {
TextNode textNode = (TextNode) node;
string = textNode.getText();
} else {
throw new IllegalArgumentException("Unknown node type: " + node.getClass().getName());
}
return string;
}
use of org.apache.pivot.xml.TextNode in project pivot by apache.
the class NodeRenderer method render.
@Override
public void render(Object node, Sequence.Tree.Path path, int rowIndex, TreeView treeView, boolean expanded, boolean selected, TreeView.NodeCheckState checkState, boolean highlighted, boolean disabled) {
if (node != null) {
String text;
if (node instanceof Element) {
Element element = (Element) node;
text = "<" + element.getName() + ">";
} else if (node instanceof TextNode) {
TextNode textNode = (TextNode) node;
text = textNode.getText();
if (text.length() > MAXIMUM_TEXT_LENGTH) {
text = "\"" + text.substring(0, MAXIMUM_TEXT_LENGTH) + "\"...";
} else {
text = "\"" + text + "\"";
}
} else {
throw new IllegalArgumentException("Unknown node type: " + node.getClass().getName());
}
setText(text);
Font font = treeView.getStyles().getFont(Style.font);
getStyles().put(Style.font, font);
Color color;
if (treeView.isEnabled() && !disabled) {
if (selected) {
if (treeView.isFocused()) {
color = treeView.getStyles().getColor(Style.selectionColor);
} else {
color = treeView.getStyles().getColor(Style.inactiveSelectionColor);
}
} else {
color = treeView.getStyles().getColor(Style.color);
}
} else {
color = treeView.getStyles().getColor(Style.disabledColor);
}
getStyles().put(Style.color, color);
}
}
Aggregations