01: /*
02: * Copyright (C) 2005 Jeff Tassin
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: package com.jeta.swingbuilder.gui.images;
20:
21: import java.awt.Component;
22: import java.io.File;
23:
24: import javax.swing.JOptionPane;
25:
26: import com.jeta.forms.project.ProjectManager;
27: import com.jeta.forms.store.properties.IconProperty;
28: import com.jeta.open.i18n.I18N;
29: import com.jeta.open.registry.JETARegistry;
30: import com.jeta.swingbuilder.gui.filechooser.FileChooserConfig;
31: import com.jeta.swingbuilder.gui.filechooser.TSFileChooserFactory;
32: import com.jeta.swingbuilder.gui.filechooser.TSFileFilter;
33: import com.jeta.swingbuilder.gui.formmgr.FormManagerDesignUtils;
34:
35: public class ImageUtils {
36:
37: public static boolean chooseImageFile(Component parentComp,
38: IconProperty iprop) {
39: if (iprop == null)
40: return false;
41:
42: boolean bresult = false;
43: String relativepath = null;
44: if (iprop != null)
45: relativepath = iprop.getRelativePath();
46:
47: ProjectManager pmgr = (ProjectManager) JETARegistry
48: .lookup(ProjectManager.COMPONENT_ID);
49: String abspath = null;
50: if (pmgr.isValidResource(relativepath))
51: abspath = pmgr.getAbsolutePath(relativepath);
52: FileChooserConfig fcc = new FileChooserConfig(abspath, ".img",
53: new TSFileFilter("gif,png,jpg,jpeg",
54: "Image Files(*.gif,*.png,*.jpg)"));
55: fcc.setParentComponent(parentComp);
56:
57: File f = TSFileChooserFactory.showOpenDialog(fcc);
58: if (f != null) {
59: /** check if the path is contained in a valid package for the project */
60: if (pmgr.isValidAbsolutePath(f.getPath())) {
61: iprop
62: .setRelativePath(pmgr.getRelativePath(f
63: .getPath()));
64: iprop.setDescription(f.getName());
65: bresult = true;
66: } else {
67: String msg = I18N
68: .getLocalizedMessage("Selected image is not in source path.");
69: String title = I18N.getLocalizedMessage("Error");
70: JOptionPane.showMessageDialog(FormManagerDesignUtils
71: .getApplicationFrame(), msg, title,
72: JOptionPane.ERROR_MESSAGE);
73: }
74:
75: }
76: return bresult;
77: }
78:
79: }
|