commit
9cbb063af0
6
.classpath
Normal file
6
.classpath
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
17
.project
Normal file
17
.project
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Hajj-simulation</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -1,37 +1,29 @@
|
||||
import java.io.*;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class DataManeger {
|
||||
|
||||
private Path workingDir;
|
||||
private File workingDir;
|
||||
|
||||
// public DataManeger(Path path) {
|
||||
// this.seperator = File.separatorChar;
|
||||
// this.workingDir = path;
|
||||
// }
|
||||
|
||||
public DataManeger(State state, Date time){
|
||||
Path dir = Paths.get("");
|
||||
}
|
||||
|
||||
public DataManeger() {
|
||||
this(null, null);
|
||||
public DataManeger(){
|
||||
workingDir = new File("./data/");
|
||||
workingDir.mkdir();
|
||||
clearData();
|
||||
}
|
||||
|
||||
public boolean stateAvailable(Date time) {
|
||||
File f = new File(String.format("0x%016X.bin", time.getTime()));
|
||||
File f = new File(String.format("./data/%s.bin", time.getTime()));
|
||||
return f.exists();
|
||||
}
|
||||
|
||||
public State loadState(Date time){
|
||||
public State loadState(Date time){
|
||||
State state = null;
|
||||
if (stateAvailable(time)){
|
||||
try {
|
||||
ObjectInputStream objectInputStream = new ObjectInputStream(
|
||||
new FileInputStream(String.format("0x%016X.bin", time.getTime())));
|
||||
new FileInputStream(String.format("./data/%s.bin", time.getTime())));
|
||||
state = (State)objectInputStream.readObject();
|
||||
objectInputStream.close();
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
@ -43,7 +35,7 @@ public class DataManeger {
|
||||
|
||||
public boolean saveState(State state, Date time){
|
||||
try {
|
||||
FileOutputStream fs = new FileOutputStream(String.format("0x%016X.bin", time.getTime()));
|
||||
FileOutputStream fs = new FileOutputStream(String.format("./data/%s.bin", time.getTime()));
|
||||
BufferedOutputStream bfs = new BufferedOutputStream(fs);
|
||||
ObjectOutputStream objectOutputStream = new ObjectOutputStream(bfs);
|
||||
objectOutputStream.writeObject(state);
|
||||
@ -54,6 +46,52 @@ public class DataManeger {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public File[] savedStateFiles() {
|
||||
return workingDir.listFiles();
|
||||
}
|
||||
|
||||
public Date[] savedStatesTimes() {
|
||||
File[] files = savedStateFiles();
|
||||
ArrayList<Date> timesList = new ArrayList<>();
|
||||
for (File file : files){
|
||||
if (file.getName().contains(".bin")){
|
||||
String timeInName = file.getName().replaceAll(".bin", "").trim();
|
||||
if ("".equals(timeInName)) continue;
|
||||
long time = Long.parseLong(timeInName);
|
||||
timesList.add(new HijriDate(time));
|
||||
}
|
||||
}
|
||||
Date[] times = new Date[timesList.size()];
|
||||
times = timesList.toArray(times);
|
||||
return times;
|
||||
}
|
||||
|
||||
public List<State> getStates(){
|
||||
List<State> list = new ArrayList<>();
|
||||
for (File file : workingDir.listFiles()) {
|
||||
if (file.getName().contains(".bin")){
|
||||
try {
|
||||
FileInputStream fileInputStream = new FileInputStream(file);
|
||||
BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
|
||||
ObjectInputStream objectInputStream = new ObjectInputStream(bufferedInputStream);
|
||||
State state = (State) objectInputStream.readObject();
|
||||
list.add(state);
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private void clearData() {
|
||||
for (File file : savedStateFiles()) {
|
||||
if (file.getName().contains(".bin")){
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class State implements Serializable {
|
||||
@ -66,8 +104,15 @@ class State implements Serializable {
|
||||
private Street[] stdStreet;
|
||||
private Date allArrivedToArafatTime;
|
||||
private Date allArrivedToHotelsTime;
|
||||
private Date stateTime;
|
||||
|
||||
public State(ArrayList<Campaign> listOfCampaigns, ArrayList<Vehicle> listOfVehicles, Route[] stdRoutes, Street[] stdStreet, Date allArrivedToArafatTime, Date allArrivedToHotelsTime) {
|
||||
public State(ArrayList<Campaign> listOfCampaigns,
|
||||
ArrayList<Vehicle> listOfVehicles,
|
||||
Route[] stdRoutes,
|
||||
Street[] stdStreet,
|
||||
Date allArrivedToArafatTime,
|
||||
Date allArrivedToHotelsTime,
|
||||
Date stateTime) {
|
||||
//Make clones since values may change if this is running on a thread.
|
||||
this.listOfCampaigns = (ArrayList<Campaign>) listOfCampaigns.clone();
|
||||
this.listOfVehicles = (ArrayList<Vehicle>) listOfVehicles.clone();
|
||||
@ -79,6 +124,7 @@ class State implements Serializable {
|
||||
if (allArrivedToHotelsTime != null) {
|
||||
this.allArrivedToHotelsTime = (Date) allArrivedToHotelsTime.clone();
|
||||
}
|
||||
this.stateTime = stateTime;
|
||||
}
|
||||
|
||||
public ArrayList<Campaign> getListOfCampaigns() {
|
||||
@ -104,4 +150,9 @@ class State implements Serializable {
|
||||
public Date getAllArrivedToHotelsTime() {
|
||||
return allArrivedToHotelsTime;
|
||||
}
|
||||
|
||||
public Date getStateTime() {
|
||||
return stateTime;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,50 +1,42 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.EventQueue;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class GUI_History {
|
||||
|
||||
private static JFrame frame;
|
||||
private static JLabel Time;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
GUI_History window = new GUI_History();
|
||||
window.frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the application.
|
||||
*/
|
||||
public GUI_History() {
|
||||
private List<State> states;
|
||||
|
||||
public GUI_History(List<State> states) {
|
||||
this.states = states;
|
||||
initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the contents of the frame.
|
||||
*/
|
||||
private void initialize() {
|
||||
frame = new JFrame("History");
|
||||
frame.getContentPane().setBackground(new Color(70, 70, 70));
|
||||
frame.getContentPane().setForeground(new Color(0, 0, 0));
|
||||
frame.getContentPane().setLayout(null);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBounds(10, 11, 1228, 727);
|
||||
frame.getContentPane().add(panel);
|
||||
panel.setLayout(null);
|
||||
|
||||
JComboBox<Date> comboBox = new JComboBox<Date>();
|
||||
comboBox.setBounds(453, 46, 302, 42);
|
||||
for (State state : states) {
|
||||
comboBox.addItem(state.getStateTime());
|
||||
}
|
||||
panel.add(comboBox);
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.revalidate();
|
||||
frame.setLocation(200,150);
|
||||
frame.setAutoRequestFocus(false);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,13 +10,9 @@ import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
|
||||
import com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory.Default;
|
||||
|
||||
import javax.swing.JList;
|
||||
import javax.swing.AbstractListModel;
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.JProgressBar;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
public class GUI_ViewStreet {
|
||||
|
@ -31,6 +31,7 @@ public class MakkahCity {
|
||||
private static final InputListener inputListener = new InputListener();
|
||||
private static final Thread t = new Thread(inputListener,"InputThread-Makkah");
|
||||
private static boolean isAllRoutSet;
|
||||
private static final DataManeger dataManeger = new DataManeger();
|
||||
//GUI
|
||||
private static boolean exit_flag;
|
||||
private static boolean pause_flag;
|
||||
@ -207,14 +208,17 @@ public class MakkahCity {
|
||||
btnBrowseHistory.setBackground(new Color(9,9,9));
|
||||
btnBrowseHistory.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||
btnBrowseHistory.setForeground(Color.white);
|
||||
btnBrowseHistory.addActionListener(e -> {
|
||||
GUI_History hist = new GUI_History(dataManeger.getStates());
|
||||
});
|
||||
|
||||
//Label
|
||||
JLabel lblStreets = new JLabel("Streets History");
|
||||
JLabel lblStreets = new JLabel("Streets");
|
||||
lblStreets.setFont(new Font("Rockwell", Font.PLAIN, 24));
|
||||
lblStreets.setForeground(new Color(255, 255, 255));
|
||||
lblStreets.setBounds(49, 59, 208, 30);
|
||||
|
||||
JLabel lblDistrict = new JLabel("District History");
|
||||
JLabel lblDistrict = new JLabel("District");
|
||||
lblDistrict.setFont(new Font("Rockwell", Font.PLAIN, 24));
|
||||
lblDistrict.setForeground(new Color(255, 255, 255));
|
||||
lblDistrict.setBounds(49, 438, 166, 29);
|
||||
@ -471,17 +475,6 @@ public class MakkahCity {
|
||||
inputListener.pause();
|
||||
startMenu();
|
||||
}
|
||||
|
||||
private static Vehicle traceCar() {
|
||||
|
||||
for(int x = 20000; x < listOfVehicles.size(); x++) {
|
||||
if(listOfVehicles.get(x) instanceof Bus)
|
||||
if(((Bus)listOfVehicles.get(x)).getCampaign().getHotelDistrict() == District.ALAZIZIYA) {
|
||||
return listOfVehicles.get(x);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void checkInput() {
|
||||
String input = "";
|
||||
@ -1172,19 +1165,14 @@ public class MakkahCity {
|
||||
stdRoutes,
|
||||
stdStreet,
|
||||
allArrivedToArafatTime,
|
||||
allArrivedToHotelsTime);
|
||||
DataManeger dataManeger = new DataManeger();
|
||||
allArrivedToHotelsTime,
|
||||
currenttimeManager.getCurrentTime());
|
||||
dataManeger.saveState(s, currenttimeManager.getCurrentTime());
|
||||
|
||||
boolean result = dataManeger.saveState(s, currenttimeManager.getCurrentTime());
|
||||
if (!result) System.out.println("Could not save state "+currenttimeManager.getCurrentTime().getTime());
|
||||
}
|
||||
|
||||
private static State loadState(Date time){
|
||||
DataManeger dataManeger = new DataManeger();
|
||||
return dataManeger.loadState(time);
|
||||
}
|
||||
|
||||
private static void updateStreetFrame() {
|
||||
Object[][] streetData = new Object[stdStreet.length][6];
|
||||
for (int i = 0; i < stdStreet.length; i++) {
|
||||
|
Loading…
Reference in New Issue
Block a user