commit a3febe61068367c5a2560ca1e92d152305890e33 Author: free will <2647778488@qq.com> Date: Thu Oct 15 22:04:45 2020 +0800 实现了基本的浏览器操作;测试了本地html加载 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2bb016e --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.git/ +.gradle/ +.idea/ +out/ diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..f7c4f0b --- /dev/null +++ b/build.gradle @@ -0,0 +1,44 @@ +plugins { + id 'java' + id 'org.openjfx.javafxplugin' version '0.0.5' +} + +apply plugin: 'java' +apply plugin: 'org.openjfx.javafxplugin' +group 'PKUSZ' +version '0.1' + +sourceCompatibility = 11 +targetCompatibility = 11 + +//指定编译编码 +tasks.withType(JavaCompile){ + options.encoding="UTF-8" +} + +repositories { + maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'} +// mavenCentral() +} + +dependencies { + testCompile group: 'junit', name: 'junit', version: '4.12' + compile fileTree(dir: 'lib',includes: ['*jar']) + compile 'com.blankj:utilcode:1.10.0' +} + +javafx { + version = "11.0.2" + modules = [ 'javafx.controls','javafx.fxml','javafx.web' ] +} + +jar{ + manifestContentCharset 'utf-8' + metadataCharset 'utf-8' + manifest{ + attributes "Main-Class": "cn.minbrowser.Main" + } + from{ + configurations.compile.collect{it.isDirectory()?it:zipTree(it)} + } +} diff --git a/resources/images/about_me.png b/resources/images/about_me.png new file mode 100644 index 0000000..668afe8 Binary files /dev/null and b/resources/images/about_me.png differ diff --git a/resources/images/cloud_file.png b/resources/images/cloud_file.png new file mode 100644 index 0000000..b03c3e0 Binary files /dev/null and b/resources/images/cloud_file.png differ diff --git a/resources/images/delete.png b/resources/images/delete.png new file mode 100644 index 0000000..66f2e44 Binary files /dev/null and b/resources/images/delete.png differ diff --git a/resources/images/emailFileIcon/f.png b/resources/images/emailFileIcon/f.png new file mode 100644 index 0000000..ed4b5c5 Binary files /dev/null and b/resources/images/emailFileIcon/f.png differ diff --git a/resources/images/entry_examination.png b/resources/images/entry_examination.png new file mode 100644 index 0000000..22c4bff Binary files /dev/null and b/resources/images/entry_examination.png differ diff --git a/resources/images/evection.png b/resources/images/evection.png new file mode 100644 index 0000000..4751a43 Binary files /dev/null and b/resources/images/evection.png differ diff --git a/resources/images/headPhotos/MYGOD.png b/resources/images/headPhotos/MYGOD.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/MYGOD.png differ diff --git a/resources/images/headPhotos/byj.png b/resources/images/headPhotos/byj.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/byj.png differ diff --git a/resources/images/headPhotos/default.png b/resources/images/headPhotos/default.png new file mode 100644 index 0000000..ea96cb0 Binary files /dev/null and b/resources/images/headPhotos/default.png differ diff --git a/resources/images/headPhotos/oa_wefree.png b/resources/images/headPhotos/oa_wefree.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/oa_wefree.png differ diff --git a/resources/images/headPhotos/qjm253.png b/resources/images/headPhotos/qjm253.png new file mode 100644 index 0000000..aac9272 Binary files /dev/null and b/resources/images/headPhotos/qjm253.png differ diff --git a/resources/images/headPhotos/qjm254.png b/resources/images/headPhotos/qjm254.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/qjm254.png differ diff --git a/resources/images/headPhotos/qjm5.png b/resources/images/headPhotos/qjm5.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/qjm5.png differ diff --git a/resources/images/headPhotos/test111.png b/resources/images/headPhotos/test111.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/test111.png differ diff --git a/resources/images/headPhotos/testKey_v1.png b/resources/images/headPhotos/testKey_v1.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/testKey_v1.png differ diff --git a/resources/images/headPhotos/testKey_v2.png b/resources/images/headPhotos/testKey_v2.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/testKey_v2.png differ diff --git a/resources/images/headPhotos/testKey_v3.png b/resources/images/headPhotos/testKey_v3.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/testKey_v3.png differ diff --git a/resources/images/headPhotos/wefree.png b/resources/images/headPhotos/wefree.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/wefree.png differ diff --git a/resources/images/headPhotos/wefree70.png b/resources/images/headPhotos/wefree70.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/wefree70.png differ diff --git a/resources/images/headPhotos/wefree73.png b/resources/images/headPhotos/wefree73.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/wefree73.png differ diff --git a/resources/images/headPhotos/wefree_aac.png b/resources/images/headPhotos/wefree_aac.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/wefree_aac.png differ diff --git a/resources/images/headPhotos/wf.png b/resources/images/headPhotos/wf.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/wf.png differ diff --git a/resources/images/headPhotos/wf0.png b/resources/images/headPhotos/wf0.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/wf0.png differ diff --git a/resources/images/headPhotos/wf002.png b/resources/images/headPhotos/wf002.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/wf002.png differ diff --git a/resources/images/headPhotos/wf003.png b/resources/images/headPhotos/wf003.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/wf003.png differ diff --git a/resources/images/headPhotos/wf004.png b/resources/images/headPhotos/wf004.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/wf004.png differ diff --git a/resources/images/headPhotos/wf0977.png b/resources/images/headPhotos/wf0977.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/wf0977.png differ diff --git a/resources/images/headPhotos/wf123.png b/resources/images/headPhotos/wf123.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/wf123.png differ diff --git a/resources/images/headPhotos/wf2.png b/resources/images/headPhotos/wf2.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/wf2.png differ diff --git a/resources/images/headPhotos/wf3.png b/resources/images/headPhotos/wf3.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/wf3.png differ diff --git a/resources/images/headPhotos/wf9.png b/resources/images/headPhotos/wf9.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/wf9.png differ diff --git a/resources/images/headPhotos/wf972.png b/resources/images/headPhotos/wf972.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/wf972.png differ diff --git a/resources/images/headPhotos/wf974.png b/resources/images/headPhotos/wf974.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/wf974.png differ diff --git a/resources/images/headPhotos/wf976.png b/resources/images/headPhotos/wf976.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/wf976.png differ diff --git a/resources/images/headPhotos/wf977.png b/resources/images/headPhotos/wf977.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/wf977.png differ diff --git a/resources/images/headPhotos/wf978.png b/resources/images/headPhotos/wf978.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/wf978.png differ diff --git a/resources/images/headPhotos/wf979.png b/resources/images/headPhotos/wf979.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/wf979.png differ diff --git a/resources/images/headPhotos/wgh1.png b/resources/images/headPhotos/wgh1.png new file mode 100644 index 0000000..de71a9e Binary files /dev/null and b/resources/images/headPhotos/wgh1.png differ diff --git a/resources/images/headPhotos/wgh2.png b/resources/images/headPhotos/wgh2.png new file mode 100644 index 0000000..a092c9f Binary files /dev/null and b/resources/images/headPhotos/wgh2.png differ diff --git a/resources/images/headPhotos/wgh3.png b/resources/images/headPhotos/wgh3.png new file mode 100644 index 0000000..ea96cb0 Binary files /dev/null and b/resources/images/headPhotos/wgh3.png differ diff --git a/resources/images/headPhotos/wgh333.png b/resources/images/headPhotos/wgh333.png new file mode 100644 index 0000000..ea96cb0 Binary files /dev/null and b/resources/images/headPhotos/wgh333.png differ diff --git a/resources/images/headPhotos/wgh4.png b/resources/images/headPhotos/wgh4.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/wgh4.png differ diff --git a/resources/images/headPhotos/wgh43.png b/resources/images/headPhotos/wgh43.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/wgh43.png differ diff --git a/resources/images/headPhotos/wgh45.png b/resources/images/headPhotos/wgh45.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/wgh45.png differ diff --git a/resources/images/headPhotos/wgh49.png b/resources/images/headPhotos/wgh49.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/wgh49.png differ diff --git a/resources/images/headPhotos/wgh5.png b/resources/images/headPhotos/wgh5.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/wgh5.png differ diff --git a/resources/images/headPhotos/wgh6.png b/resources/images/headPhotos/wgh6.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/wgh6.png differ diff --git a/resources/images/headPhotos/wihteabcc.png b/resources/images/headPhotos/wihteabcc.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/wihteabcc.png differ diff --git a/resources/images/headPhotos/yinfeng.png b/resources/images/headPhotos/yinfeng.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/yinfeng.png differ diff --git a/resources/images/headPhotos/王锋.png b/resources/images/headPhotos/王锋.png new file mode 100644 index 0000000..8b8296b Binary files /dev/null and b/resources/images/headPhotos/王锋.png differ diff --git a/resources/images/ic_launcher-web.png b/resources/images/ic_launcher-web.png new file mode 100644 index 0000000..2128b74 Binary files /dev/null and b/resources/images/ic_launcher-web.png differ diff --git a/resources/images/index.png b/resources/images/index.png new file mode 100644 index 0000000..8dded7b Binary files /dev/null and b/resources/images/index.png differ diff --git a/resources/images/leave_office.png b/resources/images/leave_office.png new file mode 100644 index 0000000..14ea2d9 Binary files /dev/null and b/resources/images/leave_office.png differ diff --git a/resources/images/logo.png b/resources/images/logo.png new file mode 100644 index 0000000..b877cba Binary files /dev/null and b/resources/images/logo.png differ diff --git a/resources/images/logo_mini.png b/resources/images/logo_mini.png new file mode 100644 index 0000000..2128b74 Binary files /dev/null and b/resources/images/logo_mini.png differ diff --git a/resources/images/mImage/left.png b/resources/images/mImage/left.png new file mode 100644 index 0000000..03bae87 Binary files /dev/null and b/resources/images/mImage/left.png differ diff --git a/resources/images/mImage/right.png b/resources/images/mImage/right.png new file mode 100644 index 0000000..ce1052c Binary files /dev/null and b/resources/images/mImage/right.png differ diff --git a/resources/images/mImage/test_headPhoto.png b/resources/images/mImage/test_headPhoto.png new file mode 100644 index 0000000..2128b74 Binary files /dev/null and b/resources/images/mImage/test_headPhoto.png differ diff --git a/resources/images/mail_list.png b/resources/images/mail_list.png new file mode 100644 index 0000000..077a98f Binary files /dev/null and b/resources/images/mail_list.png differ diff --git a/resources/images/message.png b/resources/images/message.png new file mode 100644 index 0000000..d62c112 Binary files /dev/null and b/resources/images/message.png differ diff --git a/resources/images/message_list.png b/resources/images/message_list.png new file mode 100644 index 0000000..077a98f Binary files /dev/null and b/resources/images/message_list.png differ diff --git a/resources/images/mine.png b/resources/images/mine.png new file mode 100644 index 0000000..96fdbc6 Binary files /dev/null and b/resources/images/mine.png differ diff --git a/resources/images/myFileIcon/d.png b/resources/images/myFileIcon/d.png new file mode 100644 index 0000000..1ad79a4 Binary files /dev/null and b/resources/images/myFileIcon/d.png differ diff --git a/resources/images/myFileIcon/f.png b/resources/images/myFileIcon/f.png new file mode 100644 index 0000000..ed4b5c5 Binary files /dev/null and b/resources/images/myFileIcon/f.png differ diff --git a/resources/images/myFileIcon/o.png b/resources/images/myFileIcon/o.png new file mode 100644 index 0000000..71c7015 Binary files /dev/null and b/resources/images/myFileIcon/o.png differ diff --git a/resources/images/notification.png b/resources/images/notification.png new file mode 100644 index 0000000..81a2951 Binary files /dev/null and b/resources/images/notification.png differ diff --git a/resources/images/pku.jpg b/resources/images/pku.jpg new file mode 100644 index 0000000..092dcdf Binary files /dev/null and b/resources/images/pku.jpg differ diff --git a/resources/images/pku_m.png b/resources/images/pku_m.png new file mode 100644 index 0000000..502bbc4 Binary files /dev/null and b/resources/images/pku_m.png differ diff --git a/resources/images/reimbursement.png b/resources/images/reimbursement.png new file mode 100644 index 0000000..2721176 Binary files /dev/null and b/resources/images/reimbursement.png differ diff --git a/resources/images/setting_gear.png b/resources/images/setting_gear.png new file mode 100644 index 0000000..766883b Binary files /dev/null and b/resources/images/setting_gear.png differ diff --git a/resources/images/user.png b/resources/images/user.png new file mode 100644 index 0000000..7eae402 Binary files /dev/null and b/resources/images/user.png differ diff --git a/resources/images/work_summary.png b/resources/images/work_summary.png new file mode 100644 index 0000000..18dc55f Binary files /dev/null and b/resources/images/work_summary.png differ diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..d457916 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'MINBrowser' + diff --git a/src/main/java/cn/minbrowser/Main.java b/src/main/java/cn/minbrowser/Main.java new file mode 100644 index 0000000..6e68f8d --- /dev/null +++ b/src/main/java/cn/minbrowser/Main.java @@ -0,0 +1,13 @@ +package cn.minbrowser; + +/* + * @author wefree + */ + +import javafx.application.Application; + +public class Main { + public static void main(String[] args) { + Application.launch(MainApp.class); + } +} diff --git a/src/main/java/cn/minbrowser/MainApp.java b/src/main/java/cn/minbrowser/MainApp.java new file mode 100644 index 0000000..0099dd9 --- /dev/null +++ b/src/main/java/cn/minbrowser/MainApp.java @@ -0,0 +1,72 @@ +package cn.minbrowser; + +/* + * @author wefree + */ + +import cn.minbrowser.view.NavigationBarController; +import javafx.application.Application; +import javafx.event.EventHandler; +import javafx.fxml.FXMLLoader; +import javafx.scene.Scene; +import javafx.scene.image.Image; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.BorderPane; +import javafx.stage.Stage; +import javafx.stage.StageStyle; +import javafx.stage.WindowEvent; + +import java.io.IOException; + +public class MainApp extends Application { + + private Stage primaryStage; + + @Override + public void start(Stage primaryStage) { + //设置关闭监听,确保在关闭stage后关闭子线程 + primaryStage.setOnCloseRequest(new EventHandler() { + @Override + public void handle(WindowEvent event) { + System.exit(0); + } + }); + + this.primaryStage = primaryStage; + // 设置平台自带标题栏的名称 + this.primaryStage.setTitle("MINBrowser"); + // 设置平台自带标题栏的图标 + this.primaryStage.getIcons().add(new Image("file:resources/images/logo_mini.png")); + // 设置平台stage显示格式 + this.primaryStage.initStyle(StageStyle.DECORATED);// 带标题栏,默认格式 +// this.primaryStage.setResizable(false); + showNavigationBarOverview(); + } + + // 展示浏览器导航界面 + public void showNavigationBarOverview() { + try { + // 加载overview + FXMLLoader loader = new FXMLLoader(); + loader.setLocation(MainApp.class.getClassLoader().getResource("fxml/NavigationBarOverview.fxml")); + AnchorPane navigationBar = (AnchorPane) loader.load(); + + // 设置scene + Scene scene = new Scene(navigationBar); + primaryStage.setScene(scene); + + // 传参给控制器 + NavigationBarController barController = loader.getController(); + barController.setMainApp(this); + + primaryStage.show(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + // 展示登录界面 + public void showLoginOverview() { + + } +} diff --git a/src/main/java/cn/minbrowser/view/NavigationBarController.java b/src/main/java/cn/minbrowser/view/NavigationBarController.java new file mode 100644 index 0000000..f02b5ab --- /dev/null +++ b/src/main/java/cn/minbrowser/view/NavigationBarController.java @@ -0,0 +1,139 @@ +package cn.minbrowser.view; + +/* + * @author wefree + */ + +import cn.minbrowser.MainApp; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.concurrent.Worker; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.Button; +import javafx.scene.control.TextField; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.input.KeyCode; +import javafx.scene.input.KeyEvent; +import javafx.scene.web.WebView; + +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ResourceBundle; + +public class NavigationBarController implements Initializable { + private MainApp mainApp; + + @FXML + private Button backButton; + @FXML + private Button progressButton; + @FXML + private Button refreshButton; + @FXML + private TextField urlText; + @FXML + private ImageView userPhoto; + @FXML + private WebView mainWebView; + + + public NavigationBarController(){ + } + + @FXML + private void initialize() { + //在fxml被载入时候被自动调用 + this.userPhoto.setImage(new Image("file:resources/images/user.png")); + // webview 加入监听器:状态改变后,自动把新的url回显到文本输入框 + mainWebView.getEngine().getLoadWorker().stateProperty().addListener( + new ChangeListener() { + @Override + public void changed(ObservableValue ov, Worker.State oldValue, Worker.State newValue) { + System.out.println(mainWebView.getEngine().getLocation()); + urlText.setText(mainWebView.getEngine().getLocation()); + } + }); + } + + // 后退 + @FXML + private void backUrl(){ + if (mainWebView.getEngine().getHistory().getCurrentIndex() > 0) { + mainWebView.getEngine().getHistory().go(-1); + } + } + + // 前进 + @FXML + private void progressUrl(){ + if(mainWebView.getEngine().getHistory().currentIndexProperty().getValue() + < mainWebView.getEngine().getHistory().getEntries().size() - 1){ + mainWebView.getEngine().getHistory().go(1); + } + } + + // 刷新 + @FXML + private void refreshUrl(){ + mainWebView.getEngine().reload(); + } + + // 跳转/加载 + @FXML + private void loadUrl(KeyEvent keyEvent) throws MalformedURLException { + if(keyEvent.getCode()== KeyCode.ENTER){ + String url=urlText.getText().trim(); + if(isPrefix(url)){ + // 本地加载 + String filepath=getRootPath()+"/webcache"+url+"/index.html"; + File file=new File(filepath); + URL fileUrl=file.toURI().toURL(); + System.out.println(filepath); + System.out.println(fileUrl.toString()); + mainWebView.getEngine().load(fileUrl.toString()); + }else{ + // http加载 + mainWebView.getEngine().load(urlText.getText().trim()); + } + } + } + + // 获取项目根目录路径 + private static String getRootPath() { + File directory = new File("");// 参数为空 + String path = ""; + try { + path = directory.getCanonicalPath(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } +// System.out.println("客户端根目录:" + path); + return path; + } + + // 判断一个字符串是否是标识地址 + private boolean isPrefix(String url){ + if(url.startsWith("/")&&(url.length()>1)){ + return true; + }else{ + return false; + } + } + + @Override + public void initialize(URL location, ResourceBundle resources) { + } + + /* + * @param mainApp + */ + public void setMainApp(MainApp mainApp) { + this.mainApp = mainApp; + } + +} diff --git a/src/main/resources/fxml/NavigationBarOverview.fxml b/src/main/resources/fxml/NavigationBarOverview.fxml new file mode 100644 index 0000000..7b6bdd7 --- /dev/null +++ b/src/main/resources/fxml/NavigationBarOverview.fxml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + +