<commit_before>/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2009-2011 Ausenco Engineering Canada Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
package com.sandwell.JavaSimulation3D;

import com.sandwell.JavaSimulation.EventManager;
import com.sandwell.JavaSimulation.Tester;
import com.sandwell.JavaSimulation.Util;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;

/**
 * Class to display, and control the execution of events in the EventManager
 * <p>
 * EventViewer displays:<br>
 * the curent event time<br>
 * the events for the current event time<br>
 * the wait until events<br>
 * the pending events for all upcoming event times<br>
 * <p>
 * EventViewer provides:<br>
 * the ability to view pending events <br>
 * the ability to execute all events for the next timestep (including wait until events)<br>
 * the ability to execute a single event <br>
 * the ability to execute only waituntil events <br>
 */
public class EventViewer extends JFrame {
	JTable eventList;
	JScrollPane sp;
	EventManager evtMan;
	java.awt.event.MouseListener propertyListener;

	int numRetiredEvents = 0;

	/** Constructor creates and displays a new ModelBox for the specified DisplayEntity at the specified location **/
	public EventViewer( EventManager em ) {
		super("Event Viewer");
		setDefaultCloseOperation( FrameBox.DISPOSE_ON_CLOSE );

		numRetiredEvents = 0;

		evtMan = em;

		String[] headers = evtMan.getViewerHeaders();
		eventList = new JTable(new DefaultTableModel(0, headers.length));
		eventList.setFillsViewportHeight(true);
		eventList.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );

		sp = new JScrollPane();
		sp.getViewport().add(eventList);
		sp.setPreferredSize(new Dimension( 800, 300 ));
		getContentPane().add(sp, BorderLayout.CENTER);

		for (int i = 0; i < headers.length; i++) {
			eventList.getColumnModel().getColumn(i).setHeaderValue(headers[i]);
			eventList.getColumnModel().getColumn(i).setMinWidth(headers[i].length() * 6);
		}
		// create a close button on the bottom of the screen
		JButton closeButton = new JButton( "Close" );
		closeButton.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				dispose();
			}
		});

		JButton nextEventButton = new JButton( "Next Event" );
		nextEventButton.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent e ) {
				evtMan.nextOneEvent();
			}
		});

		JButton nextTimeButton = new JButton( "Next Time" );
		nextTimeButton.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent e ) {
				evtMan.nextEventTime();
			}
		});
		final JTextField runToTime = new JTextField();
		runToTime.setPreferredSize( new Dimension( 55, 16 ) );

		JButton runToButton = new JButton( "Run To Time" );
		runToButton.addActionListener( new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					if (Tester.isDate(runToTime.getText())) {
						String[] str = runToTime.getText().split("-");

						if (str.length < 3) {
							throw new NumberFormatException("Date string must be of form yyyy-mm-dd");
						}
						int year = Integer.valueOf(str[0]).intValue();
						int month = Integer.valueOf(str[1]).intValue();
						int day = Integer.valueOf(str[2]).intValue();
						double time = Clock.calcTimeForYear_Month_Day_Hour(year, month, day, 0.0);

						int startingYear = Clock.getStartingYear();
						int startingMonth = Clock.getStartingMonth();
						int startingDay = Clock.getStartingDay();
						double startingTime = Clock.calcTimeForYear_Month_Day_Hour(startingYear, startingMonth, startingDay, 0.0);

						evtMan.runToTime(time - startingTime);
					} else {
						evtMan.runToTime(Double.parseDouble(runToTime.getText()));
					}
				} catch (NumberFormatException nfe) {
					JOptionPane.showMessageDialog(null, "Invalid Event Time", "error", JOptionPane.ERROR_MESSAGE);
				}
			}
		});

		JButton clearButton = new JButton( "Clear Events" );
		clearButton.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent e ) {
				numRetiredEvents = 0;
				update();
			}
		});

		JPanel buttonPanel = new JPanel();
		buttonPanel.setLayout( new FlowLayout( FlowLayout.CENTER ) );
		buttonPanel.add( nextEventButton );
		buttonPanel.add( nextTimeButton );
		buttonPanel.add( runToTime );
		buttonPanel.add( runToButton );
		buttonPanel.add( clearButton );
		buttonPanel.add( closeButton );
		getContentPane().add(buttonPanel, BorderLayout.SOUTH);<commit_msg>JS3D: remove Run To Time from EventViewer<commit_after>/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2009-2011 Ausenco Engineering Canada Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
package com.sandwell.JavaSimulation3D;

import com.sandwell.JavaSimulation.EventManager;
import com.sandwell.JavaSimulation.Util;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/**
 * Class to display, and control the execution of events in the EventManager
 * <p>
 * EventViewer displays:<br>
 * the curent event time<br>
 * the events for the current event time<br>
 * the wait until events<br>
 * the pending events for all upcoming event times<br>
 * <p>
 * EventViewer provides:<br>
 * the ability to view pending events <br>
 * the ability to execute all events for the next timestep (including wait until events)<br>
 * the ability to execute a single event <br>
 * the ability to execute only waituntil events <br>
 */
public class EventViewer extends JFrame {
	JTable eventList;
	JScrollPane sp;
	EventManager evtMan;
	java.awt.event.MouseListener propertyListener;

	int numRetiredEvents = 0;

	/** Constructor creates and displays a new ModelBox for the specified DisplayEntity at the specified location **/
	public EventViewer( EventManager em ) {
		super("Event Viewer");
		setDefaultCloseOperation( FrameBox.DISPOSE_ON_CLOSE );

		numRetiredEvents = 0;

		evtMan = em;

		String[] headers = evtMan.getViewerHeaders();
		eventList = new JTable(new DefaultTableModel(0, headers.length));
		eventList.setFillsViewportHeight(true);
		eventList.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );

		sp = new JScrollPane();
		sp.getViewport().add(eventList);
		sp.setPreferredSize(new Dimension( 800, 300 ));
		getContentPane().add(sp, BorderLayout.CENTER);

		for (int i = 0; i < headers.length; i++) {
			eventList.getColumnModel().getColumn(i).setHeaderValue(headers[i]);
			eventList.getColumnModel().getColumn(i).setMinWidth(headers[i].length() * 6);
		}
		// create a close button on the bottom of the screen
		JButton closeButton = new JButton( "Close" );
		closeButton.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				dispose();
			}
		});

		JButton nextEventButton = new JButton( "Next Event" );
		nextEventButton.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent e ) {
				evtMan.nextOneEvent();
			}
		});

		JButton nextTimeButton = new JButton( "Next Time" );
		nextTimeButton.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent e ) {
				evtMan.nextEventTime();
			}
		});

		JButton clearButton = new JButton( "Clear Events" );
		clearButton.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent e ) {
				numRetiredEvents = 0;
				update();
			}
		});

		JPanel buttonPanel = new JPanel();
		buttonPanel.setLayout( new FlowLayout( FlowLayout.CENTER ) );
		buttonPanel.add( nextEventButton );
		buttonPanel.add( nextTimeButton );
		buttonPanel.add( clearButton );
		buttonPanel.add( closeButton );
		getContentPane().add(buttonPanel, BorderLayout.SOUTH);
{'fraction_non_alphanumeric': 0.10103204780010863, 'fraction_numerical': 0.00619228680065182, 'mean_word_length': 4.408930669800235, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 27, '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': '1076469', 'n_tokens_mistral': 3021, 'n_tokens_neox': 2704, 'n_words': 820}