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/08/13 19:34:07 UTC

svn commit: r803955 - in /incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk: ./ content/ skin/terra/

Author: gbrown
Date: Thu Aug 13 17:34:03 2009
New Revision: 803955

URL: http://svn.apache.org/viewvc?rev=803955&view=rev
Log:
Add some preliminary logic to TerraFileBrowserSkin; create abstract FileRenderer class and add ListViewFileRenderer; add ListButtonFileRenderer; fix bug in setSelectedIndex() in ListView and TreeView when clearing the selection.

Added:
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/FileRenderer.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListButtonFileRenderer.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListViewFileRenderer.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/folder_home.png
      - copied unchanged from r803846, incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/folder_home.png
Removed:
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/folder_home.png
Modified:
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TableView.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TreeViewFileRenderer.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraFileBrowserSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/terra_file_browser_skin.wtkx

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java?rev=803955&r1=803954&r2=803955&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java Thu Aug 13 17:34:03 2009
@@ -522,7 +522,11 @@
      * The index to select, or <tt>-1</tt> to clear the selection.
      */
     public void setSelectedIndex(int index) {
-        setSelectedRange(index, index);
+        if (index == -1) {
+            clearSelection();
+        } else {
+            setSelectedRange(index, index);
+        }
     }
 
     /**

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TableView.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TableView.java?rev=803955&r1=803954&r2=803955&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TableView.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TableView.java Thu Aug 13 17:34:03 2009
@@ -974,7 +974,11 @@
      * The index to select, or <tt>-1</tt> to clear the selection.
      */
     public void setSelectedIndex(int index) {
-        setSelectedRange(index, index);
+        if (index == -1) {
+            clearSelection();
+        } else {
+            setSelectedRange(index, index);
+        }
     }
 
     /**

Added: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/FileRenderer.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/FileRenderer.java?rev=803955&view=auto
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/FileRenderer.java (added)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/FileRenderer.java Thu Aug 13 17:34:03 2009
@@ -0,0 +1,99 @@
+/*
+ * 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
+ *
+ * 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.apache.pivot.wtk.content;
+
+import java.io.File;
+
+import org.apache.pivot.util.concurrent.TaskExecutionException;
+import org.apache.pivot.wtk.BoxPane;
+import org.apache.pivot.wtk.Component;
+import org.apache.pivot.wtk.HorizontalAlignment;
+import org.apache.pivot.wtk.ImageView;
+import org.apache.pivot.wtk.Label;
+import org.apache.pivot.wtk.VerticalAlignment;
+import org.apache.pivot.wtk.media.Image;
+
+/**
+ * Abstract renderer for displaying file system contents.
+ *
+ * @author gbrown
+ */
+public abstract class FileRenderer extends BoxPane {
+    protected ImageView imageView = new ImageView();
+    protected Label label = new Label();
+
+    public static final int ICON_WIDTH = 16;
+    public static final int ICON_HEIGHT = 16;
+
+    public static final Image FOLDER_IMAGE;
+    public static final Image HOME_FOLDER_IMAGE;
+    public static final Image FILE_IMAGE;
+
+    public static final File HOME_DIRECTORY;
+
+    static {
+        try {
+            FOLDER_IMAGE = Image.load(TreeViewFileRenderer.class.getResource("folder.png"));
+            HOME_FOLDER_IMAGE = Image.load(TreeViewFileRenderer.class.getResource("folder_home.png"));
+            FILE_IMAGE = Image.load(TreeViewFileRenderer.class.getResource("page_white.png"));
+
+            HOME_DIRECTORY = new File(System.getProperty("user.home"));
+        } catch (TaskExecutionException exception) {
+            throw new RuntimeException(exception);
+        }
+    }
+
+    public FileRenderer() {
+        getStyles().put("horizontalAlignment", HorizontalAlignment.LEFT);
+        getStyles().put("verticalAlignment", VerticalAlignment.CENTER);
+
+        add(imageView);
+        add(label);
+
+        imageView.setPreferredSize(ICON_WIDTH, ICON_HEIGHT);
+    }
+
+    public void setSize(int width, int height) {
+        super.setSize(width, height);
+
+        // Since this component doesn't have a parent, it won't be validated
+        // via layout; ensure that it is valid here
+        validate();
+    }
+
+    protected void render(File file, Component component, boolean disabled) {
+        // Update the image view
+        Image icon;
+        if (file.isDirectory()) {
+            icon = file.equals(HOME_DIRECTORY) ? HOME_FOLDER_IMAGE : FOLDER_IMAGE;
+        } else {
+            icon = FILE_IMAGE;
+        }
+
+        imageView.setImage(icon);
+        imageView.getStyles().put("opacity",
+            (component.isEnabled() && !disabled) ? 1.0f : 0.5f);
+
+        // Update the label
+        String text = file.getName();
+        if (text.length() == 0) {
+            text = System.getProperty("file.separator");
+        }
+
+        label.setText(text);
+    }
+}

