Source for javax.swing.plaf.basic.BasicInternalFrameUI

   1: /* BasicInternalFrameUI.java --
   2:    Copyright (C) 2004, 2005 Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: 
  39: package javax.swing.plaf.basic;
  40: 
  41: import java.awt.AWTEvent;
  42: import java.awt.Color;
  43: import java.awt.Component;
  44: import java.awt.Container;
  45: import java.awt.Dimension;
  46: import java.awt.Graphics;
  47: import java.awt.Insets;
  48: import java.awt.LayoutManager;
  49: import java.awt.Point;
  50: import java.awt.Rectangle;
  51: import java.awt.event.ComponentEvent;
  52: import java.awt.event.ComponentListener;
  53: import java.awt.event.MouseEvent;
  54: import java.beans.PropertyChangeEvent;
  55: import java.beans.PropertyChangeListener;
  56: import java.beans.PropertyVetoException;
  57: import java.beans.VetoableChangeListener;
  58: 
  59: import javax.swing.BorderFactory;
  60: import javax.swing.DefaultDesktopManager;
  61: import javax.swing.DesktopManager;
  62: import javax.swing.JComponent;
  63: import javax.swing.JDesktopPane;
  64: import javax.swing.JInternalFrame;
  65: import javax.swing.KeyStroke;
  66: import javax.swing.SwingConstants;
  67: import javax.swing.SwingUtilities;
  68: import javax.swing.UIDefaults;
  69: import javax.swing.UIManager;
  70: import javax.swing.border.AbstractBorder;
  71: import javax.swing.border.BevelBorder;
  72: import javax.swing.border.Border;
  73: import javax.swing.event.InternalFrameEvent;
  74: import javax.swing.event.InternalFrameListener;
  75: import javax.swing.event.MouseInputAdapter;
  76: import javax.swing.event.MouseInputListener;
  77: import javax.swing.plaf.ComponentUI;
  78: import javax.swing.plaf.InternalFrameUI;
  79: import javax.swing.plaf.UIResource;
  80: 
  81: /**
  82:  * This is the UI delegate for the Basic look and feel for JInternalFrames.
  83:  */
  84: public class BasicInternalFrameUI extends InternalFrameUI
  85: {
  86:   /**
  87:    * This is a helper class that listens to the JInternalFrame for
  88:    * InternalFrameEvents.
  89:    */
  90:   protected class BasicInternalFrameListener implements InternalFrameListener
  91:   {
  92:     /**
  93:      * This method is called when the JInternalFrame is activated.
  94:      *
  95:      * @param e The InternalFrameEvent.
  96:      */
  97:     public void internalFrameActivated(InternalFrameEvent e)
  98:     {
  99:       // FIXME: Implement.
 100:     }
 101: 
 102:     /**
 103:      * This method is called when the JInternalFrame is closed.
 104:      *
 105:      * @param e The InternalFrameEvent.
 106:      */
 107:     public void internalFrameClosed(InternalFrameEvent e)
 108:     {
 109:       // FIXME: Implement.
 110:     }
 111: 
 112:     /**
 113:      * This method is called when the JInternalFrame is closing.
 114:      *
 115:      * @param e The InternalFrameEvent.
 116:      */
 117:     public void internalFrameClosing(InternalFrameEvent e)
 118:     {
 119:       // FIXME: Implement.
 120:     }
 121: 
 122:     /**
 123:      * This method is called when the JInternalFrame is deactivated.
 124:      *
 125:      * @param e The InternalFrameEvent.
 126:      */
 127:     public void internalFrameDeactivated(InternalFrameEvent e)
 128:     {
 129:       // FIXME: Implement.
 130:     }
 131: 
 132:     /**
 133:      * This method is called when the JInternalFrame is  deiconified.
 134:      *
 135:      * @param e The InternalFrameEvent.
 136:      */
 137:     public void internalFrameDeiconified(InternalFrameEvent e)
 138:     {
 139:       // FIXME: Implement.
 140:     }
 141: 
 142:     /**
 143:      * This method is called when the JInternalFrame is  iconified.
 144:      *
 145:      * @param e The InternalFrameEvent.
 146:      */
 147:     public void internalFrameIconified(InternalFrameEvent e)
 148:     {
 149:       // FIXME: Implement.
 150:     }
 151: 
 152:     /**
 153:      * This method is called when the JInternalFrame is opened.
 154:      *
 155:      * @param e The InternalFrameEvent.
 156:      */
 157:     public void internalFrameOpened(InternalFrameEvent e)
 158:     {
 159:       // FIXME: Implement.
 160:     }
 161:   }
 162: 
 163:   /**
 164:    * This helper class listens to the edges of the JInternalFrame and the
 165:    * TitlePane for mouse events. It is responsible for dragging  and resizing
 166:    * the JInternalFrame in response to the MouseEvents.
 167:    */
 168:   protected class BorderListener extends MouseInputAdapter
 169:     implements SwingConstants
 170:   {
 171:     /** FIXME: Use for something. */
 172:     protected final int RESIZE_NONE = 0;
 173: 
 174:     /** The x offset from the top left corner of the JInternalFrame. */
 175:     private transient int xOffset = 0;
 176: 
 177:     /** The y offset from the top left corner of the JInternalFrame. */
 178:     private transient int yOffset = 0;
 179: 
 180:     /** The direction that the resize is occuring in. */
 181:     private transient int direction = -1;
 182: 
 183:     /** Cache rectangle that can be reused. */
 184:     private transient Rectangle cacheRect = new Rectangle();
 185: 
 186:     /**
 187:      * This method is called when the mouse is clicked.
 188:      *
 189:      * @param e The MouseEvent.
 190:      */
 191:     public void mouseClicked(MouseEvent e)
 192:     {
 193:       // There is nothing to do when the mouse is clicked
 194:       // on the border.
 195:     }
 196: 
 197:     /**
 198:      * This method is called when the mouse is dragged. This method is
 199:      * responsible for resizing or dragging the JInternalFrame.
 200:      *
 201:      * @param e The MouseEvent.
 202:      */
 203:     public void mouseDragged(MouseEvent e)
 204:     {
 205:       // If the frame is maximized, there is nothing that 
 206:       // can be dragged around.
 207:       if (frame.isMaximum())
 208:     return;
 209:       DesktopManager dm = getDesktopManager();
 210:       Rectangle b = frame.getBounds();
 211:       Dimension min = frame.getMinimumSize();
 212:       if (min == null)
 213:     min = new Dimension(0, 0);
 214:       Insets insets = frame.getInsets();
 215:       int x = e.getX();
 216:       int y = e.getY();
 217:       if (e.getSource() == frame && frame.isResizable())
 218:         {
 219:       switch (direction)
 220:         {
 221:         case NORTH:
 222:           cacheRect.setBounds(b.x,
 223:                               Math.min(b.y + y, b.y + b.height
 224:                                        - min.height), b.width, b.height
 225:                               - y);
 226:           break;
 227:         case NORTH_EAST:
 228:           cacheRect.setBounds(b.x,
 229:                               Math.min(b.y + y, b.y + b.height
 230:                                        - min.height), x, b.height - y);
 231:           break;
 232:         case EAST:
 233:           cacheRect.setBounds(b.x, b.y, x, b.height);
 234:           break;
 235:         case SOUTH_EAST:
 236:           cacheRect.setBounds(b.x, b.y, x, y);
 237:           break;
 238:         case SOUTH:
 239:           cacheRect.setBounds(b.x, b.y, b.width, y);
 240:           break;
 241:         case SOUTH_WEST:
 242:           cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width),
 243:                               b.y, b.width - x, y);
 244:           break;
 245:         case WEST:
 246:           cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width),
 247:                               b.y, b.width - x, b.height);
 248:           break;
 249:         case NORTH_WEST:
 250:           cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width),
 251:                               Math.min(b.y + y, b.y + b.height
 252:                                        - min.height), b.width - x,
 253:                               b.height - y);
 254:           break;
 255:         }
 256:       dm.resizeFrame(frame, cacheRect.x, cacheRect.y,
 257:                      Math.max(min.width, cacheRect.width),
 258:                      Math.max(min.height, cacheRect.height));
 259:         }
 260:       else if (e.getSource() == titlePane)
 261:         {
 262:       Rectangle fBounds = frame.getBounds();
 263: 
 264:       dm.dragFrame(frame, e.getX() - xOffset + b.x,
 265:                    e.getY() - yOffset + b.y);
 266:         }
 267:     }
 268: 
 269:     /**
 270:      * This method is called when the mouse exits the JInternalFrame.
 271:      *
 272:      * @param e The MouseEvent.
 273:      */
 274:     public void mouseExited(MouseEvent e)
 275:     {
 276:       // There is nothing to do when the mouse exits 
 277:       // the border area.
 278:     }
 279: 
 280:     /**
 281:      * This method is called when the mouse is moved inside the
 282:      * JInternalFrame.
 283:      *
 284:      * @param e The MouseEvent.
 285:      */
 286:     public void mouseMoved(MouseEvent e)
 287:     {
 288:       // There is nothing to do when the mouse moves
 289:       // over the border area.
 290:     }
 291: 
 292:     /**
 293:      * This method is called when the mouse is pressed.
 294:      *
 295:      * @param e The MouseEvent.
 296:      */
 297:     public void mousePressed(MouseEvent e)
 298:     {
 299:       activateFrame(frame);
 300:       DesktopManager dm = getDesktopManager();
 301:       int x = e.getX();
 302:       int y = e.getY();
 303:       Insets insets = frame.getInsets();
 304: 
 305:       if (e.getSource() == frame && frame.isResizable())
 306:         {
 307:       direction = sectionOfClick(x, y);
 308:       dm.beginResizingFrame(frame, direction);
 309:         }
 310:       else if (e.getSource() == titlePane)
 311:         {
 312:       Rectangle tBounds = titlePane.getBounds();
 313: 
 314:       xOffset = e.getX() - tBounds.x + insets.left;
 315:       yOffset = e.getY() - tBounds.y + insets.top;
 316: 
 317:       dm.beginDraggingFrame(frame);
 318:         }
 319:     }
 320: 
 321:     /**
 322:      * This method is called when the mouse is released.
 323:      *
 324:      * @param e The MouseEvent.
 325:      */
 326:     public void mouseReleased(MouseEvent e)
 327:     {
 328:       DesktopManager dm = getDesktopManager();
 329:       xOffset = 0;
 330:       yOffset = 0;
 331:       if (e.getSource() == frame && frame.isResizable())
 332:     dm.endResizingFrame(frame);
 333:       else if (e.getSource() == titlePane)
 334:     dm.endDraggingFrame(frame);
 335:     }
 336: 
 337:     /**
 338:      * This method determines the direction of the resize based on the
 339:      * coordinates and the size of the JInternalFrame.
 340:      *
 341:      * @param x The x coordinate of the MouseEvent.
 342:      * @param y The y coordinate of the MouseEvent.
 343:      *
 344:      * @return The direction of the resize (a SwingConstant direction).
 345:      */
 346:     private int sectionOfClick(int x, int y)
 347:     {
 348:       Insets insets = frame.getInsets();
 349:       Rectangle b = frame.getBounds();
 350:       if (x < insets.left && y < insets.top)
 351:     return NORTH_WEST;
 352:       else if (x > b.width - insets.right && y < insets.top)
 353:     return NORTH_EAST;
 354:       else if (x > b.width - insets.right && y > b.height - insets.bottom)
 355:     return SOUTH_EAST;
 356:       else if (x < insets.left && y > b.height - insets.bottom)
 357:     return SOUTH_WEST;
 358:       else if (y < insets.top)
 359:     return NORTH;
 360:       else if (x < insets.left)
 361:     return WEST;
 362:       else if (y > b.height - insets.bottom)
 363:     return SOUTH;
 364:       else if (x > b.width - insets.right)
 365:     return EAST;
 366: 
 367:       return -1;
 368:     }
 369:   }
 370: 
 371:   /**
 372:    * This helper class listens to the JDesktopPane that parents this
 373:    * JInternalFrame and listens for resize events and resizes the
 374:    * JInternalFrame appropriately.
 375:    */
 376:   protected class ComponentHandler implements ComponentListener
 377:   {
 378:     /**
 379:      * This method is called when the JDesktopPane is hidden.
 380:      *
 381:      * @param e The ComponentEvent fired.
 382:      */
 383:     public void componentHidden(ComponentEvent e)
 384:     {
 385:       // Do nothing.
 386:     }
 387: 
 388:     /**
 389:      * This method is called when the JDesktopPane is moved.
 390:      *
 391:      * @param e The ComponentEvent fired.
 392:      */
 393:     public void componentMoved(ComponentEvent e)
 394:     {
 395:       // Do nothing.
 396:     }
 397: 
 398:     /**
 399:      * This method is called when the JDesktopPane is resized.
 400:      *
 401:      * @param e The ComponentEvent fired.
 402:      */
 403:     public void componentResized(ComponentEvent e)
 404:     {
 405:       if (frame.isMaximum())
 406:         {
 407:       JDesktopPane pane = (JDesktopPane) e.getSource();
 408:       Insets insets = pane.getInsets();
 409:       Rectangle bounds = pane.getBounds();
 410: 
 411:       frame.setBounds(bounds.x + insets.left, bounds.y + insets.top,
 412:                       bounds.width - insets.left - insets.right,
 413:                       bounds.height - insets.top - insets.bottom);
 414:       frame.revalidate();
 415:       frame.repaint();
 416:         }
 417: 
 418:       // Sun also resizes the icons. but it doesn't seem to do anything.
 419:     }
 420: 
 421:     /**
 422:      * This method is called when the JDesktopPane is shown.
 423:      *
 424:      * @param e The ComponentEvent fired.
 425:      */
 426:     public void componentShown(ComponentEvent e)
 427:     {
 428:       // Do nothing.
 429:     }
 430:   }
 431: 
 432:   /**
 433:    * This helper class acts as the LayoutManager for JInternalFrames.
 434:    */
 435:   public class InternalFrameLayout implements LayoutManager
 436:   {
 437:     /**
 438:      * This method is called when the given Component is added  to the
 439:      * JInternalFrame.
 440:      *
 441:      * @param name The name of the Component.
 442:      * @param c The Component added.
 443:      */
 444:     public void addLayoutComponent(String name, Component c)
 445:     {
 446:     }
 447: 
 448:     /**
 449:      * This method is used to set the bounds of the children of the
 450:      * JInternalFrame.
 451:      *
 452:      * @param c The Container to lay out.
 453:      */
 454:     public void layoutContainer(Container c)
 455:     {
 456:       Dimension dims = frame.getSize();
 457:       Insets insets = frame.getInsets();
 458: 
 459:       dims.width -= insets.left + insets.right;
 460:       dims.height -= insets.top + insets.bottom;
 461: 
 462:       frame.getRootPane().getGlassPane().setBounds(0, 0, dims.width,
 463:                                                    dims.height);
 464:       int nh = 0;
 465:       int sh = 0;
 466:       int ew = 0;
 467:       int ww = 0;
 468: 
 469:       if (northPane != null)
 470:         {
 471:       Dimension nDims = northPane.getPreferredSize();
 472:       nh = Math.min(nDims.height, dims.height);
 473: 
 474:       northPane.setBounds(insets.left, insets.top, dims.width, nh);
 475:         }
 476: 
 477:       if (southPane != null)
 478:         {
 479:       Dimension sDims = southPane.getPreferredSize();
 480:       sh = Math.min(sDims.height, dims.height - nh);
 481: 
 482:       southPane.setBounds(insets.left, insets.top + dims.height - sh,
 483:                           dims.width, sh);
 484:         }
 485: 
 486:       int remHeight = dims.height - sh - nh;
 487: 
 488:       if (westPane != null)
 489:         {
 490:       Dimension wDims = westPane.getPreferredSize();
 491:       ww = Math.min(dims.width, wDims.width);
 492: 
 493:       westPane.setBounds(insets.left, insets.top + nh, ww, remHeight);
 494:         }
 495: 
 496:       if (eastPane != null)
 497:         {
 498:       Dimension eDims = eastPane.getPreferredSize();
 499:       ew = Math.min(eDims.width, dims.width - ww);
 500: 
 501:       eastPane.setBounds(insets.left + dims.width - ew, insets.top + nh,
 502:                          ew, remHeight);
 503:         }
 504: 
 505:       int remWidth = dims.width - ww - ew;
 506: 
 507:       frame.getRootPane().setBounds(insets.left + ww, insets.top + nh,
 508:                                     remWidth, remHeight);
 509:     }
 510: 
 511:     /**
 512:      * This method returns the minimum layout size.
 513:      *
 514:      * @param c The Container to find a minimum layout size for.
 515:      *
 516:      * @return The minimum dimensions for the JInternalFrame.
 517:      */
 518:     public Dimension minimumLayoutSize(Container c)
 519:     {
 520:       return getSize(c, true);
 521:     }
 522: 
 523:     /**
 524:      * This method returns the maximum layout size.
 525:      *
 526:      * @param c The Container to find a maximum layout size for.
 527:      *
 528:      * @return The maximum dimensions for the JInternalFrame.
 529:      */
 530:     public Dimension maximumLayoutSize(Container c)
 531:     {
 532:       return preferredLayoutSize(c);
 533:     }
 534: 
 535:     /**
 536:      * Th8is method returns the preferred layout size.
 537:      *
 538:      * @param c The Container to find a preferred layout size for.
 539:      *
 540:      * @return The preferred dimensions for the JInternalFrame.
 541:      */
 542:     public Dimension preferredLayoutSize(Container c)
 543:     {
 544:       return getSize(c, false);
 545:     }
 546: 
 547:     /**
 548:      * DOCUMENT ME!
 549:      *
 550:      * @param c DOCUMENT ME!
 551:      * @param min DOCUMENT ME!
 552:      *
 553:      * @return DOCUMENT ME!
 554:      */
 555:     private Dimension getSize(Container c, boolean min)
 556:     {
 557:       Insets insets = frame.getInsets();
 558: 
 559:       Dimension contentDims = frame.getContentPane().getPreferredSize();
 560:       if (min)
 561:     contentDims.width = contentDims.height = 0;
 562:       int nWidth = 0;
 563:       int nHeight = 0;
 564:       int sWidth = 0;
 565:       int sHeight = 0;
 566:       int eWidth = 0;
 567:       int eHeight = 0;
 568:       int wWidth = 0;
 569:       int wHeight = 0;
 570:       Dimension dims;
 571: 
 572:       if (northPane != null)
 573:         {
 574:       dims = northPane.getPreferredSize();
 575:       if (dims != null)
 576:         {
 577:           nWidth = dims.width;
 578:           nHeight = dims.height;
 579:         }
 580:         }
 581: 
 582:       if (southPane != null)
 583:         {
 584:       dims = southPane.getPreferredSize();
 585:       if (dims != null)
 586:         {
 587:           sWidth = dims.width;
 588:           sHeight = dims.height;
 589:         }
 590:         }
 591: 
 592:       if (eastPane != null)
 593:         {
 594:       dims = eastPane.getPreferredSize();
 595:       if (dims != null)
 596:         {
 597:           sWidth = dims.width;
 598:           sHeight = dims.height;
 599:         }
 600:         }
 601: 
 602:       if (westPane != null)
 603:         {
 604:       dims = westPane.getPreferredSize();
 605:       if (dims != null)
 606:         {
 607:           wWidth = dims.width;
 608:           wHeight = dims.height;
 609:         }
 610:         }
 611: 
 612:       int width = Math.max(sWidth, nWidth);
 613:       width = Math.max(width, contentDims.width + eWidth + wWidth);
 614: 
 615:       int height = Math.max(eHeight, wHeight);
 616:       height = Math.max(height, contentDims.height);
 617:       height += nHeight + sHeight;
 618: 
 619:       width += insets.left + insets.right;
 620:       height += insets.top + insets.bottom;
 621: 
 622:       return new Dimension(width, height);
 623:     }
 624: 
 625:     /**
 626:      * This method is called when a Component is removed from the
 627:      * JInternalFrame.
 628:      *
 629:      * @param c The Component that was removed.
 630:      */
 631:     public void removeLayoutComponent(Component c)
 632:     {
 633:     }
 634:   }
 635: 
 636:   /**
 637:    * This helper class is used to listen to the JDesktopPane's glassPane for
 638:    * MouseEvents. The JInternalFrame can then be selected if a click is
 639:    * detected on its children.
 640:    */
 641:   protected class GlassPaneDispatcher implements MouseInputListener
 642:   {
 643:     /** The MouseEvent target. */
 644:     private transient Component mouseEventTarget;
 645: 
 646:     /** The component pressed. */
 647:     private transient Component pressedComponent;
 648: 
 649:     /** The last component entered. */
 650:     private transient Component lastComponentEntered;
 651: 
 652:     /** Used to store/reset lastComponentEntered. */
 653:     private transient Component tempComponent;
 654: 
 655:     /** The number of presses. */
 656:     private transient int pressCount;
 657: 
 658:     /**
 659:      * This method is called when the mouse enters the glass pane.
 660:      *
 661:      * @param e The MouseEvent.
 662:      */
 663:     public void mouseEntered(MouseEvent e)
 664:     {
 665:       handleEvent(e);
 666:     }
 667: 
 668:     /**
 669:      * This method is called when the mouse is clicked on the glass pane.
 670:      *
 671:      * @param e The MouseEvent.
 672:      */
 673:     public void mouseClicked(MouseEvent e)
 674:     {
 675:       handleEvent(e);
 676:     }
 677: 
 678:     /**
 679:      * This method is called when the mouse is dragged in the glass pane.
 680:      *
 681:      * @param e The MouseEvent.
 682:      */
 683:     public void mouseDragged(MouseEvent e)
 684:     {
 685:       handleEvent(e);
 686:     }
 687: 
 688:     /**
 689:      * This method is called when the mouse exits the glass pane.
 690:      *
 691:      * @param e The MouseEvent.
 692:      */
 693:     public void mouseExited(MouseEvent e)
 694:     {
 695:       handleEvent(e);
 696:     }
 697: 
 698:     /**
 699:      * This method is called when the mouse is moved in the glass pane.
 700:      *
 701:      * @param e The MouseEvent.
 702:      */
 703:     public void mouseMoved(MouseEvent e)
 704:     {
 705:       handleEvent(e);
 706:     }
 707: 
 708:     /**
 709:      * This method is called when the mouse is  pressed in the glass pane.
 710:      *
 711:      * @param e The MouseEvent.
 712:      */
 713:     public void mousePressed(MouseEvent e)
 714:     {
 715:       activateFrame(frame);
 716:       handleEvent(e);
 717:     }
 718: 
 719:     /**
 720:      * This method is called when the mouse is  released in the glass pane.
 721:      *
 722:      * @param e The MouseEvent.
 723:      */
 724:     public void mouseReleased(MouseEvent e)
 725:     {
 726:       handleEvent(e);
 727:     }
 728: 
 729:     /**
 730:      * This method acquires a candidate component to dispatch the  MouseEvent
 731:      * to.
 732:      *
 733:      * @param me The MouseEvent to acquire a component for.
 734:      */
 735:     private void acquireComponentForMouseEvent(MouseEvent me)
 736:     {
 737:       int x = me.getX();
 738:       int y = me.getY();
 739: 
 740:       // Find the candidate which should receive this event.
 741:       Component parent = frame.getContentPane();
 742:       if (parent == null)
 743:     return;
 744:       Component candidate = null;
 745:       Point p = me.getPoint();
 746:       while (candidate == null && parent != null)
 747:         {
 748:       candidate = SwingUtilities.getDeepestComponentAt(parent, p.x, p.y);
 749:       if (candidate == null)
 750:         {
 751:           p = SwingUtilities.convertPoint(parent, p.x, p.y,
 752:                                           parent.getParent());
 753:           parent = parent.getParent();
 754:         }
 755:         }
 756: 
 757:       // If the only candidate we found was the native container itself,
 758:       // don't dispatch any event at all.  We only care about the lightweight
 759:       // children here.
 760:       if (candidate == frame.getContentPane())
 761:     candidate = null;
 762: 
 763:       // If our candidate is new, inform the old target we're leaving.
 764:       if (lastComponentEntered != null && lastComponentEntered.isShowing()
 765:           && lastComponentEntered != candidate)
 766:         {
 767:       Point tp = SwingUtilities.convertPoint(frame.getContentPane(), x, y,
 768:                                              lastComponentEntered);
 769:       MouseEvent exited = new MouseEvent(lastComponentEntered,
 770:                                          MouseEvent.MOUSE_EXITED,
 771:                                          me.getWhen(), me.getModifiersEx(),
 772:                                          tp.x, tp.y, me.getClickCount(),
 773:                                          me.isPopupTrigger(),
 774:                                          me.getButton());
 775:           tempComponent = lastComponentEntered;
 776:       lastComponentEntered = null;
 777:       tempComponent.dispatchEvent(exited);
 778:         }
 779: 
 780:       // If we have a candidate, maybe enter it.
 781:       if (candidate != null)
 782:         {
 783:       mouseEventTarget = candidate;
 784:       if (candidate.isLightweight() && candidate.isShowing()
 785:           && candidate != frame.getContentPane()
 786:           && candidate != lastComponentEntered)
 787:         {
 788:           lastComponentEntered = mouseEventTarget;
 789:           Point cp = SwingUtilities.convertPoint(frame.getContentPane(),
 790:                                                  x, y, lastComponentEntered);
 791:           MouseEvent entered = new MouseEvent(lastComponentEntered,
 792:                                               MouseEvent.MOUSE_ENTERED,
 793:                                               me.getWhen(),
 794:                                               me.getModifiersEx(), cp.x,
 795:                                               cp.y, me.getClickCount(),
 796:                                               me.isPopupTrigger(),
 797:                                               me.getButton());
 798:           lastComponentEntered.dispatchEvent(entered);
 799:         }
 800:         }
 801: 
 802:       if (me.getID() == MouseEvent.MOUSE_RELEASED
 803:           || me.getID() == MouseEvent.MOUSE_PRESSED && pressCount > 0
 804:           || me.getID() == MouseEvent.MOUSE_DRAGGED)
 805:     // If any of the following events occur while a button is held down,
 806:     // they should be dispatched to the same component to which the
 807:     // original MOUSE_PRESSED event was dispatched:
 808:     //   - MOUSE_RELEASED
 809:     //   - MOUSE_PRESSED: another button pressed while the first is held down
 810:     //   - MOUSE_DRAGGED
 811:     mouseEventTarget = pressedComponent;
 812:       else if (me.getID() == MouseEvent.MOUSE_CLICKED)
 813:         {
 814:       // Don't dispatch CLICKED events whose target is not the same as the
 815:       // target for the original PRESSED event.
 816:       if (candidate != pressedComponent)
 817:         mouseEventTarget = null;
 818:       else if (pressCount == 0)
 819:         pressedComponent = null;
 820:         }
 821:     }
 822: 
 823:     /**
 824:      * This is a helper method that dispatches the GlassPane MouseEvents to
 825:      * the proper component.
 826:      *
 827:      * @param e The AWTEvent to be dispatched. Usually an instance of
 828:      *        MouseEvent.
 829:      */
 830:     private void handleEvent(AWTEvent e)
 831:     {
 832:       if (e instanceof MouseEvent)
 833:         {
 834:       MouseEvent me = SwingUtilities.convertMouseEvent(frame.getRootPane()
 835:                                                             .getGlassPane(),
 836:                                                        (MouseEvent) e,
 837:                                                        frame.getRootPane()
 838:                                                             .getGlassPane());
 839: 
 840:       acquireComponentForMouseEvent(me);
 841: 
 842:       // Avoid dispatching ENTERED and EXITED events twice.
 843:       if (mouseEventTarget != null && mouseEventTarget.isShowing()
 844:           && e.getID() != MouseEvent.MOUSE_ENTERED
 845:           && e.getID() != MouseEvent.MOUSE_EXITED)
 846:         {
 847:           MouseEvent newEvt = SwingUtilities.convertMouseEvent(frame
 848:                                                                .getContentPane(),
 849:                                                                me,
 850:                                                                mouseEventTarget);
 851:           mouseEventTarget.dispatchEvent(newEvt);
 852: 
 853:           switch (e.getID())
 854:             {
 855:         case MouseEvent.MOUSE_PRESSED:
 856:           if (pressCount++ == 0)
 857:             pressedComponent = mouseEventTarget;
 858:           break;
 859:         case MouseEvent.MOUSE_RELEASED:
 860:           // Clear our memory of the original PRESSED event, only if
 861:           // we're not expecting a CLICKED event after this. If
 862:           // there is a CLICKED event after this, it will do clean up.
 863:           if (--pressCount == 0
 864:               && mouseEventTarget != pressedComponent)
 865:             pressedComponent = null;
 866:           break;
 867:             }
 868:         }
 869:         }
 870:     }
 871:   }
 872: 
 873:   /**
 874:    * This helper class listens for PropertyChangeEvents from the
 875:    * JInternalFrame.
 876:    */
 877:   public class InternalFramePropertyChangeListener
 878:     implements PropertyChangeListener, VetoableChangeListener
 879:   {
 880: 
 881:     /**
 882:      * This method is called when one of the JInternalFrame's properties
 883:      * change.  This method is to allow JInternalFrame to veto an attempt
 884:      * to close the internal frame.  This allows JInternalFrame to honour
 885:      * its defaultCloseOperation if that is DO_NOTHING_ON_CLOSE.
 886:      */
 887:     public void vetoableChange(PropertyChangeEvent e) throws PropertyVetoException
 888:     {
 889:       if (e.getPropertyName().equals(JInternalFrame.IS_CLOSED_PROPERTY))
 890:         {
 891:           if (frame.getDefaultCloseOperation() == JInternalFrame.HIDE_ON_CLOSE)
 892:             {
 893:               frame.setVisible(false);
 894:               frame.getDesktopPane().repaint();
 895:               throw new PropertyVetoException ("close operation is HIDE_ON_CLOSE\n", e);
 896:             }
 897:           else if (frame.getDefaultCloseOperation() == JInternalFrame.DISPOSE_ON_CLOSE)
 898:             closeFrame(frame);
 899:           else
 900:             throw new PropertyVetoException ("close operation is DO_NOTHING_ON_CLOSE\n", e);
 901:         }
 902:     }
 903:     
 904:     /**
 905:      * This method is called when one of the JInternalFrame's properties
 906:      * change.
 907:      *
 908:      * @param evt The PropertyChangeEvent.
 909:      */
 910:     public void propertyChange(PropertyChangeEvent evt)
 911:     {
 912:       if (evt.getPropertyName().equals(JInternalFrame.IS_MAXIMUM_PROPERTY))
 913:         {
 914:       if (frame.isMaximum())
 915:         maximizeFrame(frame);
 916:       else
 917:         minimizeFrame(frame);
 918:         }
 919:       else if (evt.getPropertyName().equals(JInternalFrame.IS_ICON_PROPERTY))
 920:         {
 921:       if (frame.isIcon())
 922:         iconifyFrame(frame);
 923:       else
 924:         deiconifyFrame(frame);
 925:         }
 926:       else if (evt.getPropertyName().equals(JInternalFrame.IS_SELECTED_PROPERTY))
 927:         {
 928:       if (frame.isSelected())
 929:         activateFrame(frame);
 930:       else
 931:         getDesktopManager().deactivateFrame(frame);
 932:         }
 933:       else if (evt.getPropertyName().equals(JInternalFrame.ROOT_PANE_PROPERTY)
 934:                || evt.getPropertyName().equals(JInternalFrame.GLASS_PANE_PROPERTY))
 935:         {
 936:       Component old = (Component) evt.getOldValue();
 937:       old.removeMouseListener(glassPaneDispatcher);
 938:       old.removeMouseMotionListener(glassPaneDispatcher);
 939: 
 940:       Component newPane = (Component) evt.getNewValue();
 941:       newPane.addMouseListener(glassPaneDispatcher);
 942:       newPane.addMouseMotionListener(glassPaneDispatcher);
 943: 
 944:       frame.revalidate();
 945:         }
 946:       /* FIXME: need to add ancestor properties to JComponents.
 947:       else if (evt.getPropertyName().equals(JComponent.ANCESTOR_PROPERTY))
 948:       {
 949:         if (desktopPane != null)
 950:           desktopPane.removeComponentListener(componentListener);
 951:         desktopPane = frame.getDesktopPane();
 952:         if (desktopPane != null)
 953:           desktopPane.addComponentListener(componentListener);
 954:       }
 955:       */
 956:     }
 957:   }
 958: 
 959:   /**
 960:    * This helper class is the border for the JInternalFrame.
 961:    */
 962:   private class InternalFrameBorder extends AbstractBorder
 963:     implements UIResource
 964:   {
 965:     /** The width of the border. */
 966:     private static final int bSize = 5;
 967: 
 968:     /** The size of the corners. */
 969:     private static final int offset = 10;
 970: 
 971:     /**
 972:      * This method returns whether the border is opaque.
 973:      *
 974:      * @return Whether the border is opaque.
 975:      */
 976:     public boolean isBorderOpaque()
 977:     {
 978:       return true;
 979:     }
 980: 
 981:     /**
 982:      * This method returns the insets of the border.
 983:      *
 984:      * @param c The Component to find border insets for.
 985:      *
 986:      * @return The border insets.
 987:      */
 988:     public Insets getBorderInsets(Component c)
 989:     {
 990:       return new Insets(bSize, bSize, bSize, bSize);
 991:     }
 992: 
 993:     /**
 994:      * This method paints the border.
 995:      *
 996:      * @param c The Component that owns the border.
 997:      * @param g The Graphics object to paint with.
 998:      * @param x The x coordinate to paint at.
 999:      * @param y The y coordinate to paint at.
1000:      * @param width The width of the Component.
1001:      * @param height The height of the Component.
1002:      */
1003:     public void paintBorder(Component c, Graphics g, int x, int y, int width,
1004:                             int height)
1005:     {
1006:       g.translate(x, y);
1007:       Color saved = g.getColor();
1008:       Rectangle b = frame.getBounds();
1009: 
1010:       Color d = c.getBackground();
1011:       g.setColor(d);
1012:       g.fillRect(0, 0, bSize, b.height);
1013:       g.fillRect(0, 0, b.width, bSize);
1014:       g.fillRect(0, b.height - bSize, b.width, bSize);
1015:       g.fillRect(b.width - bSize, 0, bSize, b.height);
1016: 
1017:       int x1 = 0;
1018:       int x2 = bSize;
1019:       int x3 = b.width - bSize;
1020:       int x4 = b.width;
1021: 
1022:       int y1 = 0;
1023:       int y2 = bSize;
1024:       int y3 = b.height - bSize;
1025:       int y4 = b.height;
1026: 
1027:       g.setColor(Color.GRAY);
1028:       g.fillRect(0, 0, bSize, y4);
1029:       g.fillRect(0, 0, x4, bSize);
1030:       g.fillRect(0, y3, b.width, bSize);
1031:       g.fillRect(x3, 0, bSize, b.height);
1032: 
1033:       g.fill3DRect(0, offset, bSize, b.height - 2 * offset, false);
1034:       g.fill3DRect(offset, 0, b.width - 2 * offset, bSize, false);
1035:       g.fill3DRect(offset, b.height - bSize, b.width - 2 * offset, bSize, false);
1036:       g.fill3DRect(b.width - bSize, offset, bSize, b.height - 2 * offset, false);
1037: 
1038:       g.translate(-x, -y);
1039:       g.setColor(saved);
1040:     }
1041:   }
1042: 
1043:   /**
1044:    * The MouseListener that is responsible for dragging and resizing the
1045:    * JInternalFrame in response to MouseEvents.
1046:    */
1047:   protected MouseInputAdapter borderListener;
1048: 
1049:   /**
1050:    * The ComponentListener that is responsible for resizing the JInternalFrame
1051:    * in response to ComponentEvents from the JDesktopPane.
1052:    */
1053:   protected ComponentListener componentListener;
1054: 
1055:   /**
1056:    * The MouseListener that is responsible for activating the JInternalFrame
1057:    * when the mouse press activates one of its descendents.
1058:    */
1059:   protected MouseInputListener glassPaneDispatcher;
1060: 
1061:   /**
1062:    * The PropertyChangeListener that is responsible for listening to
1063:    * PropertyChangeEvents from the JInternalFrame.
1064:    */
1065:   protected PropertyChangeListener propertyChangeListener;
1066: 
1067:   /**
1068:    * The VetoableChangeListener.  Listens to PropertyChangeEvents
1069:    * from the JInternalFrame and allows the JInternalFrame to 
1070:    * veto attempts to close it.
1071:    */
1072:   private VetoableChangeListener internalFrameVetoableChangeListener;
1073: 
1074:   /** The InternalFrameListener that listens to the JInternalFrame. */
1075:   private transient BasicInternalFrameListener internalFrameListener;
1076: 
1077:   /** The JComponent placed at the east region of the JInternalFrame. */
1078:   protected JComponent eastPane;
1079: 
1080:   /** The JComponent placed at the north region of the JInternalFrame. */
1081:   protected JComponent northPane;
1082: 
1083:   /** The JComponent placed at the south region of the JInternalFrame. */
1084:   protected JComponent southPane;
1085: 
1086:   /** The JComponent placed at the west region of the JInternalFrame. */
1087:   protected JComponent westPane;
1088: 
1089:   /**
1090:    * The Keystroke bound to open the menu.
1091:    * @deprecated
1092:    */
1093:   protected KeyStroke openMenuKey;
1094: 
1095:   /** The TitlePane displayed at the top of the JInternalFrame. */
1096:   protected BasicInternalFrameTitlePane titlePane;
1097: 
1098:   /** The JInternalFrame this UI is responsible for. */
1099:   protected JInternalFrame frame;
1100: 
1101:   /** The LayoutManager used in the JInternalFrame. */
1102:   protected LayoutManager internalFrameLayout;
1103: 
1104:   /** The JDesktopPane that is the parent of the JInternalFrame. */
1105:   private transient JDesktopPane desktopPane;
1106: 
1107:   /**
1108:    * Creates a new BasicInternalFrameUI object.
1109:    *
1110:    * @param b The JInternalFrame this UI will represent.
1111:    */
1112:   public BasicInternalFrameUI(JInternalFrame b)
1113:   {
1114:   }
1115: 
1116:   /**
1117:    * This method will create a new BasicInternalFrameUI for the given
1118:    * JComponent.
1119:    *
1120:    * @param b The JComponent to create a BasicInternalFrameUI for.
1121:    *
1122:    * @return A new BasicInternalFrameUI.
1123:    */
1124:   public static ComponentUI createUI(JComponent b)
1125:   {
1126:     return new BasicInternalFrameUI((JInternalFrame) b);
1127:   }
1128: 
1129:   /**
1130:    * This method installs a UI for the JInternalFrame.
1131:    *
1132:    * @param c The JComponent to install this UI on.
1133:    */
1134:   public void installUI(JComponent c)
1135:   {
1136:     if (c instanceof JInternalFrame)
1137:       {
1138:     frame = (JInternalFrame) c;
1139: 
1140:     internalFrameLayout = createLayoutManager();
1141:     frame.setLayout(internalFrameLayout);
1142: 
1143:     ((JComponent) frame.getRootPane().getGlassPane()).setOpaque(false);
1144:     frame.getRootPane().getGlassPane().setVisible(true);
1145: 
1146:     installDefaults();
1147:     installListeners();
1148:     installComponents();
1149:     installKeyboardActions();
1150: 
1151:     frame.setOpaque(true);
1152:     frame.invalidate();
1153:       }
1154:   }
1155: 
1156:   /**
1157:    * This method reverses the work done by installUI.
1158:    *
1159:    * @param c The JComponent to uninstall this UI for.
1160:    */
1161:   public void uninstallUI(JComponent c)
1162:   {
1163:     uninstallKeyboardActions();
1164:     uninstallComponents();
1165:     uninstallListeners();
1166:     uninstallDefaults();
1167: 
1168:     frame.setLayout(null);
1169:     ((JComponent) frame.getRootPane().getGlassPane()).setOpaque(true);
1170:     frame.getRootPane().getGlassPane().setVisible(false);
1171: 
1172:     frame = null;
1173:   }
1174: 
1175:   /**
1176:    * This method installs the defaults specified by the look and feel.
1177:    */
1178:   protected void installDefaults()
1179:     {
1180:       UIDefaults defaults = UIManager.getLookAndFeelDefaults();
1181:       Border border = defaults.getBorder("InternalFrame.border");
1182:       frame.setBorder(border);
1183:       frame.setFrameIcon(defaults.getIcon("InternalFrame.icon"));
1184:       // InternalFrames are invisible by default.
1185:       frame.setVisible(false);
1186:   }
1187: 
1188:   /**
1189:    * This method installs the keyboard actions for the JInternalFrame.
1190:    */
1191:   protected void installKeyboardActions()
1192:   {
1193:     // FIXME: Implement.
1194:   }
1195: 
1196:   /**
1197:    * This method installs the Components for the JInternalFrame.
1198:    */
1199:   protected void installComponents()
1200:   {
1201:     setNorthPane(createNorthPane(frame));
1202:     setSouthPane(createSouthPane(frame));
1203:     setEastPane(createEastPane(frame));
1204:     setWestPane(createWestPane(frame));
1205:   }
1206: 
1207:   /**
1208:    * This method installs the listeners for the JInternalFrame.
1209:    */
1210:   protected void installListeners()
1211:   {
1212:     glassPaneDispatcher = createGlassPaneDispatcher();
1213:     createInternalFrameListener();
1214:     borderListener = createBorderListener(frame);
1215:     componentListener = createComponentListener();
1216:     propertyChangeListener = createPropertyChangeListener();
1217:     internalFrameVetoableChangeListener = new InternalFramePropertyChangeListener();
1218: 
1219:     frame.addMouseListener(borderListener);
1220:     frame.addMouseMotionListener(borderListener);
1221:     frame.addInternalFrameListener(internalFrameListener);
1222:     frame.addPropertyChangeListener(propertyChangeListener);
1223:     frame.addVetoableChangeListener(internalFrameVetoableChangeListener);
1224:     frame.getRootPane().getGlassPane().addMouseListener(glassPaneDispatcher);
1225:     frame.getRootPane().getGlassPane().addMouseMotionListener(glassPaneDispatcher);
1226:   }
1227: 
1228:   /**
1229:    * This method uninstalls the defaults for the JInternalFrame.
1230:    */
1231:   protected void uninstallDefaults()
1232:   {
1233:     frame.setBorder(null);
1234:   }
1235: 
1236:   /**
1237:    * This method uninstalls the Components for the JInternalFrame.
1238:    */
1239:   protected void uninstallComponents()
1240:   {
1241:     setNorthPane(null);
1242:     setSouthPane(null);
1243:     setEastPane(null);
1244:     setWestPane(null);
1245:   }
1246: 
1247:   /**
1248:    * This method uninstalls the listeners for the JInternalFrame.
1249:    */
1250:   protected void uninstallListeners()
1251:   {
1252:     if (desktopPane != null)
1253:       desktopPane.removeComponentListener(componentListener);
1254: 
1255:     frame.getRootPane().getGlassPane().removeMouseMotionListener(glassPaneDispatcher);
1256:     frame.getRootPane().getGlassPane().removeMouseListener(glassPaneDispatcher);
1257: 
1258:     frame.removePropertyChangeListener(propertyChangeListener);
1259:     frame.removeInternalFrameListener(internalFrameListener);
1260:     frame.removeMouseMotionListener(borderListener);
1261:     frame.removeMouseListener(borderListener);
1262: 
1263:     propertyChangeListener = null;
1264:     componentListener = null;
1265:     borderListener = null;
1266:     internalFrameListener = null;
1267:     glassPaneDispatcher = null;
1268:   }
1269: 
1270:   /**
1271:    * This method uninstalls the keyboard actions for the JInternalFrame.
1272:    */
1273:   protected void uninstallKeyboardActions()
1274:   {
1275:     // FIXME: Implement.
1276:   }
1277: 
1278:   /**
1279:    * This method creates a new LayoutManager for the JInternalFrame.
1280:    *
1281:    * @return A new LayoutManager for the JInternalFrame.
1282:    */
1283:   protected LayoutManager createLayoutManager()
1284:   {
1285:     return new InternalFrameLayout();
1286:   }
1287: 
1288:   /**
1289:    * This method creates a new PropertyChangeListener for the JInternalFrame.
1290:    *
1291:    * @return A new PropertyChangeListener for the JInternalFrame.
1292:    */
1293:   protected PropertyChangeListener createPropertyChangeListener()
1294:   {
1295:     return new InternalFramePropertyChangeListener();
1296:   }
1297: 
1298:   /**
1299:    * This method returns the preferred size of the given JComponent.
1300:    *
1301:    * @param x The JComponent to find a preferred size for.
1302:    *
1303:    * @return The preferred size.
1304:    */
1305:   public Dimension getPreferredSize(JComponent x)
1306:   {
1307:     return internalFrameLayout.preferredLayoutSize(x);
1308:   }
1309: 
1310:   /**
1311:    * This method returns the minimum size of the given JComponent.
1312:    *
1313:    * @param x The JComponent to find a minimum size for.
1314:    *
1315:    * @return The minimum size.
1316:    */
1317:   public Dimension getMinimumSize(JComponent x)
1318:   {
1319:     return internalFrameLayout.minimumLayoutSize(x);
1320:   }
1321: 
1322:   /**
1323:    * This method returns the maximum size of the given JComponent.
1324:    *
1325:    * @param x The JComponent to find a maximum size for.
1326:    *
1327:    * @return The maximum size.
1328:    */
1329:   public Dimension getMaximumSize(JComponent x)
1330:   {
1331:     return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
1332:   }
1333: 
1334:   /**
1335:    * This method replaces the currentPane with the newPane. When replacing it
1336:    * also removes the MouseHandlers for the old pane and installs  them on
1337:    * the new pane.
1338:    *
1339:    * @param currentPane The old pane to remove.
1340:    * @param newPane The new pane to install.
1341:    */
1342:   protected void replacePane(JComponent currentPane, JComponent newPane)
1343:   {
1344:     if (currentPane != null)
1345:       {
1346:     deinstallMouseHandlers(currentPane);
1347:     frame.remove(currentPane);
1348:       }
1349: 
1350:     if (newPane != null)
1351:       {
1352:     installMouseHandlers(newPane);
1353:     frame.add(newPane);
1354:       }
1355:   }
1356: 
1357:   /**
1358:    * This method removes the necessary MouseListeners from the given
1359:    * JComponent.
1360:    *
1361:    * @param c The JComponent to remove MouseListeners from.
1362:    */
1363:   protected void deinstallMouseHandlers(JComponent c)
1364:   {
1365:     c.removeMouseListener(borderListener);
1366:     c.removeMouseMotionListener(borderListener);
1367:   }
1368: 
1369:   /**
1370:    * This method installs the necessary MouseListeners from the given
1371:    * JComponent.
1372:    *
1373:    * @param c The JComponent to install MouseListeners on.
1374:    */
1375:   protected void installMouseHandlers(JComponent c)
1376:   {
1377:     c.addMouseListener(borderListener);
1378:     c.addMouseMotionListener(borderListener);
1379:   }
1380: 
1381:   /**
1382:    * This method creates the north pane used in the JInternalFrame.
1383:    *
1384:    * @param w The JInternalFrame to create a north pane for.
1385:    *
1386:    * @return The north pane.
1387:    */
1388:   protected JComponent createNorthPane(JInternalFrame w)
1389:   {
1390:     titlePane = new BasicInternalFrameTitlePane(w);
1391:     return titlePane;
1392:   }
1393: 
1394:   /**
1395:    * This method creates the west pane used in the JInternalFrame.
1396:    *
1397:    * @param w The JInternalFrame to create a west pane for.
1398:    *
1399:    * @return The west pane.
1400:    */
1401:   protected JComponent createWestPane(JInternalFrame w)
1402:   {
1403:     return null;
1404:   }
1405: 
1406:   /**
1407:    * This method creates the south pane used in the JInternalFrame.
1408:    *
1409:    * @param w The JInternalFrame to create a south pane for.
1410:    *
1411:    * @return The south pane.
1412:    */
1413:   protected JComponent createSouthPane(JInternalFrame w)
1414:   {
1415:     return null;
1416:   }
1417: 
1418:   /**
1419:    * This method creates the east pane used in the JInternalFrame.
1420:    *
1421:    * @param w The JInternalFrame to create an east pane for.
1422:    *
1423:    * @return The east pane.
1424:    */
1425:   protected JComponent createEastPane(JInternalFrame w)
1426:   {
1427:     return null;
1428:   }
1429: 
1430:   /**
1431:    * This method returns a new BorderListener for the given JInternalFrame.
1432:    *
1433:    * @param w The JIntenalFrame to create a BorderListener for.
1434:    *
1435:    * @return A new BorderListener.
1436:    */
1437:   protected MouseInputAdapter createBorderListener(JInternalFrame w)
1438:   {
1439:     return new BorderListener();
1440:   }
1441: 
1442:   /**
1443:    * This method creates a new InternalFrameListener for the JInternalFrame.
1444:    */
1445:   protected void createInternalFrameListener()
1446:   {
1447:     internalFrameListener = new BasicInternalFrameListener();
1448:   }
1449: 
1450:   /**
1451:    * DOCUMENT ME!
1452:    *
1453:    * @return DOCUMENT ME!
1454:    */
1455:   protected final boolean isKeyBindingRegistered()
1456:   {
1457:     // FIXME: Implement.
1458:     return false;
1459:   }
1460: 
1461:   /**
1462:    * DOCUMENT ME!
1463:    *
1464:    * @param b DOCUMENT ME!
1465:    */
1466:   protected final void setKeyBindingRegistered(boolean b)
1467:   {
1468:     // FIXME: Implement.
1469:   }
1470: 
1471:   /**
1472:    * DOCUMENT ME!
1473:    *
1474:    * @return DOCUMENT ME!
1475:    */
1476:   public final boolean isKeyBindingActive()
1477:   {
1478:     // FIXME: Implement.
1479:     return false;
1480:   }
1481: 
1482:   /**
1483:    * DOCUMENT ME!
1484:    *
1485:    * @param b DOCUMENT ME!
1486:    */
1487:   protected final void setKeyBindingActive(boolean b)
1488:   {
1489:     // FIXME: Implement.
1490:   }
1491: 
1492:   /**
1493:    * DOCUMENT ME!
1494:    */
1495:   protected void setupMenuOpenKey()
1496:   {
1497:     // FIXME: Implement.
1498:   }
1499: 
1500:   /**
1501:    * DOCUMENT ME!
1502:    */
1503:   protected void setupMenuCloseKey()
1504:   {
1505:     // FIXME: Implement.
1506:   }
1507: 
1508:   /**
1509:    * This method returns the north pane.
1510:    *
1511:    * @return The north pane.
1512:    */
1513:   public JComponent getNorthPane()
1514:   {
1515:     return northPane;
1516:   }
1517: 
1518:   /**
1519:    * This method sets the north pane to be the given JComponent.
1520:    *
1521:    * @param c The new north pane.
1522:    */
1523:   public void setNorthPane(JComponent c)
1524:   {
1525:     replacePane(northPane, c);
1526:     northPane = c;
1527:   }
1528: 
1529:   /**
1530:    * This method returns the south pane.
1531:    *
1532:    * @return The south pane.
1533:    */
1534:   public JComponent getSouthPane()
1535:   {
1536:     return southPane;
1537:   }
1538: 
1539:   /**
1540:    * This method sets the south pane to be the given JComponent.
1541:    *
1542:    * @param c The new south pane.
1543:    */
1544:   public void setSouthPane(JComponent c)
1545:   {
1546:     replacePane(southPane, c);
1547:     southPane = c;
1548:   }
1549: 
1550:   /**
1551:    * This method sets the east pane to be the given JComponent.
1552:    *
1553:    * @param c The new east pane.
1554:    */
1555:   public void setEastPane(JComponent c)
1556:   {
1557:     replacePane(eastPane, c);
1558:     eastPane = c;
1559:   }
1560: 
1561:   /**
1562:    * This method returns the east pane.
1563:    *
1564:    * @return The east pane.
1565:    */
1566:   public JComponent getEastPane()
1567:   {
1568:     return eastPane;
1569:   }
1570: 
1571:   /**
1572:    * This method sets the west pane to be the given JComponent.
1573:    *
1574:    * @param c The new west pane.
1575:    */
1576:   public void setWestPane(JComponent c)
1577:   {
1578:     replacePane(westPane, c);
1579:     westPane = c;
1580:   }
1581: 
1582:   /**
1583:    * This method returns the west pane.
1584:    *
1585:    * @return The west pane.
1586:    */
1587:   public JComponent getWestPane()
1588:   {
1589:     return westPane;
1590:   }
1591: 
1592:   /**
1593:    * This method returns the DesktopManager to use with the JInternalFrame.
1594:    *
1595:    * @return The DesktopManager to use with the JInternalFrame.
1596:    */
1597:   protected DesktopManager getDesktopManager()
1598:   {
1599:     DesktopManager value = null;
1600:     JDesktopPane pane = frame.getDesktopPane();
1601:     if (pane != null)
1602:       value = frame.getDesktopPane().getDesktopManager();
1603:     if (value == null)
1604:       value = createDesktopManager();
1605:     return value;
1606:   }
1607: 
1608:   /**
1609:    * This method returns a default DesktopManager that can be used with this
1610:    * JInternalFrame.
1611:    *
1612:    * @return A default DesktopManager that can be used with this
1613:    *         JInternalFrame.
1614:    */
1615:   protected DesktopManager createDesktopManager()
1616:   {
1617:     return new DefaultDesktopManager();
1618:   }
1619: 
1620:   /**
1621:    * This is a convenience method that closes the JInternalFrame.
1622:    *
1623:    * @param f The JInternalFrame to close.
1624:    */
1625:   protected void closeFrame(JInternalFrame f)
1626:   {
1627:     getDesktopManager().closeFrame(f);
1628:   }
1629: 
1630:   /**
1631:    * This is a convenience method that maximizes the JInternalFrame.
1632:    *
1633:    * @param f The JInternalFrame to maximize.
1634:    */
1635:   protected void maximizeFrame(JInternalFrame f)
1636:   {
1637:     getDesktopManager().maximizeFrame(f);
1638:   }
1639: 
1640:   /**
1641:    * This is a convenience method that minimizes the JInternalFrame.
1642:    *
1643:    * @param f The JInternalFrame to minimize.
1644:    */
1645:   protected void minimizeFrame(JInternalFrame f)
1646:   {
1647:     getDesktopManager().minimizeFrame(f);
1648:   }
1649: 
1650:   /**
1651:    * This is a convenience method that iconifies the JInternalFrame.
1652:    *
1653:    * @param f The JInternalFrame to iconify.
1654:    */
1655:   protected void iconifyFrame(JInternalFrame f)
1656:   {
1657:     getDesktopManager().iconifyFrame(f);
1658:   }
1659: 
1660:   /**
1661:    * This is a convenience method that deiconifies the JInternalFrame.
1662:    *
1663:    * @param f The JInternalFrame to deiconify.
1664:    */
1665:   protected void deiconifyFrame(JInternalFrame f)
1666:   {
1667:     getDesktopManager().deiconifyFrame(f);
1668:   }
1669: 
1670:   /**
1671:    * This is a convenience method that activates the JInternalFrame.
1672:    *
1673:    * @param f The JInternalFrame to activate.
1674:    */
1675:   protected void activateFrame(JInternalFrame f)
1676:   {
1677:     getDesktopManager().activateFrame(f);
1678:   }
1679: 
1680:   /**
1681:    * This method returns a new ComponentListener for the JDesktopPane.
1682:    *
1683:    * @return A new ComponentListener.
1684:    */
1685:   protected ComponentListener createComponentListener()
1686:   {
1687:     return new ComponentHandler();
1688:   }
1689: 
1690:   /**
1691:    * This method returns a new GlassPaneDispatcher.
1692:    *
1693:    * @return A new GlassPaneDispatcher.
1694:    */
1695:   protected MouseInputListener createGlassPaneDispatcher()
1696:   {
1697:     return new GlassPaneDispatcher();
1698:   }
1699: }