No I store last location by invoking getCurrentDirectory() and setCurrentDirectory(), this works but the Look-In combo is not showing that directory, but I see the files in the diretory.
This is the use case.
File / Open
I start in / (The Look-In combo shows /) and I see all files in the root dir on the unix filesystem.
I double click on temp directory and I get all files inside temp directory. But the Look-In combobox is still / but should be temp.
When I press "Go up" i go back to the root. I see all files in the root. And the Look-In is /.
Observe that this behaviour is ONLY when I use windows GUI and browsing unix filesystem.
When I am using Unix GUI the Look-In combo changes as expected.
Here is my RemoteFile object that is invoked by the RemoteFSView class which is used by JFileChooser.
package cmg.services.remotefs;
import cmg.services.remotefs.File
import cmg.services.Services;
import cmg.services.ServiceNotAva
import javax.swing.filechooser.Fi
import java.io.*;
import java.util.*;
import java.rmi.*;
public class RemoteFile extends File {
private String path; // universal path
private FileServer fileServer = null;
public static String SEPARATOR = "/";
public RemoteFile(File parent, String child) {
this(parent.getAbsolutePat
}
public RemoteFile(String path) {
super(path);
this.path = canonicalPath(path);
//this.path = super.getPath();//NON ORIGINAL
}
FileServer getFileServer() throws RemoteException
{
FileServer fileServer = null;
try
{
fileServer = Services.getConfigManager(
}
catch (ServiceNotAvailableExcept
{
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
return fileServer;
}
public boolean canRead() {
try {
if (isRoot()) return true;
return getFileServer().canRead(pa
} catch(RemoteException e) {System.out.println(e);}
return false;
}
public boolean canWrite() {
try {
if (isRoot()) return false;
return getFileServer().canWrite(p
} catch(RemoteException e) {System.out.println(e);}
return false;
}
public boolean createNewFile() throws IOException {
try {
if (isRoot()) return false;
return getFileServer().createNewF
} catch(RemoteException e) {System.out.println(e);}
return false;
}
public boolean delete() {
try {
if (isRoot()) return false;
return getFileServer().delete(pat
} catch(RemoteException e) {System.out.println(e);}
return false;
}
public void deleteOnExit() {
try {
if (isRoot()) return;
getFileServer().deleteOnEx
} catch(RemoteException e) {System.out.println(e);}
}
public boolean equals(Object obj) {
if (obj instanceof RemoteFile) {
RemoteFile file = (RemoteFile)obj;
return file.getPath().equals(path
}
return false;
}
public boolean exists() {
try {
if (isRoot()) return true;
return getFileServer().exists(pat
} catch(RemoteException e) {System.out.println(e);}
return false;
}
public File getAbsoluteFile() {
return this;
}
public String getAbsolutePath() {
return path;
}
public File getCanonicalFile() {
return new RemoteFile(path);
}
public String getCanonicalPath() {
return path;
}
public String getName() {
if (isRoot()) return SEPARATOR;
/*
int i = path.lastIndexOf(SEPARATOR
if (i < 0) return "";
return path.substring(i+1);*/
String result=null;
StringTokenizer st = new StringTokenizer(path, PATHDELIMS);
while (st.hasMoreTokens())
result = st.nextToken();
if (result == null || (result.length()>1 && result.charAt(1) == ':'))
result = "";
return result;
}
final static String PATHDELIMS = "/\\";
public String getParent() {
if (isRoot()) return null;
return getParentFile().getPath();
}
public File getParentFile() {
if (isRoot()) return null;
return new RemoteFile(path+SEPARATOR+
}
public String getPath() {
/* if (path.equals("/C:\\temp"))
return "c:\\temp"; //****ED with c:\\/temp
if (path.equals("/C:\\/temp")
return "c:\\temp"; //****ED with c:\\/temp*/
return path;
}
public boolean isAbsolute() {
return path.indexOf(SEPARATOR) == 0;
// return true;
}
public boolean isDirectory() {
try {
if (isRoot()) return true;
return getFileServer().isDirector
} catch(RemoteException e) {System.out.println(e);}
return false;
}
public boolean isFile() {
try {
if (isRoot()) return false;
return getFileServer().isFile(pat
} catch(RemoteException e) {System.out.println(e);}
return false;
}
public boolean isHidden() {
try {
if (isRoot()) return false;
return getFileServer().isHidden(p
} catch(RemoteException e) {System.out.println(e);}
return false;
}
public long lastModified() {
try {
//if (isRoot()) return getDirectoryServer().lastM
return getFileServer().lastModifi
} catch(RemoteException e) {System.out.println(e);}
return 0L;
}
public long length() {
try {
if (isRoot()) return 0L;
return getFileServer().length(pat
} catch(RemoteException e) {
System.out.println(e);
}
return 0L;
}
public String[] list() {
try {
if (isRoot())
{
/*System.out.println("Root
File[] files = FileSystemView.getFileSyst
String[] paths = new String[files.length];
for(int i=0; i<files.length; i++) {
paths[i] = files[i].getAbsolutePath()
}
return paths;*/
}
/* File[] files = getDirectoryServer().getRo
String[] paths = new String[files.length];
for(int i=0; i<files.length; i++) {
paths[i] = files[i].getAbsolutePath()
}
return paths;
}*/
String[] list = getFileServer().list(path)
System.out.println("Lista:
return list;
} catch(RemoteException e) {
System.out.println("Remote
}
return null;
}
public String[] list(FilenameFilter filter) {
String[] paths = this.list();
if (filter == null) return paths;
ArrayList a = new ArrayList();
for(int i=0; i<paths.length; i++) {
if (filter.accept(this,paths[
}
String[] s = new String[a.size()];
for(int i=0; i<s.length; i++) s[i] = (String)a.get(i);
return s;
}
public File[] listFiles() {
String[] files = this.list();
RemoteFile[] f = new RemoteFile[files.length];
for(int i=0; i<files.length; i++) {
f[i] = new RemoteFile(files[i]);
}
return f;
}
public File[] listFiles(FileFilter filter) {
String[] files = this.list();
ArrayList a = new ArrayList();
for(int i=0; i<files.length; i++) {
if (filter.accept(new RemoteFile(files[i]))) a.add(files[i]);
}
RemoteFile[] s = new RemoteFile[a.size()];
for(int i=0; i<s.length; i++) s[i] = new RemoteFile((String)a.get(i
return s;
}
public File[] listFiles(FilenameFilter filter) {
String[] files = this.list(filter);
RemoteFile[] f = new RemoteFile[files.length];
for(int i=0; i<files.length; i++) {
f[i] = new RemoteFile(files[i]);
}
return f;
}
public boolean mkdir() {
try {
if (isRoot()) return false;
return getFileServer().mkdir(path
} catch(RemoteException e) {System.out.println(e);}
return false;
}
public boolean mkdirs() {
try {
if (isRoot()) return false;
return getFileServer().mkdirs(pat
} catch(RemoteException e) {System.out.println(e);}
return false;
}
public boolean renameTo(File dest) {
try {
if (isRoot()) return false;
return getFileServer().renameTo(p
} catch(RemoteException e) {System.out.println(e);}
return false;
}
public boolean setLastModified(long time) {
try {
if (isRoot()) return false;
return getFileServer().setLastMod
} catch(RemoteException e) {System.out.println(e);}
return false;
}
public boolean isRoot() { // single root version
return path.equals(SEPARATOR);
}
public boolean isLockedByExclusive() {
return false;
}
public boolean isLockedByShared() {
return false;
}
public boolean lockByExclusive() {
return false;
}
public boolean lockByShared() {
return false;
}
String canonicalPath(String path) {
StringTokenizer st = new StringTokenizer(path,SEPAR
ArrayList a = new ArrayList();
while(st.hasMoreTokens()) {
String token = st.nextToken();
//System.out.print(token+"
if (token.equals("")) continue;
if (token.equals(".")) continue;
if (token.equals("..")) {
if (a.size() > 0) a.remove(a.size()-1);
}
else a.add(token);
}
//System.out.println("");
if (a.size() == 0) return SEPARATOR;
StringBuffer sb = new StringBuffer();
for(int i=0; i<a.size(); i++) {
sb.append(SEPARATOR);
sb.append((String)a.get(i)
}
return sb.toString();
}
public int hashCode() {
return path.hashCode() ^ 1234321;
}
}
Main Topics
Browse All Topics





by: maheshexpPosted on 2004-05-22 at 09:50:56ID: 11133781
if i am right ur problem is that u need to open the location where u last browsed right???
if so, store the location while u r browsing or clicking ok or cancel or etc....and then when u show up the dialog again set to that old location. the best idea to do is
1. either u override the existing class with a extra variable called previous location or
2. just update the path with a variable in the existing Dialog.
=============
S.M.W