This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 196200
Collapse All | Expand All

(-)a/core.windows/src/org/netbeans/core/windows/services/NbPresenter.java (-165 / +156 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.core.windows.services;
44
package org.netbeans.core.windows.services;
46
45
47
import java.awt.BorderLayout;
46
import java.awt.BorderLayout;
Lines 118-138 Link Here
118
import org.openide.util.Utilities;
117
import org.openide.util.Utilities;
119
118
120
// XXX Before as org.netbeans.core.NbPresenter
119
// XXX Before as org.netbeans.core.NbPresenter
121
122
/** Default implementation of Dialog created from NotifyDescriptor.
120
/** Default implementation of Dialog created from NotifyDescriptor.
123
 *
121
 *
124
 * @author Ian Formanek, Jaroslav Tulach
122
 * @author Ian Formanek, Jaroslav Tulach
125
 */
123
 */
126
class NbPresenter extends JDialog
124
class NbPresenter extends JDialog
127
implements PropertyChangeListener, WindowListener, Mutex.Action<Void>, Comparator<Object> {
125
        implements PropertyChangeListener, WindowListener, Mutex.Action<Void>, Comparator<Object> {
128
    
126
129
    /** variable holding current modal dialog in the system */
127
    /** variable holding current modal dialog in the system */
130
    public static NbPresenter currentModalDialog;
128
    public static NbPresenter currentModalDialog;
131
    private static final ChangeSupport cs = new ChangeSupport(NbPresenter.class);
129
    private static final ChangeSupport cs = new ChangeSupport(NbPresenter.class);
132
    private static Boolean isJava17 = null;
130
    private static Boolean isJava17 = null;
133
    
134
    protected NotifyDescriptor descriptor;
131
    protected NotifyDescriptor descriptor;
135
    
136
    private final JButton stdYesButton = new JButton(NbBundle.getBundle(NbPresenter.class).getString("YES_OPTION_CAPTION")); // NOI18N
132
    private final JButton stdYesButton = new JButton(NbBundle.getBundle(NbPresenter.class).getString("YES_OPTION_CAPTION")); // NOI18N
137
    private final JButton stdNoButton = new JButton(NbBundle.getBundle(NbPresenter.class).getString("NO_OPTION_CAPTION")); // NOI18N
133
    private final JButton stdNoButton = new JButton(NbBundle.getBundle(NbPresenter.class).getString("NO_OPTION_CAPTION")); // NOI18N
138
    private final JButton stdOKButton = new JButton(NbBundle.getBundle(NbPresenter.class).getString("OK_OPTION_CAPTION")); // NOI18N
134
    private final JButton stdOKButton = new JButton(NbBundle.getBundle(NbPresenter.class).getString("OK_OPTION_CAPTION")); // NOI18N
Lines 150-161 Link Here
150
        stdHelpButton.setDefaultCapable(false);
146
        stdHelpButton.setDefaultCapable(false);
151
        stdDetailButton.setDefaultCapable(false);
147
        stdDetailButton.setDefaultCapable(false);
152
        Mnemonics.setLocalizedText (stdHelpButton, NbBundle.getBundle(NbPresenter.class).getString("HELP_OPTION_CAPTION")); // NOI18N
148
        Mnemonics.setLocalizedText (stdHelpButton, NbBundle.getBundle(NbPresenter.class).getString("HELP_OPTION_CAPTION")); // NOI18N
153
        
149
154
        /** Initilizes accessible contexts */
150
        /** Initilizes accessible contexts */
155
        initAccessibility();
151
        initAccessibility();
156
    }
152
    }
157
    private final static String ESCAPE_COMMAND = "Escape"; // NOI18N
153
    private final static String ESCAPE_COMMAND = "Escape"; // NOI18N
158
    
159
    private Component currentMessage;
154
    private Component currentMessage;
160
    private JScrollPane currentScrollPane;
155
    private JScrollPane currentScrollPane;
161
    private boolean leaf = false;
156
    private boolean leaf = false;
Lines 163-189 Link Here
163
    private JLabel notificationLine;
158
    private JLabel notificationLine;
164
    private Component[] currentPrimaryButtons;
159
    private Component[] currentPrimaryButtons;
165
    private Component[] currentSecondaryButtons;
160
    private Component[] currentSecondaryButtons;
166
    
167
    private static final int MSG_TYPE_ERROR = 1;
161
    private static final int MSG_TYPE_ERROR = 1;
168
    private static final int MSG_TYPE_WARNING = 2;
162
    private static final int MSG_TYPE_WARNING = 2;
169
    private static final int MSG_TYPE_INFO = 3;
163
    private static final int MSG_TYPE_INFO = 3;
170
    private Color nbErrorForeground;
164
    private Color nbErrorForeground;
171
    private Color nbWarningForeground;
165
    private Color nbWarningForeground;
172
    private Color nbInfoForeground;
166
    private Color nbInfoForeground;
173
174
    /** useful only for DialogDescriptor */
167
    /** useful only for DialogDescriptor */
175
    private int currentAlign;
168
    private int currentAlign;
176
    
177
    private ButtonListener buttonListener;
169
    private ButtonListener buttonListener;
178
    /** Help context to actually associate with the dialog, as it is currently known. */
170
    /** Help context to actually associate with the dialog, as it is currently known. */
179
    private transient HelpCtx currentHelp = null;
171
    private transient HelpCtx currentHelp = null;
180
    /** Used to prevent updateHelp from calling initializeButtons too many times. */
172
    /** Used to prevent updateHelp from calling initializeButtons too many times. */
181
    private transient boolean haveCalledInitializeButtons = false;
173
    private transient boolean haveCalledInitializeButtons = false;
174
    static final Logger LOG = Logger.getLogger(NbPresenter.class.getName());
182
175
183
    static final Logger LOG = Logger.getLogger(NbPresenter.class.getName());
184
    
185
    static final long serialVersionUID =-4508637164126678997L;
186
    
187
    /** Creates a new Dialog from specified NotifyDescriptor,
176
    /** Creates a new Dialog from specified NotifyDescriptor,
188
     * with given frame owner.
177
     * with given frame owner.
189
     * @param d The NotifyDescriptor to create the dialog from
178
     * @param d The NotifyDescriptor to create the dialog from
Lines 192-198 Link Here
192
        super(owner, d.getTitle(), modal); // modal
181
        super(owner, d.getTitle(), modal); // modal
193
        initialize(d);
182
        initialize(d);
194
    }
183
    }
195
    
184
196
    /** Creates a new Dialog from specified NotifyDescriptor,
185
    /** Creates a new Dialog from specified NotifyDescriptor,
197
     * with given dialog owner.
186
     * with given dialog owner.
198
     * @param d The NotifyDescriptor to create the dialog from
187
     * @param d The NotifyDescriptor to create the dialog from
Lines 201-245 Link Here
201
        super(owner, d.getTitle(), modal); // modal
190
        super(owner, d.getTitle(), modal); // modal
202
        initialize(d);
191
        initialize(d);
203
    }
192
    }
204
    
193
205
    boolean isLeaf () {
194
    boolean isLeaf () {
206
        return leaf;
195
        return leaf;
207
    }
196
    }
208
    
197
209
    private void initAccessibility(){
198
    private void initAccessibility(){
210
        
199
211
        ResourceBundle bundle;
200
        ResourceBundle bundle;
212
        bundle = NbBundle.getBundle(NbPresenter.class);
201
        bundle = NbBundle.getBundle(NbPresenter.class);
213
        
202
214
        stdYesButton.getAccessibleContext().setAccessibleName(bundle.getString("ACS_YES_OPTION_NAME")); // NOI18N
203
        stdYesButton.getAccessibleContext().setAccessibleName(bundle.getString("ACS_YES_OPTION_NAME")); // NOI18N
215
        stdYesButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_YES_OPTION_DESC")); // NOI18N
204
        stdYesButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_YES_OPTION_DESC")); // NOI18N
216
        
205
217
        stdNoButton.getAccessibleContext().setAccessibleName(bundle.getString("ACS_NO_OPTION_NAME")); // NOI18N
206
        stdNoButton.getAccessibleContext().setAccessibleName(bundle.getString("ACS_NO_OPTION_NAME")); // NOI18N
218
        stdNoButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_NO_OPTION_DESC")); // NOI18N
207
        stdNoButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_NO_OPTION_DESC")); // NOI18N
219
        
208
220
        stdOKButton.getAccessibleContext().setAccessibleName(bundle.getString("ACS_OK_OPTION_NAME")); // NOI18N
209
        stdOKButton.getAccessibleContext().setAccessibleName(bundle.getString("ACS_OK_OPTION_NAME")); // NOI18N
221
        stdOKButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_OK_OPTION_DESC")); // NOI18N
210
        stdOKButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_OK_OPTION_DESC")); // NOI18N
222
        
211
223
        stdCancelButton.getAccessibleContext().setAccessibleName(bundle.getString("ACS_CANCEL_OPTION_NAME")); // NOI18N
212
        stdCancelButton.getAccessibleContext().setAccessibleName(bundle.getString("ACS_CANCEL_OPTION_NAME")); // NOI18N
224
        stdCancelButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_CANCEL_OPTION_DESC")); // NOI18N
213
        stdCancelButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_CANCEL_OPTION_DESC")); // NOI18N
225
        
214
226
        stdClosedButton.getAccessibleContext().setAccessibleName(bundle.getString("ACS_CLOSED_OPTION_NAME")); // NOI18N
215
        stdClosedButton.getAccessibleContext().setAccessibleName(bundle.getString("ACS_CLOSED_OPTION_NAME")); // NOI18N
227
        stdClosedButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_CLOSED_OPTION_DESC")); // NOI18N
216
        stdClosedButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_CLOSED_OPTION_DESC")); // NOI18N
228
        
217
229
        stdHelpButton.getAccessibleContext().setAccessibleName(bundle.getString("ACS_HELP_OPTION_NAME")); // NOI18N
218
        stdHelpButton.getAccessibleContext().setAccessibleName(bundle.getString("ACS_HELP_OPTION_NAME")); // NOI18N
230
        stdHelpButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_HELP_OPTION_DESC")); // NOI18N
219
        stdHelpButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_HELP_OPTION_DESC")); // NOI18N
231
        
220
232
        stdDetailButton.getAccessibleContext().setAccessibleName(bundle.getString("ACS_HELP_OPTION_NAME")); // NOI18N
221
        stdDetailButton.getAccessibleContext().setAccessibleName(bundle.getString("ACS_HELP_OPTION_NAME")); // NOI18N
233
        stdDetailButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_HELP_OPTION_DESC")); // NOI18N
222
        stdDetailButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_HELP_OPTION_DESC")); // NOI18N
234
    }
223
    }
235
    
224
236
    private void initialize(NotifyDescriptor d) {
225
    private void initialize(NotifyDescriptor d) {
237
        //Optimization related to jdk bug 4393857 - on pre 1.5 jdk's an
226
        //Optimization related to jdk bug 4393857 - on pre 1.5 jdk's an
238
        //extra repaint is caused by the search for an opaque component up
227
        //extra repaint is caused by the search for an opaque component up
239
        //to the component root. Post 1.5, root pane will automatically be
228
        //to the component root. Post 1.5, root pane will automatically be
240
        //opaque.
229
        //opaque.
241
        getRootPane().setOpaque(true);
230
        getRootPane().setOpaque(true);
242
        
231
243
        if (d instanceof WizardDescriptor) {
232
        if (d instanceof WizardDescriptor) {
244
            // #81938: wizard close button shouln't work during finish progress
233
            // #81938: wizard close button shouln't work during finish progress
245
            setDefaultCloseOperation (WindowConstants.DO_NOTHING_ON_CLOSE);
234
            setDefaultCloseOperation (WindowConstants.DO_NOTHING_ON_CLOSE);
Lines 247-259 Link Here
247
            // #55273: Dialogs created by DialogDisplayer are not disposed after close
236
            // #55273: Dialogs created by DialogDisplayer are not disposed after close
248
            setDefaultCloseOperation (WindowConstants.DISPOSE_ON_CLOSE);
237
            setDefaultCloseOperation (WindowConstants.DISPOSE_ON_CLOSE);
249
        }
238
        }
250
        
239
251
        descriptor = d;
240
        descriptor = d;
252
241
253
        buttonListener = new ButtonListener();
242
        buttonListener = new ButtonListener();
254
        // set leaf by DialogDescriptor, NotifyDescriptor is leaf as default
243
        // set leaf by DialogDescriptor, NotifyDescriptor is leaf as default
255
        leaf = d instanceof DialogDescriptor ? ((DialogDescriptor)d).isLeaf () : true;
244
        leaf = d instanceof DialogDescriptor ? ((DialogDescriptor)d).isLeaf () : true;
256
        
245
257
        getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
246
        getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
258
                KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), ESCAPE_COMMAND);
247
                KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), ESCAPE_COMMAND);
259
        getRootPane().getActionMap().put(ESCAPE_COMMAND, new EscapeAction());
248
        getRootPane().getActionMap().put(ESCAPE_COMMAND, new EscapeAction());
Lines 273-290 Link Here
273
     * request first. */
262
     * request first. */
274
    private void requestFocusForMessage() {
263
    private void requestFocusForMessage() {
275
        Component comp = currentMessage;
264
        Component comp = currentMessage;
276
        
265
277
        if(comp == null) {
266
        if(comp == null) {
278
            return;
267
            return;
279
        }
268
        }
280
        
269
281
        if(!(comp instanceof JComponent) 
270
        if(!(comp instanceof JComponent) 
282
            || !((JComponent)comp).requestDefaultFocus()) {
271
            || !((JComponent)comp).requestDefaultFocus()) {
283
                
272
284
            comp.requestFocus();
273
            comp.requestFocus();
285
        }
274
        }
286
    }
275
    }
287
    
276
288
    private void initializeMessage() {
277
    private void initializeMessage() {
289
        Object newMessage = descriptor.getMessage();
278
        Object newMessage = descriptor.getMessage();
290
        // replace only if old and new messages are different
279
        // replace only if old and new messages are different
Lines 302-308 Link Here
302
            }
291
            }
303
            Dimension prefSize = currentMessage.getPreferredSize();
292
            Dimension prefSize = currentMessage.getPreferredSize();
304
            final Rectangle screenBounds = Utilities.getUsableScreenBounds();
293
            final Rectangle screenBounds = Utilities.getUsableScreenBounds();
305
            
294
306
            if (prefSize.width > screenBounds.width - 100
295
            if (prefSize.width > screenBounds.width - 100
307
                || prefSize.height > screenBounds.height- 100
296
                || prefSize.height > screenBounds.height- 100
308
                ) {
297
                ) {
Lines 323-329 Link Here
323
            } else {
312
            } else {
324
                toAdd = currentMessage;
313
                toAdd = currentMessage;
325
            }
314
            }
326
            
315
327
            if (! (descriptor instanceof WizardDescriptor) && descriptor.getNotificationLineSupport () != null) {
316
            if (! (descriptor instanceof WizardDescriptor) && descriptor.getNotificationLineSupport () != null) {
328
                JPanel enlargedToAdd = new JPanel (new BorderLayout ());
317
                JPanel enlargedToAdd = new JPanel (new BorderLayout ());
329
                enlargedToAdd.add (toAdd, BorderLayout.CENTER);
318
                enlargedToAdd.add (toAdd, BorderLayout.CENTER);
Lines 389-395 Link Here
389
        isJava17 = javaVersion.startsWith("1.7") || javaRuntimeName.startsWith("OpenJDK"); // NOI18N
378
        isJava17 = javaVersion.startsWith("1.7") || javaRuntimeName.startsWith("OpenJDK"); // NOI18N
390
        return isJava17;
379
        return isJava17;
391
    }
380
    }
392
    
381
393
    private static final class FixedHeightLabel extends JLabel {
382
    private static final class FixedHeightLabel extends JLabel {
394
383
395
        private static final int ESTIMATED_HEIGHT = 16;
384
        private static final int ESTIMATED_HEIGHT = 16;
Lines 423-442 Link Here
423
    private void initializePresenter() {
412
    private void initializePresenter() {
424
        if (currentMessage != null) 
413
        if (currentMessage != null) 
425
            return;
414
            return;
426
            
415
427
        initializeMessage();
416
        initializeMessage();
428
        
417
429
        updateHelp();
418
        updateHelp();
430
        
419
431
        initializeButtons();
420
        initializeButtons();
432
        haveCalledInitializeButtons = true;
421
        haveCalledInitializeButtons = true;
433
        
422
434
        descriptor.addPropertyChangeListener(this);
423
        descriptor.addPropertyChangeListener(this);
435
        addWindowListener(this);
424
        addWindowListener(this);
436
        
425
437
        initializeClosingOptions ();
426
        initializeClosingOptions ();
438
    }
427
    }
439
    
428
440
    /** Descriptor can be cached and reused. We need to remove listeners 
429
    /** Descriptor can be cached and reused. We need to remove listeners 
441
     *  from descriptor, buttons and disconnect componets from container hierarchy.
430
     *  from descriptor, buttons and disconnect componets from container hierarchy.
442
     */
431
     */
Lines 446-458 Link Here
446
        uninitializeButtons();
435
        uninitializeButtons();
447
        uninitializeClosingOptions ();
436
        uninitializeClosingOptions ();
448
    }
437
    }
449
    
450
    private final HackTypeAhead hack = new HackTypeAhead();
438
    private final HackTypeAhead hack = new HackTypeAhead();
451
    @Override
439
    @Override
452
    public void addNotify() {
440
    public void addNotify() {
453
        super.addNotify();
441
        super.addNotify();
454
        initializePresenter();
442
        initializePresenter();
455
        
443
456
        hack.activate();
444
        hack.activate();
457
    }
445
    }
458
446
Lines 460-466 Link Here
460
    public void removeNotify() {
448
    public void removeNotify() {
461
        super.removeNotify();
449
        super.removeNotify();
462
        uninitializePresenter();
450
        uninitializePresenter();
463
        
451
464
    }
452
    }
465
453
466
    /** Creates option pane message.
454
    /** Creates option pane message.
Lines 469-475 Link Here
469
        Object msg = descriptor.getMessage();
457
        Object msg = descriptor.getMessage();
470
        boolean override = true;
458
        boolean override = true;
471
        String strMsg = null, strMsgLower;
459
        String strMsg = null, strMsgLower;
472
        
460
473
        if (msg instanceof String) {
461
        if (msg instanceof String) {
474
            msg = ((String) msg).replace("\t", "    "); // NOI18N
462
            msg = ((String) msg).replace("\t", "    "); // NOI18N
475
            msg = ((String) msg).replace("\r", ""); // NOI18N
463
            msg = ((String) msg).replace("\r", ""); // NOI18N
Lines 488-500 Link Here
488
        if (override) {
476
        if (override) {
489
            // initialize component (override max char count per line in a message)
477
            // initialize component (override max char count per line in a message)
490
            optionPane = new JOptionPane(
478
            optionPane = new JOptionPane(
491
            msg,
479
                    msg,
492
            descriptor.getMessageType(),
480
                    descriptor.getMessageType(),
493
            0, // options type
481
                    0, // options type
494
            null, // icon
482
                    null, // icon
495
            new Object[0], // options
483
                    new Object[0], // options
496
            null // value
484
                    null // value
497
            ) {
485
                    ) {
498
                @Override
486
                @Override
499
                public int getMaxCharactersPerLineCount() {
487
                public int getMaxCharactersPerLineCount() {
500
                    return 100;
488
                    return 100;
Lines 503-517 Link Here
503
        } else {
491
        } else {
504
            //Do not override JOptionPane.getMaxCharactersPerLineCount for html text
492
            //Do not override JOptionPane.getMaxCharactersPerLineCount for html text
505
            optionPane = new JOptionPane(
493
            optionPane = new JOptionPane(
506
            msg,
494
                    msg,
507
            descriptor.getMessageType(),
495
                    descriptor.getMessageType(),
508
            0, // options type
496
                    0, // options type
509
            null, // icon
497
                    null, // icon
510
            new Object[0], // options
498
                    new Object[0], // options
511
            null // value
499
                    null // value
512
            );
500
                    );
513
        }
501
        }
514
        
502
515
        if (UIManager.getLookAndFeel().getClass() == MetalLookAndFeel.class ||
503
        if (UIManager.getLookAndFeel().getClass() == MetalLookAndFeel.class ||
516
            UIManager.getLookAndFeel().getClass() == BasicLookAndFeel.class) {
504
            UIManager.getLookAndFeel().getClass() == BasicLookAndFeel.class) {
517
            optionPane.setUI(new javax.swing.plaf.basic.BasicOptionPaneUI() {
505
            optionPane.setUI(new javax.swing.plaf.basic.BasicOptionPaneUI() {
Lines 571-599 Link Here
571
                    modifyListener(currentSecondaryButtons[i], buttonListener, false);
559
                    modifyListener(currentSecondaryButtons[i], buttonListener, false);
572
                }
560
                }
573
            }
561
            }
574
            
562
575
            getContentPane().remove(currentButtonsPanel);
563
            getContentPane().remove(currentButtonsPanel);
576
            currentButtonsPanel = null;
564
            currentButtonsPanel = null;
577
        }
565
        }
578
    }
566
    }
579
    
567
580
    private void initializeClosingOptions (boolean init) {
568
    private void initializeClosingOptions (boolean init) {
581
        Object[] options = getClosingOptions ();
569
        Object[] options = getClosingOptions ();
582
        
570
583
        if (options == null) return ;
571
        if (options == null) return ;
572
        if (options.length == 0) {
573
            setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
574
        }
584
        for (int i = 0; i < options.length; i++) {
575
        for (int i = 0; i < options.length; i++) {
585
            modifyListener (options[i], buttonListener, init);
576
            modifyListener (options[i], buttonListener, init);
586
        }
577
        }
587
    }
578
    }
588
    
579
589
    private void initializeClosingOptions () {
580
    private void initializeClosingOptions () {
590
        initializeClosingOptions (true);
581
        initializeClosingOptions (true);
591
    }
582
    }
592
    
583
593
    private void uninitializeClosingOptions () {
584
    private void uninitializeClosingOptions () {
594
        initializeClosingOptions (false);
585
        initializeClosingOptions (false);
595
    }
586
    }
596
    
587
597
    /**
588
    /**
598
     * On Aqua look and feel, options should be sorted such that the default
589
     * On Aqua look and feel, options should be sorted such that the default
599
     * button is always rightmost, and 'yes' options appear to thr right of
590
     * button is always rightmost, and 'yes' options appear to thr right of
Lines 607-640 Link Here
607
        } else {
598
        } else {
608
            result = 0;
599
            result = 0;
609
        }
600
        }
610
        
601
611
        if (isDefaultButton) {
602
        if (isDefaultButton) {
612
            result++;
603
            result++;
613
        }
604
        }
614
        return result;
605
        return result;
615
    }
606
    }
616
    
607
617
    protected final void initializeButtons() {
608
    protected final void initializeButtons() {
618
        // -----------------------------------------------------------------------------
609
        // -----------------------------------------------------------------------------
619
        // If there were any buttons previously, remove them and removeActionListener from them
610
        // If there were any buttons previously, remove them and removeActionListener from them
620
        
611
621
        Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager ().getFocusOwner ();
612
        Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager ().getFocusOwner ();
622
613
623
        boolean dontShowHelp = Constants.DO_NOT_SHOW_HELP_IN_DIALOGS ||
614
        boolean dontShowHelp = Constants.DO_NOT_SHOW_HELP_IN_DIALOGS ||
624
                ( descriptor instanceof WizardDescriptor && ( Boolean.FALSE.equals (((WizardDescriptor)descriptor).getProperty (WizardDescriptor.PROP_HELP_DISPLAYED)) )); // NOI18N
615
                ( descriptor instanceof WizardDescriptor && ( Boolean.FALSE.equals (((WizardDescriptor)descriptor).getProperty (WizardDescriptor.PROP_HELP_DISPLAYED)) )); // NOI18N
625
        boolean helpButtonShown =
616
        boolean helpButtonShown =
626
            stdHelpButton.isShowing() || ( descriptor instanceof WizardDescriptor && !dontShowHelp );
617
            stdHelpButton.isShowing() || ( descriptor instanceof WizardDescriptor && !dontShowHelp );
627
        
618
628
        
619
629
        uninitializeButtons();
620
        uninitializeButtons();
630
        
621
631
        Object[] primaryOptions = descriptor.getOptions();
622
        Object[] primaryOptions = descriptor.getOptions();
632
        Object[] secondaryOptions = descriptor.getAdditionalOptions();
623
        Object[] secondaryOptions = descriptor.getAdditionalOptions();
633
        currentAlign = getOptionsAlign();
624
        currentAlign = getOptionsAlign();
634
        
625
635
        // -----------------------------------------------------------------------------
626
        // -----------------------------------------------------------------------------
636
        // Obtain main (primary) and additional (secondary) buttons
627
        // Obtain main (primary) and additional (secondary) buttons
637
        
628
638
        currentPrimaryButtons = null;
629
        currentPrimaryButtons = null;
639
        currentSecondaryButtons = null;
630
        currentSecondaryButtons = null;
640
631
Lines 644-650 Link Here
644
            //No mac dialogs with buttons on side
635
            //No mac dialogs with buttons on side
645
            currentAlign = DialogDescriptor.BOTTOM_ALIGN;
636
            currentAlign = DialogDescriptor.BOTTOM_ALIGN;
646
        }
637
        }
647
        
638
648
        // explicitly provided options (AKA buttons)
639
        // explicitly provided options (AKA buttons)
649
        // JST: The following line causes only problems,
640
        // JST: The following line causes only problems,
650
        //      I hope that my change will not cause additional ones ;-)
641
        //      I hope that my change will not cause additional ones ;-)
Lines 720-728 Link Here
720
                    break;
711
                    break;
721
            }
712
            }
722
        }
713
        }
723
        
714
724
        // Automatically add a help button if needed.
715
        // Automatically add a help button if needed.
725
        
716
726
        if (!dontShowHelp && (currentHelp != null || helpButtonShown)) {
717
        if (!dontShowHelp && (currentHelp != null || helpButtonShown)) {
727
            if (currentPrimaryButtons == null) currentPrimaryButtons = new Component[] { };
718
            if (currentPrimaryButtons == null) currentPrimaryButtons = new Component[] { };
728
            Component[] cPB2 = new Component[currentPrimaryButtons.length + 1];
719
            Component[] cPB2 = new Component[currentPrimaryButtons.length + 1];
Lines 738-744 Link Here
738
729
739
            stdHelpButton.setEnabled(currentHelp != null);
730
            stdHelpButton.setEnabled(currentHelp != null);
740
        }
731
        }
741
        
732
742
        if ((secondaryOptions != null) && (secondaryOptions.length != 0)) {
733
        if ((secondaryOptions != null) && (secondaryOptions.length != 0)) {
743
            currentSecondaryButtons = new Component [secondaryOptions.length];
734
            currentSecondaryButtons = new Component [secondaryOptions.length];
744
            Arrays.sort (secondaryOptions, this);
735
            Arrays.sort (secondaryOptions, this);
Lines 766-784 Link Here
766
                }
757
                }
767
            }
758
            }
768
        }
759
        }
769
        
760
770
        // -----------------------------------------------------------------------------
761
        // -----------------------------------------------------------------------------
771
        // Create panels for main (primary) and additional (secondary) buttons and add to content pane
762
        // Create panels for main (primary) and additional (secondary) buttons and add to content pane
772
        
763
773
        if (currentAlign == DialogDescriptor.BOTTOM_ALIGN || currentAlign == -1) {
764
        if (currentAlign == DialogDescriptor.BOTTOM_ALIGN || currentAlign == -1) {
774
            
765
775
            JPanel panelForPrimary = null;
766
            JPanel panelForPrimary = null;
776
            JPanel panelForSecondary = null;
767
            JPanel panelForSecondary = null;
777
            
768
778
769
779
            if (currentPrimaryButtons != null) {
770
            if (currentPrimaryButtons != null) {
780
                panelForPrimary = new JPanel();
771
                panelForPrimary = new JPanel();
781
                
772
782
                if (currentAlign == -1) {
773
                if (currentAlign == -1) {
783
                    panelForPrimary.setLayout(new org.openide.awt.EqualFlowLayout());
774
                    panelForPrimary.setLayout(new org.openide.awt.EqualFlowLayout());
784
                } else {
775
                } else {
Lines 789-795 Link Here
789
                    panelForPrimary.add(currentPrimaryButtons[i]);
780
                    panelForPrimary.add(currentPrimaryButtons[i]);
790
                }
781
                }
791
            }
782
            }
792
            
783
793
            if (currentSecondaryButtons != null) {
784
            if (currentSecondaryButtons != null) {
794
                panelForSecondary = new JPanel();
785
                panelForSecondary = new JPanel();
795
                panelForSecondary.setLayout(new org.openide.awt.EqualFlowLayout(FlowLayout.LEFT));
786
                panelForSecondary.setLayout(new org.openide.awt.EqualFlowLayout(FlowLayout.LEFT));
Lines 798-804 Link Here
798
                    panelForSecondary.add(currentSecondaryButtons[i]);
789
                    panelForSecondary.add(currentSecondaryButtons[i]);
799
                }
790
                }
800
            }
791
            }
801
            
792
802
            // both primary and secondary buttons are used
793
            // both primary and secondary buttons are used
803
            if ((panelForPrimary != null) && (panelForSecondary != null)) {
794
            if ((panelForPrimary != null) && (panelForSecondary != null)) {
804
                currentButtonsPanel = new JPanel();
795
                currentButtonsPanel = new JPanel();
Lines 810-816 Link Here
810
            } else {
801
            } else {
811
                currentButtonsPanel = panelForSecondary;
802
                currentButtonsPanel = panelForSecondary;
812
            }
803
            }
813
            
804
814
            // add final button panel to the dialog
805
            // add final button panel to the dialog
815
            if ((currentButtonsPanel != null)&&(currentButtonsPanel.getComponentCount() != 0)) {
806
            if ((currentButtonsPanel != null)&&(currentButtonsPanel.getComponentCount() != 0)) {
816
                if (currentButtonsPanel.getBorder() == null) {
807
                if (currentButtonsPanel.getBorder() == null) {
Lines 818-824 Link Here
818
                }
809
                }
819
                getContentPane().add(currentButtonsPanel, BorderLayout.SOUTH);
810
                getContentPane().add(currentButtonsPanel, BorderLayout.SOUTH);
820
            }
811
            }
821
            
812
822
        } else if (currentAlign == DialogDescriptor.RIGHT_ALIGN) {
813
        } else if (currentAlign == DialogDescriptor.RIGHT_ALIGN) {
823
            currentButtonsPanel = new JPanel();
814
            currentButtonsPanel = new JPanel();
824
            currentButtonsPanel.setLayout(new GridBagLayout());
815
            currentButtonsPanel.setLayout(new GridBagLayout());
Lines 827-847 Link Here
827
            gbc.weightx = 1.0f;
818
            gbc.weightx = 1.0f;
828
            gbc.insets = new Insets(5, 4, 2, 5);
819
            gbc.insets = new Insets(5, 4, 2, 5);
829
            gbc.fill = GridBagConstraints.HORIZONTAL;
820
            gbc.fill = GridBagConstraints.HORIZONTAL;
830
            
821
831
            if (currentPrimaryButtons != null) {
822
            if (currentPrimaryButtons != null) {
832
                for (int i = 0; i < currentPrimaryButtons.length; i++) {
823
                for (int i = 0; i < currentPrimaryButtons.length; i++) {
833
                    modifyListener(currentPrimaryButtons[i], buttonListener, true); // add button listener
824
                    modifyListener(currentPrimaryButtons[i], buttonListener, true); // add button listener
834
                    currentButtonsPanel.add(currentPrimaryButtons[i], gbc);
825
                    currentButtonsPanel.add(currentPrimaryButtons[i], gbc);
835
                }
826
                }
836
            }
827
            }
837
            
828
838
            GridBagConstraints padding = new GridBagConstraints();
829
            GridBagConstraints padding = new GridBagConstraints();
839
            padding.gridwidth = GridBagConstraints.REMAINDER;
830
            padding.gridwidth = GridBagConstraints.REMAINDER;
840
            padding.weightx = 1.0f;
831
            padding.weightx = 1.0f;
841
            padding.weighty = 1.0f;
832
            padding.weighty = 1.0f;
842
            padding.fill = GridBagConstraints.BOTH;
833
            padding.fill = GridBagConstraints.BOTH;
843
            currentButtonsPanel.add(new JPanel(), padding);
834
            currentButtonsPanel.add(new JPanel(), padding);
844
            
835
845
            gbc.insets = new Insets(2, 4, 5, 5);
836
            gbc.insets = new Insets(2, 4, 5, 5);
846
            if (currentSecondaryButtons != null) {
837
            if (currentSecondaryButtons != null) {
847
                for (int i = 0; i < currentSecondaryButtons.length; i++) {
838
                for (int i = 0; i < currentSecondaryButtons.length; i++) {
Lines 849-855 Link Here
849
                    currentButtonsPanel.add(currentSecondaryButtons[i], gbc);
840
                    currentButtonsPanel.add(currentSecondaryButtons[i], gbc);
850
                }
841
                }
851
            }
842
            }
852
            
843
853
            // add final button panel to the dialog
844
            // add final button panel to the dialog
854
            if (currentButtonsPanel != null) {
845
            if (currentButtonsPanel != null) {
855
                if (currentButtonsPanel.getBorder() == null) {
846
                if (currentButtonsPanel.getBorder() == null) {
Lines 857-874 Link Here
857
                }
848
                }
858
                getContentPane().add(currentButtonsPanel, BorderLayout.EAST);
849
                getContentPane().add(currentButtonsPanel, BorderLayout.EAST);
859
            }
850
            }
860
            
851
861
        }
852
        }
862
        updateDefaultButton();
853
        updateDefaultButton();
863
        
854
864
        
855
865
        Component fo = KeyboardFocusManager.getCurrentKeyboardFocusManager ().getFocusOwner ();
856
        Component fo = KeyboardFocusManager.getCurrentKeyboardFocusManager ().getFocusOwner ();
866
        
857
867
        if (fo != focusOwner && focusOwner != null) {
858
        if (fo != focusOwner && focusOwner != null) {
868
            focusOwner.requestFocus();
859
            focusOwner.requestFocus();
869
        }
860
        }
870
    }
861
    }
871
    
862
872
    /** Checks default button and updates it
863
    /** Checks default button and updates it
873
     */
864
     */
874
    private void updateDefaultButton() {
865
    private void updateDefaultButton() {
Lines 924-945 Link Here
924
        // no default capable button found
915
        // no default capable button found
925
        getRootPane().setDefaultButton(null);
916
        getRootPane().setDefaultButton(null);
926
    }
917
    }
927
    
918
928
    private void updateNotificationLine (int msgType, Object o) {
919
    private void updateNotificationLine (int msgType, Object o) {
929
        String msg = o == null ? null : o.toString ();
920
        String msg = o == null ? null : o.toString ();
930
        if (msg != null && msg.trim().length() > 0) {
921
        if (msg != null && msg.trim().length() > 0) {
931
            switch (msgType) {
922
            switch (msgType) {
932
                case MSG_TYPE_ERROR:
923
                case MSG_TYPE_ERROR:
933
                    prepareMessage(notificationLine, ImageUtilities.loadImageIcon("org/netbeans/core/windows/resources/error.png", false),
924
                    prepareMessage(notificationLine, ImageUtilities.loadImageIcon("org/netbeans/core/windows/resources/error.png", false),
934
                        nbErrorForeground);
925
                            nbErrorForeground);
935
                    break;
926
                    break;
936
                case MSG_TYPE_WARNING:
927
                case MSG_TYPE_WARNING:
937
                    prepareMessage(notificationLine, ImageUtilities.loadImageIcon("org/netbeans/core/windows/resources/warning.png", false),
928
                    prepareMessage(notificationLine, ImageUtilities.loadImageIcon("org/netbeans/core/windows/resources/warning.png", false),
938
                        nbWarningForeground);
929
                            nbWarningForeground);
939
                    break;
930
                    break;
940
                case MSG_TYPE_INFO:
931
                case MSG_TYPE_INFO:
941
                    prepareMessage(notificationLine, ImageUtilities.loadImageIcon("org/netbeans/core/windows/resources/info.png", false),
932
                    prepareMessage(notificationLine, ImageUtilities.loadImageIcon("org/netbeans/core/windows/resources/info.png", false),
942
                        nbInfoForeground);
933
                            nbInfoForeground);
943
                    break;
934
                    break;
944
                default:
935
                default:
945
            }
936
            }
Lines 980-991 Link Here
980
            }
971
            }
981
        }
972
        }
982
    }
