Skip to content

Commit

Permalink
Fixed pom, fixed about text, refactored hyperlink listener
Browse files Browse the repository at this point in the history
  • Loading branch information
zaplatynski committed Apr 25, 2016
1 parent 3dcaf0a commit e73041a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 25 deletions.
12 changes: 5 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>de.marza.firstspirit.modules</groupId>
<artifactId>the-second-hand-log</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
<packaging>jar</packaging>
<name>The Second-Hand Log</name>

Expand Down Expand Up @@ -33,6 +33,7 @@
<filtering>true</filtering>
<includes>
<include>**/*.xml</include>
<include>**/*.txt</include>
</includes>
</resource>
<resource>
Expand Down Expand Up @@ -79,7 +80,7 @@
<version>2.6</version>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptor>${project.build.sourceDirectory}/main/assemblies/fsm.xml</descriptor>
<descriptor>src/main/assemblies/fsm.xml</descriptor>
</configuration>
<executions>
<execution>
Expand All @@ -104,11 +105,8 @@
<goal>rename</goal>
</goals>
<configuration>
<sourceFile>${project.build.outputDirectory}/${project.artifactId}-${project.version}.zip
</sourceFile>
<destinationFile>
${project.build.outputDirectory}/${project.artifactId}-${project.version}.fsm
</destinationFile>
<sourceFile>target/${project.artifactId}-${project.version}.zip</sourceFile>
<destinationFile>target/${project.artifactId}-${project.version}.fsm</destinationFile>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package de.marza.firstspirit.modules.logging.console;

import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import java.awt.*;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

public class HyperlinkExecutor implements HyperlinkListener {

@Override
public void hyperlinkUpdate(final HyperlinkEvent e) {
URI uri = null;
try {
uri = e.getURL().toURI();
} catch (final URISyntaxException exception) {
System.err.println("An error occurred while retrieving URI:" + exception.toString());
exception.printStackTrace(System.err);
}
browseTo(e, uri);
}

private void browseTo(final HyperlinkEvent e, final URI uri) {
if (uri != null && Desktop.isDesktopSupported() && isClicked(e)) {
try {
Desktop.getDesktop().browse(uri);
} catch (final IOException exception) {
System.err.println("An error occurred while browse to '" + uri.toString() + "':" + exception.toString());
exception.printStackTrace(System.err);
}
}
}

private static boolean isClicked(final HyperlinkEvent e) {
return e.getEventType() == HyperlinkEvent.EventType.ACTIVATED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URISyntaxException;


public class MenuController implements Runnable {
Expand Down Expand Up @@ -40,7 +37,6 @@ public void run() {
private JEditorPane readAboutText() {
JEditorPane message = null;


try (final BufferedReader txtReader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/about.txt")))) {
String line;
final StringBuilder sb = new StringBuilder();
Expand All @@ -51,23 +47,12 @@ private JEditorPane readAboutText() {
message.setEditable(false);
final Color backgrounfdColor = UIManager.getColor("Panel.background");
message.setBackground(backgrounfdColor);
message.addHyperlinkListener(new HyperlinkListener() {
@Override
public void hyperlinkUpdate(final HyperlinkEvent e) {
if (Desktop.isDesktopSupported() && e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
try {
Desktop.getDesktop().browse(e.getURL().toURI());
} catch (final IOException | URISyntaxException exception) {
System.err.println("An error occurred while reading the about text:" + exception.toString());
exception.printStackTrace(System.err);
}
}
}
});
message.addHyperlinkListener(new HyperlinkExecutor());
} catch (final IOException exception) {
System.err.println("An error occurred while reading the about text:" + exception.toString());
exception.printStackTrace(System.err);
}
return message;
}

}
3 changes: 2 additions & 1 deletion src/main/resources/about.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<html>
<h1>The Second-Hand Log</h2>
<h1>The Second-Hand Log version ${project.version}</h2>
<p>
<a href="https://github.com/zaplatynski/second-hand-log">Fork me on GitHub!</a>
</p>
<p>
Please file any <a href="https://github.com/zaplatynski/second-hand-log/issues">issues like bugs or feature requests</a> at GitHub. Thanks!
</p>
<br>
</html>

0 comments on commit e73041a

Please sign in to comment.