001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.welcome.ui;
043:
044: import java.awt.GridBagConstraints;
045: import java.awt.GridBagLayout;
046: import java.awt.Image;
047: import java.awt.Insets;
048: import java.awt.event.ActionEvent;
049: import java.util.ResourceBundle;
050: import javax.swing.AbstractAction;
051: import javax.swing.ImageIcon;
052: import javax.swing.JLabel;
053: import javax.swing.JPanel;
054: import javax.swing.SwingConstants;
055: import org.netbeans.modules.welcome.content.BundleSupport;
056: import org.netbeans.modules.welcome.content.ActionButton;
057: import org.netbeans.modules.welcome.content.Constants;
058: import org.netbeans.modules.welcome.content.Utils;
059: import org.openide.cookies.InstanceCookie;
060: import org.openide.cookies.OpenCookie;
061: import org.openide.filesystems.FileObject;
062: import org.openide.filesystems.Repository;
063: import org.openide.loaders.DataFolder;
064: import org.openide.loaders.DataObject;
065: import org.openide.util.NbBundle;
066: import org.openide.util.Utilities;
067:
068: /**
069: *
070: * @author S. Aubrecht
071: */
072: class GetStarted extends JPanel implements Constants {
073:
074: private int row;
075:
076: /** Creates a new instance of RecentProjects */
077: public GetStarted() {
078: super (new GridBagLayout());
079: setOpaque(false);
080: buildContent();
081: }
082:
083: private void buildContent() {
084: FileObject root = Repository.getDefault()
085: .getDefaultFileSystem().findResource(
086: "WelcomePage/GettingStartedLinks"); // NOI18N
087: DataFolder folder = DataFolder.findFolder(root);
088: DataObject[] children = folder.getChildren();
089: for (int i = 0; i < children.length; i++) {
090: if (children[i].getPrimaryFile().isFolder()) {
091: String headerText = children[i].getNodeDelegate()
092: .getDisplayName();
093: JLabel lblTitle = new JLabel(headerText);
094: lblTitle.setFont(BUTTON_FONT);
095: lblTitle.setHorizontalAlignment(JLabel.LEFT);
096: lblTitle.setOpaque(true);
097: lblTitle.setBorder(HEADER_TEXT_BORDER);
098: add(lblTitle, new GridBagConstraints(0, row++, 1, 1,
099: 1.0, 0.0, GridBagConstraints.NORTHWEST,
100: GridBagConstraints.HORIZONTAL, new Insets(0, 0,
101: 0, 0), 0, 0));
102:
103: DataFolder subFolder = DataFolder
104: .findFolder(children[i].getPrimaryFile());
105: DataObject[] subFolderChildren = subFolder
106: .getChildren();
107: for (int j = 0; j < subFolderChildren.length; j++) {
108: row = addLink(row, subFolderChildren[j]);
109: }
110:
111: } else {
112: row = addLink(row, children[i]);
113: }
114: }
115:
116: add(new JLabel(), new GridBagConstraints(0, row++, 1, 1, 0.0,
117: 1.0, GridBagConstraints.NORTHWEST,
118: GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 0), 0,
119: 0));
120: }
121:
122: private int addLink(int row, DataObject dob) {
123: OpenCookie oc = (OpenCookie) dob
124: .getCookie(InstanceCookie.class);
125: if (null != oc) {
126: JPanel panel = new JPanel(new GridBagLayout());
127: panel.setOpaque(false);
128:
129: LinkAction la = new LinkAction(dob);
130: ActionButton lb = new ActionButton(la, false, Utils
131: .getUrlString(dob));
132: panel.add(lb, new GridBagConstraints(1, 0, 1, 3, 0.0, 0.0,
133: GridBagConstraints.WEST, GridBagConstraints.NONE,
134: new Insets(0, 0, 0, 0), 0, 0));
135: lb.setFont(GET_STARTED_FONT);
136:
137: panel.add(new JLabel(), new GridBagConstraints(2, 0, 1, 3,
138: 1.0, 0.0, GridBagConstraints.WEST,
139: GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0,
140: 0));
141:
142: String bundleName = (String) dob.getPrimaryFile()
143: .getAttribute("SystemFileSystem.localizingBundle");//NOI18N
144: if (null != bundleName) {
145: ResourceBundle bundle = NbBundle.getBundle(bundleName);
146: Object imgKey = dob.getPrimaryFile().getAttribute(
147: "imageKey"); //NOI18N
148: if (null != imgKey) {
149: String imgLocation = bundle.getString(imgKey
150: .toString());
151: Image img = Utilities.loadImage(imgLocation, true);
152: JLabel lbl = new JLabel(new ImageIcon(img));
153: lbl.setVerticalAlignment(SwingConstants.TOP);
154: panel.add(lbl, new GridBagConstraints(0, 0, 1, 3,
155: 0.0, 0.0, GridBagConstraints.WEST,
156: GridBagConstraints.BOTH, new Insets(0, 0,
157: 0, 18), 0, 0));
158: }
159: }
160:
161: lb.getAccessibleContext().setAccessibleName(lb.getText());
162: lb.getAccessibleContext().setAccessibleDescription(
163: BundleSupport.getAccessibilityDescription(
164: "GettingStarted", lb.getText())); //NOI18N
165: add(panel, new GridBagConstraints(0, row++, 1, 1, 1.0, 0.0,
166: GridBagConstraints.NORTHWEST,
167: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 7,
168: 0), 0, 0));
169: }
170: return row;
171: }
172:
173: private static class LinkAction extends AbstractAction {
174: private DataObject dob;
175:
176: public LinkAction(DataObject dob) {
177: super (dob.getNodeDelegate().getDisplayName());
178: this .dob = dob;
179: }
180:
181: public void actionPerformed(ActionEvent e) {
182: OpenCookie oc = dob.getCookie(OpenCookie.class);
183: if (null != oc)
184: oc.open();
185: }
186: }
187: }
|