973
    }
983
    
974
984
    private void modifyListener(Object comp, ButtonListener l, boolean add) {
975
    private void modifyListener(Object comp, ButtonListener l, boolean add) {
985
        // on JButtons attach simply by method call
976
        // on JButtons attach simply by method call
986
        if (comp instanceof JButton) {
977
        if (comp instanceof JButton) {
987
            JButton b = (JButton)comp;
978
            JButton b = (JButton)comp;
988
            if (add) { 
979
            if (add) {
989
                List listeners;
980
                List listeners;
990
                listeners = Arrays.asList (b.getActionListeners ());
981
                listeners = Arrays.asList (b.getActionListeners ());
991
                if (!listeners.contains (l)) {
982
                if (!listeners.contains (l)) {
Lines 1030-1043 Link Here
1030
            }
1021
            }
1031
        }
1022
        }
1032
    }
1023
    }
1033
    
1024
1034
    /** Shows the dialog, used in method show so no inner class is needed.
1025
    /** Shows the dialog, used in method show so no inner class is needed.
1035
     */
1026
     */
1036
    private void superShow() {
1027
    private void superShow() {
1037
        assert SwingUtilities.isEventDispatchThread () : "Invoked super.show() in AWT event thread."; // NOI18N
1028
        assert SwingUtilities.isEventDispatchThread () : "Invoked super.show() in AWT event thread."; // NOI18N
1038
        super.show();
1029
        super.show();
1039
    }
1030
    }
1040
    
1031
1041
    @Override @Deprecated
1032
    @Override @Deprecated
1042
    public void show() {
1033
    public void show() {
1043
        //Bugfix #29993: Call show() asynchronously for non modal dialogs.
1034
        //Bugfix #29993: Call show() asynchronously for non modal dialogs.
Lines 1055-1066 Link Here
1055
            }
1046
            }
1056
        }
1047
        }
