KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > multiview > ui > LinkButton


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.xml.multiview.ui;
21
22 import org.netbeans.modules.xml.multiview.cookies.LinkCookie;
23
24 import javax.swing.*;
25
26 /**
27  * A button that represents a link.
28  *
29  *@see {@org.netbeans.modules.xml.multiview.cookies.LinkCookie}.
30  *
31  * Created on November 19, 2004, 8:06 AM
32  * @author mkuchtiak
33  */

34 public class LinkButton extends JButton {
35
36     /** Creates a new instance of LinkButton */
37     public LinkButton(LinkCookie panel, Object JavaDoc ddBean, String JavaDoc ddProperty) {
38         super();
39         initLinkButton(this, panel, ddBean, ddProperty);
40     }
41
42     public static void initLinkButton(final AbstractButton button, LinkCookie panel, Object JavaDoc ddBean, String JavaDoc ddProperty) {
43         button.setForeground(SectionVisualTheme.hyperlinkColor);
44         button.setHorizontalAlignment(SwingConstants.LEFT);
45         button.setMargin(new java.awt.Insets JavaDoc(2, 2, 2, 2));
46         button.setOpaque(false);
47         button.setBorderPainted(false);
48         button.setFocusPainted(false);
49         button.setContentAreaFilled(false);
50         String JavaDoc text = "<html><b><u>" + button.getText() + "</u></b></html>";
51         button.setAction(new LinkAction(panel, ddBean, ddProperty));
52         button.setText(text);
53
54         button.addMouseListener(new java.awt.event.MouseAdapter JavaDoc() {
55             public void mouseEntered(java.awt.event.MouseEvent JavaDoc e) {
56                 button.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.HAND_CURSOR));
57                 button.setForeground(SectionVisualTheme.hyperlinkColorFocused);
58             }
59             public void mouseExited(java.awt.event.MouseEvent JavaDoc e) {
60                 button.setCursor(java.awt.Cursor.getDefaultCursor());
61                 button.setForeground(SectionVisualTheme.hyperlinkColor);
62             }
63         });
64     }
65
66     public void setText(String JavaDoc text) {
67         super.setText("<html><b><u>"+text+"</u></b></html>");
68     }
69
70     public static class LinkAction extends AbstractAction {
71         LinkCookie panel;
72         Object JavaDoc ddBean;
73         String JavaDoc ddProperty;
74
75         public LinkAction(LinkCookie panel, Object JavaDoc ddBean, String JavaDoc ddProperty) {
76             this.panel=panel;
77             this.ddBean=ddBean;
78             this.ddProperty=ddProperty;
79         }
80
81         public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
82             panel.linkButtonPressed(ddBean, ddProperty);
83         }
84     }
85 }
86
Popular Tags