00001 package gui.Toolbars; 00002 00003 import gui.debugging.Debug; 00004 00005 import java.io.File; 00006 import java.util.ArrayList; 00007 00008 import javax.swing.JFileChooser; 00009 import javax.swing.JFrame; 00010 00011 import commandline.NormalMeshAlgorithm.Configuration; 00012 import commandline.NormalMeshAlgorithm.Extensions; 00013 00032 public class MyFileChooser extends JFileChooser implements FileChangePublisher { 00033 00034 JFrame frame; 00035 FileChangeHandler fileChangeHandler; 00036 00037 ArrayList<FileChangeListener> fileChangeListeners; 00038 private Configuration conf; 00039 00040 public MyFileChooser(Configuration conf) { 00041 00042 this.conf = conf; 00043 fileChangeListeners = new ArrayList<FileChangeListener>(); 00044 // Note: source for ExampleFileFilter can be found in FileChooserDemo, 00045 // under the demo/jfc directory in the Java 2 SDK, Standard Edition. 00046 ExampleFileFilter filter = new ExampleFileFilter(); 00047 filter.addExtension("bmp"); 00048 filter.addExtension("jpg"); 00049 filter.addExtension("gif"); 00050 filter.addExtension(Extensions.decodeExtension); 00051 filter.setDescription("JPG, GIF & BMP Images & ." 00052 + Extensions.decodeExtension + " files"); 00053 this.setFileFilter(filter); 00054 00055 } 00056 00057 public void connectToFrame(JFrame frame) { 00058 this.frame = frame; 00059 } 00060 00061 public void openBox(int type) { 00062 if (frame == null) { 00063 System.out.println("connectToFrameFirst!"); 00064 } 00066 if (type == Configuration.NO_FILE) { 00067 setCurrentDirectory(new File(conf.getOutputDir())); 00068 } 00069 if (type == Configuration.IMAGE_FILE 00070 && conf.getOpen_filechooser_path() != null) { 00071 setCurrentDirectory(conf.getOpen_filechooser_path()); 00072 } 00073 int returnVal = this.showOpenDialog(frame); 00074 if (returnVal == JFileChooser.APPROVE_OPTION) { 00075 00076 String filename = this.getSelectedFile().getName(); 00077 String path = this.getSelectedFile().getAbsolutePath(); 00078 if (type == Configuration.IMAGE_FILE) { 00079 conf.setOpen_filechooser_path(new File(path)); 00080 } 00081 conf.setPath(path); 00082 conf.setImageName(filename); 00083 conf.setOutputName(conf.getImageName_WithoutExtension()); 00084 conf.setFileSize(getSelectedFile().length()); 00085 if (Debug.DEBUG_GUI) { 00086 commandline.debuggingCode.Debug 00087 .print("You chose to open this file: " + path); 00088 commandline.debuggingCode.Debug.print("Warning all listeners"); 00089 } 00090 fileChangeHandler.updateFileChangeListeners(this); 00091 } 00092 00093 } 00094 00095 public void setFileChangeHandler(FileChangeHandler changeHandler) { 00096 this.fileChangeHandler = changeHandler; 00097 } 00098 00099 public Configuration getConfiguration() { 00100 return conf; 00101 } 00102 00103 public String getPathName() { 00104 return conf.getPath(); 00105 } 00106 00107 public String getFileName() { 00108 00109 return conf.getImageName(); 00110 } 00111 00112 }
1.5.5