1 package com.calipso.xmleditor; 2 3 import javax.swing.*; 4 import javax.swing.tree.DefaultTreeModel ; 5 import java.awt.*; 6 import java.awt.event.ActionListener ; 7 import java.awt.event.ActionEvent ; 8 9 16 17 public class XmlEditorOutputSelector extends JDialog implements ActionListener { 19 20 private JButton btAccept; 21 private JButton btCancel; 22 private DefaultTreeModel model; 23 private JTextField field; 24 25 public XmlEditorOutputSelector(Frame owner, boolean modal, DefaultTreeModel model) throws HeadlessException { 26 super(owner, modal); 27 setTitle("Path destino"); 28 this.model = model; 29 initialize(); 30 } 31 32 private void initialize() { 33 getContentPane().setLayout(new BorderLayout()); 34 getContentPane().add(createCenterPanel(), BorderLayout.CENTER); 35 getContentPane().add(createSouthPanel(), BorderLayout.SOUTH); 36 setWindowLocation(); 37 pack(); 38 setVisible(true); 39 } 40 41 private void setWindowLocation() { 42 java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); 43 setLocation((screenSize.width - getPreferredSize().width) / 2, (screenSize.height - getPreferredSize().height) / 2); 44 } 45 46 private JPanel createSouthPanel() { 47 GridBagLayout bagLayout = new GridBagLayout(); 48 GridBagConstraints constraints = new GridBagConstraints(); 49 JPanel panel = new JPanel(bagLayout); 50 51 btAccept = new JButton("Aceptar"); 52 btAccept.addActionListener(this); 53 panel.add(btAccept); 54 constraints.weightx = 30; 55 constraints.weighty = 1; 56 constraints.gridx = 0; 57 constraints.gridy = 0; 58 constraints.anchor = GridBagConstraints.EAST; 59 constraints.fill = GridBagConstraints.PAGE_START; 60 bagLayout.setConstraints(btAccept, constraints); 61 62 btCancel = new JButton("Cancelar"); 63 btCancel.addActionListener(this); 64 panel.add(btCancel); 65 constraints.weightx = 1; 66 constraints.weighty = 1; 67 constraints.gridx = 1; 68 constraints.gridy = 0; 69 constraints.anchor = GridBagConstraints.EAST; 70 constraints.fill = GridBagConstraints.HORIZONTAL; 71 bagLayout.setConstraints(btCancel, constraints); 72 73 return panel; 74 } 75 76 private JPanel createCenterPanel() { 77 JPanel panel = new JPanel(); 78 panel.setLayout(new FlowLayout()); 79 field = new JTextField(20); 80 panel.add(field); 81 return panel; 82 } 83 84 public void actionPerformed(ActionEvent e) { 85 if(e.getSource() == btAccept) { 86 try{ 87 XmlEditorXmlGenerator.generateFrom(model, field.getText()); 88 }catch(XmlEditorException ex){ 89 ((XmlEditorUI)getOwner()).showException(ex); 90 } 91 dispose(); 92 } else if(e.getSource() == btCancel) { 93 dispose(); 94 } 95 } 96 } 97 | Popular Tags |