Index: maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/ui/KeysModifier.java diff -u maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/ui/KeysModifier.java:1.1 maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/ui/KeysModifier.java:1.2 --- maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/ui/KeysModifier.java:1.1 Wed Oct 31 16:17:52 2007 +++ maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/ui/KeysModifier.java Fri Nov 2 10:28:08 2007 @@ -7,6 +7,12 @@ import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.swing.JButton; import javax.swing.JFrame; @@ -16,18 +22,28 @@ import org.codelutin.i18n.plugin.core.ParserEvent; import org.codelutin.i18n.plugin.core.ParserException; +import org.codelutin.util.FileUtil; public class KeysModifier extends JFrame implements ParserEvent { private static final long serialVersionUID = 1L; + + // Modification des clés dans le fichier + protected List newKeys; + protected String patternLeft; + protected String patternRight; + // Interface protected JLabel name = new JLabel(); protected JLabel path = new JLabel(); protected JTextField key = new JTextField(); protected JTextArea translate = new JTextArea("tututututututu\ntututututut"); protected JButton next = new JButton("Next >>"); - public KeysModifier() { + public KeysModifier(String patternLeft, String patternRight) { + this.patternLeft = patternLeft; + this.patternRight = patternRight; + setLayout(new GridLayout(7, 2, 10, 10)); Container pane = getContentPane(); @@ -66,10 +82,37 @@ path.setText(file.getPath()); key.setText(""); repaint(); + + newKeys = new ArrayList(); } + public void eventNextFile(File file) { + String content = ""; + int region = 0; + + try { + content = FileUtil.readAsString(file); + } catch (IOException e) { + throw new ParserException(e); + } + + for (Iterator iterator = newKeys.iterator(); iterator.hasNext();) { + String oldKey = iterator.next(); + String realKey = iterator.next(); + Pattern pattern = Pattern.compile("(" + patternLeft + ")(" + Pattern.quote(oldKey) + ")(" + patternRight + ")"); + Matcher matcher = pattern.matcher(content); + matcher.region(region, content.length()); + matcher.find(); + region = matcher.start(); + content = matcher.replaceFirst("$1" + realKey + "$3"); + } + + System.out.println(content); // FIXME: A supprimer + } + public synchronized void eventChangeKey(String keyI18n) { key.setText(keyI18n); + newKeys.add(key.getText()); repaint(); if(isVisible()) { try { @@ -81,13 +124,10 @@ } public String eventGetRealKey() { + newKeys.add(key.getText()); return key.getText(); } - public synchronized void eventNextKey() { - notifyAll(); - } - class EventNextKey implements ActionListener { public void actionPerformed(ActionEvent e) { eventNextKey(); @@ -108,7 +148,8 @@ public void windowOpened(WindowEvent e) {} } - public static void main(String[] args) { - new KeysModifier(); + + public synchronized void eventNextKey() { + notifyAll(); } }