118
119 void installStrings() {
120 Locale l = target.getLocale();
121 UIDefaults uid = XToolkit.getUIDefaults();
122 cancelButtonText = uid.getString("FileChooser.cancelButtonText",l);
123 enterFileNameLabelText = uid.getString("FileChooser.enterFileNameLabelText",l);
124 filesLabelText = uid.getString("FileChooser.filesLabelText",l);
125 foldersLabelText = uid.getString("FileChooser.foldersLabelText",l);
126 pathLabelText = uid.getString("FileChooser.pathLabelText",l);
127 filterLabelText = uid.getString("FileChooser.filterLabelText",l);
128 openButtonText = uid.getString("FileChooser.openButtonText",l);
129 saveButtonText = uid.getString("FileChooser.saveButtonText",l);
130
131 }
132
133 XFileDialogPeer(FileDialog target) {
134 super((Dialog)target);
135 this.target = target;
136 }
137
138 private void init(FileDialog target) {
139 fileDialog = target; //new Dialog(target, target.getTitle(), false);
140 this.title = target.getTitle();
141 this.mode = target.getMode();
142 this.target = target;
143 this.filter = target.getFilenameFilter();
144
145 savedFile = target.getFile();
146 savedDir = target.getDirectory();
147 // Shouldn't save 'user.dir' to 'savedDir'
148 // since getDirectory() will be incorrect after handleCancel
149 userDir = AccessController.doPrivileged(
150 new PrivilegedAction<String>() {
151 public String run() {
152 return System.getProperty("user.dir");
153 }
154 });
155
156 installStrings();
157 gbl = new GridBagLayout();
397 savedFile = file.substring(index+1);
398 }
399
400 String[] fileNames = fileList.getSelectedItems();
401 int filesNumber = (fileNames != null) ? fileNames.length : 0;
402 File[] files = new File[filesNumber];
403 for (int i = 0; i < filesNumber; i++) {
404 files[i] = new File(savedDir, fileNames[i]);
405 }
406
407 AWTAccessor.FileDialogAccessor fileDialogAccessor = AWTAccessor.getFileDialogAccessor();
408
409 fileDialogAccessor.setDirectory(target, savedDir);
410 fileDialogAccessor.setFile(target, savedFile);
411 fileDialogAccessor.setFiles(target, files);
412 }
413
414 /**
415 * handle the cancel event
416 */
417 void handleCancel() {
418 KeyboardFocusManager.getCurrentKeyboardFocusManager()
419 .removeKeyEventDispatcher(this);
420
421 setSelectionField(null);
422 setFilterField(null);
423 directoryList.clear();
424 fileList.clear();
425
426 AWTAccessor.FileDialogAccessor fileDialogAccessor = AWTAccessor.getFileDialogAccessor();
427
428 fileDialogAccessor.setDirectory(target, null);
429 fileDialogAccessor.setFile(target, null);
430 fileDialogAccessor.setFiles(target, null);
431
432 handleQuitButton();
433 }
434
435 /**
436 * handle the quit event
437 */
438 void handleQuitButton() {
439 dir = null;
440 file = null;
441 target.hide();
442 }
443
444 /**
445 * set the entry of the new dir with f
446 */
447 void setFilterEntry(String d, String f) {
448 File fe = new File(d);
449
450 if (fe.isDirectory() && fe.canRead()) {
451 // Fixed 6260659: File Name set programmatically in FileDialog is overridden during navigation, XToolkit
452 // Here we restoring Motif behaviour
453 setSelectionField(target.getFile());
454
455 if (f.equals("")) {
456 f = "*";
457 setFilterField(f);
458 } else {
459 setFilterField(f);
460 }
461 String l[];
462
463 if (f.equals("*")) {
464 l = fe.list();
465 } else {
466 // REMIND: fileDialogFilter is not implemented yet
621 handleSelection(selectionField.getText());
622 handleQuitButton();
623 } else if (filterField == ((TextField)source)) {
624 handleFilter(filterField.getText());
625 } else if (pathField == ((TextField)source)) {
626 target.setDirectory(pathField.getText());
627 }
628 } else if (source instanceof List) {
629 if (directoryList == ((List)source)) {
630 //handleFilter( actionCommand + getFileName( filterField.getText() ) );
631 if (updateDirectoryByUserAction(actionCommand)){
632 handleFilter( getFileName( filterField.getText() ) );
633 }
634 } else if (fileList == ((List)source)) {
635 handleSelection( actionCommand );
636 handleQuitButton();
637 }
638 }
639 }
640
641 public boolean dispatchKeyEvent(KeyEvent keyEvent) {
642 int id = keyEvent.getID();
643 int keyCode = keyEvent.getKeyCode();
644
645 if (id == KeyEvent.KEY_PRESSED && keyCode == KeyEvent.VK_ESCAPE) {
646 synchronized (target.getTreeLock()) {
647 Component comp = (Component) keyEvent.getSource();
648 while (comp != null) {
649 // Fix for 6240084 Disposing a file dialog when the drop-down is active does not dispose the dropdown menu, on Xtoolkit
650 // See also 6259493
651 if (comp == pathChoice) {
652 XChoicePeer choicePeer = (XChoicePeer)pathChoice.getPeer();
653 if (choicePeer.isUnfurled()){
654 return false;
655 }
656 }
657 if (comp.getPeer() == this) {
658 handleCancel();
659 return true;
660 }
757 }
758
759 /**
760 * set filenameFilter
761 *
762 */
763 public void setFilenameFilter(FilenameFilter filter) {
764 this.filter = filter;
765 }
766
767
768 public void dispose() {
769 FileDialog fd = (FileDialog)fileDialog;
770 if (fd != null) {
771 fd.removeAll();
772 }
773 super.dispose();
774 }
775
776 // 03/02/2005 b5097243 Pressing 'ESC' on a file dlg does not dispose the dlg on Xtoolkit
777 public void setVisible(boolean b){
778 if (fileDialog == null) {
779 init(target);
780 }
781
782 if (savedDir != null || userDir != null) {
783 setDirectory(savedDir != null ? savedDir : userDir);
784 }
785
786 if (savedFile != null) {
787 // Actually in Motif implementation lost file value which was saved after prevously showing
788 // Seems we shouldn't restore Motif behaviour in this case
789 setFile(savedFile);
790 }
791
792 super.setVisible(b);
793 if (b == true){
794 // See 6240074 for more information
795 XChoicePeer choicePeer = (XChoicePeer)pathChoice.getPeer();
796 choicePeer.addXChoicePeerListener(this);
835 }
836
837 /*
838 * Refresh the file dialog at the time of the closing choice according to the selected item of the choice
839 * See 6240074 for more information
840 */
841 public void unfurledChoiceClosing(){
842 // This is the exactly same code as invoking later at the time of the itemStateChanged
843 // Here is we restore Windows behaviour: change current directory if user press 'ESC'
844 String dir = pathChoice.getSelectedItem();
845 target.setDirectory(dir);
846 }
847 }
848
849 @SuppressWarnings("serial") // JDK-implementation class
850 class Separator extends Canvas {
851 public final static int HORIZONTAL = 0;
852 public final static int VERTICAL = 1;
853 int orientation;
854
855 public Separator(int length, int thickness, int orient) {
856 super();
857 orientation = orient;
858 if (orient == HORIZONTAL) {
859 resize(length, thickness);
860 } else {
861 // VERTICAL
862 resize(thickness, length);
863 }
864 }
865
866 public void paint(Graphics g) {
867 int x1, y1, x2, y2;
868 Rectangle bbox = bounds();
869 Color c = getBackground();
870 Color brighter = c.brighter();
871 Color darker = c.darker();
872
873 if (orientation == HORIZONTAL) {
874 x1 = 0;
875 x2 = bbox.width - 1;
876 y1 = y2 = bbox.height/2 - 1;
877
878 } else {
879 // VERTICAL
880 x1 = x2 = bbox.width/2 - 1;
881 y1 = 0;
882 y2 = bbox.height - 1;
883 }
884 g.setColor(darker);
885 g.drawLine(x1, y2, x2, y2);
|
118
119 void installStrings() {
120 Locale l = target.getLocale();
121 UIDefaults uid = XToolkit.getUIDefaults();
122 cancelButtonText = uid.getString("FileChooser.cancelButtonText",l);
123 enterFileNameLabelText = uid.getString("FileChooser.enterFileNameLabelText",l);
124 filesLabelText = uid.getString("FileChooser.filesLabelText",l);
125 foldersLabelText = uid.getString("FileChooser.foldersLabelText",l);
126 pathLabelText = uid.getString("FileChooser.pathLabelText",l);
127 filterLabelText = uid.getString("FileChooser.filterLabelText",l);
128 openButtonText = uid.getString("FileChooser.openButtonText",l);
129 saveButtonText = uid.getString("FileChooser.saveButtonText",l);
130
131 }
132
133 XFileDialogPeer(FileDialog target) {
134 super((Dialog)target);
135 this.target = target;
136 }
137
138 @SuppressWarnings("deprecation")
139 private void init(FileDialog target) {
140 fileDialog = target; //new Dialog(target, target.getTitle(), false);
141 this.title = target.getTitle();
142 this.mode = target.getMode();
143 this.target = target;
144 this.filter = target.getFilenameFilter();
145
146 savedFile = target.getFile();
147 savedDir = target.getDirectory();
148 // Shouldn't save 'user.dir' to 'savedDir'
149 // since getDirectory() will be incorrect after handleCancel
150 userDir = AccessController.doPrivileged(
151 new PrivilegedAction<String>() {
152 public String run() {
153 return System.getProperty("user.dir");
154 }
155 });
156
157 installStrings();
158 gbl = new GridBagLayout();
398 savedFile = file.substring(index+1);
399 }
400
401 String[] fileNames = fileList.getSelectedItems();
402 int filesNumber = (fileNames != null) ? fileNames.length : 0;
403 File[] files = new File[filesNumber];
404 for (int i = 0; i < filesNumber; i++) {
405 files[i] = new File(savedDir, fileNames[i]);
406 }
407
408 AWTAccessor.FileDialogAccessor fileDialogAccessor = AWTAccessor.getFileDialogAccessor();
409
410 fileDialogAccessor.setDirectory(target, savedDir);
411 fileDialogAccessor.setFile(target, savedFile);
412 fileDialogAccessor.setFiles(target, files);
413 }
414
415 /**
416 * handle the cancel event
417 */
418 @SuppressWarnings("deprecation")
419 void handleCancel() {
420 KeyboardFocusManager.getCurrentKeyboardFocusManager()
421 .removeKeyEventDispatcher(this);
422
423 setSelectionField(null);
424 setFilterField(null);
425 directoryList.clear();
426 fileList.clear();
427
428 AWTAccessor.FileDialogAccessor fileDialogAccessor = AWTAccessor.getFileDialogAccessor();
429
430 fileDialogAccessor.setDirectory(target, null);
431 fileDialogAccessor.setFile(target, null);
432 fileDialogAccessor.setFiles(target, null);
433
434 handleQuitButton();
435 }
436
437 /**
438 * handle the quit event
439 */
440 @SuppressWarnings("deprecation")
441 void handleQuitButton() {
442 dir = null;
443 file = null;
444 target.hide();
445 }
446
447 /**
448 * set the entry of the new dir with f
449 */
450 @SuppressWarnings("deprecation")
451 void setFilterEntry(String d, String f) {
452 File fe = new File(d);
453
454 if (fe.isDirectory() && fe.canRead()) {
455 // Fixed 6260659: File Name set programmatically in FileDialog is overridden during navigation, XToolkit
456 // Here we restoring Motif behaviour
457 setSelectionField(target.getFile());
458
459 if (f.equals("")) {
460 f = "*";
461 setFilterField(f);
462 } else {
463 setFilterField(f);
464 }
465 String l[];
466
467 if (f.equals("*")) {
468 l = fe.list();
469 } else {
470 // REMIND: fileDialogFilter is not implemented yet
625 handleSelection(selectionField.getText());
626 handleQuitButton();
627 } else if (filterField == ((TextField)source)) {
628 handleFilter(filterField.getText());
629 } else if (pathField == ((TextField)source)) {
630 target.setDirectory(pathField.getText());
631 }
632 } else if (source instanceof List) {
633 if (directoryList == ((List)source)) {
634 //handleFilter( actionCommand + getFileName( filterField.getText() ) );
635 if (updateDirectoryByUserAction(actionCommand)){
636 handleFilter( getFileName( filterField.getText() ) );
637 }
638 } else if (fileList == ((List)source)) {
639 handleSelection( actionCommand );
640 handleQuitButton();
641 }
642 }
643 }
644
645 @SuppressWarnings("deprecation")
646 public boolean dispatchKeyEvent(KeyEvent keyEvent) {
647 int id = keyEvent.getID();
648 int keyCode = keyEvent.getKeyCode();
649
650 if (id == KeyEvent.KEY_PRESSED && keyCode == KeyEvent.VK_ESCAPE) {
651 synchronized (target.getTreeLock()) {
652 Component comp = (Component) keyEvent.getSource();
653 while (comp != null) {
654 // Fix for 6240084 Disposing a file dialog when the drop-down is active does not dispose the dropdown menu, on Xtoolkit
655 // See also 6259493
656 if (comp == pathChoice) {
657 XChoicePeer choicePeer = (XChoicePeer)pathChoice.getPeer();
658 if (choicePeer.isUnfurled()){
659 return false;
660 }
661 }
662 if (comp.getPeer() == this) {
663 handleCancel();
664 return true;
665 }
762 }
763
764 /**
765 * set filenameFilter
766 *
767 */
768 public void setFilenameFilter(FilenameFilter filter) {
769 this.filter = filter;
770 }
771
772
773 public void dispose() {
774 FileDialog fd = (FileDialog)fileDialog;
775 if (fd != null) {
776 fd.removeAll();
777 }
778 super.dispose();
779 }
780
781 // 03/02/2005 b5097243 Pressing 'ESC' on a file dlg does not dispose the dlg on Xtoolkit
782 @SuppressWarnings("deprecation")
783 public void setVisible(boolean b){
784 if (fileDialog == null) {
785 init(target);
786 }
787
788 if (savedDir != null || userDir != null) {
789 setDirectory(savedDir != null ? savedDir : userDir);
790 }
791
792 if (savedFile != null) {
793 // Actually in Motif implementation lost file value which was saved after prevously showing
794 // Seems we shouldn't restore Motif behaviour in this case
795 setFile(savedFile);
796 }
797
798 super.setVisible(b);
799 if (b == true){
800 // See 6240074 for more information
801 XChoicePeer choicePeer = (XChoicePeer)pathChoice.getPeer();
802 choicePeer.addXChoicePeerListener(this);
841 }
842
843 /*
844 * Refresh the file dialog at the time of the closing choice according to the selected item of the choice
845 * See 6240074 for more information
846 */
847 public void unfurledChoiceClosing(){
848 // This is the exactly same code as invoking later at the time of the itemStateChanged
849 // Here is we restore Windows behaviour: change current directory if user press 'ESC'
850 String dir = pathChoice.getSelectedItem();
851 target.setDirectory(dir);
852 }
853 }
854
855 @SuppressWarnings("serial") // JDK-implementation class
856 class Separator extends Canvas {
857 public final static int HORIZONTAL = 0;
858 public final static int VERTICAL = 1;
859 int orientation;
860
861 @SuppressWarnings("deprecation")
862 public Separator(int length, int thickness, int orient) {
863 super();
864 orientation = orient;
865 if (orient == HORIZONTAL) {
866 resize(length, thickness);
867 } else {
868 // VERTICAL
869 resize(thickness, length);
870 }
871 }
872
873 @SuppressWarnings("deprecation")
874 public void paint(Graphics g) {
875 int x1, y1, x2, y2;
876 Rectangle bbox = bounds();
877 Color c = getBackground();
878 Color brighter = c.brighter();
879 Color darker = c.darker();
880
881 if (orientation == HORIZONTAL) {
882 x1 = 0;
883 x2 = bbox.width - 1;
884 y1 = y2 = bbox.height/2 - 1;
885
886 } else {
887 // VERTICAL
888 x1 = x2 = bbox.width/2 - 1;
889 y1 = 0;
890 y2 = bbox.height - 1;
891 }
892 g.setColor(darker);
893 g.drawLine(x1, y2, x2, y2);
|