< prev index next >

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

Print this page




 103     private String renameErrorFileExistsText;
 104 
 105     private static final Cursor waitCursor =
 106         Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
 107 
 108     private final KeyListener detailsKeyListener = new KeyAdapter() {
 109         private final long timeFactor;
 110 
 111         private final StringBuilder typedString = new StringBuilder();
 112 
 113         private long lastTime = 1000L;
 114 
 115         {
 116             Long l = (Long) UIManager.get("Table.timeFactor");
 117             timeFactor = (l != null) ? l : 1000L;
 118         }
 119 
 120         /**
 121          * Moves the keyboard focus to the first element whose prefix matches
 122          * the sequence of alphanumeric keys pressed by the user with delay
 123          * less than value of <code>timeFactor</code>. Subsequent same key
 124          * presses move the keyboard focus to the next object that starts with
 125          * the same letter until another key is pressed, then it is treated
 126          * as the prefix with appropriate number of the same letters followed
 127          * by first typed another letter.
 128          */
 129         public void keyTyped(KeyEvent e) {
 130             BasicDirectoryModel model = getModel();
 131             int rowCount = model.getSize();
 132 
 133             if (detailsTable == null || rowCount == 0 ||
 134                     e.isAltDown() || e.isControlDown() || e.isMetaDown()) {
 135                 return;
 136             }
 137 
 138             InputMap inputMap = detailsTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
 139             KeyStroke key = KeyStroke.getKeyStrokeForEvent(e);
 140 
 141             if (inputMap != null && inputMap.get(key) != null) {
 142                 return;
 143             }


1302             this.editFile = editFile;
1303             if (isShowing()) {
1304                 SwingUtilities.invokeLater(this);
1305             }
1306         }
1307 
1308         public void run() {
1309             setFileSelected();
1310             if (editFile != null) {
1311                 editFileName(getRowSorter().convertRowIndexToView(
1312                         getModel().indexOf(editFile)));
1313                 editFile = null;
1314             }
1315         }
1316     }
1317 
1318 
1319     /**
1320      * Creates a selection listener for the list of files and directories.
1321      *
1322      * @return a <code>ListSelectionListener</code>
1323      */
1324     public ListSelectionListener createListSelectionListener() {
1325         return fileChooserUIAccessor.createListSelectionListener();
1326     }
1327 
1328     int lastIndex = -1;
1329     File editFile = null;
1330 
1331     private int getEditIndex() {
1332         return lastIndex;
1333     }
1334 
1335     private void setEditIndex(int i) {
1336         lastIndex = i;
1337     }
1338 
1339     private void resetEditIndex() {
1340         lastIndex = -1;
1341     }
1342 


