PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/gui/PanelWindowContainer.java

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