KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > core > palette > items > ChooseCustomizer


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
21 package org.netbeans.modules.web.core.palette.items;
22 import java.awt.Dialog JavaDoc;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25 import javax.swing.JSpinner JavaDoc;
26 import javax.swing.SpinnerNumberModel JavaDoc;
27 import javax.swing.text.JTextComponent JavaDoc;
28 import org.openide.DialogDescriptor;
29 import org.openide.DialogDisplayer;
30 import org.openide.util.NbBundle;
31
32
33
34 /**
35  *
36  * @author Libor Kotouc
37  */

38 public class ChooseCustomizer extends javax.swing.JPanel JavaDoc {
39
40     private Dialog JavaDoc dialog = null;
41     private DialogDescriptor descriptor = null;
42     private boolean dialogOK = false;
43
44     private Choose choose;
45     JTextComponent JavaDoc target;
46             
47     public ChooseCustomizer(Choose choose, JTextComponent JavaDoc target) {
48         this.choose = choose;
49         this.target = target;
50
51         initComponents();
52     }
53     
54     public boolean showDialog() {
55         
56         dialogOK = false;
57         
58         String JavaDoc displayName = "";
59         try {
60             displayName = NbBundle.getBundle("org.netbeans.modules.web.core.palette.items.resources.Bundle").getString("NAME_jsp-Choose"); // NOI18N
61
}
62         catch (Exception JavaDoc e) {}
63         
64         descriptor = new DialogDescriptor
65                 (this, NbBundle.getMessage(ChooseCustomizer.class, "LBL_Customizer_InsertPrefix") + " " + displayName, true,
66                  DialogDescriptor.OK_CANCEL_OPTION, DialogDescriptor.OK_OPTION,
67                  new ActionListener JavaDoc() {
68                      public void actionPerformed(ActionEvent JavaDoc e) {
69                         if (descriptor.getValue().equals(DialogDescriptor.OK_OPTION)) {
70                             evaluateInput();
71                             dialogOK = true;
72                         }
73                         dialog.dispose();
74              }
75          }
76                 );
77         
78         dialog = DialogDisplayer.getDefault().createDialog(descriptor);
79         dialog.setVisible(true);
80         repaint();
81         
82         return dialogOK;
83     }
84     
85     private void evaluateInput() {
86         
87         int whens = ((Integer JavaDoc)jSpinner1.getValue()).intValue();
88         choose.setWhens(whens);
89
90         choose.setOtherwise(jCheckBox1.isSelected());
91     }
92     
93     /** This method is called from within the constructor to
94      * initialize the form.
95      * WARNING: Do NOT modify this code. The content of this method is
96      * always regenerated by the Form Editor.
97      */

98     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
99
private void initComponents() {
100         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
101
102         jLabel2 = new javax.swing.JLabel JavaDoc();
103         jSpinner1 = new javax.swing.JSpinner JavaDoc();
104         jCheckBox1 = new javax.swing.JCheckBox JavaDoc();
105
106         setLayout(new java.awt.GridBagLayout JavaDoc());
107
108         jLabel2.setLabelFor(jSpinner1);
109         org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(ChooseCustomizer.class, "LBL_Choose_Whens"));
110         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
111         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
112         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
113         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
114         add(jLabel2, gridBagConstraints);
115         jLabel2.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ChooseCustomizer.class, "ACSN_Choose_Whens"));
116         jLabel2.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ChooseCustomizer.class, "ACSD_Choose_Whens"));
117
118         jSpinner1.setModel(new SpinnerNumberModel JavaDoc(Choose.DEFAULT_WHENS, 1, Integer.MAX_VALUE, 1));
119         jSpinner1.setEditor(new JSpinner.NumberEditor JavaDoc(jSpinner1, "#"));
120         jSpinner1.setValue(new Integer JavaDoc(Choose.DEFAULT_WHENS));
121         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
122         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
123         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
124         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 18);
125         add(jSpinner1, gridBagConstraints);
126
127         jCheckBox1.setSelected(true);
128         org.openide.awt.Mnemonics.setLocalizedText(jCheckBox1, org.openide.util.NbBundle.getMessage(ChooseCustomizer.class, "LBL_Choose_Otherwise"));
129         jCheckBox1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
130         jCheckBox1.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
131         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
132         gridBagConstraints.gridx = 0;
133         gridBagConstraints.gridy = 1;
134         gridBagConstraints.gridwidth = 2;
135         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
136         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
137         gridBagConstraints.weightx = 1.0;
138         gridBagConstraints.weighty = 1.0;
139         gridBagConstraints.insets = new java.awt.Insets JavaDoc(11, 11, 11, 0);
140         add(jCheckBox1, gridBagConstraints);
141         jCheckBox1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ChooseCustomizer.class, "ACSN_Choose_Otherwise"));
142         jCheckBox1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ChooseCustomizer.class, "ACSD_Choose_Otherwise"));
143
144     }// </editor-fold>//GEN-END:initComponents
145

146     
147     // Variables declaration - do not modify//GEN-BEGIN:variables
148
private javax.swing.JCheckBox JavaDoc jCheckBox1;
149     private javax.swing.JLabel JavaDoc jLabel2;
150     private javax.swing.JSpinner JavaDoc jSpinner1;
151     // End of variables declaration//GEN-END:variables
152

153 }
154
Popular Tags