KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > windows > services > NbPresenter


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.core.windows.services;
21
22
23
24 import java.awt.BorderLayout JavaDoc;
25 import java.awt.Component JavaDoc;
26 import java.awt.DefaultKeyboardFocusManager JavaDoc;
27 import java.awt.Dialog JavaDoc;
28 import java.awt.Dimension JavaDoc;
29 import java.awt.FlowLayout JavaDoc;
30 import java.awt.Frame JavaDoc;
31 import java.awt.GridBagConstraints JavaDoc;
32 import java.awt.GridBagLayout JavaDoc;
33 import java.awt.Insets JavaDoc;
34 import java.awt.KeyboardFocusManager JavaDoc;
35 import java.awt.Rectangle JavaDoc;
36 import java.awt.event.*;
37 import java.beans.PropertyChangeListener JavaDoc;
38 import java.lang.reflect.*;
39 import java.util.*;
40 import java.util.logging.*;
41 import javax.swing.*;
42 import javax.swing.event.*;
43 import javax.swing.plaf.basic.BasicLookAndFeel JavaDoc;
44 import javax.swing.plaf.metal.MetalLookAndFeel JavaDoc;
45 import org.openide.*;
46 import org.openide.awt.Mnemonics;
47 import org.openide.util.*;
48
49
50 // XXX Before as org.netbeans.core.NbPresenter
51

52 /** Default implementation of Dialog created from NotifyDescriptor.
53  *
54  * @author Ian Formanek, Jaroslav Tulach
55  */

