import java.awt.event.*;
import de.campino.util.*;
import javax.swing.*;
import java.io.*;
public class StartEncoding extends JFrame implements ActionListener{
private JMenuBar jmb=new JMenuBar();
private JMenu jm=new JMenu("Datei");
private JMenuItem jml=new JMenuItem("laden");
private JMenuItem jme=new JMenuItem("encodieren");
private JMenuItem jms=new JMenuItem("speichern");
private File file;
private JTextArea text=new JTextArea();
public static void main(String[] args) {
new StartEncoding();
}
public StartEncoding(){
super("Character Encoding");
createMenu();
this.setJMenuBar(jmb);
this.getContentPane().add(text);
this.setVisible(true);
}
private void createMenu(){
jml.addActionListener(this);
jme.addActionListener(this);
jms.addActionListener(this);
jm.add(jml);
jm.add(jme);
jm.add(jms);
jmb.add(jm);
}
public void actionPerformed(ActionEvent ie) {
if(ie.getSource().equals(jml)){ //datei laden
text.setText("");
JFileChooser fc=new JFileChooser();
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.setMultiSelectionEnabled(false);
fc.showOpenDialog(this);
if(fc.getSelectedFile()!=null){
file=fc.getSelectedFile();
}
BufferedReader bs;
try{
bs=new BufferedReader(new InputStreamReader(new FileInputStream(file)));
String line;
while((line=bs.readLine())!=null){
text.append(line);
text.append("\n");
}
}catch(FileNotFoundException e){
new JMessage(e.getMessage(), "Fehler!", "Ok");
}catch(IOException e){
new JMessage(e.getMessage(), "Fehler!", "Ok");
}
}else if(ie.getSource().equals(jme)){ //austauschen
System.out.println("tach z'samm");
String sb=text.getText();
//kleines ä
sb.replace(new String("ä"), new String("& auml;"));
// großes Ä
sb.replace(new String("Ä"), new String("& Auml;"));
// großes Ü
sb.replace(new String("Ü"), new String("& Uuml;"));
// kleines ü
sb.replace(new String("ü"), new String("& uuml;"));
// großes Ö
sb.replace(new String("Ö"), new String("& Ouml;"));
// kleines ö
sb.replace(new String("ö"), new String("& ouml;"));
// scharfes S
sb.replace(new String("ß"), new String("& szlig;"));
System.out.println(sb);
text.setText(sb);
}else if(ie.getSource().equals(jms)){
//speichern (fehlt noch)
}
}
}