commit 627cf80969a173bb9e728fe52dde9ae13470a72f
Author: Marek Sobota <sobotama@students.zcu.cz>
Date:   Thu Apr 11 13:52:16 2019 +0200

    GUI - vstup a ověření (Re #7239)

diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..ffb52c6
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="lib" path="/home/marek/git/aswi2019scurkojirman/lib/jdatepicker-1.3.4.jar"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ae3c172
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/.project b/.project
new file mode 100644
index 0000000..ffa7f58
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>aswi2019scurkojirman</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>
diff --git a/lib/jdatepicker-1.3.4.jar b/lib/jdatepicker-1.3.4.jar
new file mode 100644
index 0000000..a716259
Binary files /dev/null and b/lib/jdatepicker-1.3.4.jar differ
diff --git a/src/gui/Window.java b/src/gui/Window.java
new file mode 100644
index 0000000..eb20903
--- /dev/null
+++ b/src/gui/Window.java
@@ -0,0 +1,442 @@
+package gui;
+
+import java.awt.BorderLayout;
+import java.awt.FlowLayout;
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import java.io.File;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Properties;
+
+import javax.swing.JButton;
+import javax.swing.JFileChooser;
+import javax.swing.JFormattedTextField.AbstractFormatter;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+
+import org.jdatepicker.impl.JDatePanelImpl;
+import org.jdatepicker.impl.JDatePickerImpl;
+import org.jdatepicker.impl.UtilDateModel;
+
+/**
+ * 
+ * Zakladni okno aplikace, zprostredkovava vstupy od uzivatele
+ * 
+ * @author Marek Sobota, Daniel Stus, Lukas Scurko, Jan Jirman
+ * @version 1.0
+ *
+ */
+public class Window extends JFrame{
+
+	/**zakladni verze serializace*/
+	private static final long serialVersionUID = 1L;
+	
+	/**konstanta pro oznaceni souboru se spoji*/
+	private static final int SPOJ_FILE = 0;
+	
+	/**konstanta pro oznaceni slozky JDF*/
+	private static final int JDF_DIR = 1;
+	
+	/**konstanta pro oznaceni dialogu pro vyber zacinajiciho data*/
+	private static final int DATE_PICKER_FROM = 2;
+	
+	/**konstanta pro oznaceni dialogu pro vyber konciciho data*/
+	private static final int DATE_PICKER_TO = 3;
+	
+	/**spolecna delka pro vsechny {@code JTextField}*/
+	private static final int TEXT_FIELD_LENGTH = 15;
+	
+	/**konstanta pro nazev souboru caskody*/
+	private static final String CASKODY = "caskody.txt";
+	
+	/**konstanta pro nazev souboru linky*/
+	private static final String LINKY = "linky.txt";
+	
+	/**konstanta pro nazev souboru pevnykod*/
+	private static final String PEVNY_KOD = "pevnykod.txt";
+	
+	/**konstanta pro nazev souboru spoje*/
+	private static final String SPOJE = "spoje.txt";
+	
+	/**pouzivany datovy format*/
+	public static final DateFormat df = new SimpleDateFormat("yyyy/MM/dd");
+	
+	/**atribut se souborem se spoji*/
+	private File spojFile = null;
+	
+	/**atribut se slozkou JDF*/
+	private File jdfDir = null;
+	
+	/**den zacatku obdobi*/
+	private Calendar dateFrom = null;
+	
+	/**dden konce obdobi*/
+	private Calendar dateTo = null;
+	
+	/**panel pro zadani vstupnich dat*/
+	private JPanel inputP;
+	
+	/**tlacitko pro odeslani zadanych dat*/
+	private JButton confirmBT;
+	
+	/**tlacitko pro vypnuti programu*/
+	private JButton endBT;
+	
+	/**Dialog pro vybrani cesty k souborum*/
+	private JFileChooser fileChooser;
+	
+	/**Dialog pro vybrani data zacatku*/
+	private JDatePickerImpl datePickerFrom;
+	
+	/**Dialog pro vybrani data konce*/
+	private JDatePickerImpl datePickerTo;
+	
+	/**TextField pro zobrazeni cesty k souboru se spojema*/
+	private JTextField spojPathTF;
+	
+	/**TextField pro zobrazeni cesty k slozce JDF*/
+	private JTextField jdfPathTF;
+	
+	/**TextArea pro výpis informací o běhu programu*/
+	private JTextArea infoTA;
+
+	/**ScrollPane pro obaleni infoTA*/
+	private JScrollPane scrollPane;
+	
+	/**
+	 * inicializuje okno, jmenovite jeho panely, komponenty, priradi potrebne listenery a prida je do zobrazeni
+	 */
+	public Window(){
+		super("POVED");
+		this.setLayout(new BorderLayout());
+		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
+				
+		//nastaveni JPanelu
+		inputP = new JPanel();
+		JPanel dateFromP = new JPanel();
+		JPanel dateToP = new JPanel();
+		JPanel spojPathP = new JPanel();
+		JPanel jdfPathP = new JPanel();
+		inputP.setLayout(new GridLayout(4, 1));
+		dateFromP.setLayout(new FlowLayout());
+		dateToP.setLayout(new FlowLayout());
+		spojPathP.setLayout(new FlowLayout());
+		jdfPathP.setLayout(new FlowLayout());
+		
+		//inicializace kompoment
+		JLabel povedLB = new JLabel("POVED", JLabel.CENTER);
+		JLabel dateFromLB = new JLabel("Obdobi od: ");
+		JLabel dateToLB = new JLabel ("Obdobi do: ");
+		JLabel spojPathLB = new JLabel("Spoje: ");
+		JLabel jdfPathLB = new JLabel("JDF: ");
+		confirmBT = new JButton("Potvrdit");
+		endBT = new JButton("Ukoncit");
+		JButton spojBT = new JButton("Vybrat spoj soubor");
+		JButton jdfBT = new JButton("Vybrat JDF slozku");
+		spojPathTF = new JTextField(TEXT_FIELD_LENGTH);
+		jdfPathTF = new JTextField(TEXT_FIELD_LENGTH);
+		fileChooser = new JFileChooser();
+		infoTA = new JTextArea();
+		scrollPane = new JScrollPane(infoTA);
+		initDatePicker();
+		
+		//nastaveni komponent
+		spojPathTF.setEditable(false);
+		jdfPathTF.setEditable(false);
+		infoTA.setEditable(false);
+		fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
+		
+		
+		//pridani listeneru k buttonum
+		confirmBT.addActionListener(new ConfirmListener());
+		endBT.addActionListener(new ActionListener(){
+			//@Override
+			/**
+			 * ukonci program
+			 * 
+			 * @param arg0	kod udalosti
+			 */
+			public void actionPerformed(ActionEvent arg0) {
+				printMessage("Exiting...");
+				System.exit(0);
+			}
+		});
+		spojBT.addActionListener(new FileChooserListener(SPOJ_FILE));
+		jdfBT.addActionListener(new FileChooserListener(JDF_DIR));
+		
+		//pridani komponent do panelu
+		inputP.add(dateFromP);
+		inputP.add(dateToP);
+		inputP.add(spojPathP);
+		inputP.add(jdfPathP);
+		dateFromP.add(dateFromLB);
+		dateFromP.add(datePickerFrom);
+		dateToP.add(dateToLB);
+		dateToP.add(datePickerTo);
+		spojPathP.add(spojPathLB);
+		spojPathP.add(spojPathTF);
+		spojPathP.add(spojBT);
+		jdfPathP.add(jdfPathLB);
+		jdfPathP.add(jdfPathTF);
+		jdfPathP.add(jdfBT);
+		
+		//pridani panelu do okna
+		this.add(povedLB, BorderLayout.NORTH);
+		this.add(inputP, BorderLayout.CENTER);
+		this.add(confirmBT, BorderLayout.SOUTH);
+			
+		this.pack();
+		
+	}
+	
+	/**
+	 * 
+	 * inicializuje dve na sobe nezavisle instance {@code DatePickerImpl}
+	 */
+	private void initDatePicker(){
+		UtilDateModel modelFrom = new UtilDateModel();
+        Properties pFrom = new Properties();
+        pFrom.put("text.today", "Today");
+        pFrom.put("text.month", "Month");
+        pFrom.put("text.year", "Year");
+        UtilDateModel modelTo = new UtilDateModel();
+        Properties pTo = new Properties();
+        pTo.put("text.today", "Today");
+        pTo.put("text.month", "Month");
+        pTo.put("text.year", "Year");
+        JDatePanelImpl datePanelFrom = new JDatePanelImpl(modelFrom, pFrom);
+        JDatePanelImpl datePanelTo = new JDatePanelImpl(modelTo, pTo);
+        datePickerFrom = new JDatePickerImpl(datePanelFrom, new DateLabelFormatter());
+        datePickerTo = new JDatePickerImpl(datePanelTo, new DateLabelFormatter());
+        datePickerFrom.addActionListener(new DatePickerListener(DATE_PICKER_FROM));
+        datePickerTo.addActionListener(new DatePickerListener(DATE_PICKER_TO));
+        
+	}
+	
+	/**
+	 * zmeni okno ze vstupoveho pohledu, aby od ted zobrazovalo prubezne informace
+	 */
+	private void changeToInfo(){
+		this.remove(inputP);
+		this.remove(confirmBT);
+		
+		this.add(scrollPane, BorderLayout.CENTER);
+		this.add(endBT, BorderLayout.SOUTH);
+		this.revalidate();
+	}
+	
+	
+	/**
+	 * metoda pro pridani zpravy do vypisu uzivateli
+	 * 
+	 * @param message zprava, kterou chceme uzivateli sdelit
+	 */
+	public void printMessage(String message){
+		infoTA.append(message + "\n");
+	}
+
+	/**
+	 * 
+	 * Listener pro potvrzovaci tlacitko, kontroluje, jestli vsechna zadana data jsou platna
+	 * 
+	 * @author Marek Sobota, Daniel Stus, Lukas Scurko, Jan Jirman
+	 * @version 1.0
+	 *
+	 */
+	class ConfirmListener implements ActionListener{
+
+		//@Override
+		/**
+		 * zkontroluje, zda-li zadana data jsou platna, pote zmeni panely aby okno vypisovalo informace o prubehu generace
+		 * a odesle data na zpracovani
+		 * 
+		 * @param arg0 kod udalosti
+		 */
+		public void actionPerformed(ActionEvent arg0) {
+			//kontrola jestli jsou obdobi zadana a ve spravnem poradi a jestli jsou cesty vyplněny
+			if(spojFile == null || jdfDir == null){
+				JOptionPane.showMessageDialog(null, "Nejsou vybrany potrebne soubory", 
+						"Varovani", JOptionPane.WARNING_MESSAGE);
+				return;
+			}
+			if(dateTo == null || dateFrom == null){
+				JOptionPane.showMessageDialog(null, "Neni zadano datum", 
+						"Varovani", JOptionPane.WARNING_MESSAGE);
+				return;
+			}
+			if(dateTo.compareTo(dateFrom) < 0){
+				JOptionPane.showMessageDialog(null, "Zacatek obdobi je po konci obdobi", 
+						"Varovani", JOptionPane.WARNING_MESSAGE);
+				return;
+			}
+			
+			changeToInfo();
+		}
+		
+	}
+	
+	/**
+	 * Listener pro {@code JFileChooser}, zpracovava dialog pro vybrani souboru a kontrolu jeho platnosti
+	 * 
+	 * @author Marek Sobota, Daniel Stus, Lukas Scurko, Jan Jirman
+	 * @version 1.0
+	 *
+	 */
+	class FileChooserListener implements ActionListener{
+
+		/**
+		 * cislo oznacujici, jestli se jedna o soubor se spoji nebo o slozku JDF
+		 */
+		private int fileType;
+		
+		/**
+		 * konstruktor ulozi do atributu typ souboru, ktery ma vybirat
+		 * 
+		 * @param fileType ktery soubor se vybral (0 = spoj, 1 = jdf slozka)
+		 */
+		public FileChooserListener(int fileType) {
+			this.fileType = fileType;
+		}
+		
+		//@Override
+		/**
+		 * otevre dialog pro vybrani souboru nebo slozky, overi, zda-li typ souboru vyhovuje
+		 * pokud ano, ulozi ho do prislusne promene, jinak vypise varovani
+		 * 
+		 */
+		public void actionPerformed(ActionEvent arg0) {
+			int option = fileChooser.showOpenDialog(null);
+			if(option == JFileChooser.APPROVE_OPTION){
+				File selectedFile = fileChooser.getSelectedFile();
+				
+				if(selectedFile.isFile() && fileType == SPOJ_FILE && selectedFile.getName().endsWith(".txt")){
+					spojFile = selectedFile;
+					spojPathTF.setText(spojFile.getAbsolutePath());
+				}
+				else if(selectedFile.isDirectory() && fileType == JDF_DIR){
+					//overi existenci potrebnych souboru ve slozce
+					File caskody = new File(selectedFile.getAbsolutePath() + File.separator + CASKODY);
+					File linky = new File(selectedFile.getAbsolutePath() + File.separator + LINKY);
+					File pevnyKod = new File(selectedFile.getAbsolutePath() + File.separator + PEVNY_KOD);
+					File spoje = new File(selectedFile.getAbsolutePath() + File.separator + SPOJE);
+					if(!caskody.exists()){
+						JOptionPane.showMessageDialog(null, "Ve slozce se nenachazi soubor " + CASKODY, 
+								"Varovani", JOptionPane.WARNING_MESSAGE);
+						return;
+					}
+					if(!linky.exists()){
+						JOptionPane.showMessageDialog(null, "Ve slozce se nenachazi soubor " + LINKY, 
+								"Varovani", JOptionPane.WARNING_MESSAGE);
+						return;
+					}
+					if(!pevnyKod.exists()){
+						JOptionPane.showMessageDialog(null, "Ve slozce se nenachazi soubor " + PEVNY_KOD, 
+								"Varovani", JOptionPane.WARNING_MESSAGE);
+						return;
+					}
+					if(!spoje.exists()){
+						JOptionPane.showMessageDialog(null, "Ve slozce se nenachazi soubor " + SPOJE, 
+								"Varovani", JOptionPane.WARNING_MESSAGE);
+						return;
+					}
+					
+					jdfDir = selectedFile;
+					jdfPathTF.setText(jdfDir.getAbsolutePath());
+				}
+				else{
+					JOptionPane.showMessageDialog(null, "Vybran nespravny typ souboru", 
+												"Varovani", JOptionPane.WARNING_MESSAGE);
+				}
+			}
+		}
+		
+	}
+	
+	/**
+	 * 
+	 * Listener pro {@code JDatePicker}, zpracovava dialog pro vybrani data
+	 * 
+	 * @author Marek Sobota, Daniel Stus, Lukas Scurko, Jan Jirman
+	 * @version 1.0
+	 *
+	 */
+	class DatePickerListener implements ActionListener{
+
+		/**cislo oznacujici zda-li se jedna o zacatek nebo konec obdobi*/
+		private int datePickerType;
+		
+		/**
+		 * konstruktor ulozi do atributu typ souboru, ktery ma vybirat
+		 * 
+		 * @param datePickerType typ data, ktery se vybral (2 = od, 3 = do)
+		 */
+		public DatePickerListener(int datePickerType){
+			this.datePickerType = datePickerType;
+		}
+		
+		//@Override
+		/**
+		 * ulozi vybrane datum z dialogu do odpovidajiciho data
+		 * 
+		 * @param arg0 kod udalosti
+		 */
+		public void actionPerformed(ActionEvent arg0) {
+			if(datePickerType == DATE_PICKER_FROM){
+				dateFrom = Calendar.getInstance();
+				dateFrom.setTime((Date) datePickerFrom.getModel().getValue());
+							}
+			else if (datePickerType == DATE_PICKER_TO){
+				dateTo = Calendar.getInstance();
+				dateTo.setTime((Date) datePickerTo.getModel().getValue());
+			}
+		}
+		
+		
+	}
+	
+	class DateLabelFormatter extends AbstractFormatter {
+		
+		private static final long serialVersionUID = 1L;
+		
+		private String datePattern = "yyyy-MM-dd";
+        private SimpleDateFormat dateFormatter = new SimpleDateFormat(datePattern);
+
+        @Override
+        public Object stringToValue(String text) throws ParseException {
+            return dateFormatter.parseObject(text);
+        }
+
+        @Override
+        public String valueToString(Object value) throws ParseException {
+            if (value != null) {
+                Calendar cal = (Calendar) value;
+                return dateFormatter.format(cal.getTime());
+            }
+
+            return "";
+        }
+
+    }
+	
+	/**
+	 * 
+	 * hlavni metoda pro ozkouseni funkcnosti {@code Window}
+	 * 
+	 * @param args parametry programu
+	 */
+	public static void main(String[] args){
+		Window w = new Window();
+		w.setVisible(true);
+	}
+}
