Skip to content

Commit

Permalink
Changed a lot
Browse files Browse the repository at this point in the history
  • Loading branch information
BeboKhouja committed Jul 1, 2024
1 parent cbda116 commit 266b4cd
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 103 deletions.
1 change: 1 addition & 0 deletions .idea/artifacts/main_jar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/libraries/swt.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions PC Simulator Save Editor.iml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
<orderEntry type="jdk" jdkName="22" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="ChmWeb-0.5.4" level="project" />
<orderEntry type="library" name="swt" level="project" />
</component>
</module>
Binary file modified chmhelp/Program.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions chmhelp/Taking a look at the program.htm
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
<BODY>
Welcome to PC Simulator Save Editor Help. I'll guide you how to use the program. <br><br>

Most help is also available through tooltips.<br><br>

<h1> First step: Taking a look at the program </h1><br>
<img src='Program.png' alt="Program window" style="height:30%" /><br>

The left textbox is where you put your encrypted/decrypted texts to decrypt/encrypt.<br>
The right textbox is where the encrypted/decrypted files get decrypted/encrypted.<br>
The "Copy to clipboard" button copies the output text to the clipboard.<br>
The "Decrypt/Encrypt" button as explained, decrypts/encrypts the input and then outputs it.
Press ENTER on the left textbox to encrypt/decrypt.

<h2>File Menu</h2><br>
The Open button opens a save file.<br>
Expand Down
Binary file removed libs/jchmlib-0.5.4.jar
Binary file not shown.
Binary file added libs/swt.jar
Binary file not shown.
37 changes: 7 additions & 30 deletions src/com/mokkachocolata/project/pcsimsaveeditor/MainGUI.form
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.mokkachocolata.project.pcsimsaveeditor.MainGUI">
<grid id="27dc6" binding="panel" layout-manager="GridLayoutManager" row-count="2" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="panel" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="586" height="400"/>
Expand All @@ -17,13 +17,16 @@
<children>
<component id="a40c9" class="javax.swing.JTextArea" binding="Input">
<constraints/>
<properties/>
<properties>
<dragEnabled value="false"/>
<toolTipText value="Input, press ENTER to encrypt/decrypt."/>
</properties>
</component>
</children>
</scrollpane>
<scrollpane id="9a652">
<constraints>
<grid row="0" column="2" row-span="2" col-span="1" vsize-policy="5" hsize-policy="5" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="0" column="1" row-span="2" col-span="1" vsize-policy="5" hsize-policy="5" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
Expand All @@ -32,37 +35,11 @@
<constraints/>
<properties>
<editable value="true"/>
<toolTipText value="Output"/>
</properties>
</component>
</children>
</scrollpane>
<grid id="1012b" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="da0f0" class="javax.swing.JButton" binding="copyToClipboardButton" default-binding="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="1" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Copy to clipboard"/>
<verticalAlignment value="0"/>
</properties>
</component>
</children>
</grid>
<component id="6d134" class="javax.swing.JButton" binding="decryptButton" default-binding="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="1" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Decrypt/Encrypt"/>
</properties>
</component>
</children>
</grid>
</form>
157 changes: 86 additions & 71 deletions src/com/mokkachocolata/project/pcsimsaveeditor/MainGUI.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.mokkachocolata.project.pcsimsaveeditor;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.FileDialog;
import org.jchmlib.app.ChmWeb;

import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import org.eclipse.swt.widgets.*;
import java.awt.event.*;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
Expand All @@ -19,6 +19,7 @@
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Objects;