1057
    }
1048
    }
1058
    
1049
1059
    public Void run() {
1050
    public Void run() {
1060
        doShow();
1051
        doShow();
1061
        return null;
1052
        return null;
1062
    }
1053
    }
1063
    
1054
1064
    private void doShow () {
1055
    private void doShow () {
1065
        NbPresenter prev = null;
1056
        NbPresenter prev = null;
1066
        if (isModal()) {
1057
        if (isModal()) {
Lines 1068-1082 Link Here
1068
            currentModalDialog = this;
1059
            currentModalDialog = this;
1069
            fireChangeEvent();
1060
            fireChangeEvent();
1070
        }
1061
        }
1071
        
1062
1072
        superShow();
1063
        superShow();
1073
        
1064
1074
        if (currentModalDialog != prev) {
1065
        if (currentModalDialog != prev) {
1075
            currentModalDialog = prev;
1066
            currentModalDialog = prev;
1076
            fireChangeEvent();
1067
            fireChangeEvent();
1077
        }
1068
        }
1078
    }
1069
    }
1079
    
1070
1080
    public void propertyChange(final java.beans.PropertyChangeEvent evt) {
1071
    public void propertyChange(final java.beans.PropertyChangeEvent evt) {
1081
        if( !SwingUtilities.isEventDispatchThread() ) {
1072
        if( !SwingUtilities.isEventDispatchThread() ) {
1082
            SwingUtilities.invokeLater(new Runnable() {
1073
            SwingUtilities.invokeLater(new Runnable() {
Lines 1087-1093 Link Here
1087
            return;
1078
            return;
1088
        }
1079
        }
1089
        boolean update = false;
1080
        boolean update = false;
1090
        
1081
1091
        if (DialogDescriptor.PROP_OPTIONS.equals(evt.getPropertyName())) {
1082
        if (DialogDescriptor.PROP_OPTIONS.equals(evt.getPropertyName())) {
1092
            initializeButtons();
1083
            initializeButtons();
1093
            update = true;
1084
            update = true;
Lines 1134-1140 Link Here
1134
            // XXX: need set update on true?
1125
            // XXX: need set update on true?
1135
            updateNotificationLine (MSG_TYPE_ERROR, evt.getNewValue ());
1126
            updateNotificationLine (MSG_TYPE_ERROR, evt.getNewValue ());
1136
        }
1127
        }
1137
        
1128
1138
        if (update) {
1129
        if (update) {
1139
            Dimension sz = getSize();
1130
            Dimension sz = getSize();
1140
            Dimension prefSize = getPreferredSize();
1131
            Dimension prefSize = getPreferredSize();
Lines 1147-1153 Link Here
1147
            repaint();
1138
            repaint();
1148
        }
1139
        }
1149
    }
1140
    }
1150
    
1141
1151
    private void updateHelp() {
1142
    private void updateHelp() {
1152
        //System.err.println ("Updating help for NbDialog...");
1143
        //System.err.println ("Updating help for NbDialog...");
1153
        HelpCtx help = getHelpCtx();
1144
        HelpCtx help = getHelpCtx();
Lines 1159-1165 Link Here
1159
                help = HelpCtx.findHelp((Component) msg);
1150
                help = HelpCtx.findHelp((Component) msg);
1160
            }
1151
            }
1161
            if (HelpCtx.DEFAULT_HELP.equals(help)) help = null;
1152
            if (HelpCtx.DEFAULT_HELP.equals(help)) help = null;
1162
        }
1153
            }
1163
        if (! Utilities.compareObjects(currentHelp, help)) {
1154
        if (! Utilities.compareObjects(currentHelp, help)) {
1164
            currentHelp = help;
1155
            currentHelp = help;
1165
            if (help != null && help.getHelpID() != null) {
1156
            if (help != null && help.getHelpID() != null) {
Lines 1168-1201 Link Here
1168
            }
1159
            }
1169
            // Refresh button list if it had already been created.
1160
            // Refresh button list if it had already been created.
1170
            if (haveCalledInitializeButtons) initializeButtons();
1161
            if (haveCalledInitializeButtons) initializeButtons();
1162
            }
1171
        }
1163
        }
1172
    }
