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