PageRenderTime 55ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/org/gjt/sp/jedit/gui/PanelWindowContainer.java

#
Java | 923 lines | 686 code | 112 blank | 125 comment | 114 complexity | cf6434d44ca6acaf60b8097e929d5ac7 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. * PanelWindowContainer.java - holds dockable windows
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2000, 2004 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 javax.swing.border.*;
  25. import javax.swing.plaf.metal.*;
  26. import javax.swing.*;
  27. import java.awt.event.*;
  28. import java.awt.font.*;
  29. import java.awt.geom.AffineTransform;
  30. import java.awt.*;
  31. import java.util.*;
  32. import org.gjt.sp.jedit.*;
  33. //}}}
  34. /**
  35. * A container for dockable windows. This class should never be used
  36. * directly.
  37. * @author Slava Pestov
  38. * @version $Id: PanelWindowContainer.java 5516 2006-07-03 16:27:09Z ezust $
  39. * @since jEdit 4.0pre1
  40. */
  41. public class PanelWindowContainer implements DockableWindowContainer
  42. {
  43. //{{{ PanelWindowContainer constructor
  44. public PanelWindowContainer(DockableWindowManager wm, String position,
  45. int dimension)
  46. {
  47. this.wm = wm;
  48. this.position = position;
  49. //{{{ Button box setup
  50. buttonPanel = new JPanel(new ButtonLayout());
  51. buttonPanel.setBorder(new EmptyBorder(1,1,1,1));
  52. closeBox = new JButton(GUIUtilities.loadIcon("closebox.gif"));
  53. closeBox.setRequestFocusEnabled(false);
  54. closeBox.setToolTipText(jEdit.getProperty("view.docking.close-tooltip"));
  55. if(OperatingSystem.isMacOSLF())
  56. closeBox.putClientProperty("JButton.buttonType","toolbar");
  57. closeBox.setMargin(new Insets(0,0,0,0));
  58. closeBox.addActionListener(new ActionHandler());
  59. menuBtn = new JButton(GUIUtilities.loadIcon("ToolbarMenu.gif"));
  60. menuBtn.setRequestFocusEnabled(false);
  61. menuBtn.setToolTipText(jEdit.getProperty("view.docking.menu-tooltip"));
  62. if(OperatingSystem.isMacOSLF())
  63. menuBtn.putClientProperty("JButton.buttonType","toolbar");
  64. menuBtn.setMargin(new Insets(0,0,0,0));
  65. menuBtn.addMouseListener(new MenuMouseHandler());
  66. buttonGroup = new ButtonGroup();
  67. // JDK 1.4 workaround
  68. buttonGroup.add(nullButton = new JToggleButton());
  69. //}}}
  70. dockables = new ArrayList();
  71. buttons = new ArrayList();
  72. dockablePanel = new DockablePanel(this);
  73. this.dimension = dimension;
  74. } //}}}
  75. //{{{ getDockableWindowManager() method
  76. /**
  77. * @since jEdit 4.3pre2
  78. */
  79. public DockableWindowManager getDockableWindowManager()
  80. {
  81. return wm;
  82. } //}}}
  83. //{{{ register() method
  84. public void register(final DockableWindowManager.Entry entry)
  85. {
  86. dockables.add(entry);
  87. //{{{ Create button
  88. int rotation;
  89. if(position.equals(DockableWindowManager.TOP)
  90. || position.equals(DockableWindowManager.BOTTOM))
  91. rotation = RotatedTextIcon.NONE;
  92. else if(position.equals(DockableWindowManager.LEFT))
  93. rotation = RotatedTextIcon.CCW;
  94. else if(position.equals(DockableWindowManager.RIGHT))
  95. rotation = RotatedTextIcon.CW;
  96. else
  97. throw new InternalError("Invalid position: " + position);
  98. JToggleButton button = new JToggleButton();
  99. button.setMargin(new Insets(1,1,1,1));
  100. button.setRequestFocusEnabled(false);
  101. button.setIcon(new RotatedTextIcon(rotation,button.getFont(),
  102. entry.label()));
  103. button.setActionCommand(entry.factory.name);
  104. button.addActionListener(new ActionHandler());
  105. button.addMouseListener(new MenuMouseHandler());
  106. if(OperatingSystem.isMacOSLF())
  107. button.putClientProperty("JButton.buttonType","toolbar");
  108. //}}}
  109. buttonGroup.add(button);
  110. buttons.add(button);
  111. entry.btn = button;
  112. wm.revalidate();
  113. } //}}}
  114. //{{{ unregister() method
  115. public void unregister(DockableWindowManager.Entry entry)
  116. {
  117. if(entry.factory.name.equals(mostRecent))
  118. mostRecent = null;
  119. if(entry.btn != null)
  120. {
  121. buttonPanel.remove(entry.btn);
  122. buttons.remove(entry.btn);
  123. entry.btn = null;
  124. }
  125. dockables.remove(entry);
  126. if(entry.win != null)
  127. dockablePanel.remove(entry.win);
  128. if(current == entry)
  129. {
  130. current = null;
  131. show(null);
  132. }
  133. else
  134. {
  135. wm.revalidate();
  136. dockablePanel.repaint();
  137. buttonPanel.repaint();
  138. }
  139. } //}}}
  140. //{{{ remove() method
  141. public void remove(final DockableWindowManager.Entry entry)
  142. {
  143. if(entry.factory.name.equals(mostRecent))
  144. mostRecent = null;
  145. if(entry.win != null)
  146. {
  147. dockablePanel.remove(entry.win);
  148. entry.win = null;
  149. }
  150. if(current == entry)
  151. {
  152. current = null;
  153. show(null);
  154. }
  155. else
  156. {
  157. wm.revalidate();
  158. dockablePanel.repaint();
  159. }
  160. } //}}}
  161. //{{{ showMostRecent() method
  162. public void showMostRecent()
  163. {
  164. if(dockables.size() == 0)
  165. {
  166. Toolkit.getDefaultToolkit().beep();
  167. return;
  168. }
  169. if(mostRecent == null)
  170. {
  171. mostRecent = ((DockableWindowManager.Entry)
  172. dockables.get(0)).factory.name;
  173. }
  174. wm.showDockableWindow(mostRecent);
  175. } //}}}
  176. //{{{ show() method
  177. public void show(final DockableWindowManager.Entry entry)
  178. {
  179. if(current == entry)
  180. {
  181. if(entry != null)
  182. {
  183. if(entry.win instanceof DefaultFocusComponent)
  184. {
  185. ((DefaultFocusComponent)entry.win)
  186. .focusOnDefaultComponent();
  187. }
  188. else
  189. {
  190. entry.win.requestDefaultFocus();
  191. }
  192. }
  193. return;
  194. }
  195. if(entry != null)
  196. {
  197. if(current == null)
  198. {
  199. // we didn't have a component previously, so
  200. // create a border
  201. dockablePanel.setBorder(new DockBorder(position));
  202. }
  203. mostRecent = entry.factory.name;
  204. this.current = entry;
  205. if(entry.win.getParent() != dockablePanel)
  206. dockablePanel.add(entry.factory.name,entry.win);
  207. dockablePanel.showDockable(entry.factory.name);
  208. entry.btn.setSelected(true);
  209. if(entry.win instanceof DefaultFocusComponent)
  210. {
  211. ((DefaultFocusComponent)entry.win)
  212. .focusOnDefaultComponent();
  213. }
  214. else
  215. {
  216. entry.win.requestDefaultFocus();
  217. }
  218. }
  219. else
  220. {
  221. current = null;
  222. nullButton.setSelected(true);
  223. // removing last component, so remove border
  224. dockablePanel.setBorder(null);
  225. wm.getView().getTextArea().requestFocus();
  226. }
  227. wm.revalidate();
  228. dockablePanel.repaint();
  229. } //}}}
  230. //{{{ isVisible() method
  231. public boolean isVisible(DockableWindowManager.Entry entry)
  232. {
  233. return current == entry;
  234. } //}}}
  235. //{{{ getCurrent() method
  236. /**
  237. * Returns the name of the dockable in this container.
  238. * @since jEdit 4.2pre1
  239. */
  240. public String getCurrent()
  241. {
  242. if(current == null)
  243. return null;
  244. else
  245. return current.factory.name;
  246. } //}}}
  247. //{{{ getDimension() method
  248. /**
  249. * Returns the width or height (depending on position) of the dockable
  250. * window container.
  251. * @since jEdit 4.2pre1
  252. */
  253. public int getDimension()
  254. {
  255. return dimension;
  256. } //}}}
  257. //{{{ getPosition() method
  258. /**
  259. * @since jEdit 4.3pre2
  260. */
  261. public String getPosition()
  262. {
  263. return position;
  264. } //}}}
  265. //{{{ getDockables() method
  266. public String[] getDockables()
  267. {
  268. String[] retVal = new String[dockables.size()];
  269. for(int i = 0; i < dockables.size(); i++)
  270. {
  271. DockableWindowManager.Entry entry =
  272. (DockableWindowManager.Entry) dockables.get(i);
  273. retVal[i] = entry.factory.name;
  274. }
  275. return retVal;
  276. } //}}}
  277. //{{{ Package-private members
  278. static final int SPLITTER_WIDTH = 10;
  279. DockablePanel dockablePanel;
  280. JPanel buttonPanel;
  281. //{{{ save() method
  282. void save()
  283. {
  284. jEdit.setIntegerProperty("view.dock." + position + ".dimension",
  285. dimension);
  286. if(current == null)
  287. jEdit.unsetProperty("view.dock." + position + ".last");
  288. else
  289. {
  290. jEdit.setProperty("view.dock." + position + ".last",
  291. current.factory.name);
  292. }
  293. } //}}}
  294. //{{{ setDimension() method
  295. void setDimension(int dimension)
  296. {
  297. if(dimension > SPLITTER_WIDTH)
  298. this.dimension = dimension - SPLITTER_WIDTH;
  299. } //}}}
  300. //{{{ sortDockables() method
  301. void sortDockables()
  302. {
  303. buttonPanel.removeAll();
  304. buttonPanel.add(closeBox);
  305. buttonPanel.add(menuBtn);
  306. Collections.sort(buttons,new DockableWindowCompare());
  307. for(int i = 0; i < buttons.size(); i++)
  308. {
  309. buttonPanel.add((AbstractButton)buttons.get(i));
  310. }
  311. } //}}}
  312. //{{{ getWrappedDimension() method
  313. /**
  314. * Returns the width or height of wrapped rows or columns.
  315. */
  316. int getWrappedDimension(int dimension)
  317. {
  318. return ((ButtonLayout)buttonPanel.getLayout())
  319. .getWrappedDimension(buttonPanel,dimension);
  320. } //}}}
  321. //}}}
  322. //{{{ Private members
  323. private DockableWindowManager wm;
  324. private String position;
  325. private JButton closeBox;
  326. private JButton menuBtn;
  327. private ButtonGroup buttonGroup;
  328. private JToggleButton nullButton;
  329. private int dimension;
  330. private ArrayList dockables;
  331. private ArrayList buttons;
  332. private DockableWindowManager.Entry current;
  333. private JPopupMenu popup;
  334. // remember the most recent dockable
  335. private String mostRecent;
  336. //}}}
  337. //{{{ Inner classes
  338. //{{{ DockableWindowCompare class
  339. static class DockableWindowCompare implements Comparator
  340. {
  341. public int compare(Object o1, Object o2)
  342. {
  343. String name1 = ((AbstractButton)o1).getActionCommand();
  344. String name2 = ((AbstractButton)o2).getActionCommand();
  345. return MiscUtilities.compareStrings(
  346. jEdit.getProperty(name1 + ".title",""),
  347. jEdit.getProperty(name2 + ".title",""),
  348. true);
  349. }
  350. } //}}}
  351. //{{{ ActionHandler class
  352. class ActionHandler implements ActionListener
  353. {
  354. public void actionPerformed(ActionEvent evt)
  355. {
  356. if(popup != null && popup.isVisible())
  357. popup.setVisible(false);
  358. if(evt.getSource() == closeBox)
  359. show(null);
  360. else
  361. {
  362. if(wm.isDockableWindowVisible(evt.getActionCommand()))
  363. show(null);
  364. else
  365. wm.showDockableWindow(evt.getActionCommand());
  366. }
  367. }
  368. } //}}}
  369. //{{{ MenuMouseHandler class
  370. class MenuMouseHandler extends MouseAdapter
  371. {
  372. public void mousePressed(MouseEvent evt)
  373. {
  374. if(popup != null && popup.isVisible())
  375. {
  376. popup.setVisible(false);
  377. return;
  378. }
  379. Component comp = (Component)evt.getSource();
  380. String dockable;
  381. if(comp instanceof JToggleButton)
  382. dockable = ((JToggleButton)comp).getActionCommand();
  383. else
  384. dockable = getCurrent();
  385. if(comp == menuBtn || GUIUtilities.isPopupTrigger(evt))
  386. {
  387. if(dockable == null)
  388. {
  389. popup = wm.createPopupMenu(PanelWindowContainer.this,null,false);
  390. }
  391. else
  392. {
  393. popup = wm.createPopupMenu(PanelWindowContainer.this,dockable,false);
  394. }
  395. int x, y;
  396. boolean point;
  397. if(comp == menuBtn)
  398. {
  399. x = 0;
  400. y = menuBtn.getHeight();
  401. point = false;
  402. }
  403. else
  404. {
  405. x = evt.getX();
  406. y = evt.getY();
  407. point = true;
  408. }
  409. GUIUtilities.showPopupMenu(popup,
  410. comp,x,y,point);
  411. }
  412. }
  413. } //}}}
  414. //{{{ DockBorder class
  415. static class DockBorder implements Border
  416. {
  417. String position;
  418. Insets insets;
  419. Color color1;
  420. Color color2;
  421. Color color3;
  422. //{{{ DockBorder constructor
  423. DockBorder(String position)
  424. {
  425. this.position = position;
  426. insets = new Insets(
  427. position.equals(DockableWindowManager.BOTTOM)
  428. ? SPLITTER_WIDTH : 0,
  429. position.equals(DockableWindowManager.RIGHT)
  430. ? SPLITTER_WIDTH : 0,
  431. position.equals(DockableWindowManager.TOP)
  432. ? SPLITTER_WIDTH : 0,
  433. position.equals(DockableWindowManager.LEFT)
  434. ? SPLITTER_WIDTH : 0);
  435. } //}}}
  436. //{{{ paintBorder() method
  437. public void paintBorder(Component c, Graphics g,
  438. int x, int y, int width, int height)
  439. {
  440. updateColors();
  441. if(color1 == null || color2 == null || color3 == null)
  442. return;
  443. if(position.equals(DockableWindowManager.BOTTOM))
  444. paintHorizBorder(g,x,y,width);
  445. else if(position.equals(DockableWindowManager.RIGHT))
  446. paintVertBorder(g,x,y,height);
  447. else if(position.equals(DockableWindowManager.TOP))
  448. {
  449. paintHorizBorder(g,x,y + height
  450. - SPLITTER_WIDTH,width);
  451. }
  452. else if(position.equals(DockableWindowManager.LEFT))
  453. {
  454. paintVertBorder(g,x + width
  455. - SPLITTER_WIDTH,y,height);
  456. }
  457. } //}}}
  458. //{{{ getBorderInsets() method
  459. public Insets getBorderInsets(Component c)
  460. {
  461. return insets;
  462. } //}}}
  463. //{{{ isBorderOpaque() method
  464. public boolean isBorderOpaque()
  465. {
  466. return false;
  467. } //}}}
  468. //{{{ paintHorizBorder() method
  469. private void paintHorizBorder(Graphics g, int x, int y, int width)
  470. {
  471. g.setColor(color3);
  472. g.fillRect(x,y,width,SPLITTER_WIDTH);
  473. for(int i = 0; i < width / 4 - 1; i++)
  474. {
  475. g.setColor(color1);
  476. g.drawLine(x + i * 4 + 2,y + 3,
  477. x + i * 4 + 2,y + 3);
  478. g.setColor(color2);
  479. g.drawLine(x + i * 4 + 3,y + 4,
  480. x + i * 4 + 3,y + 4);
  481. g.setColor(color1);
  482. g.drawLine(x + i * 4 + 4,y + 5,
  483. x + i * 4 + 4,y + 5);
  484. g.setColor(color2);
  485. g.drawLine(x + i * 4 + 5,y + 6,
  486. x + i * 4 + 5,y + 6);
  487. }
  488. } //}}}
  489. //{{{ paintVertBorder() method
  490. private void paintVertBorder(Graphics g, int x, int y, int height)
  491. {
  492. g.setColor(color3);
  493. g.fillRect(x,y,SPLITTER_WIDTH,height);
  494. for(int i = 0; i < height / 4 - 1; i++)
  495. {
  496. g.setColor(color1);
  497. g.drawLine(x + 3,y + i * 4 + 2,
  498. x + 3,y + i * 4 + 2);
  499. g.setColor(color2);
  500. g.drawLine(x + 4,y + i * 4 + 3,
  501. x + 4,y + i * 4 + 3);
  502. g.setColor(color1);
  503. g.drawLine(x + 5,y + i * 4 + 4,
  504. x + 5,y + i * 4 + 4);
  505. g.setColor(color2);
  506. g.drawLine(x + 6,y + i * 4 + 5,
  507. x + 6,y + i * 4 + 5);
  508. }
  509. } //}}}
  510. //{{{ updateColors() method
  511. private void updateColors()
  512. {
  513. if(UIManager.getLookAndFeel() instanceof MetalLookAndFeel)
  514. {
  515. color1 = MetalLookAndFeel.getControlHighlight();
  516. color2 = MetalLookAndFeel.getControlDarkShadow();
  517. color3 = MetalLookAndFeel.getControl();
  518. }
  519. else
  520. {
  521. color1 = color2 = color3 = null;
  522. }
  523. } //}}}
  524. } //}}}
  525. //{{{ RotatedTextIcon class
  526. public static class RotatedTextIcon implements Icon
  527. {
  528. public static final int NONE = 0;
  529. public static final int CW = 1;
  530. public static final int CCW = 2;
  531. //{{{ RotatedTextIcon constructor
  532. public RotatedTextIcon(int rotate, Font font, String text)
  533. {
  534. this.rotate = rotate;
  535. this.font = font;
  536. FontRenderContext fontRenderContext
  537. = new FontRenderContext(null,true,true);
  538. this.text = text;
  539. glyphs = font.createGlyphVector(fontRenderContext,text);
  540. width = (int)glyphs.getLogicalBounds().getWidth() + 4;
  541. //height = (int)glyphs.getLogicalBounds().getHeight();
  542. LineMetrics lineMetrics = font.getLineMetrics(text,fontRenderContext);
  543. ascent = lineMetrics.getAscent();
  544. height = (int)lineMetrics.getHeight();
  545. renderHints = new RenderingHints(
  546. RenderingHints.KEY_ANTIALIASING,
  547. RenderingHints.VALUE_ANTIALIAS_ON);
  548. renderHints.put(RenderingHints.KEY_FRACTIONALMETRICS,
  549. RenderingHints.VALUE_FRACTIONALMETRICS_ON);
  550. renderHints.put(RenderingHints.KEY_RENDERING,
  551. RenderingHints.VALUE_RENDER_QUALITY);
  552. } //}}}
  553. //{{{ getIconWidth() method
  554. public int getIconWidth()
  555. {
  556. return (int)(rotate == RotatedTextIcon.CW
  557. || rotate == RotatedTextIcon.CCW
  558. ? height : width);
  559. } //}}}
  560. //{{{ getIconHeight() method
  561. public int getIconHeight()
  562. {
  563. return (int)(rotate == RotatedTextIcon.CW
  564. || rotate == RotatedTextIcon.CCW
  565. ? width : height);
  566. } //}}}
  567. //{{{ paintIcon() method
  568. public void paintIcon(Component c, Graphics g, int x, int y)
  569. {
  570. Graphics2D g2d = (Graphics2D)g;
  571. g2d.setFont(font);
  572. AffineTransform oldTransform = g2d.getTransform();
  573. RenderingHints oldHints = g2d.getRenderingHints();
  574. g2d.setRenderingHints(renderHints);
  575. g2d.setColor(c.getForeground());
  576. //{{{ No rotation
  577. if(rotate == RotatedTextIcon.NONE)
  578. {
  579. g2d.drawGlyphVector(glyphs,x + 2,y + ascent);
  580. } //}}}
  581. //{{{ Clockwise rotation
  582. else if(rotate == RotatedTextIcon.CW)
  583. {
  584. AffineTransform trans = new AffineTransform();
  585. trans.concatenate(oldTransform);
  586. trans.translate(x,y + 2);
  587. trans.rotate(Math.PI / 2,
  588. height / 2, width / 2);
  589. g2d.setTransform(trans);
  590. g2d.drawGlyphVector(glyphs,(height - width) / 2,
  591. (width - height) / 2
  592. + ascent);
  593. } //}}}
  594. //{{{ Counterclockwise rotation
  595. else if(rotate == RotatedTextIcon.CCW)
  596. {
  597. AffineTransform trans = new AffineTransform();
  598. trans.concatenate(oldTransform);
  599. trans.translate(x,y - 2);
  600. trans.rotate(Math.PI * 3 / 2,
  601. height / 2, width / 2);
  602. g2d.setTransform(trans);
  603. g2d.drawGlyphVector(glyphs,(height - width) / 2,
  604. (width - height) / 2
  605. + ascent);
  606. } //}}}
  607. g2d.setTransform(oldTransform);
  608. g2d.setRenderingHints(oldHints);
  609. } //}}}
  610. //{{{ Private members
  611. private int rotate;
  612. private Font font;
  613. private String text;
  614. private GlyphVector glyphs;
  615. private float width;
  616. private float height;
  617. private float ascent;
  618. private RenderingHints renderHints;
  619. //}}}
  620. } //}}}
  621. //{{{ ButtonLayout class
  622. class ButtonLayout implements LayoutManager
  623. {
  624. //{{{ addLayoutComponent() method
  625. public void addLayoutComponent(String name, Component comp) {} //}}}
  626. //{{{ removeLayoutComponent() method
  627. public void removeLayoutComponent(Component comp) {} //}}}
  628. //{{{ getWrappedDimension() method
  629. /**
  630. * Returns the width or height of wrapped rows or columns.
  631. */
  632. int getWrappedDimension(JComponent parent, int dimension)
  633. {
  634. Insets insets = (parent).getBorder()
  635. .getBorderInsets(parent);
  636. Component[] comp = parent.getComponents();
  637. if(comp.length <= 2)
  638. return 0;
  639. Dimension dim = comp[2].getPreferredSize();
  640. if(position.equals(DockableWindowManager.TOP)
  641. || position.equals(DockableWindowManager.BOTTOM))
  642. {
  643. int width = dimension - insets.right;
  644. int rowHeight = Math.max(dim.height,closeBox.getPreferredSize().width);
  645. int x = rowHeight * 2 + insets.left;
  646. Dimension returnValue = new Dimension(0,rowHeight
  647. + insets.top + insets.bottom);
  648. for(int i = 2; i < comp.length; i++)
  649. {
  650. int btnWidth = comp[i].getPreferredSize().width;
  651. if(btnWidth + x > width)
  652. {
  653. returnValue.height += rowHeight;
  654. x = insets.left;
  655. }
  656. x += btnWidth;
  657. }
  658. return returnValue.height;
  659. }
  660. else
  661. {
  662. int height = dimension - insets.bottom;
  663. int colWidth = Math.max(dim.width,closeBox.getPreferredSize().height);
  664. int y = colWidth * 2 + insets.top;
  665. Dimension returnValue = new Dimension(colWidth
  666. + insets.left + insets.right,0);
  667. for(int i = 2; i < comp.length; i++)
  668. {
  669. int btnHeight = comp[i].getPreferredSize().height;
  670. if(btnHeight + y > height)
  671. {
  672. returnValue.width += colWidth;
  673. y = insets.top;
  674. }
  675. y += btnHeight;
  676. }
  677. return returnValue.width;
  678. }
  679. } //}}}
  680. //{{{ preferredLayoutSize() method
  681. public Dimension preferredLayoutSize(Container parent)
  682. {
  683. Insets insets = ((JComponent)parent).getBorder()
  684. .getBorderInsets(parent);
  685. Component[] comp = parent.getComponents();
  686. if(comp.length <= 2)
  687. {
  688. // nothing 'cept close box
  689. return new Dimension(0,0);
  690. }
  691. Dimension dim = comp[2].getPreferredSize();
  692. if(position.equals(DockableWindowManager.TOP)
  693. || position.equals(DockableWindowManager.BOTTOM))
  694. {
  695. int width = parent.getWidth() - insets.right;
  696. int rowHeight = Math.max(dim.height,closeBox.getPreferredSize().width);
  697. int x = rowHeight * 2 + insets.left;
  698. Dimension returnValue = new Dimension(0,rowHeight
  699. + insets.top + insets.bottom);
  700. for(int i = 2; i < comp.length; i++)
  701. {
  702. int btnWidth = comp[i].getPreferredSize().width;
  703. if(btnWidth + x > width)
  704. {
  705. returnValue.height += rowHeight;
  706. x = insets.left;
  707. }
  708. x += btnWidth;
  709. }
  710. return returnValue;
  711. }
  712. else
  713. {
  714. int height = parent.getHeight() - insets.bottom;
  715. int colWidth = Math.max(dim.width,closeBox.getPreferredSize().height);
  716. int y = colWidth * 2 + insets.top;
  717. Dimension returnValue = new Dimension(colWidth
  718. + insets.left + insets.right,0);
  719. for(int i = 2; i < comp.length; i++)
  720. {
  721. int btnHeight = comp[i].getPreferredSize().height;
  722. if(btnHeight + y > height)
  723. {
  724. returnValue.width += colWidth;
  725. y = insets.top;
  726. }
  727. y += btnHeight;
  728. }
  729. return returnValue;
  730. }
  731. } //}}}
  732. //{{{ minimumLayoutSize() method
  733. public Dimension minimumLayoutSize(Container parent)
  734. {
  735. return preferredLayoutSize(parent);
  736. } //}}}
  737. //{{{ layoutContainer() method
  738. public void layoutContainer(Container parent)
  739. {
  740. Insets insets = ((JComponent)parent).getBorder()
  741. .getBorderInsets(parent);
  742. Component[] comp = parent.getComponents();
  743. if(comp.length <= 2)
  744. {
  745. for(int i = 0; i < comp.length; i++)
  746. {
  747. comp[i].setVisible(false);
  748. }
  749. return;
  750. }
  751. comp[0].setVisible(true);
  752. comp[1].setVisible(true);
  753. Dimension dim = comp[2].getPreferredSize();
  754. if(position.equals(DockableWindowManager.TOP)
  755. || position.equals(DockableWindowManager.BOTTOM))
  756. {
  757. int width = parent.getWidth() - insets.right;
  758. int rowHeight = Math.max(dim.height,closeBox.getPreferredSize().width);
  759. int x = rowHeight * 2 + insets.left;
  760. int y = insets.top;
  761. closeBox.setBounds(insets.left,insets.top,rowHeight,rowHeight);
  762. menuBtn.setBounds(insets.left + rowHeight,insets.top,rowHeight,rowHeight);
  763. for(int i = 2; i < comp.length; i++)
  764. {
  765. int btnWidth = comp[i].getPreferredSize().width;
  766. if(btnWidth + x > width)
  767. {
  768. x = insets.left;
  769. y += rowHeight;
  770. }
  771. comp[i].setBounds(x,y,btnWidth,rowHeight);
  772. x += btnWidth;
  773. }
  774. /* if(y + rowHeight != parent.getHeight())
  775. {
  776. parent.setSize(
  777. parent.getWidth(),
  778. y + rowHeight);
  779. ((JComponent)parent).revalidate();
  780. } */
  781. }
  782. else
  783. {
  784. int height = parent.getHeight() - insets.bottom;
  785. int colWidth = Math.max(dim.width,closeBox.getPreferredSize().height);
  786. int x = insets.left;
  787. int y = colWidth * 2 + insets.top;
  788. closeBox.setBounds(insets.left,insets.top,colWidth,colWidth);
  789. menuBtn.setBounds(insets.left,insets.top + colWidth,colWidth,colWidth);
  790. for(int i = 2; i < comp.length; i++)
  791. {
  792. int btnHeight = comp[i].getPreferredSize().height;
  793. if(btnHeight + y > height)
  794. {
  795. x += colWidth;
  796. y = insets.top;
  797. }
  798. comp[i].setBounds(x,y,colWidth,btnHeight);
  799. y += btnHeight;
  800. }
  801. /* if(x + colWidth != parent.getWidth())
  802. {
  803. parent.setSize(x + colWidth,
  804. parent.getHeight());
  805. ((JComponent)parent).revalidate();
  806. } */
  807. }
  808. } //}}}
  809. } //}}}
  810. //}}}
  811. }