1 19 20 package org.netbeans.modules.db.explorer.dlg; 21 22 import java.awt.*; 23 import java.awt.event.*; 24 import java.util.*; 25 import javax.swing.*; 26 import javax.swing.border.EmptyBorder ; 27 import org.openide.DialogDescriptor; 28 import org.openide.DialogDisplayer; 29 import org.openide.util.NbBundle; 30 31 import org.netbeans.modules.db.explorer.*; 32 33 36 public class LabeledComboDialog { 37 boolean result = false; 38 Dialog dialog = null; 39 Object combosel = null; 40 JComboBox combo; 41 42 public LabeledComboDialog(String title, String lab, Collection items) { 43 try { 44 JPanel pane = new JPanel(); 45 pane.setBorder(new EmptyBorder (new Insets(5,5,5,5))); 46 GridBagLayout layout = new GridBagLayout(); 47 GridBagConstraints con = new GridBagConstraints (); 48 pane.setLayout (layout); 49 50 ResourceBundle bundle = NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle"); 52 pane.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_AddToIndexDialogA11yDesc")); 54 56 JLabel label = new JLabel(lab); 57 con.anchor = GridBagConstraints.WEST; 58 con.insets = new java.awt.Insets (2, 2, 2, 2); 59 con.gridx = 0; 60 con.gridy = 0; 61 layout.setConstraints(label, con); 62 pane.add(label); 63 64 66 con.fill = GridBagConstraints.HORIZONTAL; 67 con.weightx = 1.0; 68 con.gridx = 1; 69 con.gridy = 0; 70 con.insets = new java.awt.Insets (2, 2, 2, 2); 71 combo = new JComboBox((items instanceof Vector) ? (Vector)items : new Vector(items)); 72 combo.getAccessibleContext().setAccessibleName(bundle.getString("ACS_AddToIndexComboA11yName")); combo.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_AddToIndexComboA11yDesc")); combo.setToolTipText(bundle.getString("ACS_AddToIndexComboA11yDesc")); layout.setConstraints(combo, con); 76 pane.add(combo); 77 78 ActionListener listener = new ActionListener() { 79 public void actionPerformed(ActionEvent event) { 80 boolean dispcond = true; 81 if (event.getSource() == DialogDescriptor.OK_OPTION) { 82 result = true; 83 combosel = combo.getSelectedItem(); 84 } else 85 result = false; 86 87 if (dispcond) { 88 dialog.setVisible(false); 89 dialog.dispose(); 90 } else 91 Toolkit.getDefaultToolkit().beep(); 92 } 93 }; 94 95 DialogDescriptor descriptor = new DialogDescriptor(pane, title, true, listener); 96 dialog = DialogDisplayer.getDefault().createDialog(descriptor); 97 dialog.setResizable(false); 98 } catch (MissingResourceException ex) { 99 ex.printStackTrace(); 100 } 101 } 102 103 public boolean run() { 104 if (dialog != null) 105 dialog.setVisible(true); 106 107 return result; 108 } 109 110 public Object getSelectedItem() { 111 return combosel; 112 } 113 } 114 | Popular Tags |