View Javadoc

1   /*
2    *  Copyright 2006 the 3Ddesktop-Configurator Team, all rights reserved.
3    *  
4    *  This file is part of 3Ddesktop-Configurator.
5    *  3Ddesktop-Configurator is free software; you can redistribute it and/or modify
6    *  it under the terms of the GNU General Public License as published by
7    *  the Free Software Foundation; either version 2 of the License.
8    *  3ddesktop-configurator is distributed in the hope that it will be useful,
9    *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11   *  GNU General Public License for more details.
12   *  You should have received a copy of the GNU General Public License
13   *  along with 3Ddesktop-Configurator; if not, write to the Free Software
14   *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
15   */
16  
17  package net.sf.glxdesktop.gui.about;
18  
19  import java.io.FileNotFoundException;
20  
21  import net.sf.glxdesktop.Utils;
22  import net.sf.glxdesktop.UtilsException;
23  
24  import org.apache.commons.logging.Log;
25  import org.apache.commons.logging.LogFactory;
26  import org.gnu.gdk.Pixbuf;
27  import org.gnu.glib.JGException;
28  import org.gnu.gtk.AboutDialog;
29  
30  /***
31   * @author fons
32   * 
33   */
34  public abstract class AboutCommonsDialog implements AboutProperties {
35  	
36  	private static final Log LOG = LogFactory.getLog(AboutCommonsDialog.class);
37  	
38  	public AboutCommonsDialog() {
39  		initGui();
40  	}
41  	
42  	private String appName = null, appIcon = null, appVersion = null,
43  		appDescription = null, appCopyright = null, appWebsite = null;
44  	
45  	public void initGui() {
46  		appName = getApplicationNameString();
47  		appVersion = getApplicationVersionString();
48  		appDescription = getApplicationDescritionString();
49  		appWebsite = getWebsiteString();
50  		appCopyright = getCopyrightString();
51  		
52  		try {
53  			// TODO add method that retrive a real path from a given file name to 
54  			// Utils Class (like fileToString method.)
55  			appIcon = ClassLoader.getSystemClassLoader().getResource(getApplicationImagePath()).getFile();
56  		} catch (Exception exception) {
57  			appIcon = null;
58  		}
59  		
60  		AboutDialog about = new AboutDialog();
61  		if (appName != null)
62  			about.setName(appName);
63  		if (appIcon != null) {
64  			try {
65  				Pixbuf appPixBuffer= new Pixbuf(appIcon);
66  				about.setLogo(appPixBuffer);
67  				about.setIcon(appPixBuffer);
68  			} catch (FileNotFoundException e) {
69  				if (!LOG.isDebugEnabled()) {
70  					LOG.warn(e.getMessage());
71  				} else {
72  					LOG.warn(e.getMessage(), e);
73  				}
74  			} catch (JGException e) {
75  				if (!LOG.isDebugEnabled()) {
76  					LOG.warn(e.getMessage());
77  				} else {
78  					LOG.warn(e.getMessage(), e);
79  				}
80  			}
81  		}
82  		try {
83  			if (getFileLicensePath() != null)
84  				about.setLicense(Utils.fileToString(getFileLicensePath()));
85  			
86  			if (getFileAuthorsPath() != null)
87  				about.setAuthors(Utils.fileToString(getFileAuthorsPath()).split("\n")); //$NON-NLS-1$;
88  			if (getFileDocumentorPath() != null)
89  				about.setDocumenters(Utils.fileToString(getFileDocumentorPath()).split(
90  				"\n")); //$NON-NLS-1$
91  			if (getFileTranslatorsPath() != null)
92  				about.setTranslatorCredits(Utils.fileToString(getFileTranslatorsPath()));
93  		} catch (UtilsException e1) {
94  			LOG.warn(e1);
95  		}
96  		
97  		if (appVersion != null)
98  			about.setVersion(appVersion);
99  		if (appDescription != null)
100 			about.setComments(appDescription);
101 		if (appCopyright != null)
102 			about.setCopyright(appCopyright);
103 		if (appWebsite != null)
104 			about.setWebsite(appWebsite);
105 		about.show();
106 	}
107 }