PageRenderTime 51ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/jEdit/tags/jedit-4-2-pre4/org/gjt/sp/jedit/View.java

#
Java | 1670 lines | 990 code | 216 blank | 464 comment | 203 complexity | 0b0155a9a9f3cf590e1bd42ace047363 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * View.java - jEdit view
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 1998, 2003 Slava Pestov
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. */
  22. package org.gjt.sp.jedit;
  23. //{{{ Imports
  24. import javax.swing.event.*;
  25. import javax.swing.text.*;
  26. import javax.swing.*;
  27. import java.awt.*;
  28. import java.awt.event.*;
  29. import java.io.IOException;
  30. import java.net.Socket;
  31. import java.util.*;
  32. import org.gjt.sp.jedit.msg.*;
  33. import org.gjt.sp.jedit.gui.*;
  34. import org.gjt.sp.jedit.search.*;
  35. import org.gjt.sp.jedit.textarea.*;
  36. import org.gjt.sp.util.Log;
  37. //}}}
  38. /**
  39. * A <code>View</code> is jEdit's top-level frame window.<p>
  40. *
  41. * In a BeanShell script, you can obtain the current view instance from the
  42. * <code>view</code> variable.<p>
  43. *
  44. * The largest component it contains is an {@link EditPane} that in turn
  45. * contains a {@link org.gjt.sp.jedit.textarea.JEditTextArea} that displays a
  46. * {@link Buffer}.
  47. * A view can have more than one edit pane in a split window configuration.
  48. * A view also contains a menu bar, an optional toolbar and other window
  49. * decorations, as well as docked windows.<p>
  50. *
  51. * The <b>View</b> class performs two important operations
  52. * dealing with plugins: creating plugin menu items, and managing dockable
  53. * windows.
  54. *
  55. * <ul>
  56. * <li>When a view is being created, its initialization routine
  57. * iterates through the collection of loaded plugins and constructs the
  58. * <b>Plugins</b> menu using the properties as specified in the
  59. * {@link EditPlugin} class.</li>
  60. * <li>The view also creates and initializes a
  61. * {@link org.gjt.sp.jedit.gui.DockableWindowManager}
  62. * object. This object is
  63. * responsible for creating, closing and managing dockable windows.</li>
  64. * </ul>
  65. *
  66. * This class does not have a public constructor.
  67. * Views can be opened and closed using methods in the <code>jEdit</code>
  68. * class.
  69. *
  70. * @see org.gjt.sp.jedit.jEdit#newView(View)
  71. * @see org.gjt.sp.jedit.jEdit#newView(View,Buffer)
  72. * @see org.gjt.sp.jedit.jEdit#newView(View,Buffer,boolean)
  73. * @see org.gjt.sp.jedit.jEdit#closeView(View)
  74. *
  75. * @author Slava Pestov
  76. * @author John Gellene (API documentation)
  77. * @version $Id: View.java 4841 2003-07-28 21:08:04Z spestov $
  78. */
  79. public class View extends JFrame implements EBComponent
  80. {
  81. //{{{ User interface
  82. //{{{ ToolBar-related constants
  83. //{{{ Groups
  84. /**
  85. * The group of tool bars above the DockableWindowManager
  86. * @see #addToolBar(int,int,java.awt.Component)
  87. * @since jEdit 4.0pre7
  88. */
  89. public static final int TOP_GROUP = 0;
  90. /**
  91. * The group of tool bars below the DockableWindowManager
  92. * @see #addToolBar(int,int,java.awt.Component)
  93. * @since jEdit 4.0pre7
  94. */
  95. public static final int BOTTOM_GROUP = 1;
  96. public static final int DEFAULT_GROUP = TOP_GROUP;
  97. //}}}
  98. //{{{ Layers
  99. // Common layers
  100. /**
  101. * The highest possible layer.
  102. * @see #addToolBar(int,int,java.awt.Component)
  103. * @since jEdit 4.0pre7
  104. */
  105. public static final int TOP_LAYER = Integer.MAX_VALUE;
  106. /**
  107. * The default layer for tool bars with no preference.
  108. * @see #addToolBar(int,int,java.awt.Component)
  109. * @since jEdit 4.0pre7
  110. */
  111. public static final int DEFAULT_LAYER = 0;
  112. /**
  113. * The lowest possible layer.
  114. * @see #addToolBar(int,int,java.awt.Component)
  115. * @since jEdit 4.0pre7
  116. */
  117. public static final int BOTTOM_LAYER = Integer.MIN_VALUE;
  118. // Layers for top group
  119. /**
  120. * Above system tool bar layer.
  121. * @see #addToolBar(int,int,java.awt.Component)
  122. * @since jEdit 4.0pre7
  123. */
  124. public static final int ABOVE_SYSTEM_BAR_LAYER = 150;
  125. /**
  126. * System tool bar layer.
  127. * jEdit uses this for the main tool bar.
  128. * @see #addToolBar(int,int,java.awt.Component)
  129. * @since jEdit 4.0pre7
  130. */
  131. public static final int SYSTEM_BAR_LAYER = 100;
  132. /**
  133. * Below system tool bar layer.
  134. * @see #addToolBar(int,int,java.awt.Component)
  135. * @since jEdit 4.0pre7
  136. */
  137. public static final int BELOW_SYSTEM_BAR_LAYER = 75;
  138. /**
  139. * Search bar layer.
  140. * @see #addToolBar(int,int,java.awt.Component)
  141. * @since jEdit 4.0pre7
  142. */
  143. public static final int SEARCH_BAR_LAYER = 75;
  144. /**
  145. * Below search bar layer.
  146. * @see #addToolBar(int,int,java.awt.Component)
  147. * @since jEdit 4.0pre7
  148. */
  149. public static final int BELOW_SEARCH_BAR_LAYER = 50;
  150. // Layers for bottom group
  151. /**
  152. * @deprecated Status bar no longer added as a tool bar.
  153. */
  154. public static final int ABOVE_ACTION_BAR_LAYER = -50;
  155. /**
  156. * Action bar layer.
  157. * @see #addToolBar(int,int,java.awt.Component)
  158. * @since jEdit 4.2pre1
  159. */
  160. public static final int ACTION_BAR_LAYER = -75;
  161. /**
  162. * Status bar layer.
  163. * @see #addToolBar(int,int,java.awt.Component)
  164. * @since jEdit 4.2pre1
  165. */
  166. public static final int STATUS_BAR_LAYER = -100;
  167. /**
  168. * Status bar layer.
  169. * @see #addToolBar(int,int,java.awt.Component)
  170. * @since jEdit 4.2pre1
  171. */
  172. public static final int BELOW_STATUS_BAR_LAYER = -150;
  173. //}}}
  174. //}}}
  175. //{{{ getDockableWindowManager() method
  176. /**
  177. * Returns the dockable window manager associated with this view.
  178. * @since jEdit 2.6pre3
  179. */
  180. public DockableWindowManager getDockableWindowManager()
  181. {
  182. return dockableWindowManager;
  183. } //}}}
  184. //{{{ getToolBar() method
  185. /**
  186. * Returns the view's tool bar.
  187. * @since jEdit 4.2pre1
  188. */
  189. public Box getToolBar()
  190. {
  191. return toolBar;
  192. } //}}}
  193. //{{{ addToolBar() method
  194. /**
  195. * Adds a tool bar to this view.
  196. * @param toolBar The tool bar
  197. */
  198. public void addToolBar(Component toolBar)
  199. {
  200. addToolBar(DEFAULT_GROUP, DEFAULT_LAYER, toolBar);
  201. } //}}}
  202. //{{{ addToolBar() method
  203. /**
  204. * Adds a tool bar to this view.
  205. * @param group The tool bar group to add to
  206. * @param toolBar The tool bar
  207. * @see org.gjt.sp.jedit.gui.ToolBarManager
  208. * @since jEdit 4.0pre7
  209. */
  210. public void addToolBar(int group, Component toolBar)
  211. {
  212. addToolBar(group, DEFAULT_LAYER, toolBar);
  213. } //}}}
  214. //{{{ addToolBar() method
  215. /**
  216. * Adds a tool bar to this view.
  217. * @param group The tool bar group to add to
  218. * @param layer The layer of the group to add to
  219. * @param toolBar The tool bar
  220. * @see org.gjt.sp.jedit.gui.ToolBarManager
  221. * @since jEdit 4.0pre7
  222. */
  223. public void addToolBar(int group, int layer, Component toolBar)
  224. {
  225. toolBarManager.addToolBar(group, layer, toolBar);
  226. getRootPane().revalidate();
  227. } //}}}
  228. //{{{ removeToolBar() method
  229. /**
  230. * Removes a tool bar from this view.
  231. * @param toolBar The tool bar
  232. */
  233. public void removeToolBar(Component toolBar)
  234. {
  235. toolBarManager.removeToolBar(toolBar);
  236. getRootPane().revalidate();
  237. } //}}}
  238. //{{{ showWaitCursor() method
  239. /**
  240. * Shows the wait cursor. This method and
  241. * {@link #hideWaitCursor()} are implemented using a reference
  242. * count of requests for wait cursors, so that nested calls work
  243. * correctly; however, you should be careful to use these methods in
  244. * tandem.<p>
  245. *
  246. * To ensure that {@link #hideWaitCursor()} is always called
  247. * after a {@link #showWaitCursor()}, use a
  248. * <code>try</code>/<code>finally</code> block, like this:
  249. * <pre>try
  250. *{
  251. * view.showWaitCursor();
  252. * // ...
  253. *}
  254. *finally
  255. *{
  256. * view.hideWaitCursor();
  257. *}</pre>
  258. */
  259. public synchronized void showWaitCursor()
  260. {
  261. if(waitCount++ == 0)
  262. {
  263. Cursor cursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
  264. setCursor(cursor);
  265. EditPane[] editPanes = getEditPanes();
  266. for(int i = 0; i < editPanes.length; i++)
  267. {
  268. EditPane editPane = editPanes[i];
  269. editPane.getTextArea().getPainter()
  270. .setCursor(cursor);
  271. }
  272. }
  273. } //}}}
  274. //{{{ hideWaitCursor() method
  275. /**
  276. * Hides the wait cursor.
  277. */
  278. public synchronized void hideWaitCursor()
  279. {
  280. if(waitCount > 0)
  281. waitCount--;
  282. if(waitCount == 0)
  283. {
  284. // still needed even though glass pane
  285. // has a wait cursor
  286. Cursor cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
  287. setCursor(cursor);
  288. cursor = Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR);
  289. EditPane[] editPanes = getEditPanes();
  290. for(int i = 0; i < editPanes.length; i++)
  291. {
  292. EditPane editPane = editPanes[i];
  293. editPane.getTextArea().getPainter()
  294. .setCursor(cursor);
  295. }
  296. }
  297. } //}}}
  298. //{{{ getSearchBar() method
  299. /**
  300. * Returns the search bar.
  301. * @since jEdit 2.4pre4
  302. */
  303. public final SearchBar getSearchBar()
  304. {
  305. return searchBar;
  306. } //}}}
  307. //{{{ getActionBar() method
  308. /**
  309. * Returns the action bar.
  310. * @since jEdit 4.2pre3
  311. */
  312. public final ActionBar getActionBar()
  313. {
  314. return actionBar;
  315. } //}}}
  316. //{{{ getStatus() method
  317. /**
  318. * Returns the status bar. The
  319. * {@link org.gjt.sp.jedit.gui.StatusBar#setMessage(String)} and
  320. * {@link org.gjt.sp.jedit.gui.StatusBar#setMessageAndClear(String)} methods can
  321. * be called on the return value of this method to display status
  322. * information to the user.
  323. * @since jEdit 3.2pre2
  324. */
  325. public StatusBar getStatus()
  326. {
  327. return status;
  328. } //}}}
  329. //}}}
  330. //{{{ Input handling
  331. //{{{ getKeyEventInterceptor() method
  332. /**
  333. * Returns the listener that will handle all key events in this
  334. * view, if any.
  335. */
  336. public KeyListener getKeyEventInterceptor()
  337. {
  338. return keyEventInterceptor;
  339. } //}}}
  340. //{{{ setKeyEventInterceptor() method
  341. /**
  342. * Sets the listener that will handle all key events in this
  343. * view. For example, the complete word command uses this so
  344. * that all key events are passed to the word list popup while
  345. * it is visible.
  346. * @param comp The component
  347. */
  348. public void setKeyEventInterceptor(KeyListener listener)
  349. {
  350. this.keyEventInterceptor = listener;
  351. } //}}}
  352. //{{{ getInputHandler() method
  353. /**
  354. * Returns the input handler.
  355. */
  356. public InputHandler getInputHandler()
  357. {
  358. return inputHandler;
  359. } //}}}
  360. //{{{ setInputHandler() method
  361. /**
  362. * Sets the input handler.
  363. * @param inputHandler The new input handler
  364. */
  365. public void setInputHandler(InputHandler inputHandler)
  366. {
  367. this.inputHandler = inputHandler;
  368. } //}}}
  369. //{{{ getMacroRecorder() method
  370. /**
  371. * Returns the macro recorder.
  372. */
  373. public Macros.Recorder getMacroRecorder()
  374. {
  375. return recorder;
  376. } //}}}
  377. //{{{ setMacroRecorder() method
  378. /**
  379. * Sets the macro recorder.
  380. * @param recorder The macro recorder
  381. */
  382. public void setMacroRecorder(Macros.Recorder recorder)
  383. {
  384. this.recorder = recorder;
  385. } //}}}
  386. //{{{ processKeyEvent() method
  387. /**
  388. * Forwards key events directly to the input handler.
  389. * This is slightly faster than using a KeyListener
  390. * because some Swing overhead is avoided.
  391. */
  392. public void processKeyEvent(KeyEvent evt)
  393. {
  394. processKeyEvent(evt,false);
  395. } //}}}
  396. //{{{ processKeyEvent() method
  397. /**
  398. * Forwards key events directly to the input handler.
  399. * This is slightly faster than using a KeyListener
  400. * because some Swing overhead is avoided.
  401. */
  402. public void processKeyEvent(KeyEvent evt, boolean calledFromTextArea)
  403. {
  404. if(Debug.DUMP_KEY_EVENTS && calledFromTextArea)
  405. Log.log(Log.DEBUG,this,"Key event: " + evt);
  406. if(getTextArea().hasFocus() && !calledFromTextArea)
  407. return;
  408. evt = _preprocessKeyEvent(evt);
  409. if(evt == null)
  410. return;
  411. switch(evt.getID())
  412. {
  413. case KeyEvent.KEY_TYPED:
  414. boolean focusOnTextArea = false;
  415. // if the user pressed eg C+e n n in the
  416. // search bar we want focus to go back there
  417. // after the prefix is done
  418. if(prefixFocusOwner != null)
  419. {
  420. if(prefixFocusOwner.isShowing())
  421. {
  422. prefixFocusOwner.requestFocus();
  423. focusOnTextArea = true;
  424. }
  425. }
  426. if(keyEventInterceptor != null)
  427. keyEventInterceptor.keyTyped(evt);
  428. else if(inputHandler.isPrefixActive()
  429. || getTextArea().hasFocus())
  430. {
  431. inputHandler.keyTyped(evt);
  432. }
  433. // we might have been closed as a result of
  434. // the above
  435. if(isClosed())
  436. return;
  437. // this is a weird hack.
  438. // we don't want C+e a to insert 'a' in the
  439. // search bar if the search bar has focus...
  440. if(inputHandler.isPrefixActive())
  441. {
  442. if(getFocusOwner() instanceof JTextComponent)
  443. {
  444. prefixFocusOwner = getFocusOwner();
  445. getTextArea().requestFocus();
  446. }
  447. else if(focusOnTextArea)
  448. {
  449. getTextArea().requestFocus();
  450. }
  451. else
  452. {
  453. prefixFocusOwner = null;
  454. }
  455. }
  456. else
  457. {
  458. prefixFocusOwner = null;
  459. }
  460. break;
  461. case KeyEvent.KEY_PRESSED:
  462. if(keyEventInterceptor != null)
  463. keyEventInterceptor.keyPressed(evt);
  464. else
  465. {
  466. /* boolean */ focusOnTextArea = false;
  467. if(prefixFocusOwner != null)
  468. {
  469. if(prefixFocusOwner.isShowing())
  470. {
  471. prefixFocusOwner.requestFocus();
  472. focusOnTextArea = true;
  473. }
  474. prefixFocusOwner = null;
  475. }
  476. inputHandler.keyPressed(evt);
  477. // we might have been closed as a result of
  478. // the above
  479. if(isClosed())
  480. return;
  481. // this is a weird hack.
  482. // we don't want C+e a to insert 'a' in the
  483. // search bar if the search bar has focus...
  484. if(inputHandler.isPrefixActive())
  485. {
  486. if(getFocusOwner() instanceof JTextComponent)
  487. {
  488. prefixFocusOwner = getFocusOwner();
  489. getTextArea().requestFocus();
  490. }
  491. else if(focusOnTextArea)
  492. {
  493. getTextArea().requestFocus();
  494. }
  495. else
  496. {
  497. prefixFocusOwner = null;
  498. }
  499. }
  500. else
  501. {
  502. prefixFocusOwner = null;
  503. }
  504. }
  505. break;
  506. case KeyEvent.KEY_RELEASED:
  507. if(keyEventInterceptor != null)
  508. keyEventInterceptor.keyReleased(evt);
  509. else
  510. inputHandler.keyReleased(evt);
  511. break;
  512. }
  513. if(!evt.isConsumed())
  514. super.processKeyEvent(evt);
  515. } //}}}
  516. //}}}
  517. //{{{ Buffers, edit panes, split panes
  518. //{{{ splitHorizontally() method
  519. /**
  520. * Splits the view horizontally.
  521. * @since jEdit 4.1pre2
  522. */
  523. public EditPane splitHorizontally()
  524. {
  525. return split(JSplitPane.VERTICAL_SPLIT);
  526. } //}}}
  527. //{{{ splitVertically() method
  528. /**
  529. * Splits the view vertically.
  530. * @since jEdit 4.1pre2
  531. */
  532. public EditPane splitVertically()
  533. {
  534. return split(JSplitPane.HORIZONTAL_SPLIT);
  535. } //}}}
  536. //{{{ split() method
  537. /**
  538. * Splits the view.
  539. * @since jEdit 4.1pre2
  540. */
  541. public EditPane split(int orientation)
  542. {
  543. editPane.saveCaretInfo();
  544. EditPane oldEditPane = editPane;
  545. setEditPane(createEditPane(oldEditPane.getBuffer()));
  546. editPane.loadCaretInfo();
  547. JComponent oldParent = (JComponent)oldEditPane.getParent();
  548. final JSplitPane newSplitPane = new JSplitPane(orientation);
  549. newSplitPane.setOneTouchExpandable(true);
  550. newSplitPane.setBorder(null);
  551. newSplitPane.setMinimumSize(new Dimension(0,0));
  552. int parentSize = (orientation == JSplitPane.VERTICAL_SPLIT
  553. ? oldEditPane.getHeight() : oldEditPane.getWidth());
  554. final int dividerPosition = (int)((double)(parentSize
  555. - newSplitPane.getDividerSize()) * 0.5);
  556. newSplitPane.setDividerLocation(dividerPosition);
  557. if(oldParent instanceof JSplitPane)
  558. {
  559. JSplitPane oldSplitPane = (JSplitPane)oldParent;
  560. int dividerPos = oldSplitPane.getDividerLocation();
  561. Component left = oldSplitPane.getLeftComponent();
  562. if(left == oldEditPane)
  563. oldSplitPane.setLeftComponent(newSplitPane);
  564. else
  565. oldSplitPane.setRightComponent(newSplitPane);
  566. newSplitPane.setLeftComponent(oldEditPane);
  567. newSplitPane.setRightComponent(editPane);
  568. oldSplitPane.setDividerLocation(dividerPos);
  569. }
  570. else
  571. {
  572. this.splitPane = newSplitPane;
  573. newSplitPane.setLeftComponent(oldEditPane);
  574. newSplitPane.setRightComponent(editPane);
  575. oldParent.add(newSplitPane,0);
  576. oldParent.revalidate();
  577. }
  578. SwingUtilities.invokeLater(new Runnable()
  579. {
  580. public void run()
  581. {
  582. newSplitPane.setDividerLocation(dividerPosition);
  583. }
  584. });
  585. editPane.focusOnTextArea();
  586. return editPane;
  587. } //}}}
  588. //{{{ unsplit() method
  589. /**
  590. * Unsplits the view.
  591. * @since jEdit 2.3pre2
  592. */
  593. public void unsplit()
  594. {
  595. if(splitPane != null)
  596. {
  597. EditPane[] editPanes = getEditPanes();
  598. for(int i = 0; i < editPanes.length; i++)
  599. {
  600. EditPane _editPane = editPanes[i];
  601. if(editPane != _editPane)
  602. _editPane.close();
  603. }
  604. JComponent parent = (JComponent)splitPane.getParent();
  605. parent.remove(splitPane);
  606. parent.add(editPane,0);
  607. parent.revalidate();
  608. splitPane = null;
  609. updateTitle();
  610. editPane.focusOnTextArea();
  611. }
  612. else
  613. getToolkit().beep();
  614. } //}}}
  615. //{{{ unsplitCurrent() method
  616. /**
  617. * Removes the current split.
  618. * @since jEdit 2.3pre2
  619. */
  620. public void unsplitCurrent()
  621. {
  622. if(splitPane != null)
  623. {
  624. // find first split pane parenting current edit pane
  625. Component comp = editPane;
  626. while(!(comp instanceof JSplitPane))
  627. {
  628. comp = comp.getParent();
  629. }
  630. // get rid of any edit pane that is a child
  631. // of the current edit pane's parent splitter
  632. EditPane[] editPanes = getEditPanes();
  633. for(int i = 0; i < editPanes.length; i++)
  634. {
  635. EditPane _editPane = editPanes[i];
  636. if(GUIUtilities.isAncestorOf(comp,_editPane)
  637. && _editPane != editPane)
  638. _editPane.close();
  639. }
  640. JComponent parent = (JComponent)comp.getParent();
  641. if(parent instanceof JSplitPane)
  642. {
  643. JSplitPane parentSplit = (JSplitPane)parent;
  644. int pos = parentSplit.getDividerLocation();
  645. if(parentSplit.getLeftComponent() == comp)
  646. parentSplit.setLeftComponent(editPane);
  647. else
  648. parentSplit.setRightComponent(editPane);
  649. parentSplit.setDividerLocation(pos);
  650. }
  651. else
  652. {
  653. parent.remove(comp);
  654. parent.add(editPane,0);
  655. splitPane = null;
  656. }
  657. parent.revalidate();
  658. updateTitle();
  659. editPane.focusOnTextArea();
  660. }
  661. else
  662. getToolkit().beep();
  663. } //}}}
  664. //{{{ nextTextArea() method
  665. /**
  666. * Moves keyboard focus to the next text area.
  667. * @since jEdit 2.7pre4
  668. */
  669. public void nextTextArea()
  670. {
  671. EditPane[] editPanes = getEditPanes();
  672. for(int i = 0; i < editPanes.length; i++)
  673. {
  674. if(editPane == editPanes[i])
  675. {
  676. if(i == editPanes.length - 1)
  677. editPanes[0].focusOnTextArea();
  678. else
  679. editPanes[i+1].focusOnTextArea();
  680. break;
  681. }
  682. }
  683. } //}}}
  684. //{{{ prevTextArea() method
  685. /**
  686. * Moves keyboard focus to the previous text area.
  687. * @since jEdit 2.7pre4
  688. */
  689. public void prevTextArea()
  690. {
  691. EditPane[] editPanes = getEditPanes();
  692. for(int i = 0; i < editPanes.length; i++)
  693. {
  694. if(editPane == editPanes[i])
  695. {
  696. if(i == 0)
  697. editPanes[editPanes.length - 1].focusOnTextArea();
  698. else
  699. editPanes[i-1].focusOnTextArea();
  700. break;
  701. }
  702. }
  703. } //}}}
  704. //{{{ getSplitPane() method
  705. /**
  706. * Returns the top-level split pane, if any.
  707. * @since jEdit 2.3pre2
  708. */
  709. public JSplitPane getSplitPane()
  710. {
  711. return splitPane;
  712. } //}}}
  713. //{{{ getBuffer() method
  714. /**
  715. * Returns the current edit pane's buffer.
  716. */
  717. public Buffer getBuffer()
  718. {
  719. if(editPane == null)
  720. return null;
  721. else
  722. return editPane.getBuffer();
  723. } //}}}
  724. //{{{ setBuffer() method
  725. /**
  726. * Sets the current edit pane's buffer.
  727. */
  728. public void setBuffer(Buffer buffer)
  729. {
  730. editPane.setBuffer(buffer);
  731. } //}}}
  732. //{{{ goToBuffer() method
  733. /**
  734. * If this buffer is open in one of the view's edit panes, sets focus
  735. * to that edit pane. Otherwise, opens the buffer in the currently
  736. * active edit pane.
  737. * @param buffer The buffer
  738. * @since jEdit 4.2pre1
  739. */
  740. public EditPane goToBuffer(Buffer buffer)
  741. {
  742. if(editPane.getBuffer() == buffer)
  743. {
  744. editPane.focusOnTextArea();
  745. return editPane;
  746. }
  747. EditPane[] editPanes = getEditPanes();
  748. for(int i = 0; i < editPanes.length; i++)
  749. {
  750. EditPane ep = editPanes[i];
  751. if(ep.getBuffer() == buffer)
  752. {
  753. setEditPane(ep);
  754. ep.focusOnTextArea();
  755. return ep;
  756. }
  757. }
  758. setBuffer(buffer);
  759. return editPane;
  760. } //}}}
  761. //{{{ getTextArea() method
  762. /**
  763. * Returns the current edit pane's text area.
  764. */
  765. public JEditTextArea getTextArea()
  766. {
  767. if(editPane == null)
  768. return null;
  769. else
  770. return editPane.getTextArea();
  771. } //}}}
  772. //{{{ getEditPane() method
  773. /**
  774. * Returns the current edit pane.
  775. * @since jEdit 2.5pre2
  776. */
  777. public EditPane getEditPane()
  778. {
  779. return editPane;
  780. } //}}}
  781. //{{{ getEditPanes() method
  782. /**
  783. * Returns all edit panes.
  784. * @since jEdit 2.5pre2
  785. */
  786. public EditPane[] getEditPanes()
  787. {
  788. if(splitPane == null)
  789. {
  790. EditPane[] ep = { editPane };
  791. return ep;
  792. }
  793. else
  794. {
  795. Vector vec = new Vector();
  796. getEditPanes(vec,splitPane);
  797. EditPane[] ep = new EditPane[vec.size()];
  798. vec.copyInto(ep);
  799. return ep;
  800. }
  801. } //}}}
  802. //{{{ getViewConfig() method
  803. /**
  804. * @since jEdit 4.2pre1
  805. */
  806. public ViewConfig getViewConfig()
  807. {
  808. StringBuffer splitConfig = new StringBuffer();
  809. if(splitPane != null)
  810. getSplitConfig(splitPane,splitConfig);
  811. else
  812. {
  813. splitConfig.append(getBuffer().getIndex());
  814. splitConfig.append(" buffer");
  815. }
  816. ViewConfig config = new ViewConfig();
  817. config.plainView = isPlainView();
  818. config.splitConfig = splitConfig.toString();
  819. config.x = getX();
  820. config.y = getY();
  821. config.width = getWidth();
  822. config.height = getHeight();
  823. config.extState = GUIUtilities.getExtendedState(this);
  824. config.top = dockableWindowManager.getTopDockingArea().getCurrent();
  825. config.left = dockableWindowManager.getLeftDockingArea().getCurrent();
  826. config.bottom = dockableWindowManager.getBottomDockingArea().getCurrent();
  827. config.right = dockableWindowManager.getRightDockingArea().getCurrent();
  828. config.topPos = dockableWindowManager.getTopDockingArea().getDimension();
  829. config.leftPos = dockableWindowManager.getLeftDockingArea().getDimension();
  830. config.bottomPos = dockableWindowManager.getBottomDockingArea().getDimension();
  831. config.rightPos = dockableWindowManager.getRightDockingArea().getDimension();
  832. return config;
  833. } //}}}
  834. //}}}
  835. //{{{ quickIncrementalSearch() method
  836. /**
  837. * Quick search.
  838. * @since jEdit 4.0pre3
  839. */
  840. public void quickIncrementalSearch(boolean word)
  841. {
  842. if(searchBar == null)
  843. searchBar = new SearchBar(this,true);
  844. if(searchBar.getParent() == null)
  845. addToolBar(TOP_GROUP,SEARCH_BAR_LAYER,searchBar);
  846. searchBar.setHyperSearch(false);
  847. JEditTextArea textArea = getTextArea();
  848. if(word)
  849. {
  850. String text = textArea.getSelectedText();
  851. if(text == null)
  852. {
  853. textArea.selectWord();
  854. text = textArea.getSelectedText();
  855. }
  856. else if(text.indexOf('\n') != -1)
  857. text = null;
  858. searchBar.getField().setText(text);
  859. }
  860. searchBar.getField().requestFocus();
  861. searchBar.getField().selectAll();
  862. } //}}}
  863. //{{{ quickHyperSearch() method
  864. /**
  865. * Quick HyperSearch.
  866. * @since jEdit 4.0pre3
  867. */
  868. public void quickHyperSearch(boolean word)
  869. {
  870. JEditTextArea textArea = getTextArea();
  871. if(word)
  872. {
  873. String text = textArea.getSelectedText();
  874. if(text == null)
  875. {
  876. textArea.selectWord();
  877. text = textArea.getSelectedText();
  878. }
  879. if(text != null && text.indexOf('\n') == -1)
  880. {
  881. HistoryModel.getModel("find").addItem(text);
  882. SearchAndReplace.setSearchString(text);
  883. SearchAndReplace.setSearchFileSet(new CurrentBufferSet());
  884. SearchAndReplace.hyperSearch(this);
  885. return;
  886. }
  887. }
  888. if(searchBar == null)
  889. searchBar = new SearchBar(this,true);
  890. if(searchBar.getParent() == null)
  891. addToolBar(TOP_GROUP,SEARCH_BAR_LAYER,searchBar);
  892. searchBar.setHyperSearch(true);
  893. searchBar.getField().setText(null);
  894. searchBar.getField().requestFocus();
  895. searchBar.getField().selectAll();
  896. } //}}}
  897. //{{{ actionBar() method
  898. /**
  899. * Shows the action bar if needed, and sends keyboard focus there.
  900. * @since jEdit 4.2pre1
  901. */
  902. public void actionBar()
  903. {
  904. if(actionBar == null)
  905. actionBar = new ActionBar(this,true);
  906. if(actionBar.getParent() == null)
  907. addToolBar(BOTTOM_GROUP,ACTION_BAR_LAYER,actionBar);
  908. actionBar.goToActionBar();
  909. } //}}}
  910. //{{{ isClosed() method
  911. /**
  912. * Returns true if this view has been closed with
  913. * {@link jEdit#closeView(View)}.
  914. */
  915. public boolean isClosed()
  916. {
  917. return closed;
  918. } //}}}
  919. //{{{ isPlainView() method
  920. /**
  921. * Returns true if this is an auxilliary view with no dockable windows.
  922. * @since jEdit 4.1pre2
  923. */
  924. public boolean isPlainView()
  925. {
  926. return plainView;
  927. } //}}}
  928. //{{{ getNext() method
  929. /**
  930. * Returns the next view in the list.
  931. */
  932. public View getNext()
  933. {
  934. return next;
  935. } //}}}
  936. //{{{ getPrev() method
  937. /**
  938. * Returns the previous view in the list.
  939. */
  940. public View getPrev()
  941. {
  942. return prev;
  943. } //}}}
  944. //{{{ handleMessage() method
  945. public void handleMessage(EBMessage msg)
  946. {
  947. if(msg instanceof PropertiesChanged)
  948. propertiesChanged();
  949. else if(msg instanceof SearchSettingsChanged)
  950. {
  951. if(searchBar != null)
  952. searchBar.update();
  953. }
  954. else if(msg instanceof BufferUpdate)
  955. handleBufferUpdate((BufferUpdate)msg);
  956. else if(msg instanceof EditPaneUpdate)
  957. handleEditPaneUpdate((EditPaneUpdate)msg);
  958. else if(msg instanceof PluginUpdate)
  959. {
  960. if(actionBar != null)
  961. actionBar.actionListChanged();
  962. }
  963. } //}}}
  964. //{{{ getMinimumSize() method
  965. public Dimension getMinimumSize()
  966. {
  967. return new Dimension(0,0);
  968. } //}}}
  969. //{{{ setWaitSocket() method
  970. /**
  971. * This socket is closed when the buffer is closed.
  972. */
  973. public void setWaitSocket(Socket waitSocket)
  974. {
  975. this.waitSocket = waitSocket;
  976. } //}}}
  977. //{{{ toString() method
  978. public String toString()
  979. {
  980. return getClass().getName() + "["
  981. + (jEdit.getActiveView() == this
  982. ? "active" : "inactive")
  983. + "]";
  984. } //}}}
  985. //{{{ Package-private members
  986. View prev;
  987. View next;
  988. //{{{ View constructor
  989. View(Buffer buffer, ViewConfig config)
  990. {
  991. this.plainView = config.plainView;
  992. enableEvents(AWTEvent.KEY_EVENT_MASK);
  993. setIconImage(GUIUtilities.getEditorIcon());
  994. dockableWindowManager = new DockableWindowManager(this,config);
  995. topToolBars = new JPanel(new VariableGridLayout(
  996. VariableGridLayout.FIXED_NUM_COLUMNS,
  997. 1));
  998. bottomToolBars = new JPanel(new VariableGridLayout(
  999. VariableGridLayout.FIXED_NUM_COLUMNS,
  1000. 1));
  1001. /* bottomToolBars.setLayout(new BoxLayout(bottomToolBars,
  1002. BoxLayout.X_AXIS)); */
  1003. toolBarManager = new ToolBarManager(topToolBars, bottomToolBars);
  1004. status = new StatusBar(this);
  1005. inputHandler = new DefaultInputHandler(this,(DefaultInputHandler)
  1006. jEdit.getInputHandler());
  1007. Component comp = restoreSplitConfig(buffer,config.splitConfig);
  1008. dockableWindowManager.add(comp,0);
  1009. getContentPane().add(BorderLayout.CENTER,dockableWindowManager);
  1010. dockableWindowManager.init();
  1011. // tool bar and status bar gets added in propertiesChanged()
  1012. // depending in the 'tool bar alternate layout' setting.
  1013. propertiesChanged();
  1014. setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
  1015. addWindowListener(new WindowHandler());
  1016. EditBus.addToBus(this);
  1017. SearchDialog.preloadSearchDialog(this);
  1018. } //}}}
  1019. //{{{ close() method
  1020. void close()
  1021. {
  1022. GUIUtilities.saveGeometry(this,plainView ? "plain-view" : "view");
  1023. closed = true;
  1024. // save dockable window geometry, and close 'em
  1025. dockableWindowManager.close();
  1026. EditBus.removeFromBus(this);
  1027. dispose();
  1028. EditPane[] editPanes = getEditPanes();
  1029. for(int i = 0; i < editPanes.length; i++)
  1030. editPanes[i].close();
  1031. // null some variables so that retaining references
  1032. // to closed views won't hurt as much.
  1033. toolBarManager = null;
  1034. toolBar = null;
  1035. searchBar = null;
  1036. splitPane = null;
  1037. inputHandler = null;
  1038. recorder = null;
  1039. getContentPane().removeAll();
  1040. // notify clients with -wait
  1041. if(waitSocket != null)
  1042. {
  1043. try
  1044. {
  1045. waitSocket.getOutputStream().write('\0');
  1046. waitSocket.getOutputStream().flush();
  1047. waitSocket.getInputStream().close();
  1048. waitSocket.getOutputStream().close();
  1049. waitSocket.close();
  1050. }
  1051. catch(IOException io)
  1052. {
  1053. //Log.log(Log.ERROR,this,io);
  1054. }
  1055. }
  1056. } //}}}
  1057. //{{{ updateTitle() method
  1058. /**
  1059. * Updates the title bar.
  1060. */
  1061. void updateTitle()
  1062. {
  1063. Vector buffers = new Vector();
  1064. EditPane[] editPanes = getEditPanes();
  1065. for(int i = 0; i < editPanes.length; i++)
  1066. {
  1067. Buffer buffer = editPanes[i].getBuffer();
  1068. if(buffers.indexOf(buffer) == -1)
  1069. buffers.addElement(buffer);
  1070. }
  1071. StringBuffer title = new StringBuffer(jEdit.getProperty("view.title"));
  1072. for(int i = 0; i < buffers.size(); i++)
  1073. {
  1074. if(i != 0)
  1075. title.append(", ");
  1076. Buffer buffer = (Buffer)buffers.elementAt(i);
  1077. title.append((showFullPath && !buffer.isNewFile())
  1078. ? buffer.getPath() : buffer.getName());
  1079. if(buffer.isDirty())
  1080. title.append(jEdit.getProperty("view.title.dirty"));
  1081. }
  1082. setTitle(title.toString());
  1083. } //}}}
  1084. //}}}
  1085. //{{{ Private members
  1086. //{{{ Instance variables
  1087. private boolean closed;
  1088. private DockableWindowManager dockableWindowManager;
  1089. private JPanel topToolBars;
  1090. private JPanel bottomToolBars;
  1091. private ToolBarManager toolBarManager;
  1092. private Box toolBar;
  1093. private SearchBar searchBar;
  1094. private ActionBar actionBar;
  1095. private EditPane editPane;
  1096. private JSplitPane splitPane;
  1097. private StatusBar status;
  1098. private KeyListener keyEventInterceptor;
  1099. private InputHandler inputHandler;
  1100. private Macros.Recorder recorder;
  1101. private Component prefixFocusOwner;
  1102. private int waitCount;
  1103. private boolean showFullPath;
  1104. private boolean plainView;
  1105. private Socket waitSocket;
  1106. //}}}
  1107. //{{{ getEditPanes() method
  1108. private void getEditPanes(Vector vec, Component comp)
  1109. {
  1110. if(comp instanceof EditPane)
  1111. vec.addElement(comp);
  1112. else if(comp instanceof JSplitPane)
  1113. {
  1114. JSplitPane split = (JSplitPane)comp;
  1115. getEditPanes(vec,split.getLeftComponent());
  1116. getEditPanes(vec,split.getRightComponent());
  1117. }
  1118. } //}}}
  1119. //{{{ getSplitConfig() method
  1120. /*
  1121. * The split config is recorded in a simple RPN "language".
  1122. */
  1123. private void getSplitConfig(JSplitPane splitPane,
  1124. StringBuffer splitConfig)
  1125. {
  1126. Component right = splitPane.getRightComponent();
  1127. if(right instanceof JSplitPane)
  1128. getSplitConfig((JSplitPane)right,splitConfig);
  1129. else
  1130. {
  1131. splitConfig.append(((EditPane)right).getBuffer().getIndex());
  1132. splitConfig.append(" buffer");
  1133. }
  1134. splitConfig.append(' ');
  1135. Component left = splitPane.getLeftComponent();
  1136. if(left instanceof JSplitPane)
  1137. getSplitConfig((JSplitPane)left,splitConfig);
  1138. else
  1139. {
  1140. splitConfig.append(((EditPane)left).getBuffer().getIndex());
  1141. splitConfig.append(" buffer");
  1142. }
  1143. splitConfig.append(' ');
  1144. splitConfig.append(splitPane.getDividerLocation());
  1145. splitConfig.append(' ');
  1146. splitConfig.append(splitPane.getOrientation()
  1147. == JSplitPane.VERTICAL_SPLIT ? "vertical" : "horizontal");
  1148. } //}}}
  1149. //{{{ restoreSplitConfig() method
  1150. private Component restoreSplitConfig(Buffer buffer, String splitConfig)
  1151. {
  1152. if(buffer != null)
  1153. return (editPane = createEditPane(buffer));
  1154. else if(splitConfig == null)
  1155. return (editPane = createEditPane(jEdit.getFirstBuffer()));
  1156. Buffer[] buffers = jEdit.getBuffers();
  1157. Stack stack = new Stack();
  1158. StringTokenizer st = new StringTokenizer(splitConfig);
  1159. while(st.hasMoreTokens())
  1160. {
  1161. String token = st.nextToken();
  1162. if(token.equals("vertical") || token.equals("horizontal"))
  1163. {
  1164. int orientation = (token.equals("vertical")
  1165. ? JSplitPane.VERTICAL_SPLIT
  1166. : JSplitPane.HORIZONTAL_SPLIT);
  1167. int divider = Integer.parseInt((String)stack.pop());
  1168. stack.push(splitPane = new JSplitPane(
  1169. orientation,
  1170. (Component)stack.pop(),
  1171. (Component)stack.pop()));
  1172. splitPane.setOneTouchExpandable(true);
  1173. splitPane.setBorder(null);
  1174. splitPane.setMinimumSize(new Dimension(0,0));
  1175. splitPane.setDividerLocation(divider);
  1176. }
  1177. else if(token.equals("buffer"))
  1178. {
  1179. int index = Integer.parseInt((String)stack.pop());
  1180. if(index < buffers.length && index >= 0)
  1181. buffer = buffers[index];
  1182. if(buffer == null)
  1183. buffer = jEdit.getFirstBuffer();
  1184. stack.push(editPane = createEditPane(buffer));
  1185. }
  1186. else
  1187. {
  1188. stack.push(token);
  1189. }
  1190. }
  1191. updateGutterBorders();
  1192. return (Component)stack.peek();
  1193. } //}}}
  1194. //{{{ propertiesChanged() method
  1195. /**
  1196. * Reloads various settings from the properties.
  1197. */
  1198. private void propertiesChanged()
  1199. {
  1200. setJMenuBar(GUIUtilities.loadMenuBar("view.mbar"));
  1201. loadToolBars();
  1202. showFullPath = jEdit.getBooleanProperty("view.showFullPath");
  1203. updateTitle();
  1204. status.propertiesChanged();
  1205. removeToolBar(status);
  1206. getContentPane().remove(status);
  1207. if(jEdit.getBooleanProperty("view.toolbar.alternateLayout"))
  1208. {
  1209. getContentPane().add(BorderLayout.NORTH,topToolBars);
  1210. getContentPane().add(BorderLayout.SOUTH,bottomToolBars);
  1211. if(!plainView && jEdit.getBooleanProperty("view.status.visible"))
  1212. addToolBar(BOTTOM_GROUP,STATUS_BAR_LAYER,status);
  1213. }
  1214. else
  1215. {
  1216. dockableWindowManager.add(topToolBars,
  1217. DockableWindowManager.DockableLayout
  1218. .TOP_TOOLBARS,0);
  1219. dockableWindowManager.add(bottomToolBars,
  1220. DockableWindowManager.DockableLayout
  1221. .BOTTOM_TOOLBARS,0);
  1222. if(!plainView && jEdit.getBooleanProperty("view.status.visible"))
  1223. getContentPane().add(BorderLayout.SOUTH,status);
  1224. }
  1225. getRootPane().revalidate();
  1226. //SwingUtilities.updateComponentTreeUI(getRootPane());
  1227. } //}}}
  1228. //{{{ loadToolBars() method
  1229. private void loadToolBars()
  1230. {
  1231. if(jEdit.getBooleanProperty("view.showToolbar") && !plainView)
  1232. {
  1233. if(toolBar != null)
  1234. toolBarManager.removeToolBar(toolBar);
  1235. toolBar = GUIUtilities.loadToolBar("view.toolbar");
  1236. addToolBar(TOP_GROUP, SYSTEM_BAR_LAYER, toolBar);
  1237. }
  1238. else if(toolBar != null)
  1239. {
  1240. removeToolBar(toolBar);
  1241. toolBar = null;
  1242. }
  1243. if(searchBar != null)
  1244. removeToolBar(searchBar);
  1245. if(jEdit.getBooleanProperty("view.showSearchbar") && !plainView)
  1246. {
  1247. if(searchBar == null)
  1248. searchBar = new SearchBar(this,false);
  1249. searchBar.propertiesChanged();
  1250. addToolBar(TOP_GROUP,SEARCH_BAR_LAYER,searchBar);
  1251. }
  1252. } //}}}
  1253. //{{{ createEditPane() method
  1254. private EditPane createEditPane(Buffer buffer)
  1255. {
  1256. EditPane editPane = new EditPane(this,buffer);
  1257. JEditTextArea textArea = editPane.getTextArea();
  1258. textArea.addFocusListener(new FocusHandler());
  1259. textArea.addCaretListener(new CaretHandler());
  1260. textArea.addScrollListener(new ScrollHandler());
  1261. EditBus.send(new EditPaneUpdate(editPane,EditPaneUpdate.CREATED));
  1262. return editPane;
  1263. } //}}}
  1264. //{{{ setEditPane() method
  1265. private void setEditPane(EditPane editPane)
  1266. {
  1267. this.editPane = editPane;
  1268. status.updateCaretStatus();
  1269. status.updateBufferStatus();
  1270. status.updateMiscStatus();
  1271. // repaint the gutter so that the border color
  1272. // reflects the focus state
  1273. updateGutterBorders();
  1274. EditBus.send(new ViewUpdate(this,ViewUpdate.EDIT_PANE_CHANGED));
  1275. } //}}}
  1276. //{{{ handleBufferUpdate() method
  1277. private void handleBufferUpdate(BufferUpdate msg)
  1278. {
  1279. Buffer buffer = msg.getBuffer();
  1280. if(msg.getWhat() == BufferUpdate.DIRTY_CHANGED
  1281. || msg.getWhat() == BufferUpdate.LOADED)
  1282. {
  1283. EditPane[] editPanes = getEditPanes();
  1284. for(int i = 0; i < editPanes.length; i++)
  1285. {
  1286. if(editPanes[i].getBuffer() == buffer)
  1287. {
  1288. updateTitle();
  1289. break;
  1290. }
  1291. }
  1292. }
  1293. } //}}}
  1294. //{{{ handleEditPaneUpdate() method
  1295. private void handleEditPaneUpdate(EditPaneUpdate msg)
  1296. {
  1297. EditPane editPane = msg.getEditPane();
  1298. if(editPane.getView() == this
  1299. && msg.getWhat() == EditPaneUpdate.BUFFER_CHANGED
  1300. && editPane.getBuffer().isLoaded())
  1301. {
  1302. status.updateCaretStatus();
  1303. status.updateBufferStatus();
  1304. status.updateMiscStatus();
  1305. }
  1306. } //}}}
  1307. //{{{ updateGutterBorders() method
  1308. /**
  1309. * Updates the borders of all gutters in this view to reflect the
  1310. * currently focused text area.
  1311. * @since jEdit 2.6final
  1312. */
  1313. private void updateGutterBorders()
  1314. {
  1315. EditPane[] editPanes = getEditPanes();
  1316. for(int i = 0; i < editPanes.length; i++)
  1317. editPanes[i].getTextArea().getGutter().updateBorder();
  1318. } //}}}
  1319. //{{{ _preprocessKeyEvent() method
  1320. private KeyEvent _preprocessKeyEvent(KeyEvent evt)
  1321. {
  1322. if(isClosed())
  1323. return null;
  1324. if(getFocusOwner() instanceof JComponent)
  1325. {
  1326. JComponent comp = (JComponent)getFocusOwner();
  1327. InputMap map = comp.getInputMap();
  1328. ActionMap am = comp.getActionMap();
  1329. if(map != null && am != null && comp.isEnabled())
  1330. {
  1331. Object binding = map.get(KeyStroke.getKeyStrokeForEvent(evt));
  1332. if(binding != null && am.get(binding) != null)
  1333. {
  1334. return null;
  1335. }
  1336. }
  1337. }
  1338. if(getFocusOwner() instanceof JTextComponent)
  1339. {
  1340. // fix for the bug where key events in JTextComponents
  1341. // inside views are also handled by the input handler
  1342. if(evt.getID() == KeyEvent.KEY_PRESSED)
  1343. {
  1344. switch(evt.getKeyCode())
  1345. {
  1346. case KeyEvent.VK_ENTER:
  1347. case KeyEvent.VK_TAB:
  1348. case KeyEvent.VK_BACK_SPACE:
  1349. case KeyEvent.VK_SPACE:
  1350. return null;
  1351. }
  1352. }
  1353. }
  1354. if(evt.isConsumed())
  1355. return null;
  1356. return KeyEventWorkaround.processKeyEvent(evt);
  1357. } //}}}
  1358. //}}}
  1359. //{{{ Inner classes
  1360. //{{{ CaretHandler class
  1361. class CaretHandler implements CaretListener
  1362. {
  1363. public void caretUpdate(CaretEvent evt)
  1364. {
  1365. if(evt.getSource() == getTextArea())
  1366. status.updateCaretStatus();
  1367. }
  1368. } //}}}
  1369. //{{{ FocusHandler class
  1370. class FocusHandler extends FocusAdapter
  1371. {
  1372. public void focusGained(FocusEvent evt)
  1373. {
  1374. // walk up hierarchy, looking for an EditPane
  1375. Component comp = (Component)evt.getSource();
  1376. while(!(comp instanceof EditPane))
  1377. {
  1378. if(comp == null)
  1379. return;
  1380. comp = comp.getParent();
  1381. }
  1382. if(comp != editPane)
  1383. setEditPane((EditPane)comp);
  1384. else
  1385. updateGutterBorders();
  1386. }
  1387. } //}}}
  1388. //{{{ ScrollHandler class
  1389. class ScrollHandler implements ScrollListener
  1390. {
  1391. public void scrolledVertically(JEditTextArea textArea)
  1392. {
  1393. if(getTextArea() == textArea)
  1394. status.updateCaretStatus();
  1395. }
  1396. public void scrolledHorizontally(JEditTextArea textArea) {}
  1397. } //}}}
  1398. //{{{ WindowHandler class
  1399. class WindowHandler extends WindowAdapter
  1400. {
  1401. public void windowActivated(WindowEvent evt)
  1402. {
  1403. jEdit.setActiveView(View.this);
  1404. // People have reported hangs with JDK 1.4; might be
  1405. // caused by modal dialogs being displayed from
  1406. // windowActivated()
  1407. SwingUtilities.invokeLater(new Runnable()
  1408. {
  1409. public void run()
  1410. {
  1411. jEdit.checkBufferStatus(View.this);
  1412. }
  1413. });
  1414. }
  1415. public void windowClosing(WindowEvent evt)
  1416. {
  1417. jEdit.closeView(View.this);
  1418. }
  1419. } //}}}
  1420. //{{{ ViewConfig class
  1421. public static class ViewConfig
  1422. {
  1423. public boolean plainView;
  1424. public String splitConfig;
  1425. public int x, y, width, height, extState;
  1426. // dockables
  1427. public String top, left, bottom, right;
  1428. public int topPos, leftPos, bottomPos, rightPos;
  1429. public ViewConfig()
  1430. {
  1431. }
  1432. public ViewConfig(boolean plainView)
  1433. {
  1434. this.plainView = plainView;
  1435. String prefix = (plainView ? "plain-view" : "view");
  1436. x = jEdit.getIntegerProperty(prefix + ".x",0);
  1437. y = jEdit.getIntegerProperty(prefix + ".y",0);
  1438. width = jEdit.getIntegerProperty(prefix + ".width",0);
  1439. height = jEdit.getIntegerProperty(prefix + ".height",0);
  1440. }
  1441. public ViewConfig(boolean plainView, String splitConfig,
  1442. int x, int y, int width, int height, int extState)
  1443. {
  1444. this.plainView = plainView;
  1445. this.splitConfig = splitConfig;
  1446. this.x = x;
  1447. this.y = y;
  1448. this.width = width;
  1449. this.height = height;
  1450. this.extState = extState;
  1451. }
  1452. } //}}}
  1453. //}}}
  1454. }