Example usage for javax.swing JOptionPane getFrameForComponent

List of usage examples for javax.swing JOptionPane getFrameForComponent

Introduction

In this page you can find the example usage for javax.swing JOptionPane getFrameForComponent.

Prototype

public static Frame getFrameForComponent(Component parentComponent) throws HeadlessException 

Source Link

Document

Returns the specified component's Frame.

Usage

From source file:org.freeplane.main.application.MapViewDockingWindows.java

public void focusMapViewLater(final MapView mapView) {
    Timer timer = new Timer(40, new ActionListener() {
        int retryCount = 5;

        public void actionPerformed(final ActionEvent event) {
            final Timer eventTimer = (Timer) event.getSource();
            focusMapLater(mapView, eventTimer);
        }//from ww  w.j a v a2 s .c  om

        private void focusMapLater(final MapView mapView, final Timer eventTimer) {
            if (mapView.isShowing()
                    && Controller.getCurrentController().getMapViewManager().getMapViewComponent() == mapView) {
                final NodeView selected = mapView.getSelected();
                if (selected != null) {
                    final Frame frame = JOptionPane.getFrameForComponent(mapView);
                    if (frame.isFocused())
                        selected.requestFocusInWindow();
                    else
                        frame.addWindowFocusListener(new WindowAdapter() {
                            @Override
                            public void windowGainedFocus(WindowEvent e) {
                                frame.removeWindowFocusListener(this);
                                selected.requestFocusInWindow();
                                retryCount = 2;
                                eventTimer.start();
                            }
                        });
                }
            }
            if (retryCount > 1) {
                retryCount--;
                eventTimer.start();
            }
        }
    });
    timer.setRepeats(false);
    timer.start();
}

From source file:pcgen.gui2.dialog.CharacterHPDialog.java

public static void showHPDialog(Component parent, CharacterFacade character) {
    Frame frame = JOptionPane.getFrameForComponent(parent);
    CharacterHPDialog dialog = new CharacterHPDialog(frame, character);
    Utility.setComponentRelativeLocation(frame, dialog);
    dialog.setVisible(true);/*ww  w  .ja  v a 2  s.co  m*/
}

From source file:pcgen.gui2.dialog.PostLevelUpDialog.java

/**
 * Display the post levelling dialog for a character. This will display a 
 * list of levels just added along with the hit points and skill points 
 * gained. The hit points gained may be edited.
 * // w w w.  j  av a2  s.co m
 * @param parent The component we should appear above.
 * @param character The character that has been levelled up.
 * @param oldLevel The character's level before the level up action.
 */
public static void showPostLevelUpDialog(Component parent, CharacterFacade character, int oldLevel) {
    int size = character.getCharacterLevelsFacade().getSize();
    if (size - oldLevel + 1 < 1) {
        return;
    }

    Frame frame = JOptionPane.getFrameForComponent(parent);
    PostLevelUpDialog dialog = new PostLevelUpDialog(frame, character, oldLevel);
    Utility.setComponentRelativeLocation(frame, dialog);
    dialog.setVisible(true);
}

From source file:plugin.notes.NotesPlugin.java

public boolean isActive() {
    JTabbedPane tp = Utility.getTabbedPaneFor(theView);
    return tp != null && JOptionPane.getFrameForComponent(tp).isFocused()
            && tp.getSelectedComponent().equals(theView);
}

From source file:typoscript.TypoScriptPluginOptions.java

/**
 * Construcs the dialog to add or edit a site
 * If a site object is passed in, we are editing
 * otherwise a null site means new//  w w w  .j a  v a  2  s  . c  o m
 * 
 * @param parent A reference to the option pane that opened this dialog
 * @param site A T3Site object to edit, or null to create a new one
 */
