码迷,mamicode.com
首页 > 其他好文 > 详细

HZAU_Parser

时间:2014-04-27 21:34:04      阅读:492      评论:0      收藏:0      [点我收藏+]

标签:java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gao.hzau;

import java.awt.Color;
import java.awt.FileDialog;
import java.awt.Font;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
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 javax.swing.text.StyleContext;

/**
 *
 * @author 高冠军
 */
public class LanguageLabel extends javax.swing.JFrame {

     JFileChooser fileChooser = new JFileChooser();
     String fileName = new String();
     String tempString=new String();
     String one=new String();
     String pathName=new String();
     String fileName1=new String();
     
     char a[]=new char[200];
     String b=new String();
     int star=0,en=0;
     int next=0;
     int count=1;
     boolean flag_s=false;
     boolean flag_b=false;
    /**
     * Creates new form LanguageLabel
     */
    public LanguageLabel() {
        initComponents();
    }

    /**
     * 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">                          
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextPane1 = new javax.swing.JTextPane();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextPane2 = new javax.swing.JTextPane();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jButton10 = new javax.swing.JButton();
        jScrollPane5 = new javax.swing.JScrollPane();
        jTextArea3 = new javax.swing.JTextArea();
        jLabel4 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Semantic Association Annotation");
        setBackground(new java.awt.Color(255, 255, 153));
        setFont(new java.awt.Font("宋体", 0, 18)); // NOI18N

        jPanel2.setBackground(new java.awt.Color(255, 255, 153));

        jButton1.setText("Select>");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton3.setText("< Prev");

        jButton4.setText("Next >");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jScrollPane1.setViewportView(jTextPane1);

        jScrollPane2.setViewportView(jTextPane2);

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jTextArea1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTextArea1MouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(jTextArea1);

        jLabel1.setText("    Entity");

        jLabel2.setText(" Feature");

        jLabel3.setText("Value");

        jPanel1.setBackground(new java.awt.Color(255, 255, 153));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jButton5.setText("To Entity");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton5, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 20, 90, 30));

        jButton6.setText("To Feature");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton6, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 90, 90, 30));

        jButton7.setText("To Feature");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton7, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 160, 90, 30));

        jButton8.setText("Append");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton8, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 230, 90, 30));

        jButton9.setText("Delete");
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton9, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 300, 90, 30));

        jButton10.setText("Save");
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton10, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 370, 90, 30));

        jTextArea3.setColumns(20);
        jTextArea3.setRows(5);
        jScrollPane5.setViewportView(jTextArea3);

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel4.setText("Filename");

        jTextField4.setBackground(new java.awt.Color(255, 255, 153));
        jTextField4.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTextField4.setMinimumSize(new java.awt.Dimension(10, 21));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 245, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(jPanel2Layout.createSequentialGroup()
                                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel2Layout.createSequentialGroup()
                                            .addGap(46, 46, 46)
                                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGap(42, 42, 42)
                                            .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(jPanel2Layout.createSequentialGroup()
                                            .addGap(60, 60, 60)
                                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGap(67, 67, 67)
                                            .addComponent(jLabel3))))
                                .addComponent(jScrollPane5)
                                .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 330, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap())
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton3, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jButton4, javax.swing.GroupLayout.Alignment.TRAILING)))))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jButton3)
                        .addGap(18, 18, 18)
                        .addComponent(jButton4))
                    .addComponent(jButton1))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel3)
                                .addComponent(jLabel2)))
                        .addGap(9, 9, 9)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 265, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addComponent(jScrollPane1)
                    .addComponent(jScrollPane3)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 417, Short.MAX_VALUE)))
        );

        jMenuBar1.setBackground(new java.awt.Color(255, 255, 153));

        jMenu1.setText("File");

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem1.setText("打开文件");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);
        jMenu1.add(jSeparator1);

        jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem2.setText("退出");
        jMenu1.add(jMenuItem2);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Help");
        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        jPanel2.getAccessibleContext().setAccessibleName("");

        setSize(new java.awt.Dimension(834, 587));
        setLocationRelativeTo(null);
    }// </editor-fold>                        

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
        //响应Open按钮
        this.Open();
    }                                          

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        //响应select按钮
        
        one= this.jTextPane1.getSelectedText();
        next=this.jTextPane1.getCaretPosition();
       // Graphic t=new Graphic()
        showFront(star,en,new Color(0,0,0));
        int start=jTextPane1.getSelectionStart();
        int end=jTextPane1.getSelectionEnd();
         Color t=new Color(255,0,0);
         showFront(start,end,t);
         star=start;
         en=end;
       // t.getRed();
        this.jTextPane1.setCaretColor(t);
        //this.jTextPane1.setForeground(t);//设置字体的颜色
        this.jTextPane1.setSelectedTextColor(t);//选中部分的颜色
       // this.jTextPane1.setSelectionColor(t);
        this.jTextPane2.setText(one);
        this.Show();
    }                                        

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        //响应next按钮
        int i,j=0;
        tempString=jTextPane1.getText();
        if(tempString.equals("")==true)
        {
            javax.swing.JOptionPane.showMessageDialog(this, "你尚未打开文件,不能进行下一句标注!", "消息对话框", javax.swing.JOptionPane.INFORMATION_MESSAGE);
            return ;
        }
        i=en;
        char[] tem=new char[1000];
        while(tempString.charAt(i)!=‘.‘)
        {
         //System.out.println(tempString.charAt(i));
         tem[j++]=tempString.charAt(i);
         i++;
        }
        i++;
        en=i;
        
          String te=new String(tem);

        showFront(star,en,new Color(255,0,0));
        star=en-1;
      
          this.jTextPane2.setText(te+".\n");
       System.out.println(tem);
    }                                        

    private void jTextArea1MouseClicked(java.awt.event.MouseEvent evt) {                                        
        // TODO add your handling code here:
        //单击鼠标
        String str=jTextArea1.getText();
          int t=jTextArea1.getCaretPosition(),i=0,temp;
        temp=t;
        //i=t;
        //System.out.println(t);
        /*
        int m=t/201;
        m=t-m*201;
        t=t-m;
        * */
        while((int)str.charAt(t)==0)
        {
            t--;
        }
        while((int)str.charAt(t)!=0&&t>=1)
        {
            //System.out.println(t);
            t--;
        }
        if(t!=0)
        t++;
           // System.out.println(str.charAt(t));
       
