java.awt.Dialog#getParent ( )源码实例Demo

下面列出了java.awt.Dialog#getParent ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ccu-historian   文件: RefineryUtilities.java
/**
 * Positions the specified dialog at a position relative to its parent.
 *
 * @param dialog  the dialog to be positioned.
 * @param horizontalPercent  the relative location.
 * @param verticalPercent  the relative location.
 */
public static void positionDialogRelativeToParent(final Dialog dialog,
                                                  final double horizontalPercent,
                                                  final double verticalPercent) {
  final Container parent = dialog.getParent();
  if (parent == null)
  {
    centerFrameOnScreen(dialog);
    return;
  }

  final Dimension d = dialog.getSize();
  final Dimension p = parent.getSize();

  final int baseX = parent.getX();
  final int baseY = parent.getY();

  final int x = baseX + (int) (horizontalPercent * p.width);
  final int y = baseY + (int) (verticalPercent * p.height);

  // make sure the dialog fits completely on the screen...
  final Rectangle s = parent.getGraphicsConfiguration().getBounds();
  final Rectangle r = new Rectangle(x, y, d.width, d.height);
  dialog.setBounds(r.intersection(s));
}
 
源代码2 项目: astor   文件: RefineryUtilities.java
/**
 * Positions the specified dialog at a position relative to its parent.
 *
 * @param dialog  the dialog to be positioned.
 * @param horizontalPercent  the relative location.
 * @param verticalPercent  the relative location.
 */
public static void positionDialogRelativeToParent(Dialog dialog,
                                                  double horizontalPercent,
                                                  double verticalPercent) {
    Dimension d = dialog.getSize();
    Container parent = dialog.getParent();
    Dimension p = parent.getSize();

    int baseX = parent.getX() - d.width;
    int baseY = parent.getY() - d.height;
    int w = d.width + p.width;
    int h = d.height + p.height;
    int x = baseX + (int) (horizontalPercent * w);
    int y = baseY + (int) (verticalPercent * h);

    // make sure the dialog fits completely on the screen...
    Rectangle s = getMaximumWindowBounds();
    x = Math.min(x, (s.width - d.width));
    x = Math.max(x, 0);
    y = Math.min(y, (s.height - d.height));
    y = Math.max(y, 0);

    dialog.setBounds(x + s.x, y + s.y, d.width, d.height);

}
 
源代码3 项目: astor   文件: RefineryUtilities.java
/**
 * Positions the specified dialog at a position relative to its parent.
 *
 * @param dialog  the dialog to be positioned.
 * @param horizontalPercent  the relative location.
 * @param verticalPercent  the relative location.
 */
public static void positionDialogRelativeToParent(Dialog dialog,
                                                  double horizontalPercent,
                                                  double verticalPercent) {
    Dimension d = dialog.getSize();
    Container parent = dialog.getParent();
    Dimension p = parent.getSize();

    int baseX = parent.getX() - d.width;
    int baseY = parent.getY() - d.height;
    int w = d.width + p.width;
    int h = d.height + p.height;
    int x = baseX + (int) (horizontalPercent * w);
    int y = baseY + (int) (verticalPercent * h);

    // make sure the dialog fits completely on the screen...
    Rectangle s = getMaximumWindowBounds();
    x = Math.min(x, (s.width - d.width));
    x = Math.max(x, 0);
    y = Math.min(y, (s.height - d.height));
    y = Math.max(y, 0);

    dialog.setBounds(x + s.x, y + s.y, d.width, d.height);

}
 
源代码4 项目: pentaho-reporting   文件: SwingUtil.java
/**
 * Positions the specified dialog at a position relative to its parent.
 *
 * @param dialog
 *          the dialog to be positioned.
 * @param horizontalPercent
 *          the relative location.
 * @param verticalPercent
 *          the relative location.
 */
public static void positionDialogRelativeToParent( final Dialog dialog, final double horizontalPercent,
    final double verticalPercent ) {
  final Container parent = dialog.getParent();
  if ( parent == null || ( parent.isVisible() == false ) ) {
    positionFrameOnScreen( dialog, horizontalPercent, verticalPercent );
    return;
  }

  final Dimension d = dialog.getSize();
  final Dimension p = parent.getSize();

  final int baseX = parent.getX();
  final int baseY = parent.getY();

  final int parentPointX = baseX + (int) ( horizontalPercent * p.width );
  final int parentPointY = baseY + (int) ( verticalPercent * p.height );

  final int dialogPointX = Math.max( 0, parentPointX - (int) ( horizontalPercent * d.width ) );
  final int dialogPointY = Math.max( 0, parentPointY - (int) ( verticalPercent * d.height ) );

  // make sure the dialog fits completely on the screen...
  final Rectangle s = parent.getGraphicsConfiguration().getBounds();
  final Rectangle r = new Rectangle( dialogPointX, dialogPointY, d.width, d.height );
  final Rectangle intersectedDialogBounds = r.intersection( s );
  if ( intersectedDialogBounds.width < d.width ) {
    r.x = s.width - d.width;
    r.width = d.width;
  }
  if ( intersectedDialogBounds.height < d.height ) {
    r.y = s.height - d.height;
    r.height = d.height;
  }
  final Rectangle finalIntersection = r.intersection( s );
  dialog.setBounds( finalIntersection );
}