/* * @(#)Tilegen.java 1.0 08/08/18 * * * * * * * * */ import java.awt.*; import java.applet.*; import java.net.*; import java.awt.event.*; import java.lang.*; import java.util.Scanner; import java.io.File; import java.io.FileNotFoundException; import java.util.Formatter; import java.util.FormatterClosedException; import java.lang.String; import java.util.Calendar; import java.text.SimpleDateFormat; import java.util.NoSuchElementException; public class Tilegen11 extends Applet implements ActionListener { Image tile_gif,qug_gif; URL base; MediaTracker mt; Button okButton; Button confirmButton; Button frameButton; Button proofButton; Button snakeButton; TextField north_inputs,east_inputs,south_inputs,west_inputs,frame_inputs,proof_inputs,snake_inputs; TextArea gls,tls,proof,snake; int cflag,frflag,proofflag,snakeflag; String newline; public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss"; static Formatter output1k; static Formatter output2k; static Formatter output3k; static Formatter output; static Formatter output1; static Formatter output2;//for writing the vertical frame tiles static Formatter output3;//for writing the horiz6ontal frame tiles static Formatter output4;//for writing the seed tile static Formatter output5; static Formatter output6; static Formatter output7; static Formatter output8; static Scanner input1; static Scanner input2; static Scanner input3; static Scanner input4; static Scanner input5;//for reading frame tiles' glues static Scanner input6;//for proofreading verticalframe tiles' glues static Scanner input7;//for proofreading horizontal frame tiles' glues static Scanner input8;//for proofreading seed frame tiles' glues static Scanner input9;//for finding total glues in computational tiles before any error correction; static Scanner input10; static Scanner input11; static Scanner input12; static Scanner input13; static Scanner sinput1; static Scanner sinput2; static Scanner sinput3; static Scanner sinput4; static Scanner sinput5; static Scanner sinput6; static Scanner sinput7; static Scanner sinput8; static Scanner sinput9; static Scanner sinput10; static Formatter soutput1;//for writing vertical frame tiles without any manipulation to the original .tile structure static Formatter soutput2;//for writing horizontal frame tiles without any manipulation to the original .tile structure static Formatter soutput3;//for writing seed tiles without any manipulation to the original .tile structure static Formatter sgh4;//for writing all broken frame tiles into snake_frame.txt file static Formatter sgh5; public void init() { setLayout(null); okButton = new Button("Submit Inputs"); frameButton = new Button("Submit frame glues"); confirmButton = new Button("Click to confirm"); proofButton = new Button("Apply proofread"); snakeButton = new Button("Apply Snake"); north_inputs = new TextField("Type north outputs here",40); east_inputs = new TextField("Type east inputs here",40); south_inputs = new TextField("Type south inputs here",40); west_inputs = new TextField("Type west outputs here",40); snake_inputs = new TextField("m",80); snake_inputs.setBounds(500,740,80,30); add(snake_inputs); gls = new TextArea(10,40); gls.setEditable(false); tls = new TextArea(10,40); tls.setEditable(false); proof = new TextArea(10,40); proof.setEditable(false); snake = new TextArea(10,40); snake.setEditable(false); frame_inputs = new TextField("Type frame inputs here",80); frame_inputs.setBounds(500,320,400,30); add(frame_inputs); proof_inputs = new TextField("m",80); proof_inputs.setBounds(10,740,80,30); add(proof_inputs); cflag=0; frflag=0; north_inputs.setBounds(130,40,200,30); add(north_inputs); east_inputs.setBounds(340,150,130,30); add(east_inputs); south_inputs.setBounds(130,250,200,30); add(south_inputs); west_inputs.setBounds(10,150,130,30); add(west_inputs); gls.setBounds(500,10,400,200); add(gls); tls.setBounds(500,420,400,280); add(tls); proof.setBounds(10,790,400,300); add(proof); snake.setBounds(500,790,400,300); add(snake); okButton.setBounds(130,280,100,30); add(okButton); okButton.addActionListener(this); confirmButton.setBounds(10,430,120,30); add(confirmButton); confirmButton.addActionListener(this); frameButton.setBounds(500,370,200,30); add(frameButton); frameButton.addActionListener(this); proofButton.setBounds(120,740,100,30); add(proofButton); proofButton.addActionListener(this); snakeButton.setBounds(600,740,100,30); add(snakeButton); snakeButton.addActionListener(this); newline = System.getProperty("line.separator"); mt = new MediaTracker(this); try { base = getDocumentBase(); } catch (Exception e) {} tile_gif = getImage(base,"tile_sample.gif"); qug_gif = getImage(base, "quick_user_guide.gif"); try { mt.waitForAll(); } catch (InterruptedException e) {} } public void paint(Graphics g) { g.drawString("Welcome to Tilegen Applet", 10, 20 ); g.drawString("\n Please enter inputs for the four sides of the computational tile design.", 10, 35 ); //g.drawImage(tile_gif,150,80,this); //g.drawImage(qug_gif,10,540,this); g.drawString("North inputs :"+north_inputs.getText(),10,360); g.drawString("East inputs :"+east_inputs.getText(),10,380); g.drawString("South inputs :"+south_inputs.getText(),10,400); g.drawString("West inputs :"+west_inputs.getText(),10,420); g.drawString("Below you enter glues from either the table given",500,240); g.drawString(",by entering the glue no. as per your need.",500,260); g.drawString("If you enter a new glue type not present in the table, that would be added",500,280); g.drawString("following this format a,b,c,d;e,f,g,h;....;w,x,y,z",500,300); g.drawString("Quick User Guide:\n \n ",10,480); g.drawString("1. Enter inputs in this form : a+b,(a.b)^c,a,a.(~b)\n",10,510); g.drawString("2. only four gates : AND(.), OR(+), NOT(~), XOR(^) are allowed\n",10,535); g.drawString("3. If more than one gates are used, two operands and an \n",10,560); g.drawString(" operator must be bracketed by ( ).\n",10,580); g.drawString("4. Do take care in entering frame tile glues. commas ',' seperate \n",10,605); g.drawString("glues and semicolon ';' seperate tiles, with NO semicolon in the ending\n",10,625); g.drawString("5.Error handling has not been implemented till now. So if you dont \n ",10,650); g.drawString("follow the directions, incorrect results are surely expected",10,670); int[] xcd = new int[3]; int[] ycd = new int[3]; xcd[0]=150;xcd[1]=235;xcd[2]=150; ycd[0]=80;ycd[1]=160;ycd[2]=240; g.setColor( Color.red ); g.drawPolygon(xcd, ycd, 3); g.fillPolygon(xcd, ycd, 3); xcd[0]=150;xcd[1]=235;xcd[2]=320; ycd[0]=80;ycd[1]=160;ycd[2]=80; g.setColor( Color.blue ); g.drawPolygon(xcd, ycd, 3); g.fillPolygon(xcd, ycd, 3); xcd[0]=320;xcd[1]=235;xcd[2]=320; ycd[0]=80;ycd[1]=160;ycd[2]=240; g.setColor( Color.yellow ); g.drawPolygon(xcd, ycd, 3); g.fillPolygon(xcd, ycd, 3); xcd[0]=150;xcd[1]=235;xcd[2]=320; ycd[0]=240;ycd[1]=160;ycd[2]=240; g.setColor( Color.green ); g.drawPolygon(xcd, ycd, 3); g.fillPolygon(xcd, ycd, 3); g.setColor( Color.black ); g.drawString("\n W", 192, 160 ); g.drawString("\n E", 276, 160 ); g.drawString("\n N", 235, 120 ); g.drawString("\n S", 234, 200 ); g.drawString(" below give value for 'm' to perform m*m proofread ",10,720); g.drawString(" below give value for 'm' to perform m*m snake ( m should be an even integer)",500,720); } public void actionPerformed(ActionEvent evt) { frflag=0; proofflag=0; snakeflag=0; if(evt.getSource() == frameButton) { frflag=1; } if(evt.getSource() == proofButton) { proofflag=1; } if(evt.getSource() == snakeButton) { snakeflag=1; } if (evt.getSource() == okButton){ repaint();okButton.setLabel("Submitted");cflag=0;frflag=1;} else if ((evt.getSource() == confirmButton && cflag==0) || frflag==1 || proofflag==1 || snakeflag==1) { String[] in = new String[100]; int i=0; for(i=0;i<100;i++) {in[i]="";} int xi=0; int l1,l2,l3,l4; l1=l2=l3=l4=0; char[] ni = north_inputs.getText().toCharArray(); int nil = north_inputs.getText().length(); if(north_inputs.getText()!="\n") { l1++; for(i=0;iend); } } //converting infix expression to postfix expression String[] piptable = new String[1000]; for(int g=0;g0); } piptable[g]=""; for(int g2=0;g20)gs--; arr[gy][gx]=stk[gs]; //storing the computed value from stack to array } } for(int a=0;agv[v2+1]) { int temp=gv[v2]; gv[v2]=gv[v2+1]; gv[v2+1]=temp; } } } int nullflag=0; int[][] gc = new int[5000][3]; int lgc=0; int w1=0; int w4=0; //looping to create a glue compare strap according to the no of bits in input taking all faces into consideration for(int q1=0;q10); for(int nc=1;nc0); tv=temp1; //removing the dummy mask and displaying the correct used codes for the glues do{ int tp = tv%10; if(tp==4) glue_strap=glue_strap.concat("0"); else if(tp==5) glue_strap=glue_strap.concat("1"); else if(tp==3) glue_strap=glue_strap.concat("null"); tv=tv/10; }while(tv>0); } //north glues array int[][] nga = new int[r][2]; if(size_north == 0) { for(int zt=0;zt0); for(int nc=1;nc0); nga[g1][0]=temp1; //comparing with glue strap for(int g3=0;g30); for(int nc=1;nc0); ega[g1][0]=temp1; for(int g3=0;g30); for(int nc=1;nc0); sga[g1][0]=temp1; for(int g3=0;g30); for(int nc=1;nc0); wga[g1][0]=temp1; for(int g3=0;g3lgc) //checking to see if new glues are entered { int flagg=0; for(int ui=0;uilgc) { int flagg=0; for(int ui=0;uilgc) { int flagg=0; for(int ui=0;uilgc) { int flagg=0; for(int ui=0;ui sbig3) sbig3 = stemp; } for(ssi = sbig3 +1;ssi <= sbig; ssi++) sstrength[ssi] = 2; //for spliting the computational tiles ssi=1; sj=1; sbig1 = sbig; // System.out.printf("big befor while %d",sbig); while(sinput6.hasNext()) { //System.out.printf("\n value of big in beginning %d\n",sbig); sbig1 = sbig; sn=sinput6.nextInt(); se=sinput6.nextInt(); ss=sinput6.nextInt(); sw=sinput6.nextInt(); for(sj=1;sj<=2*sk;sj++)// filling in the north side { for(ssi=1;ssi<=2*sk;ssi++) { if(sj==ssi+1 && ssi%2==0 && sk!=1)//for T(2i,2i+1) North condition { sglue[ssi][sj][0] = ++sbig; stemp = sglue[ssi][sj][0]; sstrength[stemp] = 2; } else if(ssi%2==0 && sj==1 && sk!=1 && ssi != 2*sk)//for T(2i,1) North condition { sglue[ssi][sj][0] = 0; //temp = glue[i][j][0]; //strength[temp] = 0; } else if(ssi==2*sk-2 && sj==2*sk && sk!=1)//for T(2k-2,2k) North condition { sglue[ssi][sj][0] = ++sbig; stemp = sglue[ssi][sj][0]; sstrength[stemp] = 2; } else if(ssi==2*sk)//for T(2k,j) North condition { sglue[ssi][sj][0] = sn; stemp = sglue[ssi][sj][0]; sstrength[stemp] = 1; } else//for a normal case { sglue[ssi][sj][0] = ++sbig; stemp = sglue[ssi][sj][0]; sstrength[stemp] = 1; } } }//end of for //filling in the south side sbig = sbig1; //System.out.printf("\n%d\n",sbig); for(sj=1;sj<=2*sk;sj++)// filling in the south side { for(ssi=1;ssi<=2*sk;ssi++) { if(sj==ssi && ssi%2==1 && sk!=1 && ssi != 1)//for T(2i+1,2i+1) South condition { sglue[ssi][sj][2] = ++sbig; stemp = sglue[ssi][sj][2]; sstrength[stemp] = 2; } else if(ssi%2==1 && sj==1 && sk!=1 && ssi != 1)//T(2i+1,1) { sglue[ssi][sj][2] = 0; //temp = glue[i][j][2]; //strength[temp] = 0; } else if(ssi==2*sk-1 && sj==2*sk && sk!=1)//T(2k-1,2k) { sglue[ssi][sj][2] = ++sbig; stemp = sglue[ssi][sj][2]; sstrength[stemp] = 2; } else if(ssi==1) { sglue[ssi][sj][2] = ss; stemp = sglue[ssi][sj][2]; sstrength[stemp] = 1; } else { sglue[ssi][sj][2] = ++sbig; stemp = sglue[ssi][sj][2]; sstrength[stemp] = 1; } } }//end of for //for filling the east side sbig2 = sbig; for(sj=1;sj<=2*sk;sj++)// filling in the east side { for(ssi=1;ssi<=2*sk;ssi++) { if(ssi==1 && sj%2==0 )//for T(1,2i) east condition { sglue[ssi][sj][1] = 0; //temp = glue[i][j][1]; //strength[temp] = 0; } else if(ssi==sj && ssi%2==0 )//T(2i,2i) { sglue[ssi][sj][1] = ++sbig; stemp = sglue[ssi][sj][1]; sstrength[stemp] = 2; } else if(ssi==(2*sk)-2 && sj==2*sk && sk != 1)//T(2k-2,2k) { sglue[ssi][sj][1] = 0; //temp = glue[i][j][1]; //strength[temp] = 0; } else if(sj==1) { sglue[ssi][sj][1] = se; stemp = sglue[ssi][sj][1]; sstrength[stemp] = 1; } else { sglue[ssi][sj][1] = ++sbig; stemp = sglue[ssi][sj][1]; sstrength[stemp] = 1; } } }//end of for sbig = sbig2; for(sj=1;sj<=2*sk;sj++)// filling in the west side { for(ssi=1;ssi<=2*sk;ssi++) { if(ssi==1 && sj%2==1)//for T(1,2i-1) west condition { sglue[ssi][sj][3] = 0; //temp = glue[i][j][3]; //strength[temp] = 0; } else if(ssi%2==0 && sj==ssi-1 )//for T(2i,2i-1) { sglue[ssi][sj][3] = ++sbig; stemp = sglue[ssi][sj][3]; sstrength[stemp] = 2; } else if(ssi==2*sk-2 && sj==2*sk-1 && sk != 1)//T(2k-2,2k-1) { sglue[ssi][sj][3] = 0; //temp = glue[i][j][3]; //strength[temp] = 0; } else if(sj==2*sk) { sglue[ssi][sj][3] = sw; stemp = sglue[ssi][sj][3]; sstrength[stemp] = 1; } else { sglue[ssi][sj][3] = ++sbig; stemp = sglue[ssi][sj][3]; sstrength[stemp] = 1; } } }//end of for //for writting all the glues after breaking in snake_frame.txt for(ssi=1;ssi<= 2 * sk; ssi++) for(sj=1; sj <= 2 * sk; sj++) sgh4.format("%d\t%d\t%d\t%d\n",sglue[ssi][sj][0],sglue[ssi][sj][1],sglue[ssi][sj][2],sglue[ssi][sj][3]); //System.out.printf("\n value of big %d\n",sbig); } sgh4.close(); //System.out.printf("\n value of big %d\n",sbig); while(sinput7.hasNext()) { stemp = sinput7.nextInt(); if(stemp > snum_binding_types) snum_binding_types = stemp; } while(sinput8.hasNext()) { stemp = sinput8.nextInt(); stemp = sinput8.nextInt(); stemp = sinput8.nextInt(); stemp = sinput8.nextInt(); snum_tile_types = snum_tile_types + 1; } //now starting to make .tiles file String naag=""; sgh5.format("tile edges matches {{N E S W}*}\n"); sgh5.format("num tile types=%d\n",snum_tile_types); sgh5.format("num binding types=%d\ntile edges={\n",snum_binding_types); String timeds = Tilegen11.now(); naag = naag.concat("/*This .tiles file was generated using XTile 1.1 ").concat("at ").concat(timeds); naag = naag.concat("\n").concat("developed by Anshul Chaurasia, Sudhanshu Dwivedi and Prateek Jain, DA-IICT,INDIA"); naag = naag.concat("\n").concat("detailed documentation and tool available at www.guptalab.org/xtile"); naag = naag.concat("\n").concat("this .tiles file is input to Xgrow developed by Eric Winfree, Caltech ").concat("*/"); naag = naag.concat("\n"); naag = naag.concat("tile edges matches {{N E S W}*}\n"); naag = naag.concat("num tile types=").concat(String.valueOf(snum_tile_types)).concat("\n"); naag = naag.concat("num binding types=").concat(String.valueOf(snum_binding_types)).concat("\n").concat("tile edges={\n"); //int p,q,r,s; while(sinput9.hasNext()) { sn=sinput9.nextInt(); se=sinput9.nextInt(); ss=sinput9.nextInt(); sw=sinput9.nextInt(); sgh5.format("{%d\t%d\t%d\t%d}\n",sn,se,ss,sw); naag = naag.concat("{").concat(String.valueOf(sn)).concat("\t").concat(String.valueOf(se)).concat("\t").concat(String.valueOf(ss)).concat("\t").concat(String.valueOf(sw)).concat("}\n"); } sgh5.format("}\n"); sgh5.format("binding strengths=\n{"); naag = naag.concat("}\n"); naag = naag.concat("binding strengths=\n{"); for(ssi = 1; ssi <= snum_binding_types; ssi++) { sgh5.format("%d\t",sstrength[ssi]); naag = naag.concat(String.valueOf(sstrength[ssi])).concat("\t"); } /*for(int d1=0; d1< glue_strength_2; d1++) { output1.format("2\t"); }*/ sgh5.format("}"); naag = naag.concat("}"); sgh5.close(); snake.setText(naag + newline); } catch ( SecurityException securityException ) { System.err.println( "You do not have write access to this file." ); System.exit( 1 ); } // end catch catch ( FileNotFoundException filesNotFoundException ) { System.err.println( "Error creating file." ); System.exit( 1 ); } // end catch catch ( FormatterClosedException formatterClosedException ) { System.err.println( "Error writing to file." ); return; } // end catch catch ( NoSuchElementException elementException ) { System.err.println( "Invalid input. Please try again." ); sinput6.nextLine(); // discard input so user can try again } // end catch repaint(); } } } } public static String now() { Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW); return sdf.format(cal.getTime()); } static int tobin(int x1,int x2) { int x3,x4; x3=0; x4=0; int n=0; do{ int pw=1; for(int t=0;t0); if(x2>0) { do { int pw=1; for(int t=0;t0); } return x4; } }