View Javadoc

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