1164
1173
    
1174
    /** Options align.
1165
    /** Options align.
1175
     */
1166
     */
1176
    protected int getOptionsAlign() {
1167
    protected int getOptionsAlign() {
1177
        return -1;
1168
        return -1;
1178
    }
1169
    }
1179
    
1170
1180
    /** Getter for button listener or null
1171
    /** Getter for button listener or null
1181
     */
1172
     */
1182
    protected ActionListener getButtonListener() {
1173
    protected ActionListener getButtonListener() {
1183
        return null;
1174
        return null;
1184
    }
1175
    }
1185
    
1176
1186
    /** Closing options.
1177
    /** Closing options.
1187
     */
1178
     */
1188
    protected Object[] getClosingOptions() {
1179
    protected Object[] getClosingOptions() {
1189
        return null;
1180
        return null;
1190
    }
1181
    }
1191
    
1182
1192
    /** Updates help.
1183
    /** Updates help.
1193
     */
1184
     */
1194
    protected HelpCtx getHelpCtx() {
1185
    protected HelpCtx getHelpCtx() {
1195
        return null;
1186
        return null;
1196
    }
1187
    }
1197
    
1188
1198
    
1199
    public void windowDeactivated(final java.awt.event.WindowEvent p1) {
1189
    public void windowDeactivated(final java.awt.event.WindowEvent p1) {
1200
    }
1190
    }
