Fixed reading LICENSE.txt for about information.

This commit is contained in:
neviyn 2016-03-15 00:53:12 +00:00
parent 5eb3446416
commit 4a6cc6f563

View File

@ -27,12 +27,12 @@ import java.awt.event.ItemEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
@ -503,22 +503,21 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
JMenu helpMenu = new JMenu("Help");
menuItem = new JMenuItem("About");
menuItem.addActionListener(e -> {
try {
//noinspection ConstantConditions
JEditorPane messagePane = new JEditorPane("text/html", Files.readAllLines(
Paths.get(PlayerGUI.class.getClassLoader().getResource("LICENSE.txt").toURI())).get(0));
try(BufferedReader reader = new BufferedReader(new InputStreamReader(PlayerGUI.class.getClassLoader().getResourceAsStream("LICENSE.txt")))) {
JEditorPane messagePane = new JEditorPane("text/html", reader.lines().collect(Collectors.toList()).get(0));
messagePane.setEditable(false);
messagePane.addHyperlinkListener(hl -> {
messagePane.addHyperlinkListener(hl ->
{
if (hl.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
if(Desktop.isDesktopSupported())
if (Desktop.isDesktopSupported())
try {
Desktop.getDesktop().browse(hl.getURL().toURI());
} catch (IOException | URISyntaxException e1) {
e1.printStackTrace();
}
});
JOptionPane.showMessageDialog(mainPanel, messagePane, "About", JOptionPane.INFORMATION_MESSAGE);
} catch (IOException | URISyntaxException e1) {
JOptionPane.showMessageDialog(mainPanel,messagePane,"About",JOptionPane.INFORMATION_MESSAGE);
} catch (IOException e1) {
e1.printStackTrace();
}
});