public class MainGUI {
private final JMenuBar menuBar = new JMenuBar();
Expand All @@ -33,9 +34,7 @@ public class MainGUI {
private final ChmWeb chmWeb = new ChmWeb();
private JTextArea Output;
private JTextArea Input;
private JButton decryptButton;
private JPanel panel;
private JButton copyToClipboardButton;

private String getEncryptedDecryptedString(String decryptEncrypt) throws InterruptedException {
PerformOperation crypt = new PerformOperation();
Expand All @@ -47,27 +46,17 @@ private String getEncryptedDecryptedString(String decryptEncrypt) throws Interru
}

public MainGUI() {
decryptButton.addActionListener(_ -> {
try {
Output.setText(getEncryptedDecryptedString(Input.getText()));
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
});
copyToClipboardButton.addActionListener(_ -> {
StringSelection stringSelection = new StringSelection(Output.getText());
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(stringSelection, null);
});
open.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String home = System.getProperty("user.home");
File downloads = new File(home+"/Downloads/");
File selected;
JFileChooser fileChooser = getjFileChooser(downloads);
if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
selected = fileChooser.getSelectedFile();
final Display display = new Display();
FileDialog dialog = getFileDialog(display, downloads);
display.dispose();
if (!Objects.equals(dialog.getFileName(), "")) {
selected = new File(dialog.getFilterPath() + getWin32OrLinuxSeperator() + dialog.getFileName());
try {
Output.setText(decryptWhenChecked(Files.readString(selected.toPath())));
} catch (IOException | InterruptedException ex) {
Expand All @@ -76,47 +65,56 @@ public void actionPerformed(ActionEvent e) {
}
}

private static FileDialog getFileDialog(Display display, File downloads) {
final Shell shell = new Shell(display);
FileDialog dialog = new FileDialog(shell, SWT.OPEN);
dialog.setText("Open PC Simulator Save File");
String[] filterNames = {"PC Simulator save file", "All Files"};
String[] filterExtensions = {"*.pc","*"};
dialog.setFilterNames(filterNames);
dialog.setFilterExtensions(filterExtensions);
dialog.setFilterPath(downloads.getPath());
dialog.open();
return dialog;
}

private String getWin32OrLinuxSeperator() {
String OS;
OS = System.getProperty("os.name");
if (OS.startsWith("Windows")) {
return "\\";
} else {
return "/";
}
}

public String decryptWhenChecked(String arg) throws InterruptedException {
if(decryptWhenOpening.isSelected()){
return getEncryptedDecryptedString(arg);
} else {
return arg;
}
}

private static JFileChooser getjFileChooser(File downloads) {
JFileChooser fileChooser = new JFileChooser(downloads);
FileFilter filter = new FileFilter() {
@Override
public boolean accept(File pathname) {
if (pathname.isDirectory()) {
return true;
} else {
String filename = pathname.getName().toLowerCase();
return filename.endsWith(".pc") ;
}
}

@Override
public String getDescription() {
return ".pc (PC Simulator save file)";
}
};
fileChooser.addChoosableFileFilter(filter);
fileChooser.setFileFilter(filter);
fileChooser.setDialogTitle("Open PC Simulator save file...");
return fileChooser;
}
});
save.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String home = System.getProperty("user.home");
File downloads = new File(home+"/Downloads/");
File selected;
JFileChooser fileChooser = getjFileChooser(downloads);
if (fileChooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
selected = fileChooser.getSelectedFile();
final Display display = new Display();
final Shell shell = new Shell(display);
FileDialog dialog = new FileDialog(shell, SWT.SAVE);
dialog.setText("Save to");
String[] filterNames = {"PC Simulator save file", "All Files"};
String[] filterExtensions = {"*.pc","*"};
dialog.setFilterNames(filterNames);
dialog.setFilterExtensions(filterExtensions);
dialog.setFilterPath(downloads.getPath());
dialog.open();
display.dispose();
if (!Objects.equals(dialog.getFileName(), "")) {
selected = new File(dialog.getFilterPath() + getWin32OrLinuxSeperator() + dialog.getFileName());
try {
FileWriter writer = new FileWriter(selected);
writer.write(encryptWhenChecked(Output.getText()));
Expand All @@ -135,28 +133,14 @@ public String encryptWhenChecked(String arg) throws InterruptedException {
}
}

private static JFileChooser getjFileChooser(File downloads) {
JFileChooser fileChooser = new JFileChooser(downloads);
FileFilter filter = new FileFilter() {
@Override
public boolean accept(File pathname) {
if (pathname.isDirectory()) {
return true;
} else {
String filename = pathname.getName().toLowerCase();
return filename.endsWith(".pc") ;
}
}

@Override
public String getDescription() {
return ".pc (PC Simulator save file)";
}
};
fileChooser.addChoosableFileFilter(filter);
fileChooser.setFileFilter(filter);
fileChooser.setDialogTitle("Save to...");
return fileChooser;
private String getWin32OrLinuxSeperator() {
String OS;
OS = System.getProperty("os.name");
if (OS.startsWith("Windows")) {
return "\\";
} else {
return "/";
}
}
});
help.addActionListener(new ActionListener() {
Expand Down Expand Up @@ -186,6 +170,24 @@ public void actionPerformed(ActionEvent e) {
}
}
});
Input.addKeyListener(new KeyAdapter() {
private String removeLastChar(String s) {
return (s == null || s.isEmpty())
? null
: (s.substring(0, s.length() - 1));
}
@Override
public void keyReleased(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_ENTER){
Input.setText(removeLastChar(Input.getText()));
try {
Output.setText(getEncryptedDecryptedString(Input.getText()));
} catch (InterruptedException ee) {
throw new RuntimeException(ee);
}
}
}
});
}

public static void main(String[] args) {
Expand All @@ -201,14 +203,27 @@ public static void main(String[] args) {
gui.menuBar.add(gui.fileMenu);
gui.menuBar.add(gui.optionsMenu);
gui.menuBar.add(gui.helpMenu);
gui.fileMenu.setMnemonic(KeyEvent.VK_F);
gui.optionsMenu.setMnemonic(KeyEvent.VK_O);
gui.helpMenu.setMnemonic(KeyEvent.VK_H);
// Menus add items
gui.fileMenu.add(gui.open);
gui.open.setMnemonic(KeyEvent.VK_P);
gui.open.setToolTipText("Open a PC Simulator save file, and outputs it to the Output textbox.");
gui.fileMenu.add(gui.save);
gui.save.setMnemonic(KeyEvent.VK_S);
gui.save.setToolTipText("Saves the current output text to the specified file.");
gui.decryptWhenOpening.setSelected(true);
gui.decryptWhenOpening.setMnemonic(KeyEvent.VK_D);
gui.decryptWhenOpening.setToolTipText("When checked, decrypts the file when opening.");
gui.encryptWhenSaving.setSelected(true);
gui.encryptWhenSaving.setMnemonic(KeyEvent.VK_E);
gui.encryptWhenSaving.setToolTipText("When checked, encrypts the output text before saving it.");
gui.optionsMenu.add(gui.decryptWhenOpening);
gui.optionsMenu.add(gui.encryptWhenSaving);
gui.helpMenu.add(gui.help);
gui.help.setMnemonic(KeyEvent.VK_E);
gui.help.setToolTipText("Opens the help document.");

frame.setContentPane(gui.panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Expand Down
Binary file modified src/resources/PCSimulatorSaveEditor.chm
Binary file not shown.
Binary file modified src/resources/PCSimulatorSaveEditor.chw
Binary file not shown.

0 comments on commit 266b4cd

Please sign in to comment.