Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 2015 Leibniz Institute of Plant Genetics and Crop Plant Research (IPK), Gatersleben, Germany.
   * All rights reserved. This program and the accompanying materials
   * are made available under the terms of the Creative Commons Attribution-NoDerivatives 4.0 International (CC BY-ND 4.0)
   * which accompanies this distribution, and is available at http://creativecommons.org/licenses/by-nd/4.0/
   *
   * Contributors:
   *      Leibniz Institute of Plant Genetics and Crop Plant Research (IPK), Gatersleben, Germany - RMI Client, FileChooser and WebDAV
   */
 package de.ipk_gatersleben.bit.bi.edal.rmi.client.util;
 
 
An implementation of EDALFileFilter that filters using a specified set of extensions. The extension for a file is the portion of the file name after the last ".". Files whose name does not contain a "." have no file name extension. File name extension comparisons are case insensitive.

The following example creates a EDALFileNameExtensionFilter that will show jpg files:

 EDALFileFilter filter = new EDALFileNameExtensionFilter("JPEG file", "jpg", "jpeg");
 EDALFileChooser fileChooser = ...;
 fileChooser.setFileFilter(filter);
 

 
 
 	// Description of this filter.
 	private final String description;
 	// Known extensions.
 	private final String[] extensions;
 	// Cached ext
 	private final String[] lowerCaseExtensions;

Creates a EDALFileNameExtensionFilter with the specified description and file name extensions. The returned EDALFileNameExtensionFilter will accept all directories and any file with a file name extension contained in extensions.

Parameters:
description textual description for the filter, may be null
extensions the accepted file name extensions
Throws:
java.lang.IllegalArgumentException if extensions is null, empty, contains null, or contains an empty string
See also:
accept(de.ipk_gatersleben.bit.bi.edal.rmi.client.ClientPrimaryDataFile)
 
 	public EdalFileNameExtensionFilter(String descriptionString... extensions) {
 		if (extensions == null || extensions.length == 0) {
 					"Extensions must be non-null and not empty");
 		}
 		this. = description;
 		this. = new String[extensions.length];
 		this. = new String[extensions.length];
 		for (int i = 0; i < extensions.lengthi++) {
 			if (extensions[i] == null || extensions[i].length() == 0) {
 						"Each extension must be non-null and not empty");
 			}
 			this.[i] = extensions[i];
 		}
 	}

Tests the specified file, returning true if the file is accepted, false otherwise. True is returned if the extension matches one of the file name extensions of this EDALFileFilter, or the file is a directory.

Parameters:
f the File to test
Returns:
true if the file is to be accepted, false otherwise
 
 	public boolean accept(ClientPrimaryDataFile f) {
 		if (f != null) {
 			String fileName;
 			try {
 				fileName = f.getName();
 				int i = fileName.lastIndexOf('.');
 				if (i > 0 && i < fileName.length() - 1) {
 					String desiredExtension = fileName.substring(i + 1)
 					for (String extension : ) {
 						if (desiredExtension.equals(extension)) {
							return true;
						}
					}
				}
catch (RemoteException e) {
			}
		}
		return false;
	}

The description of this filter. For example: "JPG and GIF Images."

Returns:
the description of this filter
	public String getDescription() {
		return ;
	}

Returns the set of file name extensions files are tested against.

Returns:
the set of file name extensions files are tested against
	public String[] getExtensions() {
		String[] result = new String[.];
		System.arraycopy(, 0, result, 0, .);
		return result;
	}

Returns a string representation of the EDALFileNameExtensionFilter. This method is intended to be used for debugging purposes, and the content and format of the returned string may vary between implementations.

Returns:
a string representation of this EDALFileNameExtensionFilter
	public String toString() {
		return super.toString() + "[description=" + getDescription()
" extensions=" + java.util.Arrays.asList(getExtensions())
"]";
	}
New to GrepCode? Check out our FAQ X