1 19 package org.openharmonise.him.serverconfig; 20 21 import java.awt.Color ; 22 import java.awt.Component ; 23 import java.awt.Container ; 24 import java.awt.Dialog ; 25 import java.awt.Dimension ; 26 import java.awt.Frame ; 27 import java.awt.GraphicsConfiguration ; 28 import java.awt.HeadlessException ; 29 import java.awt.LayoutManager ; 30 import java.awt.event.ActionEvent ; 31 import java.awt.event.ActionListener ; 32 33 import javax.swing.BorderFactory ; 34 import javax.swing.ImageIcon ; 35 import javax.swing.JButton ; 36 import javax.swing.JDialog ; 37 import javax.swing.JFrame ; 38 import javax.swing.JLabel ; 39 import javax.swing.JTextArea ; 40 import javax.swing.JTextField ; 41 42 import org.openharmonise.commons.xml.*; 43 import org.openharmonise.commons.xml.namespace.*; 44 import org.openharmonise.vfs.gui.*; 45 import org.w3c.dom.Document ; 46 import org.xml.sax.SAXException ; 47 48 49 55 public class StateXmlDialog extends JDialog implements LayoutManager , ActionListener { 56 57 private JTextArea m_stateTextArea = null; 58 59 private JTextField m_nameTextField = null; 60 61 private XMLPrettyPrint m_printer = null; 62 63 private JButton m_addButton = null; 64 65 private JButton m_cancelButton = null; 66 67 private JLabel m_validLabel = null; 68 69 PagePreviewConfigOptions m_options = null; 70 75 public StateXmlDialog(Frame arg0, String arg1, PagePreviewConfigOptions options) throws HeadlessException { 76 super(arg0, arg1); 77 m_options = options; 78 setup(); 79 } 80 private void setup(){ 81 m_printer = new XMLPrettyPrint(); 82 83 this.getContentPane().setLayout(this); 84 this.setSize(250,350); 85 int x = this.getGraphicsConfiguration().getBounds().width/2-this.getSize().width/2; 86 int y = this.getGraphicsConfiguration().getBounds().height/2-this.getSize().height/2; 87 88 this.setLocation(x, y); 89 90 m_stateTextArea = new JTextArea (); 91 getContentPane().add(m_stateTextArea); 92 93 m_nameTextField = new JTextField (); 94 getContentPane().add(m_nameTextField); 95 96 m_addButton = new JButton ("Add"); 97 m_addButton.setActionCommand("ADD"); 98 m_addButton.addActionListener(this); 99 getContentPane().add(m_addButton); 100 101 m_cancelButton = new JButton ("Cancel"); 102 m_cancelButton.setActionCommand("CANCEL"); 103 m_cancelButton.addActionListener(this); 104 getContentPane().add(m_cancelButton); 105 106 m_validLabel = new JLabel ("Invalid XML"); 107 m_validLabel.setForeground(Color.RED); 108 m_validLabel.setVisible(false); 109 getContentPane().add(m_validLabel); 110 111 getContentPane().setBackground(new Color (224,224,224)); 112 } 113 114 117 public void layoutContainer(Container arg0) { 118 119 m_nameTextField.setSize(200, 20); 120 m_nameTextField.setLocation(10, 30); 121 m_nameTextField.setBorder(BorderFactory.createEtchedBorder()); 122 123 m_stateTextArea.setSize(200, 150); 124 m_stateTextArea.setLocation(10, 60); 125 m_stateTextArea.setBorder(BorderFactory.createEtchedBorder()); 126 127 m_addButton.setSize(70,20); 128 m_addButton.setLocation(10,230); 129 m_cancelButton.setSize(90,20); 130 m_cancelButton.setLocation(90,230); 131 132 m_validLabel.setSize(100,20); 133 m_validLabel.setLocation(10,210); 134 135 } 136 137 140 public void populateState(String name, Document stateDoc) { 141 m_validLabel.setVisible(false); 142 if (stateDoc != null) { 143 m_nameTextField.setText(name); 144 try { 145 this.m_stateTextArea.setText(m_printer.printNode(stateDoc 146 .getDocumentElement(), false)); 147 } catch (NamespaceClashException e) { 148 e.printStackTrace(); 149 } 150 } 151 } 152 153 public void clear() { 154 this.m_validLabel.setVisible(false); 155 m_nameTextField.setText(""); 156 m_stateTextArea.setText(""); 157 } 158 159 162 public void actionPerformed(ActionEvent ae) { 163 if (ae.getActionCommand().equals("ADD")) { 164 String name = m_nameTextField.getText(); 165 String xml = m_stateTextArea.getText(); 166 try { 167 m_options.addState(name,xml); 168 this.hide(); 169 } catch (SAXException e) { 170 m_validLabel.setVisible(true); 171 } 172 } else if (ae.getActionCommand().equals("CANCEL")) { 173 this.hide(); 174 } 175 176 } 177 178 181 public StateXmlDialog() throws HeadlessException { 182 super(); 183 } 184 185 189 public StateXmlDialog(Dialog arg0) throws HeadlessException { 190 super(arg0); 191 } 192 193 198 public StateXmlDialog(Dialog arg0, boolean arg1) throws HeadlessException { 199 super(arg0, arg1); 200 } 201 202 206 public StateXmlDialog(Frame arg0) throws HeadlessException { 207 super(arg0); 208 } 209 210 215 public StateXmlDialog(Frame arg0, boolean arg1) throws HeadlessException { 216 super(arg0, arg1); 217 } 218 219 224 public StateXmlDialog(Dialog arg0, String arg1) throws HeadlessException { 225 super(arg0, arg1); 226 } 227 228 234 public StateXmlDialog(Dialog arg0, String arg1, boolean arg2) 235 throws HeadlessException { 236 super(arg0, arg1, arg2); 237 } 238 239 245 public StateXmlDialog(Frame arg0, String arg1, boolean arg2) 246 throws HeadlessException { 247 super(arg0, arg1, arg2); 248 } 249 250 257 public StateXmlDialog(Dialog arg0, String arg1, boolean arg2, 258 GraphicsConfiguration arg3) throws HeadlessException { 259 super(arg0, arg1, arg2, arg3); 260 } 261 262 268 public StateXmlDialog(Frame arg0, String arg1, boolean arg2, 269 GraphicsConfiguration arg3) { 270 super(arg0, arg1, arg2, arg3); 271 } 272 273 public static void main(String [] args) { 274 JFrame frame = new JFrame (); 275 frame.setIconImage( ((ImageIcon )IconManager.getInstance().getIcon("16-command-server-properties.gif")).getImage() ); 276 277 StateXmlDialog dialog = new StateXmlDialog(frame, "State xml", null); 278 dialog.show(); 279 } 280 281 284 public void removeLayoutComponent(Component arg0) { 285 } 286 287 288 291 public void addLayoutComponent(String arg0, Component arg1) { 292 } 293 294 297 public Dimension minimumLayoutSize(Container arg0) { 298 return null; 299 } 300 301 304 public Dimension preferredLayoutSize(Container arg0) { 305 return null; 306 } 307 } 308
| Popular Tags
|