View Javadoc

1   package gov.nasa.pds.ltdt.gui;
2   
3   import gov.nasa.pds.ltdt.gui.configuration.LTDTKeys;
4   
5   import java.awt.Dimension;
6   import java.awt.FlowLayout;
7   import java.awt.event.WindowAdapter;
8   import java.awt.event.WindowEvent;
9   import java.awt.event.WindowListener;
10  import java.util.Properties;
11  
12  import javax.swing.Box;
13  import javax.swing.JDialog;
14  import javax.swing.JFrame;
15  import javax.swing.JTabbedPane;
16  import javax.swing.SwingUtilities;
17  import javax.swing.event.ChangeEvent;
18  import javax.swing.event.ChangeListener;
19  
20  public class ProjectGalleryDialog extends JDialog{
21  	
22  	public JTabbedPane jtp;
23  	public NewProjectFromPresetTemplatePane templatePane;
24  	public NewProjectFromFilePane filePane;
25  	public OpenProjectPane openProjectPane;
26  	
27  	private MainWindow window;
28  	private Properties props;
29  	private String directory;
30  	
31  	private ProjectGalleryWindowListener wListener;
32  	
33  	/***
34  	 * Constructor
35  	 * @param props  Tool properties
36  	 * @param window Main Window
37  	 * @param title  Title to be placed for this dialog
38  	 * @param index  Index of selected tab
39  	 */
40  	public ProjectGalleryDialog (Properties props, MainWindow window, String title, int index) {
41  		
42  		new ProjectGalleryDialog (props, window, title, index, null);		
43  	}
44  	
45  	public ProjectGalleryDialog (Properties props, MainWindow window, String title, int index, String directory) {
46  		
47  		super (window, title, true);
48  		
49  		this.window = window;
50  		this.props = props;
51  		this.directory = directory;
52  				
53  		constructDialogPane();
54  		
55  		if (index>=0) {
56  			setTopPanel(index);
57  		}
58  		
59  		wListener = new ProjectGalleryWindowListener(window, this);
60  		addWindowListener(wListener);
61  		
62  		
63  		this.setVisible(true);
64  	}
65  	
66  	private void constructDialogPane() {
67  		
68  		this.setSize(new Dimension(600,510));
69  		this.getContentPane().setLayout(new FlowLayout());
70  			
71  		jtp = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
72  		
73  		templatePane = new NewProjectFromPresetTemplatePane(props, window, this);
74  		if (directory!=null)
75  			filePane = new NewProjectFromFilePane(props, window, this, directory);
76  		else
77  			filePane = new NewProjectFromFilePane(props, window, this, null);
78  		openProjectPane = new OpenProjectPane(props, window, this);
79  		
80  		jtp.addChangeListener( new ChangeListener() {
81  
82  			public void stateChanged(ChangeEvent ce) {
83  				tabSelectionHandler();				
84  			}
85  			
86  		});
87  		
88  		jtp.addTab(LTDTKeys.NEWFROMTEMPLATETABNAME, templatePane);
89  		jtp.addTab(LTDTKeys.NEWFROMFILETABNAME, filePane);
90  		jtp.addTab(LTDTKeys.OPENPROJECTTABNAME, openProjectPane);
91  
92  		this.getContentPane().add(jtp);
93  	}
94  	
95  	private void tabSelectionHandler() {
96  		if (window.windowVisible) {
97  			
98  			int selectionIdx = this.jtp.getSelectedIndex();
99  
100 			switch (selectionIdx) {
101 				case LTDTKeys.NEWFROMTEMPLATETABINDEX:	
102 					this.setTitle(LTDTKeys.PROJECTGALLERYTITLE+" - "+LTDTKeys.CREATEFROMTEMPLATETITLE);
103 					break;
104 				case LTDTKeys.NEWFROMFILETABINDEX:
105 					this.setTitle(LTDTKeys.PROJECTGALLERYTITLE+" - "+LTDTKeys.CREATEFROMFILETITLE);
106 					break;
107 				case LTDTKeys.OPENPROJECTTABINDEX:
108 					this.setTitle(LTDTKeys.PROJECTGALLERYTITLE+" - "+LTDTKeys.OPENPROJECTTITLE);
109 					break;
110 				default: return;
111 			}		
112 		}
113 		
114 		return;
115 	}
116 
117 	private void setTopPanel(int index) {
118 		switch (index) {
119 		case LTDTKeys.NEWFROMTEMPLATETABINDEX:
120 			this.jtp.setSelectedIndex(LTDTKeys.NEWFROMTEMPLATETABINDEX);
121 			break;
122 		case LTDTKeys.NEWFROMFILETABINDEX:
123 			this.jtp.setSelectedIndex(LTDTKeys.NEWFROMFILETABINDEX);
124 			break;
125 		case LTDTKeys.OPENPROJECTTABINDEX:
126 			this.jtp.setSelectedIndex(LTDTKeys.OPENPROJECTTABINDEX);
127 			break;
128 		default:;
129 			
130 			
131 		}
132 	}
133 	
134 	/***
135 	 * Handler of window events related to Project Gallery Dialog window
136 	 * @author jwang
137 	 *
138 	 */
139 	private class ProjectGalleryWindowListener extends WindowAdapter {
140 		
141 		private MainWindow window;
142 		private ProjectGalleryDialog pd;
143 		
144 		/***
145 		 * Constructor
146 		 * @param window
147 		 * @param pd
148 		 */
149 		public ProjectGalleryWindowListener (MainWindow window, ProjectGalleryDialog pd) {
150 			this.window = window;
151 			this.pd = pd;
152 		}
153 		
154 		/***
155 		 * Project Gallery window closing event handling
156 		 */
157 		public void windowClosing (WindowEvent we) {
158 			pd.setVisible(false);
159 			window.editorPane.jta.grabFocus();
160 		}
161 	}
162 }