Browse Source

Use default RequestProcessor instead of Timer

Toni Helenius 3 years ago
parent
commit
88c6a84f28
1 changed files with 11 additions and 16 deletions
  1. 11 16
      jme3-core/src/com/jme3/gde/core/util/notify/NotifyUtil.java

+ 11 - 16
jme3-core/src/com/jme3/gde/core/util/notify/NotifyUtil.java

@@ -1,22 +1,22 @@
 /*
  * Copyright (c) 2003-2012 jMonkeyEngine
  * All rights reserved.
- * 
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
  * met:
- * 
+ *
  * * Redistributions of source code must retain the above copyright
  *   notice, this list of conditions and the following disclaimer.
- * 
+ *
  * * Redistributions in binary form must reproduce the above copyright
  *   notice, this list of conditions and the following disclaimer in the
  *   documentation and/or other materials provided with the distribution.
- * 
+ *
  * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
  *   may be used to endorse or promote products derived from this software
  *   without specific prior written permission.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
@@ -35,11 +35,11 @@ import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.io.PrintWriter;
 import java.io.StringWriter;
-import javax.swing.Timer;
 import org.openide.DialogDisplayer;
 import org.openide.NotifyDescriptor;
 import org.openide.awt.Notification;
 import org.openide.awt.NotificationDisplayer;
+import org.openide.util.RequestProcessor;
 
 /**
  *
@@ -60,19 +60,14 @@ public class NotifyUtil {
         if (title == null) {
             title = "null";
         }
-        final Notification n = (Notification) NotificationDisplayer.getDefault().notify(title, type.getIcon(), message, actionListener);
+        final Notification n = NotificationDisplayer.getDefault().notify(title, type.getIcon(), message, actionListener);
         if (timeout > 0) {
-            java.awt.EventQueue.invokeLater(new Runnable() {
+            RequestProcessor.getDefault().post(new Runnable() {
+                @Override
                 public void run() {
-                    Timer timer = new Timer(timeout, new ActionListener() {
-                        public void actionPerformed(ActionEvent e) {
-                            n.clear();
-                        }
-                    });
-                    timer.setRepeats(false);
-                    timer.start();
+                    n.clear();
                 }
-            });
+            }, timeout);
         }
         return n;
     }