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/11/02 15:20:20 UTC
svn commit: r831905 - in
/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk: ./ skin/terra/
Author: gbrown
Date: Mon Nov 2 14:20:20 2009
New Revision: 831905
URL: http://svn.apache.org/viewvc?rev=831905&view=rev
Log:
Add support to FileBrowser for navigating additional drives on Windows.
Added:
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/drive.png (with props)
Modified:
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListButton.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Spinner.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TableView.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/TerraFileBrowserSkin.json
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/terra_file_browser_sheet_skin.wtkx
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/ListButton.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListButton.java?rev=831905&r1=831904&r2=831905&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListButton.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListButton.java Mon Nov 2 14:20:20 2009
@@ -165,7 +165,7 @@
if (previousListData != listData) {
if (previousListData != null) {
- setSelectedIndex(-1);
+ selectedIndex = -1;
}
// Update the list data and fire change event
@@ -180,7 +180,7 @@
* @param listData
* The list data to be presented by the list button as a JSON array.
*/
- public void setListData(String listData) {
+ public final void setListData(String listData) {
if (listData == null) {
throw new IllegalArgumentException("listData is null.");
}
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=831905&r1=831904&r2=831905&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 Mon Nov 2 14:20:20 2009
@@ -677,7 +677,7 @@
* A JSON string (must begin with <tt>[</tt> and end with <tt>]</tt>)
* denoting the data to be presented by the list view.
*/
- public void setListData(String listData) {
+ public final void setListData(String listData) {
if (listData == null) {
throw new IllegalArgumentException("listData is null.");
}
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Spinner.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Spinner.java?rev=831905&r1=831904&r2=831905&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Spinner.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Spinner.java Mon Nov 2 14:20:20 2009
@@ -259,7 +259,7 @@
if (previousSpinnerData != spinnerData) {
if (previousSpinnerData != null) {
// Clear any existing selection
- setSelectedIndex(-1);
+ selectedIndex = -1;
((List<Object>)previousSpinnerData).getListListeners().remove(spinnerDataHandler);
}
@@ -272,7 +272,7 @@
}
}
- public void setSpinnerData(String spinnerData) {
+ public final void setSpinnerData(String spinnerData) {
if (spinnerData == null) {
throw new IllegalArgumentException("spinnerData is null.");
}
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=831905&r1=831904&r2=831905&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 Mon Nov 2 14:20:20 2009
@@ -1275,7 +1275,7 @@
if (previousTableData != tableData) {
if (previousTableData != null) {
// Clear any existing selection
- clearSelection();
+ selectedRanges.clear();
((List<Object>)previousTableData).getListListeners().remove(tableDataListener);
}
@@ -1295,7 +1295,7 @@
* A JSON string (must begin with <tt>[</tt> and end with <tt>]</tt>)
* denoting the data to be presented by the table view.
*/
- public void setTableData(String tableData) {
+ public final void setTableData(String tableData) {
if (tableData == null) {
throw new IllegalArgumentException("tableData is null.");
}
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=831905&r1=831904&r2=831905&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 Mon Nov 2 14:20:20 2009
@@ -288,6 +288,115 @@
}
}
+
+ /**
+ * Abstract base class for drive renderers.
+ */
+ public static abstract class DriveRenderer 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 DRIVE_IMAGE;
+
+ static {
+ try {
+ DRIVE_IMAGE = Image.load(FileRenderer.class.getResource("drive.png"));
+ } catch (TaskExecutionException exception) {
+ throw new RuntimeException(exception);
+ }
+ }
+
+ public DriveRenderer() {
+ getStyles().put("verticalAlignment", VerticalAlignment.CENTER);
+
+ add(imageView);
+ add(label);
+
+ imageView.setPreferredSize(ICON_WIDTH, ICON_HEIGHT);
+ imageView.getStyles().put("backgroundColor", null);
+ }
+
+ @Override
+ 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();
+ }
+ }
+
+ /**
+ * List button drive renderer.
+ */
+ public static class ListButtonDriveRenderer extends DriveRenderer implements Button.DataRenderer {
+ public ListButtonDriveRenderer() {
+ getStyles().put("horizontalAlignment", HorizontalAlignment.LEFT);
+ }
+
+ @Override
+ public void render(Object data, Button button, boolean highlight) {
+ if (data != null) {
+ File file = (File)data;
+
+ // Update the image view
+ imageView.setImage(DRIVE_IMAGE);
+ imageView.getStyles().put("opacity", button.isEnabled() ? 1.0f : 0.5f);
+
+ // Update the label
+ label.setText(file.toString());
+ }
+ }
+ }
+
+ /**
+ * List view drive renderer.
+ */
+ public static class ListViewDriveRenderer extends DriveRenderer implements ListView.ItemRenderer {
+ public ListViewDriveRenderer() {
+ getStyles().put("horizontalAlignment", HorizontalAlignment.LEFT);
+ getStyles().put("padding", new Insets(2, 3, 2, 3));
+ }
+
+ @Override
+ public void render(Object item, int index, 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) {
+ File file = (File)item;
+
+ // Update the image view
+ imageView.setImage(DRIVE_IMAGE);
+ imageView.getStyles().put("opacity",
+ (listView.isEnabled() && !disabled) ? 1.0f : 0.5f);
+
+ // Update the label
+ label.setText(file.toString());
+ }
+ }
+ }
+
/**
* File comparator.
*/
@@ -361,6 +470,7 @@
private Component content = null;
+ @WTKX private ListButton driveListButton = null;
@WTKX private ListButton pathListButton = null;
@WTKX private PushButton goUpButton = null;
@WTKX private PushButton newFolderButton = null;
@@ -411,6 +521,16 @@
wtkxSerializer.bind(this, TerraFileBrowserSkin.class);
+ driveListButton.getListButtonSelectionListeners().add(new ListButtonSelectionListener() {
+ @Override
+ public void selectedIndexChanged(ListButton listButton, int previousSelectedIndex) {
+ if (previousSelectedIndex != -1) {
+ File drive = (File)listButton.getSelectedItem();
+ fileBrowser.setRootDirectory(drive);
+ }
+ }
+ });
+
pathListButton.getListButtonSelectionListeners().add(new ListButtonSelectionListener() {
@Override
public void selectedIndexChanged(ListButton listButton, int previousSelectedIndex) {
@@ -508,7 +628,6 @@
updatingSelection = true;
Sequence<File> files = (Sequence<File>)tableView.getSelectedRows();
- // TODO Revisit this for loop
for (int i = 0, n = files.getLength(); i < n; i++) {
File file = files.get(i);
files.update(i, file);
@@ -706,10 +825,24 @@
ancestorDirectory = ancestorDirectory.getParentFile();
}
+ ArrayList<File> rootFolders = new ArrayList<File>(File.listRoots());
+ driveListButton.setListData(rootFolders);
+ driveListButton.setVisible(rootFolders.getLength() > 1);
+
+ File drive;
+ if (path.getLength() == 0) {
+ drive = rootDirectory;
+ } else {
+ drive = path.get(path.getLength() - 1);
+ }
+
+ driveListButton.setSelectedItem(drive);
+
pathListButton.setListData(path);
pathListButton.setButtonData(rootDirectory);
+ pathListButton.setEnabled(rootDirectory.getParentFile() != null);
- goUpButton.setEnabled(rootDirectory.getParentFile() != null);
+ goUpButton.setEnabled(pathListButton.isEnabled());
File homeDirectory = new File(System.getProperty("user.home"));
goHomeButton.setEnabled(!rootDirectory.equals(homeDirectory));
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraFileBrowserSkin.json
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraFileBrowserSkin.json?rev=831905&r1=831904&r2=831905&view=diff
==============================================================================
Binary files - no diff available.
Added: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/drive.png
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/drive.png?rev=831905&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/drive.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/terra_file_browser_sheet_skin.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/terra_file_browser_sheet_skin.wtkx?rev=831905&r1=831904&r2=831905&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/terra_file_browser_sheet_skin.wtkx (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/terra_file_browser_sheet_skin.wtkx Mon Nov 2 14:20:20 2009
@@ -37,7 +37,7 @@
</TablePane.Row>
<TablePane.Row height="1*">
<FileBrowser wtkx:id="fileBrowser"
- preferredWidth="420" preferredHeight="220"/>
+ preferredWidth="480" preferredHeight="240"/>
</TablePane.Row>
<TablePane.Row height="-1">
<BoxPane styles="{horizontalAlignment:'right', verticalAlignment:'center'}">
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=831905&r1=831904&r2=831905&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 Mon Nov 2 14:20:20 2009
@@ -28,8 +28,9 @@
<rows>
<TablePane.Row height="-1">
<!-- Toolbar -->
- <TablePane>
+ <TablePane styles="{horizontalSpacing:2}">
<columns>
+ <TablePane.Column width="-1"/>
<TablePane.Column width="2*"/>
<TablePane.Column width="-1"/>
<TablePane.Column width="1*"/>
@@ -37,6 +38,15 @@
</columns>
<rows>
<TablePane.Row>
+ <ListButton wtkx:id="driveListButton" tooltipText="%selectDrive">
+ <dataRenderer>
+ <terra:TerraFileBrowserSkin.ListButtonDriveRenderer/>
+ </dataRenderer>
+ <itemRenderer>
+ <terra:TerraFileBrowserSkin.ListViewDriveRenderer/>
+ </itemRenderer>
+ </ListButton>
+
<ListButton wtkx:id="pathListButton" tooltipText="%goTo">
<dataRenderer>
<terra:TerraFileBrowserSkin.ListButtonFileRenderer/>
@@ -46,7 +56,7 @@
</itemRenderer>
</ListButton>
- <BoxPane styles="{verticalAlignment:'center', padding:{left:2, right:2}, spacing:0}">
+ <BoxPane styles="{verticalAlignment:'center', spacing:0}">
<PushButton wtkx:id="goUpButton" styles="{toolbar:true}" tooltipText="%goUp">
<buttonData>
<content:ButtonData icon="@folder_up.png"/>