diff --git a/resources/fxml/WebBrowserTabContextMenu.fxml b/resources/fxml/WebBrowserTabContextMenu.fxml
new file mode 100644
index 0000000..e61664a
--- /dev/null
+++ b/resources/fxml/WebBrowserTabContextMenu.fxml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/application/ApplicationMain.java b/src/application/ApplicationMain.java
deleted file mode 100644
index 5414e4b..0000000
--- a/src/application/ApplicationMain.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see .
-
- Also(warning!):
-
- 1)You are not allowed to sell this product to third party.
- 2)You can't change license and made it like you are the owner,author etc.
- 3)All redistributions of source code files must contain all copyright
- notices that are currently in this file, and this list of conditions without
- modification.
- */
-
-
-package application;
-
-import javafx.application.Application;
-import javafx.scene.Scene;
-import javafx.scene.layout.BorderPane;
-import javafx.stage.Screen;
-import javafx.stage.Stage;
-
-/**
- * From here you start the application
- *
- * @author GOXR3PLUS STUDIO ( your bro! )
- *
- */
-public class ApplicationMain extends Application {
-
- /* (non-Javadoc)
- * @see javafx.application.Application#start(javafx.stage.Stage)
- */
- @Override
- public void start(Stage primaryStage) {
-
- //Root
- BorderPane root = new BorderPane();
- root.setCenter(new WebBrowserController());
-
- //Scene
- Scene scene = new Scene(root, getVisualScreenWidth() / 1.2, getVisualScreenHeight() / 1.2);
-
- //Prepare the Stage
- primaryStage.setTitle("JavaFX WebBrowser Made By GOXR3PLUS STUDIO :) ");
- primaryStage.setScene(scene);
- primaryStage.show();
-
- }
-
- /**
- * Gets the visual screen width.
- *
- * @return The screen Width based on the visual bounds of the Screen.These bounds account for objects in the native windowing system
- * such as task bars and menu bars. These bounds are contained by Screen.bounds.
- */
- public static double getVisualScreenWidth() {
- return Screen.getPrimary().getVisualBounds().getWidth();
- }
-
- /**
- * Gets the visual screen height.
- *
- * @return The screen Height based on the visual bounds of the Screen.These bounds account for objects in the native windowing
- * system such as task bars and menu bars. These bounds are contained by Screen.bounds.
- */
- public static double getVisualScreenHeight() {
- return Screen.getPrimary().getVisualBounds().getHeight();
- }
-
- /**
- * Main Method
- *
- * @param args
- */
- public static void main(String[] args) {
- launch(args);
- }
-}
diff --git a/src/main/java/com/goxr3plus/JavaFXWebBrowser/application/Main.java b/src/main/java/com/goxr3plus/JavaFXWebBrowser/application/Main.java
new file mode 100644
index 0000000..5500c92
--- /dev/null
+++ b/src/main/java/com/goxr3plus/JavaFXWebBrowser/application/Main.java
@@ -0,0 +1,87 @@
+/*
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version. This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details. You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ * Also(warning!): 1)You are not allowed to sell this product to third party.
+ * 2)You can't change license and made it like you are the owner,author etc.
+ * 3)All redistributions of source code files must contain all copyright notices
+ * that are currently in this file, and this list of conditions without
+ * modification.
+ */
+
+package main.java.com.goxr3plus.JavaFXWebBrowser.application;
+
+import javafx.application.Application;
+import javafx.scene.Scene;
+import javafx.scene.layout.BorderPane;
+import javafx.stage.Screen;
+import javafx.stage.Stage;
+import main.java.com.goxr3plus.JavaFXWebBrowser.browser.WebBrowserController;
+
+/**
+ * From here you start the application
+ *
+ * @author GOXR3PLUS STUDIO ( your bro! )
+ *
+ */
+public class Main extends Application {
+
+ /*
+ * (non-Javadoc)
+ * @see javafx.application.Application#start(javafx.stage.Stage)
+ */
+ @Override
+ public void start(Stage primaryStage) {
+
+ //Root
+ BorderPane root = new BorderPane();
+ root.setCenter(new WebBrowserController());
+
+ //Scene
+ Scene scene = new Scene(root, getVisualScreenWidth() / 1.2, getVisualScreenHeight() / 1.2);
+
+ //Prepare the Stage
+ primaryStage.setTitle("JavaFX WebBrowser Made By GOXR3PLUS STUDIO :) ");
+ primaryStage.setScene(scene);
+ primaryStage.show();
+
+ }
+
+ /**
+ * Gets the visual screen width.
+ *
+ * @return The screen Width based on the visual bounds of the
+ * Screen.These bounds account for objects in the native windowing
+ * system such as task bars and menu bars. These bounds are
+ * contained by Screen.bounds.
+ */
+ public static double getVisualScreenWidth() {
+ return Screen.getPrimary().getVisualBounds().getWidth();
+ }
+
+ /**
+ * Gets the visual screen height.
+ *
+ * @return The screen Height based on the visual bounds of the
+ * Screen.These bounds account for objects in the native windowing
+ * system such as task bars and menu bars. These bounds are
+ * contained by Screen.bounds.
+ */
+ public static double getVisualScreenHeight() {
+ return Screen.getPrimary().getVisualBounds().getHeight();
+ }
+
+ /**
+ * Main Method
+ *
+ * @param args
+ */
+ public static void main(String[] args) {
+ launch(args);
+ }
+}
diff --git a/src/application/AutoCompleteTextField.java b/src/main/java/com/goxr3plus/JavaFXWebBrowser/browser/AutoCompleteTextField.java
similarity index 99%
rename from src/application/AutoCompleteTextField.java
rename to src/main/java/com/goxr3plus/JavaFXWebBrowser/browser/AutoCompleteTextField.java
index c2112dd..85f021e 100644
--- a/src/application/AutoCompleteTextField.java
+++ b/src/main/java/com/goxr3plus/JavaFXWebBrowser/browser/AutoCompleteTextField.java
@@ -1,7 +1,7 @@
/*
*
*/
-package application;
+package main.java.com.goxr3plus.JavaFXWebBrowser.browser;
import java.util.List;
import java.util.SortedSet;
diff --git a/src/application/WebBrowserController.java b/src/main/java/com/goxr3plus/JavaFXWebBrowser/browser/WebBrowserController.java
similarity index 96%
rename from src/application/WebBrowserController.java
rename to src/main/java/com/goxr3plus/JavaFXWebBrowser/browser/WebBrowserController.java
index 2c05238..61dc6bc 100644
--- a/src/application/WebBrowserController.java
+++ b/src/main/java/com/goxr3plus/JavaFXWebBrowser/browser/WebBrowserController.java
@@ -1,4 +1,7 @@
-package application;
+/**
+ * TODO LISENSE
+ */
+package main.java.com.goxr3plus.JavaFXWebBrowser.browser;
import java.io.IOException;
import java.util.Arrays;
@@ -6,6 +9,7 @@
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
+import java.util.stream.Collectors;
import com.jfoenix.controls.JFXButton;
@@ -14,6 +18,7 @@
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.StackPane;
+import main.java.com.goxr3plus.JavaFXWebBrowser.tools.InfoTool;
/**
* @author GOXR3PLUS
@@ -40,7 +45,7 @@ public class WebBrowserController extends StackPane {
public WebBrowserController() {
// ------------------------------------FXMLLOADER ----------------------------------------
- FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/WebBrowserController.fxml"));
+ FXMLLoader loader = new FXMLLoader(getClass().getResource(InfoTool.FXMLS + "WebBrowserController.fxml"));
loader.setController(this);
loader.setRoot(this);
@@ -91,10 +96,10 @@ public WebBrowserTabController createNewTab(String... webSite) {
//Create
Tab tab = new Tab("");
WebBrowserTabController webBrowserTab = new WebBrowserTabController(this, tab, webSite.length == 0 ? null : webSite[0]);
- tab.setOnCloseRequest(c -> {
+ tab.setOnClosed(c -> {
//Check the tabs number
- if (tabPane.getTabs().size() == 1)
+ if (tabPane.getTabs().isEmpty())
createAndAddNewTab();
// Delete cache for navigate back
@@ -108,6 +113,60 @@ public WebBrowserTabController createNewTab(String... webSite) {
return webBrowserTab;
}
+ /**
+ * Closes the tabs to the right of the given Tab
+ *
+ * @param tab
+ */
+ public void closeTabsToTheRight(Tab givenTab) {
+ //Return if size <= 1
+ if (tabPane.getTabs().size() <= 1)
+ return;
+
+ //The start
+ int start = tabPane.getTabs().indexOf(givenTab);
+
+ //Remove the appropriate items
+ tabPane.getTabs().stream()
+ //filter
+ .filter(tab -> tabPane.getTabs().indexOf(tab) > start)
+ //Collect the all to a list
+ .collect(Collectors.toList()).forEach(this::removeTab);
+
+ }
+
+ /**
+ * Closes the tabs to the left of the given Tab
+ *
+ * @param tab
+ */
+ public void closeTabsToTheLeft(Tab givenTab) {
+ //Return if size <= 1
+ if (tabPane.getTabs().size() <= 1)
+ return;
+
+ //The start
+ int start = tabPane.getTabs().indexOf(givenTab);
+
+ //Remove the appropriate items
+ tabPane.getTabs().stream()
+ //filter
+ .filter(tab -> tabPane.getTabs().indexOf(tab) < start)
+ //Collect the all to a list
+ .collect(Collectors.toList()).forEach(this::removeTab);
+
+ }
+
+ /**
+ * Removes this Tab from the TabPane
+ *
+ * @param tab
+ */
+ public void removeTab(Tab tab) {
+ tabPane.getTabs().remove(tab);
+ tab.getOnClosed().handle(null);
+ }
+
/**
* @return the tabPane
*/
diff --git a/src/main/java/com/goxr3plus/JavaFXWebBrowser/browser/WebBrowserTabContextMenu.java b/src/main/java/com/goxr3plus/JavaFXWebBrowser/browser/WebBrowserTabContextMenu.java
new file mode 100644
index 0000000..9ad5299
--- /dev/null
+++ b/src/main/java/com/goxr3plus/JavaFXWebBrowser/browser/WebBrowserTabContextMenu.java
@@ -0,0 +1,95 @@
+package main.java.com.goxr3plus.JavaFXWebBrowser.browser;
+
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javafx.fxml.FXML;
+import javafx.fxml.FXMLLoader;
+import javafx.scene.control.ContextMenu;
+import javafx.scene.control.MenuItem;
+import main.java.com.goxr3plus.JavaFXWebBrowser.tools.InfoTool;
+
+public class WebBrowserTabContextMenu extends ContextMenu {
+
+ //--------------------------------------------------------------
+
+ @FXML
+ private MenuItem newTab;
+
+ @FXML
+ private MenuItem reloadTab;
+
+ @FXML
+ private MenuItem closeOtherTabs;
+
+ @FXML
+ private MenuItem closeTabsRight;
+
+ @FXML
+ private MenuItem closeTabsLeft;
+
+ @FXML
+ private MenuItem closeTab;
+
+ // -------------------------------------------------------------
+
+ /** The logger. */
+ private final Logger logger = Logger.getLogger(getClass().getName());
+
+ private final WebBrowserTabController webBrowserTabController;
+
+ private final WebBrowserController webBrowserController;
+
+ /**
+ * Constructor
+ *
+ * @param tab
+ * @param webBrowserController
+ */
+ public WebBrowserTabContextMenu(WebBrowserTabController webBrowserTabController, WebBrowserController webBrowserController) {
+ this.webBrowserTabController = webBrowserTabController;
+ this.webBrowserController = webBrowserController;
+
+ // ------------------------------------FXMLLOADER ----------------------------------------
+ FXMLLoader loader = new FXMLLoader(getClass().getResource(InfoTool.FXMLS + "WebBrowserTabContextMenu.fxml"));
+ loader.setController(this);
+ loader.setRoot(this);
+
+ try {
+ loader.load();
+ } catch (IOException ex) {
+ logger.log(Level.SEVERE, "", ex);
+ }
+
+ }
+
+ /**
+ * Called as soon as .FXML is loaded from FXML Loader
+ */
+ @FXML
+ private void initialize() {
+
+ //newTab
+ newTab.setOnAction(a -> webBrowserController.createAndAddNewTab());
+
+ //reloadTab
+ reloadTab.setOnAction(a -> webBrowserTabController.reloadWebSite());
+
+ //closeTabsRight
+ closeTabsRight.setOnAction(a -> webBrowserController.closeTabsToTheRight(webBrowserTabController.getTab()));
+
+ //closeTabsLeft
+ closeTabsLeft.setOnAction(a -> webBrowserController.closeTabsToTheLeft(webBrowserTabController.getTab()));
+
+ //closeOtherTabs
+ closeOtherTabs.setOnAction(a -> {
+ webBrowserController.closeTabsToTheLeft(webBrowserTabController.getTab());
+ webBrowserController.closeTabsToTheRight(webBrowserTabController.getTab());
+ });
+
+ //closeTab
+ closeTab.setOnAction(a -> webBrowserController.removeTab(webBrowserTabController.getTab()));
+
+ }
+}
diff --git a/src/application/WebBrowserTabController.java b/src/main/java/com/goxr3plus/JavaFXWebBrowser/browser/WebBrowserTabController.java
similarity index 92%
rename from src/application/WebBrowserTabController.java
rename to src/main/java/com/goxr3plus/JavaFXWebBrowser/browser/WebBrowserTabController.java
index 3b0a779..f68aab1 100644
--- a/src/application/WebBrowserTabController.java
+++ b/src/main/java/com/goxr3plus/JavaFXWebBrowser/browser/WebBrowserTabController.java
@@ -1,5 +1,7 @@
-
-package application;
+/**
+ *
+ */
+package main.java.com.goxr3plus.JavaFXWebBrowser.browser;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
@@ -33,12 +35,13 @@
import javafx.scene.web.WebHistory;
import javafx.scene.web.WebHistory.Entry;
import javafx.scene.web.WebView;
-import marquee.Marquee;
+import main.java.com.goxr3plus.JavaFXWebBrowser.marquee.Marquee;
+import main.java.com.goxr3plus.JavaFXWebBrowser.tools.InfoTool;
/**
* This class represents a Tab from The WebBrowser
*
- * @author GOXR3PLUS STUDIO
+ * @author GOXR3PLUS
*
*/
public class WebBrowserTabController extends StackPane {
@@ -108,7 +111,7 @@ public WebBrowserTabController(WebBrowserController webBrowserController, Tab ta
this.tab.setContent(this);
// ------------------------------------FXMLLOADER ----------------------------------------
- FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/WebBrowserTabController.fxml"));
+ FXMLLoader loader = new FXMLLoader(getClass().getResource(InfoTool.FXMLS + "WebBrowserTabController.fxml"));
loader.setController(this);
loader.setRoot(this);
@@ -191,6 +194,9 @@ private void initialize() {
hBox.getChildren().addAll(stack, marquee);
tab.setGraphic(hBox);
+ //ContextMenu
+ tab.setContextMenu(new WebBrowserTabContextMenu(this,webBrowserController));
+
//-------------------Items------------------------
//searchBar
@@ -371,7 +377,7 @@ void checkForInternetConnection() {
//Check for internet connection
Thread thread = new Thread(() -> {
- boolean hasInternet = isReachableByPing("www.google.com");
+ boolean hasInternet = InfoTool.isReachableByPing("www.google.com");
Platform.runLater(() -> {
errorPane.setVisible(!hasInternet);
if (hasInternet)
@@ -397,29 +403,4 @@ public void setHistory(WebHistory history) {
this.history = history;
}
- /**
- * Checks if a web site is reachable using ping command.
- *
- * @param host
- * the host
- * @return true if Connected on Internet, false if not.
- */
- public static boolean isReachableByPing(String host) {
- try {
-
- // Start a new Process
- Process process = Runtime.getRuntime().exec("ping -" + ( System.getProperty("os.name").toLowerCase().startsWith("windows") ? "n" : "c" ) + " 1 " + host);
-
- //Wait for it to finish
- process.waitFor();
-
- //Check the return value
- return process.exitValue() == 0;
-
- } catch (Exception ex) {
- Logger.getLogger(WebBrowserTabController.class.getName()).log(Level.INFO, null, ex);
- return false;
- }
- }
-
}
diff --git a/src/marquee/Marquee.java b/src/main/java/com/goxr3plus/JavaFXWebBrowser/marquee/Marquee.java
similarity index 98%
rename from src/marquee/Marquee.java
rename to src/main/java/com/goxr3plus/JavaFXWebBrowser/marquee/Marquee.java
index ef57edf..94d4e00 100644
--- a/src/marquee/Marquee.java
+++ b/src/main/java/com/goxr3plus/JavaFXWebBrowser/marquee/Marquee.java
@@ -21,7 +21,7 @@
modification.
*/
-package marquee;
+package main.java.com.goxr3plus.JavaFXWebBrowser.marquee;
import java.io.IOException;
diff --git a/src/main/java/com/goxr3plus/JavaFXWebBrowser/tools/InfoTool.java b/src/main/java/com/goxr3plus/JavaFXWebBrowser/tools/InfoTool.java
new file mode 100644
index 0000000..88cb38f
--- /dev/null
+++ b/src/main/java/com/goxr3plus/JavaFXWebBrowser/tools/InfoTool.java
@@ -0,0 +1,164 @@
+/*
+ *
+ */
+package main.java.com.goxr3plus.JavaFXWebBrowser.tools;
+
+import java.io.File;
+import java.net.URISyntaxException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javafx.scene.image.Image;
+import main.java.com.goxr3plus.JavaFXWebBrowser.application.Main;
+
+/**
+ * Provides useful methods for retrieving informations.
+ *
+ * @author GOXR3PLUS
+ */
+public final class InfoTool {
+
+ /** Logger */
+ public static final Logger logger = Logger.getLogger(InfoTool.class.getName());
+
+ /** WebSite url */
+ public static final String WEBSITE = "http://goxr3plus.co.nf";
+
+ /** XR3Player Tutorials */
+ public static final String TUTORIALS = "https://www.youtube.com/playlist?list=PL-xqaiRUr_iRKDkpFWPfSRFmJvHSr1VJI";
+
+ /** The Constant images. */
+ public static final String IMAGES = "/image/";
+
+ /** The Constant styLes. */
+ public static final String STYLES = "/style/";
+
+ /** The Constant applicationCss. */
+ public static final String APPLICATIONCSS = "application.css";
+
+ /** The Constant fxmls. */
+ public static final String FXMLS = "/fxml/";
+
+ // --------------------------------------------------------------------------------------------------------------
+
+ /**
+ * Private Constructor , we don't want instances of this class
+ */
+ private InfoTool() {
+ }
+
+ /**
+ * Returns the absolute path of the current directory in which the given
+ * class file is.
+ *
+ * @param classs
+ * * @return The absolute path of the current directory in which the
+ * class file is. [it ends with File.Separator!!]
+ * @author GOXR3PLUS[StackOverFlow user] + bachden [StackOverFlow user]
+ */
+ public static final String getBasePathForClass(Class> classs) {
+
+ // Local variables
+ File file;
+ String basePath = "";
+ boolean failed = false;
+
+ // Let's give a first try
+ try {
+ file = new File(classs.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
+
+ basePath = ( file.isFile() || file.getPath().endsWith(".jar") || file.getPath().endsWith(".zip") ) ? file.getParent() : file.getPath();
+ } catch (URISyntaxException ex) {
+ failed = true;
+ Logger.getLogger(classs.getName()).log(Level.WARNING, "Cannot firgue out base path for class with way (1): ", ex);
+ }
+
+ // The above failed?
+ if (failed)
+ try {
+ file = new File(classs.getClassLoader().getResource("").toURI().getPath());
+ basePath = file.getAbsolutePath();
+
+ // the below is for testing purposes...
+ // starts with File.separator?
+ // String l = local.replaceFirst("[" + File.separator +
+ // "/\\\\]", "")
+ } catch (URISyntaxException ex) {
+ Logger.getLogger(classs.getName()).log(Level.WARNING, "Cannot firgue out base path for class with way (2): ", ex);
+ }
+
+ // fix to run inside Eclipse
+ if (basePath.endsWith(File.separator + "lib") || basePath.endsWith(File.separator + "bin") || basePath.endsWith("bin" + File.separator)
+ || basePath.endsWith("lib" + File.separator)) {
+ basePath = basePath.substring(0, basePath.length() - 4);
+ }
+ // fix to run inside NetBeans
+ if (basePath.endsWith(File.separator + "build" + File.separator + "classes")) {
+ basePath = basePath.substring(0, basePath.length() - 14);
+ }
+ // end fix
+ if (!basePath.endsWith(File.separator))
+ basePath += File.separator;
+
+ return basePath;
+ }
+
+ /**
+ * Checks if a web site is reachable using ping command.
+ *
+ * @param host
+ * the host
+ * @return true if Connected on Internet, false if not.
+ */
+ public static boolean isReachableByPing(String host) {
+ try {
+
+ // Start a new Process
+ Process process = Runtime.getRuntime().exec("ping -" + ( System.getProperty("os.name").toLowerCase().startsWith("windows") ? "n" : "c" ) + " 1 " + host);
+
+ //Wait for it to finish
+ process.waitFor();
+
+ //Check the return value
+ return process.exitValue() == 0;
+
+ } catch (Exception ex) {
+ Logger.getLogger(Main.class.getName()).log(Level.INFO, null, ex);
+ return false;
+ }
+ }
+
+ /**
+ * Use this method to retrieve an image from the resources of the
+ * application.
+ *
+ * @param imageName
+ * the image name
+ * @return Returns an image which is already into the resources folder of
+ * the application
+ */
+ public static Image getImageFromResourcesFolder(String imageName) {
+ return new Image(InfoTool.class.getResourceAsStream(IMAGES + imageName));
+ }
+
+ /**
+ * Gets the file size edited in format "x MiB , y KiB"
+ *
+ * @param bytes
+ * File size in bytes
+ * @return a String representing the file size in MB and kB
+ */
+ public static String getFileSizeEdited(long bytes) {
+
+ //Find it
+ int kilobytes = (int) ( bytes / 1024 ) , megabytes = kilobytes / 1024;
+ if (kilobytes < 1024)
+ return kilobytes + " KiB";
+ else if (kilobytes > 1024)
+ return megabytes + " MiB + " + ( kilobytes - ( megabytes * 1024 ) ) + " KiB";
+
+ return "error";
+
+ }
+
+}