Source for javax.swing.JSplitPane

   1: /* JSplitPane.java -- 
   2:    Copyright (C) 2004, 2006,  Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   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.
  10: 
  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.
  15: 
  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., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  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.
  25: 
  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. */
  37: 
  38: 
  39: package javax.swing;
  40: 
  41: import java.awt.Component;
  42: import java.awt.Graphics;
  43: import java.beans.PropertyChangeEvent;
  44: 
  45: import javax.accessibility.Accessible;
  46: import javax.accessibility.AccessibleContext;
  47: import javax.accessibility.AccessibleRole;
  48: import javax.accessibility.AccessibleState;
  49: import javax.accessibility.AccessibleStateSet;
  50: import javax.accessibility.AccessibleValue;
  51: import javax.swing.plaf.SplitPaneUI;
  52: 
  53: /**
  54:  * This class implements JSplitPane. It is used to divide two components. By
  55:  * dragging the SplitPane's divider, the user can resize the two components.
  56:  * Note that the divider cannot resize a component to smaller than it's
  57:  * minimum size.
  58:  */
  59: public class JSplitPane extends JComponent implements Accessible
  60: {
  61: 
  62:   /**
  63:    * Provides the accessibility features for the <code>JSplitPane</code>
  64:    * component.
  65:    */
  66:   protected class AccessibleJSplitPane extends JComponent.AccessibleJComponent
  67:     implements AccessibleValue
  68:   {
  69:   private static final long serialVersionUID = -1788116871416305366L;
  70:   
  71:     /**
  72:      * Creates a new <code>AccessibleJSplitPane</code> instance.
  73:      */
  74:     protected AccessibleJSplitPane()
  75:     {
  76:       // Nothing to do here.
  77:     }
  78: 
  79:     /**
  80:      * Returns a set containing the current state of the {@link JSplitPane} 
  81:      * component.
  82:      *
  83:      * @return The accessible state set.
  84:      */
  85:     public AccessibleStateSet getAccessibleStateSet()
  86:     {
  87:       AccessibleStateSet result = super.getAccessibleStateSet();
  88:       if (getOrientation() == HORIZONTAL_SPLIT)
  89:         {
  90:           result.add(AccessibleState.HORIZONTAL);
  91:         }
  92:       else if (getOrientation() == VERTICAL_SPLIT)
  93:         {
  94:           result.add(AccessibleState.VERTICAL);
  95:         }
  96:       return result;
  97:     }
  98: 
  99:     /**
 100:      * Returns the accessible role for the <code>JSplitPane</code> component.
 101:      *
 102:      * @return {@link AccessibleRole#SPLIT_PANE}.
 103:      */
 104:     public AccessibleRole getAccessibleRole()
 105:     {
 106:       return AccessibleRole.SPLIT_PANE;
 107:     }
 108: 
 109:     /**
 110:      * Returns an object that provides access to the current, minimum and 
 111:      * maximum values for the {@link JSplitPane}.  Since this class implements 
 112:      * {@link AccessibleValue}, it returns itself.
 113:      *
 114:      * @return The accessible value.
 115:      */
 116:     public AccessibleValue getAccessibleValue()
 117:     {
 118:       return this;
 119:     }
 120: 
 121:     /**
 122:      * Returns the current divider location for the {@link JSplitPane} 
 123:      * component, as an {@link Integer}.
 124:      *
 125:      * @return The current divider location.
 126:      */
 127:     public Number getCurrentAccessibleValue()
 128:     {
 129:       return new Integer(getDividerLocation());
 130:     }
 131: 
 132:     /**
 133:      * Sets the divider location for the {@link JSplitPane} component and sends 
 134:      * a {@link PropertyChangeEvent} (with the property name 
 135:      * {@link AccessibleContext#ACCESSIBLE_VALUE_PROPERTY}) to all registered
 136:      * listeners.  If the supplied value is <code>null</code>, this method 
 137:      * does nothing and returns <code>false</code>.
 138:      *
 139:      * @param value  the new divider location (<code>null</code> permitted).
 140:      *
 141:      * @return <code>true</code> if the divider location value is updated, and 
 142:      *     <code>false</code> otherwise.
 143:      */
 144:     public boolean setCurrentAccessibleValue(Number value)
 145:     {
 146:       if (value == null)
 147:         return false;
 148:       Number oldValue = getCurrentAccessibleValue();
 149:       setDividerLocation(value.intValue());
 150:       firePropertyChange(AccessibleContext.ACCESSIBLE_VALUE_PROPERTY, oldValue, 
 151:                          new Integer(value.intValue()));
 152:       return true;
 153:     }
 154: 
 155:     /**
 156:      * Returns the minimum divider location for the {@link JSplitPane} 
 157:      * component, as an {@link Integer}.
 158:      *
 159:      * @return The minimum divider location.
 160:      */
 161:     public Number getMinimumAccessibleValue()
 162:     {
 163:       return new Integer(getMinimumDividerLocation());
 164:     }
 165: 
 166:     /**
 167:      * Returns the maximum divider location for the {@link JSplitPane} 
 168:      * component, as an {@link Integer}.
 169:      *
 170:      * @return The maximum divider location.
 171:      */
 172:     public Number getMaximumAccessibleValue()
 173:     {
 174:       return new Integer(getMaximumDividerLocation());
 175:     }
 176:   }
 177: 
 178:   private static final long serialVersionUID = -5634142046175988380L;
 179:   
 180:   /** The constraints string used to add components to the bottom. */
 181:   public static final String BOTTOM = "bottom";
 182: 
 183:   /** The property fired when the continuousLayout property changes. */
 184:   public static final String CONTINUOUS_LAYOUT_PROPERTY = "continuousLayout";
 185: 
 186:   /** The property fired when the divider property changes. */
 187:   public static final String DIVIDER = "divider";
 188: 
 189:   /** The property fired when the divider location property changes. */
 190:   public static final String DIVIDER_LOCATION_PROPERTY = "dividerLocation";
 191: 
 192:   /** The property fired when the divider size property changes. */
 193:   public static final String DIVIDER_SIZE_PROPERTY = "dividerSize";
 194: 
 195:   /**
 196:    * The value of the orientation when the components are split horizontally.
 197:    */
 198:   public static final int HORIZONTAL_SPLIT = 1;
 199: 
 200:   /** The property fired when the last divider location property changes. */
 201:   public static final String LAST_DIVIDER_LOCATION_PROPERTY = 
 202:     "lastDividerLocation";
 203: 
 204:   /** The constraints string used to add components to the left. */
 205:   public static final String LEFT = "left";
 206: 
 207:   /** The property fired when the one touch expandable property changes. */
 208:   public static final String ONE_TOUCH_EXPANDABLE_PROPERTY = 
 209:     "oneTouchExpandable";
 210: 
 211:   /** The property fired when the orientation property changes. */
 212:   public static final String ORIENTATION_PROPERTY = "orientation";
 213: 
 214:   /** The property fired when the resize weight property changes. */
 215:   public static final String RESIZE_WEIGHT_PROPERTY = "resizeWeight";
 216: 
 217:   /** The constraints string used to add components to the right. */
 218:   public static final String RIGHT = "right";
 219: 
 220:   /** The constraints string used to add components to the top. */
 221:   public static final String TOP = "top";
 222: 
 223:   /** The value of the orientation when the components are split vertically. */
 224:   public static final int VERTICAL_SPLIT = 0;
 225: 
 226:   /** Whether the JSplitPane uses continuous layout. */
 227:   protected boolean continuousLayout;
 228: 
 229:   /** Whether the JSplitPane uses one touch expandable buttons. */
 230:   protected boolean oneTouchExpandable = false;
 231: 
 232:   // This is the master dividerSize variable and sets the 
 233:   // BasicSplitPaneDivider one accordingly
 234: 
 235:   /** The size of the divider. */
 236:   protected int dividerSize = 10;
 237: 
 238:   /** The last location of the divider given by the UI. */
 239:   protected int lastDividerLocation;
 240: 
 241:   /** The orientation of the JSplitPane. */
 242:   protected int orientation;
 243: 
 244:   /** The component on the top or left. */
 245:   protected Component leftComponent;
 246: 
 247:   /** The component on the right or bottom. */
 248:   protected Component rightComponent;
 249: 
 250:   /** Determines how extra space should be allocated. */
 251:   private transient double resizeWeight;
 252: 
 253:   /**
 254:    * Indicates if the dividerSize property has been set by a client program or
 255:    * by the UI.
 256:    *
 257:    * @see #setUIProperty(String, Object)
 258:    * @see LookAndFeel#installProperty(JComponent, String, Object)
 259:    */
 260:   private boolean clientDividerSizeSet = false;
 261: 
 262:   /**
 263:    * Indicates if the oneTouchExpandable property has been set by a client
 264:    * program or by the UI.
 265:    *
 266:    * @see #setUIProperty(String, Object)
 267:    * @see LookAndFeel#installProperty(JComponent, String, Object)
 268:    */
 269:   private boolean clientOneTouchExpandableSet = false;
 270: 
 271:   /**
 272:    * Creates a new JSplitPane object with the given orientation, layout mode,
 273:    * and left and right components.
 274:    *
 275:    * @param newOrientation The orientation to use.
 276:    * @param newContinuousLayout The layout mode to use.
 277:    * @param newLeftComponent The left component.
 278:    * @param newRightComponent The right component.
 279:    *
 280:    * @throws IllegalArgumentException DOCUMENT ME!
 281:    */
 282:   public JSplitPane(int newOrientation, boolean newContinuousLayout,
 283:                     Component newLeftComponent, Component newRightComponent)
 284:   {
 285:     if (newOrientation != HORIZONTAL_SPLIT && newOrientation != VERTICAL_SPLIT)
 286:       throw new IllegalArgumentException("orientation is invalid.");
 287:     orientation = newOrientation;
 288:     continuousLayout = newContinuousLayout;
 289:     setLeftComponent(newLeftComponent);
 290:     setRightComponent(newRightComponent);
 291: 
 292:     updateUI();
 293:   }
 294: 
 295:   /**
 296:    * Creates a new JSplitPane object using nonContinuousLayout mode, the given
 297:    * orientation and left and right components.
 298:    *
 299:    * @param newOrientation The orientation to use.
 300:    * @param newLeftComponent The left component.
 301:    * @param newRightComponent The right component.
 302:    */
 303:   public JSplitPane(int newOrientation, Component newLeftComponent,
 304:                     Component newRightComponent)
 305:   {
 306:     this(newOrientation, false, newLeftComponent, newRightComponent);
 307:   }
 308: 
 309:   /**
 310:    * Creates a new JSplitPane object with the given layout mode and
 311:    * orientation.
 312:    *
 313:    * @param newOrientation The orientation to use.
 314:    * @param newContinuousLayout The layout mode to use.
 315:    */
 316:   public JSplitPane(int newOrientation, boolean newContinuousLayout)
 317:   {
 318:     this(newOrientation, newContinuousLayout, null, null);
 319:   }
 320: 
 321:   /**
 322:    * Creates a new JSplitPane object using a nonContinuousLayout mode and the
 323:    * given orientation.
 324:    *
 325:    * @param newOrientation The orientation to use.
 326:    */
 327:   public JSplitPane(int newOrientation)
 328:   {
 329:     this(newOrientation, false, null, null);
 330:   }
 331: 
 332:   /**
 333:    * Creates a new JSplitPane object using HORIZONTAL_SPLIT and a
 334:    * nonContinuousLayout mode.
 335:    */
 336:   public JSplitPane()
 337:   {
 338:     this(HORIZONTAL_SPLIT, false, new JButton("left button"),
 339:          new JButton("right button"));
 340:   }
 341: 
 342:   /**
 343:    * This method adds a component to the JSplitPane. The constraints object is
 344:    * a string that identifies where this component should go. If the
 345:    * constraints is not a known one, it will throw an
 346:    * IllegalArgumentException. The valid constraints are LEFT, TOP, RIGHT,
 347:    * BOTTOM and DIVIDER.
 348:    *
 349:    * @param comp The component to add.
 350:    * @param constraints The constraints string to use.
 351:    * @param index Where to place to component in the list of components.
 352:    *
 353:    * @throws IllegalArgumentException When the constraints is not a known 
 354:    * identifier.
 355:    */
 356:   protected void addImpl(Component comp, Object constraints, int index)
 357:   {
 358:     int left = 0;
 359:     int right = 1;
 360:     int div = 2;
 361:     int place;
 362:     if (constraints == null)
 363:       {
 364:         if (leftComponent == null)
 365:           constraints = LEFT;
 366:         else if (rightComponent == null)
 367:           constraints = RIGHT;
 368:       }
 369: 
 370:     if (constraints instanceof String)
 371:       {
 372:         String placement = (String) constraints;
 373: 
 374:         if (placement.equals(BOTTOM) || placement.equals(RIGHT))
 375:           {
 376:             if (rightComponent != null)
 377:               remove(rightComponent);
 378:             rightComponent = comp;
 379:           }
 380:         else if (placement.equals(LEFT) || placement.equals(TOP))
 381:           {
 382:             if (leftComponent != null)
 383:               remove(leftComponent);
 384:             leftComponent = comp;
 385:           }
 386:         else if (placement.equals(DIVIDER))
 387:           constraints = null;
 388:         else
 389:           throw new 
 390:             IllegalArgumentException("Constraints is not a known identifier.");
 391: 
 392:         // If no dividerLocation has been set, then we need to trigger an
 393:         // initial layout.
 394:         if (getDividerLocation() != -1)
 395:           resetToPreferredSizes();
 396: 
 397:         super.addImpl(comp, constraints, index);
 398:       }
 399:   }
 400: 
 401:   /**
 402:    * Returns the object that provides accessibility features for this
 403:    * <code>JSplitPane</code> component.
 404:    *
 405:    * @return The accessible context (an instance of 
 406:    *     {@link AccessibleJSplitPane}).
 407:    */
 408:   public AccessibleContext getAccessibleContext()
 409:   {
 410:     if (accessibleContext == null)
 411:       accessibleContext = new AccessibleJSplitPane();
 412:     
 413:     return accessibleContext;
 414:   }
 415: 
 416:   /**
 417:    * This method returns the bottom component.
 418:    *
 419:    * @return The bottom component.
 420:    */
 421:   public Component getBottomComponent()
 422:   {
 423:     return rightComponent;
 424:   }
 425: 
 426:   /**
 427:    * This method returns the location of the divider. This method is passed to
 428:    * the UI.
 429:    *
 430:    * @return The location of the divider.
 431:    */
 432:   public int getDividerLocation()
 433:   {
 434:     if (ui != null)
 435:       return ((SplitPaneUI) ui).getDividerLocation(this);
 436:     else
 437:       return -1;
 438:   }
 439: 
 440:   /**
 441:    * This method returns the size of the divider.
 442:    *
 443:    * @return The size of the divider.
 444:    */
 445:   public int getDividerSize()
 446:   {
 447:     return dividerSize;
 448:   }
 449: 
 450:   /**
 451:    * This method returns the last divider location.
 452:    *
 453:    * @return The last divider location.
 454:    */
 455:   public int getLastDividerLocation()
 456:   {
 457:     return lastDividerLocation;
 458:   }
 459: 
 460:   /**
 461:    * This method returns the left component.
 462:    *
 463:    * @return The left component.
 464:    */
 465:   public Component getLeftComponent()
 466:   {
 467:     return leftComponent;
 468:   }
 469: 
 470:   /**
 471:    * This method returns the maximum divider location. This method is passed
 472:    * to  the UI.
 473:    *
 474:    * @return DOCUMENT ME!
 475:    */
 476:   public int getMaximumDividerLocation()
 477:   {
 478:     if (ui != null)
 479:       return ((SplitPaneUI) ui).getMaximumDividerLocation(this);
 480:     else
 481:       return -1;
 482:   }
 483: 
 484:   /**
 485:    * This method returns the minimum divider location. This method is passed
 486:    * to the UI.
 487:    *
 488:    * @return The minimum divider location.
 489:    */
 490:   public int getMinimumDividerLocation()
 491:   {
 492:     if (ui != null)
 493:       return ((SplitPaneUI) ui).getMinimumDividerLocation(this);
 494:     else
 495:       return -1;
 496:   }
 497: 
 498:   /**
 499:    * This method returns the orientation that the JSplitPane is using.
 500:    *
 501:    * @return The current orientation.
 502:    */
 503:   public int getOrientation()
 504:   {
 505:     return orientation;
 506:   }
 507: 
 508:   /**
 509:    * This method returns the current resize weight.
 510:    *
 511:    * @return The current resize weight.
 512:    */
 513:   public double getResizeWeight()
 514:   {
 515:     return resizeWeight;
 516:   }
 517: 
 518:   /**
 519:    * This method returns the right component.
 520:    *
 521:    * @return The right component.
 522:    */
 523:   public Component getRightComponent()
 524:   {
 525:     return rightComponent;
 526:   }
 527: 
 528:   /**
 529:    * This method returns the top component.
 530:    *
 531:    * @return The top component.
 532:    */
 533:   public Component getTopComponent()
 534:   {
 535:     return leftComponent;
 536:   }
 537: 
 538:   /**
 539:    * This method returns the UI.
 540:    *
 541:    * @return The UI.
 542:    */
 543:   public SplitPaneUI getUI()
 544:   {
 545:     return (SplitPaneUI) ui;
 546:   }
 547: 
 548:   /**
 549:    * This method returns true if the JSplitPane is using a continuousLayout.
 550:    *
 551:    * @return True if using a continuousLayout.
 552:    */
 553:   public boolean isContinuousLayout()
 554:   {
 555:     return continuousLayout;
 556:   }
 557: 
 558:   /**
 559:    * This method returns true if the divider has one touch expandable buttons.
 560:    *
 561:    * @return True if one touch expandable is used.
 562:    */
 563:   public boolean isOneTouchExpandable()
 564:   {
 565:     return oneTouchExpandable;
 566:   }
 567: 
 568:   /**
 569:    * This method returns true.
 570:    *
 571:    * @return true.
 572:    */
 573:   public boolean isValidateRoot()
 574:   {
 575:     return true;
 576:   }
 577: 
 578:   /**
 579:    * This method overrides JComponent's paintChildren so the UI can be
 580:    * messaged when the children have finished painting.
 581:    *
 582:    * @param g The Graphics object to paint with.
 583:    */
 584:   protected void paintChildren(Graphics g)
 585:   {
 586:     super.paintChildren(g);
 587:     if (ui != null)
 588:       ((SplitPaneUI) ui).finishedPaintingChildren(this, g);
 589:   }
 590: 
 591:   /**
 592:    * Returns an implementation-dependent string describing the attributes of
 593:    * this <code>JSplitPane</code>.
 594:    *
 595:    * @return A string describing the attributes of this <code>JSplitPane</code>
 596:    *         (never <code>null</code>).
 597:    */
 598:   protected String paramString()
 599:   {
 600:     // FIXME: the next line can be restored once PR27208 is fixed
 601:     String superParamStr = ""; //super.paramString();
 602:     StringBuffer sb = new StringBuffer();
 603:     sb.append(",continuousLayout=").append(isContinuousLayout());
 604:     sb.append(",dividerSize=").append(getDividerSize());
 605:     sb.append(",lastDividerLocation=").append(getLastDividerLocation());
 606:     sb.append(",oneTouchExpandable=").append(isOneTouchExpandable());
 607:     sb.append(",orientation=");
 608:     if (orientation == HORIZONTAL_SPLIT)
 609:       sb.append("HORIZONTAL_SPLIT");
 610:     else
 611:       sb.append("VERTICAL_SPLIT");
 612:     return superParamStr + sb.toString();
 613:   }
 614: 
 615:   /**
 616:    * This method removes the given component from the JSplitPane.
 617:    *
 618:    * @param component The Component to remove.
 619:    */
 620:   public void remove(Component component)
 621:   {
 622:     if (component == leftComponent)
 623:       leftComponent = null;
 624:     else if (component == rightComponent)
 625:       rightComponent = null;
 626:     super.remove(component);
 627:   }
 628: 
 629:   /**
 630:    * This method removes the component at the given index.
 631:    *
 632:    * @param index The index of the component to remove.
 633:    */
 634:   public void remove(int index)
 635:   {
 636:     Component component = getComponent(index);
 637:     if (component == leftComponent)
 638:       leftComponent = null;
 639:     else if (component == rightComponent)
 640:       rightComponent = null;
 641:     super.remove(index);
 642:   }
 643: 
 644:   /**
 645:    * This method removes all components from the JSplitPane.
 646:    */
 647:   public void removeAll()
 648:   {
 649:     leftComponent = null;
 650:     rightComponent = null;
 651:     super.removeAll();
 652:   }
 653: 
 654:   /**
 655:    * This method resets all children of the JSplitPane to their preferred
 656:    * sizes.
 657:    */
 658:   public void resetToPreferredSizes()
 659:   {
 660:     if (ui != null)
 661:       ((SplitPaneUI) ui).resetToPreferredSizes(this);
 662:   }
 663: 
 664:   /**
 665:    * This method sets the bottom component.
 666:    *
 667:    * @param comp The Component to be placed at the bottom.
 668:    */
 669:   public void setBottomComponent(Component comp)
 670:   {
 671:     if (comp != null)
 672:       add(comp, BOTTOM);
 673:     else
 674:       add(new JButton("right button"), BOTTOM);
 675:   }
 676: 
 677:   /**
 678:    * This method sets the layout mode for the JSplitPane.
 679:    *
 680:    * @param newContinuousLayout Whether the JSplitPane is in continuousLayout
 681:    *        mode.
 682:    */
 683:   public void setContinuousLayout(boolean newContinuousLayout)
 684:   {
 685:     if (newContinuousLayout != continuousLayout)
 686:       {
 687:         boolean oldValue = continuousLayout;
 688:         continuousLayout = newContinuousLayout;
 689:         firePropertyChange(CONTINUOUS_LAYOUT_PROPERTY, oldValue,
 690:                            continuousLayout);
 691:       }
 692:   }
 693: 
 694:   /**
 695:    * This method sets the location of the divider. A value of 0 sets the
 696:    * divider to the farthest left. A value of 1 sets the divider to the
 697:    * farthest right.
 698:    *
 699:    * @param proportionalLocation A double that describes the location of the
 700:    *        divider.
 701:    *
 702:    * @throws IllegalArgumentException if <code>proportionalLocation</code> is
 703:    *     not in the range from 0.0 to 1.0 inclusive.
 704:    */
 705:   public void setDividerLocation(double proportionalLocation)
 706:   {
 707:     if (proportionalLocation > 1 || proportionalLocation < 0)
 708:       throw new IllegalArgumentException
 709:         ("proportion has to be between 0 and 1.");
 710: 
 711:     int max = ((orientation == HORIZONTAL_SPLIT) ? getWidth() : getHeight())
 712:               - getDividerSize();
 713:     setDividerLocation((int) (proportionalLocation * max));
 714:   }
 715: 
 716:   /**
 717:    * This method sets the location of the divider.
 718:    * 
 719:    * @param location The location of the divider. The negative value forces to
 720:    *          compute the new location from the preferred sizes of the split
 721:    *          pane components.
 722:    */
 723:   public void setDividerLocation(int location)
 724:   {
 725:     if (ui != null && location != getDividerLocation())
 726:       {
 727:         int oldLocation = getDividerLocation();        
 728:         if (location < 0)
 729:           ((SplitPaneUI) ui).resetToPreferredSizes(this);
 730:         else
 731:             ((SplitPaneUI) ui).setDividerLocation(this, location);
 732:         
 733:         firePropertyChange(DIVIDER_LOCATION_PROPERTY, oldLocation, 
 734:                            getDividerLocation());
 735:       }
 736:   }
 737: 
 738:   /**
 739:    * This method sets the size of the divider.
 740:    *
 741:    * @param newSize The size of the divider.
 742:    */
 743:   public void setDividerSize(int newSize)
 744:   {
 745:     clientDividerSizeSet = true;
 746:     if (newSize != dividerSize)
 747:       {
 748:         int oldSize = dividerSize;
 749:         dividerSize = newSize;
 750:         firePropertyChange(DIVIDER_SIZE_PROPERTY, oldSize, dividerSize);
 751:       }
 752:   }
 753: 
 754:   // This doesn't appear to do anything when set from user side.
 755:   // so it probably is only used from the UI side to change the
 756:   // lastDividerLocation var.
 757: 
 758:   /**
 759:    * This method sets the last location of the divider.
 760:    *
 761:    * @param newLastLocation The last location of the divider.
 762:    */
 763:   public void setLastDividerLocation(int newLastLocation)
 764:   {
 765:     if (newLastLocation != lastDividerLocation)
 766:       {
 767:         int oldValue = lastDividerLocation;
 768:         lastDividerLocation = newLastLocation;
 769:         firePropertyChange(LAST_DIVIDER_LOCATION_PROPERTY, oldValue,
 770:                            lastDividerLocation);
 771:       }
 772:   }
 773: 
 774:   /**
 775:    * This method sets the left component.
 776:    *
 777:    * @param comp The left component.
 778:    */
 779:   public void setLeftComponent(Component comp)
 780:   {    
 781:     if (comp != null)
 782:       add(comp, LEFT);
 783:     else
 784:       remove (leftComponent);
 785:   }
 786: 
 787:   /**
 788:    * This method sets whether the divider has one touch expandable buttons.
 789:    * The one touch expandable buttons can expand the size of either component
 790:    * to the maximum allowed size.
 791:    *
 792:    * @param newValue Whether the divider will have one touch expandable
 793:    *        buttons.
 794:    */
 795:   public void setOneTouchExpandable(boolean newValue)
 796:   {
 797:     clientOneTouchExpandableSet = true;
 798:     if (newValue != oneTouchExpandable)
 799:       {
 800:         boolean oldValue = oneTouchExpandable;
 801:         oneTouchExpandable = newValue;
 802:         firePropertyChange(ONE_TOUCH_EXPANDABLE_PROPERTY, oldValue,
 803:                            oneTouchExpandable);
 804:       }
 805:   }
 806: 
 807:   /**
 808:    * Sets the orientation for the <code>JSplitPane</code> and sends a 
 809:    * {@link PropertyChangeEvent} (with the property name 
 810:    * {@link #ORIENTATION_PROPERTY}) to all registered listeners.
 811:    *
 812:    * @param orientation  the orientation (either {@link #HORIZONTAL_SPLIT}
 813:    * or {@link #VERTICAL_SPLIT}).
 814:    *
 815:    * @throws IllegalArgumentException if <code>orientation</code> is not one of
 816:    *     the listed values.
 817:    */
 818:   public void setOrientation(int orientation)
 819:   {
 820:     if (orientation != HORIZONTAL_SPLIT && orientation != VERTICAL_SPLIT)
 821:       throw new IllegalArgumentException
 822:         ("orientation must be one of VERTICAL_SPLIT, HORIZONTAL_SPLIT");
 823:     if (orientation != this.orientation)
 824:       {
 825:         int oldOrientation = this.orientation;
 826:         this.orientation = orientation;
 827:         firePropertyChange(ORIENTATION_PROPERTY, oldOrientation,
 828:                            this.orientation);
 829:       }
 830:   }
 831: 
 832:   /**
 833:    * This method determines how extra space will be distributed among the left
 834:    * and right components. A value of 0 will allocate all extra space to the
 835:    * right component. A value of 1 indicates that all extra space will go to
 836:    * the left component. A value in between 1 and 0 will split the space
 837:    * accordingly.
 838:    *
 839:    * @param value The resize weight.
 840:    */
 841:   public void setResizeWeight(double value)
 842:   {
 843:     if (value < 0.0 || value > 1.0)
 844:       throw new IllegalArgumentException("Value outside permitted range.");
 845:     if (this.resizeWeight != value)
 846:       { 
 847:         double old = resizeWeight;
 848:         resizeWeight = value;
 849:         firePropertyChange(RESIZE_WEIGHT_PROPERTY, old, value);
 850:       }
 851:   }
 852: 
 853:   /**
 854:    * This method sets the right component.
 855:    *
 856:    * @param comp The right component.
 857:    */
 858:   public void setRightComponent(Component comp)
 859:   {
 860:     if (comp != null)
 861:       add(comp, RIGHT);
 862:     else
 863:       remove (rightComponent);
 864:   }
 865: 
 866:   /**
 867:    * This method sets the top component.
 868:    *
 869:    * @param comp The top component.
 870:    */
 871:   public void setTopComponent(Component comp)
 872:   {
 873:     if (comp != null)
 874:       add(comp, TOP);
 875:     else
 876:       add(new JButton("left button"), TOP);
 877:   }
 878: 
 879:   /**
 880:    * This method sets the UI used by the JSplitPane.
 881:    *
 882:    * @param ui The UI to use.
 883:    */
 884:   public void setUI(SplitPaneUI ui)
 885:   {
 886:     super.setUI(ui);
 887:   }
 888: 
 889:   /**
 890:    * This method resets the UI to the one specified by the current Look and
 891:    * Feel.
 892:    */
 893:   public void updateUI()
 894:   {
 895:     setUI((SplitPaneUI) UIManager.getUI(this));
 896:   }
 897: 
 898:   /**
 899:    * This method returns a string identifier to determine which UI class it
 900:    * needs.
 901:    *
 902:    * @return A string that identifies it's UI class.
 903:    */
 904:   public String getUIClassID()
 905:   {
 906:     return "SplitPaneUI";
 907:   }
 908: 
 909:   /**
 910:    * Helper method for
 911:    * {@link LookAndFeel#installProperty(JComponent, String, Object)}.
 912:    * 
 913:    * @param propertyName the name of the property
 914:    * @param value the value of the property
 915:    *
 916:    * @throws IllegalArgumentException if the specified property cannot be set
 917:    *         by this method
 918:    * @throws ClassCastException if the property value does not match the
 919:    *         property type
 920:    * @throws NullPointerException if <code>c</code> or
 921:    *         <code>propertyValue</code> is <code>null</code>
 922:    */
 923:   void setUIProperty(String propertyName, Object value)
 924:   {
 925:     if (propertyName.equals("dividerSize"))
 926:       {
 927:         if (! clientDividerSizeSet)
 928:           {
 929:             setDividerSize(((Integer) value).intValue());
 930:             clientDividerSizeSet = false;
 931:           }
 932:       }
 933:     else if (propertyName.equals("oneTouchExpandable"))
 934:       {
 935:         if (! clientOneTouchExpandableSet)
 936:           {
 937:             setOneTouchExpandable(((Boolean) value).booleanValue());
 938:             clientOneTouchExpandableSet = false;
 939:           }
 940:       }
 941:     else
 942:       {
 943:         super.setUIProperty(propertyName, value);
 944:       }
 945:   }
 946: }