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;
    }
  }