KickJava   Java API By Example, From Geeks To Geeks.

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


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.JButton JavaDoc;
24 import java.net.URL JavaDoc;
25
26 import org.openide.DialogDescriptor;
27 import org.openide.DialogDisplayer;
28 import org.openide.util.Exceptions;
29 import org.openide.util.NbBundle;
30
31 /** Panel and dialog for showing External package information.
32  * @author Ales Kemr
33  */

34 class ExternalDialog extends javax.swing.JPanel JavaDoc {
35
36     /** Preferred size of this dialog */
37     private static final java.awt.Dimension JavaDoc preferredSize = new java.awt.Dimension JavaDoc( 450, 250 );
38
39     /** The only External panel instance in system */
40     private static ExternalDialog externalPanel;
41     /** The dialog descriptor of External dialog */
42     private static DialogDescriptor dialogDescriptor = null;
43     /** The External dialog */
44     private static java.awt.Dialog JavaDoc dialog = null;
45     /** External dialog Accept button */
46     private static JButton JavaDoc acceptButton;
47     /** External dialog Decline button */
48     private static JButton JavaDoc declineButton;
49     
50     private static String JavaDoc module_name;
51     private static ModuleUpdate.External external;
52     
53     static final long serialVersionUID =-4862117522808181670L;
54     /** Creates new form ExternalPanel */
55     public ExternalDialog() {
56         initComponents ();
57         
58         commentTextArea.setText(NbBundle.getMessage( ExternalDialog.class, "LBL_Ext_Comment",
59                            module_name));
60         nameTextField.setText( external.getName() );
61         targetTextField.setText( external.getTarget_name() );
62         descTextArea.setText( external.getDescription() );
63         initAccessibility();
64     }
65
66     /** Overload getPreffered size to get a bit bigger dialog */
67     public java.awt.Dimension JavaDoc getPreferredSize() {
68         return preferredSize;
69     }
70
71     /** This method is called from within the constructor to
72      * initialize the form.
73      * WARNING: Do NOT modify this code. The content of this method is
74      * always regenerated by the FormEditor.
75      */

76     private void initComponents() {//GEN-BEGIN:initComponents
77
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
78
79         commentTextArea = new javax.swing.JTextArea JavaDoc();
80         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
81         descTextArea = new javax.swing.JTextArea JavaDoc();
82         nameLabel = new javax.swing.JLabel JavaDoc();
83         nameTextField = new javax.swing.JTextField JavaDoc();
84         targetLabel = new javax.swing.JLabel JavaDoc();
85         descLabel = new javax.swing.JLabel JavaDoc();
86         targetTextField = new javax.swing.JTextField JavaDoc();
87
88         setLayout(new java.awt.GridBagLayout JavaDoc());
89
90         setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(8, 8, 8, 8)));
91         commentTextArea.setWrapStyleWord(true);
92         commentTextArea.setLineWrap(true);
93         commentTextArea.setEditable(false);
94         commentTextArea.setBackground(nameLabel.getBackground());
95         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
96         gridBagConstraints.gridwidth = 4;
97         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
98         add(commentTextArea, gridBagConstraints);
99
100         descTextArea.setEditable(false);
101         descTextArea.setFont(new Font JavaDoc("Monospaced", Font.PLAIN, descTextArea.getFont().getSize() + 1));
102         descTextArea.setLineWrap(true);
103         descTextArea.setWrapStyleWord(true);
104         jScrollPane1.setViewportView(descTextArea);
105
106         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
107         gridBagConstraints.gridy = 3;
108         gridBagConstraints.gridwidth = 4;
109         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
110         gridBagConstraints.weightx = 1.0;
111         gridBagConstraints.weighty = 1.0;
112         add(jScrollPane1, gridBagConstraints);
113
114         nameLabel.setLabelFor(nameTextField);
115         nameLabel.setText(getBundle("LBL_Ext_Name"));
116         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
117         gridBagConstraints.gridx = 0;
118         gridBagConstraints.gridy = 1;
119         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
120         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
121         add(nameLabel, gridBagConstraints);
122
123         nameTextField.setEditable(false);
124         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
125         gridBagConstraints.gridx = 1;
126         gridBagConstraints.gridy = 1;
127         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
128         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
129         gridBagConstraints.weightx = 1.0;
130         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 6, 0, 0);
131         add(nameTextField, gridBagConstraints);
132
133         targetLabel.setLabelFor(targetTextField);
134         targetLabel.setText(getBundle("LBL_Ext_Target"));
135         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
136         gridBagConstraints.gridx = 2;
137         gridBagConstraints.gridy = 1;
138         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
139         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 24, 0, 0);
140         add(targetLabel, gridBagConstraints);
141
142         descLabel.setLabelFor(descTextArea);
143         descLabel.setText(getBundle("LBL_Ext_Desc"));
144         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
145         gridBagConstraints.gridx = 0;
146         gridBagConstraints.gridy = 2;
147         gridBagConstraints.gridwidth = 2;
148         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
149         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
150         add(descLabel, gridBagConstraints);
151
152         targetTextField.setEditable(false);
153         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
154         gridBagConstraints.gridx = 3;
155         gridBagConstraints.gridy = 1;
156         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
157         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
158         gridBagConstraints.weightx = 1.0;
159         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 6, 0, 0);
160         add(targetTextField, gridBagConstraints);
161
162     }//GEN-END:initComponents
163

164     private void initAccessibility(){
165         getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/autoupdate/Bundle").getString("ACSD_ExtDialog"));
166         getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/autoupdate/Bundle").getString("CTL_Ext_Title"));
167         commentTextArea.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/autoupdate/Bundle").getString("ACSD_Comment_Text"));
168         commentTextArea.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/autoupdate/Bundle").getString("ACSN_Comment_Text"));
169         descTextArea.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/autoupdate/Bundle").getString("ACSD_Ext_Desc"));
170         nameLabel.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/autoupdate/Bundle").getString("ACS_Ext_Name_mnc").charAt(0));
171         nameTextField.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/autoupdate/Bundle").getString("ACSD_Ext_Name"));
172         targetLabel.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/autoupdate/Bundle").getString("ACS_Ext_Target_mnc").charAt(0));
173         descLabel.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/autoupdate/Bundle").getString("ACS_Ext_Desc_mnc").charAt(0));
174         targetTextField.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/autoupdate/Bundle").getString("ACSD_Ext_Target"));
175     }
176
177     // Variables declaration - do not modify//GEN-BEGIN:variables
178
private javax.swing.JTextArea JavaDoc commentTextArea;
179     private javax.swing.JLabel JavaDoc descLabel;
180     private javax.swing.JTextArea JavaDoc descTextArea;
181     private javax.swing.JScrollPane JavaDoc jScrollPane1;
182     private javax.swing.JLabel JavaDoc nameLabel;
183     private javax.swing.JTextField JavaDoc nameTextField;
184     private javax.swing.JLabel JavaDoc targetLabel;
185     private javax.swing.JTextField JavaDoc targetTextField;
186     // End of variables declaration//GEN-END:variables
187

188     static void showExternal( String JavaDoc name, ModuleUpdate.External ext_upd ) {
189         module_name = name;
190         external = ext_upd;
191
192         createDialog();
193         
194         dialog.setVisible(true);
195     }
196     
197     private static void createDialog() {
198         externalPanel = new ExternalDialog();
199
200         acceptButton = new JButton JavaDoc( getBundle( "BTN_Ext_OK" ) );
201         acceptButton.getAccessibleContext().setAccessibleDescription(getBundle( "ACSD_Ext_OK" ));
202         acceptButton.setMnemonic(getBundle( "ACS_Ext_OK_mnc" ).charAt(0));
203         declineButton = new JButton JavaDoc( getBundle( "BTN_Ext_Cancel" ) );
204         declineButton.getAccessibleContext().setAccessibleDescription(getBundle( "ACSD_Ext_Cancel" ));
205         declineButton.setMnemonic(getBundle( "ACS_Ext_Cancel_mnc" ).charAt(0));
206
207         dialogDescriptor = new DialogDescriptor(
208                                externalPanel,
209                                getBundle( "CTL_Ext_Title" ),
210                                true, // Modal
211
new Object JavaDoc[] { acceptButton, declineButton }, // Option list
212
acceptButton, // Default
213
DialogDescriptor.BOTTOM_ALIGN, // Align
214
null, // Help
215
new java.awt.event.ActionListener JavaDoc() {
216
217                                    public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
218                                        if (evt.getSource() == acceptButton)
219                                            try {
220                                                org.openide.awt.HtmlBrowser.URLDisplayer.getDefault().showURL(new URL JavaDoc(external.getStart_url()));
221                                            }
222                                            catch (java.net.MalformedURLException JavaDoc e) {
223                                                Exceptions.printStackTrace(e);
224                                            }
225                                        dialog.setVisible(false);
226                                    }
227                                });
228
229         dialog = DialogDisplayer.getDefault().createDialog( dialogDescriptor );
230     }
231
232     private static String JavaDoc getBundle( String JavaDoc key ) {
233         return NbBundle.getMessage( ExternalDialog.class, key );
234     }
235 }
236
Popular Tags