// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class HTMLEdit extends JFrame implements ActionListener {
    private JButton bold;
    private JButton save;
    private JEditorPane html;

    public HTMLEdit() {
        getContentPane().setLayout(new BorderLayout());
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(600, 400);
        html = new JEditorPane();
        html.setEditable(true);
        html.setContentType("text/html");
        html.setPreferredSize(new Dimension(600, 300));
        getContentPane().add(html, BorderLayout.NORTH);
        bold = new JButton("Bold");
        bold.addActionListener(this);
        getContentPane().add(bold, BorderLayout.EAST);
        save = new JButton("Save");
        save.addActionListener(this);
        getContentPane().add(save, BorderLayout.WEST);
    }
    public void actionPerformed(ActionEvent evt) {
        if(evt.getSource() == bold) {
         html.replaceSelection("####B####" + html.getSelectedText() + "####/B####");
            html.setText(html.getText().replaceAll("####B####", "<b>"));
            html.setText(html.getText().replaceAll("####/B####", "</b>"));
        }
        if(evt.getSource() == save) {
            // her skulle gemmes i databasen
            JOptionPane.showMessageDialog(this, html.getText());
        }
    }
    public static void main(String[] args) {
        HTMLEdit f = new HTMLEdit();
        f.show();
    }
}
