- add NotifyUtil / MessageUtil to display "Bubble" messages git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10251 75d07b2b-3a1a-0410-a2c5-0572b91ccdca3.0
parent
d138668ce4
commit
94da7c8190
@ -0,0 +1,67 @@ |
|||||||
|
/* |
||||||
|
* 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 |
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
||||||
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
||||||
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
||||||
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||||
|
*/ |
||||||
|
package com.jme3.gde.core.util.notify; |
||||||
|
|
||||||
|
import com.jme3.gde.core.icons.IconList; |
||||||
|
import java.net.URL; |
||||||
|
import javax.swing.Icon; |
||||||
|
import javax.swing.ImageIcon; |
||||||
|
import org.openide.NotifyDescriptor; |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* @author qbeukes.blogspot.com, used by metalklesk |
||||||
|
*/ |
||||||
|
public enum MessageType { |
||||||
|
|
||||||
|
PLAIN(NotifyDescriptor.PLAIN_MESSAGE, IconList.chimpSmile), |
||||||
|
INFO(NotifyDescriptor.INFORMATION_MESSAGE, IconList.chimpSmile), |
||||||
|
QUESTION(NotifyDescriptor.QUESTION_MESSAGE, IconList.chimpConfused), |
||||||
|
EXCEPTION(NotifyDescriptor.ERROR_MESSAGE, IconList.chimpLobo), |
||||||
|
ERROR(NotifyDescriptor.ERROR_MESSAGE, IconList.chimpSad), |
||||||
|
WARNING(NotifyDescriptor.WARNING_MESSAGE, IconList.chimpNogood); |
||||||
|
private int notifyDescriptorType; |
||||||
|
private Icon icon; |
||||||
|
|
||||||
|
private MessageType(int notifyDescriptorType, ImageIcon icon) { |
||||||
|
this.notifyDescriptorType = notifyDescriptorType; |
||||||
|
this.icon = icon; |
||||||
|
} |
||||||
|
|
||||||
|
int getNotifyDescriptorType() { |
||||||
|
return notifyDescriptorType; |
||||||
|
} |
||||||
|
|
||||||
|
Icon getIcon() { |
||||||
|
return icon; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,121 @@ |
|||||||
|
/* |
||||||
|
* 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 |
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
||||||
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
||||||
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
||||||
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||||
|
*/ |
||||||
|
package com.jme3.gde.core.util.notify; |
||||||
|
|
||||||
|
import org.openide.DialogDisplayer; |
||||||
|
import org.openide.NotifyDescriptor; |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* @author qbeukes.blogspot.com, used by metalklesk |
||||||
|
*/ |
||||||
|
public class MessageUtil { |
||||||
|
|
||||||
|
private MessageUtil() {} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return The dialog displayer used to show message boxes |
||||||
|
*/ |
||||||
|
public static DialogDisplayer getDialogDisplayer() { |
||||||
|
return DialogDisplayer.getDefault(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Show a message of the specified type |
||||||
|
* |
||||||
|
* @param message |
||||||
|
* @param messageType As in {@link NotifyDescription} message type constants. |
||||||
|
*/ |
||||||
|
public static void show(String message, MessageType messageType) { |
||||||
|
getDialogDisplayer().notify(new NotifyDescriptor.Message(message, |
||||||
|
messageType.getNotifyDescriptorType())); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Show an exception message dialog |
||||||
|
* |
||||||
|
* @param message |
||||||
|
* @param exception |
||||||
|
*/ |
||||||
|
public static void showException(String message, Throwable exception) { |
||||||
|
getDialogDisplayer().notify(new NotifyDescriptor.Exception(exception, message)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Show an information dialog |
||||||
|
* @param message |
||||||
|
*/ |
||||||
|
public static void info(String message) { |
||||||
|
show(message, MessageType.INFO); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Show an error dialog |
||||||
|
* @param message |
||||||
|
*/ |
||||||
|
public static void error(String message) { |
||||||
|
show(message, MessageType.ERROR); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Show an error dialog for an exception |
||||||
|
* @param message |
||||||
|
* @param exception |
||||||
|
*/ |
||||||
|
public static void error(String message, Throwable exception) { |
||||||
|
showException(message, exception); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Show an question dialog |
||||||
|
* @param message |
||||||
|
*/ |
||||||
|
public static void question(String message) { |
||||||
|
show(message, MessageType.QUESTION); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Show an warning dialog |
||||||
|
* @param message |
||||||
|
*/ |
||||||
|
public static void warn(String message) { |
||||||
|
show(message, MessageType.WARNING); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Show an plain dialog |
||||||
|
* @param message |
||||||
|
*/ |
||||||
|
public static void plain(String message) { |
||||||
|
show(message, MessageType.PLAIN); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,137 @@ |
|||||||
|
/* |
||||||
|
* 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 |
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
||||||
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
||||||
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
||||||
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||||
|
*/ |
||||||
|
package com.jme3.gde.core.util.notify; |
||||||
|
|
||||||
|
import java.awt.event.ActionEvent; |
||||||
|
import java.awt.event.ActionListener; |
||||||
|
import org.openide.awt.Notification; |
||||||
|
import org.openide.awt.NotificationDisplayer; |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* @author qbeukes.blogspot.com, used by metalklesk |
||||||
|
*/ |
||||||
|
public class NotifyUtil { |
||||||
|
|
||||||
|
private NotifyUtil() { |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Show message with the specified type and action listener |
||||||
|
*/ |
||||||
|
public static void show(String title, String message, MessageType type, ActionListener actionListener, boolean clear) { |
||||||
|
Notification n = (Notification) NotificationDisplayer.getDefault().notify(title, type.getIcon(), message, actionListener); |
||||||
|
if (clear == true) { |
||||||
|
n.clear(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Show message with the specified type and a default action which displays |
||||||
|
* the message using {@link MessageUtil} with the same message type |
||||||
|
*/ |
||||||
|
public static void show(String title, final String message, final MessageType type, boolean clear) { |
||||||
|
ActionListener actionListener = new ActionListener() { |
||||||
|
@Override |
||||||
|
public void actionPerformed(ActionEvent e) { |
||||||
|
MessageUtil.show(message, type); |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
show(title, message, type, actionListener, clear); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Show an information notification |
||||||
|
* @param message |
||||||
|
*/ |
||||||
|
public static void info(String title, String message) { |
||||||
|
error(title, message, true); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Show an information notification |
||||||
|
* @param message |
||||||
|
*/ |
||||||
|
public static void info(String title, String message, boolean clear) { |
||||||
|
show(title, message, MessageType.INFO, clear); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Show an exception |
||||||
|
* @param exception |
||||||
|
*/ |
||||||
|
public static void error(Throwable exception) { |
||||||
|
error("Exception in SDK!", exception.getMessage(), exception, true); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Show an error notification |
||||||
|
* @param message |
||||||
|
*/ |
||||||
|
public static void error(String title, String message, boolean clear) { |
||||||
|
show(title, message, MessageType.ERROR, clear); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Show an error notification for an exception |
||||||
|
* @param message |
||||||
|
* @param exception |
||||||
|
*/ |
||||||
|
public static void error(String title, final String message, final Throwable exception, boolean clear) { |
||||||
|
ActionListener actionListener = new ActionListener() { |
||||||
|
@Override |
||||||
|
public void actionPerformed(ActionEvent e) { |
||||||
|
// ErrorManager.getDefault().notify(exception);
|
||||||
|
MessageUtil.showException(message, exception); |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
show(title, message, MessageType.EXCEPTION, actionListener, clear); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Show an warning notification |
||||||
|
* @param message |
||||||
|
*/ |
||||||
|
public static void warn(String title, String message, boolean clear) { |
||||||
|
show(title, message, MessageType.WARNING, clear); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Show an plain notification |
||||||
|
* @param message |
||||||
|
*/ |
||||||
|
public static void plain(String title, String message, boolean clear) { |
||||||
|
show(title, message, MessageType.PLAIN, clear); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue