1 21 22 package org.armedbear.j; 23 24 import java.awt.Cursor ; 25 import java.awt.Dimension ; 26 import java.awt.Insets ; 27 import java.awt.Rectangle ; 28 import java.awt.Toolkit ; 29 import java.awt.event.ComponentEvent ; 30 import java.awt.event.ComponentListener ; 31 import java.awt.event.FocusEvent ; 32 import java.awt.event.FocusListener ; 33 import java.awt.event.KeyEvent ; 34 import java.awt.event.WindowEvent ; 35 import java.awt.event.WindowListener ; 36 import java.awt.event.WindowStateListener ; 37 import java.lang.reflect.Method ; 38 import javax.swing.JButton ; 39 import javax.swing.JComponent ; 40 import javax.swing.JFrame ; 41 import javax.swing.SwingUtilities ; 42 43 public final class Frame extends JFrame implements Constants, ComponentListener , 44 FocusListener , WindowListener , WindowStateListener 45 { 46 private Editor[] editors = new Editor[2]; 47 private Editor currentEditor; 48 private ToolBar toolbar; 49 private boolean showToolbar; 50 private AdjustPlacementRunnable adjustPlacementRunnable; 51 private Rectangle rect; 52 private int extendedState; 53 54 public Frame(Editor editor) 55 { 56 Editor.frames.add(this); 57 addComponentListener(this); 58 addWindowListener(this); 59 addFocusListener(this); 60 addWindowStateListener(this); 61 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); 62 statusBar = new StatusBar(this); 63 getContentPane().add(statusBar, "South"); 64 final SessionProperties sessionProperties = 65 Editor.getSessionProperties(); 66 showToolbar = sessionProperties.getShowToolbar(this); 67 currentEditor = editors[0] = editor; 68 if (sessionProperties.getShowSidebar(this)) { 69 sidebar = new Sidebar(this); 70 sidebarSplitPane = createSidebarSplitPane(); 71 getContentPane().add(sidebarSplitPane, "Center"); 72 } else 73 getContentPane().add(editors[0], "Center"); 74 titleChanged(); 75 } 76 77 public void titleChanged() 78 { 79 FastStringBuffer sb = 80 new FastStringBuffer(Version.getShortVersionString()); 81 String sessionName = Editor.getSessionName(); 82 if (sessionName != null) { 83 sb.append(" ["); 84 sb.append(sessionName); 85 sb.append(']'); 86 } 87 if (Editor.isDebugEnabled()) { 88 sb.append(" Java "); 89 sb.append(System.getProperty("java.version")); 90 sb.append(' '); 91 sb.append(System.getProperty("java.vendor")); 92 } 93 setTitle(sb.toString()); 94 } 95 96 public void storeExtendedState(int state) 97 { 98 extendedState = state; 99 } 100 101 public int retrieveExtendedState() 102 { 103 return extendedState; 104 } 105 106 public Rectangle getRect() 107 { 108 return rect; 109 } 110 111 protected void processEvent(java.awt.AWTEvent e) 112 { 113 if (!(e instanceof KeyEvent )) 114 super.processEvent(e); 115 } 116 117 public int getEditorCount() 118 { 119 int count = 0; 120 if (editors[0] != null) 121 ++count; 122 if (editors[1] != null) 123 ++count; 124 return count; 125 } 126 127 public Editor getEditor() 128 { 129 return editors[0]; 130 } 131 132 public final Editor getCurrentEditor() 133 { 134 return currentEditor; 135 } 136 137 public final Editor getOtherEditor() 139 { 140 return currentEditor == editors[0] ? editors[1] : editors[0]; 141 } 142 143 public final void setCurrentEditor(Editor editor) 144 { 145 Debug.assertTrue(editor != null); 146 Debug.assertTrue(editor == editors[0] || editor == editors[1]); 147 currentEditor = editor; 148 } 149 150 public final Editor getPrimaryEditor() 151 { 152 return editors[0]; 153 } 154 155 public final Editor getSecondaryEditor() 156 { 157 return editors[1]; 158 } 159 160 public final boolean isPrimaryEditor(Editor ed) 161 { 162 return ed != null && ed == editors[0]; 163 } 164 165 public final boolean contains(Editor ed) 166 { 167 return ed != null && (ed == editors[0] || ed == editors[1]); 168 } 169 170 public void updateTitle() 171 { 172 if (editors[0] != null) 173 editors[0].updateLocation(); 174 if (editors[1] != null) 175 editors[1].updateLocation(); 176 } 177 178 private Sidebar sidebar; 179 180 public final Sidebar getSidebar() 181 { 182 return sidebar; 183 } 184 185 private SplitPane sidebarSplitPane; 186 187 public final SplitPane getSidebarSplitPane() 188 { 189 return sidebarSplitPane; 190 } 191 192 private SplitPane createSidebarSplitPane() 193 { 194 SplitPane splitPane = 195 new SplitPane(SplitPane.HORIZONTAL_SPLIT, 196 sidebar, getEditorPane()); 197 int dividerLocation = 198 Editor.getSessionProperties().getSidebarWidth(this); 199 splitPane.setDividerLocation(dividerLocation); 200 splitPane.setBorder(null); 201 return splitPane; 202 } 203 204 private void addSidebar() 205 { 206 if (sidebarSplitPane != null) 207 getContentPane().remove(sidebarSplitPane); 208 sidebar = new Sidebar(this); 209 sidebarSplitPane = createSidebarSplitPane(); 210 getContentPane().add(sidebarSplitPane, "Center"); 211 validate(); 212 currentEditor.setFocusToDisplay(); 213 sidebar.setUpdateFlag(SIDEBAR_ALL); 214 } 215 216 private JComponent editorPane; 217 218 public final JComponent getEditorPane() 219 { 220 if (editorPane != null) 221 return editorPane; 222 else 223 return editors[0]; 224 } 225 226 public void frameToggleSidebar() 227 { 228 if (sidebar == null) { 229 getContentPane().remove(getEditorPane()); 231 addSidebar(); 232 } else { 233 Editor.getSessionProperties().saveSidebarState(this); 235 getContentPane().remove(sidebarSplitPane); 237 sidebarSplitPane = null; 238 sidebar = null; 239 getContentPane().add(getEditorPane(), "Center"); 240 } 241 validate(); 242 editors[0].updateScrollBars(); 243 if (editors[1] != null) 244 editors[1].updateScrollBars(); 245 currentEditor.setFocusToDisplay(); 246 } 247 248 private StatusBar statusBar; 249 250 public final StatusBar getStatusBar() 251 { 252 return statusBar; 253 } 254 255 public void repaintStatusBar() 256 { 257 if (statusBar != null) 258 statusBar.repaint(); 259 } 260 261 public void setStatusText(String text) 262 { 263 if (statusBar != null && text != null && !text.equals(statusBar.getText())) { 264 statusBar.setText(text); 265 statusBar.repaintNow(); 266 } 267 } 268 269 public boolean getShowToolbar() 270 { 271 return showToolbar; 272 } 273 274 public void setToolbar() 275 { 276 if (showToolbar && ToolBar.isToolBarEnabled()) { 277 ToolBar tb = currentEditor.getMode().getToolBar(this); 279 if (tb != toolbar) { 280 if (toolbar != null) { 281 getContentPane().remove(toolbar); 282 toolbar = null; 283 } 284 if (tb != null) { 285 getContentPane().add(toolbar = tb, "North"); 286 toolbar.repaint(); 287 } 288 getContentPane().validate(); 289 } 290 } else { 291 if (toolbar != null) { 293 getContentPane().remove(toolbar); 294 getContentPane().validate(); 295 } 296 } 297 } 298 299 public void frameToggleToolbar() 300 { 301 showToolbar = !showToolbar; 302 if (toolbar != null) { 303 if (!showToolbar) { 304 getContentPane().remove(toolbar); 305 toolbar = null; 306 getContentPane().validate(); 307 } 308 } else { 309 if (showToolbar && ToolBar.isToolBarEnabled()) { 310 ToolBar tb = currentEditor.getMode().getToolBar(this); 311 if (tb != null) { 312 getContentPane().add(toolbar = tb, "North"); 313 toolbar.repaint(); 314 getContentPane().validate(); 315 } 316 } 317 } 318 Editor.getSessionProperties().setShowToolbar(this, showToolbar); 320 } 321 322 private ToolBar defaultToolBar; 323 324 public ToolBar getDefaultToolBar() 325 { 326 if (defaultToolBar == null) 327 defaultToolBar = new DefaultToolBar(this); 328 329 return defaultToolBar; 330 } 331 332 public void addToolbar(ToolBar tb) 333 { 334 Debug.assertTrue(toolbar == null); 335 if (tb != null) { 336 toolbar = tb; 337 getContentPane().add(toolbar, "North"); 338 toolbar.repaint(); 339 } 340 Runnable r = new Runnable () { 342 public void run() 343 { 344 JComponent c = getFocusedComponent(); 345 if (c != null) 346 c.requestFocus(); 347 } 348 }; 349 SwingUtilities.invokeLater(r); 350 } 351 352 public void maybeAddToolbar() 353 { 354 if (toolbar != null) 355 return; 356 ToolBar tb = currentEditor.getMode().getToolBar(this); 357 if (tb != null) 358 addToolbar(tb); 359 } 360 361 public void removeToolbar() 362 { 363 if (toolbar != null) { 364 getContentPane().remove(toolbar); 365 toolbar = null; 366 getContentPane().validate(); 367 } 368 } 369 370 public void setMenu() 371 { 372 final Mode mode = currentEditor.getMode(); 373 final MenuBar oldMenuBar = (MenuBar) getJMenuBar(); 374 if (oldMenuBar == null || oldMenuBar.getMenuName() != mode.getMenuName()) { 375 setJMenuBar(mode.createMenuBar(this)); 376 validate(); 377 } 378 } 379 380 public void placeWindow() 381 { 382 final SessionProperties sessionProperties = 383 Editor.getSessionProperties(); 384 if (editors[0] == Editor.getEditor(0)) { 385 Rectangle desired = sessionProperties.getWindowPlacement(0); 387 if (desired.width == 0 || desired.height == 0) { 388 Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); 390 desired.width = dim.width - 100; 391 if (desired.width > 800) 392 desired.width = 800; 393 desired.height = dim.height - 100; 394 desired.x = (dim.width - desired.width) / 2; 395 desired.y = (dim.height - desired.height) / 2; 396 } 397 int extendedState = sessionProperties.getExtendedState(0); 398 adjustPlacementRunnable = 399 new AdjustPlacementRunnable(this, extendedState); 400 setBounds(desired); 401 } else { 402 Rectangle desired = sessionProperties.getWindowPlacement(1); 404 if (desired.width == 0 || desired.height == 0) { 405 desired = Editor.getCurrentFrame().getBounds(); 407 Insets insets = Editor.getCurrentFrame().getInsets(); 408 desired.x += insets.left; 409 desired.width -= insets.left; 410 desired.y += insets.top; 411 desired.height -= insets.top; 412 } 413 setBounds(desired); 414 int extendedState = sessionProperties.getExtendedState(1); 415 if (extendedState != 0) 416 setExtendedState(extendedState); 417 } 418 } 419 420 public void splitWindow() 421 { 422 if (editors[1] == null) { 423 Editor.getSessionProperties().saveSidebarState(this); 424 final int height = editors[0].getHeight(); 425 editors[0].saveView(); 426 editors[1] = new Editor(this); 427 editors[1].activate(editors[0].getBuffer()); 428 editors[1].updateLocation(); 429 SplitPane sp = new SplitPane(SplitPane.VERTICAL_SPLIT, 430 editors[0], editors[1]); 431 sp.setBorder(null); 432 sp.setDividerLocation(height / 2); 433 editorPane = sp; 434 if (sidebar != null) { 435 sidebarSplitPane.setRightComponent(editorPane); 436 int dividerLocation = 437 Editor.getSessionProperties().getSidebarWidth(this); 438 sidebarSplitPane.setDividerLocation(dividerLocation); 439 } else { 440 getContentPane().remove(editors[0]); 442 getContentPane().add(editorPane, "Center"); 443 } 444 validate(); 445 editors[0].setUpdateFlag(REFRAME); 446 editors[1].updateDisplay(); 447 restoreFocus(); 448 updateControls(); 449 } 450 } 451 452 public void switchToBuffer(final Buffer buf) 453 { 454 Debug.bugIfNot(buf.isPaired() || 455 (getEditorCount() == 2 && editors[0].getBuffer().isPaired())); 456 final Buffer primary; 457 final Buffer secondary; 458 if (buf.isPrimary()) { 459 primary = buf; 460 secondary = buf.getSecondary(); 461 } else { 462 Debug.bugIfNot(buf.isSecondary()); 463 primary = buf.getPrimary(); 464 Debug.bugIfNot(primary != null); 465 secondary = buf; 466 } 467 if (getEditorCount() == 2) { 468 if (secondary != null) { 470 if (editors[0].getBuffer() != primary) 473 editors[0].activate(primary); 474 if (editors[1].getBuffer() != secondary) 475 editors[1].activate(secondary); 476 if (editorPane instanceof SplitPane) { 478 SplitPane sp = (SplitPane) editorPane; 479 int height = sp.getHeight(); 480 float split = secondary.getSplit(); 481 int dividerLocation = 482 (int)(height * (1 - split) - sp.getDividerSize()); 483 sp.setDividerLocation(dividerLocation); 484 } 485 Editor.setCurrentEditor(buf == primary ? editors[0] : editors[1]); 486 editors[0].updateDisplay(); 487 editors[1].updateDisplay(); 488 } else { 489 Debug.bugIfNot(secondary == null); 491 Editor keep = editors[0]; 493 Editor kill = editors[1]; 494 final Buffer b = kill.getBuffer(); 497 if (b != null) { 498 b.autosave(); 499 kill.saveView(); 500 RecentFiles.getInstance().bufferDeactivated(b, 501 kill.getDot()); 502 b.windowClosing(); 503 } 504 unsplitInternal(keep, kill); 505 Debug.bugIfNot(editors[0] == keep); 507 keep.activate(primary); 508 } 509 } else { 510 Debug.bugIfNot(getEditorCount() == 1); 512 if (secondary != null) { 513 splitWindow(primary, secondary, secondary.getSplit()); 516 Editor.setCurrentEditor(buf == primary ? editors[0] : editors[1]); 517 editors[0].updateDisplay(); 518 editors[1].updateDisplay(); 519 restoreFocus(); 520 } else { 521 Debug.bugIfNot(editors[0] != null); 523 Debug.bugIfNot(editors[1] == null); 524 Debug.bugIfNot(secondary == null); 525 editors[0].activate(primary); 527 } 528 } 529 buf.setLastActivated(System.currentTimeMillis()); 530 if (Editor.isDebugEnabled()) { 531 if (buf.isPrimary()) { 532 Debug.bugIfNot(getPrimaryEditor().getBuffer() == buf); 533 } else { 534 Debug.bugIfNot(buf.isSecondary()); 535 Buffer bufPrimary = buf.getPrimary(); 536 Debug.bugIfNot(primary != null); 537 Debug.bugIfNot(getPrimaryEditor().getBuffer() == bufPrimary); 538 } 539 } 540 } 541 542 public void splitWindow(Buffer buf1, Buffer buf2, float split) 543 { 544 if (editors[1] == null) { 545 final SessionProperties sessionProperties = 546 Editor.getSessionProperties(); 547 sessionProperties.saveSidebarState(this); 548 final int height = editors[0].getHeight(); 549 editors[0].saveView(); 550 editors[0].activate(buf1); 551 editors[1] = new Editor(this); 552 editors[1].activate(buf2); 553 editors[1].updateLocation(); 554 SplitPane sp = new SplitPane(SplitPane.VERTICAL_SPLIT, 555 editors[0], editors[1]); 556 sp.setBorder(null); 557 int dividerLocation = 558 (int)(height * (1 - split) - sp.getDividerSize()); 559 sp.setDividerLocation(dividerLocation); 560 editorPane = sp; 561 if (sidebar != null) { 562 sidebarSplitPane.setRightComponent(editorPane); 563 dividerLocation = sessionProperties.getSidebarWidth(this); 564 sidebarSplitPane.setDividerLocation(dividerLocation); 565 } else { 566 getContentPane().remove(editors[0]); 568 getContentPane().add(editorPane, "Center"); 569 } 570 validate(); 571 editors[0].setUpdateFlag(REFRAME | REPAINT); 572 editors[1].setUpdateFlag(REFRAME | REPAINT); 573 updateControls(); 574 } 575 } 576 577 public final Editor activateInOtherWindow(Editor editor, Buffer buffer) 578 { 579 return openInOtherWindow(editor, buffer, 0.5F, true); 581 } 582 583 public final Editor activateInOtherWindow(Editor editor, Buffer buffer, 584 float split) 585 { 586 return openInOtherWindow(editor, buffer, split, true); 588 } 589 590 public final Editor displayInOtherWindow(Editor editor, Buffer buffer) 591 { 592 return openInOtherWindow(editor, buffer, 0.5F, false); 594 } 595 596 private Editor openInOtherWindow(Editor editor, Buffer buffer, float split, 597 boolean switchWindows) 598 { 599 editor.saveView(); 600 Editor otherEditor = null; 601 if (editors[1] == null) { 602 Debug.assertTrue(editor == editors[0]); 603 editors[1] = new Editor(this); 604 editors[1].activate(buffer); 605 editors[1].updateLocation(); 606 SplitPane sp = new SplitPane(SplitPane.VERTICAL_SPLIT, 607 editor, editors[1]); 608 sp.setBorder(null); 609 int dividerLocation = 610 (int)(editor.getHeight() * (1 - split) - sp.getDividerSize()); 611 sp.setDividerLocation(dividerLocation); 612 editorPane = sp; 613 if (sidebar != null) { 614 sidebarSplitPane.setRightComponent(editorPane); 615 sidebarSplitPane.setDividerLocation( 616 Editor.getSessionProperties().getSidebarWidth(this)); 617 } else { 618 getContentPane().remove(editor); 620 getContentPane().add(editorPane, "Center"); 621 } 622 validate(); 623 otherEditor = editors[1]; 624 } else { 625 if (editor == editors[0]) 627 otherEditor = editors[1]; 628 else if (editor == editors[1]) 629 otherEditor = editors[0]; 630 else 631 Debug.assertTrue(false); 632 otherEditor.activate(buffer); 633 otherEditor.updateLocation(); 634 } 635 if (switchWindows) { 636 Editor.setCurrentEditor(otherEditor); 637 setMenu(); 638 setToolbar(); 639 } 640 editors[0].setUpdateFlag(REFRAME | REPAINT); 641 editors[0].updateDisplay(); 642 editors[1].setUpdateFlag(REFRAME | REPAINT); 643 editors[1].updateDisplay(); 644 currentEditor.setFocusToDisplay(); 645 restoreFocus(); 646 updateControls(); 647 return otherEditor; 648 } 649 650 public void closeEditor(Editor editor) 651 { 652 if (editors[1] == null) 653 return; 654 if (editor != editors[0] && editor != editors[1]) 655 return; 656 promoteSecondaryBuffers(); 657 Editor keep = editor == editors[0] ? editors[1] : editors[0]; 658 Editor kill = editor; 659 unsplitInternal(keep, kill); 660 } 661 662 public void unsplitWindow() 663 { 664 if (editors[1] == null) 665 return; 666 promoteSecondaryBuffers(); 667 Editor keep = currentEditor; 668 Editor kill = getOtherEditor(); 669 unsplitInternal(keep, kill); 670 } 671 672 public void unsplitWindowKeepOther() 673 { 674 if (editors[1] == null) 675 return; 676 promoteSecondaryBuffers(); 677 Editor keep = getOtherEditor(); 678 Editor kill = currentEditor; 679 unsplitInternal(keep, kill); 680 } 681 682 public void promoteSecondaryBuffers() 683 { 684 Buffer buffer = editors[0].getBuffer(); 685 if (buffer.isSecondary()) 686 buffer.promote(); 687 if (editors[1] != null) { 688 buffer = editors[1].getBuffer(); 689 if (buffer.isSecondary()) 690 buffer.promote(); 691 } 692 } 693 694 private void unsplitInternal(final Editor keep, final Editor kill) 695 { 696 Editor.getSessionProperties().saveSidebarState(this); 697 if (sidebar != null) { 698 sidebarSplitPane.setRightComponent(keep); 699 int dividerLocation = 700 Editor.getSessionProperties().getSidebarWidth(this); 701 sidebarSplitPane.setDividerLocation(dividerLocation); 702 } else { 703 getContentPane().remove(editorPane); 705 getContentPane().add(keep, "Center"); 706 } 707 validate(); 708 editorPane = null; 709 Editor.removeEditor(kill); 710 editors[0] = keep; 711 editors[1] = null; 712 Buffer buffer = keep.getBuffer(); 713 if (buffer.isSecondary()) 714 buffer.promote(); 715 Editor.setCurrentEditor(keep); 716 keep.setUpdateFlag(REFRAME); 717 keep.reframe(); 718 restoreFocus(); 719 statusBar.repaint(); 720 updateControls(); 721 } 722 723 public void updateControls() 724 { 725 boolean enable = editors[1] != null; 726 LocationBar locationBar = editors[0].getLocationBar(); 727 if (locationBar != null) { 728 JButton closeButton = locationBar.getCloseButton(); 729 if (closeButton != null) 730 closeButton.setEnabled(enable); 731 } 732 if (editors[1] != null) { 733 locationBar = editors[1].getLocationBar(); 734 if (locationBar != null) { 735 JButton closeButton = locationBar.getCloseButton(); 736 if (closeButton != null) 737 closeButton.setEnabled(enable); 738 } 739 } 740 } 741 742 private boolean active; 743 744 public final boolean isActive() 745 { 746 return active; 747 } 748 749 public void reactivate() 750 { 751 if (currentEditor.getBuffer() == null) 752 return; 753 boolean changed = false; 754 for (BufferIterator it = new BufferIterator(); it.hasNext();) { 755 if (currentEditor.reactivate(it.nextBuffer())) 756 changed = true; 757 } 758 if (changed) { 759 for (int i = 0; i < Editor.getFrameCount(); i++) { 760 Frame frame = Editor.getFrame(i); 761 frame.setMenu(); 762 } 763 Sidebar.repaintBufferListInAllFrames(); 764 } 765 } 766 767 public void windowActivated(WindowEvent e) 768 { 769 active = true; 770 Editor.setCurrentEditor(currentEditor); 771 setFocus(currentEditor.getDisplay()); 772 repaint(); 773 Runnable r = new Runnable () { 775 public void run() 776 { 777 reactivate(); 778 } 779 }; 780 SwingUtilities.invokeLater(r); 781 } 782 783 public void windowDeactivated(WindowEvent e) 784 { 785 active = false; 786 editors[0].repaint(); 788 if (editors[1] != null) 789 editors[1].repaint(); 790 } 791 792 public void windowOpened(WindowEvent e) 793 { 794 if (adjustPlacementRunnable != null) { 795 adjustPlacementRunnable.run(); 796 adjustPlacementRunnable = null; 797 } 798 } 799 800 public void windowClosing(WindowEvent e) 801 { 802 editors[0].killFrame(); 803 } 804 805 public void windowClosed(WindowEvent e) 806 { 807 } 808 809 public void windowIconified(WindowEvent e) 810 { 811 } 812 813 public void windowDeiconified(WindowEvent e) 814 { 815 } 816 817 public void windowStateChanged(WindowEvent e) 818 { 819 int newState = e.getNewState(); 820 if (newState == 0) { 821 if (rect != null) 823 setBounds(rect); 824 } 825 storeExtendedState(newState); 826 } 827 828 private JComponent focusedComponent; 829 830 public void setFocus(JComponent c) 831 { 832 boolean change = focusedComponent != c; 833 if (c != null) 834 c.requestFocus(); 835 if (change) { 836 JComponent lastFocusedComponent = focusedComponent; 837 focusedComponent = c; 838 for (int i = 0; i < editors.length; i++) { 841 Editor editor = editors[i]; 842 if (editor != null && editor.getDot() != null) { 843 Display display = editor.getDisplay(); 844 if (display == focusedComponent || display == lastFocusedComponent) { 845 editor.updateDotLine(); 846 display.repaintChangedLines(); 847 } 848 } 849 } 850 } 851 } 852 853 public JComponent getFocusedComponent() 854 { 855 return focusedComponent; 856 } 857 858 private static final Cursor waitCursor = 859 Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR); 860 861 public final void setWaitCursor() 862 { 863 setCursor(waitCursor); 864 editors[0].setWaitCursor(); 865 if (editors[1] != null) 866 editors[1].setWaitCursor(); 867 } 868 869 public final void setDefaultCursor() 870 { 871 setCursor(Cursor.getDefaultCursor()); 872 editors[0].setDefaultCursor(); 873 if (editors[1] != null) 874 editors[1].setDefaultCursor(); 875 } 876 877 public void resetDisplay() 878 { 879 if (toolbar != null) { 880 getContentPane().remove(toolbar); 881 toolbar = null; 882 } 883 defaultToolBar = null; 884 for (int i = 0; i < editors.length; i++) { 885 Editor editor = editors[i]; 886 if (editor != null) { 887 editor.removeLocationBar(); 888 editor.removeVerticalScrollBar(); 889 editor.removeHorizontalScrollBar(); 890 } 891 } 892 DefaultLookAndFeel.setLookAndFeel(); 893 final Mode mode = currentEditor.getMode(); 894 setJMenuBar(mode.createMenuBar(this)); 895 final SessionProperties sessionProperties = Editor.getSessionProperties(); 896 if (sessionProperties.getShowToolbar(this) && ToolBar.isToolBarEnabled()) { 897 ToolBar tb = mode.getToolBar(this); 898 if (tb != null) 899 addToolbar(tb); 900 } 901 if (sidebarSplitPane != null) { 902 sessionProperties.saveSidebarState(this); 904 getContentPane().remove(sidebarSplitPane); 906 sidebarSplitPane = null; 907 sidebar = null; 908 909 if (Platform.isJava14()) { 910 918 getContentPane().add(getEditorPane(), "Center"); 920 currentEditor.getDisplay().requestFocus(); 921 getContentPane().remove(getEditorPane()); 922 } 923 924 sidebar = new Sidebar(this); 925 sidebarSplitPane = createSidebarSplitPane(); 926 getContentPane().add(sidebarSplitPane, "Center"); 927 sidebar.setUpdateFlag(SIDEBAR_ALL); 928 } 929 for (int i = 0; i < editors.length; i++) { 930 Editor editor = editors[i]; 931 if (editor != null) { 932 editor.addLocationBar(); 933 editor.updateLocation(); 934 editor.addVerticalScrollBar(); 935 editor.addHorizontalScrollBar(); 936 editor.getDisplay().initialize(); 937 } 938 } 939 updateControls(); 940 validate(); 941 } 942 943 public static final void restoreFocus() 944 { 945 Editor.restoreFocus(); 946 } 947 948 private Object folderTree; 949 950 public final Object getFolderTree() 951 { 952 return folderTree; 953 } 954 955 public final void setFolderTree(Object obj) 956 { 957 folderTree = obj; 958 } 959 960 public void componentResized(ComponentEvent e) 961 { 962 if (extendedState != 6) { 963 rect = getBounds(); 965 } 966 } 967 968 public void componentMoved(ComponentEvent e) 969 { 970 if (extendedState != 6) { 971 rect = getBounds(); 973 } 974 } 975 976 public void componentShown(ComponentEvent e) {} 977 978 public void componentHidden(ComponentEvent e) {} 979 980 public void focusGained(FocusEvent e) 981 { 982 currentEditor.setFocusToDisplay(); 983 } 984 985 public void focusLost(FocusEvent e) {} 986 } 987 | Popular Tags |