~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to editor/libsrc/org/netbeans/editor/ext/ScrollJavaDocPane.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
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]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
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.
 
29
 *
 
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.
 
40
 */
 
41
 
 
42
 
 
43
package org.netbeans.editor.ext;
 
44
 
 
45
import java.awt.event.MouseAdapter;
 
46
import java.awt.event.MouseEvent;
 
47
import java.awt.Dimension;
 
48
import java.awt.Rectangle;
 
49
 
 
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;
 
58
 
 
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;
 
73
import java.net.URL;
 
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;
 
93
 
 
94
/**
 
95
 *  JScrollPane implementation of JavaDocPane.
 
96
 *
 
97
 *  @author  Martin Roskanin
 
98
 *  @since   03/2002
 
99
 */
 
100
public class ScrollJavaDocPane extends JPanel implements JavaDocPane, SettingsChangeListener{
 
101
 
 
102
    protected  ExtEditorUI extEditorUI;
 
103
    private JComponent view;
 
104
    private  CompletionJavaDoc cjd;
 
105
    protected JScrollPane scrollPane = new JScrollPane();
 
106
    Border lineBorder;
 
107
    
 
108
    /** Creates a new instance of ScrollJavaDocPane */
 
109
    public ScrollJavaDocPane(ExtEditorUI extEditorUI) {
 
110
        
 
111
//        new RuntimeException("ScrollJavaDocPane.<init>").printStackTrace();
 
112
        
 
113
        setLayout(null);
 
114
 
 
115
        this.extEditorUI = extEditorUI;
 
116
        
 
117
        // Add the completionJavaDoc view
 
118
        cjd = extEditorUI.getCompletionJavaDoc();
 
119
        if (cjd!=null){
 
120
            JavaDocView javaDocView = cjd.getJavaDocView();
 
121
            if (javaDocView instanceof JComponent) {
 
122
                if (javaDocView instanceof JEditorPane){
 
123
                    ((JEditorPane)javaDocView).addHyperlinkListener(createHyperlinkAction());
 
124
                }
 
125
                view = (JComponent)javaDocView;
 
126
                scrollPane.setViewportView(view);
 
127
            }
 
128
        
 
129
            Settings.addSettingsChangeListener(this);
 
130
            setMinimumSize(new Dimension(100,100)); //[PENDING] put it into the options
 
131
            setMaximumSize(getMaxPopupSize());        
 
132
        }else{
 
133
            setMinimumSize(new Dimension(0,0));
 
134
            setMaximumSize(new Dimension(0,0));        
 
135
        }
 
136
        super.setVisible(false);
 
137
        add(scrollPane);
 
138
        getAccessibleContext().setAccessibleDescription(
 
139
                NbBundle.getBundle(org.netbeans.editor.BaseKit.class).
 
140
                getString("ACSD_JAVADOC_javaDocPane")); //NOI18N
 
141
        
 
142
        // !!! virtual method called from contructor!!
 
143
        installTitleComponent();
 
144
        setBorder(new LineBorder(javax.swing.UIManager.getColor("controlDkShadow"))); //NOI18N
 
145
    }
 
146
    
 
147
    protected HyperlinkAction createHyperlinkAction(){
 
148
        return new HyperlinkAction();
 
149
    }
 
150
    
 
151
    public void setBounds(Rectangle r){
 
152
        super.setBounds(r);
 
153
        scrollPane.setBounds(r.x, 0, r.width+1, r.height );
 
154
    }
 
155
    
 
156
    public void setVisible(boolean visible){
 
157
        super.setVisible(visible);
 
158
        if (cjd!=null && !visible){
 
159
            cjd.clearHistory();
 
160
        }
 
161
    }
 
162
    
 
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;
 
168
    }
 
169
 
 
170
    protected void installTitleComponent() {
 
171
    }
 
172
    
 
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);
 
179
            
 
180
        }
 
181
        return ExtSettingsDefaults.defaultJavaDocPreferredSize;
 
182
    }
 
183
    
 
184
    public void settingsChange(SettingsChangeEvent evt) {
 
185
        if (ExtSettingsNames.JAVADOC_PREFERRED_SIZE.equals(evt.getSettingName())){
 
186
            setMaximumSize(getMaxPopupSize());
 
187
        }
 
188
    }   
 
189
    
 
190
    public JComponent getComponent() {
 
191
        return this;
 
192
    }
 
193
    
 
194
    public void setForwardEnabled(boolean enable) {
 
195
    }
 
196
    
 
197
    public void setBackEnabled(boolean enable) {
 
198
    }
 
199
    
 
200
    public void setShowWebEnabled(boolean enable) {
 
201
    }    
 
202
    
 
203
    
 
204
    public JComponent getJavadocDisplayComponent() {
 
205
        return scrollPane;
 
206
    }
 
207
    
 
208
    public class BrowserButton extends JButton {
 
209
        public BrowserButton() {
 
210
            setBorderPainted(false);
 
211
            setFocusPainted(false);
 
212
        }
 
213
        
 
214
        public BrowserButton(String text){
 
215
            super(text);
 
216
            setBorderPainted(false);
 
217
            setFocusPainted(false);
 
218
        }
 
219
        
 
220
        public BrowserButton(Icon icon){
 
221
            super(icon);
 
222
            setBorderPainted(false);
 
223
            setFocusPainted(false);
 
224
        }
 
225
    }
 
226
    
 
227
 
 
228
    protected  class HyperlinkAction implements HyperlinkListener{
 
229
        
 
230
        public HyperlinkAction(){
 
231
            
 
232
        }
 
233
        
 
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);
 
238
                    if (obj!=null){
 
239
                        cjd.setContent(obj, false);
 
240
                        cjd.addToHistory(obj);
 
241
                    } else {
 
242
                        obj = (e.getURL() == null) ? e.getDescription() : (Object)e.getURL();
 
243
                        cjd.setContent(obj, false);
 
244
                    }
 
245
                }
 
246
            }
 
247
        }
 
248
    }
 
249
    /*
 
250
    private class BackAction implements ActionListener{
 
251
        public void actionPerformed(ActionEvent evt) {
 
252
            if (cjd!=null){
 
253
                System.out.println("back");
 
254
                cjd.backHistory();
 
255
            }
 
256
        }
 
257
    }
 
258
 
 
259
    private class ForwardAction implements ActionListener {
 
260
        public void actionPerformed(ActionEvent evt) {
 
261
            if (cjd!=null){
 
262
                System.out.println("fwd");
 
263
                cjd.forwardHistory();
 
264
            }
 
265
        }
 
266
    }
 
267
    */
 
268
}