Skip to content

Commit

Permalink
Replaces system type from sig ID
Browse files Browse the repository at this point in the history
  • Loading branch information
Afalinko committed Sep 10, 2017
1 parent 6a6936f commit eef4dba
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 11 deletions.
33 changes: 31 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<groupId>com.eve.copilot</groupId>
<artifactId>bookmark</artifactId>
<version>1.0-SNAPSHOT</version>

<packaging>jar</packaging>


Expand All @@ -17,6 +16,27 @@

<build>
<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand All @@ -39,7 +59,8 @@
</excludes>
<archive>
<manifest>
<!-- Jar file entry point -->
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.eve.copilot.Application</mainClass>
</manifest>
</archive>
Expand All @@ -49,4 +70,12 @@
</build>


<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
</dependency>
</dependencies>

</project>
55 changes: 46 additions & 9 deletions src/main/java/com/eve/copilot/Application.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,78 @@
package com.eve.copilot;

import com.google.gson.Gson;

import java.awt.*;
import java.awt.datatransfer.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

public class Application {

private static String bookmarkFromScanLine(String scanLine){
private static String bookmarkFromScanLine(String scanLine) {
if (!scanLine.matches("[A-Z]{3}-[0-9]{3}\t[A-Za-z ]+\t[A-Za-z ]+\t[A-Za-z -0-9]+\t100.0%\t[0-9\\.,]+ [A-Za-z]+$")) {
return null;
}

String[] data_parts = scanLine.split("\t");
char type = data_parts[2].charAt(0);
if (type=='W'){
if (type == 'W') {
return data_parts[0].substring(0, 3) + "-C?-K162";
} else {
return data_parts[0].substring(0, 3) + "-" + data_parts[2].charAt(0) + "-" + data_parts[3];
}
}

private static Map<String, String> loadSigs() {
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
InputStream is = classloader.getResourceAsStream("wh_sig.json");

Gson g = new Gson();
Signature[] sigDb = g.fromJson(new BufferedReader(new InputStreamReader(is)), Signature[].class);
System.out.println("Signatures loaded: " + sigDb.length);
return Arrays.stream(sigDb).collect(Collectors.toMap(o -> o.sig, o -> o.val));
}

private static String expandSig(String scanLine, Map<String, String> sigDB) {
if (!scanLine.matches("[A-Z]{3}-C\\?-[A-Za-z][0-9]+")) {
return null;
}

final String[] data_parts = scanLine.split("-");
if (sigDB.containsKey(data_parts[2])) {
final String val = sigDB.get(data_parts[2]);
return data_parts[0] + "-" + val + "-" + data_parts[2];
}

return null;
}

public static void main(String args[]) throws InterruptedException {
String data = "";
Map<String, String> sigDB = loadSigs();
while (true) {
String clipboardContents = getClipboardContents();
if (!data.equalsIgnoreCase(clipboardContents)) {
data = clipboardContents;

if (!data.contains("\n")) {
final String bookmark = bookmarkFromScanLine(data);
if (bookmark!=null){
if (bookmark != null) {
StringSelection selection = new StringSelection(bookmark);
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, selection);
System.out.println("set: "+bookmark);
System.out.println("set: " + bookmark);
}
final String sigExpansion = expandSig(data, sigDB);
if (sigExpansion != null) {
StringSelection selection = new StringSelection(sigExpansion);
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, selection);
System.out.println("set: " + sigExpansion);
}
}

Expand All @@ -41,7 +81,7 @@ public static void main(String args[]) throws InterruptedException {
}
}

public static String getClipboardContents() {
private static String getClipboardContents() {
String result = "";
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();

Expand All @@ -52,10 +92,7 @@ public static String getClipboardContents() {
if (hasTransferableText) {
try {
result = (String) contents.getTransferData(DataFlavor.stringFlavor);
} catch (UnsupportedFlavorException ex) {
System.out.println(ex);
ex.printStackTrace();
} catch (IOException ex) {
} catch (UnsupportedFlavorException | IOException ex) {
System.out.println(ex);
ex.printStackTrace();
}
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/com/eve/copilot/Signature.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.eve.copilot;

public class Signature {

public String sig;
public String val;

public Signature(String sig, String val) {
this.sig = sig;
this.val = val;
}

public String getSig() {
return sig;
}

public void setSig(String sig) {
this.sig = sig;
}

public String getVal() {
return val;
}

public void setVal(String val) {
this.val = val;
}
}
89 changes: 89 additions & 0 deletions src/main/resources/wh_sig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
[{"sig":"A009", "val":"C13"},
{"sig":"A239", "val":"LS"},
{"sig":"A641", "val":"HS"},
{"sig":"A982", "val":"C6"},
{"sig":"B041", "val":"C6"},
{"sig":"B274", "val":"HS"},
{"sig":"B449", "val":"HS"},
{"sig":"B520", "val":"HS"},
{"sig":"B735", "val":"Barbican"},
{"sig":"C008", "val":"C5"},
{"sig":"C125", "val":"C2"},
{"sig":"C140", "val":"LS"},
{"sig":"C247", "val":"C3"},
{"sig":"C248", "val":"NS"},
{"sig":"C391", "val":"LS"},
{"sig":"C414", "val":"Conflux"},
{"sig":"D364", "val":"C2"},
{"sig":"D382", "val":"C2"},
{"sig":"D792", "val":"HS"},
{"sig":"D845", "val":"HS"},
{"sig":"E004", "val":"C1"},
{"sig":"E175", "val":"C4"},
{"sig":"E545", "val":"NS"},
{"sig":"E587", "val":"NS"},
{"sig":"F135", "val":"Thera"},
{"sig":"F355", "val":"Thera"},
{"sig":"G008", "val":"C6"},
{"sig":"G024", "val":"C2"},
{"sig":"H121", "val":"C1"},
{"sig":"H296", "val":"C5"},
{"sig":"H900", "val":"C5"},
{"sig":"I182", "val":"C2"},
{"sig":"J244", "val":"LS"},
{"sig":"K329", "val":"NS"},
{"sig":"K346", "val":"NS"},
{"sig":"L005", "val":"C2"},
{"sig":"L031", "val":"Thera"},
{"sig":"L477", "val":"C3"},
{"sig":"L614", "val":"C5"},
{"sig":"M001", "val":"C4"},
{"sig":"M164", "val":"Thera"},
{"sig":"M267", "val":"C3"},
{"sig":"M555", "val":"C5"},
{"sig":"M609", "val":"C4"},
{"sig":"N062", "val":"C5"},
{"sig":"N110", "val":"HS"},
{"sig":"N290", "val":"LS"},
{"sig":"N432", "val":"C5"},
{"sig":"N766", "val":"C2"},
{"sig":"N770", "val":"C5"},
{"sig":"N944", "val":"LS"},
{"sig":"N968", "val":"C3"},
{"sig":"O128", "val":"C4"},
{"sig":"O477", "val":"C3"},
{"sig":"O883", "val":"C3"},
{"sig":"P060", "val":"C1"},
{"sig":"Q003", "val":"NS"},
{"sig":"Q063", "val":"HS"},
{"sig":"Q317", "val":"C1"},
{"sig":"R051", "val":"LS"},
{"sig":"R259", "val":"Redoubt"},
{"sig":"R474", "val":"C6"},
{"sig":"R943", "val":"C2"},
{"sig":"S047", "val":"HS"},
{"sig":"S199", "val":"NS"},
{"sig":"S804", "val":"C6"},
{"sig":"S877", "val":"Sentinel"},
{"sig":"T405", "val":"C4"},
{"sig":"T458", "val":"Thera"},
{"sig":"U210", "val":"LS"},
{"sig":"U319", "val":"C6"},
{"sig":"U574", "val":"C6"},
{"sig":"V283", "val":"NS"},
{"sig":"V301", "val":"C1"},
{"sig":"V753", "val":"C6"},
{"sig":"V898", "val":"LS"},
{"sig":"V911", "val":"C5"},
{"sig":"V928", "val":"Vidette"},
{"sig":"W237", "val":"C6"},
{"sig":"X702", "val":"C3"},
{"sig":"X877", "val":"C4"},
{"sig":"Y683", "val":"C4"},
{"sig":"Y790", "val":"C1"},
{"sig":"Z006", "val":"C3"},
{"sig":"Z060", "val":"NS"},
{"sig":"Z142", "val":"NS"},
{"sig":"Z457", "val":"C4"},
{"sig":"Z647", "val":"C1"},
{"sig":"Z971", "val":"C1"}]

0 comments on commit eef4dba

Please sign in to comment.