⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filebrowser.java.svn-base

📁 j2me mobile application for upload file to server.
💻 SVN-BASE
字号:
/* *  * Copyright © 2007 Sun Microsystems, Inc. All rights reserved. Use is subject * to license terms. */package org.celllife.clforms;import java.io.IOException;import java.util.Enumeration;import javax.microedition.lcdui.Command;import javax.microedition.lcdui.Displayable;import javax.microedition.lcdui.Image;import javax.microedition.lcdui.List;import org.celllife.clforms.task.BrowseTask;import org.celllife.clforms.task.IOTask;/** * Demonstration MIDlet for File Connection API. This MIDlet implements simple * file browser for the filesystem available to the J2ME applications. *  */public class FileBrowser extends MVCComponent {	/* special string denotes upper directory */	private static final String UP_DIRECTORY = "..";	/*	 * special string that denotes upper directory accessible by this browser.	 * this virtual directory contains all roots.	 */	public static final String MEGA_ROOT = "/";	/* separator string as defined by FC specification */	private static final String SEP_STR = "/";	public static final String SERVER_URL = "file://localhost/";	/* separator character as defined by FC specification */	private static final char SEP = '/';	private static String currDirName;	private static Command view = new Command("View", Command.ITEM, 1);	private static Command back = new Command("Back", Command.BACK, 2);	private static Command cancel = new Command("Cancel", Command.EXIT, 3);	private static Image dirIcon;	private static Image fileIcon;	private static Enumeration dirEnum;	private static Displayable screen = null;	public FileBrowser(Enumeration dirEnum) {		FileBrowser.dirEnum = dirEnum;	}	public void initModel() {		//#debug debug		System.out.println("FB init model");				currDirName = MEGA_ROOT;		try {			dirIcon = Image.createImage("/icons/dir.png");		} catch (IOException e) {			dirIcon = null;		}		try {			fileIcon = Image.createImage("/icons/file.png");		} catch (IOException e) {			fileIcon = null;		}	}	protected void createView() {		//#debug debug		System.out.println("FB create view");				updateView();		//		try {		//			showCurrDir();		//		} catch (SecurityException e) {		//			Form form = new Form("Cannot access FileConnection");		//			form		//					.append(new StringItem(		//							null,		//							"You cannot run this MIDlet with the current permissions. "		//									+ "Sign the MIDlet suite, or run it in a different security domain"));		//			form.addCommand(cancel);		//			form.setCommandListener(this);		//			screen = form;		//		} catch (Exception e) {		//			e.printStackTrace();		//		}	}	public void commandAction(Command c, Displayable d) {		if (c == view) {			List curr = (List) d;			String currFile = curr.getString(curr.getSelectedIndex());			if (currFile.endsWith(SEP_STR) || currFile.equals(UP_DIRECTORY)) {				//#debug debug				System.out.println("dir: " + currDirName + " - file: " + currFile);				traverseDirectory(currFile);			} else {				IOTask t = new IOTask(SERVER_URL + currDirName + currFile, display, true);				t.go();				// Show file contents				// selectFile(currFile);			}		} else if (c == back) {			showScreen();		} else if (c == cancel) {			(new XFormScreen()).showScreen();		}	}	/**	 * Show file list in the current directory .	 */	protected void updateView() {		screen = new List(currDirName, List.IMPLICIT);		//#debug debug		System.out.println("update: " + currDirName);		if (!MEGA_ROOT.equals(currDirName)) {			System.out.println("not root");			((List) screen).append(UP_DIRECTORY, dirIcon);		}		while (dirEnum.hasMoreElements()) {			String fileName = (String) dirEnum.nextElement();			if (fileName.charAt(fileName.length() - 1) == SEP) {				// This is directory				((List) screen).append(fileName, dirIcon);			} else {				// this is regular file				((List) screen).append(fileName, fileIcon);			}		}		((List) screen).setSelectCommand(view);		screen.addCommand(cancel);	}	private void traverseDirectory(String fileName) {		/*		 * In case of directory just change the current directory and show it		 */		if (currDirName.equals(MEGA_ROOT)) {			if (fileName.equals(UP_DIRECTORY)) {				// can not go up from MEGA_ROOT				return;			}			currDirName = fileName;		} else if (fileName.equals(UP_DIRECTORY)) {			// Go up one directory			// TODO use setFileConnection when implemented			int i = currDirName.lastIndexOf(SEP, currDirName.length() - 2);			if (i != -1) {				currDirName = currDirName.substring(0, i + 1);			} else {				currDirName = MEGA_ROOT;			}		} else {			currDirName = currDirName + fileName;		}		//#debug debug		System.out.println("Browse to: " + currDirName);				BrowseTask b = new BrowseTask(currDirName, display);		b.go();	}	/*	 * (non-Javadoc)	 * 	 * @see org.celllife.clforms.MVCComponent#getScreen()	 */	public Displayable getScreen() {		return screen;	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -