/[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.1 by mark, Sat Jun 26 16:07:02 2004 UTC revision 1.2 by mark, Thu Jul 22 19:45:39 2004 UTC
# Line 37  exception statement from your version. * Line 37  exception statement from your version. *
37    
38  package javax.swing.plaf.basic;  package javax.swing.plaf.basic;
39    
40    import java.awt.AWTEvent;
41  import java.awt.Color;  import java.awt.Color;
42  import java.awt.Component;  import java.awt.Component;
43  import java.awt.Container;  import java.awt.Container;
# Line 179  public class BasicInternalFrameUI extend Line 180  public class BasicInternalFrameUI extend
180      /** The direction that the resize is occuring in. */      /** The direction that the resize is occuring in. */
181      private transient int direction = -1;      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.       * This method is called when the mouse is clicked.
188       *       *
# Line 204  public class BasicInternalFrameUI extend Line 208  public class BasicInternalFrameUI extend
208          return;          return;
209        DesktopManager dm = getDesktopManager();        DesktopManager dm = getDesktopManager();
210        Rectangle b = frame.getBounds();        Rectangle b = frame.getBounds();
211          Dimension min = frame.getMinimumSize();
212          if (min == null)
213            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();
# Line 212  public class BasicInternalFrameUI extend Line 219  public class BasicInternalFrameUI extend
219            switch (direction)            switch (direction)
220              {              {
221              case NORTH:              case NORTH:
222                dm.resizeFrame(frame, b.x, b.y + y, b.width, b.height - y);                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;                break;
227              case NORTH_EAST:              case NORTH_EAST:
228                dm.resizeFrame(frame, b.x, b.y + y, x, b.height - y);                cacheRect.setBounds(b.x,
229                                      Math.min(b.y + y, b.y + b.height
230                                               - min.height), x, b.height - y);
231                break;                break;
232              case EAST:              case EAST:
233                dm.resizeFrame(frame, b.x, b.y, x, b.height);                cacheRect.setBounds(b.x, b.y, x, b.height);
234                break;                break;
235              case SOUTH_EAST:              case SOUTH_EAST:
236                dm.resizeFrame(frame, b.x, b.y, x, y);                cacheRect.setBounds(b.x, b.y, x, y);
237                break;                break;
238              case SOUTH:              case SOUTH:
239                dm.resizeFrame(frame, b.x, b.y, b.width, y);                cacheRect.setBounds(b.x, b.y, b.width, y);
240                break;                break;
241              case SOUTH_WEST:              case SOUTH_WEST:
242                dm.resizeFrame(frame, b.x + x, b.y, b.width - x, y);                cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width),
243                                      b.y, b.width - x, y);
244                break;                break;
245              case WEST:              case WEST:
246                dm.resizeFrame(frame, b.x + x, b.y, b.width - x, b.height);                cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width),
247                                      b.y, b.width - x, b.height);
248                break;                break;
249              case NORTH_WEST:              case NORTH_WEST:
250                dm.resizeFrame(frame, b.x + x, b.y + y, b.width - x, b.height                cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width),
251                               - y);                                    Math.min(b.y + y, b.y + b.height
252                                               - min.height), b.width - x,
253                                      b.height - y);
254                break;                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)        else if (e.getSource() == titlePane)
261          {          {
# Line 498  public class BasicInternalFrameUI extend Line 517  public class BasicInternalFrameUI extend
517       */       */
518      public Dimension minimumLayoutSize(Container c)      public Dimension minimumLayoutSize(Container c)
519      {      {
520        return preferredLayoutSize(c);        return getSize(c, true);
521      }      }
522    
523      /**      /**
# Line 522  public class BasicInternalFrameUI extend Line 541  public class BasicInternalFrameUI extend
541       */       */
542      public Dimension preferredLayoutSize(Container c)      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();        Insets insets = frame.getInsets();
558    
559        Dimension contentDims = frame.getContentPane().getPreferredSize();        Dimension contentDims = frame.getContentPane().getPreferredSize();
560          if (min)
561            contentDims.width = contentDims.height = 0;
562        int nWidth = 0;        int nWidth = 0;
563        int nHeight = 0;        int nHeight = 0;
564        int sWidth = 0;        int sWidth = 0;
# Line 578  public class BasicInternalFrameUI extend Line 612  public class BasicInternalFrameUI extend
612        int width = Math.max(sWidth, nWidth);        int width = Math.max(sWidth, nWidth);
613        width = Math.max(width, contentDims.width + eWidth + wWidth);        width = Math.max(width, contentDims.width + eWidth + wWidth);
614    
615        int height = Math.max(contentDims.height, eHeight);        int height = Math.max(eHeight, wHeight);
616        height = Math.max(height, wHeight);        height = Math.max(height, contentDims.height);
617        height += nHeight + sHeight;        height += nHeight + sHeight;
618    
619        width += insets.left + insets.right;        width += insets.left + insets.right;
# Line 606  public class BasicInternalFrameUI extend Line 640  public class BasicInternalFrameUI extend
640     */     */
641    protected class GlassPaneDispatcher implements MouseInputListener    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        /** The number of presses. */
653        private transient int pressCount;
654    
655      /**      /**
656       * This method is called when the mouse enters the glass pane.       * This method is called when the mouse enters the glass pane.
657       *       *
# Line 613  public class BasicInternalFrameUI extend Line 659  public class BasicInternalFrameUI extend
659       */       */
660      public void mouseEntered(MouseEvent e)      public void mouseEntered(MouseEvent e)
661      {      {
662        dispatchFor(e);        handleEvent(e);
663      }      }
664    
665      /**      /**
# Line 623  public class BasicInternalFrameUI extend Line 669  public class BasicInternalFrameUI extend
669       */       */
670      public void mouseClicked(MouseEvent e)      public void mouseClicked(MouseEvent e)
671      {      {
672        dispatchFor(e);        handleEvent(e);
673      }      }
674    
675      /**      /**
# Line 633  public class BasicInternalFrameUI extend Line 679  public class BasicInternalFrameUI extend
679       */       */
680      public void mouseDragged(MouseEvent e)      public void mouseDragged(MouseEvent e)
681      {      {
682        dispatchFor(e);        handleEvent(e);
683      }      }
684    
685      /**      /**
# Line 643  public class BasicInternalFrameUI extend Line 689  public class BasicInternalFrameUI extend
689       */       */
690      public void mouseExited(MouseEvent e)      public void mouseExited(MouseEvent e)
691      {      {
692        dispatchFor(e);        handleEvent(e);
693      }      }
694    
695      /**      /**
# Line 653  public class BasicInternalFrameUI extend Line 699  public class BasicInternalFrameUI extend
699       */       */
700      public void mouseMoved(MouseEvent e)      public void mouseMoved(MouseEvent e)
701      {      {
702        dispatchFor(e);        handleEvent(e);
703      }      }
704    
705      /**      /**
# Line 664  public class BasicInternalFrameUI extend Line 710  public class BasicInternalFrameUI extend
710      public void mousePressed(MouseEvent e)      public void mousePressed(MouseEvent e)
711      {      {
712        activateFrame(frame);        activateFrame(frame);
713        dispatchFor(e);        handleEvent(e);
714      }      }
715    
716      /**      /**
# Line 674  public class BasicInternalFrameUI extend Line 720  public class BasicInternalFrameUI extend
720       */       */
721      public void mouseReleased(MouseEvent e)      public void mouseReleased(MouseEvent e)
722      {      {
723        dispatchFor(e);        handleEvent(e);
724      }      }
725    
726      /**      /**
727       * This helper method redispatches the MouseEvent to the  proper sub       * This method acquires a candidate component to dispatch the  MouseEvent
728       * component.       * to.
729       *       *
730       * @param e The MouseEvent.       * @param me The MouseEvent to acquire a component for.
731       */       */
732      private void dispatchFor(MouseEvent e)      private void acquireComponentForMouseEvent(MouseEvent me)
733      {      {
734        Component candidate = SwingUtilities.getDeepestComponentAt(frame.getRootPane()        int x = me.getX();
735                                                                        .getContentPane(),        int y = me.getY();
736                                                                   e.getX(),  
737                                                                   e.getY());        // Find the candidate which should receive this event.
738        if (candidate == null || candidate == frame.getRootPane().getGlassPane())        Component parent = frame.getContentPane();
739          if (parent == null)
740          return;          return;
741        MouseEvent newevt = SwingUtilities.convertMouseEvent(frame.getRootPane()        Component candidate = null;
742          Point p = me.getPoint();
743          while (candidate == null && parent != null)
744            {
745              candidate = SwingUtilities.getDeepestComponentAt(parent, p.x, p.y);
746              if (candidate == null)
747                {
748                  p = SwingUtilities.convertPoint(parent, p.x, p.y,
749                                                  parent.getParent());
750                  parent = parent.getParent();
751                }
752            }
753    
754          // If the only candidate we found was the native container itself,
755          // don't dispatch any event at all.  We only care about the lightweight
756          // children here.
757          if (candidate == frame.getContentPane())
758            candidate = null;
759    
760          // If our candidate is new, inform the old target we're leaving.
761          if (lastComponentEntered != null && lastComponentEntered.isShowing()
762              && lastComponentEntered != candidate)
763            {
764              Point tp = SwingUtilities.convertPoint(frame.getContentPane(), x, y,
765                                                     lastComponentEntered);
766              MouseEvent exited = new MouseEvent(lastComponentEntered,
767                                                 MouseEvent.MOUSE_EXITED,
768                                                 me.getWhen(), me.getModifiers(),
769                                                 tp.x, tp.y, me.getClickCount(),
770                                                 me.isPopupTrigger(),
771                                                 me.getButton());
772              lastComponentEntered.dispatchEvent(exited);
773              lastComponentEntered = null;
774            }
775    
776          // If we have a candidate, maybe enter it.
777          if (candidate != null)
778            {
779              mouseEventTarget = candidate;
780              if (candidate.isLightweight() && candidate.isShowing()
781                  && candidate != frame.getContentPane()
782                  && candidate != lastComponentEntered)
783                {
784                  lastComponentEntered = mouseEventTarget;
785                  Point cp = SwingUtilities.convertPoint(frame.getContentPane(),
786                                                         x, y, lastComponentEntered);
787                  MouseEvent entered = new MouseEvent(lastComponentEntered,
788                                                      MouseEvent.MOUSE_ENTERED,
789                                                      me.getWhen(),
790                                                      me.getModifiers(), cp.x,
791                                                      cp.y, me.getClickCount(),
792                                                      me.isPopupTrigger(),
793                                                      me.getButton());
794                  lastComponentEntered.dispatchEvent(entered);
795                }
796            }
797    
798          if (me.getID() == MouseEvent.MOUSE_RELEASED
799              || me.getID() == MouseEvent.MOUSE_PRESSED && pressCount > 0
800              || me.getID() == MouseEvent.MOUSE_DRAGGED)
801            // If any of the following events occur while a button is held down,
802            // they should be dispatched to the same component to which the
803            // original MOUSE_PRESSED event was dispatched:
804            //   - MOUSE_RELEASED
805            //   - MOUSE_PRESSED: another button pressed while the first is held down
806            //   - MOUSE_DRAGGED
807            mouseEventTarget = pressedComponent;
808          else if (me.getID() == MouseEvent.MOUSE_CLICKED)
809            {
810              // Don't dispatch CLICKED events whose target is not the same as the
811              // target for the original PRESSED event.
812              if (candidate != pressedComponent)
813                mouseEventTarget = null;
814              else if (pressCount == 0)
815                pressedComponent = null;
816            }
817        }
818    
819        /**
820         * This is a helper method that dispatches the GlassPane MouseEvents to
821         * the proper component.
822         *
823         * @param e The AWTEvent to be dispatched. Usually an instance of
824         *        MouseEvent.
825         */
826        private void handleEvent(AWTEvent e)
827        {
828          if (e instanceof MouseEvent)
829            {
830              MouseEvent me = SwingUtilities.convertMouseEvent(frame.getRootPane()
831                                                                  .getGlassPane(),                                                                  .getGlassPane(),
832                                                             e, candidate);                                                             (MouseEvent) e,
833        candidate.dispatchEvent(newevt);                                                             frame.getRootPane()
834                                                                    .getGlassPane());
835    
836              acquireComponentForMouseEvent(me);
837    
838              // Avoid dispatching ENTERED and EXITED events twice.
839              if (mouseEventTarget != null && mouseEventTarget.isShowing()
840                  && e.getID() != MouseEvent.MOUSE_ENTERED
841                  && e.getID() != MouseEvent.MOUSE_EXITED)
842                {
843                  MouseEvent newEvt = SwingUtilities.convertMouseEvent(frame
844                                                                       .getContentPane(),
845                                                                       me,
846                                                                       mouseEventTarget);
847                  mouseEventTarget.dispatchEvent(newEvt);
848    
849                  switch (e.getID())
850                    {
851                    case MouseEvent.MOUSE_PRESSED:
852                      if (pressCount++ == 0)
853                        pressedComponent = mouseEventTarget;
854                      break;
855                    case MouseEvent.MOUSE_RELEASED:
856                      // Clear our memory of the original PRESSED event, only if
857                      // we're not expecting a CLICKED event after this. If
858                      // there is a CLICKED event after this, it will do clean up.
859                      if (--pressCount == 0
860                          && mouseEventTarget != pressedComponent)
861                        pressedComponent = null;
862                      break;
863                    }
864                }
865            }
866      }      }
867    }    }
868    
# Line 1108  public class BasicInternalFrameUI extend Line 1276  public class BasicInternalFrameUI extend
1276     */     */
1277    public Dimension getMinimumSize(JComponent x)    public Dimension getMinimumSize(JComponent x)
1278    {    {
1279      return getPreferredSize(x);      return internalFrameLayout.minimumLayoutSize(x);
1280    }    }
1281    
1282    /**    /**

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

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