⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basicdirectorymodel.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    sort(acceptsList);                            Vector newDirectories = new Vector(50);                    Vector newFiles = new Vector();                    // run through list grabbing directories in chunks of ten                    for(int i = 0; i < acceptsList.size(); i++) {                        File f = (File) acceptsList.elementAt(i);                        boolean isTraversable = filechooser.isTraversable(f);                        if (isTraversable) {                            newDirectories.addElement(f);                        } else if (!isTraversable && filechooser.isFileSelectionEnabled()) {                            newFiles.addElement(f);                        }                        if(isInterrupted()) {                            return null;                        }                    }                            Vector newFileCache = new Vector(newDirectories);                    newFileCache.addAll(newFiles);                            int newSize = newFileCache.size();                    int oldSize = fileCache.size();                            if (newSize > oldSize) {                        //see if interval is added                        int start = oldSize;                        int end = newSize;                        for (int i = 0; i < oldSize; i++) {                            if (!newFileCache.get(i).equals(fileCache.get(i))) {                                start = i;                                for (int j = i; j < newSize; j++) {                                    if (newFileCache.get(j).equals(fileCache.get(i))) {                                        end = j;                                        break;                                    }                                }                                break;                            }                        }                        if (start >= 0 && end > start                            && newFileCache.subList(end, newSize).equals(fileCache.subList(start, oldSize))) {                            if(isInterrupted()) {                                return null;                            }                            invokeLater(new DoChangeContents(newFileCache.subList(start, end), start, null, 0, fid));                            newFileCache = null;                        }                    } else if (newSize < oldSize) {                        //see if interval is removed                        int start = -1;                        int end = -1;                        for (int i = 0; i < newSize; i++) {                            if (!newFileCache.get(i).equals(fileCache.get(i))) {                                start = i;                                end = i + oldSize - newSize;                                break;                            }                        }                        if (start >= 0 && end > start                            && fileCache.subList(end, oldSize).equals(newFileCache.subList(start, newSize))) {                            if(isInterrupted()) {                                return null;                            }                            invokeLater(new DoChangeContents(null, 0, new Vector(fileCache.subList(start, end)),                                                             start, fid));                            newFileCache = null;                        }                    }                    if (newFileCache != null && !fileCache.equals(newFileCache)) {                        if (isInterrupted()) {                            cancelRunnables(runnables);                        }                        invokeLater(new DoChangeContents(newFileCache, 0, fileCache, 0, fid));                    }                    return null;                }            });        }        public void cancelRunnables(Vector runnables) {            for(int i = 0; i < runnables.size(); i++) {                ((DoChangeContents)runnables.elementAt(i)).cancel();            }        }         public void cancelRunnables() {            cancelRunnables(runnables);        }   }    /**     * Adds a PropertyChangeListener to the listener list. The listener is     * registered for all bound properties of this class.     * <p>     * If <code>listener</code> is <code>null</code>,     * no exception is thrown and no action is performed.     *     * @param    listener  the property change listener to be added     *     * @see #removePropertyChangeListener     * @see #getPropertyChangeListeners     *     * @since 1.6     */    public void addPropertyChangeListener(PropertyChangeListener listener) {        if (changeSupport == null) {            changeSupport = new PropertyChangeSupport(this);        }        changeSupport.addPropertyChangeListener(listener);    }    /**     * Removes a PropertyChangeListener from the listener list.     * <p>     * If listener is null, no exception is thrown and no action is performed.     *     * @param listener the PropertyChangeListener to be removed     *     * @see #addPropertyChangeListener     * @see #getPropertyChangeListeners     *     * @since 1.6     */    public void removePropertyChangeListener(PropertyChangeListener listener) {        if (changeSupport != null) {            changeSupport.removePropertyChangeListener(listener);        }    }    /**     * Returns an array of all the property change listeners     * registered on this component.     *     * @return all of this component's <code>PropertyChangeListener</code>s     *         or an empty array if no property change     *         listeners are currently registered     *     * @see      #addPropertyChangeListener     * @see      #removePropertyChangeListener     * @see      java.beans.PropertyChangeSupport#getPropertyChangeListeners     *     * @since 1.6     */    public PropertyChangeListener[] getPropertyChangeListeners() {        if (changeSupport == null) {            return new PropertyChangeListener[0];        }        return changeSupport.getPropertyChangeListeners();    }    /**     * Support for reporting bound property changes for boolean properties.      * This method can be called when a bound property has changed and it will     * send the appropriate PropertyChangeEvent to any registered     * PropertyChangeListeners.     *     * @param propertyName the property whose value has changed     * @param oldValue the property's previous value     * @param newValue the property's new value     *     * @since 1.6     */    protected void firePropertyChange(String propertyName,                                      Object oldValue, Object newValue) {        if (changeSupport != null) {            changeSupport.firePropertyChange(propertyName,                                             oldValue, newValue);        }    }    /**     * Set the busy state for the model. The model is considered     * busy when it is running a separate (interruptable)     * thread in order to load the contents of a directory.     */    private synchronized void setBusy(final boolean busy, int fid) {        if (fid == fetchID) {            boolean oldValue = this.busy;            this.busy = busy;            if (changeSupport != null && busy != oldValue) {                SwingUtilities.invokeLater(new Runnable() {                    public void run() {                        firePropertyChange("busy", !busy, busy);                    }                });            }        }    }    class DoChangeContents implements Runnable {        private List addFiles;        private List remFiles;        private boolean doFire = true;        private int fid;        private int addStart = 0;        private int remStart = 0;        private int change;        public DoChangeContents(List addFiles, int addStart, List remFiles, int remStart, int fid) {            this.addFiles = addFiles;            this.addStart = addStart;            this.remFiles = remFiles;            this.remStart = remStart;            this.fid = fid;        }        synchronized void cancel() {                doFire = false;        }        public synchronized void run() {            if (fetchID == fid && doFire) {                int remSize = (remFiles == null) ? 0 : remFiles.size();                int addSize = (addFiles == null) ? 0 : addFiles.size();                synchronized(fileCache) {                    if (remSize > 0) {                        fileCache.removeAll(remFiles);                    }                    if (addSize > 0) {                        fileCache.addAll(addStart, addFiles);                    }                    files = null;                    directories = null;                }                if (remSize > 0 && addSize == 0) {                    fireIntervalRemoved(BasicDirectoryModel.this, remStart, remStart + remSize - 1);                } else if (addSize > 0 && remSize == 0 && fileCache.size() > addSize) {                    fireIntervalAdded(BasicDirectoryModel.this, addStart, addStart + addSize - 1);                } else {                    fireContentsChanged();                }            }        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -