KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > welcome > content > Utils


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.welcome.content;
21
22 import java.awt.Color JavaDoc;
23 import java.awt.Font JavaDoc;
24 import java.awt.Graphics JavaDoc;
25 import java.awt.Graphics2D JavaDoc;
26 import java.awt.RenderingHints JavaDoc;
27 import java.awt.Toolkit JavaDoc;
28 import java.lang.reflect.Method JavaDoc;
29 import java.net.URL JavaDoc;
30 import java.util.Map JavaDoc;
31 import java.util.ResourceBundle JavaDoc;
32 import javax.swing.Action JavaDoc;
33 import javax.swing.UIManager JavaDoc;
34 import org.openide.ErrorManager;
35 import org.openide.awt.HtmlBrowser;
36 import org.openide.cookies.InstanceCookie;
37 import org.openide.filesystems.FileObject;
38 import org.openide.filesystems.Repository;
39 import org.openide.loaders.DataObject;
40 import org.openide.util.Lookup;
41 import org.openide.util.NbBundle;
42
43 /**
44  *
45  * @author S. Aubrecht
46  */

47 public class Utils {
48     
49     /** Creates a new instance of Utils */
50     private Utils() {
51     }
52
53     public static Graphics2D JavaDoc prepareGraphics(Graphics JavaDoc g) {
54         Graphics2D JavaDoc g2 = (Graphics2D JavaDoc) g;
55         Map JavaDoc rhints = (Map JavaDoc)(Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints")); //NOI18N
56
if( rhints == null && Boolean.getBoolean("swing.aatext") ) { //NOI18N
57
g2.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
58         } else if( rhints != null ) {
59             g2.addRenderingHints( rhints );
60         }
61         return g2;
62     }
63
64     public static void showURL(String JavaDoc href) {
65         try {
66             HtmlBrowser.URLDisplayer displayer = HtmlBrowser.URLDisplayer.getDefault();
67             if (displayer != null) {
68                 displayer.showURL(new URL JavaDoc(href));
69             }
70         } catch (Exception JavaDoc e) {}
71     }
72
73     static int getDefaultFontSize() {
74         Integer JavaDoc customFontSize = (Integer JavaDoc)UIManager.get("customFontSize"); // NOI18N
75
if (customFontSize != null) {
76             return customFontSize.intValue();
77         } else {
78             Font JavaDoc systemDefaultFont = UIManager.getFont("TextField.font"); // NOI18N
79
return (systemDefaultFont != null)
80                 ? systemDefaultFont.getSize()
81                 : 12;
82         }
83     }
84
85     static String JavaDoc getFontName() {
86         //#75759 Verdana not supported on Japanese locale
87
return null;//Utilities.isWindows() ? "Verdana" : null; // NOI18N
88
}
89
90     public static Action JavaDoc findAction( String JavaDoc key ) {
91         FileObject fo = Repository.getDefault().getDefaultFileSystem().findResource(key);
92         
93         if (fo != null && fo.isValid()) {
94             try {
95                 DataObject dob = DataObject.find(fo);
96                 InstanceCookie ic = (InstanceCookie) dob.getCookie(InstanceCookie.class);
97                 
98                 if (ic != null) {
99                     Object JavaDoc instance = ic.instanceCreate();
100                     if (instance instanceof Action JavaDoc) {
101                         Action JavaDoc a = (Action JavaDoc) instance;
102                         return a;
103                     }
104                 }
105             } catch (Exception JavaDoc e) {
106                 ErrorManager.getDefault().notify(ErrorManager.WARNING, e);
107                 return null;
108             }
109         }
110         return null;
111     }
112
113     public static Action JavaDoc createSampleProjectAction() {
114         ClassLoader JavaDoc loader = (ClassLoader JavaDoc)Lookup.getDefault().lookup( ClassLoader JavaDoc.class );
115         if( null == loader )
116             loader = ClassLoader.getSystemClassLoader();
117         try {
118             Class JavaDoc clazz = Class.forName( "org.netbeans.modules.project.ui.actions.NewProject", true, loader ); // NOI18N
119
Method JavaDoc getDefault = clazz.getMethod( "newSample"); // NOI18N
120
Object JavaDoc newSample = getDefault.invoke( null );
121             if( newSample instanceof Action JavaDoc )
122                 return (Action JavaDoc)newSample;
123         } catch( Exception JavaDoc e ) {
124             ErrorManager.getDefault().notify( ErrorManager.INFORMATIONAL, e );
125         }
126         return null;
127     }
128     
129     public static Color JavaDoc getColor( String JavaDoc resId ) {
130         ResourceBundle JavaDoc bundle = NbBundle.getBundle("org.netbeans.modules.welcome.resources.Bundle"); // NOI18N
131
try {
132             Integer JavaDoc rgb = Integer.decode(bundle.getString(resId));
133             return new Color JavaDoc(rgb.intValue());
134         } catch( NumberFormatException JavaDoc nfE ) {
135             ErrorManager.getDefault().notify( ErrorManager.INFORMATIONAL, nfE );
136             return Color.BLACK;
137         }
138     }
139 }
140
Popular Tags