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

The following examples show how to use java.awt.Dialog#dispose() . 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: ImportHelper.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static List<String> showFixImportChooser(Map<String, Set<ImportCandidate>> multipleCandidates) {
    List<String> result = new ArrayList<>();
    ImportChooserInnerPanel panel = new ImportChooserInnerPanel();

    panel.initPanel(multipleCandidates);

    DialogDescriptor dd = new DialogDescriptor(panel, NbBundle.getMessage(ImportHelper.class, "FixImportsDialogTitle")); //NOI18N
    Dialog d = DialogDisplayer.getDefault().createDialog(dd);

    d.setVisible(true);
    d.setVisible(false);
    d.dispose();

    if (dd.getValue() == DialogDescriptor.OK_OPTION) {
        result = panel.getSelections();
    }
    return result;
}
 
Example 2
Source File: ManagePluginsAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void actionPerformed(ActionEvent arg0) {
    GrailsPluginsPanel panel = new GrailsPluginsPanel(project);
    javax.swing.JButton close =
        new javax.swing.JButton(NbBundle.getMessage(ManagePluginsAction.class, "CTL_Close"));
    close.getAccessibleContext()
         .setAccessibleDescription(NbBundle.getMessage(ManagePluginsAction.class, "CTL_Close"));

    DialogDescriptor descriptor =
        new DialogDescriptor(panel, NbBundle.getMessage(ManagePluginsAction.class, "CTL_PluginTitle"),
            true, new Object[] { close }, close, DialogDescriptor.DEFAULT_ALIGN,
            new HelpCtx(GrailsPluginsPanel.class), null); // NOI18N
    Dialog dlg = null;

    try {
        dlg = DialogDisplayer.getDefault().createDialog(descriptor);
        dlg.setVisible(true);
    } finally {
        try {
            if (dlg != null) {
                dlg.dispose();
            }
        } finally {
            panel.dispose();
        }
    }
}
 
Example 3
Source File: WatchesActionsProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static void customize (Watch w) {

        WatchPanel wp = new WatchPanel(w.getExpression());
        JComponent panel = wp.getPanel();

        org.openide.DialogDescriptor dd = new org.openide.DialogDescriptor(
            panel,
            NbBundle.getMessage(WatchesActionsProvider.class, "CTL_WatchDialog_Title", // NOI18N 
                                           w.getExpression())
        );
        dd.setHelpCtx(new HelpCtx("debug.add.watch"));
        Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
        dialog.setVisible(true);
        dialog.dispose();

        if (dd.getValue() != org.openide.DialogDescriptor.OK_OPTION) return;
        w.setExpression(wp.getExpression());
    }
 
Example 4
Source File: MultiResolutionSplashTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
static float getScaleFactor() {

        final Dialog dialog = new Dialog((Window) null);
        dialog.setSize(100, 100);
        dialog.setModal(true);
        final float[] scaleFactors = new float[1];
        Panel panel = new Panel() {

            @Override
            public void paint(Graphics g) {
                float scaleFactor = 1;
                if (g instanceof SunGraphics2D) {
                    scaleFactor = ((SunGraphics2D) g).surfaceData.getDefaultScale();
                }
                scaleFactors[0] = scaleFactor;
                dialog.setVisible(false);
            }
        };

        dialog.add(panel);
        dialog.setVisible(true);
        dialog.dispose();

        return scaleFactors[0];
    }
 
Example 5
Source File: CustomizerCompile.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void addProcessorButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addProcessorButtonActionPerformed
        final AddAnnotationProcessor panel = new AddAnnotationProcessor();
        final DialogDescriptor desc = new DialogDescriptor(panel, NbBundle.getMessage(CustomizerCompile.class, "LBL_AddAnnotationProcessor_Title")); //NOI18N
        desc.setValid(false);
        panel.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                String fqn = panel.getProcessorFQN();
                desc.setValid(fqn.length() > 0);
            }
        });
        Dialog dlg = DialogDisplayer.getDefault().createDialog(desc);
        dlg.setVisible(true);
        if (desc.getValue() == DialogDescriptor.OK_OPTION) {
            ((DefaultListModel)annotationProcessorsList.getModel()).addElement(panel.getProcessorFQN());
        }
        dlg.dispose();
}
 
