001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package javax.swing.plaf.basic;
018:
019: import java.awt.Canvas;
020: import java.awt.Color;
021: import java.awt.Component;
022: import java.awt.Container;
023: import java.awt.Dimension;
024: import java.awt.Graphics;
025: import java.awt.Insets;
026: import java.awt.LayoutManager2;
027: import java.awt.event.ActionEvent;
028: import java.awt.event.ActionListener;
029: import java.awt.event.FocusAdapter;
030: import java.awt.event.FocusEvent;
031: import java.awt.event.FocusListener;
032: import java.beans.PropertyChangeEvent;
033: import java.beans.PropertyChangeListener;
034:
035: import javax.swing.JComponent;
036: import javax.swing.JSplitPane;
037: import javax.swing.KeyStroke;
038: import javax.swing.LookAndFeel;
039: import javax.swing.UIManager;
040: import javax.swing.plaf.ComponentUI;
041: import javax.swing.plaf.SplitPaneUI;
042:
043: import org.apache.harmony.x.swing.Utilities;
044:
045: import org.apache.harmony.x.swing.internal.nls.Messages;
046:
047: public class BasicSplitPaneUI extends SplitPaneUI {
048:
049: public class BasicHorizontalLayoutManager implements LayoutManager2 {
050: final int COMPONENTS_COUNT = 3;
051: final int LEFT_COMPONENT_INDEX = 0;
052: final int RIGHT_COMPONENT_INDEX = 1;
053: final int DIVIDER_INDEX = 2;
054:
055: protected int[] sizes = new int[3];
056: protected Component[] components = new Component[COMPONENTS_COUNT];
057:
058: private BasicHorizontalLayoutManager(final BasicSplitPaneUI ui) {
059: }
060:
061: public void layoutContainer(final Container container) {
062: Insets insets = container.getInsets();
063:
064: if (getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
065: calculateNewDividerLocation(container.getWidth(),
066: insets.left, insets.right);
067:
068: int divX = dividerLocation;
069: int divY = insets.top;
070: int divWidth = dividerSize;
071:
072: int leftCompX = insets.left;
073: int leftCompY = insets.top;
074: int leftCompWidth = divX - insets.left;
075:
076: int rightCompX = divX + divWidth;
077: int rightCompY = leftCompY;
078: int rightCompWidth = container.getWidth()
079: - leftCompWidth - divWidth - insets.left
080: - insets.right;
081:
082: if ((components[RIGHT_COMPONENT_INDEX] != null)
083: && (components[LEFT_COMPONENT_INDEX] != null)
084: && rightCompWidth < components[RIGHT_COMPONENT_INDEX]
085: .getMinimumSize().width
086: && leftCompWidth > components[LEFT_COMPONENT_INDEX]
087: .getMinimumSize().width) {
088:
089: rightCompWidth = components[RIGHT_COMPONENT_INDEX]
090: .getMinimumSize().width;
091: leftCompWidth = container.getWidth()
092: - rightCompWidth - divWidth - insets.left
093: - insets.right;
094:
095: if (leftCompWidth < components[LEFT_COMPONENT_INDEX]
096: .getMinimumSize().width) {
097: leftCompWidth = components[LEFT_COMPONENT_INDEX]
098: .getMinimumSize().width;
099: rightCompWidth = container.getWidth()
100: - leftCompWidth - divWidth
101: - insets.left - insets.right;
102: }
103:
104: dividerLocation = leftCompWidth + insets.left;
105: if (dividerLocation >= insets.left
106: && dividerLocation != splitPane
107: .getDividerLocation()
108: && isDisplayed) {
109: splitPane.setDividerLocation(dividerLocation);
110: }
111: }
112:
113: int height = container.getHeight() - insets.top
114: - insets.bottom;
115:
116: if (components[LEFT_COMPONENT_INDEX] != null) {
117: components[LEFT_COMPONENT_INDEX]
118: .setBounds(leftCompX, leftCompY,
119: leftCompWidth, height);
120: sizes[LEFT_COMPONENT_INDEX] = leftCompWidth;
121: }
122: if (components[DIVIDER_INDEX] != null) {
123: components[DIVIDER_INDEX].setBounds(divX, divY,
124: divWidth, height);
125: sizes[DIVIDER_INDEX] = divWidth;
126: }
127: if (components[RIGHT_COMPONENT_INDEX] != null) {
128: components[RIGHT_COMPONENT_INDEX].setBounds(
129: rightCompX, rightCompY, rightCompWidth,
130: height);
131: sizes[RIGHT_COMPONENT_INDEX] = rightCompWidth;
132: }
133: } else {
134: calculateNewDividerLocation(container.getHeight(),
135: insets.top, insets.bottom);
136:
137: int divX = insets.left;
138: int divY = dividerLocation;
139: int divHeight = dividerSize;
140:
141: int leftCompX = insets.left;
142: int leftCompY = insets.top;
143: int leftCompHeight = divY - insets.top;
144:
145: int rightCompX = insets.left;
146: int rightCompY = divY + divHeight;
147: int rightCompHeight = container.getHeight()
148: - leftCompHeight - divHeight - insets.top
149: - insets.bottom;
150:
151: if ((components[RIGHT_COMPONENT_INDEX] != null)
152: && (components[LEFT_COMPONENT_INDEX] != null)
153: && rightCompHeight < components[RIGHT_COMPONENT_INDEX]
154: .getMinimumSize().height
155: && leftCompHeight > components[LEFT_COMPONENT_INDEX]
156: .getMinimumSize().height) {
157:
158: rightCompHeight = components[RIGHT_COMPONENT_INDEX]
159: .getMinimumSize().height;
160: leftCompHeight = container.getHeight()
161: - rightCompHeight - divHeight - insets.top
162: - insets.bottom;
163:
164: if (leftCompHeight < components[LEFT_COMPONENT_INDEX]
165: .getMinimumSize().height) {
166: leftCompHeight = components[LEFT_COMPONENT_INDEX]
167: .getMinimumSize().height;
168: rightCompHeight = container.getHeight()
169: - leftCompHeight - divHeight
170: - insets.top - insets.bottom;
171: }
172:
173: dividerLocation = leftCompHeight + insets.top;
174: if (dividerLocation >= insets.top
175: && dividerLocation != splitPane
176: .getDividerLocation()
177: && isDisplayed) {
178: splitPane.setDividerLocation(dividerLocation);
179: }
180: }
181:
182: int width = container.getWidth() - insets.left
183: - insets.right;
184: if (components[LEFT_COMPONENT_INDEX] != null) {
185: components[LEFT_COMPONENT_INDEX]
186: .setBounds(leftCompX, leftCompY, width,
187: leftCompHeight);
188: sizes[LEFT_COMPONENT_INDEX] = leftCompHeight;
189: }
190: if (components[DIVIDER_INDEX] != null) {
191: components[DIVIDER_INDEX].setBounds(divX, divY,
192: width, divHeight);
193: sizes[DIVIDER_INDEX] = divHeight;
194: }
195: if (components[RIGHT_COMPONENT_INDEX] != null) {
196: components[RIGHT_COMPONENT_INDEX].setBounds(
197: rightCompX, rightCompY, width,
198: rightCompHeight);
199: sizes[RIGHT_COMPONENT_INDEX] = rightCompHeight;
200: }
201: }
202: }
203:
204: public void addLayoutComponent(final String place,
205: final Component component) {
206: if (place != null && !JSplitPane.TOP.equals(place)
207: && !JSplitPane.LEFT.equals(place)
208: && !JSplitPane.BOTTOM.equals(place)
209: && !JSplitPane.RIGHT.equals(place)
210: && !JSplitPane.DIVIDER.equals(place)) {
211: throw new IllegalArgumentException(Messages
212: .getString("swing.73")); //$NON-NLS-1$
213: }
214: if (JSplitPane.DIVIDER.equals(place)) {
215: components[DIVIDER_INDEX] = component;
216: return;
217: }
218: if (JSplitPane.TOP.equals(place)
219: || JSplitPane.LEFT.equals(place)) {
220: components[LEFT_COMPONENT_INDEX] = component;
221: return;
222: }
223: if (JSplitPane.BOTTOM.equals(place)
224: || JSplitPane.RIGHT.equals(place)) {
225: components[RIGHT_COMPONENT_INDEX] = component;
226: }
227:
228: //resetToPreferredSizes();
229: }
230:
231: public Dimension minimumLayoutSize(final Container container) {
232: int width;
233: int height;
234: Insets insets = splitPane.getInsets();
235: if (getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
236: width = insets.left + insets.right
237: + componentMinWidth(LEFT_COMPONENT_INDEX)
238: + componentMinWidth(RIGHT_COMPONENT_INDEX)
239: + sizes[DIVIDER_INDEX];
240: height = Math.max(
241: componentMinHeight(LEFT_COMPONENT_INDEX),
242: componentMinHeight(RIGHT_COMPONENT_INDEX));
243: height = Math.max(height, sizes[DIVIDER_INDEX])
244: + insets.top + insets.bottom;
245: } else {
246: width = Math.max(
247: componentMinWidth(LEFT_COMPONENT_INDEX),
248: componentMinWidth(RIGHT_COMPONENT_INDEX));
249: width = Math.max(width, sizes[DIVIDER_INDEX])
250: + insets.left + insets.right;
251: height = insets.top + insets.bottom
252: + componentMinHeight(LEFT_COMPONENT_INDEX)
253: + componentMinHeight(RIGHT_COMPONENT_INDEX)
254: + sizes[DIVIDER_INDEX];
255: }
256: return new Dimension(width, height);
257: }
258:
259: public Dimension preferredLayoutSize(final Container container) {
260: int width;
261: int height;
262: Insets insets = splitPane.getInsets();
263: if (getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
264: width = insets.left + insets.right
265: + componentPrefWidth(LEFT_COMPONENT_INDEX)
266: + componentPrefWidth(RIGHT_COMPONENT_INDEX)
267: + dividerSize;
268: height = Math.max(
269: componentPrefHeight(LEFT_COMPONENT_INDEX),
270: componentPrefHeight(RIGHT_COMPONENT_INDEX));
271: height = Math.max(height, sizes[DIVIDER_INDEX])
272: + insets.top + insets.bottom;
273: } else {
274: width = Math.max(
275: componentPrefWidth(LEFT_COMPONENT_INDEX),
276: componentPrefWidth(RIGHT_COMPONENT_INDEX));
277: width = Math.max(width, sizes[DIVIDER_INDEX])
278: + insets.left + insets.right;
279: height = insets.top + insets.bottom
280: + componentPrefHeight(LEFT_COMPONENT_INDEX)
281: + componentPrefHeight(RIGHT_COMPONENT_INDEX)
282: + dividerSize;
283: }
284: return new Dimension(width, height);
285: }
286:
287: public void removeLayoutComponent(final Component component) {
288: for (int i = 0; i < COMPONENTS_COUNT; i++) {
289: if (components[i] == component) {
290: components[i] = null;
291: }
292: }
293: }
294:
295: public void addLayoutComponent(final Component comp,
296: final Object constraints) {
297: if (!(constraints instanceof String)) {
298: throw new IllegalArgumentException(Messages
299: .getString("swing.74")); //$NON-NLS-1$
300: }
301: addLayoutComponent((String) constraints, comp);
302: }
303:
304: public float getLayoutAlignmentX(final Container target) {
305: return 0;
306: }
307:
308: public float getLayoutAlignmentY(final Container target) {
309: return 0;
310: }
311:
312: public void invalidateLayout(final Container c) {
313: }
314:
315: public Dimension maximumLayoutSize(final Container target) {
316: return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
317: }
318:
319: public void resetToPreferredSizes() {
320: if (components[LEFT_COMPONENT_INDEX] == null) {
321: return;
322: }
323:
324: int prefLocation = getPreferredSizeOfComponent(components[LEFT_COMPONENT_INDEX])
325: + getInitialLocation(splitPane.getInsets());
326: int minLocation = getMinimumSizeOfComponent(components[LEFT_COMPONENT_INDEX])
327: + getInitialLocation(splitPane.getInsets());
328: dividerLocation = prefLocation > minLocation ? prefLocation
329: : minLocation;
330: splitPane.setDividerLocation(dividerLocation);
331: }
332:
333: protected void resetSizeAt(final int index) {
334: if (getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
335: sizes[index] = components[index] == null ? 0
336: : components[index].getMinimumSize().width;
337: } else {
338: sizes[index] = components[index] == null ? 0
339: : components[index].getMinimumSize().height;
340: }
341: }
342:
343: protected void setSizes(final int[] newSizes) {
344: System.arraycopy(sizes, 0, newSizes, 0, sizes.length);
345: }
346:
347: protected int[] getSizes() {
348: int[] result = new int[COMPONENTS_COUNT];
349: System.arraycopy(result, 0, sizes, 0, sizes.length);
350:
351: return result;
352: }
353:
354: protected int getPreferredSizeOfComponent(final Component c) {
355: if (c == null) {
356: return 0;
357: }
358:
359: if (getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
360: return c.getPreferredSize().width;
361: } else {
362: return c.getPreferredSize().height;
363: }
364: }
365:
366: protected int getSizeOfComponent(final Component c) {
367: if (getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
368: return c.getSize().width;
369: } else {
370: return c.getSize().height;
371: }
372: }
373:
374: protected int getAvailableSize(final Dimension containerSize,
375: final Insets insets) {
376: if (getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
377: return containerSize.width - insets.left - insets.right;
378: } else {
379: return containerSize.height - insets.top
380: - insets.bottom;
381: }
382: }
383:
384: protected int getInitialLocation(final Insets insets) {
385: if (getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
386: return insets.left;
387: } else {
388: return insets.top;
389: }
390: }
391:
392: protected void setComponentToSize(final Component c,
393: final int size, final int location,
394: final Insets insets, final Dimension containerSize) {
395: if (c == null) {
396: return;
397: }
398: if (splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
399: c.setBounds(location, insets.top, size,
400: containerSize.height - insets.top
401: - insets.bottom);
402: } else {
403: c.setBounds(insets.left, location, containerSize.width
404: - insets.left - insets.right, size);
405: }
406: }
407:
408: protected void updateComponents() {
409: components[LEFT_COMPONENT_INDEX] = splitPane
410: .getLeftComponent();
411: components[RIGHT_COMPONENT_INDEX] = splitPane
412: .getRightComponent();
413: components[DIVIDER_INDEX] = getDivider();
414: }
415:
416: int componentPrefWidth(final int index) {
417: return components[index] == null ? 0 : components[index]
418: .getPreferredSize().width;
419: }
420:
421: int componentPrefHeight(final int index) {
422: return components[index] == null ? 0 : components[index]
423: .getPreferredSize().height;
424: }
425:
426: private int componentMinWidth(final int index) {
427: return components[index] == null ? 0 : components[index]
428: .getMinimumSize().width;
429: }
430:
431: private int componentMinHeight(final int index) {
432: return components[index] == null ? 0 : components[index]
433: .getMinimumSize().height;
434: }
435:
436: private void calculateNewDividerLocation(
437: final int containerSize, final int topLeft,
438: final int bottomRight) {
439: if (dividerLocation != splitPane.getDividerLocation()) {
440: if (splitPane.getDividerLocation() < 0
441: || splitPane.getDividerLocation() < topLeft) {
442: dividerLocation = topLeft;
443: } else if (splitPane.getDividerLocation() > containerSize
444: - bottomRight - dividerSize) {
445: dividerLocation = containerSize - bottomRight
446: - dividerSize;
447: } else {
448: dividerLocation = splitPane.getDividerLocation();
449: }
450:
451: if (dividerLocation >= topLeft
452: && dividerLocation != splitPane
453: .getDividerLocation() && isDisplayed) {
454: splitPane.setDividerLocation(dividerLocation);
455: }
456: }
457: if ((components[RIGHT_COMPONENT_INDEX] != null)
458: && (components[LEFT_COMPONENT_INDEX] == null)) {
459: dividerLocation = topLeft;
460: if (dividerLocation != splitPane.getDividerLocation()
461: && isDisplayed) {
462: splitPane.setDividerLocation(dividerLocation);
463: }
464: }
465: if ((components[RIGHT_COMPONENT_INDEX] == null)
466: && (components[LEFT_COMPONENT_INDEX] != null)) {
467: dividerLocation = containerSize - bottomRight
468: - dividerSize;
469: if (dividerLocation != splitPane.getDividerLocation()
470: && isDisplayed) {
471: splitPane.setDividerLocation(dividerLocation);
472: }
473: }
474: }
475: }
476:
477: public class BasicVerticalLayoutManager extends
478: BasicHorizontalLayoutManager {
479: public BasicVerticalLayoutManager() {
480: super (BasicSplitPaneUI.this );
481: }
482: }
483:
484: public class FocusHandler extends FocusAdapter {
485: @Override
486: public void focusGained(final FocusEvent ev) {
487: divider.repaint();
488: }
489:
490: @Override
491: public void focusLost(final FocusEvent ev) {
492: divider.repaint();
493: }
494: }
495:
496: public class KeyboardDownRightHandler implements ActionListener {
497: public void actionPerformed(final ActionEvent ev) {
498: }
499: }
500:
501: public class KeyboardEndHandler implements ActionListener {
502: public void actionPerformed(final ActionEvent ev) {
503: }
504: }
505:
506: public class KeyboardHomeHandler implements ActionListener {
507: public void actionPerformed(final ActionEvent ev) {
508: }
509: }
510:
511: public class KeyboardResizeToggleHandler implements ActionListener {
512: public void actionPerformed(final ActionEvent ev) {
513: }
514: }
515:
516: public class KeyboardUpLeftHandler implements ActionListener {
517: public void actionPerformed(final ActionEvent ev) {
518: }
519: }
520:
521: public class PropertyHandler implements PropertyChangeListener {
522: public void propertyChange(final PropertyChangeEvent e) {
523: if (JSplitPane.CONTINUOUS_LAYOUT_PROPERTY.equals(e
524: .getPropertyName())) {
525: setContinuousLayout(((Boolean) e.getNewValue())
526: .booleanValue());
527: } else if (JSplitPane.ORIENTATION_PROPERTY.equals(e
528: .getPropertyName())) {
529: setOrientation(((Integer) e.getNewValue()).intValue());
530: } else if (JSplitPane.DIVIDER_SIZE_PROPERTY.equals(e
531: .getPropertyName())) {
532: dividerSize = ((Integer) e.getNewValue()).intValue();
533: divider.setDividerSize(dividerSize);
534: layoutManager.sizes[layoutManager.DIVIDER_INDEX] = dividerSize;
535: }
536: splitPane.revalidate();
537: }
538: }
539:
540: protected static final String NON_CONTINUOUS_DIVIDER = "nonContinuousDivider";
541: protected static int KEYBOARD_DIVIDER_MOVE_OFFSET;
542: protected JSplitPane splitPane;
543: protected BasicHorizontalLayoutManager layoutManager;
544: protected BasicSplitPaneDivider divider;
545: protected PropertyChangeListener propertyChangeListener;
546: protected FocusListener focusListener;
547: protected int dividerSize;
548: protected Component nonContinuousLayoutDivider;
549: protected boolean draggingHW;
550: protected int beginDragDividerLocation;
551: /**
552: * @deprecated
553: */
554: protected KeyStroke upKey;
555: /**
556: * @deprecated
557: */
558: protected KeyStroke downKey;
559: /**
560: * @deprecated
561: */
562: protected KeyStroke leftKey;
563: /**
564: * @deprecated
565: */
566: protected KeyStroke rightKey;
567: /**
568: * @deprecated
569: */
570: protected KeyStroke homeKey;
571: /**
572: * @deprecated
573: */
574: protected KeyStroke endKey;
575: /**
576: * @deprecated
577: */
578: protected KeyStroke dividerResizeToggleKey;
579: /**
580: * @deprecated
581: */
582: protected ActionListener keyboardUpLeftListener;
583: /**
584: * @deprecated
585: */
586: protected ActionListener keyboardDownRightListener;
587: /**
588: * @deprecated
589: */
590: protected ActionListener keyboardHomeListener;
591: /**
592: * @deprecated
593: */
594: protected ActionListener keyboardEndListener;
595: /**
596: * @deprecated
597: */
598: protected ActionListener keyboardResizeToggleListener;
599:
600: private boolean isContinuousLayout;
601: private int orientation;
602: private int lastDragLocation;
603: private int dividerLocation;
604: private boolean isDisplayed;
605:
606: public static ComponentUI createUI(final JComponent c) {
607: return new BasicSplitPaneUI();
608: }
609:
610: @Override
611: public void installUI(final JComponent c) {
612: splitPane = (JSplitPane) c;
613:
614: setOrientation(splitPane.getOrientation());
615: setContinuousLayout(splitPane.isContinuousLayout());
616:
617: resetLayoutManager();
618:
619: installDefaults();
620: installListeners();
621: installKeyboardActions();
622:
623: divider.oneTouchExpandableChanged();
624: resetToPreferredSizes(getSplitPane());
625:
626: setLastDragLocation(-1);
627: }
628:
629: protected void installDefaults() {
630: LookAndFeel.installProperty(splitPane, "opaque", Boolean.TRUE);
631:
632: Color backgroundColor = splitPane.getBackground();
633: if (Utilities.isUIResource(backgroundColor)) {
634: splitPane.setForeground(UIManager
635: .getColor("SplitPane.background"));
636: }
637:
638: if (splitPane.getLeftComponent() != null) {
639: layoutManager.addLayoutComponent(splitPane
640: .getLeftComponent(), JSplitPane.LEFT);
641: }
642: if (splitPane.getRightComponent() != null) {
643: layoutManager.addLayoutComponent(splitPane
644: .getRightComponent(), JSplitPane.RIGHT);
645: }
646:
647: dividerSize = UIManager.getInt("SplitPane.dividerSize");
648: divider = createDefaultDivider();
649: divider.setDividerSize(dividerSize);
650: LookAndFeel.installBorder(splitPane, "SplitPane.border");
651: splitPane.setDividerSize(dividerSize);
652:
653: setNonContinuousLayoutDivider(createDefaultNonContinuousLayoutDivider());
654:
655: splitPane.add(divider, JSplitPane.DIVIDER);
656: }
657:
658: protected void installListeners() {
659: propertyChangeListener = createPropertyChangeListener();
660: splitPane.addPropertyChangeListener(propertyChangeListener);
661:
662: focusListener = createFocusListener();
663: splitPane.addFocusListener(focusListener);
664: }
665:
666: protected void installKeyboardActions() {
667: BasicSplitPaneKeyboardActions.installKeyboardActions(splitPane);
668: }
669:
670: @Override
671: public void uninstallUI(final JComponent c) {
672: splitPane = (JSplitPane) c;
673:
674: uninstallDefaults();
675: uninstallListeners();
676: uninstallKeyboardActions();
677: }
678:
679: protected void uninstallDefaults() {
680: Utilities.uninstallColorsAndFont(splitPane);
681: }
682:
683: protected void uninstallKeyboardActions() {
684: Utilities.uninstallKeyboardActions(splitPane,
685: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
686: }
687:
688: protected void uninstallListeners() {
689: splitPane.removePropertyChangeListener(propertyChangeListener);
690: propertyChangeListener = null;
691:
692: splitPane.removeFocusListener(focusListener);
693: focusListener = null;
694: }
695:
696: protected PropertyChangeListener createPropertyChangeListener() {
697: return new PropertyHandler();
698: }
699:
700: protected FocusListener createFocusListener() {
701: return new FocusHandler();
702: }
703:
704: /**
705: * @deprecated
706: */
707: protected ActionListener createKeyboardUpLeftListener() {
708: return new KeyboardUpLeftHandler();
709: }
710:
711: /**
712: * @deprecated
713: */
714: protected ActionListener createKeyboardDownRightListener() {
715: return new KeyboardDownRightHandler();
716: }
717:
718: /**
719: * @deprecated
720: */
721: protected ActionListener createKeyboardHomeListener() {
722: return new KeyboardHomeHandler();
723: }
724:
725: /**
726: * @deprecated
727: */
728: protected ActionListener createKeyboardEndListener() {
729: return new KeyboardEndHandler();
730: }
731:
732: /**
733: * @deprecated
734: */
735: protected ActionListener createKeyboardResizeToggleListener() {
736: return new KeyboardResizeToggleHandler();
737: }
738:
739: public int getOrientation() {
740: return orientation;
741: }
742:
743: public void setOrientation(final int orientation) {
744: this .orientation = orientation;
745: }
746:
747: public boolean isContinuousLayout() {
748: return isContinuousLayout;
749: }
750:
751: public void setContinuousLayout(final boolean b) {
752: isContinuousLayout = b;
753: }
754:
755: public int getLastDragLocation() {
756: return lastDragLocation;
757: }
758:
759: public void setLastDragLocation(final int l) {
760: lastDragLocation = l;
761: }
762:
763: public BasicSplitPaneDivider getDivider() {
764: return divider;
765: }
766:
767: protected Component createDefaultNonContinuousLayoutDivider() {
768: return new Canvas() {
769: // Note: this is not a guaratee for correct serialization/deserialization
770: // but rather a performance optimization
771: private static final long serialVersionUID = 1L;
772:
773: @Override
774: public void paint(final Graphics g) {
775: Color oldColor = g.getColor();
776: g.setColor(Color.DARK_GRAY);
777:
778: int x;
779: int y;
780: int w;
781: int h;
782: if (getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
783: x = lastDragLocation;
784: y = 0;
785: w = dividerSize;
786: h = splitPane.getHeight();
787: } else {
788: x = 0;
789: y = lastDragLocation;
790: w = splitPane.getWidth();
791: h = dividerSize;
792: }
793:
794: g.fillRect(x, y, w, h);
795:
796: g.setColor(oldColor);
797: }
798: };
799: }
800:
801: protected void setNonContinuousLayoutDivider(
802: final Component newDivider) {
803: setNonContinuousLayoutDivider(newDivider, true);
804: }
805:
806: protected void setNonContinuousLayoutDivider(
807: final Component newDivider, final boolean rememberSizes) {
808: nonContinuousLayoutDivider = newDivider;
809: }
810:
811: public Component getNonContinuousLayoutDivider() {
812: return nonContinuousLayoutDivider;
813: }
814:
815: public JSplitPane getSplitPane() {
816: return splitPane;
817: }
818:
819: public BasicSplitPaneDivider createDefaultDivider() {
820: return new BasicSplitPaneDivider(this );
821: }
822:
823: @Override
824: public void resetToPreferredSizes(final JSplitPane jc) {
825: layoutManager.resetToPreferredSizes();
826: splitPane.repaint();
827: }
828:
829: @Override
830: public void setDividerLocation(final JSplitPane jc,
831: final int location) {
832: splitPane.revalidate();
833: }
834:
835: @Override
836: public int getDividerLocation(final JSplitPane jc) {
837: if (jc == null) { // Fix for HARMONY-2661, for compatibility with RI
838: throw new NullPointerException(Messages.getString(
839: "swing.03", "jc")); //$NON-NLS-1$ //$NON-NLS-2$
840: }
841: return dividerLocation;
842: }
843:
844: @Override
845: public int getMinimumDividerLocation(final JSplitPane jc) {
846: if (getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
847: return jc.getLeftComponent() == null ? 0 : jc
848: .getLeftComponent().getMinimumSize().width
849: + jc.getInsets().left;
850: } else {
851: return jc.getLeftComponent() == null ? 0 : jc
852: .getLeftComponent().getMinimumSize().height
853: + jc.getInsets().top;
854: }
855: }
856:
857: @Override
858: public int getMaximumDividerLocation(final JSplitPane jc) {
859: Insets insets = jc.getInsets();
860: if (getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
861: return jc.getRightComponent() == null ? jc.getWidth()
862: - dividerSize - insets.right : jc.getWidth()
863: - dividerSize
864: - jc.getRightComponent().getMinimumSize().width
865: - insets.right;
866: } else {
867: return jc.getRightComponent() == null ? jc.getHeight()
868: - dividerSize - insets.bottom : jc.getHeight()
869: - dividerSize
870: - jc.getRightComponent().getMinimumSize().height
871: - insets.bottom;
872: }
873: }
874:
875: @Override
876: public void finishedPaintingChildren(final JSplitPane jc,
877: final Graphics g) {
878: g.setClip(0, 0, jc.getWidth(), jc.getHeight());
879: if (!isContinuousLayout() && lastDragLocation != -1) {
880: nonContinuousLayoutDivider.paint(g);
881: }
882: }
883:
884: @Override
885: public void paint(final Graphics g, final JComponent jc) {
886: isDisplayed = true;
887: }
888:
889: @Override
890: public Dimension getPreferredSize(final JComponent jc) {
891: return ((layoutManager != null) ? layoutManager
892: .preferredLayoutSize(jc) : new Dimension(0, 0));
893: }
894:
895: @Override
896: public Dimension getMinimumSize(final JComponent jc) {
897: return ((layoutManager != null) ? layoutManager
898: .minimumLayoutSize(jc) : new Dimension(0, 0));
899: }
900:
901: @Override
902: public Dimension getMaximumSize(final JComponent jc) {
903: return ((layoutManager != null) ? layoutManager
904: .maximumLayoutSize(jc) : new Dimension(0, 0));
905: }
906:
907: public Insets getInsets(final JComponent jc) {
908: return jc.getBorder().getBorderInsets(jc);
909: }
910:
911: protected void resetLayoutManager() {
912: if (getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
913: layoutManager = new BasicHorizontalLayoutManager(this );
914: } else {
915: layoutManager = new BasicVerticalLayoutManager();
916: }
917: splitPane.setLayout(layoutManager);
918: }
919:
920: protected void startDragging() {
921: beginDragDividerLocation = splitPane.getDividerLocation();
922: lastDragLocation = splitPane.getDividerLocation();
923: splitPane.repaint();
924: }
925:
926: protected void dragDividerTo(final int location) {
927: if (isContinuousLayout()) {
928: layoutManager.layoutContainer(splitPane);
929: } else {
930: lastDragLocation = location;
931: splitPane.repaint();
932: }
933: }
934:
935: protected void finishDraggingTo(final int location) {
936: splitPane.setDividerLocation(location);
937: layoutManager.layoutContainer(splitPane);
938: splitPane.repaint();
939: lastDragLocation = -1;
940: }
941:
942: /**
943: * @deprecated
944: */
945: protected int getDividerBorderSize() {
946: return 0;
947: }
948:
949: private int getMinimumSizeOfComponent(final Component c) {
950: if (c == null) {
951: return 0;
952: }
953:
954: if (getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
955: return c.getMinimumSize().width;
956: } else {
957: return c.getMinimumSize().height;
958: }
959: }
960: }
|