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/10/13 16:37:50 UTC

svn commit: r824789 - in /incubator/pivot/trunk: demos/www/ tutorials/src/org/apache/pivot/tutorials/filebrowsing/ tutorials/www/

Author: gbrown
Date: Tue Oct 13 14:37:50 2009
New Revision: 824789

URL: http://svn.apache.org/viewvc?rev=824789&view=rev
Log:
Add file browsing tutorial documentation; trim whitespace in url_utilities.jsp.

Added:
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/filebrowsing/FileBrowsing.java
      - copied, changed from r824713, incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/filebrowsing/FileBrowserSheets.java
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/filebrowsing/file_browsing.wtkx
      - copied unchanged from r824713, incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/filebrowsing/file_browser_sheets.wtkx
Removed:
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/filebrowsing/FileBrowserSheets.java
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/filebrowsing/FileBrowsers.java
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/filebrowsing/file_browser_sheets.wtkx
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/filebrowsing/file_browsers.wtkx
Modified:
    incubator/pivot/trunk/demos/www/url_utilities.jsp
    incubator/pivot/trunk/tutorials/www/file_browsing.html

Modified: incubator/pivot/trunk/demos/www/url_utilities.jsp
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/demos/www/url_utilities.jsp?rev=824789&r1=824788&r2=824789&view=diff
==============================================================================
--- incubator/pivot/trunk/demos/www/url_utilities.jsp (original)
+++ incubator/pivot/trunk/demos/www/url_utilities.jsp Tue Oct 13 14:37:50 2009
@@ -23,21 +23,21 @@
 
     String requestURL  = request.getRequestURL().toString();
     int    lastSlash   = requestURL.lastIndexOf('/');
-	String codebase    = "";
-	String href        = "";
-	if (requestURL != null)
-	{
-	    if (lastSlash < 0)
-	        lastSlash = 0;
+    String codebase    = "";
+    String href        = "";
+    if (requestURL != null)
+    {
+        if (lastSlash < 0)
+            lastSlash = 0;
 
-	    codebase = requestURL.substring(0, lastSlash + 1);
-	    if ((lastSlash + 1) < requestURL.length())
-	    	href = requestURL.substring(lastSlash + 1);
+        codebase = requestURL.substring(0, lastSlash + 1);
+        if ((lastSlash + 1) < requestURL.length())
+            href = requestURL.substring(lastSlash + 1);
 
-	}
+    }
 
     /*
-	String codebase = request.getScheme() + "://" 
+    String codebase = request.getScheme() + "://"
         + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();
     String href     = request.getServletPath();
      */

Copied: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/filebrowsing/FileBrowsing.java (from r824713, incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/filebrowsing/FileBrowserSheets.java)
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/filebrowsing/FileBrowsing.java?p2=incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/filebrowsing/FileBrowsing.java&p1=incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/filebrowsing/FileBrowserSheets.java&r1=824713&r2=824789&rev=824789&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/filebrowsing/FileBrowserSheets.java (original)
+++ incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/filebrowsing/FileBrowsing.java Tue Oct 13 14:37:50 2009
@@ -38,7 +38,7 @@
 import org.apache.pivot.wtkx.WTKX;
 import org.apache.pivot.wtkx.WTKXSerializer;
 