1201
    public void windowClosed(final java.awt.event.WindowEvent p1) {
1191
    public void windowClosed(final java.awt.event.WindowEvent p1) {
Lines 1214-1220 Link Here
1214
    }
1204
    }
1215
    public void windowActivated(final java.awt.event.WindowEvent p1) {
1205
    public void windowActivated(final java.awt.event.WindowEvent p1) {
1216
    }
1206
    }
1217
    
1207
1218
    // Used by JavaHelp:
1208
    // Used by JavaHelp:
1219
    public static void addChangeListener(ChangeListener l) {
1209
    public static void addChangeListener(ChangeListener l) {
1220
        cs.addChangeListener(l);
1210
        cs.addChangeListener(l);
Lines 1229-1235 Link Here
1229
            }
1219
            }
1230
        });
1220
        });
1231
    }
1221
    }
1232
    
1222
1233
    private final class EscapeAction extends AbstractAction {
1223
    private final class EscapeAction extends AbstractAction {
1234
1224
1235
        public EscapeAction () {
1225
        public EscapeAction () {
Lines 1239-1247 Link Here
1239
        public void actionPerformed(ActionEvent e) {
1229
        public void actionPerformed(ActionEvent e) {
1240
            buttonListener.actionPerformed(e);
1230
            buttonListener.actionPerformed(e);
1241
        }
1231
        }
1242
        
1243
    }
1232
    }
1244
    
1233
1245
    /** Button listener
1234
    /** Button listener
1246
     */
1235
     */
1247
    private class ButtonListener implements ActionListener, ComponentListener, PropertyChangeListener {
1236
    private class ButtonListener implements ActionListener, ComponentListener, PropertyChangeListener {
Lines 1249-1262 Link Here
1249
        public void actionPerformed(ActionEvent evt) {
1238
        public void actionPerformed(ActionEvent evt) {
1250
            boolean isAqua = "Aqua".equals (UIManager.getLookAndFeel().getID()) || //NOI18N
1239
            boolean isAqua = "Aqua".equals (UIManager.getLookAndFeel().getID()) || //NOI18N
1251
                            "true".equalsIgnoreCase (System.getProperty ("xtest.looks_as_mac"));
1240
                            "true".equalsIgnoreCase (System.getProperty ("xtest.looks_as_mac"));
1252
            
1241
1253
            Object pressedOption = evt.getSource();
1242
            Object pressedOption = evt.getSource();
1254
            // handle ESCAPE
1243
            // handle ESCAPE
1255
            if (ESCAPE_COMMAND.equals (evt.getActionCommand ())) {
1244
            if (ESCAPE_COMMAND.equals (evt.getActionCommand ())) {
1256
                MenuElement[] selPath = MenuSelectionManager.defaultManager().getSelectedPath();
1245
                MenuElement[] selPath = MenuSelectionManager.defaultManager().getSelectedPath();
1257
                // part of #130919 fix - handle ESC key well in dialogs with menus
1246
                // part of #130919 fix - handle ESC key well in dialogs with menus
1258
                if (selPath == null || selPath.length == 0) {
1247
                if (selPath == null || selPath.length == 0) {
1259
                    pressedOption = NotifyDescriptor.CLOSED_OPTION;
1248
                    //check if closingOptions is != null && 0
1249
                    if (getClosingOptions() != null && getClosingOptions().length == 0) {
1250
                        pressedOption = WindowConstants.DO_NOTHING_ON_CLOSE;
1251
                    } else {
1252
                        pressedOption = NotifyDescriptor.CLOSED_OPTION;
1253
                    }
1260
                } else {
1254
                } else {
1261
                    MenuSelectionManager.defaultManager().clearSelectedPath();
1255
                    MenuSelectionManager.defaultManager().clearSelectedPath();
1262
                    return ;
1256
                    return ;
Lines 1267-1278 Link Here
1267
                    showHelp(currentHelp);
1261
                    showHelp(currentHelp);
1268
                    return;
1262
                    return;
1269
                }
1263
                }
1270
                
1264
1271
                Object[] options = descriptor.getOptions();
1265
                Object[] options = descriptor.getOptions();
1272
                if (isAqua && options != null) {
1266
                if (isAqua && options != null) {
1273
                    Arrays.sort (options, NbPresenter.this);
1267
                    Arrays.sort (options, NbPresenter.this);
1274
                }
1268
                }
1275
                
1269
1276
                if (
1270
                if (
1277
                options != null &&
1271
                options != null &&
1278
                currentPrimaryButtons != null &&
1272
                currentPrimaryButtons != null &&
Lines 1287-1298 Link Here
1287
                        }
1281
                        }
1288
                    }
1282
                    }
1289
                }
1283
                }
1290
                
1284
1291
                options = descriptor.getAdditionalOptions();
1285
                options = descriptor.getAdditionalOptions();
1292
                if (isAqua && options != null) {
1286
                if (isAqua && options != null) {
1293
                    Arrays.sort (options, NbPresenter.this);
1287
                    Arrays.sort (options, NbPresenter.this);
1294
                }
1288
                }
1295
                
1289
1296
                if (
1290
                if (
1297
                options != null &&
1291
                options != null &&
1298
                currentSecondaryButtons != null &&
1292
                currentSecondaryButtons != null &&
Lines 1304-1310 Link Here
1304
                        }
1298
                        }
1305
                    }
1299
                    }
1306
                }
1300
                }
