Source for javax.swing.JFileChooser

   1: /* JFileChooser.java --
   2:    Copyright (C) 2002, 2004, 2005  Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: package javax.swing;
  39: 
  40: import java.awt.Component;
  41: import java.awt.Frame;
  42: import java.awt.HeadlessException;
  43: import java.awt.event.ActionEvent;
  44: import java.awt.event.ActionListener;
  45: import java.io.File;
  46: import java.util.ArrayList;
  47: import javax.accessibility.Accessible;
  48: import javax.accessibility.AccessibleContext;
  49: import javax.swing.JDialog;
  50: import javax.swing.filechooser.FileFilter;
  51: import javax.swing.filechooser.FileSystemView;
  52: import javax.swing.filechooser.FileView;
  53: import javax.swing.plaf.FileChooserUI;
  54: 
  55: 
  56: /**
  57:  * DOCUMENT ME!
  58:  */
  59: public class JFileChooser extends JComponent implements Accessible
  60: {
  61:   private static final long serialVersionUID = 3162921138695327837L;
  62: 
  63:   /** DOCUMENT ME! */
  64:   public static final int OPEN_DIALOG = 0;
  65: 
  66:   /** DOCUMENT ME! */
  67:   public static final int SAVE_DIALOG = 1;
  68: 
  69:   /** DOCUMENT ME! */
  70:   public static final int CUSTOM_DIALOG = 2;
  71: 
  72:   /** DOCUMENT ME! */
  73:   public static final int CANCEL_OPTION = 1;
  74: 
  75:   /** DOCUMENT ME! */
  76:   public static final int APPROVE_OPTION = 0;
  77: 
  78:   /** DOCUMENT ME! */
  79:   public static final int ERROR_OPTION = -1;
  80: 
  81:   /** DOCUMENT ME! */
  82:   public static final int FILES_ONLY = 0;
  83: 
  84:   /** DOCUMENT ME! */
  85:   public static final int DIRECTORIES_ONLY = 1;
  86: 
  87:   /** DOCUMENT ME! */
  88:   public static final int FILES_AND_DIRECTORIES = 2;
  89: 
  90:   /** DOCUMENT ME! */
  91:   public static final String CANCEL_SELECTION = "CancelSelection";
  92: 
  93:   /** DOCUMENT ME! */
  94:   public static final String APPROVE_SELECTION = "ApproveSelection";
  95: 
  96:   /** DOCUMENT ME! */
  97:   public static final String APPROVE_BUTTON_TEXT_CHANGED_PROPERTY =
  98:     "ApproveButtonTextChangedProperty";
  99: 
 100:   /** DOCUMENT ME! */
 101:   public static final String APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY =
 102:     "ApproveButtonToolTipTextChangedProperty";
 103: 
 104:   /** DOCUMENT ME! */
 105:   public static final String APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY =
 106:     "ApproveButtonMnemonicChangedProperty";
 107: 
 108:   /** DOCUMENT ME! */
 109:   public static final String CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY =
 110:     "ControlButtonsAreShownChangedProperty";
 111: 
 112:   /** DOCUMENT ME! */
 113:   public static final String DIRECTORY_CHANGED_PROPERTY = "directoryChanged";
 114: 
 115:   /** DOCUMENT ME! */
 116:   public static final String SELECTED_FILE_CHANGED_PROPERTY =
 117:     "SelectedFileChangedProperty";
 118: 
 119:   /** DOCUMENT ME! */
 120:   public static final String SELECTED_FILES_CHANGED_PROPERTY =
 121:     "SelectedFilesChangedProperty";
 122: 
 123:   /** DOCUMENT ME! */
 124:   public static final String MULTI_SELECTION_ENABLED_CHANGED_PROPERTY =
 125:     "MultiSelectionEnabledChangedProperty";
 126: 
 127:   /** DOCUMENT ME! */
 128:   public static final String FILE_SYSTEM_VIEW_CHANGED_PROPERTY =
 129:     "FileSystemViewChanged";
 130: 
 131:   /** DOCUMENT ME! */
 132:   public static final String FILE_VIEW_CHANGED_PROPERTY = "fileViewChanged";
 133: 
 134:   /** DOCUMENT ME! */
 135:   public static final String FILE_HIDING_CHANGED_PROPERTY =
 136:     "FileHidingChanged";
 137: 
 138:   /** DOCUMENT ME! */
 139:   public static final String FILE_FILTER_CHANGED_PROPERTY =
 140:     "fileFilterChanged";
 141: 
 142:   /** DOCUMENT ME! */
 143:   public static final String FILE_SELECTION_MODE_CHANGED_PROPERTY =
 144:     "fileSelectionChanged";
 145: 
 146:   /** DOCUMENT ME! */
 147:   public static final String ACCESSORY_CHANGED_PROPERTY =
 148:     "AccessoryChangedProperty";
 149: 
 150:   /** DOCUMENT ME! */
 151:   public static final String ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY =
 152:     "acceptAllFileFilterUsedChanged";
 153: 
 154:   /** DOCUMENT ME! */
 155:   public static final String DIALOG_TITLE_CHANGED_PROPERTY =
 156:     "DialogTitleChangedProperty";
 157: 
 158:   /** DOCUMENT ME! */
 159:   public static final String DIALOG_TYPE_CHANGED_PROPERTY =
 160:     "DialogTypeChangedProperty";
 161: 
 162:   /** DOCUMENT ME! */
 163:   public static final String CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY =
 164:     "ChoosableFileFilterChangedProperty";
 165: 
 166:   /** DOCUMENT ME! */
 167:   protected AccessibleContext accessibleContext;
 168: 
 169:   /** DOCUMENT ME! */
 170:   private FileSystemView fsv;
 171: 
 172:   /** DOCUMENT ME! */
 173:   private JComponent accessory;
 174: 
 175:   /** DOCUMENT ME! */
 176:   private int approveButtonMnemonic = 0;
 177: 
 178:   /** DOCUMENT ME! */
 179:   private String approveButtonText;
 180: 
 181:   /** DOCUMENT ME! */
 182:   private String approveButtonToolTipText;
 183: 
 184:   /** DOCUMENT ME! */
 185:   private ArrayList choosableFilters = new ArrayList();
 186: 
 187:   /** DOCUMENT ME! */
 188:   private boolean isAcceptAll = true;
 189: 
 190:   /** DOCUMENT ME! */
 191:   private String dialogTitle;
 192: 
 193:   /** DOCUMENT ME! */
 194:   private int dialogType = OPEN_DIALOG;
 195: 
 196:   /** DOCUMENT ME! */
 197:   private int retval = ERROR_OPTION;
 198: 
 199:   /** DOCUMENT ME! */
 200:   private boolean multiSelection = false;
 201: 
 202:   /** DOCUMENT ME! */
 203:   private boolean fileHiding = true;
 204: 
 205:   /** DOCUMENT ME! */
 206:   private int fileSelectionMode = FILES_AND_DIRECTORIES;
 207: 
 208:   /** DOCUMENT ME! */
 209:   private FileView fv = null;
 210: 
 211:   /** DOCUMENT ME! */
 212:   private boolean controlButtonsShown = true;
 213: 
 214:   /** DOCUMENT ME! */
 215:   private File currentDir = null;
 216: 
 217:   /** DOCUMENT ME! */
 218:   private FileFilter currentFilter = null;
 219: 
 220:   /** DOCUMENT ME! */
 221:   private File[] selectedFiles;
 222: 
 223:   /** DOCUMENT ME! */
 224:   private File selectedFile;
 225: 
 226:   /**
 227:    * Creates a new JFileChooser object.
 228:    */
 229:   public JFileChooser()
 230:   {
 231:     setup(null);
 232:     setCurrentDirectory(null);
 233:   }
 234: 
 235:   /**
 236:    * Creates a new JFileChooser object.
 237:    *
 238:    * @param currentDirectoryPath DOCUMENT ME!
 239:    */
 240:   public JFileChooser(String currentDirectoryPath)
 241:   {
 242:     setup(null);
 243:     setCurrentDirectory(fsv.createFileObject(currentDirectoryPath));
 244:   }
 245: 
 246:   /**
 247:    * Creates a new JFileChooser object with the specified directory and
 248:    * FileSystemView.
 249:    *
 250:    * @param currentDirectoryPath the directory that should initially be
 251:    *     shown the filechooser
 252:    * @param fsv the FileSystemView object to use
 253:    */
 254:   public JFileChooser(String currentDirectoryPath, FileSystemView fsv)
 255:   {
 256:     setup(fsv);
 257:     setCurrentDirectory(fsv.createFileObject(currentDirectoryPath));
 258:   }
 259: 
 260:   /**
 261:    * Creates a new JFileChooser object.
 262:    *
 263:    * @param currentDirectory DOCUMENT ME!
 264:    */
 265:   public JFileChooser(File currentDirectory)
 266:   {
 267:     setup(null);
 268:     setCurrentDirectory(currentDirectory);
 269:   }
 270: 
 271:   /**
 272:    * Creates a new JFileChooser object.
 273:    *
 274:    * @param fsv DOCUMENT ME!
 275:    */
 276:   public JFileChooser(FileSystemView fsv)
 277:   {
 278:     setup(fsv);
 279:     setCurrentDirectory(null);
 280:   }
 281: 
 282:   /**
 283:    * Creates a new JFileChooser object.
 284:    *
 285:    * @param currentDirectory DOCUMENT ME!
 286:    * @param fsv DOCUMENT ME!
 287:    */
 288:   public JFileChooser(File currentDirectory, FileSystemView fsv)
 289:   {
 290:     setup(fsv);
 291:     setCurrentDirectory(currentDirectory);
 292:   }
 293: 
 294:   /**
 295:    * DOCUMENT ME!
 296:    *
 297:    * @param view DOCUMENT ME!
 298:    */
 299:   protected void setup(FileSystemView view)
 300:   {
 301:     if (view == null)
 302:       view = FileSystemView.getFileSystemView();
 303:     setFileSystemView(view);
 304:     updateUI();
 305:   }
 306: 
 307:   /**
 308:    * DOCUMENT ME!
 309:    *
 310:    * @param b DOCUMENT ME!
 311:    */
 312:   public void setDragEnabled(boolean b)
 313:   {
 314:     // FIXME: Implement
 315:   }
 316: 
 317:   /**
 318:    * DOCUMENT ME!
 319:    *
 320:    * @return DOCUMENT ME!
 321:    */
 322:   public boolean getDragEnabled()
 323:   {
 324:     // FIXME: Implement
 325:     return false;
 326:   }
 327: 
 328:   /**
 329:    * DOCUMENT ME!
 330:    *
 331:    * @return DOCUMENT ME!
 332:    */
 333:   public File getSelectedFile()
 334:   {
 335:     return selectedFile;
 336:   }
 337: 
 338:   /**
 339:    * DOCUMENT ME!
 340:    *
 341:    * @param file DOCUMENT ME!
 342:    */
 343:   public void setSelectedFile(File file)
 344:   {
 345:     if (selectedFile != file)
 346:       {
 347:     File old = selectedFile;
 348:     selectedFile = file;
 349:     firePropertyChange(SELECTED_FILE_CHANGED_PROPERTY, old, selectedFile);
 350:       }
 351:   }
 352: 
 353:   /**
 354:    * DOCUMENT ME!
 355:    *
 356:    * @return DOCUMENT ME!
 357:    */
 358:   public File[] getSelectedFiles()
 359:   {
 360:     if (selectedFiles != null)
 361:       return selectedFiles;
 362:     if (selectedFile != null)
 363:       return new File[] { selectedFile };
 364:     return null;
 365:   }
 366: 
 367:   /**
 368:    * DOCUMENT ME!
 369:    *
 370:    * @param selectedFiles DOCUMENT ME!
 371:    */
 372:   public void setSelectedFiles(File[] selectedFiles)
 373:   {
 374:     if (this.selectedFiles != selectedFiles)
 375:       {
 376:     File[] old = this.selectedFiles;
 377:     this.selectedFiles = selectedFiles;
 378:     firePropertyChange(SELECTED_FILES_CHANGED_PROPERTY, old, selectedFiles);
 379:       }
 380: 
 381:     if (selectedFiles != null)
 382:       setSelectedFile(selectedFiles[0]);
 383:   }
 384: 
 385:   /**
 386:    * DOCUMENT ME!
 387:    *
 388:    * @return DOCUMENT ME!
 389:    */
 390:   public File getCurrentDirectory()
 391:   {
 392:     return currentDir;
 393:   }
 394: 
 395:   /**
 396:    * DOCUMENT ME!
 397:    *
 398:    * @param dir DOCUMENT ME!
 399:    */
 400:   public void setCurrentDirectory(File dir)
 401:   {
 402:     if (currentDir != dir || dir == null)
 403:       {
 404:     if (dir == null)
 405:       dir = fsv.getDefaultDirectory();
 406: 
 407:     File old = currentDir;
 408:     currentDir = dir;
 409:     firePropertyChange(DIRECTORY_CHANGED_PROPERTY, old, currentDir);
 410:       }
 411:   }
 412: 
 413:   /**
 414:    * DOCUMENT ME!
 415:    */
 416:   public void changeToParentDirectory()
 417:   {
 418:     setCurrentDirectory(fsv.getParentDirectory(currentDir));
 419:   }
 420: 
 421:   /**
 422:    * DOCUMENT ME!
 423:    */
 424:   public void rescanCurrentDirectory()
 425:   {
 426:     getUI().rescanCurrentDirectory(this);
 427:   }
 428: 
 429:   /**
 430:    * DOCUMENT ME!
 431:    *
 432:    * @param f DOCUMENT ME!
 433:    */
 434:   public void ensureFileIsVisible(File f)
 435:   {
 436:     getUI().ensureFileIsVisible(this, f);
 437:   }
 438: 
 439:   /**
 440:    * DOCUMENT ME!
 441:    *
 442:    * @param parent DOCUMENT ME!
 443:    *
 444:    * @return DOCUMENT ME!
 445:    *
 446:    * @throws HeadlessException DOCUMENT ME!
 447:    */
 448:   public int showOpenDialog(Component parent) throws HeadlessException
 449:   {
 450:     JDialog d = createDialog(parent);
 451: 
 452:     // FIXME: Remove when we get ancestor property
 453:     d.setTitle("Open");
 454:     setDialogType(OPEN_DIALOG);
 455: 
 456:     retval = ERROR_OPTION;
 457: 
 458:     d.pack();
 459:     d.show();
 460:     return retval;
 461:   }
 462: 
 463:   /**
 464:    * DOCUMENT ME!
 465:    *
 466:    * @param parent DOCUMENT ME!
 467:    *
 468:    * @return DOCUMENT ME!
 469:    *
 470:    * @throws HeadlessException DOCUMENT ME!
 471:    */
 472:   public int showSaveDialog(Component parent) throws HeadlessException
 473:   {
 474:     JDialog d = createDialog(parent);
 475:     setDialogType(SAVE_DIALOG);
 476: 
 477:     retval = ERROR_OPTION;
 478: 
 479:     d.pack();
 480:     d.show();
 481:     return retval;
 482:   }
 483: 
 484:   /**
 485:    * DOCUMENT ME!
 486:    *
 487:    * @param parent DOCUMENT ME!
 488:    * @param approveButtonText DOCUMENT ME!
 489:    *
 490:    * @return DOCUMENT ME!
 491:    *
 492:    * @throws HeadlessException DOCUMENT ME!
 493:    */
 494:   public int showDialog(Component parent, String approveButtonText)
 495:                  throws HeadlessException
 496:   {
 497:     JDialog d = createDialog(parent);
 498:     setApproveButtonText(approveButtonText);
 499:     setDialogType(CUSTOM_DIALOG);
 500: 
 501:     retval = ERROR_OPTION;
 502: 
 503:     d.pack();
 504:     d.show();
 505:     return retval;
 506:   }
 507: 
 508:   /**
 509:    * DOCUMENT ME!
 510:    *
 511:    * @param parent DOCUMENT ME!
 512:    *
 513:    * @return DOCUMENT ME!
 514:    *
 515:    * @throws HeadlessException DOCUMENT ME!
 516:    */
 517:   protected JDialog createDialog(Component parent) throws HeadlessException
 518:   {
 519:     Frame toUse = (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent);
 520:     if (toUse == null)
 521:       toUse = SwingUtilities.getOwnerFrame();
 522: 
 523:     JDialog dialog = new JDialog(toUse);
 524:     setSelectedFile(null);
 525:     dialog.getContentPane().add(this);
 526:     dialog.setModal(true);
 527:     dialog.invalidate();
 528:     dialog.repaint();
 529: 
 530:     return dialog;
 531:   }
 532: 
 533:   /**
 534:    * DOCUMENT ME!
 535:    *
 536:    * @return DOCUMENT ME!
 537:    */
 538:   public boolean getControlButtonsAreShown()
 539:   {
 540:     return controlButtonsShown;
 541:   }
 542: 
 543:   /**
 544:    * DOCUMENT ME!
 545:    *
 546:    * @param b DOCUMENT ME!
 547:    */
 548:   public void setControlButtonsAreShown(boolean b)
 549:   {
 550:     if (controlButtonsShown != b)
 551:       {
 552:     controlButtonsShown = b;
 553:     firePropertyChange(CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY,
 554:                        ! controlButtonsShown, controlButtonsShown);
 555:       }
 556:   }
 557: 
 558:   /**
 559:    * DOCUMENT ME!
 560:    *
 561:    * @return DOCUMENT ME!
 562:    */
 563:   public int getDialogType()
 564:   {
 565:     return dialogType;
 566:   }
 567: 
 568:   /**
 569:    * DOCUMENT ME!
 570:    *
 571:    * @param dialogType DOCUMENT ME!
 572:    */
 573:   public void setDialogType(int dialogType)
 574:   {
 575:     if (dialogType != OPEN_DIALOG && dialogType != SAVE_DIALOG
 576:         && dialogType != CUSTOM_DIALOG)
 577:       throw new IllegalArgumentException("Choose allowable dialogType.");
 578: 
 579:     if (this.dialogType != dialogType)
 580:       {
 581:     int old = this.dialogType;
 582:     this.dialogType = dialogType;
 583:     firePropertyChange(DIALOG_TYPE_CHANGED_PROPERTY, old, this.dialogType);
 584:       }
 585:   }
 586: 
 587:   /**
 588:    * DOCUMENT ME!
 589:    *
 590:    * @param dialogTitle DOCUMENT ME!
 591:    */
 592:   public void setDialogTitle(String dialogTitle)
 593:   {
 594:     if (this.dialogTitle != dialogTitle)
 595:       {
 596:     String old = this.dialogTitle;
 597:     this.dialogTitle = dialogTitle;
 598:     firePropertyChange(DIALOG_TITLE_CHANGED_PROPERTY, old, this.dialogTitle);
 599:       }
 600:   }
 601: 
 602:   /**
 603:    * DOCUMENT ME!
 604:    *
 605:    * @return DOCUMENT ME!
 606:    */
 607:   public String getDialogTitle()
 608:   {
 609:     return dialogTitle;
 610:   }
 611: 
 612:   /**
 613:    * DOCUMENT ME!
 614:    *
 615:    * @param toolTipText DOCUMENT ME!
 616:    */
 617:   public void setApproveButtonToolTipText(String toolTipText)
 618:   {
 619:     if (approveButtonToolTipText != toolTipText)
 620:       {
 621:     String oldText = approveButtonToolTipText;
 622:     approveButtonToolTipText = toolTipText;
 623:     firePropertyChange(APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY,
 624:                        oldText, approveButtonToolTipText);
 625:       }
 626:   }
 627: 
 628:   /**
 629:    * DOCUMENT ME!
 630:    *
 631:    * @return DOCUMENT ME!
 632:    */
 633:   public String getApproveButtonToolTipText()
 634:   {
 635:     return approveButtonToolTipText;
 636:   }
 637: 
 638:   /**
 639:    * DOCUMENT ME!
 640:    *
 641:    * @return DOCUMENT ME!
 642:    */
 643:   public int getApproveButtonMnemonic()
 644:   {
 645:     return approveButtonMnemonic;
 646:   }
 647: 
 648:   /**
 649:    * DOCUMENT ME!
 650:    *
 651:    * @param mnemonic DOCUMENT ME!
 652:    */
 653:   public void setApproveButtonMnemonic(int mnemonic)
 654:   {
 655:     if (approveButtonMnemonic != mnemonic)
 656:       {
 657:     int oldMnemonic = approveButtonMnemonic;
 658:     approveButtonMnemonic = mnemonic;
 659:     firePropertyChange(APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY,
 660:                        oldMnemonic, approveButtonMnemonic);
 661:       }
 662:   }
 663: 
 664:   /**
 665:    * DOCUMENT ME!
 666:    *
 667:    * @param mnemonic DOCUMENT ME!
 668:    */
 669:   public void setApproveButtonMnemonic(char mnemonic)
 670:   {
 671:     setApproveButtonMnemonic((int) Character.toUpperCase(mnemonic));
 672:   }
 673: 
 674:   /**
 675:    * DOCUMENT ME!
 676:    *
 677:    * @param approveButtonText DOCUMENT ME!
 678:    */
 679:   public void setApproveButtonText(String approveButtonText)
 680:   {
 681:     if (this.approveButtonText != approveButtonText)
 682:       {
 683:     String oldText = this.approveButtonText;
 684:     this.approveButtonText = approveButtonText;
 685:     firePropertyChange(APPROVE_BUTTON_TEXT_CHANGED_PROPERTY, oldText,
 686:                        this.approveButtonText);
 687:       }
 688:   }
 689: 
 690:   /**
 691:    * DOCUMENT ME!
 692:    *
 693:    * @return DOCUMENT ME!
 694:    */
 695:   public String getApproveButtonText()
 696:   {
 697:     return approveButtonText;
 698:   }
 699: 
 700:   /**
 701:    * DOCUMENT ME!
 702:    *
 703:    * @return DOCUMENT ME!
 704:    */
 705:   public FileFilter[] getChoosableFileFilters()
 706:   {
 707:     return (FileFilter[]) choosableFilters.toArray(new FileFilter[0]);
 708:   }
 709: 
 710:   /**
 711:    * DOCUMENT ME!
 712:    *
 713:    * @param filter DOCUMENT ME!
 714:    */
 715:   public void addChoosableFileFilter(FileFilter filter)
 716:   {
 717:     FileFilter[] old = getChoosableFileFilters();
 718:     choosableFilters.add(filter);
 719:     FileFilter[] newFilters = getChoosableFileFilters();
 720:     firePropertyChange(CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY, old, newFilters);
 721:   }
 722: 
 723:   /**
 724:    * DOCUMENT ME!
 725:    *
 726:    * @param f DOCUMENT ME!
 727:    *
 728:    * @return DOCUMENT ME!
 729:    */
 730:   public boolean removeChoosableFileFilter(FileFilter f)
 731:   {
 732:     FileFilter[] old = getChoosableFileFilters();
 733:     if (! choosableFilters.remove(f))
 734:       return false;
 735:     FileFilter[] newFilters = getChoosableFileFilters();
 736:     firePropertyChange(CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY, old, newFilters);
 737:     return true;
 738:   }
 739: 
 740:   /**
 741:    * DOCUMENT ME!
 742:    */
 743:   public void resetChoosableFileFilters()
 744:   {
 745:     choosableFilters.clear();
 746:     choosableFilters.add(getUI().getAcceptAllFileFilter(this));
 747:     setFileFilter((FileFilter) choosableFilters.get(0));
 748:   }
 749: 
 750:   /**
 751:    * DOCUMENT ME!
 752:    *
 753:    * @return DOCUMENT ME!
 754:    */
 755:   public FileFilter getAcceptAllFileFilter()
 756:   {
 757:     return getUI().getAcceptAllFileFilter(this);
 758:   }
 759: 
 760:   /**
 761:    * DOCUMENT ME!
 762:    *
 763:    * @return DOCUMENT ME!
 764:    */
 765:   public boolean isAcceptAllFileFilterUsed()
 766:   {
 767:     return isAcceptAll;
 768:   }
 769: 
 770:   /**
 771:    * DOCUMENT ME!
 772:    *
 773:    * @param b DOCUMENT ME!
 774:    */
 775:   public void setAcceptAllFileFilterUsed(boolean b)
 776:   {
 777:     if (isAcceptAll != b)
 778:       {
 779:     isAcceptAll = b;
 780:     firePropertyChange(ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY,
 781:                        ! isAcceptAll, isAcceptAll);
 782:       }
 783:   }
 784: 
 785:   /**
 786:    * DOCUMENT ME!
 787:    *
 788:    * @return DOCUMENT ME!
 789:    */
 790:   public JComponent getAccessory()
 791:   {
 792:     return accessory;
 793:   }
 794: 
 795:   /**
 796:    * DOCUMENT ME!
 797:    *
 798:    * @param newAccessory DOCUMENT ME!
 799:    */
 800:   public void setAccessory(JComponent newAccessory)
 801:   {
 802:     if (accessory != newAccessory)
 803:       {
 804:     JComponent old = accessory;
 805:     accessory = newAccessory;
 806:     firePropertyChange(ACCESSORY_CHANGED_PROPERTY, old, accessory);
 807:       }
 808:   }
 809: 
 810:   /**
 811:    * DOCUMENT ME!
 812:    *
 813:    * @param mode DOCUMENT ME!
 814:    */
 815:   public void setFileSelectionMode(int mode)
 816:   {
 817:     if (mode != FILES_ONLY && mode != DIRECTORIES_ONLY
 818:         && mode != FILES_AND_DIRECTORIES)
 819:       throw new IllegalArgumentException("Choose a correct file selection mode.");
 820:     if (fileSelectionMode != mode)
 821:       {
 822:     int old = fileSelectionMode;
 823:     fileSelectionMode = mode;
 824:     firePropertyChange(FILE_SELECTION_MODE_CHANGED_PROPERTY, old,
 825:                        fileSelectionMode);
 826:       }
 827:   }
 828: 
 829:   /**
 830:    * DOCUMENT ME!
 831:    *
 832:    * @return DOCUMENT ME!
 833:    */
 834:   public int getFileSelectionMode()
 835:   {
 836:     return fileSelectionMode;
 837:   }
 838: 
 839:   /**
 840:    * DOCUMENT ME!
 841:    *
 842:    * @return DOCUMENT ME!
 843:    */
 844:   public boolean isFileSelectionEnabled()
 845:   {
 846:     return (fileSelectionMode == FILES_ONLY
 847:            || fileSelectionMode == FILES_AND_DIRECTORIES);
 848:   }
 849: 
 850:   /**
 851:    * DOCUMENT ME!
 852:    *
 853:    * @return DOCUMENT ME!
 854:    */
 855:   public boolean isDirectorySelectionEnabled()
 856:   {
 857:     return (fileSelectionMode == DIRECTORIES_ONLY
 858:            || fileSelectionMode == FILES_AND_DIRECTORIES);
 859:   }
 860: 
 861:   /**
 862:    * DOCUMENT ME!
 863:    *
 864:    * @param b DOCUMENT ME!
 865:    */
 866:   public void setMultiSelectionEnabled(boolean b)
 867:   {
 868:     if (multiSelection != b)
 869:       {
 870:     multiSelection = b;
 871:     firePropertyChange(MULTI_SELECTION_ENABLED_CHANGED_PROPERTY,
 872:                        ! multiSelection, multiSelection);
 873:       }
 874:   }
 875: 
 876:   /**
 877:    * DOCUMENT ME!
 878:    *
 879:    * @return DOCUMENT ME!
 880:    */
 881:   public boolean isMultiSelectionEnabled()
 882:   {
 883:     return multiSelection;
 884:   }
 885: 
 886:   /**
 887:    * DOCUMENT ME!
 888:    *
 889:    * @return DOCUMENT ME!
 890:    */
 891:   public boolean isFileHidingEnabled()
 892:   {
 893:     return fileHiding;
 894:   }
 895: 
 896:   /**
 897:    * DOCUMENT ME!
 898:    *
 899:    * @param b DOCUMENT ME!
 900:    */
 901:   public void setFileHidingEnabled(boolean b)
 902:   {
 903:     if (fileHiding != b)
 904:       {
 905:     fileHiding = b;
 906:     firePropertyChange(FILE_HIDING_CHANGED_PROPERTY, ! fileHiding,
 907:                        fileHiding);
 908:       }
 909:   }
 910: 
 911:   /**
 912:    * DOCUMENT ME!
 913:    *
 914:    * @param filter DOCUMENT ME!
 915:    */
 916:   public void setFileFilter(FileFilter filter)
 917:   {
 918:     if (currentFilter != filter)
 919:       {
 920:     FileFilter old = currentFilter;
 921:     currentFilter = filter;
 922:     firePropertyChange(FILE_FILTER_CHANGED_PROPERTY, old, currentFilter);
 923:       }
 924:   }
 925: 
 926:   /**
 927:    * DOCUMENT ME!
 928:    *
 929:    * @return DOCUMENT ME!
 930:    */
 931:   public FileFilter getFileFilter()
 932:   {
 933:     return currentFilter;
 934:   }
 935: 
 936:   /**
 937:    * DOCUMENT ME!
 938:    *
 939:    * @param fileView DOCUMENT ME!
 940:    */
 941:   public void setFileView(FileView fileView)
 942:   {
 943:     if (fv != fileView)
 944:       {
 945:     FileView old = fv;
 946:     fv = fileView;
 947:     firePropertyChange(FILE_VIEW_CHANGED_PROPERTY, old, fv);
 948:       }
 949:   }
 950: 
 951:   /**
 952:    * DOCUMENT ME!
 953:    *
 954:    * @return DOCUMENT ME!
 955:    */
 956:   public FileView getFileView()
 957:   {
 958:     return fv;
 959:   }
 960: 
 961:   /**
 962:    * DOCUMENT ME!
 963:    *
 964:    * @return DOCUMENT ME!
 965:    */
 966:   private FileView getInternalFileView()
 967:   {
 968:     if (fv == null)
 969:       return getUI().getFileView(this);
 970:     return fv;
 971:   }
 972: 
 973:   /**
 974:    * DOCUMENT ME!
 975:    *
 976:    * @param f DOCUMENT ME!
 977:    *
 978:    * @return DOCUMENT ME!
 979:    */
 980:   public String getName(File f)
 981:   {
 982:     return getInternalFileView().getName(f);
 983:   }
 984: 
 985:   /**
 986:    * DOCUMENT ME!
 987:    *
 988:    * @param f DOCUMENT ME!
 989:    *
 990:    * @return DOCUMENT ME!
 991:    */
 992:   public String getDescription(File f)
 993:   {
 994:     return getInternalFileView().getDescription(f);
 995:   }
 996: 
 997:   /**
 998:    * DOCUMENT ME!
 999:    *
1000:    * @param f DOCUMENT ME!
1001:    *
1002:    * @return DOCUMENT ME!
1003:    */
1004:   public String getTypeDescription(File f)
1005:   {
1006:     return getInternalFileView().getTypeDescription(f);
1007:   }
1008: 
1009:   /**
1010:    * DOCUMENT ME!
1011:    *
1012:    * @param f DOCUMENT ME!
1013:    *
1014:    * @return DOCUMENT ME!
1015:    */
1016:   public Icon getIcon(File f)
1017:   {
1018:     return getInternalFileView().getIcon(f);
1019:   }
1020: 
1021:   /**
1022:    * DOCUMENT ME!
1023:    *
1024:    * @param f DOCUMENT ME!
1025:    *
1026:    * @return DOCUMENT ME!
1027:    */
1028:   public boolean isTraversable(File f)
1029:   {
1030:     return getFileSystemView().isTraversable(f).booleanValue();
1031:   }
1032: 
1033:   /**
1034:    * DOCUMENT ME!
1035:    *
1036:    * @param f DOCUMENT ME!
1037:    *
1038:    * @return DOCUMENT ME!
1039:    */
1040:   public boolean accept(File f)
1041:   {
1042:     if (f == null)
1043:       return false;
1044:     return getFileFilter().accept(f);
1045:   }
1046: 
1047:   /**
1048:    * DOCUMENT ME!
1049:    *
1050:    * @param fsv DOCUMENT ME!
1051:    */
1052:   public void setFileSystemView(FileSystemView fsv)
1053:   {
1054:     if (this.fsv != fsv)
1055:       {
1056:     FileSystemView old = this.fsv;
1057:     this.fsv = fsv;
1058:     firePropertyChange(FILE_SYSTEM_VIEW_CHANGED_PROPERTY, old, this.fsv);
1059:       }
1060:   }
1061: 
1062:   /**
1063:    * DOCUMENT ME!
1064:    *
1065:    * @return DOCUMENT ME!
1066:    */
1067:   public FileSystemView getFileSystemView()
1068:   {
1069:     return fsv;
1070:   }
1071: 
1072:   /**
1073:    * DOCUMENT ME!
1074:    */
1075:   public void approveSelection()
1076:   {
1077:     retval = APPROVE_OPTION;
1078:     fireActionPerformed(APPROVE_SELECTION);
1079:   }
1080: 
1081:   /**
1082:    * DOCUMENT ME!
1083:    */
1084:   public void cancelSelection()
1085:   {
1086:     retval = CANCEL_OPTION;
1087:     fireActionPerformed(CANCEL_SELECTION);
1088:   }
1089: 
1090:   /**
1091:    * DOCUMENT ME!
1092:    *
1093:    * @param l DOCUMENT ME!
1094:    */
1095:   public void addActionListener(ActionListener l)
1096:   {
1097:     listenerList.add(ActionListener.class, l);
1098:   }
1099: 
1100:   /**
1101:    * DOCUMENT ME!
1102:    *
1103:    * @param l DOCUMENT ME!
1104:    */
1105:   public void removeActionListener(ActionListener l)
1106:   {
1107:     try
1108:       {
1109:     listenerList.remove(ActionListener.class, l);
1110:       }
1111:     catch (IllegalArgumentException e)
1112:       {
1113:     e.printStackTrace();
1114:       }
1115:   }
1116: 
1117:   /**
1118:    * DOCUMENT ME!
1119:    *
1120:    * @return DOCUMENT ME!
1121:    */
1122:   public ActionListener[] getActionListeners()
1123:   {
1124:     return (ActionListener[]) getListeners(ActionListener.class);
1125:   }
1126: 
1127:   /**
1128:    * DOCUMENT ME!
1129:    *
1130:    * @param command DOCUMENT ME!
1131:    */
1132:   protected void fireActionPerformed(String command)
1133:   {
1134:     ActionListener[] list = getActionListeners();
1135:     ActionEvent event = new ActionEvent(this, ActionEvent.ACTION_PERFORMED,
1136:                                         command);
1137: 
1138:     for (int i = 0; i < list.length; i++)
1139:       list[i].actionPerformed(event);
1140:   }
1141: 
1142:   /**
1143:    * DOCUMENT ME!
1144:    */
1145:   public void updateUI()
1146:   {
1147:     setUI((FileChooserUI) UIManager.getUI(this));
1148:     revalidate();
1149:   }
1150: 
1151:   /**
1152:    * DOCUMENT ME!
1153:    *
1154:    * @return DOCUMENT ME!
1155:    */
1156:   public String getUIClassID()
1157:   {
1158:     return "FileChooserUI";
1159:   }
1160: 
1161:   /**
1162:    * DOCUMENT ME!
1163:    *
1164:    * @return DOCUMENT ME!
1165:    */
1166:   public FileChooserUI getUI()
1167:   {
1168:     return (FileChooserUI) ui;
1169:   }
1170: 
1171:   /**
1172:    * DOCUMENT ME!
1173:    *
1174:    * @return DOCUMENT ME!
1175:    */
1176:   protected String paramString()
1177:   {
1178:     return "JFileChooser";
1179:   }
1180: 
1181:   /**
1182:    * DOCUMENT ME!
1183:    *
1184:    * @return DOCUMENT ME!
1185:    */
1186:   public AccessibleContext getAccessibleContext()
1187:   {
1188:     return null;
1189:   }
1190: }