public AddEditSiteDialog(Component ourParent, T3Site site) {
    super(JOptionPane.getFrameForComponent(ourParent), (site == null) ? "New Site" : "Edit Site", true);
    parent = (TypoScriptPluginOptions) ourParent;

    if (site == null) {
        curSite = new T3Site(); // temporary
        isNew = true;
        origSite = null;
    } else {
        curSite = site;
        isNew = false;
        origSite = site;
    }

    JPanel formPanel = new JPanel(new GridBagLayout());

    JLabel lblURL = new JLabel("Site root URL");
    JLabel lblUser = new JLabel("Backend Login");
    JLabel lblPass = new JLabel("Password");

    txtURL = new JTextField(curSite.getUrlBase().toString(), 20);
    txtUser = new JTextField(curSite.getUsername(), 20);
    txtPass = new JPasswordField(curSite.getPassword(), 20);
    chkClearCache = new JCheckBox("Clear TYPO3 cache on template save", curSite.clearCacheOnSave()); // defaults to true

    btnSave = new JButton("Save");
    btnSave.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            ok();
        }
    });
    btnCancel = new JButton("Cancel");
    btnCancel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            cancel();
        }
    });
    btnTest = new JButton("Test settings");
    btnTest.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            test(true);
        }
    });

    formPanel.add(lblURL, GridBagHelper.getConstraint(0, 0, 1, 1, "right"));
    formPanel.add(txtURL, GridBagHelper.getConstraintWithInsets(1, 0, 1, 1, "left", 1, 5, 1, 0));
    formPanel.add(lblUser, GridBagHelper.getConstraint(0, 1, 1, 1, "right"));
    formPanel.add(txtUser, GridBagHelper.getConstraintWithInsets(1, 1, 1, 1, "left", 1, 5, 1, 0));
    formPanel.add(lblPass, GridBagHelper.getConstraint(0, 2, 1, 1, "right"));
    formPanel.add(txtPass, GridBagHelper.getConstraintWithInsets(1, 2, 1, 1, "left", 1, 5, 3, 0));
    formPanel.add(chkClearCache, GridBagHelper.getConstraint(0, 3, 2, 1, "centre"));

    JPanel buttons = new JPanel();
    buttons.add(btnSave);
    buttons.add(btnCancel);
    buttons.add(btnTest);
    formPanel.add(buttons, GridBagHelper.getConstraint(0, 5, 2, 1, "centre"));

    this.getContentPane().add(formPanel);
    this.pack();
    this.setLocationRelativeTo(GUIUtilities.getParentDialog(parent));
    this.setVisible(true);

    txtURL.requestFocus();
}

From source file:util.ui.UiUtilities.java

/**
 * Centers a window to its parent frame and shows it.
 * <p>/*from w ww. ja  va2s.c o  m*/
 * If the window has no parent frame it will be centered to the screen.
 *
 * @param win
 *          The window to center and show.
 */
public static void centerAndShow(Window win) {
    Dimension wD = win.getSize();
    Dimension frameD;
    Point framePos;
    Frame frame = JOptionPane.getFrameForComponent(win);

    // Should this window be centered to its parent frame?
    boolean centerToParentFrame = (frame != null) && (frame != win) && frame.isShowing();

    // Center to parent frame or to screen
    if (centerToParentFrame) {
        frameD = frame.getSize();
        framePos = frame.getLocation();
    } else {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        // dual head, use first screen
        if (ge.getScreenDevices().length > 1) {
            try {
                GraphicsDevice gd = ge.getDefaultScreenDevice();
                GraphicsConfiguration config = gd.getConfigurations()[0];
                frameD = config.getBounds().getSize();
                framePos = config.getBounds().getLocation();
            } catch (RuntimeException e) {
                frameD = Toolkit.getDefaultToolkit().getScreenSize();
                framePos = new Point(0, 0);
            }
        }
        // single screen only
        else {
            frameD = Toolkit.getDefaultToolkit().getScreenSize();
            framePos = new Point(0, 0);
        }
    }

    Point wPos = new Point(framePos.x + (frameD.width - wD.width) / 2,
            framePos.y + (frameD.height - wD.height) / 2);
    wPos.x = Math.max(0, wPos.x); // Make x > 0
    wPos.y = Math.max(0, wPos.y); // Make y > 0
    win.setLocation(wPos);
    win.setVisible(true);
}

From source file:util.ui.UiUtilities.java

/**
 * Gets the best dialog parent for a new JDialog. The best parent is the last
 * visible modal dialog in the component tree.
 * <p>//from   ww w .ja  v  a 2  s  . c  om
 * If there is no visible modal dialog the root frame will be returned.
 *
 * @param parent
 *          One component of the component tree.
 * @return the best dialog parent for a new JDialog.
 */
public static Window getBestDialogParent(Component parent) {
    Frame root = JOptionPane.getFrameForComponent(parent);
    return getLastModalChildOf(root);
}

From source file:vistas.dialogos.DlgEmpleadoCRUD.java

public DlgEmpleadoCRUD(JInternalFrame parent, Empleado empleado, int accion) {
    super(JOptionPane.getFrameForComponent(parent), true);
    this.empleado = empleado;
    this.accion = accion;
    padre = parent;/*from w  w  w  .  j a  va2 s.  com*/
    initComponents();
    iniciar();
    ec = new EmpleadoControlador();
    agregar = true;
    ec.setSeleccionado(empleado);
    if (this.accion == Controlador.MODIFICAR) {
        this.mostrarDatos(empleado);
    }
    if (this.accion == Controlador.NUEVO) {
        tab = false;
        this.tblPane.setEnabledAt(2, false);
    }

    this.setLocationRelativeTo(parent);
    listarArea();
    listarContratos();

    FormularioUtil.activarComponente(panelDatosC, false);
    FormularioUtil.activarComponente(panelDatosA, false);
}