package ITUannotation;

import javax.swing.JComponent;
import javax.swing.JLayeredPane;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JScrollBar;
import javax.swing.ScrollPaneConstants;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.List;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Locale;
import java.util.Scanner;

import javax.swing.BorderFactory;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.xpath.XPathExpressionException;

import org.maltparser.MaltParserService;
import org.maltparser.core.exception.MaltChainedException;
import org.xml.sax.SAXException;
import javax.swing.JLabel;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.geom.QuadCurve2D;

import javax.swing.JComboBox;
import javax.swing.JCheckBox;
import javax.swing.JEditorPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.text.Caret;

import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;

public class Syntactic_Analysis_Interface extends JFrame {

	private static final long serialVersionUID = 1L;
	private ArrayList<Syntactic_Elements> SntItarr = new ArrayList<Syntactic_Elements>(); // @jve:decl-index=0:
	private ArrayList<CheckBoxList> checkarr = new ArrayList<CheckBoxList>(); // @jve:decl-index=0:
	private JPanel jContentPane = null; // @jve:decl-index=0:visual-constraint="30,826"
	private JButton btnOpen = null;
	private File opened;
	static public String cpath=null;
	private Syntactic_Analysis_Interface mythis;
	private JTextArea xmlarea = null;
	private int wordn = 0;
	private int sumofc = 0;
	private ArrayList<JLabel> labelarr = new ArrayList<JLabel>(); // @jve:decl-index=0:
	private static final ArrayList<String> bagdata = new ArrayList<String>(); // @jve:decl-index=0:
	private ArrayList<Syntactic_Elements> words = new ArrayList<Syntactic_Elements>(); // @jve:decl-index=0:
	private JComboBox jComboBox = null;
	boolean draw;
	CheckBoxListener myListener = new CheckBoxListener(); // @jve:decl-index=0:
	private ArrayList<Arrow> arrowList = new ArrayList<Arrow>(); // @jve:decl-index=0:
	private JButton btnOpen1 = null;
	private boolean itemStateChangedFlag = false;
	private String clickedCheckbox;
	private int buttonClickCounter = 0;
	private Arrow lArrow = new Arrow(); // @jve:decl-index=0:
	private JButton xmlButton = null;
	private String PxmlText, OrgnlxmlText;
	private JButton kaydetButton = null;
	private JButton jButton = null;
	private JButton SuggestButton = null;
	private boolean vazgecClicked = false;
	private boolean SuggestClicked = false;
	private boolean convertedConll=false;
	private boolean convertedXML=false;
	private ArrayList<String> depList = new ArrayList<String>();  //  @jve:decl-index=0:
	int indexArrayList;
	private int checkBoxClicked = 0;
	JTextArea resultTA;
	private JScrollPane jScrollPane = null;
	private JScrollPane jScrollPane1 = null;
	private JScrollPane jScrollPane11 = null;
	private JButton But_Conll = null;
	private JButton ButBLY = null;
	private Language lang;
	private JButton conllSaveButton = null;
	private int line_num;
	private ArrayList<String> TDKList;  //  @jve:decl-index=0:
	private String TheSentence;
	private ArrayList<ColElement> collocationsFound;
	private int arrowOrder = 0;
	private int lastChecked = -1;
	private int tempToCheck = 0;
	
	
	public Syntactic_Analysis_Interface(int Langindex) throws FileNotFoundException {
		super();
		mythis=this;
		lang= new Language(Langindex);
		SntItarr.clear();
		checkarr.clear();
		TheSentence="";
		initialize();
	}

