1 19 20 package org.netbeans.modules.welcome.content; 21 22 import java.awt.Color ; 23 import java.awt.Font ; 24 import java.awt.Graphics ; 25 import java.awt.Graphics2D ; 26 import java.awt.RenderingHints ; 27 import java.awt.Toolkit ; 28 import java.lang.reflect.Method ; 29 import java.net.URL ; 30 import java.util.Map ; 31 import java.util.ResourceBundle ; 32 import javax.swing.Action ; 33 import javax.swing.UIManager ; 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 47 public class Utils { 48 49 50 private Utils() { 51 } 52 53 public static Graphics2D prepareGraphics(Graphics g) { 54 Graphics2D g2 = (Graphics2D ) g; 55 Map rhints = (Map )(Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints")); if( rhints == null && Boolean.getBoolean("swing.aatext") ) { 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 href) { 65 try { 66 HtmlBrowser.URLDisplayer displayer = HtmlBrowser.URLDisplayer.getDefault(); 67 if (displayer != null) { 68 displayer.showURL(new URL (href)); 69 } 70 } catch (Exception e) {} 71 } 72 73 static int getDefaultFontSize() { 74 Integer customFontSize = (Integer )UIManager.get("customFontSize"); if (customFontSize != null) { 76 return customFontSize.intValue(); 77 } else { 78 Font systemDefaultFont = UIManager.getFont("TextField.font"); return (systemDefaultFont != null) 80 ? systemDefaultFont.getSize() 81 : 12; 82 } 83 } 84 85 static String getFontName() { 86 return null; } 89 90 public static Action findAction( String 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 instance = ic.instanceCreate(); 100 if (instance instanceof Action ) { 101 Action a = (Action ) instance; 102 return a; 103 } 104 } 105 } catch (Exception e) { 106 ErrorManager.getDefault().notify(ErrorManager.WARNING, e); 107 return null; 108 } 109 } 110 return null; 111 } 112 113 public static Action createSampleProjectAction() { 114 ClassLoader loader = (ClassLoader )Lookup.getDefault().lookup( ClassLoader .class ); 115 if( null == loader ) 116 loader = ClassLoader.getSystemClassLoader(); 117 try { 118 Class clazz = Class.forName( "org.netbeans.modules.project.ui.actions.NewProject", true, loader ); Method getDefault = clazz.getMethod( "newSample"); Object newSample = getDefault.invoke( null ); 121 if( newSample instanceof Action ) 122 return (Action )newSample; 123 } catch( Exception e ) { 124 ErrorManager.getDefault().notify( ErrorManager.INFORMATIONAL, e ); 125 } 126 return null; 127 } 128 129 public static Color getColor( String resId ) { 130 ResourceBundle bundle = NbBundle.getBundle("org.netbeans.modules.welcome.resources.Bundle"); try { 132 Integer rgb = Integer.decode(bundle.getString(resId)); 133 return new Color (rgb.intValue()); 134 } catch( NumberFormatException nfE ) { 135 ErrorManager.getDefault().notify( ErrorManager.INFORMATIONAL, nfE ); 136 return Color.BLACK; 137 } 138 } 139 } 140 | Popular Tags |