001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.him.serverconfig;
020:
021: import java.awt.Color;
022: import java.awt.Component;
023: import java.awt.Container;
024: import java.awt.Dialog;
025: import java.awt.Dimension;
026: import java.awt.Frame;
027: import java.awt.GraphicsConfiguration;
028: import java.awt.HeadlessException;
029: import java.awt.LayoutManager;
030: import java.awt.event.ActionEvent;
031: import java.awt.event.ActionListener;
032:
033: import javax.swing.BorderFactory;
034: import javax.swing.ImageIcon;
035: import javax.swing.JButton;
036: import javax.swing.JDialog;
037: import javax.swing.JFrame;
038: import javax.swing.JLabel;
039: import javax.swing.JTextArea;
040: import javax.swing.JTextField;
041:
042: import org.openharmonise.commons.xml.*;
043: import org.openharmonise.commons.xml.namespace.*;
044: import org.openharmonise.vfs.gui.*;
045: import org.w3c.dom.Document;
046: import org.xml.sax.SAXException;
047:
048: /**
049: *
050: * @author matt treanor
051: * @version $Revision: 1.1 $
052: *
053: */
054: public class StateXmlDialog extends JDialog implements LayoutManager,
055: ActionListener {
056:
057: private JTextArea m_stateTextArea = null;
058:
059: private JTextField m_nameTextField = null;
060:
061: private XMLPrettyPrint m_printer = null;
062:
063: private JButton m_addButton = null;
064:
065: private JButton m_cancelButton = null;
066:
067: private JLabel m_validLabel = null;
068:
069: PagePreviewConfigOptions m_options = null;
070:
071: /**
072: * @param arg0
073: * @param arg1
074: * @throws java.awt.HeadlessException
075: */
076: public StateXmlDialog(Frame arg0, String arg1,
077: PagePreviewConfigOptions options) throws HeadlessException {
078: super (arg0, arg1);
079: m_options = options;
080: setup();
081: }
082:
083: private void setup() {
084: m_printer = new XMLPrettyPrint();
085:
086: this .getContentPane().setLayout(this );
087: this .setSize(250, 350);
088: int x = this .getGraphicsConfiguration().getBounds().width / 2
089: - this .getSize().width / 2;
090: int y = this .getGraphicsConfiguration().getBounds().height / 2
091: - this .getSize().height / 2;
092:
093: this .setLocation(x, y);
094:
095: m_stateTextArea = new JTextArea();
096: getContentPane().add(m_stateTextArea);
097:
098: m_nameTextField = new JTextField();
099: getContentPane().add(m_nameTextField);
100:
101: m_addButton = new JButton("Add");
102: m_addButton.setActionCommand("ADD");
103: m_addButton.addActionListener(this );
104: getContentPane().add(m_addButton);
105:
106: m_cancelButton = new JButton("Cancel");
107: m_cancelButton.setActionCommand("CANCEL");
108: m_cancelButton.addActionListener(this );
109: getContentPane().add(m_cancelButton);
110:
111: m_validLabel = new JLabel("Invalid XML");
112: m_validLabel.setForeground(Color.RED);
113: m_validLabel.setVisible(false);
114: getContentPane().add(m_validLabel);
115:
116: getContentPane().setBackground(new Color(224, 224, 224));
117: }
118:
119: /* (non-Javadoc)
120: * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
121: */
122: public void layoutContainer(Container arg0) {
123:
124: m_nameTextField.setSize(200, 20);
125: m_nameTextField.setLocation(10, 30);
126: m_nameTextField.setBorder(BorderFactory.createEtchedBorder());
127:
128: m_stateTextArea.setSize(200, 150);
129: m_stateTextArea.setLocation(10, 60);
130: m_stateTextArea.setBorder(BorderFactory.createEtchedBorder());
131:
132: m_addButton.setSize(70, 20);
133: m_addButton.setLocation(10, 230);
134: m_cancelButton.setSize(90, 20);
135: m_cancelButton.setLocation(90, 230);
136:
137: m_validLabel.setSize(100, 20);
138: m_validLabel.setLocation(10, 210);
139:
140: }
141:
142: /**
143: * @param name State scenario name
144: */
145: public void populateState(String name, Document stateDoc) {
146: m_validLabel.setVisible(false);
147: if (stateDoc != null) {
148: m_nameTextField.setText(name);
149: try {
150: this .m_stateTextArea.setText(m_printer.printNode(
151: stateDoc.getDocumentElement(), false));
152: } catch (NamespaceClashException e) {
153: e.printStackTrace();
154: }
155: }
156: }
157:
158: public void clear() {
159: this .m_validLabel.setVisible(false);
160: m_nameTextField.setText("");
161: m_stateTextArea.setText("");
162: }
163:
164: /* (non-Javadoc)
165: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
166: */
167: public void actionPerformed(ActionEvent ae) {
168: if (ae.getActionCommand().equals("ADD")) {
169: String name = m_nameTextField.getText();
170: String xml = m_stateTextArea.getText();
171: try {
172: m_options.addState(name, xml);
173: this .hide();
174: } catch (SAXException e) {
175: m_validLabel.setVisible(true);
176: }
177: } else if (ae.getActionCommand().equals("CANCEL")) {
178: this .hide();
179: }
180:
181: }
182:
183: /**
184: * @throws java.awt.HeadlessException
185: */
186: public StateXmlDialog() throws HeadlessException {
187: super ();
188: }
189:
190: /**
191: * @param arg0
192: * @throws java.awt.HeadlessException
193: */
194: public StateXmlDialog(Dialog arg0) throws HeadlessException {
195: super (arg0);
196: }
197:
198: /**
199: * @param arg0
200: * @param arg1
201: * @throws java.awt.HeadlessException
202: */
203: public StateXmlDialog(Dialog arg0, boolean arg1)
204: throws HeadlessException {
205: super (arg0, arg1);
206: }
207:
208: /**
209: * @param arg0
210: * @throws java.awt.HeadlessException
211: */
212: public StateXmlDialog(Frame arg0) throws HeadlessException {
213: super (arg0);
214: }
215:
216: /**
217: * @param arg0
218: * @param arg1
219: * @throws java.awt.HeadlessException
220: */
221: public StateXmlDialog(Frame arg0, boolean arg1)
222: throws HeadlessException {
223: super (arg0, arg1);
224: }
225:
226: /**
227: * @param arg0
228: * @param arg1
229: * @throws java.awt.HeadlessException
230: */
231: public StateXmlDialog(Dialog arg0, String arg1)
232: throws HeadlessException {
233: super (arg0, arg1);
234: }
235:
236: /**
237: * @param arg0
238: * @param arg1
239: * @param arg2
240: * @throws java.awt.HeadlessException
241: */
242: public StateXmlDialog(Dialog arg0, String arg1, boolean arg2)
243: throws HeadlessException {
244: super (arg0, arg1, arg2);
245: }
246:
247: /**
248: * @param arg0
249: * @param arg1
250: * @param arg2
251: * @throws java.awt.HeadlessException
252: */
253: public StateXmlDialog(Frame arg0, String arg1, boolean arg2)
254: throws HeadlessException {
255: super (arg0, arg1, arg2);
256: }
257:
258: /**
259: * @param arg0
260: * @param arg1
261: * @param arg2
262: * @param arg3
263: * @throws java.awt.HeadlessException
264: */
265: public StateXmlDialog(Dialog arg0, String arg1, boolean arg2,
266: GraphicsConfiguration arg3) throws HeadlessException {
267: super (arg0, arg1, arg2, arg3);
268: }
269:
270: /**
271: * @param arg0
272: * @param arg1
273: * @param arg2
274: * @param arg3
275: */
276: public StateXmlDialog(Frame arg0, String arg1, boolean arg2,
277: GraphicsConfiguration arg3) {
278: super (arg0, arg1, arg2, arg3);
279: }
280:
281: public static void main(String[] args) {
282: JFrame frame = new JFrame();
283: frame.setIconImage(((ImageIcon) IconManager.getInstance()
284: .getIcon("16-command-server-properties.gif"))
285: .getImage());
286:
287: StateXmlDialog dialog = new StateXmlDialog(frame, "State xml",
288: null);
289: dialog.show();
290: }
291:
292: /* (non-Javadoc)
293: * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
294: */
295: public void removeLayoutComponent(Component arg0) {
296: }
297:
298: /* (non-Javadoc)
299: * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
300: */
301: public void addLayoutComponent(String arg0, Component arg1) {
302: }
303:
304: /* (non-Javadoc)
305: * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
306: */
307: public Dimension minimumLayoutSize(Container arg0) {
308: return null;
309: }
310:
311: /* (non-Javadoc)
312: * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
313: */
314: public Dimension preferredLayoutSize(Container arg0) {
315: return null;
316: }
317: }
|