class FolderItem extends FileItem implements MapModel { MapLayout algorithm = new PivotBySplitSize( ); Mappable[] items; boolean contentsVisible; boolean layoutValid; public FolderItem(FolderItem parent, File folder, int level, int order) { super(parent, folder, level, order); String[] contents = folder.list( ); if (contents != null) { contents = sort(contents); items = new Mappable[contents.length]; int count = 0; for (int i = 0; i < contents.length; i++) { if (contents[i].equals(".") || contents[i].equals("..")) { continue; } File fileItem = new File(folder, contents[i]); try { String absolutePath = fileItem.getAbsolutePath( ); String canonicalPath = fileItem.getCanonicalPath( ); if (!absolutePath.equals(canonicalPath)) { continue; } } catch (IOException e) { } FileItem newItem = null; if (fileItem.isDirectory( )) { newItem = new FolderItem(this, fileItem, level+1, count); } else { newItem = new FileItem(this, fileItem, level+1, count); } items[count++] = newItem; size += newItem.getSize( ); } if (count != items.length) { items = (Mappable[]) subset(items, 0, count); } } else { // If no items found in this folder, create a dummy array so that // items will not be null, which will ensure that items.length will // return 0 rather than causing a NullPointerException. items = new Mappable[0]; } } void checkLayout( ) { if (!layoutValid) { if (getItemCount( ) != 0) { algorithm.layout(this, bounds); } layoutValid = true; } } void draw( ) { checkLayout( ); calcBox( ); if (contentsVisible) { for (int i = 0; i < items.length; i++) { items[i].draw( ); } } else { super.draw( ); } } void drawTitle() { if(contentsVisible==false) { super.drawTitle(); } } Mappable[] getItems( ) { return items; } void showContents( ) { contentsVisible = true; } void hideContents( ) { // Prevent the user from closing the root level. if (parent != null) { contentsVisible = false; } } boolean mousePressed() { print(mouseX); print(mouseY); if(mouseInside()) { print("inside "); println(name); if(contentsVisible) { for (int i = 0; i < items.length; i++) { super.mousePressed(); } } else { if(mouseButton==LEFT) showContents(); if(mouseButton==RIGHT) { hideContents(); parent.hideContents(); return true; } } } return false; } int getItemCount( ) { return items.length; } }