package controller;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.ResourceBundle;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import javafx.beans.binding.Bindings;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Scene;
import javafx.scene.control.DatePicker;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TablePosition;
import javafx.scene.control.TableView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import model.Booking;
import model.BookingCell;
import model.BusinessDay;
import model.Connection;
import model.User;
public class AppointTabController extends ConnectionController implements Initializable {
// FXML - GUI Components
@FXML
TableView<ObservableList<BookingCell>> appointTable;
@FXML
DatePicker appointDate;
// Constants
private final String BOOKING_COLOURS = "src/colours.csv";
// Table data
private List<String> columns = new ArrayList<String>();
private List<String> rows = new ArrayList<String>();
private List<List<BookingCell>> rowsData = new ArrayList<List<BookingCell>>(7);
private ObservableList<ObservableList<BookingCell>> csvData = FXCollections.observableArrayList();
private ArrayList<String> closedDays = new ArrayList<String>();
// Custom row colour names
private ArrayList<String> tableNames = new ArrayList<String>();
private ArrayList<String> tableColours = new ArrayList<String>();
private ArrayList<Booking> currentBookings = new ArrayList<Booking>();
// Whenever we click on a date on the date picker we store the days of the week
// in date form here
private ArrayList<String> currentDates = new ArrayList<String>();
private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
private String getDay(int day) {
String[] days = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
return days[day];
}
@SuppressWarnings("unchecked")
@Override
public void initialize(URL location, ResourceBundle resources) {
appointDate.setShowWeekNumbers(true);
appointDate.setValue(NOW_LOCAL_DATE());
loadCellColours();
load();
appointTable.setFixedCellSize(25);
appointTable.prefHeightProperty()
.bind(Bindings.size(appointTable.getItems()).multiply(appointTable.getFixedCellSize()).add(30));
// END
System.out.println("// END of AppointTab Initialize");
}
private void loadData() {
// Clear everything before rebuilding the table
csvData.clear();
columns.clear();
rows.clear();
appointTable.getColumns().clear();
appointTable.getItems().clear();
// Build the table columns and headers from the json output
loadTableColumns();
// Load up the current bookings from date selected
loadTableRows();
// Creates the columns and rows visually from the two arraylists columns + rows
createTable();
}
private void loadCellColours() {
// Read the csv file
File f = new File(BOOKING_COLOURS);
if (f.exists() && !f.isDirectory()) {
try (FileReader fin = new FileReader(f); BufferedReader in = new BufferedReader(fin);) {
String l;
while ((l = in.readLine()) != null) {
// Break up the csv (should be two values e.g:
// Booking, light green
// brokenLine[0] = Booking
// brokenLine[1] = light green
String[] brokenLine = l.split(",");
// Save to the String ArrayLists to use when colouring cells
tableNames.add(brokenLine[0]);
tableColours.add(brokenLine[1]);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* We know there is going to be 7 rows (Monday-Sunday) We already know how many
* columns there are (columns array) Now we need to create the cell data so that
* it matches the Dates and Time to each cell If X is number of time intervals
* then total cell data must be 7x + 7(days)
*/
private void loadTableRows() {
rowsData.clear();
// 7 rows
for (int i = 0; i < 7; i++) {
String day = getDay(i);
String date = getDate(i);
List<BookingCell> weekData = new ArrayList<BookingCell>();
// First value in row is going to be Day
weekData.add(new BookingCell(new String[] { "00:00:00", date, day, day }, false, null));
// Next X values are times
for (int z = 1; z < columns.size(); z++) {
// Create BookingCell and place it into ObservableData
String time = columns.get(z);
// re factor this
Booking b = booked(time, date);
String text = "Open";
if (b != null)
text = "Booked";
// Check if its a closed day today
for (int p = 0; p < closedDays.size(); p++) {
if (day.equals(closedDays.get(p))) {
text = "Closed";
}
}
weekData.add(new BookingCell(new String[] { time, date, day, text }, true, b));
}
rowsData.add(weekData);
}
}
private String getDate(int i) {
return currentDates.get(i);
}
// Checks whether or not there is a booking on this date
private Booking booked(String time, String date) {
// quick hack, not neat!
// Converts 09:00:00 to 09:00 the b.getStartTime() format
time = time.substring(0, time.length() - 3);
// Check if there's a matching booking
for (int i = 0; i < currentBookings.size(); i++) {
Booking b = currentBookings.get(i);
if (b.getDate().equals(date) && b.getStartTime().equals(time)) {
// Its a matching date
return b;
}
}
return null;
}
private void createTable() {
buildTableColumns();
buildTableRows();
appointTable.setItems(csvData);
System.out.println("CSV SIZE: " + csvData.size());
System.out.println("ROW SIZE: " + csvData.get(6).size());
System.out.println(appointTable.getItems().size());
}
private void buildTableColumns() {
for (int i = 0; i < columns.size(); i++) {
final int finalIdx = i;
// re factor substring here
String name = columns.get(i);
if (name.length() > 3) {
name = name.substring(0, name.length() - 3);
}
TableColumn<ObservableList<BookingCell>, BookingCell> column = new TableColumn<>(name);
// Set the text of the cells
setupColumnNames(column, finalIdx);
setupColumnDesign(column);
// Add the columns to the table
appointTable.getColumns().add(column);
}
}
private void setupColumnNames(TableColumn<ObservableList<BookingCell>, BookingCell> column, int finalIdx) {
column.setCellValueFactory(param -> new ReadOnlyObjectWrapper<>(param.getValue().get(finalIdx)));
}
private void setupColumnDesign(TableColumn<ObservableList<BookingCell>, BookingCell> column) {
// Set the colour of the cell
column.setCellFactory(param -> {
return new TableCell<ObservableList<BookingCell>, BookingCell>() {
protected void updateItem(BookingCell item, boolean empty) {
super.updateItem(item, empty);
super.setText(empty ? "" : getItem().getText());
super.setGraphic(null);
if (item == null || empty) {
super.setStyle("");
小云同志你好
- 粉丝: 1067
- 资源: 1067
最新资源
- S7-200基于PLC的复杂路交通灯控制系统 带解释的梯形图程序,接线图原理图图纸,io分配,组态画面
- 基于PLC的4路抢答器控制系统的设计四路抢答 带解释的梯形图程序,接线图原理图图纸,io分配,组态画面
- 双容水箱液位PID控制设计(matlab simulink控制采用p pi pd pid 四种对比 包含说明文档
- S7-200组态王基于PLC的游泳池水处理 带解释的梯形图程序,接线图原理图图纸,io分配,组态画面
- 远景能源风机平台主控制系统
- 光伏同步发电机并网matlab simulink模型,pv-vsg 通过波形观察,运行良好 只提供模型,供参考学习
- 六轴机械臂时间能量冲击最优轨迹规划 轨迹优化 支持最高7次NURBS 默认7次 可修改成其他阶数 扩展性强 可出 关节位置 关节速度 关节加速度图 pareto最优解集图 可复现浙大机械手多目标轨迹规
- MATLAB simulink软件设计汽车七自由度整车模型的建模 有仿真结果文件和资料 下图是部分仿真
- 埃斯顿伺服驱动器源码;PCB;源理图;BOM;技术参数 埃斯顿 伺服驱动器源码;PCB;源理图;BOM;技术参数 埃斯顿 伺服驱动器源码;PCB;源理图;BOM;技术参数;资料齐全可直接生产 250
- 基于用户的协同过滤购物系统 协同过滤网上购物 协同过滤商城系统 推荐原理:根据用户拿后记录计算用户相似度,将相似度高的用户的拿后进行互相推荐 技术栈:springboot mybatis jsp my
- 西门子1200程序双相机4轴多工位检测设备,KTP700触摸屏,仅供电气编程者学习借鉴 程序主要有,上下双工位4轴脉冲控制步进电机; 与上位机双相机的TCP IP通讯;有一台第三设备的modbus r
- 基于时间和空间的大规模电动汽车入网网损调度 建立MISOCP模型,分时段优化,并行计算(实时优化) 并对比了优化和未优化结果,验证了调度的有效性 考虑到电动汽车的机动性,市区可分为三类功能区:住宅
- 异步电机无速度传感器控制仿真 全部采用sfunction搭建 可以赠送有速度传感器控制 图片为正反转转速零穿波形
- 基于matlab语音信号处理,针对采集的语音信号,观察其时域、频域波形,然后分别通过抽取,内插操作,结合处理后的时频域波形,分析了抽取与内插对信号的影响 最后分别设计了两个模拟滤波器,并利用脉冲响应
- K7+6678信号处理板 方案 原理图 pcb
- 基于fpga的qam调制解调器设计
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