KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > editor > ext > ScrollJavaDocPane


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
21 package org.netbeans.editor.ext;
22
23 import java.awt.event.MouseAdapter JavaDoc;
24 import java.awt.event.MouseEvent JavaDoc;
25 import java.awt.Dimension JavaDoc;
26 import java.awt.Rectangle JavaDoc;
27
28 import javax.swing.JScrollPane JavaDoc;
29 import javax.swing.JComponent JavaDoc;
30 import javax.swing.JRootPane JavaDoc;
31 import javax.swing.text.JTextComponent JavaDoc;
32 import javax.swing.JLayeredPane JavaDoc;
33 import javax.swing.JList JavaDoc;
34 import javax.swing.SwingUtilities JavaDoc;
35 import javax.swing.JPanel JavaDoc;
36
37 import org.netbeans.editor.SettingsChangeListener;
38 import org.netbeans.editor.Utilities;
39 import org.netbeans.editor.SettingsUtil;
40 import org.netbeans.editor.ext.ExtSettingsNames;
41 import org.netbeans.editor.ext.ExtSettingsDefaults;
42 import org.netbeans.editor.SettingsChangeEvent;
43 import org.netbeans.editor.Settings;
44 import javax.swing.JButton JavaDoc;
45 import javax.swing.border.CompoundBorder JavaDoc;
46 import javax.swing.border.EtchedBorder JavaDoc;
47 import javax.swing.border.EmptyBorder JavaDoc;
48 import java.awt.BorderLayout JavaDoc;
49 import java.awt.Color JavaDoc;
50 import javax.swing.ImageIcon JavaDoc;
51 import java.net.URL JavaDoc;
52 import javax.swing.Icon JavaDoc;
53 import java.awt.FlowLayout JavaDoc;
54 import java.awt.GridBagConstraints JavaDoc;
55 import java.awt.Insets JavaDoc;
56 import java.awt.GridLayout JavaDoc;
57 import java.awt.ComponentOrientation JavaDoc;
58 import java.awt.GridBagLayout JavaDoc;
59 import javax.swing.BoxLayout JavaDoc;
60 import javax.swing.AbstractAction JavaDoc;
61 import java.awt.event.ActionEvent JavaDoc;
62 import java.awt.event.ActionListener JavaDoc;
63 import javax.swing.BorderFactory JavaDoc;
64 import javax.swing.event.HyperlinkListener JavaDoc;
65 import javax.swing.event.HyperlinkEvent JavaDoc;
66 import javax.swing.JEditorPane JavaDoc;
67 import javax.swing.UIManager JavaDoc;
68 import javax.swing.border.Border JavaDoc;
69 import javax.swing.border.LineBorder JavaDoc;
70 import org.openide.util.NbBundle;
71
72 /**
73  * JScrollPane implementation of JavaDocPane.
74  *
75  * @author Martin Roskanin
76  * @since 03/2002
77  */

