import java.io.*; import java.beans.*; import java.net.URL; import java.text.*; import java.awt.*; import java.awt.Window; import java.awt.event.*; import javax.swing.*; import javax.swing.JOptionPane; import javax.swing.border.*; import javax.swing.plaf.*; import javax.swing.event.*; import javax.swing.JFrame; import javax.swing.JList; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.JButton; import javax.swing.JScrollPane; import javax.swing.DefaultListModel; import java.util.*; import java.util.List; import java.util.Vector; import java.util.ResourceBundle; import sun.net.ftp.FtpClient; public class NCR30h implements ListSelectionListener { public static void main(String[] arg){ new NCR30h(); } public NCR30h() { WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) { DelOut(); System.exit(0); } }; //loc1 = "h"; loc1 = "d"; container=new JFrame("NCR Query"); container.addWindowListener(l); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize=new Dimension((int)(screenSize.width/2),(int)(screenSize.height/2)); int x=(int)(frameSize.width/2); int y=(int)(frameSize.height/2); container.setBounds(x,y,frameSize.width,frameSize.height); container.getContentPane().setLayout( new BorderLayout() ); JPanel jb_out = new JPanel(); jb_out.setLayout(new BorderLayout()); jb_out.add(buildJBallPanel(), BorderLayout.NORTH); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout ( new FlowLayout(FlowLayout.CENTER) ); ExitBut = new JButton("RUN"); ExitBut.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { svr_cyc(); }}); buttonPanel.add(ExitBut); container.getContentPane().add(jb_out, BorderLayout.NORTH); container.getContentPane().add(buttonPanel, BorderLayout.SOUTH); container.pack(); container.setVisible(true); } public JPanel buildJBallPanel() { JPanel JBallGrid = new JPanel(); GridBagLayout gbc0 = new GridBagLayout(); JBallGrid.setLayout(gbc0); // Part, Lot & Serial Number Panels JPanel JBtaPanel = new JPanel(); GridBagLayout gbc2 = new GridBagLayout(); JBtaPanel.setLayout(gbc2); JBtaPanel.setBorder( new TitledBorder("INPUT") ); // Lot Number List/Panel JPanel LnumJl_StgPanel = new JPanel(); LnumJl_StgPanel.setLayout(new BorderLayout()); JLabel LnumJl_StgLabel = new JLabel (" Lot Number: "); LnumJl_StgPanel.add(LnumJl_StgLabel, BorderLayout.NORTH); LlistModel = new DefaultListModel(); LnumJList = new JList(LlistModel); LnumJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); //LnumJList.setSelectedIndex(0); LnumJList.addListSelectionListener(this); LtextScroller = new JScrollPane( LnumJList, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); LtextScroller.setPreferredSize(new Dimension(80, 360)); LnumJl_StgPanel.add(LtextScroller); LnumField = new JTextField(35); LnumJl_StgPanel.add(LnumField, BorderLayout.SOUTH); JBtaPanel.add(LnumJl_StgPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 5, 0)); // All Panel Grid JBallGrid.add(JBtaPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 5, 0)); return JBallGrid; } public void svr_cyc() { setVar(); fulV = new Vector(); if ( LnumJList.getModel().getSize() > 0 ) { LnumJList.setModel(LlistModel = new DefaultListModel()); LnumField.setText(""); } tBC4 = System.currentTimeMillis(); String[] ncrLocal = rtnNcrStg(); tAC4 = System.currentTimeMillis(); System.out.println("\n4) Cameleon Connect time(secs): " + java.lang.Long.toString(tAC4-tBC4) + "\n" ); String[] serStgArr = new String[ fulV.size() ]; fulV.copyInto( serStgArr ); String[] ncrLocal1 = sortStrings( ncrLocal ); String[] ncrLocalS = reverseStrings( ncrLocal1 ); for (int t = 0; t < ncrLocalS.length; t++) { int spPos0 = ncrLocal[t].lastIndexOf("\\"); dirStg1 = ncrLocal[t].substring(spPos0+1,ncrLocal[t].length()); //System.out.println("1) dirStg1: " + dirStg1); int spPosC = ncrLocal[t].lastIndexOf("Cameleon-"); dirStg2 = ncrLocal[t].substring(spPosC+9,spPosC+10); dirStgF = dirStg1 + ":@:Cameleon-" + dirStg2; LlistModel.addElement(dirStgF); } } public void DirListGet( String sn_array_in ) { String cdP = path1 + jbStg; System.out.println("cdP: " + cdP); tBC2 = System.currentTimeMillis(); DirGet( sn_array_in, uNm, pWd, cdP ); tAC2 = System.currentTimeMillis(); System.out.println( "t2) " + sn_array_in + " Connect time(ms): " + java.lang.Long.toString(tAC2-tBC2) + "\n" ); } public void DirGet( String sName, String uName, String pWord, String cdPath ) { try { FtpWr ftpt = new FtpWr(); String[] fulTextR = null; String[] fulTextR2 = null; ftpt.openServer(sName); if (ftpt.serverIsOpen()) { System.out.println("cdPath: " + cdPath); try { ftpt.login(uName, pWord); ftpt.cdDir(cdPath); fulTextR=ftpt.listRawStg(); for (int i = 0; i < fulTextR.length; i++) { int spPos = fulTextR[i].lastIndexOf(" "); dirStg = fulTextR[i].substring(spPos+1,fulTextR[i].length()); int dotPos = dirStg.indexOf("."); int dPos = fulTextR[i].indexOf("d"); int revPos = dirStg.indexOf("rev"); int tmpPos = dirStg.indexOf("TMP"); if ( dotPos < 0 && dPos == 0 && revPos < 0 && tmpPos < 0 ) { String tmpDirStg = cdPath+"/"+dirStg; ftpt.cdDir(tmpDirStg); fulTextR2=ftpt.listRawStg(); for (int i2 = 0; i2 < fulTextR2.length; i2++) { int spPos2 = fulTextR2[i2].lastIndexOf(" "); dirStg2 = fulTextR2[i2].substring(spPos2+1,fulTextR2[i2].length()); int dotPos2 = dirStg2.indexOf("."); int dPos2 = fulTextR2[i2].indexOf("d"); int revPos2 = dirStg2.indexOf("rev"); int tmpPos2 = dirStg.indexOf("TMP"); if ( dotPos2 < 0 && dPos2 == 0 && revPos2 < 0 && tmpPos2 < 0 ) { String dirStg3 = dirStg2 + ":@:" + dirStg + ":@:" + sName; fulV.addElement( dirStg3 ); } } } } } catch (Exception ftpe) { System.out.println("Exception: "); ftpe.printStackTrace(); } finally { ftpt.closeServer(); } } else { System.out.println("Unable to connect to: " + sName); } } catch(Exception e) { System.out.println("Exception: " ); e.printStackTrace(); } } public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting() == false) { if (LnumJList.getSelectedIndex() != -1) { LnumSnm = LnumJList.getSelectedValue().toString(); //System.out.println(LnumSnm); LnumField.setText(""); LnumField.setText(LnumSnm); LnumJList.clearSelection(); tBC1 = System.currentTimeMillis(); int Pos1 = LnumSnm.lastIndexOf(":@:"); String tStg1 = LnumSnm.substring(0,Pos1); String tStg2 = LnumSnm.substring(Pos1+3,LnumSnm.length()); dirStg3 = caStg + tStg2 + "\\LOT_DATA\\" + tStg1; System.out.println("dirStg3: " + dirStg3 ); String[] PnStg = PartNmS( dirStg3 ); //System.out.println("PnStg: " + PnStg); //A5-172:@:A2JAP105_C:@:www.datajett.com System.out.println("FfileStg: " + FfileStg); int spPos0 = FfileStg.lastIndexOf("\\"); dirStg1 = FfileStg.substring(spPos0+1,FfileStg.length()); System.out.println("2) dirStg1: " + dirStg1); int spPos1 = dirStg1.lastIndexOf(".txt"); dirStg2 = dirStg1.substring(0,spPos1); System.out.println("dirStg2: " + dirStg2); String[] varArr = creTArray( dirStg2, "_" ); for (i = 0; i < sn_array.length; i++) { uStg = varArr[2] + ":@:" + varArr[0] + "_" + varArr[1] + ":@:" + sn_array[i]; if ( varArr.length > 3 ) { uStg = varArr[2] + "_" + varArr[3] + ":@:" + varArr[0] + "_" + varArr[1] + ":@:" + sn_array[i]; } System.out.println("uStg: " + uStg); tBC5 = System.currentTimeMillis(); DirGetFeed( uStg ); tAC5 = System.currentTimeMillis(); System.out.println("\nt5) " + uStg + " Connect time(ms): " + java.lang.Long.toString(tAC5-tBC5) ); } tAC1 = System.currentTimeMillis(); System.out.println("\nt1) " + LnumSnm + " Connect time(ms): " + java.lang.Long.toString(tAC1-tBC1) ); } } } public String[] PartNmS ( String aFileStg ){ int spPos0 = aFileStg.lastIndexOf("\\"); dirStg1 = aFileStg.substring(spPos0+1,aFileStg.length()); System.out.println("3) dirStg1: " + dirStg1); File aFile = new File(aFileStg); File[] theFiles = aFile.listFiles(); for(int x=0; x= 0 && spPos >= 0 ) { System.out.println("fileStg: " + fileStg ); String[] LotFileStg = lotFlRead( fileStg ); FfileStg = fileStg; for (int s = 0; s < LotFileStg.length; s++) { System.out.println("PN: ***LotFileStg[s]: " + LotFileStg[s] + " & s: " + s ); ncrV.addElement( LotFileStg[s] ); } } } fulNcr = new String[ ncrV.size() ]; ncrV.copyInto( fulNcr ); return fulNcr; } public void DirGetFeed( String LnumSnm2 ) { int Pos1 = LnumSnm2.lastIndexOf(":@:"); dirStg0 = LnumSnm2.substring(0,Pos1); Fstg = LnumSnm2.substring(Pos1+3,LnumSnm2.length()); int Pos2 = dirStg0.lastIndexOf(":@:"); LotStg = dirStg0.substring(0,Pos2); PartStg = dirStg0.substring(Pos2+3,dirStg0.length()); String cdP = path1 + jbStg + PartStg + "/" + LotStg; System.out.println("cdP: " + cdP); LnumQuery( Fstg, uNm, pWd, cdP ); } public void LnumQuery( String sName, String uName, String pWord, String cdPath ) { try { String outInPut = "ftp://" + uName + ":" + pWord + "@" + sName + cdPath + "/MRB.TXT"; System.out.println("Scanning File: " + outInPut); String surl = outInPut; URL url = new URL(surl); BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); Vector lines = new Vector(); String aLine = reader.readLine(); while( aLine != null ) { lines.addElement( aLine ); aLine = reader.readLine(); } fulText = new String[ lines.size() ]; lines.copyInto( fulText ); reader.close(); } catch (IOException exc2) { System.out.println("Exception: "); exc2.printStackTrace(); } stgRead(); getDataNm = getDataNm(); SaveSelected( getDataNm ); RunCmdInt( getDataNm ); } public void stgRead() { Vector entV = new Vector(); int tcntr = cntr; int scntr = 0; for (i = 2; i < fulText.length; i++) { if ( fulText[i].indexOf(statStg) < 0 ) { String[] varArr = creTArray( fulText[i], " " ); codeStg = "AIRFOIL"; if ( varArr[2].compareTo("N_ANGLE") == 0 || varArr[2].compareTo("LEA") == 0 || varArr[2].compareTo("TEA") == 0 ) { codeStg = "ROOT"; } String secfStg = varArr[0].substring(4,varArr[0].length()); // Found "FF" tfulStg = varArr[1]+",0,1,"+codeStg+","+secfStg+"|"+varArr[2]+"|"+varArr[3]; entV.addElement( tfulStg ); } else { i = fulText.length; } } tBC6 = System.currentTimeMillis(); String[] ncrLocal = rtnNcrStgN(); tAC6 = System.currentTimeMillis(); System.out.println("\nt6) Cameleon Connect time(secs): " + java.lang.Long.toString(tAC6-tBC6) + "\n" ); for (int t = 0; t < ncrLocal.length; t++) { System.out.println("XXX-ncrLocal[t]: " + ncrLocal[t] + " & t: " + t ); entV.addElement( ncrLocal[t] ); } finText = new String[ entV.size() ]; entV.copyInto( finText ); } public String[] rtnNcrStgN() { ncrV = new Vector(); fulNcr = null; for (i = 0; i < cam_array.length; i++) { tBC3 = System.currentTimeMillis(); String tmpCamStg = cam_array[i]; String nCamFile = cam_array[i] + "\\" + LotStg + "\\" + PartStg + "_" + LotStg + ".txt"; System.out.println( "nCamFile: " + nCamFile ); File aFile = new File(nCamFile); if(!aFile.exists()) { System.out.println("File: " + nCamFile + " does not exist"); } else{ String[] LotFileStg = lotFlRead( nCamFile ); System.out.println( "Found: " + nCamFile); } tAC3 = System.currentTimeMillis(); System.out.println("\nt3) " + tmpCamStg + " Connect time(ms): " + java.lang.Long.toString(tAC3-tBC3) ); } fulNcr = new String[ ncrV.size() ]; ncrV.copyInto( fulNcr ); return fulNcr; } public String[] rtnNcrStg() { ncrV = new Vector(); fulNcr = null; for (i = 0; i < cam_array.length; i++) { tBC3 = System.currentTimeMillis(); String tmpCamStg = cam_array[i]; System.out.println( "tmpCamStg: " + tmpCamStg ); File aFile = new File(cam_array[i]); if(!aFile.exists()) System.out.println("Directory: " + tmpCamStg + " does not exist"); else if(!aFile.isDirectory()) System.out.println( tmpCamStg + " is not a directory" ); else{ PrintDirN(0, aFile); System.out.println( "Completed: " + tmpCamStg); } tAC3 = System.currentTimeMillis(); System.out.println("\nt3) " + tmpCamStg + " Connect time(ms): " + java.lang.Long.toString(tAC3-tBC3) ); } fulNcr = new String[ ncrV.size() ]; ncrV.copyInto( fulNcr ); for (h = 0; h < fulNcr.length; h++) { //System.out.println("Lot Folders: fulNcr[h]: " + fulNcr[h]); } return fulNcr; } public void PrintDirN(int indent, File aFile){ File[] theFiles = aFile.listFiles(); Vector vec = new Vector(); for(int x=0; x 0 ) { System.out.println("%%%[IS1] LotStg: " + LotStg + " == fileStg: " + fileStg ); for(int i=1; i<=indent; i++) { System.out.println(" *File - Add: " + fileStg); int spPos = fileStg.lastIndexOf("/"); finFlStg = fileStg.substring(spPos+1,fileStg.length()); int lotPos = finFlStg.lastIndexOf(LotStg); int prtPos = finFlStg.lastIndexOf(PartStg); if ( lotPos >= 0 && prtPos >= 0 ) { String[] LotFileStg = lotFlRead( fileStg ); for (int s = 0; s < LotFileStg.length; s++) { System.out.println("PD: ***LotFileStg[s]: " + LotFileStg[s] + " & s: " + s ); ncrV.addElement( LotFileStg[s] ); } } } } } int count = 0; while(count != vecV.size()){ PrintDir(indent+1, (File)vecV.elementAt(count)); count++; } fulLdir = new String[ lDirV.size() ]; lDirV.copyInto( fulLdir ); for (h = 0; h < fulLdir.length; h++) { System.out.println("Lot Folders: fulLdir[h]: " + fulLdir[h]); } } public String[] lotFlRead( String filename ) { try { FileInputStream fis = new FileInputStream(filename); InputStreamReader isr = new InputStreamReader(fis); LineNumberReader lnr = new LineNumberReader(isr); Vector flines = new Vector(); String afLine = lnr.readLine(); while( afLine != null ) { flines.addElement( afLine ); afLine = lnr.readLine(); } lfText = new String[ flines.size() ]; flines.copyInto( lfText ); isr.close(); lotReadStg = QueryRead( lfText ); } catch (IOException exc2) { System.out.println("Exception: "); exc2.printStackTrace(); } return lotReadStg; } public String[] QueryRead( String[] fulText ) { Vector lotV = new Vector(); for (i = 0; i < fulText.length; i++) { int cnPos, dimPos, snPos = 0; cnPos = fulText[i].indexOf("C/N"); snPos = fulText[i].indexOf("S/N"); dimPos = fulText[i].indexOf("DIM"); if ( cnPos > -1 || snPos > -1 ) { int spPos = fulText[i].lastIndexOf(" "); cnStg1 = fulText[i].substring(spPos+1,fulText[i].length()); // Found C/N } else if ( dimPos > -1 ) { tmpStg = fulText[i+2]; System.out.println( "tmpStg: " + tmpStg ); String[] varArr = creTArray( tmpStg, " " ); lfulStg = cnStg1+",0,1,Other,NOM="+varArr[1]+"|+TOL="+varArr[2]+"|-TOL="+varArr[3]+"|MEAS="+varArr[4]; System.out.println("lfulStg: " + lfulStg); lotV.addElement( lfulStg ); ncrV.addElement( lfulStg ); i++;i++; } } String[] cnStgArr = new String[ lotV.size() ]; lotV.copyInto( cnStgArr ); for (int s = 0; s < cnStgArr.length; s++) { System.out.println("C/N||S/N: cnStgArr[s]: " + cnStgArr[s] + " & s: " + s ); } return cnStgArr; } public String[] creTArray(String toArray, String splitChar) { StringTokenizer token1 = new StringTokenizer(toArray,splitChar); int number1 = token1.countTokens(); String[] newArray = new String[ number1 ]; for (int i = 0; i < number1; i++) { String st = token1.nextToken(); newArray[i] = st; } return newArray; } public void RunCmdInt ( String getDataNm ) { String s = null; try { String wordpad = ("\"C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe\""); Process p = Runtime.getRuntime().exec("cmd /C " + wordpad + " " + getDataNm ); BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream())); while ((s = stdInput.readLine()) != null) { System.out.println( s ); } } catch (IOException e) { System.out.println("Exception: " ); e.printStackTrace(); System.exit(-1); } } public void SaveSelected( String getDataNm ) { try { PrintStream expfl = new PrintStream(new FileOutputStream(getDataNm)); for (j = 0; j < finText.length; j++) { if ( finText[j] != "" ) { expfl.println( finText[j] ); } } expfl.flush(); expfl.close(); } catch(java.io.IOException IOEx) { System.out.println("Cannot create " + getDataNm + " file."); } } protected boolean alreadyInLList(String name) { return LlistModel.contains(name); } public void DelOut() { String s2 = null; try { String delStg = ("\"del *_out.txt\""); Process p2 = Runtime.getRuntime().exec("cmd /C " + delStg ); BufferedReader stdInput2 = new BufferedReader(new InputStreamReader(p2.getInputStream())); BufferedReader stdError2 = new BufferedReader(new InputStreamReader(p2.getErrorStream())); while ((s2 = stdInput2.readLine()) != null) { System.out.println( s2 ); } } catch (IOException e9) { System.out.println("Exception: "); e9.printStackTrace(); System.exit(-1); } } public String[] sortStrings( String[] strings ) { for ( int i = 0; i < strings.length - 1; ++i ) { for ( int j = i + 1; j < strings.length; ++j ) { if ( strings[i].compareTo( strings[j] ) > 0 ) { String t = strings[i]; strings[i] = strings[j]; strings[j] = t; } } } return strings; } public String[] reverseStrings( String[] strings ) { String temp; int left = 0; int right = strings.length - 1; while (left < right) { temp = strings[left]; strings[left] = strings[right]; strings[right] = temp; right--; left++; } return strings; } public String getDataNm() { OutFileNm = LotStg + "." + PartStg + "." + sName + "_out.txt"; return OutFileNm; } public void setVar() { if ( loc1.compareTo("d") == 0 ) { sn_array = new String[1]; cam_array = new String[4]; sn_array[0] = "www.datajett.com"; cam_array[0] = "D:\\Dev\\HTML\\datajett.com\\public_html\\HC\\NCR\\Cameleon-1\\LOT_DATA"; cam_array[1] = "D:\\Dev\\HTML\\datajett.com\\public_html\\HC\\NCR\\Cameleon-2\\LOT_DATA"; cam_array[2] = "D:\\Dev\\HTML\\datajett.com\\public_html\\HC\\NCR\\Cameleon-3\\LOT_DATA"; cam_array[3] = "D:\\Dev\\HTML\\datajett.com\\public_html\\HC\\NCR\\Cameleon-4\\LOT_DATA"; uNm = "datajett";pWd = "rbjllj69";path1 = "/public_html/HC"; } else { sn_array = new String[3];cam_array = new String[4]; sn_array[0] = "blacmm1.heico-dc.com"; sn_array[1] = "meatii.heico-dc.com"; sn_array[2] = "heisco1.heico-dc.com"; cam_array[0] = "\\\\Chameleon-1\\PC-DMIS\\LOT_DATA"; cam_array[1] = "\\\\Chameleon-2\\PC-DMIS\\LOT_DATA"; cam_array[2] = "\\\\Chameleon-3\\PC-DMIS\\LOT_DATA"; cam_array[3] = "\\\\Chameleon-4\\PC-DMIS\\LOT_DATA"; uNm = "transfer";pWd = "transfer";path1 = "/u/mm4"; } } JFrame container; JList LnumJList; JTextField PnumField, LnumField, SnumField, ProgField, ftp_Field; JButton ButQry, ButRQry, ExitBut, ResBut, OpenBut, GetBut, RInBut, RStatBut, RQuBut; JScrollPane PtextScroller, LtextScroller, StextScroller; ListSelectionModel listSelectionModel; DefaultListModel LlistModel; String Fstg, Pnum, Lnum, Snum, query, ftp_stg, ftp_Fstg, OutFileNm, uNm, pWd, path1, loc1; String LnumSnm, TmpFileNm, getDataNm, dataOutStg, DOSubNm, DataOutSubStg, delStg, SubStg; String LotStg, PartStg, paramStg, tfulStg, codeStg, sName, finFlStg, uStg, fileStg; String dirStg, dirStg0, dirStg1, dirStg2, dirStg3, dirStgF, lfulStg, tmpStg, cnStg1; String FfileStg; String jbStg = "/JB_FILES/"; String caStg = "D:\\Dev\\HTML\\datajett.com\\public_html\\HC\\NCR\\"; String statStg = "STATISTICAL PROCESS CONTROL"; String[] fulText, finText, fulNcr, fulLdir, lfText, lotReadStg, sn_array, cam_array; int trackWord, cntr, scntr, nctr, rcntr, h, i, j, k, mtPos = 0; long tBC1, tBC2, tBC3, tBC4, tBC5, tBC6, tAC1, tAC2, tAC3, tAC4, tAC5, tAC6; Vector ncrV, fulV; } class FtpWr extends FtpClient { public boolean cdDir (String rdirPath) throws IOException { issueCommand("CWD " + rdirPath); return isValidResponse(); } public String[] listRawStg() throws IOException { BufferedReader lreader = new BufferedReader(new InputStreamReader(list())); Vector rlines = new Vector(); String sLine = lreader.readLine(); while( sLine != null ) { rlines.addElement( sLine ); sLine = lreader.readLine(); } String[] rlineArray = new String[ rlines.size() ]; rlines.copyInto( rlineArray ); return rlineArray; } public boolean isValidResponse() { try { int respCode = Integer.parseInt(getResponseString().substring(0, 3)); return (respCode >= 200 && respCode < 300); } catch (Exception e) { return false; } } }