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/03/27 18:43:44 UTC
svn commit: r759281 - in /incubator/pivot/trunk/demos/src/pivot/demos:
dnd/FileCellRenderer.java dnd/FileDropTargetDemo.java
dnd/file_drop_target_demo.wtkx filebrowser/file_browser_demo.wtkx
Author: gbrown
Date: Fri Mar 27 17:43:43 2009
New Revision: 759281
URL: http://svn.apache.org/viewvc?rev=759281&view=rev
Log:
Add a file uploader demo.
Added:
incubator/pivot/trunk/demos/src/pivot/demos/dnd/FileCellRenderer.java
incubator/pivot/trunk/demos/src/pivot/demos/dnd/FileDropTargetDemo.java
incubator/pivot/trunk/demos/src/pivot/demos/dnd/file_drop_target_demo.wtkx
Modified:
incubator/pivot/trunk/demos/src/pivot/demos/filebrowser/file_browser_demo.wtkx
Added: incubator/pivot/trunk/demos/src/pivot/demos/dnd/FileCellRenderer.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/demos/src/pivot/demos/dnd/FileCellRenderer.java?rev=759281&view=auto
==============================================================================
--- incubator/pivot/trunk/demos/src/pivot/demos/dnd/FileCellRenderer.java (added)
+++ incubator/pivot/trunk/demos/src/pivot/demos/dnd/FileCellRenderer.java Fri Mar 27 17:43:43 2009
@@ -0,0 +1,97 @@
+/*
+ * 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
+ *
+ * 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 pivot.demos.dnd;
+
+import java.awt.Color;
+import java.awt.Font;
+import java.io.File;
+import java.text.DateFormat;
+import java.util.Date;
+
+import pivot.wtk.HorizontalAlignment;
+import pivot.wtk.Insets;
+import pivot.wtk.Label;
+import pivot.wtk.TableView;
+import pivot.wtk.VerticalAlignment;
+
+public class FileCellRenderer extends Label implements TableView.CellRenderer {
+ public static final String NAME_KEY = "name";
+ public static final String SIZE_KEY = "size";
+ public static final String LAST_MODIFIED_KEY = "lastModified";
+
+ public FileCellRenderer() {
+ getStyles().put("verticalAlignment", VerticalAlignment.CENTER);
+ getStyles().put("padding", new Insets(2));
+ }
+
+ @SuppressWarnings("unchecked")
+ public void render(Object value, TableView tableView, TableView.Column column,
+ boolean rowSelected, boolean rowHighlighted, boolean rowDisabled) {
+ File file = (File)value;
+ String columnName = column.getName();
+
+ String text;
+ if (columnName.equals(NAME_KEY)) {
+ text = file.getName();
+ getStyles().put("horizontalAlignment", HorizontalAlignment.LEFT);
+ } else if (columnName.equals(SIZE_KEY)) {
+ long length = file.length();
+
+ // TODO kB, MB, etc.
+ text = Long.toString(length);
+ getStyles().put("horizontalAlignment", HorizontalAlignment.RIGHT);
+ } else if (columnName.equals(LAST_MODIFIED_KEY)) {
+ long lastModified = file.lastModified();
+ Date lastModifiedDate = new Date(lastModified);
+
+ // TODO Use an appropriate format
+ DateFormat dateFormat = DateFormat.getDateInstance();
+ text = dateFormat.format(lastModifiedDate);
+ getStyles().put("horizontalAlignment", HorizontalAlignment.RIGHT);
+ } else {
+ text = null;
+ }
+
+ setText(text);
+
+ // Update the styles
+ Object font = tableView.getStyles().get("font");
+
+ if (font instanceof Font) {
+ getStyles().put("font", font);
+ }
+
+ Object color = null;
+
+ if (tableView.isEnabled() && !rowDisabled) {
+ if (rowSelected) {
+ if (tableView.isFocused()) {
+ color = tableView.getStyles().get("selectionColor");
+ } else {
+ color = tableView.getStyles().get("inactiveSelectionColor");
+ }
+ } else {
+ color = tableView.getStyles().get("color");
+ }
+ } else {
+ color = tableView.getStyles().get("disabledColor");
+ }
+
+ if (color instanceof Color) {
+ getStyles().put("color", color);
+ }
+ }
+}
Added: incubator/pivot/trunk/demos/src/pivot/demos/dnd/FileDropTargetDemo.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/demos/src/pivot/demos/dnd/FileDropTargetDemo.java?rev=759281&view=auto
==============================================================================
--- incubator/pivot/trunk/demos/src/pivot/demos/dnd/FileDropTargetDemo.java (added)
+++ incubator/pivot/trunk/demos/src/pivot/demos/dnd/FileDropTargetDemo.java Fri Mar 27 17:43:43 2009
@@ -0,0 +1,193 @@
+/*
+ * 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
+ *
+ * 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 pivot.demos.dnd;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Comparator;
+
+import pivot.collections.Dictionary;
+import pivot.collections.List;
+import pivot.collections.ListListener;
+import pivot.collections.Sequence;
+import pivot.io.FileList;
+import pivot.io.Folder;
+import pivot.wtk.Application;
+import pivot.wtk.Button;
+import pivot.wtk.ButtonPressListener;
+import pivot.wtk.Component;
+import pivot.wtk.ComponentKeyListener;
+import pivot.wtk.Display;
+import pivot.wtk.DropAction;
+import pivot.wtk.DropTarget;
+import pivot.wtk.Keyboard;
+import pivot.wtk.Manifest;
+import pivot.wtk.MessageType;
+import pivot.wtk.Prompt;
+import pivot.wtk.PushButton;
+import pivot.wtk.Span;
+import pivot.wtk.TableView;
+import pivot.wtk.Window;
+import pivot.wtkx.WTKXSerializer;
+
+public class FileDropTargetDemo implements Application {
+ private Window window = null;
+
+ private FileList fileList = null;
+ private TableView fileTableView = null;
+ private PushButton uploadButton = null;
+
+ public void startup(Display display, Dictionary<String, String> properties)
+ throws Exception {
+ WTKXSerializer wtkxSerializer = new WTKXSerializer();
+ window = new Window((Component)wtkxSerializer.readObject(getClass().getResource("file_drop_target_demo.wtkx")));
+
+ fileTableView = (TableView)wtkxSerializer.getObjectByName("fileTableView");
+
+ fileList = new FileList();
+ fileTableView.setTableData(fileList);
+
+ fileList.getListListeners().add(new ListListener<File>() {
+ public void itemInserted(List<File> list, int index) {
+ uploadButton.setEnabled(list.getLength() > 0);
+ }
+
+ public void itemsRemoved(List<File> list, int index, Sequence<File> files) {
+ uploadButton.setEnabled(list.getLength() > 0);
+
+ if (fileTableView.isFocused()
+ && index < list.getLength()) {
+ fileTableView.setSelectedIndex(index);
+ }
+ }
+
+ public void itemUpdated(List<File> list, int index, File previousFile) {
+ // No-op
+ }
+
+ public void comparatorChanged(List<File> fileList, Comparator<File> previousComparator) {
+ // No-op
+ }
+ });
+
+ fileTableView.getComponentKeyListeners().add(new ComponentKeyListener() {
+ public boolean keyTyped(Component component, char character) {
+ return false;
+ }
+
+ public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
+ if (keyCode == Keyboard.KeyCode.DELETE
+ || keyCode == Keyboard.KeyCode.BACKSPACE) {
+ Sequence<Span> selectedRanges = fileTableView.getSelectedRanges();
+
+ for (int i = selectedRanges.getLength() - 1; i >= 0; i--) {
+ Span range = selectedRanges.get(i);
+ int index = range.getStart();
+ int count = range.getEnd() - index + 1;
+ fileList.remove(index, count);
+ }
+ }
+
+ return false;
+ }
+
+ public boolean keyReleased(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
+ return false;
+ }
+ });
+
+ fileTableView.setDropTarget(new DropTarget() {
+ public DropAction dragEnter(Component component, Manifest dragContent,
+ int supportedDropActions, DropAction userDropAction) {
+ DropAction dropAction = null;
+
+ if (dragContent.containsFileList()
+ && DropAction.COPY.isSelected(supportedDropActions)) {
+ dropAction = DropAction.COPY;
+ }
+
+ return dropAction;
+ }
+
+ public void dragExit(Component component) {
+ }
+
+ public DropAction dragMove(Component component, Manifest dragContent,
+ int supportedDropActions, int x, int y, DropAction userDropAction) {
+ return (dragContent.containsFileList() ? DropAction.COPY : null);
+ }
+
+ public DropAction userDropActionChange(Component component, Manifest dragContent,
+ int supportedDropActions, int x, int y, DropAction userDropAction) {
+ return (dragContent.containsFileList() ? DropAction.COPY : null);
+ }
+
+ public DropAction drop(Component component, Manifest dragContent,
+ int supportedDropActions, int x, int y, DropAction userDropAction) {
+ DropAction dropAction = null;
+
+ if (dragContent.containsFileList()) {
+ try {
+ FileList tableData = (FileList)fileTableView.getTableData();
+ FileList fileList = dragContent.getFileList();
+ for (File file : fileList) {
+ if (file instanceof Folder) {
+ tableData.add((Folder)file);
+ } else {
+ tableData.add(file);
+ }
+ }
+
+ dropAction = DropAction.COPY;
+ } catch(IOException exception) {
+ System.err.println(exception);
+ }
+ }
+
+ dragExit(component);
+
+ return dropAction;
+ }
+ });
+
+ uploadButton = (PushButton)wtkxSerializer.getObjectByName("uploadButton");
+ uploadButton.getButtonPressListeners().add(new ButtonPressListener() {
+ public void buttonPressed(Button button) {
+ Prompt.prompt(MessageType.INFO, "Pretending to upload...", window);
+ }
+ });
+
+ window.setTitle("File Drop Target Demo");
+ window.setMaximized(true);
+ window.open(display);
+ }
+
+ public boolean shutdown(boolean optional) throws Exception {
+ if (window != null) {
+ window.close();
+ }
+
+ window = null;
+
+ return false;
+ }
+
+ public void suspend() {
+ }
+
+ public void resume() {
+ }
+}
Added: incubator/pivot/trunk/demos/src/pivot/demos/dnd/file_drop_target_demo.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/demos/src/pivot/demos/dnd/file_drop_target_demo.wtkx?rev=759281&view=auto
==============================================================================
--- incubator/pivot/trunk/demos/src/pivot/demos/dnd/file_drop_target_demo.wtkx (added)
+++ incubator/pivot/trunk/demos/src/pivot/demos/dnd/file_drop_target_demo.wtkx Fri Mar 27 17:43:43 2009
@@ -0,0 +1,66 @@
+<?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
+
+ 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.
+-->
+
+<TablePane xmlns:wtkx="http://incubator.apache.org/pivot/wtkx/1.1"
+ xmlns:dnd="pivot.demos.dnd"
+ xmlns="pivot.wtk">
+ <columns>
+ <TablePane.Column width="1*"/>
+ </columns>
+ <rows>
+ <TablePane.Row height="1*">
+ <Border styles="{color:10, padding:0}">
+ <content>
+ <ScrollPane horizontalScrollBarPolicy="fillToCapacity"
+ verticalScrollBarPolicy="fillToCapacity">
+ <view>
+ <TableView wtkx:id="fileTableView" selectMode="multi"
+ styles="{showHorizontalGridLines:false}">
+ <columns>
+ <TableView.Column name="name" width="180" headerData="File">
+ <cellRenderer>
+ <dnd:FileCellRenderer/>
+ </cellRenderer>
+ </TableView.Column>
+ <TableView.Column name="size" width="60" headerData="Size">
+ <cellRenderer>
+ <dnd:FileCellRenderer/>
+ </cellRenderer>
+ </TableView.Column>
+ <TableView.Column name="lastModified" width="120" headerData="Modified">
+ <cellRenderer>
+ <dnd:FileCellRenderer/>
+ </cellRenderer>
+ </TableView.Column>
+ </columns>
+ </TableView>
+ </view>
+ <columnHeader>
+ <TableViewHeader tableView="$fileTableView" styles="{headersPressable:false}"/>
+ </columnHeader>
+ </ScrollPane>
+ </content>
+ </Border>
+ </TablePane.Row>
+ <TablePane.Row height="-1">
+ <FlowPane styles="{padding:6, horizontalAlignment:'right', verticalAlignment:'center'}">
+ <PushButton wtkx:id="uploadButton" buttonData="Upload"
+ enabled="false" styles="{preferredAspectRatio:3}"/>
+ </FlowPane>
+ </TablePane.Row>
+ </rows>
+</TablePane>
Modified: incubator/pivot/trunk/demos/src/pivot/demos/filebrowser/file_browser_demo.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/demos/src/pivot/demos/filebrowser/file_browser_demo.wtkx?rev=759281&r1=759280&r2=759281&view=diff
==============================================================================
--- incubator/pivot/trunk/demos/src/pivot/demos/filebrowser/file_browser_demo.wtkx (original)
+++ incubator/pivot/trunk/demos/src/pivot/demos/filebrowser/file_browser_demo.wtkx Fri Mar 27 17:43:43 2009
@@ -17,7 +17,6 @@
<Border styles="{color:10, padding:0}"
xmlns:wtkx="http://incubator.apache.org/pivot/wtkx/1.1"
- xmlns:collections="pivot.collections"
xmlns:content="pivot.wtk.content"
xmlns="pivot.wtk">
<content>