1307
                
1301
1308
                if (evt.getSource() == stdYesButton) {
1302
                if (evt.getSource() == stdYesButton) {
1309
                    pressedOption = NotifyDescriptor.YES_OPTION;
1303
                    pressedOption = NotifyDescriptor.YES_OPTION;
1310
                } else if (evt.getSource() == stdNoButton) {
1304
                } else if (evt.getSource() == stdNoButton) {
Lines 1319-1328 Link Here
1319
            }
1313
            }
1320
1314
1321
            descriptor.setValue(pressedOption);
1315
            descriptor.setValue(pressedOption);
1322
            
1316
1323
            ActionListener al = getButtonListener();
1317
            ActionListener al = getButtonListener();
1324
            if (al != null) {
1318
            if (al != null) {
1325
                
1319
1326
                if (pressedOption == evt.getSource()) {
1320
                if (pressedOption == evt.getSource()) {
1327
                    al.actionPerformed(evt);
1321
                    al.actionPerformed(evt);
1328
                } else {
1322
                } else {
Lines 1331-1344 Link Here
1331
                    ));
1325
                    ));
1332
                }
1326
                }
1333
            }
1327
            }
1334
            
1328
1335
            Object[] arr = getClosingOptions();
1329
            Object[] arr = getClosingOptions();
