svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / view / legend / gui / LegendFileFilter.java @ 42223
History | View | Annotate | Download (2.44 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.app.project.documents.view.legend.gui; |
25 |
|
26 |
import org.gvsig.tools.ToolsLocator; |
27 |
import org.gvsig.tools.i18n.I18nManager; |
28 |
|
29 |
import org.apache.commons.lang3.StringUtils; |
30 |
|
31 |
import java.io.File; |
32 |
|
33 |
import javax.swing.filechooser.FileFilter; |
34 |
|
35 |
/**
|
36 |
* Utility class to deal with legend files (sld, gvsleg, etc)
|
37 |
*/
|
38 |
public class LegendFileFilter extends FileFilter { |
39 |
|
40 |
private String fileExt = ""; |
41 |
|
42 |
private String description = ""; |
43 |
|
44 |
private I18nManager i18n = ToolsLocator.getI18nManager();
|
45 |
|
46 |
public LegendFileFilter(String ext, String desc) { |
47 |
fileExt = ext.toLowerCase(); |
48 |
description = desc; |
49 |
} |
50 |
|
51 |
public LegendFileFilter(String ext) { |
52 |
|
53 |
StringBuilder sb = new StringBuilder(); |
54 |
fileExt = ext.toLowerCase(); |
55 |
|
56 |
description = i18n.getTranslation("format_for_legends");
|
57 |
description = StringUtils.replace(description, "%(ext)",
|
58 |
ext.toUpperCase()); |
59 |
|
60 |
sb.append(description); |
61 |
sb.append(" (*." + ext.toLowerCase() + ")"); |
62 |
description = sb.toString(); |
63 |
} |
64 |
|
65 |
public String getFileExtension() { |
66 |
return fileExt;
|
67 |
} |
68 |
|
69 |
public boolean accept(File pathname) { |
70 |
if (pathname.isDirectory()) {
|
71 |
return true; |
72 |
} |
73 |
else {
|
74 |
return pathname.getAbsolutePath().toLowerCase()
|
75 |
.endsWith("." + fileExt);
|
76 |
} |
77 |
} |
78 |
|
79 |
public String getDescription() { |
80 |
return description;
|
81 |
} |
82 |
|
83 |
} |