001: /*
002: * Copyright (c) 2004-2006, Jean-François Brazeau. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * 1. Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * 2. Redistributions in binary form must reproduce the above copyright
011: * notice, this list of conditions and the following disclaimer in the
012: * documentation and/or other materials provided with the distribution.
013: *
014: * 3. The name of the author may not be used to endorse or promote products
015: * derived from this software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
018: * IMPLIEDWARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
019: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
020: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
021: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
022: * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
023: * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
024: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
025: * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
026: * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: */
028: package jfb.tools.activitymgr.ui;
029:
030: import java.io.IOException;
031: import java.io.InputStream;
032: import java.io.InputStreamReader;
033: import java.io.LineNumberReader;
034:
035: import jfb.tools.activitymgr.ui.images.ImagesDatas;
036: import jfb.tools.activitymgr.ui.util.SafeRunner;
037:
038: import org.apache.log4j.Logger;
039: import org.eclipse.jface.dialogs.MessageDialog;
040: import org.eclipse.swt.SWT;
041: import org.eclipse.swt.dnd.Clipboard;
042: import org.eclipse.swt.dnd.TextTransfer;
043: import org.eclipse.swt.dnd.Transfer;
044: import org.eclipse.swt.events.SelectionEvent;
045: import org.eclipse.swt.events.SelectionListener;
046: import org.eclipse.swt.graphics.Image;
047: import org.eclipse.swt.layout.GridData;
048: import org.eclipse.swt.layout.GridLayout;
049: import org.eclipse.swt.widgets.Composite;
050: import org.eclipse.swt.widgets.Label;
051: import org.eclipse.swt.widgets.Link;
052: import org.eclipse.swt.widgets.List;
053: import org.eclipse.swt.widgets.TabItem;
054:
055: /**
056: * IHM contenant des informations générales sur le projet.
057: */
058: public class AboutUI implements SelectionListener {
059:
060: /** Logger */
061: private static Logger log = Logger.getLogger(AboutUI.class);
062:
063: /** Composant parent */
064: private Composite parent;
065:
066: /**
067: * Constructeur permettant de placer l'IHM dans un onglet.
068: * @param tabItem item parent.
069: */
070: public AboutUI(TabItem tabItem) {
071: this (tabItem.getParent());
072: tabItem.setControl(parent);
073: }
074:
075: /**
076: * Constructeur par défaut.
077: * @param parentComposite composant parent.
078: */
079: public AboutUI(Composite parentComposite) {
080: GridData data = null;
081: // Création du composite parent
082: parent = new Composite(parentComposite, SWT.NONE);
083: parent.setLayout(new GridLayout(1, false));
084:
085: // Création du composite centré
086: Composite centeredPanel = new Composite(parent, SWT.NONE);
087: centeredPanel.setLayoutData(new GridData(SWT.CENTER, SWT.FILL,
088: true, true));
089: centeredPanel.setLayout(new GridLayout(1, false));
090: log.debug("About UI initialized");
091:
092: // Logo
093: Label logo = new Label(centeredPanel, SWT.NONE);
094: logo.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false,
095: false));
096: logo.setImage(new Image(parentComposite.getDisplay(),
097: ImagesDatas.APPLICATION_LOGO));
098:
099: // Contact
100: Link contactText = new Link(centeredPanel, SWT.NONE);
101: contactText
102: .setText("To report a bug, request a new feature, ask a question or anything else,\n"
103: + "please write to <a>jfbraz@yahoo.fr</a>.");
104: contactText.addSelectionListener(this );
105:
106: // Documentation
107: Link documentationText = new Link(centeredPanel, SWT.NONE);
108: documentationText
109: .setText("For more information about Activity Manager, please refer to the documentation\n"
110: + "at : <a>http://www.jfbrazeau.fr</a>");
111: documentationText.addSelectionListener(this );
112:
113: // Apache license
114: Link apacheText = new Link(centeredPanel, SWT.NONE);
115: apacheText
116: .setText("This product includes software developed by The Apache Software Foundation\n"
117: + "(<a>http://www.apache.org/</a>).");
118: apacheText.addSelectionListener(this );
119:
120: // Third parties licenses
121: Link thirdPartiesText = new Link(centeredPanel, SWT.NONE);
122: thirdPartiesText
123: .setText("This product also includes software developped by \n"
124: + " - The Eclipse foundation (<a>http://www.eclipse.org</a>)\n"
125: + " - MySQL organization (<a>http://www.mysql.com</a>)\n"
126: + " - The HSQLDB Development Group (<a>http://www.hsqldb.org</a>)");
127: thirdPartiesText.addSelectionListener(this );
128:
129: // Ajout de la license
130: Label label = new Label(centeredPanel, SWT.NONE);
131: label
132: .setText("Activity Manager is distributed under a BSD License :");
133: List list = new List(centeredPanel, SWT.BORDER | SWT.H_SCROLL
134: | SWT.V_SCROLL | SWT.MULTI);
135: data = new GridData(SWT.NONE, SWT.FILL, false, true);
136: list.setLayoutData(data);
137:
138: // Ajout de la license
139: try {
140: InputStream in = AboutUI.class
141: .getResourceAsStream("LICENSE.txt");
142: LineNumberReader lin = new LineNumberReader(
143: new InputStreamReader(in));
144: String line = null;
145: while ((line = lin.readLine()) != null) {
146: list.add(line);
147: }
148: } catch (IOException e) {
149: log.error(
150: "Unexpected I/O error while printing stack trace.",
151: e);
152: list
153: .add("Unexpected I/O error while printing stack trace.");
154: list.add("See logs for more details.");
155: }
156: }
157:
158: /* (non-Javadoc)
159: * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
160: */
161: public void widgetSelected(SelectionEvent e) {
162: String osName = System.getProperty("os.name");
163: String link = e.text;
164: if (!link.startsWith("http://"))
165: link = "mailto:" + link;
166: final String url = link;
167: boolean windows = osName != null
168: && osName.toLowerCase().indexOf("windows") >= 0;
169: boolean copyURLToClipboard = true;
170: // Sous windows lancement du brower ou du client de mail
171: if (windows) {
172: SafeRunner runner = new SafeRunner() {
173: protected Object runUnsafe() throws Exception {
174: Process proc = Runtime.getRuntime().exec(
175: "rundll32 url.dll,FileProtocolHandler "
176: + url);
177: return proc;
178: }
179: };
180: // Si le lancement échoue, on effectuera le copier/coller
181: if (runner.run(parent.getShell()) != null)
182: copyURLToClipboard = false;
183: }
184: // Sur les autres plateformes que linux, dépot dans le clipboard
185: if (copyURLToClipboard) {
186: Clipboard clipBoard = new Clipboard(parent.getDisplay());
187: clipBoard.setContents(new Object[] { e.text },
188: new Transfer[] { TextTransfer.getInstance() });
189: clipBoard.dispose();
190: MessageDialog
191: .openInformation(
192: parent.getShell(),
193: "Information",
194: "Couldn't open default mail/browser desktop application.\n"
195: + "'"
196: + e.text
197: + "' has been copied to your clipboard.\n"
198: + "You may paste it in your mail/browser to proceed.");
199: }
200: }
201:
202: /* (non-Javadoc)
203: * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
204: */
205: public void widgetDefaultSelected(SelectionEvent e) {
206: widgetSelected(e);
207: }
208:
209: }
|