1 7 8 package javax.swing.plaf.basic; 9 10 import sun.swing.DefaultLookup; 11 import sun.swing.UIAction; 12 13 import javax.swing.*; 14 import javax.swing.event.*; 15 import javax.swing.border.*; 16 import javax.swing.plaf.*; 17 18 import java.beans.PropertyChangeListener ; 19 import java.beans.PropertyChangeEvent ; 20 21 import java.awt.Component ; 22 import java.awt.Container ; 23 import java.awt.LayoutManager ; 24 import java.awt.Rectangle ; 25 import java.awt.Dimension ; 26 import java.awt.Point ; 27 import java.awt.Insets ; 28 import java.awt.Graphics ; 29 import java.awt.event.*; 30 import java.io.Serializable ; 31 import java.awt.Toolkit ; 32 33 39 public class BasicScrollPaneUI 40 extends ScrollPaneUI implements ScrollPaneConstants 41 { 42 protected JScrollPane scrollpane; 43 protected ChangeListener vsbChangeListener; 44 protected ChangeListener hsbChangeListener; 45 protected ChangeListener viewportChangeListener; 46 protected PropertyChangeListener spPropertyChangeListener; 47 private MouseWheelListener mouseScrollListener; 48 49 52 private PropertyChangeListener vsbPropertyChangeListener; 53 54 57 private PropertyChangeListener hsbPropertyChangeListener; 58 59 private Handler handler; 60 61 66 private boolean setValueCalled = false; 67 68 69 public static ComponentUI createUI(JComponent x) { 70 return new BasicScrollPaneUI (); 71 } 72 73 static void loadActionMap(LazyActionMap map) { 74 map.put(new Actions(Actions.SCROLL_UP)); 75 map.put(new Actions(Actions.SCROLL_DOWN)); 76 map.put(new Actions(Actions.SCROLL_HOME)); 77 map.put(new Actions(Actions.SCROLL_END)); 78 map.put(new Actions(Actions.UNIT_SCROLL_UP)); 79 map.put(new Actions(Actions.UNIT_SCROLL_DOWN)); 80 map.put(new Actions(Actions.SCROLL_LEFT)); 81 map.put(new Actions(Actions.SCROLL_RIGHT)); 82 map.put(new Actions(Actions.UNIT_SCROLL_RIGHT)); 83 map.put(new Actions(Actions.UNIT_SCROLL_LEFT)); 84 } 85 86 87 88 public void paint(Graphics g, JComponent c) { 89 Border vpBorder = scrollpane.getViewportBorder(); 90 if (vpBorder != null) { 91 Rectangle r = scrollpane.getViewportBorderBounds(); 92 vpBorder.paintBorder(scrollpane, g, r.x, r.y, r.width, r.height); 93 } 94 } 95 96 97 100 public Dimension getMaximumSize(JComponent c) { 101 return new Dimension (Short.MAX_VALUE, Short.MAX_VALUE); 102 } 103 104 105 protected void installDefaults(JScrollPane scrollpane) 106 { 107 LookAndFeel.installBorder(scrollpane, "ScrollPane.border"); 108 LookAndFeel.installColorsAndFont(scrollpane, 109 "ScrollPane.background", 110 "ScrollPane.foreground", 111 "ScrollPane.font"); 112 113 Border vpBorder = scrollpane.getViewportBorder(); 114 if ((vpBorder == null) ||( vpBorder instanceof UIResource)) { 115 vpBorder = UIManager.getBorder("ScrollPane.viewportBorder"); 116 scrollpane.setViewportBorder(vpBorder); 117 } 118 LookAndFeel.installProperty(scrollpane, "opaque", Boolean.TRUE); 119 } 120 121 122 protected void installListeners(JScrollPane c) 123 { 124 vsbChangeListener = createVSBChangeListener(); 125 vsbPropertyChangeListener = createVSBPropertyChangeListener(); 126 hsbChangeListener = createHSBChangeListener(); 127 hsbPropertyChangeListener = createHSBPropertyChangeListener(); 128 viewportChangeListener = createViewportChangeListener(); 129 spPropertyChangeListener = createPropertyChangeListener(); 130 131 JViewport viewport = scrollpane.getViewport(); 132 JScrollBar vsb = scrollpane.getVerticalScrollBar(); 133 JScrollBar hsb = scrollpane.getHorizontalScrollBar(); 134 135 if (viewport != null) { 136 viewport.addChangeListener(viewportChangeListener); 137 } 138 if (vsb != null) { 139 vsb.getModel().addChangeListener(vsbChangeListener); 140 vsb.addPropertyChangeListener(vsbPropertyChangeListener); 141 } 142 if (hsb != null) { 143 hsb.getModel().addChangeListener(hsbChangeListener); 144 hsb.addPropertyChangeListener(hsbPropertyChangeListener); 145 } 146 147 scrollpane.addPropertyChangeListener(spPropertyChangeListener); 148 149 mouseScrollListener = createMouseWheelListener(); 150 scrollpane.addMouseWheelListener(mouseScrollListener); 151 152 } 153 154 protected void installKeyboardActions(JScrollPane c) { 155 InputMap inputMap = getInputMap(JComponent. 156 WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); 157 158 SwingUtilities.replaceUIInputMap(c, JComponent. 159 WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap); 160 161 LazyActionMap.installLazyActionMap(c, BasicScrollPaneUI .class, 162 "ScrollPane.actionMap"); 163 } 164 165 InputMap getInputMap(int condition) { 166 if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) { 167 InputMap keyMap = (InputMap)DefaultLookup.get(scrollpane, this, 168 "ScrollPane.ancestorInputMap"); 169 InputMap rtlKeyMap; 170 171 if (scrollpane.getComponentOrientation().isLeftToRight() || 172 ((rtlKeyMap = (InputMap)DefaultLookup.get(scrollpane, this, 173 "ScrollPane.ancestorInputMap.RightToLeft")) == null)) { 174 return keyMap; 175 } else { 176 rtlKeyMap.setParent(keyMap); 177 return rtlKeyMap; 178 } 179 } 180 return null; 181 } 182 183 public void installUI(JComponent x) { 184 scrollpane = (JScrollPane)x; 185 installDefaults(scrollpane); 186 installListeners(scrollpane); 187 installKeyboardActions(scrollpane); 188 } 189 190 191 protected void uninstallDefaults(JScrollPane c) { 192 LookAndFeel.uninstallBorder(scrollpane); 193 194 if (scrollpane.getViewportBorder() instanceof UIResource) { 195 scrollpane.setViewportBorder(null); 196 } 197 } 198 199 200 protected void uninstallListeners(JComponent c) { 201 JViewport viewport = scrollpane.getViewport(); 202 JScrollBar vsb = scrollpane.getVerticalScrollBar(); 203 JScrollBar hsb = scrollpane.getHorizontalScrollBar(); 204 205 if (viewport != null) { 206 viewport.removeChangeListener(viewportChangeListener); 207 } 208 if (vsb != null) { 209 vsb.getModel().removeChangeListener(vsbChangeListener); 210 vsb.removePropertyChangeListener(vsbPropertyChangeListener); 211 } 212 if (hsb != null) { 213 hsb.getModel().removeChangeListener(hsbChangeListener); 214 hsb.removePropertyChangeListener(hsbPropertyChangeListener); 215 } 216 217 scrollpane.removePropertyChangeListener(spPropertyChangeListener); 218 219 if (mouseScrollListener != null) { 220 scrollpane.removeMouseWheelListener(mouseScrollListener); 221 } 222 223 vsbChangeListener = null; 224 hsbChangeListener = null; 225 viewportChangeListener = null; 226 spPropertyChangeListener = null; 227 mouseScrollListener = null; 228 handler = null; 229 } 230 231 232 protected void uninstallKeyboardActions(JScrollPane c) { 233 SwingUtilities.replaceUIActionMap(c, null); 234 SwingUtilities.replaceUIInputMap(c, JComponent. 235 WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null); 236 } 237 238 239 public void uninstallUI(JComponent c) { 240 uninstallDefaults(scrollpane); 241 uninstallListeners(scrollpane); 242 uninstallKeyboardActions(scrollpane); 243 scrollpane = null; 244 } 245 246 private Handler getHandler() { 247 if (handler == null) { 248 handler = new Handler(); 249 } 250 return handler; 251 } 252 253 protected void syncScrollPaneWithViewport() 254 { 255 JViewport viewport = scrollpane.getViewport(); 256 JScrollBar vsb = scrollpane.getVerticalScrollBar(); 257 JScrollBar hsb = scrollpane.getHorizontalScrollBar(); 258 JViewport rowHead = scrollpane.getRowHeader(); 259 JViewport colHead = scrollpane.getColumnHeader(); 260 boolean ltr = scrollpane.getComponentOrientation().isLeftToRight(); 261 262 if (viewport != null) { 263 Dimension extentSize = viewport.getExtentSize(); 264 Dimension viewSize = viewport.getViewSize(); 265 Point viewPosition = viewport.getViewPosition(); 266 267 if (vsb != null) { 268 int extent = extentSize.height; 269 int max = viewSize.height; 270 int value = Math.max(0, Math.min(viewPosition.y, max - extent)); 271 vsb.setValues(value, extent, 0, max); 272 } 273 274 if (hsb != null) { 275 int extent = extentSize.width; 276 int max = viewSize.width; 277 int value; 278 279 if (ltr) { 280 value = Math.max(0, Math.min(viewPosition.x, max - extent)); 281 } else { 282 int currentValue = hsb.getValue(); 283 284 287 if (setValueCalled && ((max - currentValue) == viewPosition.x)) { 288 value = Math.max(0, Math.min(max - extent, currentValue)); 289 291 if (extent != 0) { 292 setValueCalled = false; 293 } 294 } else { 295 if (extent > max) { 296 viewPosition.x = max - extent; 297 viewport.setViewPosition(viewPosition); 298 value = 0; 299 } else { 300 311 value = Math.max(0, Math.min(max - extent, max - extent - viewPosition.x)); 312 } 313 } 314 } 315 hsb.setValues(value, extent, 0, max); 316 } 317 318 if (rowHead != null) { 319 Point p = rowHead.getViewPosition(); 320 p.y = viewport.getViewPosition().y; 321 p.x = 0; 322 rowHead.setViewPosition(p); 323 } 324 325 if (colHead != null) { 326 Point p = colHead.getViewPosition(); 327 if (ltr) { 328 p.x = viewport.getViewPosition().x; 329 } else { 330 p.x = Math.max(0, viewport.getViewPosition().x); 331 } 332 p.y = 0; 333 colHead.setViewPosition(p); 334 } 335 } 336 } 337 338 339 342 public class ViewportChangeHandler implements ChangeListener 343 { 344 345 350 public void stateChanged(ChangeEvent e) { 351 getHandler().stateChanged(e); 352 } 353 } 354 355 protected ChangeListener createViewportChangeListener() { 356 return getHandler(); 357 } 358 359 360 363 public class HSBChangeListener implements ChangeListener 364 { 365 366 371 public void stateChanged(ChangeEvent e) 372 { 373 getHandler().stateChanged(e); 374 } 375 } 376 377 381 private PropertyChangeListener createHSBPropertyChangeListener() { 382 return getHandler(); 383 } 384 385 protected ChangeListener createHSBChangeListener() { 386 return getHandler(); 387 } 388 389 390 393 public class VSBChangeListener implements ChangeListener 394 { 395 396 401 public void stateChanged(ChangeEvent e) 402 { 403 getHandler().stateChanged(e); 404 } 405 } 406 407 408 412 private PropertyChangeListener createVSBPropertyChangeListener() { 413 return getHandler(); 414 } 415 416 protected ChangeListener createVSBChangeListener() { 417 return getHandler(); 418 } 419 420 434 protected class MouseWheelHandler implements MouseWheelListener { 435 436 441 448 public void mouseWheelMoved(MouseWheelEvent e) { 449 getHandler().mouseWheelMoved(e); 450 } 451 } 452 453 463 protected MouseWheelListener createMouseWheelListener() { 464 return getHandler(); 465 } 466 467 protected void updateScrollBarDisplayPolicy(PropertyChangeEvent e) { 468 scrollpane.revalidate(); 469 scrollpane.repaint(); 470 } 471 472 473 protected void updateViewport(PropertyChangeEvent e) 474 { 475 JViewport oldViewport = (JViewport)(e.getOldValue()); 476 JViewport newViewport = (JViewport)(e.getNewValue()); 477 478 if (oldViewport != null) { 479 oldViewport.removeChangeListener(viewportChangeListener); 480 } 481 482 if (newViewport != null) { 483 Point p = newViewport.getViewPosition(); 484 if (scrollpane.getComponentOrientation().isLeftToRight()) { 485 p.x = Math.max(p.x, 0); 486 } else { 487 int max = newViewport.getViewSize().width; 488 int extent = newViewport.getExtentSize().width; 489 if (extent > max) { 490 p.x = max - extent; 491 } else { 492 p.x = Math.max(0, Math.min(max - extent, p.x)); 493 } 494 } 495 p.y = Math.max(p.y, 0); 496 newViewport.setViewPosition(p); 497 newViewport.addChangeListener(viewportChangeListener); 498 } 499 } 500 501 502 protected void updateRowHeader(PropertyChangeEvent e) 503 { 504 JViewport newRowHead = (JViewport)(e.getNewValue()); 505 if (newRowHead != null) { 506 JViewport viewport = scrollpane.getViewport(); 507 Point p = newRowHead.getViewPosition(); 508 p.y = (viewport != null) ? viewport.getViewPosition().y : 0; 509 newRowHead.setViewPosition(p); 510 } 511 } 512 513 514 protected void updateColumnHeader(PropertyChangeEvent e) 515 { 516 JViewport newColHead = (JViewport)(e.getNewValue()); 517 if (newColHead != null) { 518 JViewport viewport = scrollpane.getViewport(); 519 Point p = newColHead.getViewPosition(); 520 if (viewport == null) { 521 p.x = 0; 522 } else { 523 if (scrollpane.getComponentOrientation().isLeftToRight()) { 524 p.x = viewport.getViewPosition().x; 525 } else { 526 p.x = Math.max(0, viewport.getViewPosition().x); 527 } 528 } 529 newColHead.setViewPosition(p); 530 scrollpane.add(newColHead, COLUMN_HEADER); 531 } 532 } 533 534 private void updateHorizontalScrollBar(PropertyChangeEvent pce) { 535 updateScrollBar(pce, hsbChangeListener, hsbPropertyChangeListener); 536 } 537 538 private void updateVerticalScrollBar(PropertyChangeEvent pce) { 539 updateScrollBar(pce, vsbChangeListener, vsbPropertyChangeListener); 540 } 541 542 private void updateScrollBar(PropertyChangeEvent pce, ChangeListener cl, 543 PropertyChangeListener pcl) { 544 JScrollBar sb = (JScrollBar)pce.getOldValue(); 545 if (sb != null) { 546 if (cl != null) { 547 sb.getModel().removeChangeListener(cl); 548 } 549 if (pcl != null) { 550 sb.removePropertyChangeListener(pcl); 551 } 552 } 553 sb = (JScrollBar)pce.getNewValue(); 554 if (sb != null) { 555 if (cl != null) { 556 sb.getModel().addChangeListener(cl); 557 } 558 if (pcl != null) { 559 sb.addPropertyChangeListener(pcl); 560 } 561 } 562 } 563 564 public class PropertyChangeHandler implements PropertyChangeListener 565 { 566 567 572 public void propertyChange(PropertyChangeEvent e) 573 { 574 getHandler().propertyChange(e); 575 } 576 } 577 578 579 580 603 protected PropertyChangeListener createPropertyChangeListener() { 604 return getHandler(); 605 } 606 607 608 private static class Actions extends UIAction { 609 private static final String SCROLL_UP = "scrollUp"; 610 private static final String SCROLL_DOWN = "scrollDown"; 611 private static final String SCROLL_HOME = "scrollHome"; 612 private static final String SCROLL_END = "scrollEnd"; 613 private static final String UNIT_SCROLL_UP = "unitScrollUp"; 614 private static final String UNIT_SCROLL_DOWN = "unitScrollDown"; 615 private static final String SCROLL_LEFT = "scrollLeft"; 616 private static final String SCROLL_RIGHT = "scrollRight"; 617 private static final String UNIT_SCROLL_LEFT = "unitScrollLeft"; 618 private static final String UNIT_SCROLL_RIGHT = "unitScrollRight"; 619 620 621 Actions(String key) { 622 super(key); 623 } 624 625 public void actionPerformed(ActionEvent e) { 626 JScrollPane scrollPane = (JScrollPane)e.getSource(); 627 boolean ltr = scrollPane.getComponentOrientation().isLeftToRight(); 628 String key = getName(); 629 630 if (key == SCROLL_UP) { 631 scroll(scrollPane, SwingConstants.VERTICAL, -1, true); 632 } 633 else if (key == SCROLL_DOWN) { 634 scroll(scrollPane, SwingConstants.VERTICAL, 1, true); 635 } 636 else if (key == SCROLL_HOME) { 637 scrollHome(scrollPane); 638 } 639 else if (key == SCROLL_END) { 640 scrollEnd(scrollPane); 641 } 642 else if (key == UNIT_SCROLL_UP) { 643 scroll(scrollPane, SwingConstants.VERTICAL, -1, false); 644 } 645 else if (key == UNIT_SCROLL_DOWN) { 646 scroll(scrollPane, SwingConstants.VERTICAL, 1, false); 647 } 648 else if (key == SCROLL_LEFT) { 649 scroll(scrollPane, SwingConstants.HORIZONTAL, ltr ? -1 : 1, 650 true); 651 } 652 else if (key == SCROLL_RIGHT) { 653 scroll(scrollPane, SwingConstants.HORIZONTAL, ltr ? 1 : -1, 654 true); 655 } 656 else if (key == UNIT_SCROLL_LEFT) { 657 scroll(scrollPane, SwingConstants.HORIZONTAL, ltr ? -1 : 1, 658 false); 659 } 660 else if (key == UNIT_SCROLL_RIGHT) { 661 scroll(scrollPane, SwingConstants.HORIZONTAL, ltr ? 1 : -1, 662 false); 663 } 664 } 665 666 private void scrollEnd(JScrollPane scrollpane) { 667 JViewport vp = scrollpane.getViewport(); 668 Component view; 669 if (vp != null && (view = vp.getView()) != null) { 670 Rectangle visRect = vp.getViewRect(); 671 Rectangle bounds = view.getBounds(); 672 if (scrollpane.getComponentOrientation().isLeftToRight()) { 673 vp.setViewPosition(new Point (bounds.width - visRect.width, 674 bounds.height - visRect.height)); 675 } else { 676 vp.setViewPosition(new Point (0, 677 bounds.height - visRect.height)); 678 } 679 } 680 } 681 682 private void scrollHome(JScrollPane scrollpane) { 683 JViewport vp = scrollpane.getViewport(); 684 Component view; 685 if (vp != null && (view = vp.getView()) != null) { 686 if (scrollpane.getComponentOrientation().isLeftToRight()) { 687 vp.setViewPosition(new Point (0, 0)); 688 } else { 689 Rectangle visRect = vp.getViewRect(); 690 Rectangle bounds = view.getBounds(); 691 vp.setViewPosition(new Point (bounds.width - visRect.width, 0)); 692 } 693 } 694 } 695 696 private void scroll(JScrollPane scrollpane, int orientation, 697 int direction, boolean block) { 698 JViewport vp = scrollpane.getViewport(); 699 Component view; 700 if (vp != null && (view = vp.getView()) != null) { 701 Rectangle visRect = vp.getViewRect(); 702 Dimension vSize = view.getSize(); 703 int amount; 704 705 if (view instanceof Scrollable) { 706 if (block) { 707 amount = ((Scrollable)view).getScrollableBlockIncrement 708 (visRect, orientation, direction); 709 } 710 else { 711 amount = ((Scrollable)view).getScrollableUnitIncrement 712 (visRect, orientation, direction); 713 } 714 } 715 else { 716 if (block) { 717 if (orientation == SwingConstants.VERTICAL) { 718 amount = visRect.height; 719 } 720 else { 721 amount = visRect.width; 722 } 723 } 724 else { 725 amount = 10; 726 } 727 } 728 if (orientation == SwingConstants.VERTICAL) { 729 visRect.y += (amount * direction); 730 if ((visRect.y + visRect.height) > vSize.height) { 731 visRect.y = Math.max(0, vSize.height - visRect.height); 732 } 733 else if (visRect.y < 0) { 734 visRect.y = 0; 735 } 736 } 737 else { 738 if (scrollpane.getComponentOrientation().isLeftToRight()) { 739 visRect.x += (amount * direction); 740 if ((visRect.x + visRect.width) > vSize.width) { 741 visRect.x = Math.max(0, vSize.width - visRect.width); 742 } else if (visRect.x < 0) { 743 visRect.x = 0; 744 } 745 } else { 746 visRect.x -= (amount * direction); 747 if (visRect.width > vSize.width) { 748 visRect.x = vSize.width - visRect.width; 749 } else { 750 visRect.x = Math.max(0, Math.min(vSize.width - visRect.width, visRect.x)); 751 } 752 } 753 } 754 vp.setViewPosition(visRect.getLocation()); 755 } 756 } 757 } 758 759 760 class Handler implements ChangeListener , PropertyChangeListener , MouseWheelListener { 761 public void mouseWheelMoved(MouseWheelEvent e) { 765 if (scrollpane.isWheelScrollingEnabled() && 766 e.getScrollAmount() != 0) { 767 JScrollBar toScroll = scrollpane.getVerticalScrollBar(); 768 int direction = 0; 769 if (toScroll == null || !toScroll.isVisible()) { 771 toScroll = scrollpane.getHorizontalScrollBar(); 772 if (toScroll == null || !toScroll.isVisible()) { 773 return; 774 } 775 } 776 direction = e.getWheelRotation() < 0 ? -1 : 1; 777 if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) { 778 BasicScrollBarUI.scrollByUnits(toScroll, direction, 779 e.getScrollAmount()); 780 } 781 else if (e.getScrollType() == 782 MouseWheelEvent.WHEEL_BLOCK_SCROLL) { 783 BasicScrollBarUI.scrollByBlock(toScroll, direction); 784 } 785 } 786 } 787 788 789 public void stateChanged(ChangeEvent e) { 793 JViewport viewport = scrollpane.getViewport(); 794 795 if (viewport != null) { 796 if (e.getSource() == viewport) { 797 viewportStateChanged(e); 798 } 799 else { 800 JScrollBar hsb = scrollpane.getHorizontalScrollBar(); 801 if (hsb != null && e.getSource() == hsb.getModel()) { 802 hsbStateChanged(viewport, e); 803 } 804 else { 805 JScrollBar vsb = scrollpane.getVerticalScrollBar(); 806 if (vsb != null && e.getSource() == vsb.getModel()) { 807 vsbStateChanged(viewport, e); 808 } 809 } 810 } 811 } 812 } 813 814 private void vsbStateChanged(JViewport viewport, ChangeEvent e) { 815 BoundedRangeModel model = (BoundedRangeModel)(e.getSource()); 816 Point p = viewport.getViewPosition(); 817 p.y = model.getValue(); 818 viewport.setViewPosition(p); 819 } 820 821 private void hsbStateChanged(JViewport viewport, ChangeEvent e) { 822 BoundedRangeModel model = (BoundedRangeModel)(e.getSource()); 823 Point p = viewport.getViewPosition(); 824 int value = model.getValue(); 825 if (scrollpane.getComponentOrientation().isLeftToRight()) { 826 p.x = value; 827 } else { 828 int max = viewport.getViewSize().width; 829 int extent = viewport.getExtentSize().width; 830 int oldX = p.x; 831 832 834 p.x = max - extent - value; 835 836 839 if ((extent == 0) && (value != 0) && (oldX == max)) { 840 setValueCalled = true; 841 } else { 842 846 if ((extent != 0) && (oldX < 0) && (p.x == 0)) { 847 p.x += value; 848 } 849 } 850 } 851 viewport.setViewPosition(p); 852 } 853 854 private void viewportStateChanged(ChangeEvent e) { 855 syncScrollPaneWithViewport(); 856 } 857 858 859 864 public void propertyChange(PropertyChangeEvent e) { 867 if (e.getSource() == scrollpane) { 868 scrollPanePropertyChange(e); 869 } 870 else { 871 sbPropertyChange(e); 872 } 873 } 874 875 private void scrollPanePropertyChange(PropertyChangeEvent e) { 876 String propertyName = e.getPropertyName(); 877 878 if (propertyName == "verticalScrollBarDisplayPolicy") { 879 updateScrollBarDisplayPolicy(e); 880 } 881 else if (propertyName == "horizontalScrollBarDisplayPolicy") { 882 updateScrollBarDisplayPolicy(e); 883 } 884 else if (propertyName == "viewport") { 885 updateViewport(e); 886 } 887 else if (propertyName == "rowHeader") { 888 updateRowHeader(e); 889 } 890 else if (propertyName == "columnHeader") { 891 updateColumnHeader(e); 892 } 893 else if (propertyName == "verticalScrollBar") { 894 updateVerticalScrollBar(e); 895 } 896 else if (propertyName == "horizontalScrollBar") { 897 updateHorizontalScrollBar(e); 898 } 899 else if (propertyName == "componentOrientation") { 900 scrollpane.revalidate(); 901 scrollpane.repaint(); 902 } 903 } 904 905 private void sbPropertyChange(PropertyChangeEvent e) { 907 String propertyName = e.getPropertyName(); 908 Object source = e.getSource(); 909 910 if ("model" == propertyName) { 911 JScrollBar sb = scrollpane.getVerticalScrollBar(); 912 BoundedRangeModel oldModel = (BoundedRangeModel)e. 913 getOldValue(); 914 ChangeListener cl = null; 915 916 if (source == sb) { 917 cl = vsbChangeListener; 918 } 919 else if (source == scrollpane.getHorizontalScrollBar()) { 920 sb = scrollpane.getHorizontalScrollBar(); 921 cl = hsbChangeListener; 922 } 923 if (cl != null) { 924 if (oldModel != null) { 925 oldModel.removeChangeListener(cl); 926 } 927 if (sb.getModel() != null) { 928 sb.getModel().addChangeListener(cl); 929 } 930 } 931 } 932 else if ("componentOrientation" == propertyName) { 933 if (source == scrollpane.getHorizontalScrollBar()) { 934 JScrollBar hsb = scrollpane.getHorizontalScrollBar(); 935 JViewport viewport = scrollpane.getViewport(); 936 Point p = viewport.getViewPosition(); 937 if (scrollpane.getComponentOrientation().isLeftToRight()) { 938 p.x = hsb.getValue(); 939 } else { 940 p.x = viewport.getViewSize().width - viewport.getExtentSize().width - hsb.getValue(); 941 } 942 viewport.setViewPosition(p); 943 } 944 } 945 } 946 } 947 } 948 | Popular Tags |