fixed styling

This commit is contained in:
Daniel
2024-10-14 20:10:57 +03:00
parent e5c780d658
commit d46d258889
7 changed files with 355 additions and 97 deletions

14
pom.xml
View File

@@ -11,7 +11,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.10.2</junit.version> </properties>
<junit.version>5.10.2</junit.version>
</properties>
<dependencies>
<dependency>
@@ -24,7 +25,11 @@
<artifactId>javafx-fxml</artifactId>
<version>17.0.6</version>
</dependency>
<dependency>
<groupId>io.github.mkpaz</groupId>
<artifactId>atlantafx-base</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
@@ -36,7 +41,8 @@
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency> </dependencies>
</dependency>
</dependencies>
<build>
<plugins>
@@ -58,7 +64,7 @@
<!-- Default configuration for running with: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>org.lumijiez.monoalpha/org.lumijiez.monoalpha.HelloApplication</mainClass>
<mainClass>org.lumijiez.monoalpha/org.lumijiez.monoalpha.MonoAlpha</mainClass>
<launcher>app</launcher>
<jlinkZipName>app</jlinkZipName>
<jlinkImageName>app</jlinkImageName>

View File

@@ -1,8 +1,10 @@
module org.lumijiez.monoalpha {
requires javafx.controls;
requires javafx.fxml;
requires atlantafx.base;
opens org.lumijiez.monoalpha to javafx.fxml;
exports org.lumijiez.monoalpha;
exports org.lumijiez.monoalpha.util;
opens org.lumijiez.monoalpha.util to javafx.fxml;
}

View File

