2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / javax / swing / plaf / basic / BasicSplitPaneDivider.java
blob39db7e76bfb09b55d5b807e43dae43f35695b1bb
1 /* BasicSplitPaneDivider.java
2 Copyright (C) 2003 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax.swing.plaf.basic;
41 import java.awt.Component;
42 import java.awt.Container;
43 import java.awt.Dimension;
44 import java.awt.Graphics;
45 import java.awt.Insets;
46 import java.awt.event.MouseAdapter;
47 import java.awt.event.MouseEvent;
48 import java.awt.event.MouseMotionListener;
49 import java.beans.PropertyChangeEvent;
50 import java.beans.PropertyChangeListener;
51 import javax.swing.JButton;
52 import javax.swing.JSplitPane;
53 import javax.swing.border.Border;
56 /**
57 * The divider that separates the two parts of a JSplitPane in the
58 * Basic look and feel.
60 * <p>Implementation status: We do not have a real implementation yet.
61 * Currently, it is mostly a stub to allow compiling other parts of
62 * the javax.swing.plaf.basic package, although some parts are already
63 * functional.
65 * @author Sascha Brawer (brawer@dandelis.ch)
67 public class BasicSplitPaneDivider
68 extends Container
69 implements PropertyChangeListener
71 /**
72 * Determined using the <code>serialver</code> tool
73 * of Apple/Sun JDK 1.3.1 on MacOS X 10.1.5.
75 static final long serialVersionUID = 1463404307042803342L;
78 /**
79 * The width and height of the little buttons for showing and
80 * hiding parts of a JSplitPane in a single mouse click.
82 protected static final int ONE_TOUCH_SIZE = 6;
85 // FIXME: Javadoc.
86 protected static final int ONE_TOUCH_OFFSET = 2;
89 /**
90 * An object that performs the tasks associated with an ongoing drag
91 * operation, or <code>null</code> if the user is currently not
92 * dragging the divider.
94 protected DragController dragger;
97 /**
98 * The delegate object that is responsible for the UI of the
99 * <code>JSplitPane</code> that contains this divider.
101 protected BasicSplitPaneUI splitPaneUI;
105 * The thickness of the divider in pixels.
107 protected int dividerSize;
111 * A divider that is used for layout purposes.
113 protected Component hiddenDivider;
117 * The JSplitPane containing this divider.
119 protected JSplitPane splitPane;
123 * The listener for handling mouse events from both the divider
124 * and the containing <code>JSplitPane</code>.
126 * <p>The reason for also handling MouseEvents from the containing
127 * <code>JSplitPane</code> is that users should be able to start
128 * a drag gesture from inside the JSplitPane, but slightly outisde
129 * the divider.
131 protected MouseHandler mouseHandler = new MouseHandler();
135 * The current orientation of the containing <code>JSplitPane</code>,
136 * which is either {@link javax.swing.JSplitPane#HORIZONTAL_SPLIT}
137 * or {@link javax.swing.JSplitPane#VERTICAL_SPLIT}.
139 protected int orientation;
143 * The button for showing and hiding the left (or top) component
144 * of the <code>JSplitPane</code>.
146 protected JButton leftButton;
150 * The button for showing and hiding the right (or bottom) component
151 * of the <code>JSplitPane</code>.
153 protected JButton rightButton;
157 * The border of this divider. Typically, this will be an instance of
158 * {@link javax.swing.plaf.basic.BasicBorders.SplitPaneDividerBorder}.
160 * @see #getBorder()
161 * @see #setBorder(javax.swing.border.Border)
163 private Border border;
167 * Constructs a new divider.
169 * @param ui the UI delegate of the enclosing
170 * <code>JSplitPane</code>.
172 public BasicSplitPaneDivider(BasicSplitPaneUI ui)
174 setBasicSplitPaneUI(ui);
179 * Sets the delegate object that is responsible for the UI of the
180 * {@link javax.swing.JSplitPane} containing this divider.
182 * @param newUI the UI delegate, or <code>null</code> to release
183 * the connection to the current delegate.
185 public void setBasicSplitPaneUI(BasicSplitPaneUI newUI)
187 /* Remove the connection to the existing JSplitPane. */
188 if (splitPane != null)
190 splitPane.removePropertyChangeListener(this);
191 splitPane.removeMouseListener(mouseHandler);
192 splitPane.removeMouseMotionListener(mouseHandler);
193 splitPane = null;
196 /* Establish the connection to the new JSplitPane. */
197 splitPaneUI = newUI;
198 if (splitPaneUI != null)
199 splitPane = newUI.getSplitPane();
200 if (splitPane != null)
202 splitPane.addPropertyChangeListener(this);
203 splitPane.addMouseListener(mouseHandler);
204 splitPane.addMouseMotionListener(mouseHandler);
205 orientation = splitPane.getOrientation();
211 * Returns the delegate object that is responsible for the UI of the
212 * {@link javax.swing.JSplitPane} containing this divider.
214 public BasicSplitPaneUI getBasicSplitPaneUI()
216 return splitPaneUI;
221 * Sets the thickness of the divider.
223 * @param newSize the new width or height in pixels.
225 public void setDividerSize(int newSize)
227 this.dividerSize = newSize;
232 * Retrieves the thickness of the divider.
234 public int getDividerSize()
236 return dividerSize;
241 * Sets the border of this divider.
243 * @param border the new border. Typically, this will be an instance of
244 * {@link javax.swing.plaf.basic.BasicBorders.SplitPaneDividerBorder}.
246 * @since 1.3
248 public void setBorder(Border border)
250 Border oldValue = this.border;
251 this.border = border;
252 firePropertyChange("border", oldValue, border);
257 * Retrieves the border of this divider.
259 * @return the current border, or <code>null</code> if no border
260 * has been set.
262 * @since 1.3
264 public Border getBorder()
266 return border;
271 * Retrieves the insets of the divider. If a border has been
272 * installed on the divider, the result of calling its
273 * <code>getBorderInsets</code> method is returned. Otherwise,
274 * the inherited implementation will be invoked.
276 * @see javax.swing.border.Border#getBorderInsets(java.awt.Component)
278 public Insets getInsets()
280 if (border != null)
281 return border.getBorderInsets(this);
282 else
283 return super.getInsets();
288 * Returns the preferred size of this divider, which is
289 * <code>dividerSize</code> by <code>dividerSize</code>
290 * pixels.
292 public Dimension getPreferredSize()
294 return new Dimension(dividerSize, dividerSize);
299 * Returns the minimal size of this divider, which is
300 * <code>dividerSize</code> by <code>dividerSize</code>
301 * pixels.
303 public Dimension getMinimumSize()
305 return getPreferredSize();
310 * Processes events from the <code>JSplitPane</code> that contains
311 * this divider.
313 public void propertyChange(PropertyChangeEvent e)
315 // FIXME: Not yet implemented.
320 * Paints the divider by painting its border.
322 public void paint(Graphics g)
324 Dimension dividerSize;
326 super.paint(g);
327 if (border != null)
329 dividerSize = getSize();
330 border.paintBorder(this, g, 0, 0, dividerSize.width, dividerSize.height);
331 //System.out.println(dividerSize);
332 //g.setColor(java.awt.Color.white);
333 //g.drawRect(0, 0, 5, 5);
339 * Reacts to changes of the <code>oneToughExpandable</code>
340 * property of the containing <code>JSplitPane</code>.
342 protected void oneTouchExpandableChanged()
344 // FIXME: Not yet implemented.
349 * Creates a button for showing and hiding the left (or top)
350 * part of a <code>JSplitPane</code>.
352 protected JButton createLeftOneTouchButton()
354 return new OneTouchButton(/* left */ true);
359 * Creates a button for showing and hiding the right (or bottom)
360 * part of a <code>JSplitPane</code>.
362 protected JButton createRightOneTouchButton()
364 return new OneTouchButton(/* left */ false);
369 * Prepares the divider for dragging by calling the
370 * <code>startDragging</code> method of the UI delegate of the
371 * enclosing <code>JSplitPane</code>.
373 * @see BasicSplitPaneUI#startDragging()
375 protected void prepareForDragging()
377 if (splitPaneUI != null)
378 splitPaneUI.startDragging();
383 * Drags the divider to a given location by calling the
384 * <code>dragDividerTo</code> method of the UI delegate of the
385 * enclosing <code>JSplitPane</code>.
387 * @param location the new location of the divider.
389 * @see BasicSplitPaneUI#dragDividerTo(int location)
391 protected void dragDividerTo(int location)
393 if (splitPaneUI != null)
394 splitPaneUI.dragDividerTo(location);
399 * Finishes a dragging gesture by calling the
400 * <code>finishDraggingTo</code> method of the UI delegate of the
401 * enclosing <code>JSplitPane</code>.
403 * @param location the new, final location of the divider.
405 * @see BasicSplitPaneUI#finishDraggingTo(int location)
407 protected void finishDraggingTo(int location)
409 if (splitPaneUI != null)
410 splitPaneUI.finishDraggingTo(location);
415 * The listener for handling mouse events from both the divider
416 * and the containing <code>JSplitPane</code>.
418 * <p>The reason for also handling MouseEvents from the containing
419 * <code>JSplitPane</code> is that users should be able to start
420 * a drag gesture from inside the JSplitPane, but slightly outisde
421 * the divider.
423 * @author Sascha Brawer (brawer@dandelis.ch)
425 protected class MouseHandler
426 extends MouseAdapter
427 implements MouseMotionListener
430 public void mousePressed(MouseEvent e)
432 // FIXME: Not yet implemented.
436 public void mouseReleased(MouseEvent e)
438 // FIXME: Not yet implemented.
443 * Repeatedly invoked when the user is dragging the mouse cursor
444 * while having pressed a mouse button.
446 public void mouseDragged(MouseEvent e)
448 // FIXME: Not yet implemented.
453 * Repeatedly invoked when the user is dragging the mouse cursor
454 * without having pressed a mouse button.
456 public void mouseMoved(MouseEvent e)
458 // FIXME: Not yet implemented.
464 * A small button for showing and hiding parts of a
465 * <code>JSplitPane</code> with a single mouse click.
467 * @author Sascha Brawer (brawer@dandelis.ch)
469 private static class OneTouchButton
470 extends JButton
472 OneTouchButton(boolean left)
474 // FIXME: Set various properties of the button.
475 // Make sure it looks identical to the small
476 // buttons of the Sun reference implementation.
477 // The size should also be the same.
478 if (left)
479 setText("<");
480 else
481 setText(">");
483 Dimension butSize = new Dimension(ONE_TOUCH_SIZE, ONE_TOUCH_SIZE);
484 setMinimumSize(butSize);
485 setMaximumSize(butSize);
486 setPreferredSize(butSize);
488 setBorderPainted(false);
494 * Performs the tasks associated with an ongoing drag
495 * operation.
497 * @author Sascha Brawer (brawer@dandelis.ch)
499 protected class DragController
501 // FIXME: Not yet implemented.
502 protected DragController(MouseEvent e)
506 protected boolean isValid()
508 // FIXME: Not yet implemented.
509 return true;
512 protected int positionForMouseEvent(MouseEvent e)
514 return 0;
517 protected int getNeededLocation(int x, int y)
519 return 0;
522 protected void continueDrag(int newX, int newY)
526 protected void completeDrag(int x, int y)
530 protected void completeDrag(MouseEvent e)