1 19 20 package org.netbeans.modules.welcome.ui; 21 22 import java.awt.GridBagConstraints ; 23 import java.awt.GridBagLayout ; 24 import java.awt.Insets ; 25 import java.awt.event.ActionEvent ; 26 import java.lang.reflect.Method ; 27 import javax.swing.AbstractAction ; 28 import javax.swing.BorderFactory ; 29 import javax.swing.JComponent ; 30 import javax.swing.JLabel ; 31 import javax.swing.JPanel ; 32 import javax.swing.JScrollPane ; 33 import org.netbeans.modules.welcome.content.BundleSupport; 34 import org.netbeans.modules.welcome.content.ContentPanel; 35 import org.netbeans.modules.welcome.content.ActionButton; 36 import org.netbeans.modules.welcome.content.Utils; 37 import org.openide.cookies.InstanceCookie; 38 import org.openide.cookies.OpenCookie; 39 import org.openide.filesystems.FileObject; 40 import org.openide.filesystems.Repository; 41 import org.openide.loaders.DataFolder; 42 import org.openide.loaders.DataObject; 43 44 48 public class GetStarted extends ContentPanel { 49 50 private int row; 51 52 53 public GetStarted() { 54 super( BundleSupport.getLabel( "GettingStarted" ) ); 56 setContent( buildContent() ); 57 } 58 59 private JComponent buildContent() { 60 int row = 0; 61 JPanel panel = new JPanel ( new GridBagLayout () ); 62 panel.setOpaque( false ); 63 FileObject root = Repository.getDefault().getDefaultFileSystem().findResource( "WelcomePage/GettingStartedLinks" ); DataFolder folder = DataFolder.findFolder( root ); 65 DataObject[] children = folder.getChildren(); 66 for( int i=0; i<children.length; i++ ) { 67 if( children[i].getPrimaryFile().isFolder() ) { 68 String headerText = children[i].getNodeDelegate().getDisplayName(); 69 JLabel lblTitle = new JLabel ( headerText ); 70 lblTitle.setFont( HEADER_FONT ); 71 lblTitle.setForeground( Utils.getColor(SECTION_TEXT_COLOR) ); 72 lblTitle.setBackground( Utils.getColor(SECTION_BACKGROUND_COLOR) ); 73 lblTitle.setHorizontalAlignment( JLabel.LEFT ); 74 lblTitle.setOpaque( true ); 75 lblTitle.setBorder( HEADER_TEXT_BORDER ); 76 panel.add( lblTitle, new GridBagConstraints ( 0,row++,1,1,1.0,0.0, 77 GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, 78 new Insets (row==1 ? UNDER_HEADER_MARGIN : SECTION_MARGIN,0, 79 UNDER_SECTION_MARGIN,1), 0, 0 ) ); 80 81 DataFolder subFolder = DataFolder.findFolder( children[i].getPrimaryFile() ); 82 DataObject[] subFolderChildren = subFolder.getChildren(); 83 for( int j=0; j<subFolderChildren.length; j++ ) { 84 row = addLink( panel, row, subFolderChildren[j] ); 85 } 86 87 } else { 88 row = addLink( panel, row, children[i] ); 89 } 90 } 91 92 panel.add( new JLabel (), new GridBagConstraints (0, row++, 1, 1, 0.0, 1.0, 93 GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets (0,0,15,0), 0, 0 ) ); 94 95 JScrollPane scroll = new RelativeSizeScrollPane( panel, 0.70f, 50 ); 96 scroll.getViewport().setOpaque( false ); 97 scroll.setOpaque( false ); 98 scroll.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ); 99 scroll.setBorder( BorderFactory.createEmptyBorder(0,0,20,0) ); 100 return scroll; 101 } 102 103 private int addLink( JPanel panel, int row, DataObject dob ) { 104 OpenCookie oc = (OpenCookie)dob.getCookie( InstanceCookie.class ); 105 if( null != oc ) { 106 LinkAction la = new LinkAction( dob ); 107 ActionButton lb = new ActionButton( la, true, getUrlString( dob ) ); 108 lb.getAccessibleContext().setAccessibleName( lb.getText() ); 109 lb.getAccessibleContext().setAccessibleDescription( 110 BundleSupport.getAccessibilityDescription( "GettingStarted", lb.getText() ) ); panel.add( lb, new GridBagConstraints ( 0,row++,1,1,1.0,0.0, 112 GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, 113 new Insets (row==1? UNDER_HEADER_MARGIN : ROW_MARGIN,TEXT_INSETS_LEFT+3,0,2*TEXT_INSETS_RIGHT), 0, 0 ) ); 114 } 115 return row; 116 } 117 118 122 private String getUrlString(DataObject dob) { 123 try { 124 Method m = dob.getClass().getDeclaredMethod( "getURLString", new Class [] {} ); 125 m.setAccessible( true ); 126 Object res = m.invoke( dob ); 127 if( null != res ) { 128 return res.toString(); 129 } 130 } catch (Exception ex) { 131 } 133 return null; 134 } 135 136 private static class LinkAction extends AbstractAction { 137 private DataObject dob; 138 public LinkAction( DataObject dob ) { 139 super( dob.getNodeDelegate().getDisplayName() ); 140 this.dob = dob; 141 } 142 143 public void actionPerformed(ActionEvent e) { 144 OpenCookie oc = (OpenCookie)dob.getCookie( OpenCookie.class ); 145 if( null != oc ) 146 oc.open(); 147 } 148 } 149 } 150 | Popular Tags |