
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.net.*;
import java.io.*;
import java.util.*;
import java.util.Properties;
import java.text.*;

public class WOR_FormFrame37 extends JInternalFrame {

	static int openFrameCount = 0;
	static final int offset = 20;

	JTextField desPSField, desDateField, engPSField, engDateField, projPSField;
	JTextField custPSField, platPSField, IRField, WORField;
	JTextField aDateField, CadField, DrwField, engApField;
	JTextArea EJDcontent;

	String des_prop_val, eng_prop_val, proj_prop_val, cust_prop_val, plat_prop_val;

	String[] engAp_val	= { "No","Yes" };
	String[] Cad_val	= { "ProEng","Catia","Cadra","UG","Acad" };
	String[] Drw_val	= { "Layout","Experimental","Z Drawing","Released" };

	String if_wor, irTxt = "", NEJDstg, EJDgetstg, EJDstgtmp, savestg;
	String prjcts, dsgns, engns, cstmrs, pltfms, dtstg, dtstgsh, aDateStg;
	String fCadStg, fDrwStg, projStg, desStg, engStg, custStg, platStg;
	String desDt, engDt, engApStg, shworflnm, rworflnmver3;

	String WOR_DIR 	= "./wor";
	String EJDstg = "1. On Drawing ***, Change the following:\n\n" +
					"2. On Drawing ***, Change the following:\n\n" +
					"3. On Drawing ***, Change the following:\n\n" +
					"4. On Drawing ***, Change the following:\n\n" +
					"5. On Drawing ***, Change the following:\n";

