You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2009/04/22 21:38:43 UTC
svn commit: r767632 - in /incubator/pivot/trunk/demos/src/pivot/demos/rss:
NodeListAdapter.java RSSFeedDemo.java rss_feed_demo.wtkx
Author: gbrown
Date: Wed Apr 22 19:38:43 2009
New Revision: 767632
URL: http://svn.apache.org/viewvc?rev=767632&view=rev
Log:
Update RSS feed demo.
Modified:
incubator/pivot/trunk/demos/src/pivot/demos/rss/NodeListAdapter.java
incubator/pivot/trunk/demos/src/pivot/demos/rss/RSSFeedDemo.java
incubator/pivot/trunk/demos/src/pivot/demos/rss/rss_feed_demo.wtkx
Modified: incubator/pivot/trunk/demos/src/pivot/demos/rss/NodeListAdapter.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/demos/src/pivot/demos/rss/NodeListAdapter.java?rev=767632&r1=767631&r2=767632&view=diff
==============================================================================
--- incubator/pivot/trunk/demos/src/pivot/demos/rss/NodeListAdapter.java (original)
+++ incubator/pivot/trunk/demos/src/pivot/demos/rss/NodeListAdapter.java Wed Apr 22 19:38:43 2009
@@ -1,9 +1,10 @@
/*
- * Copyright (c) 2009 VMware, Inc.
- *
- * 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
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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
*
Modified: incubator/pivot/trunk/demos/src/pivot/demos/rss/RSSFeedDemo.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/demos/src/pivot/demos/rss/RSSFeedDemo.java?rev=767632&r1=767631&r2=767632&view=diff
==============================================================================
--- incubator/pivot/trunk/demos/src/pivot/demos/rss/RSSFeedDemo.java (original)
+++ incubator/pivot/trunk/demos/src/pivot/demos/rss/RSSFeedDemo.java Wed Apr 22 19:38:43 2009
@@ -33,8 +33,13 @@
import org.xml.sax.InputSource;
import pivot.collections.Dictionary;
+import pivot.io.IOTask;
+import pivot.util.concurrent.Task;
+import pivot.util.concurrent.TaskExecutionException;
+import pivot.util.concurrent.TaskListener;
import pivot.wtk.Application;
import pivot.wtk.BrowserApplicationContext;
+import pivot.wtk.CardPane;
import pivot.wtk.Component;
import pivot.wtk.ComponentMouseButtonListener;
import pivot.wtk.Display;
@@ -53,11 +58,24 @@
* @author gbrown
*/
public class RSSFeedDemo implements Application {
- /**
- * Prepares an RSS feed news item for presentation in a list view.
- *
- * @author gbrown
- */
+ // Loads the feed in the background so the UI doesn't block
+ private class LoadFeedTask extends IOTask<NodeList> {
+ public NodeList execute() throws TaskExecutionException {
+ NodeList itemNodeList = null;
+
+ try {
+ InputSource inputSource = new InputSource(FEED_URI);
+ itemNodeList = (NodeList)xpath.evaluate("/rss/channel/item",
+ inputSource, XPathConstants.NODESET);
+ } catch(XPathExpressionException exception) {
+ // No-op
+ }
+
+ return itemNodeList;
+ }
+ }
+
+ // Prepares an RSS feed news item for presentation in a list view
private class RSSItemRenderer extends FlowPane implements ListView.ItemRenderer {
private Label titleLabel = new Label();
private Label categoriesHeadingLabel = new Label("subject:");
@@ -159,14 +177,41 @@
}
}
- private Window window = null;
- private ListView feedListView = null;
+ // Handles double-clicks on the list view
+ private class FeedViewMouseButtonHandler extends ComponentMouseButtonListener.Adapter {
+ private int index = -1;
+
+ @Override
+ public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
+ if (count == 1) {
+ index = feedListView.getItemAt(y);
+ } else if (count == 2
+ && feedListView.getItemAt(y) == index) {
+ Element itemElement = (Element)feedListView.getListData().get(index);
+
+ try {
+ String link = (String)xpath.evaluate("link", itemElement, XPathConstants.STRING);
+ BrowserApplicationContext.open(new URL(link));
+ } catch(XPathExpressionException exception) {
+ System.err.print(exception);
+ } catch(MalformedURLException exception) {
+ System.err.print(exception);
+ }
+ }
+
+ return false;
+ }
+ };
private XPath xpath = XPathFactory.newInstance().newXPath();
+ private Window window = null;
+ private ListView feedListView = null;
+
public static final String FEED_URI = "http://feeds.dzone.com/javalobby/frontpage?format=xml";
public RSSFeedDemo() {
+ // Set the namespace resolver
xpath.setNamespaceContext(new NamespaceContext() {
public String getNamespaceURI(String prefix) {
String namespaceURI;
@@ -196,33 +241,22 @@
feedListView = (ListView)wtkxSerializer.getObjectByName("feedListView");
feedListView.setItemRenderer(new RSSItemRenderer());
+ feedListView.getComponentMouseButtonListeners().add(new FeedViewMouseButtonHandler());
- feedListView.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener.Adapter() {
- @Override
- public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
- if (count == 2) {
- Element itemElement = (Element)feedListView.getListData().get(feedListView.getItemAt(y));
-
- try {
- String link = (String)xpath.evaluate("link", itemElement, XPathConstants.STRING);
- BrowserApplicationContext.open(new URL(link));
- } catch(XPathExpressionException exception) {
- System.err.print(exception);
- } catch(MalformedURLException exception) {
- System.err.print(exception);
- }
- }
+ final CardPane cardPane = (CardPane)wtkxSerializer.getObjectByName("cardPane");
+ final Label statusLabel = (Label)wtkxSerializer.getObjectByName("statusLabel");
- return false;
+ LoadFeedTask loadFeedTask = new LoadFeedTask();
+ loadFeedTask.execute(new TaskListener<NodeList>() {
+ public void taskExecuted(Task<NodeList> task) {
+ feedListView.setListData(new NodeListAdapter(task.getResult()));
+ cardPane.setSelectedIndex(1);
}
- });
- // TODO Load this in a task; it is not always fast
- InputSource inputSource = new InputSource(FEED_URI);
-
- NodeList itemNodeList = (NodeList)xpath.evaluate("/rss/channel/item",
- inputSource, XPathConstants.NODESET);
- feedListView.setListData(new NodeListAdapter(itemNodeList));
+ public void executeFailed(Task<NodeList> task) {
+ statusLabel.setText(task.getFault().toString());
+ }
+ });
window.setMaximized(true);
window.open(display);
Modified: incubator/pivot/trunk/demos/src/pivot/demos/rss/rss_feed_demo.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/demos/src/pivot/demos/rss/rss_feed_demo.wtkx?rev=767632&r1=767631&r2=767632&view=diff
==============================================================================
--- incubator/pivot/trunk/demos/src/pivot/demos/rss/rss_feed_demo.wtkx (original)
+++ incubator/pivot/trunk/demos/src/pivot/demos/rss/rss_feed_demo.wtkx Wed Apr 22 19:38:43 2009
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
-Copyright (c) 2009 VMware, Inc.
-
-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
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you 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
@@ -21,10 +22,13 @@
xmlns:rss="pivot.demos.rss"
xmlns="pivot.wtk">
<content>
- <ScrollPane horizontalScrollBarPolicy="fill">
- <view>
- <ListView wtkx:id="feedListView"/>
- </view>
- </ScrollPane>
+ <CardPane wtkx:id="cardPane" selectedIndex="0">
+ <Label wtkx:id="statusLabel" text="Loading..." styles="{horizontalAlignment:'center', verticalAlignment:'center'}"/>
+ <ScrollPane horizontalScrollBarPolicy="fill">
+ <view>
+ <ListView wtkx:id="feedListView"/>
+ </view>
+ </ScrollPane>
+ </CardPane>
</content>
</Border>