001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.editor.ext;
043:
044: import java.awt.event.MouseAdapter;
045: import java.awt.event.MouseEvent;
046: import java.awt.Dimension;
047: import java.awt.Rectangle;
048:
049: import javax.swing.JScrollPane;
050: import javax.swing.JComponent;
051: import javax.swing.JRootPane;
052: import javax.swing.text.JTextComponent;
053: import javax.swing.JLayeredPane;
054: import javax.swing.JList;
055: import javax.swing.SwingUtilities;
056: import javax.swing.JPanel;
057:
058: import org.netbeans.editor.SettingsChangeListener;
059: import org.netbeans.editor.Utilities;
060: import org.netbeans.editor.SettingsUtil;
061: import org.netbeans.editor.ext.ExtSettingsNames;
062: import org.netbeans.editor.ext.ExtSettingsDefaults;
063: import org.netbeans.editor.SettingsChangeEvent;
064: import org.netbeans.editor.Settings;
065: import javax.swing.JButton;
066: import javax.swing.border.CompoundBorder;
067: import javax.swing.border.EtchedBorder;
068: import javax.swing.border.EmptyBorder;
069: import java.awt.BorderLayout;
070: import java.awt.Color;
071: import javax.swing.ImageIcon;
072: import java.net.URL;
073: import javax.swing.Icon;
074: import java.awt.FlowLayout;
075: import java.awt.GridBagConstraints;
076: import java.awt.Insets;
077: import java.awt.GridLayout;
078: import java.awt.ComponentOrientation;
079: import java.awt.GridBagLayout;
080: import javax.swing.BoxLayout;
081: import javax.swing.AbstractAction;
082: import java.awt.event.ActionEvent;
083: import java.awt.event.ActionListener;
084: import javax.swing.BorderFactory;
085: import javax.swing.event.HyperlinkListener;
086: import javax.swing.event.HyperlinkEvent;
087: import javax.swing.JEditorPane;
088: import javax.swing.UIManager;
089: import javax.swing.border.Border;
090: import javax.swing.border.LineBorder;
091: import org.openide.util.NbBundle;
092:
093: /**
094: * JScrollPane implementation of JavaDocPane.
095: *
096: * @author Martin Roskanin
097: * @since 03/2002
098: */
099: public class ScrollJavaDocPane extends JPanel implements JavaDocPane,
100: 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)
124: .addHyperlinkListener(createHyperlinkAction());
125: }
126: view = (JComponent) javaDocView;
127: scrollPane.setViewportView(view);
128: }
129:
130: Settings.addSettingsChangeListener(this );
131: setMinimumSize(new Dimension(100, 100)); //[PENDING] put it into the options
132: setMaximumSize(getMaxPopupSize());
133: } else {
134: setMinimumSize(new Dimension(0, 0));
135: setMaximumSize(new Dimension(0, 0));
136: }
137: super .setVisible(false);
138: add(scrollPane);
139: getAccessibleContext().setAccessibleDescription(
140: NbBundle.getBundle(org.netbeans.editor.BaseKit.class)
141: .getString("ACSD_JAVADOC_javaDocPane")); //NOI18N
142:
143: // !!! virtual method called from contructor!!
144: installTitleComponent();
145: setBorder(new LineBorder(javax.swing.UIManager
146: .getColor("controlDkShadow"))); //NOI18N
147: }
148:
149: protected HyperlinkAction createHyperlinkAction() {
150: return new HyperlinkAction();
151: }
152:
153: public void setBounds(Rectangle r) {
154: super .setBounds(r);
155: scrollPane.setBounds(r.x, 0, r.width + 1, r.height);
156: }
157:
158: public void setVisible(boolean visible) {
159: super .setVisible(visible);
160: if (cjd != null && !visible) {
161: cjd.clearHistory();
162: }
163: }
164:
165: protected ImageIcon resolveIcon(String res) {
166: ClassLoader loader = this .getClass().getClassLoader();
167: URL resource = loader.getResource(res);
168: if (resource == null)
169: resource = ClassLoader.getSystemResource(res);
170: return (resource != null) ? new ImageIcon(resource) : null;
171: }
172:
173: protected void installTitleComponent() {
174: }
175:
176: private Dimension getMaxPopupSize() {
177: Class kitClass = Utilities.getKitClass(extEditorUI
178: .getComponent());
179: if (kitClass != null) {
180: return (Dimension) SettingsUtil.getValue(kitClass,
181: ExtSettingsNames.JAVADOC_PREFERRED_SIZE,
182: ExtSettingsDefaults.defaultJavaDocAutoPopupDelay);
183:
184: }
185: return ExtSettingsDefaults.defaultJavaDocPreferredSize;
186: }
187:
188: public void settingsChange(SettingsChangeEvent evt) {
189: if (ExtSettingsNames.JAVADOC_PREFERRED_SIZE.equals(evt
190: .getSettingName())) {
191: setMaximumSize(getMaxPopupSize());
192: }
193: }
194:
195: public JComponent getComponent() {
196: return this ;
197: }
198:
199: public void setForwardEnabled(boolean enable) {
200: }
201:
202: public void setBackEnabled(boolean enable) {
203: }
204:
205: public void setShowWebEnabled(boolean enable) {
206: }
207:
208: public JComponent getJavadocDisplayComponent() {
209: return scrollPane;
210: }
211:
212: public class BrowserButton extends JButton {
213: public BrowserButton() {
214: setBorderPainted(false);
215: setFocusPainted(false);
216: }
217:
218: public BrowserButton(String text) {
219: super (text);
220: setBorderPainted(false);
221: setFocusPainted(false);
222: }
223:
224: public BrowserButton(Icon icon) {
225: super (icon);
226: setBorderPainted(false);
227: setFocusPainted(false);
228: }
229: }
230:
231: protected class HyperlinkAction implements HyperlinkListener {
232:
233: public HyperlinkAction() {
234:
235: }
236:
237: public void hyperlinkUpdate(HyperlinkEvent e) {
238: if (e != null
239: && HyperlinkEvent.EventType.ACTIVATED.equals(e
240: .getEventType())) {
241: if (e.getDescription() != null) {
242: Object obj = cjd
243: .parseLink(e.getDescription(), null);
244: if (obj != null) {
245: cjd.setContent(obj, false);
246: cjd.addToHistory(obj);
247: } else {
248: obj = (e.getURL() == null) ? e.getDescription()
249: : (Object) e.getURL();
250: cjd.setContent(obj, false);
251: }
252: }
253: }
254: }
255: }
256: /*
257: private class BackAction implements ActionListener{
258: public void actionPerformed(ActionEvent evt) {
259: if (cjd!=null){
260: System.out.println("back");
261: cjd.backHistory();
262: }
263: }
264: }
265:
266: private class ForwardAction implements ActionListener {
267: public void actionPerformed(ActionEvent evt) {
268: if (cjd!=null){
269: System.out.println("fwd");
270: cjd.forwardHistory();
271: }
272: }
273: }
274: */
275: }
|