1336
            if (arr == null || pressedOption == NotifyDescriptor.CLOSED_OPTION) {
1330
            if (arr == null || pressedOption == NotifyDescriptor.CLOSED_OPTION) {
1337
                // all options should close
1331
                // all options should close
1338
                dispose();
1332
                dispose();
1339
            } else {
1333
            } else {
1340
                java.util.List l = java.util.Arrays.asList(arr);
1334
                java.util.List l = java.util.Arrays.asList(arr);
1341
                
1335
1342
                if (l.contains(pressedOption)) {
1336
                if (l.contains(pressedOption)) {
1343
                    dispose();
1337
                    dispose();
1344
                }
1338
                }
Lines 1349-1369 Link Here
1349
        }
1343
        }
1350
        public void componentResized(final java.awt.event.ComponentEvent p1) {
1344
        public void componentResized(final java.awt.event.ComponentEvent p1) {
1351
        }
1345
        }
1352
        
1346
1353
        public void componentHidden(final java.awt.event.ComponentEvent p1) {
1347
        public void componentHidden(final java.awt.event.ComponentEvent p1) {
1354
            updateDefaultButton();
1348
            updateDefaultButton();
1355
        }
1349
        }
1356
        
1350
1357
        public void componentMoved(final java.awt.event.ComponentEvent p1) {
1351
        public void componentMoved(final java.awt.event.ComponentEvent p1) {
1358
        }
1352
        }
