src/share/classes/sun/swing/FilePane.java

Print this page




 223         }
 224     };
 225 
 226     private static FocusListener repaintListener = new FocusListener() {
 227         public void focusGained(FocusEvent fe) {
 228             repaintSelection(fe.getSource());
 229         }
 230 
 231         public void focusLost(FocusEvent fe) {
 232             repaintSelection(fe.getSource());
 233         }
 234 
 235         private void repaintSelection(Object source) {
 236             if (source instanceof JList) {
 237                 repaintListSelection((JList)source);
 238             } else if (source instanceof JTable) {
 239                 repaintTableSelection((JTable)source);
 240             }
 241         }
 242 
 243         private void repaintListSelection(JList list) {
 244             int[] indices = list.getSelectedIndices();
 245             for (int i : indices) {
 246                 Rectangle bounds = list.getCellBounds(i, i);
 247                 list.repaint(bounds);
 248             }
 249         }
 250 
 251         private void repaintTableSelection(JTable table) {
 252             int minRow = table.getSelectionModel().getMinSelectionIndex();
 253             int maxRow = table.getSelectionModel().getMaxSelectionIndex();
 254             if (minRow == -1 || maxRow == -1) {
 255                 return;
 256             }
 257 
 258             int col0 = table.convertColumnIndexToView(COLUMN_FILENAME);
 259 
 260             Rectangle first = table.getCellRect(minRow, col0, false);
 261             Rectangle last = table.getCellRect(maxRow, col0, false);
 262             Rectangle dirty = first.union(last);
 263             table.repaint(dirty);
 264         }
 265     };
 266 
 267     private boolean smallIconsView = false;
 268     private Border  listViewBorder;
 269     private Color   listViewBackground;
 270     private boolean listViewWindowsStyle;
 271     private boolean readOnly;
 272     private boolean fullRowSelection = false;
 273 
 274     private ListSelectionModel listSelectionModel;
 275     private JList list;
 276     private JTable detailsTable;
 277 
 278     private static final int COLUMN_FILENAME = 0;
 279 
 280     // Provides a way to recognize a newly created folder, so it can
 281     // be selected when it appears in the model.
 282     private File newFolderFile;
 283 
 284     // Used for accessing methods in the corresponding UI class
 285     private FileChooserUIAccessor fileChooserUIAccessor;
 286     private DetailsTableModel detailsTableModel;
 287     private DetailsTableRowSorter rowSorter;
 288 
 289     public FilePane(FileChooserUIAccessor fileChooserUIAccessor) {
 290         super(new BorderLayout());
 291 
 292         this.fileChooserUIAccessor = fileChooserUIAccessor;
 293 
 294         installDefaults();
 295         createActionMap();


 315 
 316     public void setViewType(int viewType) {
 317         if (viewType == this.viewType) {
 318             return;
 319         }
 320 
 321         int oldValue = this.viewType;
 322         this.viewType = viewType;
 323 
 324         JPanel createdViewPanel = null;
 325         Component newFocusOwner = null;
 326 
 327         switch (viewType) {
 328           case VIEWTYPE_LIST:
 329             if (viewPanels[viewType] == null) {
 330                 createdViewPanel = fileChooserUIAccessor.createList();
 331                 if (createdViewPanel == null) {
 332                     createdViewPanel = createList();
 333                 }
 334 
 335                 list = (JList) findChildComponent(createdViewPanel, JList.class);
 336                 if (listSelectionModel == null) {
 337                     listSelectionModel = list.getSelectionModel();
 338                     if (detailsTable != null) {
 339                         detailsTable.setSelectionModel(listSelectionModel);
 340                     }
 341                 } else {
 342                     list.setSelectionModel(listSelectionModel);
 343                 }
 344             }
 345             list.setLayoutOrientation(JList.VERTICAL_WRAP);
 346             newFocusOwner = list;
 347             break;
 348 
 349           case VIEWTYPE_DETAILS:
 350             if (viewPanels[viewType] == null) {
 351                 createdViewPanel = fileChooserUIAccessor.createDetailsView();
 352                 if (createdViewPanel == null) {
 353                     createdViewPanel = createDetailsView();
 354                 }
 355 
 356                 detailsTable = (JTable) findChildComponent(createdViewPanel, JTable.class);
 357                 detailsTable.setRowHeight(Math.max(detailsTable.getFont().getSize() + 4, 16 + 1));
 358                 if (listSelectionModel != null) {
 359                     detailsTable.setSelectionModel(listSelectionModel);
 360                 }
 361             }
 362             newFocusOwner = detailsTable;
 363             break;
 364         }
 365 
 366         if (createdViewPanel != null) {
 367             viewPanels[viewType] = createdViewPanel;
 368             recursivelySetInheritsPopupMenu(createdViewPanel, true);
 369         }
 370 
 371         boolean isFocusOwner = false;
 372 
 373         if (currentViewPanel != null) {
 374             Component owner = DefaultKeyboardFocusManager.
 375                     getCurrentKeyboardFocusManager().getPermanentFocusOwner();
 376 


 552     }
 553 
 554     protected void createActionMap() {
 555         addActionsToMap(super.getActionMap(), getActions());
 556     }
 557 
 558 
 559     public static void addActionsToMap(ActionMap map, Action[] actions) {
 560         if (map != null && actions != null) {
 561             for (Action a : actions) {
 562                 String cmd = (String)a.getValue(Action.ACTION_COMMAND_KEY);
 563                 if (cmd == null) {
 564                     cmd = (String)a.getValue(Action.NAME);
 565                 }
 566                 map.put(cmd, a);
 567             }
 568         }
 569     }
 570 
 571 
 572     private void updateListRowCount(JList list) {
 573         if (smallIconsView) {
 574             list.setVisibleRowCount(getModel().getSize() / 3);
 575         } else {
 576             list.setVisibleRowCount(-1);
 577         }
 578     }
 579 
 580     public JPanel createList() {
 581         JPanel p = new JPanel(new BorderLayout());
 582         final JFileChooser fileChooser = getFileChooser();
 583 
 584         @SuppressWarnings("serial") // anonymous class
 585         final JList<Object> list = new JList<Object>() {
 586             public int getNextMatch(String prefix, int startIndex, Position.Bias bias) {
 587                 ListModel model = getModel();
 588                 int max = model.getSize();
 589                 if (prefix == null || startIndex < 0 || startIndex >= max) {
 590                     throw new IllegalArgumentException();
 591                 }
 592                 // start search from the next element before/after the selected element
 593                 boolean backwards = (bias == Position.Bias.Backward);
 594                 for (int i = startIndex; backwards ? i >= 0 : i < max; i += (backwards ?  -1 : 1)) {
 595                     String filename = fileChooser.getName((File)model.getElementAt(i));
 596                     if (filename.regionMatches(true, 0, prefix, 0, prefix.length())) {
 597                         return i;
 598                     }
 599                 }
 600                 return -1;
 601             }
 602         };
 603         list.setCellRenderer(new FileRenderer());
 604         list.setLayoutOrientation(JList.VERTICAL_WRAP);
 605 
 606         // 4835633 : tell BasicListUI that this is a file list
 607         list.putClientProperty("List.isFileList", Boolean.TRUE);


 901             }
 902 
 903             table.setColumnModel(columnModel);
 904         }
 905     }
 906 
 907     private DetailsTableRowSorter getRowSorter() {
 908         if (rowSorter == null) {
 909             rowSorter = new DetailsTableRowSorter();
 910         }
 911         return rowSorter;
 912     }
 913 
 914     private class DetailsTableRowSorter extends TableRowSorter<TableModel> {
 915         public DetailsTableRowSorter() {
 916             setModelWrapper(new SorterModelWrapper());
 917         }
 918 
 919         public void updateComparators(ShellFolderColumnInfo [] columns) {
 920             for (int i = 0; i < columns.length; i++) {
 921                 Comparator c = columns[i].getComparator();
 922                 if (c != null) {
 923                     c = new DirectoriesFirstComparatorWrapper(i, c);
 924                 }
 925                 setComparator(i, c);
 926             }
 927         }
 928 
 929         @Override
 930         public void sort() {
 931             ShellFolder.invoke(new Callable<Void>() {
 932                 public Void call() {
 933                     DetailsTableRowSorter.super.sort();
 934                     return null;
 935                 }
 936             });
 937         }
 938 
 939         public void modelStructureChanged() {
 940             super.modelStructureChanged();
 941             updateComparators(detailsTableModel.getColumns());


 952 
 953             public int getRowCount() {
 954                 return getDetailsTableModel().getRowCount();
 955             }
 956 
 957             public Object getValueAt(int row, int column) {
 958                 return FilePane.this.getModel().getElementAt(row);
 959             }
 960 
 961             public Integer getIdentifier(int row) {
 962                 return row;
 963             }
 964         }
 965     }
 966 
 967     /**
 968      * This class sorts directories before files, comparing directory to
 969      * directory and file to file using the wrapped comparator.
 970      */
 971     private class DirectoriesFirstComparatorWrapper implements Comparator<File> {
 972         private Comparator comparator;
 973         private int column;
 974 
 975         public DirectoriesFirstComparatorWrapper(int column, Comparator comparator) {

 976             this.column = column;
 977             this.comparator = comparator;
 978         }
 979 
 980         public int compare(File f1, File f2) {
 981             if (f1 != null && f2 != null) {
 982                 boolean traversable1 = getFileChooser().isTraversable(f1);
 983                 boolean traversable2 = getFileChooser().isTraversable(f2);
 984                 // directories go first
 985                 if (traversable1 && !traversable2) {
 986                     return -1;
 987                 }
 988                 if (!traversable1 && traversable2) {
 989                     return 1;
 990                 }
 991             }
 992             if (detailsTableModel.getColumns()[column].isCompareByColumn()) {
 993                 return comparator.compare(
 994                         getDetailsTableModel().getFileColumnValue(f1, column),
 995                         getDetailsTableModel().getFileColumnValue(f2, column)
 996                 );
 997             }


1475                 public void actionPerformed(ActionEvent ev) {
1476                     if (basicNewFolderAction == null) {
1477                         basicNewFolderAction = fileChooserUIAccessor.getNewFolderAction();
1478                     }
1479                     JFileChooser fc = getFileChooser();
1480                     File oldFile = fc.getSelectedFile();
1481                     basicNewFolderAction.actionPerformed(ev);
1482                     File newFile = fc.getSelectedFile();
1483                     if (newFile != null && !newFile.equals(oldFile) && newFile.isDirectory()) {
1484                         newFolderFile = newFile;
1485                     }
1486                 }
1487             };
1488         }
1489         return newFolderAction;
1490     }
1491 
1492     @SuppressWarnings("serial") // JDK-implementation class
1493     protected class FileRenderer extends DefaultListCellRenderer  {
1494 
1495         public Component getListCellRendererComponent(JList list, Object value,
1496                                                       int index, boolean isSelected,
1497                                                       boolean cellHasFocus) {
1498 
1499             if (listViewWindowsStyle && !list.isFocusOwner()) {
1500                 isSelected = false;
1501             }
1502 
1503             super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
1504             File file = (File) value;
1505             String fileName = getFileChooser().getName(file);
1506             setText(fileName);
1507             setFont(list.getFont());
1508 
1509             Icon icon = getFileChooser().getIcon(file);
1510             if (icon != null) {
1511                 setIcon(icon);
1512             } else {
1513                 if (getFileChooser().getFileSystemView().isTraversable(file)) {
1514                     setText(fileName+File.separator);
1515                 }


1951     /**
1952      * Property to remember whether a directory is currently selected in the UI.
1953      *
1954      * @return <code>true</code> iff a directory is currently selected.
1955      */
1956     protected boolean isDirectorySelected() {
1957         return fileChooserUIAccessor.isDirectorySelected();
1958     }
1959 
1960 
1961     /**
1962      * Property to remember the directory that is currently selected in the UI.
1963      *
1964      * @return the value of the <code>directory</code> property
1965      * @see javax.swing.plaf.basic.BasicFileChooserUI#setDirectory
1966      */
1967     protected File getDirectory() {
1968         return fileChooserUIAccessor.getDirectory();
1969     }
1970 
1971     private Component findChildComponent(Container container, Class cls) {
1972         int n = container.getComponentCount();
1973         for (int i = 0; i < n; i++) {
1974             Component comp = container.getComponent(i);
1975             if (cls.isInstance(comp)) {
1976                 return comp;
1977             } else if (comp instanceof Container) {
1978                 Component c = findChildComponent((Container)comp, cls);
1979                 if (c != null) {
1980                     return c;
1981                 }
1982             }
1983         }
1984         return null;
1985     }
1986 
1987     public boolean canWrite(File f) {
1988         // Return false for non FileSystem files or if file doesn't exist.
1989         if (!f.exists()) {
1990             return false;
1991         }
1992 
1993         if (f instanceof ShellFolder) {
1994             return f.canWrite();
1995         } else {
1996             if (usesShellFolder(getFileChooser())) {
1997                 try {
1998                     return ShellFolder.getShellFolder(f).canWrite();


2012      */
2013     public static boolean usesShellFolder(JFileChooser chooser) {
2014         Boolean prop = (Boolean) chooser.getClientProperty("FileChooser.useShellFolder");
2015 
2016         return prop == null ? chooser.getFileSystemView().equals(FileSystemView.getFileSystemView())
2017                 : prop.booleanValue();
2018     }
2019 
2020     // This interface is used to access methods in the FileChooserUI
2021     // that are not public.
2022     public interface FileChooserUIAccessor {
2023         public JFileChooser getFileChooser();
2024         public BasicDirectoryModel getModel();
2025         public JPanel createList();
2026         public JPanel createDetailsView();
2027         public boolean isDirectorySelected();
2028         public File getDirectory();
2029         public Action getApproveSelectionAction();
2030         public Action getChangeToParentDirectoryAction();
2031         public Action getNewFolderAction();
2032         public MouseListener createDoubleClickListener(JList list);
2033         public ListSelectionListener createListSelectionListener();
2034     }
2035 }


 223         }
 224     };
 225 
 226     private static FocusListener repaintListener = new FocusListener() {
 227         public void focusGained(FocusEvent fe) {
 228             repaintSelection(fe.getSource());
 229         }
 230 
 231         public void focusLost(FocusEvent fe) {
 232             repaintSelection(fe.getSource());
 233         }
 234 
 235         private void repaintSelection(Object source) {
 236             if (source instanceof JList) {
 237                 repaintListSelection((JList)source);
 238             } else if (source instanceof JTable) {
 239                 repaintTableSelection((JTable)source);
 240             }
 241         }
 242 
 243         private void repaintListSelection(JList<?> list) {
 244             int[] indices = list.getSelectedIndices();
 245             for (int i : indices) {
 246                 Rectangle bounds = list.getCellBounds(i, i);
 247                 list.repaint(bounds);
 248             }
 249         }
 250 
 251         private void repaintTableSelection(JTable table) {
 252             int minRow = table.getSelectionModel().getMinSelectionIndex();
 253             int maxRow = table.getSelectionModel().getMaxSelectionIndex();
 254             if (minRow == -1 || maxRow == -1) {
 255                 return;
 256             }
 257 
 258             int col0 = table.convertColumnIndexToView(COLUMN_FILENAME);
 259 
 260             Rectangle first = table.getCellRect(minRow, col0, false);
 261             Rectangle last = table.getCellRect(maxRow, col0, false);
 262             Rectangle dirty = first.union(last);
 263             table.repaint(dirty);
 264         }
 265     };
 266 
 267     private boolean smallIconsView = false;
 268     private Border  listViewBorder;
 269     private Color   listViewBackground;
 270     private boolean listViewWindowsStyle;
 271     private boolean readOnly;
 272     private boolean fullRowSelection = false;
 273 
 274     private ListSelectionModel listSelectionModel;
 275     private JList<?> list;
 276     private JTable detailsTable;
 277 
 278     private static final int COLUMN_FILENAME = 0;
 279 
 280     // Provides a way to recognize a newly created folder, so it can
 281     // be selected when it appears in the model.
 282     private File newFolderFile;
 283 
 284     // Used for accessing methods in the corresponding UI class
 285     private FileChooserUIAccessor fileChooserUIAccessor;
 286     private DetailsTableModel detailsTableModel;
 287     private DetailsTableRowSorter rowSorter;
 288 
 289     public FilePane(FileChooserUIAccessor fileChooserUIAccessor) {
 290         super(new BorderLayout());
 291 
 292         this.fileChooserUIAccessor = fileChooserUIAccessor;
 293 
 294         installDefaults();
 295         createActionMap();


 315 
 316     public void setViewType(int viewType) {
 317         if (viewType == this.viewType) {
 318             return;
 319         }
 320 
 321         int oldValue = this.viewType;
 322         this.viewType = viewType;
 323 
 324         JPanel createdViewPanel = null;
 325         Component newFocusOwner = null;
 326 
 327         switch (viewType) {
 328           case VIEWTYPE_LIST:
 329             if (viewPanels[viewType] == null) {
 330                 createdViewPanel = fileChooserUIAccessor.createList();
 331                 if (createdViewPanel == null) {
 332                     createdViewPanel = createList();
 333                 }
 334 
 335                 list = findChildComponent(createdViewPanel, JList.class);
 336                 if (listSelectionModel == null) {
 337                     listSelectionModel = list.getSelectionModel();
 338                     if (detailsTable != null) {
 339                         detailsTable.setSelectionModel(listSelectionModel);
 340                     }
 341                 } else {
 342                     list.setSelectionModel(listSelectionModel);
 343                 }
 344             }
 345             list.setLayoutOrientation(JList.VERTICAL_WRAP);
 346             newFocusOwner = list;
 347             break;
 348 
 349           case VIEWTYPE_DETAILS:
 350             if (viewPanels[viewType] == null) {
 351                 createdViewPanel = fileChooserUIAccessor.createDetailsView();
 352                 if (createdViewPanel == null) {
 353                     createdViewPanel = createDetailsView();
 354                 }
 355 
 356                 detailsTable = findChildComponent(createdViewPanel, JTable.class);
 357                 detailsTable.setRowHeight(Math.max(detailsTable.getFont().getSize() + 4, 16 + 1));
 358                 if (listSelectionModel != null) {
 359                     detailsTable.setSelectionModel(listSelectionModel);
 360                 }
 361             }
 362             newFocusOwner = detailsTable;
 363             break;
 364         }
 365 
 366         if (createdViewPanel != null) {
 367             viewPanels[viewType] = createdViewPanel;
 368             recursivelySetInheritsPopupMenu(createdViewPanel, true);
 369         }
 370 
 371         boolean isFocusOwner = false;
 372 
 373         if (currentViewPanel != null) {
 374             Component owner = DefaultKeyboardFocusManager.
 375                     getCurrentKeyboardFocusManager().getPermanentFocusOwner();
 376 


 552     }
 553 
 554     protected void createActionMap() {
 555         addActionsToMap(super.getActionMap(), getActions());
 556     }
 557 
 558 
 559     public static void addActionsToMap(ActionMap map, Action[] actions) {
 560         if (map != null && actions != null) {
 561             for (Action a : actions) {
 562                 String cmd = (String)a.getValue(Action.ACTION_COMMAND_KEY);
 563                 if (cmd == null) {
 564                     cmd = (String)a.getValue(Action.NAME);
 565                 }
 566                 map.put(cmd, a);
 567             }
 568         }
 569     }
 570 
 571 
 572     private void updateListRowCount(JList<?> list) {
 573         if (smallIconsView) {
 574             list.setVisibleRowCount(getModel().getSize() / 3);
 575         } else {
 576             list.setVisibleRowCount(-1);
 577         }
 578     }
 579 
 580     public JPanel createList() {
 581         JPanel p = new JPanel(new BorderLayout());
 582         final JFileChooser fileChooser = getFileChooser();
 583 
 584         @SuppressWarnings("serial") // anonymous class
 585         final JList<Object> list = new JList<Object>() {
 586             public int getNextMatch(String prefix, int startIndex, Position.Bias bias) {
 587                 ListModel<?> model = getModel();
 588                 int max = model.getSize();
 589                 if (prefix == null || startIndex < 0 || startIndex >= max) {
 590                     throw new IllegalArgumentException();
 591                 }
 592                 // start search from the next element before/after the selected element
 593                 boolean backwards = (bias == Position.Bias.Backward);
 594                 for (int i = startIndex; backwards ? i >= 0 : i < max; i += (backwards ?  -1 : 1)) {
 595                     String filename = fileChooser.getName((File)model.getElementAt(i));
 596                     if (filename.regionMatches(true, 0, prefix, 0, prefix.length())) {
 597                         return i;
 598                     }
 599                 }
 600                 return -1;
 601             }
 602         };
 603         list.setCellRenderer(new FileRenderer());
 604         list.setLayoutOrientation(JList.VERTICAL_WRAP);
 605 
 606         // 4835633 : tell BasicListUI that this is a file list
 607         list.putClientProperty("List.isFileList", Boolean.TRUE);


 901             }
 902 
 903             table.setColumnModel(columnModel);
 904         }
 905     }
 906 
 907     private DetailsTableRowSorter getRowSorter() {
 908         if (rowSorter == null) {
 909             rowSorter = new DetailsTableRowSorter();
 910         }
 911         return rowSorter;
 912     }
 913 
 914     private class DetailsTableRowSorter extends TableRowSorter<TableModel> {
 915         public DetailsTableRowSorter() {
 916             setModelWrapper(new SorterModelWrapper());
 917         }
 918 
 919         public void updateComparators(ShellFolderColumnInfo [] columns) {
 920             for (int i = 0; i < columns.length; i++) {
 921                 Comparator<?> c = columns[i].getComparator();
 922                 if (c != null) {
 923                     c = new DirectoriesFirstComparatorWrapper(i, c);
 924                 }
 925                 setComparator(i, c);
 926             }
 927         }
 928 
 929         @Override
 930         public void sort() {
 931             ShellFolder.invoke(new Callable<Void>() {
 932                 public Void call() {
 933                     DetailsTableRowSorter.super.sort();
 934                     return null;
 935                 }
 936             });
 937         }
 938 
 939         public void modelStructureChanged() {
 940             super.modelStructureChanged();
 941             updateComparators(detailsTableModel.getColumns());


 952 
 953             public int getRowCount() {
 954                 return getDetailsTableModel().getRowCount();
 955             }
 956 
 957             public Object getValueAt(int row, int column) {
 958                 return FilePane.this.getModel().getElementAt(row);
 959             }
 960 
 961             public Integer getIdentifier(int row) {
 962                 return row;
 963             }
 964         }
 965     }
 966 
 967     /**
 968      * This class sorts directories before files, comparing directory to
 969      * directory and file to file using the wrapped comparator.
 970      */
 971     private class DirectoriesFirstComparatorWrapper implements Comparator<File> {
 972         private Comparator<Object> comparator;
 973         private int column;
 974 
 975         @SuppressWarnings("unchecked")
 976         public DirectoriesFirstComparatorWrapper(int column, Comparator<?> comparator) {
 977             this.column = column;
 978             this.comparator = (Comparator<Object>)comparator;
 979         }
 980 
 981         public int compare(File f1, File f2) {
 982             if (f1 != null && f2 != null) {
 983                 boolean traversable1 = getFileChooser().isTraversable(f1);
 984                 boolean traversable2 = getFileChooser().isTraversable(f2);
 985                 // directories go first
 986                 if (traversable1 && !traversable2) {
 987                     return -1;
 988                 }
 989                 if (!traversable1 && traversable2) {
 990                     return 1;
 991                 }
 992             }
 993             if (detailsTableModel.getColumns()[column].isCompareByColumn()) {
 994                 return comparator.compare(
 995                         getDetailsTableModel().getFileColumnValue(f1, column),
 996                         getDetailsTableModel().getFileColumnValue(f2, column)
 997                 );
 998             }


1476                 public void actionPerformed(ActionEvent ev) {
1477                     if (basicNewFolderAction == null) {
1478                         basicNewFolderAction = fileChooserUIAccessor.getNewFolderAction();
1479                     }
1480                     JFileChooser fc = getFileChooser();
1481                     File oldFile = fc.getSelectedFile();
1482                     basicNewFolderAction.actionPerformed(ev);
1483                     File newFile = fc.getSelectedFile();
1484                     if (newFile != null && !newFile.equals(oldFile) && newFile.isDirectory()) {
1485                         newFolderFile = newFile;
1486                     }
1487                 }
1488             };
1489         }
1490         return newFolderAction;
1491     }
1492 
1493     @SuppressWarnings("serial") // JDK-implementation class
1494     protected class FileRenderer extends DefaultListCellRenderer  {
1495 
1496         public Component getListCellRendererComponent(JList<?> list, Object value,
1497                                                       int index, boolean isSelected,
1498                                                       boolean cellHasFocus) {
1499 
1500             if (listViewWindowsStyle && !list.isFocusOwner()) {
1501                 isSelected = false;
1502             }
1503 
1504             super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
1505             File file = (File) value;
1506             String fileName = getFileChooser().getName(file);
1507             setText(fileName);
1508             setFont(list.getFont());
1509 
1510             Icon icon = getFileChooser().getIcon(file);
1511             if (icon != null) {
1512                 setIcon(icon);
1513             } else {
1514                 if (getFileChooser().getFileSystemView().isTraversable(file)) {
1515                     setText(fileName+File.separator);
1516                 }


1952     /**
1953      * Property to remember whether a directory is currently selected in the UI.
1954      *
1955      * @return <code>true</code> iff a directory is currently selected.
1956      */
1957     protected boolean isDirectorySelected() {
1958         return fileChooserUIAccessor.isDirectorySelected();
1959     }
1960 
1961 
1962     /**
1963      * Property to remember the directory that is currently selected in the UI.
1964      *
1965      * @return the value of the <code>directory</code> property
1966      * @see javax.swing.plaf.basic.BasicFileChooserUI#setDirectory
1967      */
1968     protected File getDirectory() {
1969         return fileChooserUIAccessor.getDirectory();
1970     }
1971 
1972     private <T> T findChildComponent(Container container, Class<T> cls) {
1973         int n = container.getComponentCount();
1974         for (int i = 0; i < n; i++) {
1975             Component comp = container.getComponent(i);
1976             if (cls.isInstance(comp)) {
1977                 return cls.cast(comp);
1978             } else if (comp instanceof Container) {
1979                 T c = findChildComponent((Container)comp, cls);
1980                 if (c != null) {
1981                     return c;
1982                 }
1983             }
1984         }
1985         return null;
1986     }
1987 
1988     public boolean canWrite(File f) {
1989         // Return false for non FileSystem files or if file doesn't exist.
1990         if (!f.exists()) {
1991             return false;
1992         }
1993 
1994         if (f instanceof ShellFolder) {
1995             return f.canWrite();
1996         } else {
1997             if (usesShellFolder(getFileChooser())) {
1998                 try {
1999                     return ShellFolder.getShellFolder(f).canWrite();


2013      */
2014     public static boolean usesShellFolder(JFileChooser chooser) {
2015         Boolean prop = (Boolean) chooser.getClientProperty("FileChooser.useShellFolder");
2016 
2017         return prop == null ? chooser.getFileSystemView().equals(FileSystemView.getFileSystemView())
2018                 : prop.booleanValue();
2019     }
2020 
2021     // This interface is used to access methods in the FileChooserUI
2022     // that are not public.
2023     public interface FileChooserUIAccessor {
2024         public JFileChooser getFileChooser();
2025         public BasicDirectoryModel getModel();
2026         public JPanel createList();
2027         public JPanel createDetailsView();
2028         public boolean isDirectorySelected();
2029         public File getDirectory();
2030         public Action getApproveSelectionAction();
2031         public Action getChangeToParentDirectoryAction();
2032         public Action getNewFolderAction();
2033         public MouseListener createDoubleClickListener(JList<?> list);
2034         public ListSelectionListener createListSelectionListener();
2035     }
2036 }