mirror of
https://gitee.com/willfree/minbrowser.git
synced 2026-10-05 01:15:42 +08:00
调好了新建标签页按钮
This commit is contained in:
1 parent
9473358dfb
commit
048c56a636
4 files changed
+70
-26
No files matched your search
@@ -0,0 +1,20 @@
|
||||
package cn.minbrowser.util;
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
public class ConnectTestUtil {
|
||||
protected static int Timeout = 2000;
|
||||
public static int Request(String request){
|
||||
try{
|
||||
URL url = new URL(request);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("HEAD");
|
||||
connection.setConnectTimeout(Timeout);
|
||||
connection.setReadTimeout(Timeout);
|
||||
return connection.getResponseCode();
|
||||
}catch (Exception e){
|
||||
return 404;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,8 @@ public class NavigationBarController implements Initializable {
|
||||
private ImageView userPhoto;
|
||||
@FXML
|
||||
private ImageView settingPhoto;
|
||||
@FXML
|
||||
private Button addTabButton;
|
||||
|
||||
private final Double tabHeaderWidth = 200D;
|
||||
|
||||
@@ -59,32 +61,48 @@ public class NavigationBarController implements Initializable {
|
||||
//在fxml被载入时候被自动调用
|
||||
this.userPhoto.setImage(new Image("file:resources/images/user.png"));
|
||||
this.settingPhoto.setImage(new Image("file:resources/images/3dot.png"));
|
||||
// 初始化增加标签按钮
|
||||
Button addTabBtn=new Button("++++++++++++++++++");
|
||||
addTabBtn.setVisible(true);
|
||||
// 设置tabpane中tab的最大宽度
|
||||
tabPane.setTabMaxWidth(tabHeaderWidth);
|
||||
// 加载标签
|
||||
tabPane.getTabs().add(new MiniTab(this));
|
||||
tabPane.getSelectionModel().getSelectedItem().setClosable(true);
|
||||
iniTab();
|
||||
// 设置标签监听
|
||||
// tabPane.getTabs().addListener((ListChangeListener.Change<? extends Tab> c) -> {
|
||||
// // 如果tab全部关闭,就退出系统
|
||||
// int size = c.getList().size();
|
||||
// if (size == 0) {
|
||||
// Platform.exit();
|
||||
// }
|
||||
// // 根据tabpane的个数变换AddTabBtn的位置
|
||||
// Double width = tabPane.getScene().getWidth();
|
||||
// Double left = tabHeaderWidth * size + (size - 1) * 12D + 20D;
|
||||
// if (left - 80D > width) {
|
||||
// left = width - 80D;
|
||||
// tabPane.setTabMinWidth(5D);
|
||||
// } else if (left < width - tabHeaderWidth) {
|
||||
// tabPane.setTabMinWidth(tabHeaderWidth);
|
||||
// }
|
||||
// AnchorPane.setLeftAnchor(addTabBtn, left);
|
||||
// });
|
||||
setTabPaneListener();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初次加载标签(主页标签)
|
||||
*/
|
||||
private void iniTab(){
|
||||
tabPane.getTabs().add(new MiniTab(this));
|
||||
AnchorPane.setLeftAnchor(addTabButton,175D);
|
||||
addTabButton.setOnAction((event) -> {
|
||||
MiniTab mt = new MiniTab(this);
|
||||
tabPane.getTabs().add(mt);
|
||||
tabPane.getSelectionModel().select(mt);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置标签监听
|
||||
*/
|
||||
private void setTabPaneListener(){
|
||||
tabPane.getTabs().addListener((ListChangeListener.Change<? extends Tab> c) -> {
|
||||
// 如果tab全部关闭,就退出系统
|
||||
int size = c.getList().size();
|
||||
if (size == 0) {
|
||||
System.exit(0);
|
||||
}
|
||||
// 根据tabpane的个数变换AddTabBtn的位置
|
||||
Double width = tabPane.getScene().getWidth();
|
||||
Double left = tabHeaderWidth * size + (size - 1) * 16D + 25D;
|
||||
if (left - 80D > width) {
|
||||
left = width - 80D;
|
||||
tabPane.setTabMinWidth(5D);
|
||||
} else if (left < width - tabHeaderWidth) {
|
||||
tabPane.setTabMinWidth(tabHeaderWidth);
|
||||
}
|
||||
AnchorPane.setLeftAnchor(addTabButton, left);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.minbrowser.view.minibrowser;
|
||||
|
||||
import cn.minbrowser.protocol.util.MinUrlUtil;
|
||||
import cn.minbrowser.util.ConnectTestUtil;
|
||||
import cn.minbrowser.util.FilePermissionUtil;
|
||||
import cn.minbrowser.view.MainPageHTMLController;
|
||||
import cn.minbrowser.view.NavigationBarController;
|
||||
@@ -120,8 +121,12 @@ public class MiniTab extends Tab {
|
||||
// min协议加载
|
||||
webview.getEngine().load(url);
|
||||
} else {
|
||||
// http及其它通用网络协议的加载
|
||||
webview.getEngine().load(url);
|
||||
if(ConnectTestUtil.Request(url)==404){
|
||||
showErrorPage();
|
||||
}else{
|
||||
// http及其它通用网络协议的加载
|
||||
webview.getEngine().load(url);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -198,8 +203,6 @@ public class MiniTab extends Tab {
|
||||
showLoginPage();
|
||||
}else if(url.equals(REGISTER_URL) || url.equals(REGISTER_SHOW_URL)){
|
||||
showRegisterPage();
|
||||
}else if(url.equals(ERROR_URL)){
|
||||
showErrorPage();
|
||||
}else {
|
||||
load(url);
|
||||
}
|
||||
@@ -324,6 +327,8 @@ public class MiniTab extends Tab {
|
||||
|| url.equals(INDEX_SHOW_URL)){
|
||||
input.setText(INDEX_SHOW_URL);
|
||||
showUsernameByListenEngineState();
|
||||
}else if(url.contains("resources/html/InfoUtil/error.html")){
|
||||
input.setText(ERROR_URL);
|
||||
}else {
|
||||
try {
|
||||
input.setText(URLDecoder.decode(url, "UTF-8"));
|
||||
|
||||
@@ -26,5 +26,6 @@
|
||||
</image>
|
||||
</ImageView>
|
||||
<Button fx:id="settingButton" mnemonicParsing="false" onAction="#showNewSettingInfo" opacity="0.0" prefHeight="40.0" prefWidth="30.0" text="S" AnchorPane.rightAnchor="18.0" AnchorPane.topAnchor="41.0" />
|
||||
<Button fx:id="addTabButton" mnemonicParsing="false" text="+" AnchorPane.leftAnchor="10.0" AnchorPane.topAnchor="8.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
Reference in new issue
Block a user