Skip to content

Commit

Permalink
Fixed DNA log and About window
Browse files Browse the repository at this point in the history
  • Loading branch information
leifeld committed May 5, 2023
1 parent 554ba8d commit 4c3b110
Show file tree
Hide file tree
Showing 15 changed files with 1,055 additions and 348 deletions.
2 changes: 1 addition & 1 deletion dna/src/main/java/dna/Dna.java
Expand Up @@ -27,7 +27,7 @@ public class Dna {
public static Dna dna;
public static Logger logger;
public static Sql sql;
public static final String date = "2023-05-04";
public static final String date = "2023-05-05";
public static final String version = "3.1.0";
public static final String operatingSystem = System.getProperty("os.name");
public static File workingDirectory = null;
Expand Down
87 changes: 39 additions & 48 deletions dna/src/main/java/gui/AboutWindow.java
@@ -1,14 +1,11 @@
package gui;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.URISyntaxException;

import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;

import dna.Dna;
import logger.LogEvent;
Expand All @@ -32,12 +29,12 @@ public class AboutWindow extends JDialog {
*/
public AboutWindow(String version, String date) {
this.setTitle("About DNA");
ImageIcon dna32Icon = new ImageIcon(getClass().getResource("/icons/dna32.png"));
this.setIconImage(dna32Icon.getImage());
ImageIcon dnaSmallIcon = new SvgIcon("/icons/dna.svg", 32).getImageIcon();
this.setIconImage(dnaSmallIcon.getImage());
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
aboutContents = new JPanel(new BorderLayout());

Icon dnaTextIcon = new ImageIcon(getClass().getResource("/icons/dna128.png"));
ImageIcon dnaTextIcon = new SvgIcon("/icons/dna.svg", 96).getImageIcon();
JLabel dnaIcon = new JLabel(dnaTextIcon);
JPanel dnaIconPanel = new JPanel(new FlowLayout());
dnaIconPanel.add(dnaIcon);
Expand All @@ -46,61 +43,55 @@ public AboutWindow(String version, String date) {
aboutText = new JEditorPane();
aboutText.setEditorKit(JEditorPane.createEditorKitForContentType("text/html"));
aboutText.setEditable(false);
aboutText.setText("<p><b>Current version</b><br>" + version + " (" + date + ")</p>"
+ "<p><b>DNA project homepage</b><br>"
aboutText.setText("<p><b>Current version</b><br/>" + version + " (" + date + ")</p>"
+ "<p><b>DNA project homepage</b><br/>"
+ "Documentation, source code, publications, a forum, and a bug tracker can be found "
+ "here: <a href=\"http://github.com/leifeld/dna/\">http://github.com/leifeld/dna/</a>.</p>"
+ "<p><b>Icons</b><br> taken from <a href=\"https://tabler-icons.io/\">"
+ "https://tabler-icons.io/</a> (MIT license).</p>"
+ "<p><b>JRI</b><br>To display output in R, this software project uses JRI by Simon Urbanek (under LGPL license), "
+ "<p><b>Icons</b><br/> from <a href=\"https://tabler-icons.io/\">"
+ "https://tabler-icons.io/</a> (MIT license) <br/> "
+ "and <a href=\"https://fonts.google.com/icons/\">https://fonts.google.com/icons/</a> (Apache License 2.0)</p>"
+ "<p><b>JRI</b><br/>To display output in R, this software project uses JRI by Simon Urbanek (under LGPL license), "
+ "which can be downloaded at <a href=\"https://github.com/s-u/rJava\">https://github.com/s-u/rJava</a>.</p>"
);
aboutText.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent e) {
if(e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
if(Desktop.isDesktopSupported()) {
try {
Desktop.getDesktop().browse(e.getURL().toURI());
LogEvent l = new LogEvent(Logger.MESSAGE,
"[GUI] URL in About DNA window opened.",
"A link from the About DNA window was successfully opened in a browser.");
Dna.logger.log(l);
} catch (UnsupportedOperationException e1) {
LogEvent l = new LogEvent(Logger.WARNING,
"[GUI] URL in About DNA window could not be opened.",
"On some operating systems (notably Linux), Java does not support opening URLs by clicking on a hyperlink, such as the one in the About DNA window. The link you clicked on was not opened.",
e1);
Dna.logger.log(l);
} catch (IOException e1) {
LogEvent l = new LogEvent(Logger.WARNING,
"[GUI] URL in About DNA window could not be opened.",
"An input-output exception occurred when you tried to click on a link in the About DNA window. The link was not opened in a browser.",
e1);
Dna.logger.log(l);
} catch (URISyntaxException e1) {
LogEvent l = new LogEvent(Logger.WARNING,
"[GUI] URL in About DNA window could not be opened.",
"A URI syntax exception occurred when you tried to click on a link in the About DNA window. Something must have been wrong with the URL you clicked on; perhaps a bug in the code? The link was not opened in a browser.",
e1);
Dna.logger.log(l);
}
aboutText.addHyperlinkListener(e -> {
if(e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
if(Desktop.isDesktopSupported()) {
try {
Desktop.getDesktop().browse(e.getURL().toURI());
LogEvent l = new LogEvent(Logger.MESSAGE,
"[GUI] URL in About DNA window opened.",
"A link from the About DNA window was successfully opened in a browser.");
Dna.logger.log(l);
} catch (UnsupportedOperationException e1) {
LogEvent l = new LogEvent(Logger.WARNING,
"[GUI] URL in About DNA window could not be opened.",
"On some operating systems (notably Linux), Java does not support opening URLs by clicking on a hyperlink, such as the one in the About DNA window. The link you clicked on was not opened.",
e1);
Dna.logger.log(l);
} catch (IOException e1) {
LogEvent l = new LogEvent(Logger.WARNING,
"[GUI] URL in About DNA window could not be opened.",
"An input-output exception occurred when you tried to click on a link in the About DNA window. The link was not opened in a browser.",
e1);
Dna.logger.log(l);
} catch (URISyntaxException e1) {
LogEvent l = new LogEvent(Logger.WARNING,
"[GUI] URL in About DNA window could not be opened.",
"A URI syntax exception occurred when you tried to click on a link in the About DNA window. Something must have been wrong with the URL you clicked on; perhaps a bug in the code? The link was not opened in a browser.",
e1);
Dna.logger.log(l);
}
}
}
});
aboutScrollPane = new JScrollPane(aboutText);
aboutScrollPane.setPreferredSize(new Dimension(500, 270));
aboutScrollPane.setPreferredSize(new Dimension(500, 310));
aboutContents.add(aboutScrollPane, BorderLayout.CENTER);

// close button at the bottom of the window
ImageIcon closeIcon = new ImageIcon(new ImageIcon(getClass().getResource("/icons/tabler-icon-x.png")).getImage().getScaledInstance(18, 18, Image.SCALE_SMOOTH));
ImageIcon closeIcon = new SvgIcon("/icons/google_close.svg", 14).getImageIcon();
JButton closeButton = new JButton("Close", closeIcon);
closeButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
dispose();
}
});
closeButton.addActionListener(al -> dispose());
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
buttonPanel.add(closeButton);
aboutContents.add(buttonPanel, BorderLayout.SOUTH);
Expand Down
16 changes: 6 additions & 10 deletions dna/src/main/java/gui/MainWindow.java
Expand Up @@ -9,6 +9,7 @@
import java.awt.Rectangle;
import java.awt.event.*;
import java.awt.geom.Rectangle2D;
import java.awt.image.BaseMultiResolutionImage;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
Expand Down Expand Up @@ -132,15 +133,9 @@ public MainWindow() {
c = getContentPane();
this.setTitle("Discourse Network Analyzer");
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

List<Image> dnaIcons = new ArrayList<Image>();
dnaIcons.add(new ImageIcon(Objects.requireNonNull(getClass().getResource("/icons/dna512.png"))).getImage());
dnaIcons.add(new ImageIcon(Objects.requireNonNull(getClass().getResource("/icons/dna256.png"))).getImage());
dnaIcons.add(new ImageIcon(Objects.requireNonNull(getClass().getResource("/icons/dna128.png"))).getImage());
dnaIcons.add(new ImageIcon(Objects.requireNonNull(getClass().getResource("/icons/dna64.png"))).getImage());
dnaIcons.add(new ImageIcon(Objects.requireNonNull(getClass().getResource("/icons/dna32.png"))).getImage());
dnaIcons.add(new ImageIcon(Objects.requireNonNull(getClass().getResource("/icons/dna16.png"))).getImage());
this.setIconImages(dnaIcons);

BaseMultiResolutionImage dnaIcon = new SvgIcon("/icons/dna.svg", 16).getImage();
this.setIconImage(dnaIcon);

// close SQL connection before exit
this.addWindowListener(new WindowAdapter() {
Expand Down Expand Up @@ -249,7 +244,8 @@ public void windowClosing(WindowEvent e) {
ImageIcon loggerIcon = new ImageIcon(new ImageIcon(Objects.requireNonNull(getClass().getResource("/icons/tabler-icon-bug.png"))).getImage().getScaledInstance(18, 18, Image.SCALE_SMOOTH));
actionLoggerDialog = new ActionLoggerDialog("Display message log", loggerIcon, "Display a log of messages, warnings, and errors in a dialog window", KeyEvent.VK_L);

ImageIcon aboutIcon = new ImageIcon(new ImageIcon(Objects.requireNonNull(getClass().getResource("/icons/dna32.png"))).getImage().getScaledInstance(18, 18, Image.SCALE_SMOOTH));
// ImageIcon aboutIcon = new ImageIcon(new ImageIcon(Objects.requireNonNull(getClass().getResource("/icons/dna32.png"))).getImage().getScaledInstance(18, 18, Image.SCALE_SMOOTH));
ImageIcon aboutIcon = new SvgIcon("/icons/dna.svg", 18).getImageIcon();
actionAboutWindow = new ActionAboutWindow("About DNA", aboutIcon, "Display information about DNA", KeyEvent.VK_B);

// define models
Expand Down
4 changes: 4 additions & 0 deletions dna/src/main/java/gui/SvgIcon.java
Expand Up @@ -27,6 +27,10 @@ public ImageIcon getImageIcon() {
return new ImageIcon(this.b);
}

public BaseMultiResolutionImage getImage() {
return b;
}

private BaseMultiResolutionImage createMultiImage(String svgPath, int baselineSize) {
double[] zoomFactors = {1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5, 2.75, 3.0};
List<BufferedImage> images = new ArrayList<>();
Expand Down

0 comments on commit 4c3b110

Please sign in to comment.