Exemple #1
0
 /** Find the hosting frame, for the file-chooser dialog. */
 protected Frame getFrame() {
   for (Container p = getParent(); p != null; p = p.getParent()) {
     if (p instanceof Frame) {
       return (Frame) p;
     }
   }
   return null;
 }
 /** Return the root container (ie Frame) of this component. */
 public Container getRootParent() {
   Container c = getParent(), prev = null;
   while (c != null) {
     prev = c;
     c = c.getParent();
   }
   return prev;
 }
  /**
   * Convenience method for searching above the given component in the component hierarchy and
   * returns the first object of the given type it finds, or <code>null</code> if no such parent was
   * found.
   *
   * <p>The reason this method exists is for tidyness of the calling code, as no longer a explicit
   * cast is needed.
   *
   * @param aType the type of the parent to find, cannot be <code>null</code>;
   * @param aComponent the component to search in the hierarchy, cannot be <code>null</code>.
   * @return the requested ancestor, or <code>null</code> if not found.
   * @see SwingUtilities#getAncestorOfClass(Class, Component)
   */
  @SuppressWarnings("unchecked")
  public static <T> T getAncestorOfClass(final Class<T> aType, final Component aComponent) {
    if ((aComponent == null) || (aType == null)) {
      return null;
    }

    Container parent = aComponent.getParent();
    while ((parent != null) && !(aType.isInstance(parent))) {
      parent = parent.getParent();
    }

    return (T) parent;
  }
 void this_mouseClicked(MouseEvent e) {
   if (e.getClickCount() == 1) {
     int row = this.getSelectedRow();
     ItemTableDwnld item = (ItemTableDwnld) getMessageList().get(row);
     Container parent = (Container) this;
     while ((parent != null) && !(parent instanceof FrmMain)) parent = parent.getParent();
     if (parent != null) {
       ((FrmMain) parent).setTxtName(item.getTextName());
       ((FrmMain) parent).setTxtTextStart(item.getTextStart());
       ((FrmMain) parent).setTxtTextEnd(item.getTextEnd());
       ((FrmMain) parent).setTxtPath(item.getTextPath());
       ((FrmMain) parent).setCboxType(item.getTextType());
       ((FrmMain) parent).enableBtnUpDown(row);
     }
   }
 }
  /**
   * Calculates the preferred size dimensions for the specified panel given the components in the
   * specified parent container.
   *
   * @see #minimumLayoutSize
   * @param target The component to be laid out.
   * @return A size deemed suitable for laying out the container.
   */
  public Dimension preferredLayoutSize(Container target) {
    int count;
    Container parent;
    Component component;
    Point point;
    Dimension dimension;
    Insets insets;
    Dimension ret;

    synchronized (target.getTreeLock()) {
      count = target.getComponentCount();
      if (0 == count) {
        // be the same size unless we have a parent
        ret = target.getSize();
        parent = target.getParent();
        if (null != parent) {
          insets = parent.getInsets();
          ret = parent.getSize();
          ret.setSize(
              ret.width - insets.left - insets.right, ret.height - insets.top - insets.bottom);
        }
      } else {
        ret = new Dimension(0, 0);
        for (int i = 0; i < count; i++) {
          component = target.getComponent(i);
          if (component.isVisible()) {
            point = component.getLocation();
            dimension = component.getPreferredSize();
            ret.width = Math.max(ret.width, point.x + dimension.width);
            ret.height = Math.max(ret.height, point.y + dimension.height);
          }
        }
        insets = target.getInsets();
        ret.width += insets.left + insets.right;
        ret.height += insets.top + insets.bottom;
      }
    }

    return (ret);
  }