KickJava   Java API By Example, From Geeks To Geeks.

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


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.BorderLayout JavaDoc;
23 import java.awt.Font JavaDoc;
24 import java.util.Enumeration JavaDoc;
25 import javax.swing.*;
26 import java.beans.PropertyChangeListener JavaDoc;
27 import java.beans.PropertyChangeEvent JavaDoc;
28 import org.netbeans.api.progress.ProgressHandle;
29 import org.netbeans.api.progress.ProgressHandleFactory;
30
31 import org.openide.DialogDescriptor;
32 import org.openide.DialogDisplayer;
33 import org.openide.util.NbBundle;
34
35 /**
36  *
37  * @author Ales Kemr
38  */

39 /*was public*/ class ConnectingDialog extends javax.swing.JPanel JavaDoc {
40
41     static final int CANCEL = 1;
42     static final int SKIP = 2;
43     static final int OK = 0;
44     
45     static boolean canceled = false;
46     static boolean skipped = false;
47     
48     private ProgressHandle progress;
49     
50     /** Creates new form ConnectingDialog */
51     private /*was public*/ ConnectingDialog(String JavaDoc ucname) {
52         ProgressHandle progress = ProgressHandleFactory.createHandle (getBundle ("MSG_progressHandle_name")); // NOI18N
53
initComponents();
54         iconLabel.setText(getBundle("CTL_Connecting_Label") // NOI18N
55
+ " " + ucname + "..."); // NOI18N
56
add (ProgressHandleFactory.createProgressComponent (progress), BorderLayout.SOUTH);
57         progress.start ();
58
59         getAccessibleContext().setAccessibleName(getBundle("CTL_Connecting_Title")); // NOI18N
60
getAccessibleContext().setAccessibleDescription(iconLabel.getText());
61     }
62
63     /** This method is called from within the constructor to
64      * initialize the form.
65      * WARNING: Do NOT modify this code. The content of this method is
66      * always regenerated by the Form Editor.
67      */

68     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
69
private void initComponents() {
70         iconLabel = new javax.swing.JLabel JavaDoc();
71
72         setLayout(new java.awt.BorderLayout JavaDoc(0, 20));
73
74         setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(18, 18, 18, 18)));
75         iconLabel.setFont(new Font JavaDoc(iconLabel.getFont().getName(), Font.BOLD, iconLabel.getFont().getSize()));
76         iconLabel.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/org/netbeans/modules/autoupdate/resources/gears.gif")));
77         iconLabel.setLabelFor(this);
78         iconLabel.setText(getBundle("CTL_Connecting_Label"));
79         iconLabel.setIconTextGap(16);
80         add(iconLabel, java.awt.BorderLayout.CENTER);
81
82     }
83     // </editor-fold>//GEN-END:initComponents
84

85
86     // Variables declaration - do not modify//GEN-BEGIN:variables
87
private javax.swing.JLabel JavaDoc iconLabel;
88     // End of variables declaration//GEN-END:variables
89

90     private static DialogDescriptor createDialog(String JavaDoc ucname) {
91
92         final JButton cancelButton = new JButton(getBundle( "CTL_Connecting_Cancel" ) );
93         cancelButton.setToolTipText( getBundle( "CTL_Connecting_Cancel_ToolTip" ) );
94         cancelButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
95             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
96                 canceled = true;
97             }
98         });
99         
100         Enumeration JavaDoc ucs = AutoupdateType.autoupdateTypes ();
101         assert ucs != null : "autoupdateTypes not null";
102         
103         int cnt = 0;
104         while (cnt < 2 && ucs.hasMoreElements ()) {
105             AutoupdateType at = (AutoupdateType)ucs.nextElement ();
106             if (at.isEnabled ()) cnt ++;
107         }
108         Object JavaDoc[] options = null;
109         Object JavaDoc defaultOption = cancelButton;
110         if (cnt > 1) {
111             final JButton skipButton = new JButton( getBundle("CTL_Connecting_Skip"));
112             skipButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
113                 public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
114                     skipped = true;
115                 }
116             });
117             skipButton.getAccessibleContext().setAccessibleDescription(getBundle("ACS_Connecting_Skip"));
118             options = new Object JavaDoc[] {skipButton, cancelButton};
119             defaultOption = skipButton;
120         } else {
121             options = new Object JavaDoc[] {cancelButton};
122         }
123
124         DialogDescriptor dd;
125         dd = new DialogDescriptor(
126                  new ConnectingDialog(ucname),
127                  getBundle( "CTL_Connecting_Title" ),
128                  true, // Modal
129
options, // Option list
130
defaultOption, // Default
131
DialogDescriptor.DEFAULT_ALIGN, // Align
132
null, // Help
133
null);
134
135         dd.addPropertyChangeListener( new PropertyChangeListener JavaDoc() {
136                   public void propertyChange(PropertyChangeEvent JavaDoc event) {
137                       if (event.getPropertyName().equals(DialogDescriptor.PROP_VALUE)) {
138                           Object JavaDoc option = event.getNewValue();
139                           if (option == DialogDescriptor.CLOSED_OPTION)
140                               canceled = true;
141                       }
142                   }
143               });
144
145         dd.setClosingOptions( null );
146
147         return dd;
148     }
149     
150     static void closeDialog(java.awt.Dialog JavaDoc dialog) {
151         dialog.dispose();
152     }
153     
154     static boolean isCanceled() {
155         return canceled;
156     }
157     
158     static boolean isSkipped() {
159         return skipped;
160     }
161     
162     static java.awt.Dialog JavaDoc getDialog(String JavaDoc ucname) {
163         DialogDescriptor dd = createDialog(ucname);
164         canceled = false;
165         skipped = false;
166         java.awt.Dialog JavaDoc dialog = DialogDisplayer.getDefault().createDialog( dd );
167         return dialog;
168     }
169     
170     private static String JavaDoc getBundle( String JavaDoc key ) {
171         return NbBundle.getMessage( ConnectingDialog.class, key );
172     }
173 }
174
175
Popular Tags