Java Code Examples for java.awt.Dialog#getParent()

The following examples show how to use java.awt.Dialog#getParent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RefineryUtilities.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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));
}
 
Example 2
Source File: RefineryUtilities.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);

}
 
Example 3
Source File: RefineryUtilities.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);

}
 
Example 4
Source File: SwingUtil.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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 );
}