78 public class ScrollJavaDocPane extends JPanel JavaDoc implements JavaDocPane, SettingsChangeListener{
79
80     protected ExtEditorUI extEditorUI;
81     private JComponent JavaDoc view;
82     private CompletionJavaDoc cjd;
83     protected JScrollPane JavaDoc scrollPane = new JScrollPane JavaDoc();
84     Border JavaDoc lineBorder;
85     
86     /** Creates a new instance of ScrollJavaDocPane */
87     public ScrollJavaDocPane(ExtEditorUI extEditorUI) {
88         
89 // new RuntimeException("ScrollJavaDocPane.<init>").printStackTrace();
90

91         setLayout(null);
92  
93         this.extEditorUI = extEditorUI;
94         
95         // Add the completionJavaDoc view
96
cjd = extEditorUI.getCompletionJavaDoc();
97         if (cjd!=null){
98             JavaDocView javaDocView = cjd.getJavaDocView();
99             if (javaDocView instanceof JComponent JavaDoc) {
100                 if (javaDocView instanceof JEditorPane JavaDoc){
101                     ((JEditorPane JavaDoc)javaDocView).addHyperlinkListener(createHyperlinkAction());
102                 }
103                 view = (JComponent JavaDoc)javaDocView;
104                 scrollPane.setViewportView(view);
105             }
106         
107             Settings.addSettingsChangeListener(this);
108             setMinimumSize(new Dimension JavaDoc(100,100)); //[PENDING] put it into the options
109
setMaximumSize(getMaxPopupSize());
110         }else{
111             setMinimumSize(new Dimension JavaDoc(0,0));
112             setMaximumSize(new Dimension JavaDoc(0,0));
113         }
114         super.setVisible(false);
115         add(scrollPane);
116         getAccessibleContext().setAccessibleDescription(
117                 NbBundle.getBundle(org.netbeans.editor.BaseKit.class).
118                 getString("ACSD_JAVADOC_javaDocPane")); //NOI18N
119

120         // !!! virtual method called from contructor!!
121
installTitleComponent();
122         setBorder(new LineBorder JavaDoc(javax.swing.UIManager.getColor("controlDkShadow"))); //NOI18N
123
}
124     
125     protected HyperlinkAction createHyperlinkAction(){
126         return new HyperlinkAction();
127     }
128     
129     public void setBounds(Rectangle JavaDoc r){
130         super.setBounds(r);
131         scrollPane.setBounds(r.x, 0, r.width+1, r.height );
132     }
133     
134     public void setVisible(boolean visible){
135         super.setVisible(visible);
136         if (cjd!=null && !visible){
137             cjd.clearHistory();
138         }
139     }
140     
141     protected ImageIcon JavaDoc resolveIcon(String JavaDoc res){
142         ClassLoader JavaDoc loader = this.getClass().getClassLoader();
143         URL JavaDoc resource = loader.getResource( res );
144         if( resource == null ) resource = ClassLoader.getSystemResource( res );
145         return ( resource != null ) ? new ImageIcon JavaDoc( resource ) : null;
146     }
147
148     protected void installTitleComponent() {
149     }
150     
151     private Dimension JavaDoc getMaxPopupSize(){
152         Class JavaDoc kitClass = Utilities.getKitClass(extEditorUI.getComponent());
153         if (kitClass != null) {
154             return (Dimension JavaDoc)SettingsUtil.getValue(kitClass,
155                       ExtSettingsNames.JAVADOC_PREFERRED_SIZE,
156                       ExtSettingsDefaults.defaultJavaDocAutoPopupDelay);
157             
158         }
159         return ExtSettingsDefaults.defaultJavaDocPreferredSize;
160     }
161     
162     public void settingsChange(SettingsChangeEvent evt) {
163         if (ExtSettingsNames.JAVADOC_PREFERRED_SIZE.equals(evt.getSettingName())){
164             setMaximumSize(getMaxPopupSize());
165         }
166     }
167     
168     public JComponent JavaDoc getComponent() {
169         return this;
170     }
171     
172     public void setForwardEnabled(boolean enable) {
173     }
174     
175     public void setBackEnabled(boolean enable) {
176     }
177     
178     public void setShowWebEnabled(boolean enable) {
179     }
180     
181     
182     public JComponent JavaDoc getJavadocDisplayComponent() {
183         return scrollPane;
184     }
185     
186     public class BrowserButton extends JButton JavaDoc {
187         public BrowserButton() {
188             setBorderPainted(false);
189             setFocusPainted(false);
190         }
191         
192         public BrowserButton(String JavaDoc text){
193             super(text);
194             setBorderPainted(false);
195             setFocusPainted(false);
196         }
197         
198         public BrowserButton(Icon JavaDoc icon){
199             super(icon);
200             setBorderPainted(false);
201             setFocusPainted(false);
202         }
203     }
204     
205
206     protected class HyperlinkAction implements HyperlinkListener JavaDoc{
207         
208         public HyperlinkAction(){
209             
210         }
211         
212         public void hyperlinkUpdate(HyperlinkEvent JavaDoc e) {
213             if (e!=null && HyperlinkEvent.EventType.ACTIVATED.equals(e.getEventType())){
214                 if (e.getDescription() != null){
215                     Object JavaDoc obj = cjd.parseLink(e.getDescription(), null);
216                     if (obj!=null){
217                         cjd.setContent(obj, false);
218                         cjd.addToHistory(obj);
219                     } else {
220                         obj = (e.getURL() == null) ? e.getDescription() : (Object JavaDoc)e.getURL();
221                         cjd.setContent(obj, false);
222                     }
223                 }
224             }
225         }
226     }
227     /*
228     private class BackAction implements ActionListener{
229         public void actionPerformed(ActionEvent evt) {
230             if (cjd!=null){
231                 System.out.println("back");
232                 cjd.backHistory();
233             }
234         }
235     }
236
237     private class ForwardAction implements ActionListener {
238         public void actionPerformed(ActionEvent evt) {
239             if (cjd!=null){
240                 System.out.println("fwd");
241                 cjd.forwardHistory();
242             }
243         }
244     }
245     */

246 }
247
Popular Tags