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
How to monitor OSD TS failure and get some alert or generate an report? We have SCCM 2012 R2 CU1 with MDT 2013. I have checked the OSD reports in SCCM and everyone is emty, where do SCCM get data to the what to activate? (I thinking of "Task Sequence [More]
I've noticed that when I enter the reader on safari 5.1 for Lion, it doesn't remember the font size. I like to read articles on the maximum font size. But when I go into another article it sometimes goes back down to the small size. Has anyone else e [More]
Hi, While I try to insert into an MLS entity created in the Fusion Development Environment I am getting the following error: (oracle.jbo.RowCreateException) JBO-25017: Error while creating a new entity row for PERJOBSEO. ----- Level 1: Detail 0 ----- [More]
Hi, I have a problem with my invoice mapping. I need to exclude children parts from the outbound EDI invoice. In my mapping I was able to control the number of lines that should go out from the top line item node level using: G_SIT1 ->  If E1EDP02-QU [More]
Hello all, I am trying to deploy EMET to our organization, but I notice on my test installation on a Windows 7 PC, systemwide DEP was not enabled by default. I figured I can activate this through the command line, but I seem to be running into some t [More]
So I've upgraded to PP CC 2014, it worked fine for a while. Then I've noticed that while editing audio starts to dropout (I'm getting PP system message in the low right corner). I tried to dig up some info on the subject, but the only explanation I s [More]
See the top item in the FAQ list: http://forums.adobe.com/community/premiere/faq_list If you see questions about pricing, orders, shipping, downloads, activation, and such, you can just point people to this new FAQ entry.Great, and thank you! HuntRea [More]
Hi How can I delete a table entry which was entered in the Table through a Std Txn? I have heard that there are 3 ways: 1) SM30 2) SE16 3) Debugger What are the necessary requirements for using each of the above methods? Please guide me through the s [More]
I'm having a problem with navigation on a project, specifically the next button navigation. I have a dual layer disc with 7 20 minute shows. Track 1 = show 1, etc. Play All button leads to Track 1. End jump of Track 1 is set to Track 2 and so on unti [More]
Ever since I replaced by old Apple Base Extreme 802.11g router with an Apple Base Extreme 802.11n router, my HP Photosmart C6100 can no longer print wirelessly. Since nothing else has changed, I fear that the C6100 is incompatible with the 802.11n ro [More]