Added: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListButtonFileRenderer.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListButtonFileRenderer.java?rev=803955&view=auto
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListButtonFileRenderer.java (added)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListButtonFileRenderer.java Thu Aug 13 17:34:03 2009
@@ -0,0 +1,53 @@
+/*
+ * 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
+ *
+ * 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.apache.pivot.wtk.content;
+
+import java.io.File;
+
+import org.apache.pivot.wtk.Button;
+import org.apache.pivot.wtk.media.Image;
+
+/**
+ * List button file renderer.
+ *
+ * @author gbrown
+ */
+public class ListButtonFileRenderer extends ListButtonDataRenderer {
+    @Override
+    public void render(Object data, Button button, boolean highlight) {
+        if (data != null) {
+            File file = (File)data;
+
+            Image icon;
+            if (file.isDirectory()) {
+                icon = file.equals(FileRenderer.HOME_DIRECTORY) ?
+                    FileRenderer.HOME_FOLDER_IMAGE : FileRenderer.FOLDER_IMAGE;
+            } else {
+                icon = FileRenderer.FILE_IMAGE;
+            }
+
+            String text = file.getName();
+            if (text.length() == 0) {
+                text = System.getProperty("file.separator");
+            }
+
+            data = new ButtonData(icon, text);
+        }
+
+        super.render(data, button, highlight);
+    }
+}

Added: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListViewFileRenderer.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListViewFileRenderer.java?rev=803955&view=auto
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListViewFileRenderer.java (added)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListViewFileRenderer.java Thu Aug 13 17:34:03 2009
@@ -0,0 +1,59 @@
+/*
+ * 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
+ *
+ * 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.apache.pivot.wtk.content;
+
+import java.io.File;
+
+import org.apache.pivot.wtk.Insets;
+import org.apache.pivot.wtk.ListView;
+
+/**
+ * List view renderer for displaying file system contents.
+ *
+ * @author gbrown
+ */
+public class ListViewFileRenderer extends FileRenderer implements ListView.ItemRenderer {
+    public ListViewFileRenderer() {
+        getStyles().put("padding", new Insets(2, 3, 2, 3));
+    }
+
+    public void render(Object item, ListView listView, boolean selected,
+        boolean checked, boolean highlighted, boolean disabled) {
+        label.getStyles().put("font", listView.getStyles().get("font"));
+
+        Object color = null;
+        if (listView.isEnabled() && !disabled) {
+            if (selected) {
+                if (listView.isFocused()) {
+                    color = listView.getStyles().get("selectionColor");
+                } else {
+                    color = listView.getStyles().get("inactiveSelectionColor");
+                }
+            } else {
+                color = listView.getStyles().get("color");
+            }
+        } else {
+            color = listView.getStyles().get("disabledColor");
+        }
+
+        label.getStyles().put("color", color);
+
+        if (item != null) {
+            render((File)item, listView, disabled);
+        }
+    }
+}

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TreeViewFileRenderer.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TreeViewFileRenderer.java?rev=803955&r1=803954&r2=803955&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TreeViewFileRenderer.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TreeViewFileRenderer.java Thu Aug 13 17:34:03 2009
@@ -16,79 +16,20 @@
  */
 package org.apache.pivot.wtk.content;
 
