From 60d90e22e22d6be0f83c040cbb04d877cee892f6 Mon Sep 17 00:00:00 2001 From: Eugene Date: Sun, 9 Feb 2020 23:49:10 +0800 Subject: [PATCH] Add About menu item. --- .../eugene/controller/ParquetDataParser.java | 3 +- .../java/org/eugene/controller/Renderer.java | 9 ++-- .../java/org/eugene/core/orc/ORCReader.java | 5 +- src/main/java/org/eugene/ui/AboutDialog.java | 49 +++++++++++++++++++ src/main/java/org/eugene/ui/Constants.java | 1 + .../java/org/eugene/ui/CustomizedMenuBar.java | 15 +++++- src/main/java/org/eugene/ui/Dashboard.java | 2 - .../org/eugene/ui/SelectPropertyDialog.java | 2 - src/main/java/org/eugene/ui/Table.java | 3 +- src/main/java/org/eugene/util/CSVWriter.java | 7 ++- .../java/org/eugene/util/TypeFetcher.java | 23 --------- 11 files changed, 75 insertions(+), 44 deletions(-) create mode 100644 src/main/java/org/eugene/ui/AboutDialog.java delete mode 100644 src/main/java/org/eugene/util/TypeFetcher.java diff --git a/src/main/java/org/eugene/controller/ParquetDataParser.java b/src/main/java/org/eugene/controller/ParquetDataParser.java index 18f90f3..3930838 100644 --- a/src/main/java/org/eugene/controller/ParquetDataParser.java +++ b/src/main/java/org/eugene/controller/ParquetDataParser.java @@ -7,6 +7,7 @@ import org.eugene.model.CommonData; import org.eugene.model.TableMeta; import org.eugene.persistent.VirtualDB; +import org.eugene.ui.Constants; import org.eugene.ui.Notifier; import java.util.ArrayList; @@ -47,7 +48,7 @@ public boolean parseData(Path path) { List commonRecord = new ArrayList<>(); for (int j = 0; j < columnNumber; j++) { if (record.get(j) == null){ - commonRecord.add("NULL"); + commonRecord.add(Constants.NULL); }else{ commonRecord.add(String.valueOf(record.get(j))); } diff --git a/src/main/java/org/eugene/controller/Renderer.java b/src/main/java/org/eugene/controller/Renderer.java index adb091d..232a4df 100644 --- a/src/main/java/org/eugene/controller/Renderer.java +++ b/src/main/java/org/eugene/controller/Renderer.java @@ -2,18 +2,15 @@ import javafx.stage.FileChooser; import javafx.stage.Stage; -import org.apache.avro.Schema; -import org.apache.avro.generic.GenericData; import org.apache.hadoop.fs.Path; -import org.eugene.core.parquet.ParquetReader; import org.eugene.model.CommonData; -import org.eugene.model.Parquet; import org.eugene.model.TableMeta; import org.eugene.persistent.VirtualDB; -import org.eugene.ui.*; +import org.eugene.ui.Dashboard; +import org.eugene.ui.Main; +import org.eugene.ui.Table; import java.io.File; -import java.util.ArrayList; import java.util.List; public class Renderer { diff --git a/src/main/java/org/eugene/core/orc/ORCReader.java b/src/main/java/org/eugene/core/orc/ORCReader.java index 8848937..a26cd3f 100644 --- a/src/main/java/org/eugene/core/orc/ORCReader.java +++ b/src/main/java/org/eugene/core/orc/ORCReader.java @@ -11,6 +11,7 @@ import org.eugene.model.CommonData; import org.eugene.model.TableMeta; import org.eugene.persistent.VirtualDB; +import org.eugene.ui.Constants; import org.eugene.ui.Notifier; import java.util.ArrayList; @@ -25,8 +26,6 @@ public boolean read(Path path){ //The JSON schema provided is illegal, so need to make it valid firstly schema = schema.replaceAll("(\"[\\w]+\"):([\\s]+[{]+)", "$1,$2"); RecordReader records = reader.rows(); - //These objects are the metadata for each column. They give you the type of each column and can parse it unless you - //want to parse each column yourself List fields = inspector.getAllStructFieldRefs(); List propertyList = new ArrayList<>(); int columnNumber = fields.size(); @@ -47,7 +46,7 @@ public boolean read(Path path){ record.add(field.toString()); } else{ - record.add("NULL"); + record.add(Constants.NULL); } } data.add(record); diff --git a/src/main/java/org/eugene/ui/AboutDialog.java b/src/main/java/org/eugene/ui/AboutDialog.java new file mode 100644 index 0000000..d802c07 --- /dev/null +++ b/src/main/java/org/eugene/ui/AboutDialog.java @@ -0,0 +1,49 @@ +package org.eugene.ui; + +import javafx.geometry.Insets; +import javafx.scene.control.ButtonType; +import javafx.scene.control.Dialog; +import javafx.scene.control.Hyperlink; +import javafx.scene.control.Label; +import javafx.scene.layout.VBox; + +import java.awt.*; +import java.net.URI; + +public class AboutDialog { + Dialog dialog = new Dialog(); + + public void init(){ + Label intro = new Label(); + intro.setText(" Currently supported format: "); + Label parquet = new Label(" - Parquet"); + Label orc = new Label(" - ORC"); + orc.setPadding(new Insets(0,0,5, 0)); + Label author = new Label(); + author.setText(" Author: " ); + Hyperlink github = new Hyperlink(); + github.setText(" github: Eugene"); + github.setOnAction(event -> { + try { + Desktop.getDesktop().browse(new URI("https://github.com/Eugene-Mark/")); + } catch (Exception e) { + e.printStackTrace(); + } + }); + Hyperlink so = new Hyperlink(); + so.setText(" stack overflow: Eugene"); + so.setOnAction(event -> { + try { + Desktop.getDesktop().browse(new URI("https://stackoverflow.com/users/3378204/eugene")); + } catch (Exception e) { + e.printStackTrace(); + } + }); + dialog.getDialogPane().setContent(new VBox(intro, parquet, orc, author, github, so)); + dialog.getDialogPane().getButtonTypes().addAll(ButtonType.CLOSE); + } + + public Dialog getDialog(){ + return dialog; + } +} diff --git a/src/main/java/org/eugene/ui/Constants.java b/src/main/java/org/eugene/ui/Constants.java index d7c08f6..4adc5b9 100644 --- a/src/main/java/org/eugene/ui/Constants.java +++ b/src/main/java/org/eugene/ui/Constants.java @@ -2,4 +2,5 @@ public class Constants { public static int MAX_ROW_NUM = 1000; + public static String NULL = "NULL"; } diff --git a/src/main/java/org/eugene/ui/CustomizedMenuBar.java b/src/main/java/org/eugene/ui/CustomizedMenuBar.java index 2e03543..4d9a509 100644 --- a/src/main/java/org/eugene/ui/CustomizedMenuBar.java +++ b/src/main/java/org/eugene/ui/CustomizedMenuBar.java @@ -7,7 +7,6 @@ import javafx.scene.paint.Color; import javafx.stage.FileChooser; import javafx.stage.Stage; -import org.apache.avro.generic.GenericData; import org.apache.hadoop.fs.Path; import org.eugene.controller.Renderer; import org.eugene.util.CSVWriter; @@ -102,6 +101,20 @@ public CustomizedMenuBar(Stage stage){ this.getMenus().add(file); this.getMenus().add(view); disableAll(); + + //About menu + Menu about = new Menu(); + about.setText("About"); + MenuItem aboutItem = new MenuItem(); + aboutItem.setText("About"); + aboutItem.setOnAction(event -> { + AboutDialog aboutDialog = new AboutDialog(); + aboutDialog.init(); + aboutDialog.getDialog().show(); + }); + about.getItems().add(aboutItem); + this.getMenus().add(about); + } private void disableAll(){ diff --git a/src/main/java/org/eugene/ui/Dashboard.java b/src/main/java/org/eugene/ui/Dashboard.java index 15be8bd..e6c22b8 100644 --- a/src/main/java/org/eugene/ui/Dashboard.java +++ b/src/main/java/org/eugene/ui/Dashboard.java @@ -14,8 +14,6 @@ import javafx.scene.text.Font; import javafx.scene.text.FontWeight; import javafx.stage.Stage; -import org.apache.avro.Schema; -import org.eugene.util.TypeFetcher; import java.io.File; import java.util.HashMap; diff --git a/src/main/java/org/eugene/ui/SelectPropertyDialog.java b/src/main/java/org/eugene/ui/SelectPropertyDialog.java index 1019dae..1ce6233 100644 --- a/src/main/java/org/eugene/ui/SelectPropertyDialog.java +++ b/src/main/java/org/eugene/ui/SelectPropertyDialog.java @@ -7,9 +7,7 @@ import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.stage.Stage; -import org.apache.avro.Schema; import org.eugene.controller.Renderer; -import org.eugene.controller.TableRenderer; import org.eugene.persistent.VirtualDB; import java.util.ArrayList; diff --git a/src/main/java/org/eugene/ui/Table.java b/src/main/java/org/eugene/ui/Table.java index d7aa90f..8976e69 100644 --- a/src/main/java/org/eugene/ui/Table.java +++ b/src/main/java/org/eugene/ui/Table.java @@ -9,7 +9,6 @@ import javafx.scene.control.TableView; import javafx.scene.layout.VBox; import javafx.stage.Stage; -import org.apache.avro.generic.GenericData; import java.util.ArrayList; import java.util.List; @@ -91,7 +90,7 @@ private void generatePage(List> data, TableView tableView, int page for (int j = 0; j < colNumber; j++){ if(showingList.contains(propertyList.get(j))){ if (r.get(j) == null){ - row.add(index, new SimpleStringProperty("NULL")); + row.add(index, new SimpleStringProperty(Constants.NULL)); } else{ row.add(index, new SimpleStringProperty(r.get(j).toString())); diff --git a/src/main/java/org/eugene/util/CSVWriter.java b/src/main/java/org/eugene/util/CSVWriter.java index 97a8b51..a4626e4 100644 --- a/src/main/java/org/eugene/util/CSVWriter.java +++ b/src/main/java/org/eugene/util/CSVWriter.java @@ -1,9 +1,8 @@ package org.eugene.util; -import org.apache.avro.Schema; -import org.apache.avro.generic.GenericData; import org.apache.hadoop.fs.Path; import org.eugene.persistent.VirtualDB; +import org.eugene.ui.Constants; import java.io.PrintWriter; import java.util.List; @@ -31,7 +30,7 @@ public static boolean write(Path path, List> data){ for (int i = 0; i < colNumber; i++) { if (i == (colNumber - 1)) { if (record.get(i) == null) - out.println("NULL"); + out.println(Constants.NULL); else { if (record.get(i).toString().contains(",")) { out.println("\"" + record.get(i) + "\""); @@ -41,7 +40,7 @@ public static boolean write(Path path, List> data){ } }else{ if (record.get(i) == null){ - out.print("NULL"); + out.print(Constants.NULL); } else{ if (record.get(i).toString().contains(",")){ diff --git a/src/main/java/org/eugene/util/TypeFetcher.java b/src/main/java/org/eugene/util/TypeFetcher.java deleted file mode 100644 index d7f3e24..0000000 --- a/src/main/java/org/eugene/util/TypeFetcher.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.eugene.util; - -public class TypeFetcher { - private final static String INT = "int"; - private final static String LONG = "long"; - private final static String DOUBLE = "double"; - private final static String FLOAT = "float"; - private final static String STRING = "string"; - - public static String getType(String schema){ - if (schema.contains(INT)) - return INT; - if (schema.contains(LONG)) - return LONG; - if (schema.contains(DOUBLE)) - return DOUBLE; - if (schema.contains(FLOAT)) - return FLOAT; - if (schema.contains(STRING)) - return STRING; - return ""; - } -}