001: package com.calipso.xmleditor;
002:
003: import javax.swing.*;
004: import javax.swing.tree.DefaultTreeModel;
005: import java.awt.*;
006: import java.awt.event.ActionListener;
007: import java.awt.event.ActionEvent;
008:
009: /**
010: *
011: * User: soliveri
012: * Date: 06-oct-2003
013: * Time: 15:12:55
014: *
015: */
016:
017: //No utilizada
018: public class XmlEditorOutputSelector extends JDialog implements
019: ActionListener {
020:
021: private JButton btAccept;
022: private JButton btCancel;
023: private DefaultTreeModel model;
024: private JTextField field;
025:
026: public XmlEditorOutputSelector(Frame owner, boolean modal,
027: DefaultTreeModel model) throws HeadlessException {
028: super (owner, modal);
029: setTitle("Path destino");
030: this .model = model;
031: initialize();
032: }
033:
034: private void initialize() {
035: getContentPane().setLayout(new BorderLayout());
036: getContentPane().add(createCenterPanel(), BorderLayout.CENTER);
037: getContentPane().add(createSouthPanel(), BorderLayout.SOUTH);
038: setWindowLocation();
039: pack();
040: setVisible(true);
041: }
042:
043: private void setWindowLocation() {
044: java.awt.Dimension screenSize = java.awt.Toolkit
045: .getDefaultToolkit().getScreenSize();
046: setLocation((screenSize.width - getPreferredSize().width) / 2,
047: (screenSize.height - getPreferredSize().height) / 2);
048: }
049:
050: private JPanel createSouthPanel() {
051: GridBagLayout bagLayout = new GridBagLayout();
052: GridBagConstraints constraints = new GridBagConstraints();
053: JPanel panel = new JPanel(bagLayout);
054:
055: btAccept = new JButton("Aceptar");
056: btAccept.addActionListener(this );
057: panel.add(btAccept);
058: constraints.weightx = 30;
059: constraints.weighty = 1;
060: constraints.gridx = 0;
061: constraints.gridy = 0;
062: constraints.anchor = GridBagConstraints.EAST;
063: constraints.fill = GridBagConstraints.PAGE_START;
064: bagLayout.setConstraints(btAccept, constraints);
065:
066: btCancel = new JButton("Cancelar");
067: btCancel.addActionListener(this );
068: panel.add(btCancel);
069: constraints.weightx = 1;
070: constraints.weighty = 1;
071: constraints.gridx = 1;
072: constraints.gridy = 0;
073: constraints.anchor = GridBagConstraints.EAST;
074: constraints.fill = GridBagConstraints.HORIZONTAL;
075: bagLayout.setConstraints(btCancel, constraints);
076:
077: return panel;
078: }
079:
080: private JPanel createCenterPanel() {
081: JPanel panel = new JPanel();
082: panel.setLayout(new FlowLayout());
083: field = new JTextField(20);
084: panel.add(field);
085: return panel;
086: }
087:
088: public void actionPerformed(ActionEvent e) {
089: if (e.getSource() == btAccept) {
090: try {
091: XmlEditorXmlGenerator.generateFrom(model, field
092: .getText());
093: } catch (XmlEditorException ex) {
094: ((XmlEditorUI) getOwner()).showException(ex);
095: }
096: dispose();
097: } else if (e.getSource() == btCancel) {
098: dispose();
099: }
100: }
101: }
|