Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lab3;
- import java.io.File;
- import java.util.HashSet;
- import java.util.Map.Entry;
- import java.util.Scanner;
- import java.util.Set;
- import javafx.application.Application;
- import javafx.collections.FXCollections;
- import javafx.collections.ObservableList;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.ListView;
- import javafx.scene.control.TextField;
- import javafx.scene.layout.BorderPane;
- import javafx.scene.layout.HBox;
- import javafx.scene.layout.Priority;
- import javafx.stage.Stage;
- import textproc.GeneralWordCounter;
- import textproc.WordCountComparator;
- public class BookReaderController extends Application {
- @Override
- public void start(Stage primaryStage) throws Exception {
- BorderPane root = new BorderPane();
- Scene scene = new Scene(root, 500, 500);
- primaryStage.setTitle("BookReader");
- primaryStage.setScene(scene);
- primaryStage.show();
- // ---------------------------------------------------------------------------------------------
- Scanner scan = new Scanner(new File("undantagsord.txt"));
- Set<String> stopwords = new HashSet<String>();
- while (scan.hasNext()) {
- stopwords.add(scan.next().toLowerCase());
- }
- GeneralWordCounter<String> r = new GeneralWordCounter<String>(stopwords);
- Scanner s = new Scanner(new File("nilsholg.txt"));
- s.findWithinHorizon("\uFEFF", 1);
- s.useDelimiter("(\\s|,|\\.|:|;|!|\\?|'|\\\")+");
- while (s.hasNext()) {
- String word = s.next().toLowerCase();
- r.process(word);
- }
- s.close();
- scan.close();
- ObservableList<Entry<String, Integer>> words = FXCollections.observableArrayList(r.getWords());
- ListView<Entry<String, Integer>> listView = new ListView<Entry<String, Integer>>(words);
- root.setCenter(listView);
- //---------------------------------------------------------------------------------------------
- HBox hbox = new HBox();
- Button b1 = new Button("Alphabetical");
- Button b2 = new Button("Frequency");
- Button b3 = new Button("Find");
- TextField txt = new TextField();
- HBox.setHgrow(b1, Priority.ALWAYS);
- HBox.setHgrow(b2, Priority.ALWAYS);
- HBox.setHgrow(txt, Priority.ALWAYS);
- HBox.setHgrow(b3, Priority.ALWAYS);
- b1.setMaxWidth(Double.MAX_VALUE);
- b2.setMaxWidth(Double.MAX_VALUE);
- txt.setMaxWidth(Double.MAX_VALUE);
- b3.setMaxWidth(Double.MAX_VALUE);
- txt.setPromptText("Search");
- hbox.getChildren().addAll(b1, b2, txt, b3);
- root.setBottom(hbox);
- //---------------------------------------------------------------------------------------------
- b1.setOnAction(e -> words.setAll(r.getWords()));
- b2.setOnAction(e -> words.sort(new WordCountComparator()));
- b3.setOnAction(e -> {
- });
- //---------------------------------------------------------------------------------------------
- }
- public static void main(String[] args) {
- Application.launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement