1 19 20 package org.netbeans.editor.ext.html; 21 22 import javax.swing.JToolBar ; 23 import java.awt.GridBagLayout ; 24 import java.awt.GridBagConstraints ; 25 import java.awt.Insets ; 26 import java.awt.Rectangle ; 27 import org.netbeans.editor.ext.ScrollJavaDocPane; 28 import java.awt.event.MouseAdapter ; 29 import javax.swing.JButton ; 30 import java.awt.event.MouseEvent ; 31 import javax.swing.ImageIcon ; 32 import org.netbeans.editor.ext.CompletionJavaDoc; 33 import org.netbeans.editor.ext.ExtEditorUI; 34 import org.openide.util.NbBundle; 35 36 40 41 public class HTMLScrollJavaDocPane extends ScrollJavaDocPane { 42 43 44 private JToolBar toolbar; 45 private ImageIcon iBack, iForward, iShowWeb; 46 private JButton bBack, bForward, bShowWeb; 47 private static final String BACK = "org/netbeans/modules/html/editor/resources/back.gif"; private static final String FORWARD = "org/netbeans/modules/html/editor/resources/forward.gif"; private static final String SHOW_WEB = "org/netbeans/modules/html/editor/resources/htmlView.gif"; private CompletionJavaDoc cjd; 51 52 53 public HTMLScrollJavaDocPane(ExtEditorUI extEditorUI) { 54 super(extEditorUI); 55 cjd = extEditorUI.getCompletionJavaDoc(); 56 } 57 58 59 protected ImageIcon resolveIcon(String res){ 60 return new ImageIcon (org.openide.util.Utilities.loadImage (res)); 61 } 62 63 64 protected void installTitleComponent() { 65 toolbar = new JToolBar (); 66 toolbar.setFloatable(false); 67 68 toolbar.setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (1, 2, 1, 2))); 69 toolbar.setLayout(new GridBagLayout ()); 70 GridBagConstraints gdc = new GridBagConstraints (); 71 gdc.gridx = 0; 72 gdc.gridy = 0; 73 gdc.anchor = GridBagConstraints.WEST; 74 75 iBack = resolveIcon(BACK); 76 if (iBack !=null){ 77 78 bBack = new BrowserButton(iBack); 79 bBack.addMouseListener(new MouseEventListener(bBack)); 80 bBack.setEnabled(false); 81 bBack.setContentAreaFilled(false); 82 bBack.setMargin(new Insets (0, 0, 0, 0)); 83 bBack.setToolTipText(NbBundle.getBundle(this.getClass()).getString("HINT_javadoc_browser_back_button")); toolbar.add(bBack, gdc); 85 } 86 87 gdc.gridx = 1; 88 gdc.gridy = 0; 89 gdc.anchor = GridBagConstraints.WEST; 90 91 iForward = resolveIcon(FORWARD); 92 if (iForward !=null){ 93 bForward = new BrowserButton(iForward); 94 bForward.addMouseListener(new MouseEventListener(bForward)); 95 bForward.setEnabled(false); 96 bForward.setContentAreaFilled(false); 97 bForward.setToolTipText(NbBundle.getBundle(this.getClass()).getString("HINT_javadoc_browser_forward_button")); bForward.setMargin(new Insets (0, 0, 0, 0)); 99 toolbar.add(bForward, gdc); 100 } 101 102 gdc.gridx = 2; 103 gdc.gridy = 0; 104 gdc.weightx = 1.0; 105 gdc.anchor = GridBagConstraints.WEST; 106 107 iShowWeb = resolveIcon(SHOW_WEB); 108 if (iShowWeb !=null){ 109 110 bShowWeb = new BrowserButton(iShowWeb); 111 bShowWeb.setToolTipText(NbBundle.getBundle(this.getClass()).getString("HINT_javadoc_browser_show_web_button")); bShowWeb.addMouseListener(new MouseEventListener(bShowWeb)); 113 bShowWeb.setContentAreaFilled(false); 114 bShowWeb.setMargin(new Insets (0, 0, 0, 0)); 115 toolbar.add(bShowWeb, gdc); 116 } 117 118 add(toolbar); 119 } 120 121 public void setBounds(Rectangle r){ 122 super.setBounds(r); 123 scrollPane.setBounds(r.x, 25, r.width, r.height - 25); 124 toolbar.setBounds(r.x+1, 1, r.width-2, 24); 125 } 126 127 public void setForwardEnabled(boolean enable) { 128 bForward.setEnabled(enable); 129 } 130 131 public void setBackEnabled(boolean enable) { 132 bBack.setEnabled(enable); 133 } 134 135 public void setShowWebEnabled(boolean enable) { 136 bShowWeb.setEnabled(enable); 137 } 138 139 class MouseEventListener extends MouseAdapter { 140 JButton button; 141 MouseEventListener(JButton button) { 142 this.button = button; 143 } 144 145 public void mouseEntered(MouseEvent ev) { 146 if (button.isEnabled()){ 147 button.setContentAreaFilled(true); 148 button.setBorderPainted(true); 149 } 150 } 151 public void mouseExited(MouseEvent ev) { 152 button.setContentAreaFilled(false); 153 button.setBorderPainted(false); 154 } 155 156 public void mouseClicked(MouseEvent evt) { 157 if (button.equals(bBack)){ 158 cjd.backHistory(); 159 }else if(button.equals(bForward)){ 160 cjd.forwardHistory(); 161 }else if (button.equals(bShowWeb)){ 162 cjd.openInExternalBrowser(); 163 } 164 } 165 } 166 167 } 168 | Popular Tags |