-import java.awt.Color;
-import java.awt.Font;
 import java.io.File;
 
-import org.apache.pivot.io.Folder;
-import org.apache.pivot.util.concurrent.TaskExecutionException;
-import org.apache.pivot.wtk.BoxPane;
-import org.apache.pivot.wtk.HorizontalAlignment;
-import org.apache.pivot.wtk.ImageView;
-import org.apache.pivot.wtk.Label;
 import org.apache.pivot.wtk.TreeView;
-import org.apache.pivot.wtk.VerticalAlignment;
-import org.apache.pivot.wtk.media.Image;
-
 
 /**
  * Tree view renderer for displaying file system contents.
  *
  * @author gbrown
  */
-public class TreeViewFileRenderer extends BoxPane implements TreeView.NodeRenderer {
-    private ImageView imageView = new ImageView();
-    private Label label = new Label();
-
-    public static final int ICON_WIDTH = 16;
-    public static final int ICON_HEIGHT = 16;
-
-    public static final Image FOLDER_IMAGE;
-    public static final Image FILE_IMAGE;
-
-    static {
-        try {
-            FOLDER_IMAGE = Image.load(TreeViewFileRenderer.class.getResource("folder.png"));
-            FILE_IMAGE = Image.load(TreeViewFileRenderer.class.getResource("page_white.png"));
-        } catch (TaskExecutionException exception) {
-            throw new RuntimeException(exception);
-        }
-    }
-
-    public TreeViewFileRenderer() {
-        super();
-
-        getStyles().put("horizontalAlignment", HorizontalAlignment.LEFT);
-        getStyles().put("verticalAlignment", VerticalAlignment.CENTER);
-
-        add(imageView);
-        add(label);
-
-        imageView.setPreferredSize(ICON_WIDTH, ICON_HEIGHT);
-    }
-
-    public void setSize(int width, int height) {
-        super.setSize(width, height);
-
-        // Since this component doesn't have a parent, it won't be validated
-        // via layout; ensure that it is valid here
-        validate();
-    }
-
-    @Override
-    public int getPreferredHeight(int width) {
-        int preferredHeight = super.getPreferredHeight(width);
-        return preferredHeight;
-    }
-
+public class TreeViewFileRenderer extends FileRenderer implements TreeView.NodeRenderer {
     public void render(Object node, TreeView treeView, boolean expanded,
         boolean selected, TreeView.NodeCheckState checkState,
         boolean highlighted, boolean disabled) {
-        // Update styles
-        Object labelFont = treeView.getStyles().get("font");
-        if (labelFont instanceof Font) {
-            label.getStyles().put("font", labelFont);
-        }
+        label.getStyles().put("font", treeView.getStyles().get("font"));
 
         Object color = null;
         if (treeView.isEnabled() && !disabled) {
@@ -105,22 +46,10 @@
             color = treeView.getStyles().get("disabledColor");
         }
 
-        if (color instanceof Color) {
-            label.getStyles().put("color", color);
-        }
+        label.getStyles().put("color", color);
 
         if (node != null) {
-            File file = (File)node;
-
-            // Update the image view
-            Image icon = (file instanceof Folder) ? FOLDER_IMAGE : FILE_IMAGE;
-
-            imageView.setImage(icon);
-            imageView.getStyles().put("opacity",
-                (treeView.isEnabled() && !disabled) ? 1.0f : 0.5f);
-
-            // Update the label
-            label.setText(file.getName());
+            render((File)node, treeView, disabled);
         }
     }
 }

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraFileBrowserSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraFileBrowserSkin.java?rev=803955&r1=803954&r2=803955&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraFileBrowserSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraFileBrowserSkin.java Thu Aug 13 17:34:03 2009
@@ -19,6 +19,7 @@
 import java.io.File;
 import java.io.IOException;
 
+import org.apache.pivot.collections.ArrayList;
 import org.apache.pivot.collections.Sequence;
 import org.apache.pivot.io.Folder;
 import org.apache.pivot.serialization.SerializationException;
@@ -27,7 +28,10 @@
 import org.apache.pivot.wtk.Component;
 import org.apache.pivot.wtk.Dimensions;
 import org.apache.pivot.wtk.FileBrowser;
+import org.apache.pivot.wtk.ListButton;
+import org.apache.pivot.wtk.ListButtonSelectionListener;
 import org.apache.pivot.wtk.skin.FileBrowserSkin;
+import org.apache.pivot.wtkx.WTKX;
 import org.apache.pivot.wtkx.WTKXSerializer;
 
 /**
@@ -38,11 +42,13 @@
 public class TerraFileBrowserSkin extends FileBrowserSkin {
     private Component content = null;
 
+    @WTKX private ListButton pathListButton = null;
+
     @Override
     public void install(Component component) {
         super.install(component);
 
-        FileBrowser fileBrowser = (FileBrowser)component;
+        final FileBrowser fileBrowser = (FileBrowser)component;
 
         Resources resources;
         try {
@@ -63,6 +69,20 @@
         }
 
         fileBrowser.add(content);
+
+        wtkxSerializer.bind(this, TerraFileBrowserSkin.class);
+
+        pathListButton.getListButtonSelectionListeners().add(new ListButtonSelectionListener() {
+            public void selectedIndexChanged(ListButton listButton, int previousSelectedIndex) {
+                File directory = (File)listButton.getSelectedItem();
+
+                if (directory != null) {
+                    fileBrowser.setSelectedFolder(new Folder(directory.getPath()));
+                }
+            }
+        });
+
+        selectedFolderChanged(fileBrowser, null);
     }
 
     @Override
@@ -100,7 +120,17 @@
     }
 
     public void selectedFolderChanged(FileBrowser fileBrowser, Folder previousSelectedFolder) {
-        // TODO
+        ArrayList<File> path = new ArrayList<File>();
+
+        Folder folder = fileBrowser.getSelectedFolder();
+        File directory = folder.getParentFile();
+        while (directory != null) {
+            path.add(directory);
+            directory = directory.getParentFile();
+        }
+
+        pathListButton.setListData(path);
+        pathListButton.setButtonData(folder);
     }
 
     public void selectedFileAdded(FileBrowser fileBrowser, File file) {

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/terra_file_browser_skin.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/terra_file_browser_skin.wtkx?rev=803955&r1=803954&r2=803955&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/terra_file_browser_skin.wtkx (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/terra_file_browser_skin.wtkx Thu Aug 13 17:34:03 2009
@@ -36,15 +36,12 @@
                 <rows>
                     <TablePane.Row>
                         <BoxPane styles="{verticalAlignment:'center'}">
-                            <ListButton wtkx:id="pathListButton" selectedIndex="0" tooltipText="%goTo">
-                                <listData>
-                                    <collections:ArrayList>
-                                        <content:ListItem icon="@folder.png" text="Sample Folder"/>
-                                    </collections:ArrayList>
-                                </listData>
+                            <ListButton wtkx:id="pathListButton" tooltipText="%goTo">
+                                <dataRenderer>
+                                    <content:ListButtonFileRenderer/>
+                                </dataRenderer>
                                 <itemRenderer>
-                                    <content:ListViewItemRenderer iconWidth="16" iconHeight="16"
-                                        showIcon="true"/>
+                                    <content:ListViewFileRenderer/>
                                 </itemRenderer>
                             </ListButton>