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

The following examples show how to use java.awt.Dialog#getPreferredSize() . 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: ProfilingPointsManager.java    From netbeans with Apache License 2.0 4 votes vote down vote up
boolean customize(final ValidityAwarePanel customizer, Runnable updater, boolean focusToEditor) {
    ValidityAwarePanel showingCustomizer = getShowingCustomizer();

    if (showingCustomizer != null) {
        ProfilerDialogs.displayWarning(
                Bundle.ProfilingPointsManager_AnotherPpEditedMsg());
        SwingUtilities.getWindowAncestor(showingCustomizer).requestFocus();
        showingCustomizer.requestFocusInWindow();
    } else {
        CustomizerButton cb = getCustomizerButton();
        customizer.addValidityListener(cb);
        cb.setEnabled(customizer.areSettingsValid()); // In fact customizer should be valid but just to be sure...

        JPanel customizerContainer = new JPanel(new BorderLayout());
        JPanel customizerSpacer = new JPanel(new BorderLayout());
        customizerSpacer.setBorder(BorderFactory.createEmptyBorder(0, 0, 20, 0));
        customizerSpacer.add(customizer, BorderLayout.CENTER);
        customizerContainer.add(customizerSpacer, BorderLayout.CENTER);
        customizerContainer.add(new JSeparator(), BorderLayout.SOUTH);

        HelpCtx helpCtx = null;

        if (customizer instanceof HelpCtx.Provider) {
            helpCtx = ((HelpCtx.Provider) customizer).getHelpCtx();
        }

        DialogDescriptor dd = new DialogDescriptor(customizerContainer, Bundle.ProfilingPointsManager_PpCustomizerCaption(), false,
                                                   new Object[] { cb, DialogDescriptor.CANCEL_OPTION },
                                                   cb, 0, helpCtx, null);
        final Dialog d = DialogDisplayer.getDefault().createDialog(dd);
        d.addWindowListener(new CustomizerListener(d, dd, updater));
        d.setModal(true);
        // give focus to the initial focus target
        d.addFocusListener(new FocusAdapter() {
            @Override
            public void focusGained(FocusEvent e) {
                if (customizer.getInitialFocusTarget() != null) {
                    customizer.getInitialFocusTarget().requestFocusInWindow();
                }
            }
        });
        
        if (focusToEditor) {
            Dimension dim = d.getPreferredSize();
            Component masterComponent = WindowManager.getDefault().getRegistry().getActivated();
            if (masterComponent != null) {
                Rectangle b = masterComponent.getBounds();
                Point location = new Point((b.x + (b.width / 2)) - (dim.width / 2),
                                           (b.y + (b.height / 2)) - (dim.height / 2));
                SwingUtilities.convertPointToScreen(location, masterComponent);
                d.setLocation(location);
            }
        }
        
        d.setVisible(true);
        
        if (dd.getValue() == cb) {
            return true;
        }
    }
    return false;
}
 
Example 2
Source File: DialogFactory.java    From netbeans with Apache License 2.0 4 votes vote down vote up
static Dialog createDialog(
        final String title,
        final GoToPanelImpl panel,
        final GoToPanelImpl.ContentProvider contentProvider,
        final JButton okButton) {
    okButton.setEnabled (false);
    panel.getAccessibleContext().setAccessibleName( NbBundle.getMessage( GoToSymbolAction.class, "AN_GoToSymbol")  ); //NOI18N
    panel.getAccessibleContext().setAccessibleDescription( NbBundle.getMessage( GoToSymbolAction.class, "AD_GoToSymbol")  ); //NOI18N

    DialogDescriptor dialogDescriptor = new DialogDescriptor(
        panel,                             // innerPane
        title, // displayName
        true,
        new Object[] {okButton, DialogDescriptor.CANCEL_OPTION},
        okButton,
        DialogDescriptor.DEFAULT_ALIGN,
        HelpCtx.DEFAULT_HELP,
        new DialogButtonListener(panel, okButton));

     dialogDescriptor.setClosingOptions(new Object[] {okButton, DialogDescriptor.CANCEL_OPTION});


    Dialog d = DialogDisplayer.getDefault().createDialog( dialogDescriptor );

    // Set size when needed
    final int width = UiOptions.GoToSymbolDialog.getWidth();
    final int height = UiOptions.GoToSymbolDialog.getHeight();
    if (width != -1 && height != -1) {
        d.setPreferredSize(new Dimension(width,height));
    }

    // Center the dialog after the size changed.
    Rectangle r = Utilities.getUsableScreenBounds();
    int maxW = (r.width * 9) / 10;
    int maxH = (r.height * 9) / 10;
    final Dimension dim = d.getPreferredSize();
    dim.width = Math.min(dim.width, maxW);
    dim.height = Math.min(dim.height, maxH);
    d.setBounds(Utilities.findCenterBounds(dim));
    initialDimension = dim;
    d.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosed(WindowEvent e) {
            contentProvider.closeDialog();
        }
    });

    return d;
}
 
