Skip to content

Commit

Permalink
soluzione proposta
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Monge authored and Alberto Monge committed Mar 15, 2018
1 parent 0ce3c13 commit 870635d
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 46 deletions.
25 changes: 17 additions & 8 deletions Lab01_Parole/src/it/polito/tdp/parole/Parole.fxml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.*?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?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.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>

<BorderPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="it.polito.tdp.parole.ParoleController">
<BorderPane xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="it.polito.tdp.parole.ParoleController">
<top>
<Label text="Lab 1 - Lista di Parole" BorderPane.alignment="CENTER">
<BorderPane.margin>
Expand All @@ -25,13 +29,18 @@
</children>
</HBox>
<TextArea fx:id="txtResult" editable="false" prefHeight="200.0" prefWidth="200.0" wrapText="true" />
<TextArea fx:id="txtPerfomances" prefHeight="50.0" prefWidth="200.0" />
<HBox>
<children>
<Pane HBox.hgrow="ALWAYS" />
<Button fx:id="btnCancella" mnemonicParsing="false" onAction="#doCancella" text="Cancella" />
<Button fx:id="btnReset" alignment="CENTER_RIGHT" mnemonicParsing="false" onAction="#doReset" text="Reset" />
</children>
</HBox>
</children>
</VBox>
</center>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
<bottom>
<Button fx:id="btnReset" alignment="CENTER_RIGHT" mnemonicParsing="false" onAction="#doReset" text="Reset" BorderPane.alignment="CENTER_RIGHT" />
</bottom>
</BorderPane>
110 changes: 78 additions & 32 deletions Lab01_Parole/src/it/polito/tdp/parole/ParoleController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* Sample Skeleton for 'Parole.fxml' Controller Class
*/


import it.polito.tdp.parole.model.Parole;

import java.net.URL;
Expand All @@ -17,44 +16,91 @@
import javafx.scene.control.TextField;

public class ParoleController {

Parole elenco ;

@FXML // ResourceBundle that was given to the FXMLLoader
private ResourceBundle resources;
Parole elenco = new Parole();

@FXML // URL location of the FXML file that was given to the FXMLLoader
private URL location;
@FXML // ResourceBundle that was given to the FXMLLoader
private ResourceBundle resources;

@FXML // fx:id="txtParola"
private TextField txtParola; // Value injected by FXMLLoader
@FXML // URL location of the FXML file that was given to the FXMLLoader
private URL location;

@FXML // fx:id="txtResult"
private TextArea txtResult; // Value injected by FXMLLoader

@FXML
private Button btnReset;
@FXML // fx:id="txtParola"
private TextField txtParola; // Value injected by FXMLLoader

@FXML // fx:id="btnInserisci"
private Button btnInserisci; // Value injected by FXMLLoader
@FXML // fx:id="txtResult"
private TextArea txtResult; // Value injected by FXMLLoader

@FXML
void doInsert(ActionEvent event) {
// TODO
}

@FXML
void doReset(ActionEvent event) {
// TODO
}
@FXML
private Button btnReset;

@FXML // This method is called by the FXMLLoader when initialization is complete
void initialize() {
assert txtParola != null : "fx:id=\"txtParola\" was not injected: check your FXML file 'Parole.fxml'.";
assert txtResult != null : "fx:id=\"txtResult\" was not injected: check your FXML file 'Parole.fxml'.";
assert btnInserisci != null : "fx:id=\"btnInserisci\" was not injected: check your FXML file 'Parole.fxml'.";
@FXML // fx:id="btnInserisci"
private Button btnInserisci; // Value injected by FXMLLoader

elenco = new Parole() ;

@FXML
private Button btnCancella;

@FXML
private TextArea txtPerfomances;

@FXML
void doCancella(ActionEvent event) {
if(txtResult.getSelectedText().equals("")){
txtPerfomances.clear();
txtPerfomances.setText("Seleziona una Parola!");
}
else{
String selected = txtResult.getSelectedText();

double start = System.nanoTime();
elenco.removeParola(selected);
double stop = System.nanoTime();

txtResult.clear();
String result = "" ;
for(String p: elenco.getElenco())
result += p + "\n" ;
txtResult.setText(result);

txtPerfomances.clear();
txtPerfomances.setText("[REMOVE]: " + (stop - start) / 1e9 + " seconds");
}
}

@FXML
void doInsert(ActionEvent event) {

double start = System.nanoTime();
elenco.addParola( txtParola.getText() );
double stop = System.nanoTime();

txtResult.clear();
String result = "" ;
for(String p: elenco.getElenco())
result += p + "\n" ;
txtResult.setText(result);

txtPerfomances.clear();
txtPerfomances.setText("[INSERT]: " + (stop - start) / 1e9 + " seconds");

txtParola.clear();

}

@FXML
void doReset(ActionEvent event) {
elenco.reset();
txtResult.clear();
}

@FXML // This method is called by the FXMLLoader when initialization is
// complete
void initialize() {
assert txtParola != null : "fx:id=\"txtParola\" was not injected: check your FXML file 'Parole.fxml'.";
assert btnInserisci != null : "fx:id=\"btnInserisci\" was not injected: check your FXML file 'Parole.fxml'.";
assert txtResult != null : "fx:id=\"txtResult\" was not injected: check your FXML file 'Parole.fxml'.";
assert txtPerfomances != null : "fx:id=\"txtPerfomances\" was not injected: check your FXML file 'Parole.fxml'.";
assert btnCancella != null : "fx:id=\"btnCancella\" was not injected: check your FXML file 'Parole.fxml'.";
assert btnReset != null : "fx:id=\"btnReset\" was not injected: check your FXML file 'Parole.fxml'.";
}
}
21 changes: 15 additions & 6 deletions Lab01_Parole/src/it/polito/tdp/parole/model/Parole.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
package it.polito.tdp.parole.model;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

public class Parole {


List<String> lista;

public Parole() {
//TODO
lista = new LinkedList<String>();
// lista = new ArrayList<String>();
}

public void addParola(String p) {
//TODO
lista.add(p);
}

public List<String> getElenco() {
//TODO
return null;
Collections.sort(lista);
return lista;
}

public void reset() {
// TODO
lista.clear();
}

public void removeParola(String string) {
lista.remove(string);
}

}

0 comments on commit 870635d

Please sign in to comment.