EditLive! 9 Documentation : Setting CSS in the Swing SDK Code
Created by Jessica Hardy, last modified by Kristin Repsher on May 22, 2012
/*
* Copyright (c) 2006 Ephox Corporation.
*/
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.ephox.editlive.*;
import javax.jnlp.*;
/** Class loads a JFrame with a single panel, containing the
* Ephox EditLive! Editor
*/
public class SetStyles extends JFrame{
/** html content to appear in the instance of EditLive! */
private static final String INITIAL_HTML = "<h1>Specifying CSS for Use with EditLive!</h1><h3>Using the EditLive! Configuration File</h3><p>The EditLive! Configuration File can be used to explicitly define CSS or to reference an external CSS file.</p><h3>Using the Styles Load-Time Property</h3><p>The <em>Styles</em> load-time property for EditLive! can be used to specify CSS.</p><h5 class=\"warning\">Note: The Styles load-time property cannot be used to reference an external CSS file.</h5>";
/** Base class for EditLive! */
private ELJBean editLiveBean = new ELJBean(INITIAL_HTML, "", 700, 570, getClass().getResource("styles_config.xml"), false);
/** Creates JFrame and adds all class properties. Adds action listener to JButtons in JFrame
*
*/
public SetStyles() throws Exception {
super("Tutorial - Set Styles");
this.getContentPane().setLayout(new FlowLayout());
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
// set CSS for EditLive! and initialize
editLiveBean.setStyles("h5.warning{color:red;font-weight:bold;}");
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);
// Display the JFrame.
this.setSize(new Dimension(710, 620));
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);
}
});
}
/** Sets up the application and begins it's execution
*
* @param args the command line arguements - 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 SetStyles();
}
}