1 19 20 21 package org.netbeans.editor.ext; 22 23 import java.awt.event.MouseAdapter ; 24 import java.awt.event.MouseEvent ; 25 import java.awt.Dimension ; 26 import java.awt.Rectangle ; 27 28 import javax.swing.JScrollPane ; 29 import javax.swing.JComponent ; 30 import javax.swing.JRootPane ; 31 import javax.swing.text.JTextComponent ; 32 import javax.swing.JLayeredPane ; 33 import javax.swing.JList ; 34 import javax.swing.SwingUtilities ; 35 import javax.swing.JPanel ; 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 ; 45 import javax.swing.border.CompoundBorder ; 46 import javax.swing.border.EtchedBorder ; 47 import javax.swing.border.EmptyBorder ; 48 import java.awt.BorderLayout ; 49 import java.awt.Color ; 50 import javax.swing.ImageIcon ; 51 import java.net.URL ; 52 import javax.swing.Icon ; 53 import java.awt.FlowLayout ; 54 import java.awt.GridBagConstraints ; 55 import java.awt.Insets ; 56 import java.awt.GridLayout ; 57 import java.awt.ComponentOrientation ; 58 import java.awt.GridBagLayout ; 59 import javax.swing.BoxLayout ; 60 import javax.swing.AbstractAction ; 61 import java.awt.event.ActionEvent ; 62 import java.awt.event.ActionListener ; 63 import javax.swing.BorderFactory ; 64 import javax.swing.event.HyperlinkListener ; 65 import javax.swing.event.HyperlinkEvent ; 66 import javax.swing.JEditorPane ; 67 import javax.swing.UIManager ; 68 import javax.swing.border.Border ; 69 import javax.swing.border.LineBorder ; 70 import org.openide.util.NbBundle; 71 72 78 public class ScrollJavaDocPane extends JPanel implements JavaDocPane, SettingsChangeListener{ 79 80 protected ExtEditorUI extEditorUI; 81 private JComponent view; 82 private CompletionJavaDoc cjd; 83 protected JScrollPane scrollPane = new JScrollPane (); 84 Border lineBorder; 85 86 87 public ScrollJavaDocPane(ExtEditorUI extEditorUI) { 88 89 91 setLayout(null); 92 93 this.extEditorUI = extEditorUI; 94 95 cjd = extEditorUI.getCompletionJavaDoc(); 97 if (cjd!=null){ 98 JavaDocView javaDocView = cjd.getJavaDocView(); 99 if (javaDocView instanceof JComponent ) { 100 if (javaDocView instanceof JEditorPane ){ 101 ((JEditorPane )javaDocView).addHyperlinkListener(createHyperlinkAction()); 102 } 103 view = (JComponent )javaDocView; 104 scrollPane.setViewportView(view); 105 } 106 107 Settings.addSettingsChangeListener(this); 108 setMinimumSize(new Dimension (100,100)); setMaximumSize(getMaxPopupSize()); 110 }else{ 111 setMinimumSize(new Dimension (0,0)); 112 setMaximumSize(new Dimension (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")); 120 installTitleComponent(); 122 setBorder(new LineBorder (javax.swing.UIManager.getColor("controlDkShadow"))); } 124 125 protected HyperlinkAction createHyperlinkAction(){ 126 return new HyperlinkAction(); 127 } 128 129 public void setBounds(Rectangle 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 resolveIcon(String res){ 142 ClassLoader loader = this.getClass().getClassLoader(); 143 URL resource = loader.getResource( res ); 144 if( resource == null ) resource = ClassLoader.getSystemResource( res ); 145 return ( resource != null ) ? new ImageIcon ( resource ) : null; 146 } 147 148 protected void installTitleComponent() { 149 } 150 151 private Dimension getMaxPopupSize(){ 152 Class kitClass = Utilities.getKitClass(extEditorUI.getComponent()); 153 if (kitClass != null) { 154 return (Dimension )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 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 getJavadocDisplayComponent() { 183 return scrollPane; 184 } 185 186 public class BrowserButton extends JButton { 187 public BrowserButton() { 188 setBorderPainted(false); 189 setFocusPainted(false); 190 } 191 192 public BrowserButton(String text){ 193 super(text); 194 setBorderPainted(false); 195 setFocusPainted(false); 196 } 197 198 public BrowserButton(Icon icon){ 199 super(icon); 200 setBorderPainted(false); 201 setFocusPainted(false); 202 } 203 } 204 205 206 protected class HyperlinkAction implements HyperlinkListener { 207 208 public HyperlinkAction(){ 209 210 } 211 212 public void hyperlinkUpdate(HyperlinkEvent e) { 213 if (e!=null && HyperlinkEvent.EventType.ACTIVATED.equals(e.getEventType())){ 214 if (e.getDescription() != null){ 215 Object 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 )e.getURL(); 221 cjd.setContent(obj, false); 222 } 223 } 224 } 225 } 226 } 227 246 } 247 | Popular Tags |