FileDocCategorySizeDatePackage
SwingTransformer.javaAPI DocExample5314Sun Sep 02 14:59:04 BST 2001com.oreilly.javaxslt.swingtrans

SwingTransformer

public class SwingTransformer extends JFrame
The entry point into this application. This class displays the main window, allowing the user to select an XML file and an XSLT file.

Fields Summary
private JTextField
xmlFileFld
private JTextField
xsltFileFld
private XMLFileFilter
xmlFilter
private XSLTFileFilter
xsltFilter
private JFileChooser
fileChooser
private Action
loadXMLAction
private Action
loadXSLTAction
private Action
transformAction
Constructors Summary
public SwingTransformer()
Construct the main window and layout the GUI.

        super("Swing XSLT Transformer");

        // note: this line requires Java 2 v1.3
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        Container cp = getContentPane();
        cp.setLayout(new GridBagLayout());

        GridBagConstraints gbc = new GridBagConstraints();
        gbc.anchor = GridBagConstraints.WEST;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.gridx = GridBagConstraints.RELATIVE;
        gbc.gridy = 0;
        gbc.insets.top = 2;
        gbc.insets.left = 2;
        gbc.insets.right = 2;

        cp.add(new JLabel("XML File:"), gbc);
        gbc.weightx = 1.0;
        cp.add(this.xmlFileFld, gbc);
        gbc.weightx = 0.0;
        cp.add(new JButton(this.loadXMLAction), gbc);

        gbc.gridy++;
        cp.add(new JLabel("XSLT File:"), gbc);
        gbc.weightx = 1.0;
        cp.add(this.xsltFileFld, gbc);
        gbc.weightx = 0.0;
        cp.add(new JButton(this.loadXSLTAction), gbc);

        gbc.gridy++;
        gbc.gridx = 0;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.anchor = GridBagConstraints.CENTER;
        gbc.fill = GridBagConstraints.NONE;
        cp.add(new JButton(this.transformAction), gbc);

        pack();
    
Methods Summary
public static voidmain(java.lang.String[] args)
The entry point into the application; shows the main window.


                   
         
        new SwingTransformer().setVisible(true);
    
private voidselectXMLFile()
Show the file chooser, listing all XML files.

        this.fileChooser.setDialogTitle("Select XML File");
        this.fileChooser.setFileFilter(this.xmlFilter);
        int retVal = this.fileChooser.showOpenDialog(this);
        if (retVal == JFileChooser.APPROVE_OPTION) {
            this.xmlFileFld.setText(
                    this.fileChooser.getSelectedFile().getAbsolutePath());
        }
    
private voidselectXSLTFile()
Show the file chooser, listing all XSLT files.

        this.fileChooser.setDialogTitle("Select XSLT File");
        this.fileChooser.setFileFilter(this.xsltFilter);
        int retVal = this.fileChooser.showOpenDialog(this);
        if (retVal == JFileChooser.APPROVE_OPTION) {
            this.xsltFileFld.setText(
                    this.fileChooser.getSelectedFile().getAbsolutePath());
        }
    
private voidshowErrorDialog(java.lang.String msg)

        JOptionPane.showMessageDialog(this, msg, "Error",
                JOptionPane.ERROR_MESSAGE);