Skip to content

Commit

Permalink
html message removal #65
Browse files Browse the repository at this point in the history
  • Loading branch information
rbouckaert committed Jun 4, 2024
1 parent 627864a commit 4a84ff2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/beastfx/app/util/Alert.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@


import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.StringReader;
import java.util.Optional;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import beast.base.core.BEASTInterface;
import beastfx.app.beauti.ThemeProvider;
Expand Down Expand Up @@ -77,6 +85,7 @@ public class Alert {
public static final AlertType PLAIN_MESSAGE = AlertType.NONE;

public static void showMessageDialog(Parent parent, String message) {
message = removeHTML(message);
javafx.scene.control.Alert alert = new javafx.scene.control.Alert(AlertType.INFORMATION,
message,
ButtonType.OK);
Expand All @@ -94,6 +103,7 @@ public static ButtonType showConfirmDialog(Parent parent, String message, String
javafx.scene.control.Alert alert = new javafx.scene.control.Alert(AlertType.CONFIRMATION,
message,
yesNoCancelOption);
message = removeHTML(message);
alert.setHeaderText(header);
if (parent != null) {
Scene node = parent.getScene();
Expand All @@ -105,12 +115,8 @@ public static ButtonType showConfirmDialog(Parent parent, String message, String
return option.get();
}

public static void showMessageDialog(Pane frame, Pane scroller) {
// TODO Auto-generated method stub

}

public static void showMessageDialog(Parent parent, String message, String header, AlertType informationMessage) {
message = removeHTML(message);
javafx.scene.control.Alert alert = new javafx.scene.control.Alert(informationMessage,
message,
ButtonType.OK);
Expand Down Expand Up @@ -177,6 +183,22 @@ public static void showMessageDialog(Parent parent, Node message, String header,
alert.showAndWait();
}

private static String removeHTML(String html) {
String original = html;
html = html.replaceAll("<br>", "\n");
html = html.replaceAll("<br/>", "\n");
html = "<tag>" + html + "<tag>";
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Document doc;
try {
doc = factory.newDocumentBuilder().parse(new InputSource(new StringReader(html)));
} catch (SAXException | IOException | ParserConfigurationException e) {
return original;
}
String text = doc.getTextContent();
return text;
}

public static Object showInputDialog(Parent parent,
Object message, String title, AlertType messageType, Icon icon,
Object[] selectionValues, Object initialSelectionValue) {
Expand Down
5 changes: 5 additions & 0 deletions src/beastfx/app/util/FXUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ public static void createHMCButton(Pane pane, BEASTInterface o, Input<?> input)
}

String id = o.getID();
if (id == null) {
// cannot identify BEAST object, so there is no way to
// identify a suitable HMC page
return;
}
if (id.lastIndexOf('.') > 0) {
id = id.substring(0, id.lastIndexOf('.'));
}
Expand Down

0 comments on commit 4a84ff2

Please sign in to comment.