1f3bacfc465851c70332653d1b9154dc95147334
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / util / versioning / VersioningHelper.java
1 package com.quantum.util.versioning;
2
3 import java.lang.reflect.InvocationTargetException;
4 import java.lang.reflect.Method;
5
6 import org.eclipse.swt.SWT;
7 import org.eclipse.swt.graphics.FontData;
8 import org.eclipse.swt.widgets.FontDialog;
9
10 /**
11  * This class provides backward compatibility between versions of Eclipse for
12  * known differences.
13  * 
14  * @author BC
15  */
16 public class VersioningHelper {
17     
18     public static final int ECLIPSE_VERSION_2_1_1 = 2135;
19
20     /**
21      * Set the font in a FontDialog.  In Eclipse 2.1.1, the 
22      * <code>setFontData()</code> method was deprecated and an alternative
23      * method, <code>setFontList()</code> was suggested in its place.  
24      * 
25      * @param fontDialog
26      * @param fontData
27      */    
28     public static void setFont(FontDialog fontDialog, FontData[] fontData) {
29         try {
30             if (SWT.getVersion() >= ECLIPSE_VERSION_2_1_1) {
31                 Method method = fontDialog.getClass().getMethod(
32                     "setFontList", new Class[] { fontData.getClass()});
33                 method.invoke(fontDialog, new Object[] {fontData});
34             } else if (fontData.length > 0) {
35                 Method method = fontDialog.getClass().getMethod(
36                     "setFontData", new Class[] { FontData.class });
37                 method.invoke(fontDialog, new Object[] { fontData[0] });
38             }
39         } catch (NoSuchMethodException e) {
40             // should not happen
41         } catch (IllegalArgumentException e) {
42             // should not happen
43         } catch (IllegalAccessException e) {
44             // should not happen
45         } catch (InvocationTargetException e) {
46             // should not happen
47         }
48     }
49 }