3
* $Date: 2007-01-04 18:26:00 +0100 (Thu, 04 Jan 2007) $
6
* Copyright (C) 2003-2007 The JChemPaint project
8
* Contact: jchempaint-devel@lists.sourceforge.net
10
* This program is free software; you can redistribute it and/or
11
* modify it under the terms of the GNU Lesser General Public License
12
* as published by the Free Software Foundation; either version 2.1
13
* of the License, or (at your option) any later version.
14
* All we ask is that proper credit is given for our work, which includes
15
* - but is not limited to - adding the above copyright notice to the beginning
16
* of your source code files, and to any copyright notice that you may distribute
17
* with programs based on this work.
19
* This program is distributed in the hope that it will be useful,
20
* but WITHOUT ANY WARRANTY; without even the implied warranty of
21
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
* GNU Lesser General Public License for more details.
24
* You should have received a copy of the GNU Lesser General Public License
25
* along with this program; if not, write to the Free Software
26
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
28
package org.openscience.cdk.applications.jchempaint.io;
31
import java.util.List;
32
import java.util.ArrayList;
34
import javax.swing.JFileChooser;
37
* An export filter for JCP file formats
39
* @cdk.module jchempaint
40
* @author Egon Willighagen
41
* @cdk.created 2003-04-01
43
public class JCPExportFileFilter extends javax.swing.filechooser.FileFilter implements IJCPFileFilter {
45
// only those extensions are given here that are *not* on JCPFileFilter
46
public final static String bmp = "bmp";
47
public final static String png = "png";
48
public final static String tiff = "tiff";
49
public final static String jpg = "jpg";
50
public final static String svg = "svg";
54
public JCPExportFileFilter(String type) {
56
types = new ArrayList();
61
* Adds the JCPFileFilter to the JFileChooser object.
63
public static void addChoosableFileFilters(JFileChooser chooser) {
64
chooser.addChoosableFileFilter(new JCPExportFileFilter(JCPExportFileFilter.bmp));
65
chooser.addChoosableFileFilter(new JCPExportFileFilter(JCPExportFileFilter.jpg));
66
chooser.addChoosableFileFilter(new JCPExportFileFilter(JCPExportFileFilter.png));
67
chooser.addChoosableFileFilter(new JCPExportFileFilter(JCPExportFileFilter.svg));
68
chooser.addChoosableFileFilter(new JCPExportFileFilter(JCPExportFileFilter.tiff));
72
* The description of this filter.
74
public String getDescription() {
75
String type = (String)types.get(0);
76
String result = "Unknown";
77
if (type.equals(png)) {
79
} else if (type.equals(bmp)) {
81
} else if (type.equals(tiff)) {
83
} else if (type.equals(jpg)) {
85
} else if (type.equals(svg)) {
86
result = "Scalable Vector Graphics";
91
// Accept all directories and all gif, jpg, or tiff files.
92
public boolean accept(File f) {
93
boolean accepted = false;
94
if (f.isDirectory()) {
98
String extension = getExtension(f);
99
if (extension != null) {
100
if (types.contains(extension)) {
108
* Get the extension of a file.
110
public static String getExtension(File f)
113
String s = f.getName();
114
int i = s.lastIndexOf('.');
116
if (i > 0 && i < s.length() - 1) {
117
ext = s.substring(i+1).toLowerCase();
122
public String getType() {
123
return (String)types.get(0);
126
public void setType(String type) {