//Auto confirm timer
int timeOut = ApplicationProperties.getConfirmTimeout();
if ( timeOut > 0 ) {
- TimerTask task = new TimerTask() {
- public void run() {
- jButtonOKActionPerformed(null);
- }
- };
- confirmTimer.schedule(task, timeOut * 1000L);
+ confirmTimer.schedule(confirmTimeoutTimerTask, timeOut * 1000L);
+ }
+ }
+ private void cancelConfirmTimeoutTimerTask() {
+ if ( !confirmTimeoutTimerTask.cancel() ) {
+ System.err.println("Already do task?");
}
}
private static Timer confirmTimer = new Timer();
+ private TimerTask confirmTimeoutTimerTask = new TimerTask() {
+ public void run() {
+ jButtonOKActionPerformed(null);
+ }
+ };
/** This method is called from within the constructor to
}// </editor-fold>//GEN-END:initComponents
private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
+ cancelConfirmTimeoutTimerTask();
restorePosition();
resultNotify.sayNG();
}//GEN-LAST:event_formWindowClosing
-
+
private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
+ cancelConfirmTimeoutTimerTask();
restorePosition();
resultNotify.sayNG();
this.dispose();
private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed
//push OK
- restorePosition();
- resultNotify.sayOK();
- this.dispose();
+ //if ( isVisible() ) { //Care after dialog closing, confirm time out occurred. -> use cancelTimerTask.
+ restorePosition();
+ resultNotify.sayOK();
+ this.dispose();
+ //}
}//GEN-LAST:event_jButtonOKActionPerformed
private boolean restorePosition() {
- Point locationPoint = getLocationOnScreen(); //TODO: IllegalComponentStateException
+ Point locationPoint;
+ if ( isVisible() ) {
+ locationPoint = getLocationOnScreen(); //TODO: IllegalComponentStateException
+ } else {
+ locationPoint = new Point(ApplicationProperties.getConfirmDialogPosX(),
+ ApplicationProperties.getConfirmDialogPosY());
+ }
int x = locationPoint.x;
int y = locationPoint.y;
int h = this.getHeight();
protected void setUp() throws Exception {
}
-
+
/**
* Test of main method, of class org.jent.checksmtp.ToListUI.
+ *
+ * public void testMain() {
+ * System.out.println("main");
+ *
+ * String[] args = null;
+ *
+ * //ToListUI.main(args);
+ *
+ * // review the generated test code and remove the default call to fail.
+ * //fail("The test case is a prototype.");
+ *
+ * }
*/
- public void testMain() {
- System.out.println("main");
-
- String[] args = null;
-
- //ToListUI.main(args);
-
- // review the generated test code and remove the default call to fail.
- //fail("The test case is a prototype.");
-
- }
private void pushTestSetup(String msg) {
arrayList.add(msg);
}
public void sayOK() {
+ System.out.println("sayOK");
result = true;
notifyResult();
}
public void sayNG() {
+ System.out.println("sayNG");
result = false;
notifyResult();
}
-
+
public void testPushOK() {
+ result = false;
pushTestSetup("Please push OK button.");
assertTrue("Time out or push CANCEL", result);
}
public void testPushCANCEL() {
+ result = true;
pushTestSetup("Please push CANCEL button.");
assertTrue("Time out or push OK", !result);
}
public void testPushClose() {
+ result = true;
pushTestSetup("Please close Window.");
assertTrue("Time out or push OK", !result);
}
+ public void testPushCancelAfterTimeOut() {
+ ApplicationProperties.setConfirmTimeout(5);
+
+ result = true;
+ pushTestSetup("Test Confirm Timeout 5sec. Please push CANCEL button.");
+ assertTrue("Time out or push OK", !result);
+ try {
+ System.out.println("Wait 10sec.");
+ synchronized(this) {
+ wait(10 * 1000);
+ }
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ fail("Wait Interrupted.");
+ }
+ assertTrue("Confirm Timeout Occurred wrong.", !result);
+
+ }
+
}