/* * Example3.java * * Created on Sat Aug 17 18:17:16 2002 */ import com.brunchboy.util.swing.relativelayout.*; import javax.swing.*; import java.util.*; import java.io.*; import java.awt.event.*; /** * An example of using multiple anchor components with * {@link AttributeConstraint}.

* * @author James Elliott, jim@brunchboy.com * @version $Id: Example3.java,v 1.5 2002/08/19 02:19:47 jim Exp $ **/ public class Example3 { /** * Provides access to the CVS version of this class. **/ public static final String VERSION = "$Id: Example3.java,v 1.5 2002/08/19 02:19:47 jim Exp $"; /** * Display a prototype of a style palette. This is just a mockup of how * you might lay out the user interface; none of the checkboxes or buttons * actually do anything yet.

* * @return the window in which the palette is displayed. **/ public static JFrame showStylePalette() { // Create the palette and assign it a RelativeLayout. final JFrame style = new JFrame("Style"); style.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); RelativeLayout ourLayout = new RelativeLayout(); style.getContentPane().setLayout(ourLayout); // Add the checkboxes for the various styles that can be applied. // HTML tag names are used for the logical component names. style.getContentPane().add(new JCheckBox("Bold"), "bold"); style.getContentPane().add(new JCheckBox("Italic"), "italic"); style.getContentPane().add(new JCheckBox("Underline"), "underline"); style.getContentPane().add(new JCheckBox("Strikethrough"), "s"); style.getContentPane().add(new JCheckBox("Teletype"), "tt"); style.getContentPane().add(new JCheckBox("Emphasis"), "em"); style.getContentPane().add(new JCheckBox("Strong"), "strong"); // Create the sample text. JTextArea sample = new JTextArea( "The quick brown fox jumped over the lazy dog."); sample.setEditable(false); sample.setLineWrap(true); sample.setWrapStyleWord(true); style.getContentPane().add(sample, "sample"); // Add a caption for the sample text style.getContentPane().add(new JLabel("Sample Text:"), "caption"); // Add an "Apply" button. style.getContentPane().add(new JButton("Apply"), "apply"); // Set up the constraints for all components. XmlConstraintBuilder builder = new XmlConstraintBuilder(); try { builder.addConstraints(new File("example3.xml"), ourLayout); } catch (Exception e) { e.printStackTrace(); } // Set the initial size of the frame and show it on the screen. style.setSize(400, 150); style.setVisible(true); return style; } /** * Displays the prototype style palette when invoked from the command line. **/ public static void main(String args[]) { // Show the about box. JFrame style = showStylePalette(); // Wait for the about box to be closed, and then exit. (In a real app, // we wouldn't care about the window closing, but for this example, // be nice and exit the demo once it closes.) while(style.isVisible()) { try { Thread.sleep(500); } catch (InterruptedException ie) { ie.printStackTrace(); System.exit(1); } } System.exit(0); } }