net.maizegenetics.gui.DialogUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tassel6 Show documentation
Show all versions of tassel6 Show documentation
TASSEL 6 is a software package to evaluate traits association. Feature Tables are at the heart of the package where, a feature is a range of positions or a single position. Row in the that table are taxon.
/*
* DialogUtils.java
*
* Created on April 17, 2006
*/
package net.maizegenetics.gui;
import net.maizegenetics.util.ExceptionUtils;
import net.maizegenetics.util.Utils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javax.swing.*;
import java.awt.*;
/**
* @author Terry Casstevens
*/
public class DialogUtils {
private static final Logger myLogger = LogManager.getLogger(DialogUtils.class);
private static final int DEFAULT_MESSAGE_LINE_LENGTH = 50;
private DialogUtils() {
}
public static void showWarning(String str, Component parent) {
if (parent == null) {
myLogger.warn(str);
} else {
JOptionPane.showMessageDialog(parent, getErrorMessage(str), "Warning", JOptionPane.WARNING_MESSAGE);
}
}
public static void showError(String str, Component parent) {
if (parent == null) {
myLogger.error(str);
} else {
JOptionPane.showMessageDialog(parent, getErrorMessage(str), "Error", JOptionPane.ERROR_MESSAGE);
}
}
public static void showError(Throwable e, Component parent) {
String str = Utils.shortenStrLineLen(ExceptionUtils.getExceptionCauses(e), 50, 7);
if (parent == null) {
myLogger.error(str);
} else {
JOptionPane.showMessageDialog(parent, getErrorMessage(str), "Error", JOptionPane.ERROR_MESSAGE);
}
}
public static void showErrorCause(Throwable e, Component parent) {
Throwable temp = e.getCause();
if (temp != null) {
showError(temp, parent);
} else {
showError(e, parent);
}
}
private static String getErrorMessage(String message) {
if (message.length() <= DEFAULT_MESSAGE_LINE_LENGTH) {
return message;
}
int count = 0;
StringBuilder builder = new StringBuilder();
builder.append("");
for (int i = 0, n = message.length(); i < n; i++) {
count++;
if (message.charAt(i) == '\n') {
builder.append("
");
count = 0;
} else if ((count > DEFAULT_MESSAGE_LINE_LENGTH) && (message.charAt(i) == ' ')) {
builder.append("
");
count = 0;
} else {
builder.append(message.charAt(i));
}
}
builder.append("");
return builder.toString();
}
}