KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > autoupdate > DuplicateWarningDialog


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.autoupdate;
21
22 import java.awt.Font JavaDoc;
23 import javax.swing.*;
24 import java.beans.PropertyChangeListener JavaDoc;
25 import java.beans.PropertyChangeEvent JavaDoc;
26
27
28 import org.openide.DialogDescriptor;
29 import org.openide.DialogDisplayer;
30 import org.openide.util.NbBundle;
31
32 /**
33  *
34  * @author Ales Kemr
35  */

36 class DuplicateWarningDialog extends javax.swing.JPanel JavaDoc {
37
38     static final int YES = 0;
39     static final int YES_ALL = 1;
40     static final int NO = 2;
41     static final int NO_ALL = 3;
42
43     static int result = NO;
44
45     /** Creates new form DuplicateWarningDialog */
46     public DuplicateWarningDialog(String JavaDoc ucname) {
47         initComponents();
48         
49         iconLabel.setText(NbBundle.getMessage( DuplicateWarningDialog.class, "MSG_DuplicateModule" ,
50                            ucname ));
51         // don't use deriveFont() - see #49973 for details
52
iconLabel.setFont(ResultsPanel.doDeriveFont(iconLabel.getFont(), Font.BOLD));
53                            
54         initAccessibility();
55     }
56
57     /** This method is called from within the constructor to
58      * initialize the form.
59      * WARNING: Do NOT modify this code. The content of this method is
60      * always regenerated by the Form Editor.
61      */

62     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
63
private void initComponents() {
64         iconLabel = new javax.swing.JLabel JavaDoc();
65
66         setLayout(new java.awt.BorderLayout JavaDoc());
67
68         setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(18, 18, 18, 18)));
69         iconLabel.setText(getBundle("MSG_DuplicateModule"));
70         iconLabel.setIconTextGap(16);
71         add(iconLabel, java.awt.BorderLayout.CENTER);
72
73     }
74     // </editor-fold>//GEN-END:initComponents
75

76     private void initAccessibility(){
77         getAccessibleContext().setAccessibleDescription(getBundle("ACSD_DuplicateWarning"));
78         getAccessibleContext().setAccessibleName(getBundle( "CTL_Duplicate_Title" ));
79     }
80
81     // Variables declaration - do not modify//GEN-BEGIN:variables
82
private javax.swing.JLabel JavaDoc iconLabel;
83     // End of variables declaration//GEN-END:variables
84

85     private static DialogDescriptor createDialog(String JavaDoc ucname) {
86
87         final JButton yesButton = new JButton(getBundle( "CTL_Duplicate_Yes" ) );
88         yesButton.setToolTipText( getBundle( "CTL_Duplicate_Yes_ToolTip" ) );
89         yesButton.setMnemonic(getBundle( "ACS_Duplicate_Yes_mnc" ).charAt(0) );
90         yesButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
91             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
92                 result = YES;
93             }
94         });
95         
96         final JButton yes_allButton = new JButton(getBundle( "CTL_Duplicate_Yes_All" ) );
97         yes_allButton.setToolTipText( getBundle( "CTL_Duplicate_Yes_All_ToolTip" ) );
98         yes_allButton.setMnemonic(getBundle( "ACS_Duplicate_Yes_All_mnc" ).charAt(0) );
99         yes_allButton.getAccessibleContext ().setAccessibleName (getBundle ("ACSN_Duplicate_Yes_All"));
100         yes_allButton.getAccessibleContext ().setAccessibleDescription (getBundle ("ACSD_Duplicate_Yes_All"));
101         yes_allButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
102             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
103                 result = YES_ALL;
104             }
105         });
106         
107         final JButton noButton = new JButton(getBundle( "CTL_Duplicate_No" ) );
108         noButton.setToolTipText( getBundle( "CTL_Duplicate_No_ToolTip" ) );
109         noButton.setMnemonic(getBundle( "ACS_Duplicate_No_mnc" ).charAt(0) );
110         noButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
111             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
112                 result = NO;
113             }
114         });
115         
116         final JButton no_allButton = new JButton(getBundle( "CTL_Duplicate_No_All" ) );
117         no_allButton.setToolTipText( getBundle( "CTL_Duplicate_No_All_ToolTip" ) );
118         no_allButton.setMnemonic(getBundle( "ACS_Duplicate_No_All_mnc" ).charAt(0) );
119         no_allButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
120             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
121                 result = NO_ALL;
122             }
123         });
124
125         
126                
127         DialogDescriptor dd;
128         dd = new DialogDescriptor(
129                  new DuplicateWarningDialog(ucname),
130                  getBundle( "CTL_Duplicate_Title" ),
131                  true, // Modal
132
new Object JavaDoc [] {
133                      yesButton,
134                      yes_allButton,
135                      noButton,
136                      no_allButton
137                  }, // Option list
138
noButton, // Default
139
DialogDescriptor.DEFAULT_ALIGN, // Align
140
null, // Help
141
null);
142
143         dd.addPropertyChangeListener( new PropertyChangeListener JavaDoc() {
144                                               public void propertyChange(PropertyChangeEvent JavaDoc event) {
145                                                   if (event.getPropertyName().equals(DialogDescriptor.PROP_VALUE)) {
146                                                       Object JavaDoc option = event.getNewValue();
147                                                       if (option == DialogDescriptor.CLOSED_OPTION)
148                                                           result = NO;
149                                                   }
150                                               }
151                                           });
152
153         dd.setClosingOptions( null );
154
155         return dd;
156     }
157     
158     static void closeDialog(java.awt.Dialog JavaDoc dialog) {
159         dialog.dispose();
160     }
161     
162     static int getResult() {
163         return result;
164     }
165     
166     static java.awt.Dialog JavaDoc getDialog(String JavaDoc ucname) {
167         DialogDescriptor dd = createDialog(ucname);
168         result = NO;
169         java.awt.Dialog JavaDoc dialog = DialogDisplayer.getDefault().createDialog( dd );
170         return dialog;
171     }
172     
173     private static String JavaDoc getBundle( String JavaDoc key ) {
174         return NbBundle.getMessage( DuplicateWarningDialog.class, key );
175     }
176 }
177
178
Popular Tags