/**
   * 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 = parentPointX - (int) (horizontalPercent * d.width);
    final int dialogPointY = 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);
  }
Ejemplo n.º 2
0
  protected synchronized Dialog createGotoDialog() {
    if (gotoDialog == null) {
      gotoDialog =
          DialogSupport.createDialog(
              NbBundle.getBundle(org.netbeans.editor.BaseKit.class)
                  .getString("goto-title"), // NOI18N
              gotoPanel,
              false, // non-modal
              gotoButtons,
              false, // sidebuttons,
              0, // defaultIndex = 0 => gotoButton
              1, // cancelIndex = 1 => cancelButton
              this // listener
              );

      gotoDialog.pack();

      // Position the dialog according to the history
      Rectangle lastBounds = (Rectangle) EditorState.get(BOUNDS_KEY);
      if (lastBounds != null) {
        gotoDialog.setBounds(lastBounds);
      } else { // no history, center it on the screen
        Dimension dim = gotoDialog.getPreferredSize();
        int x;
        int y;
        JTextComponent c = EditorRegistry.lastFocusedComponent();
        Window w = c != null ? SwingUtilities.getWindowAncestor(c) : null;
        if (w != null) {
          x = Math.max(0, w.getX() + (w.getWidth() - dim.width) / 2);
          y = Math.max(0, w.getY() + (w.getHeight() - dim.height) / 2);
        } else {
          Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
          x = Math.max(0, (screen.width - dim.width) / 2);
          y = Math.max(0, (screen.height - dim.height) / 2);
        }
        gotoDialog.setLocation(x, y);
      }

      return gotoDialog;
    } else {
      gotoDialog.setVisible(true);
      gotoDialog.toFront();
      return null;
    }
  }
 /* WARNING: THIS METHOD WILL BE REGENERATED. */
 private java.awt.Dialog getDialog1() {
   if (ivjDialog1 == null) {
     try {
       ivjDialog1 = new java.awt.Dialog(new java.awt.Frame());
       ivjDialog1.setName("Dialog1");
       ivjDialog1.setLayout(new java.awt.BorderLayout());
       ivjDialog1.setBounds(65, 335, 204, 95);
       getDialog1().add(getContentsPane(), "Center");
       // user code begin {1}
       // user code end
     } catch (java.lang.Throwable ivjExc) {
       // user code begin {2}
       // user code end
       handleException(ivjExc);
     }
   }
   return ivjDialog1;
 }
Ejemplo n.º 4
0
  public void start() {
    Toolkit.getDefaultToolkit()
        .addAWTEventListener(
            new AWTEventListener() {
              public void eventDispatched(AWTEvent e) {
                System.out.println(e.toString());
              }
            },
            FocusEvent.FOCUS_EVENT_MASK
                | WindowEvent.WINDOW_FOCUS_EVENT_MASK
                | WindowEvent.WINDOW_EVENT_MASK);

    frame = new Frame("Frame");
    frame.setName("Frame-owner");
    frame.setBounds(100, 0, 100, 100);
    dialog = new Dialog(frame, "Dialog");
    dialog.setName("Dialog-owner");
    dialog.setBounds(100, 0, 100, 100);

    window1 = new Window(frame);
    window1.setName("1st child");
    window1.setBounds(100, 300, 100, 100);
    window2 = new Window(window1);
    window2.setName("2nd child");
    window2.setBounds(100, 500, 100, 100);

    test1(frame, window1);
    test2(frame, window1, window2);
    test3(frame, window1, window2);

    window1 = new Window(dialog);
    window1.setBounds(100, 300, 100, 100);
    window1.setName("1st child");
    window2 = new Window(window1);
    window2.setName("2nd child");
    window2.setBounds(100, 500, 100, 100);

    test1(dialog, window1);
    test2(dialog, window1, window2);
    test3(dialog, window1, window2);

    System.out.println("Test passed.");
  }