Example 6
Source File: LibrariesCustomizer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Shows libraries customizer for given library manager.
 * @param activeLibrary if not null the activeLibrary is selected in the opened customizer
 * @return true if user pressed OK and libraries were successfully modified
 */
@Messages("TXT_LibrariesManager=Ant Library Manager")
public static boolean showCustomizer (Library activeLibrary, LibraryManager libraryManager) {
    org.netbeans.modules.project.libraries.ui.LibrariesCustomizer  customizer =
            new org.netbeans.modules.project.libraries.ui.LibrariesCustomizer (
                    LibrariesSupport.getLibraryStorageArea(libraryManager));
    customizer.setBorder(new EmptyBorder(12, 12, 0, 12));
    if (activeLibrary != null) {
        customizer.setSelectedLibrary (LibrariesSupport.getLibraryImplementation(activeLibrary));
    }
    DialogDescriptor descriptor = new DialogDescriptor(customizer, TXT_LibrariesManager());
    Dialog dlg = DialogDisplayer.getDefault().createDialog(descriptor);
    setAccessibleDescription(dlg, customizer.getAccessibleContext().getAccessibleDescription());
    try {
        dlg.setVisible(true);
        if (descriptor.getValue() == DialogDescriptor.OK_OPTION) {
            return customizer.apply();
        } else {
            return false;
        }
    } finally {
        dlg.dispose();
    }
}
 
Example 7
Source File: MultiResolutionSplashTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static float getScaleFactor() {

        final Dialog dialog = new Dialog((Window) null);
        dialog.setSize(100, 100);
        dialog.setModal(true);
        final float[] scaleFactors = new float[1];
        Panel panel = new Panel() {

            @Override
            public void paint(Graphics g) {
                float scaleFactor = 1;
                if (g instanceof SunGraphics2D) {
                    scaleFactor = ((SunGraphics2D) g).surfaceData.getDefaultScale();
                }
                scaleFactors[0] = scaleFactor;
                dialog.setVisible(false);
            }
        };

        dialog.add(panel);
        dialog.setVisible(true);
        dialog.dispose();

        return scaleFactors[0];
    }
 
Example 8
Source File: JspWatchesActionsProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static void newWatch () {
    WatchPanel wp = new WatchPanel ("");
    JComponent panel = wp.getPanel ();

    org.openide.DialogDescriptor dd = new org.openide.DialogDescriptor (
        panel,
        NbBundle.getMessage(JspWatchesActionsProvider.class, "CTL_New_Watch_Dialog_Title") // NOI18N
    );
    dd.setHelpCtx (new HelpCtx ("debug.new.watch"));
    Dialog dialog = DialogDisplayer.getDefault ().createDialog (dd);
    dialog.setVisible (true);
    dialog.dispose ();

    if (dd.getValue () != org.openide.DialogDescriptor.OK_OPTION) return;
    DebuggerManager.getDebuggerManager ().createWatch (wp.getExpression ());
}
 
Example 9
Source File: CustomizerLibraries.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Messages("CTL_EditModuleDependencyTitle=Edit Module Dependency")
private void editModuleDependency(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editModuleDependency
    ModuleDependency origDep = getDepListModel().getDependency(
            dependencyList.getSelectedIndex());
    EditDependencyPanel editPanel = new EditDependencyPanel(
            origDep, getProperties().getActivePlatform());
    DialogDescriptor descriptor = new DialogDescriptor(editPanel,
            CTL_EditModuleDependencyTitle());
    descriptor.setHelpCtx(new HelpCtx("org.netbeans.modules.apisupport.project.ui.customizer.EditDependencyPanel"));
    Dialog d = DialogDisplayer.getDefault().createDialog(descriptor);
    d.setVisible(true);
    if (descriptor.getValue().equals(DialogDescriptor.OK_OPTION)) {
        getDepListModel().editDependency(origDep, editPanel.getEditedDependency());
    }
    d.dispose();
    dependencyList.requestFocusInWindow();
}
 
