< prev index next >

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

Print this page




1338 
1339     private void resetEditIndex() {
1340         lastIndex = -1;
1341     }
1342 
1343     private void cancelEdit() {
1344         if (editFile != null) {
1345             editFile = null;
1346             list.remove(editCell);
1347             repaint();
1348         } else if (detailsTable != null && detailsTable.isEditing()) {
1349             detailsTable.getCellEditor().cancelCellEditing();
1350         }
1351     }
1352 
1353     JTextField editCell = null;
1354 
1355     /**
1356      * @param index visual index of the file to be edited
1357      */

1358     private void editFileName(int index) {
1359         JFileChooser chooser = getFileChooser();
1360         File currentDirectory = chooser.getCurrentDirectory();
1361 
1362         if (readOnly || !canWrite(currentDirectory)) {
1363             return;
1364         }
1365 
1366         ensureIndexIsVisible(index);
1367         switch (viewType) {
1368           case VIEWTYPE_LIST:
1369             editFile = (File)getModel().getElementAt(getRowSorter().convertRowIndexToModel(index));
1370             Rectangle r = list.getCellBounds(index, index);
1371             if (editCell == null) {
1372                 editCell = new JTextField();
1373                 editCell.setName("Tree.cellEditor");
1374                 editCell.addActionListener(new EditActionListener());
1375                 editCell.addFocusListener(editorFocusListener);
1376                 editCell.setNextFocusableComponent(list);
1377             }


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                 }
1517             }
1518 
1519             return this;
1520         }
1521     }
1522 
1523 

1524     void setFileSelected() {
1525         if (getFileChooser().isMultiSelectionEnabled() && !isDirectorySelected()) {
1526             File[] files = getFileChooser().getSelectedFiles(); // Should be selected
1527             Object[] selectedObjects = list.getSelectedValues(); // Are actually selected
1528 
1529             listSelectionModel.setValueIsAdjusting(true);
1530             try {
1531                 int lead = listSelectionModel.getLeadSelectionIndex();
1532                 int anchor = listSelectionModel.getAnchorSelectionIndex();
1533 
1534                 Arrays.sort(files);
1535                 Arrays.sort(selectedObjects);
1536 
1537                 int shouldIndex = 0;
1538                 int actuallyIndex = 0;
1539 
1540                 // Remove files that shouldn't be selected and add files which should be selected
1541                 // Note: Assume files are already sorted in compareTo order.
1542                 while (shouldIndex < files.length &&
1543                        actuallyIndex < selectedObjects.length) {




1338 
1339     private void resetEditIndex() {
1340         lastIndex = -1;
1341     }
1342 
1343     private void cancelEdit() {
1344         if (editFile != null) {
1345             editFile = null;
1346             list.remove(editCell);
1347             repaint();
1348         } else if (detailsTable != null && detailsTable.isEditing()) {
1349             detailsTable.getCellEditor().cancelCellEditing();
1350         }
1351     }
1352 
1353     JTextField editCell = null;
1354 
1355     /**
1356      * @param index visual index of the file to be edited
1357      */
1358     @SuppressWarnings("deprecation")
1359     private void editFileName(int index) {
1360         JFileChooser chooser = getFileChooser();
1361         File currentDirectory = chooser.getCurrentDirectory();
1362 
1363         if (readOnly || !canWrite(currentDirectory)) {
1364             return;
1365         }
1366 
1367         ensureIndexIsVisible(index);
1368         switch (viewType) {
1369           case VIEWTYPE_LIST:
1370             editFile = (File)getModel().getElementAt(getRowSorter().convertRowIndexToModel(index));
1371             Rectangle r = list.getCellBounds(index, index);
1372             if (editCell == null) {
1373                 editCell = new JTextField();
1374                 editCell.setName("Tree.cellEditor");
1375                 editCell.addActionListener(new EditActionListener());
1376                 editCell.addFocusListener(editorFocusListener);
1377                 editCell.setNextFocusableComponent(list);
1378             }


1505             super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
1506             File file = (File) value;
1507             String fileName = getFileChooser().getName(file);
1508             setText(fileName);
1509             setFont(list.getFont());
1510 
1511             Icon icon = getFileChooser().getIcon(file);
1512             if (icon != null) {
1513                 setIcon(icon);
1514             } else {
1515                 if (getFileChooser().getFileSystemView().isTraversable(file)) {
1516                     setText(fileName+File.separator);
1517                 }
1518             }
1519 
1520             return this;
1521         }
1522     }
1523 
1524 
1525     @SuppressWarnings("deprecation")
1526     void setFileSelected() {
1527         if (getFileChooser().isMultiSelectionEnabled() && !isDirectorySelected()) {
1528             File[] files = getFileChooser().getSelectedFiles(); // Should be selected
1529             Object[] selectedObjects = list.getSelectedValues(); // Are actually selected
1530 
1531             listSelectionModel.setValueIsAdjusting(true);
1532             try {
1533                 int lead = listSelectionModel.getLeadSelectionIndex();
1534                 int anchor = listSelectionModel.getAnchorSelectionIndex();
1535 
1536                 Arrays.sort(files);
1537                 Arrays.sort(selectedObjects);
1538 
1539                 int shouldIndex = 0;
1540                 int actuallyIndex = 0;
1541 
1542                 // Remove files that shouldn't be selected and add files which should be selected
1543                 // Note: Assume files are already sorted in compareTo order.
1544                 while (shouldIndex < files.length &&
1545                        actuallyIndex < selectedObjects.length) {


< prev index next >