001: /*
002: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
003: * for visualizing and manipulating spatial features with geometry and attributes.
004: *
005: * Copyright (C) 2003 Vivid Solutions
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: *
021: * For more information, contact:
022: *
023: * Vivid Solutions
024: * Suite #1A
025: * 2328 Government Street
026: * Victoria BC V8T 5G5
027: * Canada
028: *
029: * (250)385-6040
030: * www.vividsolutions.com
031: */
032:
033: package com.vividsolutions.jump.workbench.ui;
034:
035: import java.io.File;
036:
037: import javax.swing.filechooser.FileFilter;
038:
039: /**
040: * Workbench filter that filters by fileType.
041: */
042:
043: public class WorkbenchFileFilter extends FileFilter {
044: private String description;
045:
046: //CVS issue:
047: //
048: //This class used to be called JcsFileFilter. I renamed it to JCSFileFilter
049: //and the Unix developers reported they were getting errors. So I deleted
050: //the file from the CVS repository and tried to re-add it, but I got
051: //CVS errors:
052: //
053: // cvs server: cannot add file `com/vividsolutions/jcs/workbench/ui/JCSFileFilter.java'
054: // when RCS file `/home/cvs/jcs/jcs/com/vividsolutions/jcs/workbench/ui/JCSFileFilter.java,v'
055: // already exists
056: // cvs [server aborted]: correct above errors first!
057: //
058: //This is a CVS bug mentioned on the Usenet newsgroups (deleting and re-adding
059: //a file). So I just renamed it to something totally different:
060: //WorkbenchFileFilter. [Jon Aquino]
061:
062: public WorkbenchFileFilter(String fileType) {
063: description = fileType;
064: }
065:
066: public boolean accept(File file) {
067: if (file.isDirectory()) {
068: return true;
069: }
070:
071: String extension = GUIUtil.getExtension(file);
072:
073: if (extension != null) {
074: //changed by david to be more readable and maintainable
075: if (description.equals(GUIUtil.jmlDesc)) {
076: return extension.equals(GUIUtil.jml)
077: || extension.equals("zip")
078: || extension.equals("gz");
079: }
080:
081: if (description.equals(GUIUtil.xmlDesc)) {
082: return extension.equals(GUIUtil.xml)
083: || extension.equals("zip")
084: || extension.equals("gz");
085: }
086:
087: if (description.equals(GUIUtil.shpDesc)) {
088: return extension.equals(GUIUtil.shp)
089: || extension.equals("zip");
090: }
091:
092: if (description.equals(GUIUtil.shxDesc)) {
093: return extension.equals(GUIUtil.shx);
094: }
095:
096: if (description.equals(GUIUtil.dbfDesc)) {
097: return extension.equals(GUIUtil.dbf);
098: }
099:
100: if (description.equals(GUIUtil.gmlDesc)) {
101: return extension.equals(GUIUtil.gml)
102: || extension.equals(GUIUtil.fme)
103: || extension.equals("zip")
104: || extension.equals("gz");
105: }
106:
107: if (description.equals(GUIUtil.wktDesc)) {
108: return extension.equals(GUIUtil.wkt)
109: || extension.equals("zip")
110: || extension.equals("gz");
111: }
112:
113: if (description.equals(GUIUtil.fmeDesc)) {
114: return extension.equals(GUIUtil.xml)
115: || extension.equals(GUIUtil.fme)
116: || extension.equals("zip")
117: || extension.equals("gz");
118: }
119: }
120:
121: return false;
122: }
123:
124: public String getDescription() {
125: return description;
126: }
127: }
|