/[classpath]/classpath/javax/swing/plaf/basic/BasicInternalFrameUI.java
ViewVC logotype

Diff of /classpath/javax/swing/plaf/basic/BasicInternalFrameUI.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.16 by trebligd, Wed Aug 24 09:00:32 2005 UTC revision 1.17 by abalkiss, Thu Sep 15 18:08:52 2005 UTC
# Line 202  public class BasicInternalFrameUI extend Line 202  public class BasicInternalFrameUI extend
202       */       */
203      public void mouseDragged(MouseEvent e)      public void mouseDragged(MouseEvent e)
204      {      {
205        // If the frame is maximized, there is nothing that        // If the frame is maximized, there is nothing that
206        // can be dragged around.        // can be dragged around.
207        if (frame.isMaximum())        if (frame.isMaximum())
208          return;          return;
209        DesktopManager dm = getDesktopManager();        DesktopManager dm = getDesktopManager();
210        Rectangle b = frame.getBounds();        Rectangle b = frame.getBounds();
211        Dimension min = frame.getMinimumSize();        Dimension min = frame.getMinimumSize();
212        if (min == null)        if (min == null)
213          min = new Dimension(0, 0);          min = new Dimension(0, 0);
214        Insets insets = frame.getInsets();        Insets insets = frame.getInsets();
215        int x = e.getX();        int x = e.getX();
216        int y = e.getY();        int y = e.getY();
217        if (e.getSource() == frame && frame.isResizable())        if (e.getSource() == frame && frame.isResizable())
218          {          {
219            switch (direction)            switch (direction)
220              {              {
221              case NORTH:              case NORTH:
222                cacheRect.setBounds(b.x,                cacheRect.setBounds(b.x, Math.min(b.y + y, b.y + b.height
223                                    Math.min(b.y + y, b.y + b.height                                                           - min.height),
224                                             - min.height), b.width, b.height                                    b.width, b.height - y);
225                                    - y);                break;
226                break;              case NORTH_EAST:
227              case NORTH_EAST:                cacheRect.setBounds(b.x, Math.min(b.y + y, b.y + b.height
228                cacheRect.setBounds(b.x,                                                           - min.height), x,
229                                    Math.min(b.y + y, b.y + b.height                                    b.height - y);
230                                             - min.height), x, b.height - y);                break;
231                break;              case EAST:
232              case EAST:                cacheRect.setBounds(b.x, b.y, x, b.height);
233                cacheRect.setBounds(b.x, b.y, x, b.height);                break;
234                break;              case SOUTH_EAST:
235              case SOUTH_EAST:                cacheRect.setBounds(b.x, b.y, x, y);
236                cacheRect.setBounds(b.x, b.y, x, y);                break;
237                break;              case SOUTH:
238              case SOUTH:                cacheRect.setBounds(b.x, b.y, b.width, y);
239                cacheRect.setBounds(b.x, b.y, b.width, y);                break;
240                break;              case SOUTH_WEST:
241              case SOUTH_WEST:                cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width),
242                cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width),                                    b.y, b.width - x, y);
243                                    b.y, b.width - x, y);                break;
244                break;              case WEST:
245              case WEST:                cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width),
246                cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width),                                    b.y, b.width - x, b.height);
247                                    b.y, b.width - x, b.height);                break;
248                break;              case NORTH_WEST:
249              case NORTH_WEST:                cacheRect.setBounds(
250                cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width),                                    Math.min(b.x + x, b.x + b.width - min.width),
251                                    Math.min(b.y + y, b.y + b.height                                    Math.min(b.y + y, b.y + b.height - min.height),
252                                             - min.height), b.width - x,                                    b.width - x, b.height - y);
253                                    b.height - y);                break;
254                break;              }
255              }            dm.resizeFrame(frame, cacheRect.x, cacheRect.y,
256            dm.resizeFrame(frame, cacheRect.x, cacheRect.y,                           Math.max(min.width, cacheRect.width),
257                           Math.max(min.width, cacheRect.width),                           Math.max(min.height, cacheRect.height));
                          Math.max(min.height, cacheRect.height));  
