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/14 00:27:58 UTC
svn commit: r804048 - in /incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk:
content/TableViewFileRenderer.java skin/terra/TerraFileBrowserSkin.java
skin/terra/terra_file_browser_skin.wtkx
Author: gbrown
Date: Thu Aug 13 22:27:58 2009
New Revision: 804048
URL: http://svn.apache.org/viewvc?rev=804048&view=rev
Log:
Add some additional features to FileBrowser.
Modified:
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewFileRenderer.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/content/TableViewFileRenderer.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewFileRenderer.java?rev=804048&r1=804047&r2=804048&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewFileRenderer.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewFileRenderer.java Thu Aug 13 22:27:58 2009
@@ -25,9 +25,9 @@
import org.apache.pivot.wtk.HorizontalAlignment;
import org.apache.pivot.wtk.Insets;
import org.apache.pivot.wtk.TableView;
+import org.apache.pivot.wtk.media.Image;
public class TableViewFileRenderer extends FileRenderer implements TableView.CellRenderer {
- public static final String ICON_KEY = "icon";
public static final String NAME_KEY = "name";
public static final String SIZE_KEY = "size";
public static final String LAST_MODIFIED_KEY = "lastModified";
@@ -41,61 +41,53 @@
boolean rowSelected, boolean rowHighlighted, boolean rowDisabled) {
String columnName = column.getName();
- if (columnName.equals(ICON_KEY)) {
- imageView.setVisible(true);
- label.setVisible(false);
-
- if (value != null) {
- File file = (File)value;
- imageView.setImage(FileRenderer.getIcon(file));
- }
- } else {
- imageView.setVisible(false);
- label.setVisible(true);
-
- if (value != null) {
- File file = (File)value;
+ if (value != null) {
+ File file = (File)value;
- String text;
- if (columnName.equals(NAME_KEY)) {
- text = file.getName();
- getStyles().put("horizontalAlignment", HorizontalAlignment.LEFT);
- } else if (columnName.equals(SIZE_KEY)) {
- text = formatSize(file);
- getStyles().put("horizontalAlignment", HorizontalAlignment.RIGHT);
- } else if (columnName.equals(LAST_MODIFIED_KEY)) {
- long lastModified = file.lastModified();
- Date lastModifiedDate = new Date(lastModified);
-
- DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
- text = dateFormat.format(lastModifiedDate);
- getStyles().put("horizontalAlignment", HorizontalAlignment.RIGHT);
- } else {
- text = null;
- }
+ String text = null;
+ Image icon = null;
- label.setText(text);
+ if (columnName.equals(NAME_KEY)) {
+ text = file.getName();
+ icon = getIcon(file);
+ getStyles().put("horizontalAlignment", HorizontalAlignment.LEFT);
+ } else if (columnName.equals(SIZE_KEY)) {
+ text = formatSize(file);
+ getStyles().put("horizontalAlignment", HorizontalAlignment.RIGHT);
+ } else if (columnName.equals(LAST_MODIFIED_KEY)) {
+ long lastModified = file.lastModified();
+ Date lastModifiedDate = new Date(lastModified);
+
+ DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
+ text = dateFormat.format(lastModifiedDate);
+ getStyles().put("horizontalAlignment", HorizontalAlignment.RIGHT);
+ } else {
+ System.err.println("Unexpected column name in " + getClass().getName()
+ + ": " + columnName);
}
- Font font = (Font)tableView.getStyles().get("font");
- label.getStyles().put("font", font);
+ label.setText(text);
+ imageView.setImage(icon);
+ }
+
+ Font font = (Font)tableView.getStyles().get("font");
+ label.getStyles().put("font", font);
- Color color;
- if (tableView.isEnabled() && !rowDisabled) {
- if (rowSelected) {
- if (tableView.isFocused()) {
- color = (Color)tableView.getStyles().get("selectionColor");
- } else {
- color = (Color)tableView.getStyles().get("inactiveSelectionColor");
- }
+ Color color;
+ if (tableView.isEnabled() && !rowDisabled) {
+ if (rowSelected) {
+ if (tableView.isFocused()) {
+ color = (Color)tableView.getStyles().get("selectionColor");
} else {
- color = (Color)tableView.getStyles().get("color");
+ color = (Color)tableView.getStyles().get("inactiveSelectionColor");
}
} else {
- color = (Color)tableView.getStyles().get("disabledColor");
+ color = (Color)tableView.getStyles().get("color");
}
-
- label.getStyles().put("color", color);
+ } else {
+ color = (Color)tableView.getStyles().get("disabledColor");
}
+
+ label.getStyles().put("color", color);
}
}
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=804048&r1=804047&r2=804048&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 22:27:58 2009
@@ -25,11 +25,17 @@
import org.apache.pivot.serialization.SerializationException;
import org.apache.pivot.util.Filter;
import org.apache.pivot.util.Resources;
+import org.apache.pivot.wtk.Button;
+import org.apache.pivot.wtk.ButtonPressListener;
import org.apache.pivot.wtk.Component;
+import org.apache.pivot.wtk.ComponentMouseButtonListener;
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.Mouse;
+import org.apache.pivot.wtk.PushButton;
+import org.apache.pivot.wtk.ScrollPane;
import org.apache.pivot.wtk.TableView;
import org.apache.pivot.wtk.skin.FileBrowserSkin;
import org.apache.pivot.wtkx.WTKX;
@@ -44,6 +50,11 @@
private Component content = null;
@WTKX private ListButton pathListButton = null;
+ @WTKX private PushButton goUpButton = null;
+ @WTKX private PushButton newFolderButton = null;
+ @WTKX private PushButton goHomeButton = null;
+
+ @WTKX private ScrollPane fileScrollPane = null;
@WTKX private TableView fileTableView = null;
@Override
@@ -84,6 +95,49 @@
}
});
+ goUpButton.getButtonPressListeners().add(new ButtonPressListener() {
+ public void buttonPressed(Button button) {
+ Folder selectedFolder = fileBrowser.getSelectedFolder();
+ File parentDirectory = selectedFolder.getParentFile();
+ fileBrowser.setSelectedFolder(new Folder(parentDirectory.getPath()));
+ }
+ });
+
+ newFolderButton.getButtonPressListeners().add(new ButtonPressListener() {
+ public void buttonPressed(Button button) {
+ // TODO
+ }
+ });
+
+ goHomeButton.getButtonPressListeners().add(new ButtonPressListener() {
+ public void buttonPressed(Button button) {
+ fileBrowser.setSelectedFolder(new Folder(System.getProperty("user.home")));
+ }
+ });
+
+ fileTableView.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener.Adapter() {
+ private File selectedDirectory = null;
+
+ @Override
+ public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
+ // TODO If we're in multi-select mode, we'll need to check
+ // selection length
+ if (count == 1) {
+ File selectedFile = (File)fileTableView.getSelectedRow();
+ if (selectedFile != null
+ && selectedFile.isDirectory()) {
+ selectedDirectory = selectedFile;
+ }
+ } else if (count == 2) {
+ if (selectedDirectory == fileTableView.getSelectedRow()) {
+ fileBrowser.setSelectedFolder(new Folder(selectedDirectory.getPath()));
+ }
+ }
+
+ return false;
+ }
+ });
+
selectedFolderChanged(fileBrowser, null);
}
@@ -124,17 +178,25 @@
public void selectedFolderChanged(FileBrowser fileBrowser, Folder previousSelectedFolder) {
ArrayList<File> path = new ArrayList<File>();
- Folder folder = fileBrowser.getSelectedFolder();
- File directory = folder.getParentFile();
+ Folder selectedFolder = fileBrowser.getSelectedFolder();
+
+ File directory = selectedFolder.getParentFile();
while (directory != null) {
path.add(directory);
directory = directory.getParentFile();
}
pathListButton.setListData(path);
- pathListButton.setButtonData(folder);
+ pathListButton.setButtonData(selectedFolder);
+
+ goUpButton.setEnabled(selectedFolder.getParentFile() != null);
+
+ File homeDirectory = new File(System.getProperty("user.home"));
+ goHomeButton.setEnabled(!selectedFolder.equals(homeDirectory));
- fileTableView.setTableData(folder);
+ fileScrollPane.setScrollTop(0);
+ fileScrollPane.setScrollLeft(0);
+ fileTableView.setTableData(selectedFolder);
}
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=804048&r1=804047&r2=804048&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 22:27:58 2009
@@ -51,7 +51,7 @@
<content:ButtonData icon="@folder_up.png"/>
</buttonData>
</PushButton>
- <PushButton wtkx:id="newFolderUpButton" styles="{toolbar:true}" tooltipText="%newFolder">
+ <PushButton wtkx:id="newFolderButton" styles="{toolbar:true}" tooltipText="%newFolder">
<buttonData>
<content:ButtonData icon="@folder_add.png"/>
</buttonData>
@@ -81,16 +81,12 @@
<!-- File table view -->
<Border styles="{color:10, padding:0}">
<content>
- <ScrollPane horizontalScrollBarPolicy="fill" verticalScrollBarPolicy="fill_to_capacity">
+ <ScrollPane wtkx:id="fileScrollPane"
+ horizontalScrollBarPolicy="fill" verticalScrollBarPolicy="fill_to_capacity">
<view>
<TableView wtkx:id="fileTableView"
styles="{showHorizontalGridLines:false, showVerticalGridLines:false}">
<columns>
- <TableView.Column name="icon" width="20">
- <cellRenderer>
- <content:TableViewFileRenderer/>
- </cellRenderer>
- </TableView.Column>
<TableView.Column name="name" width="3*" headerData="%fileName">
<cellRenderer>
<content:TableViewFileRenderer/>