1 19 20 package org.netbeans.editor.ext; 21 22 import java.awt.Component ; 23 import java.awt.Dimension ; 24 import java.awt.Rectangle ; 25 import java.beans.PropertyChangeEvent ; 26 import java.beans.PropertyChangeListener ; 27 import java.awt.event.KeyEvent ; 28 import java.awt.event.FocusListener ; 29 import java.awt.event.FocusAdapter ; 30 import java.awt.event.FocusEvent ; 31 import java.awt.event.ActionListener ; 32 import java.awt.event.ActionEvent ; 33 34 import javax.swing.JComponent ; 35 import javax.swing.JPanel ; 36 import javax.swing.text.JTextComponent ; 37 import javax.swing.KeyStroke ; 38 import javax.swing.SwingUtilities ; 39 import javax.swing.Action ; 40 import javax.swing.AbstractAction ; 41 42 import org.netbeans.editor.PopupManager; 43 import org.netbeans.editor.ext.ExtEditorUI; 44 import org.netbeans.editor.Utilities; 45 import org.netbeans.editor.BaseKit; 46 import org.netbeans.editor.ext.CompletionJavaDoc; 47 import org.netbeans.editor.ext.ExtKit; 48 import javax.swing.plaf.TextUI ; 49 import javax.swing.text.Keymap ; 50 import javax.swing.text.EditorKit ; 51 import java.util.Iterator ; 52 import java.util.ArrayList ; 53 import java.util.List ; 54 import org.netbeans.editor.SettingsChangeEvent; 55 import org.netbeans.editor.SettingsChangeListener; 56 import org.netbeans.editor.Settings; 57 58 59 66 public class JDCPopupPanel extends JPanel implements PropertyChangeListener , SettingsChangeListener { 67 68 private ExtCompletionPane completion; 69 70 private ExtEditorUI extEditorUI; 71 private FocusListener focusL; 72 private List keyActionPairsList; 73 74 private JavaDocPane javadoc; 77 private int lastSize = -1; 79 80 private static final int WINDOW_GAP = 1; 82 83 private static final String POPUP_HIDE = "jdc-popup-hide"; 85 private static final String COMPLETION_UP = "completion-up"; private static final String COMPLETION_DOWN = "completion-down"; private static final String COMPLETION_PGUP = "completion-pgup"; private static final String COMPLETION_PGDN = "completion-pgdn"; private static final String COMPLETION_BEGIN = "completion-begin"; private static final String COMPLETION_END = "completion-end"; 92 private static final String JAVADOC_UP = "javadoc-up"; private static final String JAVADOC_DOWN = "javadoc-down"; private static final String JAVADOC_PGUP = "javadoc-pgup"; private static final String JAVADOC_PGDN = "javadoc-pgdn"; private static final String JAVADOC_BEGIN = "javadoc-begin"; private static final String JAVADOC_END = "javadoc-end"; private static final String JAVADOC_LEFT = "javadoc-left"; private static final String JAVADOC_RIGHT = "javadoc-right"; private static final String JAVADOC_BACK = "javadoc-back"; private static final String JAVADOC_FORWARD = "javadoc-forward"; private static final String JAVADOC_OPEN_IN_BROWSER = "javadoc-open-in-browser"; private static final String JAVADOC_OPEN_SOURCE = "javadoc-open-source"; 105 public static final String COMPLETION_SUBSTITUTE_TEXT= "completion-substitute-text"; public static final String COMPLETION_SUBSTITUTE_TEXT_SIMPLE= "completion-substitute-text-simple"; private static final String COMPLETION_SUBSTITUTE_TEXT_KEEP_POPUP_OPEN = "completion-substitute-text-keep-popup-open"; private static final String COMPLETION_SUBSTITUTE_COMMON_TEXT = "completion-substitutecommon-text"; 110 private static final int ACTION_POPUP_HIDE = 1; 111 112 private static final int ACTION_COMPLETION_UP = 2; 113 private static final int ACTION_COMPLETION_DOWN = 3; 114 private static final int ACTION_COMPLETION_PGUP = 4; 115 private static final int ACTION_COMPLETION_PGDN = 5; 116 private static final int ACTION_COMPLETION_BEGIN = 6; 117 private static final int ACTION_COMPLETION_END = 7; 118 119 private static final int ACTION_JAVADOC_UP = 8; 120 private static final int ACTION_JAVADOC_DOWN = 9; 121 private static final int ACTION_JAVADOC_PGUP = 10; 122 private static final int ACTION_JAVADOC_PGDN = 11; 123 private static final int ACTION_JAVADOC_BEGIN = 12; 124 private static final int ACTION_JAVADOC_END = 13; 125 private static final int ACTION_JAVADOC_LEFT = 14; 126 private static final int ACTION_JAVADOC_RIGHT = 15; 127 private static final int ACTION_JAVADOC_BACK = 16; 128 private static final int ACTION_JAVADOC_FORWARD = 17; 129 private static final int ACTION_JAVADOC_OPEN_IN_BROWSER = 18; 130 private static final int ACTION_JAVADOC_OPEN_SOURCE = 19; 131 132 private static final int ACTION_COMPLETION_SUBSTITUTE_TEXT = 20; 133 private static final int ACTION_COMPLETION_SUBSTITUTE_TEXT_SIMPLE = 21; 134 private static final int ACTION_COMPLETION_SUBSTITUTE_TEXT_KEEP_POPUP_OPEN = 22; 135 private static final int ACTION_COMPLETION_SUBSTITUTE_COMMON_TEXT = 23; 136 137 138 public JDCPopupPanel(ExtEditorUI extEditorUI, ExtCompletionPane completion, Completion documentationProvider) { 139 super(); 140 this.completion = completion; 141 this.extEditorUI = extEditorUI; 143 this.keyActionPairsList = new ArrayList (); 144 145 setLayout(null); 146 setOpaque(false); 148 focusL = new FocusAdapter () { 149 public void focusLost(FocusEvent evt) { 150 SwingUtilities.invokeLater( new Runnable () { 151 public void run() { 152 if (isVisible()) { 153 JTextComponent component = JDCPopupPanel.this.extEditorUI.getComponent(); 154 if (component != null) { 155 java.awt.Window w = SwingUtilities.windowForComponent( 156 component); 157 Component focusOwner = (w == null) ? 158 null : w.getFocusOwner(); 159 160 if (focusOwner == null) { 161 setVisible(false); 162 } 163 164 boolean docO = javadoc != null && focusOwner == JDCPopupPanel.this.getJavaDocView(); 165 boolean docA = javadoc != null && JDCPopupPanel.this.getJavaDocPane().getComponent().isAncestorOf(focusOwner); 166 boolean comO = focusOwner == JDCPopupPanel.this.getCompletionView(); 167 if (docO || comO || docA) { 168 component.requestFocus(); 169 }else if ( focusOwner != component ) { 170 setVisible(false); } 172 } 173 } 174 } 175 } ); 176 } 177 }; 178 179 180 synchronized (extEditorUI.getComponentLock()) { 181 JTextComponent component = extEditorUI.getComponent(); 183 if (component != null) { 184 propertyChange(new PropertyChangeEvent (extEditorUI, 185 ExtEditorUI.COMPONENT_PROPERTY, null, component)); 186 } 187 extEditorUI.addPropertyChangeListener(this); 188 } 189 190 super.setVisible(false); 191 192 Settings.addSettingsChangeListener(this); 193 } 194 195 196 public ExtCompletionPane getCompletionPane(){ 197 return completion; 198 } 199 200 private void clearJavadocContent(){ 201 CompletionJavaDoc cjd = extEditorUI.getCompletionJavaDoc(); 202 if (cjd!=null){ 203 cjd.clearContent(); 204 } 205 } 206 207 private JavaDocView getJavaDocView(){ 208 CompletionJavaDoc cjd = extEditorUI.getCompletionJavaDoc(); 209 if (cjd!=null){ 210 return cjd.getJavaDocView(); 211 } 212 return null; 213 } 214 215 private CompletionView getCompletionView(){ 216 Completion c = extEditorUI.getCompletion(); 217 if (c!=null){ 218 return c.getView(); 219 } 220 return null; 221 } 222 223 224 public JavaDocPane getJavaDocPane(){ 225 if (javadoc == null) { 226 Completion c = extEditorUI.getCompletion(); 227 if (c!=null){ 228 javadoc = c.getJavaDocPane(); 229 } 230 } 231 return javadoc; 232 } 233 234 236 public Dimension getMinimumSize(){ 237 return completion.getComponent().getMinimumSize(); 238 } 239 240 242 public Dimension getMaximumSize(){ 243 Dimension compDim = completion.getComponent().getMaximumSize(); 244 Dimension javadocDim = new Dimension (); 245 if (javadoc != null) { 246 javadocDim = javadoc.getComponent().getMaximumSize(); 247 } 248 return new Dimension (Math.max(compDim.width,javadocDim.width), compDim.height+javadocDim.height); 249 } 250 251 253 public Dimension getPreferredSize(){ 254 Dimension ret = new Dimension (); 255 Dimension compPref = completion.getComponent().getPreferredSize(); 256 Dimension compMax = completion.getComponent().getMaximumSize(); 257 258 Dimension javadocPref = new Dimension (); 259 Dimension javadocMax = new Dimension (); 260 if (javadoc != null) { 261 javadocPref = javadoc.getComponent().getPreferredSize(); 262 javadocMax = javadoc.getComponent().getMaximumSize(); 263 } 264 265 ret.width = Math.min(compPref.width, compMax.width) + Math.min(javadocPref.width, javadocMax.width); 266 ret.height = Math.min(compPref.height, compMax.height) + Math.min(javadocPref.height, javadocMax.height); 267 268 return ret; 269 } 270 271 272 public void setCompletionVisible(boolean visible){ 273 completion.setVisible(visible); 274 setVisible(visible); 275 } 276 277 278 public void setJavaDocVisible(boolean visible){ 279 getJavaDocPane().getComponent().setVisible(visible); 280 if (visible || !getCompletionPane().isVisible()){ 281 setVisible(visible); 282 } 283 } 284 285 286 public void setVisible(boolean visible){ 287 if (visible){ 288 if (Utilities.getLastActiveComponent() != extEditorUI.getComponent()){ 289 return; } 291 292 boolean docv = javadoc != null && javadoc.getComponent().isVisible(); 293 Completion c = extEditorUI.getCompletion(); 294 if (c!=null){ 295 CompletionQuery.Result result = c.getLastResult(); 296 int resultSize = (result == null) ? -1 : result.getData().size(); 297 if (lastSize!=resultSize || !isVisible() || docv){ 298 extEditorUI.getPopupManager().install(this); 299 lastSize = resultSize; 300 } 301 } 302 if (docv || completion.isVisible()){ 303 super.setVisible(visible); 304 } 305 } else { 306 lastSize = -1; 307 clearJavadocContent(); 308 Completion c = extEditorUI.getCompletion(); 309 if (c!=null){ 310 c.completionCancel(); 311 } 312 if (javadoc != null) { 313 javadoc.getComponent().setVisible(visible); 314 } 315 completion.getComponent().setVisible(visible); 316 super.setVisible(visible); 317 PopupManager pm = extEditorUI.getPopupManager(); 318 if (pm!=null) pm.uninstall(this); 319 } 320 } 321 322 323 public void setSize(int width, int height){ 324 PopupManager.Placement placement = (PopupManager.Placement)getClientProperty( 325 PopupManager.Placement.class); 326 327 Dimension completionMinSize = completion.getComponent().getMinimumSize(); 328 if (completionMinSize.height > height) { putClientProperty(PopupManager.Placement.class, null); 330 } 331 332 completion.getComponent().setSize(width, height); 334 335 Dimension javaDocMinSize = new Dimension (); 336 if (javadoc != null) { 337 javaDocMinSize = javadoc.getComponent().getMinimumSize(); 338 } 339 Dimension completionMaxSize = completion.getComponent().getMaximumSize(); 340 341 Rectangle completionBounds = new Rectangle (completion.getComponent().getSize()); 342 Rectangle javadocBounds = new Rectangle (); 343 if (javadoc != null) { 344 javadocBounds = new Rectangle (javadoc.getComponent().getMaximumSize()); 345 } 346 347 boolean showJavaDoc = true; 348 if (javadoc == null || javadoc.getComponent().isVisible() == false) { 349 showJavaDoc = false; 350 } 351 352 CompletionJavaDoc completionJavaDoc = extEditorUI.getCompletionJavaDoc(); 353 if (completionJavaDoc!=null){ 354 if(completionJavaDoc.autoPopup()){ 355 showJavaDoc = javadoc != null; 356 } 357 } 358 359 boolean showCompletion = getCompletionPane().isVisible(); 360 361 if (!showCompletion){ 362 completionMinSize.height = 0; 363 completionMinSize.width = 0; 364 completionBounds = new Rectangle (); 365 }else{ 366 completionBounds.width = Math.min(completionMaxSize.width,completionBounds.width); 367 completionBounds.height = Math.min(completionMaxSize.height,completionBounds.height); 368 } 369 370 if ((javaDocMinSize.height+completionMinSize.height)>height) showJavaDoc = false; 372 373 if (showJavaDoc) { 374 375 if ((completionBounds.height + javadocBounds.height) > height ){ 376 completionBounds.height = Math.max(Math.min((int)(height/2),completionBounds.height), completionMinSize.height); 378 completionBounds.height = Math.min(130,completionBounds.height); javadocBounds.height = Math.min((height - completionBounds.height - WINDOW_GAP ), javadocBounds.height); 380 } 381 382 if (placement == PopupManager.Below) { 383 completionBounds.y = 0; 384 javadocBounds.y = completionBounds.height + WINDOW_GAP; 385 }else{ 386 completionBounds.y = javadocBounds.height + WINDOW_GAP; 387 javadocBounds.y = 0; 388 } 389 390 } 391 392 if (width < javaDocMinSize.width){ 394 showJavaDoc = false; 395 }else{ 396 javadocBounds.width = Math.min(width,javadocBounds.width); 398 399 JTextComponent component = extEditorUI.getComponent(); 400 Rectangle extBounds = extEditorUI.getExtentBounds(); 401 Rectangle caretRect = new Rectangle (); 402 try { 403 caretRect = component.getUI().modelToView( 404 component, component.getCaret().getDot(), javax.swing.text.Position.Bias.Forward); 405 } catch(javax.swing.text.BadLocationException ble){ 406 } 407 408 if (width - javadocBounds.width < caretRect.x - extBounds.x) { 409 if (caretRect.x - extBounds.x + completionBounds.width < width) { 410 completionBounds.x = caretRect.x - extBounds.x - width + javadocBounds.width; 411 } else { 412 completionBounds.x = javadocBounds.width - completionBounds.width; 413 } 414 } else { 415 completionBounds.x = 0; 416 } 417 } 418 419 420 completion.setVisible(false); 421 boolean isJavadocVisible = getJavaDocPane().getComponent().isVisible(); 422 if (isJavadocVisible && !showJavaDoc) getJavaDocPane().getComponent().setVisible(false); 423 424 remove(completion.getComponent()); 425 if (javadoc != null) { 426 remove(javadoc.getComponent()); 427 } 428 429 if (showJavaDoc) { 430 if (showCompletion){ 431 completion.getComponent().setBounds(completionBounds); 432 getJavaDocPane().getComponent().setBounds(javadocBounds); 433 super.setBounds(0,0,Math.max(completionBounds.width,javadocBounds.width),completionBounds.height+javadocBounds.height+WINDOW_GAP); 434 add(completion.getComponent()); 435 add(getJavaDocPane().getComponent()); 436 completion.setVisible(true); 437 if (isJavadocVisible) getJavaDocPane().getComponent().setVisible(true); 438 }else{ 439 javadocBounds.x = 0; javadocBounds.y = 0; 440 getJavaDocPane().getComponent().setBounds(javadocBounds); 441 super.setBounds(0,0,javadocBounds.width,javadocBounds.height); 442 add(getJavaDocPane().getComponent()); 443 if (isJavadocVisible) getJavaDocPane().getComponent().setVisible(true); 444 } 445 }else{ 446 completionBounds.x = 0; completionBounds.y = 0; 447 completion.getComponent().setBounds(completionBounds); 448 super.setBounds(0,0,completionBounds.width,completionBounds.height+WINDOW_GAP); 449 add(completion.getComponent()); 450 completion.setVisible(true); 451 } 452 } 453 454 455 public void setSize(Dimension d){ 456 setSize(d.width, d.height); 457 } 458 459 460 public void refresh(){ 461 setVisible(true); 462 } 463 464 private void performJavaDocAction(KeyStroke ks){ 465 ActionListener act = getJavaDocPane().getJavadocDisplayComponent().getActionForKeyStroke(ks); 466 if (act!=null){ 467 act.actionPerformed(new ActionEvent (getJavaDocPane().getJavadocDisplayComponent(), ActionEvent.ACTION_PERFORMED, "")); getJavaDocPane().getJavadocDisplayComponent().repaint(); 469 } 470 } 471 472 473 private KeyStroke [] findEditorKeys(String editorActionName, KeyStroke defaultKey) { 474 KeyStroke [] ret = new KeyStroke [] { defaultKey }; 477 if (editorActionName != null && extEditorUI != null) { 478 JTextComponent component = extEditorUI.getComponent(); 479 if (component != null) { 480 TextUI ui = component.getUI(); 481 Keymap km = component.getKeymap(); 482 if (ui != null && km != null) { 483 EditorKit kit = ui.getEditorKit(component); 484 if (kit instanceof BaseKit) { 485 Action a = ((BaseKit)kit).getActionByName(editorActionName); 486 if (a != null) { 487 KeyStroke [] keys = km.getKeyStrokesForAction(a); 488 if (keys != null && keys.length > 0) { 489 ret = keys; 490 } 491 } 492 } 493 } 494 } 495 } 496 497 return ret; 498 } 499 500 private void registerKeybinding(int action, String actionName, KeyStroke stroke, String editorActionName){ 501 KeyStroke [] keys = findEditorKeys(editorActionName, stroke); 502 for (int i = 0; i < keys.length; i++) { 503 getInputMap().put(keys[i], actionName); 504 keyActionPairsList.add(actionName); keyActionPairsList.add(keys[i]); } 507 508 getActionMap().put(actionName, new JDCPopupAction(action)); 509 } 510 511 private void unregisterKeybinding(String actionName, KeyStroke stroke) { 512 getInputMap().remove(stroke); 513 getActionMap().remove(actionName); 514 } 515 516 private void installKeybindings() { 517 registerKeybinding(ACTION_POPUP_HIDE, POPUP_HIDE, 519 KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), 520 ExtKit.escapeAction 521 ); 522 523 registerKeybinding(ACTION_COMPLETION_UP, COMPLETION_UP, 525 KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), 526 BaseKit.upAction 527 ); 528 529 registerKeybinding(ACTION_COMPLETION_DOWN, COMPLETION_DOWN, 531 KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), 532 BaseKit.downAction 533 ); 534 535 registerKeybinding(ACTION_COMPLETION_PGDN, COMPLETION_PGDN, 537 KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0), 538 BaseKit.pageDownAction 539 ); 540 541 registerKeybinding(ACTION_COMPLETION_PGUP, COMPLETION_PGUP, 543 KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0), 544 BaseKit.pageUpAction 545 ); 546 547 registerKeybinding(ACTION_COMPLETION_BEGIN, COMPLETION_BEGIN, 549 KeyStroke.getKeyStroke(KeyEvent.VK_HOME, 0), 550 BaseKit.beginLineAction 551 ); 552 553 registerKeybinding(ACTION_COMPLETION_END, COMPLETION_END, 555 KeyStroke.getKeyStroke(KeyEvent.VK_END, 0), 556 BaseKit.endLineAction 557 ); 558 559 registerKeybinding(ACTION_JAVADOC_UP, JAVADOC_UP, 561 KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.SHIFT_MASK), 562 null 563 ); 564 565 registerKeybinding(ACTION_JAVADOC_DOWN, JAVADOC_DOWN, 567 KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.SHIFT_MASK), 568 null 569 ); 570 571 registerKeybinding(ACTION_JAVADOC_PGDN, JAVADOC_PGDN, 573 KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, KeyEvent.SHIFT_MASK), 574 null 575 ); 576 577 registerKeybinding(ACTION_JAVADOC_PGUP, JAVADOC_PGUP, 579 KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, KeyEvent.SHIFT_MASK), 580 null 581 ); 582 583 registerKeybinding(ACTION_JAVADOC_BEGIN, JAVADOC_BEGIN, 585 KeyStroke.getKeyStroke(KeyEvent.VK_HOME, KeyEvent.SHIFT_MASK), 586 null 587 ); 588 589 registerKeybinding(ACTION_JAVADOC_END, JAVADOC_END, 591 KeyStroke.getKeyStroke(KeyEvent.VK_END, KeyEvent.SHIFT_MASK), 592 null 593 ); 594 595 registerKeybinding(ACTION_JAVADOC_LEFT, JAVADOC_LEFT, 597 KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.SHIFT_MASK), 598 null 599 ); 600 601 registerKeybinding(ACTION_JAVADOC_RIGHT, JAVADOC_RIGHT, 603 KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.SHIFT_MASK), 604 null 605 ); 606 607 registerKeybinding(ACTION_JAVADOC_BACK, JAVADOC_BACK, 609 KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.ALT_MASK), 610 null 611 ); 612 613 registerKeybinding(ACTION_JAVADOC_FORWARD, JAVADOC_FORWARD, 615 KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.ALT_MASK), 616 null 617 ); 618 619 registerKeybinding(ACTION_JAVADOC_OPEN_IN_BROWSER, JAVADOC_OPEN_IN_BROWSER, 621 KeyStroke.getKeyStroke(KeyEvent.VK_F1, KeyEvent.ALT_MASK | KeyEvent.SHIFT_MASK), 622 null 623 ); 624 625 registerKeybinding(ACTION_JAVADOC_OPEN_SOURCE, JAVADOC_OPEN_SOURCE, 627 KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.ALT_MASK | KeyEvent.CTRL_MASK), 628 null 629 ); 630 631 registerKeybinding(ACTION_COMPLETION_SUBSTITUTE_TEXT, COMPLETION_SUBSTITUTE_TEXT, 633 KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), 634 null 635 ); 636 637 registerKeybinding(ACTION_COMPLETION_SUBSTITUTE_TEXT_SIMPLE, COMPLETION_SUBSTITUTE_TEXT_SIMPLE, 639 KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.CTRL_MASK), 640 null 641 ); 642 643 registerKeybinding(ACTION_COMPLETION_SUBSTITUTE_TEXT_KEEP_POPUP_OPEN, COMPLETION_SUBSTITUTE_TEXT_KEEP_POPUP_OPEN, 645 KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.SHIFT_MASK), 646 null 647 ); 648 649 registerKeybinding(ACTION_COMPLETION_SUBSTITUTE_COMMON_TEXT, COMPLETION_SUBSTITUTE_COMMON_TEXT, 651 KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), 652 null 653 ); 654 655 } 656 657 private void uninstallKeybindings() { 658 for (Iterator it = keyActionPairsList.iterator(); it.hasNext();) { 659 unregisterKeybinding( 660 (String )it.next(), (KeyStroke )it.next() ); 663 } 664 keyActionPairsList.clear(); 665 } 666 667 668 public void propertyChange(PropertyChangeEvent evt) { 669 String propName = evt.getPropertyName(); 670 671 if (ExtEditorUI.COMPONENT_PROPERTY.equals(propName)) { 672 if (evt.getNewValue() != null) { JTextComponent component = extEditorUI.getComponent(); 674 installKeybindings(); 675 component.addFocusListener(focusL); 676 677 } else { JTextComponent component = (JTextComponent )evt.getOldValue(); 679 uninstallKeybindings(); 680 component.removeFocusListener(focusL); 681 } 682 683 } 684 } 685 686 public void settingsChange(SettingsChangeEvent evt) { 687 uninstallKeybindings(); 689 installKeybindings(); 690 } 691 692 private class JDCPopupAction extends AbstractAction { 693 private int action; 694 695 private JDCPopupAction(int action) { 696 this.action = action; 697 } 698 699 public void actionPerformed(java.awt.event.ActionEvent actionEvent) { 700 switch (action) { 701 case ACTION_POPUP_HIDE: 702 setVisible(false); 703 break; 704 case ACTION_COMPLETION_UP: 705 if (completion.isVisible()){ 706 getCompletionView().up(); 707 }else{ 708 performJavaDocAction(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0)); 709 } 710 break; 711 case ACTION_COMPLETION_DOWN: 712 if (completion.isVisible()){ 713 getCompletionView().down(); 714 }else { 715 performJavaDocAction(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0)); 716 } 717 break; 718 case ACTION_COMPLETION_PGUP: 719 if (completion.isVisible()){ 720 getCompletionView().pageUp(); 721 } else{ 722 performJavaDocAction(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0)); 723 } 724 break; 725 case ACTION_COMPLETION_PGDN: 726 if (completion.isVisible()){ 727 getCompletionView().pageDown(); 728 }else{ 729 performJavaDocAction(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0)); 730 } 731 break; 732 case ACTION_COMPLETION_BEGIN: 733 if (completion.isVisible()){ 734 getCompletionView().begin(); 735 }else{ 736 performJavaDocAction(KeyStroke.getKeyStroke(KeyEvent.VK_HOME, 0)); 737 } 738 break; 739 case ACTION_COMPLETION_END: 740 if (completion.isVisible()){ 741 getCompletionView().end(); 742 }else{ 743 performJavaDocAction(KeyStroke.getKeyStroke(KeyEvent.VK_END, 0)); 744 } 745 break; 746 case ACTION_JAVADOC_UP: 747 performJavaDocAction(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0)); 748 break; 749 case ACTION_JAVADOC_DOWN: 750 performJavaDocAction(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0)); 751 break; 752 case ACTION_JAVADOC_PGUP: 753 performJavaDocAction(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0)); 754 break; 755 case ACTION_JAVADOC_PGDN: 756 performJavaDocAction(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0)); 757 break; 758 case ACTION_JAVADOC_BEGIN: 759 performJavaDocAction(KeyStroke.getKeyStroke(KeyEvent.VK_HOME, 0)); 760 break; 761 case ACTION_JAVADOC_END: 762 performJavaDocAction(KeyStroke.getKeyStroke(KeyEvent.VK_END, 0)); 763 break; 764 case ACTION_JAVADOC_LEFT: 765 performJavaDocAction(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0)); 766 break; 767 case ACTION_JAVADOC_RIGHT: 768 performJavaDocAction(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0)); 769 break; 770 case ACTION_JAVADOC_BACK: { 771 CompletionJavaDoc cjd = extEditorUI.getCompletionJavaDoc(); 772 if (cjd!=null){ 773 cjd.backHistory(); 774 } 775 } 776 break; 777 case ACTION_JAVADOC_FORWARD: { 778 CompletionJavaDoc cjd = extEditorUI.getCompletionJavaDoc(); 779 if (cjd!=null){ 780 cjd.forwardHistory(); 781 } 782 } 783 break; 784 case ACTION_JAVADOC_OPEN_IN_BROWSER: { 785 CompletionJavaDoc cjd = extEditorUI.getCompletionJavaDoc(); 786 if (cjd!=null && cjd.isExternalJavaDocMounted()){ 787 cjd.openInExternalBrowser(); 788 } 789 } 790 break; 791 case ACTION_JAVADOC_OPEN_SOURCE: { 792 CompletionJavaDoc cjd = extEditorUI.getCompletionJavaDoc(); 793 if (cjd!=null){ 794 cjd.goToSource(); 795 } 796 } 797 break; 798 case ACTION_COMPLETION_SUBSTITUTE_TEXT: { 799 Completion cc = extEditorUI.getCompletion(); 800 if (cc != null && cc.isPaneVisible()) { 801 if (cc.substituteText(false)) { 802 cc.setPaneVisible(false); 803 } else { 804 cc.refresh(false); 805 } 806 } 807 } 808 break; 809 case ACTION_COMPLETION_SUBSTITUTE_TEXT_SIMPLE: { 810 Completion cc = extEditorUI.getCompletion(); 811 if (cc != null && cc.isPaneVisible()) { 812 if (cc.substituteSimpleText()) { 813 cc.setPaneVisible(false); 814 } else { 815 cc.refresh(false); 816 } 817 } 818 } 819 break; 820 case ACTION_COMPLETION_SUBSTITUTE_TEXT_KEEP_POPUP_OPEN: { 821 Completion cc = extEditorUI.getCompletion(); 822 if (cc != null && cc.isPaneVisible()) { 823 if (cc.substituteText( true )) { 824 } else { 825 cc.refresh(false); 826 } 827 } 828 } 829 break; 830 case ACTION_COMPLETION_SUBSTITUTE_COMMON_TEXT: { 831 Completion cc = extEditorUI.getCompletion(); 832 if (cc != null && cc.isPaneVisible()) { 833 cc.refresh(false); 834 cc.substituteCommonText(); 835 } 836 } 837 break; 838 839 } 840 } 841 842 } 843 844 845 846 } 847 | Popular Tags |