Первая отправка
This commit is contained in:
391
src/potoxml/NewJFrame.java
Normal file
391
src/potoxml/NewJFrame.java
Normal file
@ -0,0 +1,391 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package potoxml;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ivanov.i
|
||||
*/
|
||||
public class NewJFrame extends javax.swing.JFrame
|
||||
{
|
||||
|
||||
/**
|
||||
* Creates new form NewJFrame
|
||||
*/
|
||||
public NewJFrame()
|
||||
{
|
||||
initComponents();
|
||||
|
||||
//Загружаем настройки из текстового файла
|
||||
BufferedReader reader;
|
||||
try
|
||||
{
|
||||
reader = new BufferedReader(new FileReader("settings.txt"));
|
||||
String line = null;
|
||||
while ((line = reader.readLine()) != null)
|
||||
{
|
||||
textArea2.append(line + "\n");
|
||||
}
|
||||
} catch (FileNotFoundException ex)
|
||||
{
|
||||
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (IOException ex)
|
||||
{
|
||||
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
|
||||
jButton1 = new javax.swing.JButton();
|
||||
jLabel1 = new javax.swing.JLabel();
|
||||
textArea1 = new java.awt.TextArea();
|
||||
textArea2 = new java.awt.TextArea();
|
||||
jButton2 = new javax.swing.JButton();
|
||||
jLabel2 = new javax.swing.JLabel();
|
||||
jButton3 = new javax.swing.JButton();
|
||||
jTabbedPane1 = new javax.swing.JTabbedPane();
|
||||
jPanel1 = new javax.swing.JPanel();
|
||||
jTextField1 = new javax.swing.JTextField();
|
||||
jLabel3 = new javax.swing.JLabel();
|
||||
jButton4 = new javax.swing.JButton();
|
||||
jPanel2 = new javax.swing.JPanel();
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||
|
||||
jButton1.setText("Сканировать");
|
||||
jButton1.setName(""); // NOI18N
|
||||
jButton1.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton1ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
jLabel1.setText("Перебираем файлы и создаём единый PHP файлик с _(“слово”).");
|
||||
|
||||
jButton2.setText("Сохранить настройки");
|
||||
jButton2.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton2ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
jLabel2.setText("Пути для сканирования");
|
||||
|
||||
jButton3.setText("Экспорт");
|
||||
jButton3.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton3ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
jTextField1.setText("jTextField1");
|
||||
|
||||
jLabel3.setText("Файл:");
|
||||
|
||||
jButton4.setText("Выбрать/Создать");
|
||||
jButton4.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton4ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
|
||||
jPanel1.setLayout(jPanel1Layout);
|
||||
jPanel1Layout.setHorizontalGroup(
|
||||
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(jPanel1Layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addComponent(jLabel3)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 573, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addContainerGap())
|
||||
);
|
||||
jPanel1Layout.setVerticalGroup(
|
||||
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(jPanel1Layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(jLabel3)
|
||||
.addComponent(jButton4))
|
||||
.addContainerGap(304, Short.MAX_VALUE))
|
||||
);
|
||||
|
||||
jTabbedPane1.addTab("English", jPanel1);
|
||||
|
||||
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
|
||||
jPanel2.setLayout(jPanel2Layout);
|
||||
jPanel2Layout.setHorizontalGroup(
|
||||
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 772, Short.MAX_VALUE)
|
||||
);
|
||||
jPanel2Layout.setVerticalGroup(
|
||||
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 338, Short.MAX_VALUE)
|
||||
);
|
||||
|
||||
jTabbedPane1.addTab("Русский", jPanel2);
|
||||
|
||||
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()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(textArea2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(jLabel1)
|
||||
.addComponent(jLabel2))
|
||||
.addGap(0, 0, Short.MAX_VALUE)))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
|
||||
.addComponent(textArea1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.TRAILING))
|
||||
.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)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(24, 24, 24)
|
||||
.addComponent(jButton2))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(jLabel2)
|
||||
.addComponent(jButton3))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(textArea2, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jLabel1)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(textArea1, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jButton1)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||
.addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 366, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void parse(String rootDir,String file)
|
||||
{
|
||||
// Просматриваем каталоги
|
||||
FileFinder finder = new FileFinder();
|
||||
try
|
||||
{
|
||||
// Буферный файл для записи идентификаторов
|
||||
FileWriter fileWriter = new FileWriter(file);
|
||||
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
|
||||
bufferedWriter.write("<?\n");
|
||||
|
||||
List searchRes = null;
|
||||
searchRes = finder.findAll(rootDir,"(.*\\.as$)||(.*\\.mxml$)||(.*\\.xml$)");
|
||||
|
||||
//выводим результаты
|
||||
for (int i = 0; i < searchRes.size(); i++)
|
||||
{
|
||||
File curObject = (File) searchRes.get(i);
|
||||
if (curObject.isDirectory())
|
||||
{
|
||||
System.out.println(curObject.getName() + " (папка)");
|
||||
textArea1.append(curObject.getAbsolutePath() + " (папка)\n");
|
||||
} else
|
||||
{
|
||||
System.out.println(curObject.getName() + " (" + curObject.length() + " байт)");
|
||||
textArea1.append(curObject.getAbsolutePath() + " (" + curObject.length() + " байт)\n");
|
||||
|
||||
|
||||
// Открываем файл и ищем идентификаторы
|
||||
FileReader fileReader = new FileReader(curObject.getAbsolutePath());
|
||||
BufferedReader bufferedReader = new BufferedReader(fileReader);
|
||||
String line;
|
||||
//bufferedWriter.write("1\n");
|
||||
while((line = bufferedReader.readLine()) != null)
|
||||
{
|
||||
int from=0;
|
||||
while(true) //Если несколько значений в строке
|
||||
{
|
||||
int s=line.indexOf("_(", from);
|
||||
if(s>=0)
|
||||
{
|
||||
from=s+2;
|
||||
int e=-1;
|
||||
if(line.charAt(s+2) == '"') { e=line.indexOf("\")", from); }
|
||||
if(line.charAt(s+2) == '\'') { e = line.indexOf("')", from); }
|
||||
if(e>=0)
|
||||
{
|
||||
textArea1.append(line.substring(s, e + 2)+";\n");
|
||||
bufferedWriter.write(" "+line.substring(s, e + 2)+";\n");
|
||||
from=e+2;
|
||||
}
|
||||
}else { break; }
|
||||
}
|
||||
}
|
||||
bufferedReader.close();
|
||||
}
|
||||
}
|
||||
System.out.println("Найдено " + finder.getFilesNumber() + " файлов и " + finder.getDirectoriesNumber() + " папок.");
|
||||
textArea1.append("Найдено " + finder.getFilesNumber() + " файлов и " + finder.getDirectoriesNumber() + " папок.\n");
|
||||
|
||||
bufferedWriter.write("?>\n");
|
||||
bufferedWriter.close();
|
||||
|
||||
} catch (Exception err)
|
||||
{
|
||||
System.out.println(err.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton1ActionPerformed
|
||||
{//GEN-HEADEREND:event_jButton1ActionPerformed
|
||||
BufferedReader reader = new BufferedReader(new StringReader(textArea2.getText()));
|
||||
String line1;
|
||||
String line2;
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
line1 = reader.readLine();
|
||||
line2 = reader.readLine();
|
||||
if(line1==null || line2 == null) break;
|
||||
//Парсим файлы и выписываем идентификаторы для перевода
|
||||
parse(line1, line2); //Перезаписывает файл
|
||||
}
|
||||
} catch (IOException ex)
|
||||
{
|
||||
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}//GEN-LAST:event_jButton1ActionPerformed
|
||||
|
||||
|
||||
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton2ActionPerformed
|
||||
{//GEN-HEADEREND:event_jButton2ActionPerformed
|
||||
FileWriter fileWriter = null;
|
||||
try
|
||||
{
|
||||
fileWriter = new FileWriter("settings.txt");
|
||||
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
|
||||
bufferedWriter.write(textArea2.getText());
|
||||
bufferedWriter.close();
|
||||
} catch (IOException ex)
|
||||
{
|
||||
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} finally
|
||||
{
|
||||
try
|
||||
{
|
||||
fileWriter.close();
|
||||
} catch (IOException ex)
|
||||
{
|
||||
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}//GEN-LAST:event_jButton2ActionPerformed
|
||||
|
||||
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
|
||||
|
||||
new AssemblyJFrame().setVisible(true);
|
||||
|
||||
}//GEN-LAST:event_jButton3ActionPerformed
|
||||
|
||||
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
|
||||
// TODO add your handling code here:
|
||||
}//GEN-LAST:event_jButton4ActionPerformed
|
||||
|
||||
/**
|
||||
* @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(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (InstantiationException ex)
|
||||
{
|
||||
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (IllegalAccessException ex)
|
||||
{
|
||||
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (javax.swing.UnsupportedLookAndFeelException ex)
|
||||
{
|
||||
java.util.logging.Logger.getLogger(NewJFrame.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 NewJFrame().setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton jButton1;
|
||||
private javax.swing.JButton jButton2;
|
||||
private javax.swing.JButton jButton3;
|
||||
private javax.swing.JButton jButton4;
|
||||
private javax.swing.JLabel jLabel1;
|
||||
private javax.swing.JLabel jLabel2;
|
||||
private javax.swing.JLabel jLabel3;
|
||||
private javax.swing.JPanel jPanel1;
|
||||
private javax.swing.JPanel jPanel2;
|
||||
private javax.swing.JTabbedPane jTabbedPane1;
|
||||
private javax.swing.JTextField jTextField1;
|
||||
private java.awt.TextArea textArea1;
|
||||
private java.awt.TextArea textArea2;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
Reference in New Issue
Block a user