Sitemap

Amicuk Programming Answers

JFileChooser and remote filesystems

-0001-11-30   Views:4

Advertisement

I want to add(among local file system) a few remote filesystems to JFileChooser , I implemented FileSytestemVIew(FileSystem) and File(RemoteFile) class. At the first glance everything looks ok - i can see local folders and remote root folder(in combo

I want to add(among local file system) a few remote filesystems to JFileChooser ,
I implemented FileSytestemVIew(FileSystem) and File(RemoteFile) class.
At the first glance everything looks ok - i can see local folders and remote root folder(in combo box), when i choose remote root i can see remote folders and files, but when i invoke double click to enter remote folders, exception occurs.
for some reason JFileChooser sees 'ordinary' File - not my RemoteFile, and it treats it as a file (not folder) and wants to open it (approveSelection fires)
Probably i did not implemented all the methods that are used ..
Any ideas ? maybe there are some other ways to explore remote filesystems ?
package pl.edu.pw.browser;
import javax.swing.filechooser.FileSystemView;
import java.io.File;
import java.io.IOException;
import pl.edu.pw.fileserver.client.Client;
import java.util.*;
import javax.swing.Icon;
public class FileSystem extends FileSystemView {
public FileSystem(ArrayList servers) {
this.servers=servers;
public File createFileObject(File dir, String filename) {
System.out.println("createFileObject1");
if (dir instanceof RemoteFile )
return new RemoteFile(((RemoteFile)dir).getFtp(),dir.getAbsolutePath(), filename);
return super.createFileObject(dir,filename);
public boolean isDrive(File dir)
if (dir instanceof RemoteFile )
return false;
return super.isDrive(dir);
public boolean isFloppyDrive(File dir)
if (dir instanceof RemoteFile )
return false;
return super.isFloppyDrive(dir);
public boolean isComputerNode(File dir)
if (dir instanceof RemoteFile)
if(servers.contains(dir))
return true;
else
return false;
return super.isComputerNode(dir);
public File createFileObject(String path) {
return null;
public boolean isFileSystem(File f) {
System.out.println("isFileSystem");
if (f instanceof RemoteFile) {
return false;
} else
return super.isFileSystem(f);
public boolean isFileSystemRoot(File dir)
System.out.println("isFileSystemRoot");
if (dir instanceof RemoteFile)
if(servers.contains(dir))
return true;
else
return false;
return super.isFileSystemRoot(dir);
public boolean isRoot(File f) {
System.out.println("isRoot");
if (f instanceof RemoteFile )
if(servers.contains(f))
return true;
else
return false;
return super.isRoot(f);
public String getSystemTypeDescription(File f)
if (f instanceof RemoteFile)
return f.getName();
return super.getSystemTypeDescription(f);
public Icon getSystemIcon(File f)
return super.getSystemIcon(f);
public boolean isParent(File folder,
File file)
if (folder instanceof RemoteFile && file instanceof RemoteFile )
System.out.println("isParent("+folder.getAbsolutePath()+")("+file.getAbsolutePath()+")");
if(file.getParent().equals(folder.getAbsolutePath()))
System.out.println("is");
return true;
else
return false;
return super.isParent(folder,file);
public File getChild(File parent,
String fileName)
System.out.println("getChild");
if (parent instanceof RemoteFile )
return new RemoteFile(((RemoteFile)parent).getFtp(),parent.getAbsolutePath(),fileName);
return super.getChild(parent,fileName);
public File createNewFolder(File containingDir)
throws IOException {
System.out.println("createNewFolder");
if (containingDir instanceof RemoteFile )
return null;
return new File(containingDir,"/nowyFolder");
public String getSystemDisplayName(File f)
if (f instanceof RemoteFile )
return f.getName();
else
return super.getSystemDisplayName(f);
public File[] getRoots()
System.out.println("getRoots");
File[] files = super.getRoots();
File[] fileAll = new File[files.length+1];
int i=0;
for(i=0;i<files.length;i++)
fileAll=files[i];
fileAll[i]=createFileSystemRoot((RemoteFile)servers.get(0));
return fileAll;
public boolean isHiddenFile(File f) {
return f.isHidden();
public File getParentDirectory(File dir) {
System.out.println("getParentDirectory");
if (dir instanceof RemoteFile)
String p = dir.getParent();
if(p!=null)
return new RemoteFile(((RemoteFile)dir).getFtp(),p);
else
return null;
else
return super.getParentDirectory(dir);
protected File createFileSystemRoot(File f)
System.out.println("createFileSystemRoot");
if (f instanceof RemoteFile)
return new FileSystemRoot( (RemoteFile) f);
else
return super.createFileSystemRoot(f);
static class FileSystemRoot extends RemoteFile {
public FileSystemRoot(RemoteFile f) {
super(f.getFtp(),f.getAbsolutePath());
public File[] getFiles(File dir, boolean useFileHiding) {
if (dir instanceof RemoteFile)
RemoteFile[] files = (RemoteFile[])( (RemoteFile) dir).listFiles();
return files;
else
return dir.listFiles();
public File getHomeDirectory() {
return super.getHomeDirectory();
ArrayList servers = null;
package pl.edu.pw.browser;
import java.io.File;
import java.io.FilenameFilter;
import java.io.FileFilter;
import pl.edu.pw.fileserver.client.Client;
import java.util.*;
import java.text.*;
import pl.edu.pw.fileserver.Constants;
public class RemoteFile extends File {
final static char PATHDELIMS = '/';
public final static String absoluteStart = "//";
public RemoteFile(Client ftp, String parent) {
super(parent);
this.ftp = ftp;
path = parent;
public RemoteFile(Client ftp, String parent, String name) {
this(ftp, parent);
if (path.length()>0 && path.charAt(path.length()-1) == PATHDELIMS)
path += name;
else
path += PATHDELIMS + name;
public boolean equals(Object obj) {
if (!checked)
exists();
return path.equals(obj.toString());
public boolean isDirectory() {
if (!checked)
exists();
return isdirectory;
public boolean isFile() {
if (!checked)
exists();
return isfile;
public boolean isAbsolute() {
if (!checked)
exists();
return path.length() > 0 && path.startsWith(this.absoluteStart);
public boolean isHidden() {
if (!checked)
exists();
return ishidden;
public long lastModified() {
return modified;
public long length() {
return length;
public String[] list() {
return list(null);
public String[] list(FilenameFilter filter) {
System.out.println("list");
String[] result = null;
try{
ArrayList names = (ArrayList)ftp.dir(this.getAbsolutePath());
ArrayList files = new ArrayList();
for(int i=0;i<names.size();i++)
RemoteFile rf = new RemoteFile(ftp,(String)names.get(i));
if (filter == null || filter.accept(this,rf.getName()))
files.add(rf.getName());
result = new String[files.size()];
files.toArray(result);
catch(Exception ex)
ex.printStackTrace();
return result;
public File[] listFiles() {
FileFilter filter = null;
return listFiles(filter);
public File[] listFiles(FileFilter filter) {
System.out.println("listFiles");
RemoteFile[] result = null;
try{
ArrayList names = (ArrayList)ftp.dir(this.getAbsolutePath());
ArrayList files = new ArrayList();
for(int i=0;i<names.size();i++)
RemoteFile rf = new RemoteFile(ftp,(String)names.get(i));
rf.exists();
if (filter == null || filter.accept(rf))
files.add(rf);
result = new RemoteFile[files.size()];
System.out.println("listFiles.size="+files.size());
files.toArray(result);
catch(Exception ex)
ex.printStackTrace();
return result;
public String getPath() {
return path;
public String getCanonicalPath() {
return getAbsolutePath();
public String getAbsolutePath() {
if (!isAbsolute()) {
return ftp.pwd();
return path;
public String getName() {
String result=path;
if(result.charAt(result.length()-1) == this.PATHDELIMS)
result = result.substring(0,result.length()-1);
int i = result.lastIndexOf(this.PATHDELIMS);
if(i!=-1)
result = result.substring(i+1);
return result;
public String getParent() {
String result=path;
if(result.charAt(result.length()-1) == this.PATHDELIMS)
result = result.substring(0,result.length()-1);
int i = result.lastIndexOf(this.PATHDELIMS);
if(i<3)
return null;
result = result.substring(0,i);
return result;
public boolean exists() {
boolean ok = false;
try {
String r = ftp.exists(path);
if(r != null)
System.out.println("('"+path+"')header:"+r);
ok = true;
StringTokenizer st = new StringTokenizer(r,Constants.HEADER_SEPARATOR);
String answer = st.nextToken();
if(answer.equals(Constants.TRUE))
isfile=true;
isdirectory=false;
answer = st.nextToken();
if(answer.equals(Constants.TRUE))
canread = true;
answer = st.nextToken();
if(answer.equals(Constants.TRUE))
canwrite = true;
answer = st.nextToken();
if(answer.equals(Constants.TRUE))
ishidden = true;
answer = st.nextToken();
length = Long.parseLong(answer);
if(isfile)
answer = st.nextToken();
modified = Long.parseLong(answer);
checked = true;
catch (Exception ex) {
ex.printStackTrace();
return ok;
public boolean canRead() {
return canread;
public boolean canWrite() {
return canwrite;
public int hashCode() {
return path.hashCode() ^ 098123;
public boolean mkdir() {
return false;
public boolean renameTo(File dest) {
return false;
public Client getFtp() {
return ftp;
private Client ftp;
private boolean checked = false;
private boolean isdirectory = true;
private boolean isfile = false;
private boolean ishidden = false;
private boolean canread = false;
private boolean canwrite = false;
private String path;
private long length = 0;
private long modified =0;
java.lang.NullPointerException
     at pl.edu.pw.browser.Browser.openLocalFile(Browser.java:136)
     at pl.edu.pw.browser.component.FileChooser.approveSelection(FileChooser.java:31)
     at javax.swing.plaf.basic.BasicFileChooserUI$DoubleClickListener.mouseClicked(BasicFileChooserUI.java:412)
     at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:208)
     at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:207)
     at java.awt.Component.processMouseEvent(Component.java:5137)
     at java.awt.Component.processEvent(Component.java:4931)
     at java.awt.Container.processEvent(Container.java:1566)
     at java.awt.Component.dispatchEventImpl(Component.java:3639)
     at java.awt.Container.dispatchEventImpl(Container.java:1623)
     at java.awt.Component.dispatchEvent(Component.java:3480)
     at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)
     at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3174)
     at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
     at java.awt.Container.dispatchEventImpl(Container.java:1609)
     at java.awt.Window.dispatchEventImpl(Window.java:1590)
     at java.awt.Component.dispatchEvent(Component.java:3480)
     at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
     at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
     at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
     at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)

The replay answer
Advertisement
i solve the problem .
I did not overwrite File.getConicalFile() , this method is invoked at javax.swing.plaf.basic.BasicFileChooserUI$DoubleClickListener.mouseClicked(BasicFileChooserUI.java:412)
that is why i recived a new object type File when I was waiting for RemoteFile

Go to See the other 2 answers

JFileChooser and remote filesystems

Category:DefaultRelease time:-0001-11-30Views:130

I want to add(among local file system) a few remote filesystems to JFileChooser , I implemented FileSytestemVIew(FileSystem) and File(RemoteFile) class. At the first glance everything looks ok - i can see local folders and remote root folder(in combo[More]

I want to know about the role of AS application binaries, remote filesystems, and local filesystems in building a development environment on the iplanet application server.

Category:DefaultRelease time:-0001-11-30Views:130

 I think you need to be more specific in your question. The typical development environment involves the developer having his own copy of the application server binaries, executing code off of the local filesystem, and developing on the local filesys[More]

Mouting remote filesystem with "union" is broken

Category:DefaultRelease time:-0001-11-30Views:130

When mounting remote filesystems (afp and smb from a NAS server) in union mode is really broken in Yosemite. "local" files are visible from a terminal shell with "ls". But they do not show in Finder. Weird. Also, I have my iTunes Media[More]

Jfilechooser on remote directories

Category:DefaultRelease time:-0001-11-30Views:130

Hi guy's I wish to create a java swing applet to use the jfilechooser to browse the directory structure of a remote server. what is the best way of going aboput doing this? thanks in advance DannyBack when there was only SunOS (Solaris 1 as it's know[More]

Filechooser for a remote filesystem

Category:DefaultRelease time:-0001-11-30Views:130

Hi, I wish to show a remote file system graphically. I have tried overriding the methods of FileSystemView and use JFileChooser, but I failed. Then I thought of using the JTree class. The idea is good, but I want to show the filesize along with the n[More]

File Chooser in a Panel - please help

Category:DefaultRelease time:2015-10-11Views:130

Hello! I am implementing a FTP program as part of an assignment. Can you please tell me how I can get a File Chooser like interface to the files on the remote computer? Can the existing JFileChooser be modified to support this and also can it be embe[More]

RMI -How to use JFileChooser to see remote computer FileSystem

Category:DefaultRelease time:-0001-11-30Views:130

i hav made a program in RMI which uses JFileChooser to show remote-machine File System. i have made my own FileSyatemView class (MyFileSyatemViewClient which extends FileSystemView) and override all the methods of FileSystemView Except getFileSystemV[More]

Mount point for SMB filesystem

Category:DefaultRelease time:-0001-11-30Views:130

Hi folks Using the finder I've connected to a Windows box drive "D" and get a icon on the desktop. This contains GIS data. I'm using an OpenSource application GRASS and want to use that data. GRASS opens a dialogue box which wants an input of th[More]

Performance KM repository - Filesystem vs. WebDAV

Category:DefaultRelease time:-0001-11-30Views:130

Hi, I'm a newbie to KM repositories so I hope this question makes sense. I've got 2 Filesystem Repositories in my KM. One server is remote and reachable via a 4 MBit/s cable, the other one is located within the intranet. When I browse both filesystem[More]

Remote shares....

Category:DefaultRelease time:-0001-11-30Views:130

I setup WebLogic 5.1.0 Server last week on a Solaris 8 machine. The developers here told me that they need to be able to mount the weblogic directory on their local machines(Win2k, 98, 95, NT). I am playing around with SAMBA, but I wanted to make sur[More]

Jspsmartupload.. Everything works fine but i cannot figure out remote uploa

Category:DefaultRelease time:-0001-11-30Views:130

I can upload to the filesystem that jsmsmart runs on. Problem is that I want to upload to a remote filesystem. something like 216.xx.xx.xx/myFolder. Is this possible? Does anyone have any idea how to do this if its not possible with jspsmart? Thanks[More]

Hot
When I import in string format and after try to convert to number sometimes my procedure fails. I see that sometimes database need number string decimal symbol to be '.' and I replace ',' with '.' . But time after I find that I must change my procedu [More]
i have both the latest upgrades of the Desktop Manager and OS on my 8330 curve when i connect it to my pc via usb in the bottom corner it shows just connecting. it never actually connects i used windows XP 32bitHiya!  Ok so as I am understanding this [More]
I have a rather large Numbers spreadsheet.  I have used a formula to create a new column of information.  I now want to replace the formula with the actual results calculated by that formula for each cell in that column, so that I can delete some of [More]
i tried to download the secirity update for my mac, but it says it cannot be found?  is this spam? or a virus? or what? i dont understand why i cannot, update or download my security update from my mac?I'm assuming that you are talking about download [More]
Several versions of Thuderbird in the past, e-mail was stored in roughly one file per e-mail "folder". A few versions ago this changed and the number of files in my "profile" folder exploded from around one hundred to almost 120 thousa [More]
I spent all day manually locating hundreds of missing 'offline media' in a project, saving as I went. Premier Elements crashed when this was complete, now I try to open the project after rebooting and it either cannot find them again or crashes when [More]
will i be charged for downloading songs i haev previously brought?Follow the instructions here: Downloading past purchases from the App Store, iBookstore, and iTunes Store You will have to be signed into the account that purchased them to redownload [More]
I was in the process of redeeming my free upgrade to Mountain Lion today, and received a message in the "redeem" section of the App store that the redemption code had already been used. It hadn't been, unless there's a glitch in Apple's system t [More]
I received Photoshop Elements 10 installed on my new Windows computer.  When I try to use it, in EDIT mode, I immediately get the error code "213:19" and am told to contact support for a configuration issue. What can I do, as I've already loaded [More]
Hello, guys. I am using Mac Air 13-inch. I note the volume of sound from iTunes and Youtube is lower than before, and when i use a third part MP3 music player software the sound is normal( not lower than before). Who could tell me what happened on my [More]