    public WOR_FormFrame37 ( String if_wor, String savestg ){

		super("", true, true, true, true);
		setResizable( true );
		openFrameCount++;

		// Designers
		final String des_propsfile = "ROG_des.properties";
		String ROG_desSTG = "ROG_des.";
		Properties des_props = new Properties ();

		try {
			InputStream in = new FileInputStream(des_propsfile);
			des_props.load(in);
			in.close();
		}
		catch (IOException e) {}

		String[] des_prop_val = new String[des_props.size()];

		for (int n = 0; n < des_props.size(); n++) {
			des_prop_val[n] = des_props.getProperty(ROG_desSTG + n);
			//System.out.println( n + ": " + des_prop_val[n] );
		}

		// Engineers
		final String eng_propsfile = "ROG_eng.properties";
		String ROG_engSTG = "ROG_eng.";
		Properties eng_props = new Properties ();

		try {
			InputStream in = new FileInputStream(eng_propsfile);
			eng_props.load(in);
			in.close();
		}
		catch (IOException e) {}

		String[] eng_prop_val = new String[eng_props.size()];

		for (int n = 0; n < eng_props.size(); n++) {
			eng_prop_val[n] = eng_props.getProperty(ROG_engSTG + n);
		}

		// Projects
		final String proj_propsfile = "ROG_proj.properties";
		String ROG_projSTG = "ROG_proj.";
		Properties proj_props = new Properties ();

		try {
			InputStream in = new FileInputStream(proj_propsfile);
			proj_props.load(in);
            in.close();
		}
		catch (IOException e) {}

		String[] proj_prop_val = new String[proj_props.size()];

		for (int n = 0; n < proj_props.size(); n++) {
			proj_prop_val[n] = proj_props.getProperty(ROG_projSTG + n);
		}

		// Customers
		final String cust_propsfile = "ROG_cust.properties";
		String ROG_custSTG = "ROG_cust.";
		Properties cust_props = new Properties ();

		try {
			InputStream in = new FileInputStream(cust_propsfile);
			cust_props.load(in);
			in.close();
		}
		catch (IOException e) {}

		String[] cust_prop_val = new String[cust_props.size()];

		for (int n = 0; n < cust_props.size(); n++) {
			cust_prop_val[n] = cust_props.getProperty(ROG_custSTG + n);
		}

		// Platforms
		final String plat_propsfile = "ROG_plat.properties";
		String ROG_platSTG = "ROG_plat.";
		Properties plat_props = new Properties ();

		try {
			InputStream in = new FileInputStream(plat_propsfile);
			plat_props.load(in);
			in.close();
		}
		catch (IOException e) {}

		String[] plat_prop_val = new String[plat_props.size()];

		for (int n = 0; n < plat_props.size(); n++) {
			plat_prop_val[n] = plat_props.getProperty(ROG_platSTG + n);
		}

		if ( if_wor == "null-stg" ) {
			setTitle("PRODUCT DESIGN WORK ORDER REQUEST " + openFrameCount + " : New Form");

			dtstg		= getDatestg();
			NEJDstg		= EJDstg;
			engApStg	= engAp_val[0];
			desDt = engDt = aDateStg = getDatestgsh();
			desStg = engStg	= projStg = custStg	= platStg = fCadStg = fDrwStg = "";
		}
		else {
			setTitle("PRODUCT DESIGN WORK ORDER REQUEST " + openFrameCount + " : Existing Form");

			// Read WOR Properties file
			final String WOR_propsfile = if_wor;
			Properties WOR_props = new Properties ();

			try {
				InputStream din = new FileInputStream(WOR_propsfile);
				WOR_props.load(din);
	            din.close();

				dtstg		= WOR_props.getProperty("WOR_File_Name");
				dtstgsh		= WOR_props.getProperty("Date_STG");
				irTxt		= WOR_props.getProperty("IR_Packet");
				desStg		= WOR_props.getProperty("Designer");
				desDt		= WOR_props.getProperty("Designer_Date");
				engStg		= WOR_props.getProperty("Engineer");
				engDt		= WOR_props.getProperty("Engineer_Date");
				projStg		= WOR_props.getProperty("Project");
				custStg		= WOR_props.getProperty("Customer");
				platStg		= WOR_props.getProperty("Platform");
				aDateStg	= WOR_props.getProperty("Date_Reqd");
				fCadStg		= WOR_props.getProperty("Cad_Sys");
				fDrwStg		= WOR_props.getProperty("Drawing_Format");
				engApStg	= WOR_props.getProperty("Eng_Approval");
				EJDgetstg	= WOR_props.getProperty("Eng_Job_Descr_STG");
				NEJDstg		= get_dnd2n();
			}
			catch (IOException e) {}
		}

		JPanel topPanel = new JPanel();
		topPanel.setBorder(new EmptyBorder(1,1,1,1));
		topPanel.setLayout(new BorderLayout());

		// WOR Form Grid
		JPanel WORformGrid = new JPanel();
		GridBagLayout gbc0 = new GridBagLayout();
		WORformGrid.setLayout(gbc0);

		// Header Panel
		JPanel HeaderPanel = new JPanel();
		GridBagLayout gbc6 = new GridBagLayout();
		HeaderPanel.setLayout(gbc6);

		dtstgsh = getDatestgsh();

		// WORPanel Layout
		JPanel WORPanel = new JPanel();
		JLabel WORLabel = new JLabel( "Work Order Request #: " );

		if ( if_wor == "null-stg" ) WORField = new JTextField(10);
		else WORField = new JTextField(dtstg, 10);

		WORField.setEditable( false );
		WORPanel.add(WORLabel);
		WORPanel.add(WORField);

		// Date Layout
		JPanel datePanel = new JPanel();
		JLabel dateLabel = new JLabel( "Date: " + dtstgsh );
		datePanel.add(dateLabel);

		HeaderPanel.add(WORPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));
		HeaderPanel.add(datePanel, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));

		// Designers
		JPanel desPanel = new JPanel();
		GridBagLayout gbc2 = new GridBagLayout();
		desPanel.setLayout(gbc2);

		JPanel desPSPanel = new JPanel();
		JLabel desPSLabel = new JLabel ("Designer: ");
		desPSField = new JTextField(desStg,12);
		desPSPanel.add(desPSLabel);
		desPSPanel.add(desPSField);

		JPanel desCBPanel = new JPanel();
		final JComboBox dsgnsComboBox = new JComboBox(des_prop_val);
		dsgnsComboBox.setSelectedItem(desStg);
		desCBPanel.add(dsgnsComboBox);

		dsgnsComboBox.addItemListener(
			new ItemListener() {
				public void itemStateChanged( ItemEvent e ) {
					if( e.getStateChange() == ItemEvent.SELECTED ){
						desPSField.setText("" + ((JComboBox)e.getSource()).getSelectedItem());
					}
				}
			}
		);

		// Designer Date Layout
		JPanel desDatePanelLt = new JPanel();
		JLabel desDateLabel = new JLabel( "Date: " );
		desDatePanelLt.add(desDateLabel);

		JPanel desDatePanelRt = new JPanel();
		desDateField = new JTextField(""+ desDt, 6);
		desDatePanelRt.add(desDateField);

		desPanel.add(desPSPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));
		desPanel.add(desCBPanel, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));
		desPanel.add(desDatePanelLt, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));
		desPanel.add(desDatePanelRt, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));

		// Engineers
		JPanel engPanel = new JPanel();
		GridBagLayout gbc3 = new GridBagLayout();
		engPanel.setLayout(gbc3);

		JPanel engPSPanel = new JPanel();
		JLabel engPSLabel = new JLabel ("Engineer: ");
		engPSField = new JTextField(engStg,11);
		engPSPanel.add(engPSLabel);
		engPSPanel.add(engPSField);

		JPanel engCBPanel = new JPanel();
		final JComboBox engnsComboBox = new JComboBox(eng_prop_val);
		engnsComboBox.setSelectedItem(engStg);
		engCBPanel.add(engnsComboBox);

		engnsComboBox.addItemListener(
			new ItemListener() {
				public void itemStateChanged( ItemEvent e ) {
					if( e.getStateChange() == ItemEvent.SELECTED ){
						engPSField.setText("" + ((JComboBox)e.getSource()).getSelectedItem());
					}
				}
			}
		);

		// Engineer Date Layout
		JPanel engDatePanelLt = new JPanel();
		JLabel engDateLabel = new JLabel( "Date: " );
		engDatePanelLt.add(engDateLabel);

		JPanel engDatePanelRt = new JPanel();
		engDateField = new JTextField(""+ engDt, 6);
		engDatePanelRt.add(engDateField);

		engPanel.add(engPSPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));
		engPanel.add(engCBPanel, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));
		engPanel.add(engDatePanelLt, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));
		engPanel.add(engDatePanelRt, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));

		// Projects
		JPanel projPanel = new JPanel();
		GridBagLayout gbc1 = new GridBagLayout();
		projPanel.setLayout(gbc1);

		JPanel projPSPanel = new JPanel();
		JLabel projPSLabel = new JLabel ("Project #: ");
		projPSField = new JTextField(projStg,28);
		projPSPanel.add(projPSLabel);
		projPSPanel.add(projPSField);

		JPanel projCBPanel = new JPanel();
		final JComboBox prjctsComboBox = new JComboBox(proj_prop_val);
		prjctsComboBox.setSelectedItem(projStg);
		projCBPanel.add(prjctsComboBox);

		prjctsComboBox.addItemListener(
			new ItemListener() {
				public void itemStateChanged( ItemEvent e ) {
					if( e.getStateChange() == ItemEvent.SELECTED ){
						projPSField.setText("" + ((JComboBox)e.getSource()).getSelectedItem());
					}
				}
			}
		);

		projPanel.add(projPSPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));
		projPanel.add(projCBPanel, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));

		// Customers
		JPanel custPanel = new JPanel();
		GridBagLayout gbc4 = new GridBagLayout();
		custPanel.setLayout(gbc4);

		JPanel custPSPanel = new JPanel();
		JLabel custPSLabel = new JLabel ("Customer: ");
		custPSField = new JTextField(custStg,23);
		custPSPanel.add(custPSLabel);
		custPSPanel.add(custPSField);

		JPanel custCBPanel = new JPanel();
		final JComboBox cstmrsComboBox = new JComboBox(cust_prop_val);
		cstmrsComboBox.setSelectedItem(custStg);
		custCBPanel.add(cstmrsComboBox);

		cstmrsComboBox.addItemListener(
			new ItemListener() {
				public void itemStateChanged( ItemEvent e ) {
					if( e.getStateChange() == ItemEvent.SELECTED ){
						custPSField.setText("" + ((JComboBox)e.getSource()).getSelectedItem());
					}
				}
			}
		);

		custPanel.add(custPSPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));
		custPanel.add(custCBPanel, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));

		// Platforms
		JPanel platPanel = new JPanel();
		GridBagLayout gbc5 = new GridBagLayout();
		platPanel.setLayout(gbc5);

		JPanel platPSPanel = new JPanel();
		JLabel platPSLabel = new JLabel ("Vehicle Platform: ");
		platPSField = new JTextField(platStg,18);
		platPSPanel.add(platPSLabel);
		platPSPanel.add(platPSField);

		JPanel platCBPanel = new JPanel();
		final JComboBox pltfmsComboBox = new JComboBox(plat_prop_val);
		pltfmsComboBox.setSelectedItem(platStg);
		platCBPanel.add(pltfmsComboBox);

		pltfmsComboBox.addItemListener(
			new ItemListener() {
				public void itemStateChanged( ItemEvent e ) {
					if( e.getStateChange() == ItemEvent.SELECTED ){
						platPSField.setText("" + ((JComboBox)e.getSource()).getSelectedItem());
					}
				}
			}
		);

		platPanel.add(platPSPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));
		platPanel.add(platCBPanel, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));

		JPanel EJDPanel = new JPanel();
		EJDPanel.setBorder(new EmptyBorder(2,2,2,2));
		EJDPanel.setLayout(new BorderLayout());
		JLabel EJDLabel = new JLabel("Engineering Job Description:");
		EJDcontent = new JTextArea(NEJDstg, 10,40);
		EJDcontent.setBorder( new EmptyBorder(2,2,2,2));
		EJDcontent.setLineWrap(false);

		JScrollPane textScroller = new JScrollPane(EJDcontent,
						   				JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
						   				JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED );

		EJDPanel.add(EJDLabel, BorderLayout.NORTH);
		EJDPanel.add(textScroller, BorderLayout.SOUTH);

		// Grid Panel Layout
		WORformGrid.add(HeaderPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));
		WORformGrid.add(desPanel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));
		WORformGrid.add(engPanel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));
		WORformGrid.add(projPanel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));
		WORformGrid.add(custPanel, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));
		WORformGrid.add(platPanel, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));
		WORformGrid.add(EJDPanel, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));

		// Side Grid Panel
		JPanel SideGridPanel = new JPanel();
		GridBagLayout gbc10 = new GridBagLayout();
		SideGridPanel.setLayout(gbc10);

		// IR Grid Panel
		JPanel IRGridPanel = new JPanel();
		GridBagLayout gbc15 = new GridBagLayout();
		IRGridPanel.setLayout(gbc15);

		JPanel IRPanelUp = new JPanel();
		JLabel IRLabel = new JLabel( "IR Packet #: " );
		IRPanelUp.add(IRLabel);

		JPanel IRPanelLw = new JPanel();
		IRField = new JTextField(""+ irTxt, 8);
		IRPanelLw.add(IRField);

		// Action Date Grid Panel
		IRGridPanel.add(IRPanelUp, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));
		IRGridPanel.add(IRPanelLw, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));

		JPanel aDateGridPanel = new JPanel();
		GridBagLayout gbc11 = new GridBagLayout();
		aDateGridPanel.setLayout(gbc11);

		// Action Date Layout
		JPanel aDatePanelUp = new JPanel();
		JLabel aDateLabel = new JLabel( "Date Req'd: " );
		aDatePanelUp.add(aDateLabel);

		JPanel aDatePanelDn = new JPanel();
		aDateField = new JTextField(""+ aDateStg, 8);
		aDatePanelDn.add(aDateField);

		// Action Date Grid Panel
		aDateGridPanel.add(aDatePanelUp, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));
		aDateGridPanel.add(aDatePanelDn, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));

		// Cad Grid Panel
		JPanel CadGridPanel = new JPanel();
		GridBagLayout gbc12 = new GridBagLayout();
		CadGridPanel.setLayout(gbc12);

		JPanel CadPanelUp = new JPanel();
		JLabel CadLabel = new JLabel ("Cad System: ");
		CadPanelUp.add(CadLabel);

		JPanel CadPanelMid = new JPanel();
		CadField = new JTextField(""+ fCadStg, 8);
		CadPanelMid.add(CadField);

		JPanel CadPanelLw = new JPanel();
		final JComboBox CadComboBox = new JComboBox(Cad_val);
		CadComboBox.setSelectedItem(Cad_val[0]);
		CadPanelLw.add(CadComboBox);

		CadComboBox.addItemListener(
			new ItemListener() {
				public void itemStateChanged( ItemEvent e ) {
					if( e.getStateChange() == ItemEvent.SELECTED ){
						CadField.setText("" + ((JComboBox)e.getSource()).getSelectedItem());
					}
				}
			}
		);

		// Cad Grid Panel Layout
		CadGridPanel.add(CadPanelUp, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));
		CadGridPanel.add(CadPanelMid, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));
		CadGridPanel.add(CadPanelLw, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));

		// Drw Grid Panel
		JPanel DrwGridPanel = new JPanel();
		GridBagLayout gbc13 = new GridBagLayout();
		DrwGridPanel.setLayout(gbc13);

		JPanel DrwPanelUp = new JPanel();
		JLabel DrwLabel = new JLabel ("Drawing Format: ");
		DrwPanelUp.add(DrwLabel);

		JPanel DrwPanelMid = new JPanel();
		DrwField = new JTextField(""+ fDrwStg, 9);
		DrwPanelMid.add(DrwField);

		JPanel DrwPanelLw = new JPanel();
		final JComboBox DrwComboBox = new JComboBox(Drw_val);
		DrwComboBox.setSelectedItem(Drw_val[0]);
		DrwPanelLw.add(DrwComboBox);

		DrwComboBox.addItemListener(
			new ItemListener() {
				public void itemStateChanged( ItemEvent e ) {
					if( e.getStateChange() == ItemEvent.SELECTED ){
						DrwField.setText("" + ((JComboBox)e.getSource()).getSelectedItem());
					}
				}
			}
		);

		// Drw Grid Panel Layout
		DrwGridPanel.add(DrwPanelUp, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));
		DrwGridPanel.add(DrwPanelMid, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));
		DrwGridPanel.add(DrwPanelLw, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));

		// Engineer Approved Grid Panel
		JPanel engApGridPanel = new JPanel();
		GridBagLayout gbc14 = new GridBagLayout();
		engApGridPanel.setLayout(gbc14);

		// Engineer Approved Layout
		JPanel engApPanelUp = new JPanel();
		JLabel engApLabel = new JLabel( "Eng. Approved: " );
		engApPanelUp.add(engApLabel);

		JPanel engApPanelMid = new JPanel();
		engApField = new JTextField(""+ engApStg, 4);
		engApPanelMid.add(engApField);

		JPanel engApPanelLw = new JPanel();
		final JComboBox engApComboBox = new JComboBox(engAp_val);
		engApComboBox.setSelectedItem(engAp_val[0]);
		engApPanelLw.add(engApComboBox);

		engApComboBox.addItemListener(
			new ItemListener() {
				public void itemStateChanged( ItemEvent e ) {
					if( e.getStateChange() == ItemEvent.SELECTED ){
						engApField.setText("" + ((JComboBox)e.getSource()).getSelectedItem());
					}
				}
			}
		);

		engApGridPanel.add(engApPanelUp, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));
		engApGridPanel.add(engApPanelMid, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));
		engApGridPanel.add(engApPanelLw, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));

		// Side Grid Panel Layout
		SideGridPanel.add(IRGridPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));
		SideGridPanel.add(aDateGridPanel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));
		SideGridPanel.add(CadGridPanel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));
		SideGridPanel.add(DrwGridPanel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));
		SideGridPanel.add(engApGridPanel, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 1, 0));

		topPanel.add(WORformGrid, BorderLayout.WEST);
		topPanel.add(SideGridPanel, BorderLayout.EAST);

		JPanel buttonPanel = new JPanel();
		buttonPanel.setLayout ( new FlowLayout(FlowLayout.CENTER) );
		JButton SaveBut = new JButton("SAVE");
		SaveBut.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SaveSelected();
		}});
		if ( savestg == "save" ) { buttonPanel.add(SaveBut); }

		JButton ExitBut = new JButton("EXIT");
		ExitBut.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ExitSelected();
		}});
		buttonPanel.add(ExitBut);
		topPanel.add(buttonPanel, BorderLayout.SOUTH);

		setContentPane(topPanel);
		pack();
		setLocation( offset * openFrameCount, offset * openFrameCount);
    }

	public void SaveSelected() {

		String irTxt	= getirField();
		String prjcts 	= getProj();
		String dsgns 	= getDes();
		String desDt	= getdesDateStg();
		String engns 	= getEng();
		String engDt	= getengDateStg();
		String cstmrs 	= getCust();
		String pltfms 	= getPlat();
		String EJDn2dnd	= put_n2dnd();
		String EJDn2br 	= put_n2br();
		String aDateStg	= getaDateStg();
		String fCadStg	= getaCadStg();
		String fDrwStg	= getaDrwStg();
		String engApStg	= getengApStg();
    	String dtstgsh 	= getDatestgsh();

		String shworflnm = dtstg + ".wor";
		String shhtmflnm = dtstg + ".htm";
		String worflnm	= WOR_DIR + "/" + shworflnm;
		String htmflnm	= WOR_DIR + "/" + shhtmflnm;

		String revstg	= getRevstg( shworflnm );
		String rworflnm	= WOR_DIR + "/" + revstg;

		try {
			PrintStream ff = new PrintStream(new FileOutputStream(worflnm));
			ff.println( "WOR_File_Name=" + dtstg );
			ff.println( "Date_STG=" + dtstgsh );
			ff.println( "IR_Packet=" + irTxt );
			ff.println( "Project=" + prjcts );
			ff.println( "Designer=" + dsgns );
			ff.println( "Designer_Date=" + desDt );
			ff.println( "Engineer=" + engns );
			ff.println( "Engineer_Date=" + engDt );
			ff.println( "Customer=" + cstmrs );
			ff.println( "Platform=" + pltfms );
			ff.println( "Date_Reqd=" + aDateStg );
			ff.println( "Cad_Sys=" + fCadStg );
			ff.println( "Drawing_Format=" + fDrwStg );
			ff.println( "Eng_Approval=" + engApStg );
			ff.println( "Eng_Job_Descr_STG=" + EJDn2dnd );
			ff.flush();
			ff.close();
		} catch(java.io.IOException IOEx) { System.out.println("Cannot create " + worflnm + " file."); }

		try {
			PrintStream ff2 = new PrintStream(new FileOutputStream(rworflnm));
			ff2.println( "WOR_File_Name=" + dtstg );
			ff2.println( "Date_STG=" + dtstgsh );
			ff2.println( "IR_Packet=" + irTxt );
			ff2.println( "Project=" + prjcts );
			ff2.println( "Designer=" + dsgns );
			ff2.println( "Designer_Date=" + desDt );
			ff2.println( "Engineer=" + engns );
			ff2.println( "Engineer_Date=" + engDt );
			ff2.println( "Customer=" + cstmrs );
			ff2.println( "Platform=" + pltfms );
			ff2.println( "Date_Reqd=" + aDateStg );
			ff2.println( "Cad_Sys=" + fCadStg );
			ff2.println( "Drawing_Format=" + fDrwStg );
			ff2.println( "Eng_Approval=" + engApStg );
			ff2.println( "Eng_Job_Descr_STG=" + EJDn2dnd );
			ff2.flush();
			ff2.close();

		} catch(java.io.IOException IOEx) { System.out.println("Cannot create " + rworflnm + " file."); }

		try {
			PrintStream p = new PrintStream(new FileOutputStream(htmflnm));
			p.println( "<html><head>" );
			p.println( "<title> PRODUCT DESIGN WORK ORDER REQUEST: " + shhtmflnm + "</title>" );
			p.println( "</head><body bgcolor=\"white\">" );
			p.println( "<center><table width=\"500\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">" );
			p.println( "<tr><td align=center colspan=2><H2>Product Design Work Order Request</H2><HR></td></tr>" );
			p.println( "<tr><td><H3>Work Order Request #: " + dtstg + "</H3></td>" );
			p.println( "<td><H3>Date: " + dtstgsh + "</H3></td></tr>" );
			p.println( "<tr><td><H3>IR Packet #: " + irTxt + "</H3></td>" );
			p.println( "<td><H3>Project: " + prjcts + "</H3></td></tr>" );
			p.println( "<tr><td><H3>Designer: " + dsgns + "</H3></td>" );
			p.println( "<td><H3>Date: " + desDt + "</H3></td></tr>" );
			p.println( "<tr><td><H3>Engineer: " + engns + "</H3></td>" );
			p.println( "<td><H3>Date: " + engDt + "</H3></td></tr>" );
			p.println( "<tr><td><H3>Customer: " + cstmrs + "</H3></td>" );
			p.println( "<td><H3>Platform: " + pltfms + "</H3></td></tr>" );
			p.println( "<tr><td><H3>Date Reqd: " + aDateStg + "</H3></td>" );
			p.println( "<td><H3>Cad System: " + fCadStg + "</H3></td></tr>" );
			p.println( "<tr><td><H3>Drawing Format: " + fDrwStg + "</H3></td>" );
			p.println( "<td><H3>Engineering Approval: " + engApStg + "</H3></td></tr>" );
			p.println( "<tr><td colspan=2><HR><H3>Engineering Job Description:<br><br>" + EJDn2br + "</H3></td></tr>" );
			p.println( "</table></center></body></html>" );
			p.flush();
			p.close();
		} catch(java.io.IOException IOEx) {System.out.println("Cannot create HTML file."); }

    	WORField.setText(String.valueOf(dtstg));
	}

	public String getRevstg( String shworflnm ) {

		for ( int x = 1; x < 100; x++ ) {
			String rworflnmver = shworflnm + "." + x;
			String rworflnm	= WOR_DIR + "/" + rworflnmver;

			File file = new File( rworflnm );
			if ( file.exists() ) {}
			else { return rworflnmver;}
		}

		return rworflnmver3;
	}

	public String getDatestgsh() {
 		SimpleDateFormat df = new SimpleDateFormat ("MM/dd/yy", Locale.getDefault());
		Date tm = new Date();
		String dateinst = df.format(tm);

		return dateinst;
	}

    public void ExitSelected() {
		this.setVisible(false);
	}

	public String getirField() {
		irTxt = IRField.getText();
		return irTxt;
	}

	public String getProj() {
		prjcts = projPSField.getText();
		return prjcts;
	}

	public String getDes() {
		dsgns = desPSField.getText();
		return dsgns;
	}

	public String getdesDateStg() {
		desDt = desDateField.getText();
		return desDt;
	}

	public String getEng() {
		engns = engPSField.getText();
		return engns;
	}

	public String getengDateStg() {
		engDt = engDateField.getText();
		return engDt;
	}

	public String getCust() {
		cstmrs = custPSField.getText();
		return cstmrs;
	}

	public String getPlat() {
		pltfms = platPSField.getText();
		return pltfms;
	}

	public String getaDateStg() {
		aDateStg = aDateField.getText();
		return aDateStg;
	}

	public String getaCadStg() {
		fCadStg = CadField.getText();
		return fCadStg;
	}

	public String getaDrwStg() {
		fDrwStg = DrwField.getText();
		return fDrwStg;
	}

	public String getengApStg() {
		engApStg = engApField.getText();
		return engApStg;
	}

	// change /n 2 |-n-|
	public String put_n2dnd() {
		String EJDstgtmp = EJDcontent.getText();
		String EJDstg1 = StgReplace(EJDstgtmp,"\n","|-n-|");

		return EJDstg1;
	}

	// change /n 2 <br>
	public String put_n2br() {
		String EJDstgtmp = EJDcontent.getText();
		String EJDstg1 = StgReplace(EJDstgtmp,"\n","<br>");

		return EJDstg1;
	}

	// change |-n-| 2 \n
	public String get_dnd2n() {
		EJDstgtmp = EJDgetstg;
		String EJDstg1 = StgReplace(EJDstgtmp,"|-n-|","\n");

		return EJDstg1;
	}

	public static String StgReplace (String target, String from, String to) {
		int start = target.indexOf (from);
		if (start==-1) return target;
		int lf = from.length();
		int tf = target.length();
		char [] targetChars = target.toCharArray();
		StringBuffer buffer = new StringBuffer();
		int copyFrom=0;
		while (start != -1)
		{
			buffer.append (targetChars, copyFrom, start-copyFrom);
			buffer.append (to);
			copyFrom=start+lf;
			start = target.indexOf (from, copyFrom);
		}
		buffer.append (targetChars, copyFrom, targetChars.length-copyFrom);
		String finstg = buffer.toString();

		return finstg;
	}

	public String getDatestg() {
 		SimpleDateFormat formatter = new SimpleDateFormat ("yyMM", Locale.getDefault());
        Date dt = new Date();
		String yyMM = formatter.format(dt);

		for ( int x = 1; x < 1000; x++ )
		{
			String tn = "";
			if ( x<10 ) tn="00";
			if ( x<100 && x>9 ) tn="0";

			dtstg = yyMM + tn + x;

			String worflnm = WOR_DIR + "/" + dtstg + ".wor";

			File file = new File( worflnm );
			if ( file.exists() && file.isFile() && file.canRead() ) {}
			else { break; }
		}

		return dtstg;
	}
}