258          }          }
259        else if (e.getSource() == titlePane)        else if (e.getSource() == titlePane)
260          {          {
261            Rectangle fBounds = frame.getBounds();            Rectangle fBounds = frame.getBounds();
262    
263            dm.dragFrame(frame, e.getX() - xOffset + b.x,            dm.dragFrame(frame, e.getX() - xOffset + b.x, e.getY() - yOffset
264                         e.getY() - yOffset + b.y);                                                          + b.y);
265          }          }
266      }      }
267    
# Line 304  public class BasicInternalFrameUI extend Line 303  public class BasicInternalFrameUI extend
303    
304        if (e.getSource() == frame && frame.isResizable())        if (e.getSource() == frame && frame.isResizable())
305          {          {
306            direction = sectionOfClick(x, y);            direction = sectionOfClick(x, y);
307            dm.beginResizingFrame(frame, direction);            dm.beginResizingFrame(frame, direction);
308          }          }
309        else if (e.getSource() == titlePane)        else if (e.getSource() == titlePane)
310          {          {
311            Rectangle tBounds = titlePane.getBounds();            Rectangle tBounds = titlePane.getBounds();
312    
313            xOffset = e.getX() - tBounds.x + insets.left;            xOffset = e.getX() - tBounds.x + insets.left;
314            yOffset = e.getY() - tBounds.y + insets.top;            yOffset = e.getY() - tBounds.y + insets.top;
315    
316            dm.beginDraggingFrame(frame);            dm.beginDraggingFrame(frame);
317          }          }
318      }      }
319    
# Line 329  public class BasicInternalFrameUI extend Line 328  public class BasicInternalFrameUI extend
328        xOffset = 0;        xOffset = 0;
329        yOffset = 0;        yOffset = 0;
330        if (e.getSource() == frame && frame.isResizable())        if (e.getSource() == frame && frame.isResizable())
331          dm.endResizingFrame(frame);          dm.endResizingFrame(frame);
332        else if (e.getSource() == titlePane)        else if (e.getSource() == titlePane)
333          dm.endDraggingFrame(frame);          dm.endDraggingFrame(frame);
334      }      }
335    
336      /**      /**
# Line 348  public class BasicInternalFrameUI extend Line 347  public class BasicInternalFrameUI extend
347        Insets insets = frame.getInsets();        Insets insets = frame.getInsets();
348        Rectangle b = frame.getBounds();        Rectangle b = frame.getBounds();
349        if (x < insets.left && y < insets.top)        if (x < insets.left && y < insets.top)
350          return NORTH_WEST;          return NORTH_WEST;
351        else if (x > b.width - insets.right && y < insets.top)        else if (x > b.width - insets.right && y < insets.top)
352          return NORTH_EAST;          return NORTH_EAST;
353        else if (x > b.width - insets.right && y > b.height - insets.bottom)        else if (x > b.width - insets.right && y > b.height - insets.bottom)
354          return SOUTH_EAST;          return SOUTH_EAST;
355        else if (x < insets.left && y > b.height - insets.bottom)        else if (x < insets.left && y > b.height - insets.bottom)
356          return SOUTH_WEST;          return SOUTH_WEST;
357        else if (y < insets.top)        else if (y < insets.top)
358          return NORTH;          return NORTH;
359        else if (x < insets.left)        else if (x < insets.left)
360          return WEST;          return WEST;
361        else if (y > b.height - insets.bottom)        else if (y > b.height - insets.bottom)
362          return SOUTH;          return SOUTH;
363        else if (x > b.width - insets.right)        else if (x > b.width - insets.right)
364          return EAST;          return EAST;
365    
366        return -1;        return -1;
367      }      }
# Line 377  public class BasicInternalFrameUI extend Line 376  public class BasicInternalFrameUI extend
376    {    {
377      /**      /**
378       * This method is called when the JDesktopPane is hidden.       * This method is called when the JDesktopPane is hidden.
379       *       *
380       * @param e The ComponentEvent fired.       * @param e
381         *          The ComponentEvent fired.
382       */       */
383      public void componentHidden(ComponentEvent e)      public void componentHidden(ComponentEvent e)
384      {      {
# Line 387  public class BasicInternalFrameUI extend Line 387  public class BasicInternalFrameUI extend
387    
388      /**      /**
389       * This method is called when the JDesktopPane is moved.       * This method is called when the JDesktopPane is moved.
390       *       *
391       * @param e The ComponentEvent fired.       * @param e
392         *          The ComponentEvent fired.
393       */       */
394      public void componentMoved(ComponentEvent e)      public void componentMoved(ComponentEvent e)
395      {      {
# Line 397  public class BasicInternalFrameUI extend Line 398  public class BasicInternalFrameUI extend
398    
399      /**      /**
400       * This method is called when the JDesktopPane is resized.       * This method is called when the JDesktopPane is resized.
401       *       *
402       * @param e The ComponentEvent fired.       * @param e
403         *          The ComponentEvent fired.
404       */       */
405      public void componentResized(ComponentEvent e)      public void componentResized(ComponentEvent e)
406      {      {
407        if (frame.isMaximum())        if (frame.isMaximum())
408          {          {
409            JDesktopPane pane = (JDesktopPane) e.getSource();            JDesktopPane pane = (JDesktopPane) e.getSource();
410            Insets insets = pane.getInsets();            Insets insets = pane.getInsets();
411            Rectangle bounds = pane.getBounds();            Rectangle bounds = pane.getBounds();
412    
413            frame.setBounds(bounds.x + insets.left, bounds.y + insets.top,            frame.setBounds(bounds.x + insets.left, bounds.y + insets.top,
414                            bounds.width - insets.left - insets.right,                            bounds.width - insets.left - insets.right,
415                            bounds.height - insets.top - insets.bottom);                            bounds.height - insets.top - insets.bottom);
416            frame.revalidate();            frame.revalidate();
417            frame.repaint();            frame.repaint();
418          }          }
419    
420        // Sun also resizes the icons. but it doesn't seem to do anything.        // Sun also resizes the icons. but it doesn't seem to do anything.
# Line 420  public class BasicInternalFrameUI extend Line 422  public class BasicInternalFrameUI extend
422    
423      /**      /**
424       * This method is called when the JDesktopPane is shown.       * This method is called when the JDesktopPane is shown.
425       *       *
426       * @param e The ComponentEvent fired.       * @param e
427         *          The ComponentEvent fired.
428       */       */
429      public void componentShown(ComponentEvent e)      public void componentShown(ComponentEvent e)
430      {      {
# Line 435  public class BasicInternalFrameUI extend Line 438  public class BasicInternalFrameUI extend
438    public class InternalFrameLayout implements LayoutManager    public class InternalFrameLayout implements LayoutManager
439    {    {
440      /**      /**
441       * This method is called when the given Component is added  to the       * This method is called when the given Component is added to the
442       * JInternalFrame.       * JInternalFrame.
443       *       *
444       * @param name The name of the Component.       * @param name
445       * @param c The Component added.       *          The name of the Component.
446         * @param c
447         *          The Component added.
448       */       */
449      public void addLayoutComponent(String name, Component c)      public void addLayoutComponent(String name, Component c)
450      {      {
# Line 448  public class BasicInternalFrameUI extend Line 453  public class BasicInternalFrameUI extend
453      /**      /**
454       * This method is used to set the bounds of the children of the       * This method is used to set the bounds of the children of the
455       * JInternalFrame.       * JInternalFrame.
456       *       *
457       * @param c The Container to lay out.       * @param c
458         *          The Container to lay out.
459       */       */
460      public void layoutContainer(Container c)      public void layoutContainer(Container c)
461      {      {
# Line 468  public class BasicInternalFrameUI extend Line 474  public class BasicInternalFrameUI extend
474    
475        if (northPane != null)        if (northPane != null)
476          {          {
477            Dimension nDims = northPane.getPreferredSize();            Dimension nDims = northPane.getPreferredSize();
478            nh = Math.min(nDims.height, dims.height);            nh = Math.min(nDims.height, dims.height);
479    
480            northPane.setBounds(insets.left, insets.top, dims.width, nh);            northPane.setBounds(insets.left, insets.top, dims.width, nh);
481          }          }
482    
483        if (southPane != null)        if (southPane != null)
484          {          {
485            Dimension sDims = southPane.getPreferredSize();            Dimension sDims = southPane.getPreferredSize();
486            sh = Math.min(sDims.height, dims.height - nh);            sh = Math.min(sDims.height, dims.height - nh);
487    
488            southPane.setBounds(insets.left, insets.top + dims.height - sh,            southPane.setBounds(insets.left, insets.top + dims.height - sh,
489                                dims.width, sh);                                dims.width, sh);
490          }          }
491    
492        int remHeight = dims.height - sh - nh;        int remHeight = dims.height - sh - nh;
493    
494        if (westPane != null)        if (westPane != null)
495          {          {
496            Dimension wDims = westPane.getPreferredSize();            Dimension wDims = westPane.getPreferredSize();
497            ww = Math.min(dims.width, wDims.width);            ww = Math.min(dims.width, wDims.width);
498    
499            westPane.setBounds(insets.left, insets.top + nh, ww, remHeight);            westPane.setBounds(insets.left, insets.top + nh, ww, remHeight);
500          }          }
501    
502        if (eastPane != null)        if (eastPane != null)
503          {          {
504            Dimension eDims = eastPane.getPreferredSize();            Dimension eDims = eastPane.getPreferredSize();
505            ew = Math.min(eDims.width, dims.width - ww);            ew = Math.min(eDims.width, dims.width - ww);
506    
507            eastPane.setBounds(insets.left + dims.width - ew, insets.top + nh,            eastPane.setBounds(insets.left + dims.width - ew, insets.top + nh,
508                               ew, remHeight);                               ew, remHeight);
509          }          }
510    
511        int remWidth = dims.width - ww - ew;        int remWidth = dims.width - ww - ew;
# Line 510  public class BasicInternalFrameUI extend Line 516  public class BasicInternalFrameUI extend
516    
517      /**      /**
518       * This method returns the minimum layout size.       * This method returns the minimum layout size.
519       *       *
520       * @param c The Container to find a minimum layout size for.       * @param c
521       *       *          The Container to find a minimum layout size for.
522       * @return The minimum dimensions for the JInternalFrame.       * @return The minimum dimensions for the JInternalFrame.
523       */       */
524      public Dimension minimumLayoutSize(Container c)      public Dimension minimumLayoutSize(Container c)
# Line 522  public class BasicInternalFrameUI extend Line 528  public class BasicInternalFrameUI extend
528    
529      /**      /**
530       * This method returns the maximum layout size.       * This method returns the maximum layout size.
531       *       *
532       * @param c The Container to find a maximum layout size for.       * @param c
533       *       *          The Container to find a maximum layout size for.
534       * @return The maximum dimensions for the JInternalFrame.       * @return The maximum dimensions for the JInternalFrame.
535       */       */
536      public Dimension maximumLayoutSize(Container c)      public Dimension maximumLayoutSize(Container c)
# Line 534  public class BasicInternalFrameUI extend Line 540  public class BasicInternalFrameUI extend
540    
541      /**      /**
542       * Th8is method returns the preferred layout size.       * Th8is method returns the preferred layout size.
543       *       *
544       * @param c The Container to find a preferred layout size for.       * @param c
545       *       *          The Container to find a preferred layout size for.
546       * @return The preferred dimensions for the JInternalFrame.       * @return The preferred dimensions for the JInternalFrame.
547       */       */
548      public Dimension preferredLayoutSize(Container c)      public Dimension preferredLayoutSize(Container c)
# Line 546  public class BasicInternalFrameUI extend Line 552  public class BasicInternalFrameUI extend
552    
553      /**      /**
554       * DOCUMENT ME!       * DOCUMENT ME!
555       *       *
556       * @param c DOCUMENT ME!       * @param c
557       * @param min DOCUMENT ME!       *          DOCUMENT ME!
558       *       * @param min
559         *          DOCUMENT ME!
560       * @return DOCUMENT ME!       * @return DOCUMENT ME!
561       */       */
562      private Dimension getSize(Container c, boolean min)      private Dimension getSize(Container c, boolean min)
# Line 558  public class BasicInternalFrameUI extend Line 565  public class BasicInternalFrameUI extend
565    
566        Dimension contentDims = frame.getContentPane().getPreferredSize();        Dimension contentDims = frame.getContentPane().getPreferredSize();
567        if (min)        if (min)
568          contentDims.width = contentDims.height = 0;          contentDims.width = contentDims.height = 0;
569        int nWidth = 0;        int nWidth = 0;
570        int nHeight = 0;        int nHeight = 0;
571        int sWidth = 0;        int sWidth = 0;
# Line 571  public class BasicInternalFrameUI extend Line 578  public class BasicInternalFrameUI extend
578    
579        if (northPane != null)        if (northPane != null)
580          {          {
581            dims = northPane.getPreferredSize();            dims = northPane.getPreferredSize();
582            if (dims != null)            if (dims != null)
583              {              {
584                nWidth = dims.width;                nWidth = dims.width;
585                nHeight = dims.height;                nHeight = dims.height;
586              }              }
587          }          }
588    
589        if (southPane != null)        if (southPane != null)
590          {          {
591            dims = southPane.getPreferredSize();            dims = southPane.getPreferredSize();
592            if (dims != null)            if (dims != null)
593              {              {
594                sWidth = dims.width;                sWidth = dims.width;
595                sHeight = dims.height;                sHeight = dims.height;
596              }              }
597          }          }
598    
599        if (eastPane != null)        if (eastPane != null)
600          {          {
601            dims = eastPane.getPreferredSize();            dims = eastPane.getPreferredSize();
602            if (dims != null)            if (dims != null)
603              {              {
604                sWidth = dims.width;                sWidth = dims.width;
605                sHeight = dims.height;                sHeight = dims.height;
606              }              }
607          }          }
608    
609        if (westPane != null)        if (westPane != null)
610          {          {
611            dims = westPane.getPreferredSize();            dims = westPane.getPreferredSize();
612            if (dims != null)            if (dims != null)
613              {              {
614                wWidth = dims.width;                wWidth = dims.width;
615                wHeight = dims.height;                wHeight = dims.height;
616              }              }
617          }          }
618    
619        int width = Math.max(sWidth, nWidth);        int width = Math.max(sWidth, nWidth);
# Line 657  public class BasicInternalFrameUI extend Line 664  public class BasicInternalFrameUI extend
664    
665      /**      /**
666       * This method is called when the mouse enters the glass pane.       * This method is called when the mouse enters the glass pane.
667       *       *
668       * @param e The MouseEvent.       * @param e
669         *          The MouseEvent.
670       */       */
671      public void mouseEntered(MouseEvent e)      public void mouseEntered(MouseEvent e)
672      {      {
# Line 667  public class BasicInternalFrameUI extend Line 675  public class BasicInternalFrameUI extend
675    
676      /**      /**
677       * This method is called when the mouse is clicked on the glass pane.       * This method is called when the mouse is clicked on the glass pane.
678       *       *
679       * @param e The MouseEvent.       * @param e
680         *          The MouseEvent.
681       */       */
682      public void mouseClicked(MouseEvent e)      public void mouseClicked(MouseEvent e)
683      {      {
# Line 677  public class BasicInternalFrameUI extend Line 686  public class BasicInternalFrameUI extend
686    
687      /**      /**
688       * This method is called when the mouse is dragged in the glass pane.       * This method is called when the mouse is dragged in the glass pane.
689       *       *
690       * @param e The MouseEvent.       * @param e
691         *          The MouseEvent.
692       */       */
693      public void mouseDragged(MouseEvent e)      public void mouseDragged(MouseEvent e)
694      {      {
# Line 687  public class BasicInternalFrameUI extend Line 697  public class BasicInternalFrameUI extend
697    
698      /**      /**
699       * This method is called when the mouse exits the glass pane.       * This method is called when the mouse exits the glass pane.
700       *       *
701       * @param e The MouseEvent.       * @param e
702         *          The MouseEvent.
703       */       */
704      public void mouseExited(MouseEvent e)      public void mouseExited(MouseEvent e)
705      {      {
# Line 697  public class BasicInternalFrameUI extend Line 708  public class BasicInternalFrameUI extend
708    
709      /**      /**
710       * This method is called when the mouse is moved in the glass pane.       * This method is called when the mouse is moved in the glass pane.
711       *       *
712       * @param e The MouseEvent.       * @param e
713         *          The MouseEvent.
714       */       */
715      public void mouseMoved(MouseEvent e)      public void mouseMoved(MouseEvent e)
716      {      {
# Line 706  public class BasicInternalFrameUI extend Line 718  public class BasicInternalFrameUI extend
718      }      }
719    
720      /**      /**
721       * This method is called when the mouse is  pressed in the glass pane.       * This method is called when the mouse is pressed in the glass pane.
722       *       *
723       * @param e The MouseEvent.       * @param e
724         *          The MouseEvent.
725       */       */
726      public void mousePressed(MouseEvent e)      public void mousePressed(MouseEvent e)
727      {      {
# Line 717  public class BasicInternalFrameUI extend Line 730  public class BasicInternalFrameUI extend
730      }      }
731    
732      /**      /**
733       * This method is called when the mouse is  released in the glass pane.       * This method is called when the mouse is released in the glass pane.
734       *       *
735       * @param e The MouseEvent.       * @param e
736         *          The MouseEvent.
737       */       */
738      public void mouseReleased(MouseEvent e)      public void mouseReleased(MouseEvent e)
739      {      {
# Line 727  public class BasicInternalFrameUI extend Line 741  public class BasicInternalFrameUI extend
741      }      }
742    
743      /**      /**
744       * This method acquires a candidate component to dispatch the  MouseEvent       * This method acquires a candidate component to dispatch the MouseEvent to.
745       * to.       *
746       *       * @param me
747       * @param me The MouseEvent to acquire a component for.       *          The MouseEvent to acquire a component for.
748       */       */
749      private void acquireComponentForMouseEvent(MouseEvent me)      private void acquireComponentForMouseEvent(MouseEvent me)
750      {      {
# Line 740  public class BasicInternalFrameUI extend Line 754  public class BasicInternalFrameUI extend
754        // Find the candidate which should receive this event.        // Find the candidate which should receive this event.
755        Component parent = frame.getContentPane();        Component parent = frame.getContentPane();
756        if (parent == null)        if (parent == null)
757          return;          return;
758        Component candidate = null;        Component candidate = null;
759        Point p = me.getPoint();        Point p = me.getPoint();
760        while (candidate == null && parent != null)        while (candidate == null && parent != null)
761          {          {
762            candidate = SwingUtilities.getDeepestComponentAt(parent, p.x, p.y);            candidate = SwingUtilities.getDeepestComponentAt(parent, p.x, p.y);
763            if (candidate == null)            if (candidate == null)
764              {              {
765                p = SwingUtilities.convertPoint(parent, p.x, p.y,                p = SwingUtilities.convertPoint(parent, p.x, p.y,
766                                                parent.getParent());                                                parent.getParent());
767                parent = parent.getParent();                parent = parent.getParent();
768              }              }
769          }          }
770    
771        // If the only candidate we found was the native container itself,        // If the only candidate we found was the native container itself,
772        // don't dispatch any event at all.  We only care about the lightweight        // don't dispatch any event at all. We only care about the lightweight
773        // children here.        // children here.
774        if (candidate == frame.getContentPane())        if (candidate == frame.getContentPane())
775          candidate = null;          candidate = null;
776    
777        // If our candidate is new, inform the old target we're leaving.        // If our candidate is new, inform the old target we're leaving.
778        if (lastComponentEntered != null && lastComponentEntered.isShowing()        if (lastComponentEntered != null && lastComponentEntered.isShowing()
779            && lastComponentEntered != candidate)            && lastComponentEntered != candidate)
780          {          {
781            Point tp = SwingUtilities.convertPoint(frame.getContentPane(), x, y,            Point tp = SwingUtilities.convertPoint(frame.getContentPane(), x, y,
782                                                   lastComponentEntered);                                                   lastComponentEntered);
783            MouseEvent exited = new MouseEvent(lastComponentEntered,            MouseEvent exited = new MouseEvent(lastComponentEntered,
784                                               MouseEvent.MOUSE_EXITED,                                               MouseEvent.MOUSE_EXITED,
785                                               me.getWhen(), me.getModifiersEx(),                                               me.getWhen(), me.getModifiersEx(),
786                                               tp.x, tp.y, me.getClickCount(),                                               tp.x, tp.y, me.getClickCount(),
787                                               me.isPopupTrigger(),                                               me.isPopupTrigger(),
788                                               me.getButton());                                               me.getButton());
789            tempComponent = lastComponentEntered;            tempComponent = lastComponentEntered;
790            lastComponentEntered = null;            lastComponentEntered = null;
791            tempComponent.dispatchEvent(exited);            tempComponent.dispatchEvent(exited);
792          }          }
793    
794        // If we have a candidate, maybe enter it.        // If we have a candidate, maybe enter it.
795        if (candidate != null)        if (candidate != null)
796          {          {
797            mouseEventTarget = candidate;            mouseEventTarget = candidate;
798            if (candidate.isLightweight() && candidate.isShowing()            if (candidate.isLightweight() && candidate.isShowing()
799                && candidate != frame.getContentPane()                && candidate != frame.getContentPane()
800                && candidate != lastComponentEntered)                && candidate != lastComponentEntered)
801              {              {
802                lastComponentEntered = mouseEventTarget;                lastComponentEntered = mouseEventTarget;
803                Point cp = SwingUtilities.convertPoint(frame.getContentPane(),                Point cp = SwingUtilities.convertPoint(frame.getContentPane(), x,
804                                                       x, y, lastComponentEntered);                                                       y, lastComponentEntered);
805                MouseEvent entered = new MouseEvent(lastComponentEntered,                MouseEvent entered = new MouseEvent(lastComponentEntered,
806                                                    MouseEvent.MOUSE_ENTERED,                                                    MouseEvent.MOUSE_ENTERED,
807                                                    me.getWhen(),                                                    me.getWhen(),
808                                                    me.getModifiersEx(), cp.x,                                                    me.getModifiersEx(), cp.x,
809                                                    cp.y, me.getClickCount(),                                                    cp.y, me.getClickCount(),
810                                                    me.isPopupTrigger(),                                                    me.isPopupTrigger(),
811                                                    me.getButton());                                                    me.getButton());
812                lastComponentEntered.dispatchEvent(entered);                lastComponentEntered.dispatchEvent(entered);
813              }              }
814          }          }
815    
816        if (me.getID() == MouseEvent.MOUSE_RELEASED        if (me.getID() == MouseEvent.MOUSE_RELEASED
817            || me.getID() == MouseEvent.MOUSE_PRESSED && pressCount > 0            || me.getID() == MouseEvent.MOUSE_PRESSED && pressCount > 0
818            || me.getID() == MouseEvent.MOUSE_DRAGGED)            || me.getID() == MouseEvent.MOUSE_DRAGGED)
819          // If any of the following events occur while a button is held down,          // If any of the following events occur while a button is held down,
820          // they should be dispatched to the same component to which the          // they should be dispatched to the same component to which the
821          // original MOUSE_PRESSED event was dispatched:          // original MOUSE_PRESSED event was dispatched:
822          //   - MOUSE_RELEASED          // - MOUSE_RELEASED
823          //   - MOUSE_PRESSED: another button pressed while the first is held down          // - MOUSE_PRESSED: another button pressed while the first is held down
824          //   - MOUSE_DRAGGED          // - MOUSE_DRAGGED
825          mouseEventTarget = pressedComponent;          mouseEventTarget = pressedComponent;
826        else if (me.getID() == MouseEvent.MOUSE_CLICKED)        else if (me.getID() == MouseEvent.MOUSE_CLICKED)
827          {          {
828            // Don't dispatch CLICKED events whose target is not the same as the            // Don't dispatch CLICKED events whose target is not the same as the
829            // target for the original PRESSED event.            // target for the original PRESSED event.
830            if (candidate != pressedComponent)            if (candidate != pressedComponent)
831              mouseEventTarget = null;              mouseEventTarget = null;
832            else if (pressCount == 0)            else if (pressCount == 0)
833              pressedComponent = null;              pressedComponent = null;
834          }          }
835      }      }
836    
837      /**      /**
838       * This is a helper method that dispatches the GlassPane MouseEvents to       * This is a helper method that dispatches the GlassPane MouseEvents to the
839       * the proper component.       * proper component.
840       *       *
841       * @param e The AWTEvent to be dispatched. Usually an instance of       * @param e
842       *        MouseEvent.       *          The AWTEvent to be dispatched. Usually an instance of
843         *          MouseEvent.
844       */       */
845      private void handleEvent(AWTEvent e)      private void handleEvent(AWTEvent e)
846      {      {
847        if (e instanceof MouseEvent)        if (e instanceof MouseEvent)
848          {          {
849            MouseEvent me = SwingUtilities.convertMouseEvent(frame.getRootPane()            MouseEvent me = SwingUtilities.convertMouseEvent(
850                                                                  .getGlassPane(),                                                             frame.getRootPane().getGlassPane(),
851                                                             (MouseEvent) e,                                                             (MouseEvent) e,
852                                                             frame.getRootPane()                                                             frame.getRootPane().getGlassPane());
853                                                                  .getGlassPane());  
854              acquireComponentForMouseEvent(me);
855            acquireComponentForMouseEvent(me);  
856              // Avoid dispatching ENTERED and EXITED events twice.
857            // Avoid dispatching ENTERED and EXITED events twice.            if (mouseEventTarget != null && mouseEventTarget.isShowing()
858            if (mouseEventTarget != null && mouseEventTarget.isShowing()                && e.getID() != MouseEvent.MOUSE_ENTERED
859                && e.getID() != MouseEvent.MOUSE_ENTERED                && e.getID() != MouseEvent.MOUSE_EXITED)
860                && e.getID() != MouseEvent.MOUSE_EXITED)              {
861              {                MouseEvent newEvt = SwingUtilities.convertMouseEvent(
862                MouseEvent newEvt = SwingUtilities.convertMouseEvent(frame                                                                     frame.getContentPane(),
863                                                                     .getContentPane(),                                                                     me,
864                                                                     me,                                                                     mouseEventTarget);
865                                                                     mouseEventTarget);                mouseEventTarget.dispatchEvent(newEvt);
866                mouseEventTarget.dispatchEvent(newEvt);  
867                  switch (e.getID())
868                switch (e.getID())                  {
869                  {                  case MouseEvent.MOUSE_PRESSED:
870                  case MouseEvent.MOUSE_PRESSED:                    if (pressCount++ == 0)
871                    if (pressCount++ == 0)                      pressedComponent = mouseEventTarget;
872                      pressedComponent = mouseEventTarget;                    break;
873                    break;                  case MouseEvent.MOUSE_RELEASED:
874                  case MouseEvent.MOUSE_RELEASED:                    // Clear our memory of the original PRESSED event, only if
875                    // Clear our memory of the original PRESSED event, only if                    // we're not expecting a CLICKED event after this. If
876                    // we're not expecting a CLICKED event after this. If                    // there is a CLICKED event after this, it will do clean up.
877                    // there is a CLICKED event after this, it will do clean up.                    if (--pressCount == 0 && mouseEventTarget != pressedComponent)
878                    if (--pressCount == 0                      pressedComponent = null;
879                        && mouseEventTarget != pressedComponent)                    break;
880                      pressedComponent = null;                  }
881                    break;              }
                 }  
             }  
882          }          }
883      }      }
884    }    }
# Line 874  public class BasicInternalFrameUI extend Line 887  public class BasicInternalFrameUI extend
887     * This helper class listens for PropertyChangeEvents from the     * This helper class listens for PropertyChangeEvents from the
888     * JInternalFrame.     * JInternalFrame.
889     */     */
890    public class InternalFramePropertyChangeListener    public class InternalFramePropertyChangeListener implements
891      implements PropertyChangeListener, VetoableChangeListener        PropertyChangeListener, VetoableChangeListener
892    {    {
893    
894      /**      /**
895       * This method is called when one of the JInternalFrame's properties       * This method is called when one of the JInternalFrame's properties change.
896       * change.  This method is to allow JInternalFrame to veto an attempt       * This method is to allow JInternalFrame to veto an attempt to close the
897       * to close the internal frame.  This allows JInternalFrame to honour       * internal frame. This allows JInternalFrame to honour its
898       * its defaultCloseOperation if that is DO_NOTHING_ON_CLOSE.       * defaultCloseOperation if that is DO_NOTHING_ON_CLOSE.
899       */       */
900      public void vetoableChange(PropertyChangeEvent e) throws PropertyVetoException      public void vetoableChange(PropertyChangeEvent e)
901            throws PropertyVetoException
902      {      {
903        if (e.getPropertyName().equals(JInternalFrame.IS_CLOSED_PROPERTY))        if (e.getPropertyName().equals(JInternalFrame.IS_CLOSED_PROPERTY))
904          {          {
# Line 892  public class BasicInternalFrameUI extend Line 906  public class BasicInternalFrameUI extend
906              {              {
907                frame.setVisible(false);                frame.setVisible(false);
908                frame.getDesktopPane().repaint();                frame.getDesktopPane().repaint();
909                throw new PropertyVetoException ("close operation is HIDE_ON_CLOSE\n", e);                throw new PropertyVetoException(
910                                                  "close operation is HIDE_ON_CLOSE\n",
911                                                  e);
912              }              }
913            else if (frame.getDefaultCloseOperation() == JInternalFrame.DISPOSE_ON_CLOSE)            else if (frame.getDefaultCloseOperation() == JInternalFrame.DISPOSE_ON_CLOSE)
914              closeFrame(frame);              closeFrame(frame);
915            else            else
916              throw new PropertyVetoException ("close operation is DO_NOTHING_ON_CLOSE\n", e);              throw new PropertyVetoException(
917                                                "close operation is DO_NOTHING_ON_CLOSE\n",
918                                                e);
919          }          }
920      }      }
921        
922      /**      /**
923       * This method is called when one of the JInternalFrame's properties       * This method is called when one of the JInternalFrame's properties change.
924       * change.       *
925       *       * @param evt
926       * @param evt The PropertyChangeEvent.       *          The PropertyChangeEvent.
927       */       */
928      public void propertyChange(PropertyChangeEvent evt)      public void propertyChange(PropertyChangeEvent evt)
929      {      {
930        if (evt.getPropertyName().equals(JInternalFrame.IS_MAXIMUM_PROPERTY))        if (evt.getPropertyName().equals(JInternalFrame.IS_MAXIMUM_PROPERTY))
931          {          {
932            if (frame.isMaximum())            if (frame.isMaximum())
933              maximizeFrame(frame);              maximizeFrame(frame);
934            else            else
935              minimizeFrame(frame);              minimizeFrame(frame);
936          }          }
937        else if (evt.getPropertyName().equals(JInternalFrame.IS_ICON_PROPERTY))        else if (evt.getPropertyName().equals(JInternalFrame.IS_ICON_PROPERTY))
938          {          {
939            if (frame.isIcon())            if (frame.isIcon())
940              iconifyFrame(frame);              iconifyFrame(frame);
941            else            else
942              deiconifyFrame(frame);              deiconifyFrame(frame);
943          }          }
944        else if (evt.getPropertyName().equals(JInternalFrame.IS_SELECTED_PROPERTY))        else if (evt.getPropertyName().equals(JInternalFrame.IS_SELECTED_PROPERTY))
945          {          {
946            if (frame.isSelected())            if (frame.isSelected())
947              activateFrame(frame);              activateFrame(frame);
948            else            else
949              getDesktopManager().deactivateFrame(frame);              getDesktopManager().deactivateFrame(frame);
950          }          }
951        else if (evt.getPropertyName().equals(JInternalFrame.ROOT_PANE_PROPERTY)        else if (evt.getPropertyName().equals(JInternalFrame.ROOT_PANE_PROPERTY)
952                 || evt.getPropertyName().equals(JInternalFrame.GLASS_PANE_PROPERTY))                 || evt.getPropertyName().equals(
953                                                   JInternalFrame.GLASS_PANE_PROPERTY))
954          {          {
955            Component old = (Component) evt.getOldValue();            Component old = (Component) evt.getOldValue();
956            old.removeMouseListener(glassPaneDispatcher);            old.removeMouseListener(glassPaneDispatcher);
957            old.removeMouseMotionListener(glassPaneDispatcher);            old.removeMouseMotionListener(glassPaneDispatcher);
958    
959            Component newPane = (Component) evt.getNewValue();            Component newPane = (Component) evt.getNewValue();
960            newPane.addMouseListener(glassPaneDispatcher);            newPane.addMouseListener(glassPaneDispatcher);
961            newPane.addMouseMotionListener(glassPaneDispatcher);            newPane.addMouseMotionListener(glassPaneDispatcher);
962    
963            frame.revalidate();            frame.revalidate();
964          }          }
965        /* FIXME: need to add ancestor properties to JComponents.        /*
966        else if (evt.getPropertyName().equals(JComponent.ANCESTOR_PROPERTY))         * FIXME: need to add ancestor properties to JComponents. else if
967        {         * (evt.getPropertyName().equals(JComponent.ANCESTOR_PROPERTY)) { if
968          if (desktopPane != null)         * (desktopPane != null)
969            desktopPane.removeComponentListener(componentListener);         * desktopPane.removeComponentListener(componentListener); desktopPane =
970          desktopPane = frame.getDesktopPane();         * frame.getDesktopPane(); if (desktopPane != null)
971          if (desktopPane != null)         * desktopPane.addComponentListener(componentListener); }
972            desktopPane.addComponentListener(componentListener);         */
       }  
       */  
973      }      }
974    }    }
975    
976    /**    /**
977     * This helper class is the border for the JInternalFrame.     * This helper class is the border for the JInternalFrame.
978     */     */
979    private class InternalFrameBorder extends AbstractBorder    private class InternalFrameBorder extends AbstractBorder implements
980      implements UIResource        UIResource
981    {    {
982      /** The width of the border. */      /** The width of the border. */
983      private static final int bSize = 5;      private static final int bSize = 5;
# Line 970  public class BasicInternalFrameUI extend Line 987  public class BasicInternalFrameUI extend
987    
988      /**      /**
989       * This method returns whether the border is opaque.       * This method returns whether the border is opaque.
990       *       *
991       * @return Whether the border is opaque.       * @return Whether the border is opaque.
992       */       */
993      public boolean isBorderOpaque()      public boolean isBorderOpaque()
# Line 980  public class BasicInternalFrameUI extend Line 997  public class BasicInternalFrameUI extend
997    
998      /**      /**
999       * This method returns the insets of the border.       * This method returns the insets of the border.
1000       *       *
1001       * @param c The Component to find border insets for.       * @param c
1002       *       *          The Component to find border insets for.
1003       * @return The border insets.       * @return The border insets.
1004       */       */
1005      public Insets getBorderInsets(Component c)      public Insets getBorderInsets(Component c)
# Line 992  public class BasicInternalFrameUI extend Line 1009  public class BasicInternalFrameUI extend
1009    
1010      /**      /**
1011       * This method paints the border.       * This method paints the border.
1012       *       *
1013       * @param c The Component that owns the border.       * @param c
1014       * @param g The Graphics object to paint with.       *          The Component that owns the border.
1015       * @param x The x coordinate to paint at.       * @param g
1016       * @param y The y coordinate to paint at.       *          The Graphics object to paint with.
1017       * @param width The width of the Component.       * @param x
1018       * @param height The height of the Component.       *          The x coordinate to paint at.
1019         * @param y
1020         *          The y coordinate to paint at.
1021         * @param width
1022         *          The width of the Component.
1023         * @param height
1024         *          The height of the Component.
1025       */       */
1026      public void paintBorder(Component c, Graphics g, int x, int y, int width,      public void paintBorder(Component c, Graphics g, int x, int y, int width,
1027                              int height)                              int height)
# Line 1135  public class BasicInternalFrameUI extend Line 1158  public class BasicInternalFrameUI extend
1158    {    {
1159      if (c instanceof JInternalFrame)      if (c instanceof JInternalFrame)
1160        {        {
1161          frame = (JInternalFrame) c;          frame = (JInternalFrame) c;
1162    
1163          internalFrameLayout = createLayoutManager();          internalFrameLayout = createLayoutManager();
1164          frame.setLayout(internalFrameLayout);          frame.setLayout(internalFrameLayout);
1165    
1166          ((JComponent) frame.getRootPane().getGlassPane()).setOpaque(false);          ((JComponent) frame.getRootPane().getGlassPane()).setOpaque(false);
1167          frame.getRootPane().getGlassPane().setVisible(true);          frame.getRootPane().getGlassPane().setVisible(true);
1168    
1169          installDefaults();          installDefaults();
1170          installListeners();          installListeners();
1171          installComponents();          installComponents();
1172          installKeyboardActions();          installKeyboardActions();
1173    
1174          frame.setOpaque(true);          frame.setOpaque(true);
1175          frame.invalidate();          frame.invalidate();
1176        }        }
1177    }    }
1178    
# Line 1343  public class BasicInternalFrameUI extend Line 1366  public class BasicInternalFrameUI extend
1366    {    {
1367      if (currentPane != null)      if (currentPane != null)
1368        {        {
1369          deinstallMouseHandlers(currentPane);          deinstallMouseHandlers(currentPane);
1370          frame.remove(currentPane);          frame.remove(currentPane);
1371        }        }
1372    
1373      if (newPane != null)      if (newPane != null)
1374        {        {
1375          installMouseHandlers(newPane);          installMouseHandlers(newPane);
1376          frame.add(newPane);          frame.add(newPane);
1377        }        }
1378    }    }
1379    

Legend:
Removed from v.1.16  
changed lines
  Added in v.1.17

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26