1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.tags.swing;
17
18 import java.awt.Component;
19 import java.awt.Container;
20 import java.awt.Dialog;
21 import java.awt.Frame;
22 import java.util.Map;
23 import javax.swing.JDialog;
24
25 import org.apache.commons.jelly.JellyTagException;
26 import org.apache.commons.jelly.XMLOutput;
27 import org.apache.commons.jelly.tags.core.UseBeanTag;
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30
31 /***
32 * Creates a Swing Dialog. A JDialog needs to have it's owner set in the constructor,
33 * which is why this class is needed instead of just using a BeanFactory.
34 *
35 * @author Dave Pekarek Krohn
36 * @version $Revision: 155420 $
37 */
38 public class DialogTag extends UseBeanTag implements ContainerTag {
39
40 /*** The Log to which logging calls will be made. */
41 private static final Log log = LogFactory.getLog(DialogTag.class);
42
43 public DialogTag() {
44 super(JDialog.class);
45 }
46
47
48
49
50 /***
51 * Creates a JDialog. The constructor used depends on the value of the owner attribute.
52 */
53 protected Object newInstance(Class theClass, Map attributes, XMLOutput output)
54 throws JellyTagException {
55 Object owner = attributes.remove( "owner" );
56 if (owner instanceof Frame) {
57 return new JDialog((Frame) owner);
58 } else if (owner instanceof Dialog) {
59 return new JDialog((Dialog) owner);
60 } else {
61 return new JDialog();
62 }
63 }
64
65
66
67
68 /***
69 * Adds a component to the dialog.
70 */
71 public void addChild(Component component, Object constraints) {
72 Container contentPane = ((JDialog) getBean()).getContentPane();
73 if (constraints != null) {
74 contentPane.add( component, constraints );
75 } else {
76 contentPane.add( component );
77 }
78 }
79 }
80