Skip to content

Commit

Permalink
Merge branch 'release/better-text-transform'
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisAcrobat committed Apr 27, 2019
2 parents be60a08 + 46c4866 commit 9a65a40
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -13,7 +13,7 @@ The Live Cipherer is now compatible with the current version of Wolfpack (curren
### Build
Place the project in a directory is called `Wolfpack-Live-Cipherer`. In order to build this project add the following XML-`configuration` to the `RunManager` at `/.idea/workspace.xml`, then [invalidate caches and restart](https://www.jetbrains.com/help/webstorm/cleaning-system-cache.html). Compiled executables are placed in `/build/_dist_/`.
```xml
<configuration name="Main (build)" type="Application" factoryName="Application">
<configuration name="Build" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="se.olofsson.wolfpack.livecipherer.Main" />
<module name="Wolfpack-LiveCipherer" />
<method v="2">
Expand All @@ -33,4 +33,4 @@ Discussions can be held in the [Steam](https://steamcommunity.com/app/490920/dis
# Special thanks
[Submarine Icon](http://www.iconarchive.com/show/beautiful-flat-one-color-icons-by-elegantthemes/submarine-icon.html) made by [Elegantthemes](http://www.iconarchive.com/artist/elegantthemes.html).

![Submarine Icon](https://github.com/ChrisAcrobat/Wolfpack-Live-Cipherer/blob/master/res/submarine-icon.png?raw=true "Submarine Icon")
![Submarine icon by Elegantthemes](https://github.com/ChrisAcrobat/Wolfpack-Live-Cipherer/blob/master/res/submarine-icon.png?raw=true "Submarine Icon by Elegantthemes")
3 changes: 2 additions & 1 deletion build.gradle
Expand Up @@ -3,7 +3,7 @@ plugins {
id 'edu.sc.seis.launch4j' version '2.4.4'
}

version 'v0.3.1'
version 'v0.3.2'

sourceCompatibility = 1.8

Expand Down Expand Up @@ -31,6 +31,7 @@ launch4j {
jar = "$buildDir/artifacts/Wolfpack-LiveCipherer/Wolfpack-LiveCipherer.jar"
icon = "${projectDir}/src/main/resources/Elegantthemes-Beautiful-Flat-One-Color-Submarine.ico"
dontWrapJar = false
cmdLine = "lanuch4j-exe"
}

task createDist(type: Zip){
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/se/olofsson/wolfpack/livecipherer/LiveCipher.java
Expand Up @@ -4,6 +4,10 @@
import com.intellij.uiDesigner.core.GridLayoutManager;

import javax.swing.*;
import javax.swing.text.AbstractDocument;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.DocumentFilter;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
Expand All @@ -25,6 +29,7 @@ public class LiveCipher extends JFrame {
private JSpinner spnRollerRight;
private JCheckBox cbxPrivateKey;
private JMenuBar jMenuBar;
public static final String REGEX_UNSUPPORTED_CHARS = "[^A-Z]";

public LiveCipher() {
setContentPane(pnlRoot);
Expand Down Expand Up @@ -122,6 +127,26 @@ public void mouseExited(MouseEvent e) {
primeWheels(rollerList);
new TextFormatter(roller1, cbxPrivateKey, txtUpper, txtLower).start();

class UppercaseDocumentFilter extends DocumentFilter {
@Override
public void insertString(FilterBypass fb, int offset, String text, AttributeSet attr) throws BadLocationException {
fb.insertString(offset, text.toUpperCase().replaceAll(REGEX_UNSUPPORTED_CHARS, " "), attr);
}

@Override
public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
fb.replace(offset, length, text.toUpperCase().replaceAll(REGEX_UNSUPPORTED_CHARS, " "), attrs);
}
}

UppercaseDocumentFilter uppercaseDocumentFilter = new UppercaseDocumentFilter();

AbstractDocument txtUpperDocument = (AbstractDocument) txtUpper.getDocument();
txtUpperDocument.setDocumentFilter(uppercaseDocumentFilter);

AbstractDocument txtLowerDocument = (AbstractDocument) txtLower.getDocument();
txtLowerDocument.setDocumentFilter(uppercaseDocumentFilter);

// Finalize frame
pack();
setLocationRelativeTo(null);
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/se/olofsson/wolfpack/livecipherer/Main.java
@@ -1,7 +1,9 @@
package se.olofsson.wolfpack.livecipherer;

import javax.swing.*;
import java.io.IOException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.jar.Attributes;
import java.util.jar.Manifest;

Expand All @@ -22,10 +24,11 @@ public static void main(String[] args)
}

new LiveCipher().setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
sendUsageAnalytics(String.join("\n", args));
}

private static String getCurrentVersion(){
// Source (modified): https://stackoverflow.com/a/1273432
// Source by ZZ Coder (modified): https://stackoverflow.com/a/1273432
String currentVersion = null;
try{
Class clazz = Main.class;
Expand All @@ -41,4 +44,14 @@ private static String getCurrentVersion(){
}catch(Exception e){}
return currentVersion;
}

private static void sendUsageAnalytics(String args){
String baseURL = "https://docs.google.com/forms/d/e/1FAIpQLSdDQVz-MDe3pVMWO1VIt_s1c-dibNGUiNra-IpN9FeorLge3A/formResponse?usp=pp_url";
try{
String encodedVersion = URLEncoder.encode(CURRENT_VERSION == null ? "null" : CURRENT_VERSION, "UTF-8");
String encodedArgs = URLEncoder.encode(args, "UTF-8");
String fullUrl = baseURL + "&entry.762130873=" + encodedVersion + "&entry.175483917=" + encodedArgs + "&submit=Submit";
new URL(fullUrl).openConnection().getInputStream();
}catch(IOException e){}
}
}
14 changes: 2 additions & 12 deletions src/main/java/se/olofsson/wolfpack/livecipherer/TextFormatter.java
Expand Up @@ -95,17 +95,7 @@ private void cipher(final JTextArea FROM, final JTextArea TO){
isCipherWorking = true;
SwingUtilities.invokeLater(() -> {
int caretPosition = FROM.getCaretPosition();

String text = FROM.getText().toUpperCase();
FROM.setText(text);

if(text.length() < caretPosition)
{
caretPosition = text.length();
}
FROM.setCaretPosition(caretPosition);

TO.setText(cipherMessage(text));
TO.setText(cipherMessage(FROM.getText()));
TO.setCaretPosition(caretPosition);

first = FIRST.getText();
Expand All @@ -131,7 +121,7 @@ private String cipherMessage(String message){
}else{
cipherMessage += ' ';
}
boolean privateKeyIsValid = cipherMessage.replaceAll("[^A-Z]", "").equals(cipherMessage);
boolean privateKeyIsValid = cipherMessage.replaceAll(LiveCipher.REGEX_UNSUPPORTED_CHARS, "").equals(cipherMessage);
boolean privateKeyIsLength = cipherMessage.length() == 3;
if(privateKeyIsActive && privateKeyIsValid && privateKeyIsLength){
RIGHT_ROLLER.setState(cipherMessage);
Expand Down

0 comments on commit 9a65a40

Please sign in to comment.