View Javadoc

1   /*
2    * @(#) ActorDialog.java Apr 15, 2004
3    * 
4    * 
5    * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
6    * Delft, the Netherlands. All rights reserved.
7    * 
8    * See for project information <a href="http://www.simulation.tudelft.nl/">
9    * www.simulation.tudelft.nl </a>.
10   * 
11   * The source code and binary code of this software is proprietary information
12   * of Delft University of Technology.
13   */
14  
15  package org.gscg.gameleader.dialogs.actor.components;
16  
17  import java.awt.BorderLayout;
18  import java.awt.Color;
19  import java.awt.Component;
20  import java.awt.Window;
21  
22  import javax.swing.JDialog;
23  import javax.swing.JScrollPane;
24  import javax.swing.ScrollPaneConstants;
25  import javax.swing.WindowConstants;
26  
27  import nl.tudelft.simulation.actor.ActorInterface;
28  
29  import org.gscg.gameleader.dialogs.components.DialogPanelFactory;
30  
31  /***
32   * A GUI element for presentation and manipulation of an actor object. The
33   * dialog is 'powered' by an instance of {see ObjectJTable}. The dialog is
34   * positioned to a 'parent' window, or displayed centered if no parent window is
35   * available.
36   * <p>
37   * 
38   * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
39   * Delft, the Netherlands. All rights reserved.
40   * 
41   * See for project information <a href="http://www.simulation.tudelft.nl/">
42   * www.simulation.tudelft.nl </a>.
43   * 
44   * The source code and binary code of this software is proprietary information
45   * of Delft University of Technology.
46   * 
47   * @author <a
48   *         href="http://www.tbm.tudelft.nl/webstaf/stijnh/index.htm">Stijn-Pieter
49   *         van Houten </a>
50   * @version $Revision: 1.1 $ $Date: 2005/06/16 12:33:58 $
51   * @since 1.0.3
52   */
53  public class ActorDialog extends JDialog
54  {
55  	/*** the serial version uid */
56  	private static final long serialVersionUID = 11L;
57  
58  	/*** the parent window, set during initialization */
59  	private Window parent;
60  
61  	/***
62  	 * Constructs a new ActorDialog.
63  	 * 
64  	 * @param actor The introspected object
65  	 */
66  	public ActorDialog(final ActorInterface actor)
67  	{
68  		this(null, actor);
69  	}
70  
71  	/***
72  	 * Constructs a new ActorDialog.
73  	 * 
74  	 * @param parent The parent window, used for locating the dialog
75  	 * @param actor The introspected object
76  	 */
77  	public ActorDialog(final Window parent, final ActorInterface actor)
78  	{
79  		this(parent, actor.toString(), DialogPanelFactory.getPanel(actor));
80  	}
81  
82  	/***
83  	 * Constructs a new ActorDialog.
84  	 * 
85  	 * @param parent The parent window, used for locating the dialog
86  	 * @param title The title of the dialog
87  	 * @param dialog The table displaying the data of the introspected object
88  	 */
89  	public ActorDialog(final Window parent, final String title,
90  			final Component dialog)
91  	{
92  		super();
93  		this.parent = parent;
94  		this.init(title, dialog);
95  	}
96  
97  	/***
98  	 * initializes the dialog
99  	 * 
100 	 * @param title the title of the dialog
101 	 * @param dialog the table to display
102 	 */
103 	private void init(final String title, final Component dialog)
104 	{
105 		this.setModal(false);
106 		this.setTitle(title);
107 		this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
108 		this.getContentPane().setLayout(new BorderLayout());
109 		JScrollPane pane = new JScrollPane(dialog,
110 				ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
111 				ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
112 		pane.setBackground(Color.WHITE);
113 		this.getContentPane().add(pane, BorderLayout.CENTER);
114 		this.getContentPane().setBackground(Color.WHITE);
115 		this.pack();
116 		setRelativeLocation();
117 		this.setVisible(true);
118 	}
119 
120 	/***
121 	 * Initializes the location of this dialog relative to its parent window if
122 	 * any.
123 	 */
124 	private void setRelativeLocation()
125 	{
126 		setLocationRelativeTo(this.parent);
127 	}
128 }