1 19 20 package org.netbeans.modules.java.project; 21 22 import java.awt.Image ; 23 import org.netbeans.api.java.queries.AccessibilityQuery; 24 import org.netbeans.api.queries.VisibilityQuery; 25 import org.openide.filesystems.FileObject; 26 import org.openide.util.NbBundle; 27 import org.openide.util.Utilities; 28 29 31 36 public final class PackageDisplayUtils { 37 38 private PackageDisplayUtils() {} 39 40 41 private static final boolean TRUNCATE_PACKAGE_NAMES = 42 Boolean.getBoolean("org.netbeans.spi.java.project.support.ui.packageView.TRUNCATE_PACKAGE_NAMES"); 44 private static final Image PACKAGE = Utilities.loadImage("org/netbeans/spi/java/project/support/ui/package.gif"); private static final Image PACKAGE_EMPTY = Utilities.loadImage("org/netbeans/spi/java/project/support/ui/packageEmpty.gif"); private static final Image PACKAGE_PRIVATE = Utilities.loadImage("org/netbeans/spi/java/project/support/ui/packagePrivate.gif"); private static final Image PACKAGE_PUBLIC = Utilities.loadImage("org/netbeans/spi/java/project/support/ui/packagePublic.gif"); 49 55 public static String getDisplayLabel(String pkgname) { 56 return computePackageName(pkgname, TRUNCATE_PACKAGE_NAMES); 57 } 58 59 66 public static String getToolTip(FileObject pkg, String pkgname) { 67 String pkglabel = computePackageName(pkgname, false); 68 Boolean b = AccessibilityQuery.isPubliclyAccessible(pkg); 69 if (b != null) { 70 if (b.booleanValue()) { 71 return NbBundle.getMessage(PackageDisplayUtils.class, "LBL_public_package", pkglabel); 72 } else { 73 return NbBundle.getMessage(PackageDisplayUtils.class, "LBL_private_package", pkglabel); 74 } 75 } else { 76 return NbBundle.getMessage(PackageDisplayUtils.class, "LBL_package", pkglabel); 77 } 78 } 79 80 85 private static String computePackageName(String pkgname, boolean truncate) { 86 if (pkgname.length() == 0) { 87 return NbBundle.getMessage(PackageDisplayUtils.class, "LBL_DefaultPackage"); } else { 89 if (truncate) { 90 return pkgname.replaceFirst("^([^.])[^.]+\\.", "$1.").replaceAll("([^.]{3})[^.]+\\.", "$1."); } else { 93 return pkgname; 94 } 95 } 96 } 97 98 99 100 106 public static Image getIcon(FileObject pkg, String pkgname) { 107 return getIcon( pkg, pkgname, isEmpty(pkg) ); 108 } 109 110 113 public static Image getIcon(FileObject pkg, String pkgname, boolean empty ) { 114 if ( empty ) { 115 return PACKAGE_EMPTY; 116 } else { 117 Boolean b = pkg.isValid() ? AccessibilityQuery.isPubliclyAccessible(pkg) : null; 118 if (b != null) { 119 if (b.booleanValue()) { 120 return PACKAGE_PUBLIC; 121 } else { 122 return PACKAGE_PRIVATE; 123 } 124 } else { 125 return PACKAGE; 126 } 127 } 128 } 129 130 131 134 public static boolean isEmpty( FileObject fo ) { 135 return isEmpty (fo, true ); 136 } 137 138 142 public static boolean isEmpty( FileObject fo, boolean recurse ) { 143 FileObject[] kids = fo.getChildren(); 144 for( int i = 0; i < kids.length; i++ ) { 145 if ( !kids[i].isFolder() && VisibilityQuery.getDefault().isVisible( kids[i] ) ) { 147 return false; 148 } 149 else if (recurse && VisibilityQuery.getDefault().isVisible( kids[i] ) && !isEmpty(kids[i])) { 150 return false; 151 } 152 } 153 return true; 154 } 155 156 162 public static boolean isSignificant(FileObject pkg) throws IllegalArgumentException { 163 if (!pkg.isFolder()) { 164 throw new IllegalArgumentException ("Not a folder"); } 166 if (!VisibilityQuery.getDefault().isVisible(pkg)) { 168 return false; 169 } 170 FileObject[] kids = pkg.getChildren(); 171 boolean subpackages = false; 172 for (int i = 0; i < kids.length; i++) { 173 if (!VisibilityQuery.getDefault().isVisible(kids[i])) { 174 continue; 175 } 176 if (kids[i].isData()) { 177 return true; 178 } else { 179 subpackages = true; 180 } 181 } 182 return !subpackages; 183 } 184 185 } 186 | Popular Tags |