56 class NbPresenter extends JDialog
57 implements PropertyChangeListener JavaDoc, WindowListener, Mutex.Action<Void JavaDoc>, Comparator<Object JavaDoc> {
58     
59     /** variable holding current modal dialog in the system */
60     public static NbPresenter currentModalDialog;
61     private static final Set<ChangeListener JavaDoc> listeners = new HashSet<ChangeListener JavaDoc>();
62     
63     protected NotifyDescriptor descriptor;
64     
65     private final JButton stdYesButton = new JButton(NbBundle.getBundle(NbPresenter.class).getString("YES_OPTION_CAPTION")); // NOI18N
66
private final JButton stdNoButton = new JButton(NbBundle.getBundle(NbPresenter.class).getString("NO_OPTION_CAPTION")); // NOI18N
67
private final JButton stdOKButton = new JButton(NbBundle.getBundle(NbPresenter.class).getString("OK_OPTION_CAPTION")); // NOI18N
68
private final JButton stdCancelButton = new JButton(NbBundle.getBundle(NbPresenter.class).getString("CANCEL_OPTION_CAPTION")); // NOI18N
69
private final JButton stdClosedButton = new JButton(NbBundle.getBundle(NbPresenter.class).getString("CLOSED_OPTION_CAPTION")); // NOI18N
70
private final JButton stdHelpButton = new JButton();
71     private final JButton stdDetailButton = new JButton(NbBundle.getBundle(NbPresenter.class).getString("HELP_OPTION_CAPTION")); // NOI18N
72
{
73         stdYesButton.setDefaultCapable(true);
74         stdOKButton.setDefaultCapable(true);
75         stdNoButton.setDefaultCapable(false);
76         stdCancelButton.setDefaultCapable(false);
77         stdCancelButton.setVerifyInputWhenFocusTarget(false);
78         stdClosedButton.setDefaultCapable(false);
79         stdHelpButton.setDefaultCapable(false);
80         stdDetailButton.setDefaultCapable(false);
81         Mnemonics.setLocalizedText (stdHelpButton, NbBundle.getBundle(NbPresenter.class).getString("HELP_OPTION_CAPTION")); // NOI18N
82

83         /** Initilizes accessible contexts */
84         initAccessibility();
85     }
86     private final static String JavaDoc ESCAPE_COMMAND = "Escape"; // NOI18N
87

88     private Component JavaDoc currentMessage;
89     private JScrollPane currentScrollPane;
90     private boolean leaf = false;
91     private JPanel currentButtonsPanel;
92     private Component JavaDoc[] currentPrimaryButtons;
93     private Component JavaDoc[] currentSecondaryButtons;
94     
95     /** useful only for DialogDescriptor */
96     private int currentAlign;
97     
98     private ButtonListener buttonListener;
99     /** Help context to actually associate with the dialog, as it is currently known. */
100     private transient HelpCtx currentHelp = null;
101     /** Used to prevent updateHelp from calling initializeButtons too many times. */
102     private transient boolean haveCalledInitializeButtons = false;
103
104     private static Logger LOG = Logger.getLogger(NbPresenter.class.getName());
105     
106     static final long serialVersionUID =-4508637164126678997L;
107     
108     /** Creates a new Dialog from specified NotifyDescriptor,
109      * with given frame owner.
110      * @param d The NotifyDescriptor to create the dialog from
111      */

112     public NbPresenter(NotifyDescriptor d, Frame JavaDoc owner, boolean modal) {
113         super(owner, d.getTitle(), modal); // modal
114
initialize(d);
115     }
116     
117     /** Creates a new Dialog from specified NotifyDescriptor,
118      * with given dialog owner.
119      * @param d The NotifyDescriptor to create the dialog from
120      */

121     public NbPresenter(NotifyDescriptor d, Dialog JavaDoc owner, boolean modal) {
122         super(owner, d.getTitle(), modal); // modal
123
initialize(d);
124     }
125     
126     boolean isLeaf () {
127         return leaf;
128     }
129     
130     private void initAccessibility(){
131         
132         ResourceBundle bundle;
133         bundle = NbBundle.getBundle(NbPresenter.class);
134         
135         stdYesButton.getAccessibleContext().setAccessibleName(bundle.getString("ACS_YES_OPTION_NAME")); // NOI18N
136
stdYesButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_YES_OPTION_DESC")); // NOI18N
137

138         stdNoButton.getAccessibleContext().setAccessibleName(bundle.getString("ACS_NO_OPTION_NAME")); // NOI18N
139
stdNoButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_NO_OPTION_DESC")); // NOI18N
140

141         stdOKButton.getAccessibleContext().setAccessibleName(bundle.getString("ACS_OK_OPTION_NAME")); // NOI18N
142
stdOKButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_OK_OPTION_DESC")); // NOI18N
143

144         stdCancelButton.getAccessibleContext().setAccessibleName(bundle.getString("ACS_CANCEL_OPTION_NAME")); // NOI18N
145
stdCancelButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_CANCEL_OPTION_DESC")); // NOI18N
146

147         stdClosedButton.getAccessibleContext().setAccessibleName(bundle.getString("ACS_CLOSED_OPTION_NAME")); // NOI18N
148
stdClosedButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_CLOSED_OPTION_DESC")); // NOI18N
149

150         stdHelpButton.getAccessibleContext().setAccessibleName(bundle.getString("ACS_HELP_OPTION_NAME")); // NOI18N
151
stdHelpButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_HELP_OPTION_DESC")); // NOI18N
152

153         stdDetailButton.getAccessibleContext().setAccessibleName(bundle.getString("ACS_HELP_OPTION_NAME")); // NOI18N
154
stdDetailButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_HELP_OPTION_DESC")); // NOI18N
155
}
156     
157     private void initialize(NotifyDescriptor d) {
158         //Optimization related to jdk bug 4393857 - on pre 1.5 jdk's an
159
//extra repaint is caused by the search for an opaque component up
160
//to the component root. Post 1.5, root pane will automatically be
161
//opaque.
162
getRootPane().setOpaque(true);
163         
164         if (d instanceof WizardDescriptor) {
165             // #81938: wizard close button shouln't work during finish progress
166
setDefaultCloseOperation (WindowConstants.DO_NOTHING_ON_CLOSE);
167         } else {
168             // #55273: Dialogs created by DialogDisplayer are not disposed after close
169
setDefaultCloseOperation (WindowConstants.DISPOSE_ON_CLOSE);
170         }
171         
172         descriptor = d;
173
174         buttonListener = new ButtonListener();
175         // set leaf by DialogDescriptor, NotifyDescriptor is leaf as default
176
leaf = d instanceof DialogDescriptor ? ((DialogDescriptor)d).isLeaf () : true;
177         
178         getRootPane().registerKeyboardAction(
179             buttonListener,
180             ESCAPE_COMMAND,
181             KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
182             JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
183         );
184
185         initializePresenter();
186
187         pack();
188         setBounds(Utilities.findCenterBounds(getSize()));
189     }
190
191     /** Requests focus for <code>currentMessage</code> component.
192      * If it is of <code>JComponent</code> type it tries default focus
193      * request first. */

194     private void requestFocusForMessage() {
195         Component JavaDoc comp = currentMessage;
196         
197         if(comp == null) {
198             return;
199         }
200         
201         if(!(comp instanceof JComponent)
202             || !((JComponent)comp).requestDefaultFocus()) {
203                 
204             comp.requestFocus();
205         }
206     }
207     
208     private void initializeMessage() {
209         Object JavaDoc newMessage = descriptor.getMessage();
210         // replace only if old and new messages are different
211
if ((currentMessage == null) || !currentMessage.equals(newMessage)) {
212             uninitializeMessage();
213
214             if (descriptor.getMessageType() == NotifyDescriptor.PLAIN_MESSAGE &&
215                 (newMessage instanceof Component JavaDoc)) {
216                 // if plain message => use directly the component
217
currentMessage = (Component JavaDoc)newMessage;
218             } else {
219                 currentMessage = createOptionPane();
220             }
221             Dimension JavaDoc prefSize = currentMessage.getPreferredSize();
222             final Rectangle JavaDoc screenBounds = Utilities.getUsableScreenBounds();
223             
224             if (prefSize.width > screenBounds.width - 100
225                 || prefSize.height > screenBounds.height- 100
226                 ) {
227                 currentScrollPane = new JScrollPane() {
228                     public Dimension JavaDoc getPreferredSize() {
229                         Dimension JavaDoc sz = new Dimension JavaDoc(super.getPreferredSize());
230                         if (sz.width > screenBounds.width - 100) {
231                             sz.width = screenBounds.width * 3 / 4;
232                         }
233                         if (sz.height > screenBounds.height - 100)
234                             sz.height = screenBounds.height * 3 / 4;
235                         return sz;
236                     }
237                 };
238                 currentScrollPane.setViewportView(currentMessage);
239                 getContentPane().add(currentScrollPane, BorderLayout.CENTER);
240             }
241             else {
242                 getContentPane().add(currentMessage, BorderLayout.CENTER);
243             }
244         }
245     }
246     
247     private void uninitializeMessage() {
248         if (currentMessage != null) {
249             if (currentScrollPane != null) {
250                 getContentPane().remove(currentScrollPane);
251                 currentScrollPane = null;
252             }
253             else {
254                 getContentPane().remove(currentMessage);
255             }
256             currentMessage = null;
257         }
258     }
259
260     private void initializePresenter() {
261         if (currentMessage != null)
262             return;
263             
264         initializeMessage();
265         
266         updateHelp();
267         
268         initializeButtons();
269         haveCalledInitializeButtons = true;
270         
271         descriptor.addPropertyChangeListener(this);
272         addWindowListener(this);
273         
274         initializeClosingOptions ();
275     }
276     
277     /** Descriptor can be cached and reused. We need to remove listeners
278      * from descriptor, buttons and disconnect componets from container hierarchy.
279      */

280     private void uninitializePresenter() {
281         descriptor.removePropertyChangeListener(this);
282         uninitializeMessage();
283         uninitializeButtons();
284         uninitializeClosingOptions ();
285     }
286     
287     private final HackTypeAhead hack = new HackTypeAhead();
288     public void addNotify() {
289         super.addNotify();
290         initializePresenter();
291         
292         hack.activate();
293     }
294
295     public void removeNotify() {
296         super.removeNotify();
297         uninitializePresenter();
298         
299     }
300
301     /** Creates option pane message.
302      */

303     private JOptionPane createOptionPane() {
304         Object JavaDoc msg = descriptor.getMessage();
305         boolean override = true;
306         String JavaDoc strMsg = null, strMsgLower;
307         
308         if (msg instanceof String JavaDoc) {
309             msg = org.openide.util.Utilities.replaceString((String JavaDoc)msg, "\t", " "); // NOI18N
310
msg = org.openide.util.Utilities.replaceString((String JavaDoc)msg, "\r", ""); // NOI18N
311
//If string is html text (contains "<html>" or "<HTML>")
312
//we will not override JOptionPane.getMaxCharactersPerLineCount
313
//so that html text will be displayed correctly in JOptionPane
314
strMsg = (String JavaDoc)msg;
315             strMsgLower = strMsg.toLowerCase();
316             override = !strMsgLower.startsWith("<html>"); // NOI18N
317
}
318         if (msg instanceof javax.accessibility.Accessible JavaDoc) {
319             strMsg = ((javax.accessibility.Accessible JavaDoc)msg).getAccessibleContext().getAccessibleDescription();
320         }
321         
322         JOptionPane optionPane;
323         if (override) {
324             // initialize component (override max char count per line in a message)
325
optionPane = new JOptionPane(
326             msg,
327             descriptor.getMessageType(),
328             0, // options type
329
null, // icon
330
new Object JavaDoc[0], // options
331
null // value
332
) {
333                 public int getMaxCharactersPerLineCount() {
334                     return 100;
335                 }
336             };
337         } else {
338             //Do not override JOptionPane.getMaxCharactersPerLineCount for html text
339
optionPane = new JOptionPane(
340             msg,
341             descriptor.getMessageType(),
342             0, // options type
343
null, // icon
344
new Object JavaDoc[0], // options
345
null // value
346
);
347         }
348         
349         if (UIManager.getLookAndFeel().getClass() == MetalLookAndFeel JavaDoc.class ||
350             UIManager.getLookAndFeel().getClass() == BasicLookAndFeel JavaDoc.class) {
351             optionPane.setUI(new javax.swing.plaf.basic.BasicOptionPaneUI JavaDoc() {
352                 public Dimension JavaDoc getMinimumOptionPaneSize() {
353                     if (minimumSize == null) {
354                         //minimumSize = UIManager.getDimension("OptionPane.minimumSize");
355
// this is called before defaults initialized?!!!
356
return new Dimension JavaDoc(MinimumWidth, 50);
357                     }
358                     return new Dimension JavaDoc(minimumSize.width, 50);
359                 }
360             });
361         }
362         optionPane.setWantsInput(false);
363         optionPane.getAccessibleContext().setAccessibleDescription(strMsg);
364         
365         return optionPane;
366     }
367     
368     private void uninitializeButtons() {
369         if (currentButtonsPanel != null) {
370             if (currentPrimaryButtons != null) {
371                 for (int i = 0; i < currentPrimaryButtons.length; i++) {
372                     modifyListener(currentPrimaryButtons[i], buttonListener, false);
373                 }
374             }
375             if (currentSecondaryButtons != null) {
376                 for (int i = 0; i < currentSecondaryButtons.length; i++) {
377                     modifyListener(currentSecondaryButtons[i], buttonListener, false);
378                 }
379             }
380             
381             getContentPane().remove(currentButtonsPanel);
382             currentButtonsPanel = null;
383         }
384     }
385     
386     private void initializeClosingOptions (boolean init) {
387         Object JavaDoc[] options = getClosingOptions ();
388         
389         if (options == null) return ;
390         for (int i = 0; i < options.length; i++) {
391             modifyListener (options[i], buttonListener, init);
392         }
393     }
394     
395     private void initializeClosingOptions () {
396         initializeClosingOptions (true);
397     }
398     
399     private void uninitializeClosingOptions () {
400         initializeClosingOptions (false);
401     }
402     
403     /**
404      * On Aqua look and feel, options should be sorted such that the default
405      * button is always rightmost, and 'yes' options appear to thr right of
406      * 'no' options.
407      */

408     public int compare (Object JavaDoc a, Object JavaDoc b) {
409         boolean isDefaultButton = a.equals(descriptor.getDefaultValue ());
410         int result;
411         if (a.equals(NotifyDescriptor.OK_OPTION) || a.equals(NotifyDescriptor.YES_OPTION)) {
412             result = 1;
413         } else {
414             result = 0;
415         }
416         
417         if (isDefaultButton) {
418             result++;
419         }
420         return result;
421     }
422     
423     protected final void initializeButtons() {
424         // -----------------------------------------------------------------------------
425
// If there were any buttons previously, remove them and removeActionListener from them
426

427         Component JavaDoc focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager ().getFocusOwner ();
428
429         boolean dontShowHelp = ( descriptor instanceof WizardDescriptor && ( Boolean.FALSE.equals (((WizardDescriptor)descriptor).getProperty ("WizardPanel_helpDisplayed")) )); // NOI18N
430
boolean helpButtonShown =
431             stdHelpButton.isShowing() || ( descriptor instanceof WizardDescriptor && !dontShowHelp );
432         
433         
434         uninitializeButtons();
435         
436         Object JavaDoc[] primaryOptions = descriptor.getOptions();
437         Object JavaDoc[] secondaryOptions = descriptor.getAdditionalOptions();
438         currentAlign = getOptionsAlign();
439         
440         // -----------------------------------------------------------------------------
441
// Obtain main (primary) and additional (secondary) buttons
442

443         currentPrimaryButtons = null;
444         currentSecondaryButtons = null;
445
446         boolean isAqua = "Aqua".equals (UIManager.getLookAndFeel().getID()) || //NOI18N
447
"true".equalsIgnoreCase (System.getProperty ("xtest.looks_as_mac"));
448         if (isAqua) {
449             //No mac dialogs with buttons on side
450
currentAlign = DialogDescriptor.BOTTOM_ALIGN;
451         }
452         
453         // explicitly provided options (AKA buttons)
454
// JST: The following line causes only problems,
455
// I hope that my change will not cause additional ones ;-)
456
// if (descriptor.getOptionType () == NotifyDescriptor.DEFAULT_OPTION) {
457
if (primaryOptions != null) {
458             if (isAqua) {
459                 Arrays.sort(primaryOptions, this);
460             }
461             currentPrimaryButtons = new Component JavaDoc [primaryOptions.length];
462             for (int i = 0; i < primaryOptions.length; i++) {
463                 if (primaryOptions[i] == NotifyDescriptor.YES_OPTION) {
464                     currentPrimaryButtons[i] = stdYesButton;
465                 } else if (primaryOptions[i] == NotifyDescriptor.NO_OPTION) {
466                     currentPrimaryButtons[i] = stdNoButton;
467                 } else if (primaryOptions[i] == NotifyDescriptor.OK_OPTION) {
468                     currentPrimaryButtons[i] = stdOKButton;
469                     stdOKButton.setEnabled(descriptor.isValid());
470                 } else if (primaryOptions[i] == NotifyDescriptor.CANCEL_OPTION) {
471                     currentPrimaryButtons[i] = stdCancelButton;
472                 } else if (primaryOptions[i] == NotifyDescriptor.CLOSED_OPTION) {
473                     currentPrimaryButtons[i] = stdClosedButton;
474                 } else if (primaryOptions[i] instanceof Component JavaDoc) {
475                     currentPrimaryButtons[i] = (Component JavaDoc) primaryOptions [i];
476                 } else if (primaryOptions [i] instanceof Icon) {
477                     JButton button = new JButton((Icon)primaryOptions [i]);
478                     // ??? Why cannot be default capable ?
479
button.setDefaultCapable(false);
480                     currentPrimaryButtons[i] = button;
481                 } else {
482                     JButton button = new JButton();
483                     Mnemonics.setLocalizedText (button, primaryOptions [i].toString ());
484                     button.setDefaultCapable(primaryOptions[i].equals(descriptor.getDefaultValue ()));
485                     currentPrimaryButtons[i] = button;
486                 }
487             }
488         } else { // predefined option types
489
switch (descriptor.getOptionType()) {
490                 case NotifyDescriptor.YES_NO_OPTION:
491                     if (isAqua) {
492                         currentPrimaryButtons = new Component JavaDoc[2];
493                         currentPrimaryButtons[0] = stdNoButton;
494                         currentPrimaryButtons[1] = stdYesButton;
495                     } else {
496                         currentPrimaryButtons = new Component JavaDoc[2];
497                         currentPrimaryButtons[0] = stdYesButton;
498                         currentPrimaryButtons[1] = stdNoButton;
499                     }
500                     break;
501                 case NotifyDescriptor.YES_NO_CANCEL_OPTION:
502                     currentPrimaryButtons = new Component JavaDoc[3];
503                     if (isAqua) {
504                         currentPrimaryButtons[0] = stdCancelButton;
505                         currentPrimaryButtons[1] = stdNoButton;
506                         currentPrimaryButtons[2] = stdYesButton;
507                     } else {
508                         currentPrimaryButtons[0] = stdYesButton;
509                         currentPrimaryButtons[1] = stdNoButton;
510                         currentPrimaryButtons[2] = stdCancelButton;
511                     }
512                     break;
513                 case NotifyDescriptor.OK_CANCEL_OPTION:
514                 default:
515                     if (isAqua) {
516                         currentPrimaryButtons = new Component JavaDoc[2];
517                         currentPrimaryButtons[0] = stdCancelButton;
518                         currentPrimaryButtons[1] = stdOKButton;
519                     } else {
520                         currentPrimaryButtons = new Component JavaDoc[2];
521                         currentPrimaryButtons[0] = stdOKButton;
522                         currentPrimaryButtons[1] = stdCancelButton;
523                     }
524                     stdOKButton.setEnabled(descriptor.isValid());
525                     break;
526             }
527         }
528         
529         // Automatically add a help button if needed.
530

531         if (!dontShowHelp && (currentHelp != null || helpButtonShown)) {
532             if (currentPrimaryButtons == null) currentPrimaryButtons = new Component JavaDoc[] { };
533             Component JavaDoc[] cPB2 = new Component JavaDoc[currentPrimaryButtons.length + 1];
534             if (isAqua) { //NOI18N
535
//Mac default dlg button should be rightmost, not the help button
536
System.arraycopy(currentPrimaryButtons, 0, cPB2, 1, currentPrimaryButtons.length);
537                 cPB2[0] = stdHelpButton;
538             } else {
539                 System.arraycopy(currentPrimaryButtons, 0, cPB2, 0, currentPrimaryButtons.length);
540                 cPB2[currentPrimaryButtons.length] = stdHelpButton;
541             }
542             currentPrimaryButtons = cPB2;
543
544             stdHelpButton.setEnabled(currentHelp != null);
545         }
546         
547         if ((secondaryOptions != null) && (secondaryOptions.length != 0)) {
548             currentSecondaryButtons = new Component JavaDoc [secondaryOptions.length];
549             Arrays.sort (secondaryOptions, this);
550             for (int i = 0; i < secondaryOptions.length; i++) {
551                 if (secondaryOptions[i] == NotifyDescriptor.YES_OPTION) {
552                     currentSecondaryButtons[i] = stdYesButton;
553                 } else if (secondaryOptions[i] == NotifyDescriptor.NO_OPTION) {
554                     currentSecondaryButtons[i] = stdNoButton;
555                 } else if (secondaryOptions[i] == NotifyDescriptor.OK_OPTION) {
556                     currentSecondaryButtons[i] = stdOKButton;
557                     stdOKButton.setEnabled(descriptor.isValid());
558                 } else if (secondaryOptions[i] == NotifyDescriptor.CANCEL_OPTION) {
559                     currentSecondaryButtons[i] = stdCancelButton;
560                 } else if (secondaryOptions[i] == NotifyDescriptor.CLOSED_OPTION) {
561                     currentSecondaryButtons[i] = stdClosedButton;
562                 } else if (secondaryOptions[i] instanceof Component JavaDoc) {
563                     currentSecondaryButtons[i] = (Component JavaDoc) secondaryOptions [i];
564                 } else if (secondaryOptions [i] instanceof Icon) {
565                     JButton button = new JButton((Icon)secondaryOptions [i]);
566                     currentSecondaryButtons[i] = button;
567                 } else {
568                     JButton button = new JButton();
569                     Mnemonics.setLocalizedText (button, secondaryOptions [i].toString ());
570                     currentSecondaryButtons[i] = button;
571                 }
572             }
573         }
574         
575         // -----------------------------------------------------------------------------
576
// Create panels for main (primary) and additional (secondary) buttons and add to content pane
577

578         if (currentAlign == DialogDescriptor.BOTTOM_ALIGN || currentAlign == -1) {
579             
580             JPanel panelForPrimary = null;
581             JPanel panelForSecondary = null;
582             
583
584             if (currentPrimaryButtons != null) {
585                 panelForPrimary = new JPanel();
586                 
587                 if (currentAlign == -1) {
588                     panelForPrimary.setLayout(new org.openide.awt.EqualFlowLayout());
589                 } else {
590                     panelForPrimary.setLayout(new org.openide.awt.EqualFlowLayout(FlowLayout.RIGHT));
591                 }
592                 for (int i = 0; i < currentPrimaryButtons.length; i++) {
593                     modifyListener(currentPrimaryButtons[i], buttonListener, true); // add button listener
594
panelForPrimary.add(currentPrimaryButtons[i]);
595                 }
596             }
597             
598             if (currentSecondaryButtons != null) {
599                 panelForSecondary = new JPanel();
600                 panelForSecondary.setLayout(new org.openide.awt.EqualFlowLayout(FlowLayout.LEFT));
601                 for (int i = 0; i < currentSecondaryButtons.length; i++) {
602                     modifyListener(currentSecondaryButtons[i], buttonListener, true); // add button listener
603
panelForSecondary.add(currentSecondaryButtons[i]);
604                 }
605             }
606             
607             // both primary and secondary buttons are used
608
if ((panelForPrimary != null) && (panelForSecondary != null)) {
609                 currentButtonsPanel = new JPanel();
610                 currentButtonsPanel.setLayout(new BorderLayout JavaDoc());
611                 currentButtonsPanel.add(panelForPrimary, BorderLayout.EAST);
612                 currentButtonsPanel.add(panelForSecondary, BorderLayout.WEST);
613             } else if (panelForPrimary != null) {
614                 currentButtonsPanel = panelForPrimary;
615             } else {
616                 currentButtonsPanel = panelForSecondary;
617             }
618             
619             // add final button panel to the dialog
620
if ((currentButtonsPanel != null)&&(currentButtonsPanel.getComponentCount() != 0)) {
621                 if (currentButtonsPanel.getBorder() == null) {
622                     currentButtonsPanel.setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(11, 6, 5, 5)));
623                 }
624                 getContentPane().add(currentButtonsPanel, BorderLayout.SOUTH);
625             }
626             
627         } else if (currentAlign == DialogDescriptor.RIGHT_ALIGN) {
628             currentButtonsPanel = new JPanel();
629             currentButtonsPanel.setLayout(new GridBagLayout JavaDoc());
630             GridBagConstraints JavaDoc gbc = new GridBagConstraints JavaDoc();
631             gbc.gridwidth = GridBagConstraints.REMAINDER;
632             gbc.weightx = 1.0f;
633             gbc.insets = new Insets JavaDoc(5, 4, 2, 5);
634             gbc.fill = GridBagConstraints.HORIZONTAL;
635             
636             if (currentPrimaryButtons != null) {
637                 for (int i = 0; i < currentPrimaryButtons.length; i++) {
638                     modifyListener(currentPrimaryButtons[i], buttonListener, true); // add button listener
639
currentButtonsPanel.add(currentPrimaryButtons[i], gbc);
640                 }
641             }
642             
643             GridBagConstraints JavaDoc padding = new GridBagConstraints JavaDoc();
644             padding.gridwidth = GridBagConstraints.REMAINDER;
645             padding.weightx = 1.0f;
646             padding.weighty = 1.0f;
647             padding.fill = GridBagConstraints.BOTH;
648             currentButtonsPanel.add(new JPanel(), padding);
649             
650             gbc.insets = new Insets JavaDoc(2, 4, 5, 5);
651             if (currentSecondaryButtons != null) {
652                 for (int i = 0; i < currentSecondaryButtons.length; i++) {
653                     modifyListener(currentSecondaryButtons[i], buttonListener, true); // add button listener
654
currentButtonsPanel.add(currentSecondaryButtons[i], gbc);
655                 }
656             }
657             
658             // add final button panel to the dialog
659
if (currentButtonsPanel != null) {
660                 if (currentButtonsPanel.getBorder() == null) {
661                     currentButtonsPanel.setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(6, 7, 5, 5)));
662                 }
663                 getContentPane().add(currentButtonsPanel, BorderLayout.EAST);
664             }
665             
666         }
667         updateDefaultButton();
668         
669         
670         Component JavaDoc fo = KeyboardFocusManager.getCurrentKeyboardFocusManager ().getFocusOwner ();
671         
672         if (fo != focusOwner && focusOwner != null) {
673             focusOwner.requestFocus();
674         }
675     }
676     
677     /** Checks default button and updates it
678      */

