- Notifications
You must be signed in to change notification settings - Fork 5.8k
/
Copy pathJSplitPane.java
1286 lines (1124 loc) · 42.8 KB
/
JSplitPane.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
packagejavax.swing;
importjava.awt.Component;
importjava.awt.ComponentOrientation;
importjava.awt.Graphics;
importjava.beans.BeanProperty;
importjava.beans.ConstructorProperties;
importjava.beans.JavaBean;
importjava.io.IOException;
importjava.io.ObjectOutputStream;
importjava.io.Serial;
importjavax.accessibility.Accessible;
importjavax.accessibility.AccessibleContext;
importjavax.accessibility.AccessibleRole;
importjavax.accessibility.AccessibleState;
importjavax.accessibility.AccessibleStateSet;
importjavax.accessibility.AccessibleValue;
importjavax.swing.plaf.SplitPaneUI;
importjavax.swing.plaf.basic.BasicSplitPaneUI;
/**
* <code>JSplitPane</code> is used to divide two (and only two)
* <code>Component</code>s. The two <code>Component</code>s
* are graphically divided based on the look and feel
* implementation, and the two <code>Component</code>s can then be
* interactively resized by the user.
* Information on using <code>JSplitPane</code> is in
* <a
href="https://docs.oracle.com/javase/tutorial/uiswing/components/splitpane.html">How to Use Split Panes</a> in
* <em>The Java Tutorial</em>.
* <p>
* The two <code>Component</code>s in a split pane can be aligned
* left to right using
* <code>JSplitPane.HORIZONTAL_SPLIT</code>, or top to bottom using
* <code>JSplitPane.VERTICAL_SPLIT</code>.
* The preferred way to change the size of the <code>Component</code>s
* is to invoke
* <code>setDividerLocation</code> where <code>location</code> is either
* the new x or y position, depending on the orientation of the
* <code>JSplitPane</code>.
* <p>
* To resize the <code>Component</code>s to their preferred sizes invoke
* <code>resetToPreferredSizes</code>.
* <p>
* When the user is resizing the <code>Component</code>s the minimum
* size of the <code>Components</code> is used to determine the
* maximum/minimum position the <code>Component</code>s
* can be set to. If the minimum size of the two
* components is greater than the size of the split pane the divider
* will not allow you to resize it. To alter the minimum size of a
* <code>JComponent</code>, see {@link JComponent#setMinimumSize}.
* <p>
* When the user resizes the split pane the new space is distributed between
* the two components based on the <code>resizeWeight</code> property.
* A value of 0,
* the default, indicates the right/bottom component gets all the space,
* where as a value of 1 indicates the left/top component gets all the space.
* <p>
* <strong>Warning:</strong> Swing is not thread safe. For more
* information see <a
* href="package-summary.html#threading">Swing's Threading
* Policy</a>.
* <p>
* <strong>Warning:</strong>
* Serialized objects of this class will not be compatible with
* future Swing releases. The current serialization support is
* appropriate for short term storage or RMI between applications running
* the same version of Swing. As of 1.4, support for long term storage
* of all JavaBeans
* has been added to the <code>java.beans</code> package.
* Please see {@link java.beans.XMLEncoder}.
*
* @see #setDividerLocation
* @see #resetToPreferredSizes
*
* @author Scott Violet
* @since 1.2
*/
@JavaBean(defaultProperty = "UI")
@SuppressWarnings("serial") // Same-version serialization only
publicclassJSplitPaneextendsJComponentimplementsAccessible
{
/**
* @see #getUIClassID
* @see #readObject
*/
privatestaticfinalStringuiClassID = "SplitPaneUI";
/**
* Vertical split indicates the <code>Component</code>s are
* split along the y axis. For example the two
* <code>Component</code>s will be split one on top of the other.
*/
publicstaticfinalintVERTICAL_SPLIT = 0;
/**
* Horizontal split indicates the <code>Component</code>s are
* split along the x axis. For example the two
* <code>Component</code>s will be split one to the left of the
* other.
*/
publicstaticfinalintHORIZONTAL_SPLIT = 1;
/**
* Used to add a <code>Component</code> to the left of the other
* <code>Component</code>.
*/
publicstaticfinalStringLEFT = "left";
/**
* Used to add a <code>Component</code> to the right of the other
* <code>Component</code>.
*/
publicstaticfinalStringRIGHT = "right";
/**
* Used to add a <code>Component</code> above the other
* <code>Component</code>.
*/
publicstaticfinalStringTOP = "top";
/**
* Used to add a <code>Component</code> below the other
* <code>Component</code>.
*/
publicstaticfinalStringBOTTOM = "bottom";
/**
* Used to add a <code>Component</code> that will represent the divider.
*/
publicstaticfinalStringDIVIDER = "divider";
/**
* Bound property name for orientation (horizontal or vertical).
*/
publicstaticfinalStringORIENTATION_PROPERTY = "orientation";
/**
* Bound property name for continuousLayout.
*/
publicstaticfinalStringCONTINUOUS_LAYOUT_PROPERTY = "continuousLayout";
/**
* Bound property name for border.
*/
publicstaticfinalStringDIVIDER_SIZE_PROPERTY = "dividerSize";
/**
* Bound property for oneTouchExpandable.
*/
publicstaticfinalStringONE_TOUCH_EXPANDABLE_PROPERTY =
"oneTouchExpandable";
/**
* Bound property for lastLocation.
*/
publicstaticfinalStringLAST_DIVIDER_LOCATION_PROPERTY =
"lastDividerLocation";
/**
* Bound property for the dividerLocation.
* @since 1.3
*/
publicstaticfinalStringDIVIDER_LOCATION_PROPERTY = "dividerLocation";
/**
* Bound property for weight.
* @since 1.3
*/
publicstaticfinalStringRESIZE_WEIGHT_PROPERTY = "resizeWeight";
/**
* How the views are split.
*/
protectedintorientation;
/**
* Whether or not the views are continuously redisplayed while
* resizing.
*/
protectedbooleancontinuousLayout;
/**
* The left or top component.
*/
protectedComponentleftComponent;
/**
* The right or bottom component.
*/
protectedComponentrightComponent;
/**
* Size of the divider.
*/
protectedintdividerSize;
privatebooleandividerSizeSet = false;
/**
* Is a little widget provided to quickly expand/collapse the
* split pane?
*/
protectedbooleanoneTouchExpandable;
privatebooleanoneTouchExpandableSet;
/**
* Previous location of the split pane.
*/
protectedintlastDividerLocation;
/**
* How to distribute extra space.
*/
privatedoubleresizeWeight;
/**
* Location of the divider, at least the value that was set, the UI may
* have a different value.
*/
privateintdividerLocation;
/**
* Creates a new <code>JSplitPane</code> configured to arrange the child
* components side-by-side horizontally, using two buttons for the components.
*/
publicJSplitPane() {
this(JSplitPane.HORIZONTAL_SPLIT,
UIManager.getBoolean("SplitPane.continuousLayout"),
newJButton(UIManager.getString("SplitPane.leftButtonText")),
newJButton(UIManager.getString("SplitPane.rightButtonText")));
}
/**
* Creates a new <code>JSplitPane</code> configured with the
* specified orientation.
*
* @param newOrientation <code>JSplitPane.HORIZONTAL_SPLIT</code> or
* <code>JSplitPane.VERTICAL_SPLIT</code>
* @throws IllegalArgumentException if <code>orientation</code>
* is not one of HORIZONTAL_SPLIT or VERTICAL_SPLIT.
*/
@ConstructorProperties({"orientation"})
publicJSplitPane(intnewOrientation) {
this(newOrientation,
UIManager.getBoolean("SplitPane.continuousLayout"));
}
/**
* Creates a new <code>JSplitPane</code> with the specified
* orientation and redrawing style.
*
* @param newOrientation <code>JSplitPane.HORIZONTAL_SPLIT</code> or
* <code>JSplitPane.VERTICAL_SPLIT</code>
* @param newContinuousLayout a boolean, true for the components to
* redraw continuously as the divider changes position, false
* to wait until the divider position stops changing to redraw
* @throws IllegalArgumentException if <code>orientation</code>
* is not one of HORIZONTAL_SPLIT or VERTICAL_SPLIT
*/
publicJSplitPane(intnewOrientation,
booleannewContinuousLayout) {
this(newOrientation, newContinuousLayout, null, null);
}
/**
* Creates a new <code>JSplitPane</code> with the specified
* orientation and the specified components.
*
* @param newOrientation <code>JSplitPane.HORIZONTAL_SPLIT</code> or
* <code>JSplitPane.VERTICAL_SPLIT</code>
* @param newLeftComponent the <code>Component</code> that will
* appear on the left
* of a horizontally-split pane, or at the top of a
* vertically-split pane
* @param newRightComponent the <code>Component</code> that will
* appear on the right
* of a horizontally-split pane, or at the bottom of a
* vertically-split pane
* @throws IllegalArgumentException if <code>orientation</code>
* is not one of: HORIZONTAL_SPLIT or VERTICAL_SPLIT
*/
publicJSplitPane(intnewOrientation,
ComponentnewLeftComponent,
ComponentnewRightComponent){
this(newOrientation,
UIManager.getBoolean("SplitPane.continuousLayout"),
newLeftComponent, newRightComponent);
}
/**
* Creates a new <code>JSplitPane</code> with the specified
* orientation and
* redrawing style, and with the specified components.
*
* @param newOrientation <code>JSplitPane.HORIZONTAL_SPLIT</code> or
* <code>JSplitPane.VERTICAL_SPLIT</code>
* @param newContinuousLayout a boolean, true for the components to
* redraw continuously as the divider changes position, false
* to wait until the divider position stops changing to redraw
* @param newLeftComponent the <code>Component</code> that will
* appear on the left
* of a horizontally-split pane, or at the top of a
* vertically-split pane
* @param newRightComponent the <code>Component</code> that will
* appear on the right
* of a horizontally-split pane, or at the bottom of a
* vertically-split pane
* @throws IllegalArgumentException if <code>orientation</code>
* is not one of HORIZONTAL_SPLIT or VERTICAL_SPLIT
*/
publicJSplitPane(intnewOrientation,
booleannewContinuousLayout,
ComponentnewLeftComponent,
ComponentnewRightComponent){
super();
dividerLocation = -1;
setLayout(null);
setUIProperty("opaque", Boolean.TRUE);
orientation = newOrientation;
if (orientation != HORIZONTAL_SPLIT && orientation != VERTICAL_SPLIT)
thrownewIllegalArgumentException("cannot create JSplitPane, " +
"orientation must be one of " +
"JSplitPane.HORIZONTAL_SPLIT " +
"or JSplitPane.VERTICAL_SPLIT");
continuousLayout = newContinuousLayout;
if (newLeftComponent != null)
setLeftComponent(newLeftComponent);
if (newRightComponent != null)
setRightComponent(newRightComponent);
updateUI();
}
/**
* {@inheritDoc}
* @param orientation {@inheritDoc}
*/
@Override
publicvoidsetComponentOrientation(ComponentOrientationorientation) {
super.setComponentOrientation(orientation);
ComponentleftComponent = this.getLeftComponent();
ComponentrightComponent = this.getRightComponent();
if (!this.getComponentOrientation().isLeftToRight()) {
if (rightComponent != null) {
setLeftComponent(rightComponent);
}
if (leftComponent != null) {
setRightComponent(leftComponent);
}
} else {
if (leftComponent != null) {
setLeftComponent(leftComponent);
}
if (rightComponent != null) {
setRightComponent(rightComponent);
}
}
}
/**
* {@inheritDoc}
* @param enabled {@inheritDoc}
*/
@Override
publicvoidsetEnabled(booleanenabled) {
super.setEnabled(enabled);
if (this.getUI() instanceofBasicSplitPaneUI) {
((BasicSplitPaneUI)(this.getUI())).getDivider().setEnabled(enabled);
}
}
/**
* Sets the L&F object that renders this component.
*
* @param ui the <code>SplitPaneUI</code> L&F object
* @see UIDefaults#getUI
*/
publicvoidsetUI(SplitPaneUIui) {
if ((SplitPaneUI)this.ui != ui) {
super.setUI(ui);
revalidate();
}
}
/**
* Returns the <code>SplitPaneUI</code> that is providing the
* current look and feel.
*
* @return the <code>SplitPaneUI</code> object that renders this component
*/
@BeanProperty(bound = false, expert = true, description
= "The L&F object that renders this component.")
publicSplitPaneUIgetUI() {
return (SplitPaneUI)ui;
}
/**
* Notification from the <code>UIManager</code> that the L&F has changed.
* Replaces the current UI object with the latest version from the
* <code>UIManager</code>.
*
* @see JComponent#updateUI
*/
publicvoidupdateUI() {
setUI((SplitPaneUI)UIManager.getUI(this));
revalidate();
}
/**
* Returns the name of the L&F class that renders this component.
*
* @return the string "SplitPaneUI"
* @see JComponent#getUIClassID
* @see UIDefaults#getUI
*/
@BeanProperty(bound = false, expert = true, description
= "A string that specifies the name of the L&F class.")
publicStringgetUIClassID() {
returnuiClassID;
}
/**
* Sets the size of the divider.
* Divider sizes {@code newSize < 0} are ignored.
*
* @param newSize an integer giving the size of the divider in pixels
*/
@BeanProperty(description
= "The size of the divider.")
publicvoidsetDividerSize(intnewSize) {
if (newSize < 0) {
return;
}
intoldSize = dividerSize;
dividerSizeSet = true;
if (oldSize != newSize) {
dividerSize = newSize;
firePropertyChange(DIVIDER_SIZE_PROPERTY, oldSize, newSize);
}
}
/**
* Returns the size of the divider.
*
* @return an integer giving the size of the divider in pixels
*/
publicintgetDividerSize() {
returndividerSize;
}
/**
* Sets the component to the left (or above) the divider.
*
* @param comp the <code>Component</code> to display in that position
*/
publicvoidsetLeftComponent(Componentcomp) {
if (comp == null) {
if (leftComponent != null) {
remove(leftComponent);
leftComponent = null;
}
} else {
add(comp, JSplitPane.LEFT);
}
}
/**
* Returns the component to the left (or above) the divider.
*
* @return the <code>Component</code> displayed in that position
*/
@BeanProperty(bound = false, preferred = true, description
= "The component to the left (or above) the divider.")
publicComponentgetLeftComponent() {
returnleftComponent;
}
/**
* Sets the component above, or to the left of the divider.
*
* @param comp the <code>Component</code> to display in that position
*/
@BeanProperty(bound = false, description
= "The component above, or to the left of the divider.")
publicvoidsetTopComponent(Componentcomp) {
setLeftComponent(comp);
}
/**
* Returns the component above, or to the left of the divider.
*
* @return the <code>Component</code> displayed in that position
*/
publicComponentgetTopComponent() {
returnleftComponent;
}
/**
* Sets the component to the right (or below) the divider.
*
* @param comp the <code>Component</code> to display in that position
*/
@BeanProperty(bound = false, preferred = true, description
= "The component to the right (or below) the divider.")
publicvoidsetRightComponent(Componentcomp) {
if (comp == null) {
if (rightComponent != null) {
remove(rightComponent);
rightComponent = null;
}
} else {
add(comp, JSplitPane.RIGHT);
}
}
/**
* Returns the component to the right (or below) the divider.
*
* @return the <code>Component</code> displayed in that position
*/
publicComponentgetRightComponent() {
returnrightComponent;
}
/**
* Sets the component below, or to the right of the divider.
*
* @param comp the <code>Component</code> to display in that position
*/
@BeanProperty(bound = false, description
= "The component below, or to the right of the divider.")
publicvoidsetBottomComponent(Componentcomp) {
setRightComponent(comp);
}
/**
* Returns the component below, or to the right of the divider.
*
* @return the <code>Component</code> displayed in that position
*/
publicComponentgetBottomComponent() {
returnrightComponent;
}
/**
* Sets the value of the <code>oneTouchExpandable</code> property,
* which must be <code>true</code> for the
* <code>JSplitPane</code> to provide a UI widget
* on the divider to quickly expand/collapse the divider.
* The default value of this property is <code>false</code>.
* Some look and feels might not support one-touch expanding;
* they will ignore this property.
*
* @param newValue <code>true</code> to specify that the split pane should provide a
* collapse/expand widget
*
* @see #isOneTouchExpandable
*/
@BeanProperty(description
= "UI widget on the divider to quickly expand/collapse the divider.")
publicvoidsetOneTouchExpandable(booleannewValue) {
booleanoldValue = oneTouchExpandable;
oneTouchExpandable = newValue;
oneTouchExpandableSet = true;
firePropertyChange(ONE_TOUCH_EXPANDABLE_PROPERTY, oldValue, newValue);
repaint();
}
/**
* Gets the <code>oneTouchExpandable</code> property.
*
* @return the value of the <code>oneTouchExpandable</code> property
* @see #setOneTouchExpandable
*/
publicbooleanisOneTouchExpandable() {
returnoneTouchExpandable;
}
/**
* Sets the last location the divider was at to
* <code>newLastLocation</code>.
*
* @param newLastLocation an integer specifying the last divider location
* in pixels, from the left (or upper) edge of the pane to the
* left (or upper) edge of the divider
*/
@BeanProperty(description
= "The last location the divider was at.")
publicvoidsetLastDividerLocation(intnewLastLocation) {
intoldLocation = lastDividerLocation;
lastDividerLocation = newLastLocation;
firePropertyChange(LAST_DIVIDER_LOCATION_PROPERTY, oldLocation,
newLastLocation);
}
/**
* Returns the last location the divider was at.
*
* @return an integer specifying the last divider location as a count
* of pixels from the left (or upper) edge of the pane to the
* left (or upper) edge of the divider
*/
publicintgetLastDividerLocation() {
returnlastDividerLocation;
}
/**
* Sets the orientation, or how the splitter is divided. The options
* are:<ul>
* <li>JSplitPane.VERTICAL_SPLIT (above/below orientation of components)
* <li>JSplitPane.HORIZONTAL_SPLIT (left/right orientation of components)
* </ul>
*
* @param orientation an integer specifying the orientation
* @throws IllegalArgumentException if orientation is not one of:
* HORIZONTAL_SPLIT or VERTICAL_SPLIT.
*/
@BeanProperty(enumerationValues = {
"JSplitPane.HORIZONTAL_SPLIT",
"JSplitPane.VERTICAL_SPLIT"}, description
= "The orientation, or how the splitter is divided.")
publicvoidsetOrientation(intorientation) {
if ((orientation != VERTICAL_SPLIT) &&
(orientation != HORIZONTAL_SPLIT)) {
thrownewIllegalArgumentException("JSplitPane: orientation must " +
"be one of " +
"JSplitPane.VERTICAL_SPLIT or " +
"JSplitPane.HORIZONTAL_SPLIT");
}
intoldOrientation = this.orientation;
this.orientation = orientation;
firePropertyChange(ORIENTATION_PROPERTY, oldOrientation, orientation);
}
/**
* Returns the orientation.
*
* @return an integer giving the orientation
* @see #setOrientation
*/
publicintgetOrientation() {
returnorientation;
}
/**
* Sets the value of the <code>continuousLayout</code> property,
* which must be <code>true</code> for the child components
* to be continuously
* redisplayed and laid out during user intervention.
* The default value of this property is look and feel dependent.
* Some look and feels might not support continuous layout;
* they will ignore this property.
*
* @param newContinuousLayout <code>true</code> if the components
* should continuously be redrawn as the divider changes position
* @see #isContinuousLayout
*/
@BeanProperty(description
= "Whether the child components are continuously redisplayed and laid out during user intervention.")
publicvoidsetContinuousLayout(booleannewContinuousLayout) {
booleanoldCD = continuousLayout;
continuousLayout = newContinuousLayout;
firePropertyChange(CONTINUOUS_LAYOUT_PROPERTY, oldCD,
newContinuousLayout);
}
/**
* Gets the <code>continuousLayout</code> property.
*
* @return the value of the <code>continuousLayout</code> property
* @see #setContinuousLayout
*/
publicbooleanisContinuousLayout() {
returncontinuousLayout;
}
/**
* Specifies how to distribute extra space when the size of the split pane
* changes. A value of 0, the default,
* indicates the right/bottom component gets all the extra space (the
* left/top component acts fixed), where as a value of 1 specifies the
* left/top component gets all the extra space (the right/bottom component
* acts fixed). Specifically, the left/top component gets (weight * diff)
* extra space and the right/bottom component gets (1 - weight) * diff
* extra space.
*
* @param value as described above
* @throws IllegalArgumentException if <code>value</code> is < 0 or > 1
* @since 1.3
*/
@BeanProperty(description
= "Specifies how to distribute extra space when the split pane resizes.")
publicvoidsetResizeWeight(doublevalue) {
if (value < 0 || value > 1) {
thrownewIllegalArgumentException("JSplitPane weight must be between 0 and 1");
}
doubleoldWeight = resizeWeight;
resizeWeight = value;
firePropertyChange(RESIZE_WEIGHT_PROPERTY, oldWeight, value);
}
/**
* Returns the number that determines how extra space is distributed.
* @return how extra space is to be distributed on a resize of the
* split pane
* @since 1.3
*/
publicdoublegetResizeWeight() {
returnresizeWeight;
}
/**
* Lays out the <code>JSplitPane</code> layout based on the preferred size
* of the children components. This will likely result in changing
* the divider location.
*/
publicvoidresetToPreferredSizes() {
SplitPaneUIui = getUI();
if (ui != null) {
ui.resetToPreferredSizes(this);
}
}
/**
* Sets the divider location as a percentage of the
* <code>JSplitPane</code>'s size.
* <p>
* This method is implemented in terms of
* <code>setDividerLocation(int)</code>.
* This method immediately changes the size of the split pane based on
* its current size. If the split pane is not correctly realized and on
* screen, this method will have no effect (new divider location will
* become (current size * proportionalLocation) which is 0).
*
* @param proportionalLocation a double-precision floating point value
* that specifies a percentage, from zero (top/left) to 1.0
* (bottom/right)
* @throws IllegalArgumentException if the specified location is < 0
* or > 1.0
*/
@BeanProperty(description
= "The location of the divider.")
publicvoidsetDividerLocation(doubleproportionalLocation) {
if (proportionalLocation < 0.0 ||
proportionalLocation > 1.0) {
thrownewIllegalArgumentException("proportional location must " +
"be between 0.0 and 1.0.");
}
if (getOrientation() == VERTICAL_SPLIT) {
setDividerLocation((int)((double)(getHeight() - getDividerSize()) *
proportionalLocation));
} else {
setDividerLocation((int)((double)(getWidth() - getDividerSize()) *
proportionalLocation));
}
}
/**
* Sets the location of the divider. This is passed off to the
* look and feel implementation, and then listeners are notified. A value
* less than 0 implies the divider should be reset to a value that
* attempts to honor the preferred size of the left/top component.
* After notifying the listeners, the last divider location is updated,
* via <code>setLastDividerLocation</code>.
*
* @param location an int specifying a UI-specific value (typically a
* pixel count)
*/
@BeanProperty(description
= "The location of the divider.")
publicvoidsetDividerLocation(intlocation) {
intoldValue = dividerLocation;
dividerLocation = location;
// Notify UI.
SplitPaneUIui = getUI();
if (ui != null) {
ui.setDividerLocation(this, location);
}
// Then listeners
firePropertyChange(DIVIDER_LOCATION_PROPERTY, oldValue, location);
// And update the last divider location.
setLastDividerLocation(oldValue);
}
/**
* Returns the last value passed to <code>setDividerLocation</code>.
* The value returned from this method may differ from the actual
* divider location (if <code>setDividerLocation</code> was passed a
* value bigger than the current size).
*
* @return an integer specifying the location of the divider
*/
publicintgetDividerLocation() {
returndividerLocation;
}
/**
* Returns the minimum location of the divider from the look and feel
* implementation.
*
* @return an integer specifying a UI-specific value for the minimum
* location (typically a pixel count); or -1 if the UI is
* <code>null</code>
*/
@BeanProperty(bound = false, description
= "The minimum location of the divider from the L&F.")
publicintgetMinimumDividerLocation() {
SplitPaneUIui = getUI();
if (ui != null) {
returnui.getMinimumDividerLocation(this);
}
return -1;
}
/**
* Returns the maximum location of the divider from the look and feel
* implementation.
*
* @return an integer specifying a UI-specific value for the maximum
* location (typically a pixel count); or -1 if the UI is
* <code>null</code>
*/
@BeanProperty(bound = false)
publicintgetMaximumDividerLocation() {
SplitPaneUIui = getUI();
if (ui != null) {
returnui.getMaximumDividerLocation(this);
}
return -1;
}
/**
* Removes the child component, <code>component</code> from the
* pane. Resets the <code>leftComponent</code> or
* <code>rightComponent</code> instance variable, as necessary.
*
* @param component the <code>Component</code> to remove
*/
publicvoidremove(Componentcomponent) {
if (component == leftComponent) {
leftComponent = null;
} elseif (component == rightComponent) {
rightComponent = null;
}
super.remove(component);
// Update the JSplitPane on the screen
revalidate();
repaint();
}
/**
* Removes the <code>Component</code> at the specified index.
* Updates the <code>leftComponent</code> and <code>rightComponent</code>
* instance variables as necessary, and then messages super.
*
* @param index an integer specifying the component to remove, where
* 1 specifies the left/top component and 2 specifies the
* bottom/right component
*/
publicvoidremove(intindex) {
Componentcomp = getComponent(index);
if (comp == leftComponent) {
leftComponent = null;
} elseif (comp == rightComponent) {
rightComponent = null;
}
super.remove(index);
// Update the JSplitPane on the screen
revalidate();
repaint();
}
/**
* Removes all the child components from the split pane. Resets the
* <code>leftComponent</code> and <code>rightComponent</code>
* instance variables.
*/
publicvoidremoveAll() {
leftComponent = rightComponent = null;
super.removeAll();
// Update the JSplitPane on the screen
revalidate();
repaint();
}
/**
* Returns true, so that calls to <code>revalidate</code>
* on any descendant of this <code>JSplitPane</code>
* will cause a request to be queued that
* will validate the <code>JSplitPane</code> and all its descendants.
*
* @return true
* @see JComponent#revalidate
* @see java.awt.Container#isValidateRoot
*/
@Override
@BeanProperty(hidden = true)
publicbooleanisValidateRoot() {
returntrue;
}
/**
* Adds the specified component to this split pane.
* If <code>constraints</code> identifies the left/top or
* right/bottom child component, and a component with that identifier
* was previously added, it will be removed and then <code>comp</code>
* will be added in its place. If <code>constraints</code> is not
* one of the known identifiers the layout manager may throw an
* <code>IllegalArgumentException</code>.
* <p>
* The possible constraints objects (Strings) are:
* <ul>
* <li>JSplitPane.TOP
* <li>JSplitPane.LEFT
* <li>JSplitPane.BOTTOM
* <li>JSplitPane.RIGHT
* </ul>
* If the <code>constraints</code> object is <code>null</code>,