Search in sources :

Example 6 with ArrayList

use of org.apache.pivot.collections.ArrayList in project pivot by apache.

the class CSVSerializerTest method testQuotedQuoteWriteObject.

@SuppressWarnings("unchecked")
// or it will generate a warning during build with Java 7
@Test
public void testQuotedQuoteWriteObject() throws IOException {
    List<Object> items = new ArrayList<>();
    items.add(new HashMap<>(new Dictionary.Pair<String, Object>("A", "a"), new Dictionary.Pair<String, Object>("B", "\"b\""), new Dictionary.Pair<String, Object>("C", "c")));
    StringWriter writer = new StringWriter();
    CSVSerializer serializer = new CSVSerializer();
    serializer.setKeys("A", "B", "C");
    serializer.writeObject(items, writer);
    assertEquals("a,\"\"\"b\"\"\",c\r\n", writer.toString());
}
Also used : StringWriter(java.io.StringWriter) ArrayList(org.apache.pivot.collections.ArrayList) CSVSerializer(org.apache.pivot.serialization.CSVSerializer) Test(org.junit.Test)

Example 7 with ArrayList

use of org.apache.pivot.collections.ArrayList in project pivot by apache.

the class CSVSerializerTest method testQuotedCommaWriteObject.

@SuppressWarnings("unchecked")
// or it will generate a warning during build with Java 7
@Test
public void testQuotedCommaWriteObject() throws IOException {
    List<Object> items = new ArrayList<>();
    items.add(new HashMap<>(new Dictionary.Pair<String, Object>("A", "a"), new Dictionary.Pair<String, Object>("B", ",b,"), new Dictionary.Pair<String, Object>("C", "c")));
    StringWriter writer = new StringWriter();
    CSVSerializer serializer = new CSVSerializer();
    serializer.setKeys("A", "B", "C");
    serializer.writeObject(items, writer);
    assertEquals("a,\",b,\",c\r\n", writer.toString());
}
Also used : StringWriter(java.io.StringWriter) ArrayList(org.apache.pivot.collections.ArrayList) CSVSerializer(org.apache.pivot.serialization.CSVSerializer) Test(org.junit.Test)

Example 8 with ArrayList

use of org.apache.pivot.collections.ArrayList in project pivot by apache.

the class TextPaneDemo method applyStyle.

private void applyStyle(Document document, Span selectionSpan, StyleApplicator styleApplicator) {
    // I can't apply the styles while iterating over the tree, because I
    // need to update the tree.
    // So first collect a list of all the nodes in the tree.
    List<Node> nodeList = new ArrayList<>();
    collectNodes(document, nodeList);
    final int selectionStart = textPane.getSelectionStart();
    final int selectionLength = textPane.getSelectionLength();
    for (Node node : nodeList) {
        if (node instanceof TextSpan) {
            TextSpan span = (TextSpan) node;
            int documentOffset = node.getDocumentOffset();
            int characterCount = node.getCharacterCount();
            Span textSpan = new Span(documentOffset, documentOffset + characterCount - 1);
            if (selectionSpan.intersects(textSpan)) {
                applyStyleToSpanNode(selectionSpan, styleApplicator, span, characterCount, textSpan);
            }
        }
        if (node instanceof org.apache.pivot.wtk.text.TextNode) {
            org.apache.pivot.wtk.text.TextNode textNode = (org.apache.pivot.wtk.text.TextNode) node;
            int documentOffset = node.getDocumentOffset();
            int characterCount = node.getCharacterCount();
            Span textSpan = new Span(documentOffset, documentOffset + characterCount - 1);
            if (selectionSpan.intersects(textSpan)) {
                applyStyleToTextNode(selectionSpan, styleApplicator, textNode, characterCount, textSpan);
            }
        }
    }
    // maintain the selected range
    textPane.setSelection(selectionStart, selectionLength);
}
Also used : TextNode(org.apache.pivot.wtk.text.TextNode) Node(org.apache.pivot.wtk.text.Node) TextNode(org.apache.pivot.wtk.text.TextNode) ArrayList(org.apache.pivot.collections.ArrayList) TextNode(org.apache.pivot.wtk.text.TextNode) Span(org.apache.pivot.wtk.Span) TextSpan(org.apache.pivot.wtk.text.TextSpan) TextSpan(org.apache.pivot.wtk.text.TextSpan) DesktopApplicationContext(org.apache.pivot.wtk.DesktopApplicationContext) ApplicationContext(org.apache.pivot.wtk.ApplicationContext)

Example 9 with ArrayList

use of org.apache.pivot.collections.ArrayList 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();
    }
}
Also used : HashMap(org.apache.pivot.collections.HashMap) Node(org.apache.pivot.xml.Node) TextNode(org.apache.pivot.xml.TextNode) Element(org.apache.pivot.xml.Element) ArrayList(org.apache.pivot.collections.ArrayList) TextNode(org.apache.pivot.xml.TextNode)

Example 10 with ArrayList

use of org.apache.pivot.collections.ArrayList in project pivot by apache.

the class VoteResultTest method test1.

@Test
public void test1() {
    ArrayList<Vote> votes = new ArrayList<>();
    votes.add(Vote.APPROVE);
    votes.add(Vote.DEFER);
    votes.add(Vote.DENY);
    // These are the expected results as each vote is tallied
    ArrayList<Vote> results = new ArrayList<>();
    results.add(Vote.APPROVE);
    results.add(Vote.DEFER);
    results.add(Vote.DENY);
    VoteResult result = new VoteResult();
    Iterator<Vote> resultIter = results.iterator();
    for (Vote vote : votes) {
        result.tally(vote);
        assertEquals(result.get(), resultIter.next());
    }
}
Also used : Vote(org.apache.pivot.util.Vote) ArrayList(org.apache.pivot.collections.ArrayList) VoteResult(org.apache.pivot.util.VoteResult) Test(org.junit.Test)

Aggregations

ArrayList (org.apache.pivot.collections.ArrayList)41 List (org.apache.pivot.collections.List)9 Span (org.apache.pivot.wtk.Span)8 Test (org.junit.Test)6 IOException (java.io.IOException)5 ListView (org.apache.pivot.wtk.ListView)5 Point (org.apache.pivot.wtk.Point)5 TableView (org.apache.pivot.wtk.TableView)5 StringWriter (java.io.StringWriter)4 HashMap (org.apache.pivot.collections.HashMap)4 CSVSerializer (org.apache.pivot.serialization.CSVSerializer)4 SerializationException (org.apache.pivot.serialization.SerializationException)4 Vote (org.apache.pivot.util.Vote)4 Component (org.apache.pivot.wtk.Component)4 Form (org.apache.pivot.wtk.Form)4 File (java.io.File)3 FileObject (org.apache.commons.vfs2.FileObject)3 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)3 Bounds (org.apache.pivot.wtk.Bounds)3 ListButton (org.apache.pivot.wtk.ListButton)3