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

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

#
Java | 814 lines | 616 code | 94 blank | 104 comment | 102 complexity | 49ece6ebd051c2c873e2ca83f9302f61 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, 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 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.image.*;
  31. import java.awt.*;
  32. import java.util.Vector;
  33. import org.gjt.sp.jedit.*;
  34. //}}}
  35. /**
  36. * A container for dockable windows. This class should never be used
  37. * directly.
  38. * @author Slava Pestov
  39. * @version $Id: PanelWindowContainer.java 3936 2001-12-21 07:02:14Z spestov $
  40. * @since jEdit 4.0pre1
  41. */
  42. public class PanelWindowContainer implements DockableWindowContainer
  43. {
  44. //{{{ PanelWindowContainer constructor
  45. public PanelWindowContainer(DockableWindowManager wm, String position)
  46. {
  47. this.wm = wm;
  48. this.position = position;
  49. //{{{ Button box setup
  50. buttons = new JPanel(new ButtonLayout());
  51. // the close box must be the same size as the other buttons to look good.
  52. // there are two ways to achieve this:
  53. // a) write a custom layout manager
  54. // b) when the first button is added, give the close box the proper size
  55. // I'm lazy so I chose "b". See register() for details.
  56. closeBox = new JButton(GUIUtilities.loadIcon("closebox.gif"));
  57. closeBox.setRequestFocusEnabled(false);
  58. closeBox.setToolTipText(jEdit.getProperty("view.docking.close-tooltip"));
  59. buttons.add(closeBox);
  60. closeBox.addActionListener(new ActionHandler());
  61. popupButton = new JButton(GUIUtilities.loadIcon("ToolbarMenu.gif"));
  62. popupButton.setRequestFocusEnabled(false);
  63. popupButton.setToolTipText(jEdit.getProperty("view.docking.menu-tooltip"));
  64. buttons.add(popupButton);
  65. popupButton.addMouseListener(new MouseHandler());
  66. popup = new JPopupMenu();
  67. buttonGroup = new ButtonGroup();
  68. // JDK 1.4 workaround
  69. buttonGroup.add(nullButton = new JToggleButton());
  70. //}}}
  71. dockables = new Vector();
  72. dockablePanel = new DockablePanel();
  73. dimension = jEdit.getIntegerProperty(
  74. "view.dock." + position + ".dimension",0);
  75. } //}}}
  76. //{{{ register() method
  77. public void register(final DockableWindowManager.Entry entry)
  78. {
  79. dockables.addElement(entry);
  80. //{{{ Create button
  81. int rotation;
  82. if(position.equals(DockableWindowManager.TOP)
  83. || position.equals(DockableWindowManager.BOTTOM))
  84. rotation = RotatedTextIcon.NONE;
  85. else if(position.equals(DockableWindowManager.LEFT))
  86. rotation = RotatedTextIcon.CCW;
  87. else if(position.equals(DockableWindowManager.RIGHT))
  88. rotation = RotatedTextIcon.CW;
  89. else
  90. throw new InternalError("Invalid position: " + position);
  91. JToggleButton button = new JToggleButton();
  92. button.setMargin(new Insets(0,0,0,0));
  93. button.setRequestFocusEnabled(false);
  94. button.setIcon(new RotatedTextIcon(rotation,button.getFont(),
  95. entry.title));
  96. button.addActionListener(new ActionListener()
  97. {
  98. public void actionPerformed(ActionEvent evt)
  99. {
  100. if(current == entry)
  101. show(null);
  102. else
  103. wm.showDockableWindow(entry.name);
  104. }
  105. }); //}}}
  106. buttonGroup.add(button);
  107. buttons.add(button);
  108. //{{{ Create menu items
  109. JMenuItem menuItem = new JMenuItem(entry.title);
  110. menuItem.addActionListener(new ActionListener()
  111. {
  112. public void actionPerformed(ActionEvent evt)
  113. {
  114. wm.showDockableWindow(entry.name);
  115. }
  116. }); //}}}
  117. popup.add(menuItem);
  118. wm.revalidate();
  119. } //}}}
  120. //{{{ add() method
  121. public void add(DockableWindowManager.Entry entry)
  122. {
  123. dockablePanel.add(entry.name,entry.win);
  124. } //}}}
  125. //{{{ remove() method
  126. public void remove(DockableWindowManager.Entry entry)
  127. {
  128. int index = dockables.indexOf(entry);
  129. buttons.remove(index + 2);
  130. dockables.removeElement(entry);
  131. if(entry.win != null)
  132. dockablePanel.remove(entry.win);
  133. if(current == entry)
  134. {
  135. current = null;
  136. show(null);
  137. }
  138. else
  139. wm.revalidate();
  140. } //}}}
  141. //{{{ save() method
  142. public void save(DockableWindowManager.Entry entry) {}
  143. //}}}
  144. //{{{ show() method
  145. public void show(final DockableWindowManager.Entry entry)
  146. {
  147. if(current == entry)
  148. {
  149. if(entry != null)
  150. entry.win.requestDefaultFocus();
  151. return;
  152. }
  153. if(current == null)
  154. {
  155. // we didn't have a component previously, so create a border
  156. dockablePanel.setBorder(new DockBorder(position));
  157. }
  158. if(entry != null)
  159. {
  160. this.current = entry;
  161. dockablePanel.showDockable(entry.name);
  162. int index = dockables.indexOf(entry);
  163. ((JToggleButton)buttons.getComponent(index + 2)).setSelected(true);
  164. SwingUtilities.invokeLater(new Runnable()
  165. {
  166. public void run()
  167. {
  168. entry.win.requestDefaultFocus();
  169. }
  170. });
  171. }
  172. else
  173. {
  174. current = null;
  175. nullButton.setSelected(true);
  176. // removing last component, so remove border
  177. dockablePanel.setBorder(null);
  178. wm.getView().getTextArea().requestFocus();
  179. }
  180. wm.revalidate();
  181. dockablePanel.repaint();
  182. } //}}}
  183. //{{{ isVisible() method
  184. public boolean isVisible(DockableWindowManager.Entry entry)
  185. {
  186. return current == entry;
  187. } //}}}
  188. //{{{ getCurrent() method
  189. public DockableWindowManager.Entry getCurrent()
  190. {
  191. return current;
  192. } //}}}
  193. //{{{ Package-private members
  194. //{{{ save() method
  195. void save()
  196. {
  197. jEdit.setIntegerProperty("view.dock." + position + ".dimension",
  198. dimension);
  199. if(current == null)
  200. jEdit.unsetProperty("view.dock." + position + ".last");
  201. else
  202. {
  203. jEdit.setProperty("view.dock." + position + ".last",
  204. current.name);
  205. }
  206. } //}}}
  207. //{{{ getButtonBox() method
  208. JPanel getButtonBox()
  209. {
  210. return buttons;
  211. } //}}}
  212. //{{{ getDockablePanel() method
  213. DockablePanel getDockablePanel()
  214. {
  215. return dockablePanel;
  216. } //}}}
  217. //}}}
  218. //{{{ Private members
  219. private static final int SPLITTER_WIDTH = 10;
  220. private DockableWindowManager wm;
  221. private String position;
  222. private JPanel buttons;
  223. private JButton closeBox;
  224. private JButton popupButton;
  225. private ButtonGroup buttonGroup;
  226. private JToggleButton nullButton;
  227. private int dimension;
  228. private Vector dockables;
  229. private DockablePanel dockablePanel;
  230. private DockableWindowManager.Entry current;
  231. private JPopupMenu popup;
  232. //}}}
  233. //{{{ Inner classes
  234. //{{{ ActionHandler class
  235. class ActionHandler implements ActionListener
  236. {
  237. public void actionPerformed(ActionEvent evt)
  238. {
  239. show(null);
  240. }
  241. } //}}}
  242. //{{{ MouseHandler class
  243. class MouseHandler extends MouseAdapter
  244. {
  245. public void mousePressed(MouseEvent evt)
  246. {
  247. if(evt.getSource() == popupButton)
  248. {
  249. if(popup.isVisible())
  250. popup.setVisible(false);
  251. else
  252. {
  253. GUIUtilities.showPopupMenu(popup,
  254. popupButton,evt.getX(),evt.getY());
  255. }
  256. }
  257. }
  258. } //}}}
  259. //{{{ DockBorder class
  260. static class DockBorder implements Border
  261. {
  262. String position;
  263. Insets insets;
  264. Color color1;
  265. Color color2;
  266. Color color3;
  267. //{{{ DockBorder constructor
  268. DockBorder(String position)
  269. {
  270. if(UIManager.getLookAndFeel() instanceof MetalLookAndFeel)
  271. {
  272. color1 = MetalLookAndFeel.getControlHighlight();
  273. color2 = MetalLookAndFeel.getControlDarkShadow();
  274. color3 = MetalLookAndFeel.getControl();
  275. }
  276. this.position = position;
  277. insets = new Insets(
  278. position.equals(DockableWindowManager.BOTTOM)
  279. ? SPLITTER_WIDTH : 0,
  280. position.equals(DockableWindowManager.RIGHT)
  281. ? SPLITTER_WIDTH : 0,
  282. position.equals(DockableWindowManager.TOP)
  283. ? SPLITTER_WIDTH : 0,
  284. position.equals(DockableWindowManager.LEFT)
  285. ? SPLITTER_WIDTH : 0);
  286. } //}}}
  287. //{{{ paintBorder() method
  288. public void paintBorder(Component c, Graphics g,
  289. int x, int y, int width, int height)
  290. {
  291. if(color1 == null || color2 == null || color3 == null)
  292. return;
  293. if(position.equals(DockableWindowManager.BOTTOM))
  294. paintHorizBorder(g,x,y,width);
  295. else if(position.equals(DockableWindowManager.RIGHT))
  296. paintVertBorder(g,x,y,height);
  297. else if(position.equals(DockableWindowManager.TOP))
  298. {
  299. paintHorizBorder(g,x,y + height
  300. - SPLITTER_WIDTH,width);
  301. }
  302. else if(position.equals(DockableWindowManager.LEFT))
  303. {
  304. paintVertBorder(g,x + width
  305. - SPLITTER_WIDTH,y,height);
  306. }
  307. } //}}}
  308. //{{{ getBorderInsets() method
  309. public Insets getBorderInsets(Component c)
  310. {
  311. return insets;
  312. } //}}}
  313. //{{{ isBorderOpaque() method
  314. public boolean isBorderOpaque()
  315. {
  316. return false;
  317. } //}}}
  318. //{{{ paintHorizBorder() method
  319. private void paintHorizBorder(Graphics g, int x, int y, int width)
  320. {
  321. g.setColor(color3);
  322. g.fillRect(x,y,width,SPLITTER_WIDTH);
  323. for(int i = 0; i < width / 4 - 1; i++)
  324. {
  325. g.setColor(color1);
  326. g.drawLine(x + i * 4 + 2,y + 3,
  327. x + i * 4 + 2,y + 3);
  328. g.setColor(color2);
  329. g.drawLine(x + i * 4 + 3,y + 4,
  330. x + i * 4 + 3,y + 4);
  331. g.setColor(color1);
  332. g.drawLine(x + i * 4 + 4,y + 5,
  333. x + i * 4 + 4,y + 5);
  334. g.setColor(color2);
  335. g.drawLine(x + i * 4 + 5,y + 6,
  336. x + i * 4 + 5,y + 6);
  337. }
  338. } //}}}
  339. //{{{ paintVertBorder() method
  340. private void paintVertBorder(Graphics g, int x, int y, int height)
  341. {
  342. g.setColor(color3);
  343. g.fillRect(x,y,SPLITTER_WIDTH,height);
  344. for(int i = 0; i < height / 4 - 1; i++)
  345. {
  346. g.setColor(color1);
  347. g.drawLine(x + 3,y + i * 4 + 2,
  348. x + 3,y + i * 4 + 2);
  349. g.setColor(color2);
  350. g.drawLine(x + 4,y + i * 4 + 3,
  351. x + 4,y + i * 4 + 3);
  352. g.setColor(color1);
  353. g.drawLine(x + 5,y + i * 4 + 4,
  354. x + 5,y + i * 4 + 4);
  355. g.setColor(color2);
  356. g.drawLine(x + 6,y + i * 4 + 5,
  357. x + 6,y + i * 4 + 5);
  358. }
  359. } //}}}
  360. } //}}}
  361. //{{{ RotatedTextIcon class
  362. class RotatedTextIcon implements Icon
  363. {
  364. static final int NONE = 0;
  365. static final int CW = 1;
  366. static final int CCW = 2;
  367. int rotate;
  368. Font font;
  369. String text;
  370. int width;
  371. int height;
  372. RenderingHints renderHints;
  373. //{{{ RotatedTextIcon constructor
  374. RotatedTextIcon(int rotate, Font font, String text)
  375. {
  376. this.rotate = rotate;
  377. this.font = font;
  378. this.text = text;
  379. FontRenderContext fontRenderContext
  380. = new FontRenderContext(null,true,
  381. true);
  382. GlyphVector glyphs = font.createGlyphVector(
  383. fontRenderContext,text);
  384. width = (int)glyphs.getLogicalBounds().getWidth();
  385. height = (int)glyphs.getLogicalBounds().getHeight();
  386. renderHints = new RenderingHints(
  387. RenderingHints.KEY_ANTIALIASING,
  388. RenderingHints.VALUE_ANTIALIAS_ON);
  389. renderHints.put(RenderingHints.KEY_FRACTIONALMETRICS,
  390. RenderingHints.VALUE_FRACTIONALMETRICS_ON);
  391. renderHints.put(RenderingHints.KEY_RENDERING,
  392. RenderingHints.VALUE_RENDER_QUALITY);
  393. } //}}}
  394. //{{{ getIconWidth() method
  395. public int getIconWidth()
  396. {
  397. return (rotate == RotatedTextIcon.CW
  398. || rotate == RotatedTextIcon.CCW
  399. ? height : width);
  400. } //}}}
  401. //{{{ getIconHeight() method
  402. public int getIconHeight()
  403. {
  404. return (rotate == RotatedTextIcon.CW
  405. || rotate == RotatedTextIcon.CCW
  406. ? width : height);
  407. } //}}}
  408. //{{{ paintIcon() method
  409. public void paintIcon(Component c, Graphics g, int x, int y)
  410. {
  411. FontMetrics fm = c.getFontMetrics(font);
  412. Graphics2D g2d = (Graphics2D)g;
  413. g2d.setFont(font);
  414. AffineTransform oldTransform = g2d.getTransform();
  415. RenderingHints oldHints = g2d.getRenderingHints();
  416. g2d.setRenderingHints(renderHints);
  417. g2d.setColor(c.getForeground());
  418. //{{{ No rotation
  419. if(rotate == RotatedTextIcon.NONE)
  420. {
  421. g2d.drawString(text,x,y + fm.getAscent());
  422. } //}}}
  423. //{{{ Clockwise rotation
  424. else if(rotate == RotatedTextIcon.CW)
  425. {
  426. AffineTransform trans = new AffineTransform();
  427. trans.concatenate(oldTransform);
  428. trans.translate(x,y);
  429. trans.rotate(Math.PI / 2,
  430. height / 2, width / 2);
  431. g2d.setTransform(trans);
  432. g2d.drawString(text,(height - width) / 2,
  433. (width - height) / 2
  434. + fm.getAscent());
  435. } //}}}
  436. //{{{ Counterclockwise rotation
  437. else if(rotate == RotatedTextIcon.CCW)
  438. {
  439. AffineTransform trans = new AffineTransform();
  440. trans.concatenate(oldTransform);
  441. trans.translate(x,y);
  442. trans.rotate(Math.PI * 3 / 2,
  443. height / 2, width / 2);
  444. g2d.setTransform(trans);
  445. g2d.drawString(text,(height - width) / 2,
  446. (width - height) / 2
  447. + fm.getAscent());
  448. } //}}}
  449. g2d.setTransform(oldTransform);
  450. g2d.setRenderingHints(oldHints);
  451. } //}}}
  452. } //}}}
  453. //{{{ ButtonLayout class
  454. class ButtonLayout implements LayoutManager
  455. {
  456. //{{{ addLayoutComponent() method
  457. public void addLayoutComponent(String name, Component comp) {} //}}}
  458. //{{{ removeLayoutComponent() method
  459. public void removeLayoutComponent(Component comp) {} //}}}
  460. //{{{ preferredLayoutSize() method
  461. public Dimension preferredLayoutSize(Container parent)
  462. {
  463. Component[] comp = parent.getComponents();
  464. if(comp.length == 2)
  465. {
  466. // nothing 'cept close box and popup button
  467. return new Dimension(0,0);
  468. }
  469. else
  470. {
  471. if(position.equals(DockableWindowManager.TOP)
  472. || position.equals(DockableWindowManager.BOTTOM))
  473. {
  474. return new Dimension(0,comp[2].getPreferredSize().height);
  475. }
  476. else
  477. {
  478. return new Dimension(comp[2].getPreferredSize().width,0);
  479. }
  480. }
  481. } //}}}
  482. //{{{ minimumLayoutSize() method
  483. public Dimension minimumLayoutSize(Container parent)
  484. {
  485. Component[] comp = parent.getComponents();
  486. if(comp.length == 2)
  487. {
  488. // nothing 'cept close box and popup button
  489. return new Dimension(0,0);
  490. }
  491. else
  492. {
  493. if(position.equals(DockableWindowManager.TOP)
  494. || position.equals(DockableWindowManager.BOTTOM))
  495. {
  496. return new Dimension(0,comp[2].getMinimumSize().height);
  497. }
  498. else
  499. {
  500. return new Dimension(comp[2].getMinimumSize().width,0);
  501. }
  502. }
  503. } //}}}
  504. //{{{ layoutContainer() method
  505. public void layoutContainer(Container parent)
  506. {
  507. Component[] comp = parent.getComponents();
  508. if(comp.length != 2)
  509. {
  510. Dimension buttonSize = comp[2].getPreferredSize();
  511. int closeBoxDimension;
  512. if(position.equals(DockableWindowManager.TOP)
  513. || position.equals(DockableWindowManager.BOTTOM))
  514. {
  515. closeBoxDimension = comp[2].getMinimumSize().height;
  516. }
  517. else
  518. {
  519. closeBoxDimension = comp[2].getMinimumSize().width;
  520. }
  521. closeBox.setBounds(0,0,closeBoxDimension,closeBoxDimension);
  522. popupButton.setVisible(false);
  523. Dimension parentSize = parent.getSize();
  524. int pos = closeBoxDimension;
  525. for(int i = 2; i < comp.length; i++)
  526. {
  527. Dimension size = comp[i].getPreferredSize();
  528. if(position.equals(DockableWindowManager.TOP)
  529. || position.equals(DockableWindowManager.BOTTOM))
  530. {
  531. if(pos + size.width > parentSize.width)
  532. {
  533. popupButton.setBounds(
  534. parentSize.width - closeBoxDimension,
  535. 0,closeBoxDimension,closeBoxDimension);
  536. popupButton.setVisible(true);
  537. comp[i].setVisible(false);
  538. }
  539. else
  540. {
  541. comp[i].setBounds(pos,0,size.width,size.height);
  542. comp[i].setVisible(true);
  543. }
  544. pos += size.width;
  545. }
  546. else
  547. {
  548. if(pos + size.height > parentSize.height)
  549. {
  550. popupButton.setBounds(
  551. 0,parentSize.height - closeBoxDimension,
  552. closeBoxDimension,closeBoxDimension);
  553. popupButton.setVisible(true);
  554. comp[i].setVisible(false);
  555. }
  556. else
  557. {
  558. comp[i].setBounds(0,pos,size.width,size.height);
  559. comp[i].setVisible(true);
  560. }
  561. pos += size.height;
  562. }
  563. }
  564. }
  565. } //}}}
  566. } //}}}
  567. //{{{ DockablePanel class
  568. class DockablePanel extends JPanel
  569. {
  570. //{{{ DockablePanel constructor
  571. DockablePanel()
  572. {
  573. super(new CardLayout());
  574. ResizeMouseHandler resizeMouseHandler = new ResizeMouseHandler();
  575. addMouseListener(resizeMouseHandler);
  576. addMouseMotionListener(resizeMouseHandler);
  577. } //}}}
  578. //{{{ showDockable() method
  579. void showDockable(String name)
  580. {
  581. ((CardLayout)getLayout()).show(this,name);
  582. } //}}}
  583. //{{{ getMinimumSize() method
  584. public Dimension getMinimumSize()
  585. {
  586. return new Dimension(0,0);
  587. } //}}}
  588. //{{{ getPreferredSize() method
  589. public Dimension getPreferredSize()
  590. {
  591. if(current == null)
  592. return new Dimension(0,0);
  593. else
  594. {
  595. if(dimension <= 0)
  596. {
  597. int width = super.getPreferredSize().width;
  598. dimension = width - SPLITTER_WIDTH - 3;
  599. }
  600. if(position.equals(DockableWindowManager.TOP)
  601. || position.equals(DockableWindowManager.BOTTOM))
  602. {
  603. return new Dimension(0,
  604. dimension + SPLITTER_WIDTH + 3);
  605. }
  606. else
  607. {
  608. return new Dimension(dimension + SPLITTER_WIDTH + 3,
  609. 0);
  610. }
  611. }
  612. } //}}}
  613. //{{{ ResizeMouseHandler class
  614. class ResizeMouseHandler extends MouseAdapter implements MouseMotionListener
  615. {
  616. boolean canDrag;
  617. int dragStartDimension;
  618. Point dragStart;
  619. //{{{ mousePressed() method
  620. public void mousePressed(MouseEvent evt)
  621. {
  622. dragStartDimension = dimension;
  623. dragStart = evt.getPoint();
  624. } //}}}
  625. //{{{ mouseMoved() method
  626. public void mouseMoved(MouseEvent evt)
  627. {
  628. Border border = getBorder();
  629. if(border == null)
  630. {
  631. // collapsed
  632. return;
  633. }
  634. Insets insets = border.getBorderInsets(DockablePanel.this);
  635. int cursor = Cursor.DEFAULT_CURSOR;
  636. canDrag = false;
  637. //{{{ Top...
  638. if(position.equals(DockableWindowManager.TOP))
  639. {
  640. if(evt.getY() >= getHeight() - insets.bottom)
  641. {
  642. cursor = Cursor.N_RESIZE_CURSOR;
  643. canDrag = true;
  644. }
  645. } //}}}
  646. //{{{ Left...
  647. else if(position.equals(DockableWindowManager.LEFT))
  648. {
  649. if(evt.getX() >= getWidth() - insets.right)
  650. {
  651. cursor = Cursor.W_RESIZE_CURSOR;
  652. canDrag = true;
  653. }
  654. } //}}}
  655. //{{{ Bottom...
  656. else if(position.equals(DockableWindowManager.BOTTOM))
  657. {
  658. if(evt.getY() <= insets.top)
  659. {
  660. cursor = Cursor.S_RESIZE_CURSOR;
  661. canDrag = true;
  662. }
  663. } //}}}
  664. //{{{ Right...
  665. else if(position.equals(DockableWindowManager.RIGHT))
  666. {
  667. if(evt.getX() <= insets.left)
  668. {
  669. cursor = Cursor.E_RESIZE_CURSOR;
  670. canDrag = true;
  671. }
  672. } //}}}
  673. setCursor(Cursor.getPredefinedCursor(cursor));
  674. } //}}}
  675. //{{{ mouseDragged() method
  676. public void mouseDragged(MouseEvent evt)
  677. {
  678. if(!canDrag)
  679. return;
  680. if(dragStart == null) // can't happen?
  681. return;
  682. //{{{ Top...
  683. if(position.equals(DockableWindowManager.TOP))
  684. {
  685. dimension = evt.getY()
  686. + dragStartDimension
  687. - dragStart.y;
  688. } //}}}
  689. //{{{ Left...
  690. else if(position.equals(DockableWindowManager.LEFT))
  691. {
  692. dimension = evt.getX()
  693. + dragStartDimension
  694. - dragStart.x;
  695. } //}}}
  696. //{{{ Bottom...
  697. else if(position.equals(DockableWindowManager.BOTTOM))
  698. {
  699. dimension += (dragStart.y - evt.getY());
  700. } //}}}
  701. //{{{ Right...
  702. else if(position.equals(DockableWindowManager.RIGHT))
  703. {
  704. dimension += (dragStart.x - evt.getX());
  705. } //}}}
  706. if(dimension <= 0)
  707. dimension = dragStartDimension;
  708. wm.invalidate();
  709. wm.validate();
  710. } //}}}
  711. //{{{ mouseExited() method
  712. public void mouseExited(MouseEvent evt)
  713. {
  714. setCursor(Cursor.getPredefinedCursor(
  715. Cursor.DEFAULT_CURSOR));
  716. } //}}}
  717. } //}}}
  718. } //}}}
  719. //}}}
  720. }