/[classpath]/classpath/java/awt/Component.java
ViewVC logotype

Diff of /classpath/java/awt/Component.java

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

revision 1.34 by mark, Sat Jun 26 16:06:48 2004 UTC revision 1.35 by mark, Thu Jul 22 19:45:38 2004 UTC
# Line 39  exception statement from your version. * Line 39  exception statement from your version. *
39  package java.awt;  package java.awt;
40    
41  import java.awt.dnd.DropTarget;  import java.awt.dnd.DropTarget;
42    import java.awt.event.ActionEvent;
43  import java.awt.event.ComponentEvent;  import java.awt.event.ComponentEvent;
44  import java.awt.event.ComponentListener;  import java.awt.event.ComponentListener;
45  import java.awt.event.FocusEvent;  import java.awt.event.FocusEvent;
# Line 48  import java.awt.event.HierarchyEvent; Line 49  import java.awt.event.HierarchyEvent;
49  import java.awt.event.HierarchyListener;  import java.awt.event.HierarchyListener;
50  import java.awt.event.KeyEvent;  import java.awt.event.KeyEvent;
51  import java.awt.event.KeyListener;  import java.awt.event.KeyListener;
52    import java.awt.event.InputEvent;
53  import java.awt.event.InputMethodEvent;  import java.awt.event.InputMethodEvent;
54  import java.awt.event.InputMethodListener;  import java.awt.event.InputMethodListener;
55  import java.awt.event.MouseEvent;  import java.awt.event.MouseEvent;
# Line 1175  public abstract class Component Line 1177  public abstract class Component
1177     */     */
1178    public void move(int x, int y)    public void move(int x, int y)
1179    {    {
1180      int oldx = this.x;      setBounds(x, y, this.width, this.height);
     int oldy = this.y;  
   
     if (this.x == x && this.y == y)  
       return;  
     invalidate ();  
     this.x = x;  
     this.y = y;  
     if (peer != null)  
       peer.setBounds (x, y, width, height);  
   
     // Erase old bounds and repaint new bounds for lightweights.  
     if (isLightweight() && width != 0 && height !=0)  
       {  
         parent.repaint(oldx, oldy, width, height);  
         repaint();  
       }  
   
     if (oldx != x || oldy != y)  
       {  
         ComponentEvent ce = new ComponentEvent(this,  
                                                ComponentEvent.COMPONENT_MOVED);  
         getToolkit().getSystemEventQueue().postEvent(ce);  
       }  
1181    }    }
1182    
1183    /**    /**
# Line 1262  public abstract class Component Line 1241  public abstract class Component
1241     */     */
1242    public void resize(int width, int height)    public void resize(int width, int height)
1243    {    {
1244      int oldwidth = this.width;      setBounds(this.x, this.y, width, height);
     int oldheight = this.height;  
   
     if (this.width == width && this.height == height)  
       return;  
     invalidate ();  
     this.width = width;  
     this.height = height;  
     if (peer != null)  
       peer.setBounds (x, y, width, height);  
   
     // Erase old bounds and repaint new bounds for lightweights.  
     if (isLightweight())  
       {  
         if (oldwidth != 0 && oldheight != 0 && parent != null)  
           parent.repaint(x, y, oldwidth, oldheight);  
         if (width != 0 && height != 0)  
           repaint();  
       }  
   
     if (oldwidth != width || oldheight != height)  
       {  
         ComponentEvent ce =  
           new ComponentEvent(this, ComponentEvent.COMPONENT_RESIZED);  
         getToolkit().getSystemEventQueue().postEvent(ce);  
       }  
1245    }    }
1246    
1247    /**    /**
# Line 1395  public abstract class Component Line 1349  public abstract class Component
1349      // Erase old bounds and repaint new bounds for lightweights.      // Erase old bounds and repaint new bounds for lightweights.
1350      if (isLightweight())      if (isLightweight())
1351        {        {
1352          if (oldwidth != 0 && oldheight != 0 && parent != null)          boolean shouldRepaintParent = false;
1353            boolean shouldRepaintSelf = false;
1354    
1355            if (parent != null)
1356              {
1357                Rectangle parentBounds = parent.getBounds();
1358                Rectangle oldBounds = new Rectangle(parent.getX() + oldx,
1359                                                    parent.getY() + oldy,
1360                                                    oldwidth, oldheight);
1361                Rectangle newBounds = new Rectangle(parent.getX() + x,
1362                                                    parent.getY() + y,
1363                                                    width, height);
1364                shouldRepaintParent = parentBounds.intersects(oldBounds);
1365                shouldRepaintSelf = parentBounds.intersects(newBounds);
1366              }
1367    
1368            if (shouldRepaintParent)
1369            parent.repaint(oldx, oldy, oldwidth, oldheight);            parent.repaint(oldx, oldy, oldwidth, oldheight);
1370          if (width != 0 && height != 0)          if (shouldRepaintSelf)
1371            repaint();            repaint();
1372        }        }
1373    
# Line 2255  public abstract class Component Line 2225  public abstract class Component
2225    }    }
2226    
2227    /**    /**
2228     * AWT 1.0 event dispatcher.     * AWT 1.0 event delivery.
2229     *     *
2230     * @param e the event to dispatch     * Deliver an AWT 1.0 event to this Component.  This method simply
2231       * calls {@link #postEvent}.
2232       *
2233       * @param e the event to deliver
2234     * @deprecated use {@link #dispatchEvent(AWTEvent)} instead     * @deprecated use {@link #dispatchEvent(AWTEvent)} instead
2235     */     */
2236    public void deliverEvent(Event e)    public void deliverEvent(Event e)
2237    {    {
2238      // XXX Add backward compatibility handling.      postEvent (e);
2239    }    }
2240    
2241    /**    /**
# Line 2284  public abstract class Component Line 2257  public abstract class Component
2257    }    }
2258    
2259    /**    /**
2260     * AWT 1.0 event dispatcher.     * AWT 1.0 event handler.
2261     *     *
2262     * @param e the event to dispatch     * This method simply calls handleEvent and returns the result.
2263     * @return false: since the method was deprecated, the return has no meaning     *
2264       * @param e the event to handle
2265       * @return the result of handling <code>e</code>
2266     * @deprecated use {@link #dispatchEvent(AWTEvent)} instead     * @deprecated use {@link #dispatchEvent(AWTEvent)} instead
2267     */     */
2268    public boolean postEvent(Event e)    public boolean postEvent(Event e)
2269    {    {
2270      // XXX Add backward compatibility handling.      boolean handled = handleEvent (e);
2271      return false;  
2272        if (!handled)
2273          // FIXME: need to translate event coordinates to parent's
2274          // coordinate space.
2275          handled = getParent ().postEvent (e);
2276    
2277        return handled;
2278    }    }
2279    
2280    /**    /**
# Line 3170  public abstract class Component Line 3151  public abstract class Component
3151    }    }
3152    
3153    /**    /**
3154     * AWT 1.0 event processor.     * AWT 1.0 event handler.
3155       *
3156       * This method calls one of the event-specific handler methods.  For
3157       * example for key events, either {@link #keyDown (Event evt, int
3158       * key)} or {@link keyUp (Event evt, int key)} is called.  A derived
3159       * component can override one of these event-specific methods if it
3160       * only needs to handle certain event types.  Otherwise it can
3161       * override handleEvent itself and handle any event.
3162     *     *
3163     * @param evt the event to handle     * @param evt the event to handle
3164     * @return false: since the method was deprecated, the return has no meaning     * @return true if the event was handled, false otherwise
3165     * @deprecated use {@link #processEvent(AWTEvent)} instead     * @deprecated use {@link #processEvent(AWTEvent)} instead
3166     */     */
3167    public boolean handleEvent(Event evt)    public boolean handleEvent(Event evt)
3168    {    {
3169      // XXX Add backward compatibility handling.      switch (evt.id)
3170          {
3171            // Handle key events.
3172          case Event.KEY_ACTION:
3173          case Event.KEY_PRESS:
3174            return keyDown (evt, evt.key);
3175          case Event.KEY_ACTION_RELEASE:
3176          case Event.KEY_RELEASE:
3177            return keyUp (evt, evt.key);
3178    
3179            // Handle mouse events.
3180          case Event.MOUSE_DOWN:
3181            return mouseDown (evt, evt.x, evt.y);
3182          case Event.MOUSE_UP:
3183            return mouseUp (evt, evt.x, evt.y);
3184          case Event.MOUSE_MOVE:
3185            return mouseMove (evt, evt.x, evt.y);
3186          case Event.MOUSE_DRAG:
3187            return mouseDrag (evt, evt.x, evt.y);
3188          case Event.MOUSE_ENTER:
3189            return mouseEnter (evt, evt.x, evt.y);
3190          case Event.MOUSE_EXIT:
3191            return mouseExit (evt, evt.x, evt.y);
3192    
3193            // Handle focus events.
3194          case Event.GOT_FOCUS:
3195            return gotFocus (evt, evt.arg);
3196          case Event.LOST_FOCUS:
3197            return lostFocus (evt, evt.arg);
3198    
3199            // Handle action event.
3200          case Event.ACTION_EVENT:
3201            return action (evt, evt.arg);
3202          }
3203        // Unknown event.
3204      return false;      return false;
3205    }    }
3206    
3207    /**    /**
3208     * AWT 1.0 mouse event.     * AWT 1.0 mouse event handler.
3209     *     *
3210     * @param evt the event to handle     * @param evt the event to handle
3211     * @param x the x coordinate, ignored     * @param x the x coordinate, ignored
# Line 3686  public abstract class Component Line 3708  public abstract class Component
3708                      // lightweight component.  In either case we want to                      // lightweight component.  In either case we want to
3709                      // post a FOCUS_GAINED event.                      // post a FOCUS_GAINED event.
3710                      EventQueue eq = Toolkit.getDefaultToolkit ().getSystemEventQueue ();                      EventQueue eq = Toolkit.getDefaultToolkit ().getSystemEventQueue ();
3711                      eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED));                      synchronized (eq)
3712                          {
3713                            KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager ();
3714                            Component currentFocusOwner = manager.getGlobalPermanentFocusOwner ();
3715                            if (currentFocusOwner != null)
3716                              {
3717                                eq.postEvent (new FocusEvent(currentFocusOwner, FocusEvent.FOCUS_LOST,
3718                                                             false, this));
3719                                eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, false,
3720                                                             currentFocusOwner));
3721                              }
3722                            else
3723                              eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, false));
3724                          }
3725                    }                    }
3726                }                }
3727              else              else
# Line 3759  public abstract class Component Line 3794  public abstract class Component
3794                      // lightweight component.  In either case we want to                      // lightweight component.  In either case we want to
3795                      // post a FOCUS_GAINED event.                      // post a FOCUS_GAINED event.
3796                      EventQueue eq = Toolkit.getDefaultToolkit ().getSystemEventQueue ();                      EventQueue eq = Toolkit.getDefaultToolkit ().getSystemEventQueue ();
3797                        synchronized (eq)
3798                          {
3799                            KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager ();
3800                            Component currentFocusOwner = manager.getGlobalPermanentFocusOwner ();
3801                            if (currentFocusOwner != null)
3802                              {
3803                                eq.postEvent (new FocusEvent(currentFocusOwner,
3804                                                             FocusEvent.FOCUS_LOST,
3805                                                             temporary, this));
3806                                eq.postEvent (new FocusEvent(this,
3807                                                             FocusEvent.FOCUS_GAINED,
3808                                                             temporary,
3809                                                             currentFocusOwner));
3810                              }
3811                            else
3812                      eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, temporary));                      eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, temporary));
3813                    }                    }
3814                }                }
3815                  }
3816              else              else
3817                // FIXME: need to add a focus listener to our top-level                // FIXME: need to add a focus listener to our top-level
3818                // ancestor, so that we can post this event when it becomes                // ancestor, so that we can post this event when it becomes
# Line 3852  public abstract class Component Line 3903  public abstract class Component
3903                  // Check if top-level ancestor is currently focused window.                  // Check if top-level ancestor is currently focused window.
3904                  if (focusedWindow == toplevel)                  if (focusedWindow == toplevel)
3905                    {                    {
3906                      if (peer != null)                      if (peer != null
3907                            && !(this instanceof Window))
3908                        // This call will cause a FOCUS_GAINED event to be                        // This call will cause a FOCUS_GAINED event to be
3909                        // posted to the system event queue if the native                        // posted to the system event queue if the native
3910                        // windowing system grants the focus request.                        // windowing system grants the focus request.
# Line 3863  public abstract class Component Line 3915  public abstract class Component
3915                          // lightweight component.  In either case we want to                          // lightweight component.  In either case we want to
3916                          // post a FOCUS_GAINED event.                          // post a FOCUS_GAINED event.
3917                          EventQueue eq = Toolkit.getDefaultToolkit ().getSystemEventQueue ();                          EventQueue eq = Toolkit.getDefaultToolkit ().getSystemEventQueue ();
3918                            synchronized (eq)
3919                              {
3920                                Component currentFocusOwner = manager.getGlobalPermanentFocusOwner ();
3921                                if (currentFocusOwner != null)
3922                                  {
3923                                    eq.postEvent (new FocusEvent(currentFocusOwner, FocusEvent.FOCUS_LOST,
3924                                                                 temporary, this));
3925                                    eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, temporary,
3926                                                                 currentFocusOwner));
3927                                  }
3928                                else
3929                          eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, temporary));                          eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, temporary));
3930                        }                        }
3931                    }                    }
3932                      }
3933                  else                  else
3934                    return false;                    return false;
3935                }                }
# Line 4041  public abstract class Component Line 4105  public abstract class Component
4105      String name = getName();      String name = getName();
4106      if (name != null)      if (name != null)
4107        param.append(name).append(",");        param.append(name).append(",");
4108      param.append(width).append("x").append(height).append("+").append(x)      param.append(x).append(",").append(y).append(",").append(width)
4109        .append("+").append(y);        .append("x").append(height);
4110      if (! isValid())      if (! isValid())
4111        param.append(",invalid");        param.append(",invalid");
4112      if (! isVisible())      if (! isVisible())
# Line 4410  p   * <li>the set of backward traversal Line 4474  p   * <li>the set of backward traversal
4474    }    }
4475    
4476    /**    /**
4477     * Implementation of dispatchEvent. Allows trusted package classes to     * Translate an AWT 1.1 event ({@link AWTEvent}) into an AWT 1.0
4478     * dispatch additional events first.     * event ({@link Event}).
4479       *
4480       * @param e an AWT 1.1 event to translate
4481       *
4482       * @return an AWT 1.0 event representing e
4483       */
4484      private Event translateEvent (AWTEvent e)
4485      {
4486        Component target = (Component) e.getSource ();
4487        Event translated = null;
4488    
4489        if (e instanceof InputEvent)
4490          {
4491            InputEvent ie = (InputEvent) e;
4492            long when = ie.getWhen ();
4493    
4494            int oldID = 0;
4495            int id = e.getID ();
4496    
4497            int oldMods = 0;
4498            int mods = ie.getModifiers ();
4499    
4500            if ((mods & InputEvent.BUTTON2_MASK) != 0)
4501              oldMods |= Event.META_MASK;
4502            else if ((mods & InputEvent.BUTTON3_MASK) != 0)
4503              oldMods |= Event.ALT_MASK;
4504    
4505            if ((mods & (InputEvent.SHIFT_MASK | InputEvent.SHIFT_DOWN_MASK)) != 0)
4506              oldMods |= Event.SHIFT_MASK;
4507    
4508            if ((mods & (InputEvent.CTRL_MASK | InputEvent.CTRL_DOWN_MASK)) != 0)
4509              oldMods |= Event.CTRL_MASK;
4510    
4511            if ((mods & (InputEvent.META_MASK | InputEvent.META_DOWN_MASK)) != 0)
4512              oldMods |= Event.META_MASK;
4513    
4514            if ((mods & (InputEvent.ALT_MASK | InputEvent.ALT_DOWN_MASK)) != 0)
4515              oldMods |= Event.ALT_MASK;
4516    
4517            if (e instanceof MouseEvent)
4518              {
4519                if (id == MouseEvent.MOUSE_PRESSED)
4520                  oldID = Event.MOUSE_DOWN;
4521                else if (id == MouseEvent.MOUSE_RELEASED)
4522                  oldID = Event.MOUSE_UP;
4523                else if (id == MouseEvent.MOUSE_MOVED)
4524                  oldID = Event.MOUSE_MOVE;
4525                else if (id == MouseEvent.MOUSE_DRAGGED)
4526                  oldID = Event.MOUSE_DRAG;
4527                else if (id == MouseEvent.MOUSE_ENTERED)
4528                  oldID = Event.MOUSE_ENTER;
4529                else if (id == MouseEvent.MOUSE_EXITED)
4530                  oldID = Event.MOUSE_EXIT;
4531                else
4532                  // No analogous AWT 1.0 mouse event.
4533                  return null;
4534    
4535                MouseEvent me = (MouseEvent) e;
4536    
4537                translated = new Event (target, when, oldID,
4538                                        me.getX (), me.getY (), 0, oldMods);
4539              }
4540            else if (e instanceof KeyEvent)
4541              {
4542                if (id == KeyEvent.KEY_PRESSED)
4543                  oldID = Event.KEY_PRESS;
4544                else if (e.getID () == KeyEvent.KEY_RELEASED)
4545                  oldID = Event.KEY_RELEASE;
4546                else
4547                  // No analogous AWT 1.0 key event.
4548                  return null;
4549    
4550                int oldKey = 0;
4551                int newKey = ((KeyEvent) e).getKeyCode ();
4552                switch (newKey)
4553                  {
4554                  case KeyEvent.VK_BACK_SPACE:
4555                    oldKey = Event.BACK_SPACE;
4556                    break;
4557                  case KeyEvent.VK_CAPS_LOCK:
4558                    oldKey = Event.CAPS_LOCK;
4559                    break;
4560                  case KeyEvent.VK_DELETE:
4561                    oldKey = Event.DELETE;
4562                    break;
4563                  case KeyEvent.VK_DOWN:
4564                  case KeyEvent.VK_KP_DOWN:
4565                    oldKey = Event.DOWN;
4566                    break;
4567                  case KeyEvent.VK_END:
4568                    oldKey = Event.END;
4569                    break;
4570                  case KeyEvent.VK_ENTER:
4571                    oldKey = Event.ENTER;
4572                    break;
4573                  case KeyEvent.VK_ESCAPE:
4574                    oldKey = Event.ESCAPE;
4575                    break;
4576                  case KeyEvent.VK_F1:
4577                    oldKey = Event.F1;
4578                    break;
4579                  case KeyEvent.VK_F10:
4580                    oldKey = Event.F10;
4581                    break;
4582                  case KeyEvent.VK_F11:
4583                    oldKey = Event.F11;
4584                    break;
4585                  case KeyEvent.VK_F12:
4586                    oldKey = Event.F12;
4587                    break;
4588                  case KeyEvent.VK_F2:
4589                    oldKey = Event.F2;
4590                    break;
4591                  case KeyEvent.VK_F3:
4592                    oldKey = Event.F3;
4593                    break;
4594                  case KeyEvent.VK_F4:
4595                    oldKey = Event.F4;
4596                    break;
4597                  case KeyEvent.VK_F5:
4598                    oldKey = Event.F5;
4599                    break;
4600                  case KeyEvent.VK_F6:
4601                    oldKey = Event.F6;
4602                    break;
4603                  case KeyEvent.VK_F7:
4604                    oldKey = Event.F7;
4605                    break;
4606                  case KeyEvent.VK_F8:
4607                    oldKey = Event.F8;
4608                    break;
4609                  case KeyEvent.VK_F9:
4610                    oldKey = Event.F9;
4611                    break;
4612                  case KeyEvent.VK_HOME:
4613                    oldKey = Event.HOME;
4614                    break;
4615                  case KeyEvent.VK_INSERT:
4616                    oldKey = Event.INSERT;
4617                    break;
4618                  case KeyEvent.VK_LEFT:
4619                  case KeyEvent.VK_KP_LEFT:
4620                    oldKey = Event.LEFT;
4621                    break;
4622                  case KeyEvent.VK_NUM_LOCK:
4623                    oldKey = Event.NUM_LOCK;
4624                    break;
4625                  case KeyEvent.VK_PAUSE:
4626                    oldKey = Event.PAUSE;
4627                    break;
4628                  case KeyEvent.VK_PAGE_DOWN:
4629                    oldKey = Event.PGDN;
4630                    break;
4631                  case KeyEvent.VK_PAGE_UP:
4632                    oldKey = Event.PGUP;
4633                    break;
4634                  case KeyEvent.VK_PRINTSCREEN:
4635                    oldKey = Event.PRINT_SCREEN;
4636                    break;
4637                  case KeyEvent.VK_RIGHT:
4638                  case KeyEvent.VK_KP_RIGHT:
4639                    oldKey = Event.RIGHT;
4640                    break;
4641                  case KeyEvent.VK_SCROLL_LOCK:
4642                    oldKey = Event.SCROLL_LOCK;
4643                    break;
4644                  case KeyEvent.VK_TAB:
4645                    oldKey = Event.TAB;
4646                    break;
4647                  case KeyEvent.VK_UP:
4648                  case KeyEvent.VK_KP_UP:
4649                    oldKey = Event.UP;
4650                    break;
4651                  default:
4652                    oldKey = newKey;
4653                  }
4654    
4655                translated = new Event (target, when, oldID,
4656                                        0, 0, oldKey, oldMods);
4657              }
4658          }
4659        else if (e instanceof ActionEvent)
4660          translated = new Event (target, Event.ACTION_EVENT,
4661                                  ((ActionEvent) e).getActionCommand ());
4662    
4663        return translated;
4664      }
4665    
4666      /**
4667       * Implementation of dispatchEvent. Allows trusted package classes
4668       * to dispatch additional events first.  This implementation first
4669       * translates <code>e</code> to an AWT 1.0 event and sends the
4670       * result to {@link #postEvent}.  If the AWT 1.0 event is not
4671       * handled, and events of type <code>e</code> are enabled for this
4672       * component, e is passed on to {@link #processEvent}.
4673     *     *
4674     * @param e the event to dispatch     * @param e the event to dispatch
4675     */     */
4676    void dispatchEventImpl(AWTEvent e)    void dispatchEventImpl(AWTEvent e)
4677    {    {
4678        Event oldEvent = translateEvent (e);
4679    
4680        if (oldEvent != null)
4681          postEvent (oldEvent);
4682    
4683      if (eventTypeEnabled (e.id))      if (eventTypeEnabled (e.id))
4684        processEvent(e);        processEvent(e);
4685    }    }

Legend:
Removed from v.1.34  
changed lines
  Added in v.1.35

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