Source for javax.swing.plaf.basic.BasicFileChooserUI

   1: /* BasicFileChooserUI.java --
   2:    Copyright (C) 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.plaf.basic;
  39: 
  40: import java.awt.BorderLayout;
  41: import java.awt.Color;
  42: import java.awt.Component;
  43: import java.awt.Dimension;
  44: import java.awt.Graphics;
  45: import java.awt.GridBagConstraints;
  46: import java.awt.GridBagLayout;
  47: import java.awt.Point;
  48: import java.awt.Polygon;
  49: import java.awt.Window;
  50: import java.awt.event.ActionEvent;
  51: import java.awt.event.ActionListener;
  52: import java.awt.event.ItemEvent;
  53: import java.awt.event.ItemListener;
  54: import java.awt.event.MouseAdapter;
  55: import java.awt.event.MouseEvent;
  56: import java.awt.event.MouseListener;
  57: import java.beans.PropertyChangeEvent;
  58: import java.beans.PropertyChangeListener;
  59: import java.io.File;
  60: import java.io.IOException;
  61: import java.util.ArrayList;
  62: import java.util.Hashtable;
  63: import javax.swing.AbstractAction;
  64: import javax.swing.Action;
  65: import javax.swing.BoxLayout;
  66: import javax.swing.ButtonGroup;
  67: import javax.swing.Icon;
  68: import javax.swing.JButton;
  69: import javax.swing.JComboBox;
  70: import javax.swing.JComponent;
  71: import javax.swing.JDialog;
  72: import javax.swing.JFileChooser;
  73: import javax.swing.JLabel;
  74: import javax.swing.JList;
  75: import javax.swing.JPanel;
  76: import javax.swing.JScrollPane;
  77: import javax.swing.JTextField;
  78: import javax.swing.JToggleButton;
  79: import javax.swing.ListCellRenderer;
  80: import javax.swing.SwingConstants;
  81: import javax.swing.SwingUtilities;
  82: import javax.swing.Timer;
  83: import javax.swing.UIDefaults;
  84: import javax.swing.UIManager;
  85: import javax.swing.event.ListSelectionEvent;
  86: import javax.swing.event.ListSelectionListener;
  87: import javax.swing.filechooser.FileFilter;
  88: import javax.swing.filechooser.FileSystemView;
  89: import javax.swing.filechooser.FileView;
  90: import javax.swing.plaf.ComponentUI;
  91: import javax.swing.plaf.FileChooserUI;
  92: 
  93: 
  94: /**
  95:  * DOCUMENT ME!
  96:  */
  97: public class BasicFileChooserUI extends FileChooserUI
  98: {
  99:   /**
 100:    * DOCUMENT ME!
 101:    */
 102:   protected class AcceptAllFileFilter extends FileFilter
 103:   {
 104:     public AcceptAllFileFilter()
 105:     {
 106:     }
 107:     
 108:     /**
 109:      * DOCUMENT ME!
 110:      *
 111:      * @param f DOCUMENT ME!
 112:      *
 113:      * @return DOCUMENT ME!
 114:      */
 115:     public boolean accept(File f)
 116:     {
 117:       return true;
 118:     }
 119: 
 120:     /**
 121:      * DOCUMENT ME!
 122:      *
 123:      * @return DOCUMENT ME!
 124:      */
 125:     public String getDescription()
 126:     {
 127:       return acceptAllFileFilterText;
 128:     }
 129:   }
 130: 
 131:   /**
 132:    * DOCUMENT ME!
 133:    */
 134:   protected class ApproveSelectionAction extends AbstractAction
 135:   {
 136:     /**
 137:      * Creates a new ApproveSelectionAction object.
 138:      */
 139:     protected ApproveSelectionAction()
 140:     {
 141:     }
 142: 
 143:     /**
 144:      * DOCUMENT ME!
 145:      *
 146:      * @param e DOCUMENT ME!
 147:      */
 148:     public void actionPerformed(ActionEvent e)
 149:     {
 150:       Object obj = filelist.getSelectedValue();
 151:       if (obj != null)
 152:         {
 153:       File f = filechooser.getFileSystemView().createFileObject(obj
 154:                                                                 .toString());
 155:       if (filechooser.isTraversable(f) && 
 156:               filechooser.getFileSelectionMode() == JFileChooser.FILES_ONLY)
 157:             filechooser.setCurrentDirectory(f);
 158:       else
 159:         {
 160:           filechooser.setSelectedFile(f);
 161:           filechooser.approveSelection();
 162:           closeDialog();
 163:         }
 164:         }
 165:     }
 166:   }
 167: 
 168:   /**
 169:    * DOCUMENT ME!
 170:    */
 171:   protected class BasicFileView extends FileView
 172:   {
 173:     /** DOCUMENT ME! */
 174:     protected Hashtable iconCache = new Hashtable();
 175: 
 176:     public BasicFileView()
 177:     {
 178:     }
 179: 
 180:     /**
 181:      * DOCUMENT ME!
 182:      *
 183:      * @param f DOCUMENT ME!
 184:      * @param i DOCUMENT ME!
 185:      */
 186:     public void cacheIcon(File f, Icon i)
 187:     {
 188:       iconCache.put(f, i);
 189:     }
 190: 
 191:     /**
 192:      * DOCUMENT ME!
 193:      */
 194:     public void clearIconCache()
 195:     {
 196:       iconCache.clear();
 197:     }
 198: 
 199:     /**
 200:      * DOCUMENT ME!
 201:      *
 202:      * @param f DOCUMENT ME!
 203:      *
 204:      * @return DOCUMENT ME!
 205:      */
 206:     public Icon getCachedIcon(File f)
 207:     {
 208:       return (Icon) iconCache.get(f);
 209:     }
 210: 
 211:     /**
 212:      * DOCUMENT ME!
 213:      *
 214:      * @param f DOCUMENT ME!
 215:      *
 216:      * @return DOCUMENT ME!
 217:      */
 218:     public String getDescription(File f)
 219:     {
 220:       return getName(f);
 221:     }
 222: 
 223:     /**
 224:      * DOCUMENT ME!
 225:      *
 226:      * @param f DOCUMENT ME!
 227:      *
 228:      * @return DOCUMENT ME!
 229:      */
 230:     public Icon getIcon(File f)
 231:     {
 232:       Icon val = getCachedIcon(f);
 233:       if (val != null)
 234:     return val;
 235:       if (filechooser.isTraversable(f))
 236:     val = directoryIcon;
 237:       else
 238:     val = fileIcon;
 239:       cacheIcon(f, val);
 240:       return val;
 241:     }
 242: 
 243:     /**
 244:      * DOCUMENT ME!
 245:      *
 246:      * @param f DOCUMENT ME!
 247:      *
 248:      * @return DOCUMENT ME!
 249:      */
 250:     public String getName(File f)
 251:     {
 252:       return f.getName();
 253:     }
 254: 
 255:     /**
 256:      * DOCUMENT ME!
 257:      *
 258:      * @param f DOCUMENT ME!
 259:      *
 260:      * @return DOCUMENT ME!
 261:      */
 262:     public String getTypeDescription(File f)
 263:     {
 264:       if (filechooser.isTraversable(f))
 265:     return dirDescText;
 266:       else
 267:     return fileDescText;
 268:     }
 269: 
 270:     /**
 271:      * DOCUMENT ME!
 272:      *
 273:      * @param f DOCUMENT ME!
 274:      *
 275:      * @return DOCUMENT ME!
 276:      */
 277:     public Boolean isHidden(File f)
 278:     {
 279:       return new Boolean(filechooser.getFileSystemView().isHiddenFile(f));
 280:     }
 281:   }
 282: 
 283:   /**
 284:    * DOCUMENT ME!
 285:    */
 286:   protected class CancelSelectionAction extends AbstractAction
 287:   {
 288:     /**
 289:      * Creates a new CancelSelectionAction object.
 290:      */
 291:     protected CancelSelectionAction()
 292:     {
 293:     }
 294: 
 295:     /**
 296:      * DOCUMENT ME!
 297:      *
 298:      * @param e DOCUMENT ME!
 299:      */
 300:     public void actionPerformed(ActionEvent e)
 301:     {
 302:       filechooser.cancelSelection();
 303:       closeDialog();
 304:     }
 305:   }
 306: 
 307:   /**
 308:    * DOCUMENT ME!
 309:    */
 310:   protected class ChangeToParentDirectoryAction extends AbstractAction
 311:   {
 312:     /**
 313:      * Creates a new ChangeToParentDirectoryAction object.
 314:      */
 315:     protected ChangeToParentDirectoryAction()
 316:     {
 317:     }
 318: 
 319:     /**
 320:      * DOCUMENT ME!
 321:      *
 322:      * @param e DOCUMENT ME!
 323:      */
 324:     public void actionPerformed(ActionEvent e)
 325:     {
 326:       filechooser.changeToParentDirectory();
 327:       filechooser.revalidate();
 328:       filechooser.repaint();
 329:     }
 330:   }
 331: 
 332:   /**
 333:    * DOCUMENT ME!
 334:    */
 335:   protected class DoubleClickListener extends MouseAdapter
 336:   {
 337:     /** DOCUMENT ME! */
 338:     private Timer timer = null;
 339: 
 340:     /** DOCUMENT ME! */
 341:     private Object lastSelected = null;
 342: 
 343:     /** DOCUMENT ME! */
 344:     private JList list = null;
 345: 
 346:     /**
 347:      * Creates a new DoubleClickListener object.
 348:      *
 349:      * @param list DOCUMENT ME!
 350:      */
 351:     public DoubleClickListener(JList list)
 352:     {
 353:       this.list = list;
 354:       timer = new Timer(1000, null);
 355:       timer.setRepeats(false);
 356:       lastSelected = list.getSelectedValue();
 357:       setDirectorySelected(false);
 358:     }
 359: 
 360:     /**
 361:      * DOCUMENT ME!
 362:      *
 363:      * @param e DOCUMENT ME!
 364:      */
 365:     public void mouseClicked(MouseEvent e)
 366:     {
 367:       if (list.getSelectedValue() == null)
 368:     return;
 369:       FileSystemView fsv = filechooser.getFileSystemView();
 370:       if (timer.isRunning()
 371:           && list.getSelectedValue().toString().equals(lastSelected.toString()))
 372:         {
 373:       File f = fsv.createFileObject(lastSelected.toString());
 374:       timer.stop();
 375:       if (filechooser.isTraversable(f))
 376:         {
 377:           filechooser.setCurrentDirectory(f);
 378:           filechooser.rescanCurrentDirectory();
 379:         }
 380:       else
 381:         {
 382:           filechooser.setSelectedFile(f);
 383:           filechooser.approveSelection();
 384:           closeDialog();
 385:         }
 386:         }
 387:       else
 388:         {
 389:       File f = fsv.createFileObject(list.getSelectedValue().toString());
 390:       if (filechooser.isTraversable(f))
 391:         {
 392:           setDirectorySelected(true);
 393:           setDirectory(f);
 394:         }
 395:       else
 396:         {
 397:           setDirectorySelected(false);
 398:           setDirectory(null);
 399:         }
 400:       lastSelected = list.getSelectedValue().toString();
 401:       timer.restart();
 402:         }
 403:     }
 404: 
 405:     /**
 406:      * DOCUMENT ME!
 407:      *
 408:      * @param e DOCUMENT ME!
 409:      */
 410:     public void mouseEntered(MouseEvent e)
 411:     {
 412:       // FIXME: Implement
 413:     }
 414:   }
 415: 
 416:   /**
 417:    * DOCUMENT ME!
 418:    */
 419:   protected class GoHomeAction extends AbstractAction
 420:   {
 421:     /**
 422:      * Creates a new GoHomeAction object.
 423:      */
 424:     protected GoHomeAction()
 425:     {
 426:     }
 427: 
 428:     /**
 429:      * DOCUMENT ME!
 430:      *
 431:      * @param e DOCUMENT ME!
 432:      */
 433:     public void actionPerformed(ActionEvent e)
 434:     {
 435:       filechooser.setCurrentDirectory(filechooser.getFileSystemView()
 436:                                                  .getHomeDirectory());
 437:       filechooser.revalidate();
 438:       filechooser.repaint();
 439:     }
 440:   }
 441: 
 442:   /**
 443:    * DOCUMENT ME!
 444:    */
 445:   protected class NewFolderAction extends AbstractAction
 446:   {
 447:     /**
 448:      * Creates a new NewFolderAction object.
 449:      */
 450:     protected NewFolderAction()
 451:     {
 452:     }
 453: 
 454:     /**
 455:      * DOCUMENT ME!
 456:      *
 457:      * @param e DOCUMENT ME!
 458:      */
 459:     public void actionPerformed(ActionEvent e)
 460:     {
 461:       try
 462:         {
 463:       filechooser.getFileSystemView().createNewFolder(filechooser
 464:                                                       .getCurrentDirectory());
 465:         }
 466:       catch (IOException ioe)
 467:         {
 468:       return;
 469:         }
 470:       filechooser.rescanCurrentDirectory();
 471:       filechooser.repaint();
 472:     }
 473:   }
 474: 
 475:   /**
 476:    * DOCUMENT ME!
 477:    */
 478:   protected class SelectionListener implements ListSelectionListener
 479:   {
 480:     /**
 481:      * Creates a new SelectionListener object.
 482:      */
 483:     protected SelectionListener()
 484:     {
 485:     }
 486: 
 487:     /**
 488:      * DOCUMENT ME!
 489:      *
 490:      * @param e DOCUMENT ME!
 491:      */
 492:     public void valueChanged(ListSelectionEvent e)
 493:     {
 494:       Object f = filelist.getSelectedValue();
 495:       if (f == null)
 496:     return;
 497:       File file = filechooser.getFileSystemView().createFileObject(f.toString());
 498:       if (! filechooser.isTraversable(file))
 499:     filechooser.setSelectedFile(file);
 500:       else
 501:     filechooser.setSelectedFile(null);
 502:     }
 503:   }
 504: 
 505:   /**
 506:    * DOCUMENT ME!
 507:    */
 508:   protected class UpdateAction extends AbstractAction
 509:   {
 510:     /**
 511:      * Creates a new UpdateAction object.
 512:      */
 513:     protected UpdateAction()
 514:     {
 515:     }
 516: 
 517:     /**
 518:      * DOCUMENT ME!
 519:      *
 520:      * @param e DOCUMENT ME!
 521:      */
 522:     public void actionPerformed(ActionEvent e)
 523:     {
 524:     }
 525:   }
 526: 
 527:   /** DOCUMENT ME! */
 528:   protected int cancelButtonMnemonic;
 529: 
 530:   /** DOCUMENT ME! */
 531:   protected String cancelButtonText;
 532: 
 533:   /** DOCUMENT ME! */
 534:   protected String cancelButtonToolTipText;
 535: 
 536:   /** DOCUMENT ME! */
 537:   protected Icon computerIcon = new Icon()
 538:     {
 539:       public int getIconHeight()
 540:       {
 541:     return ICON_SIZE;
 542:       }
 543: 
 544:       public int getIconWidth()
 545:       {
 546:     return ICON_SIZE;
 547:       }
 548: 
 549:       public void paintIcon(Component c, Graphics g, int x, int y)
 550:       {
 551:       }
 552:     };
 553: 
 554:   /** DOCUMENT ME! */
 555:   protected Icon detailsViewIcon = new Icon()
 556:     {
 557:       public int getIconHeight()
 558:       {
 559:     return ICON_SIZE;
 560:       }
 561: 
 562:       public int getIconWidth()
 563:       {
 564:     return ICON_SIZE;
 565:       }
 566: 
 567:       public void paintIcon(Component c, Graphics g, int x, int y)
 568:       {
 569:     Color saved = g.getColor();
 570:     g.translate(x, y);
 571: 
 572:     g.setColor(Color.GRAY);
 573:     g.drawRect(1, 1, 15, 20);
 574:     g.drawLine(17, 6, 23, 6);
 575:     g.drawLine(17, 12, 23, 12);
 576:     g.drawLine(17, 18, 23, 18);
 577: 
 578:     g.setColor(saved);
 579:     g.translate(-x, -y);
 580:       }
 581:     };
 582: 
 583:   /** DOCUMENT ME! */
 584:   protected Icon directoryIcon = new Icon()
 585:     {
 586:       public int getIconHeight()
 587:       {
 588:     return ICON_SIZE;
 589:       }
 590: 
 591:       public int getIconWidth()
 592:       {
 593:     return ICON_SIZE;
 594:       }
 595: 
 596:       public void paintIcon(Component c, Graphics g, int x, int y)
 597:       {
 598:     Color saved = g.getColor();
 599:     g.translate(x, y);
 600: 
 601:     Point ap = new Point(3, 7);
 602:     Point bp = new Point(3, 21);
 603:     Point cp = new Point(21, 21);
 604:     Point dp = new Point(21, 12);
 605:     Point ep = new Point(16, 12);
 606:     Point fp = new Point(13, 7);
 607: 
 608:     Polygon dir = new Polygon(new int[] { ap.x, bp.x, cp.x, dp.x, ep.x, fp.x },
 609:                               new int[] { ap.y, bp.y, cp.y, dp.y, ep.y, fp.y },
 610:                               6);
 611: 
 612:     g.setColor(new Color(153, 204, 255));
 613:     g.fillPolygon(dir);
 614:     g.setColor(Color.BLACK);
 615:     g.drawPolygon(dir);
 616: 
 617:     g.translate(-x, -y);
 618:     g.setColor(saved);
 619:       }
 620:     };
 621: 
 622:   /** DOCUMENT ME! */
 623:   protected int directoryOpenButtonMnemonic;
 624: 
 625:   /** DOCUMENT ME! */
 626:   protected String directoryOpenButtonText;
 627: 
 628:   /** DOCUMENT ME! */
 629:   protected String directoryOpenButtonToolTipText;
 630: 
 631:   /** DOCUMENT ME! */
 632:   protected Icon fileIcon = new Icon()
 633:     {
 634:       public int getIconHeight()
 635:       {
 636:     return ICON_SIZE;
 637:       }
 638: 
 639:       public int getIconWidth()
 640:       {
 641:     return ICON_SIZE;
 642:       }
 643: 
 644:       public void paintIcon(Component c, Graphics g, int x, int y)
 645:       {
 646:     Color saved = g.getColor();
 647:     g.translate(x, y);
 648: 
 649:     Point a = new Point(5, 4);
 650:     Point b = new Point(5, 20);
 651:     Point d = new Point(19, 20);
 652:     Point e = new Point(19, 7);
 653:     Point f = new Point(16, 4);
 654: 
 655:     Polygon p = new Polygon(new int[] { a.x, b.x, d.x, e.x, f.x, },
 656:                             new int[] { a.y, b.y, d.y, e.y, f.y }, 5);
 657: 
 658:     g.setColor(Color.WHITE);
 659:     g.fillPolygon(p);
 660:     g.setColor(Color.BLACK);
 661:     g.drawPolygon(p);
 662: 
 663:     g.drawLine(16, 4, 14, 6);
 664:     g.drawLine(14, 6, 19, 7);
 665: 
 666:     g.setColor(saved);
 667:     g.translate(-x, -y);
 668:       }
 669:     };
 670: 
 671:   /** DOCUMENT ME! */
 672:   protected Icon floppyDriveIcon = new Icon()
 673:     {
 674:       public int getIconHeight()
 675:       {
 676:     return ICON_SIZE;
 677:       }
 678: 
 679:       public int getIconWidth()
 680:       {
 681:     return ICON_SIZE;
 682:       }
 683: 
 684:       public void paintIcon(Component c, Graphics g, int x, int y)
 685:       {
 686:       }
 687:     };
 688: 
 689:   /** DOCUMENT ME! */
 690:   protected Icon hardDriveIcon = new Icon()
 691:     {
 692:       public int getIconHeight()
 693:       {
 694:     return ICON_SIZE;
 695:       }
 696: 
 697:       public int getIconWidth()
 698:       {
 699:     return ICON_SIZE;
 700:       }
 701: 
 702:       public void paintIcon(Component c, Graphics g, int x, int y)
 703:       {
 704:       }
 705:     };
 706: 
 707:   /** DOCUMENT ME! */
 708:   protected int helpButtonMnemonic;
 709: 
 710:   /** DOCUMENT ME! */
 711:   protected String helpButtonText;
 712: 
 713:   /** DOCUMENT ME! */
 714:   protected String helpButtonToolTipText;
 715: 
 716:   /** DOCUMENT ME! */
 717:   protected Icon homeFolderIcon = new Icon()
 718:     {
 719:       public int getIconHeight()
 720:       {
 721:     return ICON_SIZE;
 722:       }
 723: 
 724:       public int getIconWidth()
 725:       {
 726:     return ICON_SIZE;
 727:       }
 728: 
 729:       public void paintIcon(Component c, Graphics g, int x, int y)
 730:       {
 731:     Color saved = g.getColor();
 732:     g.translate(x, y);
 733: 
 734:     Point a = new Point(12, 3);
 735:     Point b = new Point(4, 10);
 736:     Point d = new Point(20, 10);
 737: 
 738:     Polygon p = new Polygon(new int[] { a.x, b.x, d.x },
 739:                             new int[] { a.y, b.y, d.y }, 3);
 740: 
 741:     g.setColor(new Color(104, 51, 0));
 742:     g.fillPolygon(p);
 743:     g.setColor(Color.BLACK);
 744:     g.drawPolygon(p);
 745: 
 746:     g.setColor(Color.WHITE);
 747:     g.fillRect(8, 10, 8, 10);
 748:     g.setColor(Color.BLACK);
 749:     g.drawRect(8, 10, 8, 10);
 750: 
 751:     g.setColor(saved);
 752:     g.translate(-x, -y);
 753:       }
 754:     };
 755: 
 756:   /** DOCUMENT ME! */
 757:   protected Icon listViewIcon = new Icon()
 758:     {
 759:       public int getIconHeight()
 760:       {
 761:     return ICON_SIZE;
 762:       }
 763: 
 764:       public int getIconWidth()
 765:       {
 766:     return ICON_SIZE;
 767:       }
 768: 
 769:       // Not needed. Only simplifies things until we get real icons.
 770:       private void paintPartial(Graphics g, int x, int y)
 771:       {
 772:     Color saved = g.getColor();
 773:     g.translate(x, y);
 774: 
 775:     g.setColor(Color.GRAY);
 776:     g.drawRect(1, 1, 7, 10);
 777:     g.drawLine(8, 6, 11, 6);
 778: 
 779:     g.setColor(saved);
 780:     g.translate(-x, -y);
 781:       }
 782: 
 783:       public void paintIcon(Component c, Graphics g, int x, int y)
 784:       {
 785:     Color saved = g.getColor();
 786:     g.translate(x, y);
 787: 
 788:     paintPartial(g, 0, 0);
 789:     paintPartial(g, 12, 0);
 790:     paintPartial(g, 0, 12);
 791:     paintPartial(g, 12, 12);
 792: 
 793:     g.setColor(saved);
 794:     g.translate(-x, -y);
 795:       }
 796:     };
 797: 
 798:   /** DOCUMENT ME! */
 799:   protected Icon newFolderIcon = directoryIcon;
 800: 
 801:   /** DOCUMENT ME! */
 802:   protected int openButtonMnemonic;
 803: 
 804:   /** DOCUMENT ME! */
 805:   protected String openButtonText;
 806: 
 807:   /** DOCUMENT ME! */
 808:   protected String openButtonToolTipText;
 809: 
 810:   /** DOCUMENT ME! */
 811:   protected int saveButtonMnemonic;
 812: 
 813:   /** DOCUMENT ME! */
 814:   protected String saveButtonText;
 815: 
 816:   /** DOCUMENT ME! */
 817:   protected String saveButtonToolTipText;
 818: 
 819:   /** DOCUMENT ME! */
 820:   protected int updateButtonMnemonic;
 821: 
 822:   /** DOCUMENT ME! */
 823:   protected String updateButtonText;
 824: 
 825:   /** DOCUMENT ME! */
 826:   protected String updateButtonToolTipText;
 827: 
 828:   /** DOCUMENT ME! */
 829:   protected Icon upFolderIcon = new Icon()
 830:     {
 831:       public int getIconHeight()
 832:       {
 833:     return ICON_SIZE;
 834:       }
 835: 
 836:       public int getIconWidth()
 837:       {
 838:     return ICON_SIZE;
 839:       }
 840: 
 841:       public void paintIcon(Component comp, Graphics g, int x, int y)
 842:       {
 843:     Color saved = g.getColor();
 844:     g.translate(x, y);
 845: 
 846:     Point a = new Point(3, 7);
 847:     Point b = new Point(3, 21);
 848:     Point c = new Point(21, 21);
 849:     Point d = new Point(21, 12);
 850:     Point e = new Point(16, 12);
 851:     Point f = new Point(13, 7);
 852: 
 853:     Polygon dir = new Polygon(new int[] { a.x, b.x, c.x, d.x, e.x, f.x },
 854:                               new int[] { a.y, b.y, c.y, d.y, e.y, f.y }, 6);
 855: 
 856:     g.setColor(new Color(153, 204, 255));
 857:     g.fillPolygon(dir);
 858:     g.setColor(Color.BLACK);
 859:     g.drawPolygon(dir);
 860: 
 861:     a = new Point(12, 15);
 862:     b = new Point(9, 18);
 863:     c = new Point(15, 18);
 864: 
 865:     Polygon arrow = new Polygon(new int[] { a.x, b.x, c.x },
 866:                                 new int[] { a.y, b.y, c.y }, 3);
 867: 
 868:     g.fillPolygon(arrow);
 869: 
 870:     g.drawLine(12, 15, 12, 22);
 871: 
 872:     g.translate(-x, -y);
 873:     g.setColor(saved);
 874:       }
 875:     };
 876: 
 877:   // -- begin private, but package local since used in inner classes --
 878: 
 879:   JFileChooser filechooser;
 880: 
 881:   /** DOCUMENT ME! */
 882:   JList filelist;
 883: 
 884:   /** DOCUMENT ME! */
 885:   JComboBox filters;
 886: 
 887:   /** DOCUMENT ME! */
 888:   BasicDirectoryModel model;
 889: 
 890:   /** DOCUMENT ME! */
 891:   FileFilter acceptAll = new AcceptAllFileFilter();
 892: 
 893:   /** DOCUMENT ME! */
 894:   FileView fv = new BasicFileView();
 895: 
 896:   /** DOCUMENT ME! */
 897:   static final int ICON_SIZE = 24;
 898: 
 899:   /** DOCUMENT ME! */
 900:   JComboBox parents;
 901: 
 902:   /** DOCUMENT ME! */
 903:   String filename;
 904: 
 905:   /** DOCUMENT ME! */
 906:   JButton accept;
 907: 
 908:   /** DOCUMENT ME! */
 909:   JButton cancel;
 910: 
 911:   /** DOCUMENT ME! */
 912:   JButton upFolderButton;
 913: 
 914:   /** DOCUMENT ME! */
 915:   JButton newFolderButton;
 916: 
 917:   /** DOCUMENT ME! */
 918:   JButton homeFolderButton;
 919: 
 920:   /** DOCUMENT ME! */
 921:   JPanel accessoryPanel;
 922: 
 923:   /** DOCUMENT ME! */
 924:   PropertyChangeListener propertyChangeListener;
 925: 
 926:   /** DOCUMENT ME! */
 927:   String acceptAllFileFilterText;
 928: 
 929:   /** DOCUMENT ME! */
 930:   String dirDescText;
 931: 
 932:   /** DOCUMENT ME! */
 933:   String fileDescText;
 934: 
 935:   /** DOCUMENT ME! */
 936:   boolean dirSelected = false;
 937: 
 938:   /** DOCUMENT ME! */
 939:   File currDir = null;
 940: 
 941:   JPanel bottomPanel;
 942: 
 943:   /** DOCUMENT ME! */
 944:   JPanel closePanel;
 945: 
 946:   // -- end private --
 947:   private class ListLabelRenderer
 948:     extends JLabel
 949:     implements ListCellRenderer
 950:   {
 951:     /** DOCUMENT ME! */
 952:     final Color selected = new Color(153, 204, 255);
 953: 
 954:     /**
 955:      * Creates a new ListLabelRenderer object.
 956:      */
 957:     public ListLabelRenderer()
 958:     {
 959:       super();
 960:       setOpaque(true);
 961:     }
 962: 
 963:     /**
 964:      * DOCUMENT ME!
 965:      *
 966:      * @param list DOCUMENT ME!
 967:      * @param value DOCUMENT ME!
 968:      * @param index DOCUMENT ME!
 969:      * @param isSelected DOCUMENT ME!
 970:      * @param cellHasFocus DOCUMENT ME!
 971:      *
 972:      * @return DOCUMENT ME!
 973:      */
 974:     public Component getListCellRendererComponent(JList list, Object value,
 975:                                                   int index,
 976:                                                   boolean isSelected,
 977:                                                   boolean cellHasFocus)
 978:     {
 979:       setHorizontalAlignment(SwingConstants.LEFT);
 980:       File file = (File) value;
 981:       setText(filechooser.getName(file));
 982:       setIcon(filechooser.getIcon(file));
 983:       setBackground(isSelected ? selected : Color.WHITE);
 984:       setForeground(Color.BLACK);
 985: 
 986:       return this;
 987:     }
 988:   }
 989: 
 990:   /**
 991:    * DOCUMENT ME!
 992:    */
 993:   public class CBLabelRenderer extends JLabel implements ListCellRenderer
 994:   {
 995:     /**
 996:      * Creates a new CBLabelRenderer object.
 997:      */
 998:     public CBLabelRenderer()
 999:     {
1000:       super();
1001:       setOpaque(true);
1002:     }
1003: 
1004:     /**
1005:      * DOCUMENT ME!
1006:      *
1007:      * @param list DOCUMENT ME!
1008:      * @param value DOCUMENT ME!
1009:      * @param index DOCUMENT ME!
1010:      * @param isSelected DOCUMENT ME!
1011:      * @param cellHasFocus DOCUMENT ME!
1012:      *
1013:      * @return DOCUMENT ME!
1014:      */
1015:     public Component getListCellRendererComponent(JList list, Object value,
1016:                                                   int index,
1017:                                                   boolean isSelected,
1018:                                                   boolean cellHasFocus)
1019:     {
1020:       setHorizontalAlignment(SwingConstants.LEFT);
1021:       setIcon(directoryIcon);
1022:       setText(value.toString());
1023:       setForeground(Color.BLACK);
1024:       setBackground(Color.WHITE);
1025: 
1026:       return this;
1027:     }
1028:   }
1029: 
1030:   void closeDialog()
1031:   {
1032:     Window owner = SwingUtilities.windowForComponent(filechooser);
1033:     if (owner instanceof JDialog)
1034:       ((JDialog) owner).dispose();
1035:   }
1036: 
1037:   /**
1038:    * Creates a new BasicFileChooserUI object.
1039:    *
1040:    * @param b DOCUMENT ME!
1041:    */
1042:   public BasicFileChooserUI(JFileChooser b)
1043:   {
1044:     this.filechooser = b;
1045:   }
1046: 
1047:   /**
1048:    * DOCUMENT ME!
1049:    *
1050:    * @param c DOCUMENT ME!
1051:    *
1052:    * @return DOCUMENT ME!
1053:    */
1054:   public static ComponentUI createUI(JComponent c)
1055:   {
1056:     return new BasicFileChooserUI((JFileChooser) c);
1057:   }
1058: 
1059:   /**
1060:    * DOCUMENT ME!
1061:    *
1062:    * @param c DOCUMENT ME!
1063:    */
1064:   public void installUI(JComponent c)
1065:   {
1066:     if (c instanceof JFileChooser)
1067:       {
1068:     JFileChooser fc = (JFileChooser) c;
1069:     fc.resetChoosableFileFilters();
1070:     createModel();
1071:     clearIconCache();
1072:     installDefaults(fc);
1073:     installComponents(fc);
1074:     installListeners(fc);
1075:       }
1076:   }
1077: 
1078:   /**
1079:    * DOCUMENT ME!
1080:    *
1081:    * @param c DOCUMENT ME!
1082:    */
1083:   public void uninstallUI(JComponent c)
1084:   {
1085:     model = null;
1086:     uninstallListeners(filechooser);
1087:     uninstallComponents(filechooser);
1088:     uninstallDefaults(filechooser);
1089:     filechooser = null;
1090:   }
1091: 
1092:   // FIXME: Indent the entries in the combobox
1093:   // Made this method package private to access it from within inner classes
1094:   // with better performance
1095:   void boxEntries()
1096:   {
1097:     ArrayList parentFiles = new ArrayList();
1098:     File parent = filechooser.getCurrentDirectory();
1099:     if (parent == null)
1100:       parent = filechooser.getFileSystemView().getDefaultDirectory();
1101:     while (parent != null)
1102:       {
1103:         String name = parent.getName();
1104:         if (name.equals(""))
1105:           name = parent.getAbsolutePath();
1106: 
1107:         parentFiles.add(parentFiles.size(), name);
1108:         parent = parent.getParentFile();
1109:       }
1110: 
1111:     if (parentFiles.size() == 0)
1112:       return;
1113: 
1114:     if (parents.getItemCount() > 0)
1115:       parents.removeAllItems();
1116:     for (int i = parentFiles.size() - 1; i >= 0; i--)
1117:       parents.addItem(parentFiles.get(i));
1118:     parents.setSelectedIndex(parentFiles.size() - 1);
1119:     parents.revalidate();
1120:     parents.repaint();
1121:   }
1122: 
1123:   /**
1124:    * DOCUMENT ME!
1125:    *
1126:    * @return DOCUMENT ME!
1127:    */
1128:   private ItemListener createBoxListener()
1129:   {
1130:     return new ItemListener()
1131:       {
1132:     public void itemStateChanged(ItemEvent e)
1133:     {
1134:       if (parents.getItemCount() - 1 == parents.getSelectedIndex())
1135:         return;
1136:       StringBuffer dir = new StringBuffer();
1137:       for (int i = 0; i <= parents.getSelectedIndex(); i++)
1138:         {
1139:           dir.append(parents.getItemAt(i));
1140:           dir.append(File.separatorChar);
1141:         }
1142:       filechooser.setCurrentDirectory(filechooser.getFileSystemView()
1143:                                                  .createFileObject(dir
1144:                                                                    .toString()));
1145:     }
1146:       };
1147:   }
1148: 
1149:   /**
1150:    * DOCUMENT ME!
1151:    *
1152:    * @return DOCUMENT ME!
1153:    */
1154:   private ItemListener createFilterListener()
1155:   {
1156:     return new ItemListener()
1157:       {
1158:     public void itemStateChanged(ItemEvent e)
1159:     {
1160:       int index = filters.getSelectedIndex();
1161:       if (index == -1)
1162:         return;
1163:       filechooser.setFileFilter(filechooser.getChoosableFileFilters()[index]);
1164:     }
1165:       };
1166:   }
1167: 
1168:   void filterEntries()
1169:   {
1170:     FileFilter[] list = filechooser.getChoosableFileFilters();
1171:     if (filters.getItemCount() > 0)
1172:       filters.removeAllItems();
1173: 
1174:     int index = -1;
1175:     String selected = filechooser.getFileFilter().getDescription();
1176:     for (int i = 0; i < list.length; i++)
1177:       {
1178:     if (selected.equals(list[i].getDescription()))
1179:       index = i;
1180:     filters.addItem(list[i].getDescription());
1181:       }
1182:     filters.setSelectedIndex(index);
1183:     filters.revalidate();
1184:     filters.repaint();
1185:   }
1186: 
1187:   /**
1188:    * DOCUMENT ME!
1189:    *
1190:    * @param fc DOCUMENT ME!
1191:    */
1192:   public void installComponents(JFileChooser fc)
1193:   {
1194:     JLabel look = new JLabel("Look In:");
1195: 
1196:     parents = new JComboBox();
1197:     parents.setRenderer(new CBLabelRenderer());
1198:     boxEntries();
1199:     look.setLabelFor(parents);
1200:     JPanel parentsPanel = new JPanel();
1201:     parentsPanel.add(look);
1202:     parentsPanel.add(parents);
1203:     JPanel buttonPanel = new JPanel();
1204: 
1205:     upFolderButton = new JButton();
1206:     upFolderButton.setIcon(upFolderIcon);
1207:     buttonPanel.add(upFolderButton);
1208: 
1209:     homeFolderButton = new JButton();
1210:     homeFolderButton = new JButton(homeFolderIcon);
1211:     buttonPanel.add(homeFolderButton);
1212: 
1213:     newFolderButton = new JButton();
1214:     newFolderButton.setIcon(newFolderIcon);
1215:     buttonPanel.add(newFolderButton);
1216: 
1217:     ButtonGroup toggles = new ButtonGroup();
1218:     JToggleButton listViewButton = new JToggleButton();
1219:     listViewButton.setIcon(listViewIcon);
1220:     toggles.add(listViewButton);
1221:     buttonPanel.add(listViewButton);
1222: 
1223:     JToggleButton detailsViewButton = new JToggleButton();
1224:     detailsViewButton.setIcon(detailsViewIcon);
1225:     toggles.add(detailsViewButton);
1226:     buttonPanel.add(detailsViewButton);
1227: 
1228:     JPanel topPanel = new JPanel();
1229:     topPanel.setLayout(new java.awt.FlowLayout());
1230:     topPanel.add(parentsPanel);
1231:     topPanel.add(buttonPanel);
1232: 
1233:     accessoryPanel = new JPanel();
1234:     if (filechooser.getAccessory() != null)
1235:       accessoryPanel.add(filechooser.getAccessory(), BorderLayout.CENTER);
1236: 
1237:     filelist = new JList(model);
1238:     filelist.setVisibleRowCount(6);
1239:     JScrollPane scrollp = new JScrollPane(filelist);
1240:     scrollp.setPreferredSize(new Dimension(400, 175));
1241:     filelist.setBackground(Color.WHITE);
1242: 
1243:     filelist.setLayoutOrientation(JList.VERTICAL_WRAP);
1244:     filelist.setCellRenderer(new ListLabelRenderer());
1245: 
1246:     GridBagConstraints c = new GridBagConstraints();
1247:     c.gridx = 0;
1248:     c.gridy = 0;
1249:     c.fill = GridBagConstraints.BOTH;
1250:     c.weightx = 1;
1251:     c.weighty = 1;
1252: 
1253:     JPanel centrePanel = new JPanel();
1254:     centrePanel.setLayout(new GridBagLayout());
1255:     centrePanel.add(scrollp, c);
1256: 
1257:     c.gridx = 1;
1258:     centrePanel.add(accessoryPanel, c);
1259: 
1260:     JLabel fileNameLabel = new JLabel("File Name:");
1261:     JLabel fileTypesLabel = new JLabel("Files of Type:");
1262: 
1263:     JTextField entry = new JTextField();
1264:     filters = new JComboBox();
1265:     filterEntries();
1266: 
1267:     fileNameLabel.setLabelFor(entry);
1268:     fileNameLabel.setHorizontalTextPosition(SwingConstants.LEFT);
1269:     fileTypesLabel.setLabelFor(filters);
1270:     fileTypesLabel.setHorizontalTextPosition(SwingConstants.LEFT);
1271: 
1272:     closePanel = new JPanel();
1273:     accept = getApproveButton(filechooser);
1274:     cancel = new JButton(cancelButtonText);
1275:     cancel.setMnemonic(cancelButtonMnemonic);
1276:     cancel.setToolTipText(cancelButtonToolTipText);
1277:     closePanel.add(accept);
1278:     closePanel.add(cancel);
1279: 
1280:     c.anchor = GridBagConstraints.WEST;
1281:     c.weighty = 0;
1282:     c.weightx = 0;
1283:     c.gridx = 0;
1284: 
1285:     bottomPanel = new JPanel();
1286:     bottomPanel.setLayout(new GridBagLayout());
1287:     bottomPanel.add(fileNameLabel, c);
1288: 
1289:     c.gridy = 1;
1290:     bottomPanel.add(fileTypesLabel, c);
1291:     c.gridx = 1;
1292:     c.gridy = 0;
1293:     c.weightx = 1;
1294:     c.weighty = 1;
1295:     bottomPanel.add(entry, c);
1296: 
1297:     c.gridy = 1;
1298:     bottomPanel.add(filters, c);
1299: 
1300:     c.fill = GridBagConstraints.NONE;
1301:     c.gridy = 2;
1302:     c.anchor = GridBagConstraints.EAST;
1303:     bottomPanel.add(closePanel, c);
1304: 
1305:     filechooser.setLayout(new BorderLayout());
1306:     filechooser.add(topPanel, BorderLayout.NORTH);
1307:     filechooser.add(centrePanel, BorderLayout.CENTER);
1308:     filechooser.add(bottomPanel, BorderLayout.SOUTH);
1309:   }
1310: 
1311:   /**
1312:    * DOCUMENT ME!
1313:    *
1314:    * @param fc DOCUMENT ME!
1315:    */
1316:   public void uninstallComponents(JFileChooser fc)
1317:   {
1318:     parents = null;
1319: 
1320:     accept = null;
1321:     cancel = null;
1322:     upFolderButton = null;
1323:     homeFolderButton = null;
1324:     newFolderButton = null;
1325: 
1326:     filelist = null;
1327:   }
1328: 
1329:   /**
1330:    * DOCUMENT ME!
1331:    *
1332:    * @param fc DOCUMENT ME!
1333:    */
1334:   protected void installListeners(JFileChooser fc)
1335:   {
1336:     propertyChangeListener = createPropertyChangeListener(filechooser);
1337:     filechooser.addPropertyChangeListener(propertyChangeListener);
1338: 
1339:     //parents.addItemListener(createBoxListener());
1340:     accept.addActionListener(getApproveSelectionAction());
1341:     cancel.addActionListener(getCancelSelectionAction());
1342:     upFolderButton.addActionListener(getChangeToParentDirectoryAction());
1343:     homeFolderButton.addActionListener(getGoHomeAction());
1344:     newFolderButton.addActionListener(getNewFolderAction());
1345:     filters.addItemListener(createFilterListener());
1346: 
1347:     filelist.addMouseListener(createDoubleClickListener(filechooser, filelist));
1348:     filelist.addListSelectionListener(createListSelectionListener(filechooser));
1349:   }
1350: 
1351:   /**
1352:    * DOCUMENT ME!
1353:    *
1354:    * @param fc DOCUMENT ME!
1355:    */
1356:   protected void uninstallListeners(JFileChooser fc)
1357:   {
1358:     filechooser.removePropertyChangeListener(propertyChangeListener);
1359:     propertyChangeListener = null;
1360:   }
1361: 
1362:   /**
1363:    * DOCUMENT ME!
1364:    *
1365:    * @param fc DOCUMENT ME!
1366:    */
1367:   protected void installDefaults(JFileChooser fc)
1368:   {
1369:     installIcons(fc);
1370:     installStrings(fc);
1371:   }
1372: 
1373:   /**
1374:    * DOCUMENT ME!
1375:    *
1376:    * @param fc DOCUMENT ME!
1377:    */
1378:   protected void uninstallDefaults(JFileChooser fc)
1379:   {
1380:     uninstallStrings(fc);
1381:     uninstallIcons(fc);
1382:   }
1383: 
1384:   /**
1385:    * DOCUMENT ME!
1386:    *
1387:    * @param fc DOCUMENT ME!
1388:    */
1389:   protected void installIcons(JFileChooser fc)
1390:   {
1391:     // FIXME: Implement.
1392:   }
1393: 
1394:   /**
1395:    * DOCUMENT ME!
1396:    *
1397:    * @param fc DOCUMENT ME!
1398:    */
1399:   protected void uninstallIcons(JFileChooser fc)
1400:   {
1401:     // FIXME: Implement.
1402:   }
1403: 
1404:   /**
1405:    * DOCUMENT ME!
1406:    *
1407:    * @param fc DOCUMENT ME!
1408:    */
1409:   protected void installStrings(JFileChooser fc)
1410:   {
1411:     UIDefaults defaults = UIManager.getLookAndFeelDefaults();
1412: 
1413:     acceptAllFileFilterText = defaults.getString("FileChooser.acceptAllFileFilterText");
1414:     cancelButtonMnemonic = defaults.getInt("FileChooser.cancelButtonMnemonic");
1415:     cancelButtonText = defaults.getString("FileChooser.cancelButtonText");
1416:     cancelButtonToolTipText = defaults.getString("FileChooser.cancelButtonToolTipText");
1417: 
1418:     dirDescText = defaults.getString("FileChooser.directoryDescriptionText");
1419:     fileDescText = defaults.getString("FileChooser.fileDescriptionText");
1420: 
1421:     helpButtonMnemonic = defaults.getInt("FileChooser.helpButtonMnemonic");
1422:     helpButtonText = defaults.getString("FileChooser.helpButtonText");
1423:     helpButtonToolTipText = defaults.getString("FileChooser.helpButtonToolTipText");
1424: 
1425:     openButtonMnemonic = defaults.getInt("FileChooser.openButtonMnemonic");
1426:     openButtonText = defaults.getString("FileChooser.openButtonText");
1427:     openButtonToolTipText = defaults.getString("FileChooser.openButtonToolTipText");
1428: 
1429:     saveButtonMnemonic = defaults.getInt("FileChooser.saveButtonMnemonic");
1430:     saveButtonText = defaults.getString("FileChooser.saveButtonText");
1431:     saveButtonToolTipText = defaults.getString("FileChooser.saveButtonToolTipText");
1432:   }
1433: 
1434:   /**
1435:    * DOCUMENT ME!
1436:    *
1437:    * @param fc DOCUMENT ME!
1438:    */
1439:   protected void uninstallStrings(JFileChooser fc)
1440:   {
1441:     acceptAllFileFilterText = null;
1442:     cancelButtonMnemonic = 0;
1443:     cancelButtonText = null;
1444:     cancelButtonToolTipText = null;
1445: 
1446:     dirDescText = null;
1447:     fileDescText = null;
1448: 
1449:     helpButtonMnemonic = 0;
1450:     helpButtonText = null;
1451:     helpButtonToolTipText = null;
1452: 
1453:     openButtonMnemonic = 0;
1454:     openButtonText = null;
1455:     openButtonToolTipText = null;
1456: 
1457:     saveButtonMnemonic = 0;
1458:     saveButtonText = null;
1459:     saveButtonToolTipText = null;
1460:   }
1461: 
1462:   /**
1463:    * DOCUMENT ME!
1464:    */
1465:   protected void createModel()
1466:   {
1467:     model = new BasicDirectoryModel(filechooser);
1468:   }
1469: 
1470:   /**
1471:    * DOCUMENT ME!
1472:    *
1473:    * @return DOCUMENT ME!
1474:    */
1475:   public BasicDirectoryModel getModel()
1476:   {
1477:     return model;
1478:   }
1479: 
1480:   /**
1481:    * DOCUMENT ME!
1482:    *
1483:    * @param fc DOCUMENT ME!
1484:    *
1485:    * @return DOCUMENT ME!
1486:    */
1487:   public PropertyChangeListener createPropertyChangeListener(JFileChooser fc)
1488:   {
1489:     return new PropertyChangeListener()
1490:       {
1491:     public void propertyChange(PropertyChangeEvent e)
1492:     {
1493:       // FIXME: Multiple file selection waiting on JList multiple selection bug.
1494:       if (e.getPropertyName().equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY))
1495:         {
1496:           if (filechooser.getSelectedFile() == null)
1497:         setFileName(null);
1498:           else
1499:         setFileName(filechooser.getSelectedFile().toString());
1500:           int index = -1;
1501:           File file = filechooser.getSelectedFile();
1502:           for (index = 0; index < model.getSize(); index++)
1503:         if (((File) model.getElementAt(index)).equals(file))
1504:           break;
1505:           if (index == -1)
1506:         return;
1507:           filelist.setSelectedIndex(index);
1508:           filelist.ensureIndexIsVisible(index);
1509:           filelist.revalidate();
1510:           filelist.repaint();
1511:         }
1512:       else if (e.getPropertyName().equals(JFileChooser.DIRECTORY_CHANGED_PROPERTY))
1513:         {
1514:           filelist.clearSelection();
1515:           filelist.revalidate();
1516:           filelist.repaint();
1517:           setDirectorySelected(false);
1518:           setDirectory(filechooser.getCurrentDirectory());
1519:           boxEntries();
1520:         }
1521:       else if (e.getPropertyName().equals(JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY)
1522:                || e.getPropertyName().equals(JFileChooser.FILE_FILTER_CHANGED_PROPERTY))
1523:         filterEntries();
1524:       else if (e.getPropertyName().equals(JFileChooser.DIALOG_TYPE_CHANGED_PROPERTY)
1525:                || e.getPropertyName().equals(JFileChooser.DIALOG_TITLE_CHANGED_PROPERTY))
1526:         {
1527:           Window owner = SwingUtilities.windowForComponent(filechooser);
1528:           if (owner instanceof JDialog)
1529:         ((JDialog) owner).setTitle(getDialogTitle(filechooser));
1530:           accept.setText(getApproveButtonText(filechooser));
1531:           accept.setToolTipText(getApproveButtonToolTipText(filechooser));
1532:           accept.setMnemonic(getApproveButtonMnemonic(filechooser));
1533:         }
1534:       else if (e.getPropertyName().equals(JFileChooser.APPROVE_BUTTON_TEXT_CHANGED_PROPERTY))
1535:         accept.setText(getApproveButtonText(filechooser));
1536:       else if (e.getPropertyName().equals(JFileChooser.APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY))
1537:         accept.setToolTipText(getApproveButtonToolTipText(filechooser));
1538:       else if (e.getPropertyName().equals(JFileChooser.APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY))
1539:         accept.setMnemonic(getApproveButtonMnemonic(filechooser));
1540:       else if (e.getPropertyName().equals(JFileChooser.CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY))
1541:         {
1542:           if (filechooser.getControlButtonsAreShown())
1543:             {
1544:           GridBagConstraints c = new GridBagConstraints();
1545:           c.gridy = 1;
1546:           bottomPanel.add(filters, c);
1547: 
1548:           c.fill = GridBagConstraints.BOTH;
1549:           c.gridy = 2;
1550:           c.anchor = GridBagConstraints.EAST;
1551:           bottomPanel.add(closePanel, c);
1552:           bottomPanel.revalidate();
1553:           bottomPanel.repaint();
1554:           bottomPanel.doLayout();
1555:             }
1556:           else
1557:         bottomPanel.remove(closePanel);
1558:         }
1559:       else if (e.getPropertyName().equals(JFileChooser.ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY))
1560:         {
1561:           if (filechooser.isAcceptAllFileFilterUsed())
1562:         filechooser.addChoosableFileFilter(getAcceptAllFileFilter(filechooser));
1563:           else
1564:         filechooser.removeChoosableFileFilter(getAcceptAllFileFilter(filechooser));
1565:         }
1566:       else if (e.getPropertyName().equals(JFileChooser.ACCESSORY_CHANGED_PROPERTY))
1567:         {
1568:           JComponent old = (JComponent) e.getOldValue();
1569:           if (old != null)
1570:         getAccessoryPanel().remove(old);
1571:           JComponent newval = (JComponent) e.getNewValue();
1572:           if (newval != null)
1573:         getAccessoryPanel().add(newval);
1574:         }
1575:       if (e.getPropertyName().equals(JFileChooser.DIRECTORY_CHANGED_PROPERTY)
1576:           || e.getPropertyName().equals(JFileChooser.FILE_FILTER_CHANGED_PROPERTY)
1577:           || e.getPropertyName().equals(JFileChooser.FILE_HIDING_CHANGED_PROPERTY))
1578:         rescanCurrentDirectory(filechooser);
1579: 
1580:       filechooser.revalidate();
1581:       filechooser.repaint();
1582:     }
1583:       };
1584:   }
1585: 
1586:   /**
1587:    * DOCUMENT ME!
1588:    *
1589:    * @return DOCUMENT ME!
1590:    */
1591:   public String getFileName()
1592:   {
1593:     return filename;
1594:   }
1595: 
1596:   /**
1597:    * DOCUMENT ME!
1598:    *
1599:    * @return DOCUMENT ME!
1600:    */
1601:   public String getDirectoryName()
1602:   {
1603:     // XXX: I don't see a case where the thing returns something non-null..
1604:     return null;
1605:   }
1606: 
1607:   /**
1608:    * DOCUMENT ME!
1609:    *
1610:    * @param filename DOCUMENT ME!
1611:    */
1612:   public void setFileName(String filename)
1613:   {
1614:     this.filename = filename;
1615:   }
1616: 
1617:   /**
1618:    * DOCUMENT ME!
1619:    *
1620:    * @param dirname DOCUMENT ME!
1621:    */
1622:   public void setDirectoryName(String dirname)
1623:   {
1624:     // FIXME: Implement
1625:   }
1626: 
1627:   /**
1628:    * DOCUMENT ME!
1629:    *
1630:    * @param fc DOCUMENT ME!
1631:    */
1632:   public void rescanCurrentDirectory(JFileChooser fc)
1633:   {
1634:     getModel().validateFileCache();
1635:     filelist.revalidate();
1636:   }
1637: 
1638:   /**
1639:    * DOCUMENT ME!
1640:    *
1641:    * @param fc DOCUMENT ME!
1642:    * @param f DOCUMENT ME!
1643:    */
1644:   public void ensureFileIsVisible(JFileChooser fc, File f)
1645:   {
1646:     // XXX: Not sure what this does.
1647:   }
1648: 
1649:   /**
1650:    * DOCUMENT ME!
1651:    *
1652:    * @return DOCUMENT ME!
1653:    */
1654:   public JFileChooser getFileChooser()
1655:   {
1656:     return filechooser;
1657:   }
1658: 
1659:   /**
1660:    * DOCUMENT ME!
1661:    *
1662:    * @return DOCUMENT ME!
1663:    */
1664:   public JPanel getAccessoryPanel()
1665:   {
1666:     return accessoryPanel;
1667:   }
1668: 
1669:   /**
1670:    * DOCUMENT ME!
1671:    *
1672:    * @param fc DOCUMENT ME!
1673:    *
1674:    * @return DOCUMENT ME!
1675:    */
1676:   public JButton getApproveButton(JFileChooser fc)
1677:   {
1678:     accept = new JButton(getApproveButtonText(fc));
1679:     accept.setMnemonic(getApproveButtonMnemonic(fc));
1680:     accept.setToolTipText(getApproveButtonToolTipText(fc));
1681:     return accept;
1682:   }
1683: 
1684:   /**
1685:    * DOCUMENT ME!
1686:    *
1687:    * @param fc DOCUMENT ME!
1688:    *
1689:    * @return DOCUMENT ME!
1690:    */
1691:   public String getApproveButtonToolTipText(JFileChooser fc)
1692:   {
1693:     if (fc.getApproveButtonToolTipText() != null)
1694:       return fc.getApproveButtonToolTipText();
1695:     else if (fc.getDialogType() == JFileChooser.SAVE_DIALOG)
1696:       return saveButtonToolTipText;
1697:     else
1698:       return openButtonToolTipText;
1699:   }
1700: 
1701:   /**
1702:    * DOCUMENT ME!
1703:    */
1704:   public void clearIconCache()
1705:   {
1706:     if (fv instanceof BasicFileView)
1707:       ((BasicFileView) fv).clearIconCache();
1708:   }
1709: 
1710:   /**
1711:    * DOCUMENT ME!
1712:    *
1713:    * @param fc DOCUMENT ME!
1714:    *
1715:    * @return DOCUMENT ME!
1716:    */
1717:   public ListSelectionListener createListSelectionListener(JFileChooser fc)
1718:   {
1719:     return new SelectionListener();
1720:   }
1721: 
1722:   /**
1723:    * DOCUMENT ME!
1724:    *
1725:    * @param fc DOCUMENT ME!
1726:    * @param list DOCUMENT ME!
1727:    *
1728:    * @return DOCUMENT ME!
1729:    */
1730:   protected MouseListener createDoubleClickListener(JFileChooser fc, JList list)
1731:   {
1732:     return new DoubleClickListener(list);
1733:   }
1734: 
1735:   /**
1736:    * DOCUMENT ME!
1737:    *
1738:    * @return DOCUMENT ME!
1739:    */
1740:   protected boolean isDirectorySelected()
1741:   {
1742:     return dirSelected;
1743:   }
1744: 
1745:   /**
1746:    * DOCUMENT ME!
1747:    *
1748:    * @param selected DOCUMENT ME!
1749:    */
1750:   protected void setDirectorySelected(boolean selected)
1751:   {
1752:     dirSelected = selected;
1753:   }
1754: 
1755:   /**
1756:    * DOCUMENT ME!
1757:    *
1758:    * @return DOCUMENT ME!
1759:    */
1760:   protected File getDirectory()
1761:   {
1762:     return currDir;
1763:   }
1764: 
1765:   /**
1766:    * DOCUMENT ME!
1767:    *
1768:    * @param f DOCUMENT ME!
1769:    */
1770:   protected void setDirectory(File f)
1771:   {
1772:     currDir = f;
1773:   }
1774: 
1775:   /**
1776:    * DOCUMENT ME!
1777:    *
1778:    * @param fc DOCUMENT ME!
1779:    *
1780:    * @return DOCUMENT ME!
1781:    */
1782:   public FileFilter getAcceptAllFileFilter(JFileChooser fc)
1783:   {
1784:     return acceptAll;
1785:   }
1786: 
1787:   /**
1788:    * DOCUMENT ME!
1789:    *
1790:    * @param fc DOCUMENT ME!
1791:    *
1792:    * @return DOCUMENT ME!
1793:    */
1794:   public FileView getFileView(JFileChooser fc)
1795:   {
1796:     if (fc.getFileView() != null)
1797:       return fc.getFileView();
1798:     return fv;
1799:   }
1800: 
1801:   /**
1802:    * DOCUMENT ME!
1803:    *
1804:    * @param fc DOCUMENT ME!
1805:    *
1806:    * @return DOCUMENT ME!
1807:    */
1808:   public String getDialogTitle(JFileChooser fc)
1809:   {
1810:     String ret = fc.getDialogTitle();
1811:     if (ret != null)
1812:       return ret;
1813:     switch (fc.getDialogType())
1814:       {
1815:       case JFileChooser.OPEN_DIALOG:
1816:     ret = openButtonText;
1817:     break;
1818:       case JFileChooser.SAVE_DIALOG:
1819:     ret = saveButtonText;
1820:     break;
1821:       default:
1822:     ret = fc.getApproveButtonText();
1823:     break;
1824:       }
1825:     if (ret == null)
1826:       ret = openButtonText;
1827:     return ret;
1828:   }
1829: 
1830:   /**
1831:    * DOCUMENT ME!
1832:    *
1833:    * @param fc DOCUMENT ME!
1834:    *
1835:    * @return DOCUMENT ME!
1836:    */
1837:   public int getApproveButtonMnemonic(JFileChooser fc)
1838:   {
1839:     if (fc.getApproveButtonMnemonic() != 0)
1840:       return fc.getApproveButtonMnemonic();
1841:     else if (fc.getDialogType() == JFileChooser.SAVE_DIALOG)
1842:       return saveButtonMnemonic;
1843:     else
1844:       return openButtonMnemonic;
1845:   }
1846: 
1847:   /**
1848:    * DOCUMENT ME!
1849:    *
1850:    * @param fc DOCUMENT ME!
1851:    *
1852:    * @return DOCUMENT ME!
1853:    */
1854:   public String getApproveButtonText(JFileChooser fc)
1855:   {
1856:     if (fc.getApproveButtonText() != null)
1857:       return fc.getApproveButtonText();
1858:     else if (fc.getDialogType() == JFileChooser.SAVE_DIALOG)
1859:       return saveButtonText;
1860:     else
1861:       return openButtonText;
1862:   }
1863: 
1864:   /**
1865:    * DOCUMENT ME!
1866:    *
1867:    * @return DOCUMENT ME!
1868:    */
1869:   public Action getNewFolderAction()
1870:   {
1871:     return new NewFolderAction();
1872:   }
1873: 
1874:   /**
1875:    * DOCUMENT ME!
1876:    *
1877:    * @return DOCUMENT ME!
1878:    */
1879:   public Action getGoHomeAction()
1880:   {
1881:     return new GoHomeAction();
1882:   }
1883: 
1884:   /**
1885:    * DOCUMENT ME!
1886:    *
1887:    * @return DOCUMENT ME!
1888:    */
1889:   public Action getChangeToParentDirectoryAction()
1890:   {
1891:     return new ChangeToParentDirectoryAction();
1892:   }
1893: 
1894:   /**
1895:    * DOCUMENT ME!
1896:    *
1897:    * @return DOCUMENT ME!
1898:    */
1899:   public Action getApproveSelectionAction()
1900:   {
1901:     return new ApproveSelectionAction();
1902:   }
1903: 
1904:   /**
1905:    * DOCUMENT ME!
1906:    *
1907:    * @return DOCUMENT ME!
1908:    */
1909:   public Action getCancelSelectionAction()
1910:   {
1911:     return new CancelSelectionAction();
1912:   }
1913: 
1914:   /**
1915:    * DOCUMENT ME!
1916:    *
1917:    * @return DOCUMENT ME!
1918:    */
1919:   public Action getUpdateAction()
1920:   {
1921:     return new UpdateAction();
1922:   }
1923: }