<commit_before>package view;

import java.awt.Container;
import java.awt.Font;

import javax.swing.JLabel;

import net.miginfocom.swing.MigLayout;

import javax.swing.ImageIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JSpinner;
import javax.swing.SpinnerDateModel;
import javax.swing.SpinnerModel;

import main.CourierSystem;

import java.util.Calendar;
import java.util.Date;

import javax.swing.JLayeredPane;
import java.awt.BorderLayout;
import java.awt.Component;

public class MapManagement  extends Container {
	private static final long serialVersionUID = 1L;
	//private Map map;
	
	public MapManagement(JFrame window) {
		//map = new Map();
		
		setLayout(new BorderLayout(0, 0));
		
		JLayeredPane layeredPane = new JLayeredPane();
		add(layeredPane);
		layeredPane.setLayout(new MigLayout("", "[0][4.00px][34.00][24.00][41.00][24.00][46.00][24.00][46.00][24][39.00][24][45.00][24][38.00][24.00][49.00]", "[25.00][24.00px][55.00][24.00][56.00][24.00][55.00][24.00][57.00][24.00][59.00][24.00][56.00][24.00][17.00][50][]"));
		
		JLabel backgroundMap = new JLabel("");
		backgroundMap.setIcon(new ImageIcon(MapManagement.class.getResource("/view/MapLow.png")));
		layeredPane.add(backgroundMap, "cell 0 0 17 15,alignx right,aligny center");
		
		JLabel lblIntersection = new JLabel("Z0 Closure");
		layeredPane.setLayer(lblIntersection, 1);
		lblIntersection.setVisible(false);
		layeredPane.add(lblIntersection, "cell 2 0");
		
		JLabel lblClosureStart = new JLabel("Start:");
		layeredPane.setLayer(lblClosureStart, 1);
		lblClosureStart.setVisible(false);
		layeredPane.add(lblClosureStart, "cell 3 0 2");
		
		Calendar start = Calendar.getInstance();
		start.set(Calendar.HOUR_OF_DAY, 0);
		start.set(Calendar.MINUTE, 0);
		SpinnerModel startModel = new SpinnerDateModel(start.getTime(), null, null,Calendar.YEAR);
		JSpinner startSpinner = new JSpinner(startModel);
		startSpinner.setVisible(false);
		layeredPane.add(startSpinner, "cell 4 0 4 1,alignx left,aligny center");
		layeredPane.setLayer(startSpinner, 1);
		
		JLabel lblClosureEnd = new JLabel("End:");
		layeredPane.setLayer(lblClosureEnd, 1);
		lblClosureEnd.setVisible(false);
		layeredPane.add(lblClosureEnd, "cell 7 0");
		
		Calendar end = Calendar.getInstance();
		end.set(Calendar.HOUR_OF_DAY, 23);
		end.set(Calendar.MINUTE, 59);
		SpinnerModel endModel = new SpinnerDateModel(end.getTime(), null, null,Calendar.YEAR);
		JSpinner endSpinner = new JSpinner(endModel);
		endSpinner.setVisible(false);
		layeredPane.add(endSpinner, "cell 8 0 4 1,alignx left,aligny center");
		layeredPane.setLayer(endSpinner, 1);
				
		JButton saveChanges = new JButton("Save Changes");
		layeredPane.setLayer(saveChanges, 1);
		saveChanges.setIcon(null);
		saveChanges.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Calendar startTime = Calendar.getInstance();
				startTime.setTime((Date)startSpinner.getValue());
				Calendar endTime = Calendar.getInstance();
				endTime.setTime((Date)endSpinner.getValue());
				
				CourierSystem.CityMap.getIntersection(lblIntersection.getText().substring(0, lblIntersection.getText().length() - " Closure".length())).changeClosure(startTime, endTime);
				/*try {
					CourierSystem.UpdateCityMap();
				} catch (Exception e1) {
					e1.printStackTrace();
				}*/
				// indicate that the intersection is closed
				if(!CourierSystem.CityMap.getIntersection(lblIntersection.getText().substring(0, lblIntersection.getText().length() - " Closure".length())).isOpen()) {
					for(Component button :layeredPane.getComponentsInLayer(1)) {
						if(button.getClass() == JButton.class && ((JButton)button).getText().equals(lblIntersection.getText().substring(0, lblIntersection.getText().length() - " Closure".length()))) {
							((JButton)button).setIcon(new ImageIcon(MapManagement.class.getResource("/view/cancelled.png")));
							((JButton)button).setText("");
						}
					}
				} else {
					for(Component button :layeredPane.getComponentsInLayer(1)) {
						if(button.getClass() == JButton.class && ((JButton)button).getName().equals(lblIntersection.getText().substring(0, lblIntersection.getText().length() - " Closure".length()))) {
							((JButton)button).setIcon(null);
							((JButton)button).setText(button.getName());
						}
					}
				}
				
			}
		});
		saveChanges.setVisible(false);
		layeredPane.add(saveChanges, "cell 11 0 3");
		
		JButton cancel = new JButton("Cancel");
		layeredPane.setLayer(cancel, 1);
		cancel.setIcon(null);
		cancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				lblClosureEnd.setVisible(false);
				lblClosureStart.setVisible(false);<commit_msg>named cancel and saveChanges buttons so icon changing works<commit_after>package view;

import java.awt.Container;
import java.awt.Font;

import javax.swing.JLabel;

import net.miginfocom.swing.MigLayout;