679     private void updateDefaultButton() {
680         // bugfix 37083, respects DialogDescriptor's initial value ?
681
if (descriptor.getDefaultValue () != null && descriptor.getDefaultValue () instanceof JButton) {
682             JButton b = (JButton)descriptor.getDefaultValue ();
683             if (b.isVisible() && b.isEnabled () && b.isDefaultCapable ()) {
684                 getRootPane ().setDefaultButton (b);
685                 return ;
686             }
687         } else {
688             // ??? unset default button if descriptor.getValue() is null
689
}
690         if (currentPrimaryButtons != null) {
691             // finds default button
692
for (int i = 0; i < currentPrimaryButtons.length; i++) {
693                 if (currentPrimaryButtons[i] instanceof JButton) {
694                     JButton b = (JButton)currentPrimaryButtons[i];
695                     if (b.isVisible() && b.isEnabled() && b.isDefaultCapable()) {
696                         getRootPane().setDefaultButton(b);
697                         return;
698                     }
699                 }
700             }
701         }
702         // no default capable button found
703
getRootPane().setDefaultButton(null);
704     }
705     
706     /** Enables/disables OK button if it is present
707      */

708     private void updateOKButton(boolean valid) {
709         if (currentPrimaryButtons != null) {
710             for (int i = 0; i < currentPrimaryButtons.length; i++) {
711                 if (currentPrimaryButtons[i] instanceof JButton) {
712                     JButton b = (JButton)currentPrimaryButtons[i];
713                     if ((b == stdOKButton) && b.isVisible()) {
714                         b.setEnabled(valid);
715                     }
716                 }
717             }
718         }
719         if (currentSecondaryButtons != null) {
720             for (int i = 0; i < currentSecondaryButtons.length; i++) {
721                 if (currentSecondaryButtons[i] instanceof JButton) {
722                     JButton b = (JButton)currentSecondaryButtons[i];
723                     if ((b == stdOKButton) && b.isVisible()) {
724                         b.setEnabled(valid);
725                     }
726                 }
727             }
728         }
729     }
730     
731     private void modifyListener(Object JavaDoc comp, ButtonListener l, boolean add) {
732         // on JButtons attach simply by method call
733
if (comp instanceof JButton) {
734             JButton b = (JButton)comp;
735             if (add) {
736                 List listeners;
737                 listeners = Arrays.asList (b.getActionListeners ());
738                 if (!listeners.contains (l)) {
739                     b.addActionListener(l);
740                 }
741                 listeners = Arrays.asList (b.getComponentListeners ());
742                 if (!listeners.contains (l)) {
743                     b.addComponentListener(l);
744                 }
745                 listeners = Arrays.asList (b.getPropertyChangeListeners ());
746                 if (!listeners.contains (l)) {
747                     b.addPropertyChangeListener(l);
748                 }
749             } else {
750                 b.removeActionListener(l);
751                 b.removeComponentListener(l);
752                 b.removePropertyChangeListener(l);
753             }
754             return;
755         } else {
756             // we will have to use dynamic method invocation to add the action listener
757
// to generic component (and we succeed only if it has the addActionListener method)
758
java.lang.reflect.Method JavaDoc m = null;
759             try {
760                 m = comp.getClass().getMethod(add ? "addActionListener" : "removeActionListener", new Class JavaDoc[] { ActionListener.class });// NOI18N
761
try {
762                     m.setAccessible (true);
763                 } catch (SecurityException JavaDoc se) {
764                     m = null; // no jo, we cannot make accessible
765
}
766             } catch (NoSuchMethodException JavaDoc e) {
767                 m = null; // no jo, we cannot attach ActionListener to this Component
768
} catch (SecurityException JavaDoc e2) {
769                 m = null; // no jo, we cannot attach ActionListener to this Component
770
}
771             if (m != null) {
772                 try {
773                     m.invoke(comp, new Object JavaDoc[] { l });
774                 } catch (Exception JavaDoc e) {
775                     // not succeeded, so give up
776
}
777             }
778         }
779     }
780     
781     /** Shows the dialog, used in method show so no inner class is needed.
782      */

