PageRenderTime 47ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 1111 lines | 760 code | 144 blank | 207 comment | 117 complexity | 903f0519d201faf93cbab3e8e99d7eb5 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 4012 2002-02-05 06:28:10Z 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.save(entry);
  472. entry.container.remove(entry);
  473. entry.container = null;
  474. entry.win = null;
  475. }
  476. else
  477. entry.container.show(null);
  478. } //}}}
  479. //{{{ toggleDockableWindow() method
  480. /**
  481. * Toggles the visibility of the specified dockable window.
  482. * @param name The dockable window name
  483. */
  484. public void toggleDockableWindow(String name)
  485. {
  486. if(isDockableWindowVisible(name))
  487. removeDockableWindow(name);
  488. else
  489. addDockableWindow(name);
  490. } //}}}
  491. //{{{ getDockableWindow() method
  492. /**
  493. * @deprecated The DockableWindow interface is deprecated, as is this
  494. * method. Use <code>getDockable()</code> instead.
  495. */
  496. public DockableWindow getDockableWindow(String name)
  497. {
  498. if(BeanShell.isScriptRunning())
  499. {
  500. Log.log(Log.WARNING,this,"You are using the"
  501. + " DockableWindowManager.getDockableWindow() method in");
  502. Log.log(Log.WARNING,this,"your macro.");
  503. Log.log(Log.WARNING,this,"This method is deprecated and will"
  504. + " be removed in a future jEdit");
  505. Log.log(Log.WARNING,this,"version, because it cannot be used"
  506. + " with newer plugins.");
  507. Log.log(Log.WARNING,this,"Modify the macro to call"
  508. + " DockableWindowManager.getDockable() instead.");
  509. }
  510. /* this is broken, so you should switch to getDockable() ASAP.
  511. * first of all, if the dockable in question returns something
  512. * other than itself from the getComponent() method, it won't
  513. * work. it will also fail with dockables using the new API,
  514. * which don't implement the DockableWindow interface (in
  515. * which case, this method will return null). */
  516. Component comp = getDockable(name);
  517. if(comp instanceof DockableWindow)
  518. return (DockableWindow)comp;
  519. else
  520. return null;
  521. } //}}}
  522. //{{{ getDockable() method
  523. /**
  524. * Returns the specified dockable window. Use this method instead of
  525. * the deprecated <code>getDockableWindow()</code> method.
  526. * @param name The name of the dockable window
  527. * @since jEdit 4.0pre1
  528. */
  529. public JComponent getDockable(String name)
  530. {
  531. Entry entry = (Entry)windows.get(name);
  532. if(entry == null || entry.win == null)
  533. return null;
  534. else
  535. return entry.win;
  536. } //}}}
  537. //{{{ isDockableWindowVisible() method
  538. /**
  539. * Returns if the specified dockable window is visible.
  540. * @param name The dockable window name
  541. */
  542. public boolean isDockableWindowVisible(String name)
  543. {
  544. Entry entry = (Entry)windows.get(name);
  545. if(entry == null || entry.win == null)
  546. return false;
  547. else
  548. return entry.container.isVisible(entry);
  549. } //}}}
  550. //{{{ isDockableWindowDocked() method
  551. /**
  552. * Returns if the specified dockable window is docked into the
  553. * view.
  554. * @param name The dockable's name
  555. * @since jEdit 4.0pre2
  556. */
  557. public boolean isDockableWindowDocked(String name)
  558. {
  559. Entry entry = (Entry)windows.get(name);
  560. if(entry == null)
  561. return false;
  562. else
  563. return (entry.position != FLOATING);
  564. } //}}}
  565. //{{{ close() method
  566. /**
  567. * Called when the view is being closed.
  568. * @since jEdit 2.6pre3
  569. */
  570. public void close()
  571. {
  572. top.save();
  573. left.save();
  574. bottom.save();
  575. right.save();
  576. Enumeration enum = windows.elements();
  577. while(enum.hasMoreElements())
  578. {
  579. Entry entry = (Entry)enum.nextElement();
  580. if(entry.win != null)
  581. entry.remove();
  582. }
  583. } //}}}
  584. //{{{ getTopDockingArea() method
  585. public PanelWindowContainer getTopDockingArea()
  586. {
  587. return top;
  588. } //}}}
  589. //{{{ getLeftDockingArea() method
  590. public PanelWindowContainer getLeftDockingArea()
  591. {
  592. return left;
  593. } //}}}
  594. //{{{ getBottomDockingArea() method
  595. public PanelWindowContainer getBottomDockingArea()
  596. {
  597. return bottom;
  598. } //}}}
  599. //{{{ getRightDockingArea() method
  600. public PanelWindowContainer getRightDockingArea()
  601. {
  602. return right;
  603. } //}}}
  604. //{{{ propertiesChanged() method
  605. /**
  606. * Called by the view when properties change.
  607. * @since jEdit 2.6pre3
  608. */
  609. public void propertiesChanged()
  610. {
  611. alternateLayout = jEdit.getBooleanProperty("view.docking.alternateLayout");
  612. Enumeration enum = windows.elements();
  613. while(enum.hasMoreElements())
  614. {
  615. Entry entry = (Entry)enum.nextElement();
  616. String position = entry.position;
  617. String newPosition = jEdit.getProperty(entry.name
  618. + ".dock-position");
  619. if(newPosition != null /* ??? */
  620. && !newPosition.equals(position))
  621. {
  622. entry.position = newPosition;
  623. if(entry.container != null)
  624. {
  625. entry.container.remove(entry);
  626. entry.container = null;
  627. entry.win = null;
  628. }
  629. if(newPosition.equals(FLOATING))
  630. /* do nothing */;
  631. else
  632. {
  633. if(newPosition.equals(TOP))
  634. entry.container = top;
  635. else if(newPosition.equals(LEFT))
  636. entry.container = left;
  637. else if(newPosition.equals(BOTTOM))
  638. entry.container = bottom;
  639. else if(newPosition.equals(RIGHT))
  640. entry.container = right;
  641. else
  642. throw new InternalError("Unknown position: " + newPosition);
  643. entry.container.register(entry);
  644. }
  645. }
  646. if(entry.container instanceof FloatingWindowContainer)
  647. {
  648. SwingUtilities.updateComponentTreeUI(((JFrame)entry.container)
  649. .getRootPane());
  650. }
  651. }
  652. revalidate();
  653. } //}}}
  654. //{{{ Private members
  655. //{{{ Instance variables
  656. private View view;
  657. private Hashtable windows;
  658. private boolean alternateLayout;
  659. private PanelWindowContainer left;
  660. private PanelWindowContainer right;
  661. private PanelWindowContainer top;
  662. private PanelWindowContainer bottom;
  663. //}}}
  664. //}}}
  665. //}}}
  666. //{{{ DockableLayout class
  667. class DockableLayout implements LayoutManager2
  668. {
  669. // for backwards compatibility with plugins that fiddle with
  670. // jEdit's UI layout
  671. static final String CENTER = BorderLayout.CENTER;
  672. static final String TOP_BUTTONS = "top-buttons";
  673. static final String LEFT_BUTTONS = "left-buttons";
  674. static final String BOTTOM_BUTTONS = "bottom-buttons";
  675. static final String RIGHT_BUTTONS = "right-buttons";
  676. Component center;
  677. Component top, left, bottom, right;
  678. Component topButtons, leftButtons, bottomButtons, rightButtons;
  679. //{{{ addLayoutComponent() method
  680. public void addLayoutComponent(String name, Component comp)
  681. {
  682. addLayoutComponent(comp,name);
  683. } //}}}
  684. //{{{ addLayoutComponent() method
  685. public void addLayoutComponent(Component comp, Object cons)
  686. {
  687. if(cons == null || CENTER.equals(cons))
  688. center = comp;
  689. else if(TOP.equals(cons))
  690. top = comp;
  691. else if(LEFT.equals(cons))
  692. left = comp;
  693. else if(BOTTOM.equals(cons))
  694. bottom = comp;
  695. else if(RIGHT.equals(cons))
  696. right = comp;
  697. else if(TOP_BUTTONS.equals(cons))
  698. topButtons = comp;
  699. else if(LEFT_BUTTONS.equals(cons))
  700. leftButtons = comp;
  701. else if(BOTTOM_BUTTONS.equals(cons))
  702. bottomButtons = comp;
  703. else if(RIGHT_BUTTONS.equals(cons))
  704. rightButtons = comp;
  705. } //}}}
  706. //{{{ removeLayoutComponent() method
  707. public void removeLayoutComponent(Component comp)
  708. {
  709. if(center == comp)
  710. center = null;
  711. else
  712. {
  713. // none of the others are ever meant to be
  714. // removed. retarded, eh?
  715. }
  716. } //}}}
  717. //{{{ preferredLayoutSize() method
  718. public Dimension preferredLayoutSize(Container parent)
  719. {
  720. Dimension prefSize = new Dimension(0,0);
  721. Dimension _top = top.getPreferredSize();
  722. Dimension _left = left.getPreferredSize();
  723. Dimension _bottom = bottom.getPreferredSize();
  724. Dimension _right = right.getPreferredSize();
  725. Dimension _topButtons = topButtons.getPreferredSize();
  726. Dimension _leftButtons = leftButtons.getPreferredSize();
  727. Dimension _bottomButtons = bottomButtons.getPreferredSize();
  728. Dimension _rightButtons = rightButtons.getPreferredSize();
  729. Dimension _center = (center == null
  730. ? new Dimension(0,0)
  731. : center.getPreferredSize());
  732. prefSize.height = _top.height + _bottom.height + _center.height
  733. + _topButtons.height + _bottomButtons.height;
  734. prefSize.width = _left.width + _right.width + _center.width
  735. + _leftButtons.width + _rightButtons.width;
  736. return prefSize;
  737. } //}}}
  738. //{{{ minimumLayoutSize() method
  739. public Dimension minimumLayoutSize(Container parent)
  740. {
  741. Dimension minSize = new Dimension(0,0);
  742. Dimension _top = top.getMinimumSize();
  743. Dimension _left = left.getMinimumSize();
  744. Dimension _bottom = bottom.getMinimumSize();
  745. Dimension _right = right.getMinimumSize();
  746. Dimension _topButtons = topButtons.getMinimumSize();
  747. Dimension _leftButtons = leftButtons.getMinimumSize();
  748. Dimension _bottomButtons = bottomButtons.getMinimumSize();
  749. Dimension _rightButtons = rightButtons.getMinimumSize();
  750. Dimension _center = (center == null
  751. ? new Dimension(0,0)
  752. : center.getMinimumSize());
  753. minSize.height = _top.height + _bottom.height + _center.height
  754. + _topButtons.height + _bottomButtons.height;
  755. minSize.width = _left.width + _right.width + _center.width
  756. + _leftButtons.width + _rightButtons.width;
  757. return minSize;
  758. } //}}}
  759. //{{{ maximumLayoutSize() method
  760. public Dimension maximumLayoutSize(Container parent)
  761. {
  762. return new Dimension(Integer.MAX_VALUE,Integer.MAX_VALUE);
  763. } //}}}
  764. //{{{ layoutContainer() method
  765. public void layoutContainer(Container parent)
  766. {
  767. Dimension size = parent.getSize();
  768. Dimension _topButtons = topButtons.getPreferredSize();
  769. Dimension _leftButtons = leftButtons.getPreferredSize();
  770. Dimension _bottomButtons = bottomButtons.getPreferredSize();
  771. Dimension _rightButtons = rightButtons.getPreferredSize();
  772. Dimension _center = (center == null
  773. ? new Dimension(0,0)
  774. : center.getPreferredSize());
  775. int _width = size.width - _leftButtons.width - _rightButtons.width;
  776. int _height = size.height - _topButtons.height - _bottomButtons.height;
  777. Dimension _top = top.getPreferredSize();
  778. Dimension _left = left.getPreferredSize();
  779. Dimension _bottom = bottom.getPreferredSize();
  780. Dimension _right = right.getPreferredSize();
  781. int topHeight = Math.min(Math.max(0,_height - _bottom.height),_top.height);
  782. int leftWidth = Math.min(Math.max(0,_width - _right.width),_left.width);
  783. int bottomHeight = Math.min(Math.max(0,_height - topHeight),_bottom.height);
  784. int rightWidth = Math.min(Math.max(0,_width - leftWidth),_right.width);
  785. if(alternateLayout)
  786. {
  787. topButtons.setBounds(
  788. _leftButtons.width,
  789. 0,
  790. _width,
  791. _topButtons.height);
  792. leftButtons.setBounds(
  793. 0,
  794. _topButtons.height + _top.height,
  795. _leftButtons.width,
  796. _height - _top.height - _bottom.height);
  797. bottomButtons.setBounds(
  798. _leftButtons.width,
  799. size.height - _bottomButtons.height,
  800. _width,
  801. _bottomButtons.height);
  802. rightButtons.setBounds(
  803. size.width - _rightButtons.width,
  804. _topButtons.height + _top.height,
  805. _rightButtons.width,
  806. _height - _top.height - _bottom.height);
  807. top.setBounds(
  808. _leftButtons.width,
  809. _topButtons.height,
  810. _width,
  811. topHeight);
  812. bottom.setBounds(
  813. _leftButtons.width,
  814. size.height - bottomHeight - _bottomButtons.height,
  815. _width,
  816. bottomHeight);
  817. left.setBounds(
  818. _leftButtons.width,
  819. _topButtons.height + topHeight,
  820. leftWidth,
  821. _height - topHeight - bottomHeight);
  822. right.setBounds(
  823. size.width - rightWidth - _rightButtons.width,
  824. _topButtons.height + topHeight,
  825. rightWidth,
  826. _height - topHeight - bottomHeight);
  827. }
  828. else
  829. {
  830. topButtons.setBounds(
  831. _leftButtons.width + leftWidth,
  832. 0,
  833. _width - leftWidth - rightWidth,
  834. _topButtons.height);
  835. leftButtons.setBounds(
  836. 0,
  837. _topButtons.height,
  838. _leftButtons.width,
  839. _height);
  840. bottomButtons.setBounds(
  841. _leftButtons.width + leftWidth,
  842. size.height - _bottomButtons.height,
  843. _width - leftWidth - rightWidth,
  844. _bottomButtons.height);
  845. rightButtons.setBounds(
  846. size.width - _rightButtons.width,
  847. _topButtons.height,
  848. _rightButtons.width,
  849. _height);
  850. top.setBounds(
  851. _leftButtons.width + leftWidth,
  852. _topButtons.height,
  853. _width - leftWidth - rightWidth,
  854. topHeight);
  855. bottom.setBounds(
  856. _leftButtons.width + leftWidth,
  857. size.height - bottomHeight - _bottomButtons.height,
  858. _width - leftWidth - rightWidth,
  859. bottomHeight);
  860. left.setBounds(
  861. _leftButtons.width,
  862. _topButtons.height,
  863. leftWidth,
  864. _height);
  865. right.setBounds(
  866. size.width - rightWidth - _rightButtons.width,
  867. _topButtons.height,
  868. rightWidth,
  869. _height);
  870. }
  871. if(center != null)
  872. {
  873. center.setBounds(
  874. _leftButtons.width + _left.width,
  875. _topButtons.height + _top.height,
  876. _width - _left.width - _right.width,
  877. _height - _top.height - _bottom.height);
  878. }
  879. } //}}}
  880. //{{{ getLayoutAlignmentX() method
  881. public float getLayoutAlignmentX(Container target)
  882. {
  883. return 0.5f;
  884. } //}}}
  885. //{{{ getLayoutAlignmentY() method
  886. public float getLayoutAlignmentY(Container target)
  887. {
  888. return 0.5f;
  889. } //}}}
  890. //{{{ invalidateLayout() method
  891. public void invalidateLayout(Container target) {}
  892. //}}}
  893. } //}}}
  894. //{{{ Entry class
  895. class Entry
  896. {
  897. Factory factory;
  898. String name;
  899. String position;
  900. String title;
  901. DockableWindowContainer container;
  902. // only set if open
  903. JComponent win;
  904. //{{{ Entry constructor
  905. Entry(Factory factory)
  906. {
  907. this.factory = factory;
  908. this.name = factory.name;
  909. this.position = jEdit.getProperty(name + ".dock-position",
  910. FLOATING);
  911. title = jEdit.getProperty(name + ".title");
  912. if(title == null)
  913. {
  914. Log.log(Log.WARNING,this,name + ".title property"
  915. + " not defined");
  916. title = name;
  917. }
  918. if(position == null)
  919. position = FLOATING;
  920. if(position.equals(FLOATING))
  921. /* do nothing */;
  922. else
  923. {
  924. if(position.equals(TOP))
  925. container = top;
  926. else if(position.equals(LEFT))
  927. container = left;
  928. else if(position.equals(BOTTOM))
  929. container = bottom;
  930. else if(position.equals(RIGHT))
  931. container = right;
  932. else
  933. throw new InternalError("Unknown position: " + position);
  934. container.register(this);
  935. }
  936. } //}}}
  937. //{{{ open() method
  938. void open()
  939. {
  940. win = factory.createDockableWindow(view,position);
  941. if(win == null)
  942. {
  943. // error occurred
  944. return;
  945. }
  946. Log.log(Log.DEBUG,this,"Adding " + name + " with position " + position);
  947. if(position.equals(FLOATING))
  948. {
  949. container = new FloatingWindowContainer(
  950. DockableWindowManager.this);
  951. container.register(this);
  952. }
  953. container.add(this);
  954. } //}}}
  955. //{{{ remove() method
  956. void remove()
  957. {
  958. Log.log(Log.DEBUG,this,"Removing " + name + " from "
  959. + container);
  960. container.save(this);
  961. container.remove(this);
  962. if(container instanceof FloatingWindowContainer)
  963. container = null;
  964. win = null;
  965. } //}}}
  966. } //}}}
  967. }