1 19 24 package org.netbeans.modules.junit; 25 26 import java.awt.Dialog ; 27 import java.awt.event.ActionEvent ; 28 import java.awt.event.ActionListener ; 29 import javax.swing.JPanel ; 30 import javax.swing.SwingUtilities ; 31 import org.openide.DialogDescriptor; 32 import org.openide.DialogDisplayer; 33 import org.openide.awt.StatusDisplayer; 34 import org.openide.util.NbBundle; 35 36 40 public class JUnitProgress extends JPanel implements ActionListener { 41 42 public JUnitProgress(String dialogTitle) { 43 if (dialogTitle != null) { 44 this.dialogTitle = dialogTitle; 45 } 46 initComponents(); 47 } 48 public void showMe(boolean displayCancel) { 49 if (null == descriptor) { 50 Object [] options = null; 51 Object initOption = null; 52 53 if (displayCancel) { 54 options = new Object [] { DialogDescriptor.CANCEL_OPTION }; 55 initOption = DialogDescriptor.CANCEL_OPTION; 56 } 57 58 descriptor = new DialogDescriptor ( 59 this, 60 dialogTitle, 61 false, 62 options, 63 initOption, 64 DialogDescriptor.BOTTOM_ALIGN, 65 null, 66 this 67 ); 68 } 69 70 if (null != dialog) 71 dialog.dispose(); 72 73 canceled = false; 74 dialog = DialogDisplayer.getDefault().createDialog(descriptor); 75 dialog.getAccessibleContext().setAccessibleDescription( 76 NbBundle.getMessage(JUnitProgress.class, 77 "ACS_StatusBar_CreateTests")); dialog.setSize(400, 150); 79 dialog.setVisible(true); 80 } 81 82 public void hideMe() { 83 if (null != dialog) { 84 dialog.dispose(); 85 } 86 } 87 public void actionPerformed(ActionEvent ev) { 88 canceled = true; 89 } 90 91 public void setMessage(final String msg) { 92 setMessage(msg,false); 93 } 94 95 public void setMessage(final String msg, boolean displayStatus) { 96 if (SwingUtilities.isEventDispatchThread()) 97 lblMessage.setText(msg); 98 else { 99 SwingUtilities.invokeLater( 100 new Thread () { 101 public void run() { 102 lblMessage.setText(msg); 103 } 104 } 105 ); 106 } 107 if (displayStatus) { 108 displayStatusText(msg); 109 } 110 } 111 112 public boolean isCanceled() { 113 return canceled; 114 } 115 116 public void displayStatusText(String statusText) { 119 StatusDisplayer.getDefault().setStatusText(statusText); 120 } 121 122 123 private DialogDescriptor descriptor = null; 124 private Dialog dialog = null; 125 private volatile boolean canceled = false; 126 private String dialogTitle = ""; 127 128 133 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 135 136 lblMessage = new javax.swing.JLabel (); 137 138 setLayout(new java.awt.GridBagLayout ()); 139 140 lblMessage.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/junit/Bundle").getString("JUnitProgress.lblMessage.text")); 141 lblMessage.setAlignmentX(0.5F); 142 lblMessage.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); 143 gridBagConstraints = new java.awt.GridBagConstraints (); 144 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 145 gridBagConstraints.insets = new java.awt.Insets (12, 12, 4, 4); 146 gridBagConstraints.weightx = 1.0; 147 gridBagConstraints.weighty = 1.0; 148 add(lblMessage, gridBagConstraints); 149 150 } private javax.swing.JLabel lblMessage; 153 } 155 | Popular Tags |