1 19 20 package org.netbeans.modules.editor.impl; 21 22 import java.awt.event.*; 23 import java.awt.Dialog ; 24 import javax.swing.JButton ; 25 import javax.swing.JComponent ; 26 import javax.swing.JDialog ; 27 import javax.swing.JPanel ; 28 import javax.swing.KeyStroke ; 29 import org.openide.DialogDescriptor; 30 import org.openide.util.HelpCtx; 31 import java.util.HashMap ; 32 import org.netbeans.spi.editor.DialogFactory; 33 34 38 public class NbDialogFactory implements DialogFactory { 39 40 43 private static HashMap helpIDs; 44 45 private static final String HELP_ID_MacroSavePanel = "editing.macros.recording"; private static final String HELP_ID_FindPanel = "editing.find"; private static final String HELP_ID_JavaFastImportPanel = "editing.fastimport"; private static final String HELP_ID_ScrollCompletionPane = "editing.codecompletion"; 50 public NbDialogFactory() 51 { 52 if (helpIDs == null) 53 { 54 helpIDs = new HashMap (7); 55 helpIDs.put("org.netbeans.editor.MacroSavePanel", HELP_ID_MacroSavePanel); helpIDs.put("org.netbeans.editor.ext.FindDialogSupport$FindPanel", HELP_ID_FindPanel); helpIDs.put("org.netbeans.editor.ext.ScrollCompletionPane", HELP_ID_ScrollCompletionPane); helpIDs.put("org.netbeans.editor.ext.java.JavaFastImportPanel", HELP_ID_JavaFastImportPanel); } 60 } 61 62 77 public Dialog createDialog(String title, JPanel panel,boolean modal,JButton [] buttons,boolean sideButtons,int defaultIndex,int cancelIndex,ActionListener listener) { 78 String helpID = (String )helpIDs.get(panel.getClass().getName()); 79 Dialog d = org.openide.DialogDisplayer.getDefault().createDialog( 80 new DialogDescriptor( panel, title, modal, buttons, 81 defaultIndex == -1 ? buttons[0] : buttons[defaultIndex], 82 sideButtons ? DialogDescriptor.RIGHT_ALIGN : DialogDescriptor.BOTTOM_ALIGN, 83 helpID != null ? new HelpCtx( helpID ) : null, listener 84 ) 85 ); 86 87 if( cancelIndex >= 0 && d instanceof JDialog ) { 89 final JButton cancelButton = buttons[cancelIndex]; 90 ((JDialog )d).getRootPane().registerKeyboardAction( 92 new ActionListener() { 93 public void actionPerformed(ActionEvent evt) { cancelButton.doClick( 10 ); 95 } 96 }, 97 KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, true), 98 JComponent.WHEN_FOCUSED 100 ); 101 102 ((JDialog )d).getRootPane().setFocusable(false); 104 105 d.addWindowListener( 106 new WindowAdapter() { 107 public void windowClosing( WindowEvent evt ) { 108 cancelButton.doClick( 10 ); 109 } 110 } 111 ); 112 } 113 114 return d; 115 } 116 117 } 118 | Popular Tags |