working version of GUI

This commit is contained in:
nedlir 2022-03-12 02:27:08 +02:00
parent 5914a4c223
commit 993f7a4717
8 changed files with 73 additions and 67 deletions

6
.gitignore vendored
View File

@ -1,6 +0,0 @@
test.xml
Tester.java
Testing.java
tempCodeRunnerFile.java
makefile
*.class

View File

@ -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;
@ -36,20 +34,16 @@ 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;
@ -57,23 +51,16 @@ public class Controller {
@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();
}
@ -82,11 +69,9 @@ public class Controller {
@FXML
void browsePressed(ActionEvent event) {
// remove text from screen
textTitle.setVisible(false);
textInstructions.setVisible(false);
invalidFileText.setVisible(false);
try {
fileChooser = new FileChooser();
fileChooser.setTitle("Please Select a File");
file = fileChooser.showOpenDialog(null);
@ -95,9 +80,12 @@ public class Controller {
filePathText.setText(filePath);
fileType = getFileType();
if (fileType != null) {
setImageByFileType();
} catch (Exception e) {
e.printStackTrace();
}
if (fileType != null && isFileSupported()) {
setScreenByFileType();
}
}
@ -110,6 +98,7 @@ public class Controller {
invalidFileText.setVisible(true);
return;
}
try {
FileManipulator manipulator = new FileManipulator(filePath, "./"); // create new object to manipulate the file
@ -125,9 +114,9 @@ public class Controller {
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) {
@ -153,16 +142,21 @@ public class Controller {
}
}
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;
@ -170,16 +164,24 @@ public class Controller {
}
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;
}
}

View File

@ -1,4 +1,4 @@
package officerunlocker;
package officerbreaker;
import java.io.File;
import java.io.IOException;

View File

@ -1,4 +1,4 @@
package officerunlocker;
package officerbreaker;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;

View File

@ -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="http://javafx.com/javafx/17" xmlns:fx="http://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="http://javafx.com/javafx/17" xmlns:fx="http://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 name="AR CENA" size="64.0" />
</font>
</Text>
<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 name="Kristen ITC" size="18.0" />
</font>
</Text>
<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="15.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;">
<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="textTitle" fill="#000000bf" layoutX="77.0" layoutY="83.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Office Breaker">
<font>
<Font size="43.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>

View File

@ -1,4 +1,4 @@
package officerunlocker;
package officerbreaker;
import java.io.File;
import java.io.FileInputStream;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1011 KiB

BIN
img/title.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 KiB