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.GridLayout;
047: import java.awt.Insets;
048: import java.awt.event.ActionEvent;
049: import javax.swing.AbstractAction;
050: import javax.swing.JLabel;
051: import javax.swing.JPanel;
052: import org.netbeans.modules.welcome.content.BundleSupport;
053: import org.netbeans.modules.welcome.content.ActionButton;
054: import org.netbeans.modules.welcome.content.Constants;
055: import org.netbeans.modules.welcome.content.Utils;
056: import org.netbeans.modules.welcome.content.WebLink;
057: import org.openide.cookies.InstanceCookie;
058: import org.openide.cookies.OpenCookie;
059: import org.openide.filesystems.FileObject;
060: import org.openide.filesystems.Repository;
061: import org.openide.loaders.DataFolder;
062: import org.openide.loaders.DataObject;
063:
064: /**
065: *
066: * @author S. Aubrecht
067: */
068: class LearnMore extends JPanel implements Constants {
069:
070: /** Creates a new instance of RecentProjects */
071: public LearnMore() {
072: super (new GridBagLayout());
073: setOpaque(false);
074: buildContent();
075: }
076:
077: private void buildContent() {
078: FileObject root = Repository.getDefault()
079: .getDefaultFileSystem().findResource(
080: "WelcomePage/LearnMoreLinks"); // NOI18N
081: DataFolder folder = DataFolder.findFolder(root);
082: DataObject[] children = folder.getChildren();
083: JPanel panel = new JPanel(new GridLayout(0, 2, 15, 5));
084: panel.setOpaque(false);
085: for (int i = 0; i < children.length; i++) {
086: addLink(panel, children[i]);
087: }
088:
089: add(panel, new GridBagConstraints(0, 0, 2, 1, 1.0, 0.0,
090: GridBagConstraints.NORTHWEST,
091: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0),
092: 0, 0));
093:
094: WebLink more = new WebLink("MoreTutorials", false); //NOI18N
095: add(more, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
096: GridBagConstraints.NORTHEAST, GridBagConstraints.NONE,
097: new Insets(20, 0, 0, 0), 0, 0));
098: add(new JLabel(), new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0,
099: GridBagConstraints.CENTER, GridBagConstraints.NONE,
100: new Insets(0, 0, 0, 0), 0, 0));
101: }
102:
103: private void addLink(JPanel panel, DataObject dob) {
104: OpenCookie oc = (OpenCookie) dob
105: .getCookie(InstanceCookie.class);
106: if (null != oc) {
107: LinkAction la = new LinkAction(dob);
108: ActionButton lb = new ActionButton(la, true, Utils
109: .getUrlString(dob));
110: lb.getAccessibleContext().setAccessibleName(lb.getText());
111: lb.getAccessibleContext().setAccessibleDescription(
112: BundleSupport.getAccessibilityDescription(
113: "LearnMore", lb.getText())); //NOI18N
114: JPanel inner = new JPanel(new GridBagLayout());
115: inner.setOpaque(false);
116: inner.add(lb, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
117: GridBagConstraints.WEST, GridBagConstraints.NONE,
118: new Insets(0, 0, 0, 0), 0, 0));
119: inner.add(new JLabel(), new GridBagConstraints(1, 0, 1, 1,
120: 1.0, 0.0, GridBagConstraints.WEST,
121: GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0,
122: 0));
123: panel.add(inner);
124: }
125: }
126:
127: private static class LinkAction extends AbstractAction {
128: private DataObject dob;
129:
130: public LinkAction(DataObject dob) {
131: super (dob.getNodeDelegate().getDisplayName());
132: this .dob = dob;
133: }
134:
135: public void actionPerformed(ActionEvent e) {
136: OpenCookie oc = dob.getCookie(OpenCookie.class);
137: if (null != oc)
138: oc.open();
139: }
140: }
141: }
|