001/* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt 010 * or http://forgerock.org/license/CDDLv1.0.html. 011 * See the License for the specific language governing permissions 012 * and limitations under the License. 013 * 014 * When distributing Covered Code, include this CDDL HEADER in each 015 * file and include the License file at legal-notices/CDDLv1_0.txt. 016 * If applicable, add the following below this CDDL HEADER, with the 017 * fields enclosed by brackets "[]" replaced with your own identifying 018 * information: 019 * Portions Copyright [yyyy] [name of copyright owner] 020 * 021 * CDDL HEADER END 022 * 023 * 024 * Copyright 2006-2008 Sun Microsystems, Inc. 025 * Portions Copyright 2014-2015 ForgeRock AS 026 */ 027package org.opends.quicksetup.util; 028 029import java.io.File; 030 031import javax.swing.filechooser.FileFilter; 032import static com.forgerock.opendj.util.OperatingSystem.isWindows; 033 034/** 035 * This is a class used to be able to filter on certain type of files 036 * in the File Browser dialog. 037 */ 038public class ExtensionFileFilter extends FileFilter 039{ 040 private String extension; 041 042 private String description; 043 044 /** 045 * The ExtensionFiter constructor. 046 * @param extension the extension of the file we want to filter on. 047 * @param description the description for the extension. 048 */ 049 public ExtensionFileFilter(String extension, String description) 050 { 051 this.extension = extension; 052 this.description = description; 053 } 054 055 /** {@inheritDoc} */ 056 public boolean accept(File f) 057 { 058 boolean accept = false; 059 if (f != null) 060 { 061 if (f.isDirectory()) 062 { 063 accept = true; 064 } else if (isWindows()) 065 { 066 accept = 067 f.getName().toLowerCase().endsWith("." + extension.toLowerCase()); 068 } else 069 { 070 accept = f.getName().endsWith("." + extension); 071 } 072 } 073 return accept; 074 } 075 076 /** {@inheritDoc} */ 077 public String getDescription() 078 { 079 return description; 080 } 081}