/** * Returns the default extension. The default extension is the first entry in the array returned by the * <code>getExtensions</code> method. * * @return the default extension or <code>null</code> if no extensions have bees specified. * @see #getExtensions */ public String getDefaultExtension() { return hasExtensions() ? getExtensions()[0] : null; }
/** * Tests whether or not the given file is accepted by this filter. The default implementation returns * <code>true</code> if the given file is a directory or the path string ends with one of the registered extensions. * if no extension are defined, the method always returns <code>true</code> * * @param file the file to be or not be accepted. * @return <code>true</code> if given file is accepted by this filter */ @Override public boolean accept(File file) { if (!hasExtensions()) { return true; } // directories are accepted right away if (file.isDirectory()) { return true; } // otherwise name must end with one of the extensions return checkExtension(file); }
/** * Returns the description of this filter. For example: <code>"JPEG Images (*.jpg,*.jpeg)"</code>. If the extension * list is missing in the description text, it is automatically appended. * * @param description The description, must not be null. * @see #getDescription */ public void setDescription(String description) { if (hasExtensions() && !description.endsWith(")")) { StringBuilder sb = new StringBuilder(description); sb.append(" ("); for (int i = 0; i < extensions.length; i++) { if (i > 0) { sb.append(","); } sb.append("*"); if (extensions[i] != null) { sb.append(extensions[i]); } } sb.append(")"); this.description = sb.toString(); } else { this.description = description; } }
public void testDefaultConstructor() { final BeamFileFilter f = new BeamFileFilter(); assertNull(f.getFormatName()); assertNull(f.getDescription()); assertNull(f.getDefaultExtension()); assertNull(f.getExtensions()); assertFalse(f.hasExtensions()); }
public void testSingleExtConstructor() { final BeamFileFilter f = new BeamFileFilter("RALLA", ".ral", "RALLA Files"); assertEquals("RALLA", f.getFormatName()); assertEquals("RALLA Files (*.ral)", f.getDescription()); assertTrue(f.hasExtensions()); assertEquals(".ral", f.getDefaultExtension()); assertEquals(1, f.getExtensions().length); assertEquals(".ral", f.getExtensions()[0]); }
public void testMultipleExtConstructor() { final BeamFileFilter f = new BeamFileFilter("Holla", new String[]{".hol", ".ho", ".holla"}, "Holla Files"); assertEquals("Holla", f.getFormatName()); assertEquals("Holla Files (*.hol,*.ho,*.holla)", f.getDescription()); assertTrue(f.hasExtensions()); assertEquals(".hol", f.getDefaultExtension()); assertEquals(3, f.getExtensions().length); assertEquals(".hol", f.getExtensions()[0]); assertEquals(".ho", f.getExtensions()[1]); assertEquals(".holla", f.getExtensions()[2]); }
public void testSetters() { final BeamFileFilter f = new BeamFileFilter(); f.setFormatName("Zappo"); f.setDescription("Zappo File Format"); f.setExtensions(new String[]{".zap", ".ZAPPO"}); assertEquals("Zappo", f.getFormatName()); assertEquals("Zappo File Format", f.getDescription()); assertTrue(f.hasExtensions()); assertEquals(".zap", f.getDefaultExtension()); assertEquals(2, f.getExtensions().length); assertEquals(".zap", f.getExtensions()[0]); assertEquals(".ZAPPO", f.getExtensions()[1]); }