diff --git a/.classpath b/.classpath index 1de72ab..4f697fa 100644 --- a/.classpath +++ b/.classpath @@ -2,5 +2,6 @@ + diff --git a/Notepad.jar b/Notepad.jar new file mode 100644 index 0000000..beeb217 Binary files /dev/null and b/Notepad.jar differ diff --git a/filereader/.gitignore b/filereader/.gitignore index f207eba..ae5e646 100644 --- a/filereader/.gitignore +++ b/filereader/.gitignore @@ -6,3 +6,6 @@ /Utils.class /package-info.class /GUI$1.class +/TextFilePane$1.class +/TextFileUtils.class +/TextFileContentsLoader.class diff --git a/filereader/GUI.java b/filereader/GUI.java index 92344c3..28a42b7 100644 --- a/filereader/GUI.java +++ b/filereader/GUI.java @@ -5,19 +5,21 @@ import javafx.stage.Stage; public class GUI extends Application { - public static Stage newPrimaryStage; + private static Stage newPrimaryStage; + private static Scene scene; + private static MainPane pane; + + public static void main(String[] args) { + launch(); + } @Override public void start(Stage primaryStage) { newPrimaryStage = new Stage(); - MainPane pane = new MainPane(); - Scene scene = new Scene(pane); + pane = new MainPane(); + scene = new Scene(pane); newPrimaryStage.setScene(scene); newPrimaryStage.setMaximized(true); newPrimaryStage.show(); } - - public static void main(String[] args) { - launch(); - } } \ No newline at end of file diff --git a/filereader/MainPane.java b/filereader/MainPane.java index 9d5b385..540e041 100644 --- a/filereader/MainPane.java +++ b/filereader/MainPane.java @@ -1,21 +1,15 @@ package filereader; -import javafx.scene.layout.GridPane; +import javafx.scene.layout.BorderPane; -public class MainPane extends GridPane { - TextFilePane textPane; +public class MainPane extends BorderPane { + private static TextFilePane textPane; + private static MainToolbar mainToolbar; MainPane() { - MainToolbar mainToolbar = new MainToolbar(); + mainToolbar = new MainToolbar(); textPane = new TextFilePane(); - add(mainToolbar, 0, 0); - add(textPane, 0, 1); - } - - /** - * @param textPane the textPane to set - */ - public void setTextPane(TextFilePane textPane) { - this.textPane = textPane; + setTop(mainToolbar); + setCenter(textPane); } } \ No newline at end of file diff --git a/filereader/MainToolbar.java b/filereader/MainToolbar.java index e41a891..a01b71f 100644 --- a/filereader/MainToolbar.java +++ b/filereader/MainToolbar.java @@ -12,9 +12,10 @@ public class MainToolbar extends HBox { private TextField pathField; + private static Button openButton; MainToolbar() { - Button openButton = new Button("Open"); + openButton = new Button("Open"); openButton.setOnAction(new OpenFileHandler()); pathField = new TextField(); @@ -26,12 +27,11 @@ class OpenFileHandler implements EventHandler { @Override public void handle(ActionEvent event) { FileChooser fileChooser = new FileChooser(); - Utils.currentFile = fileChooser.showOpenDialog(new Stage()); - pathField.setText(Utils.currentFile.toString()); + TextFileUtils.setCurrentFile(fileChooser.showOpenDialog(new Stage())); + pathField.setText(TextFileUtils.getCurrentFile().toString()); try { - TextFilePane.getOutputArea().setText(Utils.readFileLines(Utils.currentFile, (int) (GUI.newPrimaryStage.getHeight() / 17))); + TextFileUtils.readFileLines(TextFileUtils.getCurrentFile()); } catch (IOException e) { - // TODO Auto-generated catch block e.printStackTrace(); } } diff --git a/filereader/TextFilePane.java b/filereader/TextFilePane.java index 4a8e3e1..9b8d62e 100644 --- a/filereader/TextFilePane.java +++ b/filereader/TextFilePane.java @@ -1,21 +1,21 @@ package filereader; +import javafx.scene.control.TextArea; import javafx.scene.layout.BorderPane; -import javafx.scene.text.Text; public class TextFilePane extends BorderPane { - private static Text outputArea; + private static TextArea outputArea; TextFilePane() { - outputArea = new Text(); - outputArea.setFont(Utils.font); + outputArea = new TextArea(); + setCenter(outputArea); } - + /** * @return the output TextArea */ - public static Text getOutputArea() { + public static TextArea getOutputArea() { return outputArea; } } \ No newline at end of file diff --git a/filereader/TextFileUtils.java b/filereader/TextFileUtils.java new file mode 100644 index 0000000..83fed67 --- /dev/null +++ b/filereader/TextFileUtils.java @@ -0,0 +1,39 @@ +package filereader; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.Scanner; + +import javafx.scene.text.Font; + +public class TextFileUtils { + private static File currentFile; + + private TextFileUtils() {} + + public static String readFile(File file, int length) throws IOException { + char[] contents = new char[length]; + FileReader reader = new FileReader(file); + reader.read(contents); + reader.close(); + return new String(contents); + } + + public static void readFileLines(File file) throws IOException { + TextFilePane.getOutputArea().setText(""); + Scanner reader = new Scanner(file); + while (reader.hasNext()) { + TextFilePane.getOutputArea().setText(TextFilePane.getOutputArea().getText() + reader.nextLine() + "\n"); + } + reader.close(); + } + + public static File getCurrentFile() { + return currentFile; + } + + public static void setCurrentFile(File file) { + currentFile = file; + } +} \ No newline at end of file diff --git a/filereader/Utils.java b/filereader/Utils.java deleted file mode 100644 index 12222ba..0000000 --- a/filereader/Utils.java +++ /dev/null @@ -1,36 +0,0 @@ -package filereader; - -import java.io.File; -import java.io.FileReader; -import java.io.IOException; - -import javafx.scene.text.Font; - -public class Utils { - public static File currentFile; - public static Font font = new Font(12); - - private Utils() {} - - public static String readFile(File file, int length) throws IOException { - char[] contents = new char[length]; - FileReader reader = new FileReader(file); - reader.read(contents); - reader.close(); - return new String(contents); - } - - public static String readFileLines(File file, int numberOfLines) throws IOException { - String contents = ""; - FileReader reader = new FileReader(file); - int newlines = 0; - char temp; - while (newlines < numberOfLines && (temp = (char) reader.read()) != (char) -1) { - if (temp == Character.LINE_SEPARATOR) - newlines++; - contents += temp; - } - reader.close(); - return contents; - } -} \ No newline at end of file