复选框工具8.9——导师优化和代码规范

package com.highgo.main;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import com.highgo.JDialog.NewJDialog;

import org.dom4j.DocumentException;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Highgo
 */



public class CkbMainView extends javax.swing.JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * Creates new form CheckboxSwing
	 * 
	 * 
	 */
	public CkbMainView()  {
		this.setTitle("CkbMainView");
		initComponents();
		inittable();
		this.setLocationRelativeTo(null);

	}

	private CkbMainView getThis() {
		return this;

	}

	private String filepath = null;
	private String comppath = null;
	private String resultpath = null;

	private void pathinit()  {

		getXml();

		jCKTextArea.setText(filepath);

		if (filepath == null || filepath.trim().equals("")) {
		} 
		else {
			DefaultTableModel model = (DefaultTableModel) jCKTabel.getModel();
			model.setRowCount(0);
			traverseFolder(filepath,0);
		}
	}

	private void getXml() {

		SAXReader reader = new SAXReader();
		InputStream is = null;
		try {
			is = new FileInputStream("config/filedath.xml");

			Document doc = null;
			doc = reader.read(is);

			Element root = doc.getRootElement();
			int i = 0;
			Iterator<Element> it = root.elementIterator();
			while(it.hasNext()){
				Element e = it.next();

				//Attribute idAttr = e.attribute("id");
				//String id = idAttr.getValue();
				//System.out.println(id);


				Element nameElement = e.element("name");

				if(i == 0) {
					filepath = nameElement.getText();
					//System.out.println(filepath);
				}
				if(i == 1) {
					comppath = nameElement.getText();
				}
				if(i == 2) {
					resultpath = nameElement.getText();
				}
				i++;
			}   


		} catch (DocumentException | FileNotFoundException e1) {
			// TODO Auto-generated catch block
			//jCKTextArea.setText("配置文件有错");
			JOptionPane.showMessageDialog(null, "配置文件有错", "Warning", JOptionPane.ERROR_MESSAGE); 
			e1.printStackTrace();
		} finally {
			try {
				if(is != null) {
					is.close();
				}
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

	}


	private   DefaultMutableTreeNode traverseFolder(String path,int n) {
		DefaultMutableTreeNode temp;


		DefaultTableModel model = (DefaultTableModel) jCKTabel.getModel();
		DefaultMutableTreeNode parentnode = new DefaultMutableTreeNode(new File(path).getName());
		File file = new File(path);
		if (file.exists()) {
			if(file.isDirectory()) {
				File[] files = file.listFiles();
				if (files.length == 0) {
					if(file.isDirectory()) {
						//Empty folder
						DefaultMutableTreeNode dn = new DefaultMutableTreeNode(file.getName(), false);
						return dn;
					}
				}else{
					for (File file2 : files) {
						if (file2.isDirectory()) {
							//Add Node
							if( n < 5) {
								n++;
								parentnode.add(traverseFolder(file2.getAbsolutePath(),n));
							}
						}else{
							//Generating Node

							try {
								String fileName = file2.getName();
								String fapath = file2.getCanonicalPath();

								model.addRow(new Object[] { true, model.getRowCount() + 1 , fileName, fapath});
								temp = new DefaultMutableTreeNode(file2.getName());
								parentnode.add(temp);	
							} catch (IOException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}	

						}
						javax.swing.tree.DefaultTreeModel dm = new DefaultTreeModel(parentnode);
						// Set the model to the tree
						jCKTree.setModel(dm);
					}
				}
			} else {
				System.out.println("error dir");
			}
		} else {
			//file  not exist
			return null;
		}
		return parentnode;

	}

	private void inittable()  {

		DefaultTableModel model = (DefaultTableModel) jCKTabel.getModel();




		jCKTree.setModel(null);
		jBAll.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				for (int i = 0; i < model.getRowCount(); i++) {
					model.setValueAt(true, i, 0);
				}
			}
		});

		jBAllNot.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				for (int i = 0; i < model.getRowCount(); i++) {
					model.setValueAt(false, i, 0);
				}
			}
		});

		jBClear.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				model.setRowCount(0);
			}
		});

		jBDelete.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int sum = model.getRowCount();

				for(int i = sum - 1; i >= 0; i--) {
					if((boolean) model.getValueAt(i, 0) == true) {
						model.removeRow(i);
					}
				}
			}



		});

		getRootPane().setDefaultButton(jBOK);
		jBOK.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Boolean str = null;
				List<String> mojdlogName = new ArrayList<>();
				List<String> mojdlogPath = new ArrayList<>();
				for (int i = 0; i < model.getRowCount(); i++) {
					str =  (Boolean) model.getValueAt(i, 0);
					if (str.equals(true)) {
						mojdlogName.add((String) model.getValueAt(i, 2));
						mojdlogPath.add((String) model.getValueAt(i, 3));
						System.out.println("true" + (i + 1));
					} else {
						System.out.println("false" + (i + 1));
					}
				}
				System.out.println(mojdlogName);

				new NewJDialog(getThis(), true, mojdlogName,mojdlogPath,comppath,resultpath);
			}
		});
		jBPath.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				pathinit();
			}
		});




	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed" desc="Generated
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jBAllNot = new javax.swing.JButton();
        jBAll = new javax.swing.JButton();
        jSPTabel = new javax.swing.JScrollPane();
        jCKTabel = new javax.swing.JTable();
        jBOK = new javax.swing.JButton();
        jSPArea = new javax.swing.JScrollPane();
        jCKTextArea = new javax.swing.JTextArea();
        jBPath = new javax.swing.JButton();
        jBClear = new javax.swing.JButton();
        jBDelete = new javax.swing.JButton();
        jSPTree = new javax.swing.JScrollPane();
        jCKTree = new javax.swing.JTree();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jBAllNot.setText("ANOT");

        jBAll.setText("ALL");

        jCKTabel.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Choose", "line", "Name", "path"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Boolean.class, java.lang.Integer.class, java.lang.Object.class, java.lang.Object.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jSPTabel.setViewportView(jCKTabel);
        if (jCKTabel.getColumnModel().getColumnCount() > 0) {
            jCKTabel.getColumnModel().getColumn(0).setMinWidth(30);
            jCKTabel.getColumnModel().getColumn(0).setPreferredWidth(60);
            jCKTabel.getColumnModel().getColumn(0).setMaxWidth(200);
            jCKTabel.getColumnModel().getColumn(1).setMinWidth(30);
            jCKTabel.getColumnModel().getColumn(1).setPreferredWidth(50);
            jCKTabel.getColumnModel().getColumn(1).setMaxWidth(200);
            jCKTabel.getColumnModel().getColumn(3).setMinWidth(30);
            jCKTabel.getColumnModel().getColumn(3).setPreferredWidth(30);
        }

        jBOK.setText("OK");

        jCKTextArea.setColumns(20);
        jCKTextArea.setRows(5);
        jSPArea.setViewportView(jCKTextArea);

        jBPath.setText("Path");

        jBClear.setText("Clear");

        jBDelete.setText("Delete");

        jSPTree.setViewportView(jCKTree);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jBAllNot, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBAll, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jBDelete, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jBClear, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 66, Short.MAX_VALUE)
                .addComponent(jSPArea, javax.swing.GroupLayout.PREFERRED_SIZE, 428, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBPath, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(162, 162, 162)
                .addComponent(jBOK, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(169, 169, 169))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jSPTabel, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSPTree)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSPArea, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jBAll)
                            .addComponent(jBClear))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jBAllNot)
                            .addComponent(jBDelete)))
                    .addComponent(jBPath))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jSPTabel, javax.swing.GroupLayout.DEFAULT_SIZE, 437, Short.MAX_VALUE)
                        .addGap(3, 3, 3))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jSPTree)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addComponent(jBOK)
                .addGap(6, 6, 6))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {
		/* Set the Nimbus look and feel */
		// <editor-fold defaultstate="collapsed" desc=" Look and feel setting code
		// (optional) ">
		/*
		 * If Nimbus (introduced in Java SE 6) is not available, stay with the default
		 * look and feel. For details see
		 * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
		 */
		try {
			for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
				if ("Nimbus".equals(info.getName())) {
					javax.swing.UIManager.setLookAndFeel(info.getClassName());
					break;
				}
			}
		} catch (ClassNotFoundException ex) {
			java.util.logging.Logger.getLogger(CkbMainView.class.getName()).log(java.util.logging.Level.SEVERE, null,
					ex);
		} catch (InstantiationException ex) {
			java.util.logging.Logger.getLogger(CkbMainView.class.getName()).log(java.util.logging.Level.SEVERE, null,
					ex);
		} catch (IllegalAccessException ex) {
			java.util.logging.Logger.getLogger(CkbMainView.class.getName()).log(java.util.logging.Level.SEVERE, null,
					ex);
		} catch (javax.swing.UnsupportedLookAndFeelException ex) {
			java.util.logging.Logger.getLogger(CkbMainView.class.getName()).log(java.util.logging.Level.SEVERE, null,
					ex);
		}
		// </editor-fold>
		/* Create and display the form */
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {

				new CkbMainView().setVisible(true);

			}
		});
	}

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBAll;
    private javax.swing.JButton jBAllNot;
    private javax.swing.JButton jBClear;
    private javax.swing.JButton jBDelete;
    private javax.swing.JButton jBOK;
    private javax.swing.JButton jBPath;
    private javax.swing.JTable jCKTabel;
    private javax.swing.JTextArea jCKTextArea;
    private javax.swing.JTree jCKTree;
    private javax.swing.JScrollPane jSPArea;
    private javax.swing.JScrollPane jSPTabel;
    private javax.swing.JScrollPane jSPTree;
    // End of variables declaration//GEN-END:variables
}
package com.highgo.JDialog;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;

