KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > db > explorer > dlg > LabeledComboDialog


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.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 JavaDoc;
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 /**
34 * @author Slavek Psenicka
35 */

36 public class LabeledComboDialog {
37     boolean result = false;
38     Dialog dialog = null;
39     Object JavaDoc combosel = null;
40     JComboBox combo;
41
42     public LabeledComboDialog(String JavaDoc title, String JavaDoc lab, Collection items) {
43         try {
44             JPanel pane = new JPanel();
45             pane.setBorder(new EmptyBorder JavaDoc(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"); //NOI18N
51

52             pane.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_AddToIndexDialogA11yDesc")); //NOI18N
53

54             // Title
55

56             JLabel label = new JLabel(lab);
57             con.anchor = GridBagConstraints.WEST;
58             con.insets = new java.awt.Insets JavaDoc (2, 2, 2, 2);
59             con.gridx = 0;
60             con.gridy = 0;
61             layout.setConstraints(label, con);
62             pane.add(label);
63
64             // Combo
65

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 JavaDoc (2, 2, 2, 2);
71             combo = new JComboBox((items instanceof Vector) ? (Vector)items : new Vector(items));
72             combo.getAccessibleContext().setAccessibleName(bundle.getString("ACS_AddToIndexComboA11yName")); //NOI18N
73
combo.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_AddToIndexComboA11yDesc")); //NOI18N
74
combo.setToolTipText(bundle.getString("ACS_AddToIndexComboA11yDesc")); //NOI18N
75
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 JavaDoc getSelectedItem() {
111         return combosel;
112     }
113 }
114
Popular Tags