-public class FileBrowserSheets implements Application {
+public class FileBrowsing implements Application {
     private Window window = null;
 
     @WTKX private ButtonGroup fileBrowserSheetModeGroup = null;
@@ -49,8 +49,8 @@
         throws Exception {
         WTKXSerializer wtkxSerializer = new WTKXSerializer();
 
-        window = (Window)wtkxSerializer.readObject(getClass().getResource("file_browser_sheets.wtkx"));
-        wtkxSerializer.bind(this, FileBrowserSheets.class);
+        window = (Window)wtkxSerializer.readObject(getClass().getResource("file_browsing.wtkx"));
+        wtkxSerializer.bind(this, FileBrowsing.class);
 
         openSheetButton.getButtonPressListeners().add(new ButtonPressListener() {
             @Override
@@ -102,6 +102,6 @@
     }
 
     public static void main(String[] args) {
-        DesktopApplicationContext.main(FileBrowserSheets.class, args);
+        DesktopApplicationContext.main(FileBrowsing.class, args);
     }
 }

Modified: incubator/pivot/trunk/tutorials/www/file_browsing.html
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/www/file_browsing.html?rev=824789&r1=824788&r2=824789&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/www/file_browsing.html (original)
+++ incubator/pivot/trunk/tutorials/www/file_browsing.html Tue Oct 13 14:37:50 2009
@@ -33,7 +33,170 @@
 </head>
 <body>
 <h1>File Browsing</h1>
-<p>This section is not yet complete.</p>
+
+<p>Pivot includes support for easily adding local file system access to an application. The following example demonstrates the use of the <tt>FileBrowserSheet</tt> class:</p>
+
+<script src="version.js"></script>
+<script>
+var attributes = {code:"org.apache.pivot.wtk.BrowserApplicationContext$HostApplet",
+    archive:"lib/pivot-core-" + version + ".signed.jar"
+        + ",lib/pivot-wtk-" + version + ".signed.jar"
+        + ",lib/pivot-wtk-" + version + ".terra.signed.jar"
+        + ",lib/pivot-tutorials-" + version + ".signed.jar",
+    width:640,
+    height:480
+};
+var parameters = {application_class_name:"org.apache.pivot.tutorials.filebrowsing.FileBrowsing",
+    codebase_lookup:false,
+    java_arguments:"-Dsun.awt.noerasebackground=true -Dsun.awt.erasebackgroundonresize=true"
+};
+deployJava.writeAppletTag(attributes, parameters);
+</script>
+
+<p>It allows the user to browse the local file system using one of four supported modes:</p>
+
+<ul>
+<li><p><b>Open</b> - select a single file to open</p></li>
+<li><p><b>Open Multiple</b> - select multiple files to open</p></li>
+<li><p><b>Save As</b> - select a file name to save as</p></li>
+<li><p><b>Save To</b> - select a folder to save to</p></li>
+</ul>
+
+<p>The WTKX source for the application is as follows:</p>
+
+<pre class="brush:xml">
+&lt;Window title="File Browser Sheets" maximized="true"
+    xmlns:wtkx="http://pivot.apache.org/wtkx"
+    xmlns="org.apache.pivot.wtk"&gt;
+    &lt;wtkx:define&gt;
+        &lt;ButtonGroup wtkx:id="fileBrowserSheetModeGroup"/&gt;
+    &lt;/wtkx:define&gt;
+
+    &lt;content&gt;
+        &lt;Border styles="{padding:6}"&gt;
+            &lt;content&gt;
+                &lt;BoxPane orientation="vertical" styles="{spacing:6}"&gt;
+                    &lt;Label text="Mode:" styles="{font:{bold:true}}"/&gt;
+
+                    &lt;RadioButton buttonData="Open" buttonGroup="$fileBrowserSheetModeGroup" selected="true"&gt;
+                        &lt;userData mode="open"/&gt;
+                    &lt;/RadioButton&gt;
+                    &lt;RadioButton buttonData="Open Multiple" buttonGroup="$fileBrowserSheetModeGroup"&gt;
+                        &lt;userData mode="open_multiple"/&gt;
+                    &lt;/RadioButton&gt;
+                    &lt;RadioButton buttonData="Save As" buttonGroup="$fileBrowserSheetModeGroup"&gt;
+                        &lt;userData mode="save_as"/&gt;
+                    &lt;/RadioButton&gt;
+                    &lt;RadioButton buttonData="Save To" buttonGroup="$fileBrowserSheetModeGroup"&gt;
+                        &lt;userData mode="save_to"/&gt;
+                    &lt;/RadioButton&gt;
+
+                    &lt;PushButton wtkx:id="openSheetButton" buttonData="Open Sheet"/&gt;
+                &lt;/BoxPane&gt;
+            &lt;/content&gt;
+        &lt;/Border&gt;
+    &lt;/content&gt;
+&lt;/Window&gt;
+</pre>
+
+<p>The Java source code is shown below. When the user presses the "Open Sheet" button, it creates a <tt>FileBrowserSheet</tt> using the selected mode and opens the sheet. When the sheet is closed, it simply displays an alert to the user reflecting the selection:</p>
+
+<pre class="brush:java">
+package org.apache.pivot.tutorials.filebrowsing;
+
+import java.io.File;
+
+import org.apache.pivot.collections.ArrayList;
+import org.apache.pivot.collections.Map;
+import org.apache.pivot.collections.Sequence;
+import org.apache.pivot.wtk.Alert;
+import org.apache.pivot.wtk.Application;
+import org.apache.pivot.wtk.Button;
+import org.apache.pivot.wtk.ButtonGroup;
+import org.apache.pivot.wtk.ButtonPressListener;
+import org.apache.pivot.wtk.DesktopApplicationContext;
+import org.apache.pivot.wtk.Display;
+import org.apache.pivot.wtk.FileBrowserSheet;
+import org.apache.pivot.wtk.ListView;
+import org.apache.pivot.wtk.MessageType;
+import org.apache.pivot.wtk.PushButton;
+import org.apache.pivot.wtk.Sheet;
+import org.apache.pivot.wtk.SheetCloseListener;
+import org.apache.pivot.wtk.Window;
+import org.apache.pivot.wtkx.WTKX;
+import org.apache.pivot.wtkx.WTKXSerializer;
+
+public class FileBrowsing implements Application {
+    private Window window = null;
+
+    @WTKX private ButtonGroup fileBrowserSheetModeGroup = null;
+    @WTKX private PushButton openSheetButton = null;
+
+    @Override
+    public void startup(Display display, Map&gt;String, String&gt; properties)
+        throws Exception {
+        WTKXSerializer wtkxSerializer = new WTKXSerializer();
+
+        window = (Window)wtkxSerializer.readObject(getClass().getResource("file_browsing.wtkx"));
+        wtkxSerializer.bind(this, FileBrowsing.class);
+
+        openSheetButton.getButtonPressListeners().add(new ButtonPressListener() {
+            @Override
+            public void buttonPressed(Button button) {
+                Button selection = fileBrowserSheetModeGroup.getSelection();
+
+                String mode = (String)selection.getUserData().get("mode");
+                final FileBrowserSheet fileBrowserSheet =
+                    new FileBrowserSheet(FileBrowserSheet.Mode.valueOf(mode.toUpperCase()));
+
+                fileBrowserSheet.open(window, new SheetCloseListener() {
+                    @Override
+                    public void sheetClosed(Sheet sheet) {
+                        if (sheet.getResult()) {
+                            Sequence&gt;File&gt; selectedFiles = fileBrowserSheet.getSelectedFiles();
+
+                            ListView listView = new ListView();
+                            listView.setListData(new ArrayList&gt;File&gt;(selectedFiles));
+                            listView.setSelectMode(ListView.SelectMode.NONE);
+                            listView.getStyles().put("backgroundColor", null);
+
+                            Alert.alert(MessageType.INFO, "You selected:", listView, window);
+                        } else {
+                            Alert.alert(MessageType.INFO, "You didn't select anything.", window);
+                        }
+                    }
+                });
+            }
+        });
+
+        window.open(display);
+    }
+
+    @Override
+    public boolean shutdown(boolean optional) {
+        if (window != null) {
+            window.close();
+        }
+
+        return false;
+    }
+
+    @Override
+    public void suspend() {
+    }
+
+    @Override
+    public void resume() {
+    }
+
+    public static void main(String[] args) {
+        DesktopApplicationContext.main(FileBrowsing.class, args);
+    }
+}
+</pre>
+
+<p>Note that, internally, <tt>FileBrowserSheet</tt> uses an instance of the <tt>org.apache.pivot.wtk.FileBrowser</tt> class to perform the actual file system navigation. It is possible to use this component directly within an application to create a custom file browser; however, a discussion of the <tt>FileBrowser</tt> class is outside the scope of this tutorial.</p>
+
 <p>Next: <a href="windows.html">Windows</a></p>
 </body>
 </html>