|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.examples.modules.sortbysize; import java.util.*; import org.openide.filesystems.*; import org.openide.nodes.Children; import org.openide.nodes.Node; public class FileViewChildren extends Children.Keys implements FileChangeListener, Comparator { private final FileObject f; public FileViewChildren(FileObject f) { this.f = f; } protected void addNotify() { super.addNotify(); refreshKeys(); f.addFileChangeListener(this); } protected void removeNotify() { f.removeFileChangeListener(this); setKeys(Collections.EMPTY_SET); super.removeNotify(); } private void refreshKeys() { List l = new ArrayList(Arrays.asList(f.getChildren())); Collections.sort(l, this); setKeys(l); } protected Node[] createNodes(Object key) { return new Node[] {new FileViewNode((FileObject)key)}; } public void fileFolderCreated(FileEvent fe) { refreshKeys(); } public void fileDataCreated(FileEvent fe) { refreshKeys(); } public void fileDeleted(FileEvent fe) { if (fe.getFile() != f) { refreshKeys(); } } public void fileChanged(FileEvent fe) { refreshKeys(); } public void fileRenamed(FileRenameEvent fe) {} public void fileAttributeChanged(FileAttributeEvent fe) {} public int compare(Object o1, Object o2) { FileObject f1 = (FileObject)o1; FileObject f2 = (FileObject)o2; if (f1.isFolder()) { if (f2.isFolder()) { return f1.getNameExt().compareTo(f2.getNameExt()); } else { return -1; } } else { if (f2.isFolder()) { return 1; } else { long s1 = f1.getSize(); long s2 = f2.getSize(); if (s1 < s2) { return 1; } else if (s1 > s2) { return -1; } else { return f1.getNameExt().compareTo(f2.getNameExt()); } } } } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.