783     private void superShow() {
784         assert SwingUtilities.isEventDispatchThread () : "Invoked super.show() in AWT event thread."; // NOI18N
785
super.show();
786     }
787     
788     @Override JavaDoc @Deprecated JavaDoc
789     public void show() {
790         //Bugfix #29993: Call show() asynchronously for non modal dialogs.
791
if (isModal()) {
792             Mutex.EVENT.readAccess(this);
793         } else {
794             if (SwingUtilities.isEventDispatchThread()) {
795                 doShow();
796             } else {
797                 SwingUtilities.invokeLater(new Runnable JavaDoc () {
798                     public void run () {
799                         doShow();
800                     }
801                 });
802             }
803         }
804     }
805     
806     public Void JavaDoc run() {
807         doShow();
808         return null;
809     }
810     
811     private void doShow () {
812         NbPresenter prev = null;
813         if (isModal()) {
814             prev = currentModalDialog;
815             currentModalDialog = this;
816             fireChangeEvent();
817         }
818         
819         superShow();
820         
821         if (currentModalDialog != prev) {
822             currentModalDialog = prev;
823             fireChangeEvent();
824         }
825     }
826     
827     public void propertyChange(final java.beans.PropertyChangeEvent JavaDoc evt) {
828         boolean update = false;
829         
830         if (DialogDescriptor.PROP_OPTIONS.equals(evt.getPropertyName())) {
831             initializeButtons();
832             update = true;
833         } else if (DialogDescriptor.PROP_OPTION_TYPE.equals(evt.getPropertyName())) {
834             initializeButtons();
835             update = true;
836         } else if (DialogDescriptor.PROP_OPTIONS_ALIGN.equals(evt.getPropertyName())) {
837             initializeButtons();
838             update = true;
839         } else if (DialogDescriptor.PROP_MESSAGE.equals(evt.getPropertyName())) {
840             initializeMessage();
841             requestFocusForMessage();
842             // In case change of help ID on component message:
843
updateHelp();
844             update = true;
845         } else if (DialogDescriptor.PROP_MESSAGE_TYPE.equals(evt.getPropertyName())) {
846             initializeMessage();
847             requestFocusForMessage();
848             update = true;
849         } else if (DialogDescriptor.PROP_TITLE.equals(evt.getPropertyName())) {
850             setTitle(descriptor.getTitle());
851         } else if (DialogDescriptor.PROP_HELP_CTX.equals(evt.getPropertyName())) {
852             // bugfix #40057, restore focus owner after help update
853
Component JavaDoc fo = KeyboardFocusManager.getCurrentKeyboardFocusManager ().getFocusOwner ();
854             updateHelp();
855             // In case buttons have changed: //just buttons!!
856
currentButtonsPanel.revalidate();
857             currentButtonsPanel.repaint();
858             if (fo != null) fo.requestFocus();
859         } else if (DialogDescriptor.PROP_VALID.equals(evt.getPropertyName())) {
860             updateOKButton(((Boolean JavaDoc)(evt.getNewValue())).booleanValue());
861         }
862         
863         if (update) {
864             Dimension JavaDoc sz = getSize();
865             Dimension JavaDoc prefSize = getPreferredSize();
866             if (prefSize.width > sz.width || prefSize.height > sz.height) {
867                 setSize(Math.max(prefSize.width, sz.width),
868                         Math.max(prefSize.height, sz.height));
869             }
870
871             validate();
872             repaint();
873         }
874     }
875     
876     private void updateHelp() {
877         //System.err.println ("Updating help for NbDialog...");
878
HelpCtx help = getHelpCtx();
879         // Handle help from the inner component automatically (see docs
880
// in DialogDescriptor):
881
if (HelpCtx.DEFAULT_HELP.equals(help)) {
882             Object JavaDoc msg = descriptor.getMessage();
883             if (msg instanceof Component JavaDoc) {
884                 help = HelpCtx.findHelp((Component JavaDoc) msg);
885             }
886             if (HelpCtx.DEFAULT_HELP.equals(help)) help = null;
887         }
888         if (! Utilities.compareObjects(currentHelp, help)) {
889             currentHelp = help;
890             if (help != null && help.getHelpID() != null) {
891                 //System.err.println ("New help ID for root pane: " + help.getHelpID ());
892
HelpCtx.setHelpIDString(getRootPane(), help.getHelpID());
893             }
894             // Refresh button list if it had already been created.
895
if (haveCalledInitializeButtons) initializeButtons();
896         }
897     }
898     
899     /** Options align.
900      */

