KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > editor > ext > html > HTMLScrollJavaDocPane


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.editor.ext.html;
21
22 import javax.swing.JToolBar JavaDoc;
23 import java.awt.GridBagLayout JavaDoc;
24 import java.awt.GridBagConstraints JavaDoc;
25 import java.awt.Insets JavaDoc;
26 import java.awt.Rectangle JavaDoc;
27 import org.netbeans.editor.ext.ScrollJavaDocPane;
28 import java.awt.event.MouseAdapter JavaDoc;
29 import javax.swing.JButton JavaDoc;
30 import java.awt.event.MouseEvent JavaDoc;
31 import javax.swing.ImageIcon JavaDoc;
32 import org.netbeans.editor.ext.CompletionJavaDoc;
33 import org.netbeans.editor.ext.ExtEditorUI;
34 import org.openide.util.NbBundle;
35
36 /**
37  *
38  * @author Petr Pisl
39  */

40
41 public class HTMLScrollJavaDocPane extends ScrollJavaDocPane {
42     
43     
44     private JToolBar JavaDoc toolbar;
45     private ImageIcon JavaDoc iBack, iForward, iShowWeb;
46     private JButton JavaDoc bBack, bForward, bShowWeb;
47     private static final String JavaDoc BACK = "org/netbeans/modules/html/editor/resources/back.gif"; //NOI18N
48
private static final String JavaDoc FORWARD = "org/netbeans/modules/html/editor/resources/forward.gif"; //NOI18N
49
private static final String JavaDoc SHOW_WEB = "org/netbeans/modules/html/editor/resources/htmlView.gif"; //NOI18N
50
private CompletionJavaDoc cjd;
51     
52     /** Creates a new instance of NbScrollCompletionPane */
53     public HTMLScrollJavaDocPane(ExtEditorUI extEditorUI) {
54         super(extEditorUI);
55         cjd = extEditorUI.getCompletionJavaDoc();
56     }
57
58     
59     protected ImageIcon JavaDoc resolveIcon(String JavaDoc res){
60         return new ImageIcon JavaDoc(org.openide.util.Utilities.loadImage (res));
61     }
62     
63     
64     protected void installTitleComponent() {
65         toolbar = new JToolBar JavaDoc();
66         toolbar.setFloatable(false);
67         
68         toolbar.setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(1, 2, 1, 2)));
69         toolbar.setLayout(new GridBagLayout JavaDoc());
70         GridBagConstraints JavaDoc gdc = new GridBagConstraints JavaDoc();
71         gdc.gridx = 0;
72         gdc.gridy = 0;
73         gdc.anchor = GridBagConstraints.WEST;
74         
75         iBack = resolveIcon(BACK);
76         if (iBack !=null){
77             
78             bBack = new BrowserButton(iBack);
79             bBack.addMouseListener(new MouseEventListener(bBack));
80             bBack.setEnabled(false);
81             bBack.setContentAreaFilled(false);
82             bBack.setMargin(new Insets JavaDoc(0, 0, 0, 0));
83             bBack.setToolTipText(NbBundle.getBundle(this.getClass()).getString("HINT_javadoc_browser_back_button")); //NOI18N
84
toolbar.add(bBack, gdc);
85         }
86         
87         gdc.gridx = 1;
88         gdc.gridy = 0;
89         gdc.anchor = GridBagConstraints.WEST;
90         
91         iForward = resolveIcon(FORWARD);
92         if (iForward !=null){
93             bForward = new BrowserButton(iForward);
94             bForward.addMouseListener(new MouseEventListener(bForward));
95             bForward.setEnabled(false);
96             bForward.setContentAreaFilled(false);
97             bForward.setToolTipText(NbBundle.getBundle(this.getClass()).getString("HINT_javadoc_browser_forward_button")); //NOI18N
98
bForward.setMargin(new Insets JavaDoc(0, 0, 0, 0));
99             toolbar.add(bForward, gdc);
100         }
101         
102         gdc.gridx = 2;
103         gdc.gridy = 0;
104         gdc.weightx = 1.0;
105         gdc.anchor = GridBagConstraints.WEST;
106         
107         iShowWeb = resolveIcon(SHOW_WEB);
108         if (iShowWeb !=null){
109             
110             bShowWeb = new BrowserButton(iShowWeb);
111             bShowWeb.setToolTipText(NbBundle.getBundle(this.getClass()).getString("HINT_javadoc_browser_show_web_button")); //NOI18N
112
bShowWeb.addMouseListener(new MouseEventListener(bShowWeb));
113             bShowWeb.setContentAreaFilled(false);
114             bShowWeb.setMargin(new Insets JavaDoc(0, 0, 0, 0));
115             toolbar.add(bShowWeb, gdc);
116         }
117         
118         add(toolbar);
119     }
120     
121     public void setBounds(Rectangle JavaDoc r){
122         super.setBounds(r);
123         scrollPane.setBounds(r.x, 25, r.width, r.height - 25);
124         toolbar.setBounds(r.x+1, 1, r.width-2, 24);
125     }
126
127     public void setForwardEnabled(boolean enable) {
128         bForward.setEnabled(enable);
129     }
130     
131     public void setBackEnabled(boolean enable) {
132         bBack.setEnabled(enable);
133     }
134
135     public void setShowWebEnabled(boolean enable) {
136         bShowWeb.setEnabled(enable);
137     }
138     
139     class MouseEventListener extends MouseAdapter JavaDoc {
140         JButton JavaDoc button;
141         MouseEventListener(JButton JavaDoc button) {
142             this.button = button;
143         }
144         
145         public void mouseEntered(MouseEvent JavaDoc ev) {
146             if (button.isEnabled()){
147                 button.setContentAreaFilled(true);
148                 button.setBorderPainted(true);
149             }
150         }
151         public void mouseExited(MouseEvent JavaDoc ev) {
152             button.setContentAreaFilled(false);
153             button.setBorderPainted(false);
154         }
155         
156         public void mouseClicked(MouseEvent JavaDoc evt) {
157             if (button.equals(bBack)){
158                 cjd.backHistory();
159             }else if(button.equals(bForward)){
160                 cjd.forwardHistory();
161             }else if (button.equals(bShowWeb)){
162                 cjd.openInExternalBrowser();
163             }
164         }
165     }
166     
167 }
168
Popular Tags