By this stage you've now created a new Configuration File that contains the configurations specified in the default Configuration File, as well as the following changes:
- The Design and Code view tabs are located at the top of the editor.
- When editing content in the Code view, only the HTML content in the <BODY> of the editor's HTML Document is shown.
This configuration of EditLive! for Java Swing works well with the Setting the Body Tutorial. Here is an example of the config_tutorial.xml configuration file used in conjunction with the Setting the Body Code:
This code infers that the config_tutorial.xml file is stored in the same location as the default Configuration File sample_eljconfig.xml.
import java.io.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import com.ephox.editlive.*; import javax.jnlp.*; /** This tutorial shows developers how to populate the <BODY> of * a Document stored in EditLive!, at both load-time and run-time. * */ public class Config extends JFrame implements ActionListener { /** Buttons used to get html contents of EditLive! and copy to JTextArea source */ private JButton bodyButton = new JButton("Set <BODY>"); /** Allows users to enter html content to insert into EditLive!, or holds a copy of the html contents of EditLive! */ private JTextArea source = new JTextArea(10, 30); /** html content to appear in the instance of EditLive! */ private static final String INITIAL_HTML = "<p>Original <i>HTML</i> loaded into EditLive!</p>"; /** Base class for EditLive! */ private ELJBean editLiveBean = new ELJBean(INITIAL_HTML, "", 700, 300, getClass().getResource("config_tutorial.xml"), false); /** Creates JFrame and adds all class properties. Adds action listener to JButtons in JFrame * */ public Config() throws Exception { super("Tutorial - Creating and Editing Configuration Files"); this.getContentPane().setLayout(new GridLayout(2, 1)); SwingUtilities.invokeAndWait(new Runnable() { public void run() { // initialize EditLive! editLiveBean.init(); } }); // Create a JPanel to hold the ELJBean JPanel editorHolder = new JPanel(new FlowLayout()); editorHolder.add(editLiveBean); // Add the JPanel to the JFrame this.getContentPane().add(editorHolder); // Create a JPanel to hold the button and the text area JPanel buttonAndText = new JPanel(new BorderLayout()); // create a JPanel to hold the button JPanel buttonHolder = new JPanel(new FlowLayout()); buttonHolder.add(bodyButton); // add listener to button bodyButton.addActionListener(this); // add button holding panel buttonAndText.add(buttonHolder, BorderLayout.NORTH); // specify textarea content source.setText("<p>Text Area Contents.<br/><b>Note: </b>Ensure this text area contains correctly formatted <i>HTML</i></p>"); // create scrollable pane to hold text area JScrollPane textAreaHolder = new JScrollPane(source); buttonAndText.add(textAreaHolder); // add button and textarea to frame this.getContentPane().add(buttonAndText, BorderLayout.CENTER); // Display the JFrame. this.setSize(new Dimension(710, 640)); this.setVisible(true); // Adding a listener to detect if the JFrame is closing, to close the application if needed. addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); } /** ActionListener for JButtons on the JFrame * * @param e ActionEvent sent by JButton */ public void actionPerformed(ActionEvent e) { if (e.getSource() == bodyButton) { try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { editLiveBean.setBody(source.getText()); } }); } catch (Exception exception) { exception.printStackTrace(); } } } /** Sets up the application and begins its execution * * @param args the command line arguments - ignored */ public static void main(String args[]) throws Exception { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) { System.out.println("Unable to locate UIManager class"); e.printStackTrace(); } new Config(); } }