Example 10
Source File: JFXDeploymentPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void buttonSigningActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSigningActionPerformed
    JFXSigningPanel panel = new JFXSigningPanel(jfxProps);
    DialogDescriptor dialogDesc = new DialogDescriptor(panel, NbBundle.getMessage(JFXSigningPanel.class, "TITLE_JFXSigningPanel"), true, null); // NOI18N
    panel.registerListeners();
    panel.setDialogDescriptor(dialogDesc);
    Dialog dialog = DialogDisplayer.getDefault().createDialog(dialogDesc);
    dialog.setVisible(true);
    if (dialogDesc.getValue() == DialogDescriptor.OK_OPTION) {
        panel.store();
        refreshSigningLabel();
    }
    panel.unregisterListeners();
    dialog.dispose();
}
 
Example 11
Source File: ReferencesPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static URL showInWindow() {
    JButton openBtn = new JButton();
    Mnemonics.setLocalizedText(openBtn, NbBundle.getMessage(ReferencesPanel.class, "ReferencesPanel.ok.text"));
    openBtn.getAccessibleContext().setAccessibleDescription(openBtn.getText());
    openBtn.setEnabled(false);

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

    ReferencesPanel panel = new ReferencesPanel(openBtn);
    DialogDescriptor desc = new DialogDescriptor(
            panel,
            NbBundle.getMessage(ReferencesPanel.class, "ReferencesPanel.title"),
            true,
            buttons,
            openBtn,
            DialogDescriptor.DEFAULT_ALIGN,
            HelpCtx.DEFAULT_HELP,
            null);
    desc.setClosingOptions(buttons);

    Dialog dialog = DialogDisplayer.getDefault().createDialog(desc);
    dialog.getAccessibleContext().setAccessibleName(NbBundle.getMessage(ReferencesPanel.class, "AN_ReferencesDialog"));
    dialog.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ReferencesPanel.class, "AD_ReferencesDialog"));

    // schedule computing indices
    RP.post(panel);
    dialog.setVisible(true);
    dialog.dispose();

    return desc.getValue() == openBtn
            ? panel.getSelectedItem()
            : null;
}
 
Example 12
Source File: ProjectCustomizerProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
        public void actionPerformed( ActionEvent e ) {
//#95952 some users experience this assertion on a fairly random set of changes in 
// the customizer, that leads me to assume that a project can be already marked
// as modified before the project customizer is shown. 
//            assert !ProjectManager.getDefault().isModified(project) : 
//                "Some of the customizer panels has written the changed data before OK Button was pressed. Please file it as bug."; //NOI18N
            
            // Close & dispose the the dialog
            Dialog dialog = project2Dialog.get( project );
            if ( dialog != null ) {
                dialog.setVisible(false);
                dialog.dispose();
            }
        }
 