	private Boolean updatetxt(File c) throws IOException {
		Boolean x;
		line_num=0;
		FileInputStream fis = null;
		BufferedInputStream bis = null;
		DataInputStream dis = null;
		String read1 = new String("");

		BufferedReader bfr = new BufferedReader(new InputStreamReader
				  (new FileInputStream(c),"UTF8"));
		String tempstr,outputstr;
		outputstr=tempstr="";
		
		
		 while(bfr.ready())
		 {
			 tempstr=bfr.readLine();
			 read1=read1+tempstr+"\n";
			 line_num++;
			 
		 }
		 /*if(!read1.contains("UTF-8"))
		 {						JOptionPane.showMessageDialog(null, "Please select a file in UTF-8 Format");
		 x=false;}*/
		/*fis = new FileInputStream(c);
		bis = new BufferedInputStream(fis);
		dis = new DataInputStream(bis);
		while (dis.available() != 0) {
			read1 += "\n" + dis.readLine();
			line_num++;
		}
		fis.close();
		bis.close();
		dis.close();*/
		 //else{
			 x=true;
		char q = '"';
		String Q = Character.toString(q);
		read1 = read1.replaceAll("&quot;", Q);
		// String []lines=read1.split("\n");
		//int line_num=lines.length;
		//getJContentPane().setPreferredSize(new Dimension((int)getJContentPane().getPreferredSize().getWidth(),(int)getJContentPane().getPreferredSize().getHeight()+((line_num-20)*2*getXmlarea().getFont().getSize())));
		//getXmlarea().setBounds(5,390,jScrollPane.getHorizontalScrollBar().getMaximum()-5  , (int)getJContentPane().preferredSize().getHeight()-390/*jScrollPane.getVerticalScrollBar().getMaximum()-330*/);
		//repaint();
		xmlarea.setText(read1);
		getJContentPane().setPreferredSize(new Dimension((int)getJContentPane().getPreferredSize().getWidth(),(int)getJContentPane().getPreferredSize().getHeight()+((line_num-20)*2*getXmlarea().getFont().getSize())));
		getXmlarea().setBounds(5,390,jScrollPane.getHorizontalScrollBar().getMaximum()-5  , (int)getJContentPane().preferredSize().getHeight()-390/*jScrollPane.getVerticalScrollBar().getMaximum()-330*/);
		// }
		 return x;
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 * @throws FileNotFoundException
	 */
	private void initialize() throws FileNotFoundException {
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		this.setSize(screenSize.width, screenSize.height - 50);
		this.setContentPane(getJScrollPane());
		this.setTitle(lang.getLan(2,lang.getLangIndex()));
	}

	private JPanel getJContentPane() throws FileNotFoundException {
		if (jContentPane == null) {
			Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
			jContentPane = new JPanel();
			jContentPane.setPreferredSize(new Dimension(5000, 1000));
			jContentPane.setLayout(null);
			jContentPane.setSize(new Dimension(1900, 600));
			jContentPane.add(getBtnOpen(), null);
			jContentPane.add(getXmlarea(), null);
			jContentPane.add(getJComboBox(), null);
			jContentPane.add(getBtnOpen1(), null);
			jContentPane.add(getXmlButton(), null);
			jContentPane.add(getKaydetButton(), null);
			jContentPane.add(getJButton(), null);
			jContentPane.add(getBut_Conll(), null);
			jContentPane.add(getButBLY(), null);
			jContentPane.add(getConllSaveButton(), null);
			jContentPane.add(getSuggestButton(), null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes btnOpen
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getBtnOpen() {
		if (btnOpen == null) {
			btnOpen = new JButton();
			btnOpen.setBounds(new Rectangle(70, 7, 140, 30));
			btnOpen.setText(lang.getLan(10, lang.getLangIndex()));
			if(SuggestButton!=null)
				SuggestButton.setEnabled(false);
			btnOpen.addActionListener(new java.awt.event.ActionListener() {
				

				public void actionPerformed(java.awt.event.ActionEvent e) {
					Boolean isopened;
					if (jComboBox.isVisible())
					{
						jComboBox.setVisible(false);
					}
					buttonClickCounter = 0;
					lastChecked = -1;
					tempToCheck = 0;
					arrowOrder = 0;
					arrowList.clear(); 
					SntItarr.clear();
					for (int i = 0; i < wordn; i++) {
						labelarr.get(i).removeAll();
					}
					checkarr.clear();
					sumofc = 0;
					if(SuggestClicked){
						//open the conll file suggested by the parser
						try {
							opened=new File(opened.getCanonicalPath()+".output");
						} catch (IOException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
						SuggestClicked=false;
					}
					else if(convertedXML){
						try {
							opened=new File("generatedxmlfromconll.xml");
						} catch (Exception e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
						convertedXML=false;
					}
					else if(convertedConll){
						try {
							opened=new File("generatedconllfromxml.conll");
						} catch (Exception e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
						convertedConll=false;
					}
					else {
						FileDemonstration application=null;
				
						application= new FileDemonstration();
					
						application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
						try {
							
							String[] extensions = new String[2];
							extensions[0]=new String("conll");
							extensions[1]=new String("xml");
							opened = application.getFile(cpath,extensions);
						} catch (IOException e6) {
							// TODO Auto-generated catch block
							e6.printStackTrace();
						}
					}
					
					if(opened!=null)
					{ if(opened.getName().endsWith("conll")){//*gg
						But_Conll.setEnabled(false);
						jButton.setEnabled(false);
						}
					else{
						But_Conll.setEnabled(true);
					}
						
						try {
							
							isopened=updatetxt(opened);
							
						} catch (IOException e7) {
							isopened=false;
							System.out.println("dosya yok");
						}
						if(isopened){
														
							cpath=opened.getParent();
							
							mythis.setTitle("Dependency Analysis"+" "+opened.getAbsolutePath());
							drawTree();
						}}							}
			});

		}
		return btnOpen;
	}
    private void drawTree(){
    	draw = true;
    	cleangraph();
		Sentenceparser sp;
try {
	sp = new Sentenceparser();		
	words = sp.parse(opened);
	wordn = sp.countwords(opened);

	jContentPane.setPreferredSize(new Dimension(
			50 + wordn * 120, 100));
	
	getJContentPane().setPreferredSize(new Dimension((int)getJContentPane().getPreferredSize().getWidth(),getXmlarea().getY()+ 50+2*line_num*getXmlarea().getFont().getSize()));

	//getJContentPane().setPreferredSize(new Dimension((int)getJContentPane().getPreferredSize().getWidth(),(int)getJContentPane().getPreferredSize().getHeight()+((line_num-20)*2*getXmlarea().getFont().getSize())));
	getXmlarea().setBounds(5,390,jScrollPane.getHorizontalScrollBar().getMaximum()-5  , (int)getJContentPane().preferredSize().getHeight()-390/*jScrollPane.getVerticalScrollBar().getMaximum()-330*/);
	//repaint();

	for (int a = 0; a < wordn; a++) {
		TheSentence=TheSentence+words.get(a).getwcontent()+" ";
		labelarr.add(new JLabel("Label " + wordn)); 
		labelarr.get(a)
				.setBorder(
						BorderFactory
								.createLineBorder(Color.black));
		labelarr.get(a).setBounds(14 + (121 * (a)),
				175 * (1), 120, 30);
		labelarr.get(a).setPreferredSize(
				new Dimension(140, 20));

		jContentPane.add(labelarr.get(a));
	}
	jScrollPane.revalidate();
	jContentPane.revalidate();

	for (int a = 0; a < wordn; a++) {
		Syntactic_Elements si = words.get(a);
		SntItarr.add(si);
		labelarr.add(new JLabel("Label " + wordn)); 
		labelarr.get(a)
				.setBorder(
						BorderFactory
								.createLineBorder(Color.black));

		labelarr.get(a).setBounds(14 + (121 * (a)),
				175 * (1), 120, 30);

		String content = si.getwcontent();
		labelarr.get(a).setText(content);
		labelarr.get(a).setVisible(true);
		sumofc += si.getChecknum();
		int cnum = si.getChecknum();
		for (int s = 0; s < cnum; s++) {
			checkarr.add(new CheckBoxList("region" + a
					+ "cb" + s));
		}
	}
	int index = 0;
	for (int b = 0; b < wordn; b++) {
		Syntactic_Elements si2 = words.get(b);
		int x, y, cnum;
		cnum = si2.getChecknum();
		x = 14 + (121 * (b));
		y = 175 * (1);

		for (int a = 0; a < cnum; a++) {
			String aString = Integer.toString(b);
			String bString = Integer.toString(a);
			checkarr.get(index).setText("");
			checkarr.get(index).setVisible(true);
			checkarr.get(index).setName(
					aString + "/" + bString + "*"
							+ Integer.toString(index));
			checkarr.get(index).setEnabled(false);

			if (words.get(b).getChecknum() == 1
					|| a == words.get(b).getChecknum() - 1) {
				checkarr.get(index).setenable(true);
				checkarr.get(index).setEnabled(true);
			} else {
				checkarr.get(index).setenable(false);
				checkarr.get(index).setEnabled(false);
			}
			checkarr.get(index).addActionListener(
					myListener);
			checkarr.get(index).addChangeListener(
					myListener);
			checkarr.get(index).addItemListener(myListener);

			jContentPane.add(checkarr.get(index));
			checkarr.get(index).setBounds(x + (17 * (a)),
					y + 30, 17, 14);
			index++;
		}
	}
	for (int i = 0; i < wordn; i++) {
		labelarr.get(i).revalidate();
	}
	for (int i = 0; i < sumofc; i++) {
		checkarr.get(i).revalidate();
	}
	int a = -1;
	for (int wordNum = 0; wordNum < wordn; wordNum++) {
		Syntactic_Elements si2 = words.get(wordNum);
		int cnum = si2.getChecknum();
		int connWordNum;
		int rlnCheckbox;
		String str = null;

		for (int counterCheck = 0; counterCheck < cnum; counterCheck++) {
			Sentenceparser sp1 = new Sentenceparser();
			int[] array = sp1.parsecheckbox(checkarr.get(
					counterCheck).getName());

			checkarr.get(counterCheck)
					.setLabelNum(array[0]);
			checkarr.get(counterCheck).setCheckBoxNum(
					array[1]);
			checkarr.get(counterCheck).setTotalCheckBoxNum(
					array[2]);
			a++;
			connWordNum = words.get(wordNum).getRLN()
					.getDest() - 1;
			rlnCheckbox = words.get(wordNum).getRLN()
					.getPoint();
			str = words.get(wordNum).getRLN()
					.getRelationStr();

			int sourceX = 14 + (121 * (wordNum));
			int sourceY = 175 * (1);
			int destX = 14 + (121 * (connWordNum));
			int destY = 175 * (1);

			if (counterCheck == cnum - 1 && str != "") {
				int checkBox = rlnCheckbox;
				if (rlnCheckbox == 1)
					checkBox = 0;
				int distance = connWordNum - wordNum;

				checkarr.get(a).setSelected(true);
				checkarr.get(a).setClicked(true);
				checkarr.get(a).setEnabled(false);
				checkarr.get(a).setenable(false);

				checkarr.get(a).setArrowNum(
						arrowList.size()); // kacinci arrow
				Arrow arr = new Arrow(sourceX
						+ (17 * (counterCheck)) + 14,
						sourceY + 9 + 21, destX
								+ (17 * (checkBox)) + 14,
						destY + 9 + 21, distance, str);
				arr.setStartCheckBoxIndex(counterCheck); // arrowun
				arrowList.add(arr);
				checkarr.get(a).setArrayOrder(arrowOrder++);
			}
		}
	}
	itemStateChangedFlag = true;
	btnOpen1.setVisible(false);

	javax.swing.SwingUtilities.invokeLater(new Runnable() {
		   public void run() { 
		      jScrollPane.getVerticalScrollBar().setValue(0);
		   }
		});
	
	getJContentPane().revalidate();
	getJScrollPane().revalidate();
	btnOpen1.setVisible(false);
	if(opened.getName().endsWith("xml"))
	jButton.setEnabled(true);

} catch (ParserConfigurationException e1) {
	e1.printStackTrace();
} catch (NumberFormatException e2) {
	e2.printStackTrace();
} catch (XPathExpressionException e3) {
	e3.printStackTrace();
} catch (SAXException e4) {
	e4.printStackTrace();
} catch (IOException e5) {
	JOptionPane.showMessageDialog(null, "File does not exist!");
}

    }
	private JTextArea getXmlarea() {
		if (xmlarea == null) {
			xmlarea = new JTextArea();
			xmlarea.setBounds(new Rectangle(2, 0, 1221, 324));//g*
			xmlarea.setLineWrap(true);
			xmlarea.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
			JScrollPane scrollingResult = new JScrollPane(xmlarea);
			scrollingResult
					.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
			this.add(scrollingResult);
			
		}
		return xmlarea;
	}

	@Override
	public void paint(Graphics g) {
		Graphics2D g2 = (Graphics2D) g;
		super.paint(g);
		if (draw) {

			int a1 = jScrollPane.getHorizontalScrollBar().getValue();
			int a2 =jScrollPane.getVerticalScrollBar().getValue();
			for (int arrowNum = 0; arrowNum < arrowList.size(); arrowNum++) {
				arrowList.get(arrowNum).drawArc(a1,a2);

			}
			for (int arrowNum = 0; arrowNum < arrowList.size(); arrowNum++) {
				//arrowList.get(arrowNum).setDestY(arrowList.get(arrowNum).getDestY()-a2);
				//arrowList.get(arrowNum).setSourceY(arrowList.get(arrowNum).getSourceY()-a2);
				//arrowList.get(arrowNum).setQuadCurve();
				g2.draw(arrowList.get(arrowNum).getQuadCurve());
				g2.fillPolygon(arrowList.get(arrowNum).getTriangle());
				QuadCurve2D q = arrowList.get(arrowNum).getQuadra();
				int heightArrow = 0;
				for (int a = arrowList.get(arrowNum).getChangeTopY(); a < arrowList.get(arrowNum).getDestY(); a++) {
					if (q.contains(arrowList.get(arrowNum).getRelationX(), a)) {
						heightArrow = a;
						break;
					}
				}
	
				arrowList.get(arrowNum).setRelationY(heightArrow);

				g2.drawString(arrowList.get(arrowNum).getRelation(), arrowList
						.get(arrowNum).getRelationX(), arrowList.get(arrowNum)
						.getRelationY() - 3);
			}
		}
	}

	public JComboBox getJComboBox() throws FileNotFoundException {
		if (jComboBox == null) {
			jComboBox = new JComboBox();
			jComboBox.setBounds(new Rectangle(1069, 355, 162, 21));
			jComboBox.setVisible(false);

			jComboBox.addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent e) {/*new java.awt.event.ItemListener() {
				public void itemStateChanged(java.awt.event.ItemEvent e) {*/
					System.out.println("itemstatechanged"); // TODO Auto-generated Event stub actionPerformed()

					if (jComboBox.isVisible()) {
						String str;
						if(jComboBox.getSelectedIndex()>0)
						{		str = depList.get(jComboBox.getSelectedIndex()-1);
					
						System.out.println("");
						if (indexArrayList == -1)
							indexArrayList = 0;
						arrowList.get(arrowList.size()-1).setRel(str);
						Arrow arw = arrowList.get(arrowList.size()-1);

						SntItarr.get(arw.getsourcelablnum() - 1).setRel(
								new Relation(arw.getdestlablnum(), arw
										.getdestcbox(), str));
						jComboBox.setVisible(false);
						
				//		jComboBox.setSelectedIndex(0);
						btnOpen1.setVisible(false);
						for (int i = 0; i < sumofc; i++) {
							if (checkarr.get(i).getClicked()) {
								checkarr.get(i).setEnabled(false);
								checkarr.get(i).setenable(false);
							} else {
								checkarr.get(i).setSelected(false);
							}
						}
						for (int i = 0; i < sumofc; i++) {
							if (checkarr.get(i).getClicked()) {
								checkarr.get(i).setEnabled(false);
								checkarr.get(i).setSelected(true);
							} else {
								if (checkarr.get(i).getenable())
									checkarr.get(i).setEnabled(true);
							}
						}
						btnOpen1.setVisible(false);
						jButton.setEnabled(true);
						repaint();
						}
						else{}
					}
				}
			
			});
		//	jComboBox.addActionListener(new java.awt.event.ActionListener() {
		//		public void actionPerformed(java.awt.event.ActionEvent e) {
		//			System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
		//		}
		//	});
			File read = new File("dep.txt");
			if (read.exists()) {
				Scanner in = new Scanner(read);
				while (in.hasNextLine()) // Loops through until the text file is
				{
					String info = in.nextLine();
					depList.add(info);
					bagdata.add(info);
				}
				jComboBox.addItem(lang.getLan(20, lang.getLangIndex()));
				for (int i = 0; i < bagdata.size(); i++) {
					jComboBox.addItem(bagdata.get(i));
				}
			}
		}
		return jComboBox;
	}

	/**
	 * This method initializes btnOpen1
	 * 
	 * @return javax.swing.JButton
	 */
	public JButton getBtnOpen1() {
		if (btnOpen1 == null) {
			btnOpen1 = new JButton();
			btnOpen1.setBounds(new Rectangle(245, 6, 75, 21));
			btnOpen1.setPreferredSize(new Dimension(30, 10));

			btnOpen1.setActionCommand(lang.getLan(17, lang.getLangIndex()));
			btnOpen1.setText(lang.getLan(17, lang.getLangIndex()));
			btnOpen1.setVisible(false);
			btnOpen1.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					buttonClickCounter++;
					int sourceX = 0, sourceY = 0, destX = 0, destY = 0;

					Sentenceparser sp;
					int labelNum = -1;
					int checkBoxNum = -1;
					int totalCheckNum = -1;
					try {
						sp = new Sentenceparser();
						int[] arr = sp.parsecheckbox(clickedCheckbox);
						labelNum = arr[0];
						checkBoxNum = arr[1];
						totalCheckNum = arr[2];
					} catch (ParserConfigurationException e1) {
						e1.printStackTrace();
					}

					if (buttonClickCounter == 1) {
						sourceX = 14 + (121 * (labelNum));
						sourceY = 175 * (1);

						lArrow.setsource(labelNum + 1, sourceX
								+ (17 * (checkBoxNum)) + 14, sourceY + 9 + 21);
						lArrow.setfirstClickedCheckBox(totalCheckNum);
						btnOpen1.setVisible(false);

						checkarr.get(totalCheckNum).setEnabled(false);
						checkarr.get(totalCheckNum).setSelected(true);
						checkarr.get(totalCheckNum).setEnabled(false);
						for (int checkBoxIndex = 0; checkBoxIndex < sumofc; checkBoxIndex++) {
							if (checkBoxIndex != totalCheckNum) {
								checkarr.get(checkBoxIndex).setEnabled(true);
								checkarr.get(checkBoxIndex).setSelected(false);
							}
						}

					} else if (buttonClickCounter == 2) {
						destX = 14 + (121 * (labelNum));
						destY = 175 * (1);

						lArrow.setdest(labelNum + 1, checkBoxNum + 1, destX
								+ (17 * (checkBoxNum)) + 14, destY + 9 + 21,
								"abc");
						Arrow lArrow2 = new Arrow(lArrow.getSourceX(), lArrow
								.getSourceY(), lArrow.getDestX(), lArrow
								.getDestY(), Math.abs(totalCheckNum
								- lArrow.getFirstClickedCheckBox()),
								lang.getLan(20, lang.getLangIndex()));

						lArrow2.setsource(lArrow.getsourcelablnum(),
								lArrow.getSourceX(), lArrow.getSourceY());
						lArrow2.setdest(lArrow.getdestlablnum(),
								lArrow.getdestcbox(), lArrow.getDestX(),
								lArrow.getDestY(), lang.getLan(20, lang.getLangIndex()));

						SntItarr.get((lArrow.getsourcelablnum() - 1)).setRel(
								new Relation(lArrow.getdestlablnum(), lArrow
										.getdestcbox(), "Please select"));
						buttonClickCounter = 0;

						checkarr.get(lArrow.getFirstClickedCheckBox())
								.setClicked(true);
						checkarr.get(totalCheckNum).setEnabled(false);
						checkarr.get(lArrow.getFirstClickedCheckBox()).setArrayOrder(arrowOrder++);
						indexArrayList = -1;
						for (int j = lArrow.getFirstClickedCheckBox() - 1; j >= 0; j--) {
							if (checkarr.get(j).getArrowNum() != -1) {
								indexArrayList = checkarr.get(j).getArrowNum();
								break;
							}
						}
						boolean isLastArrow = false;
						for (int j = lArrow.getFirstClickedCheckBox() + 1; j < sumofc; j++) {
							if (checkarr.get(j).getArrowNum() != -1) {
								isLastArrow = false;
							} else
								isLastArrow = false;
						}
						if (indexArrayList == -1) {
							checkarr.get(lArrow.getFirstClickedCheckBox())
									.setArrowNum(0);
						} else {
							checkarr.get(lArrow.getFirstClickedCheckBox())
									.setArrowNum(indexArrayList);
						}
						if (indexArrayList < arrowList.size()) {
							if (indexArrayList == -1)
								arrowList.add(lArrow2);
							else
								arrowList.add(lArrow2);
							
						} else
							arrowList.add(lArrow2);
						for (int j = lArrow.getFirstClickedCheckBox() + 1; j < checkarr
								.size(); j++) {
							checkarr.get(j).refleshArrowNum(-1);
						}
						buttonClickCounter = 0;
						jComboBox.setVisible(true);
						int x1 = checkarr.get(lArrow.getFirstClickedCheckBox())
								.getX();
						int y1 = checkarr.get(lArrow.getFirstClickedCheckBox())
								.getY() + 20;
						int x2=labelarr.get(lArrow.getdestlablnum()-1).getX();//checkarr.get(lArrow.getdestcbox()).getX();
						int y2=checkarr.get(lArrow.getdestcbox()).getY()+20;
						jComboBox.setBounds(x2, y2, 162, 21);
						btnOpen1.setVisible(false);
					}
					repaint();

				}
			});
		}
		return btnOpen1;
	}

	class CheckBoxListener implements ItemListener, ActionListener,
			ChangeListener {
		public void itemStateChanged(ItemEvent e) {
			JCheckBox whichCheckBox = (JCheckBox) e.getItem();
			
			Sentenceparser sp1 = null;
			int checkBoxIndex1;
			try {
				sp1 = new Sentenceparser();
			} catch (ParserConfigurationException e2) {
				// TODO Auto-generated catch block
				e2.printStackTrace();
			}
			int[] arr1 = sp1.parsecheckbox(whichCheckBox.getName());
			checkBoxIndex1 = arr1[2];
			
			int checkBoxIndex;
			if(tempToCheck == 0){
				lastChecked = checkarr.get(checkBoxIndex1).getArrayOrder();
				tempToCheck = 1;
			}
			else
				tempToCheck = 0;
			if (vazgecClicked) {
				
				Sentenceparser sp;
				try {
					sp = new Sentenceparser();
					int[] arr = sp.parsecheckbox(whichCheckBox.getName());
					int checkBoxLabel = arr[0];
					checkBoxIndex = arr[2];
					if (!whichCheckBox.isSelected()) {
						SntItarr.get(checkBoxLabel).setRel(
								new Relation(0, 0, ""));
					}
					System.out.println(checkarr.get(checkBoxIndex).getArrayOrder());
					arrowOrder--;
					arrowList.remove(checkarr.get(checkBoxIndex).getArrayOrder());
					for(int i = 0; i < checkarr.size(); i++)
						if(checkarr.get(i).getArrayOrder() != -1 && checkarr.get(i).getArrayOrder() > checkarr.get(checkBoxIndex).getArrayOrder())
							checkarr.get(i).setArrayOrder(checkarr.get(i).getArrayOrder() - 1);
							
				
					checkarr.get(checkBoxIndex).setArrowNum(-1);
					for (int i = checkBoxIndex + 1; i < sumofc; i++) {
						checkarr.get(i).refleshArrowNum(1);
					}
					repaint();
					mythis.xmlButton.doClick();
					checkarr.get(checkBoxIndex).setClicked(false);
					for (int k = 0; k < checkarr.size(); k++) {
						if (checkarr.get(k).getenable()) {
							checkarr.get(k).setEnabled(true);
						}
						if (checkarr.get(k).getClicked()) {
							checkarr.get(k).setEnabled(false);
						}
					}
					checkarr.get(checkBoxIndex).setenable(true);
					
						
					
				} catch (ParserConfigurationException e1) {
					e1.printStackTrace();
				}
				vazgecClicked = false;
				
			} else {
				if (itemStateChangedFlag == true) {
					jButton.setEnabled(false);
					btnOpen1.setEnabled(true);
					if (whichCheckBox.isSelected()) {
						int cbx = whichCheckBox.getX();
						int cby = whichCheckBox.getY();

						clickedCheckbox = whichCheckBox.getName();
						btnOpen1.setVisible(true);
						repaint();
						btnOpen1.setBounds(cbx,
								cby + whichCheckBox.getHeight(), 100, 20);

						if (buttonClickCounter == 1) {
							int totalCheckNum = 0;
							try {
								Sentenceparser sp = new Sentenceparser();
								int[] arr = sp.parsecheckbox(clickedCheckbox);
								totalCheckNum = arr[2];
							} catch (ParserConfigurationException e1) {
								e1.printStackTrace();
							}

							if (whichCheckBox.isSelected()) {
								for (int k = 0; k < sumofc; k++) {
									checkarr.get(k).setEnabled(false);
								}
								checkarr.get(totalCheckNum).setEnabled(true);
							} else {
								for (int k = 0; k < sumofc; k++) {
									checkarr.get(k).setEnabled(true);
								}
							}
						}

					} else {
						btnOpen1.setVisible(false);
						if (buttonClickCounter == 1) {
							for (int k = 0; k < sumofc; k++) {
								if (!checkarr.get(k).isSelected())
									checkarr.get(k).setEnabled(true);
							}
						}
						repaint();
						mythis.xmlButton.doClick();
					}
					
				}
			}
			
		}

		public void actionPerformed(ActionEvent e) {
		}

		public void stateChanged(ChangeEvent e) {
		}
	}

	/**
	 * This method initializes xmlButton
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getXmlButton() {
		if (xmlButton == null) {
			xmlButton = new JButton();
			xmlButton.setBounds(new Rectangle(220, 7, 140, 30));
			xmlButton.setText(lang.getLan(11, lang.getLangIndex()));
			xmlButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					But_Conll.setEnabled(true);
					jButton.setEnabled(true);
					if(opened.getName().endsWith("conll")||opened.getName().endsWith("output")){
						//*gg						
						SuggestButton.setEnabled(false);
						convertedXML=true;
						String command = null;
						try {//g*
							String perlfname=opened.getCanonicalPath();
							perlfname=perlfname.replace(File.separator, "\\");
							command = "perl.exe preparexmlfromconll.pl "+perlfname;
						} catch (IOException e2) {
							// TODO Auto-generated catch block
							e2.printStackTrace();
						}
						Process p = null;
						try {
							p = Runtime.getRuntime().exec(command);
							p.waitFor();
						} catch (Exception e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
						btnOpen.doClick();

						return;
					}
					if (!SntItarr.isEmpty()) {
						try {
							XMLCreator a = new XMLCreator(SntItarr, opened);
							PxmlText = a.sendxmlstring();
						} catch (ParserConfigurationException e1) {
							e1.printStackTrace();
						} catch (SAXException e1) {
							e1.printStackTrace();
						} catch (IOException e1) {
							e1.printStackTrace();
						}
					} else {
						XMLCreator a = new XMLCreator();
						PxmlText = a.sendxmlstring();
					}
					xmlarea.setText(PxmlText);
					javax.swing.SwingUtilities.invokeLater(new Runnable() {
						   public void run() { 
						      jScrollPane.getVerticalScrollBar().setValue(0);
						   }
						});
					
				}
			
			});
		}
		return xmlButton;
	}
	private void XMLSave(File ftosave){
		if (!SntItarr.isEmpty()) {
			try {
				XMLCreator b = new XMLCreator(SntItarr, opened);
				OrgnlxmlText = b.sendoriginalxml();
				OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(ftosave),"UTF-8");
				writer.write(OrgnlxmlText);
				writer.close();
			} catch (ParserConfigurationException e1) {
				e1.printStackTrace();
			} catch (SAXException e1) {
				e1.printStackTrace();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		} else {
			XMLCreator b = new XMLCreator();
			PxmlText = b.sendxmlstring();
			BufferedWriter writer = null;
			try {
				writer = new BufferedWriter(new FileWriter(ftosave));
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		}
	}
	private JButton getKaydetButton() {
		if (kaydetButton == null) {
			kaydetButton = new JButton();
			kaydetButton.setBounds(new Rectangle(520, 7, 140, 30));
			kaydetButton.setText(lang.getLan(15, lang.getLangIndex()));
			kaydetButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					
					FileDemonstration application2 = new FileDemonstration();
					application2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
					File ftosave=null;
					ftosave= application2.save(cpath,"xml");
					if(opened.getName().endsWith("conll")||opened.getName().endsWith("output")){
						xmlButton.doClick();
					}
					
					if(ftosave==null)
					{application2.setVisible(false);}
					else{
						cpath=ftosave.getParent();
						XMLSave(ftosave);
					}
					opened=ftosave;
					mythis.setTitle("Dependency Analysis"+" "+opened.getAbsolutePath());
					
			 }
			});
		}
		return kaydetButton;
	}

	/*private JButton getKaydetButton() {
		if (kaydetButton == null) {
			kaydetButton = new JButton();
			kaydetButton.setBounds(new Rectangle(520, 7, 140, 30));
			kaydetButton.setText(lang.getLan(15, lang.getLangIndex()));
			kaydetButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					FileDemonstration application2 = new FileDemonstration();
					application2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
					File ftosave=null;
					ftosave= application2.save(cpath,"xml");
					if(ftosave==null)
					{application2.setVisible(false);}
					else{
						cpath=ftosave.getParent();
						if (!SntItarr.isEmpty()) {
							try {
								XMLCreator b = new XMLCreator(SntItarr, opened);
								OrgnlxmlText = b.sendoriginalxml();
								OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(ftosave),"UTF-8");
								writer.write(OrgnlxmlText);
								writer.close();
							} catch (ParserConfigurationException e1) {
								e1.printStackTrace();
							} catch (SAXException e1) {
								e1.printStackTrace();
							} catch (IOException e1) {
								e1.printStackTrace();
							}
						} else {
							XMLCreator b = new XMLCreator();
							PxmlText = b.sendxmlstring();
							BufferedWriter writer = null;
							try {
								writer = new BufferedWriter(new FileWriter(ftosave));
							} catch (IOException e1) {
								e1.printStackTrace();
							}
						}
					}
				}
			});
		}
		return kaydetButton;
	}*/

	private JButton getJButton() {
		if (jButton == null) {
			jButton = new JButton();
			jButton.setBounds(new Rectangle(370, 7, 140, 30));
			jButton.setText(lang.getLan(14, lang.getLangIndex()));
			jButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					vazgecClicked = true;
					if(arrowList.size() != 0)
						for (int i = 0; i < checkarr.size(); i++) {
							if (checkarr.get(i).getClicked()) {
								checkarr.get(i).setEnabled(true);
							} else {
								checkarr.get(i).setEnabled(false);
							}
						}
					else
						vazgecClicked = false;
						
					
				}
				
			});
		}
		
		return jButton;
	}

	private JScrollPane getJScrollPane() throws FileNotFoundException {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
			jScrollPane.setBackground(Color.white);
			jScrollPane.setBounds(new Rectangle(342, 68, 259, 127));
			jScrollPane
					.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
			jScrollPane
					.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
			jScrollPane.add(getJContentPane(), null);
			jScrollPane.setViewportView(jContentPane);

			jScrollPane.getHorizontalScrollBar().addAdjustmentListener(
					new MyAction());
			jScrollPane.getVerticalScrollBar().addAdjustmentListener(new MyAction2());

		}
		return jScrollPane;
	}

	public class MyAction implements AdjustmentListener {

		@Override
		public void adjustmentValueChanged(AdjustmentEvent ae) {
			
			
			xmlarea.setBounds(5/*jScrollPane.getHorizontalScrollBar().getValue()*/,
					390, jScrollPane.getHorizontalScrollBar().getMaximum()-5,jScrollPane.getVerticalScrollBar().getMaximum()- 390);		
			repaint();
		}
	}
	public class MyAction2 implements AdjustmentListener {

		@Override
		public void adjustmentValueChanged(AdjustmentEvent ae) {
			
			
			//xmlarea.setBounds(5,390, (int)jContentPane.getPreferredSize().getWidth()-5,jScrollPane.getVerticalScrollBar().getMaximum()- 390);
			xmlarea.setBounds(5,390, (int)jScrollPane.getHorizontalScrollBar().getMaximum()-5,jScrollPane.getVerticalScrollBar().getMaximum()- 390);
			
			repaint();
		}
	}

	/**
	 * This method initializes But_Conll	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getBut_Conll() {
		if (But_Conll == null) {
			But_Conll = new JButton();
			But_Conll.setBounds(new Rectangle(670, 7, 140, 30));
			But_Conll.setText(lang.getLan(12, lang.getLangIndex()));
			But_Conll.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					SuggestButton.setEnabled(true);
					String command = null;					
					jButton.setEnabled(false);
					But_Conll.setEnabled(false);
					if(opened.getName().endsWith("conll")){
						return;
					}
					
					XMLSave(opened);
					convertedConll=true;
					String xml=getXmlarea().getText();
						//	BufferedWriter writer = null;
							File ftosave= new File("12345.xml");
							try {
								XMLCreator b = new XMLCreator(SntItarr, opened);
								
								String xmlforConLL=b.sendoriginalxml();
							//	xmlforConLL=xmlforConLL.replaceAll("UTF-8","windows-1254");
								OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(ftosave),"UTF-8");
								BufferedWriter writeFile = new BufferedWriter(writer);
								String str = null;
								BufferedReader reader = new BufferedReader(new StringReader(xmlforConLL));      	
								while ((str = reader.readLine()) != null) {	
									writeFile.write(str);	
									writeFile.newLine();
								}
								writeFile.close();
								writer.close();
							/*	writer = new BufferedWriter(new FileWriter(ftosave));
								writer.write(b.sendoriginalxml());
								writer.close();*/
							} catch (Exception e1) {
								e1.printStackTrace();
							} 
							//g*
							String perlfname = null;
							try {
								perlfname = opened.getCanonicalPath();
							} catch (IOException e2) {
								// TODO Auto-generated catch block
								e2.printStackTrace();
							}
							perlfname=perlfname.replace(File.separator, "\\");
							command="perl.exe prepareconllfromxml.pl "+perlfname;
				
					try {						
						Process p = Runtime.getRuntime().exec(command);
						p.waitFor();					
					}catch (Exception e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
					btnOpen.doClick();
					disableallcheckboxes();
				}


			});
		}
		return But_Conll;
	}
	private void disableallcheckboxes() {
		for(CheckBoxList c:checkarr){
			c.setenable(false);
			c.setEnabled(false);
		}
			
		
	}
	/**
	 * This method initializes ButBLY	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getButBLY() {
		if (ButBLY == null) {
			TDKList= new ArrayList<String>();
			ButBLY = new JButton();
			ButBLY.setBounds(new Rectangle(820, 7, 140, 30));
			ButBLY.setText(lang.getLan(16, lang.getLangIndex()));
			ButBLY.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					File TDK_List=new File("TDK_CollocationList.txt");
					 
					try {
						BufferedReader bfr = new BufferedReader(new InputStreamReader
								  (new FileInputStream(TDK_List),"UTF8"));
						String tempstr,outputstr;
						outputstr=tempstr="";
						
						
						 while(bfr.ready())
						 {
							 tempstr=bfr.readLine();
							 TDKList.add(tempstr);
							 
						 }
						 CollocationFinder CF=new CollocationFinder(TDKList,TheSentence);
						 collocationsFound=CF.findCols(TheSentence);
					//	 ArrayList<Integer>indexes=CF.getIndexes(TheSentence);
	//					 System.out.println(TheSentence);
						 ArrayList<Integer>cboxesToPaint=new ArrayList<Integer>();
						 for(int k=0;k<collocationsFound.size();k++)
						 {
							 int indexStart=collocationsFound.get(k).getFirstWordsIndexInSentence();
							 int indexEnd=indexStart+collocationsFound.get(k).getWordNumofCol();
							// ArrayList<Integer>a=;//arr;
							 int indexofCheck=0;
							 for(int i=0;i<SntItarr.size();i++)
							 { 
								 for(int j=0;j<SntItarr.get(i).getChecknum();j++)
								 {
									 if(indexEnd>i && i>=indexStart)
									 { cboxesToPaint.add(indexofCheck);}
									indexofCheck++;
									if(indexofCheck>checkarr.size())
									{
										System.out.println(" ");
									}
								 }
							 }
							 int a=0;
							 System.out.println(" ");
						 }
						 for(int k=0;k<collocationsFound.size();k++)
						 {
							 System.out.println(collocationsFound.get(k).getContentOfCol()+", "+collocationsFound.get(k).getWordNumofCol()+", "+CF.getWordIndexofCol(collocationsFound.get(k)));
							 
						 }
						 for(int j=0;j<checkarr.size()/*cboxesToPaint.size()*/;j++)
						 {
							 for(int d=0;d<cboxesToPaint.size();d++)
							 {
								 if(j==cboxesToPaint.get(d))
								 {checkarr.get(j).setBackground(Color.YELLOW);}
							}
							 //System.out.println(cboxesToPaint.get(j));
						}
						 
							
					} catch (UnsupportedEncodingException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					} catch (FileNotFoundException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					} catch (IOException e2) {
						// TODO Auto-generated catch block
						e2.printStackTrace();
					}
					 
				}
			});
		}
		return ButBLY;
	}
	/**
	 * This method initializes SuggestButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getSuggestButton() {
		if(SuggestButton==null){
			SuggestButton=new JButton();
			SuggestButton.setBounds(new Rectangle(1120, 7, 152, 30));
			SuggestButton.setText(lang.getLan(22, lang.getLangIndex()));
			SuggestButton.setEnabled(false);
			SuggestButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					
					FileDemonstration application = new FileDemonstration();
					application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
					File modelfile = null;
					try {
						File d=new File("");
						d.getAbsolutePath();
						System.out.println(d.getAbsolutePath());
						modelfile = application.getFile(d.getAbsolutePath(),"mco");
					} catch (IOException e6) {
						// TODO Auto-generated catch block
						e6.printStackTrace();
					}
					//g*
					if(modelfile!=null){
						Locale.setDefault(Locale.ENGLISH);
						String[] arg;
						String modelfilename=modelfile.getName();
						modelfilename=modelfilename.split(".mco")[0];
						String testoptions = null;
						try {
							testoptions = "-c "+modelfilename+" -i "+opened.getCanonicalPath()+" -o "+opened.getCanonicalPath()+".output -F features.xml -a nivrestandard -m parse -lso -s_0_-t_1_-d_2_-g_0.12_-c_0.7_-r_0.6_-e_.01";
						} catch (IOException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
						testoptions.replace("/", File.separator);
						// arg = testoptions.split("\\s");
						System.out.println(testoptions);
						try {
							new MaltParserService().runExperiment(testoptions);
						} catch (MaltChainedException m) {
							// TODO Auto-generated catch block
							m.printStackTrace();
						}

					
						Locale.setDefault(new Locale("tr", "", ""));
						//g*
						//clean the screen
						SuggestClicked=true;
						btnOpen.doClick();
						
					}

				}

				
			}
			);
		}
		return SuggestButton;
	}
	private void cleangraph() {
		repaint();
		int labtoremove =0, cbtoremove = 0;
		
		for (int x = 0; x < jContentPane.getComponentCount(); x++) {
			Component comp = jContentPane.getComponent(x);
			// Check what type of component have you got
			if (comp instanceof JCheckBox) {
				cbtoremove++;
			} else if (comp instanceof JLabel) {
				labtoremove++;// get the number of labels
			}
		}
		int x1;
		for (x1 = 0; x1 < jContentPane.getComponentCount(); x1++) {
			Component comp = jContentPane.getComponent(x1);
			// Check what type of component have you got
			if (comp instanceof JCheckBox) {// get the first index
				// of the checkboxes
				break;
			}

		}
		for (int d = 0; d < cbtoremove; d++)// remove the checkboxes
		{
			Component comp = jContentPane.getComponent(x1);
			JCheckBox cb = (JCheckBox) comp;
			jContentPane.remove(cb);
		}
		int x2;
		for (x2 = 0; x2 < jContentPane.getComponentCount(); x2++) {
			Component comp = jContentPane.getComponent(x2);
			// Check what type of component have you got
			if (comp instanceof JLabel) {// get the first index of
				// the labels
				break;
			}

		}
		for (int d = 0; d < labtoremove; d++)// remove the labels
		{
			Component comp = jContentPane.getComponent(x2);
			JLabel lab = (JLabel) comp;
			jContentPane.remove(lab);
		}

		
	}
	/**
	 * This method initializes conllSaveButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getConllSaveButton() {
		if (conllSaveButton == null) {
			conllSaveButton = new JButton();
			conllSaveButton.setBounds(new Rectangle(970, 7, 140, 30));
			conllSaveButton.setText(lang.getLan(18, lang.getLangIndex()));
			conllSaveButton.addActionListener(new java.awt.event.ActionListener() {
				

				public void actionPerformed(java.awt.event.ActionEvent e) {
					
					FileDemonstration application2 = new FileDemonstration();
					application2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
					File ftosave=null;
					ftosave= application2.save(cpath,"conll");
					if(ftosave==null)
					{application2.setVisible(false);}
					else{
						SuggestButton.setEnabled(true);
						//opened=ftosave;
						cpath=ftosave.getParent();
						if(opened.getName().endsWith("xml"))
							XMLSave(new File(ftosave.getAbsolutePath()+".xml"));//The xml version of the conll file is automatically recorded with an xml extension
						if (!SntItarr.isEmpty()) {
							try {
								//xmlButton.doClick();
								if(opened.getName().endsWith("xml")){									
									But_Conll.doClick();
								}
								opened=ftosave;
								mythis.setTitle("Dependency Analysis"+" "+opened.getAbsolutePath());
								OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(ftosave),"UTF-8");
								BufferedWriter writeFile = new BufferedWriter(writer);
								String str = null;
								BufferedReader reader = new BufferedReader(new StringReader(xmlarea.getText()));      	
								while ((str = reader.readLine()) != null) {	
									writeFile.write(str);	
									writeFile.newLine();
								}
								writeFile.close();
								writer.close();
							} catch (IOException e1) {
								e1.printStackTrace();
							}
						} else {
							XMLCreator b = new XMLCreator();
							PxmlText = b.sendxmlstring();
							BufferedWriter writer = null;
							try {
								writer = new BufferedWriter(new FileWriter(ftosave));
							} catch (IOException e1) {
								e1.printStackTrace();
							}
						}
					}
				}
			});
		}
		return conllSaveButton;
	}

} // @jve:decl-index=0:visual-constraint="10,10"