| 1 7 8 package javax.swing.plaf.basic; 9 10 import java.awt.*; 11 import java.awt.event.*; 12 import java.awt.peer.LightweightPeer; 13 14 import javax.swing.*; 15 import javax.swing.border.*; 16 import javax.swing.plaf.*; 17 import javax.swing.event.*; 18 19 import java.beans.*; 20 import java.io.Serializable ; 21 22 import sun.swing.DefaultLookup; 23 import sun.swing.UIAction; 24 25 32 public class BasicInternalFrameUI extends InternalFrameUI 33 { 34 35 protected JInternalFrame frame; 36 37 private Handler handler; 38 protected MouseInputAdapter borderListener; 39 protected PropertyChangeListener propertyChangeListener; 40 protected LayoutManager internalFrameLayout; 41 protected ComponentListener componentListener; 42 protected MouseInputListener glassPaneDispatcher; 43 private InternalFrameListener internalFrameListener; 44 45 protected JComponent northPane; 46 protected JComponent southPane; 47 protected JComponent westPane; 48 protected JComponent eastPane; 49 50 protected BasicInternalFrameTitlePane titlePane; 52 private static DesktopManager sharedDesktopManager; 53 private boolean componentListenerAdded = false; 54 55 private Rectangle parentBounds; 56 57 private boolean dragging = false; 58 private boolean resizing = false; 59 60 68 @Deprecated  69 protected KeyStroke openMenuKey; 70 71 private boolean keyBindingRegistered = false; 72 private boolean keyBindingActive = false; 73 74 public static ComponentUI createUI(JComponent b) { 78 return new BasicInternalFrameUI ((JInternalFrame)b); 79 } 80 81 public BasicInternalFrameUI(JInternalFrame b) { 82 } 83 84 public void installUI(JComponent c) { 85 86 frame = (JInternalFrame)c; 87 88 installDefaults(); 89 installListeners(); 90 installComponents(); 91 installKeyboardActions(); 92 93 LookAndFeel.installProperty(frame, "opaque", Boolean.TRUE); 94 } 95 96 public void uninstallUI(JComponent c) { 97 if(c != frame) 98 throw new IllegalComponentStateException( 99 this + " was asked to deinstall() " 100 + c + " when it only knows about " 101 + frame + "."); 102 103 uninstallKeyboardActions(); 104 uninstallComponents(); 105 uninstallListeners(); 106 uninstallDefaults(); 107 frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 108 handler = null; 109 frame = null; 110 } 111 112 protected void installDefaults(){ 113 Icon frameIcon = frame.getFrameIcon(); 114 if (frameIcon == null || frameIcon instanceof UIResource) { 115 frame.setFrameIcon(UIManager.getIcon("InternalFrame.icon")); 116 } 117 118 JComponent contentPane = (JComponent) frame.getContentPane(); 121 if (contentPane != null) { 122 Color bg = contentPane.getBackground(); 123 if (bg instanceof UIResource) 124 contentPane.setBackground(null); 125 } 126 frame.setLayout(internalFrameLayout = createLayoutManager()); 127 frame.setBackground(UIManager.getLookAndFeelDefaults().getColor("control")); 128 129 LookAndFeel.installBorder(frame, "InternalFrame.border"); 130 131 } 132 protected void installKeyboardActions(){ 133 createInternalFrameListener(); 134 if (internalFrameListener != null) { 135 frame.addInternalFrameListener(internalFrameListener); 136 } 137 138 LazyActionMap.installLazyActionMap(frame, BasicInternalFrameUI .class, 139 "InternalFrame.actionMap"); 140 } 141 142 static void loadActionMap(LazyActionMap map) { 143 map.put(new UIAction("showSystemMenu") { 144 public void actionPerformed(ActionEvent evt) { 145 JInternalFrame iFrame = (JInternalFrame)evt.getSource(); 146 if (iFrame.getUI() instanceof BasicInternalFrameUI ) { 147 JComponent comp = ((BasicInternalFrameUI ) 148 iFrame.getUI()).getNorthPane(); 149 if (comp instanceof BasicInternalFrameTitlePane ) { 150 ((BasicInternalFrameTitlePane )comp). 151 showSystemMenu(); 152 } 153 } 154 } 155 156 public boolean isEnabled(Object sender){ 157 if (sender instanceof JInternalFrame) { 158 JInternalFrame iFrame = (JInternalFrame)sender; 159 if (iFrame.getUI() instanceof BasicInternalFrameUI ) { 160 return ((BasicInternalFrameUI )iFrame.getUI()). 161 isKeyBindingActive(); 162 } 163 } 164 return false; 165 } 166 }); 167 168 BasicLookAndFeel.installAudioActionMap(map); 170 } 171 172 protected void installComponents(){ 173 setNorthPane(createNorthPane(frame)); 174 setSouthPane(createSouthPane(frame)); 175 setEastPane(createEastPane(frame)); 176 setWestPane(createWestPane(frame)); 177 } 178 179 182 protected void installListeners() { 183 borderListener = createBorderListener(frame); 184 propertyChangeListener = createPropertyChangeListener(); 185 frame.addPropertyChangeListener(propertyChangeListener); 186 installMouseHandlers(frame); 187 glassPaneDispatcher = createGlassPaneDispatcher(); 188 frame.getGlassPane().addMouseListener(glassPaneDispatcher); 189 frame.getGlassPane().addMouseMotionListener(glassPaneDispatcher); 190 componentListener = createComponentListener(); 191 if (frame.getParent() != null) { 192 parentBounds = frame.getParent().getBounds(); 193 } 194 if ((frame.getParent() != null) && !componentListenerAdded) { 195 frame.getParent().addComponentListener(componentListener); 196 componentListenerAdded = true; 197 } 198 } 199 200 private WindowFocusListener getWindowFocusListener(){ 201 return getHandler(); 202 } 203 204 private void cancelResize() { 205 if (resizing) { 206 if (borderListener instanceof BorderListener) { 207 ((BorderListener)borderListener).finishMouseReleased(); 208 } 209 } 210 } 211 212 private Handler getHandler() { 213 if (handler == null) { 214 handler = new Handler(); 215 } 216 return handler; 217 } 218 219 InputMap getInputMap(int condition) { 220 if (condition == JComponent.WHEN_IN_FOCUSED_WINDOW) { 221 return createInputMap(condition); 222 } 223 return null; 224 } 225 226 InputMap createInputMap(int condition) { 227 if (condition == JComponent.WHEN_IN_FOCUSED_WINDOW) { 228 Object [] bindings = (Object [])DefaultLookup.get( 229 frame, this, "InternalFrame.windowBindings"); 230 231 if (bindings != null) { 232 return LookAndFeel.makeComponentInputMap(frame, bindings); 233 } 234 } 235 return null; 236 } 237 238 protected void uninstallDefaults() { 239 Icon frameIcon = frame.getFrameIcon(); 240 if (frameIcon instanceof UIResource) { 241 frame.setFrameIcon(null); 242 } 243 internalFrameLayout = null; 244 frame.setLayout(null); 245 LookAndFeel.uninstallBorder(frame); 246 } 247 248 protected void uninstallComponents(){ 249 setNorthPane(null); 250 setSouthPane(null); 251 setEastPane(null); 252 setWestPane(null); 253 if(titlePane != null) { 254 titlePane.uninstallDefaults(); 255 } 256 titlePane = null; 257 } 258 259 262 protected void uninstallListeners() { 263 if ((frame.getParent() != null) && componentListenerAdded) { 264 frame.getParent().removeComponentListener(componentListener); 265 componentListenerAdded = false; 266 } 267 componentListener = null; 268 frame.getGlassPane().removeMouseListener(glassPaneDispatcher); 269 frame.getGlassPane().removeMouseMotionListener(glassPaneDispatcher); 270 glassPaneDispatcher = null; 271 deinstallMouseHandlers(frame); 272 frame.removePropertyChangeListener(propertyChangeListener); 273 propertyChangeListener = null; 274 borderListener = null; 275 } 276 277 protected void uninstallKeyboardActions(){ 278 if (internalFrameListener != null) { 279 frame.removeInternalFrameListener(internalFrameListener); 280 } 281 internalFrameListener = null; 282 283 SwingUtilities.replaceUIInputMap(frame, JComponent. 284 WHEN_IN_FOCUSED_WINDOW, null); 285 SwingUtilities.replaceUIActionMap(frame, null); 286 287 } 288 289 protected LayoutManager createLayoutManager(){ 290 return getHandler(); 291 } 292 293 protected PropertyChangeListener createPropertyChangeListener(){ 294 return getHandler(); 295 } 296 297 298 299 public Dimension getPreferredSize(JComponent x) { 300 if((JComponent)frame == x) 301 return frame.getLayout().preferredLayoutSize(x); 302 return new Dimension(100, 100); 303 } 304 305 public Dimension getMinimumSize(JComponent x) { 306 if((JComponent)frame == x) { 307 return frame.getLayout().minimumLayoutSize(x); 308 } 309 return new Dimension(0, 0); 310 } 311 312 public Dimension getMaximumSize(JComponent x) { 313 return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); 314 } 315 316 317 318 323 protected void replacePane(JComponent currentPane, JComponent newPane) { 324 if(currentPane != null) { 325 deinstallMouseHandlers(currentPane); 326 frame.remove(currentPane); 327 } 328 if(newPane != null) { 329 frame.add(newPane); 330 installMouseHandlers(newPane); 331 } 332 } 333 334 protected void deinstallMouseHandlers(JComponent c) { 335 c.removeMouseListener(borderListener); 336 c.removeMouseMotionListener(borderListener); 337 } 338 339 protected void installMouseHandlers(JComponent c) { 340 c.addMouseListener(borderListener); 341 c.addMouseMotionListener(borderListener); 342 } 343 344 protected JComponent createNorthPane(JInternalFrame w) { 345 titlePane = new BasicInternalFrameTitlePane (w); 346 return titlePane; 347 } 348 349 350 protected JComponent createSouthPane(JInternalFrame w) { 351 return null; 352 } 353 354 protected JComponent createWestPane(JInternalFrame w) { 355 return null; 356 } 357 358 protected JComponent createEastPane(JInternalFrame w) { 359 return null; 360 } 361 362 363 protected MouseInputAdapter createBorderListener(JInternalFrame w) { 364 return new BorderListener(); 365 } 366 367 protected void createInternalFrameListener(){ 368 internalFrameListener = getHandler(); 369 } 370 371 protected final boolean isKeyBindingRegistered(){ 372 return keyBindingRegistered; 373 } 374 375 protected final void setKeyBindingRegistered(boolean b){ 376 keyBindingRegistered = b; 377 } 378 379 public final boolean isKeyBindingActive(){ 380 return keyBindingActive; 381 } 382 383 protected final void setKeyBindingActive(boolean b){ 384 keyBindingActive = b; 385 } 386 387 388 protected void setupMenuOpenKey(){ 389 InputMap map = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); 394 SwingUtilities.replaceUIInputMap(frame, 395 JComponent.WHEN_IN_FOCUSED_WINDOW, map); 396 } 399 400 protected void setupMenuCloseKey(){ 401 } 402 403 public JComponent getNorthPane() { 404 return northPane; 405 } 406 407 public void setNorthPane(JComponent c) { 408 if (northPane != null && 409 northPane instanceof BasicInternalFrameTitlePane ) { 410 ((BasicInternalFrameTitlePane )northPane).uninstallListeners(); 411 } 412 replacePane(northPane, c); 413 northPane = c; 414 } 415 416 public JComponent getSouthPane() { 417 return southPane; 418 } 419 420 public void setSouthPane(JComponent c) { 421 southPane = c; 422 } 423 424 public JComponent getWestPane() { 425 return westPane; 426 } 427 428 public void setWestPane(JComponent c) { 429 westPane = c; 430 } 431 432 public JComponent getEastPane() { 433 return eastPane; 434 } 435 436 public void setEastPane(JComponent c) { 437 eastPane = c; 438 } 439 440 public class InternalFramePropertyChangeListener implements 441 PropertyChangeListener { 442 450 public void propertyChange(PropertyChangeEvent evt) { 451 getHandler().propertyChange(evt); 452 } 453 } 454 455 public class InternalFrameLayout implements LayoutManager { 456 public void addLayoutComponent(String name, Component c) { 461 getHandler().addLayoutComponent(name, c); 462 } 463 464 public void removeLayoutComponent(Component c) { 465 getHandler().removeLayoutComponent(c); 466 } 467 468 public Dimension preferredLayoutSize(Container c) { 469 return getHandler().preferredLayoutSize(c); 470 } 471 472 public Dimension minimumLayoutSize(Container c) { 473 return getHandler().minimumLayoutSize(c); 474 } 475 476 public void layoutContainer(Container c) { 477 getHandler().layoutContainer(c); 478 } 479 } 480 481 487 protected DesktopManager getDesktopManager() { 488 if(frame.getDesktopPane() != null 489 && frame.getDesktopPane().getDesktopManager() != null) 490 return frame.getDesktopPane().getDesktopManager(); 491 if(sharedDesktopManager == null) 492 sharedDesktopManager = createDesktopManager(); 493 return sharedDesktopManager; 494 } 495 496 protected DesktopManager createDesktopManager(){ 497 return new DefaultDesktopManager(); 498 } 499 500 505 protected void closeFrame(JInternalFrame f) { 506 BasicLookAndFeel.playSound(frame,"InternalFrame.closeSound"); 508 getDesktopManager().closeFrame(f); 510 } 511 512 517 protected void maximizeFrame(JInternalFrame f) { 518 BasicLookAndFeel.playSound(frame,"InternalFrame.maximizeSound"); 520 getDesktopManager().maximizeFrame(f); 522 } 523 524 529 protected void minimizeFrame(JInternalFrame f) { 530 if ( ! f.isIcon() ) { 532 BasicLookAndFeel.playSound(frame,"InternalFrame.restoreDownSound"); 535 } 536 getDesktopManager().minimizeFrame(f); 538 } 539 540 545 protected void iconifyFrame(JInternalFrame f) { 546 BasicLookAndFeel.playSound(frame, "InternalFrame.minimizeSound"); 548 getDesktopManager().iconifyFrame(f); 550 } 551 552 557 protected void deiconifyFrame(JInternalFrame f) { 558 if ( ! f.isMaximum() ) { 560 BasicLookAndFeel.playSound(frame, "InternalFrame.restoreUpSound"); 563 } 564 getDesktopManager().deiconifyFrame(f); 566 } 567 568 571 protected void activateFrame(JInternalFrame f) { 572 getDesktopManager().activateFrame(f); 573 } 574 577 protected void deactivateFrame(JInternalFrame f) { 578 getDesktopManager().deactivateFrame(f); 579 } 580 581 587 protected class BorderListener extends MouseInputAdapter implements SwingConstants 588 { 589 int _x, _y; 591 int __x, __y; 593 Rectangle startingBounds; 594 int resizeDir; 595 596 597 protected final int RESIZE_NONE = 0; 598 private boolean discardRelease = false; 599 600 int resizeCornerSize = 16; 601 602 public void mouseClicked(MouseEvent e) { 603 if(e.getClickCount() > 1 && e.getSource() == getNorthPane()) { 604 if(frame.isIconifiable() && frame.isIcon()) { 605 try { frame.setIcon(false); } catch (PropertyVetoException e2) { } 606 } else if(frame.isMaximizable()) { 607 if(!frame.isMaximum()) 608 try { frame.setMaximum(true); } catch (PropertyVetoException e2) { } 609 else 610 try { frame.setMaximum(false); } catch (PropertyVetoException e3) { } 611 } 612 } 613 } 614 615 void finishMouseReleased() { 616 if (discardRelease) { 617 discardRelease = false; 618 return; 619 } 620 if (resizeDir == RESIZE_NONE) { 621 getDesktopManager().endDraggingFrame(frame); 622 dragging = false; 623 } else { 624 Window windowAncestor = 625 SwingUtilities.getWindowAncestor(frame); 626 if (windowAncestor != null) { 627 windowAncestor.removeWindowFocusListener( 628 getWindowFocusListener()); 629 } 630 Container c = frame.getTopLevelAncestor(); 631 if (c instanceof JFrame) { 632 ((JFrame)frame.getTopLevelAncestor()).getGlassPane().setCursor( 633 Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 634 635 ((JFrame)frame.getTopLevelAncestor()).getGlassPane( 636 ).setVisible(false); 637 } else if (c instanceof JApplet) { 638 ((JApplet)c).getGlassPane().setCursor( 639 Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 640 ((JApplet)c).getGlassPane().setVisible(false); 641 } else if (c instanceof JWindow) { 642 ((JWindow)c).getGlassPane().setCursor( 643 Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 644 ((JWindow)c).getGlassPane().setVisible(false); 645 } else if (c instanceof JDialog) { 646 ((JDialog)c).getGlassPane().setCursor( 647 Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 648 ((JDialog)c).getGlassPane().setVisible(false); 649 } 650 getDesktopManager().endResizingFrame(frame); 651 resizing = false; 652 } 653 _x = 0; 654 _y = 0; 655 __x = 0; 656 __y = 0; 657 startingBounds = null; 658 resizeDir = RESIZE_NONE; 659 discardRelease = true; 660 } 661 662 public void mouseReleased(MouseEvent e) { 663 finishMouseReleased(); 664 } 665 666 public void mousePressed(MouseEvent e) { 667 Point p = SwingUtilities.convertPoint((Component)e.getSource(), 668 e.getX(), e.getY(), null); 669 __x = e.getX(); 670 __y = e.getY(); 671 _x = p.x; 672 _y = p.y; 673 startingBounds = frame.getBounds(); 674 resizeDir = RESIZE_NONE; 675 discardRelease = false; 676 677 if(!frame.isSelected()) { 678 try { frame.setSelected(true); } 679 catch (PropertyVetoException e1) { } 680 } 681 682 Insets i = frame.getInsets(); 683 684 Point ep = new Point(__x, __y); 685 if (e.getSource() == getNorthPane()) { 686 Point np = getNorthPane().getLocation(); 687 ep.x += np.x; 688 ep.y += np.y; 689 } 690 691 if (e.getSource() == getNorthPane()) { 692 if (ep.x > i.left && ep.y > i.top && ep.x < frame.getWidth() - i.right) { 693 getDesktopManager().beginDraggingFrame(frame); 694 dragging = true; 695 return; 696 } 697 } 698 if (!frame.isResizable()) { 699 return; 700 } 701 702 if (e.getSource() == frame || e.getSource() == getNorthPane()) { 703 if (ep.x <= i.left) { 704 if (ep.y < resizeCornerSize + i.top) { 705 resizeDir = NORTH_WEST; 706 } else if (ep.y > frame.getHeight() 707 - resizeCornerSize - i.bottom) { 708 resizeDir = SOUTH_WEST; 709 } else { 710 resizeDir = WEST; 711 } 712 } else if (ep.x >= frame.getWidth() - i.right) { 713 if (ep.y < resizeCornerSize + i.top) { 714 resizeDir = NORTH_EAST; 715 } else if (ep.y > frame.getHeight() 716 - resizeCornerSize - i.bottom) { 717 resizeDir = SOUTH_EAST; 718 } else { 719 resizeDir = EAST; 720 } 721 } else if (ep.y <= i.top) { 722 if (ep.x < resizeCornerSize + i.left) { 723 resizeDir = NORTH_WEST; 724 } else if (ep.x > frame.getWidth() 725 - resizeCornerSize - i.right) { 726 resizeDir = NORTH_EAST; 727 } else { 728 resizeDir = NORTH; 729 } 730 } else if (ep.y >= frame.getHeight() - i.bottom) { 731 if (ep.x < resizeCornerSize + i.left) { 732 resizeDir = SOUTH_WEST; 733 } else if (ep.x > frame.getWidth() 734 - resizeCornerSize - i.right) { 735 resizeDir = SOUTH_EAST; 736 } else { 737 resizeDir = SOUTH; 738 } 739 } else { 740 742 discardRelease = true; 743 return; 744 } 745 Cursor s = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); 746 switch (resizeDir) { 747 case SOUTH: 748 s = Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR); 749 break; 750 case NORTH: 751 s = Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR); 752 break; 753 case WEST: 754 s = Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR); 755 break; 756 case EAST: 757 s = Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR); 758 break; 759 case SOUTH_EAST: 760 s = Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR); 761 break; 762 case SOUTH_WEST: 763 s = Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR); 764 break; 765 case NORTH_WEST: 766 s = Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR); 767 break; 768 case NORTH_EAST: 769 s = Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR); 770 break; 771 } 772 Container c = frame.getTopLevelAncestor(); 773 if (c instanceof JFrame){ 774 ((JFrame)c).getGlassPane().setVisible(true); 775 ((JFrame)c).getGlassPane().setCursor(s); 776 } else if (c instanceof JApplet){ 777 ((JApplet)c).getGlassPane().setVisible(true); 778 ((JApplet)c).getGlassPane().setCursor(s); 779 } else if (c instanceof JWindow){ 780 ((JWindow)c).getGlassPane().setVisible(true); 781 ((JWindow)c).getGlassPane().setCursor(s); 782 } else if (c instanceof JDialog){ 783 ((JDialog)c).getGlassPane().setVisible(true); 784 ((JDialog)c).getGlassPane().setCursor(s); 785 } 786 getDesktopManager().beginResizingFrame(frame, resizeDir); 787 resizing = true; 788 Window windowAncestor = SwingUtilities.getWindowAncestor(frame); 789 if (windowAncestor != null) { 790 windowAncestor.addWindowFocusListener( 791 getWindowFocusListener()); 792 } 793 return; 794 } 795 } 796 797 public void mouseDragged(MouseEvent e) { 798 799 if ( startingBounds == null ) { 800 return; 802 } 803 804 Point p = SwingUtilities.convertPoint((Component)e.getSource(), 805 e.getX(), e.getY(), null); 806 int deltaX = _x - p.x; 807 int deltaY = _y - p.y; 808 Dimension min = frame.getMinimumSize(); 809 Dimension max = frame.getMaximumSize(); 810 int newX, newY, newW, newH; 811 Insets i = frame.getInsets(); 812 813 if (dragging) { 815 if (frame.isMaximum() || ((e.getModifiers() & 816 InputEvent.BUTTON1_MASK) != 817 InputEvent.BUTTON1_MASK)) { 818 return; 821 } 822 int pWidth, pHeight; 823 Dimension s = frame.getParent().getSize(); 824 pWidth = s.width; 825 pHeight = s.height; 826 827 828 newX = startingBounds.x - deltaX; 829 newY = startingBounds.y - deltaY; 830 831 if(newX + i.left <= -__x) 833 newX = -__x - i.left + 1; 834 if(newY + i.top <= -__y) 835 newY = -__y - i.top + 1; 836 if(newX + __x + i.right >= pWidth) 837 newX = pWidth - __x - i.right - 1; 838 if(newY + __y + i.bottom >= pHeight) 839 newY = pHeight - __y - i.bottom - 1; 840 841 getDesktopManager().dragFrame(frame, newX, newY); 842 return; 843 } 844 845 if(!frame.isResizable()) { 846 return; 847 } 848 849 newX = frame.getX(); 850 newY = frame.getY(); 851 newW = frame.getWidth(); 852 newH = frame.getHeight(); 853 854 parentBounds = frame.getParent().getBounds(); 855 856 switch(resizeDir) { 857 case RESIZE_NONE: 858 return; 859 case NORTH: 860 if(startingBounds.height + deltaY < min.height) 861 deltaY = -(startingBounds.height - min.height); 862 else if(startingBounds.height + deltaY > max.height) 863 deltaY = max.height - startingBounds.height; 864 if (startingBounds.y - deltaY < 0) {deltaY = startingBounds.y;} 865 866 newX = startingBounds.x; 867 newY = startingBounds.y - deltaY; 868 newW = startingBounds.width; 869 newH = startingBounds.height + deltaY; 870 break; 871 case NORTH_EAST: 872 if(startingBounds.height + deltaY < min.height) 873 deltaY = -(startingBounds.height - min.height); 874 else if(startingBounds.height + deltaY > max.height) 875 deltaY = max.height - startingBounds.height; 876 if (startingBounds.y - deltaY < 0) {deltaY = startingBounds.y;} 877 878 if(startingBounds.width - deltaX < min.width) 879 deltaX = startingBounds.width - min.width; 880 else if(startingBounds.width - deltaX > max.width) 881 deltaX = -(max.width - startingBounds.width); 882 if (startingBounds.x + startingBounds.width - deltaX > 883 parentBounds.width) { 884 deltaX = startingBounds.x + startingBounds.width - 885 parentBounds.width; 886 } 887 888 newX = startingBounds.x; 889 newY = startingBounds.y - deltaY; 890 newW = startingBounds.width - deltaX; 891 newH = startingBounds.height + deltaY; 892 break; 893 case EAST: 894 if(startingBounds.width - deltaX < min.width) 895 deltaX = startingBounds.width - min.width; 896 else if(startingBounds.width - deltaX > max.width) 897 deltaX = -(max.width - startingBounds.width); 898 if (startingBounds.x + startingBounds.width - deltaX > 899 parentBounds.width) { 900 deltaX = startingBounds.x + startingBounds.width - 901 parentBounds.width; 902 } 903 904 newW = startingBounds.width - deltaX; 905 newH = startingBounds.height; 906 break; 907 case SOUTH_EAST: 908 if(startingBounds.width - deltaX < min.width) 909 deltaX = startingBounds.width - min.width; 910 else if(startingBounds.width - deltaX > max.width) 911 deltaX = -(max.width - startingBounds.width); 912 if (startingBounds.x + startingBounds.width - deltaX > 913 parentBounds.width) { 914 deltaX = startingBounds.x + startingBounds.width - 915 parentBounds.width; 916 } 917 918 if(startingBounds.height - deltaY < min.height) 919 deltaY = startingBounds.height - min.height; 920 else if(startingBounds.height - deltaY > max.height) 921 deltaY = -(max.height - startingBounds.height); 922 if (startingBounds.y + startingBounds.height - deltaY > 923 parentBounds.height) { 924 deltaY = startingBounds.y + startingBounds.height - 925 parentBounds.height ; 926 } 927 928 newW = startingBounds.width - deltaX; 929 newH = startingBounds.height - deltaY; 930 break; 931 case SOUTH: 932 if(startingBounds.height - deltaY < min.height) 933 deltaY = startingBounds.height - min.height; 934 else if(startingBounds.height - deltaY > max.height) 935 deltaY = -(max.height - startingBounds.height); 936 |