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:   private void boxEntries()
1094:   {
1095:     ArrayList parentFiles = new ArrayList();
1096:     File parent = filechooser.getCurrentDirectory();
1097:     if (parent == null)
1098:       parent = filechooser.getFileSystemView().getDefaultDirectory();
1099:     while (parent != null)
1100:       {
1101:     String name = parent.getName();
1102:     if (name.equals(""))
1103:       name = parent.getAbsolutePath();
1104: 
1105:     parentFiles.add(parentFiles.size(), name);
1106:     parent = parent.getParentFile();
1107:       }
1108: 
1109:     if (parentFiles.size() == 0)
1110:       return;
1111: 
1112:     if (parents.getItemCount() > 0)
1113:       parents.removeAllItems();
1114:     for (int i = parentFiles.size() - 1; i >= 0; i--)
1115:       parents.addItem(parentFiles.get(i));
1116:     parents.setSelectedIndex(parentFiles.size() - 1);
1117:     parents.revalidate();
1118:     parents.repaint();
1119:   }
1120: 
1121:   /**
1122:    * DOCUMENT ME!
1123:    *
1124:    * @return DOCUMENT ME!
1125:    */
1126:   private ItemListener createBoxListener()
1127:   {
1128:     return new ItemListener()
1129:       {
1130:     public void itemStateChanged(ItemEvent e)
1131:     {
1132:       if (parents.getItemCount() - 1 == parents.getSelectedIndex())
1133:         return;
1134:       StringBuffer dir = new StringBuffer();
1135:       for (int i = 0; i <= parents.getSelectedIndex(); i++)
1136:         {
1137:           dir.append(parents.getItemAt(i));
1138:           dir.append(File.separatorChar);
1139:         }
1140:       filechooser.setCurrentDirectory(filechooser.getFileSystemView()
1141:                                                  .createFileObject(dir
1142:                                                                    .toString()));
1143:     }
1144:       };
1145:   }
1146: 
1147:   /**
1148:    * DOCUMENT ME!
1149:    *
1150:    * @return DOCUMENT ME!
1151:    */
1152:   private ItemListener createFilterListener()
1153:   {
1154:     return new ItemListener()
1155:       {
1156:     public void itemStateChanged(ItemEvent e)
1157:     {
1158:       int index = filters.getSelectedIndex();
1159:       if (index == -1)
1160:         return;
1161:       filechooser.setFileFilter(filechooser.getChoosableFileFilters()[index]);
1162:     }
1163:       };
1164:   }
1165: 
1166:   void filterEntries()
1167:   {
1168:     FileFilter[] list = filechooser.getChoosableFileFilters();
1169:     if (filters.getItemCount() > 0)
1170:       filters.removeAllItems();
1171: 
1172:     int index = -1;
1173:     String selected = filechooser.getFileFilter().getDescription();
1174:     for (int i = 0; i < list.length; i++)
1175:       {
1176:     if (selected.equals(list[i].getDescription()))
1177:       index = i;
1178:     filters.addItem(list[i].getDescription());
1179:       }
1180:     filters.setSelectedIndex(index);
1181:     filters.revalidate();
1182:     filters.repaint();
1183:   }
1184: 
1185:   /**
1186:    * DOCUMENT ME!
1187:    *
1188:    * @param fc DOCUMENT ME!
1189:    */
1190:   public void installComponents(JFileChooser fc)
1191:   {
1192:     JLabel look = new JLabel("Look In:");
1193: 
1194:     parents = new JComboBox();
1195:     parents.setRenderer(new CBLabelRenderer());
1196:     boxEntries();
1197:     look.setLabelFor(parents);
1198:     JPanel parentsPanel = new JPanel();
1199:     parentsPanel.add(look);
1200:     parentsPanel.add(parents);
1201:     JPanel buttonPanel = new JPanel();
1202: 
1203:     upFolderButton = new JButton();
1204:     upFolderButton.setIcon(upFolderIcon);
1205:     buttonPanel.add(upFolderButton);
1206: 
1207:     homeFolderButton = new JButton();
1208:     homeFolderButton = new JButton(homeFolderIcon);
1209:     buttonPanel.add(homeFolderButton);
1210: 
1211:     newFolderButton = new JButton();
1212:     newFolderButton.setIcon(newFolderIcon);
1213:     buttonPanel.add(newFolderButton);
1214: 
1215:     ButtonGroup toggles = new ButtonGroup();
1216:     JToggleButton listViewButton = new JToggleButton();
1217:     listViewButton.setIcon(listViewIcon);
1218:     toggles.add(listViewButton);
1219:     buttonPanel.add(listViewButton);
1220: 
1221:     JToggleButton detailsViewButton = new JToggleButton();
1222:     detailsViewButton.setIcon(detailsViewIcon);
1223:     toggles.add(detailsViewButton);
1224:     buttonPanel.add(detailsViewButton);
1225: 
1226:     JPanel topPanel = new JPanel();
1227:     topPanel.setLayout(new java.awt.FlowLayout());
1228:     topPanel.add(parentsPanel);
1229:     topPanel.add(buttonPanel);
1230: 
1231:     accessoryPanel = new JPanel();
1232:     if (filechooser.getAccessory() != null)
1233:       accessoryPanel.add(filechooser.getAccessory(), BorderLayout.CENTER);
1234: 
1235:     filelist = new JList(model);
1236:     filelist.setVisibleRowCount(6);
1237:     JScrollPane scrollp = new JScrollPane(filelist);
1238:     scrollp.setPreferredSize(new Dimension(400, 175));
1239:     filelist.setBackground(Color.WHITE);
1240: 
1241:     filelist.setLayoutOrientation(JList.VERTICAL_WRAP);
1242:     filelist.setCellRenderer(new ListLabelRenderer());
1243: 
1244:     GridBagConstraints c = new GridBagConstraints();
1245:     c.gridx = 0;
1246:     c.gridy = 0;
1247:     c.fill = GridBagConstraints.BOTH;
1248:     c.weightx = 1;
1249:     c.weighty = 1;
1250: 
1251:     JPanel centrePanel = new JPanel();
1252:     centrePanel.setLayout(new GridBagLayout());
1253:     centrePanel.add(scrollp, c);
1254: 
1255:     c.gridx = 1;
1256:     centrePanel.add(accessoryPanel, c);
1257: 
1258:     JLabel fileNameLabel = new JLabel("File Name:");
1259:     JLabel fileTypesLabel = new JLabel("Files of Type:");
1260: 
1261:     JTextField entry = new JTextField();
1262:     filters = new JComboBox();
1263:     filterEntries();
1264: 
1265:     fileNameLabel.setLabelFor(entry);
1266:     fileNameLabel.setHorizontalTextPosition(SwingConstants.LEFT);
1267:     fileTypesLabel.setLabelFor(filters);
1268:     fileTypesLabel.setHorizontalTextPosition(SwingConstants.LEFT);
1269: 
1270:     closePanel = new JPanel();
1271:     accept = getApproveButton(filechooser);
1272:     cancel = new JButton(cancelButtonText);
1273:     cancel.setMnemonic(cancelButtonMnemonic);
1274:     cancel.setToolTipText(cancelButtonToolTipText);
1275:     closePanel.add(accept);
1276:     closePanel.add(cancel);
1277: 
1278:     c.anchor = GridBagConstraints.WEST;
1279:     c.weighty = 0;
1280:     c.weightx = 0;
1281:     c.gridx = 0;
1282: 
1283:     bottomPanel = new JPanel();
1284:     bottomPanel.setLayout(new GridBagLayout());
1285:     bottomPanel.add(fileNameLabel, c);
1286: 
1287:     c.gridy = 1;
1288:     bottomPanel.add(fileTypesLabel, c);
1289:     c.gridx = 1;
1290:     c.gridy = 0;
1291:     c.weightx = 1;
1292:     c.weighty = 1;
1293:     bottomPanel.add(entry, c);
1294: 
1295:     c.gridy = 1;
1296:     bottomPanel.add(filters, c);
1297: 
1298:     c.fill = GridBagConstraints.NONE;
1299:     c.gridy = 2;
1300:     c.anchor = GridBagConstraints.EAST;
1301:     bottomPanel.add(closePanel, c);
1302: 
1303:     filechooser.setLayout(new BorderLayout());
1304:     filechooser.add(topPanel, BorderLayout.NORTH);
1305:     filechooser.add(centrePanel, BorderLayout.CENTER);
1306:     filechooser.add(bottomPanel, BorderLayout.SOUTH);
1307:   }
1308: 
1309:   /**
1310:    * DOCUMENT ME!
1311:    *
1312:    * @param fc DOCUMENT ME!
1313:    */
1314:   public void uninstallComponents(JFileChooser fc)
1315:   {
1316:     parents = null;
1317: 
1318:     accept = null;
1319:     cancel = null;
1320:     upFolderButton = null;
1321:     homeFolderButton = null;
1322:     newFolderButton = null;
1323: 
1324:     filelist = null;
1325:   }
1326: 
1327:   /**
1328:    * DOCUMENT ME!
1329:    *
1330:    * @param fc DOCUMENT ME!
1331:    */
1332:   protected void installListeners(JFileChooser fc)
1333:   {
1334:     propertyChangeListener = createPropertyChangeListener(filechooser);
1335:     filechooser.addPropertyChangeListener(propertyChangeListener);
1336: 
1337:     //parents.addItemListener(createBoxListener());
1338:     accept.addActionListener(getApproveSelectionAction());
1339:     cancel.addActionListener(getCancelSelectionAction());
1340:     upFolderButton.addActionListener(getChangeToParentDirectoryAction());
1341:     homeFolderButton.addActionListener(getGoHomeAction());
1342:     newFolderButton.addActionListener(getNewFolderAction());
1343:     filters.addItemListener(createFilterListener());
1344: 
1345:     filelist.addMouseListener(createDoubleClickListener(filechooser, filelist));
1346:     filelist.addListSelectionListener(createListSelectionListener(filechooser));
1347:   }
1348: 
1349:   /**
1350:    * DOCUMENT ME!
1351:    *
1352:    * @param fc DOCUMENT ME!
1353:    */
1354:   protected void uninstallListeners(JFileChooser fc)
1355:   {
1356:     filechooser.removePropertyChangeListener(propertyChangeListener);
1357:     propertyChangeListener = null;
1358:   }
1359: 
1360:   /**
1361:    * DOCUMENT ME!
1362:    *
1363:    * @param fc DOCUMENT ME!
1364:    */
1365:   protected void installDefaults(JFileChooser fc)
1366:   {
1367:     installIcons(fc);
1368:     installStrings(fc);
1369:   }
1370: 
1371:   /**
1372:    * DOCUMENT ME!
1373:    *
1374:    * @param fc DOCUMENT ME!
1375:    */
1376:   protected void uninstallDefaults(JFileChooser fc)
1377:   {
1378:     uninstallStrings(fc);
1379:     uninstallIcons(fc);
1380:   }
1381: 
1382:   /**
1383:    * DOCUMENT ME!
1384:    *
1385:    * @param fc DOCUMENT ME!
1386:    */
1387:   protected void installIcons(JFileChooser fc)
1388:   {
1389:     // FIXME: Implement.
1390:   }
1391: 
1392:   /**
1393:    * DOCUMENT ME!
1394:    *
1395:    * @param fc DOCUMENT ME!
1396:    */
1397:   protected void uninstallIcons(JFileChooser fc)
1398:   {
1399:     // FIXME: Implement.
1400:   }
1401: 
1402:   /**
1403:    * DOCUMENT ME!
1404:    *
1405:    * @param fc DOCUMENT ME!
1406:    */
1407:   protected void installStrings(JFileChooser fc)
1408:   {
1409:     UIDefaults defaults = UIManager.getLookAndFeelDefaults();
1410: 
1411:     acceptAllFileFilterText = defaults.getString("FileChooser.acceptAllFileFilterText");
1412:     cancelButtonMnemonic = defaults.getInt("FileChooser.cancelButtonMnemonic");
1413:     cancelButtonText = defaults.getString("FileChooser.cancelButtonText");
1414:     cancelButtonToolTipText = defaults.getString("FileChooser.cancelButtonToolTipText");
1415: 
1416:     dirDescText = defaults.getString("FileChooser.directoryDescriptionText");
1417:     fileDescText = defaults.getString("FileChooser.fileDescriptionText");
1418: 
1419:     helpButtonMnemonic = defaults.getInt("FileChooser.helpButtonMnemonic");
1420:     helpButtonText = defaults.getString("FileChooser.helpButtonText");
1421:     helpButtonToolTipText = defaults.getString("FileChooser.helpButtonToolTipText");
1422: 
1423:     openButtonMnemonic = defaults.getInt("FileChooser.openButtonMnemonic");
1424:     openButtonText = defaults.getString("FileChooser.openButtonText");
1425:     openButtonToolTipText = defaults.getString("FileChooser.openButtonToolTipText");
1426: 
1427:     saveButtonMnemonic = defaults.getInt("FileChooser.saveButtonMnemonic");
1428:     saveButtonText = defaults.getString("FileChooser.saveButtonText");
1429:     saveButtonToolTipText = defaults.getString("FileChooser.saveButtonToolTipText");
1430:   }
1431: 
1432:   /**
1433:    * DOCUMENT ME!
1434:    *
1435:    * @param fc DOCUMENT ME!
1436:    */
1437:   protected void uninstallStrings(JFileChooser fc)
1438:   {
1439:     acceptAllFileFilterText = null;
1440:     cancelButtonMnemonic = 0;
1441:     cancelButtonText = null;
1442:     cancelButtonToolTipText = null;
1443: 
1444:     dirDescText = null;
1445:     fileDescText = null;
1446: 
1447:     helpButtonMnemonic = 0;
1448:     helpButtonText = null;
1449:     helpButtonToolTipText = null;
1450: 
1451:     openButtonMnemonic = 0;
1452:     openButtonText = null;
1453:     openButtonToolTipText = null;
1454: 
1455:     saveButtonMnemonic = 0;
1456:     saveButtonText = null;
1457:     saveButtonToolTipText = null;
1458:   }
1459: 
1460:   /**
1461:    * DOCUMENT ME!
1462:    */
1463:   protected void createModel()
1464:   {
1465:     model = new BasicDirectoryModel(filechooser);
1466:   }
1467: 
1468:   /**
1469:    * DOCUMENT ME!
1470:    *
1471:    * @return DOCUMENT ME!
1472:    */
1473:   public BasicDirectoryModel getModel()
1474:   {
1475:     return model;
1476:   }
1477: 
1478:   /**
1479:    * DOCUMENT ME!
1480:    *
1481:    * @param fc DOCUMENT ME!
1482:    *
1483:    * @return DOCUMENT ME!
1484:    */
1485:   public PropertyChangeListener createPropertyChangeListener(JFileChooser fc)
1486:   {
1487:     return new PropertyChangeListener()
1488:       {
1489:     public void propertyChange(PropertyChangeEvent e)
1490:     {
1491:       // FIXME: Multiple file selection waiting on JList multiple selection bug.
1492:       if (e.getPropertyName().equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY))
1493:         {
1494:           if (filechooser.getSelectedFile() == null)
1495:         setFileName(null);
1496:           else
1497:         setFileName(filechooser.getSelectedFile().toString());
1498:           int index = -1;
1499:           File file = filechooser.getSelectedFile();
1500:           for (index = 0; index < model.getSize(); index++)
1501:         if (((File) model.getElementAt(index)).equals(file))
1502:           break;
1503:           if (index == -1)
1504:         return;
1505:           filelist.setSelectedIndex(index);
1506:           filelist.ensureIndexIsVisible(index);
1507:           filelist.revalidate();
1508:           filelist.repaint();
1509:         }
1510:       else if (e.getPropertyName().equals(JFileChooser.DIRECTORY_CHANGED_PROPERTY))
1511:         {
1512:           //boxEntries();
1513:           filelist.clearSelection();
1514:           filelist.revalidate();
1515:           filelist.repaint();
1516:           setDirectorySelected(false);
1517:           setDirectory(filechooser.getCurrentDirectory());
1518:         }
1519:       else if (e.getPropertyName().equals(JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY)
1520:                || e.getPropertyName().equals(JFileChooser.FILE_FILTER_CHANGED_PROPERTY))
1521:         filterEntries();
1522:       else if (e.getPropertyName().equals(JFileChooser.DIALOG_TYPE_CHANGED_PROPERTY)
1523:                || e.getPropertyName().equals(JFileChooser.DIALOG_TITLE_CHANGED_PROPERTY))
1524:         {
1525:           Window owner = SwingUtilities.windowForComponent(filechooser);
1526:           if (owner instanceof JDialog)
1527:         ((JDialog) owner).setTitle(getDialogTitle(filechooser));
1528:           accept.setText(getApproveButtonText(filechooser));
1529:           accept.setToolTipText(getApproveButtonToolTipText(filechooser));
1530:           accept.setMnemonic(getApproveButtonMnemonic(filechooser));
1531:         }
1532:       else if (e.getPropertyName().equals(JFileChooser.APPROVE_BUTTON_TEXT_CHANGED_PROPERTY))
1533:         accept.setText(getApproveButtonText(filechooser));
1534:       else if (e.getPropertyName().equals(JFileChooser.APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY))
1535:         accept.setToolTipText(getApproveButtonToolTipText(filechooser));
1536:       else if (e.getPropertyName().equals(JFileChooser.APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY))
1537:         accept.setMnemonic(getApproveButtonMnemonic(filechooser));
1538:       else if (e.getPropertyName().equals(JFileChooser.CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY))
1539:         {
1540:           if (filechooser.getControlButtonsAreShown())
1541:             {
1542:           GridBagConstraints c = new GridBagConstraints();
1543:           c.gridy = 1;
1544:           bottomPanel.add(filters, c);
1545: 
1546:           c.fill = GridBagConstraints.BOTH;
1547:           c.gridy = 2;
1548:           c.anchor = GridBagConstraints.EAST;
1549:           bottomPanel.add(closePanel, c);
1550:           bottomPanel.revalidate();
1551:           bottomPanel.repaint();
1552:           bottomPanel.doLayout();
1553:             }
1554:           else
1555:         bottomPanel.remove(closePanel);
1556:         }
1557:       else if (e.getPropertyName().equals(JFileChooser.ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY))
1558:         {
1559:           if (filechooser.isAcceptAllFileFilterUsed())
1560:         filechooser.addChoosableFileFilter(getAcceptAllFileFilter(filechooser));
1561:           else
1562:         filechooser.removeChoosableFileFilter(getAcceptAllFileFilter(filechooser));
1563:         }
1564:       else if (e.getPropertyName().equals(JFileChooser.ACCESSORY_CHANGED_PROPERTY))
1565:         {
1566:           JComponent old = (JComponent) e.getOldValue();
1567:           if (old != null)
1568:         getAccessoryPanel().remove(old);
1569:           JComponent newval = (JComponent) e.getNewValue();
1570:           if (newval != null)
1571:         getAccessoryPanel().add(newval);
1572:         }
1573:       if (e.getPropertyName().equals(JFileChooser.DIRECTORY_CHANGED_PROPERTY)
1574:           || e.getPropertyName().equals(JFileChooser.FILE_FILTER_CHANGED_PROPERTY)
1575:           || e.getPropertyName().equals(JFileChooser.FILE_HIDING_CHANGED_PROPERTY))
1576:         rescanCurrentDirectory(filechooser);
1577: 
1578:       filechooser.revalidate();
1579:       filechooser.repaint();
1580:     }
1581:       };
1582:   }
1583: 
1584:   /**
1585:    * DOCUMENT ME!
1586:    *
1587:    * @return DOCUMENT ME!
1588:    */
1589:   public String getFileName()
1590:   {
1591:     return filename;
1592:   }
1593: 
1594:   /**
1595:    * DOCUMENT ME!
1596:    *
1597:    * @return DOCUMENT ME!
1598:    */
1599:   public String getDirectoryName()
1600:   {
1601:     // XXX: I don't see a case where the thing returns something non-null..
1602:     return null;
1603:   }
1604: 
1605:   /**
1606:    * DOCUMENT ME!
1607:    *
1608:    * @param filename DOCUMENT ME!
1609:    */
1610:   public void setFileName(String filename)
1611:   {
1612:     this.filename = filename;
1613:   }
1614: 
1615:   /**
1616:    * DOCUMENT ME!
1617:    *
1618:    * @param dirname DOCUMENT ME!
1619:    */
1620:   public void setDirectoryName(String dirname)
1621:   {
1622:     // FIXME: Implement
1623:   }
1624: 
1625:   /**
1626:    * DOCUMENT ME!
1627:    *
1628:    * @param fc DOCUMENT ME!
1629:    */
1630:   public void rescanCurrentDirectory(JFileChooser fc)
1631:   {
1632:     getModel().validateFileCache();
1633:     filelist.revalidate();
1634:   }
1635: 
1636:   /**
1637:    * DOCUMENT ME!
1638:    *
1639:    * @param fc DOCUMENT ME!
1640:    * @param f DOCUMENT ME!
1641:    */
1642:   public void ensureFileIsVisible(JFileChooser fc, File f)
1643:   {
1644:     // XXX: Not sure what this does.
1645:   }
1646: 
1647:   /**
1648:    * DOCUMENT ME!
1649:    *
1650:    * @return DOCUMENT ME!
1651:    */
1652:   public JFileChooser getFileChooser()
1653:   {
1654:     return filechooser;
1655:   }
1656: 
1657:   /**
1658:    * DOCUMENT ME!
1659:    *
1660:    * @return DOCUMENT ME!
1661:    */
1662:   public JPanel getAccessoryPanel()
1663:   {
1664:     return accessoryPanel;
1665:   }
1666: 
1667:   /**
1668:    * DOCUMENT ME!
1669:    *
1670:    * @param fc DOCUMENT ME!
1671:    *
1672:    * @return DOCUMENT ME!
1673:    */
1674:   public JButton getApproveButton(JFileChooser fc)
1675:   {
1676:     accept = new JButton(getApproveButtonText(fc));
1677:     accept.setMnemonic(getApproveButtonMnemonic(fc));
1678:     accept.setToolTipText(getApproveButtonToolTipText(fc));
1679:     return accept;
1680:   }
1681: 
1682:   /**
1683:    * DOCUMENT ME!
1684:    *
1685:    * @param fc DOCUMENT ME!
1686:    *
1687:    * @return DOCUMENT ME!
1688:    */
1689:   public String getApproveButtonToolTipText(JFileChooser fc)
1690:   {
1691:     if (fc.getApproveButtonToolTipText() != null)
1692:       return fc.getApproveButtonToolTipText();
1693:     else if (fc.getDialogType() == JFileChooser.SAVE_DIALOG)
1694:       return saveButtonToolTipText;
1695:     else
1696:       return openButtonToolTipText;
1697:   }
1698: 
1699:   /**
1700:    * DOCUMENT ME!
1701:    */
1702:   public void clearIconCache()
1703:   {
1704:     if (fv instanceof BasicFileView)
1705:       ((BasicFileView) fv).clearIconCache();
1706:   }
1707: 
1708:   /**
1709:    * DOCUMENT ME!
1710:    *
1711:    * @param fc DOCUMENT ME!
1712:    *
1713:    * @return DOCUMENT ME!
1714:    */
1715:   public ListSelectionListener createListSelectionListener(JFileChooser fc)
1716:   {
1717:     return new SelectionListener();
1718:   }
1719: 
1720:   /**
1721:    * DOCUMENT ME!
1722:    *
1723:    * @param fc DOCUMENT ME!
1724:    * @param list DOCUMENT ME!
1725:    *
1726:    * @return DOCUMENT ME!
1727:    */
1728:   protected MouseListener createDoubleClickListener(JFileChooser fc, JList list)
1729:   {
1730:     return new DoubleClickListener(list);
1731:   }
1732: 
1733:   /**
1734:    * DOCUMENT ME!
1735:    *
1736:    * @return DOCUMENT ME!
1737:    */
1738:   protected boolean isDirectorySelected()
1739:   {
1740:     return dirSelected;
1741:   }
1742: 
1743:   /**
1744:    * DOCUMENT ME!
1745:    *
1746:    * @param selected DOCUMENT ME!
1747:    */
1748:   protected void setDirectorySelected(boolean selected)
1749:   {
1750:     dirSelected = selected;
1751:   }
1752: 
1753:   /**
1754:    * DOCUMENT ME!
1755:    *
1756:    * @return DOCUMENT ME!
1757:    */
1758:   protected File getDirectory()
1759:   {
1760:     return currDir;
1761:   }
1762: 
1763:   /**
1764:    * DOCUMENT ME!
1765:    *
1766:    * @param f DOCUMENT ME!
1767:    */
1768:   protected void setDirectory(File f)
1769:   {
1770:     currDir = f;
1771:   }
1772: 
1773:   /**
1774:    * DOCUMENT ME!
1775:    *
1776:    * @param fc DOCUMENT ME!
1777:    *
1778:    * @return DOCUMENT ME!
1779:    */
1780:   public FileFilter getAcceptAllFileFilter(JFileChooser fc)
1781:   {
1782:     return acceptAll;
1783:   }
1784: 
1785:   /**
1786:    * DOCUMENT ME!
1787:    *
1788:    * @param fc DOCUMENT ME!
1789:    *
1790:    * @return DOCUMENT ME!
1791:    */
1792:   public FileView getFileView(JFileChooser fc)
1793:   {
1794:     if (fc.getFileView() != null)
1795:       return fc.getFileView();
1796:     return fv;
1797:   }
1798: 
1799:   /**
1800:    * DOCUMENT ME!
1801:    *
1802:    * @param fc DOCUMENT ME!
1803:    *
1804:    * @return DOCUMENT ME!
1805:    */
1806:   public String getDialogTitle(JFileChooser fc)
1807:   {
1808:     String ret = fc.getDialogTitle();
1809:     if (ret != null)
1810:       return ret;
1811:     switch (fc.getDialogType())
1812:       {
1813:       case JFileChooser.OPEN_DIALOG:
1814:     ret = openButtonText;
1815:     break;
1816:       case JFileChooser.SAVE_DIALOG:
1817:     ret = saveButtonText;
1818:     break;
1819:       default:
1820:     ret = fc.getApproveButtonText();
1821:     break;
1822:       }
1823:     if (ret == null)
1824:       ret = openButtonText;
1825:     return ret;
1826:   }
1827: 
1828:   /**
1829:    * DOCUMENT ME!
1830:    *
1831:    * @param fc DOCUMENT ME!
1832:    *
1833:    * @return DOCUMENT ME!
1834:    */
1835:   public int getApproveButtonMnemonic(JFileChooser fc)
1836:   {
1837:     if (fc.getApproveButtonMnemonic() != 0)
1838:       return fc.getApproveButtonMnemonic();
1839:     else if (fc.getDialogType() == JFileChooser.SAVE_DIALOG)
1840:       return saveButtonMnemonic;
1841:     else
1842:       return openButtonMnemonic;
1843:   }
1844: 
1845:   /**
1846:    * DOCUMENT ME!
1847:    *
1848:    * @param fc DOCUMENT ME!
1849:    *
1850:    * @return DOCUMENT ME!
1851:    */
1852:   public String getApproveButtonText(JFileChooser fc)
1853:   {
1854:     if (fc.getApproveButtonText() != null)
1855:       return fc.getApproveButtonText();
1856:     else if (fc.getDialogType() == JFileChooser.SAVE_DIALOG)
1857:       return saveButtonText;
1858:     else
1859:       return openButtonText;
1860:   }
1861: 
1862:   /**
1863:    * DOCUMENT ME!
1864:    *
1865:    * @return DOCUMENT ME!
1866:    */
1867:   public Action getNewFolderAction()
1868:   {
1869:     return new NewFolderAction();
1870:   }
1871: 
1872:   /**
1873:    * DOCUMENT ME!
1874:    *
1875:    * @return DOCUMENT ME!
1876:    */
1877:   public Action getGoHomeAction()
1878:   {
1879:     return new GoHomeAction();
1880:   }
1881: 
1882:   /**
1883:    * DOCUMENT ME!
1884:    *
1885:    * @return DOCUMENT ME!
1886:    */
1887:   public Action getChangeToParentDirectoryAction()
1888:   {
1889:     return new ChangeToParentDirectoryAction();
1890:   }
1891: 
1892:   /**
1893:    * DOCUMENT ME!
1894:    *
1895:    * @return DOCUMENT ME!
1896:    */
1897:   public Action getApproveSelectionAction()
1898:   {
1899:     return new ApproveSelectionAction();
1900:   }
1901: 
1902:   /**
1903:    * DOCUMENT ME!
1904:    *
1905:    * @return DOCUMENT ME!
1906:    */
1907:   public Action getCancelSelectionAction()
1908:   {
1909:     return new CancelSelectionAction();
1910:   }
1911: 
1912:   /**
1913:    * DOCUMENT ME!
1914:    *
1915:    * @return DOCUMENT ME!
1916:    */
1917:   public Action getUpdateAction()
1918:   {
1919:     return new UpdateAction();
1920:   }
1921: }