1 /*
2 J-Bird net/sourceforge/jbird/swing/JEncodedFileChooser.java
3
4 Copyright 2001, 2002, 2003 Dick Repasky
5 */
6 package net.sourceforge.jbird.swing;
7
8 import java.awt.Component;
9 import java.io.File;
10
11 import javax.swing.JFileChooser;
12 import javax.swing.filechooser.FileSystemView;
13
14 import net.sourceforge.jbird.io.FileTextSource;
15 import net.sourceforge.jbird.io.TextSourceInterface;
16 import net.sourceforge.jbird.io.TextSourceSource;
17
18 /**
19 * A subclass of JFileChooser that includes an auxillary component
20 * that allows users to choose the file encoding of a file.
21 * <p>
22 * ENCODING CAPACITY GUTTED BECAUSE OF PROBLEMS WITH BLACKDOWN JAVA
23 * 1.4.1. getEncoding ALWAYS RETURNS SYSTEM FILE ENCODING.
24 * @author Dick Repasky
25 *
26 */
27
28 public class JEncodedFileChooser extends JFileChooser
29 implements TextSourceSource {
30
31 //protected EncodingChooser encchooser; // RESTORE HERE
32 protected Component parentcomponent;
33
34 // constructors to implement
35
36 public JEncodedFileChooser() {
37 addEncodingChooser();
38 }
39
40 public JEncodedFileChooser(File currentDirectory){
41 addEncodingChooser();
42 }
43
44 public JEncodedFileChooser(File currentDirectory,
45 FileSystemView fsv){
46 addEncodingChooser();
47 }
48
49 public JEncodedFileChooser(FileSystemView fsv){
50 addEncodingChooser();
51 }
52
53 public JEncodedFileChooser(String currentpath) {
54 addEncodingChooser();
55 }
56
57 public JEncodedFileChooser(String currentpath,
58 FileSystemView fsv) {
59 addEncodingChooser();
60 }
61
62 protected void addEncodingChooser() {
63 //encchooser = new EncodingChooser(); // RESTORE HERE
64 //setAccessory(encchooser); // RESTORE HERE
65 }
66
67 public void setEncodingChooserHeader(String to) {
68 //encchooser.setHeaderLabel(to); // RESTORE HERE
69 }
70
71 public void setEncodingChooserEncodingFMT(String fmt) {
72 //encchooser.setDefaultEncodingLabel(fmt); // RESTORE HERE
73 }
74
75 public void setParentComponent(Component c) {
76 parentcomponent = c;
77 }
78
79 public String getEncoding() {
80 //return encchooser.getSelectedEncoding();
81 return System.getProperty("file.encoding"); // RESTORE HERE
82 }
83
84 public Exception getException() {
85 return null;
86 }
87
88 public TextSourceInterface getTextSource() {
89 int response = showDialog(parentcomponent, null);
90 if (response == JFileChooser.CANCEL_OPTION) {
91 return null;
92 }
93 return new FileTextSource(getSelectedFile().getAbsolutePath());
94 }
95
96 }