AppPage.java 5.37 KB
package cn.csbr.app.gui.page;

import cn.csbr.app.gui.page.useAndBackTab.BackTabPage;
import cn.csbr.app.gui.page.useAndBackTab.UseTabPage;
import cn.csbr.app.model.InboundItem;
import cn.csbr.app.service.TabUseBackService;
import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;

import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import org.springframework.beans.factory.annotation.Autowired;

import cn.csbr.app.config.FxConfigure;
import cn.csbr.app.gui.GUIContext;
import cn.csbr.app.gui.component.common.ImageButton;
import cn.hutool.core.date.DateUtil;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 出库入库这些都是要集成子这个类的 这个类里边做基本的布局管理
 */
public abstract class AppPage extends AbstractPage {
    Label userlable = new Label();
    Label timelable = new Label();
    Label label = new Label();

    //控制时间的变化
    private boolean timeflag = false;
    @Autowired
    private GUIContext context;
    public HBox head=null;
    @Autowired
    private FxConfigure fxConfigure;

    /**
     * 第一排是用户名和密码 第二排是文字的名称 第三批是按钮 第四排是公司名称版本号
     *
     * @return
     */
    private Node createHeader() {
        HBox headerBox = new HBox();

//        Region spacer = new Region();
//        spacer.setMinWidth(550);
//        titlelabel.setId("appTitle");
//        titlelabel.setText(getTitle());
//        titlelabel.setMinWidth(250);
//        namelabel.setId("namelabel");
//        namelabel.setWrapText(false);
//        namelabel.setMinWidth(180);
//        timelabel.setId("timelabel");
//        timelabel.setWrapText(false);
//        timelabel.setMinWidth(150);

       // label =new Label(getTitle());
        label.setText(getTitle());
        label.setFont(Font.font("圆体",28));
        label.setTranslateX(950);
        label.setTranslateY(-290);
        label.setTextFill(Color.WHITE);


      //  userlable=new Label("张三 / 内科2区");
        userlable.setFont(Font.font("14"));
        userlable.setTextFill(Color.rgb(140,140,140));
        userlable.setTranslateX(260);
        userlable.setTranslateY(-220);
        VBox imagehb1=new VBox();
        imagehb1.setStyle("-fx-background-image: url(images/New/renyuan.png);-fx-background-repeat: stretch;-fx-background-position: center center;");
        imagehb1.setTranslateX(255);
        imagehb1.setTranslateY(-212);
        imagehb1.setMinWidth(30);
        //imagehb1.setStyle("-fx-background-color: red");


        SimpleDateFormat sdf =   new SimpleDateFormat( "yyyy.MM.dd hh:mm:ss" );

       // String str = sdf.format(new Date());
        //timelable=new Label(sdf.format(new Date()));
        timelable.setFont(Font.font("14"));
        timelable.setTextFill(Color.rgb(140,140,140));
        timelable.setTranslateX(360);
        timelable.setTranslateY(-220);
        HBox imagehb2=new HBox();
        imagehb2.setTranslateX(355);
        imagehb2.setTranslateY(-212);
        imagehb2.setMinWidth(30);
        imagehb2.setStyle("-fx-background-image: url(images/New/24hour.png);-fx-background-repeat: stretch;-fx-background-position: center center;");



        headerBox.getChildren().addAll(label,imagehb1,userlable,imagehb2,timelable);
        headerBox.setMinWidth(fxConfigure.getMinWidth());
        headerBox.setStyle("-fx-text-alignment:left;-fx-alignment:bottom-left");
        head=headerBox;
        return headerBox;
    }

    @Override
    protected Node constructNode() {
        this.setTitle(appTitle());

        VBox main = new VBox();
        main.setId("appPage");
       // main.getStylesheets().add("styles/app.css");
        main.setPadding(new Insets(10, 10, 10, 10));

        Region spacer = new Region();
        spacer.setMinHeight(50);
        Node node =appContent();
        if (node!= null) {
            main.getChildren().addAll(createHeader(), spacer, node);
        } else {
            main.getChildren().add(createHeader());
        }
        main.setMinWidth(fxConfigure.getMinWidth());
        main.setMinHeight(fxConfigure.getMinHeight());
        main.setMaxHeight(fxConfigure.getMinHeight());
        main.setMaxWidth(fxConfigure.getMinWidth());
        return main;
    }

    @Override
    public void refresh() {
        StringBuilder desc = new StringBuilder();
        desc.append(context.getLoginUser().getUserName() + "/" + context.getLoginUser().getOrgName());
        userlable.setText(desc.toString());
        timelable.setText(DateUtil.now());
        if(!timeflag) {
            new Thread(() -> {
                try {
                    timeflag = true;
                    while (timeflag) {
                        Platform.runLater(() -> {
                            timelable.setText(DateUtil.now());
                        });
                        Thread.sleep(1000);
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }).start();
        }
        appRefresh();
    }

    abstract protected void appRefresh();

    abstract protected Node appContent();

    abstract protected String appTitle();
}