901     protected int getOptionsAlign() {
902         return -1;
903     }
904     
905     /** Getter for button listener or null
906      */

907     protected ActionListener getButtonListener() {
908         return null;
909     }
910     
911     /** Closing options.
912      */

913     protected Object JavaDoc[] getClosingOptions() {
914         return null;
915     }
916     
917     /** Updates help.
918      */

919     protected HelpCtx getHelpCtx() {
920         return null;
921     }
922     
923     
924     public void windowDeactivated(final java.awt.event.WindowEvent JavaDoc p1) {
925     }
926     public void windowClosed(final java.awt.event.WindowEvent JavaDoc p1) {
927     }
928     public void windowDeiconified(final java.awt.event.WindowEvent JavaDoc p1) {
929     }
930     public void windowOpened(final java.awt.event.WindowEvent JavaDoc p1) {
931     }
932     public void windowIconified(final java.awt.event.WindowEvent JavaDoc p1) {
933     }
934     public void windowClosing(final java.awt.event.WindowEvent JavaDoc p1) {
935         // #81938: special handling WizardDescriptor to avoid close wizard during instantiate
936
if (! (descriptor instanceof WizardDescriptor)) {
937             descriptor.setValue(NotifyDescriptor.CLOSED_OPTION);
938         }
939     }
940     public void windowActivated(final java.awt.event.WindowEvent JavaDoc p1) {
941     }
942     
943     // Used by JavaHelp:
944
public static void addChangeListener(ChangeListener JavaDoc l) {
945         synchronized (listeners) {
946             listeners.add(l);
947         }
948     }
949     public static void removeChangeListener(ChangeListener JavaDoc l) {
950         synchronized (listeners) {
951             listeners.remove(l);
952         }
953     }
954     private static void fireChangeEvent() {
955         SwingUtilities.invokeLater(new Runnable JavaDoc() {
956             public void run() {
957                 Iterator<ChangeListener JavaDoc> it;
958                 synchronized (listeners) {
959                     it = new HashSet<ChangeListener JavaDoc>(listeners).iterator();
960                 }
961                 ChangeEvent ev = new ChangeEvent(NbPresenter.class);
962                 while (it.hasNext()) {
963                     it.next().stateChanged(ev);
964                 }
965             }
966         });
967     }
968     
969     /** Button listener
970      */

971     private class ButtonListener implements ActionListener, ComponentListener, PropertyChangeListener JavaDoc {
972         ButtonListener() {}
973         public void actionPerformed(ActionEvent evt) {
974             boolean isAqua = "Aqua".equals (UIManager.getLookAndFeel().getID()) || //NOI18N
975
"true".equalsIgnoreCase (System.getProperty ("xtest.looks_as_mac"));
976             
977             Object JavaDoc pressedOption = evt.getSource();
978             // handle ESCAPE
979
if (ESCAPE_COMMAND.equals (evt.getActionCommand ())) {
980                 pressedOption = NotifyDescriptor.CLOSED_OPTION;
981             } else {
982                 // handle buttons
983
if (evt.getSource() == stdHelpButton) {
984                     org.netbeans.core.NbTopManager.get().showHelp(currentHelp);
985                     return;
986                 }
987                 
988                 Object JavaDoc[] options = descriptor.getOptions();
989                 if (isAqua && options != null) {
990                     Arrays.sort (options, NbPresenter.this);
991                 }
992                 
993                 if (
994                 options != null &&
995                 currentPrimaryButtons != null &&
996                 options.length == (currentPrimaryButtons.length -
997                     ((currentHelp != null) ? 1 : 0))
998                 ) {
999                     int offset = currentHelp != null && isAqua ?
1000                        -1 : 0;
1001                    for (int i = 0; i < currentPrimaryButtons.length; i++) {
1002                        if (evt.getSource() == currentPrimaryButtons[i]) {
1003                            pressedOption = options[i + offset];
1004                        }
1005                    }
1006                }
1007                
1008                options = descriptor.getAdditionalOptions();
1009                if (isAqua && options != null) {
1010                    Arrays.sort (options, NbPresenter.this);
1011                }
1012                
1013                if (
1014                options != null &&
1015                currentSecondaryButtons != null &&
1016                options.length == currentSecondaryButtons.length
1017                ) {
1018                    for (int i = 0; i < currentSecondaryButtons.length; i++) {
1019                        if (evt.getSource() == currentSecondaryButtons[i]) {
1020                            pressedOption = options[i];
1021                        }
1022                    }
1023                }
1024                
1025                if (evt.getSource() == stdYesButton) {
1026                    pressedOption = NotifyDescriptor.YES_OPTION;
1027                } else if (evt.getSource() == stdNoButton) {
1028                    pressedOption = NotifyDescriptor.NO_OPTION;
1029                } else if (evt.getSource() == stdCancelButton) {
1030                    pressedOption = NotifyDescriptor.CANCEL_OPTION;
1031                } else if (evt.getSource() == stdClosedButton) {
1032                    pressedOption = NotifyDescriptor.CLOSED_OPTION;
1033                } else if (evt.getSource() == stdOKButton) {
1034                    pressedOption = NotifyDescriptor.OK_OPTION;
1035                }
1036            }
1037
1038            descriptor.setValue(pressedOption);
1039            
1040            ActionListener al = getButtonListener();
1041            if (al != null) {
1042                
1043                if (pressedOption == evt.getSource()) {
1044                    al.actionPerformed(evt);
1045                } else {
1046                    al.actionPerformed(new ActionEvent(
1047                    pressedOption, evt.getID(), evt.getActionCommand(), evt.getModifiers()
1048                    ));
1049                }
1050            }
1051            
1052            Object JavaDoc[] arr = getClosingOptions();
1053            if (arr == null || pressedOption == NotifyDescriptor.CLOSED_OPTION) {
1054                // all options should close
1055
dispose();
1056            } else {
1057                java.util.List JavaDoc l = java.util.Arrays.asList(arr);
1058                
1059                if (l.contains(pressedOption)) {
1060                    dispose();
1061                }
1062            }
1063        }
1064        public void componentShown(final java.awt.event.ComponentEvent JavaDoc p1) {
1065            updateDefaultButton();
1066        }
1067        public void componentResized(final java.awt.event.ComponentEvent JavaDoc p1) {
1068        }
1069        
1070        public void componentHidden(final java.awt.event.ComponentEvent JavaDoc p1) {
1071            updateDefaultButton();
1072        }
1073        
1074        public void componentMoved(final java.awt.event.ComponentEvent JavaDoc p1) {
1075        }
1076        
1077        public void propertyChange(final java.beans.PropertyChangeEvent JavaDoc p1) {
1078            if ("enabled".equals(p1.getPropertyName())) {
1079                updateDefaultButton();
1080            }
1081        }
1082    }
1083    
1084    public javax.accessibility.AccessibleContext JavaDoc getAccessibleContext() {
1085        if (accessibleContext == null) {
1086            accessibleContext = new AccessibleNbPresenter();
1087        }
1088        return accessibleContext;
1089    }
1090    
1091    private static String JavaDoc getMessageTypeDescription(int messageType) {
1092        switch(messageType) {
1093        case NotifyDescriptor.ERROR_MESSAGE:
1094            return NbBundle.getBundle(NbPresenter.class).getString("ACSD_ErrorMessage"); // NOI18N
1095
case NotifyDescriptor.WARNING_MESSAGE:
1096            return NbBundle.getBundle(NbPresenter.class).getString("ACSD_WarningMessage"); // NOI18N
1097
case NotifyDescriptor.QUESTION_MESSAGE:
1098            return NbBundle.getBundle(NbPresenter.class).getString("ACSD_QuestionMessage"); // NOI18N
1099
case NotifyDescriptor.INFORMATION_MESSAGE:
1100            return NbBundle.getBundle(NbPresenter.class).getString("ACSD_InformationMessage"); // NOI18N
1101
case NotifyDescriptor.PLAIN_MESSAGE:
1102            return NbBundle.getBundle(NbPresenter.class).getString("ACSD_PlainMessage"); // NOI18N
1103
}
1104        return ""; // NOI18N
1105
}
1106
1107    private class AccessibleNbPresenter extends AccessibleJDialog {
1108        AccessibleNbPresenter() {}
1109        public String JavaDoc getAccessibleName() {
1110            if (accessibleName != null) {
1111                return accessibleName;
1112            } else {
1113                if (currentMessage instanceof javax.accessibility.Accessible JavaDoc
1114                    && currentMessage.getAccessibleContext().getAccessibleName() != null) {
1115                    return currentMessage.getAccessibleContext().getAccessibleName();
1116                } else {
1117                    return super.getAccessibleName();
1118                }
1119            }
1120        }
1121        public String JavaDoc getAccessibleDescription() {
1122            if (accessibleDescription != null) {
1123                return accessibleDescription;
1124            } else {
1125                if (currentMessage instanceof javax.accessibility.Accessible JavaDoc
1126                    && currentMessage.getAccessibleContext().getAccessibleDescription() != null) {
1127                    return java.text.MessageFormat.format(
1128                        getMessageTypeDescription(descriptor.getMessageType()),
1129                        new Object JavaDoc[] {
1130                            currentMessage.getAccessibleContext().getAccessibleDescription()
1131                        }
1132                    );
1133                } else {
1134                    return super.getAccessibleDescription();
1135                }
1136            }
1137        }
1138    }
1139
1140    static Field markers;
1141    static Method dequeue;
1142    static {
1143        if (Boolean.getBoolean("netbeans.hack.50423")) { // NOI18N
1144
try {
1145                markers = DefaultKeyboardFocusManager JavaDoc.class.getDeclaredField("typeAheadMarkers"); // NOI18N
1146
markers.setAccessible(true);
1147                dequeue = DefaultKeyboardFocusManager JavaDoc.class.getDeclaredMethod("dequeueKeyEvents", new Class JavaDoc[] { Long.TYPE, java.awt.Component JavaDoc.class });
1148                dequeue.setAccessible(true);
1149            } catch (Throwable JavaDoc ex) {
1150                LOG.log(Level.WARNING, "Not activating workaround for #50423", ex); // NOI18N
1151
}
1152        }
1153    }
1154    
1155    private final class HackTypeAhead implements Runnable JavaDoc {
1156        private RequestProcessor.Task task = RequestProcessor.getDefault().create(this);
1157        
1158        
1159        public HackTypeAhead() {
1160        }
1161        
1162        public void activate() {
1163            if (markers != null) {
1164                task.schedule(1000);
1165            }
1166        }
1167        
1168        public void run() {
1169            if (!SwingUtilities.isEventDispatchThread()) {
1170                SwingUtilities.invokeLater(this);
1171                return;
1172            }
1173
1174            KeyboardFocusManager JavaDoc fm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
1175            Collection result = null;
1176            try {
1177                result = (Collection) markers.get(fm);
1178            } catch (Exception JavaDoc ex) {
1179                Logger.getLogger(NbPresenter.class.getName()).log(Level.WARNING, null, ex);
1180            }
1181
1182            if (result == null || result.isEmpty()) {
1183                return;
1184            }
1185
1186            LOG.warning("Symptoms of #50423: There is something in type ahead: " + result + " requesting focus change"); // NOI18N
1187
try {
1188                dequeue.invoke(fm, new Object JavaDoc[] { Long.valueOf(-1), NbPresenter.this });
1189            } catch (Exception JavaDoc ex) {
1190                Logger.getLogger(NbPresenter.class.getName()).log(Level.WARNING, null, ex);
1191            }
1192        }
1193    } // end of HackTypeAhead
1194
}
1195
Popular Tags