-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
JIMMY
authored and
JIMMY
committed
Mar 21, 2018
1 parent
636fa0b
commit 875a911
Showing
21 changed files
with
390 additions
and
92 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
69 changes: 69 additions & 0 deletions
69
Lab2_Alien_soluzione_Ese2/bin/it/polito/tdp/alien/Alien.fxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import javafx.geometry.Insets?> | ||
<?import javafx.scene.control.Button?> | ||
<?import javafx.scene.control.Label?> | ||
<?import javafx.scene.control.TextArea?> | ||
<?import javafx.scene.control.TextField?> | ||
<?import javafx.scene.image.Image?> | ||
<?import javafx.scene.image.ImageView?> | ||
<?import javafx.scene.layout.BorderPane?> | ||
<?import javafx.scene.layout.HBox?> | ||
<?import javafx.scene.layout.VBox?> | ||
<?import javafx.scene.text.Font?> | ||
|
||
<BorderPane xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="it.polito.tdp.alien.AlienController"> | ||
<top> | ||
<Label text="Lab 1 - Alien Translator" BorderPane.alignment="CENTER"> | ||
<BorderPane.margin> | ||
<Insets bottom="10.0" /> | ||
</BorderPane.margin> | ||
<font> | ||
<Font name="System Bold" size="13.0" /> | ||
</font> | ||
</Label> | ||
</top> | ||
<padding> | ||
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" /> | ||
</padding> | ||
<center> | ||
<VBox alignment="CENTER" BorderPane.alignment="CENTER"> | ||
<children> | ||
<HBox alignment="CENTER_LEFT" spacing="10.0"> | ||
<children> | ||
<Label text="Insert Text: " /> | ||
<TextField fx:id="lblTesto" promptText="Insert the text here.." /> | ||
<Button fx:id="btnTranslate" mnemonicParsing="false" onAction="#doTranslate" text="Translate" /> | ||
<ImageView fitHeight="82.0" fitWidth="150.0" pickOnBounds="true" preserveRatio="true"> | ||
<image> | ||
<Image url="@../../../../../rsc/Alien-512.png" /> | ||
</image> | ||
<HBox.margin> | ||
<Insets left="15.0" /> | ||
</HBox.margin> | ||
</ImageView> | ||
</children> | ||
<opaqueInsets> | ||
<Insets /> | ||
</opaqueInsets> | ||
<VBox.margin> | ||
<Insets bottom="15.0" /> | ||
</VBox.margin> | ||
</HBox> | ||
<TextArea fx:id="txtResult" promptText="Welcome to the AlienDictionary v2016..."> | ||
<VBox.margin> | ||
<Insets /> | ||
</VBox.margin></TextArea> | ||
</children> | ||
<BorderPane.margin> | ||
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" /> | ||
</BorderPane.margin> | ||
</VBox> | ||
</center> | ||
<bottom> | ||
<Button fx:id="btnReset" mnemonicParsing="false" onAction="#doReset" text="Reset" BorderPane.alignment="CENTER_RIGHT"> | ||
<BorderPane.margin> | ||
<Insets bottom="10.0" right="15.0" top="20.0" /> | ||
</BorderPane.margin></Button> | ||
</bottom> | ||
</BorderPane> |
Binary file added
BIN
+3.38 KB
Lab2_Alien_soluzione_Ese2/bin/it/polito/tdp/alien/AlienController.class
Binary file not shown.
Binary file added
BIN
+2.28 KB
Lab2_Alien_soluzione_Ese2/bin/it/polito/tdp/alien/AlienDictionary.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes
69 changes: 69 additions & 0 deletions
69
Lab2_Alien_soluzione_Ese2/src/it/polito/tdp/alien/Alien.fxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import javafx.geometry.Insets?> | ||
<?import javafx.scene.control.Button?> | ||
<?import javafx.scene.control.Label?> | ||
<?import javafx.scene.control.TextArea?> | ||
<?import javafx.scene.control.TextField?> | ||
<?import javafx.scene.image.Image?> | ||
<?import javafx.scene.image.ImageView?> | ||
<?import javafx.scene.layout.BorderPane?> | ||
<?import javafx.scene.layout.HBox?> | ||
<?import javafx.scene.layout.VBox?> | ||
<?import javafx.scene.text.Font?> | ||
|
||
<BorderPane xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="it.polito.tdp.alien.AlienController"> | ||
<top> | ||
<Label text="Lab 1 - Alien Translator" BorderPane.alignment="CENTER"> | ||
<BorderPane.margin> | ||
<Insets bottom="10.0" /> | ||
</BorderPane.margin> | ||
<font> | ||
<Font name="System Bold" size="13.0" /> | ||
</font> | ||
</Label> | ||
</top> | ||
<padding> | ||
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" /> | ||
</padding> | ||
<center> | ||
<VBox alignment="CENTER" BorderPane.alignment="CENTER"> | ||
<children> | ||
<HBox alignment="CENTER_LEFT" spacing="10.0"> | ||
<children> | ||
<Label text="Insert Text: " /> | ||
<TextField fx:id="lblTesto" promptText="Insert the text here.." /> | ||
<Button fx:id="btnTranslate" mnemonicParsing="false" onAction="#doTranslate" text="Translate" /> | ||
<ImageView fitHeight="82.0" fitWidth="150.0" pickOnBounds="true" preserveRatio="true"> | ||
<image> | ||
<Image url="@../../../../../rsc/Alien-512.png" /> | ||
</image> | ||
<HBox.margin> | ||
<Insets left="15.0" /> | ||
</HBox.margin> | ||
</ImageView> | ||
</children> | ||
<opaqueInsets> | ||
<Insets /> | ||
</opaqueInsets> | ||
<VBox.margin> | ||
<Insets bottom="15.0" /> | ||
</VBox.margin> | ||
</HBox> | ||
<TextArea fx:id="txtResult" promptText="Welcome to the AlienDictionary v2016..."> | ||
<VBox.margin> | ||
<Insets /> | ||
</VBox.margin></TextArea> | ||
</children> | ||
<BorderPane.margin> | ||
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" /> | ||
</BorderPane.margin> | ||
</VBox> | ||
</center> | ||
<bottom> | ||
<Button fx:id="btnReset" mnemonicParsing="false" onAction="#doReset" text="Reset" BorderPane.alignment="CENTER_RIGHT"> | ||
<BorderPane.margin> | ||
<Insets bottom="10.0" right="15.0" top="20.0" /> | ||
</BorderPane.margin></Button> | ||
</bottom> | ||
</BorderPane> |
117 changes: 117 additions & 0 deletions
117
Lab2_Alien_soluzione_Ese2/src/it/polito/tdp/alien/AlienController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package it.polito.tdp.alien; | ||
|
||
import java.net.URL; | ||
import java.util.ResourceBundle; | ||
import java.util.StringTokenizer; | ||
|
||
import javafx.event.ActionEvent; | ||
import javafx.fxml.FXML; | ||
import javafx.scene.control.Button; | ||
import javafx.scene.control.TextArea; | ||
import javafx.scene.control.TextField; | ||
|
||
public class AlienController { | ||
|
||
private AlienDictionary alienDictionary = new AlienDictionary(); | ||
|
||
@FXML | ||
private ResourceBundle resources; | ||
|
||
@FXML | ||
private URL location; | ||
|
||
@FXML | ||
private TextField lblTesto; | ||
|
||
@FXML | ||
private Button btnTranslate; | ||
|
||
@FXML | ||
private TextArea txtResult; | ||
|
||
@FXML | ||
private Button btnReset; | ||
|
||
@FXML | ||
void doReset(ActionEvent event) { | ||
lblTesto.clear(); | ||
txtResult.clear(); | ||
alienDictionary.resetDictionary(); | ||
} | ||
|
||
@FXML | ||
void doTranslate(ActionEvent event) { | ||
|
||
txtResult.clear(); | ||
String riga = lblTesto.getText().toLowerCase(); | ||
|
||
// Controllo sull'input | ||
if (riga == null || riga.length() == 0) { | ||
txtResult.setText("Inserire una o due parole."); | ||
return; | ||
} | ||
|
||
StringTokenizer st = new StringTokenizer(riga, " "); | ||
|
||
// Controllo su String Tokenizer (superfluo) | ||
if (!st.hasMoreElements()) { | ||
txtResult.setText("Inserire una o due parole."); | ||
return; | ||
} | ||
|
||
// Estraggo la prima parola | ||
String alienWord = st.nextToken(); | ||
|
||
if (st.hasMoreTokens()) { | ||
// Devo inserire nel dizionario | ||
|
||
// Estraggo la seconda parola | ||
String translation = st.nextToken(); | ||
|
||
if (!alienWord.matches("[a-zA-Z]*") || !translation.matches("[a-zA-Z]*")) { | ||
txtResult.setText("Inserire solo caratteri alfabetici."); | ||
return; | ||
} | ||
|
||
// Aggiungo la parola aliena e traduzione nel dizionario | ||
alienDictionary.addWord(alienWord, translation); | ||
|
||
txtResult.setText("La parola: " + alienWord + " traduzione: " + translation + " è stata inserita."); | ||
|
||
} else { | ||
|
||
// Controllo che non ci siano caratteri non ammessi | ||
if (!alienWord.matches("[a-zA-Z?]*")) { | ||
txtResult.setText("Inserire solo caratteri alfabetici."); | ||
return; | ||
} | ||
|
||
String translation; | ||
|
||
if (alienWord.matches("[a-zA-Z?]*") && !alienWord.matches("[a-zA-Z]*")) { | ||
|
||
// Traduzione con WildCard | ||
translation = alienDictionary.translateWordWildCard(alienWord); | ||
|
||
} else { | ||
|
||
// Traduzione classica | ||
translation = alienDictionary.translateWord(alienWord); | ||
} | ||
|
||
if (translation != null) { | ||
txtResult.setText(translation); | ||
} else { | ||
txtResult.setText("La parola cercata non esiste nel dizionario."); | ||
} | ||
} | ||
} | ||
|
||
@FXML | ||
void initialize() { | ||
assert lblTesto != null : "fx:id=\"lblTesto\" was not injected: check your FXML file 'Alien.fxml'."; | ||
assert btnTranslate != null : "fx:id=\"btnTranslate\" was not injected: check your FXML file 'Alien.fxml'."; | ||
assert txtResult != null : "fx:id=\"txtResult\" was not injected: check your FXML file 'Alien.fxml'."; | ||
assert btnReset != null : "fx:id=\"btnReset\" was not injected: check your FXML file 'Alien.fxml'."; | ||
} | ||
} |
Oops, something went wrong.