Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add languages #78

Merged
merged 1 commit into from
Jan 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 78 additions & 17 deletions src/main/java/Controller_2.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ParseObjects.Between;
import com.sun.org.apache.xml.internal.utils.StringComparable;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
Expand Down Expand Up @@ -50,6 +51,8 @@ public class Controller_2 {
private TextArea query;
@FXML
private TextField pathSave;
@FXML
private ChoiceBox<String> language;


/**
Expand Down Expand Up @@ -96,19 +99,49 @@ public void changed(final ObservableValue<? extends String> observable, final St
}


private Vector<String> getLanguages(String path) {
Vector<String> langs = new Vector<>();
public String removeFromTheTermUndefindSigns(String termS) { //like: "dfsdfdsf
try {
int startIndex = -1;// the index that the _token begin.
int endIndex = termS.length(); //the index that the _token ends
if (termS != null && !termS.equals("")) {
for (int i = 0; i < termS.length() && startIndex == -1; i++) {
if ( Character.isLetter(termS.charAt(i))) {
startIndex = i;
break;
}
}
for (int i = termS.length() - 1; 0 <= i && endIndex == termS.length(); i--) {
if ( Character.isLetter(termS.charAt(i))) {
endIndex = i;
break;
}
}
if (termS.length() > 1 && startIndex >= endIndex) return "";
if ((startIndex != 0) || (endIndex != termS.length())) {
termS = termS.substring(startIndex, endIndex + 1);
}
return termS;
}
return "";
} catch (Exception e) {
return "";
}
}

private Vector<String> getLanguages(String path) throws Exception {
Vector<String> langs = new Vector<>();

BufferedReader reader = new BufferedReader(new FileReader(new File(path + "/Languages.txt")));
String lang = reader.readLine();
while (lang != null && !lang.equals("")) {
langs.add(lang);
lang = removeFromTheTermUndefindSigns(lang);
if (!lang.equals("")) {
if (!langs.contains(lang)) {
langs.add(lang);
}
}
lang=reader.readLine();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return langs;
}

Expand Down Expand Up @@ -201,22 +234,50 @@ public void getDirChooser(ActionEvent actionEvent) {
File file = chooser.showDialog(new Stage());
if (file != null) {
path.setText(file.getAbsolutePath());
ObservableList<String> list = FXCollections.observableArrayList();
ObservableList<String> ObserCityList = FXCollections.observableArrayList();
ObservableList<String> ObserLangList = FXCollections.observableArrayList();
Vector<String> cities = getCitys(path.getText());
File cityDic = new File(path.getText() + "/" + "CityDictionary.txt");

if (cityDic.exists()) {
boolean thereIsLangFile = true;
Vector<String> languages = new Vector<>();
try{
languages=getLanguages(file.getAbsolutePath());
}
catch (Exception e){
thereIsLangFile=false;
}
if (thereIsLangFile && cityDic.exists()) {
filterbycity.setDisable(false);
language.setDisable(false);
for (String city : cities) {
list.add(city);
ObserCityList.add(city);
}
listView.setItems(list);
for (String lang: languages ){
ObserLangList.add(lang);
}
listView.setItems(ObserCityList);
listView.getItems().sort(Comparator.naturalOrder());
language.setItems(ObserLangList);
language.getItems().sort(String::compareTo);
} else {
path.setText("");
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setContentText("There is no \"CityDictionary.txt\".");
alert.show();
if(!thereIsLangFile && !cityDic.exists()) {
path.setText("");
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setContentText("There are no \"CityDictionary.txt\" and \"Languages.txt\".");
alert.show();
}
else if(!cityDic.exists()) {
path.setText("");
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setContentText("There is no \"CityDictionary.txt\".");
alert.show();
}
else{// if(!thereIsLangFile){
path.setText("");
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setContentText("There is no \"Languages.txt\".");
alert.show();
}
}
} else {
Alert alert = new Alert(Alert.AlertType.INFORMATION);
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/View_2.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<?import javafx.scene.control.Accordion?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.ChoiceBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.RadioButton?>
Expand Down Expand Up @@ -62,6 +63,8 @@
</Label>
<Button fx:id="saveResults" layoutX="363.0" layoutY="511.0" mnemonicParsing="false" onAction="#getDirSaveChooser" prefHeight="25.0" prefWidth="220.0" text="Save Results to folder" />
<TextField fx:id="pathSave" disable="true" layoutX="363.0" layoutY="542.0" prefHeight="25.0" prefWidth="220.0" promptText="the folder to save results..." />
<ChoiceBox fx:id="language" disable="true" layoutX="14.0" layoutY="542.0" prefWidth="150.0" />
<Label layoutX="14.0" layoutY="511.0" prefHeight="25.0" prefWidth="93.0" text="Choose language" />

</children>
</AnchorPane>
Expand Down