2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
43
package org.netbeans.editor.ext;
45
import java.awt.event.MouseAdapter;
46
import java.awt.event.MouseEvent;
47
import java.awt.Dimension;
48
import java.awt.Rectangle;
50
import javax.swing.JScrollPane;
51
import javax.swing.JComponent;
52
import javax.swing.JRootPane;
53
import javax.swing.text.JTextComponent;
54
import javax.swing.JLayeredPane;
55
import javax.swing.JList;
56
import javax.swing.SwingUtilities;
57
import javax.swing.JPanel;
59
import org.netbeans.editor.SettingsChangeListener;
60
import org.netbeans.editor.Utilities;
61
import org.netbeans.editor.SettingsUtil;
62
import org.netbeans.editor.ext.ExtSettingsNames;
63
import org.netbeans.editor.ext.ExtSettingsDefaults;
64
import org.netbeans.editor.SettingsChangeEvent;
65
import org.netbeans.editor.Settings;
66
import javax.swing.JButton;
67
import javax.swing.border.CompoundBorder;
68
import javax.swing.border.EtchedBorder;
69
import javax.swing.border.EmptyBorder;
70
import java.awt.BorderLayout;
71
import java.awt.Color;
72
import javax.swing.ImageIcon;
74
import javax.swing.Icon;
75
import java.awt.FlowLayout;
76
import java.awt.GridBagConstraints;
77
import java.awt.Insets;
78
import java.awt.GridLayout;
79
import java.awt.ComponentOrientation;
80
import java.awt.GridBagLayout;
81
import javax.swing.BoxLayout;
82
import javax.swing.AbstractAction;
83
import java.awt.event.ActionEvent;
84
import java.awt.event.ActionListener;
85
import javax.swing.BorderFactory;
86
import javax.swing.event.HyperlinkListener;
87
import javax.swing.event.HyperlinkEvent;
88
import javax.swing.JEditorPane;
89
import javax.swing.UIManager;
90
import javax.swing.border.Border;
91
import javax.swing.border.LineBorder;
92
import org.openide.util.NbBundle;
95
* JScrollPane implementation of JavaDocPane.
97
* @author Martin Roskanin
100
public class ScrollJavaDocPane extends JPanel implements JavaDocPane, SettingsChangeListener{
102
protected ExtEditorUI extEditorUI;
103
private JComponent view;
104
private CompletionJavaDoc cjd;
105
protected JScrollPane scrollPane = new JScrollPane();
108
/** Creates a new instance of ScrollJavaDocPane */
109
public ScrollJavaDocPane(ExtEditorUI extEditorUI) {
111
// new RuntimeException("ScrollJavaDocPane.<init>").printStackTrace();
115
this.extEditorUI = extEditorUI;
117
// Add the completionJavaDoc view
118
cjd = extEditorUI.getCompletionJavaDoc();
120
JavaDocView javaDocView = cjd.getJavaDocView();
121
if (javaDocView instanceof JComponent) {
122
if (javaDocView instanceof JEditorPane){
123
((JEditorPane)javaDocView).addHyperlinkListener(createHyperlinkAction());
125
view = (JComponent)javaDocView;
126
scrollPane.setViewportView(view);
129
Settings.addSettingsChangeListener(this);
130
setMinimumSize(new Dimension(100,100)); //[PENDING] put it into the options
131
setMaximumSize(getMaxPopupSize());
133
setMinimumSize(new Dimension(0,0));
134
setMaximumSize(new Dimension(0,0));
136
super.setVisible(false);
138
getAccessibleContext().setAccessibleDescription(
139
NbBundle.getBundle(org.netbeans.editor.BaseKit.class).
140
getString("ACSD_JAVADOC_javaDocPane")); //NOI18N
142
// !!! virtual method called from contructor!!
143
installTitleComponent();
144
setBorder(new LineBorder(javax.swing.UIManager.getColor("controlDkShadow"))); //NOI18N
147
protected HyperlinkAction createHyperlinkAction(){
148
return new HyperlinkAction();
151
public void setBounds(Rectangle r){
153
scrollPane.setBounds(r.x, 0, r.width+1, r.height );
156
public void setVisible(boolean visible){
157
super.setVisible(visible);
158
if (cjd!=null && !visible){
163
protected ImageIcon resolveIcon(String res){
164
ClassLoader loader = this.getClass().getClassLoader();
165
URL resource = loader.getResource( res );
166
if( resource == null ) resource = ClassLoader.getSystemResource( res );
167
return ( resource != null ) ? new ImageIcon( resource ) : null;
170
protected void installTitleComponent() {
173
private Dimension getMaxPopupSize(){
174
Class kitClass = Utilities.getKitClass(extEditorUI.getComponent());
175
if (kitClass != null) {
176
return (Dimension)SettingsUtil.getValue(kitClass,
177
ExtSettingsNames.JAVADOC_PREFERRED_SIZE,
178
ExtSettingsDefaults.defaultJavaDocAutoPopupDelay);
181
return ExtSettingsDefaults.defaultJavaDocPreferredSize;
184
public void settingsChange(SettingsChangeEvent evt) {
185
if (ExtSettingsNames.JAVADOC_PREFERRED_SIZE.equals(evt.getSettingName())){
186
setMaximumSize(getMaxPopupSize());
190
public JComponent getComponent() {
194
public void setForwardEnabled(boolean enable) {
197
public void setBackEnabled(boolean enable) {
200
public void setShowWebEnabled(boolean enable) {
204
public JComponent getJavadocDisplayComponent() {
208
public class BrowserButton extends JButton {
209
public BrowserButton() {
210
setBorderPainted(false);
211
setFocusPainted(false);
214
public BrowserButton(String text){
216
setBorderPainted(false);
217
setFocusPainted(false);
220
public BrowserButton(Icon icon){
222
setBorderPainted(false);
223
setFocusPainted(false);
228
protected class HyperlinkAction implements HyperlinkListener{
230
public HyperlinkAction(){
234
public void hyperlinkUpdate(HyperlinkEvent e) {
235
if (e!=null && HyperlinkEvent.EventType.ACTIVATED.equals(e.getEventType())){
236
if (e.getDescription() != null){
237
Object obj = cjd.parseLink(e.getDescription(), null);
239
cjd.setContent(obj, false);
240
cjd.addToHistory(obj);
242
obj = (e.getURL() == null) ? e.getDescription() : (Object)e.getURL();
243
cjd.setContent(obj, false);
250
private class BackAction implements ActionListener{
251
public void actionPerformed(ActionEvent evt) {
253
System.out.println("back");
259
private class ForwardAction implements ActionListener {
260
public void actionPerformed(ActionEvent evt) {
262
System.out.println("fwd");
263
cjd.forwardHistory();