import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import javax.swing.text.DefaultEditorKit;
import javax.swing.text.Document;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
import javax.swing.text.StyledEditorKit;
import javax.swing.text.StyledEditorKit.BoldAction;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.HTMLEditorKit.HTMLTextAction;
public class Stream extends JFrame implements ActionListener, WindowListener{
JTextPane ta = new JTextPane();
JTextPane ta1 = new JTextPane();
JMenuBar mb1;
JMenu file;
JMenu farbe;
JMenu schrift;
JMenu menu;
JButton Bold,Italic,Underline,left,center,right,red,green,black;
JTextPane tp = new JTextPane();
JMenuItem load,save,exit,neu,rote,gruene,schwarze,serif,sanserif,monospaced;
String hilf = new String ();
public Stream(String s){
super(s);
this.setSize(600,650);
this.addWindowListener(this);
mb1 = new JMenuBar();
file = new JMenu("Datei");
farbe = new JMenu("Farbe");
schrift = new JMenu("Schriftart");
ImageIcon icon1 = new ImageIcon("neu.gif");
JMenuItem neu = new JMenuItem("Neu", icon1);
neu.setBackground(Color.WHITE);
ImageIcon icon2 = new ImageIcon("open.gif");
load = new JMenuItem("Laden",icon2);
load.setBackground(Color.WHITE);
ImageIcon icon3 = new ImageIcon("save.gif");
save = new JMenuItem("Speichern",icon3);
save.setBackground(Color.WHITE);
exit = new JMenuItem("Beenden");
exit.setBackground(Color.WHITE);
ImageIcon icon6 = new ImageIcon("bold.gif");
Bold = new JButton("",icon6);
ImageIcon icon4 = new ImageIcon("italic.gif");
Italic = new JButton("",icon4);
ImageIcon icon5 = new ImageIcon("underline.gif");
Underline = new JButton("",icon5);
ImageIcon icon7 = new ImageIcon("left.gif");
left = new JButton("",icon7);
ImageIcon icon8 = new ImageIcon("center.gif");
center = new JButton("",icon8);
ImageIcon icon9 = new ImageIcon("right.gif");
right = new JButton("",icon9);
ImageIcon icon10 = new ImageIcon("green.gif");
green = new JButton("",icon10);
ImageIcon icon11 = new ImageIcon("red.gif");
red = new JButton("",icon11);
ImageIcon icon12 = new ImageIcon("black.gif");
black = new JButton("",icon12);
ImageIcon icon15 = new ImageIcon("red.gif");
rote = new JMenuItem("Rot",icon15);
rote.setBackground(Color.WHITE);
ImageIcon icon13 = new ImageIcon("black.gif");
schwarze = new JMenuItem("Grün",icon13);
schwarze.setBackground(Color.WHITE);
ImageIcon icon14 = new ImageIcon("green.gif");
gruene = new JMenuItem("Schwarz",icon14);
gruene.setBackground(Color.WHITE);
serif = new JMenuItem("Serif");
serif.setBackground(Color.WHITE);
sanserif = new JMenuItem("San Serif");
sanserif.setBackground(Color.WHITE);
monospaced = new JMenuItem("Monospaced");
monospaced.setBackground(Color.WHITE);
//styleBox = new StyleBox();
setJMenuBar(mb1);
file.add(neu);
file.add(load);
file.add(save);
file.addSeparator();
file.add(exit);
mb1.add(file);
farbe.add(rote);
farbe.add(gruene);
farbe.add(schwarze);
schrift.add(serif);
schrift.add(sanserif);
schrift.add(monospaced);
mb1.add(file);
mb1.add(file);
mb1.add(farbe);
mb1.add(schrift);
mb1.add(Bold);
mb1.add(Italic);
mb1.add(Underline);
mb1.add(left);
mb1.add(center);
mb1.add(right);
mb1.add(file);
ta.add(tp);
neu.addActionListener(this);
load.addActionListener(this);
save.addActionListener(this);
exit.addActionListener(this);
center.addActionListener(new HTMLEditorKit.AlignmentAction("zentrieren",StyleConstants.ALIGN_CENTER));
left.addActionListener(new HTMLEditorKit.AlignmentAction("linksbündig",StyleConstants.ALIGN_LEFT));
right.addActionListener(new HTMLEditorKit.AlignmentAction("rechtsbündig",StyleConstants.ALIGN_RIGHT));
serif.addActionListener(new schriftan(ta));
sanserif.addActionListener(new schriftan1(ta));
monospaced.addActionListener(new schriftan2(ta));
rote.addActionListener(new HTMLEditorKit.ForegroundAction("Farbe", Color.red));
gruene.addActionListener(new HTMLEditorKit.ForegroundAction("Farbe", Color.green));
schwarze.addActionListener(new HTMLEditorKit.ForegroundAction("Farbe", Color.black));
// JEditorPane editorPane = createEditorPane();
JScrollPane editorScrollPane = new JScrollPane(ta);
editorScrollPane.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
editorScrollPane.setPreferredSize(new Dimension(250, 145));
editorScrollPane.setMinimumSize(new Dimension(10, 10));
// JTextPane textPane = createTextPane();
JScrollPane paneScrollPane = new JScrollPane(tp);
paneScrollPane.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
paneScrollPane.setPreferredSize(new Dimension(250, 155));
paneScrollPane.setMinimumSize(new Dimension(10, 10));
this.add(ta);
this.setVisible(true);
this.add(tp);
}
public static void main(String args[]){
Stream g = new Stream("Editor");
}
// public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
@Override
public void windowActivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowClosed(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowClosing(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowDeactivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowDeiconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowIconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowOpened(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void append(String str) {
Document doc = getDocument();
if (doc != null) {
try {
doc.insertString(doc.getLength(), str, null);
} catch (BadLocationException e) {
}
}
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==load){
ta.setText("");
readin();
}
if(e.getSource()==save){
writeout();
}
if(e.getSource()==neu){
ta.setText("");
}
if(e.getSource()==exit){
System.exit(0);
}
if(e.getSource()==right){
tp = new JTextPane();
SimpleAttributeSet attribs = new SimpleAttributeSet();
StyleConstants.setAlignment(attribs , StyleConstants.ALIGN_RIGHT);
tp.setParagraphAttributes(attribs,true);
}
}
public class serif implements ActionListener {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
Font font = new Font("Serif", Font.ITALIC, 20);
ta.setFont(font);
}
}
public void writeout(){
FileDialog fd2 = new FileDialog (this,"Speichern",FileDialog.SAVE);
fd2.setVisible(true);
File f = new File(fd2.getDirectory()+fd2.getFile());
FileOutputStream f1 = null;
try {
f1 = new FileOutputStream(f);
} catch (FileNotFoundException e2) {
e2.printStackTrace();
}
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(f1));
String line = new String();
line=ta.getText();
try {
out.append(line);
} catch (IOException e1) {
e1.printStackTrace();
}
try {
out.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
public void readin(){
ta1.getText();
ta1 = ta ;
FileDialog fd1 = new FileDialog (this,"Laden",FileDialog.LOAD);
fd1.setVisible(true);
File f = new File(fd1.getDirectory()+fd1.getFile());
FileInputStream f1 = null;
try {
f1 = new FileInputStream(f);
} catch (FileNotFoundException e2) {
e2.printStackTrace();
}
BufferedReader in = new BufferedReader(new InputStreamReader(f1));
String line = new String();
while(line!=null){
try {
line = in.readLine();
} catch (IOException e1) {
e1.printStackTrace();
}
//ta.append(line);
//ta.append("\n");
}
try {
in.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}