1359
        
1353
1360
        public void propertyChange(final java.beans.PropertyChangeEvent p1) {
1354
        public void propertyChange(final java.beans.PropertyChangeEvent p1) {
1361
            if ("enabled".equals(p1.getPropertyName())) {
1355
            if ("enabled".equals(p1.getPropertyName())) {
1362
                updateDefaultButton();
1356
                updateDefaultButton();
1363
            }
1357
            }
1364
        }
1358
        }
1365
    }
1359
    }
1366
    
1360
1367
    @Override
1361
    @Override
1368
    public javax.accessibility.AccessibleContext getAccessibleContext() {
1362
    public javax.accessibility.AccessibleContext getAccessibleContext() {
1369
        if (accessibleContext == null) {
1363
        if (accessibleContext == null) {
Lines 1371-1389 Link Here
1371
        }
1365
        }
1372
        return accessibleContext;
1366
        return accessibleContext;
1373
    }
1367
    }
1374
    
1368
1375
    private static String getMessageTypeDescription(int messageType) {
1369
    private static String getMessageTypeDescription(int messageType) {
1376
        switch(messageType) {
1370
        switch(messageType) {
1377
        case NotifyDescriptor.ERROR_MESSAGE:
1371
            case NotifyDescriptor.ERROR_MESSAGE:
1378
            return NbBundle.getBundle(NbPresenter.class).getString("ACSD_ErrorMessage"); // NOI18N
1372
                return NbBundle.getBundle(NbPresenter.class).getString("ACSD_ErrorMessage"); // NOI18N
1379
        case NotifyDescriptor.WARNING_MESSAGE:
1373
            case NotifyDescriptor.WARNING_MESSAGE:
1380
            return NbBundle.getBundle(NbPresenter.class).getString("ACSD_WarningMessage"); // NOI18N
1374
                return NbBundle.getBundle(NbPresenter.class).getString("ACSD_WarningMessage"); // NOI18N
1381
        case NotifyDescriptor.QUESTION_MESSAGE:
1375
            case NotifyDescriptor.QUESTION_MESSAGE:
1382
            return NbBundle.getBundle(NbPresenter.class).getString("ACSD_QuestionMessage"); // NOI18N
1376
                return NbBundle.getBundle(NbPresenter.class).getString("ACSD_QuestionMessage"); // NOI18N
1383
        case NotifyDescriptor.INFORMATION_MESSAGE:
1377
            case NotifyDescriptor.INFORMATION_MESSAGE:
1384
            return NbBundle.getBundle(NbPresenter.class).getString("ACSD_InformationMessage"); // NOI18N
1378
                return NbBundle.getBundle(NbPresenter.class).getString("ACSD_InformationMessage"); // NOI18N
1385
        case NotifyDescriptor.PLAIN_MESSAGE:
1379
            case NotifyDescriptor.PLAIN_MESSAGE:
1386
            return NbBundle.getBundle(NbPresenter.class).getString("ACSD_PlainMessage"); // NOI18N
1380
                return NbBundle.getBundle(NbPresenter.class).getString("ACSD_PlainMessage"); // NOI18N
1387
        }
1381
        }
1388
        return ""; // NOI18N
1382
        return ""; // NOI18N
1389
    }
1383
    }
Lines 1396-1402 Link Here
1396
                return accessibleName;
1390
                return accessibleName;
1397
            } else {
1391
            } else {
1398
                if (currentMessage instanceof javax.accessibility.Accessible
1392
                if (currentMessage instanceof javax.accessibility.Accessible
1399
                    && currentMessage.getAccessibleContext().getAccessibleName() != null) {
1393
                        && currentMessage.getAccessibleContext().getAccessibleName() != null) {
1400
                    return currentMessage.getAccessibleContext().getAccessibleName();
1394
                    return currentMessage.getAccessibleContext().getAccessibleName();
1401
                } else {
1395
                } else {
1402
                    return super.getAccessibleName();
1396
                    return super.getAccessibleName();
Lines 1409-1419 Link Here
1409
                return accessibleDescription;
1403
                return accessibleDescription;
1410
            } else {
1404
            } else {
1411
                if (currentMessage instanceof javax.accessibility.Accessible
1405
                if (currentMessage instanceof javax.accessibility.Accessible
1412
                    && currentMessage.getAccessibleContext().getAccessibleDescription() != null) {
1406
                        && currentMessage.getAccessibleContext().getAccessibleDescription() != null) {
1413
                    return java.text.MessageFormat.format(
1407
                    return java.text.MessageFormat.format(
1414
                        getMessageTypeDescription(descriptor.getMessageType()),
1408
                            getMessageTypeDescription(descriptor.getMessageType()),
1415
                        new Object[] {
1409
                        new Object[] {
1416
                            currentMessage.getAccessibleContext().getAccessibleDescription()
1410
                                currentMessage.getAccessibleContext().getAccessibleDescription()
1417
                        }
1411
                        }
1418
                    );
1412
                    );
1419
                } else {
1413
                } else {
Lines 1422-1428 Link Here
1422
            }
1416
            }
1423
        }
1417
        }
1424
    }
1418
    }
1425
1426
    static Field markers;
1419
    static Field markers;
1427
    static Method dequeue;
1420
    static Method dequeue;
1428
    static {
1421
    static {
Lines 1437-1456 Link Here
1437
            }
1430
            }
1438
        }
1431
        }
1439
    }
1432
    }
1440
    
1433
1441
    private final class HackTypeAhead implements Runnable {
1434
    private final class HackTypeAhead implements Runnable {
1442
        private RequestProcessor.Task task = RequestProcessor.getDefault().create(this);
1435
        private RequestProcessor.Task task = RequestProcessor.getDefault().create(this);
1443
        
1436
1444
        
1445
        public HackTypeAhead() {
1437
        public HackTypeAhead() {
1446
        }
1438
        }
1447
        
1439
1448
        public void activate() {
1440
        public void activate() {
1449
            if (markers != null) {
1441
            if (markers != null) {
1450
                task.schedule(1000);
1442
                task.schedule(1000);
1451
            }
1443
            }
1452
        }
1444
        }
1453
        
1445
1454
        public void run() {
1446
        public void run() {
1455
            if (!SwingUtilities.isEventDispatchThread()) {
1447
            if (!SwingUtilities.isEventDispatchThread()) {
1456
                SwingUtilities.invokeLater(this);
1448
                SwingUtilities.invokeLater(this);
Lines 1480-1487 Link Here
1480
1472
1481
    /** Shows a specified HelpCtx in IDE's help window.
1473
    /** Shows a specified HelpCtx in IDE's help window.
1482
     * XXX would be better to directly depend on org.netbeans.api.javahelp.Help
1474
     * XXX would be better to directly depend on org.netbeans.api.javahelp.Help
1483
    * @param helpCtx thehelp to be shown
1475
     * @param helpCtx thehelp to be shown
1484
    */
1476
     */
1485
    private static void showHelp(HelpCtx helpCtx) {
1477
    private static void showHelp(HelpCtx helpCtx) {
1486
        // Awkward but should work.
1478
        // Awkward but should work.
1487
        try {
1479
        try {
Lines 1501-1505 Link Here
1501
        // Did not work.
1493
        // Did not work.
1502
        Toolkit.getDefaultToolkit().beep();
1494
        Toolkit.getDefaultToolkit().beep();
1503
    }
1495
    }
1504
1505
}
1496
}

Return to bug 196200