@@ -3,12 +3,22 @@ package org.lumijiez.monoalpha;
import javafx.fxml.FXML;
import javafx.scene.chart.BarChart;
import javafx.scene.chart.XYChart;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import org.lumijiez.monoalpha.util.CharacterSwitcher;
import org.lumijiez.monoalpha.util.InputAnalyzer;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class HelloController {
public class MainController {
@FXML
private BarChart<String, Integer> barChart;
@@ -16,9 +26,34 @@ public class HelloController {
@FXML
private TextArea inputArea;
@FXML
private TextArea ruleArea;
@FXML
private TextArea outputArea;
@FXML
private TextField patternInput;
@FXML
private Button patternButton;
@FXML
private TextArea patternOutput;
private Map<String, List<String>> dictionaryMap;
@FXML
private void initialize() {
analyzeText();
loadDictionary();
barChart.setStyle("-fx-font-size: 18px;");
inputArea.textProperty().addListener((observable, oldValue, newValue) -> {
analyzeText();
applyChanges();
});
ruleArea.textProperty().addListener((observable, oldValue, newValue) -> applyChanges());
patternButton.setOnAction(e -> matchPattern());
}
@FXML
@@ -26,18 +61,78 @@ public class HelloController {
String inputText = inputArea.getText();
Map<Character, Integer> frequencyMap = InputAnalyzer.analyzeFrequency(inputText);
List<XYChart.Data<String, Integer>> barChartData = InputAnalyzer.getBarChartData(frequencyMap);
updateBarChart(barChart, barChartData);
InputAnalyzer.updateBarChart(barChart, barChartData);
}
private void updateBarChart(BarChart<String, Integer> barChart, List<XYChart.Data<String, Integer>> data) {
barChart.getData().clear();
XYChart.Series<String, Integer> series = new XYChart.Series<>();
series.setName("Letter Frequencies");
for (XYChart.Data<String, Integer> datum : data) {
series.getData().add(new XYChart.Data<>(datum.getXValue(), datum.getYValue()));
private void applyChanges() {
String rules = ruleArea.getText();
String changedText = CharacterSwitcher.applyRules(rules, inputArea.getText());
outputArea.setText(changedText);
}
barChart.getData().add(series);
private void loadDictionary() {
dictionaryMap = new HashMap<>();
try (InputStream is = getClass().getResourceAsStream("/org/lumijiez/monoalpha/dictionary.txt")) {
assert is != null;
try (BufferedReader reader = new BufferedReader(new InputStreamReader(is))) {
String line;
while ((line = reader.readLine()) != null) {
String[] parts = line.split(" ");
if (parts.length == 2) {
String pattern = parts[0];
String word = parts[1];
dictionaryMap.computeIfAbsent(pattern, k -> new ArrayList<>()).add(word);
}
}
}
} catch (IOException e) {
e.printStackTrace();
patternOutput.setText("Error loading dictionary");
}
}
private void matchPattern() {
String inputWord = patternInput.getText().trim();
if (inputWord.isEmpty()) {
patternOutput.setText("Please enter a word.");
return;
}
String inputPattern = generatePattern(inputWord);
List<String> matchingWords = dictionaryMap.getOrDefault(inputPattern, new ArrayList<>());
if (matchingWords.isEmpty()) {
patternOutput.setText("No matching words found.");
} else {
patternOutput.setText(String.join("\n", matchingWords));
}
}
private String generatePattern(String word) {
StringBuilder pattern = new StringBuilder();
char nextLower = 'a';
char nextUpper = 'A';
Map<Character, Character> charMap = new HashMap<>();
for (char c : word.toCharArray()) {
if (Character.isLowerCase(c)) {
if (!charMap.containsKey(c)) {
charMap.put(c, nextLower++);
}
pattern.append(charMap.get(c));
} else if (Character.isUpperCase(c)) {
if (!charMap.containsKey(c)) {
charMap.put(c, nextUpper++);
}
pattern.append(charMap.get(c));
} else {
pattern.append(c);
}
}
return pattern.toString();
}
}

View File

@@ -1,17 +1,27 @@
package org.lumijiez.monoalpha;
import atlantafx.base.theme.Dracula;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.BackgroundImage;
import javafx.scene.layout.BackgroundPosition;
import javafx.scene.layout.BackgroundRepeat;
import javafx.scene.layout.BackgroundSize;
import javafx.stage.Stage;
import java.io.IOException;
import java.util.Objects;
public class HelloApplication extends Application {
public class MonoAlpha extends Application {
@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("monoalpha.fxml"));
Application.setUserAgentStylesheet(new Dracula().getUserAgentStylesheet());
FXMLLoader fxmlLoader = new FXMLLoader(MonoAlpha.class.getResource("monoalpha.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 1280, 720);
stage.setMinHeight(720);
stage.setMinWidth(1280);
stage.setTitle("MonoAlpha");

View File

@@ -1,4 +1,4 @@
package org.lumijiez.monoalpha;
package org.lumijiez.monoalpha.util;
import java.util.HashMap;
import java.util.Map;
@@ -21,10 +21,7 @@ public class CharacterSwitcher {
StringBuilder result = new StringBuilder();
for (char c : text.toCharArray()) {
char newChar = c;
while (ruleMap.containsKey(newChar)) {
newChar = ruleMap.get(newChar);
}
char newChar = ruleMap.getOrDefault(c, c);
result.append(newChar);
}

View File

@@ -1,4 +1,4 @@
package org.lumijiez.monoalpha;
package org.lumijiez.monoalpha.util;
import javafx.scene.chart.BarChart;
import javafx.scene.chart.XYChart;
@@ -28,7 +28,7 @@ public class InputAnalyzer {
.collect(Collectors.toList());
}
static void updateBarChart(BarChart<String, Integer> barChart, List<XYChart.Data<String, Integer>> data) {
public static void updateBarChart(BarChart<String, Integer> barChart, List<XYChart.Data<String, Integer>> data) {
barChart.getData().clear();
XYChart.Series<String, Integer> series = new XYChart.Series<>();

View File

@@ -1,16 +1,164 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.chart.BarChart?>
<?import javafx.scene.chart.CategoryAxis?>
<?import javafx.scene.chart.NumberAxis?>
<?import javafx.scene.control.Button?>
<VBox alignment="CENTER" spacing="20.0" xmlns:fx="http://javafx.com/fxml"
fx:controller="org.lumijiez.monoalpha.HelloController">
<padding>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0"/>
</padding>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<Label fx:id="welcomeText"/>
<Button text="Hello!" onAction="#onHelloButtonClick"/>
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" style="-fx-background-image: url(https://i.ibb.co/mRZkK7v/Pngtree-wrinkled-polyethylene-film-cling-film-7266284.png); -fx-padding: 10; -fx-background-repeat: no-repeat; -fx-background-size: cover;" xmlns="http://javafx.com/javafx/23" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.lumijiez.monoalpha.MainController">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" percentWidth="80" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" percentWidth="20" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<GridPane>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" percentHeight="30" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" percentHeight="70" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<GridPane>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="15.0" percentWidth="15" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<BarChart fx:id="barChart" alternativeColumnFillVisible="true" legendSide="TOP" legendVisible="false" opacity="0.85" GridPane.columnIndex="1">
<xAxis>
<CategoryAxis side="BOTTOM" />
</xAxis>
<yAxis>
<NumberAxis side="LEFT" tickLabelFill="WHITE">
<tickLabelFont>
<Font name="Copperplate Gothic Light" size="18.0" />
</tickLabelFont></NumberAxis>
</yAxis>
</BarChart>
<GridPane>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" percentHeight="20" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="F(X) -&gt; Y">
<font>
<Font name="Copperplate Gothic Bold" size="12.0" />
</font></Label>
<TextArea fx:id="ruleArea" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" opacity="0.85" prefHeight="200.0" prefWidth="200.0" promptText="a &gt; C; G &gt; g;" wrapText="true" GridPane.rowIndex="1">
<font>
<Font size="20.0" />
</font>
</TextArea>
</children>
</GridPane>
</children>
</GridPane>
<GridPane style="-fx-padding: 5; -fx-border-insets: 5; -fx-background-insets: 5;" GridPane.rowIndex="1">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" percentWidth="75" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<GridPane prefHeight="280.0" prefWidth="263.0" style="-fx-background-insets: 5; -fx-border-insets: 5; -fx-padding: 5;" GridPane.columnIndex="1">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" percentHeight="10" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" percentHeight="10" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" percentHeight="10" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="Pattern Matcher">
<font>
<Font name="Copperplate Gothic Bold" size="16.0" />
</font>
</Label>
<TextField fx:id="patternInput" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" promptText="Any word..." GridPane.rowIndex="1">
<font>
<Font size="18.0" />
</font>
</TextField>
<Button fx:id="patternButton" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Search" GridPane.rowIndex="2" />
<TextArea fx:id="patternOutput" editable="false" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" opacity="0.85" prefHeight="200.0" prefWidth="200.0" wrapText="true" GridPane.rowIndex="3">
<font>
<Font size="16.0" />
</font></TextArea>
</children>
</GridPane>
<GridPane>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" percentHeight="10" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<TextArea fx:id="outputArea" editable="false" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" opacity="0.85" prefHeight="200.0" prefWidth="200.0" wrapText="true" GridPane.rowIndex="1">
<font>
<Font size="19.0" />
</font>
</TextArea>
<Label alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="Decrypted Output">
<font>
<Font name="Copperplate Gothic Bold" size="22.0" />
</font>
</Label>
</children>
</GridPane>
</children>
</GridPane>
</children>
</GridPane>
<VBox prefHeight="200.0" prefWidth="100.0" GridPane.columnIndex="1">
<children>
<GridPane VBox.vgrow="ALWAYS">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" percentHeight="7" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label alignment="CENTER" contentDisplay="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="Encrypted Input">
<font>
<Font name="Copperplate Gothic Bold" size="22.0" />
</font>
</Label>
<TextArea fx:id="inputArea" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" onInputMethodTextChanged="#analyzeText" opacity="0.85" prefHeight="200.0" prefWidth="200.0" promptText="Input encrypted text..." wrapText="true" GridPane.rowIndex="1">
<font>
<Font size="13.0" />
</font>
</TextArea>
</children>
</GridPane>
</children>
</VBox>
</children>
</GridPane>