Beispiel #1
0
  private static Frame getFrame(Component c) {
    Component w = c;

    while (!(w instanceof Frame) && (w != null)) {
      w = w.getParent();
    }
    return (Frame) w;
  }
Beispiel #2
0
 /**
  * Processes events on this button. If an event is an instance of <code>ActionEvent</code>, this
  * method invokes the <code>processActionEvent</code> method. Otherwise, it invokes <code>
  * processEvent</code> on the superclass.
  *
  * <p>Note that if the event parameter is <code>null</code> the behavior is unspecified and may
  * result in an exception.
  *
  * @param e the event
  * @see java.awt.event.ActionEvent
  * @see java.awt.Button#processActionEvent
  * @since JDK1.1
  */
 protected void processEvent(AWTEvent e) {
   if (e instanceof ActionEvent) {
     processActionEvent((ActionEvent) e);
     return;
   }
   super.processEvent(e);
 }
Beispiel #3
0
  /**
   * Displays the popup menu at the position x,y in the coordinate space of the component invoker.
   *
   * @param invoker the component in whose space the popup menu is to appear
   * @param x the x coordinate in invoker's coordinate space at which the popup menu is to be
   *     displayed
   * @param y the y coordinate in invoker's coordinate space at which the popup menu is to be
   *     displayed
   */
  public void show(Component invoker, int x, int y) {
    if (DEBUG) {
      System.out.println("in JPopupMenu.show ");
    }
    setInvoker(invoker);
    Frame newFrame = getFrame(invoker);
    if (newFrame != frame) {
      // Use the invoker's frame so that events
      // are propagated properly
      if (newFrame != null) {
        this.frame = newFrame;
        if (popup != null) {
          setVisible(false);
        }
      }
    }
    Point invokerOrigin;
    if (invoker != null) {
      invokerOrigin = invoker.getLocationOnScreen();

      // To avoid integer overflow
      long lx, ly;
      lx = ((long) invokerOrigin.x) + ((long) x);
      ly = ((long) invokerOrigin.y) + ((long) y);
      if (lx > Integer.MAX_VALUE) lx = Integer.MAX_VALUE;
      if (lx < Integer.MIN_VALUE) lx = Integer.MIN_VALUE;
      if (ly > Integer.MAX_VALUE) ly = Integer.MAX_VALUE;
      if (ly < Integer.MIN_VALUE) ly = Integer.MIN_VALUE;

      setLocation((int) lx, (int) ly);
    } else {
      setLocation(x, y);
    }
    setVisible(true);
  }
Beispiel #4
0
  /**
   * Overridden to enforce the position of the glass component as the zero child.
   *
   * @param comp the component to be enhanced
   * @param constraints the constraints to be respected
   * @param index the index
   */
  protected void addImpl(Component comp, Object constraints, int index) {
    super.addImpl(comp, constraints, index);

    /// We are making sure the glassPane is on top.
    if (glassPane != null && glassPane.getParent() == this && getComponent(0) != glassPane) {
      add(glassPane, 0);
    }
  }
Beispiel #5
0
  /**
   * Sets a specified <code>Component</code> to be the glass pane for this root pane. The glass pane
   * should normally be a lightweight, transparent component, because it will be made visible when
   * ever the root pane needs to grab input events.
   *
   * <p>The new glass pane's visibility is changed to match that of the current glass pane. An
   * implication of this is that care must be taken when you want to replace the glass pane and make
   * it visible. Either of the following will work:
   *
   * <pre>
   *   root.setGlassPane(newGlassPane);
   *   newGlassPane.setVisible(true);
   * </pre>
   *
   * or:
   *
   * <pre>
   *   root.getGlassPane().setVisible(true);
   *   root.setGlassPane(newGlassPane);
   * </pre>
   *
   * @param glass the <code>Component</code> to use as the glass pane for this <code>JRootPane
   *     </code>
   * @exception NullPointerException if the <code>glass</code> parameter is <code>null</code>
   */
  public void setGlassPane(Component glass) {
    if (glass == null) {
      throw new NullPointerException("glassPane cannot be set to null.");
    }

    AWTAccessor.getComponentAccessor().setMixingCutoutShape(glass, new Rectangle());

    boolean visible = false;
    if (glassPane != null && glassPane.getParent() == this) {
      this.remove(glassPane);
      visible = glassPane.isVisible();
    }

    glass.setVisible(visible);
    glassPane = glass;
    this.add(glassPane, 0);
    if (visible) {
      repaint();
    }
  }
 public synchronized void paintIcon(Component c, Graphics g, int x, int y) {
   g.setColor(Color.white);
   g.fillRect(0, 0, c.getWidth(), c.getHeight());
   if (getImageObserver() == null) {
     g.drawImage(
         getImage(),
         c.getWidth() / 2 - getIconWidth() / 2,
         c.getHeight() / 2 - getIconHeight() / 2,
         c);
   } else {
     g.drawImage(
         getImage(),
         c.getWidth() / 2 - getIconWidth() / 2,
         c.getHeight() / 2 - getIconHeight() / 2,
         getImageObserver());
   }
 }
Beispiel #7
0
 /**
  * The <code>glassPane</code> and <code>contentPane</code> have the same bounds, which means
  * <code>JRootPane</code> does not tiles its children and this should return false. On the other
  * hand, the <code>glassPane</code> is normally not visible, and so this can return true if the
  * <code>glassPane</code> isn't visible. Therefore, the return value here depends upon the
  * visibility of the <code>glassPane</code>.
  *
  * @return true if this component's children don't overlap
  */
 public boolean isOptimizedDrawingEnabled() {
   return !glassPane.isVisible();
 }
Beispiel #8
0
 /**
  * Creates the peer of the button. The button's peer allows the application to change the look of
  * the button without changing its functionality.
  *
  * @see java.awt.Toolkit#createButton(java.awt.Button)
  * @see java.awt.Component#getToolkit()
  */
 public void addNotify() {
   synchronized (getTreeLock()) {
     if (peer == null) peer = getToolkit().createButton(this);
     super.addNotify();
   }
 }