Example 3
Source File: FileSearchAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private Dialog createDialog( final FileSearchPanel panel) {
    openBtn = new JButton();
    Mnemonics.setLocalizedText(openBtn, NbBundle.getMessage(FileSearchAction.class, "CTL_Open"));
    openBtn.getAccessibleContext().setAccessibleDescription(openBtn.getText());
    openBtn.setEnabled( false );

    final Object[] buttons = new Object[] { openBtn, DialogDescriptor.CANCEL_OPTION };

    String title = NbBundle.getMessage(FileSearchAction.class, "MSG_FileSearchDlgTitle");
    DialogDescriptor dialogDescriptor = new DialogDescriptor(
            panel,
            title,
            true,
            buttons,
            openBtn,
            DialogDescriptor.DEFAULT_ALIGN,
            HelpCtx.DEFAULT_HELP,
            new DialogButtonListener(panel));
    dialogDescriptor.setClosingOptions(buttons);

    Dialog d = DialogDisplayer.getDefault().createDialog(dialogDescriptor);
    d.getAccessibleContext().setAccessibleName(NbBundle.getMessage(FileSearchAction.class, "AN_FileSearchDialog"));
    d.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(FileSearchAction.class, "AD_FileSearchDialog"));

    // Set size
    d.setPreferredSize( new Dimension(  FileSearchOptions.getWidth(),
                                             FileSearchOptions.getHeight() ) );

    // Center the dialog after the size changed.
    Rectangle r = Utilities.getUsableScreenBounds();
    int maxW = (r.width * 9) / 10;
    int maxH = (r.height * 9) / 10;
    Dimension dim = d.getPreferredSize();
    dim.width = Math.min(dim.width, maxW);
    dim.height = Math.min(dim.height, maxH);
    initialDimension = dim;
    d.setBounds(Utilities.findCenterBounds(dim));
    d.addWindowListener(new WindowAdapter() {
        public @Override void windowClosed(WindowEvent e) {
            cleanup(false);
        }
    });

    return d;
}
 
Example 4
Source File: GoToTypeAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Creates the dialog to show
     */
   private Dialog createDialog( final GoToPanel panel) {

        okButton = new JButton (NbBundle.getMessage(GoToTypeAction.class, "CTL_OK"));
        okButton.getAccessibleContext().setAccessibleDescription(okButton.getText());
        okButton.setEnabled (false);
        panel.getAccessibleContext().setAccessibleName( NbBundle.getMessage( GoToTypeAction.class, "AN_GoToType") ); //NOI18N
        panel.getAccessibleContext().setAccessibleDescription( NbBundle.getMessage( GoToTypeAction.class, "AD_GoToType") ); //NOI18N

        DialogDescriptor dialogDescriptor = new DialogDescriptor(
            panel,                             // innerPane
            title, // displayName
            true,
            new Object[] {okButton, DialogDescriptor.CANCEL_OPTION},
            okButton,
            DialogDescriptor.DEFAULT_ALIGN,
            HelpCtx.DEFAULT_HELP,
            new DialogButtonListener( panel ) );                                 // Action listener

         dialogDescriptor.setClosingOptions(new Object[] {okButton, DialogDescriptor.CANCEL_OPTION});

        // panel.addPropertyChangeListener( new HelpCtxChangeListener( dialogDescriptor, helpCtx ) );
//        if ( panel instanceof HelpCtx.Provider ) {
//            dialogDescriptor.setHelpCtx( ((HelpCtx.Provider)panel).getHelpCtx() );
//        }

        Dialog d = DialogDisplayer.getDefault().createDialog( dialogDescriptor );

        // Set size when needed
        final int width = UiOptions.GoToTypeDialog.getWidth();
        final int height = UiOptions.GoToTypeDialog.getHeight();
        if (width != -1 && height != -1) {
            d.setPreferredSize(new Dimension(width,height));
        }

        // Center the dialog after the size changed.
        Rectangle r = Utilities.getUsableScreenBounds();
        int maxW = (r.width * 9) / 10;
        int maxH = (r.height * 9) / 10;
        final Dimension dim = d.getPreferredSize();
        dim.width = Math.min(dim.width, maxW);
        dim.height = Math.min(dim.height, maxH);
        d.setBounds(Utilities.findCenterBounds(dim));
        initialDimension = dim;
        d.addWindowListener(new WindowAdapter() {
            public @Override void windowClosed(WindowEvent e) {
                cleanup();
            }
        });

        return d;

    }