1937                 // Forward event to Basic
1938                 if (getDoubleClickListener() != null) {
1939                     getDoubleClickListener().mouseReleased(evt);
1940                 }
1941             }
1942         }
1943 
1944         private MouseListener getDoubleClickListener() {
1945             // Lazy creation of Basic's listener
1946             if (doubleClickListener == null && list != null) {
1947                 doubleClickListener =
1948                     fileChooserUIAccessor.createDoubleClickListener(list);
1949             }
1950             return doubleClickListener;
1951         }
1952     }
1953 
1954     /**
1955      * Property to remember whether a directory is currently selected in the UI.
1956      *
1957      * @return <code>true</code> iff a directory is currently selected.
1958      */
1959     protected boolean isDirectorySelected() {
1960         return fileChooserUIAccessor.isDirectorySelected();
1961     }
1962 
1963 
1964     /**
1965      * Property to remember the directory that is currently selected in the UI.
1966      *
1967      * @return the value of the <code>directory</code> property
1968      * @see javax.swing.plaf.basic.BasicFileChooserUI#setDirectory
1969      */
1970     protected File getDirectory() {
1971         return fileChooserUIAccessor.getDirectory();
1972     }
1973 
1974     private <T> T findChildComponent(Container container, Class<T> cls) {
1975         int n = container.getComponentCount();
1976         for (int i = 0; i < n; i++) {
1977             Component comp = container.getComponent(i);
1978             if (cls.isInstance(comp)) {
1979                 return cls.cast(comp);
1980             } else if (comp instanceof Container) {
1981                 T c = findChildComponent((Container)comp, cls);
1982                 if (c != null) {
1983                     return c;
1984                 }
1985             }
1986         }
1987         return null;




 103     private String renameErrorFileExistsText;
 104 
 105     private static final Cursor waitCursor =
 106         Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
 107 
 108     private final KeyListener detailsKeyListener = new KeyAdapter() {
 109         private final long timeFactor;
 110 
 111         private final StringBuilder typedString = new StringBuilder();
 112 
 113         private long lastTime = 1000L;
 114 
 115         {
 116             Long l = (Long) UIManager.get("Table.timeFactor");
 117             timeFactor = (l != null) ? l : 1000L;
 118         }
 119 
 120         /**
 121          * Moves the keyboard focus to the first element whose prefix matches
 122          * the sequence of alphanumeric keys pressed by the user with delay
 123          * less than value of {@code timeFactor}. Subsequent same key
 124          * presses move the keyboard focus to the next object that starts with
 125          * the same letter until another key is pressed, then it is treated
 126          * as the prefix with appropriate number of the same letters followed
 127          * by first typed another letter.
 128          */
 129         public void keyTyped(KeyEvent e) {
 130             BasicDirectoryModel model = getModel();
 131             int rowCount = model.getSize();
 132 
 133             if (detailsTable == null || rowCount == 0 ||
 134                     e.isAltDown() || e.isControlDown() || e.isMetaDown()) {
 135                 return;
 136             }
 137 
 138             InputMap inputMap = detailsTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
 139             KeyStroke key = KeyStroke.getKeyStrokeForEvent(e);
 140 
 141             if (inputMap != null && inputMap.get(key) != null) {
 142                 return;
 143             }


1302             this.editFile = editFile;
1303             if (isShowing()) {
1304                 SwingUtilities.invokeLater(this);
1305             }
1306         }
1307 
1308         public void run() {
1309             setFileSelected();
1310             if (editFile != null) {
1311                 editFileName(getRowSorter().convertRowIndexToView(
1312                         getModel().indexOf(editFile)));
1313                 editFile = null;
1314             }
1315         }
1316     }
1317 
1318 
1319     /**
1320      * Creates a selection listener for the list of files and directories.
1321      *
1322      * @return a {@code ListSelectionListener}
1323      */
1324     public ListSelectionListener createListSelectionListener() {
1325         return fileChooserUIAccessor.createListSelectionListener();
1326     }
1327 
1328     int lastIndex = -1;
1329     File editFile = null;
1330 
1331     private int getEditIndex() {
1332         return lastIndex;
1333     }
1334 
1335     private void setEditIndex(int i) {
1336         lastIndex = i;
1337     }
1338 
1339     private void resetEditIndex() {
1340         lastIndex = -1;
1341     }
1342 


1937                 // Forward event to Basic
1938                 if (getDoubleClickListener() != null) {
1939                     getDoubleClickListener().mouseReleased(evt);
1940                 }
1941             }
1942         }
1943 
1944         private MouseListener getDoubleClickListener() {
1945             // Lazy creation of Basic's listener
1946             if (doubleClickListener == null && list != null) {
1947                 doubleClickListener =
1948                     fileChooserUIAccessor.createDoubleClickListener(list);
1949             }
1950             return doubleClickListener;
1951         }
1952     }
1953 
1954     /**
1955      * Property to remember whether a directory is currently selected in the UI.
1956      *
1957      * @return {@code true} iff a directory is currently selected.
1958      */
1959     protected boolean isDirectorySelected() {
1960         return fileChooserUIAccessor.isDirectorySelected();
1961     }
1962 
1963 
1964     /**
1965      * Property to remember the directory that is currently selected in the UI.
1966      *
1967      * @return the value of the {@code directory} property
1968      * @see javax.swing.plaf.basic.BasicFileChooserUI#setDirectory
1969      */
1970     protected File getDirectory() {
1971         return fileChooserUIAccessor.getDirectory();
1972     }
1973 
1974     private <T> T findChildComponent(Container container, Class<T> cls) {
1975         int n = container.getComponentCount();
1976         for (int i = 0; i < n; i++) {
1977             Component comp = container.getComponent(i);
1978             if (cls.isInstance(comp)) {
1979                 return cls.cast(comp);
1980             } else if (comp instanceof Container) {
1981                 T c = findChildComponent((Container)comp, cls);
1982                 if (c != null) {
1983                     return c;
1984                 }
1985             }
1986         }
1987         return null;


< prev index next >