import javax.swing.table.DefaultTableModel;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Highgo
 */
public class NewJDialog extends javax.swing.JDialog {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private List<String> path;

	private String comppath;
	private String resultpath;
	public NewJDialog(java.awt.Frame parent, boolean modal, List<String> mojdlogName , List<String> mojdlogPath, String comp_path, String result_path) {
		super(parent, modal);
		initComponents();
		path = mojdlogPath;
		comppath = comp_path;
		resultpath = result_path;
		String file_path = null;

		DefaultTableModel model = (DefaultTableModel) jTableNewD.getModel();
		for(int i = 0 ; i < mojdlogName.size(); i++) {
			if(mojdlogName != null) {
				file_path = mojdlogPath.get(i);
				compare(file_path,comp_path,true);
				boolean compbl = compare(file_path,comp_path,true);
				model.addRow(new Object[] { model.getRowCount() + 1 ,mojdlogName.get(i), compbl});
			}
		}
		//	System.out.println(path);
		initAction();

		this.setTitle("NewjDialog");
		this.setLocationRelativeTo(null);
		this.setVisible(true);



	}

	private boolean compare(String file_path,String comp_path,boolean compbl) {
		BufferedReader	br = null;
		BufferedReader	cbr = null;
		try {
			br = new BufferedReader(new FileReader(file_path));
			cbr = new BufferedReader(new FileReader(comp_path));

			String brStr = null;
			String cbrStr = null;
			while((brStr = br.readLine()) != null  && (cbrStr = cbr.readLine()) != null) {
				if (brStr.equals(cbrStr)) {
					compbl = true;
				} else {
					compbl = false;
					break;
				}
			}
				while ((cbrStr = cbr.readLine()) != null)
				{
					compbl = false;	
					break;
				}
				while((brStr = br.readLine()) != null )
				{
					compbl = false;
					break;
				}

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				if (br != null) {
					br.close();
				}
				
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			try {
				if (cbr != null) {
					cbr.close();
				}
				
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return compbl;
	}

	private void initAction() {
		DefaultTableModel model = (DefaultTableModel) jTableNewD.getModel();
		jTableNewD.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				int clickCount = e.getClickCount();
				if ( clickCount == 2 ) {
					int numac = jTableNewD.getSelectedRow();
					System.out.println(numac);
					if (model.getValueAt(numac, 2).equals(false)) {
						String file_name = (String)model.getValueAt(numac, 1);
						new JDiaComp( null, true, numac, path,comppath,resultpath,file_name);
					}
				}		
			}
		});
	}


	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents() {

		jScrollPaneNewD = new javax.swing.JScrollPane();
		jTableNewD = new javax.swing.JTable();

		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

		jTableNewD.setModel(new javax.swing.table.DefaultTableModel(
				new Object [][] {

				},
				new String [] {
						"Line", "Name", "Boolean"
				}
				) {
			boolean[] canEdit = new boolean [] {
					false, false, false
			};

			public boolean isCellEditable(int rowIndex, int columnIndex) {
				return canEdit [columnIndex];
			}
		});
		jScrollPaneNewD.setViewportView(jTableNewD);
		if (jTableNewD.getColumnModel().getColumnCount() > 0) {
			jTableNewD.getColumnModel().getColumn(0).setMinWidth(30);
			jTableNewD.getColumnModel().getColumn(0).setPreferredWidth(60);
			jTableNewD.getColumnModel().getColumn(0).setMaxWidth(150);
		}

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(
				layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
						.addContainerGap()
						.addComponent(jScrollPaneNewD)
						.addContainerGap())
				);
		layout.setVerticalGroup(
				layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
						.addContainerGap()
						.addComponent(jScrollPaneNewD)
						.addContainerGap())
				);

		pack();
	}// </editor-fold>//GEN-END:initComponents

	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {
		/* Set the Nimbus look and feel */
		//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
		/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
		 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
		 */
		try {
			for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
				if ("Nimbus".equals(info.getName())) {
					javax.swing.UIManager.setLookAndFeel(info.getClassName());
					break;
				}
			}
		} catch (ClassNotFoundException ex) {
			java.util.logging.Logger.getLogger(NewJDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (InstantiationException ex) {
			java.util.logging.Logger.getLogger(NewJDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (IllegalAccessException ex) {
			java.util.logging.Logger.getLogger(NewJDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (javax.swing.UnsupportedLookAndFeelException ex) {
			java.util.logging.Logger.getLogger(NewJDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		}
		//</editor-fold>

		/* Create and display the dialog */
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				NewJDialog dialog = new NewJDialog(new javax.swing.JFrame(), true, null,null,null,null);
				dialog.addWindowListener(new java.awt.event.WindowAdapter() {
					@Override
					public void windowClosing(java.awt.event.WindowEvent e) {
						System.exit(0);
					}
				});
				dialog.setVisible(true);
			}
		});
	}

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JScrollPane jScrollPaneNewD;
	private javax.swing.JTable jTableNewD;
	// End of variables declaration//GEN-END:variables
}
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.highgo.JDialog;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import java.util.Locale;

import javax.swing.BoundedRangeModel;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;

import com.highgo.comp.DNASequence;
import com.highgo.comp.Read_File;

/**
 *
 * @author Highgo
 */
public class JDiaComp extends javax.swing.JDialog {

	/**
	 * Creates new form JDiaComp
	 *   
	 * 
	 */


	public JDiaComp(java.awt.Frame parent, boolean modal, int num, List<String> path, String comppath, String resultpath, String file_name)   {
		super(parent, modal);
		initComponents();
		String result = resultpath + "//result_" + (num + 1) + "_" + file_name+ ".txt";
		compareDNA(num, path, comppath, result);
		
		String str1 = jDCompTextLeft.getText();
		String str2 = jDCompTextRight.getText();
		int i2 = str2.length();
		int i1 = str1.length();
		int i =i2 - i1;
		System.out.println("iiiiiiiiiiiiii"+i);
		
		if(i > 0) {
			while(i != 0) {
			str1 = str1 + "\n" ;
			 i2 = str2.length();
			 i1 = str1.length();
			 i = i2 - i1;
			 System.out.println("=============" + i);
			}
			System.out.println("=============" + i);
			jDCompTextLeft.setText(str1);
		}
		if(i < 0) {
			while(i != 0) {
			str2 = str2 + "\n" ;
			 i2 = str2.length();
			 i1 = str1.length();
			 i = i2 - i1;
			 System.out.println("=============" + i);
			}
			System.out.println("====================" + i);
			jDCompTextRight.setText(str2);
		}
		jScrollPaneLeft.getVerticalScrollBar().setModel(jScrollPaneRight.getVerticalScrollBar().getModel());
	
	

		this.setTitle("JDiaComp");
		this.setLocationRelativeTo(null);
		this.setVisible(true);

	}


	private void compareDNA(int num, List<String> path, String comppath, String resultpath) {
		String filepath ;
		String dnas1file,dnas2comp;
		filepath =  path.get(num);
		BufferedWriter rbw = null;
		try {
			 rbw = new BufferedWriter(new FileWriter(resultpath));

			
			String File1 = Read_File.getFile(filepath);
			String File2 = Read_File.getFile(comppath);
			
			DNASequence dna = new DNASequence(File1,File2);
			dna.runAnalysis();
			dna.traceback();
			dnas1file = dna.getString1();
			dnas2comp = dna.getString2();

			Document docs1 = jDCompTextLeft.getDocument();
			Document docs2 = jDCompTextRight.getDocument();

			char[] s = dnas1file.toCharArray();
			char[] p = dnas2comp.toCharArray();
			SimpleAttributeSet set2 = new SimpleAttributeSet();
			StyleConstants.setFontSize(set2,16);
			for(int i = 0; i < dnas1file.length(); i++){
				if(s[i] == '~'){
					StyleConstants.setForeground(set2,Color.BLUE);
					docs2.insertString(docs2.getLength(), String.valueOf(p[i]), set2);
				}else if(p[i] == '~'){
					StyleConstants.setForeground(set2,Color.BLUE);
					docs1.insertString(docs1.getLength(), String.valueOf(s[i]), set2);
				}else if(s[i] == p[i]){
					StyleConstants.setForeground(set2,Color.black);
					docs1.insertString(docs1.getLength(), String.valueOf(s[i]), set2);
					docs2.insertString(docs2.getLength(), String.valueOf(p[i]), set2);
				}else if(s[i] != p[i]){                                
					StyleConstants.setForeground(set2,Color.red);
					docs1.insertString(docs1.getLength(), String.valueOf(s[i]), set2);
					docs2.insertString(docs2.getLength(), String.valueOf(p[i]), set2);
				}else{
					System.out.print(" other ");
				}
			}
			
			rbw.write(dnas1file + "\r\n" + dnas2comp);
		
		} catch (IOException | BadLocationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				if (rbw != null) {
					rbw.close();
				}
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	

	

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPaneLeft = new javax.swing.JScrollPane();
        jDCompTextLeft = new javax.swing.JTextPane();
        jScrollPaneRight = new javax.swing.JScrollPane();
        jDCompTextRight = new javax.swing.JTextPane();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jScrollPaneLeft.setViewportView(jDCompTextLeft);

        jScrollPaneRight.setViewportView(jDCompTextRight);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPaneLeft, javax.swing.GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPaneRight, javax.swing.GroupLayout.DEFAULT_SIZE, 245, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPaneRight)
                    .addComponent(jScrollPaneLeft, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {
		/* Set the Nimbus look and feel */
		//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
		/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
		 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
		 */
		try {
			for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
				if ("Nimbus".equals(info.getName())) {
					javax.swing.UIManager.setLookAndFeel(info.getClassName());
					break;
				}
			}
		} catch (ClassNotFoundException ex) {
			java.util.logging.Logger.getLogger(JDiaComp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (InstantiationException ex) {
			java.util.logging.Logger.getLogger(JDiaComp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (IllegalAccessException ex) {
			java.util.logging.Logger.getLogger(JDiaComp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (javax.swing.UnsupportedLookAndFeelException ex) {
			java.util.logging.Logger.getLogger(JDiaComp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		}
		//</editor-fold>

		/* Create and display the dialog */
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				JDiaComp dialog;
				try {
					dialog = new JDiaComp(new javax.swing.JFrame(), true, 0, null,null,null,null);

					dialog.addWindowListener(new java.awt.event.WindowAdapter() {
						@Override
						public void windowClosing(java.awt.event.WindowEvent e) {
							System.exit(0);
						}
					});
					dialog.setVisible(true);
				} catch (HeadlessException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
	}

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextPane jDCompTextLeft;
    private javax.swing.JTextPane jDCompTextRight;
    private javax.swing.JScrollPane jScrollPaneLeft;
    private javax.swing.JScrollPane jScrollPaneRight;
    // End of variables declaration//GEN-END:variables
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值