import javax.swing.ImageIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JSpinner;
import javax.swing.SpinnerDateModel;
import javax.swing.SpinnerModel;

import main.CourierSystem;

import java.util.Calendar;
import java.util.Date;

import javax.swing.JLayeredPane;
import java.awt.BorderLayout;
import java.awt.Component;

public class MapManagement  extends Container {
	private static final long serialVersionUID = 1L;
	//private Map map;
	
	public MapManagement(JFrame window) {
		//map = new Map();
		
		setLayout(new BorderLayout(0, 0));
		
		JLayeredPane layeredPane = new JLayeredPane();
		add(layeredPane);
		layeredPane.setLayout(new MigLayout("", "[0][4.00px][34.00][24.00][41.00][24.00][46.00][24.00][46.00][24][39.00][24][45.00][24][38.00][24.00][49.00]", "[25.00][24.00px][55.00][24.00][56.00][24.00][55.00][24.00][57.00][24.00][59.00][24.00][56.00][24.00][17.00][50][]"));
		
		JLabel backgroundMap = new JLabel("");
		backgroundMap.setIcon(new ImageIcon(MapManagement.class.getResource("/view/MapLow.png")));
		layeredPane.add(backgroundMap, "cell 0 0 17 15,alignx right,aligny center");
		
		JLabel lblIntersection = new JLabel("Z0 Closure");
		layeredPane.setLayer(lblIntersection, 1);
		lblIntersection.setVisible(false);
		layeredPane.add(lblIntersection, "cell 2 0");
		
		JLabel lblClosureStart = new JLabel("Start:");
		layeredPane.setLayer(lblClosureStart, 1);
		lblClosureStart.setVisible(false);
		layeredPane.add(lblClosureStart, "cell 3 0 2");
		
		Calendar start = Calendar.getInstance();
		start.set(Calendar.HOUR_OF_DAY, 0);
		start.set(Calendar.MINUTE, 0);
		SpinnerModel startModel = new SpinnerDateModel(start.getTime(), null, null,Calendar.YEAR);
		JSpinner startSpinner = new JSpinner(startModel);
		startSpinner.setVisible(false);
		layeredPane.add(startSpinner, "cell 4 0 4 1,alignx left,aligny center");
		layeredPane.setLayer(startSpinner, 1);
		
		JLabel lblClosureEnd = new JLabel("End:");
		layeredPane.setLayer(lblClosureEnd, 1);
		lblClosureEnd.setVisible(false);
		layeredPane.add(lblClosureEnd, "cell 7 0");
		
		Calendar end = Calendar.getInstance();
		end.set(Calendar.HOUR_OF_DAY, 23);
		end.set(Calendar.MINUTE, 59);
		SpinnerModel endModel = new SpinnerDateModel(end.getTime(), null, null,Calendar.YEAR);
		JSpinner endSpinner = new JSpinner(endModel);
		endSpinner.setVisible(false);
		layeredPane.add(endSpinner, "cell 8 0 4 1,alignx left,aligny center");
		layeredPane.setLayer(endSpinner, 1);
				
		JButton saveChanges = new JButton("Save Changes");
		layeredPane.setLayer(saveChanges, 1);
		saveChanges.setIcon(null);
		saveChanges.setName("saveChanges");
		saveChanges.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Calendar startTime = Calendar.getInstance();
				startTime.setTime((Date)startSpinner.getValue());
				Calendar endTime = Calendar.getInstance();
				endTime.setTime((Date)endSpinner.getValue());
				
				CourierSystem.CityMap.getIntersection(lblIntersection.getText().substring(0, lblIntersection.getText().length() - " Closure".length())).changeClosure(startTime, endTime);
				/*try {
					CourierSystem.UpdateCityMap();
				} catch (Exception e1) {
					e1.printStackTrace();
				}*/
				// indicate that the intersection is closed
				if(!CourierSystem.CityMap.getIntersection(lblIntersection.getText().substring(0, lblIntersection.getText().length() - " Closure".length())).isOpen()) {
					for(Component button :layeredPane.getComponentsInLayer(1)) {
						if(button.getClass() == JButton.class && ((JButton)button).getText().equals(lblIntersection.getText().substring(0, lblIntersection.getText().length() - " Closure".length()))) {
							((JButton)button).setIcon(new ImageIcon(MapManagement.class.getResource("/view/cancelled.png")));
							((JButton)button).setText("");
						}
					}
				} else {
					for(Component button :layeredPane.getComponentsInLayer(1)) {
						if(button.getClass() == JButton.class && ((JButton)button).getName().equals(lblIntersection.getText().substring(0, lblIntersection.getText().length() - " Closure".length()))) {
							((JButton)button).setIcon(null);
							((JButton)button).setText(button.getName());
						}
					}
				}
				
			}
		});
		saveChanges.setVisible(false);
		layeredPane.add(saveChanges, "cell 11 0 3");
		
		JButton cancel = new JButton("Cancel");
		layeredPane.setLayer(cancel, 1);
		cancel.setIcon(null);
		cancel.setName("cancel");
		cancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				lblClosureEnd.setVisible(false);
				lblClosureStart.setVisible(false);
{'fraction_non_alphanumeric': 0.14969072164948455, 'fraction_numerical': 0.03505154639175258, 'mean_word_length': 5.08976773383553, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3823621', 'n_tokens_mistral': 3798, 'n_tokens_neox': 3181, 'n_words': 527}