PageRenderTime 53ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre3/org/gjt/sp/jedit/gui/DockableWindowManager.java

#
Java | 1099 lines | 750 code | 142 blank | 207 comment | 115 complexity | 84fbeb9dd1a137ebb3d1c3a8ddb808a6 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. * DockableWindowManager.java - manages dockable windows
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2000, 2001 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.gui;
  23. //{{{ Imports
  24. import bsh.EvalError;
  25. import com.microstar.xml.*;
  26. import org.gjt.sp.jedit.browser.VFSBrowser;
  27. import org.gjt.sp.jedit.msg.CreateDockableWindow;
  28. import org.gjt.sp.jedit.search.HyperSearchResults;
  29. import org.gjt.sp.jedit.*;
  30. import org.gjt.sp.util.Log;
  31. import javax.swing.*;
  32. import java.awt.event.*;
  33. import java.awt.*;
  34. import java.io.*;
  35. import java.util.*;
  36. //}}}
  37. /**
  38. * Manages dockable windows.
  39. * @author Slava Pestov
  40. * @version $Id: DockableWindowManager.java 3915 2001-11-24 09:45:13Z spestov $
  41. * @since jEdit 2.6pre3
  42. */
  43. public class DockableWindowManager extends JPanel
  44. {
  45. //{{{ Static part of class
  46. //{{{ Constants
  47. /**
  48. * Floating position.
  49. * @since jEdit 2.6pre3
  50. */
  51. public static final String FLOATING = "floating";
  52. /**
  53. * Top position.
  54. * @since jEdit 2.6pre3
  55. */
  56. public static final String TOP = "top";
  57. /**
  58. * Left position.
  59. * @since jEdit 2.6pre3
  60. */
  61. public static final String LEFT = "left";
  62. /**
  63. * Bottom position.
  64. * @since jEdit 2.6pre3
  65. */
  66. public static final String BOTTOM = "bottom";
  67. /**
  68. * Right position.
  69. * @since jEdit 2.6pre3
  70. */
  71. public static final String RIGHT = "right";
  72. //}}}
  73. //{{{ loadDockableWindows() method
  74. /**
  75. * Plugins shouldn't need to call this method.
  76. * @since jEdit 4.0pre1
  77. */
  78. public static boolean loadDockableWindows(String path, Reader in, ActionSet actionSet)
  79. {
  80. try
  81. {
  82. Log.log(Log.DEBUG,jEdit.class,"Loading dockables from " + path);
  83. DockableListHandler dh = new DockableListHandler(path,actionSet);
  84. XmlParser parser = new XmlParser();
  85. parser.setHandler(dh);
  86. parser.parse(null, null, in);
  87. return true;
  88. }
  89. catch(XmlException xe)
  90. {
  91. int line = xe.getLine();
  92. String message = xe.getMessage();
  93. Log.log(Log.ERROR,jEdit.class,path + ":" + line
  94. + ": " + message);
  95. }
  96. catch(Exception e)
  97. {
  98. Log.log(Log.ERROR,jEdit.class,e);
  99. }
  100. return false;
  101. } //}}}
  102. //{{{ registerDockableWindow() method
  103. public static void registerDockableWindow(String name, String code,
  104. boolean actions, ActionSet actionSet)
  105. {
  106. dockableWindowFactories.addElement(new Factory(name,code,
  107. actions,actionSet));
  108. } //}}}
  109. //{{{ getRegisteredDockableWindows() method
  110. public static String[] getRegisteredDockableWindows()
  111. {
  112. String[] retVal = new String[dockableWindowFactories.size()];
  113. for(int i = 0; i < dockableWindowFactories.size(); i++)
  114. {
  115. retVal[i] = ((Factory)dockableWindowFactories.elementAt(i)).name;
  116. }
  117. return retVal;
  118. } //}}}
  119. //{{{ DockableListHandler class
  120. static class DockableListHandler extends HandlerBase
  121. {
  122. //{{{ DockableListHandler constructor
  123. DockableListHandler(String path, ActionSet actionSet)
  124. {
  125. this.path = path;
  126. this.actionSet = actionSet;
  127. stateStack = new Stack();
  128. actions = true;
  129. } //}}}
  130. //{{{ resolveEntity() method
  131. public Object resolveEntity(String publicId, String systemId)
  132. {
  133. if("dockables.dtd".equals(systemId))
  134. {
  135. try
  136. {
  137. return new BufferedReader(new InputStreamReader(
  138. getClass().getResourceAsStream
  139. ("/org/gjt/sp/jedit/dockables.dtd")));
  140. }
  141. catch(Exception e)
  142. {
  143. Log.log(Log.ERROR,this,"Error while opening"
  144. + " dockables.dtd:");
  145. Log.log(Log.ERROR,this,e);
  146. }
  147. }
  148. return null;
  149. } //}}}
  150. //{{{ attribute() method
  151. public void attribute(String aname, String value, boolean isSpecified)
  152. {
  153. aname = (aname == null) ? null : aname.intern();
  154. value = (value == null) ? null : value.intern();
  155. if(aname == "NAME")
  156. dockableName = value;
  157. else if(aname == "NO_ACTIONS")
  158. actions = (value == "FALSE");
  159. } //}}}
  160. //{{{ doctypeDecl() method
  161. public void doctypeDecl(String name, String publicId,
  162. String systemId) throws Exception
  163. {
  164. if("DOCKABLES".equals(name))
  165. return;
  166. Log.log(Log.ERROR,this,path + ": DOCTYPE must be DOCKABLES");
  167. } //}}}
  168. //{{{ charData() method
  169. public void charData(char[] c, int off, int len)
  170. {
  171. String tag = peekElement();
  172. String text = new String(c, off, len);
  173. if (tag == "DOCKABLE")
  174. {
  175. code = text;
  176. }
  177. } //}}}
  178. //{{{ startElement() method
  179. public void startElement(String tag)
  180. {
  181. tag = pushElement(tag);
  182. } //}}}
  183. //{{{ endElement() method
  184. public void endElement(String name)
  185. {
  186. if(name == null)
  187. return;
  188. String tag = peekElement();
  189. if(name.equals(tag))
  190. {
  191. if(tag == "DOCKABLE")
  192. {
  193. registerDockableWindow(dockableName,
  194. code,actions,actionSet);
  195. // make default be true for the next
  196. // action
  197. actions = true;
  198. }
  199. popElement();
  200. }
  201. else
  202. {
  203. // can't happen
  204. throw new InternalError();
  205. }
  206. } //}}}
  207. //{{{ startDocument() method
  208. public void startDocument()
  209. {
  210. try
  211. {
  212. pushElement(null);
  213. }
  214. catch (Exception e)
  215. {
  216. e.printStackTrace();
  217. }
  218. } //}}}
  219. //{{{ Private members
  220. //{{{ Instance variables
  221. private String path;
  222. private ActionSet actionSet;
  223. private String dockableName;
  224. private String code;
  225. private boolean actions;
  226. private Stack stateStack;
  227. //}}}
  228. //{{{ pushElement() method
  229. private String pushElement(String name)
  230. {
  231. name = (name == null) ? null : name.intern();
  232. stateStack.push(name);
  233. return name;
  234. } //}}}
  235. //{{{ peekElement() method
  236. private String peekElement()
  237. {
  238. return (String) stateStack.peek();
  239. } //}}}
  240. //{{{ popElement() method
  241. private String popElement()
  242. {
  243. return (String) stateStack.pop();
  244. } //}}}
  245. //}}}
  246. } //}}}
  247. //{{{ Factory class
  248. static class Factory
  249. {
  250. String name;
  251. String code;
  252. //{{{ Factory constructor
  253. Factory(String name, String code, boolean actions, ActionSet actionSet)
  254. {
  255. this.name = name;
  256. this.code = code;
  257. if(actions)
  258. {
  259. actionSet.addAction(new OpenAction());
  260. actionSet.addAction(new ToggleAction());
  261. }
  262. } //}}}
  263. //{{{ createDockableWindow() method
  264. JComponent createDockableWindow(View view, String position)
  265. {
  266. // BACKWARDS COMPATIBILITY with jEdit 2.6-3.2 docking APIs
  267. if(code == null)
  268. {
  269. CreateDockableWindow msg = new CreateDockableWindow(view,name,
  270. position);
  271. EditBus.send(msg);
  272. DockableWindow win = msg.getDockableWindow();
  273. if(win == null)
  274. {
  275. Log.log(Log.ERROR,this,"Unknown dockable window: " + name);
  276. return null;
  277. }
  278. return (JComponent)win.getComponent();
  279. }
  280. // END BACKWARDS COMPATIBILITY
  281. else
  282. {
  283. try
  284. {
  285. BeanShell.getNameSpace().setVariable(
  286. "position",position);
  287. }
  288. catch(EvalError e)
  289. {
  290. Log.log(Log.ERROR,this,e);
  291. }
  292. JComponent win = (JComponent)
  293. BeanShell.eval(view,
  294. code,false);
  295. return win;
  296. }
  297. } //}}}
  298. //{{{ OpenAction class
  299. class OpenAction extends EditAction
  300. {
  301. //{{{ OpenAction constructor
  302. OpenAction()
  303. {
  304. super(name);
  305. } //}}}
  306. //{{{ invoke() method
  307. public void invoke(View view)
  308. {
  309. view.getDockableWindowManager()
  310. .showDockableWindow(name);
  311. } //}}}
  312. //{{{ getCode() method
  313. public String getCode()
  314. {
  315. return "view.getDockableWindowManager()"
  316. + ".showDockableWindow(\"" + name + "\");";
  317. } //}}}
  318. } //}}}
  319. //{{{ ToggleAction class
  320. class ToggleAction extends EditAction
  321. {
  322. //{{{ ToggleAction constructor
  323. ToggleAction()
  324. {
  325. super(name + "-toggle");
  326. } //}}}
  327. //{{{ invoke() method
  328. public void invoke(View view)
  329. {
  330. view.getDockableWindowManager()
  331. .toggleDockableWindow(name);
  332. } //}}}
  333. //{{{ isToggle() method
  334. public boolean isToggle()
  335. {
  336. return true;
  337. } //}}}
  338. //{{{ isSelected() method
  339. public boolean isSelected(View view)
  340. {
  341. return view.getDockableWindowManager()
  342. .isDockableWindowVisible(name);
  343. } //}}}
  344. //{{{ getCode() method
  345. public String getCode()
  346. {
  347. return "view.getDockableWindowManager()"
  348. + ".toggleDockableWindow(\"" + name + "\");";
  349. } //}}}
  350. } //}}}
  351. } //}}}
  352. private static Vector dockableWindowFactories;
  353. //{{{ Static initializer
  354. static
  355. {
  356. dockableWindowFactories = new Vector();
  357. } //}}}
  358. //}}}
  359. //{{{ Instance part of class
  360. //{{{ DockableWindowManager constructor
  361. /**
  362. * Creates a new dockable window manager.
  363. * @param view The view
  364. * @since jEdit 2.6pre3
  365. */
  366. public DockableWindowManager(View view)
  367. {
  368. setLayout(new DockableLayout());
  369. this.view = view;
  370. windows = new Hashtable();
  371. top = new PanelWindowContainer(this,TOP);
  372. left = new PanelWindowContainer(this,LEFT);
  373. bottom = new PanelWindowContainer(this,BOTTOM);
  374. right = new PanelWindowContainer(this,RIGHT);
  375. add(DockableLayout.TOP_BUTTONS,top.getButtonBox());
  376. add(DockableLayout.LEFT_BUTTONS,left.getButtonBox());
  377. add(DockableLayout.BOTTOM_BUTTONS,bottom.getButtonBox());
  378. add(DockableLayout.RIGHT_BUTTONS,right.getButtonBox());
  379. add(TOP,top.getDockablePanel());
  380. add(LEFT,left.getDockablePanel());
  381. add(BOTTOM,bottom.getDockablePanel());
  382. add(RIGHT,right.getDockablePanel());
  383. } //}}}
  384. //{{{ init() method
  385. /**
  386. * Initialises dockable window manager.
  387. * @since jEdit 2.6pre3
  388. */
  389. public void init()
  390. {
  391. for(int i = 0; i < dockableWindowFactories.size(); i++)
  392. {
  393. Factory factory = (Factory)
  394. dockableWindowFactories.elementAt(i);
  395. Entry entry = new Entry(factory);
  396. windows.put(factory.name,entry);
  397. }
  398. String lastTop = jEdit.getProperty("view.dock.top.last");
  399. if(lastTop != null)
  400. showDockableWindow(lastTop);
  401. String lastLeft = jEdit.getProperty("view.dock.left.last");
  402. if(lastLeft != null)
  403. showDockableWindow(lastLeft);
  404. String lastBottom = jEdit.getProperty("view.dock.bottom.last");
  405. if(lastBottom != null)
  406. showDockableWindow(lastBottom);
  407. String lastRight = jEdit.getProperty("view.dock.right.last");
  408. if(lastRight != null)
  409. showDockableWindow(lastRight);
  410. } //}}}
  411. //{{{ getView() method
  412. /**
  413. * Returns this dockable window manager's view.
  414. * @since jEdit 4.0pre2
  415. */
  416. public View getView()
  417. {
  418. return view;
  419. } //}}}
  420. //{{{ showDockableWindow() method
  421. /**
  422. * Opens the specified dockable window.
  423. * @param name The dockable window name
  424. * @since jEdit 2.6pre3
  425. */
  426. public void showDockableWindow(String name)
  427. {
  428. Entry entry = (Entry)windows.get(name);
  429. if(entry == null)
  430. {
  431. Log.log(Log.ERROR,this,"Unknown dockable window: " + name);
  432. return;
  433. }
  434. if(entry.win == null)
  435. entry.open();
  436. if(entry.win != null)
  437. entry.container.show(entry);
  438. else
  439. /* an error occurred */;
  440. } //}}}
  441. //{{{ addDockableWindow() method
  442. /**
  443. * Opens the specified dockable window. As of version 4.0pre1, has the same
  444. * effect as calling showDockableWindow().
  445. * @param name The dockable window name
  446. * @since jEdit 2.6pre3
  447. */
  448. public void addDockableWindow(String name)
  449. {
  450. showDockableWindow(name);
  451. } //}}}
  452. //{{{ removeDockableWindow() method
  453. /**
  454. * Removes the specified dockable window.
  455. * @param name The dockable window name
  456. * @since jEdit 2.6pre3
  457. */
  458. public void removeDockableWindow(String name)
  459. {
  460. Entry entry = (Entry)windows.get(name);
  461. if(entry == null)
  462. {
  463. Log.log(Log.ERROR,this,"This DockableWindowManager"
  464. + " does not have a window named " + name);
  465. return;
  466. }
  467. if(entry.win == null)
  468. return;
  469. if(entry.container instanceof FloatingWindowContainer)
  470. {
  471. entry.container.remove(entry);
  472. entry.container = null;
  473. entry.win = null;
  474. }
  475. else
  476. entry.container.show(null);
  477. } //}}}
  478. //{{{ toggleDockableWindow() method
  479. /**
  480. * Toggles the visibility of the specified dockable window.
  481. * @param name The dockable window name
  482. */
  483. public void toggleDockableWindow(String name)
  484. {
  485. if(isDockableWindowVisible(name))
  486. removeDockableWindow(name);
  487. else
  488. addDockableWindow(name);
  489. } //}}}
  490. //{{{ getDockableWindow() method
  491. /**
  492. * @deprecated The DockableWindow interface is deprecated, as is this
  493. * method. Use <code>getDockable()</code> instead.
  494. */
  495. public DockableWindow getDockableWindow(String name)
  496. {
  497. if(BeanShell.isScriptRunning())
  498. {
  499. Log.log(Log.WARNING,this,"You are using the"
  500. + " DockableWindowManager.getDockableWindow() method in");
  501. Log.log(Log.WARNING,this,"your macro.");
  502. Log.log(Log.WARNING,this,"This method is deprecated and will"
  503. + " be removed in a future jEdit");
  504. Log.log(Log.WARNING,this,"version, because it cannot be used"
  505. + " with newer plugins.");
  506. Log.log(Log.WARNING,this,"Modify the macro to call"
  507. + " DockableWindowManager.getDockable() instead.");
  508. }
  509. /* this is broken, so you should switch to getDockable() ASAP.
  510. * first of all, if the dockable in question returns something
  511. * other than itself from the getComponent() method, it won't
  512. * work. it will also fail with dockables using the new API,
  513. * which don't implement the DockableWindow interface (in
  514. * which case, this method will return null). */
  515. Component comp = getDockable(name);
  516. if(comp instanceof DockableWindow)
  517. return (DockableWindow)comp;
  518. else
  519. return null;
  520. } //}}}
  521. //{{{ getDockable() method
  522. /**
  523. * Returns the specified dockable window. Use this method instead of
  524. * the deprecated <code>getDockableWindow()</code> method.
  525. * @param name The name of the dockable window
  526. * @since jEdit 4.0pre1
  527. */
  528. public JComponent getDockable(String name)
  529. {
  530. Entry entry = (Entry)windows.get(name);
  531. if(entry == null || entry.win == null)
  532. return null;
  533. else
  534. return entry.win;
  535. } //}}}
  536. //{{{ isDockableWindowVisible() method
  537. /**
  538. * Returns if the specified dockable window is visible.
  539. * @param name The dockable window name
  540. */
  541. public boolean isDockableWindowVisible(String name)
  542. {
  543. Entry entry = (Entry)windows.get(name);
  544. if(entry == null || entry.win == null)
  545. return false;
  546. else
  547. return entry.container.isVisible(entry);
  548. } //}}}
  549. //{{{ isDockableWindowDocked() method
  550. /**
  551. * Returns if the specified dockable window is docked into the
  552. * view.
  553. * @param name The dockable's name
  554. * @since jEdit 4.0pre2
  555. */
  556. public boolean isDockableWindowDocked(String name)
  557. {
  558. Entry entry = (Entry)windows.get(name);
  559. if(entry == null)
  560. return false;
  561. else
  562. return (entry.position != FLOATING);
  563. } //}}}
  564. //{{{ close() method
  565. /**
  566. * Called when the view is being closed.
  567. * @since jEdit 2.6pre3
  568. */
  569. public void close()
  570. {
  571. top.save();
  572. left.save();
  573. bottom.save();
  574. right.save();
  575. Enumeration enum = windows.elements();
  576. while(enum.hasMoreElements())
  577. {
  578. Entry entry = (Entry)enum.nextElement();
  579. if(entry.win != null)
  580. entry.remove();
  581. }
  582. } //}}}
  583. //{{{ getTopDockingArea() method
  584. public PanelWindowContainer getTopDockingArea()
  585. {
  586. return top;
  587. } //}}}
  588. //{{{ getLeftDockingArea() method
  589. public PanelWindowContainer getLeftDockingArea()
  590. {
  591. return left;
  592. } //}}}
  593. //{{{ getBottomDockingArea() method
  594. public PanelWindowContainer getBottomDockingArea()
  595. {
  596. return bottom;
  597. } //}}}
  598. //{{{ getRightDockingArea() method
  599. public PanelWindowContainer getRightDockingArea()
  600. {
  601. return right;
  602. } //}}}
  603. //{{{ propertiesChanged() method
  604. /**
  605. * Called by the view when properties change.
  606. * @since jEdit 2.6pre3
  607. */
  608. public void propertiesChanged()
  609. {
  610. alternateLayout = jEdit.getBooleanProperty("view.docking.alternateLayout");
  611. Enumeration enum = windows.elements();
  612. while(enum.hasMoreElements())
  613. {
  614. Entry entry = (Entry)enum.nextElement();
  615. String position = entry.position;
  616. String newPosition = jEdit.getProperty(entry.name
  617. + ".dock-position");
  618. if(newPosition != null /* ??? */
  619. && !newPosition.equals(position))
  620. {
  621. entry.position = newPosition;
  622. if(entry.container != null)
  623. {
  624. entry.container.remove(entry);
  625. entry.container = null;
  626. entry.win = null;
  627. }
  628. if(newPosition.equals(FLOATING))
  629. /* do nothing */;
  630. else
  631. {
  632. if(newPosition.equals(TOP))
  633. entry.container = top;
  634. else if(newPosition.equals(LEFT))
  635. entry.container = left;
  636. else if(newPosition.equals(BOTTOM))
  637. entry.container = bottom;
  638. else if(newPosition.equals(RIGHT))
  639. entry.container = right;
  640. else
  641. throw new InternalError("Unknown position: " + newPosition);
  642. entry.container.register(entry);
  643. }
  644. }
  645. if(entry.container instanceof FloatingWindowContainer)
  646. {
  647. SwingUtilities.updateComponentTreeUI(((JFrame)entry.container)
  648. .getRootPane());
  649. }
  650. }
  651. revalidate();
  652. } //}}}
  653. //{{{ Private members
  654. //{{{ Instance variables
  655. private View view;
  656. private Hashtable windows;
  657. private boolean alternateLayout;
  658. private PanelWindowContainer left;
  659. private PanelWindowContainer right;
  660. private PanelWindowContainer top;
  661. private PanelWindowContainer bottom;
  662. //}}}
  663. //}}}
  664. //}}}
  665. //{{{ DockableLayout class
  666. class DockableLayout implements LayoutManager2
  667. {
  668. // for backwards compatibility with plugins that fiddle with
  669. // jEdit's UI layout
  670. static final String CENTER = BorderLayout.CENTER;
  671. static final String TOP_BUTTONS = "top-buttons";
  672. static final String LEFT_BUTTONS = "left-buttons";
  673. static final String BOTTOM_BUTTONS = "bottom-buttons";
  674. static final String RIGHT_BUTTONS = "right-buttons";
  675. Component center;
  676. Component top, left, bottom, right;
  677. Component topButtons, leftButtons, bottomButtons, rightButtons;
  678. //{{{ addLayoutComponent() method
  679. public void addLayoutComponent(String name, Component comp)
  680. {
  681. addLayoutComponent(comp,name);
  682. } //}}}
  683. //{{{ addLayoutComponent() method
  684. public void addLayoutComponent(Component comp, Object cons)
  685. {
  686. if(cons == null || CENTER.equals(cons))
  687. center = comp;
  688. else if(TOP.equals(cons))
  689. top = comp;
  690. else if(LEFT.equals(cons))
  691. left = comp;
  692. else if(BOTTOM.equals(cons))
  693. bottom = comp;
  694. else if(RIGHT.equals(cons))
  695. right = comp;
  696. else if(TOP_BUTTONS.equals(cons))
  697. topButtons = comp;
  698. else if(LEFT_BUTTONS.equals(cons))
  699. leftButtons = comp;
  700. else if(BOTTOM_BUTTONS.equals(cons))
  701. bottomButtons = comp;
  702. else if(RIGHT_BUTTONS.equals(cons))
  703. rightButtons = comp;
  704. } //}}}
  705. //{{{ removeLayoutComponent() method
  706. public void removeLayoutComponent(Component comp)
  707. {
  708. if(center == comp)
  709. center = null;
  710. else
  711. {
  712. // none of the others are ever meant to be
  713. // removed. retarded, eh?
  714. }
  715. } //}}}
  716. //{{{ preferredLayoutSize() method
  717. public Dimension preferredLayoutSize(Container parent)
  718. {
  719. Dimension prefSize = new Dimension(0,0);
  720. Dimension _top = top.getPreferredSize();
  721. Dimension _left = left.getPreferredSize();
  722. Dimension _bottom = bottom.getPreferredSize();
  723. Dimension _right = right.getPreferredSize();
  724. Dimension _topButtons = topButtons.getPreferredSize();
  725. Dimension _leftButtons = leftButtons.getPreferredSize();
  726. Dimension _bottomButtons = bottomButtons.getPreferredSize();
  727. Dimension _rightButtons = rightButtons.getPreferredSize();
  728. Dimension _center = (center == null
  729. ? new Dimension(0,0)
  730. : center.getPreferredSize());
  731. prefSize.height = _top.height + _bottom.height + _center.height
  732. + _topButtons.height + _bottomButtons.height;
  733. prefSize.width = _left.width + _right.width + _center.width
  734. + _leftButtons.width + _rightButtons.width;
  735. return prefSize;
  736. } //}}}
  737. //{{{ minimumLayoutSize() method
  738. public Dimension minimumLayoutSize(Container parent)
  739. {
  740. Dimension minSize = new Dimension(0,0);
  741. Dimension _top = top.getMinimumSize();
  742. Dimension _left = left.getMinimumSize();
  743. Dimension _bottom = bottom.getMinimumSize();
  744. Dimension _right = right.getMinimumSize();
  745. Dimension _topButtons = topButtons.getMinimumSize();
  746. Dimension _leftButtons = leftButtons.getMinimumSize();
  747. Dimension _bottomButtons = bottomButtons.getMinimumSize();
  748. Dimension _rightButtons = rightButtons.getMinimumSize();
  749. Dimension _center = (center == null
  750. ? new Dimension(0,0)
  751. : center.getMinimumSize());
  752. minSize.height = _top.height + _bottom.height + _center.height
  753. + _topButtons.height + _bottomButtons.height;
  754. minSize.width = _left.width + _right.width + _center.width
  755. + _leftButtons.width + _rightButtons.width;
  756. return minSize;
  757. } //}}}
  758. //{{{ maximumLayoutSize() method
  759. public Dimension maximumLayoutSize(Container parent)
  760. {
  761. return new Dimension(Integer.MAX_VALUE,Integer.MAX_VALUE);
  762. } //}}}
  763. //{{{ layoutContainer() method
  764. public void layoutContainer(Container parent)
  765. {
  766. Dimension size = parent.getSize();
  767. Dimension prefSize = new Dimension(0,0);
  768. Dimension _top = top.getPreferredSize();
  769. Dimension _left = left.getPreferredSize();
  770. Dimension _bottom = bottom.getPreferredSize();
  771. Dimension _right = right.getPreferredSize();
  772. Dimension _topButtons = topButtons.getPreferredSize();
  773. Dimension _leftButtons = leftButtons.getPreferredSize();
  774. Dimension _bottomButtons = bottomButtons.getPreferredSize();
  775. Dimension _rightButtons = rightButtons.getPreferredSize();
  776. Dimension _center = (center == null
  777. ? new Dimension(0,0)
  778. : center.getPreferredSize());
  779. int _width = size.width - _leftButtons.width - _rightButtons.width;
  780. int _height = size.height - _topButtons.height - _bottomButtons.height;
  781. if(alternateLayout)
  782. {
  783. topButtons.setBounds(
  784. _leftButtons.width,
  785. 0,
  786. _width,
  787. _topButtons.height);
  788. leftButtons.setBounds(
  789. 0,
  790. _topButtons.height + _top.height,
  791. _leftButtons.width,
  792. _height - _top.height - _bottom.height);
  793. bottomButtons.setBounds(
  794. _leftButtons.width,
  795. size.height - _bottomButtons.height,
  796. _width,
  797. _bottomButtons.height);
  798. rightButtons.setBounds(
  799. size.width - _rightButtons.width,
  800. _topButtons.height + _top.height,
  801. _rightButtons.width,
  802. _height - _top.height - _bottom.height);
  803. top.setBounds(
  804. _leftButtons.width,
  805. _topButtons.height,
  806. _width,
  807. _top.height);
  808. bottom.setBounds(
  809. _leftButtons.width,
  810. size.height - _bottom.height - _bottomButtons.height,
  811. _width,
  812. _bottom.height);
  813. left.setBounds(
  814. _leftButtons.width,
  815. _topButtons.height + _top.height,
  816. _left.width,
  817. _height - _top.height - _bottom.height);
  818. right.setBounds(
  819. size.width - _right.width - _rightButtons.width,
  820. _topButtons.height + _top.height,
  821. _right.width,
  822. _height - _top.height - _bottom.height);
  823. }
  824. else
  825. {
  826. topButtons.setBounds(
  827. _leftButtons.width + _left.width,
  828. 0,
  829. _width - _left.width - _right.width,
  830. _topButtons.height);
  831. leftButtons.setBounds(
  832. 0,
  833. _topButtons.height,
  834. _leftButtons.width,
  835. _height);
  836. bottomButtons.setBounds(
  837. _leftButtons.width + _left.width,
  838. size.height - _bottomButtons.height,
  839. _width - _left.width - _right.width,
  840. _bottomButtons.height);
  841. rightButtons.setBounds(
  842. size.width - _rightButtons.width,
  843. _topButtons.height,
  844. _rightButtons.width,
  845. _height);
  846. top.setBounds(
  847. _leftButtons.width + _left.width,
  848. _topButtons.height,
  849. _width - _left.width - _right.width,
  850. _top.height);
  851. bottom.setBounds(
  852. _leftButtons.width + _left.width,
  853. size.height - _bottom.height - _bottomButtons.height,
  854. _width - _left.width - _right.width,
  855. _bottom.height);
  856. left.setBounds(
  857. _leftButtons.width,
  858. _topButtons.height,
  859. _left.width,
  860. _height);
  861. right.setBounds(
  862. size.width - _right.width - _rightButtons.width,
  863. _topButtons.height,
  864. _right.width,
  865. _height);
  866. }
  867. if(center != null)
  868. {
  869. center.setBounds(
  870. _leftButtons.width + _left.width,
  871. _topButtons.height + _top.height,
  872. _width - _left.width - _right.width,
  873. _height - _top.height - _bottom.height);
  874. }
  875. } //}}}
  876. //{{{ getLayoutAlignmentX() method
  877. public float getLayoutAlignmentX(Container target)
  878. {
  879. return 0.5f;
  880. } //}}}
  881. //{{{ getLayoutAlignmentY() method
  882. public float getLayoutAlignmentY(Container target)
  883. {
  884. return 0.5f;
  885. } //}}}
  886. //{{{ invalidateLayout() method
  887. public void invalidateLayout(Container target) {}
  888. //}}}
  889. } //}}}
  890. //{{{ Entry class
  891. class Entry
  892. {
  893. Factory factory;
  894. String name;
  895. String position;
  896. String title;
  897. DockableWindowContainer container;
  898. // only set if open
  899. JComponent win;
  900. //{{{ Entry constructor
  901. Entry(Factory factory)
  902. {
  903. this.factory = factory;
  904. this.name = factory.name;
  905. this.position = jEdit.getProperty(name + ".dock-position",
  906. FLOATING);
  907. title = jEdit.getProperty(name + ".title");
  908. if(position == null)
  909. position = FLOATING;
  910. if(position.equals(FLOATING))
  911. /* do nothing */;
  912. else
  913. {
  914. if(position.equals(TOP))
  915. container = top;
  916. else if(position.equals(LEFT))
  917. container = left;
  918. else if(position.equals(BOTTOM))
  919. container = bottom;
  920. else if(position.equals(RIGHT))
  921. container = right;
  922. else
  923. throw new InternalError("Unknown position: " + position);
  924. container.register(this);
  925. }
  926. } //}}}
  927. //{{{ open() method
  928. void open()
  929. {
  930. win = factory.createDockableWindow(view,position);
  931. if(win == null)
  932. {
  933. // error occurred
  934. return;
  935. }
  936. Log.log(Log.DEBUG,this,"Adding " + name + " with position " + position);
  937. if(position.equals(FLOATING))
  938. {
  939. container = new FloatingWindowContainer(
  940. DockableWindowManager.this);
  941. container.register(this);
  942. }
  943. container.add(this);
  944. } //}}}
  945. //{{{ remove() method
  946. void remove()
  947. {
  948. Log.log(Log.DEBUG,this,"Removing " + name + " from "
  949. + container);
  950. container.save(this);
  951. container.remove(this);
  952. if(container instanceof FloatingWindowContainer)
  953. container = null;
  954. win = null;
  955. } //}}}
  956. } //}}}
  957. }