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 tassel Show documentation
Show all versions of tassel Show documentation
TASSEL is a software package to evaluate traits associations, evolutionary patterns, and linkage
disequilibrium.
/*
* DialogUtils.java
*
* Created on April 17, 2006
*/
package net.maizegenetics.gui;
import org.apache.log4j.Logger;
import javax.swing.*;
import java.awt.*;
/**
* @author Terry Casstevens
*/
public class DialogUtils {
private static final Logger myLogger = Logger.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 {
SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(parent, getErrorMessage(str), "Warning", JOptionPane.WARNING_MESSAGE));
}
}
public static void showError(String str, Component parent) {
if (parent == null) {
myLogger.error(str);
} else {
SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(parent, getErrorMessage(str), "Error", JOptionPane.ERROR_MESSAGE));
}
}
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();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy