Merge pull request #119 from kwando/better_error_dialog
SDK: A better error dialog.
This commit is contained in:
commit
f6f13d5f1d
65
jme3-desktop/src/main/java/com/jme3/system/ErrorDialog.java
Normal file
65
jme3-desktop/src/main/java/com/jme3/system/ErrorDialog.java
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
package com.jme3.system;
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Container;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Insets;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import javax.swing.AbstractAction;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JDialog;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.JTextArea;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple dialog for diplaying error messages,
|
||||||
|
*
|
||||||
|
* @author kwando
|
||||||
|
*/
|
||||||
|
public class ErrorDialog extends JDialog {
|
||||||
|
public static String DEFAULT_TITLE = "Error in application";
|
||||||
|
public static int PADDING = 8;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Dialog with a title and a message.
|
||||||
|
* @param message
|
||||||
|
* @param title
|
||||||
|
*/
|
||||||
|
public ErrorDialog(String message, String title) {
|
||||||
|
setTitle(title);
|
||||||
|
setSize(new Dimension(600, 400));
|
||||||
|
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||||
|
setLocationRelativeTo(null);
|
||||||
|
|
||||||
|
Container container = getContentPane();
|
||||||
|
container.setLayout(new BorderLayout());
|
||||||
|
|
||||||
|
JTextArea textArea = new JTextArea();
|
||||||
|
textArea.setText(message);
|
||||||
|
textArea.setEditable(false);
|
||||||
|
textArea.setMargin(new Insets(PADDING, PADDING, PADDING, PADDING));
|
||||||
|
add(new JScrollPane(textArea), BorderLayout.CENTER);
|
||||||
|
|
||||||
|
final JDialog dialog = this;
|
||||||
|
JButton button = new JButton(new AbstractAction("OK"){
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
dialog.dispose();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
add(button, BorderLayout.SOUTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorDialog(String message){
|
||||||
|
this(message, DEFAULT_TITLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show a dialog with the proved message.
|
||||||
|
* @param message
|
||||||
|
*/
|
||||||
|
public static void showDialog(String message){
|
||||||
|
ErrorDialog dialog = new ErrorDialog("Opps, this was bad =S");
|
||||||
|
dialog.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -52,7 +52,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -87,10 +86,9 @@ public class JmeDesktopSystem extends JmeSystemDelegate {
|
|||||||
@Override
|
@Override
|
||||||
public void showErrorDialog(String message) {
|
public void showErrorDialog(String message) {
|
||||||
final String msg = message;
|
final String msg = message;
|
||||||
final String title = "Error in application";
|
|
||||||
EventQueue.invokeLater(new Runnable() {
|
EventQueue.invokeLater(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
JOptionPane.showMessageDialog(null, msg, title, JOptionPane.ERROR_MESSAGE);
|
ErrorDialog.showDialog(msg);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user