1 19 20 package org.netbeans.modules.autoupdate; 21 22 import java.awt.BorderLayout ; 23 import java.awt.Font ; 24 import java.util.Enumeration ; 25 import javax.swing.*; 26 import java.beans.PropertyChangeListener ; 27 import java.beans.PropertyChangeEvent ; 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 39 class ConnectingDialog extends javax.swing.JPanel { 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 51 private ConnectingDialog(String ucname) { 52 ProgressHandle progress = ProgressHandleFactory.createHandle (getBundle ("MSG_progressHandle_name")); initComponents(); 54 iconLabel.setText(getBundle("CTL_Connecting_Label") + " " + ucname + "..."); add (ProgressHandleFactory.createProgressComponent (progress), BorderLayout.SOUTH); 57 progress.start (); 58 59 getAccessibleContext().setAccessibleName(getBundle("CTL_Connecting_Title")); getAccessibleContext().setAccessibleDescription(iconLabel.getText()); 61 } 62 63 68 private void initComponents() { 70 iconLabel = new javax.swing.JLabel (); 71 72 setLayout(new java.awt.BorderLayout (0, 20)); 73 74 setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (18, 18, 18, 18))); 75 iconLabel.setFont(new Font (iconLabel.getFont().getName(), Font.BOLD, iconLabel.getFont().getSize())); 76 iconLabel.setIcon(new javax.swing.ImageIcon (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 85 86 private javax.swing.JLabel iconLabel; 88 90 private static DialogDescriptor createDialog(String 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 () { 95 public void actionPerformed(java.awt.event.ActionEvent evt) { 96 canceled = true; 97 } 98 }); 99 100 Enumeration 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 [] options = null; 109 Object defaultOption = cancelButton; 110 if (cnt > 1) { 111 final JButton skipButton = new JButton( getBundle("CTL_Connecting_Skip")); 112 skipButton.addActionListener(new java.awt.event.ActionListener () { 113 public void actionPerformed(java.awt.event.ActionEvent evt) { 114 skipped = true; 115 } 116 }); 117 skipButton.getAccessibleContext().setAccessibleDescription(getBundle("ACS_Connecting_Skip")); 118 options = new Object [] {skipButton, cancelButton}; 119 defaultOption = skipButton; 120 } else { 121 options = new Object [] {cancelButton}; 122 } 123 124 DialogDescriptor dd; 125 dd = new DialogDescriptor( 126 new ConnectingDialog(ucname), 127 getBundle( "CTL_Connecting_Title" ), 128 true, options, defaultOption, DialogDescriptor.DEFAULT_ALIGN, null, null); 134 135 dd.addPropertyChangeListener( new PropertyChangeListener () { 136 public void propertyChange(PropertyChangeEvent event) { 137 if (event.getPropertyName().equals(DialogDescriptor.PROP_VALUE)) { 138 Object 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 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 getDialog(String ucname) { 163 DialogDescriptor dd = createDialog(ucname); 164 canceled = false; 165 skipped = false; 166 java.awt.Dialog dialog = DialogDisplayer.getDefault().createDialog( dd ); 167 return dialog; 168 } 169 170 private static String getBundle( String key ) { 171 return NbBundle.getMessage( ConnectingDialog.class, key ); 172 } 173 } 174 175 | Popular Tags |