Example 13
Source File: ModalDialogOrderingTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void runTest(Dialog dialog, Frame frame) {
    try {
        Robot robot = new Robot();
        robot.setAutoDelay(50);
        robot.mouseMove(300, 300);

        while (!dialog.isVisible()) {
            sleep();
        }

        Rectangle dialogBounds = dialog.getBounds();
        Rectangle frameBounds = frame.getBounds();

        int y1 = dialogBounds.y + dialogBounds.height;
        int y2 = frameBounds.y + frameBounds.height;

        int clickX = frameBounds.x + frameBounds.width / 2;
        int clickY = y1 + (y2 - y1) / 2;

        robot.mouseMove(clickX, clickY);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        sleep();

        int colorX = dialogBounds.x + dialogBounds.width / 2;
        int colorY = dialogBounds.y + dialogBounds.height / 2;

        Color color = robot.getPixelColor(colorX, colorY);

        dialog.dispose();
        frame.dispose();

        if (!DIALOG_COLOR.equals(color)) {
            throw new RuntimeException("The frame is on top"
                    + " of the modal dialog!");
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
 
Example 14
Source File: ModalDialogOrderingTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static void runTest(Dialog dialog, Frame frame) {
    try {
        Robot robot = new Robot();
        robot.setAutoDelay(50);
        robot.mouseMove(300, 300);

        while (!dialog.isVisible()) {
            sleep();
        }

        Rectangle dialogBounds = dialog.getBounds();
        Rectangle frameBounds = frame.getBounds();

        int y1 = dialogBounds.y + dialogBounds.height;
        int y2 = frameBounds.y + frameBounds.height;

        int clickX = frameBounds.x + frameBounds.width / 2;
        int clickY = y1 + (y2 - y1) / 2;

        robot.mouseMove(clickX, clickY);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        sleep();

        int colorX = dialogBounds.x + dialogBounds.width / 2;
        int colorY = dialogBounds.y + dialogBounds.height / 2;

        Color color = robot.getPixelColor(colorX, colorY);

        dialog.dispose();
        frame.dispose();

        if (!DIALOG_COLOR.equals(color)) {
            throw new RuntimeException("The frame is on top"
                    + " of the modal dialog!");
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
 
Example 15
Source File: DialogAboveFrameTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Robot robot = Util.createRobot();

    Frame frame = new Frame("Frame");
    frame.setBackground(Color.BLUE);
    frame.setBounds(200, 50, 300, 300);
    frame.setVisible(true);

    Dialog dialog1 = new Dialog(frame, "Dialog 1", false);
    dialog1.setBackground(Color.RED);
    dialog1.setBounds(100, 100, 200, 200);
    dialog1.setVisible(true);

    Dialog dialog2 = new Dialog(frame, "Dialog 2", false);
    dialog2.setBackground(Color.GREEN);
    dialog2.setBounds(400, 100, 200, 200);
    dialog2.setVisible(true);

    Util.waitForIdle(robot);

    Util.clickOnComp(dialog2, robot);
    Util.waitForIdle(robot);

    Point point = dialog1.getLocationOnScreen();
    int x = point.x + (int)(dialog1.getWidth() * 0.9);
    int y = point.y + (int)(dialog1.getHeight() * 0.9);

    try {
        if (!Util.testPixelColor(x, y, dialog1.getBackground(), 10, 100, robot)) {
            throw new RuntimeException("Test FAILED: Dialog is behind the frame");
        }
    } finally {
        frame.dispose();
        dialog1.dispose();
        dialog2.dispose();
    }
}
 
Example 16
Source File: CustomizerProviderImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public @Override void windowClosing(WindowEvent e) {
    //Dispose the dialog otherwsie the {@link WindowAdapter#windowClosed}
    //may not be called
    Dialog dialog = project2Dialog.get(project);
    if ( dialog != null ) {
        dialog.setVisible(false);
        dialog.dispose();
    }
}
 
Example 17
Source File: DialogAboveFrameTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Robot robot = Util.createRobot();

    Frame frame = new Frame("Frame");
    frame.setBackground(Color.BLUE);
    frame.setBounds(200, 50, 300, 300);
    frame.setVisible(true);

    Dialog dialog1 = new Dialog(frame, "Dialog 1", false);
    dialog1.setBackground(Color.RED);
    dialog1.setBounds(100, 100, 200, 200);
    dialog1.setVisible(true);

    Dialog dialog2 = new Dialog(frame, "Dialog 2", false);
    dialog2.setBackground(Color.GREEN);
    dialog2.setBounds(400, 100, 200, 200);
    dialog2.setVisible(true);

    Util.waitForIdle(robot);

    Util.clickOnComp(dialog2, robot);
    Util.waitForIdle(robot);

    Point point = dialog1.getLocationOnScreen();
    int x = point.x + (int)(dialog1.getWidth() * 0.9);
    int y = point.y + (int)(dialog1.getHeight() * 0.9);

    try {
        if (!Util.testPixelColor(x, y, dialog1.getBackground(), 10, 100, robot)) {
            throw new RuntimeException("Test FAILED: Dialog is behind the frame");
        }
    } finally {
        frame.dispose();
        dialog1.dispose();
        dialog2.dispose();
    }
}
 
Example 18
Source File: CustomizerProviderImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void windowClosing(WindowEvent e) {
    // dispose the dialog otherwise {@link WindowAdapter#windowClosed} may not be called
    Dialog dialog = PROJECT_2_DIALOG.get(project);
    if (dialog != null) {
        dialog.setVisible(false);
        dialog.dispose();
    }
}
 
Example 19
Source File: ModalDialogOrderingTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static void runTest(Dialog dialog, Frame frame) {
    try {
        ExtendedRobot robot = new ExtendedRobot();
        robot.setAutoDelay(50);
        robot.mouseMove(300, 300);

        while (!dialog.isVisible()) {
            robot.waitForIdle(1000);
        }

        Rectangle dialogBounds = dialog.getBounds();
        Rectangle frameBounds = frame.getBounds();

        int y1 = dialogBounds.y + dialogBounds.height;
        int y2 = frameBounds.y + frameBounds.height;

        int clickX = frameBounds.x + frameBounds.width / 2;
        int clickY = y1 + (y2 - y1) / 2;

        robot.mouseMove(clickX, clickY);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        robot.waitForIdle(1000);

        int colorX = dialogBounds.x + dialogBounds.width / 2;
        int colorY = dialogBounds.y + dialogBounds.height / 2;

        Color color = robot.getPixelColor(colorX, colorY);


        if (!DIALOG_COLOR.equals(color)) {
            throw new RuntimeException("The frame is on top"
                    + " of the modal dialog!");
        }else{
            frame.dispose();
            dialog.dispose();
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
 
Example 20
Source File: AddServerInstanceWizard.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public static String showAddServerInstanceWizard(Map<String, String> props) {
    Collection<Server> allServers = ServerRegistry.getInstance().getServers();
    for (java.util.Iterator<Server> it = allServers.iterator(); it.hasNext();) {
        Server server = it.next();
        OptionalDeploymentManagerFactory factory = server.getOptionalFactory();
        if (factory == null || factory.getAddInstanceIterator() == null) {
            it.remove();
        }
    }
    if (allServers.isEmpty()) {
        // display the warning dialog - no server plugins
        String close = NbBundle.getMessage(AddServerInstanceWizard.class, "LBL_NoServerPlugins_Close");
        DialogDescriptor descriptor = new DialogDescriptor(
                NbBundle.getMessage(AddServerInstanceWizard.class, "LBL_NoServerPlugins_Text"),
                NbBundle.getMessage(AddServerInstanceWizard.class, "LBL_NoServerPlugins_Title"),
                true,
                new Object[] {close},
                close,
                DialogDescriptor.DEFAULT_ALIGN,
                null,
                null);

        // TODO invoke plugin manager once API to do that will be available
        DialogDisplayer.getDefault().notify(descriptor);
        return null;
    }
        
    AddServerInstanceWizard wizard = new AddServerInstanceWizard(props);
    Dialog dialog = DialogDisplayer.getDefault().createDialog(wizard);
    try {
        dialog.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AddServerInstanceWizard.class, "ACSD_Add_Server_Instance"));
        dialog.setVisible(true);
    } finally {
        dialog.dispose();
    }
    if (wizard.getValue() == WizardDescriptor.FINISH_OPTION) {
        Set instantiatedObjects = wizard.getInstantiatedObjects();
        if (instantiatedObjects != null && instantiatedObjects.size() > 0) {
            Object result = instantiatedObjects.iterator().next();
            if (result instanceof InstanceProperties) {
                return ((InstanceProperties) result).getProperty(InstanceProperties.URL_ATTR);
            } else {
                LOGGER.warning(wizard.iterator.getSelectedServer() + "'s add server instance wizard iterator should return " + // NOI18N
                        "a Set containing new server instance InstanceProperties object as a result of the " + // NOI18N
                        "WizardDescriptor.InstantiatingIterator.instantiate() method."); // NOI18N
                // there is an error in the server plugin, cannot return the added instance
                return null;
            }
        }
    }
    // the wizard was cancelled
    return null;
}