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