1 19 20 package org.netbeans.modules.junit; 21 22 import java.awt.EventQueue ; 23 import java.lang.reflect.Method ; 24 import org.openide.ErrorManager; 25 import org.openide.awt.StatusDisplayer; 26 import org.openide.util.NbBundle; 27 28 36 class ProgressIndicator { 37 38 42 private String initialMessage; 43 private JUnitProgress progressPanel; 44 45 private boolean guiCreationScheduled; 46 47 synchronized boolean isCanceled() { 48 return progressPanel != null ? progressPanel.isCanceled() : false; 49 } 50 51 void displayStatusText(String statusText) { 52 StatusDisplayer.getDefault().setStatusText(statusText); 53 } 54 55 62 synchronized void setMessage(final String msg, final boolean displayStatus) { 63 if (guiCreationScheduled) { 64 EventQueue.invokeLater(new Runnable () { 65 public void run() { 66 progressPanel.setMessage(msg, displayStatus); 67 } 68 }); 69 } else { 70 74 initialMessage = msg; 75 } 76 } 77 78 synchronized void show() { 79 if (!guiCreationScheduled) { 80 sendToAwtQueue("createAndShowDialog"); guiCreationScheduled = true; 82 } else { 83 sendToAwtQueue("showDialog"); } 85 } 86 87 synchronized void hide() { 88 if (guiCreationScheduled) { 89 sendToAwtQueue("hideDialog"); } 91 StatusDisplayer.getDefault().setStatusText(""); } 93 94 96 synchronized void createAndShowDialog() { 97 String msg = NbBundle.getMessage(ProgressIndicator.class, 98 "LBL_generator_progress_title"); progressPanel = new JUnitProgress(msg); 100 101 if (initialMessage != null) { 102 progressPanel.setMessage(initialMessage); 103 initialMessage = null; 104 } 105 106 showDialog(); 107 } 108 109 111 synchronized void showDialog() { 112 progressPanel.showMe(true); 113 } 114 115 117 synchronized void hideDialog() { 118 progressPanel.hideMe(); 119 } 120 121 123 private void sendToAwtQueue(String methodName) { 124 final Method method; 125 try { 126 method = getClass().getDeclaredMethod(methodName, new Class [0]); 127 } catch (Exception ex) { 128 ErrorManager.getDefault().notify(ErrorManager.ERROR, ex); 129 return; 130 } 131 EventQueue.invokeLater(new Runnable () { 132 public void run() { 133 try { 134 method.invoke(ProgressIndicator.this, (Object []) null); 135 } catch (Exception ex) { 136 ErrorManager.getDefault().notify(ErrorManager.ERROR, ex); 137 } 138 } 139 }); 140 } 141 142 } 143 | Popular Tags |