Skip to content

Commit

Permalink
working version of GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
nedlir committed Mar 12, 2022
1 parent 5914a4c commit 993f7a4
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 66 deletions.
6 changes: 0 additions & 6 deletions .gitignore

This file was deleted.

90 changes: 46 additions & 44 deletions Controller.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package officerunlocker;
package officerbreaker;

import java.awt.Desktop;
import java.io.File;
import javafx.scene.image.Image;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URL;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
Expand Down Expand Up @@ -36,44 +34,33 @@ public class Controller {
private String fileType;

@FXML
private ImageView image;
private InputStream stream;
private ImageView titleImageView;

@FXML
private ImageView fileImageView;
private Image wordImage;
private Image excelImage;
private Image powerpointImage;
private Image openingImage;

// opening screen instructions
@FXML
private Text textInstructions;

// opening screen title
@FXML
private Text textTitle;
private Text fileText;

@FXML
private Text invalidFileText;

@FXML
public void initialize() {
anchorPane.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
invalidFileText.setVisible(false);

textInstructions.setText(instructions());
invalidFileText.setVisible(false); // hides the invalid file text

try {
openingImage = new Image(getClass().getResourceAsStream("img/opening.png"));


wordImage = new Image(getClass().getResourceAsStream("img/word.png"));

powerpointImage = new Image(getClass().getResourceAsStream("img/powerpoint.png"));

excelImage = new Image(getClass().getResourceAsStream("img/excel.png"));

image.setImage(openingImage);
image.setVisible(true);

} catch (Exception e) {
e.printStackTrace();
}
Expand All @@ -82,22 +69,23 @@ public void initialize() {
@FXML
void browsePressed(ActionEvent event) {

// remove text from screen
textTitle.setVisible(false);
textInstructions.setVisible(false);
invalidFileText.setVisible(false);

fileChooser = new FileChooser();
fileChooser.setTitle("Please Select a File");
file = fileChooser.showOpenDialog(null);
filePath = file.toString();
fileName = file.getName();
filePathText.setText(filePath);
fileType = getFileType();
try {
fileChooser = new FileChooser();
fileChooser.setTitle("Please Select a File");
file = fileChooser.showOpenDialog(null);
filePath = file.toString();
fileName = file.getName();
filePathText.setText(filePath);
fileType = getFileType();

if (fileType != null) {
setImageByFileType();
} catch (Exception e) {
e.printStackTrace();
}

if (fileType != null && isFileSupported()) {
setScreenByFileType();
}
}

Expand All @@ -110,6 +98,7 @@ void removePasswordPressed(ActionEvent event) {
invalidFileText.setVisible(true);
return;
}

try {
FileManipulator manipulator = new FileManipulator(filePath, "./"); // create new object to manipulate the file

Expand All @@ -125,9 +114,9 @@ void removePasswordPressed(ActionEvent event) {

manipulator.insertFile(); // write back to file

manipulator.removeXMLFile();
manipulator.removeXMLFile(); // cleans the xml extracted from origin file

System.out.println("Finished");
fileText.setText(fileFinishedMessage());
}

} catch (Exception e) {
Expand All @@ -153,33 +142,46 @@ private boolean isFileSupported() {
}
}

private void setImageByFileType() {
private void setScreenByFileType() {
titleImageView.setVisible(false);

switch (fileType) {
case EXCEL:
image.setImage(excelImage);
fileImageView.setImage(excelImage);
fileText.setText(fileRecognizedMessage("Excel"));
break;
case WORD:
image.setImage(wordImage);
fileImageView.setImage(wordImage);
fileText.setText(fileRecognizedMessage("Word"));
break;
case POWERPOINT:
image.setImage(powerpointImage);
fileImageView.setImage(powerpointImage);
fileText.setText(fileRecognizedMessage("PowerPoint"));
break;
default:
break;
}
}

private String getFileType() {
int indexOfLastDot = this.fileName.lastIndexOf(".");
int indexOfLastDot = fileName.lastIndexOf(".");
if (indexOfLastDot == -1) // dot not found, invalid file
{
return null;
}
return this.fileName.substring(indexOfLastDot + 1);
return fileName.substring(indexOfLastDot + 1);
}

private String instructions() {
return "Welcome to Office Breaker!\n" + "This tool is deisgned to help remove read-only protection from .pptx, .xlsx. .docx filetypes.";

// Messages on screen
private String fileRecognizedMessage(String fileType){
String messageOnScreen = "Officer Breaker recognized " + "\"" + fileName + "\"" +" as " + fileType + " file.\n\n";
messageOnScreen = messageOnScreen + "Press \"Remove Password\" to unprotect the file.";
return messageOnScreen;
}


private String fileFinishedMessage(){
String messageOnScreen = "Yay! Officer Breaker removed the protection from your file!";
return messageOnScreen;
}

}
2 changes: 1 addition & 1 deletion FileManipulator.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package officerunlocker;
package officerbreaker;

import java.io.File;
import java.io.IOException;
Expand Down
2 changes: 1 addition & 1 deletion OfficerBreaker.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package officerunlocker;
package officerbreaker;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
Expand Down
36 changes: 23 additions & 13 deletions View.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,43 @@

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Hyperlink?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>

<AnchorPane fx:id="anchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="501.0" prefWidth="675.0" xmlns="https://javafx.com/javafx/17" xmlns:fx="https://javafx.com/fxml/1" fx:controller="officerunlocker.Controller">
<AnchorPane fx:id="anchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="548.0" prefWidth="675.0" xmlns="https://javafx.com/javafx/17" xmlns:fx="https://javafx.com/fxml/1" fx:controller="officerbreaker.Controller">
<children>
<Button layoutX="90.0" layoutY="401.0" mnemonicParsing="false" onAction="#browsePressed" text="Browse" />
<Button layoutX="89.0" layoutY="445.0" mnemonicParsing="false" onAction="#removePasswordPressed" text="Remove Password" />
<Text fx:id="filePathText" layoutX="158.0" layoutY="419.0" strokeType="OUTSIDE" strokeWidth="0.0">
<Text fx:id="textTitle" fill="#000000bf" layoutX="164.0" layoutY="67.0" opacity="0.96" strokeLineCap="ROUND" strokeType="OUTSIDE" strokeWidth="0.0" text="Officer Breaker" wrappingWidth="397.650390625">
<font>
<Font size="15.0" />
<Font name="AR CENA" size="64.0" />
</font>
</Text>
<Text layoutX="260.0" layoutY="493.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Art by " />
<Hyperlink layoutX="293.0" layoutY="477.0" onAction="#openCioccolatodorimaURL" text="Cioccolatodorima" />
<ImageView fx:id="image" fitHeight="335.0" fitWidth="267.0" layoutX="394.0" layoutY="66.0" pickOnBounds="true" preserveRatio="true" />
<Text fx:id="invalidFileText" fill="RED" layoutX="220.0" layoutY="463.0" strokeType="OUTSIDE" strokeWidth="0.0" text="File not supported. Please use &quot;.pptx&quot;, &quot;.docx&quot; or &quot;.xlsx&quot;">
<ImageView fx:id="titleImageView" fitHeight="343.0" fitWidth="553.0" layoutX="81.0" layoutY="95.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@img/title.png" />
</image>
</ImageView>
<ImageView fx:id="fileImageView" fitHeight="332.0" fitWidth="267.0" layoutX="395.0" layoutY="118.0" pickOnBounds="true" preserveRatio="true" />
<Text fx:id="fileText" fill="#000000bf" layoutX="81.0" layoutY="241.0" stroke="BLACK" strokeType="OUTSIDE" strokeWidth="0.0" wrappingWidth="321.6494140625">
<font>
<Font size="14.0" />
<Font name="Kristen ITC" size="18.0" />
</font>
</Text>
<Text fx:id="textTitle" fill="#000000bf" layoutX="77.0" layoutY="83.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Office Breaker">
<Button layoutX="99.0" layoutY="451.0" mnemonicParsing="false" onAction="#browsePressed" text="Browse" />
<Button layoutX="98.0" layoutY="494.0" mnemonicParsing="false" onAction="#removePasswordPressed" text="Remove Password" />
<Text fx:id="filePathText" layoutX="162.0" layoutY="468.0" strokeType="OUTSIDE" strokeWidth="0.0" wrappingWidth="505.0">
<font>
<Font size="43.0" />
<Font size="15.0" />
</font>
</Text>
<Text layoutX="280.0" layoutY="537.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Art by " />
<Hyperlink layoutX="312.0" layoutY="521.0" onAction="#openCioccolatodorimaURL" text="Cioccolatodorima" />
<Text fx:id="invalidFileText" fill="RED" layoutX="221.0" layoutY="512.0" strokeType="OUTSIDE" strokeWidth="0.0" text="File not supported. Please use &quot;.pptx&quot;, &quot;.docx&quot; or &quot;.xlsx&quot;">
<font>
<Font size="14.0" />
</font>
</Text>
<Text fx:id="textInstructions" fill="#000000c0" layoutX="57.0" layoutY="118.0" strokeType="OUTSIDE" strokeWidth="0.0" wrappingWidth="326.13671875" />
</children>
</AnchorPane>
2 changes: 1 addition & 1 deletion XMLParser.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package officerunlocker;
package officerbreaker;

import java.io.File;
import java.io.FileInputStream;
Expand Down
Binary file removed img/opening.png
Binary file not shown.
Binary file added img/title.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 993f7a4

Please sign in to comment.