/* * 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") //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); }// 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/* 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); } // /* 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