        a=new char[200];
        b=new String();
        while((int)str.charAt(t)!=0)
        {
           a[i]=str.charAt(t++);
             b=b+new String(a[i]+"");
             i++;
        }
       //System.out.println(a);
      
    }                                       

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        //To实体
        //jTextField1.setText("");
        jTextField1.setText(b);
    }                                        

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        jTextField2.setText(b);
    }                                        

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        jTextField3.setText(b);
    }                                        

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        //增加按钮
        String d="$";
        String area3=new String();
        if(jTextField1.getText().equals("")==true)
       area3+=d+";  ";
        else{
            area3+=jTextField1.getText();
             area3+=";    ";
        }
         if(jTextField2.getText().equals("")==true)
       area3+=d+";  ";
        else{
            area3+=jTextField2.getText();
             area3+=";    ";
        }
        if(jTextField3.getText().equals("")==true)
       area3+=d;
        else{
            area3+=jTextField3.getText();
             area3+="    ";
        }
        area3+="\n";
        jTextArea3.setText(jTextArea3.getText()+area3);
        jTextField1.setText("");
        jTextField2.setText("");
        jTextField3.setText("");
    }                                        

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        //删除按钮
        String del=jTextArea3.getSelectedText();
        String sum=jTextArea3.getText();
        int i=sum.lastIndexOf(del)+del.length();
        System.out.println(del);
       // System.out.println(sum);
        if(sum.length()==del.length())
        {
            jTextArea3.setText("");
        }
        else if(sum.indexOf(del)!=0)
        {
        String last=sum.substring(0,sum.indexOf(del)-1)+sum.substring(i, sum.length()-1)+"\n";
        jTextArea3.setText(last);
        }
        else {
            String last=sum.substring(i+1, sum.length()-1);
        jTextArea3.setText(last); 
        }
       
    }                                        

    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        //保存
        String []Substring=jTextArea3.getText().split("\n");
        //pathName=pathName.substring(0, pathName.length()-4);
        
        
        //System.out.println(pathName);
         File file1=new File(pathName+jTextField4.getText());
         jTextField4.setText( fileName1+"-"+count+".txt");
         count++;
         jTextArea3.setText("");
         
          StringBuffer bf=new StringBuffer("");
         try {
             BufferedWriter bufw;
             bufw = new BufferedWriter(new FileWriter(file1));
                for(int i=0;i<Substring.length;i++)
        {
            System.out.println(Substring[i]);
            bufw.write("("+Substring[i]+")");
            bufw.newLine();
        }
                bufw.flush();
      } catch (IOException ex) {
             Logger.getLogger(LanguageLabel.class.getName()).log(Level.SEVERE, null, ex);
         }	
    }                                         

    /**
     * @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(LanguageLabel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(LanguageLabel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(LanguageLabel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(LanguageLabel.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 LanguageLabel().setVisible(true);
            }
        });
    }
    
  //打开文件
    void Open()
    {
        //打开文件
        /*变量声明
         * fileChooser:文件选择器,选择要打开的文件
         * selectFile:选择的文件
         * fileName:选择的文件的名字
         * pathName:选择文件的路径
         * tempString:文件中的内容
         */
        fileChooser.showOpenDialog(this);
        File selectFile = fileChooser.getSelectedFile();
         if (selectFile == null) {
            JOptionPane.showMessageDialog(this, "你没有选择要打开的文件!", "提示:", JOptionPane.INFORMATION_MESSAGE);
            return;
        } else {
             BufferedReader buffRead = null;
                 pathName = selectFile.getPath();
                
                fileName = selectFile.getName();
               
                count=1;
                fileName=fileName.substring(0, fileName.length()-4);
                fileName1=fileName;
                 fileName=fileName+"-"+count+".txt";
                  pathName=pathName.substring(0, pathName.indexOf(fileName1));
                 count++;
                jTextField4.setText(fileName);
                //System.out.println(pathName);
               // System.out.println(fileName);
                try {
                    int size = (int) selectFile.length();
                    byte[] tempArray = new byte[size];
                    FileInputStream fin = new FileInputStream(selectFile);
                    fin.read(tempArray);
                    tempString = new String(tempArray);
                    
                    this.jTextPane1.setText(tempString+"\n");
                    //this.jScrollPane1.setToolTipText(temp + "\n");

                } catch (IOException e) {
                    e.printStackTrace();
                }
            //}
         }
    }
    //把每一句显示在树形框内
    void Show()
    {
        String showStr=this.jTextPane2.getText();
        int i=0,length=showStr.length(),x=0,y=0,j=0;
        System.out.println(showStr);
        char t[][]=new char[length][2*length];
        int t1[]=new int [length];
        int t2[]=new int[length];
        while(i<length)
        {
            if(showStr.charAt(i)==‘,‘)
            {
                i++;
                continue;
            }
            if(showStr.charAt(i)==‘ ‘||showStr.charAt(i)==‘.‘)
            { 
                t2[x]=y;
                x++;
                y=0;
            }
            else {
                t[x][y++]=showStr.charAt(i);
            }
            i++;
        }
        for(i=0;i<x;i++)
        {
            String temp1=new String(t[i]);
            int  ch=1;
            char ch1=‘2‘;
            for(j=i+1;j<x;j++)
            {
                String temp2=new String(t[j]);
                if(temp1.endsWith(temp2)==true&&t1[i]==0)
                { 
                    //int temp3=temp2.length();
                    //t[i][]=ch;
                    if((int)t[j][0]==0)break;
                    t1[i]=0;
                    t1[j]=ch;
                    t[i][t2[j]]=‘@‘;
                    t[i][t2[j]+1]=‘1‘;
                    t[j][t2[j]]=‘@‘;
                    t[j][t2[j]+1]=ch1;
                   // System.out.println(t1[j]);
                   ch++;
                   ch1++;
                }
            }
        }
        showStr=new String();
        for(i=0;i<x;i++)
        {
            //System.out.println(t[i]);
           // System.out.println(t[i].length);
            showStr=showStr+new String(t[i]);
           // showStr+=""+t1[i];
            //System.out.println(showStr);
            showStr+="\n";
        }
        jTextArea1.setText(showStr);
    }
   void  showFront(int start,int end,Color t)
   {
        Document document=jTextPane1.getDocument();
        StyleContext sc=StyleContext.getDefaultStyleContext();
        AttributeSet   aset   =   sc.addAttribute(SimpleAttributeSet.EMPTY,StyleConstants.Foreground, t);
     
        Font font=new Font("Times New Roman",Font.CENTER_BASELINE,13);
         aset=sc.addAttribute(aset, StyleConstants.Family, font.getFamily());
         try {
               aset=sc.addAttribute(aset, StyleConstants.FontSize, 13);
             String str= document.getText(start,end-start);   
                //设置字体的大小
              document.remove(start, end-start);
//重新插入字符串,并按新设置的样式进行插入
     document.insertString(start, str, aset);
         } catch (BadLocationException ex) {
             Logger.getLogger(LanguageLabel.class.getName()).log(Level.SEVERE, null, ex);
         }
   }
    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextArea jTextArea3;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextPane jTextPane1;
    private javax.swing.JTextPane jTextPane2;
    // End of variables declaration                   
}
mamicode.com,码迷

HZAU_Parser

标签:java

原文地址:http://blog.csdn.net/guanjungao/article/details/24600959

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!